Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "1209"
goal_ref: "implementation-worker の dedicated worktree 内で canonical な `git add -- <allowed-path>` が `local_main_branch_guard` に `unknown_command_requires_review` と誤判定されず、#1209 の publish が完了できる状態にする"
change_kind: workflowParent Issue
Parent Goal Ref
- Goal: implementation-worker が安全な exact command class で Issue worktree を作成でき、impl-review-loop が実装前に停止しない状態にする
- Desired Destination: dedicated worktree での実装・検証完了後、Allowed Paths 内の変更を通常の
git add/git commit/ Draft PR 起票まで進められ、publish 手前で local hook false positive に止められない状態
Current Validated Scope
- 実装: implement-issue の worktree bootstrap を controlled executor 化し、rtk/raw git policy 衝突を解消する #1209 の専用 worktree
.claude/worktrees/issue-1209-worktree-bootstrap-codex/ branchworktree-issue-1209-worktree-bootstrap-codexでは、実装と検証は完了している uv run pytest tests/agent_ops/test_worktree_bootstrap_exec.py -vuv run pytest tests/agent_ops/test_implement_issue_worktree_bootstrap_docs.py -vuv run pytest tests/codex/test_worktree_bootstrap_command_policy.py -vuv run pytest .claude/hooks/tests/test_worktree_scope_guard_worktree_bootstrap.py -vpnpm typecheckpnpm lintpnpm testpnpm build- ただし dedicated worktree 内の canonical な
git add -- <allowed-path>がlocal_main_branch_guardにreason_code: unknown_command_requires_reviewで fail-closed block され、commit / push / Draft PR 起票へ進めない - 2026-06-27 の owner comment では、
local_main_branch_guardは linked issue worktree context を早期 allow し、git addの pathspec / staging 判定はworktree_scope_guard側に分離するよう REQUEST_CHANGES が出ている
Remaining Parent Gaps
- worktree bootstrap executor 自体の実装・検証は 実装: implement-issue の worktree bootstrap を controlled executor 化し、rtk/raw git policy 衝突を解消する #1209 側で完了済みのため、本 issue は publish blocker の除去だけを扱う
- root checkout での read-only false positive 全般は 実装: local hook の unparseable_branch_mutation 誤判定で issue-refinement-loop が停止する問題を解消する #1198 側で継続する
- owner comment 内の根因仮説(cwd mismatch など)は本 issue の契約へ確定事実として昇格させず、必要になった場合のみ follow-up 調査で扱う
Outcome
dedicated worktree 上の implementation issue で、local_main_branch_guard は linked issue worktree context を root checkout と誤認せず context ベースで早期 allow し、git add の pathspec / staging 判定は worktree_scope_guard のみに集約されたまま、Allowed Paths 内ファイルに対する canonical な git add -- <path> が commit / push / Draft PR 起票まで進められる状態。
In Scope
local_main_branch_guardに linked issue worktree context の早期 allow を追加し、root default branch drift 防御とは責務を分離するlocal_main_branch_guardはgit addpathspec / Allowed Paths 判定を持たず、command 例外ではなく context 判定だけを担当する形に修正するworktree_scope_guardに dedicated worktree publish 向けgit addpathspec classifier を追加し、git add -- <explicit-file> [<explicit-file>...]のみを明示ファイル staging として許可するPreToolUseとPermissionRequestの両イベントで、実装: implement-issue の worktree bootstrap を controlled executor 化し、rtk/raw git policy 衝突を解消する #1209 相当の dedicated worktree publish blocker を再現する regression fixture / test を追加する- fixture は実際に block された hook payload を最小化した JSON とし、少なくとも
cwd、tool_name、tool_input.command、hook_event_nameまたは同等のイベント識別情報を保持する - 必要最小限の shared guard helper / catalog / diagnostics を更新し、判定経路と reason_code を追跡可能にする
- 実装: implement-issue の worktree bootstrap を controlled executor 化し、rtk/raw git policy 衝突を解消する #1209 publish blocker の再現と解消確認
Out of Scope
- root checkout での branch mutation 保護の緩和
git add .、git add -A、git add --all、git add -u、git add --update、glob / pathspec magic / directory-wide staging の許可git add --pathspec-from-file ...、git add --pathspec-from-file=...、git add :/、git add ':(glob)**'などの広域 pathspec staging の許可git checkout、git switch、git reset --hardなど危険コマンドの緩和- 実装: implement-issue の worktree bootstrap を controlled executor 化し、rtk/raw git policy 衝突を解消する #1209 の executor 実装そのものの再設計
- GitHub remote write policy 全体の再設計
rtk proxy/ arbitrary shell passthrough の許可- owner comment 内の仮説群を、この issue 単独で広域原因調査に拡張すること
Acceptance Criteria
- AC1: dedicated worktree context では
local_main_branch_guardが linked issue worktree を root checkout と誤認せず、branch drift 判定より前に context ベースで allow してunknown_command_requires_reviewを返さない - AC2:
local_main_branch_guardはgit addpathspec / Allowed Paths 判定を持たず、git addの command-specific 例外追加ではなく linked issue worktree context 判定だけで publish 経路を通す - AC3: dedicated worktree 内の
git addpathspec 判定はworktree_scope_guardが担い、git add -- <explicit-file> [<explicit-file>...]のみ publish staging として継続可能になる - AC4: dedicated worktree 内でも Allowed Paths 外の
git add、git add .、git add -A、git add --all、git add -u、git add --update、git add --pathspec-from-file ...、git add --pathspec-from-file=...、git add :/、git add ':(glob)**'、directory-wide staging、git -C <outside> add、bash -lc 'git add ...'、rtk proxy ...、危険な branch mutation コマンドは引き続き block または review される - AC5:
tests/fixtures/hooks/issue1215-pretooluse-dedicated-worktree-git-add.jsonとtests/fixtures/hooks/issue1215-permissionrequest-dedicated-worktree-git-add.jsonが追加され、実 blocker を最小化した payload でcwd、tool_name、tool_input.command、イベント識別情報を保持する - AC6: dedicated worktree publish path の判定理由が diagnostics またはテストで追跡可能になり、
linked_issue_worktree_context相当の context-based reason とunknown_command_requires_reviewからの脱出が確認できる - AC7: 実装: implement-issue の worktree bootstrap を controlled executor 化し、rtk/raw git policy 衝突を解消する #1209 worktree で commit / push / Draft PR 起票まで再開できることが確認できる
Verification Commands
# AC1
# baseline-expect: fail
$ rg -n "issue1215_worktree_context" tests/codex/test_local_main_branch_guard.py
# AC2
# baseline-expect: fail
$ rg -n "issue1215_no_git_add_exception" tests/codex/test_local_main_branch_guard.py
# AC3
# baseline-expect: fail
$ test -f .claude/hooks/tests/test_issue1215_git_add_allow.py
# AC4
# baseline-expect: fail
$ test -f .claude/hooks/tests/test_issue1215_git_add_block.py
# AC5
# baseline-expect: fail
$ test -f tests/fixtures/hooks/issue1215-permissionrequest-dedicated-worktree-git-add.json
# AC6
# baseline-expect: fail
$ rg -n "linked_issue_worktree_context" scripts/agent-guards/local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py
# AC7
# baseline-expect: fail
$ test -f .claude/hooks/tests/test_issue1215_publish_resume.pyAllowed Paths
scripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/worktree_scope_guard.pyscripts/agent-guards/worktree_catalog.pyscripts/agent-guards/utils/**.claude/hooks/**tests/codex/test_local_main_branch_guard.pytests/codex/test_worktree_scope_guard.pytests/fixtures/hooks/issue1215-pretooluse-dedicated-worktree-git-add.jsontests/fixtures/hooks/issue1215-permissionrequest-dedicated-worktree-git-add.jsondocs/dev/hook-boundaries.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- local root default branch 保護を弱めないと修正できない場合
local_main_branch_guardの責務を壊さずに dedicated worktree allow を導入できないと判明した場合- wrapper / hook event ordering の安全性要件が 実装: local hook の unparseable_branch_mutation 誤判定で issue-refinement-loop が停止する問題を解消する #1198 や別仕様と広く衝突すると判明した場合
- repo 外 hook や Codex/Claude 本体側 bug で、repo 側修正だけでは解決不能と判明した場合
Runtime Verification Applicability
decision: not_applicable
reason: static checks only
Required Skills
- Python 3
- Git
Delivery Rule
1 Issue = 1 PR。dedicated worktree で実装し、#1209 の未公開差分を壊さず publish blocker だけを解消する。
Scope Delta(任意)
N/A
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 27, 2026
判定: REQUEST_CHANGES
#1215 は必要です。ただし、現契約のまま実装すると
local_main_branch_guardにgit addの例外を足して、root checkout の index mutation まで緩める事故が起きやすいです。正しい分離は、local_main_branch_guardは「linked worktree なら早期 allow」、worktree_scope_guardは「その worktree 内の staging だけを pathspec まで検査」です。#1215 は #1209 の publish blocker で、#1209 専用 worktree では実装・検証は完了しているが、dedicated worktree 内の単純な
git add <allowed-path>がunknown_command_requires_reviewで止まり、commit/push/Draft PR に進めない、という問題です。AC もgit add <allowed-path>の通過、git add ./git add -A/ Allowed Paths 外 staging の継続 block、#1209 相当 fixture、診断追跡を要求しています。 #1215 自体にはコメントはありません。P0 ブロッカー
1. 根因 fixture が足りない
現行
local_main_branch_guard.pyの目的は「local root checkout が default branch から drift する Bash command を止める」ことです。linked issue worktree 内の通常作業を裁く guard ではありません。 さらに現行実装はis_local_root_context(cwd)が false ならnot_local_root_contextで allow する構造です。したがって、dedicated worktree 内の
git addが本当にこの guard で止まるなら、少なくとも次のどれかです。cwdが worktree ではなく main root になっている。CLAUDE_PROJECT_DIR/ wrapper 経由の project root 解決が実 runtime と test fixture でズレている。unknown_command_requires_reviewを fail-closed に変更している。rtk git addなど envelope 化された command が rawgit addと異なる経路を踏んでいる。#1215 は「実際に block された raw Codex/Claude hook JSON」を fixture 化する AC を追加するべきです。
evaluate("git add ...", cwd=worktree)だけでは再現として弱いです。run_guard_script(payload, cwd=...)で PreToolUse と PermissionRequest の両方を固定してください。2.
git addの pathspec policy が未定義git addは branch mutation ではありませんが、index mutation です。Git 公式仕様でもgit addは index/staging area に内容を追加する command で、-A/--allは working tree に一致するよう追加・変更・削除を index に反映し、pathspec 無しなら working tree 全体が対象です。(Git)現行
worktree_scope_guard.pyは_GIT_MUTATING_SUBCMDSにaddを含め、git addを mutating と分類します。 その後、cwd が expected worktree 内なら mutating command を allow します。 つまり 今の構造ではgit add ./git add -Aも worktree 内なら通る可能性が高い。これは #1215 AC2 と衝突します。#1215 は
local_main_branch_guardだけでなく、worktree_scope_guard側にgit add専用 classifier を要求すべきです。少なくとも block/review 対象は以下です。許可するなら、形はこの程度まで絞るべきです。
Git 公式にも
--は option と file list の区切りとして定義されています。(Git) また<pathspec>は glob や directory 指定で広範囲に展開され得るので、「Allowed Paths 内の明示ファイル staging」を主張するなら、directory path / glob / pathspec magic をそのまま許可してはいけません。([Git]1)3. hook ordering 上、PreToolUse だけ直しても足りない
Codex の PreToolUse では
local_main_branch_guardが先に走り、その後にworktree_scope_guardが走ります。 PermissionRequest ではlocal_main_branch_guardと session recording だけで、worktree_scope_guardは入っていません。したがって #1215 の fixture は最低限この 2 経路が必要です。
片方だけ通しても publish blocker は再発します。
4.
local_main_branch_guardに Allowed Paths 判定を持ち込むべきではないlocal_main_branch_guardは branch drift guard です。Allowed Paths / worktree containment / mutation target はworktree_scope_guardの責務です。現行worktree_scope_guardは expected worktree 解決で sharedworktree_catalogを使い、branch short-name と path basename の両方が issue に一致する worktree を選ぶ設計です。worktree_catalog.pyもgit worktree list --porcelain -zの SSOT として導入され、newline/quoting ambiguity を避ける前提です。 Git 公式でも porcelain-zは NUL 区切りで、worktree 属性が record の先頭になる形式です。(Git)よって修正方針は次です。
5. #1209 / #1198 との整合がまだ弱い
#1209 は worktree bootstrap を controlled executor 化し、raw
git worktree addと wrapper を deny-by-default に保つ契約です。 #1198 はrtk <inner>を wrapper として unwrap し、inner classifier の結果を踏襲する方向でした。 rtk 本体も hook-based agents でgit status等をrtk git statusに rewrite し、rtk git add/commit/pushとrtk proxy <command>を扱います。([GitHub]3)したがって #1215 は
rtk git add -- <path>をどうするかを明示する必要があります。安全側なら初回は rawgit add -- <path>のみ許可し、rtk git addは #1198 の wrapper policy に従って innergit addclassifier と完全同値になる場合だけ許可、rtk proxyは block です。契約修正案
#1215 に以下を追記するのが妥当です。
実装上の推奨
local_main_branch_guard.pyには、command 例外ではなく context 例外を追加してください。classify_worktree_contextは可能ならworktree_catalog.pyのlist_worktrees()/find_by_realpath()/select_issue_worktrees()を再利用してください。git worktree list --porcelain -zを各 guard が独自 parse し始めると、#1197/#1137 で潰した quoting drift が再発します。git addの実行や検証に subprocess を使う場合は、Python 公式どおりsubprocess.run([...], shell=False, capture_output=True, timeout=...)の argv list 形式を維持してください。capture_outputは stdout/stderr を PIPE にし、timeout超過時は child process を kill/wait して例外化します。([Python documentation]4)shlex.split(..., comments=False)は#をコメント扱いしないため、URL fragment や pathspec を扱う parser ではこの前提も固定した方がよいです。([Python documentation]5)最終コメント
#1215 は「
git addを許可する Issue」ではなく、dedicated worktree context をlocal_main_branch_guardが root checkout と誤認しないようにし、その後のgit addはworktree_scope_guardが明示 pathspec だけ許す Issue として書き直すべきです。この分離を入れない場合、#1209 の publish は通るかもしれませんが、次に
git add ./git add -A/rtk git add/ PermissionRequest 経路で同じ種類の穴か詰まりが再発します。squne121 commentedon Jun 27, 2026
Contract Review Result
fix(#1215): wrapper-aware git add policy + directory pathspec + fixtu…
fix: complete issue-1215 publish guard updates (#1217)