Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "runtime smoke の hook-chain evidence が handler-level if 条件付き hook を常時 fire する前提で期待件数に数えず、その tool call で発火し得る hook のみを window ごとの期待件数とし、条件評価が確定できない window は PASS にしない"
change_kind: workflow
dedupe_key: "runtime-smoke:hook-chain-evidence-if-conditional-expected-count:v1"Parent Issue
なし
Parent Goal Ref
- Goal:
--require-hook-chain-evidenceが current repository の.claude/settings.jsonに対して構造的に fail せず、実際に PASS し得る状態に戻す。 - Desired Destination: N/A(実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 は runner を Allowed Paths に持たないため、本 Issue が runner 側の是正のみを所有する)。
Current Validated Scope
2026-10-02 に origin/main 254a2205、現 repo の runner / tests / .claude/settings.json を直接読んで確認した(初回測定は 2026-10-01、Claude Code 2.1.286)。
scripts/agent-ops/run_worktree_agent_runtime_smoke.pyのevaluate_all_matching_hooks_observedは_load_command_hooks_for_event(settings, "PreToolUse", "Bash")が返す command hook の個数を、全 window 共通のexpected_countとする。loader はlist[str]を返し、hook["if"]を読まない。同 loader の consumer は他に Stop 側の side-effect 判定(_HOOK_CHAIN_SIDE_EFFECT_TARGET_BASENAME in command)が 1 件ある(同一 file 内)。- 現行
.claude/settings.jsonの PreToolUse で matcher が Bash を含む command hook は、無条件 4 件(secret_boundary_guard.sh・guard-japanese-prose.sh・ci_test_performance_advisory.sh・root_temporary_residue_advisory.sh)と、if: "Bash(herdr *)"付き 1 件(feat: Task Context に Task-aware cross-session messaging guard と cross-Task Herdr control guard を追加する #2691 由来)の計 5 件で、expected_count == 5。 - 非 herdr の Bash tool call では
ifにより herdr hook は発火せず、1 call あたりの非 observer hook は 4 件になる。_evaluate_hook_chain_windowはobserved_count 4 < expected_count 5でmissing_handler_evidence/failを返し、全 window が fail する。 - 既存 test
test_run_worktree_agent_runtime_smoke.pyの hook-chain 正常系はexpected_count == 4を前提とする固定 fixture を使い、if付き hook の fixture を持たない。 _claude_bash_tool_use_eventsはstream_indexとtool_use_idのみを返し、input.commandは意図的に読み捨てている。window 帰属は共有stream_index(同一 assistant message 内の複数 Bash call)と遅延hook_responseを扱う既存 semantics を持つ。- 外部仕様(Claude Code 公式 hooks reference、2026-10-02 fresh 確認): handler-level
ifは permission rule 構文で評価され、tool event(PreToolUse / PostToolUse / PostToolUseFailure / PermissionRequest / PermissionDenied)でのみ有効。Bash では先頭のVAR=valueが剥がされ、&&・パイプ・;・$()・backtick 内の各 subcommand が評価される。Bash command を解析できない場合は hook を pattern に関係なく実行する。Bash(ls *)はls -laに一致しlsofには一致しない(空白が word boundary)。素の command(引数なし)への一致は v2.1.72 でBash(x *)が裸のxにも一致するよう修正済み。process wrapper(timeout等)、path 付き command、quote された command 名の扱いは公式に記述がない。 - 所有権の境界: 実装: worktree-agent-runtime-smoke に generic hook-chain evidence capability を追加する #2663(CLOSED)は hook-chain evidence capability、実装: runtime_only VC の repository PreToolUse guard 互換性を Step 2 で早期検証する #2824(OPEN)は runtime_only VC の PreToolUse guard 互換性の早期検証、実装: Runtime Verification の assertion 単位 applicability を表現し、無関係な assertion の AC binding が readiness 通過のための空 evidence になる false-required を防ぐ #2852(OPEN)は assertion 単位 applicability、feat: Task Context に Task-aware cross-session messaging guard と cross-Task Herdr control guard を追加する #2691 / 実装: Task ContextにTask-aware cross-session messaging guardとcross-Task Herdr control guardを追加する #2566 は
if: Bash(herdr *)条件付き hook の導入を所有する。本 Issue は期待件数算出におけるif条件の扱いと、その runtime 証明のみを所有し、これらと重複しない。PR 実装: Claude-GPT model/proxy runtime migration の3分類ルーティングを追加する #2831 / 実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 の AC10 再実行は本 Issue 完了後に 実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 側で行う。
Remaining Parent Gaps
- 実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 AC10 の contract 側の扱い(残る classifier / fixture 問題を含む)は 実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 で行う。本 Issue 完了後に 実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 が再検証できる状態になる。
if条件の完全な permission rule 文法・Bash parser の再実装は行わない(下記 In Scope の判定規則に限定し、判定できないものは unverified とする)。
Outcome
scripts/agent-ops/run_worktree_agent_runtime_smoke.py の hook-chain evidence の期待件数が window ごとに算出され、if 条件付き hook は「その window の Bash tool call の command で発火するか」を match / nonmatch / unknown の 3 値で判定して扱われる。現 repo 設定の非 herdr command window は expected 4 / observed 4 で window status: pass となり、unknown の window は件数が偶然一致しても pass にならない。これを focused test と、current HEAD に対する実 runtime 確認 1 件で示す。観測件数 >= 期待件数のような緩和、解釈不能な if を期待件数へ足す処理、if / hook / permission 設定の変更で帳尻を合わせることはしない。
Runtime Verification Applicability
runtime_verification_applicability:
decision: immediate
reason: "成果物が live Claude structured runtime の hook-chain evidence 判定であり、synthetic stream の test だけでは current settings に対する実 window の判定結果を代替できない。"
applicable_acs: [AC4, AC5]
verification_profile: hook-chain-runtime-smoke
runtime_assertion_bindings:
- profile: subagent-lifecycle-causal-evidence-smoke
assertion: subagent_start_stop_causal_evidence_correlated
ac: AC4
execution_environment: "linked worktree、既存 worktree-agent-runtime-smoke の canonical live invocation(native Claude structured lane、--require-hook-chain-evidence)。"
skip_conditions: "Claude CLI 又は required isolated runtime が利用不能なら stdout を SKIP: で開始し exit 77 とする。SKIP は runtime PASS ではない。"
fallback_policy: "prompt self-report、marker text、raw transcript、--help 出力、synthetic stream を runtime PASS の代替にしない。"
binding_note: "runner file が subagent-lifecycle profile の hard selector に一致するための structural binding。本 Issue は SubAgent lifecycle の causal evidence 処理を変更しない(変更が必要になれば Stop Condition)。非退行は AC3 の既存 test 全件で担保し、binding 先 AC の意味的十分性は semantic review の責務とする。"
artifact_requirements: "--evidence-json の bounded summary のうち tested_head、hook_chain_evidence.all_matching_hooks_observed の status / expected_count / observed_count / windows[] の status・expected_count・observed_count、runner の exit code のみをレビューする。raw prompt / transcript、credential、HOME absolute path、hook command / output body、Bash command 本文を保存又は引用しない。"In Scope
scripts/agent-ops/run_worktree_agent_runtime_smoke.py_load_command_hooks_for_eventの内部返却表現を、hook ごとのcommandとif条件を保持する形へ変更してよい(詳細 record を返す内部 helper と、従来のlist[str]を返す wrapper に分けてもよい)。同一 file 内の既存 consumer(Stop side-effect 判定を含む)は同一 PR で追随修正し、既存挙動を維持する。これは repo 内 helper の内部表現変更であり、新しい外部 schema / protocol の変更ではない。- Bash tool_use の
input.commandをtool_use_idと束縛して取得し、memory 内だけで条件判定に使う。command 本文は summary / evidence / error 文言のいずれにも出力しない。input.commandの欠落・非 string は空 command として扱わずunknownとする。 - handler-level
ifの判定を次の 3 値とする。match: 当該 hook をその window の expected set に含める。nonmatch: 不一致を確実に判定できた場合だけ、その window の expected set から除外する。unknown: expected count を確定値として扱わず、その window をstatus: unverified(固定 reason、例:if_condition_unverifiable)としpassにしない。解釈不能なifを「念のため」expected_count に足す処理は禁止する(count-only 照合では別 source の hook と偶然一致して false-green になるため)。
- 判定規則は current settings に存在する形式
Bash(<単語> *)と、単純な単一 command に限定する。ifがBash(<単語> *)以外の形式、ifが string でない、tool_name が Bash でない場合はunknown。command は、先頭のVAR=value代入を剥がした後、(a) 先頭 token が<単語>と完全一致するならmatch(引数なしの裸の command を含む)、(b) シェル制御文字(&|;<>()`$\改行{})・quote を含まず、先頭 token が単純な bare word で、かつ wrapper 類(timeouttimenicenohupstdbufxargsenvcommandexecsudoshbashzshevalを最低限含む固定の小集合)でも<単語>と一致もしない場合に限りnonmatch、それ以外(複合 command・command substitution・quote・path 付き・wrapper 付き等)はunknownとする。 ifを持たない hook の扱い、unmatched / extra / unverified / deny、observer self-echo、global hook_id pairing、window 帰属(同一 message 内の複数 Bash call、共有stream_index、遅延 response)の既存 semantics は変更しない。- 出力 contract:
windows[i].expected_countを正本とする。window ごとに expected が異なり得るため、トップレベルexpected_countは全 window の値が同一のときだけその値、異なる場合はNone(既存の nullable 表現を再利用。新しい key は追加しない)とし、既存 consumer への影響を確認して追随する。
scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py- synthetic stream による focused regression test を追加する(AC1〜AC3 参照)。既存の
expected_count == 4前提 fixture は、現 settings 相当(if付き hook を含む)の fixture と整合させて修正してよい。
- synthetic stream による focused regression test を追加する(AC1〜AC3 参照)。既存の
Out of Scope
- approval carrier・permission 設定・
secret_boundary_guard.shの変更。 .claude/settings.jsonの hook 構成・if条件の変更。- 完全な Bash parser / permission rule interpreter、新しい security framework、approval layer、handler identity 基盤、新しい schema family / receipt。
- 観測件数 >= 期待件数のような判定緩和。
- 実装: runtime_only VC の repository PreToolUse guard 互換性を Step 2 で早期検証する #2824 / 実装: Runtime Verification の assertion 単位 applicability を表現し、無関係な assertion の AC binding が readiness 通過のための空 evidence になる false-required を防ぐ #2852 / 実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 の所有範囲(実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 の runtime migration を本 Issue の検証 fixture に持ち込まない)。
- Claude Code の version upgrade を本修正の前提条件にすること。
Acceptance Criteria
- AC1:
if付き hook が現 settings 相当に存在する状態で、if条件にnonmatchと確定できる単純な command(例:echo smoke)の window はstatus: passとなり、windows[i].expected_countは発火し得る hook 数(現 settings 相当では herdr hook を除く 4)、observed と一致する。条件付き hook の evidence が無いこと自体は fail 要因にならない。 - AC2:
if条件にmatchする command(例:herdr list、引数なしのherdr、X=1 herdr x)の window は当該 hook を期待件数に含み(5)、その hook の evidence が欠落した場合はstatus: fail(missing_handler_evidence)、全件揃えばpassになる。同一 assistant message 内にnonmatch/matchの Bash call が混在する場合、tool_use_idごとにそれぞれ 4 / 5 で評価され、順序や遅延hook_responseで混同しない。トップレベルexpected_countは window 間で値が異なるときNoneとなる。 - AC3:
unknown(ifが未対応形式、input.commandの欠落・非 string・複合 command・command substitution・quote・path 付き・wrapper 付き、Bash tool が対象でない等)の window は、観測件数がどの expected 候補と偶然一致してもpassにならずunverifiedとなる。既存の unmatched / extra / unverified / deny / orphan 判定、Stop side-effect 判定(target handler 設定済みならtarget_handler_not_configuredにならないこと)、ifなし hook の件数は退行しない。Bash command 本文が summary / evidence / error 文言に含まれない(sentinel 文字列を command に含めた test で固定)。 - AC4: current HEAD を commit した linked worktree に対する既存 canonical live invocation で
--require-hook-chain-evidenceを実行し、runner が exit 0 で終了し、--evidence-json上でhook_chain_evidence.statusとhook_chain_evidence.all_matching_hooks_observed.statusがpass(runner 全体・aggregate の判定。positive と deny の両 window とsibling_side_effect_inventory_completeの pass を要する)であること。runtime が利用不能ならSKIP:+ exit 77 とし、PASS と扱わない。 - AC5: AC4 の同一 evidence の
all_matching_hooks_observed.windows[](AC4 とは別の window 単体の判定)について、positive・deny 両 scenario を含む 2 件以上の window が全てstatus: passかつexpected_count == observed_count == 4(current settings の非 herdr command では条件付き hook が除外される)であること。tested_headは VC 実行時のgit rev-parse HEADと一致すること。window の pass を runner 全体の PASS と呼ばず、AC4 の runner exit code・aggregate status とは別々に PR 証跡へ記録する。
Verification Commands
# AC1
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py::test_hook_chain_if_nonmatch_window_passes_with_four_expected -q
# AC2
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py::test_hook_chain_if_match_window_requires_conditional_hook_evidence -q
# AC3
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py::test_hook_chain_if_unknown_window_is_unverified -q
# AC3
$ uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py -q
# AC4
# preflight-scope: runtime_only
$ uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py --runtime claude --mode structured --worktree "$PWD" --prompt-file artifacts/runtime-smoke/2865-hook-chain-prompt.md --output-dir artifacts/runtime-smoke/2865-hook-chain-current-head --evidence-json artifacts/runtime-smoke/2865-hook-chain-evidence.json --timeout-seconds 180 --max-turns 4 --require-clean-postcondition --require-hook-chain-evidence
# AC5
# preflight-scope: runtime_only
$ jq -e --arg head "$(git rev-parse HEAD)" '.tested_head == $head and .hook_chain_evidence.all_matching_hooks_observed.windows as $w | ($w | length) >= 2 and all($w[]; .status == "pass" and .expected_count == 4 and .observed_count == 4)' artifacts/runtime-smoke/2865-hook-chain-evidence.jsonAC1〜AC3 の focused test は既存 test file に top-level 関数として追加し、名前は VC の node-id と一致させる(test_hook_chain_if_nonmatch_window_passes_with_four_expected: AC1 と非一致 window 内の混在 call、test_hook_chain_if_match_window_requires_conditional_hook_evidence: AC2 の欠落 fail・全件 pass・混在 message・トップレベル expected_count、test_hook_chain_if_unknown_window_is_unverified: AC3 の unknown 全種・既存判定の非退行・Stop consumer・command 本文の非漏洩)。baseline では未作成のため exit 非 0 となることを # baseline-expect: fail で明示する。追加 test は旧実装に対して「期待 5・観測 4」の失敗として落ちることを確認する(collect 不能や環境エラーを狙った baseline failure と扱わない)。
AC4 / AC5 の prompt file artifacts/runtime-smoke/2865-hook-chain-prompt.md は gitignore 配下の untracked file として、実装者が runtime 実行前に作成する。内容は positive scenario(例: echo smoke)と deny scenario(secret_boundary_guard.sh が deny する printenv)の 2 つの単純な単一 Bash command を別々の tool_use として指示するものとし、複合 command・quote・wrapper は使わない(unknown 化を避けるため)。AC4 / AC5 は post-implementation の runtime 確認であり、baseline では実行しない(runtime_only)。AC5 は AC4 の runner が書いた evidence JSON を読むため AC4 の後に実行する。runner の exit code・aggregate status・window status は PR 証跡に別々に記録する。
Allowed Paths
scripts/agent-ops/run_worktree_agent_runtime_smoke.pyscripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
.claude/settings.jsonや hook 側の変更なしには解決できないと判明した場合- 外部に公開される schema / protocol(
WORKTREE_AGENT_RUNTIME_SMOKE_RESULT_V1の既存 key 集合を含む)の変更が必要になった場合
補足(停止条件の解釈、operator 承認済み): 上記 2 項目目の「固定契約(キー集合・スキーマ・型定義)」は外部に公開される契約を指し、In Scope に記載した runner 内部 helper(_load_command_hooks_for_event 等)の返却表現変更・同一 file 内 consumer の追随・expected_count の既存 nullable 表現の再利用は含まない。5 項目目の「nested SubAgent delegation」は、canonical root が必要な first-level SubAgent を起動することを禁止せず、それ以上の孫 Agent 起動が必要になる場合を指す。
Required Skills
なし
Required Design References
scripts/agent-ops/run_worktree_agent_runtime_smoke.pyscripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py.claude/settings.json.claude/skills/worktree-agent-runtime-smoke/SKILL.md(canonical live invocation)docs/dev/runtime-verification-policy.md- https://code.claude.com/docs/en/hooks(handler-level
ifと Bash permission rule の評価) - Issue 実装: worktree-agent-runtime-smoke に generic hook-chain evidence capability を追加する #2663 / feat: Task Context に Task-aware cross-session messaging guard と cross-Task Herdr control guard を追加する #2691 / 実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 / 実装: runtime_only VC の repository PreToolUse guard 互換性を Step 2 で早期検証する #2824 / 実装: Runtime Verification の assertion 単位 applicability を表現し、無関係な assertion の AC binding が readiness 通過のための空 evidence になる false-required を防ぐ #2852(related ownership boundary)
Scope Delta
- source: OWNER REQUEST_CHANGES anchor review, https://github.com/squne121/loop-protocol/issues/2865#issuecomment-5941902874(operator-selected human context、確認時点 main
254a22055bb93163c567e1c799f90689f92fc25b)。 - validated_scope_delta: AC4 の
--helpを実 hook-chain runtime 検証へ置換、if判定を match / nonmatch / unknown の 3 値化、unknown は expected_count へ足さず unverified、loader 内部表現変更と同一 file consumer 追随を In Scope 化、tool_use_idと束縛した memory-only の command 取得、windows[i].expected_countを正本化、focused regression test と evidence hygiene を AC 化した。Allowed Paths は変更しない。
Delivery Rule
1 Issue = 1 PR、専用 worktree で作業し、Draft PR を既定とする。- AC4 の runtime 確認は
docs/dev/runtime-verification-policy.mdの SKIP 規約・証跡保存に従い、commit 済み current HEAD に対して行う。
Activity
squne121 commentedon Oct 1, 2026
判定:REQUEST_CHANGES — 修正方針は正しいですが、Issue の検証契約に穴があります
#2865 は進める価値があります。ただし、「条件付き hook を数えないようにする」だけの実装では、別の誤判定に置き換わる可能性があります。 特に直すべきなのは、AC4 の実行不能な検証定義、Bash 条件照合の意味、解釈不能な条件の扱いの3点です。新しいセキュリティ基盤や承認レイヤーではなく、この Issue 内の小さな契約修正と既存 runner の局所修正を勧めます。
確認対象は、取得時の main
0a90b505f8368e7e8483ed27932fc7f7bbc6d99c、Issue #2865、関連 #2663・#2810・#2824・#2852、PR #2691、PR #2831 のコメント、runner・settings・tests・runtime 検証ポリシーです。#2865 自体には取得時点でコメントがありませんでした。今回の判定は Issue 契約と既存実装に対するレビューです。まず、原因の切り分けは支持します
現行 loader は Bash に該当する
type: commandhook のcommandを集めますが、ifは読みません。一方、現 settings には無条件の4件とif: "Bash(herdr *)"の1件があります。このため、非 herdr 呼び出しでも期待数が5になってしまう、という指摘はコードと整合します。ifを settings から削除して帳尻を合わせるべきではありません。 PR #2691 は、通常の Bash 呼び出しのたびに不要な Python interpreter が起動する問題を直すため、この native filter を導入しています。その性能改善を維持し、観測側の期待数を修正するのが適切です。1. P1:AC4 の
--helpは、この不具合が直った証拠になりません該当箇所:Issue #2865 の AC4/Verification Commands。
AC4 は実 runtime の window が PASS することを要求していますが、記載されたコマンドは次だけです。
これは hook-chain 検証の実行ではなく、
--require-hook-chain-evidenceも指定していません。したがって、この VC の成功を AC4 の成功として採用できません。runtime_onlyの注記を付けても、検証内容の不足は解決しません。さらに、window 単体の PASS、
all_matching_hooks_observedの PASS、runner の hook-chain 全体の PASS は別物です。現実装では、各 window が PASS でも positive window と deny window の両方がなければ
all_matching_hooks_observedは FAIL になります。その上位のhook_chain_evidenceは、sibling_side_effect_inventory_completeも PASS の場合だけ PASS になります。最小修正
AC4 の VC を、既存
worktree-agent-runtime-smokeの実行経路へ置き換え、対象 prompt・linked worktree・出力先・確認する assertion を具体化してください。その際、次のように受け入れ対象を分けるのがよいです。既存の positive/deny smoke を利用できるなら、それを1回使うのが最も簡単です。#2810 の runtime migration 全体を #2865 の検証 fixture に持ち込む必要はありません。 既存 skill には hook-chain 用の canonical live invocation が用意されています。
併せて、AC4 に既存ポリシーが要求する
<!-- runtime-verification: true -->を付けるべきです。これは新しい gate の追加ではなく、すでに宣言したdecision: immediateと AC の整合修正です。2. P1:
Bash(<prefix> *)に限定しても、単純な文字列 prefix 判定では不正確です該当箇所:In Scope の「current settings に存在する形式に限定」。
この限定は、実装範囲を小さくする方向としてはよいです。しかし、条件文字列の文法が単純であることと、対象 Bash command の解釈が単純であることは別です。
Claude Code の公式 hooks reference は、Bash の
ifについて、先頭の環境変数代入を除去し、複合コマンドの各 subcommand と command substitution 内を確認すると説明しています。また、Bash command を解析できない場合は hook を実行する挙動です。Claude Codeしたがって、公式仕様を
Bash(herdr *)に当てはめると、少なくとも次はcommand.startswith("herdr ")では扱えません。以下は仕様から導いた反例であり、この環境での実CLI測定結果ではありません。手動で期待数を変えたケースは修正実装ではなく、分岐を確認するための対照実験です。 リポジトリ全体の pytest と実 Claude runtime smoke は実行していません。この実行環境には
claudeCLI がなく、実 hook の配信順序やバージョン固有挙動まで検証したとは主張しません。review_probes.py / review_probe_results.txt
推奨する進め方
まず #2865 本文を、「実際に動く AC4」「3値の条件判定」「unknown を件数一致で PASS にしない」「既存 consumer と window 帰属の維持」に絞って補正し、そのまま runner と tests の2ファイル中心で実装することを勧めます。
settings の条件付き hook、既存 guard、permission 設定は変更せず、完全な Bash interpreter・handler identity 基盤・新しい承認 gate は追加しない。通常の回帰確認は deterministic test で行い、実 runtime は対象 HEAD に対する必要な確認に限定する。これが、今回の「正しく動くのにハーネスが失敗させる」問題を、開発の手間を増やさずに解消する方向です。
GitHub への投稿・Issue 本文変更は行っていません。
## 判定:REQUEST_CHANGES — 修正方針は正しいですが、Issue の検証契約に穴があります#2865 は進める価値があります。ただし、「条件付き hook を数えないようにする」だけの実装では、別の誤判定に置き換わる可能性があります。 特に直すべきなのは、AC4 の実行不能な検証定義、Bash 条件照合の意味、解釈不能な条件の扱いの3点です。新しいセキュリティ基盤や承認レイヤーではなく、この Issue 内の小さな契約修正と既存 runner の局所修正を勧めます。
確認対象は、取得時の main
0a90b505f8368e7e8483ed27932fc7f7bbc6d99c、Issue #2865、関連 #2663・#2810・#2824・#2852、PR #2691、PR #2831 のコメント、runner・settings・tests・runtime 検証ポリシーです。#2865 自体には取得時点でコメントがありませんでした。今回の判定は Issue 契約と既存実装に対するレビューです。まず、原因の切り分けは支持します
現行 loader は Bash に該当する
type: commandhook のcommandを集めますが、ifは読みません。一方、現 settings には無条件の4件とif: "Bash(herdr *)"の1件があります。このため、非 herdr 呼び出しでも期待数が5になってしまう、という指摘はコードと整合します。ifを settings から削除して帳尻を合わせるべきではありません。 PR #2691 は、通常の Bash 呼び出しのたびに不要な Python interpreter が起動する問題を直すため、この native filter を導入しています。その性能改善を維持し、観測側の期待数を修正するのが適切です。1. P1:AC4 の
--helpは、この不具合が直った証拠になりません該当箇所:Issue #2865 の AC4/Verification Commands。
AC4 は実 runtime の window が PASS することを要求していますが、記載されたコマンドは次だけです。
これは hook-chain 検証の実行ではなく、
--require-hook-chain-evidenceも指定していません。したがって、この VC の成功を AC4 の成功として採用できません。runtime_onlyの注記を付けても、検証内容の不足は解決しません。さらに、window 単体の PASS、
all_matching_hooks_observedの PASS、runner の hook-chain 全体の PASS は別物です。現実装では、各 window が PASS でも positive window と deny window の両方がなければ
all_matching_hooks_observedは FAIL になります。その上位のhook_chain_evidenceは、sibling_side_effect_inventory_completeも PASS の場合だけ PASS になります。最小修正
AC4 の VC を、既存
worktree-agent-runtime-smokeの実行経路へ置き換え、対象 prompt・linked worktree・出力先・確認する assertion を具体化してください。その際、次のように受け入れ対象を分けるのがよいです。既存の positive/deny smoke を利用できるなら、それを1回使うのが最も簡単です。#2810 の runtime migration 全体を #2865 の検証 fixture に持ち込む必要はありません。 既存 skill には hook-chain 用の canonical live invocation が用意されています。
併せて、AC4 に既存ポリシーが要求する
<!-- runtime-verification: true -->を付けるべきです。これは新しい gate の追加ではなく、すでに宣言したdecision: immediateと AC の整合修正です。2. P1:
Bash(<prefix> *)に限定しても、単純な文字列 prefix 判定では不正確です該当箇所:In Scope の「current settings に存在する形式に限定」。
この限定は、実装範囲を小さくする方向としてはよいです。しかし、条件文字列の文法が単純であることと、対象 Bash command の解釈が単純であることは別です。
Claude Code の公式 hooks reference は、Bash の
ifについて、先頭の環境変数代入を除去し、複合コマンドの各 subcommand と command substitution 内を確認すると説明しています。また、Bash command を解析できない場合は hook を実行する挙動です。Claude Codeしたがって、公式仕様を
Bash(herdr *)に当てはめると、少なくとも次はcommand.startswith("herdr ")では扱えません。以下は仕様から導いた反例であり、この環境での実CLI測定結果ではありません。X=1 herdr --versionprintf ready && herdr --versionprintf '%s\n' "$(herdr --version)"この取りこぼしは、単に厳しすぎる判定になるだけではありません。条件付き hook を誤って除外すると、実行されている場合は「余分な hook」となり、逆にその実行証拠が欠けた場合には少ない期待数と一致して window が誤PASS になり得ます。現 evaluator は観測数と期待数の比較でこの分岐を決めています。
最小修正
完全な permission rule interpreter や Bash parser は作らず、内部判定を次の3値にしてください。
日常的な単純コマンドを確実に処理し、複雑な入力を処理できない場合は
nonmatchと断定しない、という設計です。よく出る複合形をどこまで処理するかは小さく決められます。「未対応の構文まで全部実装する」ではなく、「未対応を不一致として黙って扱わない」が必要条件です。3. P1:「解釈不能なら期待数に含める」は、
unverifiedと同等の保守的処理ではありません該当箇所:In Scope の「期待件数に含める、または unverified とする」。
ここは選択肢を残さず、
unverifiedに統一することを推奨します。現 evaluator は、observer を除いた完了済みペアの件数が期待数と一致すれば PASS にします。
hook_idによる対応付けは開始と応答が同じ invocation であることを示すもので、settings に列挙された特定 handler の識別ではない、とコード自身が明記しています。例えば、次の構成が反例になります。
ここで未対応の条件付き hook を「保守的に」期待数へ足すと、次の差が生まれます。
期待数を多くすれば必ず安全側になるわけではありません。 この count-only 判定では、上限を正確な期待数として使うことで、追加 hook が条件付き hook の分を埋めてしまいます。
この分岐は、現行関数を転記した局所プローブでも再現しました。ただし、これは合成済みの hook ペアに対する判定実験であり、実CLI上で追加 hook を発火させた実験ではありません。
最小修正
解釈不能な
if、または条件評価に必要な command が不明な場合は、その window を PASS に昇格させないことを契約にしてください。raw command を保存する必要はなく、理由は短い固定値で足ります。なお、ここから handler identity を完全に証明する新基盤へ話を広げる必要はありません。今回必要なのは、既存の観測限界の下で、解釈不能な期待数を確定値として扱わないことです。
4. P2:loader の返却型変更には、すでに具体的な影響先があります
該当箇所:
_load_command_hooks_for_eventの変更指示。Issue は loader に
ifを保持させるよう求めていますが、現関数の返却値はlist[str]であり、PreToolUse の件数計算以外にも使われています。Stop の side-effect 判定には、次の consumer があります。例えば返却値を
{"command": ..., "if": ...}へ変えてここを放置すると、文字列内の basename 検索ではなく辞書キーの検索になります。その結果、設定済みの coordinator を「未設定」と判定する可能性があります。これは現在すでに発生している不具合ではなく、Issue が指定する変更に伴う、実在 consumer の回帰リスクです。
最小修正
loader の返却型を変えるなら同じファイル内の consumer を一緒に直し、Stop の既存判定が維持されるテストを追加してください。あるいは、詳細な hook record を返す内部 helper と、従来の command 文字列を返す wrapper を分けても構いません。
この程度の内部表現変更を、Issue の「型定義変更が必要なら停止」という一般文言で止めないよう、本変更に必要な内部型・同一ファイル内 consumer の追随は In Scope と明記するのが適切です。新しい外部 schema を作る話ではありません。
5. P2:command の取得・window への結び付け・件数の表示契約が不足しています
該当箇所:window ごとの期待数計算と証跡要件。
現
_claude_bash_tool_use_events()が返すのは、stream_indexとtool_use_idだけです。command は意図的に読み捨てています。また、現在の window 分割には、同じ assistant message 内の複数 Bash 呼び出しと、遅れて届く hook responseを扱う処理があります。ここを実装者の推測に任せると、代表的には次の間違いが入り得ます。
input.commandが欠落した際に空文字へ置き換え、条件不一致として除外する。stream_indexの複数呼び出しに、同じ command を適用する。最小修正
構造化された tool-use の
input.commandを、対応するtool_use_idとともにメモリ内でだけ条件判定へ渡す、と明記してください。欠落・型不正は「空の有効な command」ではなく不明です。既存の開始/応答ペアリングと window 帰属処理は維持します。また、非一致 window が4件、一致 window が5件になると、従来のトップレベル
expected_count一つでは全 window の期待数を表せません。各windows[i].expected_countを正本とし、トップレベル値の意味を明示する必要があります。 現在は一つの値を全 window とトップレベルへ流しています。新しい schema family は不要です。例えば値が混在する場合に既存の nullable 表現を使う案など、既存 consumer への影響を確認して小さく決めれば足ります。
必要なテストは、広い suite を増やすより「この失敗を固定する」ものです
AC1 は既存の
-k hook_chain実行にbaseline-expect: failを付けています。しかし、現行 tests には従来の期待数4を前提とするテストがあり、取得したテスト本文ではBash(herdrの条件付き fixture を確認できませんでした。この既存コマンドが baseline で狙いどおり失敗することは、今回実行確認できていません。追加する回帰テストは、次の程度に絞れます。これは提案するテスト集合であり、既存テストの実行結果ではありません。
if、または command 欠落・型不正ifなし、orphan、extra、deny、Stop consumerbaseline の赤を確認するなら、追加した条件付き hook の回帰テストを旧実装に適用し、「期待5・観測4」の問題で失敗することを確かめるのが直接的です。テスト未検出や別の環境エラーを、狙った baseline failure と扱わないことが重要です。
外部仕様・配布物の調査からの補足
Claude Code の更新だけで直る問題ではありません
公式リポジトリの CHANGELOG では、取得時の先頭は 2.1.287 でした。この版には、transcript の「N hooks ran」と verbose debug log の件数へ内部 callback が混ざっていた問題の修正が載っています。
ただし、これは 表示・debug の件数修正であり、今回の Python loader が
ifを無視している事実を解消する根拠にはなりません。runtime 証跡には実際に使った Claude Code version を記録すべきですが、アップグレードをこの局所修正の前提条件にする必要はありません。#2865 の修正は、PR #2831 の AC10 完了と同義ではありません
2026年10月1日23:47 JST の PR #2831 checkpoint は、件数不整合とは別に、AC10 の
pre-repair-checkが Auto classifier に拒否される問題を報告しています。AC9 は同 checkpoint で PASS とされ、deny probe の文脈が影響している可能性が記されていますが、後者は報告者による推定です。したがって、責務は次のように分けるのが適切です。
#2865 は期待数計算とその証明を直す。#2810/PR #2831 は修正取り込み後に AC10 を再実行し、残る classifier/fixture 問題を扱う。
#2824 は runtime-only VC と repository guard の早期互換性検査、#2852 は assertion の applicability 表現を所有しており、どちらも今回の条件付き hook 数修正を待たせる理由にはなりません。
今回、実際に再現した範囲
現行 main から loader と window evaluator の実行文を転記し、secret-free な合成入力で局所プローブを実行しました。
fail / missing_handler_evidencepassunverified / unattributable_extra_hook_executionpassfail手動で期待数を変えたケースは修正実装ではなく、分岐を確認するための対照実験です。 リポジトリ全体の pytest と実 Claude runtime smoke は実行していません。この実行環境には
claudeCLI がなく、実 hook の配信順序やバージョン固有挙動まで検証したとは主張しません。review_probes.py局所再現プローブ / review_probe_results.txt実行結果
推奨する進め方
まず #2865 本文を、「実際に動く AC4」「3値の条件判定」「unknown を件数一致で PASS にしない」「既存 consumer と window 帰属の維持」に絞って補正し、そのまま runner と tests の2ファイル中心で実装することを勧めます。
settings の条件付き hook、既存 guard、permission 設定は変更せず、完全な Bash interpreter・handler identity 基盤・新しい承認 gate は追加しない。通常の回帰確認は deterministic test で行い、実 runtime は対象 HEAD に対する必要な確認に限定する。これが、今回の「正しく動くのにハーネスが失敗させる」問題を、開発の手間を増やさずに解消する方向です。
GitHub への投稿・Issue 本文変更は行っていません。
squne121 commentedon Oct 1, 2026
推奨は、指定コメントを operator-selected human context anchor として #2865 を in-place refinement することです。現在の
mainは254a22055bb93163c567e1c799f90689f92fc25bまで進んでおり、レビューコメントが確認した0a90b505...より新しいため、Claude Code 側では必ず live state を再取得させるべきです。現時点では #2865 は OPEN、指定コメントは OWNER 投稿、#2865 を直接実装する PR は検索上見つかっていません。技術方針としてもコメントの主要指摘を採用するのが妥当です。現在の Claude Code 公式 hooks reference は、Bash の
ifが leadingVAR=valueを除去し、各 subcommand や$()/ backticks 内も評価し、コマンドを判定できない場合は hook を実行すると明記しています。したがって単純 prefix 判定ではなく、少なくともmatch / nonmatch / unknownを区別し、unknownをnonmatchとして除外しない契約が適切です。[Claude Code](https://code.claude.com/docs/en/hooks)また、添付ログで使っている「SubAgent を dispatch しただけでは完了扱いせず、final structured result と terminal completion の両方を確認する」という completion barrier もそのまま維持します。貼り付けたテキスト(1)
以下を fresh の対話的 Claude Code にそのまま貼り付けてください。
repo は
squne121/loop-protocol。対象 Issue:
#2865
trusted human-context anchor として扱う対象コメント:
#2865 (comment)
使用する current Agent Skill:
.claude/skills/issue-refinement-loop/SKILL.mdこの interactive Claude Code session は fresh かつ既に Auto mode で起動済みである。現在の session をそのまま利用し、permission mode を変更しないこと。
bypassPermissions、--dangerously-skip-permissions、permission bypass、user-wide persistent allow、~/.claude/settings.jsonの変更は使用・要求しない。目的は、指定 OWNER review comment を operator-selected human context として current
issue-refinement-loopに投入し、#2865 の Issue contract を current repository / current Claude Code 仕様と整合する状態まで人間承認なしで refinement することである。この invocation は Issue refinement のみを依頼している。refinement が approved になってもimpl-review-loop、implementation-worker による production implementation、実装用 PR 作成へ自動的に進んではならない。この prompt による明示的な operator decision / 承認
指定コメント
#issuecomment-5941902874をoperator_asserted_human_contextとして扱い、canonicalwith_human_contextlane で snapshot / target binding / trusted-principal checks を行った上で 実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865 の refinement authority として使用することを明示的に承認する。各 refinement iteration ごとの追加承認は不要である。コメントの REQUEST_CHANGES を fresh repository evidence と current upstream official documentation で fact-check した上で、支持される指摘を 実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865 本文へ in-place で吸収することを承認する。単なるコメント要約ではなく、Acceptance Criteria、Verification Commands、In Scope、Runtime Verification Applicability、Stop Conditions 等を相互整合する contract にすること。
AC4 の現行
run_worktree_agent_runtime_smoke.py --helpは runtime verification の証拠にならないため、current repository に実在する canonical hook-chain runtime smoke / equivalent live invocation を調査し、実際に--require-hook-chain-evidenceの対象 window を検証する executable VC へ置換することを承認する。対象 prompt、worktree、output/evidence、current-head binding、どの assertion を PASS とするかを曖昧にしないこと。AC4 には current runtime-verification policy が要求する marker / metadata を適切に反映すること。window 単体の verdict、
all_matching_hooks_observedaggregate、上位hook_chain_evidence、runner process の exit/result を区別すること。AC4 が window 単体の条件付き-hook expected-count correctness を証明するなら、それを runner 全体の PASS と誤記しない。必要な aggregate 条件は別途明記すること。Bash handler-level
ifの条件判定は単純なcommand.startswith(...)と同一視しないこと。current Claude Code official hooks / permission-rule semantics を fresh Web research で確認し、少なくとも次の意味を contract に反映すること:match= 当該 hook を expected set に含める。nonmatch= 不一致を確実に判定できた場合だけ expected set から除外する。unknown= expected count を確定値として扱わず、その window を PASS に昇格させない。unsupported / ambiguous Bash syntax を黙って
nonmatchにしてはならない。解釈不能な
ifを「念のため expected_count に含める」ことで済ませる案は採用しない。現 evaluator は count-only identity limitation を持つため、過大な expected count が別ソース hook と偶然一致して false-green を作り得る。unknown は明示的unverified相当として扱う contract に統一してよい。_load_command_hooks_for_eventの内部返却型または内部 representation を変更し、同じ Allowed Path 内の既存 consumer を追随修正することを この refinement の In Scope として承認する。特に Stop side-effect detection 等の既存 consumer を壊さないこと。これは repository 内 helper の内部型変更であり、新しい外部 schema / protocol family の変更とはみなさない。この内部変更だけを理由に Stop Condition の「型定義変更」と判定して人間へ戻さないこと。Bash tool-use の
input.commandが条件評価に必要なら、対応するtool_use_idと束縛して memory-only evidence として利用する方向を承認する。command 欠落・型不正を空 command としてnonmatchにしてはならない。同一 assistant message 内の複数 Bash calls、shared stream index、遅延 hook response 等、current window attribution / global hook-id pairing の既存 semantics を壊さないこと。window ごとに expected hook count が異なり得る場合、
windows[i].expected_countを正本とする等、意味が一意になるよう既存 output contract を最小限明確化することを承認する。トップレベルexpected_countが単一値では表現不能になるなら、current consumer を調査して既存 nullable / summary 表現を再利用するなど最小変更にする。新しい schema family、receipt、handler-identity framework は作らない。focused regression tests は少なくとも failure class を直接固定すること。current settings 相当の non-herdr command、matching herdr command、matching hook evidence 欠落、全 evidence 有り、同一 message 内の matching/nonmatching 複数 Bash calls、unknown/unsupported
if、command 欠落/型不正、既存 orphan/extra/deny/Stop consumer の非退行、および raw Bash command が persisted summary/evidence へ漏れないことを current code/design に合わせて検討する。単に広い suite が green であることを今回の defect の証明にしない。.claude/settings.json、既存 conditional hook、secret_boundary_guard.sh、permission configuration を変更して帳尻を合わせることは承認しない。完全な Bash parser / permission-rule interpreter、新しい security framework、新しい approval layer、新しい handler identity 基盤も追加しない。個人趣味開発として、この defect に必要な局所 contract / runner 修正だけを優先する。指定コメント内の外部仕様 claim は stale knowledge で確定せず、current Claude Code official documentation / upstream source を web-researcher lane で fresh 確認すること。特に handler-level
if、Bash permission rule matching、leading environment assignment、compound subcommands、command substitutions、解析不能時の挙動を確認する。external research は repository contract の authority を上書きするためではなく、Bash matching semantics の事実確認に使う。current state の扱い
この prompt 作成時点で取得した
mainは254a22055bb93163c567e1c799f90689f92fc25bだが、これは参考値にすぎない。最初にgit fetch/ live GitHub / current main を fresh 取得し、この SHA を authority として固定しないこと。#2865 は現在 OPEN。related ownership として少なくとも #2663(closed)、#2810(open)、#2824(open)、#2852(open)、merged PR #2691、open PR #2831 が存在する。これらの current state、最新 comments、current main の relevant code/tests/settings/docs を fresh 確認し、scope ownership を再評価すること。
#2865 を直接実装する既存 PR / branch / worktree が現在存在するかも fresh 検索する。ただし今回は refinement-only なので、見つかったとしても production implementation を開始せず、Issue contract の事実確認材料としてのみ扱う。
issue-refinement-loop の実行
最初に current main の以下を読むこと:
.claude/skills/issue-refinement-loop/SKILL.md必要に応じて
references/anchor-comment-handling.md、references/semantic-design-review.md、references/follow-up-materialization.md、references/termination-policy.md、current planner/router/checker。Skill の procedure を過去知識から推測しないこと。
指定コメント URL は current canonical
with_human_contextlane を使う。コメント URL だけから human origin を推測するのではなく、この prompt 自身が operator-selected human context であることを authority とする。current canonical preflight / planner / contract-update / editor route を使用し、raw
gh issue editによる shortcut はしない。planner、scope-delta authority、deterministic checker、routing の判断を prose で再実装しない。Step 1 の
codebase-investigatorを使用して、comment の repository claims を current main で fact-checkする。外部 Claude Code semantics が判断に影響するため、current planner の canonical web-research route を通じてweb-researcherを利用し、公式一次資料を優先する。canonical Step 2 が current Skill で root-owned pipeline なら、その契約に従い legacy
issue-reviewerSubAgent を無理に起動しない。semantic design review が applicable なら currentissue-design-reviewerlane を使用する。Issue rewrite が必要なら currentissue-editor/ controlled transaction route を使用する。SubAgent を dispatch した場合は、final structured result と terminal completion の両方を必ず取得するまで待つこと。
background dispatch の成功通知だけ、
pending/ partial handback、terminal status だけ、final text だけのいずれも completion とみなさない。completion join barrier を満たす前に downstream step へ進まない。子 SubAgent に task を渡す際は、対象 Issue/anchor URL、authority、current evidence refs、read-only/mutation boundary、期待出力を明示し、親 thread の暗黙 context に依存させない。Issue body の Stop Condition にある「nested SubAgent delegation」は、canonical root から必要な first-level SubAgent を使うことを禁止する意味にはしない。ただし child が current contract 外でさらに孫 Agent を起動する必要があるなら canonical policy に従い fail-closed / escalation 判定する。
refinement 方針
指定 OWNER review comment の各 finding を個別に disposition し、support / superseded / inaccurate を current evidence 付きで判断する。最低限、AC4 executable VC、3値 Bash-if 判定、unknown→unverified、loader consumer regression、tool_use_id と command の束縛、per-window expected count semantics、focused regression test、evidence hygiene を検討する。
review comment をそのまま Issue 本文へ転載しない。current repo 事実と external facts を検証し、Issue contract として短く・検証可能・実装可能な文言へ正規化する。
Outcome、In Scope、Out of Scope、Runtime Verification Applicability、AC、VC、Allowed Paths、Stop Conditions、Required Design References の間に矛盾を残さない。VC は AC を実際に検証できる executable command でなければならない。placeholder-only /--help/ self-report を runtime PASS としない。current Allowed Paths の runner と focused test の2ファイルで実装可能な contract を優先する。レビュー指摘を吸収するために同じ runner file 内の helper/consumer 内部変更が必要でも、それだけで Allowed Paths expansion としない。
iteration / approval
current Skill の既定 max iteration と routing を使用する。
needs-fix/request_changesが current loop 上限未満なら追加の人間承認を求めず自動 rewrite → fresh review を継続する。deterministic review finding、semantic review finding、readiness failure、stale body readback 等が修正可能なら current scope 内で修正し、fresh body SHA に対して再検証する。旧 review / old body SHA / old main evidence を使い回さない。
この prompt が具体的に判断済みの上記 contract changesについて
human_judgment_requiredとして再承認を求めない。current repository authority が別の新しい boundary を検出した場合のみ停止候補とする。recurrence / follow-up issue
refinement 中に、今回の #2865 の defect と別の distinct・再現可能・再発し得る failure class を発見した場合は、まず current open/closed Issues を dedupe key、mechanism、related code、owner Issue で fresh 検索する。
#2663 / #2810 / #2824 / #2852 / #2691 等に既存 ownership がある問題は新規 Issue にしない。今回の anchor comment の各 P1/P2 finding は原則 #2865 の contract refinement 自体で扱い、新規 Issue に逃がさない。
genuinely distinct で既存 ownership が無いものだけ、current
follow-up-materialization/ repository-nativecreate-issueworkflow を使って GitHub Issue に起票する。rawgh issue createの shortcut は使わない。generic hardening、新しい schema/framework/approval layer を「再発防止」という理由だけで起票しない。起票した場合は #2865 と双方向に trace できる related context / dedupe key / reproduction class / why-not-owned-by-existing-issue を明記する。
停止境界
通常の refinement finding、deterministic repair、semantic review finding、stale snapshot、fact-check mismatch、Issue body rewrite の必要性は停止理由にしない。
停止候補は、secret/credential の取得・変更・公開、sudo / privilege escalation、destructive operation、permission/policy bypass、current repository contract が要求する新しい
human_judgment_requiredでこの prompt が具体的に判断していない論点、irreconcilable scope conflict、authority 外の別アーキテクチャ層への変更が不可避、evidence integrity を維持不能、canonical loop 上限到達、live OWNER/operator の明示停止に限定する。今回の refinement に必要な
_load_command_hooks_for_event内部 representation と同一 runner file consumer の追随を「型変更」という文言だけで停止理由にしてはならない。外部 schema / protocol change が必要になった場合とは区別すること。terminal condition
以下を満たすまで issue-refinement-loop を進めること。
#2865 の live Issue body が指定 anchor の支持された REQUEST_CHANGES を吸収済みであること。
current-main repository evidence と current upstream official documentation に整合していること。
AC と VC が対応し、特に AC4 が real runtime verification として executable であること。
unknown Bash-if semantics が false-green を許さないこと。
既存 hook/window/Stop consumer の非退行が contract に固定されていること。
deterministic Step 2 review が approved / proceed 相当であること。
semantic review が applicable な場合、その actionable findings が解消済みであること。
fresh readiness / body SHA binding が成立していること。
follow-up materialization / recurrence dedupe が完了していること。
current issue-refinement-loop の approved termination / handoff publication が必要なら canonical publisher 経由で完了していること。
ここまで到達したら正常終了する。
この invocation では implementation を開始しない。
production code を変更しない。
実装用 branch / PR を新規作成しない。
impl-review-loop を自動開始しない。
merge / auto-merge を行わない。
最終報告には、final Issue body SHA、吸収した anchor findings、棄却/修正した finding があれば理由、fresh deterministic review、semantic review の有無と結果、external official docs verification の結論、remaining blockers、follow-up/recurrent Issue の有無と URL、
issue-refinement-loop approved相当まで到達したか、そしてimplementation not startedを簡潔に含めること。この prompt は、レビューコメントの指摘を丸ごと盲目的に採用するのではなく、current main と公式仕様で再検証したうえで、#2865 の契約に必要な部分だけを吸収する形にしています。
squne121 commentedon Oct 1, 2026
issue-refinement-loop 終了報告: approved(実装は未開始)
OWNER の REQUEST_CHANGES(operator が human context として指定した anchor、https://github.com/squne121/loop-protocol/issues/2865#issuecomment-5941902874)を current main
254a22055bb93163c567e1c799f90689f92fc25bの repository 証拠と Claude Code 公式ドキュメントで fact-check し、支持された指摘を Issue 本文へ吸収した。承認済み body の SHA-256 は411e6c44c791ee20d7af8c29db3af0694fae85b60bb58a6fcbc184b9ab31f66b。--helpを実 hook-chain runtime 検証へ置換し、runner 全体(AC4)と window 単体(AC5)を分離した。if判定を match / nonmatch / unknown の 3 値にし、unknown は expected_count へ足さず unverified とした。loader の内部表現変更と同一 file consumer の追随を In Scope 化した。tool_use_idと束縛した memory-only の command 取得、windows[i].expected_countの正本化、focused regression test、evidence hygiene を AC に反映した。herdrは公式の v2.1.72 修正に従い match とした。ifは permission rule 構文、先頭VAR=valueの除去、複合 command と command substitution の各部分の評価、解析不能時は hook 実行(fail-open)を公式 hooks reference で確認した。wrapper・path・quote の扱いは公式に記述がなく、unknown 扱いで確定した。VCP_VC_NO_TESTS_COLLECTED2 件)で needs-fix となり、node-id 形式へ修正後の fresh review で approve / proceed(SHA411e6c44…に束縛)。semantic_review_trigger.pyがsemantic_review_applicable: falseを返したため実施していない。status: go、同一 SHA に束縛。approvedは実装開始の承認ではない。squne121 commentedon Oct 1, 2026
推奨アクションは、fresh live state → current-run contract review → 同一 root transition から
impl-review-loop→ 実装・独立検証・PR review/fix → current-head CI/mergeability 確認 → merge 判断直前で停止です。過去の refinementapprovedコメントだけを実装開始 authority にはせず、現行 Skill の root-owned synchronous transition を通す構成にしています。以下を、すでに Auto mode で起動している現在の対話的 Claude Code にそのまま貼り付けてください。
repo=
squne121/loop-protocol対象は implementation Issue #2865。
この interactive Claude Code session は既に Auto mode で起動済みである。現在の session と permission mode をそのまま継続すること。
bypassPermissions、--dangerously-skip-permissions、permission bypass、user-wide persistent allow、~/.claude/settings.jsonの変更は要求・使用しない。目的は、current repository の canonical Agent Skill
.claude/skills/impl-review-loop/SKILL.mdを使い、Issue #2865 を 実装 → 検証 → PR review → 必要な修正 → 再検証 → fresh-head review の loop で進め、人間が merge 判断できる直前の canonical terminal state まで自律的に完遂することである。単なる調査・計画・提案で終了せず、contract が実行可能なら実際に implementation workflow を開始し、必要な repository / GitHub mutation を行うこと。
Source of Truth と開始時 fresh check
過去の chat、古い SHA、過去の refinement report を current state の代用にしない。
開始時に必ず current state を fresh に取得すること。
main.claude/skills/impl-review-loop/SKILL.mdと、その Skill が参照する currentsteps/**.claude/skills/implement-issue/SKILL.md.claude/skills/pr-review-judge/SKILL.md.claude/agents/implementation-worker.md、.claude/agents/test-runner.md、.claude/agents/pr-reviewer.md等、実際に今回使う custom SubAgent 定義scripts/agent-ops/run_worktree_agent_runtime_smoke.pyscripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py.claude/settings.json.claude/skills/worktree-agent-runtime-smoke/SKILL.mddocs/dev/runtime-verification-policy.md過去の
LOOP_HANDOFF_RESULT_V1: refinement_approvedは historical evidence として参照してよいが、それ単独を Step 1 authorization にしない。current
impl-review-loopが要求する Root-Owned Synchronous Entry Transition を遵守すること。すなわち root/main thread が一続きの control flow で capability preflight → live Issue fetch → current-runissue-contract-review→ 直後の live再取得 → routing →invoke_impl_review_loopが成立した場合のみ Step 1 を起動すること。過去 review 以降に main が進んでいるため、古い base SHA を current authority とみなさないこと。
operator による明示的承認
この prompt により、以下を iteration ごとの追加の人間承認なしで実施することを明示的に承認する。
Closes #2865等の repository-native metadata 整備これらについて私への逐次確認を求めないこと。
ただし、この承認は Allowed Paths や Issue contract を勝手に拡張する承認ではない。
#2865 の実装境界
live Issue body を正本とするが、現契約上の production change は次の Allowed Paths に限定されている。
scripts/agent-ops/run_worktree_agent_runtime_smoke.pyscripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py.claude/settings.jsonや hook configuration を変更して expected count を帳尻合わせしてはならない。完全な Bash parser、permission-rule interpreter、新しい schema family、receipt、handler identity framework、新しい approval/security frameworkを作らない。
個人趣味開発として、今回の具体的 defect を解決しない security/harness hardening を追加して workflow を重くしないこと。
実装方針は live Issue の refinement 済み contract を維持し、handler-level
ifを少なくとも次の3値で扱うこと。match: この window の expected set に含めるnonmatch: 不一致を確実に証明できた場合だけ expected set から除外unknown: PASS にせずunverified相当unsupported / ambiguous syntax を都合よく
nonmatchにして false-green を作らない。逆に unknown hook を単純に expected count へ足して count-only coincidence により false-green を作る実装にも戻さない。
input.commandを必要とする場合はtool_use_idと正しく束縛し、memory-only evaluation に使用する。raw Bash command を persisted summary / evidence / error message に漏らさない。既存の unmatched / extra / deny / orphan / observer self-echo / global hook-id pairing / delayed hook response / shared stream index / Stop side-effect semantics を壊さない。
upstream 仕様
実装判断に current Claude Code の handler-level
ifsemantics が実質的に影響する場合は、current official Claude Code hooks reference を fresh に確認すること。ただし #2865 の refined contract がすでに十分具体的で、追加調査が実装結果を変えないなら無駄な外部調査は増やさなくてよい。current
impl-review-loopの external-research routing を正本とする。単純 prefix matcher を公式 semantics 全体の再実装だとみなして scope を広げない。Issue が intentionally conservative に
unknownとしている wrapper / path / quote / compound 等はその契約を守る。SubAgent を必ず使用する
root/main thread は control-plane として振る舞い、current
impl-review-loopの canonical delegation を使用する。少なくとも canonical flow が要求する以下を first-level SubAgent として使うこと。
implementation-workertest-runnerpr-reviewerIssue #2865 の Stop Conditions に従い、root → first-level SubAgent は許可されるが、child → grandchild の nested SubAgent delegation は行わない。必要になった場合は current contract の hard stop として扱う。
SubAgent には親会話の暗黙 context に依存させず、実値を materialize して渡すこと。最低限:
current、LOOP_STATE、placeholder のような未展開値を child prompt に残さない。SubAgent completion barrier — dispatch だけで完了扱い禁止
すべての canonical child dispatch について current
Common Completion Protocolを厳守すること。spawn_agentの戻り値から canonicaltask_nameを保存する。wait_agentは mailbox activity 待ちにしか使用しない。timeout、途中 update、steer response は成功ではない。list_agentsで、その canonical task が terminalcompletedであることを確認する。completedの両方が揃うまで downstream step に進まない。errored/interrupted/shutdown/not_foundは成功として扱わない。特に Step 2 の test-runner は、final read-only report と terminal completion の両方を確認してから Step 4 を開始すること。
実装 → 検証 → review loop
current Skill の canonical flowをそのまま実行する。
Step 1 — Implementation
pre-Step-1 landing disposition を必ず確認する。
旧実装で failure class が再現可能なら、Issue contract に沿う baseline evidence を取得してから修正する。
Issue ACを満たす最小で明確な implementation を行う。
Step 2 — Verification
test-runner を独立した read-only verifier として使う。
live Issue の literal Verification Commands と current PR head を binding し、省略・改変した代替コマンドで PASS を主張しない。
#2865 の AC1〜AC3 の focused tests と full target test file を実行する。
AC4 / AC5 は
runtime_onlyであり、post-implementation の commit 済み current HEAD に対して canonical live invocation を実行する。runtime prompt は live Issue の契約どおり、positive と deny の単純な別 Bash tool_use を使い、unknown 化する compound/quote/wrapper 等を混ぜない。
AC4 では runner exit code、
hook_chain_evidence.status、all_matching_hooks_observed.statusを独立して確認する。AC5 では同じ evidence の windows を確認し、window-level PASS と runner-level PASS を混同しない。
SKIP:+ exit 77 は runtime PASS ではない。raw prompt/transcript、credentials、HOME absolute path、hook command/output body、Bash command body を PR evidence に保存・引用しない。
Step 4 — PR Review
current-head verification binding が成立した場合のみ pr-reviewer を起動する。
required CI は current Skill の head-scoped canonical route で確認する。
reviewer には live Issue AC、Allowed Paths、actual diff、current head、verification evidence を渡す。
PR reviewer の
APPROVE自己申告だけで終了しない。currentroute_loop_verdict_v2()と live mergeability を正本にする。REQUEST_CHANGES / stale / CI failures
通常の修正可能 failure は人間への確認理由にしない。
fix_deltaにして Step 1 へ戻るcurrent Skill の iteration budget を守ること。勝手に無限ループしない。
GitHub PR
1 Issue = 1 PRを維持する。既存対応 PR が無ければ repository-native workflow で Draft PR を作る。
PR には Issue #2865 との closing relation を canonical な形で持たせる。
PR body には、少なくとも:
Closes #2865を current repository convention に合わせて記載する。
ただし sensitive/runtime raw data を貼らない。
current Skill が PR の actual Draft/Ready 状態について定める semantics に従い、勝手な独自ルールを追加しない。
再発防止 Issue
実装・テスト・review の過程で 同じ failure class が別 producer/consumer、別 runtime path、別 fixture、別 evaluator でも再発し得る構造的原因を発見した場合は、最終報告だけで済ませない。
まず GitHub で open/closed Issue を検索し、特に #2663 / #2810 / #2824 / #2852 / #2691 その他 current related Issue と重複しないか確認する。
すでに同一 root cause / prevention scope を所有する Issue がある場合:
未所有の recurrent defect であれば、新しい GitHub Issue を起票することをここで明示的に承認する。追加の人間確認は不要。
follow-up Issue には最低限:
Refs #2865を入れる。
この follow-up Issue 作成承認は、#2865 の Allowed Paths を拡張する承認ではない。follow-up の implementation を今回の #2865 PR に混ぜない。
なお、#2865 自身の AC を満たすために Allowed Paths 外の production change が不可避と判明した場合は、勝手に越境実装せず current contract の hard stop として正確に報告すること。
承認しない操作 / 停止境界
以下はこの prompt では承認しない。
.claude/settings.json/ hook configuration の帳尻合わせ変更不可逆操作、secret boundary、実 Git conflict、irreconcilable contract/scope conflict、canonical iteration 上限、current repository policy が明示する
human_judgment_requiredに到達した場合のみ停止候補とする。単なる warning、stale evidence、通常の test/CI failure、修正可能 REQUEST_CHANGES は停止理由にしない。
完了条件
以下を満たすまで「完了」としない。
impl-review-loopが定める terminal result に到達最終地点は 人間が merge 判断する直前。
merge、auto-merge、post-merge cleanup、不可逆 cleanup は実行しない。
最後に簡潔に次を報告すること。
今すぐ開始し、調査だけで終了しないこと。
この prompt では、#2865 の「新規 Issue が必要なら停止」という条件を無制限に解除せず、今回の修正範囲を広げない再発防止 follow-up の起票だけを明示承認しています。これなら再発防止 Issue を作りつつ、Allowed Paths 越境を正当化する抜け道にはなりません。
squne121 commentedon Oct 1, 2026
root-owned entry router audit
route: invoke_impl_review_loop
reason: fresh_review_go_live_equality
fix: hook if 条件評価で Bash の語区切り以外の空白を含む command を unknown にする (#2865)
fix: hook-chain evidence の期待件数を handler-level if 条件で window ごとに算出する (#…