Skip to content

fix(hooks): emit AC7 diagnostic fields on block - #1208

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-1198-local-hook-unparseable-branch-mutation-i
Jun 27, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-1198-local-hook-unparseable-branch-mutation-i

Conversation

@squne121

@squne121 squne121 commented Jun 27, 2026 •

Copy link
Copy Markdown
Owner

Re-supplement PR1207 fallback issue1198.\nCloses #1198\n\nこのPRは、PR1207でリバートされたIssue1198要件の復旧とAC7診断の補強を行います。\n\n概要: PR1207後の差分を回収し、local_main_branch_guardのstderrブロック診断を復元しました。\n\n検証: 以下を実行済み。\n- uv run ruff check .claude/hooks/tests/test_local_main_branch_guard.py scripts/agent-guards/local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py\n- uv run python3 -m pytest tests/codex/test_local_main_branch_guard.py .claude/hooks/tests/test_local_main_branch_guard.py -q

@github-actions

github-actions Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1208 closed).

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "b1c32f11220b3fd73fe7cfd711aefc7c988abdad"
  merge_ready: true
  mergeability:
    mergeable: MERGEABLE
    merge_state_status: CLEAN
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "b1c32f11220b3fd73fe7cfd711aefc7c988abdad"
  merge_ready: true
  mergeability:
    mergeable: MERGEABLE
    merge_state_status: CLEAN
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "b1c32f11220b3fd73fe7cfd711aefc7c988abdad"
  merge_ready: true
  mergeability:
    mergeable: MERGEABLE
    merge_state_status: CLEAN
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []

@squne121
squne121 marked this pull request as ready for review June 27, 2026 07:33
@squne121

Copy link
Copy Markdown
Owner Author

判定: REQUEST_CHANGES

PR #1208 は、Issue #1198 / PR #1204 の未達だった AC7: hook block 時の stderr 診断項目 を補う差分です。PR は open / mergeable、head は b1c32f...、変更は 3 ファイル・+124/-27 です。
ただし、このまま Closes #1198 としてマージするのは危険です。特に gh api parser の allow bypass と stderr へ出す argv_redacted の赤裸々化 が残っています。

良い点

PR #1208 の方向性自体は正しいです。Claude Code hook は exit 2 のとき stdout JSON を無視し、stderr をモデルへ返す仕様なので、AC7 を evaluate() の JSON だけでなく実 hook stderr に載せる必要があります。([Claude Platform Docs]1)
今回の差分は run_hook() の block 経路から decision / event_kind / command_kind / parser_stage / rule_id / argv_redacted を _emit_block_stderr() に渡すようにしており、狙いは Issue #1198 の AC7 と一致します。

また、実スクリプト経由で git switch issue-1198-block を投げ、stderr に AC7 フィールドが含まれることを確認するテストが追加されています。これは PR #1204 で不足していた「実 hook stderr 経路」の穴を一定程度埋めています。

ブロッカー

B1. gh api --raw-field=... / --field=... / --input=... が exact GET allowlist をすり抜ける

_parse_gh_api_command() は -f, -F, --field, --input の 分離 token 形式 だけを block していますが、GitHub CLI の長形式 --raw-field=key=value, --field=key=value, --input=file.json を block していません。該当実装は token in {"-f", "-F", "--field", "--input"} だけで、startswith("--raw-field=") 等を見ていません。

これは仕様上まずいです。GitHub CLI は -f/--raw-field や -F/--field で request parameter を追加でき、parameter 追加時は通常 GET から POST に切り替わります。--input は request body file / stdin を使います。([GitHub CLI]2) ([GitHub CLI]2)

現状だと、少なくとも次のような fixture が不足しています。

gh api --raw-field=body=x repos/squne121/loop-protocol/issues/comments/4814545233
gh api --field=body=x repos/squne121/loop-protocol/issues/comments/4814545233
gh api --input=tmp/payload.json repos/squne121/loop-protocol/issues/comments/4814545233
rtk gh api --raw-field=body=x repos/squne121/loop-protocol/issues/comments/4814545233

Issue #1198 の方針は gh api の blanket allow ではなく exact GET issue-comment endpoint だけの allow です。現 fixture は --method PATCH と -f body='x' だけなので、長形式 bypass を捕まえられません。

修正要求: _parse_gh_api_command() で以下をすべて block してください。

MUTATION_PARAM_FLAGS = {
    "-f", "-F",
    "--raw-field", "--field",
    "--input",
}
MUTATION_PARAM_PREFIXES = (
    "--raw-field=",
    "--field=",
    "--input=",
)

加えて --method=GET があっても、exact endpoint 以外・parameter 付き・body input 付きは block に寄せるべきです。

B2. PR #1208 が stderr に argv_redacted を出すため、現 redaction の弱さが実害化している

今回の PR は argv_redacted を stderr に出します。Claude Code では exit 2 の stderr がモデルへ返るため、ここは redaction 境界です。([Claude Platform Docs]1)

