Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "post-merge-cleanup: canonical repository root selection"
change_kind: workflow
dedupe_key: "post-merge-cleanup:guard-canonical-root-selection"Parent Issue
none
Parent Goal Ref
post-merge cleanup の guard / executor が、Claude Code session の current worktree に依存せず canonical repository root を判定し、安全な cleanup を false-negative で停止しないこと。
Current Validated Scope
今回の failure class は cleanup policy の緩和ではなく repository root selection の誤り。
現行 scripts/agent-ops/guard_preflight.py::resolve_project_root() と scripts/agent-ops/cleanup_exec.py::resolve_project_root() は、CLAUDE_PROJECT_DIR があればその realpath、無ければ実行中 script の配置元を repository root とみなす。
interactive Claude Code session が issue worktree に固定されている場合、CLAUDE_PROJECT_DIR / script location のどちらも issue worktree を指し得る。この状態で guard_preflight.py --json を通常どおり実行すると、issue branch を root branch として観測し、canonical root checkout が main/clean でも root_branch_state: drifted / active_worktree_state: mismatch / status: human_required に落ちる。
また select_issue_worktree(..., root_realpath) は root とみなした entry を除外するため、issue worktree 自身を誤って root にした場合は active issue の catalog entry も見失い、mismatch を増幅する。
追加で OWNER 敵対的レビュー(https://github.com/squne121/loop-protocol/issues/2979#issuecomment-6047844759)が、root resolver だけ直しても次の 4 点が残ることを指摘した(base 8561d147 で実機・コード確認済み)。
- linked worktree から
git checkout mainすると、primary が main を checkout 済みのためfatal: 'main' is already used by worktreeで exit 128 になる(post-merge-cleanup-executorStep 2 が issue worktree session から完遂できない)。 guard_preflight.build_preflight()はlist_worktrees()がNone(git 失敗)を返してもcatalog = []に変換し、root が default ならstatus=okになり得る。worktree_catalog.list_worktrees()はgit_common_dirを 1 回だけ求めて全 entry に複写するため、entry 同士の比較は独立検証にならない。_active_issue()は cwd の basename または root branch 名でのみ Issue 番号を推定するため、issue-N-slug/srcのような nested cwd では active Issue を見失う。- 現行の
-k付き VC は対象テスト名が未存在のため pytest exit 5(no tests collected)になり、欠陥再現ではなく未収集を baseline fail の根拠にしている。
既存テストは build_preflight(project_root=str(repo["root"]), cwd=str(repo["root"])) のように canonical root を直接注入しており、実 CLI が issue worktree から root を自己解決する production path を固定していない。
Remaining Parent Gaps
- guard / cleanup 以外の repository-root resolver 全体を統一する一般化は本 Issue の範囲外。
- Claude Code / Claude-GPT の project-dir semantics 自体を変更しない。
- cleanup policy(root drift 時の human_required、dirty worktree の拒否等)は変更しない。
Source
- runtime reproduction: Issue 実装: source-evidence human_review 後の operator C1 判断を Step 1 に安全に渡す #2930 / PR feat: source-evidence C1 の初回取得後 operator 判断を束縛する (#2930) #2951 の post-merge cleanup session
- related prior guard contract: 実装: guard arbitration preflight と cleanup contract delivery を機械化する (agent-ops) #1137
- related branch-only cleanup: 実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196
- current implementation:
scripts/agent-ops/guard_preflight.pyscripts/agent-ops/cleanup_exec.pyscripts/agent-ops/worktree_catalog.py.claude/skills/post-merge-cleanup-executor/SKILL.md
Outcome
issue worktree 内で起動された interactive session から post-merge cleanup を実行しても、guard / cleanup executor は current worktree と canonical repository primary root を分離して判定する。
canonical root checkout が default branch で clean、active issue worktree が catalog 上で正しく存在する場合、guard_preflight.py --json は issue worktree を root と誤認せず root_branch_state: default / active_worktree_state: matches を返す。
一方、canonical root checkout 自体が本当に drift / detached / ambiguous な場合は、既存の fail-closed / human-required semantics を維持する。
Problem
再現条件:
- canonical root checkout は
mainかつ clean。 - linked issue worktree が存在し、その worktree branch 上で interactive session が起動している。
- session の
CLAUDE_PROJECT_DIRまたは script resolution が issue worktree を指す。 .claude/skills/post-merge-cleanup-executor/SKILL.md記載どおりuv run --locked python3 scripts/agent-ops/guard_preflight.py --jsonを実行する。
現状は issue worktree を root として評価し、実際の canonical root が正常でも以下の false result を返し得る:
root_branch_state: drifted
active_worktree_state: mismatch
status: human_required
blocked_reason_codes:
- root_drift_active_worktree_mismatch
この false-human-required に対して cleanup を再実行・override するのは不適切であり、正規 root から preflight をやり直す手動回復が必要になっている。
Design Requirements
-
root と cwd を分離する
cwd/ session project dir は「現在どの issue worktree から呼ばれたか」の観測に使ってよいが、canonical repository root の authority にしない。 -
Git repository identity から primary root を解決する
linked worktree からでも同じ git common-dir /git worktree list --porcelain -zcatalog を使って canonical primary worktree を決定する。branch 名を root identity の代用にせず、primary worktree を解決してからその branch を default branch と比較する。 -
shared resolution
guard_preflightとcleanup_exec(およびcleanup_exec.resolve_project_rootを利用する materialize lane)が同じ root-resolution semantics を使い、preflight が ok でも executor が別 root を見て拒否する divergence を作らない。 -
fail closed
primary root が一意に解決できない / catalog 取得に失敗する / git common-dir が不整合な場合、issue worktree を silently root 扱いしない。structured reason で blocked / human_required に倒す。 -
既存 policy は維持
canonical root 自体が本当に drifted の場合のroot_drift_active_worktree_mismatch、dirty worktree 拒否、PR merged / branch / linked issue 検証は緩和しない。 -
catalog / identity は独立に検証する
git worktree list --porcelain -zの先頭 entry を primary とし、linked worktree と primary root の双方で独立にgit rev-parse --git-common-dirを実行して realpath 比較する(相対パスで返る場合は実行 cwd 基準で解決する)。catalog producer が全 entry に複写した field 同士の比較を独立検証とみなさない。bare repository など先頭 entry が work tree を持たない場合は primary 不在として structured failure にする。この検証はworktree_catalog.pyへの additive な共有 helper として実装し、既存list_worktrees()の戻り値(失敗時None、git_common_dirfield の複写)と署名は変更しない(worktree_bootstrap_exec/git_worktree_probe/verified_*_merge_execなど Allowed Paths 外の既存 consumer を壊さない)。 -
cleanup 全工程の実行 cwd を分離する
main 同期は canonical primary root に対して、root identity / state の gate(guard_preflight.py --jsonがroot_branch_state=default)を通過した場合のみ行う。drift した primary を preflight より前に切り替えない。現在 session が削除対象 worktree 上にいる場合は、削除後に無効 cwd で後続 Step を実行しない。既存のcleanup_exec認可境界は維持する。 -
失敗は固定 reason code で返す
新規 reason code は次の固定 literal とし、既存の拒否応答 field(guard はblocked_reason_codes、executor は既存の拒否 reason)に載せる:worktree_catalog_unavailable/git_common_dir_unavailable/primary_root_unresolved/repository_identity_mismatch/active_issue_catalog_conflict。新しい schema・field 群は追加しない。
Acceptance Criteria
- AC1: issue worktree を cwd とし、
CLAUDE_PROJECT_DIRも issue worktree を指す real-Git fixture から public CLIguard_preflight.py --jsonを起動しても、canonical primary root が main/default の場合はroot_branch_state=default、active_worktree_state=matches、status=okになる。 - AC2: AC1 の fixture で canonical root checkout 自体を non-default branch に drift させると、従来どおり fail-closed / human-required になり、issue worktree 側の branch 状態で誤って ok にならない。
- AC3: root resolver は linked worktree / canonical root の双方から同一 primary root realpath を返す。identity 検証は、linked worktree と primary root のそれぞれで独立に
git rev-parse --git-common-dirを subprocess 実行して得た realpath 同士を比較する。negative control は、primary 候補を別 repository(異なる common-dir)の path へ差し替える、または helper の test seam(catalog 引数 / module-level のlist_worktreespatch)で foreign common-dir を注入したとき、repository_identity_mismatchで非成功になること(catalog entry のgit_common_dirfield を改ざんしても結果が変わらないことは仕様であり、field 同士の比較で PASS しないことの根拠とする)。list_worktrees()の署名・戻り値は不変で、helper は additive であること。 - AC4: primary root を一意に解決できない / catalog failure の場合、issue worktree fallback を行わず structured failure を返す。
- AC5:
cleanup_execの public CLI でも issue-worktree session から同じ canonical root を使う。preflight が root 正常と判定した直後に executor がroot_not_default_branchだけを理由に拒否する divergence がない。 - AC6: existing 実装: guard arbitration preflight と cleanup contract delivery を機械化する (agent-ops) #1137 semantics(real catalog、cwd classification、root drift policy、cleanup authorization checks)を回帰させない。
- AC7:
post-merge-cleanup-executorの documented invocation を実際に通す integration regression を追加し、test helper がproject_root=canonical_rootを直接注入するだけの false-green にしない。 - AC8: full workflow reachability(
post-merge-cleanup-executor/SKILL.mdの記述と test が同一の command 列を使う)。issue worktree session から real-Git fixture(primary root + linked issue worktree + local bare origin。GitHub API 呼び出しghのみ PATH 上の fake を許容し、git は実物)で次を満たす。(1) canonical root はgit_worktree_probe.py --jsonのentries[0].worktree_realpathから取得する(guard_preflightの出力 field は追加しない)。(2) Step 2 の main 同期は、先にguard_preflight.py --jsonがroot_branch_state=defaultを返した場合のみ canonical root に対して行い(linked worktree からgit checkout mainしない)、drift 時は同期せずhuman_requiredのまま停止する。stash /git stash popは canonical root 自身の変更に対してのみ行い、issue worktree の変更を main へ carry over しない。(3) Step 3 で session の worktree をcleanup_exec経由で削除した後の Step 4〜8 の command は、canonical root を cwd として実行され(相対 path のまま解決できる)、削除済み cwd に依存しない。test は削除前に cwd を worktree に置いた状態から実行し、削除後に削除済み cwd で同じ command を実行すると失敗する negative control と、canonical root cwd で成功する positive を持つ。(4) 実行する step は 1・2・3・7、gh 非依存の後続 command(fake gh 許容)で、command を持たない Step 6・8 は「削除済み cwd に依存する相対参照を含まない」ことを SKILL.md の静的検査で確認する。(5) SKILL.md のcleanup_exec.pycommand は相対 path の単一 bash block のまま維持し(実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891 の parity test が機械抽出する)、追加する block はscripts/agent-ops/cleanup_exec.pyを含めない。cleanup_execの削除認可(PR merged / branch・OID / linked Issue / target clean / partial cleanup 検証)は緩和しない。 - AC9: nested cwd identity。cwd が issue worktree 配下のサブディレクトリ(例
.claude/worktrees/issue-N-slug/src)でLOOP_ISSUE_NUMBER未設定でも、catalog entry の worktree realpath と cwd の realpath containment で active Issue を特定する。primary root は全 worktree の path prefix になり得るため、linked worktree entry を優先し、複数一致する場合は最も深い一致を採用する(primary は他に一致が無い場合のみ)。basename / branch 名だけに依存しない。LOOP_ISSUE_NUMBERが設定され catalog 上の実 identity と矛盾する場合はactive_issue_catalog_conflictで非成功にする。canonical root が真に drift している場合は従来どおりhuman_required/root_drift_active_worktree_mismatchを維持し、root cwd + 明示 Issue 番号の既存挙動は変えない。 - AC10: catalog failure semantics。
list_worktrees()がNoneを返す場合(worktree_catalog_unavailable)、git common-dir 取得失敗(git_common_dir_unavailable)、primary root 不在(primary_root_unresolved)、repository identity 不一致(repository_identity_mismatch)を、空 catalog や正常として扱わず、guard / executor / materialize lane のそれぞれで structured failure(JSON 応答と非 ok の status / 固定 reason code)を返す。materialize_cleanup_contract.pyは Allowed Paths 外のため変更しない:cleanup_exec.resolve_project_root()は例外を投げず best-effort の path を返し、identity 検証はverify_cleanup_authorization/verify_discard_authorization/run/run_discard_check/run_discard_consumeの既存の構造化 refusal 経路で行う。materialize lane の test は public CLI(materialize_cleanup_contract.py、既定の verify 経路)を subprocess 実行して JSON と非成功を確認する(verify=Falseは function-only parameter で CLI からは到達できず、本 AC の対象外とする)。status=okへの false-green を各失敗種別の regression test で防ぐ。新しい approval layer・schema・hook は追加しない。 - AC11: public CLI parity。root 候補の優先順は
--project-root(guard_preflight のみ)→CLAUDE_PROJECT_DIR→ script 位置とし、いずれの候補も独立にgit rev-parse --git-common-dirで repository を特定する。入力種別ごとの期待結果は単一とする: 候補が linked worktree なら同一 repository の primary root へ正規化し、候補が Git work tree でない、または独立に得た common-dir が catalog の primary と一致しない場合は拒否(repository_identity_mismatch/primary_root_unresolved)する。cwd の repository との一致は要求しない(既存 AC6 の fixture が cwd とCLAUDE_PROJECT_DIRを別 repository にするため)。CLAUDE_PROJECT_DIRが (a) primary root、(b) issue worktree を指す場合、および (c) 未設定で script が issue worktree 内に存在する場合(fixture は script 一式を fixture repository の tracked tree に含めて linked worktree 内の script を実行する)の全てで、guard_preflight.py/cleanup_exec.py/ materialize lane が同一の canonical primary root を評価する。root selection の共有 helper はworktree_catalog.pyに置く。 - AC12: 証跡。新規テストは
test_ac<N>_*の命名規約に従い、各 AC に 1 件以上の専用 test を持つ。新規テスト追加後は、(1) 各 AC の-k test_ac<N>_が 1 件以上収集され PASS すること、(2) 修正前 commit で実行した assertion failure(pytest exit 1)、(3) 修正後 PASS(exit 0)、(4) public CLI の exit code と JSON、(5) negative control、(6) 実行後の worktree / branch / root の状態を PR 本文に記録する。(2)(4)(5)(6) は機械検証 VC を持たない PR 本文証跡であり、pr-review(pr-reviewer)が AC ごとに独立再検証する。exit 5(no tests collected)や exit 4(file not found)を assertion failure の証拠にしない。既存テストの全 PASS だけで AC8〜AC11 の達成を主張しない。RVA の immediate は pytest subprocess による実 CLI 実行証跡のみで充足され、live Claude Code session での skill invocation(procedure_steps_executed_in_declared_order)は本 Issue では unverified のまま PASS と主張しない。
Verification Commands
各 AC の marker は # AC<N> の bare 形式。新規テストは未作成の specific test file を参照し、-k test_ac<N>_ で AC ごとの専用 test を選択する。修正前は file 不在により pytest exit 4(ERROR: file or directory not found)となり expected baseline fail として扱われる。実装後は、当該 AC の test が 1 件も無ければ exit 5 で VC が失敗するため、空疎な test file で全 AC が green になることはない。-k による未存在テスト名の選択(exit 5)を baseline fail の根拠にしない。実装後は、修正前 commit での exit 1(assertion failure)と修正後 exit 0 を AC12 の証跡として別途取得する。
# AC1
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py -k test_ac1_ -q
# AC2
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py -k test_ac2_ -q
# AC3
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py -k test_ac3_ -q
# AC4
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py -k test_ac4_ -q
# AC5
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec_root_selection.py -k test_ac5_ -q
# AC7
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py scripts/agent-ops/tests/test_cleanup_exec_root_selection.py -k test_ac7_ -q
# AC8
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec_root_selection.py -k test_ac8_ -q
# AC9
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py -k test_ac9_ -q
# AC10
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py scripts/agent-ops/tests/test_cleanup_exec_root_selection.py -k test_ac10_ -q
# AC11
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py scripts/agent-ops/tests/test_cleanup_exec_root_selection.py -k test_ac11_ -q
# AC12
# baseline-expect: fail
$ uv run --locked pytest tests/agent_guards/test_guard_preflight_cli_root_selection.py scripts/agent-ops/tests/test_cleanup_exec_root_selection.py --collect-only -q
# AC6
# baseline-expect: pass
$ uv run --locked pytest tests/agent_guards/test_worktree_scope_guard.py scripts/agent-ops/tests/test_cleanup_exec.py scripts/agent-ops/tests/test_cleanup_exec_non_closing_authority.py tests/test_post_merge_cleanup_boundary.py -qAllowed Paths
scripts/agent-ops/guard_preflight.pyscripts/agent-ops/cleanup_exec.pyscripts/agent-ops/worktree_catalog.pyscripts/agent-ops/tests/test_cleanup_exec.pytests/agent_guards/test_worktree_scope_guard.pytests/agent_guards/test_guard_preflight_cli_root_selection.py(新規)scripts/agent-ops/tests/test_cleanup_exec_root_selection.py(新規).claude/skills/post-merge-cleanup-executor/SKILL.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- canonical primary worktree identity を解決するために cleanup policy の緩和が必要になる場合
- destructive cleanup を guard/preflight の外へ移す必要がある場合
- Allowed Paths 外の runtime/harness 変更が不可避な場合(
scripts/agent-guards/worktree_scope_guard.pyの root 解決の統一を含む) CLAUDE_PROJECT_DIR自体の global semantics 変更が必要になる場合- unrelated worktree / branch の削除・変更が必要になる場合
Required Skills
なし。Python / Git worktree / repository-native post-merge-cleanup contract の範囲。
Runtime Verification Applicability
decision: immediate
reason: "Allowed Paths の scripts/agent-ops/** と .claude/skills/post-merge-cleanup-executor/SKILL.md は docs/dev/extension-surface-runtime-policy.yaml の rule skill-invocation-procedure-or-contract-change と subagent-lifecycle-start-stop-delegation-fallback に一致し、いずれも default_decision: immediate である(assertion 単位の not_applicable / compat でも Issue-level の decision 要求は緩まない)。proven_not_runtime_loaded / executable_or_prompt_semantics_unchanged の exception はいずれも成立しない(AC8 は SKILL.md の手順を変更する)。ゲーム runtime の起動は不要だが、documented 8 ステップの実行到達性は real-Git fixture 上で実 CLI を subprocess 実行して観測する。"
applicable_acs: [AC8]
runtime_assertion_bindings:
- profile: skill-invocation-runtime-smoke
assertion: procedure_steps_executed_in_declared_order
disposition: non_dispositive_readiness_compat
demonstrated_by: AC8
reason: "AC8 が documented 8 ステップの command 列を real-Git fixture 上で宣言順に実 CLI 実行して観測する。live Claude Code session での skill invocation smoke は本 Issue では実施しない(その旨を AC12 の証跡に明記し、PASS と主張しない)。"
- profile: skill-invocation-runtime-smoke
assertion: output_contract_schema_fields_present
disposition: not_applicable
reason: "POST_MERGE_CLEANUP_REPORT_V1 の出力契約フィールドは変更しない。"
- profile: subagent-lifecycle-causal-evidence-smoke
assertion: subagent_start_stop_causal_evidence_correlated
disposition: not_applicable
reason: "SubAgent の delegation 条件・fallback 分岐・start/stop signal 処理は変更しない(scripts/agent-ops/** は path 一致のみ)。"
execution_environment: "Current developer machine、isolated tmp_path 内の real-Git fixture(primary root + linked issue worktree)、実 CLI の subprocess 実行。"
skip_conditions: "git が利用不能な場合のみ SKIP(unavailable)。SKIP / unavailable は PASS ではない。"
fallback_policy: "project_root の直接注入・mock のみ・fake git のみ・marker 文字列の存在のみを PASS として数えない。許容するのは local bare origin と、GitHub API 呼び出し(gh)のみの PATH 上 fake であり、git は実物を使う。"
artifact_requirements: "tested HEAD(commit SHA)、実行した CLI の argv・exit code・JSON、fixture の worktree / branch / root の実行前後の状態を PR 本文に引用する(HOME 絶対パス・secret を含めない)。"In Scope
worktree_catalog.pyへの primary root 解決・identity 検証の additive な共有 helper 追加(list_worktrees()は不変)と、guard_preflight.py/cleanup_exec.pyからの利用。materialize lane はcleanup_exec.resolve_project_root()経由で同じ root を使い、materialize_cleanup_contract.py自体は変更しない。- catalog / common-dir / primary 不在 / identity 不一致の structured failure 化(AC10)。
- nested cwd からの active Issue 特定(AC9)。
post-merge-cleanup-executor/SKILL.mdの main 同期と自 worktree 削除後の実行 cwd の是正(AC8)。- 上記を固定する real-Git fixture + public CLI の新規テスト(既存 2 テストファイルの回帰維持を含む)。
Out of Scope
materialize_cleanup_contract.pyの変更、list_worktrees()の署名・戻り値の変更、およびworktree_bootstrap_exec.py/git_worktree_probe.py/verified_*_merge_exec.pyなど既存 consumer の変更。scripts/agent-guards/worktree_scope_guard.pyなど guard / cleanup 以外の repository-root resolver の統一(別 Issue)。cleanup_exec._perform()の worktree remove 後例外時のactions_taken保持(実装: cleanup_exec の worktree remove 成功後の例外で成功済み actions_taken を保持する #2913 が所有。同一ファイルの別関数であり、競合時は後続 PR が rebase する)。- 実装: guard arbitration preflight と cleanup contract delivery を機械化する (agent-ops) #1137 の guard contract / 実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196 の branch-only lane の再実装、cleanup 認可 policy の緩和。
- 新しい approval layer・hook・wrapper・schema、
CLAUDE_PROJECT_DIRの global semantics 変更。
Required Design References
- docs/dev/workflow.md(Availability Invariant、Issue contract を作業計画の正本として扱う条件)
- docs/dev/runtime-verification-policy.md(Runtime Verification Applicability と assertion binding)
- docs/dev/extension-surface-runtime-policy.yaml(Allowed Paths と RVA decision の整合)
- docs/dev/secret-policy.md(本 Issue は secret を扱わない)
- .claude/skills/post-merge-cleanup-executor/SKILL.md(documented 8 ステップ)
- 実装: guard arbitration preflight と cleanup contract delivery を機械化する (agent-ops) #1137 / 実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196(既存 cleanup 認可境界と branch-only lane。再実装しない)
Delivery Rule
1 Issue = 1 PR。既存 cleanup policy を緩和せず、root-selection false-positive の除去に限定する。
Activity
squne121 commentedon Oct 7, 2026
Issue #2979 敵対的レビュー
対象: Issue #2979 | 2026年10月8日時点
暫定判定: 修正推奨(Issue refinement)
Issue の問題設定は妥当です。現行実装では、Claude Code の issue worktree を repository primary root と誤認する経路が存在します。
ただし、root resolver の修正だけでは、cleanup の誤判定と安全な実行を両立できない可能性があります。 特に Git catalog 取得失敗時の扱いと、現在の worktree の識別に注意が必要です。
確認済みの状態:
guard_preflight.pyとcleanup_exec.pyの両方で、CLAUDE_PROJECT_DIRまたは実行スクリプトの配置先を root として採用する実装を確認しました。推奨する基本方針は、cleanup policy を緩和せず、Git の primary worktree identity を共有 resolver で特定することです。新たな承認レイヤーや恒久的 gate は不要です。
Findings — 重要度順
P1-1: root resolver 修正後も、cleanup Skill 全体が issue worktree から実行できない
問題
post-merge-cleanup-executor/SKILL.md の Step 2 は以下を実行します。
ところが、canonical primary worktree が既に
mainを checkout している場合、linked issue worktree からgit checkout mainは失敗します。実際に独立した real-Git fixture で検証すると、
checkoutは exit 128、既存のmainworktree との衝突を報告しました。さらに、現在の issue worktree 自身を削除した場合、後続の相対パス実行が失敗することも確認しました。
Claude Code の公式仕様でも、SubAgent の
cdは各 Bash 呼び出し間で持続せず、削除された作業ディレクトリへの操作は失敗し得ます。image
Claude Code Docs
影響: Issue #2979 の AC1〜AC7 が成功しても、実際の8ステップ cleanup が完遂できない可能性があります。
最小修正: Allowed Paths 内の executor Skill を修正し、main 同期は canonical root 側で実行する。現在の session が削除対象 worktree 上にいる場合は、自己削除を開始せず、root 側の正規 cleanup 実行コンテキストへ引き継ぐ。既存の認可境界
cleanup_execは維持します。P1-2: catalog failure が
status=okに変換される問題
guard_preflight.py L170-L235 では、
list_worktrees()がNoneを返しても空リストへ変換します。root branch が default なら、その後
status=okになる経路が残ります。また worktree_catalog.py は
git_common_dirの取得に失敗しても catalog 自体を返します。影響: primary root resolver の初回 catalog 取得が成功しても、その後の preflight catalog 取得に失敗すると、false-green が成立し得ます。
最小修正: catalog failure / common-dir failure を構造化 reason code で非成功にする。guard、executor、materialize の public CLI で JSON 応答が維持されることを検証する。
これは AC4 の具体的な負例として明記すべきです。
P1-3: worktree 内のサブディレクトリから実行すると active issue を見失う
問題
guard_preflight.py::_active_issue()は cwd の basename または root branch 名から Issue 番号を推定します。例えば、実際の cwd が次の場合です。
root resolver が正しく primary root を返すと、
current_branchはmainまたは primary root 側の別 branch になります。LOOP_ISSUE_NUMBERがない場合、srcと root branch からは2979を復元できません。影響: 本当に root drift が起きていても、active issue を検出できず、
human_requiredではなくblockedと自動回復 hint に落ちる可能性があります。最小修正: cwd を catalog の worktree realpath に包含関係で対応付け、該当 entry の branch/path から active issue を特定する。
LOOP_ISSUE_NUMBERが存在する場合は、その対応が矛盾しないことを確認する。既存の root cwd + 明示 Issue 番号の動作は維持します。
P2-4: common-dir identity のテストが自己整合性だけで PASS し得る
現行
list_worktrees()はgit_common_dirを一度だけ求めて全 entry に設定します。したがって、catalog entry 同士の
git_common_dirを比較しても、独立した identity 検証にはなりません。AC3 は、linked worktree と primary root のそれぞれに対して実際に
git rev-parse --git-common-dirを実行し、realpath で比較することを明示すべきです。Git 公式資料では、primary worktree が catalog の先頭に現れ、linked worktree は共通 Git directory を共有する仕様です。
image
Git at Google
+1
この既存 Git 機能を使えば、branch 名や
.gitの親ディレクトリを root identity と推測する必要はありません。P2-5: baseline-fail がテスト未収集だけで成立する
Issue #2979 の指定 Verification Commands にある次の選択名は、調査時点の main の対象テストファイルには存在しません。
guard_preflight_cli_issue_worktree_root_resolutionissue_worktree_session_uses_primary_rootpytest はテスト未収集時に exit 5 を返すため、これを
baseline-expect: failの根拠にすると欠陥を再現したことになりません。image
pytest documentation
最小修正: テストを先に追加し、対象ケースの収集件数が正であることを確認してから、修正前に assertion failure(exit 1)、修正後に PASS(exit 0)となることを要求する。
推奨する Issue contract 改訂
既存 AC1〜AC7 は維持し、以下の具体的な拡張を推奨します。
issue-N-slug/srcなどの配下からも active issue を正しく特定すること。root drift 時のhuman_requiredを維持すること。CLAUDE_PROJECT_DIRが primary root を指す場合と issue worktree を指す場合の双方で同じ primary root を得ること。guard_preflight --project-rootを指定した場合も root identity の照合を省略しないこと。CLAUDE_PROJECT_DIRは Claude Code の仕様上、session 開始時の project root を保持し、途中で worktree に入っても自動更新されません。image
Claude Code Docs
そのため、両方の環境変数パターンを検証する価値があります。
実装方針の評価
共有 root resolver を
worktree_catalog.pyに配置推奨
既存 Git catalog と deadline を再利用し、重複実装を避けられます。
既存 cleanup authorization を保持
必須
PR merged、branch / OID、linked Issue、target cleanliness、partial cleanup の検証は緩和しません。
新規 hook・approval layer・独自 schema の追加
不要
今回の不具合を解消する直接的な価値がありません。
実ゲーム runtime による検証
不要
isolated real-Git fixture と public CLI のプロセス統合テストで検証可能です。
最終結論
Issue #2979 は実装価値が高く、主たる設計方向も正しい。ただし現状のまま implementation-ready とするには不足があります。
最優先は P1-1 の実 workflow 到達性と、P1-2・P1-3 の preflight false-green / 誤った recovery hint の是正です。
#1137 の既存 guard contract と #1196 の branch-only lane は変更せず、現在の Issue の Allowed Paths 内で対処する方向を推奨します。実行コンテキストの修正がその範囲で成立しない場合だけ、Outcome を CLI root-resolution に限定して別 Issue へ切り分けるのが適切です。
今回の判定は live GitHub 本文・コメント、関連実装、公式 Git / Claude Code 仕様、および独立した real-Git の局所再現に基づきます。実際の Claude Code session 全体を再実行して成功・失敗を検証したものではありません。
squne121 commentedon Oct 7, 2026
推奨アクション
Issue #2979 を既存の
issue-refinement-loopで精緻化し、承認済みの実装契約へ更新する方針を推奨します。対象の OWNERコメント #6047844759 には、優先して反映すべき5件の指摘があります。
既存 AC1〜AC7 を維持し、提案された AC8〜AC11 と Verification Commands の補強を承認するのが妥当です。Git の primary worktree 判定には公式の
git worktree list --porcelain -zを利用でき、pytest の exit 5 はテスト未収集を意味します。現行 Skill では通常の refinement iteration に個別承認は不要で、既定上限は3回です。一方、canonical な environment/integrity failure や genuine human judgment は迂回しない設計です。
Claude Code に貼り付ける実行プロンプト
Issue #2979 — OWNER 承認済み Issue Refinement 実行指示
あなたは既に auto mode で起動している interactive Claude Code の main/root control-plane です。現在の session を継続し、追加の人間承認を要求せず、repository-native
issue-refinement-loopを完了してください。対象
Repository:
squne121/loop-protocolIssue: https://github.com/squne121/loop-protocol/issues/2979
Trusted human-context anchor: https://github.com/squne121/loop-protocol/issues/2979#issuecomment-6047844759
Skill:
.claude/skills/issue-refinement-loop/SKILL.mdMax iterations: 3(現行既定値)
今回のユーザーメッセージは新しい明示的な人間指示です。 対象コメントで提案された技術的修正、Issue 本文の改訂、AC/VC 補強、通常の controlled GitHub mutation、調査・SubAgent 委譲・review/fix iteration の自動実行を承認します。
ただし、この承認は Claude Code の permission bypass や canonical policy の無効化を意味しません。
1. Fresh state の取得
最初に以下を実施してください。
GitHub の Issue 実装: post-merge cleanup guard が issue worktree を repository root と誤認する root selection を是正する #2979 本文・全コメント・関連 Issue・PR を再取得。
指定 anchor comment が対象 Issue に所属し、OWNER による投稿であり、内容が drift していないことを確認。
GitHub default-branch HEAD、
origin/main、local checkout、active worktree、dirty state を確認。current HEAD の
CLAUDE.md、AGENTS.md(存在する場合)、現行 Skill と必要な references を読む。.claude/agents/codebase-investigator.md、.claude/agents/issue-editor.md、必要なら.claude/agents/web-researcher.mdを読み、現在の tool/permission/input/output 契約を確認。対象 Issue と重複する既存 Issue、既存 PR、変更予定ファイルとの ownership conflict を検索。
過去の session 情報やこのプロンプト内の説明より、fresh repository evidence と canonical SSOT を優先してください。
2. Canonical refinement entry
issue-refinement-loopを正規の Skill entrypoint として実行してください。今回指定された GitHub コメントを operator-selected human-context anchor として扱い、単なる unlabeled URL や agent report に降格させないでください。ただし、trusted principal と origin binding は canonical evaluator に検証させ、結果を捏造しないこと。
現行 Skill に記載された
preflight.run.with_human_contextを canonical main root から使用します。戻り値の
STATUS、NEXT_ACTION、BLOCKERS、artifact、planner decisions に従ってください。Trusted contract patch が必要と判定された場合のみ、現行 Skill が許可する
contract_update.run.with_human_contextを main/root thread から実行します。調査証跡 transport が必要な場合は、read-only preflight と mutation phase の binding を維持し、正規の evidence transport を使用します。
NEXT_ACTION: issue_editor_requiredが返った場合は、同じ contract update を無限再試行せず、既存のissue-editor/edit-issuecontrolled transaction による full rewrite route へ進んでください。手書きの新規 schema、独自 gate、非正規の raw GitHub mutation を追加しないこと。
3. SubAgent の実行と完了待機
必要な SubAgent を実際に起動し、その最終結果を受信するまで後続処理へ進まないこと。
codebase-investigator
Planner の
investigation_policyに従い、必要な read-only 調査を委譲してください。調査対象:
guard_preflight.pyの root selection と active Issue classificationcleanup_exec.pyと materialize laneworktree_catalog.pyの catalog/common-dir failure semanticspost-merge-cleanup-executor/SKILL.mdの全8ステップ実行到達性既存 tests と real-Git fixture の coverage
関連 Issue 実装: guard arbitration preflight と cleanup contract delivery を機械化する (agent-ops) #1137、実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196、実装: source-evidence human_review 後の operator C1 判断を Step 1 に安全に渡す #2930
現行 Issue の Allowed Paths で修正可能か
SubAgent には task、対象ファイル、base SHA、authority、制約、必要な証跡形式、期待成果物を明示してください。
現行 AGY / native fallback policy を守り、許容された advisory fallback は利用して構いません。AGY 失敗や未検証結果を成功に変換しないこと。
web-researcher
Planner の
web_research_policy.requiredが true の場合のみ起動してください。Git worktree、pytest、Claude Code の最新公式仕様を一次資料で確認し、Issue contract に影響する外部 claim のみ検証してください。
Step 1 と Step 1b が独立なら並列実行して構いません。ただし 全 SubAgent の terminal result を join した後 に Step 2 へ進んでください。
issue-editor
Issue 書き換えが必要な場合、現行 Step 4 に従って起動してください。
入力は対象 Issue 番号、canonical reviewer feedback URL、readiness payload、検証済み findings
Issue 本文以外の implementation mutation をさせない
controlled transaction と GitHub readback を必須とする
結果が返る前に review を再開しない
SubAgent の dispatch 成功、task ID 発行、background 開始は完了ではありません。
4. 承認する Issue contract 変更
対象コメントの Findings P1-1〜P2-5 を精緻化対象として採用します。
既存の Issue goal、AC1〜AC7、既存 cleanup authorization、fail-closed policy、Delivery Rule を維持した上で、以下を追加・補強してください。
AC8 — Full workflow reachability
issue worktree session から main 同期を行う際、canonical primary root を正しく対象にする。
linked worktree から
git checkout mainして衝突する設計を解消する。実行中 session の worktree を削除した後、無効な cwd で後続処理を実行しない。
必要なら canonical root の正規 cleanup execution context へ移行する。
cleanup_execによる既存の削除認可を維持する。実8ステップの到達性をテストする。
AC9 — Nested cwd identity
issue worktree 内の
src/等のサブディレクトリからも active Issue を識別する。catalog entry と cwd の realpath containment を使用する。
branch name / cwd basename だけに依存しない。
LOOP_ISSUE_NUMBERと実 catalog identity の矛盾を検出する。真の root drift 時には従来の human-required 判定を維持する。
AC10 — Catalog failure semantics
list_worktrees()failure を正常な空 catalog と同一視しない。git common-dir failure、primary root 不在、repository identity 不一致を成功扱いしない。
guard、executor、materialize lane に必要な structured failure を維持する。
status=okへの false-green を regression test で防ぐ。不必要な新しい承認 layer や schema は追加しない。
AC11 — Public CLI parity
CLAUDE_PROJECT_DIRが primary root を指す場合と issue worktree を指す場合の双方を検証する。explicit
--project-rootでも repository identity の検証を省略しない。guard / executor / materialize の root selection semantics を共有する。
preflight と executor が異なる root を評価しない。
既存 AC3 の補強
linked worktree と primary root のそれぞれから独立に
git rev-parse --git-common-dirを実行し、canonical realpath identity を比較すること。同一 catalog producer が全 entry に複写した field 同士の比較だけを独立検証としないこと。
5. Verification Commands の修正
対象コメントの P2-5 を必ず反映してください。
新規テスト名がまだ存在しない状態で
pytest -kを実行し、exit 5 になっただけでは baseline RED を実証していません。次を区別してください。
exit 5: no tests collected。assertion failure の証拠にしない。
exit 1: 実際に収集・実行されたテストの assertion failure を確認する。
exit 0: 対象 assertion が実行され、PASS したことを確認する。
既存 repository の canonical baseline-fail VC 規則と整合する形へ Verification Commands を修正してください。
実装時に新規テストを追加した後は、テスト収集件数、修正前 RED、修正後 GREEN、public CLI JSON、negative control、実行後 state を証跡として取得できる契約にしてください。
既存テストの全 PASS だけで AC8〜AC11 を証明したことにしないこと。
6. Scope と変更制約
本 refinement では原則として Issue #2979 の既存 Allowed Paths を維持します。
対象コメントが示す範囲での AC/VC 追加、Issue 本文構造改善、既存ファイルのテスト要件追加は承認済みです。
新しい architecture layer や別 Issue が所有する runtime/harness の変更が必要だと判明した場合は、最初に existing Issue / owner を調査し、現在の Issue 内で対処可能か判断してください。
独立した follow-up が必要なら重複を確認して起票します。必要性がない場合は Issue を増殖させないこと。
個人趣味開発のため、品質・実用性・実行完了率を優先します。
新規 approval framework、hook、wrapper、schema、一般的 security hardening は、今回の具体的 failure class の修正に不可欠でなければ追加しません。
7. Refinement review loop
現行 Skill の以下の経路を遵守してください。
Fresh preflight と planner result
必要な investigation / web research
SubAgent completion join
Canonical Step 2 review
必要なら controlled Issue rewrite
GitHub body/title readback
Fresh preflight / review
Semantic design review(applicable の場合)
Final readiness / termination
Step 2 の
root_review_pipeline.produceは Skill 規定どおりrun_in_background: trueで起動し、background task の完了通知と実 JSON result を join してからcanonical_step2_routeを consume してください。canonical Step 2 で legacy
issue-reviewerSubAgent を追加起動したり、独自の verdict classifier を実装したりしないこと。needs-fixは既定の最大3 iteration まで自動継続してください。通常の修正、review finding、VC 修正、controlled GitHub 更新のたびに人間承認を要求しないでください。
ただし genuine
human_judgment_required、authority binding 不成立、integrity failure、irreconcilable scope conflict、規定 iteration 上限については正規停止条件を守ります。結果を捏造したり gate を迂回したりしないこと。8. 再発防止 Issue
調査で独立した再発リスクが確認された場合は、既存 Issue を全 state で検索してください。
実装: post-merge cleanup guard が issue worktree を repository root と誤認する root selection を是正する #2979 内の AC/VC で解消できる問題は 実装: post-merge cleanup guard が issue worktree を repository root と誤認する root selection を是正する #2979 に集約する。
実装: guard arbitration preflight と cleanup contract delivery を機械化する (agent-ops) #1137 / 実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196 の既存契約は再実装しない。
pytest no-collection 関連の 実装: pytest未収集のreadiness誤分類を修正し、明示した新規テスト指定を自動修正経路でも維持する #1434 / 改善: baseline_vc_preflight.py classifier に pytest invocation 検出と exit 4/5 baseline-fail 分類を追加する #366 / 実装: VC baseline-fail 用 pytest command を canonical form に正規化して contract-review 往復を削減する #1285 / 実装: baseline_vc_preflight.py の existing_file_missing_node_id_noncanonical 分類に baseline-expect: fail escape hatch を追加する #2515 と重複しない。
既存 Issue で未解決の問題なら既存 Issue を再利用する。
他の scope が所有し、独立した implementation を必要とする新規欠陥だけを、具体的な再現条件・root cause・AC/VC・Allowed Paths・dedupe_key を備えた GitHub Issue として起票する。
再発防止 Issue の起票はこの invocation で承認します。
9. 完了条件
以下を満たすまで、単なる提案・調査で終了しないでください。
Issue 実装: post-merge cleanup guard が issue worktree を repository root と誤認する root selection を是正する #2979 の review findings が適切に反映されている
AC1〜AC11 の範囲・責任・検証方法が明確
Verification Commands が canonical である
GitHub 最新本文への controlled mutation が確認されている
Fresh contract review / readiness が完了している
Skill の正規 termination が完了している
SubAgent / background task が全て terminal 状態である
再発防止 Issue の要否を判定済みである
approvedで終了した場合も、今回は Issue refinement のみ です。impl-review-loop、実装、PR 作成、merge、cleanup を勝手に開始しないでください。最後に日本語で以下を報告してください。
Issue 実装: post-merge cleanup guard が issue worktree を repository root と誤認する root selection を是正する #2979 の最終状態と本文更新内容
消化した各 finding と AC/VC への反映
使用した SubAgent とその terminal result
Review iteration 数と最終判定
Fresh verification evidence
新規再発防止 Issue の URL、または不要とした根拠
残 blocker と次の implementation handoff 条件
これらの作業を現在の interactive auto-mode session で直ちに実行してください。
再発防止 Issue の判断
今回、新規 Issue は起票していません。P1-1〜P2-5 は原則として #2979 の既存 Allowed Paths 内で扱えます。また、pytest 未収集の分類については #1434 が CLOSED であり、現行
baseline_vc_preflight.pyにも exit 5 をvc_no_tests_collected / blockedとする処理を確認しました。別の failure class が実調査で確認された場合のみ、プロンプト内の指示に従って重複を確認し、独立 Issue を起票させる構成です。
squne121 commentedon Oct 7, 2026
Issue refinement 終了報告(approved)
Issue #2979 の refinement を OWNER 承認済み anchor(https://github.com/squne121/loop-protocol/issues/2979#issuecomment-6047844759)に基づき完了した。本文 sha256 は
56cb97f7c9923d5e4c98c6b23884b85347928a6b38444e554b10441de85017f2。この終了は実装開始の承認ではない(impl-review-loopは起動していない)。反映内容
-kによる未収集(exit 5)は baseline fail の根拠にしない。未作成の specific test file を参照する exit 4 方式に改め、-k test_ac<N>_で AC ごとの専用 test を要求した。not_applicableからimmediateへ是正した。procedure の live 検証は unverified のまま残し、AC12 で PASS と主張しないことを明記した。review の経過
実装時に確定すべき非 blocking の注意事項(反復 2 の medium / low)
verify_*の current_branch 判定より前に行う。rev-parse --is-bare-repositoryを使う。worktree_scope_guard.pyの root 解決は out of scope のまま。同 hook は現行 settings.json に未配線であることを確認済みで、runtime への影響は限定的。guard 配線時に contract の読み取り root が乖離しないかを再確認する。git -C <canonical_root>か cwd 指定)が.claude/settings.json(Allowed Paths 外)の変更を要さないことを確認する。root drift 時の停止範囲も固定する。tests/codex/test_cleanup_exec_branch_only.py、scripts/agent-ops/tests/test_cleanup_exec_issue_2628_e2e.py、tests/agent_ops/test_control_plane_worktree_remote_binding.pyも実行する。git_worktree_probe.pyは catalog 失敗時に exit 0 かつ entries 空を返すため、空 entries を検出したら停止する。OWNER 判断として本 refinement が採った方針
materialize_cleanup_contract.pyは変更せず、cleanup_exec.resolve_project_root()が例外を投げない方針で Allowed Paths 内に収めた。guard_preflightがroot_branch_state=defaultを返す場合のみ行い、root drift 時の human_required を迂回しない。再発防止 Issue
不要と判定した。guard 側 root 統一は現行配線外で実害がなく、live skill smoke の基盤は #2981 が所有する。pytest 未収集の扱いは #1434 の既存契約と重複する。
未実施の項目
git checkout mainの失敗)は実機で独立に再現して確認した。squne121 commentedon Oct 8, 2026
確認結果と推奨方針
2026年10月8日時点の GitHub を確認しました。
refinement_approvedが記録されています。推奨は、現行 Issue contract を維持し、
impl-review-loopを最大3 iterationの正規ループで実行することです。 通常の修正・テスト失敗・レビュー差し戻し・CI修復は自動継続し、最終的にPRを人間がmerge判断できる状態にします。重要なのは、refinement 時に残った medium/low findings も実装前に確認することです。特に materialize lane の失敗処理、固定 reason code、cleanup Skill の実行コンテキスト、既存テストとの互換性を省略しない構成にします。
再発防止 Issue を起票
#2988 — termination publisher の dry-run 誤投稿
GitHubへの新規起票を確認しました。legacy モードでも
--dry-runを正しく伝搬させ、GitHub投稿と Task Context signal が発生しないことを回帰テストで固定する内容です。これは #2979 の Allowed Paths 外の独立した不具合として扱います。今回の実装PRには混在させません。
Claude Code に貼り付ける実行プロンプト
以下は、既に auto mode で起動している fresh interactive Claude Code にそのまま貼り付ける指示です。現行
impl-review-loopの Step 1 → 2 → 4 → 5、SubAgent completion protocol、current-HEAD verification、terminal gate に沿って設計しています。Issue #2979 — impl-review-loop 自律実装・検証・PRレビュー指示
あなたは、既に auto mode で起動している interactive Claude Code の main/root control-plane です。現在の session を継続し、repository-native
impl-review-loopに従って Issue #2979 の実装から PR の merge 直前までを完遂してください。目的と実行承認
squne121/loop-protocol.claude/skills/impl-review-loop/SKILL.mdmax_iterations: 3(現行 canonical default)このユーザーメッセージを、新たな明示的な実装実行承認として扱ってください。
次の通常作業は個別の人間承認を求めず、自律的に実行することを承認します。
実行できる作業を調査や提案だけで終了しないでください。
ただし、この承認は Claude Code permission bypass、repository authority の無効化、secret 取得、force push、実 merge、auto-merge、不可逆 cleanup の承認ではありません。
auto mode の既存 session・permissions・hooks を維持してください。通常の permission classifier が認める正規 workflow を使用し、権限回避手段を追加しないでください。
1. Fresh state と canonical contract の確認
最初に次を fresh に確認してください。
origin/main、local HEAD、branch、worktree catalog、dirty state。CLAUDE.md、AGENTS.md、.claude/rules/**、必要なdocs/dev/**と SSOT。impl-review-loop/SKILL.mdと次の Step 定義。steps/preparation.mdsteps/step-1-implementation.mdsteps/step-2-verification.mdsteps/step-4-pr-review.mdsteps/step-5-feedback-and-termination.mdsteps/step-5-mergeability-handling.mdsteps/conflicting-pr-escalation-runbook.mdsteps/context-protocol-and-guardrails.md.claude/agents/implementation-worker.md、test-runner.md、pr-reviewer.md。.claude/skills/implement-issue/SKILL.md、.claude/skills/pr-review-judge/SKILL.mdと必要な references。今回の Issue は refinement が
refinement_approvedで終了した履歴を持ちます。ただし過去の終了コメントだけを Step 1 起動 authority にしないでください。最新 Issue body、fresh contract-review result、snapshot、current-run intake の canonical 判定を再取得してください。
過去の refinement ログには generated_at の不正確な記録、および Task Context signal の conflict が存在します。これらの過去記録を freshness の証明とせず、現行 workflow が必要とする fresh evidence を使用してください。
preparation.mdの Root-Owned Synchronous Entry Transition を守り、capability preflight → live Issue fetch → current-run intake → route 判定 → Step 1 dispatch を、現行規定に従う連続した root-owned 実行で行ってください。必要な contract snapshot が欠落・stale の場合は、既存の canonical materialization / review repair route を使って回復してください。独自の authorization packet や bypass を作らないでください。
既存 branch / PR が見つかった場合は再利用し、重複作成しないでください。
2. Issue #2979 の実装スコープ
実装の唯一の正本は GitHub 上の最新 Issue #2979 本文です。
現在の契約は AC1〜AC12 を対象としています。実装前に全 AC、Verification Commands、Allowed Paths、Stop Conditions を逐語で確認し、AC ごとの実装対象と検証方法を整理してください。
特に以下の欠陥を修正してください。
2.1 Canonical primary root resolution
git worktree list --porcelain -zを用いて primary worktree を特定する。git rev-parse --git-common-dirを実行し、realpath identity を照合する。worktree_catalog.pyへ共有 helper を additive に追加し、既存list_worktrees()API の互換性を維持する。guard_preflight、cleanup_exec、materialize lane の root 解決を整合させる。2.2 Cleanup workflow の到達性
.claude/skills/post-merge-cleanup-executor/SKILL.mdの実8ステップを調べ、issue worktree session から開始しても実行が継続可能になるよう修正してください。git checkout mainを実行しない。cdの状態が持続すると仮定しない。cleanup_execの既存削除認可は必ず保持する。この Issue の実装中に、実際の開発 worktree を post-merge cleanup しないでください。 削除操作の検証対象は管理された隔離 fixture に限定します。
2.3 Nested cwd と active Issue identity
src/等から起動しても active Issue を識別する。LOOP_ISSUE_NUMBERと実 catalog identity の矛盾を検出する。human_required判定を維持する。2.4 Failure semantics
少なくとも次の reason code を、既存 schema に従って適切に返してください。
worktree_catalog_unavailablegit_common_dir_unavailableprimary_root_unresolvedrepository_identity_mismatchactive_issue_catalog_conflict入力条件と reason code、status、CLI exit code の対応を実装前に明確化してください。
guard、executor、materialize の各 lane で、正常系と異常系を確認してください。
status=okへの false-green を防ぎます。ただし、既存の実行を無意味にブロックする過剰な gate は追加しないでください。2.5 Materialize / compatibility
materialize_cleanup_contract.pyは現在の Issue Allowed Paths 外です。まず
cleanup_exec.resolve_project_root()と既存 verification functions によって、例外を発生させず structured refusal を返せることを確認してください。Allowed Paths 外の変更が不要な設計を優先します。
また、次を維持してください。
cleanup_execの partial-success /actions_taken契約関連する #2913 は
cleanup_exec.pyの別領域を扱うため、current ownership と main drift を確認し、修正を衝突させないでください。3. Verification — false-green を禁止
Issue の Verification Commands を実際に実行してください。
新規テストとして、Issue が許可している次のファイルを使用します。
tests/agent_guards/test_guard_preflight_cli_root_selection.pyscripts/agent-ops/tests/test_cleanup_exec_root_selection.py各 AC に対して
test_ac<N>_*の専用 assertion を配置し、実際の収集件数が正であることを確認してください。検証では以下を必ず区別してください。
実装前 RED を示すときは、追加した regression test を修正前コードに適用した隔離 checkout で実際の assertion failure を観測してください。既存作業や他の worktree を上書きしてはなりません。
real-Git fixture を主とし、GitHub API が必要な箇所のみ fake
ghを使います。故障注入の negative control に限り、目的を明示して Git shim を使って構いません。次の回帰テストも実行してください。
tests/agent_guards/test_worktree_scope_guard.pyscripts/agent-ops/tests/test_cleanup_exec.pyscripts/agent-ops/tests/test_cleanup_exec_non_closing_authority.pytests/test_post_merge_cleanup_boundary.pytests/codex/test_cleanup_exec_branch_only.pyscripts/agent-ops/tests/test_cleanup_exec_issue_2628_e2e.pytests/agent_ops/test_control_plane_worktree_remote_binding.pyテスト対象が最新 main で変わっている場合は、現行契約に従ってください。
post-merge-cleanup-executor/SKILL.mdの documented commands と実際にテストされる経路が一致することを検証してください。RVA が
immediateであることを尊重します。ただし、pytest subprocess の証跡を live Claude Code Skill invocation の成功として誤記しないでください。live 未検証は unverified と報告し、Issue 契約に存在しない新たな恒久 gate を勝手に導入しないでください。4. impl-review-loop の SubAgent orchestration
次の SubAgent を実際に使用し、それぞれの terminal result と final output を取得してから依存する後続 Step に進んでください。
implementation-worker
Step 1 で current Skill に従って起動してください。
SubAgent への message に以下を明示します。
IMPLEMENT_RESULT_V1implement-issueSkill に従い、実装、commit、push、PR 作成または既存 PR 更新まで担当させてください。test-runner
Step 1 が terminal completion した後に起動してください。
current PR HEAD、Issue contract、AC / VC の逐語的 command、command_hash、PR number、worktree を明示的に渡してください。
実際の test 実行事実と
TEST_VERDICT_MACHINE/v2を取得してください。SubAgent が completed であることだけでなく、final result の存在・内容・HEAD binding を確認してください。
pr-reviewer
Step 2 が完了し、canonical VC adjudication により reviewer dispatch が許可された後で起動してください。
pr-review-judgeSkill を使用し、最新 PR HEAD、実 diff、Issue AC、テスト証跡、既存レビューコメント、CI、関連コードを敵対的にレビューしてください。レビューでは次を優先します。
maindrift / stale evidence / stale PR HEAD返却された
verdict、reviewed_head_sha、blockers、warningsを canonical routing に渡してください。Completion join barrier
すべての SubAgent について、dispatch しただけで成功扱いしないでください。
list_agents等、現行 Skill が指定する確認経路で terminal state を確認する。独立した read-only 調査は並列化して構いません。implementation → verification → PR review → judgment の依存関係は守ってください。
必要なら codebase-investigator を追加使用しても構いませんが、現在の Agent 定義と route contract を読んでから委譲してください。
SubAgent discovery failure は、現行 Skill の Stage A / Stage B recovery を利用してください。Stage B の
--agentmain-session persona invocation は child spawn ではないため、存在しない child terminal result を待たないでください。5. Review / Fix loop
impl-review-loopの canonical routing を使用します。基本フロー:
inspect → implement → test → PR review → fix → re-test → fresh review → terminal gateREQUEST_CHANGESは可能な限り自動修正する。fix_deltaは actual reviewer findings を基に作成する。BEHINDは canonical update-branch route に従う。max_iterationsを恣意的にリセット・拡張しない。step4-adjudicateの reviewer dispatch 許可だけで terminal approval としないでください。最終承認の正本は
adjudicate_vc_result.py step5-terminal-gateの exit 0 と、現行 Skill が要求する最新 HEAD の evidence です。APPROVEの自己申告だけで完了扱いしないでください。actual Git conflict、真正な authority conflict、irreconcilable scope conflict、secret 操作、canonical iteration 上限、evidence integrity failure などの本当の停止条件を除き、通常の修正可能な失敗で人間判断を求めないでください。
6. 再発防止 Issue
この invocation では、再発防止 Issue の重複検索と必要な新規起票を承認します。
ただし、すでに次の Issue が存在します。
#2988 は refinement 終了レポートの legacy
--dry-runが GitHub コメントを投稿する別問題です。#2979 の PR には混在させず、重複起票もしないでください。その他についても以下を守ります。
7. PR の完成条件
次を満たすまで、単なる調査・設計・SubAgent dispatch で終了しないでください。
PR の実 merge、auto-merge、post-merge cleanup は行わないでください。
8. 最終報告
日本語で以下を報告してください。
最終報告では、実際に確認できた事実と未検証の主張を区別してください。
この指示に基づいて、現在の interactive auto-mode session で Issue #2979 の
impl-review-loopを直ちに実行してください。人間の merge 判断が必要になる直前まで進めてください。このプロンプトでは、Claude Code の SubAgent が独立した context を持つ点と、現行 repository の completion join 契約を前提にしています。
image
Claude Code Docs
また、Git の primary / linked worktree の識別は公式の porcelain format と common-dir semantics を利用する方針です。
image
git-worktree Documentation
停止境界: 通常の auto mode は継続させますが、genuine な human-judgment gate や権限上の拒否まで無条件に通過させる指示ではありません。実装・PR更新・レビュー修正までを自律実行し、実際の merge は行わない構成です。
fix: post-merge cleanup の main 同期で stash を廃止し ff-only で root の index/…
fix: post-merge cleanup の guard / executor が canonical primary root を…