Repository navigation
Closed
6 / 66 of 6 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: "#1384"
goal_ref: "issue-refinement-loop の canonical preflight runtime が root checkout 保護と raw mutation deny を保ったまま hook で誤判定されないようにする"
change_kind: workflow
preflight_scope: implementation
runtime_verification:
required: true
mode: immediate
evidence_type: hook-evaluation-testsParent Issue
Parent Goal Ref
- 実装: VRT overlay rollout の baseline maturity registry を定義する #1384 refinement 中、
run_refinement_preflight.pyなどの canonical preflight 経路がlocal_main_branch_guardによりissue_refinement_direct/compound_wrapper_blockedとして止まり、手順が controlled edit fallback へ逸れた。 - ただし現行の安全境界は direct skill script allow ではなく、
skill_runtime_exec.py --command-id preflight.runの exact executor allow を正本とする。
Current Validated Scope
local_main_branch_guard/ Codex hook parity / Claude hook parity / repair hint の allow/block 境界だけを扱う。- 本 Issue は
preflight.runexecutor 境界に縮小し、build_refinement_phase_state.pyとdecide_next_loop_action.pyの direct allow は扱わない。 - GitHub Issue mutation の raw bypass は許可しない。
Remaining Parent Gaps
- 実装: VRT overlay rollout の baseline maturity registry を定義する #1384 本文 refinement 自体は完了済み。この Issue は今後の同種 loop runtime の preflight 実行境界だけを扱う。
build_refinement_phase_state.py/decide_next_loop_action.py/ SKILL.md 手順全体の executor 化が必要な場合は、本 Issue では停止して別 Issue に分離する。
Outcome
issue-refinement-loop の root preflight は direct skill script 実行ではなく、uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number <N> --repo squne121/loop-protocol の exact executor 経由でのみ allow される。direct .claude/skills/issue-refinement-loop/scripts/*.py、raw gh issue edit/comment、unsafe compound/wrapper は引き続き fail-closed で deny され、Claude/Codex hook parity tests と repair hint で再現可能に検証できる。
In Scope
local_main_branch_guard.pyで exactskill_runtime_exec.py --command-id preflight.runをskill_runtime_executor_commandとして allow する境界を regression test に固定する。- direct
.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.pyは引き続きissue_refinement_direct/unparseable_branch_mutation系で block されることを固定する。 rtkwrapper は exact inner executor command に限って unwrap/allow され、rtk run uv ...、rtk bash -lc ...、rtk gh issue edit ...、direct skill script wrapper は block されることを固定する。hook_repair_hints.pyに、direct script ではなく exact executor command を提示するHOOK_COMMAND_REPAIR_HINT_V1を追加または補強する。- Claude / Codex hook parity tests で同じ allow/deny matrix を検証する。
docs/dev/hook-boundaries.mdの rawgh issue edit/comment/create分類が現行の raw mutation deny 方針と矛盾する場合は、分類 drift を修正する。
Out of Scope
- direct
.claude/skills/issue-refinement-loop/scripts/*.pyの root allow build_refinement_phase_state.py/decide_next_loop_action.pyの executor allow 追加skill_runtime_exec.py/skill_runtime_command_policy.py/ command registry の新規 command id 追加- Issue 本文更新 helper の仕様変更
- raw
gh issue edit/gh issue comment/ mutatinggh api -f body=...の許可 --dangerously-skip-permissionsや Codex permission mode の変更- issue-refinement-loop planner 判定ロジックの変更
- 実装: VRT overlay rollout の baseline maturity registry を定義する #1384 registry docs 本体の変更
Acceptance Criteria
- AC1: root default branch で、
uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number 1395 --repo squne121/loop-protocolが Claude hook evaluation で allow され、reason_code はskill_runtime_executor_commandである。 - AC2: root default branch で、同じ exact executor command が Codex hook evaluation で allow され、reason_code は
skill_runtime_executor_commandである。 - AC3: direct
uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py --issue-number 1395 --repo squne121/loop-protocolは Claude/Codex hook evaluation で block され、issue_refinement_directまたは同等の unsafe direct runtime diagnostic が出る。 - AC4:
rtk uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number 1395 --repo squne121/loop-protocolの exact inner executor command だけが allow される。 - AC5:
rtk run uv ...、rtk bash -lc ...、rtk gh issue edit ...、rtk uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py ...は block される。 - AC6: raw
gh issue edit、gh issue comment、gh api -f body=...は引き続き block される。 - AC7:
issue_refinement_directまたは unsafe direct runtime block の repair hint は、direct script ではなくuv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number <N> --repo squne121/loop-protocolを suggested command として提示する。 - AC8:
.claude/hooks/tests/test_local_main_branch_guard.pyとtests/codex/test_local_main_branch_guard.pyがskill_runtime_executorを検証し、少なくとも Claude hook 側でissue_refinement_directの deny regression を検証する。 - AC9:
docs/dev/hook-boundaries.mdに raw GitHub mutation command の分類 drift が残らない。
Runtime Verification Applicability
runtime_verification_applicability:
decision: immediate
reason: "hook evaluation の allow/block/reason_code/repair hint は実テストで即時検証できる"
applicable_acs:
- AC1
- AC2
- AC3
- AC4
- AC5
- AC6
- AC7
- AC8
- AC9
execution_environment: "local WSL2 Ubuntu 24.04 / repo hook tests"
skip_conditions:
- "ローカル依存関係が欠落し、hook test harness 自体が起動できない場合"
- "Stop Conditions に該当する executor policy 拡張が必要と判明した場合"
fallback_policy: "テストで再現不能な hook 実経路差分が出た場合は実装を停止し、follow-up Issue に分離する"
artifact_requirements:
- "Claude hook evaluation test output"
- "Codex hook evaluation test output"
- "repair hint payload or stderr assertion"
- "docs drift check result"Verification Commands
# AC1
$ uv run --locked pytest .claude/hooks/tests/test_local_main_branch_guard.py -k skill_runtime_executor -v
# AC2
$ uv run --locked pytest tests/codex/test_local_main_branch_guard.py -k skill_runtime_executor -v
# AC3
$ uv run --locked pytest .claude/hooks/tests/test_local_main_branch_guard.py -k direct_preflight_script_not_in_root_allowlist -v
# AC4
$ uv run --locked pytest tests/codex/test_local_main_branch_guard.py -k skill_runtime_executor -v
# AC5
$ uv run --locked pytest tests/codex/test_local_main_branch_guard.py -k rtk -v
# AC6
$ uv run --locked pytest .claude/hooks/tests/test_local_main_branch_guard.py -k gh_issue_edit -v
# AC7
# baseline-expect: pass
$ rg -n "skill_runtime_exec.py --command-id preflight.run" scripts/agent-guards/hook_repair_hints.py 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
# AC8
$ uv run --locked pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -k "skill_runtime_executor or direct_preflight_script_not_in_root_allowlist" -v
# AC9
# baseline-expect: pass
$ rg -n "gh issue edit" docs/dev/hook-boundaries.md scripts/agent-guards/local_main_branch_guard.py .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.pyAllowed Paths
scripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/hook_repair_hints.pyscripts/agent-guards/tests/test_local_main_branch_guard.py.claude/hooks/tests/test_local_main_branch_guard.pytests/codex/test_local_main_branch_guard.pydocs/dev/hook-boundaries.mddocs/dev/agent-skill-boundaries.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
skill_runtime_exec.py/skill_runtime_command_policy.py/ command registry の新規 command id 追加が必要と判明した場合build_refinement_phase_state.py/decide_next_loop_action.pyの executor allow が必要と判明した場合.claude/skills/issue-refinement-loop/SKILL.mdの direct command 手順修正が本 Issue の実装完了条件になると判明した場合- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- raw GitHub mutation の許可が必要になった場合
Required Skills
- Python
- Hook policy
Required Design References
docs/dev/hook-boundaries.mddocs/dev/agent-skill-boundaries.md.claude/skills/issue-refinement-loop/SKILL.mdscripts/agent-guards/skill_runtime_exec.pyscripts/agent-guards/skill_runtime_command_policy.py
Scope Delta
- Derived from 実装: VRT overlay rollout の baseline maturity registry を定義する #1384 refinement run and owner review comment: canonical preflight commands were blocked by
local_main_branch_guard, but the correct fix is to preserve thepreflight.runexecutor boundary rather than allowing direct skill script execution. - Anchor comment: 実装: issue-refinement-loop canonical runtime の hook allowlist を整備する #1395 (comment)
Delivery Rule
- 1 Issue = 1 PR
- 作業前に issue-contract-review で fresh
CONTRACT_REVIEW_RESULT_V1 status: goを取得する。 - raw mutation allowlist を広げず、exact executor command と deterministic tests で完結させる。
Sub-issues
Collapse Sub-issuesSub-issues
Loading 6 sub-issues
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jul 8, 2026
判定: REQUEST_CHANGES
#1395 の目的は妥当です。#1384 refinement 中に
run_refinement_preflight.pyや SSOT discovery / worktree setup 系の read-only/canonical command がlocal_main_branch_guardにissue_refinement_direct/compound_wrapper_blockedとして止められた、という問題設定は具体的です。#1395 は raw mutation を引き続き deny し、Codex/Claude parity と repair hint で canonical command と raw mutation を分離する方針も正しいです。ただし、現行 contract のまま実装に入ると、既存の
preflight.run専用 privileged executor 境界と衝突します。特に「canonicalrun_refinement_preflight.pycommand」を direct script allow と解釈できる書き方、build_refinement_phase_state.py/decide_next_loop_action.pyまで同一Issueで扱うスコープ、rtkwrapper の曖昧さ、SKILL.md の direct command 記述との不整合が P0 です。#1395 自体にはコメントはありません。関連文脈としては、#1154 が
preflight.run専用 privileged executor を導入し、PR #1177 がそれを merged 実装として閉じています。#1228 は no-worktree / no-env の root preflight allow をpreflight.runに限って解消した後続です。#1026 は command registry を導入し、#1383 は controlled metadata mutation lane を別スコープで扱っています。P0-1: AC1 が direct script allow と executor allow を分離していない
現行実装は、
skill_runtime_exec.py --command-id preflight.run ...だけを exact executor として allow し、.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.pyの direct root 実行は明示的に block します。local_main_branch_guard.pyも exact executor をREASON_SKILL_RUNTIME_EXECUTORで allow し、lookalike/direct issue-refinement runtime をissue_refinement_directとして block する分岐を持っています。この既存境界はテストでも固定済みです。Claude 側テストは exact
skill_runtime_exec.py --command-id preflight.runを allow し、directrun_refinement_preflight.pyは block することを確認しています。Codex 側も同じ exact executor 契約を持ち、noncanonical lexical form を block します。修正案: #1395 の AC1 は次のように書き換えるべきです。
run_refinement_preflight.pyという文字列を repair hint に出す場合も、direct script ではなく executor 経由の canonical shape を出す必要があります。P0-2:
build_refinement_phase_state.py/decide_next_loop_action.pyは現行 Allowed Paths では安全に許可できない#1395 は
run_refinement_preflight.py、build_refinement_phase_state.py、decide_next_loop_action.pyの許可境界を tests に固定するとしています。 しかし現行SKILL_RUNTIME_COMMAND_POLICY_V2の eligible command はpreflight.runのみです。policy は root/no-worktree allow もpreflight.runに限定しています。さらに
skill_runtime_exec.py側も registry からpreflight.runを検証し、実行対象 script はrun_refinement_preflight.pyに固定されています。build_refinement_phase_state.pyやdecide_next_loop_action.pyを executor 経由で安全に通す設計にはなっていません。command registry には
preflight.runとdecide.runはありますが、preflight.runだけが executor 契約に必要なexecution_class/required_cwd/required_branch/allowed_write_roots/network_effectを持っています。build_refinement_phase_state.pyの registry entry は確認できません。修正案は二択です。
preflight.run/local_main_branch_guardfalse-positive の修正に縮小し、build_refinement_phase_state.pyとdecide_next_loop_action.pyは別 Issue に分離する。skill_runtime_command_policy.py、skill_runtime_exec.py、command_registry.py、.claude/skills/issue-refinement-loop/SKILL.md、必要なら.claude/hooks/worktree_scope_guard.pyを追加し、各 script ごとの effect inventory / path containment / argv schema / positive-negative hook tests を AC に追加する。現状の Allowed Paths は guard、repair hint、tests、docs に寄っており、Required Design References として SKILL.md を挙げながら、SKILL.md 自体の修正は許容していません。
P0-3: SKILL.md の手順が direct command を案内しており、#1395 の実装だけでは運用上の false-green になる
issue-refinement-loop/SKILL.mdは Step 0f で directuv run --locked python3 .claude/skills/.../run_refinement_preflight.pyを示し、その直後にbuild_refinement_phase_state.pyも direct 実行する手順を載せています。 Review phase 以降でも directbuild_refinement_phase_state.pyと directdecide_next_loop_action.pyが記載されています。一方で repo の command registry は「SubAgent / main thread は手書き shell string を consume しない」という SSOT 方針を掲げています。 この矛盾を直さずに
local_main_branch_guard.pyのテストだけを green にしても、実際の loop procedure は direct command を出し続け、guard と衝突します。修正案: #1395 に SKILL.md / references の更新を含めるか、少なくとも Stop Condition に「SKILL.md の direct command 記述変更が必要なら本Issueを停止し、command registry / executor 対応Issueへ分割する」を追加してください。
P0-4:
rtkwrapper AC が曖昧で、wrapper bypass の再導入になり得る#1395 の AC2 は「
rtkwrapper 経由の canonical command がcompound_wrapper_blockedにならない」としていますが、rtkのどの lexical shape を許可するのかが未定義です。現行local_main_branch_guard.pyは compound/wrapped command を先に block し、その後rtkinner command を解析します。unknown なrtkinner command は最終的に block されます。#1383 でも、
rtk run uv ...やrtk gh issue editが拒否され、controlled mutation executor lane が必要になった実観測が記載されています。 したがって、AC2 は「rtkwrapper なら canonical」と読める余地を排除する必要があります。修正案:
P0-5: repair hint AC5 が現在の実装と検証方法では弱い
hook_repair_hints.pyの現在の reason-specific hint はdirect_bypass_requires_rtk、rtk_unknown_inner、git add/commit/push、worktree context などに寄っており、issue_refinement_direct/compound_wrapper_blocked/run_refinement_preflight.py用の exact executor hint はありません。また
docs/dev/agent-skill-boundaries.mdは、HOOK_COMMAND_REPAIR_HINT_V1は steering 用 diagnostics であり、hook authorization を上書きしない、wrapper 展開や bypass shell を agent が自動採用してはならない、と定義しています。修正案: AC5 の検証は単なる
rg -n "run_refinement_preflight.py" scripts/agent-guards/hook_repair_hints.pyでは不足です。少なくとも block stderr または result payload に以下を assert してください。P1: hook-boundaries.md に gh mutation 分類の drift がある
docs/dev/hook-boundaries.mdはgh issue createまたはgh issue edit <N>が--repoと--body-file tmp/...を満たせば allow と説明しています。 しかし現行テストは rawgh issue editを block する fixtures を持ち、Codex/Claude の mutation deny テストでもgh issue editを block としています。GitHub CLI 公式 manual 上も
gh issue editは--body-fileや title/label/assignee/project 等を編集できる remote mutation command です。gh issue createも issue を作成し、--body-fileは body 入力元にすぎません。([GitHub CLI]1) (GitHub CLI) したがって #1395 が raw mutation deny を回帰テストに残すなら、docs 側の分類 drift を同時に整理する必要があります。P1: verification が hook 実経路ではなく、false-green を作りやすい
Claude Code hooks は command hook に JSON context を stdin で渡し、
PreToolUseは tool call の前に発火します。exit code 2 はPreToolUseでは tool call を block し、PermissionRequestでは permission を deny します。([Claude Platform Docs]3) ([Claude Platform Docs]3)そのため #1395 の verification は
evaluate()関数単体だけでは弱いです。最低限、以下の実 stdin JSON 経路を追加してください。加えて、
scripts/agent-guards/tests/test_local_main_branch_guard.pyは shim であり、実体は.claude/hooks/tests/test_local_main_branch_guard.pyにあります。#1395 の VC は shim 経由だけでなく、Claude/Codex の両実体を直接指定する方が安全です。Web検索を踏まえた実装品質条件
実装方針は「shell string を緩く許す」ではなく、「exact argv /
shell=False/ deny-by-default / postcondition」です。Python 公式 docs は、subprocessは暗黙に shell を呼ばないため shell metacharacter を安全に子プロセスへ渡せる一方、shell=Trueを明示した場合は shell injection を避けるため quoting 責任がアプリ側にあると説明しています。([Python documentation]4)shlexは Unix shell 風の tokenization には使えますが、shell の完全 parser ではなく、返った token の semantic validation は利用側で必要です。([Python documentation]5)gh apiは parameter を追加すると通常 POST に切り替わるため、gh api -f body=...や--raw-fieldを read-only と誤分類すると remote mutation 経路になります。([GitHub CLI]6) GitHub Issue 操作もgh issue edit --body-fileやgh issue create --body-fileは body 入力方式であって、操作自体は remote mutation です。([GitHub CLI]1) ([GitHub CLI]2)Git worktree は main worktree と linked worktree を分け、同一 repo で複数 branch を checkout するための公式機構です。#1395 が「dedicated worktree または controlled executor lane」を掲げるなら、main root direct script allow ではなく、linked worktree 分離または exact executor のどちらかに明確化すべきです。([Git]7)
#1395 本文への具体的な修正案
現行 Issue を通すなら、以下の形に直すのが安全です。
この修正を入れない場合、#1395 は #1154/#1177/#1228 で作った安全境界を「read-only/canonical だから direct skill script を許す」という古い失敗モードへ戻すリスクがあります。
squne121 commentedon Jul 8, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 8, 2026
Contract Review Result
squne121 commentedon Jul 8, 2026
scope 統合メモ
#1383 との Allowed Paths overlap を人間判断で scope 統合として扱います。
squne121 commentedon Jul 8, 2026
impl-review-loop: 完了 (2026-07-08T13:45:00Z)
test: align gh api hook docs and regressions (#1395)
squne121 commentedon Jul 8, 2026
改善点追記: #1395 周辺の後続候補
PR #1399 の reviewer 指摘対応中に、同種 Issue / PR / agent 運用へ再利用できる改善点を整理しました。
G1/G2 は PR #1399 head
548a586282307908903b917c49102f20d267d4e1で対応済みです。G3/G5 は #1395 の実装境界と reviewer コメントに紐づく運用上の注意点として、この Issue に追記します。squne121 commentedon Jul 8, 2026
impl-review-loop: 完了更新 (current head)
PR #1399 は current head
a8e7e3eb20ee24694387c4233e68a04a7f98b56bで再同期され、検証と PR review loop が完了しました。次アクション: 人間レビュー → マージ → post-merge-cleanup
fix: preflight repair hint と hook docs を整合させる (#1395) (#1399)
squne121 commentedon Jul 8, 2026
post-merge-cleanup: 完了 (2026-07-08T17:44:00Z)
worktree-issue-1395-hook-allowlistは ancestry 上 not fully merged 扱いのため残存。worktree は削除済み。