Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "issue-refinement-loop の control-plane(planner/preflight) が local root default branch から起動できず planner SSOT routing を bypass せざるを得ない friction を解消する"
change_kind: codeParent Issue
none
Parent Goal Ref
- Goal: N/A(単独改善のため parent tracker なし)
- Desired Destination: N/A
Current Validated Scope
scripts/agent-guards/skill_runtime_command_policy.pyのis_exact_skill_runtime_executor_commandから read-onlypreflight.runの worktree binding とactive_issue_worktree_missing前提を外す。ただし issue-number は exact argv から取り、resolve_active_issue()の汎用 semantics は変更しないscripts/agent-guards/skill_runtime_exec.pyの_validate_runtime_contextを read-onlypreflight.run用に修正し、canonical root / default branch / repo binding / artifact-only write は維持しつつ worktree 要求を外す- real PreToolUse hook chain で must-allow(no-worktree / no-env の preflight allow)と must-block(direct preflight・非 exact argv・mutation・artifact 外 write)を検証する adversarial harness を
scripts/agent-guards/tests/に追加する local_main_branch_guardとworktree_scope_guardの両方で no-worktree read-onlypreflight.runが split-brain なく扱われることを確認し、必要なら同一 exact executor 契約で parity 修正する- 既存 guard テスト(
.claude/hooks/tests/test_local_main_branch_guard.py/tests/codex/test_local_main_branch_guard.py/.claude/hooks/tests/test_worktree_scope_guard.py)へ no-worktree allow ケースを反映する - reviewer 指摘に対応するため
docs/dev/agent-skill-boundaries.mdを 実装: issue-refinement-loop の control-plane を local root から起動できない guard 前提を read-only preflight profile で解消する #1228 の no-worktree read-only preflight 仕様へ同期する
Remaining Parent Gaps
- 改善: post-merge-cleanup-worker が root checkout で local_main_branch_guard にブロックされ機能しない #1147(post-merge-cleanup の git mutation 経路)は本 Issue の対象外であり別途継続する
- 他 control-plane skill の root 起動 friction は本 Issue の
preflight.runprofile を前例として個別対応する
Outcome
skill_runtime_command_policy.py と skill_runtime_exec.py が修正され、main session(local root checkout・default branch・対象 issue の linked worktree 無し・LOOP_ISSUE_NUMBER 未設定)から exact command uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number <N> --repo squne121/loop-protocol を実行したとき、real PreToolUse hook chain で local_main_branch_guard と worktree_scope_guard が block せず refinement preflight が read-only で起動する状態。must-block 不変条件(direct run_refinement_preflight.py ブロック維持・非 exact argv ブロック維持・mutation/compound ブロック維持・repo tree outside allowed artifact root への write fail-close 維持)は保持され、real PreToolUse hook chain を用いた adversarial harness(must-allow / must-block 両軸)が PASS した PR がマージされた状態。
In Scope
preflight.runだけに限定して、is_exact_skill_runtime_executor_command/_validate_runtime_contextから worktree 存在要求(active_issue_worktree_missing)とLOOP_ISSUE_NUMBERenv 一致要求を外す- canonical root / default branch / repo binding / exact argv /
network_effect: github_read_only/ artifact-only write の各不変条件は維持する - 実 hook 経路(stdin JSON を渡した real PreToolUse chain)で must-allow(no-worktree / no-env の
preflight.run)と must-block(direct preflight・非 exact argv・mutation/compound・wrong repo・artifact root 外 write)の両軸を検証する adversarial harness 追加 .claude/hooks/worktree_scope_guard.py/.claude/hooks/tests/test_worktree_scope_guard.pyについて、既存 exact skill runtime executor command class が no-worktree / no-env のpreflight.runを block しないことを確認し、必要なら同一 reason code / 同一 parser contract で parity 修正する- 既存 guard テスト(
.claude/hooks/tests/test_local_main_branch_guard.py/tests/codex/test_local_main_branch_guard.py/.claude/hooks/tests/test_worktree_scope_guard.py)の no-worktree allow ケース反映と回帰維持 docs/dev/agent-skill-boundaries.mdの Privileged Skill Runtime Command Boundary を 実装: issue-refinement-loop の control-plane を local root から起動できない guard 前提を read-only preflight profile で解消する #1228 の最終仕様に同期する
Out of Scope
local_main_branch_guardの root mutation 防止方針そのものの撤廃(main 保護は維持)- post-merge-cleanup の git mutation 経路修正(改善: post-merge-cleanup-worker が root checkout で local_main_branch_guard にブロックされ機能しない #1147 の責務)
- agent-ops cleanup_exec 機械化(実装: guard arbitration preflight と cleanup contract delivery を機械化する (agent-ops) #1137 の責務)
issue-refinement-loopの planner/reviewer 判定ロジック変更(thin entrypoint 原則維持)- mutation を伴う refinement 経路の変更(Issue 本文 edit は既存の
gh issue edit --body-file tmp/...allow で対応済み) preflight.run以外の command_id を worktree-free allow する policy 拡張
Acceptance Criteria
- AC1a: 対象 issue の linked worktree 不在かつ
LOOP_ISSUE_NUMBER未設定でも、canonical root / default branch / exactpreflight.runが real PreToolUse hook chain のlocal_main_branch_guard経路で allow される - AC1b: 同条件の exact
preflight.runが real PreToolUse hook chain のworktree_scope_guard経路でも block されない - AC1c: direct
uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py --issue-number 1228 --repo squne121/loop-protocolは root から block され続ける - AC1d: non-exact executor argv(
--command-id相違、余剰 / 欠落 / 重複フラグ、--flag=value、leading env、metachar、wrong repo、non-default branch、detached HEAD)は block される - AC1e:
skill_runtime_exec.pyの child が.claude/artifacts/issue-refinement-loop/1228/外へ write した場合、artifact-only write postcondition が fail-close する - AC2: 既存 claude hook guard テスト
.claude/hooks/tests/test_local_main_branch_guard.pyが回帰なく PASS する - AC3: 既存 codex guard テスト
tests/codex/test_local_main_branch_guard.pyが回帰なく PASS する - AC4:
uv run pytest .claude/hooks/tests/test_worktree_scope_guard.py -k "skill_runtime_executor" -vが PASS する - AC5:
pnpm typecheckが PASS する - AC6:
pnpm lintが PASS する - AC7:
pnpm testが PASS する - AC8:
pnpm buildが PASS する
Verification Commands
# AC1a
# baseline-expect: deferred
$ uv run pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py -k "local_main_branch_guard" -v
# AC1b
# baseline-expect: deferred
$ uv run pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py -k "worktree_scope_guard" -v
# AC1c
# baseline-expect: deferred
$ uv run pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py -k "direct_preflight_block" -v
# AC1d
# baseline-expect: deferred
$ uv run pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py -k "non_exact_executor_argv" -v
# AC1e
# baseline-expect: deferred
$ uv run pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py -k "artifact_only_write_postcondition" -v
# AC2
# baseline-expect: pass
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -v
# AC3
# baseline-expect: pass
$ uv run pytest tests/codex/test_local_main_branch_guard.py -v
# AC4
# baseline-expect: pass
$ uv run pytest .claude/hooks/tests/test_worktree_scope_guard.py -k "skill_runtime_executor" -v
# AC5
# baseline-expect: pass
$ pnpm typecheck
# AC6
# baseline-expect: pass
$ pnpm lint
# AC7
# baseline-expect: pass
$ pnpm test
# AC8
# baseline-expect: pass
$ pnpm buildRuntime Verification Applicability
decision: immediate
applicable_acs:
- AC1a
- AC1b
- AC1c
- AC1d
- AC1e
execution_environment:
cli_tools:
- python3
- uv
- git
auth_required: false
network_required: false
skip_conditions:
- "local repository checkout が存在しない場合は SKIP ではなく environment blocked として扱う"
- "real PreToolUse hook chain を subprocess で再現できない場合は PASS 扱いせず block として扱う"
fallback_policy:
fallback_success_is_pass: false
notes: "関数直接呼び出しや簡略ハーネス成功を runtime AC PASS に変換しない"
artifact_requirements:
- "scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py の pytest 出力"
- ".claude/hooks/tests/test_local_main_branch_guard.py の pytest 出力"
- ".claude/hooks/tests/test_worktree_scope_guard.py -k \"skill_runtime_executor\" の pytest 出力"
reason: PreToolUse guard の判定挙動を変更するため、real hook chain(stdin JSON・実 git 状態: default branch root / worktree 不在)での allow/block 検証が必須。local_main_branch_guard だけでなく worktree_scope_guard との parity も実経路で確認しないと split-brain を見落とす。Allowed Paths
- scripts/agent-guards/skill_runtime_command_policy.py
- scripts/agent-guards/skill_runtime_exec.py
- scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py
- .claude/hooks/worktree_scope_guard.py
- .claude/hooks/tests/test_worktree_scope_guard.py
- .claude/hooks/tests/test_local_main_branch_guard.py
- tests/codex/test_local_main_branch_guard.py
- docs/dev/agent-skill-boundaries.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
preflight.run以外の command_id を worktree-free allow する必要が判明した場合resolve_active_issue()の汎用 semantics を変更しないと成立しない場合local_main_branch_guard/worktree_scope_guardの allow 判定が一致しない場合- read-only 前提を外すことで mutation 経路の allow が混入するなど security 境界の後退が判明した場合
- codex parity(
tests/codex/)の修正が非自明に大きくなり別 Issue 分離が妥当と判明した場合
Required Skills
なし
Scope Delta(任意)
- reviewer comment #4825999581 に対応し、仕様同期用に
docs/dev/agent-skill-boundaries.mdを Allowed Paths へ追加
Notes for Reviewer
- canonical fix 点として「privileged executor の
preflight.runprofile を worktree-free read-only に修正」を採用している。parse_exact_skill_runtime_command()の exact argv contract は緩めず、preflight.run以外の root allow へ一般化しない resolve_active_issue()は既存の active issue worktree 前提を他 command / test / reason code に提供しているため、本 Issue では汎用 helper を緩めずpreflight.run専用の issue source を分離して扱う前提でレビューする- security boundary として、canonical root / default branch / trusted repo binding / registry validation /
network_effect: github_read_only/ artifact-only write postcondition を維持する。directrun_refinement_preflight.pyroot 実行、registry 全件自動 allow、.claude/skills/**/*.pyblanket allow、hook disable / bypass は不採用 - 実装: docs/product/features/upgrade.md を新規作成し Upgrade Loop の正本 spec を定義する #1170 の refinement 実行時に本 friction が顕在化し、control-plane が planner(
run_refinement_preflight.py/plan_refinement_loop.py)を bypass して downstream checker を直接実行する回避を強いられた
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
squne121 commentedon Jun 28, 2026
結論
Issue #1228 は 目的は妥当です。現行実装では
preflight.runが「root checkout / default branch / repo binding / exact argv」までは満たしていても、LOOP_ISSUE_NUMBERと linked issue worktree の存在を要求しているため、Issue 本文が言う「local root default branch から planner/preflight を起動したい」経路と矛盾しています。該当箇所は明確で、is_exact_skill_runtime_executor_command()がactive_issue == parsed.issue_number and entry is not Noneを要求し、_validate_runtime_context()もactive_issue_mismatch/active_issue_worktree_missingで落とします。ただし、この Issue はそのまま実装投入すると security boundary を誤って緩める危険があります。特に「read-only profile」を新設するなら、単に worktree / env 要求を外すだけでは不十分です。
preflight.run専用の exact executor 境界、direct preflight block、artifact-only write postcondition、repo binding、default branch binding、shell/argv negative fixture を維持する必要があります。参照した主要文脈
Issue #1228 は、
skill_runtime_command_policy.pyとskill_runtime_exec.pyのpreflight.runだけを worktree-free read-only にする実装 Issue です。AC1 は real PreToolUse hook chain で no-worktree / no-env の allow と、direct preflight・非 exact argv・mutation・artifact 外 write の block を要求しています。前身の #1154 は、
preflight.run専用 privileged executor を root checkout から安全実行するための Issue で、preflight.run以外の root allow、registry 全件自動許可、.claude/skills/**/*.pyblanket allow、hook disable / bypass を明確に Out of Scope にしています。PR #1177 は #1154 の実装 PR で、
preflight.runexact privileged executor、Claude/Codex guard parity、active issue / repo binding、artifact subtree boundary を安全 claim として実装した merged PR です。 その過程で Codex parity test が古い direct-preflight allowlist expectation のまま失敗し、tests/codex/test_local_main_branch_guard.pyを exact executor 契約へ更新する必要がレビューで指摘されています。#1147 は post-merge-cleanup の root checkout mutation 問題で、
git checkout/pull/branch -d/worktree removeのような mutation 経路を扱う別問題です。#1228 本文が Out of Scope として分離している判断は正しいです。敵対的レビュー
P0-1:
resolve_active_issue()の意味を壊さず、preflight.run専用の issue source を分離すべき現行
resolve_active_issue()はLOOP_ISSUE_NUMBERを読み、さらに worktree catalog から該当 issue worktree を探します。 #1228 の目的は「issue-number は exact argv から取る」なので、ここを汎用的に緩めると危険です。避けるべき実装:
これは既存の「active issue worktree があること」を前提にした他 command / test / reason code を汚染します。
推奨:
preflight.runだけに限定した helper を追加します。そして
is_exact_skill_runtime_executor_command()と_validate_runtime_context()の中で、preflight.runのみresolve_active_issue()を使わない分岐にする。既存の active issue worktree semantics は温存します。P0-2: Issue #1228 の AC1 は「artifact 外 write fail-close」を要求しているが、現 executor の postcondition は child 実行後検査であり、preflight の失敗時にも必ず検査されることを固定すべき
skill_runtime_exec.pyは child 実行前に repo snapshot / git status を取り、child 実行後に_find_unauthorized_repo_changes()で artifact root 外の変化を検出して return 2 します。 この設計は良いですが、#1228 では worktree-free 化により実行される場面が増えるため、以下を必須にしてください。.claude/artifacts/issue-refinement-loop/<issue>/以外の untracked / modified / deleted を fail-closerun_refinement_preflight.pyは引き続き root allow しない現行コードは大枠でこの構造ですが、テストがこれを real hook + executor subprocess で検証しないと false green になります。
P0-3:
local_main_branch_guard.pyだけでなくworktree_scope_guard.pyとの split-brain を検証対象に入れるべきIssue #1228 は Allowed Paths に
.claude/hooks/worktree_scope_guard.pyとそのテストを含めていません。しかし #1154 の元設計では、root allow はworktree_scope_guard.pyとlocal_main_branch_guard.pyの両方で parity を保つことが AC でした。#1228 の本文は「real PreToolUse hook chain(
local_main_branch_guard.pyに stdin JSON)」だけを要求していますが、実際の Claude hook chain で複数 guard が動くなら片側 allow / 片側 block の split-brain が起き得ます。Claude Code の PreToolUse は tool 実行前に JSON input を hook stdin へ渡し、複数 hook decision は deny が優先されます。([Claude Platform Docs]1) ([Claude Platform Docs]1)修正推奨:
Allowed Paths に最低限これを追加するか、Stop Condition に「worktree_scope_guard 側変更が必要なら分割」と明記するだけではなく、実装前に probe する。
少なくとも AC に以下を追加:
uv run pytest .claude/hooks/tests/test_worktree_scope_guard.py -k "skill_runtime_executor" -vP0-4:
shlex.split()だけを安全性の根拠にしない。exact token sequence + shell operator block を維持するPython docs は
subprocessで sequence args を渡す方が escaping / quoting を扱いやすいと説明していますが、shell string の分解は複雑で、shlex自体も Unix shell 向けです。([Python documentation]2) ([Python documentation]3) 現行parse_exact_skill_runtime_command()はshlex.split()の前に metachar / leading env を拒否し、token 数 10、token 位置、flag 形式、repo、command_id を固定しているため筋が良いです。#1228 の実装でここを「registry render と同じなら OK」のように広げるのは危険です。#1154 でも registry 全件自動許可は Out of Scope でした。
Issue #1228 本文への修正提案
1. In Scope に
worktree_scope_guardparity を追加現状の In Scope は
local_main_branch_guard.py寄りです。実 hook chain で deny が優先される以上、片方だけの allow は実運用で失敗します。追加案:
2. AC1 を分割する
今の AC1 が巨大で、実装者が検証を雑にまとめやすいです。
推奨:
3. Stop Condition を少し厳格化
追加:
推奨実装方針
最小パッチ方針
parse_exact_skill_runtime_command()は変更しない。is_exact_skill_runtime_executor_command()でparsed.command_id == "preflight.run"の場合だけ、resolve_active_issue()の要求をスキップする。_validate_runtime_context()もpreflight.runの場合だけLOOP_ISSUE_NUMBER/ linked worktree 要求をスキップし、args.issue_numberを artifact root に使う。validate_registry_entry()は維持。network_effect == github_read_only、allowed_write_roots、cwd_policy、argv template の検証を弱めない。--flag=value/ artifact 外 write を must-block として固定する。CodexCLI に依頼する次の推奨アクション
追加で起票を検討する follow-up
Issue #1228 の中で
worktree_scope_guard.pyも触る必要が出た場合、スコープが広がります。その場合は次の follow-up を切る方が安全です。現時点では、#1228 は 実装可。ただし worktree-free 化は
preflight.runの read-only profile に閉じ、guard 全体の security boundary を広げないことが条件です。squne121 commentedon Jun 28, 2026
Contract Review Result
fix(#1228): wrap no-worktree harness lines for ruff
fix(#1228): harden no-worktree preflight guard coverage
squne121 commentedon Jun 28, 2026
Contract Review Result
squne121 commentedon Jun 28, 2026
Contract Review Result
squne121 commentedon Jun 28, 2026
Contract Review Result
squne121 commentedon Jun 28, 2026
Contract Review Result
squne121 commentedon Jun 28, 2026
Contract Review Result
fix(#1228): allow read-only preflight.run without linked worktree (#1231