Skip to content

docs: 新增 hooks/__protocol__.md 契约 cheat-sheet (v0.6.3) - #8

Merged
loong10k merged 1 commit into
mainfrom
feat/host-protocol-cheatsheet-v0.6.3
Sep 22, 2026
Merged

loong10k merged 1 commit into
mainfrom
feat/host-protocol-cheatsheet-v0.6.3

Conversation

@loong10k

Copy link
Copy Markdown
Contributor

What

  • 新增 hooks/protocol.md(7 节)作为 codeguard hooks 与宿主三端(Codex/ZCode/Kimi)契约的单源事实
  • tests/run_all.py 顶部 docstring 增加单源引用
  • OpenSpec spec: hook-protocol (3 Requirements) 合入

Sections

  1. 协议总表(事件 × exit × stdout × 阻断)
  2. 三端兼容矩阵
  3. fail-open 约定(main 必须 swallow Exception → exit 0)
  4. PreToolUse 硬拦截边界(唯一 exit 2 的 hook + 综述行契约)
  5. 新增 hook checklist
  6. 协议变更策略(同一 commit 原子化)
  7. 与 OpenSpec spec 的对应

Why

MEDIUM #7 评审已指出协议契约散布在 8 处(5 个 hook docstring + 2 份 docs + gate_lib 钩子间互引)。
新加 hook 时容易在退出码语义(0 vs 2 vs fail-open)与 JSON 协议(stdout / additionalContext / stderr)走偏。

Verification

  • unittest 14/14
  • run_all 141/141/0
  • openspec strict 6/6
  • git diff --check clean

Spec

  • ADDED hook-protocol (3 Requirements):
    • canonical source SHALL live in hooks/protocol.md
    • tests/run_all.py SHALL reference the cheat-sheet
    • cheat-sheet SHALL document fail-open convention
  • Change archived: openspec/changes/archive/2026-09-22-add-host-protocol-cheatsheet/

新增 hooks/__protocol__.md(7 节):
- 协议总表:5 个事件 × exit 码 × stdout 形态 × 阻断语义
- 三端兼容矩阵:Codex / ZCode / Kimi
- fail-open 约定:__main__ 必须 swallow Exception → exit 0
- PreToolUse 硬拦截边界:唯一 exit 2 的 hook + 综述行契约
- 新增 hook checklist:7 步自检清单
- 协议变更策略:同一 commit 改本文件 + 实现 + 测试 + OpenSpec
- 与 OpenSpec spec 的对应映射

tests/run_all.py 顶部 docstring 增加单源引用
OpenSpec spec: hook-protocol (3 Requirements) 已合入

验证:unittest 14/14 + run_all 141/141/0 + openspec strict 6/6 + diff clean

实现定位行号锁在 v0.6.2:
- SessionStart 摘要:env_check.py:34
- UserPromptSubmit JSON:user_prompt_validator.py:104,117
- PreToolUse stderr:pre_tool_git_guard.py:159
- PostToolUse JSON:post_tool_lint.py:226,253,275
- Stop 摘要:stop_summary.py:46
@loong10k loong10k added the documentation Improvements or additions to documentation label Sep 22, 2026
@loong10k
loong10k merged commit 25d34d2 into main Sep 22, 2026
1 check passed
@loong10k
loong10k deleted the feat/host-protocol-cheatsheet-v0.6.3 branch September 22, 2026 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant