Skip to content

実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865

Closed

Description

@squne121

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

Current Validated Scope

2026-10-02 に origin/main 254a2205、現 repo の runner / tests / .claude/settings.json を直接読んで確認した(初回測定は 2026-10-01、Claude Code 2.1.286)。

Remaining Parent Gaps

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 類(timeout time nice nohup stdbuf xargs env command exec sudo sh bash zsh eval を最低限含む固定の小集合)でも <単語> と一致もしない場合に限り 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 と整合させて修正してよい。

Out of Scope

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

AC1〜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.py
  • scripts/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

Scope Delta

Delivery Rule

  • 1 Issue = 1 PR、専用 worktree で作業し、Draft PR を既定とする。
  • AC4 の runtime 確認は docs/dev/runtime-verification-policy.md の SKIP 規約・証跡保存に従い、commit 済み current HEAD に対して行う。

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Oct 1, 2026
  2. squne121 commented on Oct 1, 2026

    @squne121
    OwnerAuthor

    判定: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: command hook の 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 することを要求していますが、記載されたコマンドは次だけです。

    uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py --help

    これは 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 を具体化してください。その際、次のように受け入れ対象を分けるのがよいです。

    AC4 は、current settings の非一致 command に対応する window について、条件付き hook が除外され、正しい expected_count と observed_count で PASS することを証明する。runner の exit code と上位 aggregate は別途記録し、window の PASS を runner 全体の PASS と呼ばない。

    既存の 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測定結果ではありません。

    Bash 入力 | 単純な先頭一致が見落とす点 -- | -- X=1 herdr --version | コマンド名の前に代入がある printf ready && herdr --version | 2つ目の subcommand が一致する printf '%s\n' "$(herdr --version)" | command substitution 内で一致する

    手動で期待数を変えたケースは修正実装ではなく、分岐を確認するための対照実験です。 リポジトリ全体の pytest と実 Claude runtime smoke は実行していません。この実行環境には claude CLI がなく、実 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: command hook の 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 することを要求していますが、記載されたコマンドは次だけです。

    uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py --help

    これは 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 を具体化してください。その際、次のように受け入れ対象を分けるのがよいです。

    AC4 は、current settings の非一致 command に対応する window について、条件付き hook が除外され、正しい expected_count と observed_count で PASS することを証明する。runner の exit code と上位 aggregate は別途記録し、window の PASS を runner 全体の PASS と呼ばない。

    既存の 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測定結果ではありません。

    Bash 入力 単純な先頭一致が見落とす点
    X=1 herdr --version コマンド名の前に代入がある
    printf ready && herdr --version 2つ目の subcommand が一致する
    printf '%s\n' "$(herdr --version)" command substitution 内で一致する

    この取りこぼしは、単に厳しすぎる判定になるだけではありません。条件付き hook を誤って除外すると、実行されている場合は「余分な hook」となり、逆にその実行証拠が欠けた場合には少ない期待数と一致して window が誤PASS になり得ます。現 evaluator は観測数と期待数の比較でこの分岐を決めています。

    最小修正

    完全な permission rule interpreter や Bash parser は作らず、内部判定を次の3値にしてください。

    match      → 期待数に含める
    nonmatch   → 不一致を確定できた場合だけ除外する
    unknown    → その window の条件評価を unverified とする
    

    日常的な単純コマンドを確実に処理し、複雑な入力を処理できない場合は nonmatch と断定しない、という設計です。よく出る複合形をどこまで処理するかは小さく決められます。「未対応の構文まで全部実装する」ではなく、「未対応を不一致として黙って扱わない」が必要条件です。


    3. P1:「解釈不能なら期待数に含める」は、unverified と同等の保守的処理ではありません

    該当箇所:In Scope の「期待件数に含める、または unverified とする」。

    ここは選択肢を残さず、unverified に統一することを推奨します。

    現 evaluator は、observer を除いた完了済みペアの件数が期待数と一致すれば PASS にします。hook_id による対応付けは開始と応答が同じ invocation であることを示すもので、settings に列挙された特定 handler の識別ではない、とコード自身が明記しています。

    例えば、次の構成が反例になります。

    無条件の project hook                        4件
    条件付き project hook                       1件
      if: Bash(git status)
      今回の限定 evaluator では未対応
    実行する command: printf smoke
    
    実際に動く project hook                     4件
    別ソースの、対応付け済み追加 hook             1件
    

    ここで未対応の条件付き hook を「保守的に」期待数へ足すと、次の差が生まれます。

    正確な期待数 4、観測数 5 → unverified(追加 hook を識別できない)
    上限としての期待数 5、観測数 5 → pass
    

    期待数を多くすれば必ず安全側になるわけではありません。 この 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 があります。

    stop_commands = _load_command_hooks_for_event(
        settings, _HOOK_CHAIN_SIDE_EFFECT_EVENT, None
    )
    target_configured = any(
        _HOOK_CHAIN_SIDE_EFFECT_TARGET_BASENAME in command
        for command in stop_commands
    )

    例えば返却値を {"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 を適用する。
    • 最初の window で求めた期待数を後続 window に使い回す。

    最小修正

    構造化された 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 で狙いどおり失敗することは、今回実行確認できていません。

    追加する回帰テストは、次の程度に絞れます。これは提案するテスト集合であり、既存テストの実行結果ではありません。

    テスト 固定すべき結果
    現 settings 相当、単純な非 herdr command 条件付き hook を除外し、4/4 で window PASS
    herdr command、条件付き hook の証拠が欠落 期待数5のまま FAIL
    herdr command、全件の証拠あり 5/5 で window PASS
    同じ message 内に非一致/一致の2呼び出し それぞれ4/5。順序や遅延応答で混同しない
    未対応 if、または command 欠落・型不正 観測数がたまたま一致しても PASS にしない
    if なし、orphan、extra、deny、Stop consumer 既存の判定を維持
    command に保存禁止を検出する sentinel を含める 永続化される summary/evidence に漏れない

    baseline の赤を確認するなら、追加した条件付き 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 な合成入力で局所プローブを実行しました。

    ケース 再現結果
    現構成相当の loader 期待数5
    観測4・期待5 fail / missing_handler_evidence
    期待数だけを手動で4へ補正 window pass
    観測5・正確な期待4 unverified / unattributable_extra_hook_execution
    観測5・上限を期待5として使用 window pass
    positive window だけが1件 現 aggregate 式では fail

    手動で期待数を変えたケースは修正実装ではなく、分岐を確認するための対照実験です。 リポジトリ全体の pytest と実 Claude runtime smoke は実行していません。この実行環境には claude CLI がなく、実 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 本文変更は行っていません。

  3. squne121 commented on Oct 1, 2026

    @squne121
    OwnerAuthor

    推奨は、指定コメントを 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 が leading VAR=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 / 承認

    1. 指定コメント #issuecomment-5941902874 を operator_asserted_human_context として扱い、canonical with_human_context lane で snapshot / target binding / trusted-principal checks を行った上で 実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865 の refinement authority として使用することを明示的に承認する。各 refinement iteration ごとの追加承認は不要である。

    2. コメントの 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 にすること。

    3. 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 を適切に反映すること。

    4. window 単体の verdict、all_matching_hooks_observed aggregate、上位 hook_chain_evidence、runner process の exit/result を区別すること。AC4 が window 単体の条件付き-hook expected-count correctness を証明するなら、それを runner 全体の PASS と誤記しない。必要な aggregate 条件は別途明記すること。

    5. 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 にしてはならない。

    6. 解釈不能な if を「念のため expected_count に含める」ことで済ませる案は採用しない。現 evaluator は count-only identity limitation を持つため、過大な expected count が別ソース hook と偶然一致して false-green を作り得る。unknown は明示的 unverified 相当として扱う contract に統一してよい。

    7. _load_command_hooks_for_event の内部返却型または内部 representation を変更し、同じ Allowed Path 内の既存 consumer を追随修正することを この refinement の In Scope として承認する。特に Stop side-effect detection 等の既存 consumer を壊さないこと。これは repository 内 helper の内部型変更であり、新しい外部 schema / protocol family の変更とはみなさない。この内部変更だけを理由に Stop Condition の「型定義変更」と判定して人間へ戻さないこと。

    8. 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 を壊さないこと。

    9. window ごとに expected hook count が異なり得る場合、windows[i].expected_count を正本とする等、意味が一意になるよう既存 output contract を最小限明確化することを承認する。トップレベル expected_count が単一値では表現不能になるなら、current consumer を調査して既存 nullable / summary 表現を再利用するなど最小変更にする。新しい schema family、receipt、handler-identity framework は作らない。

    10. 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 の証明にしない。

    11. .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 修正だけを優先する。

    12. 指定コメント内の外部仕様 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_context lane を使う。コメント 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-reviewer SubAgent を無理に起動しない。semantic design review が applicable なら current issue-design-reviewer lane を使用する。Issue rewrite が必要なら current issue-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-native create-issue workflow を使って GitHub Issue に起票する。raw gh 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 の契約に必要な部分だけを吸収する形にしています。

  4. squne121 commented on Oct 1, 2026

    @squne121
    OwnerAuthor

    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。

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: issue-refinement-loop
      follow_up_issues: []
      note_only_observations: []
    LOOP_HANDOFF_RESULT_V1:
      status: refinement_approved
      routing_action: none
      contract_review:
        status: go
        gate_result: fresh_go
        latest_comment_url: "https://github.com/squne121/loop-protocol/issues/2865"
        generated_at: "2026-10-01T23:05:00Z"
        body_sha256: "sha256:411e6c44c791ee20d7af8c29db3af0694fae85b60bb58a6fcbc184b9ab31f66b"
      metadata:
        title_prefix_ready: true
      label_sync_observation:
        kind: presentation_sync
        result: noop
        detail: "label は変更していない"
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: "2026-10-01T23:05:00Z"
      checked_body_sha256: "sha256:411e6c44c791ee20d7af8c29db3af0694fae85b60bb58a6fcbc184b9ab31f66b"
      checker_exit_code: 0
      missing_sections: []
      missing_contract_keys: []
  5. squne121 commented on Oct 1, 2026

    @squne121
    OwnerAuthor

    推奨アクションは、fresh live state → current-run contract review → 同一 root transition から impl-review-loop → 実装・独立検証・PR review/fix → current-head CI/mergeability 確認 → merge 判断直前で停止です。過去の refinement approved コメントだけを実装開始 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 に取得すること。

    1. current main
    2. live Issue 実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865 の title / body / comments / state
    3. 実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865 に紐づく既存 branch / worktree / open・draft・closed PR
    4. current .claude/skills/impl-review-loop/SKILL.md と、その Skill が参照する current steps/**
    5. current .claude/skills/implement-issue/SKILL.md
    6. current .claude/skills/pr-review-judge/SKILL.md
    7. current .claude/agents/implementation-worker.md、.claude/agents/test-runner.md、.claude/agents/pr-reviewer.md 等、実際に今回使う custom SubAgent 定義
    8. Issue 実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865 の Required Design References:
      • scripts/agent-ops/run_worktree_agent_runtime_smoke.py
      • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py
      • .claude/settings.json
      • .claude/skills/worktree-agent-runtime-smoke/SKILL.md
      • docs/dev/runtime-verification-policy.md
      • 必要な repository SSOT
    9. related ownership boundary として 実装: 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 および current related PR/Issue state

    過去の 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-run issue-contract-review → 直後の live再取得 → routing → invoke_impl_review_loop が成立した場合のみ Step 1 を起動すること。

    過去 review 以降に main が進んでいるため、古い base SHA を current authority とみなさないこと。

    operator による明示的承認

    この prompt により、以下を iteration ごとの追加の人間承認なしで実施することを明示的に承認する。

    • current repository / GitHub state の read-only 調査
    • current contract review / intake / landing-disposition の実行
    • canonical linked worktree の作成・再利用
    • 実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865 専用 branch の作成・再利用
    • Issue が許可する Allowed Paths 内の source/test 編集
    • focused test、関連 test suite、lint/static checks、Issue に記載された literal Verification Commands の実行
    • gitignored runtime evidence / prompt artifact の作成
    • Issue AC4/AC5 が要求する live runtime smoke の実行
    • commit の作成
    • non-destructive な branch update
    • feature branch の通常 push
    • Draft PR の作成、または既存対応 PR の再利用・更新
    • PR body / Closes #2865 等の repository-native metadata 整備
    • current Skill が要求する PR comment / verdict evidence の投稿
    • required CI の確認・通常の retry
    • REQUEST_CHANGES に対する bounded な修正
    • stale HEAD の fresh review
    • BEHIND の場合の current Skill に従った update-branch 処理
    • review/fix 後の再 test・再 runtime verification
    • recurrence candidate の重複 Issue 検索
    • 下記条件を満たす再発防止 follow-up Issue の新規起票

    これらについて私への逐次確認を求めないこと。

    ただし、この承認は Allowed Paths や Issue contract を勝手に拡張する承認ではない。

    #2865 の実装境界

    live Issue body を正本とするが、現契約上の production change は次の Allowed Paths に限定されている。

    • scripts/agent-ops/run_worktree_agent_runtime_smoke.py
    • scripts/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 if semantics が実質的に影響する場合は、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 として使うこと。

    • Step 1: implementation-worker
    • Step 2: test-runner
    • Step 4: pr-reviewer

    Issue #2865 の Stop Conditions に従い、root → first-level SubAgent は許可されるが、child → grandchild の nested SubAgent delegation は行わない。必要になった場合は current contract の hard stop として扱う。

    SubAgent には親会話の暗黙 context に依存させず、実値を materialize して渡すこと。最低限:

    • task/objective
    • actual Issue / PR number
    • current head SHA
    • authority / current live contract
    • Allowed Paths
    • AC / literal Verification Commands
    • fix_delta
    • relevant evidence
    • expected structured output

    current、LOOP_STATE、placeholder のような未展開値を child prompt に残さない。

    SubAgent completion barrier — dispatch だけで完了扱い禁止

    すべての canonical child dispatch について current Common Completion Protocol を厳守すること。

    1. spawn_agent の戻り値から canonical task_name を保存する。
    2. wait_agent は mailbox activity 待ちにしか使用しない。timeout、途中 update、steer response は成功ではない。
    3. 対象 task の final result を実際に取得・消費する。
    4. その後 list_agents で、その canonical task が terminal completed であることを確認する。
    5. final result と terminal completed の両方が揃うまで downstream step に進まない。
    6. errored / interrupted / shutdown / not_found は成功として扱わない。
    7. child が開始された、mailbox が返った、部分 report が返った、という事実だけで Step 完了と宣言しない。

    特に 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 自己申告だけで終了しない。current route_loop_verdict_v2() と live mergeability を正本にする。

    REQUEST_CHANGES / stale / CI failures

    通常の修正可能 failure は人間への確認理由にしない。

    • REQUEST_CHANGES → blockers を fix_delta にして Step 1 へ戻る
    • stale reviewed head → fresh head で re-review
    • BEHIND → canonical update-branch action → verification / review 再実行
    • ordinary test failure → root cause 修正 → rerun
    • deterministic CI failure → log を確認し scope 内なら修正 → rerun
    • transient CI failure → repository policy 内で bounded retry
    • review 後に head が変化 → stale evidence を破棄し fresh verification/review

    current Skill の iteration budget を守ること。勝手に無限ループしない。

    GitHub PR

    1 Issue = 1 PR を維持する。

    既存対応 PR が無ければ repository-native workflow で Draft PR を作る。

    PR には Issue #2865 との closing relation を canonical な形で持たせる。

    PR body には、少なくとも:

    • problem/root cause
    • implementation summary
    • AC/VC evidence
    • AC4 runner/aggregate evidence
    • AC5 window evidence
    • test/CI status
    • relevant limitations
    • 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 がある場合:

    • duplicate Issue は作らない。
    • relevant evidence と既存 Issue を final report で示す。
    • 必要かつ repository workflow 上適切なら既存 Issue へ bounded な evidence/comment を追加してよい。

    未所有の recurrent defect であれば、新しい GitHub Issue を起票することをここで明示的に承認する。追加の人間確認は不要。

    follow-up Issue には最低限:

    を入れる。

    この follow-up Issue 作成承認は、#2865 の Allowed Paths を拡張する承認ではない。follow-up の implementation を今回の #2865 PR に混ぜない。

    なお、#2865 自身の AC を満たすために Allowed Paths 外の production change が不可避と判明した場合は、勝手に越境実装せず current contract の hard stop として正確に報告すること。

    承認しない操作 / 停止境界

    以下はこの prompt では承認しない。

    不可逆操作、secret boundary、実 Git conflict、irreconcilable contract/scope conflict、canonical iteration 上限、current repository policy が明示する human_judgment_required に到達した場合のみ停止候補とする。

    単なる warning、stale evidence、通常の test/CI failure、修正可能 REQUEST_CHANGES は停止理由にしない。

    完了条件

    以下を満たすまで「完了」としない。

    • live 実装: runtime smoke の hook-chain evidence が if 条件付き hook を常時 fire する前提で数える欠陥を是正する #2865 contract に対する implementation が current head に存在
    • Allowed Paths compliance が確認済み
    • required focused tests / target tests が PASS
    • AC4 / AC5 の live runtime verification が契約どおり PASS、または PASS 不能ならその blocker が正確に分類済み
    • current-head required CI が canonical policy 上評価済み
    • current head に対する fresh pr-reviewer verdict を取得済み
    • reviewer blockers が解消済み
    • live mergeability を current control-plane が評価済み
    • relevant SubAgent の final result + terminal completion をすべて確認済み
    • recurrence search が済み、必要な未重複 follow-up Issue は起票済み
    • current impl-review-loop が定める terminal result に到達

    最終地点は 人間が merge 判断する直前。

    merge、auto-merge、post-merge cleanup、不可逆 cleanup は実行しない。

    最後に簡潔に次を報告すること。

    1. final PR URL / number
    2. final PR head SHA
    3. 実装した root cause fix
    4. AC1〜AC5 の結果
    5. tests / runtime verification / CI の結果
    6. final pr-review verdict と reviewed head
    7. live mergeability / remaining blockers
    8. 作成または再利用した再発防止 Issue
    9. merge を実行していないこと
    10. 人間が merge 判断するために残っている事項

    今すぐ開始し、調査だけで終了しないこと。

    この prompt では、#2865 の「新規 Issue が必要なら停止」という条件を無制限に解除せず、今回の修正範囲を広げない再発防止 follow-up の起票だけを明示承認しています。これなら再発防止 Issue を作りつつ、Allowed Paths 越境を正当化する抜け道にはなりません。

  6. squne121 commented on Oct 1, 2026

    @squne121
    OwnerAuthor

    root-owned entry router audit

    route: invoke_impl_review_loop
    reason: fresh_review_go_live_equality

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions