Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: >
allowed_paths_review_gate.py の引数に issue-refinement-loop 配下パスが
含まれていても、local_main_branch_guard の issue_refinement_direct
ルールによって誤遮断されず、guard 判定が allow まで進む状態にする
change_kind: codeParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: pr-review-judge の allowed_paths_review_gate.py が review_subagent(root checkout)から実行される際、issue-refinement-loop 配下パスを含む allowed-paths 引数によって local_main_branch_guard の issue_refinement_direct ルールに誤遮断されず、guard 判定が allow まで進むこと。
ALLOWED_PATHS_GATE_RESULT_V1.status: ok自体への到達は、expected_contract_fingerprint が正しく供給された場合にのみ成立するものであり、fingerprint 供給の実装は本 Issue のスコープ外(別 Issue 前提)とする。 - Desired Destination: N/A(単独 Issue)
Current Validated Scope
- scripts/agent-guards/local_main_branch_guard.py の _looks_like_direct_issue_refinement_runtime_command classifier とその呼び出し箇所のみを対象とする
Remaining Parent Gaps
- expected_contract_fingerprint を供給する upstream artifact の正本確立は本 Issue のスコープ外とする。別 Issue として起票要否を判断する
- scripts/agent-guards/skill_runtime_command_policy.py の looks_like_skill_runtime_executor_command も同型の naive substring 判定であり、将来同種の false-positive を引き起こしうるが、本 Issue では実際の再現報告がないため対象外とする
Outcome
scripts/agent-guards/local_main_branch_guard.py の _looks_like_direct_issue_refinement_runtime_command が、コマンド文字列全体への部分文字列判定ではなく tokenize 済み argv 上で実際に issue-refinement-loop 配下スクリプトを実行対象として起動しているかを判定するよう修正され、allowed_paths_review_gate.py を issue-refinement-loop 配下パスを含む allowed-paths JSON 引数で実行しても issue_refinement_direct ルールで block されなくなり、guard 判定が allow まで進む状態になっている。ALLOWED_PATHS_GATE_RESULT_V1.status: ok 自体は fingerprint 供給という別要因に依存するため、本 Issue の Outcome は「誤遮断が解消され guard 判定が allow まで進むこと」に限定する。対応する pytest が正本テスト(.claude/hooks/tests/)・compat shim(scripts/agent-guards/tests/)・Codex parity テスト(tests/codex/)の全レイヤに追加され、CI で green になっている。
In Scope
- _looks_like_direct_issue_refinement_runtime_command(scripts/agent-guards/local_main_branch_guard.py 950行目)を、raw command 文字列への substring 判定や単純な再tokenize ではなく、以下の設計の classifier に置き換える
- classifier は tokenize 済みの token list(
Sequence[str])を受け取り、cwd/project_rootを考慮した上で、launcher grammar(<target-script>直接指定 /python3 [opts] <script>/uv run [opts] [--] <script>/uv run [opts] [--] python3 [opts] <script>)から実際に実行される script operand のみを抽出する python -c/-m/ stdin 実行 / 未対応 wrapper 形式は、本 classifier の対象外とし、既存の fail-closed 分類(安全側で block 側に倒す既存挙動)にそのまま委ねる- path identity の比較は realpath 正規化を行い、symlink を経由した迂回を拒否する方針を明記する。
./相対表記・絶対パス表記・uv run --directory <dir> <script>のような別表記であっても、実行対象が issue-refinement-loop 配下の同一スクリプトであれば同一 script identity として block されることを保証する - allowed-paths のような JSON 配列値が単一トークン内に当該パス文字列を部分文字列として含むだけのケース(実行対象 script operand ではない)は false とする
- classifier は tokenize 済みの token list(
- 呼び出し側 evaluate() が現在 normalized_cmd(tokenize 済み argv を
" ".join(tokens)で再構築した文字列)を classifier に渡している問題を修正し、tokenize 済みの実際の argv(token list)を classifier に直接渡すよう変更する - 呼び出し箇所(scripts/agent-guards/local_main_branch_guard.py 1935行目付近、local_rule_id が issue_refinement_direct になる分岐)の挙動を新 classifier に合わせて更新する
- 既存の正当な block ケース(issue-refinement-loop 配下スクリプトを root checkout から直接実行するコマンド)が引き続き block されることを回帰させない
- 正本テスト(.claude/hooks/tests/test_local_main_branch_guard.py)・Codex parity テスト(tests/codex/test_local_main_branch_guard.py)の両方に、must allow(allowed_paths_review_gate.py を issue-refinement-loop 配下パスを含む allowed-paths JSON 引数付きで実行するコマンド)・must block(issue-refinement-loop 配下スクリプトを直接実行するコマンド、および別表記での同一 script identity 実行コマンド)双方向のテストを追加する
- scripts/agent-guards/tests/test_local_main_branch_guard.py(既存 VC 互換の compat shim)は削除せず維持し、正本テストと整合する形で必要な追加テストを反映する
Out of Scope
- expected_contract_fingerprint を供給する upstream artifact(snapshot artifact の正本)の設計・実装
- scripts/agent-guards/skill_runtime_command_policy.py の looks_like_skill_runtime_executor_command の同種修正
- .claude/skills/pr-review-judge/scripts/allowed_paths_review_gate.py 自体のロジック変更
Acceptance Criteria
- AC1: PR fix: review compact artifact の parent-local replay integrity binding を再設計する (#1532) #1535 相当の
allowed_paths_review_gate.py --allowed-paths '<JSON>'(issue-refinement-loop 配下パスを含む JSON)を evaluate() に渡すとstatus=allowになり、local_rule_idがissue_refinement_directにならないことを示す pytest が正本テスト(.claude/hooks/tests/)に追加され green である - AC2: issue-refinement-loop script の exact path を別プログラムの通常引数(allowed-paths JSON 配列値等)として渡した場合に誤認せず allow になることを示す pytest が追加され green である
- AC3:
python3 <issue-refinement-script>/uv run <script>/uv run python3 <script>の形で issue-refinement-loop 配下スクリプトを直接実行するコマンドは引き続き block されることを示す pytest が追加され green である(既存 block 挙動の非回帰) - AC4:
./相対表記・絶対パス表記・python -I・uv run --directory <dir> <script>等の別表記であっても、issue-refinement-loop 配下スクリプトの直接実行が同一 script identity として block されることを示す pytest が追加され green である - AC5: allowed-paths JSON 引数内の空白・引用符・複数パス指定がトークン境界を壊さず allow 判定になることを示す pytest が追加され green である
- AC6: Claude hook wrapper 経由の invocation と Codex event fixture 経由の invocation の双方で、同一入力コマンドに対して同一の policy verdict(allow/block)になることを示す pytest が tests/codex/test_local_main_branch_guard.py に追加され green である
- AC7: 正本テスト(.claude/hooks/tests/test_local_main_branch_guard.py)・compat shim(scripts/agent-guards/tests/test_local_main_branch_guard.py)・Codex dedicated test(tests/codex/test_local_main_branch_guard.py)の全件が green である
Verification Commands
# AC1
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py
# AC2
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py
# AC3
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py
# AC4
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py
# AC5
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py
# AC6
$ uv run pytest tests/codex/test_local_main_branch_guard.py
# AC7
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py scripts/agent-guards/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.pyAllowed Paths
- scripts/agent-guards/local_main_branch_guard.py
- .claude/hooks/tests/test_local_main_branch_guard.py
- tests/codex/test_local_main_branch_guard.py
- scripts/agent-guards/tests/test_local_main_branch_guard.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
なし
Required Design References
- docs/dev/hook-boundaries.md — local_main_branch_guard の責務・reason code taxonomy
- scripts/agent-guards/local_main_branch_guard.py — 対象実装ファイル
Scope Delta(該当時のみ記載)
N/A
Delivery Rule
- 1 Issue = 1 PR を厳守する
- 実装は issue worktree で行い、root checkout を直接編集しない
- PR は Draft PR として作成する
Runtime Verification Applicability
decision: immediate
applicable_acs:
- AC1
- AC2
- AC3
- AC4
- AC5
- AC6
- AC7
execution_environment:
cli_tools:
- python3
- uv
- pytest
auth_required: false
network_required: false
skip_conditions:
- "local repository checkout が存在しない場合は SKIP ではなく environment blocked として扱う"
fallback_policy:
fallback_success_is_pass: false
notes: "fallback 経由の成功を PASS に変換しない"
artifact_requirements:
- "pytest output(.claude/hooks/tests/、scripts/agent-guards/tests/、tests/codex/ の各実行結果)"Notes for Reviewer
本 Issue は PR 1535(Closes 1532)のレビュー中に review_subagent が繰り返し観測した false-positive block の follow-up である。該当コメント: #1535 (comment) 、 #1535 (comment) 。dedupe_key: follow-up:squne121/loop-protocol:pr/1535:allowed_paths_gate_hook_block
提案されていた二つの方向(hook allowlist 拡張、fingerprint artifact 正本確立)のうち、本 Issue は hook 側の false-positive 修正(_looks_like_direct_issue_refinement_runtime_command の argv-aware 化)を採用する。理由は、この classifier が raw command 文字列全体への naive substring 判定であり、allowed-paths JSON 引数の値に issue-refinement-loop 配下パス文字列が含まれるだけで、実際には無関係なスクリプトの実行までブロックしてしまうバグであることを scripts/agent-guards/local_main_branch_guard.py の該当箇所(950行目の関数定義、1935行目・1943行目の呼び出しと emit 箇所)で確認済みだからである。expected_contract_fingerprint の未整備は本 hook バグとは別の独立した gap であり(fingerprint が仮に供給されても hook block は解消しない)、Out of Scope として明記した。
本 Issue の保証範囲は scripts/agent-guards/local_main_branch_guard.py の _looks_like_direct_issue_refinement_runtime_command に限定する。scripts/agent-guards/skill_runtime_command_policy.py の looks_like_skill_runtime_executor_command() にも同型の naive substring 判定バグが存在することを確認しているが、同型バグの修正は本 Issue のスコープ外とし、follow-up Issue に切り出す方針とする(follow-up Issue 自体の起票は本 Issue の実装者の責務ではない)。
なお、docs/dev/hook-boundaries.md の reason code 一覧には issue_refinement_direct が現時点で未記載である。本 Issue は Allowed Paths に docs/dev/hook-boundaries.md を含めておらず、reason code 一覧の更新は本 Issue のスコープ外とする。
Activity
squne121 commentedon Jul 17, 2026
判定
REQUEST_CHANGES — 現状の Issue 契約のままでは実装着手不可
false-positive の存在と直接原因の特定自体は正しいです。現在の
_looks_like_direct_issue_refinement_runtime_command()は、コマンド全体にissue-refinement-loop/scripts/が含まれるかだけを見ており、PR #1535 でも Allowed Paths の JSON 引数を直接実行と誤認して繰り返し block したことが記録されています。 (GitHub)ただし、Issue #1543 は以下の三点で実装契約が成立していません。
ALLOWED_PATHS_GATE_RESULT_V1.status: okを Outcome に掲げながら、独立した必須条件である fingerprint 供給をスコープ外にしている。「argv の任意トークンが script path と完全一致すれば直接実行」という設計は、実行対象と単なる引数を区別できない。
実際の hook/evaluate 経路ではなく private classifier と互換 shim だけをテストしようとしている。
Issue は open、
triage-requiredで、現時点の本文はこの設計を明示しています。1. Blocker: Goal / Outcome と Out of Scope が矛盾している
PR #1535 の最終レビューでは、Allowed Paths gate が
indeterminateのままだった原因として、次の二つが明示されています。local_main_branch_guard.shによる false-positive blockexpected_contract_fingerprintの供給元 artifact が存在しないことbranch 更新後・CI green 後の最終判定でも、この二つの gap は未解消として残っています。(GitHub)
gate 実装も、
expected_contract_fingerprintがなければexpected_contract_fingerprint_missingとして merge-blocking なindeterminateを返し、不一致ならstale_snapshotを返します。CLI 上も--expected-contract-fingerprintは必須引数です。一方、Issue #1543 は次を同時に要求しています。
Goal: review_subagent が
status: okを取得できるOut of Scope: fingerprint artifact の設計・実装
AC1/AC2: private classifier の真偽だけ
AC3:
scripts/agent-guards/tests/が greenこの AC 群では、hook block が消えることは確認できても、
ALLOWED_PATHS_GATE_RESULT_V1.status: okは証明できません。必須修正
次のどちらかに契約を変更すべきです。
狭い修正 Issue として維持する場合
この場合、
ALLOWED_PATHS_GATE_RESULT_V1.status: okは Goal / Parent Goal / Outcome から削除し、fingerprint が正しく供給された場合のみ到達可能であると明記します。status: okを維持する場合fingerprint artifact の Issue を明示的な prerequisite としてリンクし、有効な fingerprint fixture を使った gate の subprocess E2E を AC に追加する必要があります。
2. Blocker: 提案された再 tokenization は実際の argv を保持しない
Issue は classifier 内で
tokenize_command(cmd)を呼び、argv 単位に変更するよう要求しています。しかし、現在のevaluate()は既に一度 tokenization した後、normalized_tokensを" ".join(tokens)で文字列へ戻し、そのnormalized_cmdを classifier に渡しています。この文字列を classifier 内で再度
shlex.split()すると、元の argv 境界は失われます。例えば、元の一引数が次の場合、
最初の tokenization では一つの JSON トークンですが、単純な
" ".join()の後に再 tokenization すると、概ね次の二トークンへ崩れます。JSON 内の引用符も shell quoting として再解釈されます。Python 標準ライブラリで token list と shell 文字列の逆変換を担当するのは
shlex.join()であり、単純な空白 join ではありません。もっとも、policy 判定ではそもそも文字列へ戻すべきではありません。(Python documentation)必須修正
classifier の契約を文字列ではなく token list に変更します。
呼び出し側は次の形にします。
normalized_cmdは既存 regex 互換のために残してもよいですが、この classifier の入力にしてはいけません。3. Blocker: 「任意トークンの完全一致」は直接実行判定ではない
Issue は「argv の各トークンを検査し、script path と完全一致するトークンがあれば直接実行」と定義しています。これは substring 判定より改善しますが、実行対象とデータ引数を区別できません。
例えば次は、issue-refinement-loop のスクリプトを実行していません。
しかし「任意トークン完全一致」なら
Trueになり、同じ false-positive が残ります。Bash の simple command では、コマンド名と残りの引数には明確な役割差があります。任意の引数に実行ファイル名が現れたからといって、そのファイルが実行対象になるわけではありません。(GNU)
さらに、実際の実行対象位置は launcher によって異なります。
Python は interpreter option の後に
script、-m、-c、-のいずれかを取る。(Python documentation)uv run file.pyはuv run python file.py相当として動作する。(Astral Docs)uv runは command より前に uv options を取り、--delimiter も使用できる。(Astral Docs)必須修正
「全トークン走査」ではなく、対応する launcher grammar から実行 script operand だけを抽出する必要があります。
最低限、次の形を識別します。
python -c、python -m、stdin 実行、未対応 wrapper は別扱いにし、既存の fail-closed policy と整合させるべきです。4. High: literal path 完全一致は既存 block の回避経路を作る
相対パス文字列の完全一致だけでは、同じスクリプトを以下の別表記で直接起動できます。
現在の substring 判定は、少なくとも
./と絶対パスについては対象文字列を含むため block します。単純な token equality に変更すると、canonical relative spelling 以外を見逃します。PR #1535 の記録にも、root checkout だけでなく
--directory経由の worktree 実行でも同じ判定が発生したとあります。uv --directoryは command 実行前に working directory を変更し、相対パスの基準も変更します。(GitHub)リポジトリ内の既存
skill_runtime_command_policy.pyは、exact command parser で以下まで実施しています。token position の固定
project root を基準とした
realpath比較symlink の拒否
flag/value の位置検査
今回の classifier も、この実装水準を参照すべきです。
必須修正
classifier に
cwdとproject_rootを渡し、launcher が設定する effective cwd を考慮して script operand を正規化します。また、以下を契約として固定する必要があります。
./の扱いabsolute path の扱い
..の扱いsymlink の扱い
non-existent path の扱い
uv run --directoryの扱いこれは security boundary の主張ではありません。リポジトリ自身も hooks を fail-closed local guardrail であり security boundary ではないと定義していますが、policy の同値表現を取りこぼさないことは correctness 上必要です。
5. High: AC が実際の失敗経路を通っていない
現在の AC1/AC2 は private helper の
True/Falseだけをテストします。しかし、実障害は次の全経路にあります。classifier の unit test が通っても、呼び出し側が
normalized_cmdを渡し続ける、別の earlier rule に捕まる、hook wrapper が異なる結果を返す、といった不具合を検出できません。現在の call site では、skill runtime の粗い判定後に issue-refinement direct 判定が行われます。新 classifier が
Falseを返し、他の分類にも該当しなければ、default branch 上の gate command は最終的にunknown_non_branch_command_allowedとして allow されるのが現行挙動です。ここまで assert する必要があります。最低限、以下を subprocess または
evaluate()で検証すべきです。加えて、実 hook wrapper に PreToolUse JSON を与え、allow 時の exit code と stderr/stdout contract も確認すべきです。
6. High: 指定されたテストファイルは正本ではなく互換 shim
Issue は
scripts/agent-guards/tests/test_local_main_branch_guard.pyにテストを追加するよう指定しています。しかし、このファイル自身が「canonical contract tests は.claude/hooks/tests/にある」と明記したrunpycompatibility shim です。実際の正本は次です。
この正本は actual guard logic と hook wrapper を対象にしています。
さらに Codex parity は別の dedicated test surface にあります。
このテストも同じ
local_main_branch_guard.pyを import しています。CI の test plan でも、
.claude/hooks/tests/scripts/agent-guards/tests/Codex 専用 lane
は別々の test surface として管理されています。
互換 shim にだけ新規テストを置くと、「正本テストには存在しないが shim 経由でだけ実行される policy test」が生まれます。
Allowed Paths の最低限の修正
shim は既存 Verification Command の互換 entrypoint として維持し、原則として新しい契約テストの正本にしない方がよいです。
7. High: 同型の class bug が earlier rule に残る
Issue 自身も、
skill_runtime_command_policy.pyのlooks_like_skill_runtime_executor_command()が同じ naive substring 判定であることを認識しています。実装は実際に"skill_runtime_exec.py" in commandだけです。しかも、この粗い classifier は issue-refinement classifier より前に実行されます。したがって、将来 Allowed Paths や fingerprint JSON に
skill_runtime_exec.pyが含まれた場合、今回と同じ種類の誤遮断が earlier rule で再発します。この修正を #1543 に必ず含める必要はありません。ただし「実再現がないので将来判断」ではなく、少なくとも以下のどちらかが必要です。
同一の argv/script-operand parser に集約して同時修正する。
明示的な follow-up Issue を起票・リンクし、実装: allowed_paths_review_gate.py が issue-refinement-loop 配下パス引数で local_main_branch_guard.sh に false-positive block される問題を解消する #1543 の保証を
_looks_like_direct_issue_refinement_runtime_commandだけに限定する。現在の Issue は、新規 Issue が必要なら Stop Condition としつつ、既知の同型欠陥について「起票要否を判断」としており、実装中断条件が予見可能な状態です。契約確定前に切り分けるべきです。
8. Medium: guard の責務とドキュメントが既に drift している
docs/dev/hook-boundaries.mdはlocal_main_branch_guardを local root branch drift 防止の hook と定義し、主要 reason code を列挙しています。しかし、issue_refinement_directはその列挙や責務説明に現れません。今回の変更は単なる内部リファクタではなく、特定 skill runtime の実行可否境界を変更します。理想的には classifier を
skill_runtime_command_policy.pyの共有 pure function に移し、branch guard はその結果を消費する形に寄せるべきです。最小修正を優先する場合でも、以下は必要です。
issue_refinement_directの責務と適用条件を hook boundaries に記載する。「任意引数の文字列ではなく actual script operand のみを対象にする」と明文化する。
reason code / rule ID を validator またはテストで固定する。
推奨実装形
実装の中心は「文字列を探す関数」ではなく「実行対象 script を抽出する関数」にします。
重要なのは以下です。
tokenize は一度だけ。
arbitrary argument token を検索しない。
launcher grammar から script operand を抽出する。
effective cwd を考慮する。
lexical spelling ではなく path identity を比較する。
symlink policy を明示する。
unknown wrapper は既存の fail-closed 分類へ渡す。
改訂 Acceptance Criteria 案
最終評価
修正対象のバグは実在し、優先して直す価値があります。
ただし、現行 Issue は「raw substring を token equality に変える」ことを解決策として先に固定しており、実行対象の意味解析、path identity、既存 test SSOT、gate の独立必須条件を取り込めていません。このまま実装すると、PR #1535 の一例だけは通っても、別の opaque argument で再び false-positive を起こし、
./・absolute path・uv --directoryでは既存 block を回避する可能性があります。したがって、Goal を hook allow までに狭め、classifier を token list + script-operand parser に変更し、正本 hook/Codex tests を Allowed Paths に追加した後に implementation-ready とするのが妥当です。
## 判定REQUEST_CHANGES — 現状の Issue 契約のままでは実装着手不可
false-positive の存在と直接原因の特定自体は正しいです。現在の
_looks_like_direct_issue_refinement_runtime_command()は、コマンド全体にissue-refinement-loop/scripts/が含まれるかだけを見ており、PR #1535 でも Allowed Paths の JSON 引数を直接実行と誤認して繰り返し block したことが記録されています。 ([GitHub]1)ただし、Issue #1543 は以下の三点で実装契約が成立していません。
ALLOWED_PATHS_GATE_RESULT_V1.status: okを Outcome に掲げながら、独立した必須条件である fingerprint 供給をスコープ外にしている。Issue は open、
triage-requiredで、現時点の本文はこの設計を明示しています。1. Blocker: Goal / Outcome と Out of Scope が矛盾している
PR #1535 の最終レビューでは、Allowed Paths gate が
indeterminateのままだった原因として、次の二つが明示されています。local_main_branch_guard.shによる false-positive blockexpected_contract_fingerprintの供給元 artifact が存在しないことbranch 更新後・CI green 後の最終判定でも、この二つの gap は未解消として残っています。([GitHub]1)
gate 実装も、
expected_contract_fingerprintがなければexpected_contract_fingerprint_missingとして merge-blocking なindeterminateを返し、不一致ならstale_snapshotを返します。CLI 上も--expected-contract-fingerprintは必須引数です。一方、Issue #1543 は次を同時に要求しています。
status: okを取得できるscripts/agent-guards/tests/が greenこの AC 群では、hook block が消えることは確認できても、
ALLOWED_PATHS_GATE_RESULT_V1.status: okは証明できません。必須修正
次のどちらかに契約を変更すべきです。
狭い修正 Issue として維持する場合
この場合、
ALLOWED_PATHS_GATE_RESULT_V1.status: okは Goal / Parent Goal / Outcome から削除し、fingerprint が正しく供給された場合のみ到達可能であると明記します。status: okを維持する場合fingerprint artifact の Issue を明示的な prerequisite としてリンクし、有効な fingerprint fixture を使った gate の subprocess E2E を AC に追加する必要があります。
2. Blocker: 提案された再 tokenization は実際の argv を保持しない
Issue は classifier 内で
tokenize_command(cmd)を呼び、argv 単位に変更するよう要求しています。しかし、現在のevaluate()は既に一度 tokenization した後、normalized_tokensを" ".join(tokens)で文字列へ戻し、そのnormalized_cmdを classifier に渡しています。この文字列を classifier 内で再度
shlex.split()すると、元の argv 境界は失われます。例えば、元の一引数が次の場合、
最初の tokenization では一つの JSON トークンですが、単純な
" ".join()の後に再 tokenization すると、概ね次の二トークンへ崩れます。JSON 内の引用符も shell quoting として再解釈されます。Python 標準ライブラリで token list と shell 文字列の逆変換を担当するのは
shlex.join()であり、単純な空白 join ではありません。もっとも、policy 判定ではそもそも文字列へ戻すべきではありません。([Python documentation]2)必須修正
classifier の契約を文字列ではなく token list に変更します。
呼び出し側は次の形にします。
normalized_cmdは既存 regex 互換のために残してもよいですが、この classifier の入力にしてはいけません。3. Blocker: 「任意トークンの完全一致」は直接実行判定ではない
Issue は「argv の各トークンを検査し、script path と完全一致するトークンがあれば直接実行」と定義しています。これは substring 判定より改善しますが、実行対象とデータ引数を区別できません。
例えば次は、issue-refinement-loop のスクリプトを実行していません。
しかし「任意トークン完全一致」なら
Trueになり、同じ false-positive が残ります。Bash の simple command では、コマンド名と残りの引数には明確な役割差があります。任意の引数に実行ファイル名が現れたからといって、そのファイルが実行対象になるわけではありません。([GNU]3)
さらに、実際の実行対象位置は launcher によって異なります。
script、-m、-c、-のいずれかを取る。([Python documentation]4)uv run file.pyはuv run python file.py相当として動作する。([Astral Docs]5)uv runは command より前に uv options を取り、--delimiter も使用できる。([Astral Docs]5)必須修正
「全トークン走査」ではなく、対応する launcher grammar から実行 script operand だけを抽出する必要があります。
最低限、次の形を識別します。
python -c、python -m、stdin 実行、未対応 wrapper は別扱いにし、既存の fail-closed policy と整合させるべきです。4. High: literal path 完全一致は既存 block の回避経路を作る
相対パス文字列の完全一致だけでは、同じスクリプトを以下の別表記で直接起動できます。
現在の substring 判定は、少なくとも
./と絶対パスについては対象文字列を含むため block します。単純な token equality に変更すると、canonical relative spelling 以外を見逃します。PR #1535 の記録にも、root checkout だけでなく
--directory経由の worktree 実行でも同じ判定が発生したとあります。uv --directoryは command 実行前に working directory を変更し、相対パスの基準も変更します。([GitHub]1)リポジトリ内の既存
skill_runtime_command_policy.pyは、exact command parser で以下まで実施しています。realpath比較今回の classifier も、この実装水準を参照すべきです。
必須修正
classifier に
cwdとproject_rootを渡し、launcher が設定する effective cwd を考慮して script operand を正規化します。また、以下を契約として固定する必要があります。
./の扱い..の扱いuv run --directoryの扱いこれは security boundary の主張ではありません。リポジトリ自身も hooks を fail-closed local guardrail であり security boundary ではないと定義していますが、policy の同値表現を取りこぼさないことは correctness 上必要です。
5. High: AC が実際の失敗経路を通っていない
現在の AC1/AC2 は private helper の
True/Falseだけをテストします。しかし、実障害は次の全経路にあります。classifier の unit test が通っても、呼び出し側が
normalized_cmdを渡し続ける、別の earlier rule に捕まる、hook wrapper が異なる結果を返す、といった不具合を検出できません。現在の call site では、skill runtime の粗い判定後に issue-refinement direct 判定が行われます。新 classifier が
Falseを返し、他の分類にも該当しなければ、default branch 上の gate command は最終的にunknown_non_branch_command_allowedとして allow されるのが現行挙動です。ここまで assert する必要があります。最低限、以下を subprocess または
evaluate()で検証すべきです。加えて、実 hook wrapper に PreToolUse JSON を与え、allow 時の exit code と stderr/stdout contract も確認すべきです。
6. High: 指定されたテストファイルは正本ではなく互換 shim
Issue は
scripts/agent-guards/tests/test_local_main_branch_guard.pyにテストを追加するよう指定しています。しかし、このファイル自身が「canonical contract tests は.claude/hooks/tests/にある」と明記したrunpycompatibility shim です。実際の正本は次です。
この正本は actual guard logic と hook wrapper を対象にしています。
さらに Codex parity は別の dedicated test surface にあります。
このテストも同じ
local_main_branch_guard.pyを import しています。CI の test plan でも、
.claude/hooks/tests/scripts/agent-guards/tests/は別々の test surface として管理されています。
互換 shim にだけ新規テストを置くと、「正本テストには存在しないが shim 経由でだけ実行される policy test」が生まれます。
Allowed Paths の最低限の修正
shim は既存 Verification Command の互換 entrypoint として維持し、原則として新しい契約テストの正本にしない方がよいです。
7. High: 同型の class bug が earlier rule に残る
Issue 自身も、
skill_runtime_command_policy.pyのlooks_like_skill_runtime_executor_command()が同じ naive substring 判定であることを認識しています。実装は実際に"skill_runtime_exec.py" in commandだけです。しかも、この粗い classifier は issue-refinement classifier より前に実行されます。したがって、将来 Allowed Paths や fingerprint JSON に
skill_runtime_exec.pyが含まれた場合、今回と同じ種類の誤遮断が earlier rule で再発します。この修正を #1543 に必ず含める必要はありません。ただし「実再現がないので将来判断」ではなく、少なくとも以下のどちらかが必要です。
_looks_like_direct_issue_refinement_runtime_commandだけに限定する。現在の Issue は、新規 Issue が必要なら Stop Condition としつつ、既知の同型欠陥について「起票要否を判断」としており、実装中断条件が予見可能な状態です。契約確定前に切り分けるべきです。
8. Medium: guard の責務とドキュメントが既に drift している
docs/dev/hook-boundaries.mdはlocal_main_branch_guardを local root branch drift 防止の hook と定義し、主要 reason code を列挙しています。しかし、issue_refinement_directはその列挙や責務説明に現れません。今回の変更は単なる内部リファクタではなく、特定 skill runtime の実行可否境界を変更します。理想的には classifier を
skill_runtime_command_policy.pyの共有 pure function に移し、branch guard はその結果を消費する形に寄せるべきです。最小修正を優先する場合でも、以下は必要です。
issue_refinement_directの責務と適用条件を hook boundaries に記載する。推奨実装形
実装の中心は「文字列を探す関数」ではなく「実行対象 script を抽出する関数」にします。
重要なのは以下です。
改訂 Acceptance Criteria 案
allowed_paths_review_gate.py --allowed-paths '<JSON>'をevaluate()に渡すstatus=allow、issue_refinement_directにならないpython3 <issue-refinement-script>issue_refinement_directuv run <script>とuv run python3 <script>./、absolute path、python -I、uv run --directorystatus: okを残す場合のみ、有効な fingerprint fixture で gate subprocess を完走ALLOWED_PATHS_GATE_RESULT_V1.status=ok最終評価
修正対象のバグは実在し、優先して直す価値があります。
ただし、現行 Issue は「raw substring を token equality に変える」ことを解決策として先に固定しており、実行対象の意味解析、path identity、既存 test SSOT、gate の独立必須条件を取り込めていません。このまま実装すると、PR #1535 の一例だけは通っても、別の opaque argument で再び false-positive を起こし、
./・absolute path・uv --directoryでは既存 block を回避する可能性があります。したがって、Goal を hook allow までに狭め、classifier を token list + script-operand parser に変更し、正本 hook/Codex tests を Allowed Paths に追加した後に implementation-ready とするのが妥当です。
squne121 commentedon Jul 17, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jul 17, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 17, 2026
Contract Review Result
squne121 commentedon Jul 17, 2026
implement-issue: 実装完了
.claude/worktrees/issue-1543-issue-refinement-direct-classifier-fix-v2worktree-issue-1543-issue-refinement-direct-classifier-fix-v2uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -q→ 355 passeduv run pytest tests/codex/test_local_main_branch_guard.py -q→ 300 passeduv run pytest .claude/hooks/tests/test_local_main_branch_guard.py scripts/agent-guards/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -q→ 1010 passed補足: 先に作成した worktree
.claude/worktrees/issue-1543-issue-refinement-direct-classifier-fix(branchworktree-issue-1543-issue-refinement-direct-classifier-fix)はセッション中断の影響で未使用のまま残存しています。branch は main と同一 commit(差分なし)で安全に削除可能です。PR #1558 は別 slug(-v2)の worktree/branch から作成しています。fix: launcher grammar classifier を uv/python の実 CLI arity に合わせて再設計する (#…
fix: local_main_branch_guard の issue_refinement_direct 判定を argv-aware…