Communitygithub.com

delivery-gate

Stop hook,在 Claude 完成任務前進行機械式品質檢查,確保學習記錄已更新且磁碟空間充足。

delivery-gate 是什麼?

Delivery Gate 是一個用於 Claude Code 的 Stop hook,透過檔案修改時間戳記、磁碟用量以及正則表達式比對等純機械式檢查,在 Claude 完成工作前自動驗證三個關鍵條件:學習庫是否在今天被更新、磁碟空間是否充足、以及是否有捷徑或合理化(rationalization)的文字模式。與仰賴 AI 推理的品質閘門(如 self-audit)不同,Delivery Gate 只檢查機器具可驗證的事實,無需任何 AI 推論,因此不會受到幻覺或主觀判斷影響。當複雜任務(編輯或寫入次數 ≥ 3)完成但學習庫未更新時,或磁碟空間低於 15GB 時,該 hook 會直接阻斷任務完成並輸出錯誤訊息。此工具支援 Python 3.8+,跨平台(Windows、macOS、Linux),無需任何第三方套件,僅依賴 Python 標準庫。建議與 self-audit(推理品質閘門)搭配使用,形成縱深防禦:Delivery Gate 確保「學習被記錄」,self-audit 確保「記錄品質正確」。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Delivery Gate — 機械式品質閘門 for Claude Code

一個 Stop hook,在 Claude 完成工作前檢查三件事,僅使用確定性檢查 — 檔案修改時間戳記、磁碟用量以及 transcript 文字中的正則表達式。無任何 AI 推論。

這與推理閘門(如 self-audit)不同:delivery-gate 檢查機器可驗證的事實;self-audit 則從四個推理維度檢查輸出品質。兩者共同形成縱深防禦:

  • delivery-gate:「學習庫今天有更新嗎?磁碟空間安全嗎?」
  • self-audit:「檔案內容正確、完整且誠實嗎?」

這與 CI 管線閘門相同 — 自動化、確定性的檢查,驗證機器可讀的事實,而非信任自我回報的狀態。

檢查項目

檢查項目機制觸發結果
合理化模式對 transcript 結尾進行正則比對僅警告(永不阻擋)
學習庫過時檢查 5 個可設定路徑的 mtime若部分過時則警告;若 ≥3 個過時 或 growth-log 過時且任務複雜則阻擋
磁碟空間 < 50GBshutil.disk_usage警告
磁碟空間 < 15GBshutil.disk_usage阻擋(exit 2)

合理化偵測會針對諸如「先跳過測試」和「預先存在的錯誤」等模式發出警告 — 這些是思考可能被中斷的表面跡象。它永遠不會自行阻擋,因為正則啟發式可能誤判。阻擋條件為:磁碟空間危急、≥3 個學習庫過時,或 growth-log 特定過時(均需複雜任務編輯次數 ≥3)。

為什麼需要

Claude Code 內建的檢查涵蓋程式碼品質(建置 → 型別檢查 → 語法檢查 → 測試)。但存在另一種失敗模式:AI 產出可運作的程式碼,但工作階段的衛生習慣被忽略 — 學習未被記錄、合理化捷徑、磁碟空間悄悄用完。

在多次「出貨後就忘記」的工作階段後,人類沒有成長。這個 hook 強制執行習慣:複雜任務 → 必須更新學習庫。

安裝

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

在 ~/.claude/settings.json 中加入:

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

學習庫

在專案的記憶體目錄中建立以下檔案。hook 會檢查是否至少有一個在今天被更新:

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,非複雜任務) → exit 0

複雜任務,有學習記錄 — 允許:

edit_count=5 (複雜) → 檢查 LIBS → growth-log 今天已更新 → exit 0

複雜任務,無學習記錄 — 阻擋:

edit_count=4 (複雜) → 檢查 LIBS → 全部 5 個過時 → exit 2
stderr: "Blocked: complex task completed but no learning captured today."

磁碟空間不足 — 阻擋:

disk_free=12GB < 15GB 危急 → exit 2
stderr: "Blocked: disk space at 12GB (threshold: 15GB)."

限制

這個 hook 強制的是更新學習庫的習慣,而非記錄的品質。如果 output-index.md 已更新但 growth-log 被跳過,hook 仍會通過(5 個學習庫中更新了 1 個)。這是刻意設計的:機械式閘門檢查機器可驗證的事實。若要驗證內容品質,請搭配 self-audit 使用。

相容性

  • Python 3.8+(使用 from __future__ import annotations)
  • 跨平台:Windows、macOS、Linux
  • 無任何第三方相依套件

品質

此程式碼經過 4 輪自動化程式碼審查(CodeRabbit + Greptile),共發現並修復了 9 個實際錯誤。

參見

  • 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.

相關技能