Skip to content

実装: skill-runtime target predicate を Issue #1595 の共有 launcher classifier ベースに置換する #1565

Open

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "OWNER anchor comment(https://github.com/squne121/loop-protocol/issues/1565#issuecomment-5009975121)で提案された3分割のうち Issue B(skill-runtime target predicate の置換)を、Issue #1595 が提供する共有 launcher classifier の TargetEvidence / ParseStatus 分類結果を消費する形で実装する"
change_kind: code

Parent Issue

なし(単独改善。ただし Issue #1595 の完了を前提条件とする。「Depends On」参照)

Parent Goal Ref

Depends On

Current Validated Scope

Remaining Parent Gaps

Outcome

scripts/agent-guards/skill_runtime_command_policy.py の looks_like_skill_runtime_executor_command()(または #1595 が確立する invocation contract に沿った同等関数)が、raw command 文字列への naive substring 判定("skill_runtime_exec.py" in command)から、Issue #1595 が提供する launcher_command_classifier.py の TargetEvidence / ParseStatus 分類結果を消費する skill-runtime target 固有の predicate 判定へ置き換えられ、以下の5点が pytest で確認できている状態。

  • 引数値中(例: --allowed-paths の JSON 配列値など、実行対象ではない operand 位置)にのみ skill_runtime_exec.py という文字列が現れるコマンドは、上流分類器が返す TargetEvidence.NONE を受けて skill-runtime target と判定されない。
  • canonical path、絶対パス、相対パス、symlink alias で scripts/agent-guards/skill_runtime_exec.py を実行対象とするコマンドは、上流分類器が返す TargetEvidence.EXACT を受けて skill-runtime target と判定される。
  • brace expansion / tilde expansion 等の dynamic expansion により target になり得る operand は、上流分類器が返す TargetEvidence.POSSIBLE を受けて保守的に skill-runtime target(block 対象)として扱われる。
  • target evidence を持たない未対応 wrapper(TargetEvidence.NONE かつ ParseStatus.UNSUPPORTED 等)は、skill-runtime 固有の predicate では skill-runtime target と分類しない(generic wrapper / unknown-command policy 側の判定に委譲する)。
  • 既存の exact authorized skill-runtime command(is_exact_skill_runtime_executor_command() / is_exact_skill_runtime_anchor_executor_command() 等)の allow 判定順序は、新 predicate 導入後も維持される。

In Scope

Out of Scope

Acceptance Criteria

  • AC1: looks_like_skill_runtime_executor_command()(または同等関数)が、raw command 文字列への substring 判定ではなく、launcher_command_classifier.py が返す TargetEvidence / ParseStatus を入力とする predicate 判定に置き換わっている
  • AC2: --allowed-paths 引数値の JSON 配列内など、実行対象ではない引数値にのみ skill_runtime_exec.py という文字列が含まれるコマンド(上流分類器が TargetEvidence.NONE を返すケース)に対して、predicate が skill-runtime target ではないと判定する回帰テストが追加されている
  • AC3: canonical path・絶対パス・相対パス・symlink alias で scripts/agent-guards/skill_runtime_exec.py を実行対象とするコマンド(上流分類器が TargetEvidence.EXACT を返すケース)に対して、predicate が skill-runtime target と判定する既存挙動が維持されている
  • AC4: brace expansion / tilde expansion 等の dynamic expansion で target になり得る operand(上流分類器が TargetEvidence.POSSIBLE を返すケース)に対して、predicate が保守的に skill-runtime target(block 対象)として扱う回帰テストが追加されている
  • AC5: target evidence のない未対応 wrapper(TargetEvidence.NONE かつ ParseStatus.UNSUPPORTED 等)を経由するコマンドに対して、predicate が skill-runtime target として誤分類しない(generic wrapper / unknown-command policy 側へ委譲する)ことを検証するテストが追加されている
  • AC6: 既存の exact authorized skill-runtime command(is_exact_skill_runtime_executor_command() / is_exact_skill_runtime_anchor_executor_command())の allow 判定順序が、新 predicate 導入後も変更なしで動作し続けることを既存テストスイートで確認できる

Verification Commands

# AC1
# baseline-expect: pass
$ grep -c "in (command or" scripts/agent-guards/skill_runtime_command_policy.py

# AC2
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_command_policy_argv_classifier.py -k test_argument_value_only_mention_returns_none_evidence

# AC3
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_command_policy_argv_classifier.py -k test_exact_target_evidence_returns_true

# AC4
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_command_policy_argv_classifier.py -k test_possible_target_evidence_dynamic_expansion_blocks

# AC5
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_command_policy_argv_classifier.py -k test_unsupported_wrapper_without_target_evidence_not_skill_runtime

# AC6
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_command_policy_anchor.py

Allowed Paths

  • scripts/agent-guards/skill_runtime_command_policy.py
  • scripts/agent-guards/tests/test_skill_runtime_command_policy_argv_classifier.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

なし

Required Design References

Scope Delta(該当時のみ記載)

reframe_in_place: OWNER anchor comment(REQUEST_CHANGES、3分割提案)を受け、Outcome / In Scope / Out of Scope / Allowed Paths / Acceptance Criteria / Verification Commands / Required Design References を、3分割のうち Issue B(skill-runtime target predicate の置換)へ縮小した。共有 launcher parser の抽出・consumer invocation contract 移行(Issue A)は #1595 として、uv / GitHub Actions toolchain pin(Issue C)は #1598 としてそれぞれ別 Issue に分離済み。旧 ## Open Scope Question (Requires OWNER Decision) セクション(_rebuild_normalized_cmd() の不可逆変換と「呼び出し元変更禁止」制約の矛盾)は、この3分割によって解消されたため削除した(Notes for Reviewer に経緯を記載)。

Delivery Rule

  • 1 Issue = 1 PR を原則とする
  • worktree での実装を前提とし、issue 番号付き worktree ディレクトリを使う
  • PR は Draft PR として起票する

Notes for Reviewer

Runtime Verification Applicability

decision: immediate
rationale: "本 Issue は skill_runtime_command_policy.py の target predicate 判定ロジックを扱い、既存の false-positive/false-negative 回帰ケース(引数値内の偶然の文字列一致、dynamic expansion による target 判定、target evidence のない wrapper の非分類、exact allow 順序維持)は静的検証だけでは意味論を確認できないため、pytest による実行時検証が必須。"
applicable_acs: ["AC1", "AC2", "AC3", "AC4", "AC5", "AC6"]
execution_environment: "uv run --locked pytest によるローカル subprocess 実行(外部サービス・ネットワーク不要)"
skip_conditions: "uv / pytest が実行環境に存在しない場合のみ SKIP(exit code 77, stdout に SKIP: プレフィックス)とし、Stop Conditions に従って人間判断を仰ぐ。それ以外は SKIP を認めない"
fallback_policy: "fallback 経由で得られた PASS は FAIL として扱う。実 pytest 実行結果のみを PASS の根拠とする"
artifact_requirements: "各 pytest の exit code / stdout ログを PR コメントまたは artifacts/{issue_number}/ 配下に保存し、実行証跡として添付する"

Source

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    triage-required
    on Jul 18, 2026
  2. squne121 commented on Jul 18, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES — 現状の Issue #1565 は実装着手不可です。

    目的である「単なる引数値中の skill_runtime_exec.py を実行対象と誤認しない」は妥当です。しかし、Issue が要求する次の3条件は同時に成立しません。

    1. tokenize 済み argv に基づく classifier にする

    2. 既存呼び出し元の引数・戻り値の意味を変えない

    3. local_main_branch_guard.py を変更対象外にする

    さらに、Required Design Reference とされている Issue #1543 / PR #1558 の実装には、現在の Python CLI grammar と Bash expansion に対して未処理のケースがあり、そのまま移植すると実際の skill_runtime_exec.py 起動を allow 側へ落とす false-negativeが発生し得ます。

    Issue #1565 自体には現時点でコメントがなく、実装前の設計反証がまだ行われていません。一方、参照元 PR #1558 では、初回レビュー後に OWNER が uv/Python option arity、wrapper、shell expansion、テスト不足を追加発見した履歴があります。今回も参照実装を前提にするのではなく、その参照実装自体を再検証すべきです。


    重大指摘

    Blocker 1 — argv-aware 化と「呼び出し元変更禁止」が論理的に両立しない

    現行 local_main_branch_guard.py は、一度得た normalized_tokens を次のように文字列へ戻しています。

    def _rebuild_normalized_cmd(tokens: list[str]) -> str:
        return " ".join(tokens)
    

    その再構築文字列を exact classifier と looks_like_skill_runtime_executor_command() に渡しています。

    これは不可逆変換です。例えば元のコマンドが次の場合、

    uv run --directory "/tmp/project with spaces" \
      python3 /repo/scripts/agent-guards/skill_runtime_exec.py \
      --command-id preflight.run ...
    

    最初の shlex.split() では "/tmp/project with spaces" は1トークンですが、" ".join(tokens) 後は引用符が消えます。その文字列を classifier 内で再度 shlex.split() すると、

    /tmp/project
    with
    spaces
    

    の3トークンになります。parser は with を script operand と誤認し、後方にある本物の skill_runtime_exec.py を見落とせます。

    Python 標準ライブラリには、token list を安全に文字列へ戻す逆変換として shlex.join() がありますが、最善策はそもそも文字列へ戻さず argv を直接渡すことです。 (Python documentation)

    実際、Issue #1543 と PR #1558 はまさにこの問題を認識し、classifier を Sequence[str] 受け取りへ変更し、呼び出し側も normalized_cmd ではなく normalized_tokens を直接渡す修正を行っています。

    必要な修正

    • looks_like_skill_runtime_executor_command(command: str) の既存シグネチャ維持を撤回する

    • 少なくとも argv: Sequence[str], raw_command: str, cwd: str, project_root: str を入力にする

    • local_main_branch_guard.py を Allowed Paths に追加する

    • すべての consumer で tokens → join → split を禁止する

    この変更なしで AC1、AC3、AC4、AC6 を同時に満たすことはできません。


    Blocker 2 — cwd と project_root なしでは realpath 判定も uv --directory 判定も成立しない

    Issue は script operand の realpath 比較と、uv run --directory の正しい arity・実効 cwd 解決を要求しています。しかし現行関数の引数は command: str のみです。

    uv の --directory は単なる project 選択ではなく、実行前に作業ディレクトリを変更し、相対パスの基準もそのディレクトリへ変更します。 (Astral Docs)

    したがって、例えば次の identity 判定には呼び出し時の cwd が必要です。

    uv run --directory ../other-root \
      python3 scripts/agent-guards/skill_runtime_exec.py
    

    hook payload の cwd と classifier プロセス自身の os.getcwd() が同一とは限りません。project_root も渡されなければ、次を区別できません。

    • 当該 repository の正規 skill_runtime_exec.py

    • 別 repository にある同名ファイル

    • --directory 適用後の相対パス

    • symlink 経由で正規 target に到達するパス

    参照実装側が tokens, cwd, project_root を受け取っているのは必須条件であり、実装上の便宜ではありません。


    Blocker 3 — 参照実装を移植すると、有効な CPython option で target 起動を回避できる

    参照実装の Python option parser は、値付き option を次の完全一致だけで処理しています。

    _PY_VALUE_FLAGS = {"-W", "-X", "--check-hash-based-pycs"}
    

    また、既知の完全一致 flag 以外の複数文字 short option は NOT_TARGET として処理します。

    ところが CPython は次の形式を正規に受け付けます。

    python3 -Wignore script.py
    python3 -Xdev script.py
    python3 -BE script.py
    

    公式 Python 3.12 ドキュメントも -Wignore を有効な形式として明記しています。CPython の getopt 実装も、short option を文字単位で走査し、値付き option では同一トークン内の残りを option argument として扱っています。 (Python documentation)

    したがって、参照ロジックをそのまま使った場合、次が問題になります。

    python3 -Wignore \
      /repo/scripts/agent-guards/skill_runtime_exec.py \
      --command-id preflight.run \
      --issue-number 1565 \
      --repo squne121/loop-protocol
    

    現行参照実装上の推移は次のとおりです。

    1. -Wignore は _PY_VALUE_FLAGS の -W と一致しない

    2. 複数文字 short option なので NOT_TARGET

    3. 参照 classifier は NOT_TARGET に対して False

    4. 下流の is_tmp_wrapper_or_python_c_command() は -c / -m を含む option しか捕捉しない

    5. default branch 上では最終的に unknown command の default allow へ到達し得る

    NOT_TARGET → False という参照挙動と、下流 classifier の限定的な補完範囲はコード上確認できます。

    これは availability 上の過剰 block ではなく、実 target 起動の false-negativeです。

    AC に追加すべき必須ケース

    python3 -Wignore <target>
    python3 -W ignore <target>
    python3 -Xdev <target>
    python3 -X dev <target>
    python3 -BE <target>
    python3 -Ib <target>
    

    Python short-option grammar は「既知 token の集合」ではなく、option cluster と attached argument を解析する scanner として実装する必要があります。


    Blocker 4 — shell expansion 検出が不完全で、quote provenance も失っている

    参照実装の shell expansion 判定は次の4種だけです。

    re.compile(r"[$*?\[]")
    

    Bash が行う展開はこれだけではありません。公式 Bash manual では、brace expansion、tilde expansion、parameter expansion、command substitution、arithmetic expansion、word splitting、filename expansion、process substitution などが定義されています。 (GNU)

    見逃しによる false-negative

    python3 /repo/scripts/{agent-guards,other}/skill_runtime_exec.py ...
    

    Bash は brace expansion により、最初の引数を次へ展開できます。

    /repo/scripts/agent-guards/skill_runtime_exec.py
    

    一方 classifier は { と } を dynamic syntax と認識せず、brace を含むリテラルパスに realpath を適用して非targetと判断できます。

    同様に次も未処理です。

    python3 ~/loop-protocol/scripts/agent-guards/skill_runtime_exec.py ...
    python3 ~+/scripts/agent-guards/skill_runtime_exec.py ...
    

    quote 消失による false-positive

    python3 '$PWD/scripts/agent-guards/skill_runtime_exec.py'
    

    単一引用符内の $PWD は Bash 上では完全なリテラルです。 (GNU)

    しかし shlex.split() 後は引用符が消え、classifier が見る token は $PWD/... です。そのため $ を理由に UNSUPPORTED として block します。二重引用符では $ が展開されるため、同じ token 文字列でも意味が異なります。 (GNU)

    つまり、tokenize 後の文字列だけでは次を区別できません。

    '$PWD/file.py'   # リテラル
    "$PWD/file.py"   # parameter expansion
    $PWD/file.py     # parameter expansion + word splitting 等
    

    必要な修正

    • raw command と token span、quote mode を保持する lexer を共有資産として実装する

    • dynamic operand を「文字集合」で判定せず、unquoted / double-quoted / single-quoted の文脈で分類する

    • brace と tilde を最低限カバーする

    • expansion 自体は実行せず、target になり得る dynamic operand を POSSIBLE_TARGET として block する


    Blocker 5 — bool 戻り値が「target identity」と「fail-closed policy」を混同している

    現在の関数名と意味は「skill-runtime executor に見えるか」です。しかし Issue は、target の証拠がない未対応 wrapper まで True にして block する設計を要求しています。

    参照実装では以下がすべて UNSUPPORTED です。

    • exec

    • time

    • timeout

    • basename が env

    • path-qualified uv

    この UNSUPPORTED → True を共有関数へ持ち込むと、例えば次が skill-runtime command と分類されます。

    time git status
    timeout 1 echo ok
    /usr/bin/env git status
    /usr/local/bin/uv --version
    

    これは Issue の目的である false-positive 削減と正面から衝突します。

    影響は local_main_branch_guard.py だけではありません。

    • local_main_branch_guard.py: True なら skill_runtime_guess として block

    • worktree_scope_guard.py: exact allow の直後に True なら skill_runtime_executor_denied

    • pretool_fastpath_classifier.py: exact parse 不能なら controlled executor shape とし、最終的に mutation_or_unknown

    「未解析なので安全側へ倒す」と「skill-runtime target の証拠がある」は別の事実です。1つの bool に畳み込んではいけません。

    推奨する戻り値は最低でも次の二軸です。

    class TargetEvidence(Enum):
        EXACT = "exact"
        POSSIBLE = "possible"
        NONE = "none"
    

    class ParseStatus(Enum):
    PARSED = "parsed"
    DYNAMIC = "dynamic"
    UNSUPPORTED = "unsupported"
    MALFORMED = "malformed"

    @dataclass(frozen=True)
    class LauncherClassification:
    target_evidence: TargetEvidence
    parse_status: ParseStatus
    script_operand: str | None
    effective_cwd: str
    reason_code: str

    policy は次のように分離すべきです。

    • EXACT / POSSIBLE target: skill-runtime 系 reason code で block

    • NONE + UNSUPPORTED: generic wrapper / unknown-command policy へ委譲

    • exact authorized invocation: broad deny より先に allow

    • malformed command: generic parse-failure reason で block


    高リスク指摘

    High 1 — import 再利用とロジック複製を「実装者裁量」にしてはいけない

    Issue Notes は、local_main_branch_guard.py の parser を import するか、skill_runtime_command_policy.py へ複製するかを実装者裁量にしています。

    しかし、local_main_branch_guard.py は既に skill_runtime_command_policy.py を top-level import しています。逆方向の top-level import は circular import になります。

    リポジトリ内には、別の classifier との circular import が import 順序によって恒久的な機能無効化を起こすため、lazy import にしたという説明も既にあります。

    一方、複製すると次が二重管理になります。

    • uv global option table

    • uv run option table

    • Python option grammar

    • wrapper taxonomy

    • dynamic shell syntax

    • cwd / realpath semantics

    必要な設計

    新しい中立モジュールを正本にします。

    scripts/agent-guards/launcher_command_classifier.py

    local_main_branch_guard.py と skill_runtime_command_policy.py の双方がこれを import する構造にすべきです。現在の Allowed Paths では実現できません。


    High 2 — uv の静的 grammar table と、配布される uv のバージョンが同期していない

    参照実装の _UV_RUN_BOOL_FLAGS / _UV_RUN_VALUE_FLAGS は固定テーブルです。

    一方、現在の uv CLI には、参照表にない次の option が既にあります。

    • --active

    • --all-groups

    • --managed-python

    • --module, -m

    • --no-managed-python

    • --no-progress

    • --no-index

    (Astral Docs)

    未知 option を fail-closed にするため直接の bypass にはなりにくいものの、uv 更新後に正当な invocation が突然 block される availability regression を生みます。特に uv run -m module は「script operand」の意味自体を変更します。

    リポジトリの composite action は astral-sh/[email protected] を使っていますが、uv binary の version input は設定していません。root pyproject.toml にも required-version はありません。

    setup-uv は、version や required-version が見つからない場合、最新 uv をインストールします。 (GitHub)

    安全境界として静的 option table を使うなら、次が必要です。

    [tool.uv]
    required-version = "==<検証済みバージョン>"

    uv 自身も required-version による実行時バージョン制約を提供しています。 (Astral Docs)

    加えて、GitHub Actions の第三者 action は tag ではなく full-length commit SHA へ pin すべきです。GitHub は full SHA を immutable release として使用する唯一の方法と説明しています。 (GitHub Docs)

    setup-uv の公式例に合わせれば、少なくとも次の形になります。

    uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0

    この hardening は Issue #1565 に含めるか、parser 実装の前提 Issue として先行させるべきです。


    Issue 契約・検証コマンドの欠陥

    1. Runtime Verification Applicability が欠落している

    リポジトリの SSOT は、全 Issue に次のいずれかを明示することを要求しています。

    not_applicable | immediate | deferred

    プロセス起動や実 argv 判定を扱う場合は immediate が妥当です。

    Issue #1543 には runtime verification 定義がありましたが、#1565 にはありません。単体 helper テストだけでなく、実 hook payload と実 command string を通した証跡が必要です。

    2. AC1 の Verification Command は成功条件と exit status が逆

    現在の AC1 は次です。

    grep -c "in (command or" scripts/agent-guards/skill_runtime_command_policy.py

    期待値が「該当コードが消えている」なら、出力は 0 ですが grep の exit status は 1 です。GNU grep は一致なしを status 1 と定義しています。 (GNU)

    少なくとも次へ変更すべきです。

    ! grep -Fq 'in (command or' 
    scripts/agent-guards/skill_runtime_command_policy.py

    ただし、source text grep は設計検証として弱すぎます。別の substring 実装へ書き換えるだけで通るため、AC1 は behavior test に統合すべきです。

    3. テストパスと Allowed Paths が自己矛盾している

    Issue は Verification Commands で次を指定しています。

    .claude/skills/issue-refinement-loop/tests/test_skill_runtime_command_policy.py
    .claude/skills/issue-refinement-loop/tests/test_local_main_branch_guard.py

    一方で Notes は「存在しない場合は既存テストファイルを探索し、別ファイルへ追加してよい」としています。しかし Allowed Paths は前者の test_skill_runtime_command_policy.py しか許可していません。

    現行の関連テスト資産は少なくとも次の場所にあります。

    • .claude/hooks/tests/test_worktree_scope_guard.py

    • .claude/hooks/tests/test_local_main_branch_guard.py

    • scripts/agent-guards/tests/test_skill_runtime_command_policy_anchor.py

    • tests/codex/test_local_main_branch_guard.py

    実装者が Notes に従うと Allowed Paths 違反になり、Allowed Paths に従うと consumer parity を検証できません。

    4. AC6 が consumer inventory を満たしていない

    共有関数の consumer は少なくとも次の3系統です。

    1. local_main_branch_guard.py

    2. .claude/hooks/worktree_scope_guard.py

    3. pretool_fastpath_classifier.py

    AC6 は local-main のみを対象としています。戻り値の意味を変えないという要件なら、3 consumer 全てについて分類結果と最終 verdict の非回帰が必要です。


    推奨する Issue 再定義

    最小安全分割

    Issue A — 共有 launcher parser の抽出と invocation contract 移行

    対象:

    scripts/agent-guards/launcher_command_classifier.py
    scripts/agent-guards/local_main_branch_guard.py
    scripts/agent-guards/skill_runtime_command_policy.py
    .claude/hooks/worktree_scope_guard.py
    scripts/agent-guards/pretool_fastpath_classifier.py
    各 consumer の正本テスト

    保証:

    • argv boundary を一切再構築しない

    • raw command の quote context を保持する

    • cwd / project_root / effective cwd を明示入力とする

    • Python short-option cluster と attached value を解析する

    • uv grammar の対応バージョンを宣言する

    • identity classification と fail-closed policy を分離する

    Issue B — skill-runtime target predicate の置換

    保証:

    • 引数値中の mention は TargetEvidence.NONE

    • canonical path、絶対パス、相対パス、symlink alias は EXACT

    • dynamic expansion で target になり得るものは POSSIBLE

    • target evidence のない wrapper unsupported は skill-runtime と分類しない

    • exact authorized command の allow 順序は維持する

    Issue C — uv / GitHub Actions toolchain pin

    保証:

    • uv binary version を固定

    • option table の対応 uv version をコード定数化

    • pinned uv の uv run --help と parser table の整合テスト

    • setup-uv を full commit SHA pin

    • Dependabot 等で更新PRを生成


    最低限必要な敵対的テスト行列

    分類 入力例 必須結果
    引数値のみ other.py --allowed-paths '[".../skill_runtime_exec.py"]' skill-runtime target ではない
    canonical target python3 scripts/agent-guards/skill_runtime_exec.py ... block
    attached Python value python3 -Wignore ... block
    separated Python value python3 -W ignore ... block
    Python cluster python3 -BE ... block
    -X attached python3 -Xdev ... block
    token boundary uv run --directory "/tmp/a b" python3 block、境界維持
    現行uv flag uv run --active --managed-python python3 block
    uv module uv run -m some.module script target と区別
    unrelated wrapper time git status skill-runtime target ではない
    target wrapper time python3 generic または target-specific reason で block
    brace expansion python3 /repo/scripts/{agent-guards,x}/skill_runtime_exec.py dynamic possible target として block
    tilde expansion python3 ~/repo/scripts/agent-guards/skill_runtime_exec.py dynamic possible target として block
    quoted literal python3 '$PWD/skill_runtime_exec.py' expansion と誤認しない
    malformed arity uv run --directory malformed / fail-closed
    consumer parity 同一入力を local-main / worktree / fastpath に投入 定義済みの一貫した分類
    frontend parity Claude hook / Codex event fixture 最終 verdict 一致
    exact allow 正規 authorized executor invocation 従来どおり allow

    結論

    Issue #1565 の狙いは正しいものの、現状は参照実装の表面的な移植になっており、PR #1558 で重要だったcaller の argv 移行を Out of Scope に戻してしまっています。

    特に次の2件は、実装上の nit ではなく安全性を破る blocker です。

    • " ".join(tokens) 後の再tokenizeによる argv boundary 消失

    • -Wignore、-Xdev、-BE など正規 CPython option による target 検出回避

    したがって、現Issueをそのまま実装するのではなく、共有 parser 抽出・consumer contract 移行・toolchain pin を先に契約化し、#1565 をその後段の predicate migration に縮小するのが妥当です。現状の判定は REQUEST_CHANGES / implementation not ready です。

    # 判定

    REQUEST_CHANGES — 現状の Issue #1565 は実装着手不可です。

    目的である「単なる引数値中の skill_runtime_exec.py を実行対象と誤認しない」は妥当です。しかし、Issue が要求する次の3条件は同時に成立しません。

    1. tokenize 済み argv に基づく classifier にする
    2. 既存呼び出し元の引数・戻り値の意味を変えない
    3. local_main_branch_guard.py を変更対象外にする

    さらに、Required Design Reference とされている Issue #1543 / PR #1558 の実装には、現在の Python CLI grammar と Bash expansion に対して未処理のケースがあり、そのまま移植すると実際の skill_runtime_exec.py 起動を allow 側へ落とす false-negativeが発生し得ます。

    Issue #1565 自体には現時点でコメントがなく、実装前の設計反証がまだ行われていません。一方、参照元 PR #1558 では、初回レビュー後に OWNER が uv/Python option arity、wrapper、shell expansion、テスト不足を追加発見した履歴があります。今回も参照実装を前提にするのではなく、その参照実装自体を再検証すべきです。


    重大指摘

    Blocker 1 — argv-aware 化と「呼び出し元変更禁止」が論理的に両立しない

    現行 local_main_branch_guard.py は、一度得た normalized_tokens を次のように文字列へ戻しています。

    def _rebuild_normalized_cmd(tokens: list[str]) -> str:
        return " ".join(tokens)

    その再構築文字列を exact classifier と looks_like_skill_runtime_executor_command() に渡しています。

    これは不可逆変換です。例えば元のコマンドが次の場合、

    uv run --directory "/tmp/project with spaces" \
      python3 /repo/scripts/agent-guards/skill_runtime_exec.py \
      --command-id preflight.run ...

    最初の shlex.split() では "/tmp/project with spaces" は1トークンですが、" ".join(tokens) 後は引用符が消えます。その文字列を classifier 内で再度 shlex.split() すると、

    /tmp/project
    with
    spaces
    

    の3トークンになります。parser は with を script operand と誤認し、後方にある本物の skill_runtime_exec.py を見落とせます。

    Python 標準ライブラリには、token list を安全に文字列へ戻す逆変換として shlex.join() がありますが、最善策はそもそも文字列へ戻さず argv を直接渡すことです。 ([Python documentation]1)

    実際、Issue #1543 と PR #1558 はまさにこの問題を認識し、classifier を Sequence[str] 受け取りへ変更し、呼び出し側も normalized_cmd ではなく normalized_tokens を直接渡す修正を行っています。

    必要な修正

    • looks_like_skill_runtime_executor_command(command: str) の既存シグネチャ維持を撤回する
    • 少なくとも argv: Sequence[str], raw_command: str, cwd: str, project_root: str を入力にする
    • local_main_branch_guard.py を Allowed Paths に追加する
    • すべての consumer で tokens → join → split を禁止する

    この変更なしで AC1、AC3、AC4、AC6 を同時に満たすことはできません。


    Blocker 2 — cwd と project_root なしでは realpath 判定も uv --directory 判定も成立しない

    Issue は script operand の realpath 比較と、uv run --directory の正しい arity・実効 cwd 解決を要求しています。しかし現行関数の引数は command: str のみです。

    uv の --directory は単なる project 選択ではなく、実行前に作業ディレクトリを変更し、相対パスの基準もそのディレクトリへ変更します。 ([Astral Docs]2)

    したがって、例えば次の identity 判定には呼び出し時の cwd が必要です。

    uv run --directory ../other-root \
      python3 scripts/agent-guards/skill_runtime_exec.py

    hook payload の cwd と classifier プロセス自身の os.getcwd() が同一とは限りません。project_root も渡されなければ、次を区別できません。

    • 当該 repository の正規 skill_runtime_exec.py
    • 別 repository にある同名ファイル
    • --directory 適用後の相対パス
    • symlink 経由で正規 target に到達するパス

    参照実装側が tokens, cwd, project_root を受け取っているのは必須条件であり、実装上の便宜ではありません。


    Blocker 3 — 参照実装を移植すると、有効な CPython option で target 起動を回避できる

    参照実装の Python option parser は、値付き option を次の完全一致だけで処理しています。

    _PY_VALUE_FLAGS = {"-W", "-X", "--check-hash-based-pycs"}

    また、既知の完全一致 flag 以外の複数文字 short option は NOT_TARGET として処理します。

    ところが CPython は次の形式を正規に受け付けます。

    python3 -Wignore script.py
    python3 -Xdev script.py
    python3 -BE script.py

    公式 Python 3.12 ドキュメントも -Wignore を有効な形式として明記しています。CPython の getopt 実装も、short option を文字単位で走査し、値付き option では同一トークン内の残りを option argument として扱っています。 ([Python documentation]3)

    したがって、参照ロジックをそのまま使った場合、次が問題になります。

    python3 -Wignore \
      /repo/scripts/agent-guards/skill_runtime_exec.py \
      --command-id preflight.run \
      --issue-number 1565 \
      --repo squne121/loop-protocol

    現行参照実装上の推移は次のとおりです。

    1. -Wignore は _PY_VALUE_FLAGS の -W と一致しない
    2. 複数文字 short option なので NOT_TARGET
    3. 参照 classifier は NOT_TARGET に対して False
    4. 下流の is_tmp_wrapper_or_python_c_command() は -c / -m を含む option しか捕捉しない
    5. default branch 上では最終的に unknown command の default allow へ到達し得る

    NOT_TARGET → False という参照挙動と、下流 classifier の限定的な補完範囲はコード上確認できます。

    これは availability 上の過剰 block ではなく、実 target 起動の false-negativeです。

    AC に追加すべき必須ケース

    python3 -Wignore <target>
    python3 -W ignore <target>
    python3 -Xdev <target>
    python3 -X dev <target>
    python3 -BE <target>
    python3 -Ib <target>
    

    Python short-option grammar は「既知 token の集合」ではなく、option cluster と attached argument を解析する scanner として実装する必要があります。


    Blocker 4 — shell expansion 検出が不完全で、quote provenance も失っている

    参照実装の shell expansion 判定は次の4種だけです。

    re.compile(r"[$*?\[]")

    Bash が行う展開はこれだけではありません。公式 Bash manual では、brace expansion、tilde expansion、parameter expansion、command substitution、arithmetic expansion、word splitting、filename expansion、process substitution などが定義されています。 ([GNU]4)

    見逃しによる false-negative

    python3 /repo/scripts/{agent-guards,other}/skill_runtime_exec.py ...

    Bash は brace expansion により、最初の引数を次へ展開できます。

    /repo/scripts/agent-guards/skill_runtime_exec.py
    

    一方 classifier は { と } を dynamic syntax と認識せず、brace を含むリテラルパスに realpath を適用して非targetと判断できます。

    同様に次も未処理です。

    python3 ~/loop-protocol/scripts/agent-guards/skill_runtime_exec.py ...
    python3 ~+/scripts/agent-guards/skill_runtime_exec.py ...

    quote 消失による false-positive

    python3 '$PWD/scripts/agent-guards/skill_runtime_exec.py'

    単一引用符内の $PWD は Bash 上では完全なリテラルです。 ([GNU]5)

    しかし shlex.split() 後は引用符が消え、classifier が見る token は $PWD/... です。そのため $ を理由に UNSUPPORTED として block します。二重引用符では $ が展開されるため、同じ token 文字列でも意味が異なります。 ([GNU]6)

    つまり、tokenize 後の文字列だけでは次を区別できません。

    '$PWD/file.py'   # リテラル
    "$PWD/file.py"   # parameter expansion
    $PWD/file.py     # parameter expansion + word splitting 等

    必要な修正

    • raw command と token span、quote mode を保持する lexer を共有資産として実装する
    • dynamic operand を「文字集合」で判定せず、unquoted / double-quoted / single-quoted の文脈で分類する
    • brace と tilde を最低限カバーする
    • expansion 自体は実行せず、target になり得る dynamic operand を POSSIBLE_TARGET として block する

    Blocker 5 — bool 戻り値が「target identity」と「fail-closed policy」を混同している

    現在の関数名と意味は「skill-runtime executor に見えるか」です。しかし Issue は、target の証拠がない未対応 wrapper まで True にして block する設計を要求しています。

    参照実装では以下がすべて UNSUPPORTED です。

    • exec
    • time
    • timeout
    • basename が env
    • path-qualified uv

    この UNSUPPORTED → True を共有関数へ持ち込むと、例えば次が skill-runtime command と分類されます。

    time git status
    timeout 1 echo ok
    /usr/bin/env git status
    /usr/local/bin/uv --version

    これは Issue の目的である false-positive 削減と正面から衝突します。

    影響は local_main_branch_guard.py だけではありません。

    • local_main_branch_guard.py: True なら skill_runtime_guess として block

    • worktree_scope_guard.py: exact allow の直後に True なら skill_runtime_executor_denied

    • pretool_fastpath_classifier.py: exact parse 不能なら controlled executor shape とし、最終的に mutation_or_unknown

    「未解析なので安全側へ倒す」と「skill-runtime target の証拠がある」は別の事実です。1つの bool に畳み込んではいけません。

    推奨する戻り値は最低でも次の二軸です。

    class TargetEvidence(Enum):
        EXACT = "exact"
        POSSIBLE = "possible"
        NONE = "none"
    
    
    class ParseStatus(Enum):
        PARSED = "parsed"
        DYNAMIC = "dynamic"
        UNSUPPORTED = "unsupported"
        MALFORMED = "malformed"
    
    
    @dataclass(frozen=True)
    class LauncherClassification:
        target_evidence: TargetEvidence
        parse_status: ParseStatus
        script_operand: str | None
        effective_cwd: str
        reason_code: str

    policy は次のように分離すべきです。

    • EXACT / POSSIBLE target: skill-runtime 系 reason code で block
    • NONE + UNSUPPORTED: generic wrapper / unknown-command policy へ委譲
    • exact authorized invocation: broad deny より先に allow
    • malformed command: generic parse-failure reason で block

    高リスク指摘

    High 1 — import 再利用とロジック複製を「実装者裁量」にしてはいけない

    Issue Notes は、local_main_branch_guard.py の parser を import するか、skill_runtime_command_policy.py へ複製するかを実装者裁量にしています。

    しかし、local_main_branch_guard.py は既に skill_runtime_command_policy.py を top-level import しています。逆方向の top-level import は circular import になります。

    リポジトリ内には、別の classifier との circular import が import 順序によって恒久的な機能無効化を起こすため、lazy import にしたという説明も既にあります。

    一方、複製すると次が二重管理になります。

    • uv global option table
    • uv run option table
    • Python option grammar
    • wrapper taxonomy
    • dynamic shell syntax
    • cwd / realpath semantics

    必要な設計

    新しい中立モジュールを正本にします。

    scripts/agent-guards/launcher_command_classifier.py
    

    local_main_branch_guard.py と skill_runtime_command_policy.py の双方がこれを import する構造にすべきです。現在の Allowed Paths では実現できません。


    High 2 — uv の静的 grammar table と、配布される uv のバージョンが同期していない

    参照実装の _UV_RUN_BOOL_FLAGS / _UV_RUN_VALUE_FLAGS は固定テーブルです。

    一方、現在の uv CLI には、参照表にない次の option が既にあります。

    • --active
    • --all-groups
    • --managed-python
    • --module, -m
    • --no-managed-python
    • --no-progress
    • --no-index

    ([Astral Docs]2)

    未知 option を fail-closed にするため直接の bypass にはなりにくいものの、uv 更新後に正当な invocation が突然 block される availability regression を生みます。特に uv run -m module は「script operand」の意味自体を変更します。

    リポジトリの composite action は astral-sh/[email protected] を使っていますが、uv binary の version input は設定していません。root pyproject.toml にも required-version はありません。

    setup-uv は、version や required-version が見つからない場合、最新 uv をインストールします。 ([GitHub]7)

    安全境界として静的 option table を使うなら、次が必要です。

    [tool.uv]
    required-version = "==<検証済みバージョン>"

    uv 自身も required-version による実行時バージョン制約を提供しています。 ([Astral Docs]8)

    加えて、GitHub Actions の第三者 action は tag ではなく full-length commit SHA へ pin すべきです。GitHub は full SHA を immutable release として使用する唯一の方法と説明しています。 ([GitHub Docs]9)

    setup-uv の公式例に合わせれば、少なくとも次の形になります。

    uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0

    この hardening は Issue #1565 に含めるか、parser 実装の前提 Issue として先行させるべきです。


    Issue 契約・検証コマンドの欠陥

    1. Runtime Verification Applicability が欠落している

    リポジトリの SSOT は、全 Issue に次のいずれかを明示することを要求しています。

    not_applicable | immediate | deferred
    

    プロセス起動や実 argv 判定を扱う場合は immediate が妥当です。

    Issue #1543 には runtime verification 定義がありましたが、#1565 にはありません。単体 helper テストだけでなく、実 hook payload と実 command string を通した証跡が必要です。

    2. AC1 の Verification Command は成功条件と exit status が逆

    現在の AC1 は次です。

    grep -c "in (command or" scripts/agent-guards/skill_runtime_command_policy.py

    期待値が「該当コードが消えている」なら、出力は 0 ですが grep の exit status は 1 です。GNU grep は一致なしを status 1 と定義しています。 (GNU)

    少なくとも次へ変更すべきです。

    ! grep -Fq 'in (command or' \
      scripts/agent-guards/skill_runtime_command_policy.py

    ただし、source text grep は設計検証として弱すぎます。別の substring 実装へ書き換えるだけで通るため、AC1 は behavior test に統合すべきです。

    3. テストパスと Allowed Paths が自己矛盾している

    Issue は Verification Commands で次を指定しています。

    .claude/skills/issue-refinement-loop/tests/test_skill_runtime_command_policy.py
    .claude/skills/issue-refinement-loop/tests/test_local_main_branch_guard.py
    

    一方で Notes は「存在しない場合は既存テストファイルを探索し、別ファイルへ追加してよい」としています。しかし Allowed Paths は前者の test_skill_runtime_command_policy.py しか許可していません。

    現行の関連テスト資産は少なくとも次の場所にあります。

    • .claude/hooks/tests/test_worktree_scope_guard.py

    • .claude/hooks/tests/test_local_main_branch_guard.py

    • scripts/agent-guards/tests/test_skill_runtime_command_policy_anchor.py

    • tests/codex/test_local_main_branch_guard.py

    実装者が Notes に従うと Allowed Paths 違反になり、Allowed Paths に従うと consumer parity を検証できません。

    4. AC6 が consumer inventory を満たしていない

    共有関数の consumer は少なくとも次の3系統です。

    1. local_main_branch_guard.py
    2. .claude/hooks/worktree_scope_guard.py
    3. pretool_fastpath_classifier.py

    AC6 は local-main のみを対象としています。戻り値の意味を変えないという要件なら、3 consumer 全てについて分類結果と最終 verdict の非回帰が必要です。


    推奨する Issue 再定義

    最小安全分割

    Issue A — 共有 launcher parser の抽出と invocation contract 移行

    対象:

    scripts/agent-guards/launcher_command_classifier.py
    scripts/agent-guards/local_main_branch_guard.py
    scripts/agent-guards/skill_runtime_command_policy.py
    .claude/hooks/worktree_scope_guard.py
    scripts/agent-guards/pretool_fastpath_classifier.py
    各 consumer の正本テスト
    

    保証:

    • argv boundary を一切再構築しない
    • raw command の quote context を保持する
    • cwd / project_root / effective cwd を明示入力とする
    • Python short-option cluster と attached value を解析する
    • uv grammar の対応バージョンを宣言する
    • identity classification と fail-closed policy を分離する

    Issue B — skill-runtime target predicate の置換

    保証:

    • 引数値中の mention は TargetEvidence.NONE
    • canonical path、絶対パス、相対パス、symlink alias は EXACT
    • dynamic expansion で target になり得るものは POSSIBLE
    • target evidence のない wrapper unsupported は skill-runtime と分類しない
    • exact authorized command の allow 順序は維持する

    Issue C — uv / GitHub Actions toolchain pin

    保証:

    • uv binary version を固定
    • option table の対応 uv version をコード定数化
    • pinned uv の uv run --help と parser table の整合テスト
    • setup-uv を full commit SHA pin
    • Dependabot 等で更新PRを生成

    最低限必要な敵対的テスト行列

    分類 入力例 必須結果
    引数値のみ other.py --allowed-paths '[".../skill_runtime_exec.py"]' skill-runtime target ではない
    canonical target python3 scripts/agent-guards/skill_runtime_exec.py ... block
    attached Python value python3 -Wignore <target> ... block
    separated Python value python3 -W ignore <target> ... block
    Python cluster python3 -BE <target> ... block
    -X attached python3 -Xdev <target> ... block
    token boundary uv run --directory "/tmp/a b" python3 <absolute-target> block、境界維持
    現行uv flag uv run --active --managed-python python3 <target> block
    uv module uv run -m some.module script target と区別
    unrelated wrapper time git status skill-runtime target ではない
    target wrapper time python3 <target> generic または target-specific reason で block
    brace expansion python3 /repo/scripts/{agent-guards,x}/skill_runtime_exec.py dynamic possible target として block
    tilde expansion python3 ~/repo/scripts/agent-guards/skill_runtime_exec.py dynamic possible target として block
    quoted literal python3 '$PWD/skill_runtime_exec.py' expansion と誤認しない
    malformed arity uv run --directory malformed / fail-closed
    consumer parity 同一入力を local-main / worktree / fastpath に投入 定義済みの一貫した分類
    frontend parity Claude hook / Codex event fixture 最終 verdict 一致
    exact allow 正規 authorized executor invocation 従来どおり allow

    結論

    Issue #1565 の狙いは正しいものの、現状は参照実装の表面的な移植になっており、PR #1558 で重要だったcaller の argv 移行を Out of Scope に戻してしまっています。

    特に次の2件は、実装上の nit ではなく安全性を破る blocker です。

    • " ".join(tokens) 後の再tokenizeによる argv boundary 消失
    • -Wignore、-Xdev、-BE など正規 CPython option による target 検出回避

    したがって、現Issueをそのまま実装するのではなく、共有 parser 抽出・consumer contract 移行・toolchain pin を先に契約化し、#1565 をその後段の predicate migration に縮小するのが妥当です。現状の判定は REQUEST_CHANGES / implementation not ready です。

  3. squne121 commented on Jul 18, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. changed the title [-]実装: skill_runtime_command_policy.py の looks_like_skill_runtime_executor_command() を argv-aware classifier に置き換える[/-] [+]実装: skill-runtime target predicate を Issue #1595 の共有 launcher classifier ベースに置換する[/+] on Jul 18, 2026
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/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions