Repository navigation
Closed
2 / 22 of 2 issues completed
Copy link
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "agent-skill-runtime-hook-relaxation"
change_kind: workflow
dedupe_key: "hooks:skill-runtime-exact-preflight-executor:issue-refinement-loop"Parent Issue
none
Parent Goal Ref
- Goal: AI agent の skill 実行経路を、security hook を無効化せずに通せるようにする。
- Desired Destination: root checkout 上の PreToolUse guard が、広い registry-backed allow ではなく、deny-by-default の privileged command class と単一 executor を通じて
issue-refinement-loopのpreflight.runだけを安全に実行できる状態。
Current Validated Scope
scripts/agent-guards/skill_runtime_command_policy.pyに deny-by-default のSKILL_RUNTIME_COMMAND_POLICY_V2を定義するscripts/agent-guards/skill_runtime_exec.pyを新規作成し、preflight.run専用の privileged executor を実装する.claude/hooks/worktree_scope_guard.pyにskill_runtime_exec.py --command-id preflight.run ...の exact command class 判定を追加するscripts/agent-guards/local_main_branch_guard.pyを更新し、同じ exact command class / reason code を consume する.claude/skills/issue-refinement-loop/scripts/command_registry.pyのpreflight.runentry を executor 契約と矛盾しない最小形へ調整する.claude/settings.jsonにskill_runtime_exec.pyと最小補助 script だけを permission allowlist 追加する.claude/hooks/tests/test_worktree_scope_guard.pyと.claude/hooks/tests/test_local_main_branch_guard.pyに exact command / negative fixture の実 hook 経路テストを追加するtests/codex/test_local_main_branch_guard.pyに exact executor 契約へ揃える Codex parity expectation を追加する.github/ci/python-test-plan.jsonとgenerate_ci_test_selection_artifact.pyを更新し、dedicated codex execpolicy lane で実行されるtests/codex/test_local_main_branch_guard.pyをci_test_selectionの未カバー変更として誤判定しないよう整合させる.claude/artifacts/context-mode/fetch-strict-negative-test.jsonを current HEAD に同期し、python-test lane の tracked artifact freshness を維持するdocs/dev/agent-skill-boundaries.mdに privileged skill runtime command boundary を追記する
Remaining Parent Gaps
build_refinement_phase_state.py/reviewer_claim_replay.py/compact_review_result.py/compact_author_result.pyの root allow 拡張は別 Issue- producer output budget / schema mismatch / termination bypass の fail-closed 強化は別 Issue
publish_termination_report.pyの mutation-capable root allow は別 Issue- registry の追加 command ID を privileged set に広げる場合は command ごとに別 Issue で扱う
Outcome
root checkout 上の worktree_scope_guard.py と local_main_branch_guard.py が、preflight.run 専用の単一 executor command class だけを許可し、repo / active issue / artifact subtree に束縛された実 hook 経路テスト付きで標準ゲートを PASS している状態。
In Scope
preflight.runだけを対象にした privileged exact command class の導入- deny-by-default policy と単一 executor による root 実行認可
- repo / active issue / artifact subtree binding の導入
- Claude/Codex guard parity の維持
- positive / negative の実 PreToolUse hook テスト
- Codex parity test expectation の同期
- dedicated codex lane と
ci_test_selectionの coverage parity 維持 - python-test lane で検証される tracked context-mode artifact の current-head freshness 維持
- settings / docs / validator 対応の最小同期
Out of Scope
mutation: falseを根拠にした registry 全件自動許可preflight.run以外の skill runtime command の root allow.claude/skills/**/*.pyの blanket allowbuild_refinement_phase_state.py/reviewer_claim_replay.py/compact_review_result.py/compact_author_result.pyの root allow- producer output budget / schema mismatch / termination bypass の修正
publish_termination_report.pyの root allow 拡張- security hook の disable / bypass
python -c・bash -lc・inline env・uv --with・/tmpscript の許可
Acceptance Criteria
- AC1:
scripts/agent-guards/skill_runtime_command_policy.pyが新規追加され、preflight.run専用の deny-by-default policy module として導入されている - AC2: policy は
mutation: falseを認可根拠に使わず、execution_class/required_cwd/required_branch/allowed_write_roots/network_effectを command ID ごとに明示する - AC3:
scripts/agent-guards/skill_runtime_exec.pyが--command-id preflight.run --issue-number <active> --repo <canonical>の exact argv だけを受け付け、subprocess.run(..., shell=False)で registry command を実行する - AC4:
scripts/agent-guards/skill_runtime_exec.pyが executor として新規追加され、repo == canonical origin repositoryとissue_number == resolved active issueを実行前に検証する - AC5:
scripts/agent-guards/skill_runtime_exec.pyが.claude/artifacts/issue-refinement-loop/<active_issue>/外への出力、absolute path、..、symlink substitution、PYTHONPATHshadowing、/tmpscript substitution を fail-closed で拒否する - AC6:
.claude/hooks/worktree_scope_guard.pyは active issue worktree 存在下でも、skill_runtime_exec.pyの exact command class に一致するpreflight.runだけを root cwd から allow し、prefix match や registry 全件自動許可を行わない - AC7:
scripts/agent-guards/local_main_branch_guard.pyは同じ exact command class / reason code を consume し、独自 allowlist との split-brain を作らない - AC8:
uv.pytest、pnpm.typecheck、pnpm.lint、pnpm.test、pnpm.build、gh.*、未登録 script、unknown flag、duplicate flag、newline / chain / pipe / redirect / inline env /bash -lc/python -c/uv --withは negative fixture で deny される - AC9: 実 PreToolUse hook 経路テストが、temp repo + real issue worktree +
LOOP_ISSUE_NUMBER+ cwd=root でskill_runtime_exec.py --command-id preflight.run ...の allow を確認する - AC10: 実 PreToolUse hook 経路テストが、root drift / detached root / no-active-worktree / wrong repo / wrong issue / wrong artifact subtree を fail-closed で検出する
- AC11:
.claude/settings.json、policy、executor、docs、tests の eligible command 集合がpreflight.runのみで一致し、wildcard allow を追加しない - AC12:
publish_termination_report.pyと producer output budget / schema mismatch / termination bypass が本 Issue の許可対象外であることが本文と docs に明記されている - AC13: 標準ゲートが PASS する
- AC14: dedicated codex execpolicy lane で実行される
tests/codex/test_local_main_branch_guard.pyの変更が、ci_test_selectionartifact generator で fail-closed のuncovered_changed_test_filesと誤判定されず、python-test / node-backed-hook-tests の lane split 契約を壊さない
Verification Commands
# baseline-expect: fail
# AC1
$ test -f scripts/agent-guards/skill_runtime_command_policy.py
# baseline-expect: fail
# AC2
$ rg -n "execution_class: exact_skill_runtime" docs/dev/agent-skill-boundaries.md
# baseline-expect: fail
# AC3
$ test -f scripts/agent-guards/skill_runtime_exec.py
# baseline-expect: fail
# AC4
$ test -f scripts/agent-guards/skill_runtime_exec.py
# baseline-expect: fail
# AC5
$ test -f scripts/agent-guards/skill_runtime_exec.py
# baseline-expect: fail
# AC6
$ rg -n "_is_skill_runtime_executor_command" .claude/hooks/worktree_scope_guard.py
# baseline-expect: fail
# AC7
$ rg -n "_is_skill_runtime_executor_command" scripts/agent-guards/local_main_branch_guard.py
# baseline-expect: fail
# AC8
$ rg -n "def test_skill_runtime_executor_negative" .claude/hooks/tests/test_worktree_scope_guard.py
# baseline-expect: fail
# AC9
$ rg -n "def test_skill_runtime_executor_allows_preflight_run" .claude/hooks/tests/test_worktree_scope_guard.py
# baseline-expect: fail
# AC10
$ rg -n "def test_skill_runtime_executor_blocks_wrong_issue_context" .claude/hooks/tests/test_local_main_branch_guard.py
# baseline-expect: fail
# AC11
$ rg -n "skill_runtime_exec.py" .claude/settings.json
# baseline-expect: fail
# AC12
$ rg -n "producer output budget / schema mismatch / termination bypass" docs/dev/agent-skill-boundaries.md
# baseline-expect: fail
# AC14
$ rg -n "dedicated_lanes_excluded" .github/ci/python-test-plan.json
$ rg -n "cross_job_covered_test_files" .claude/skills/pr-review-judge/scripts/generate_ci_test_selection_artifact.py
# AC13
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildRuntime Verification Applicability
- decision: not_applicable
- reason: 本 Issue は hook / guard / settings / docs / pytest harness の静的変更で完結し、実行時プロセス疎通や外部サービス接続を前提にした runtime AC を要求しない
Allowed Paths
.claude/settings.json.claude/hooks/worktree_scope_guard.py.claude/hooks/worktree_scope_guard.sh.claude/hooks/tests/test_worktree_scope_guard.py.claude/hooks/tests/test_local_main_branch_guard.pytests/codex/test_local_main_branch_guard.py.github/ci/python-test-plan.json.claude/artifacts/context-mode/fetch-strict-negative-test.jsonscripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/skill_runtime_command_policy.pyscripts/agent-guards/skill_runtime_exec.py.claude/skills/issue-refinement-loop/scripts/command_registry.py.claude/skills/pr-review-judge/scripts/generate_ci_test_selection_artifact.py.claude/skills/pr-review-judge/tests/test_generate_ci_test_selection_artifact.py.claude/skills/pr-review-judge/scripts/tests/test_generate_ci_test_selection_fail_close.pydocs/dev/agent-skill-boundaries.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
preflight.run以外の command ID を同一 PR に含める必要が出た場合- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- security hook の disable / bypass が必要になった場合
repo/issue_number/ artifact subtree binding を executor で保証できないと判明した場合- registry を forward renderer のまま reverse matcher として使わないと成立しないと判明した場合
publish_termination_report.pyも同時に root allow しないと完走不能であると判明した場合
Required Skills
- Python 3(hooks / guard / executor 実装)
- PreToolUse hook 経路理解(exact command class / fail-closed 判定)
- pytest adversarial harness(temp repo / worktree fixture / subprocess stdin JSON)
Scope Delta(任意)
N/A
Delivery Rule
1 Issue = 1 PR。worktree: worktree-issue-{N}-skill-runtime-exact-preflight-executor。Draft PR で起票。
Sub-issues
Collapse Sub-issuesSub-issues
Loading 2 sub-issues
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 25, 2026
判定
REQUEST_CHANGES — 現行の Issue contract のまま実装すべきではありません。
#1154 の目的自体は妥当です。しかし、
command_registry.pyの運用メタデータをそのまま PreToolUse の認可根拠へ昇格させており、#1137/PR #1139/PR #1143 で確立した「完全一致 command class・単一 executor・実 hook 経路テスト」という境界を再び緩める設計になっています。確認時点で #1154 自体にはレビューコメントがなく、対応PRも見当たりません。P0-1:
mutation: falseは認可属性として使用できないIssue の中心条件は、概ね次です。
mutation: falsecwd_policy: repo_rootしかし現行 registry には、同じ条件を満たす以下のコマンドがあります。
uv.pytestpnpm.typecheckpnpm.lintpnpm.testpnpm.buildすべて
mutation: false、cwd_policy: repo_rootです。これらは「非破壊コマンド」ではありません。
PYTEST_PLUGINS、対象パス配下と親ディレクトリのconftest.pyをロードしてPythonコードを実行します。(pytest)package.json内の任意コマンドを実行し、既定で pre/post scripts も実行します。(pnpm)uv runは任意コマンドをproject environmentで起動でき、実行前に環境を最新状態へ同期します。--withによる追加依存の取得やbash実行も可能です。([Astral Docs]3)したがって、Issue記載の選択条件を一般化すると、active worktree が存在する状態で main root 上のproject-controlled code execution を許可する経路になります。
必須修正
mutationとは別に、認可専用のdeny-by-default属性を導入してください。以下は明示的に認可対象外に固定すべきです。
mutation: falseは、必要ならremote_mutation: falseやgithub_mutation: falseに改名し、ローカルファイル副作用を意味しないことを明示する必要があります。P0-2: 対象スクリプト自体がroot checkoutへ書き込む
「non-mutating skill runtime command」という前提が実装と一致していません。
run_refinement_preflight.pyはGitHub APIを読み、root配下の.claude/artifacts/issue-refinement-loop/<issue>/に3種類のartifactを書きます。build_refinement_phase_state.pyは利用者指定の任意の--output-pathに対して親ディレクトリを作成し、JSONを書き込みます。containment制約がありません。reviewer_claim_replay.pyは任意の--state-fileに親ディレクトリを作成して状態を書き込みます。compact_review_result.pyのcontainment検証は--repo-rootが指定された場合だけです。一方、公開CLIでは--artifact-dirが任意指定可能で、--repo-rootはoptionalです。完全一致するscript pathだけを検査しても不十分です。引数値が書込み能力そのものになっています。
必須修正
各placeholderへ能力ベースの型を導入してください。
最低限、次を検査する必要があります。
--repoはGit remoteから解決した当該repositoryと一致--issue-numberは現在解決済みのactive issueと一致..、absolute pathを拒否--artifact-dir、--repo-root、--state-fileなどを利用者が自由指定できない現行の
repo_relative_fileはabsolute path、..、NUL/改行、leading dashを拒否するだけで、artifact subtreeやsymlinkを認可境界にしていません。P0-3: Issueの対象コマンドとregistryが矛盾している
#1154 は6スクリプトをpermission対象として挙げていますが、現行registryに該当するcommand IDがあるのは主に次の2件です。
run_refinement_preflight.py→preflight.rundecide_next_loop_action.py→decide.run一方、以下はregistry未登録です。
build_refinement_phase_state.pyreviewer_claim_replay.pycompact_review_result.pycompact_author_result.pyregistryには逆に、Issueの6スクリプトに含まれていない
plan.runや汎用テスト・ビルドコマンドが存在します。さらに
preflight.runのregistry entryには--issue-numberと--repoしかなく、実スクリプトがサポートする--anchor-comment-urlやfixture経路が表現されていません。decide.runには別の問題があります。max_iterationsとphase_state_fileはoptional指定ですが、argv template内には常にplaceholder tokenが存在します。現行rendererはoptional値が未指定でもそのtokenを削除せず、{max_iterations}のようなliteralを残し得ます。必須修正
最初のPRは
preflight.run1件だけ に限定するのが妥当です。その後、各スクリプトについて以下を完了してからeligible setへ追加してください。
registry全件を自動的に認可対象にする設計は禁止すべきです。
P0-4: registryはforward rendererであり、認可用reverse matcherではない
guardが受け取るのは任意のBash文字列です。一方、
command_registry.pyはplaceholderからargvを生成するforward rendererです。任意のshell入力がregistry entryと完全一致することを安全に逆算する契約はありません。特に現行の
validate_shell_string()はregistry membershipを証明しません。gitghcurlnpmmkdirなどを既知executableとして許可しています。
その後の検証もshell operatorを拒否し、先頭tokenが既知executableかを確認するだけです。したがって、この関数単独では、例えば
git reset --hardやmutation系のghcommandも「構文上ok」となり得ます。Python公式ドキュメントも、
shlexはshellの完全なparserではなく、返されたtokenのsemantic validationは利用側で実装する必要があるとしています。可能ならargv listをshell=Falseで渡すことが推奨されています。([Python documentation]4)またBashでは改行がsemicolonと同等のcommand delimiterです。([GNU]5)
これは過去の仮説上の懸念ではありません。PR #1139 のOWNERレビューでは改行によるcommand追加や未検証argvが実際にblockerとなり、PR #1143では以下へ再設計されています。
([GitHub]6)
#1154 はこの先行設計を一般化するのではなく、緩和してしまっています。
推奨アーキテクチャ: 単一のprivileged executor
guardから個別skill scriptを直接allowするのではなく、#1137と同様に、認可境界を1つのexecutorへ集約すべきです。
guardが認識するのはこのcommand classだけとします。
skill_runtime_exec.pyの責務は次です。subprocess.run(argv, shell=False, cwd=root, env=sanitized_env)で実行command_registry.pyを通常のmodule名でimportする設計も避けるべきです。#1089では/tmpwrapperとstaleな/tmp/command_registry.pyの混入が実際の回帰原因になっています。最善はregistryを副作用のないJSON/TOMLへ分離することです。Python moduleを使う場合でも、公式の
spec_from_file_location()相当でcanonical absolute pathからロードし、spec.origin/__file__の一致を検査し、load失敗時はdenyしてください。([Python documentation]7)P1:
repoとissue_numberがcontextへbindingされていない現行placeholder validatorは、
repoがowner/name形式であること、issue numberが正数であることしか検証しません。このままでは、active issueが1154でも次のような別repository/別issueのpreflightがrootから実行できます。
これは直接的なshell injectionではありませんが、外部のissue本文・コメントをplanner inputとartifactへ取り込み、workflow contextを汚染する経路です。#1154が掲げる「重複調査・コンテキスト汚染の削減」と逆行します。
以下を固定してください。
P1: Claude/Codexの実行モデルをIssueに明記すべき
Claude Codeでは、PreToolUseは実行前にblockできますが、exit 0かつ無出力は明示的allowではなく、通常のpermission flowへ戻るだけです。したがって
.claude/settings.jsonのallow ruleは操作性レイヤー、hook/executorは認可レイヤーとして分離する必要があります。([Claude API Docs]8)また、Claude Codeのmatching hooksは並行実行され、current directoryとClaude Code環境を引き継ぎます。hook定義自体は、可能なら
argsを使用するexec formにし、guard起動部分からshell解釈を排除すべきです。([Claude API Docs]8) ([Claude API Docs]8)Codex側では、matching command hooksが並行起動され、PreToolUseは公式にも「完全なenforcement boundaryではない」とされています。すべてのshell/非shell経路を捕捉するものではありません。([OpenAI Developers]9) ([OpenAI Developers]9)
したがってIssueの安全性主張は、次に限定すべきです。
「root isolationを完全に保証する」「sandboxになる」といった主張は不正確です。
P1: AC11/AC12は別Issueへ分割すべき
output_budget_violation、schema_mismatch、termination bypassは重要ですが、guard認可とは別のproducer/publisher契約です。現状のAllowed Pathsには対象producerの実装ファイルが含まれていないため、テストで実装不備を発見しても同じPRで修正できません。結果としてmockだけを満たすhollow testになりやすく、Stop Conditionにも抵触します。
次の2件へ分離するのが妥当です。
本Issue
exact skill runtime authorization、guard parity、settings、registry drift
follow-up Issue
producer output budget、schema mismatch fail-closed、termination publisher bypass防止
Issue本文へ追加すべきAcceptance Criteria
最低限、以下へ差し替えるべきです。
preflight.runのみで、registry全件からの自動選択を禁止するmutation:falseは認可根拠として使用せず、独立したdeny-by-default policyでcommand IDを列挙するrepo、issue_number、artifact slotは実repository/active issueと一致するbash -lc、python -c、uv --with、未知uv optionを拒否するPYTHONPATHshadowing//tmpsubstitutionを拒否するuv.pytest、全pnpm.*、gh.*、未登録scriptは明示的negative fixtureでdenyする最終結論
#1154 は必要な改善ですが、現在のcontractは認可境界を広げすぎています。
mutation:falsefilterではなく、明示的なprivileged subset+単一executor+effect/path binding を中心にIssueを書き直した後でのみ着手可能、と判断します。[-]実装: hooks: registry-backed skill runtime command を PreToolUse guard で実行可能にする[/-][+]実装: hooks: preflight.run 専用 privileged executor を root checkout から安全実行可能にする[/+]squne121 commentedon Jun 25, 2026
Contract Review Result
fix: codex parity for skill runtime executor (#1154)
fix: cover dedicated codex lane in ci selection (#1154)
fix(ci): resolve python-test-plan conflict for #1154
fix(hooks): allow legal preflight placeholders (#1154)
fix(hooks): harden preflight executor boundary (#1154)
fix(hooks): remove unused artifact root binding (#1154)
test(context-mode): refresh fetch strict artifact (#1154)
feat(hooks): preflight.run 専用 skill runtime executor を root guard に追加 (…
docs(agent-skill-boundaries): document issue-refinement-loop producer…
fix(issue-refinement-loop): add fail-closed routing to compact produc…