しかし _redact_argv() は値付き flag の次 token を redaction する対象に -f, -F, --raw-field を含めていません。_redact_token() 側には -f / -F が入っていますが、次 token の body=secret はそのまま残り得ます。

例:

gh api repos/squne121/loop-protocol/issues/1198/comments -f body='token-like-value'

この command は block されますが、stderr の argv_redacted に body=token-like-value が残る可能性があります。リポジトリの hook boundary doc は no_raw_secret_like_value: true を契約しています。

修正要求: redaction 側も -f, -F, --raw-field, --field, --input と --raw-field=..., --field=..., --input=... を潰してください。最低限、次の stderr 回帰テストが必要です。

gh api repos/squne121/loop-protocol/issues/1198/comments -f body='SECRET_VALUE'
gh api --raw-field=body=SECRET_VALUE repos/squne121/loop-protocol/issues/comments/4814545233
gh api --input=tmp/payload.json repos/squne121/loop-protocol/issues/comments/4814545233

期待値は SECRET_VALUE と body/path 実値が stderr に出ないことです。

B3. PR #1207 が open のままだと、PR #1208 の前提を破壊する

PR #1208 は PR #1204 で入った classifier / telemetry 拡張を前提に、その stderr 経路を補っています。一方で PR #1207 は open / mergeable の revert PR で、本文上も「PR #1204 を revert」する内容です。
PR #1207 の patch は REASON_UNKNOWN_COMMAND, REASON_GH_API, COMMAND_KIND_*, redaction, gh api, rtk wrapper 等を削除する方向です。

修正要求: PR #1208 を採用するなら、PR #1207 は close / superseded 明記が必要です。両方を merge-ready として残すと、後続の自動 merge / 人間 merge で #1198 の復旧状態が壊れます。

非ブロッカーだが直したい点

_emit_block_stderr() は rule_id, command_kind, parser_stage を 1 行に詰めています。AC7 の「machine-readable fields」としては弱いです。
最大10行制約を守るなら、banner を短縮するか、1 行 JSON / NDJSON に寄せた方が後続 parser に強いです。

また、docs/dev/hook-boundaries.md の reason_code 一覧は github_api_command, rtk_help_command, rtk_proxy_requires_review, unknown_command_requires_review を反映していません。docs は hook 境界の正本と書かれているため、#1198 を close するなら更新対象です。

最小修正案

  1. _parse_gh_api_command() で --raw-field, --raw-field=, --field=, --input= を block。
  2. _redact_argv() で -f, -F, --raw-field, --field, --input の値を必ず <redacted> 化。
  3. issue1198-command-matrix.json に長形式 gh api / rtk gh api の block fixture を追加。
  4. 実 hook stderr テストで secret-like value が出ないことを検証。
  5. PR revert #1204: restore issue 1198 guard flow #1207 を superseded として close、または PR fix(hooks): emit AC7 diagnostic fields on block #1208 側に「revert #1204: restore issue 1198 guard flow #1207 は merge しない」旨を明記。
  6. docs/dev/hook-boundaries.md の reason_code / stderr diagnostic contract を更新。

結論

PR #1208 は AC7 の方向性としては必要です。しかし、stderr へ argv_redacted を露出する変更なのに redaction が足りない、かつ gh api の長形式 flag で exact GET allowlist をすり抜ける ため、現状は REQUEST_CHANGES が妥当です。CI が green でも、hook guardrail の設計上この2点はマージ前に潰すべきです。

@squne121

Copy link
Copy Markdown
Owner Author

実装反映 PR1208 を維持し、PR1207 は本件のrevertとして扱う運用を明確化しました。 PR1207 は close し、レビュー時は PR1208 が優先という扱いを確約します。

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "a643b93889e344d84f44ca566a2e6e97eae3fb09"
  merge_ready: true
  mergeability:
    mergeable: MERGEABLE
    merge_state_status: CLEAN
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []

@squne121
squne121 merged commit 6ddf94a into main Jun 27, 2026
22 checks passed
@squne121
squne121 deleted the worktree-issue-1198-local-hook-unparseable-branch-mutation-i branch June 27, 2026 08:19
@squne121

Copy link
Copy Markdown
Owner Author

post-merge cleanup test

@squne121

Copy link
Copy Markdown
Owner Author

post-merge-cleanup #1208 status: partial (unresolved_cleanup_items: pr_head_oid_mismatch). worktree branch worktree-issue-1198-local-hook-unparseable-branch-mutation-i(910e...) does not match PR1208 head a643...). resolved: 1207 is closed. issue #1198 remains open (PR #1212 open).

@squne121

Copy link
Copy Markdown
Owner Author

test

@squne121

Copy link
Copy Markdown
Owner Author

done

@squne121

Copy link
Copy Markdown
Owner Author

cleanup done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants