Communitygithub.com

交付门控

一个阻止 Claude 在质量检查通过前结束会话的停止钩子。它能检测合理化模式、过时的学习日志以及低磁盘空间,从而机械地强制执行学习记录习惯。

交付门控 是什么?

交付门控(Delivery Gate)是一个用于 Claude Code 的确定性停止钩子,它通过检查文件修改时间戳、磁盘使用情况和转录文本的正则表达式模式,阻止 Claude 在质量检查和学习记录完成前声明工作结束。与基于 AI 推理的 reasoning gates(如 self-audit)不同,delivery-gate 专注于机器可验证的事实,形成防御纵深:前者验证文件内容的正确性与完整性,后者强制执行学习习惯(如必须每日更新学习库)和资源限制(磁盘空间低于 15GB 时直接阻塞)。该工具配置灵活,用户可自定义检查的学习库路径、复杂任务阈值和磁盘警告/阻塞阈值。它使用纯 Python 标准库,跨平台兼容,非常适合需要培养长期学习习惯、避免“交付即遗忘”模式的开发团队。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/delivery-gate

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

交付门控 — Claude Code 的机械式质量门控

一个停止钩子,在 Claude 能够结束会话之前检查三项内容,仅使用确定性检查 — 文件修改时间戳、磁盘使用量和转录文本的正则表达式模式。无 AI 推理。

这与推理门控(如 self-audit)不同:delivery-gate 检查机器可验证的事实;self-audit 在四个推理维度上检查输出质量。它们共同构成纵深防御:

  • delivery-gate:“学习库今天是否被更新?磁盘空间是否安全?”
  • self-audit:“文件内容是否正确、完整、诚实?”

这与 CI 流水线门控的模式相同 — 自动化的、确定性的检查,验证机器可读的事实,而非信任自我报告的状态。

检查项

检查项机制命中时行为
合理化模式对转录文本尾部进行正则匹配仅警告(永不阻塞)
过时的学习库对 5 个可配置路径进行 mtime 检查部分过时时警告;阻塞条件:>=3 个过时 或 growth-log 过时且任务复杂
磁盘空间 < 50GBshutil.disk_usage警告
磁盘空间 < 15GBshutil.disk_usage阻塞(退出码 2)

合理化检测会警告诸如“暂时跳过测试”和“预先存在的 bug”等模式 — 这些是思考可能被中断的表面信号。它永远不会单独阻塞,因为正则启发式方法可能产生误报。阻塞条件是:磁盘临界、>=3 个学习库过时,或 growth-log 特别过时(均要求复杂任务 >=3 次编辑)。

为什么需要

Claude Code 的内置检查涵盖代码质量(构建 → 类型检查 → 检查 → 测试)。但存在另一种失败模式:代理生成了可用的代码,但会话卫生被忽视 — 学习未被记录、合理化的捷径、磁盘空间悄然耗尽。

在多次“交付即忘”的会话中,人类没有成长。此钩子强制执行习惯:复杂任务 → 必须更新学习库。

安装

cp quality-gate.py ~/.claude/scripts/

添加到 ~/.claude/settings.json:

{
  "hooks": {
    "Stop": [{
      "hooks": [{
        "type": "command",
        "command": "python3 ~/.claude/scripts/quality-gate.py",
        "timeout": 5000
      }]
    }]
  }
}

学习库

在项目的 memory 目录中创建这些文件。钩子会检查今天是否至少有一个被更新:

memory/
├── growth-log/          # 每日学习条目(目录)
├── decisions/log.md     # 决策日志
├── output-index.md      # 会话输出索引
├── ratings-tracker.md   # 随时间变化的技能评分
└── tooling_capabilities.md  # 已知工具清单

自定义 LIBS 字典以匹配你自己的文件结构。

配置

编辑 quality-gate.py:

变量默认值用途
RATIONALIZE4 条模式用于检测合理化模式的正则表达式
LIBS5 个库要检查今日更新的文件/目录
COMPLEX_THRESHOLD3将编辑/写入调用归类为复杂任务的门槛
DISK_WARN_GB50低于此值发出警告
DISK_CRIT_GB15低于此值阻塞

示例

简单会话 — 允许通过:

edit_count=1 (< 3,非复杂任务) → 退出码 0

复杂任务,学习已记录 — 允许通过:

edit_count=5 (复杂) → 检查 LIBS → growth-log 今天已更新 → 退出码 0

复杂任务,无学习记录 — 被阻塞:

edit_count=4 (复杂) → 检查 LIBS → 全部 5 个过时 → 退出码 2
stderr: "Blocked: complex task completed but no learning captured today."

磁盘空间低 — 被阻塞:

disk_free=12GB < 15GB 临界 → 退出码 2
stderr: "Blocked: disk space at 12GB (threshold: 15GB)."

局限性

此钩子强制执行触及学习库的习惯,而非记录内容的质量。如果 output-index.md 已更新但 growth-log 被跳过,钩子会通过(5 个库中的 1 个被触及)。这是设计使然:机械门控检查机器可验证的事实。对于内容质量验证,请与 self-audit 配合使用。

兼容性

  • Python 3.8+(使用 from __future__ import annotations)
  • 跨平台:Windows、macOS、Linux
  • 零依赖,仅使用标准库

质量

此代码经过了 4 轮自动化代码审查(CodeRabbit + Greptile),发现并修复了 9 个真实 bug。

另见

  • self-audit — 推理质量门控(完整性/一致性/基于实际/诚实性)
  • verification-loop — 代码质量检查(构建/类型检查/检查/测试)
  • gateguard — PreToolUse 安全门控

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能