Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "Issue metadata mutation の認可経路を controlled executor lane へ一本化する(#1284 follow-up)"
change_kind: codeParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: 実装: Issue metadata mutation を worktree ではなく controlled metadata executor 経由にする #1284 で
issue_body.update/issue_comment.publish/contract_snapshot.publishの controlled executor lane を成立させ、metadata mutation を controlled executor 経由に一本化する - Desired Destination:
local_main_branch_guard.pyの rawgh issue edit/gh issue commentallowlist を deprecate し、Issue body/comment mutation は controlled executor 経由のみを production path とする
Current Validated Scope
scripts/agent-guards/local_main_branch_guard.pyのis_github_issue_mutation_command(rawgh issue editallow 判定)とis_github_remote_ops_commandの rawgh issue comment分岐を deprecate 対象として特定し、controlled executor 経由のissue_body.update/issue_comment.publishcommand class(実装: Issue metadata mutation を worktree ではなく controlled metadata executor 経由にする #1284 で追加済み)との重複を解消するgh issue create --repo squne121/loop-protocol --title ... --body-file tmp/...、gh issue close、gh issue reopen、gh pr comment、既存の selectedgh pr editは本 Issue の raw Issue body/comment mutation lane ではないため維持するgh issue commentは--body/--body-file/-F/ stdin body / editor/web/edit-last/delete-last/create-if-none 系を含め、raw Issue comment mutation として local main から block する- Claude hook と Codex hook が同じ shared core を使う前提で、
.claude側テストとtests/codex側テストの parity を更新する - raw
gh issue edit/ rawgh issue commentが block されたとき、recovery hint / stderr が禁止経路を approved path として案内しないことを保証する - 既存の
post-merge-cleanup経路が rawgh issue edit/ rawgh issue commentを使わず、gh issue close/gh issue reopenまたは controlled executor lane に収まることを静的監査で確認する
Remaining Parent Gaps
なし(本 Issue が #1284 の該当 gap の受け皿)
Outcome
scripts/agent-guards/local_main_branch_guard.py の raw gh issue edit / raw gh issue comment allowlist が deprecate され、Issue body/comment mutation の認可経路が controlled executor lane(#1284)に一本化された状態で、Claude/Codex parity を含む must-block / must-allow adversarial テストが CI で PASS している。
Background
local_main_branch_guard.py には gh issue comment <N> --body ... / gh issue comment <N> --body-file tmp/...(is_github_remote_ops_command)と gh issue edit <N> --repo squne121/loop-protocol --body-file tmp/...(is_github_issue_mutation_command)を条件付きで allow する既存 lane がある。
#1284 で issue_body.update / issue_comment.publish / contract_snapshot.publish の controlled executor lane(scripts/agent-guards/controlled_skill_mutation_policy.py / controlled_skill_mutation_exec.py)が成立し、.claude/hooks/worktree_scope_guard.py に controlled executor 経由の exact command class allow が追加された。この結果、Issue body/comment mutation には「raw gh issue edit/gh issue comment allowlist(local_main_branch_guard.py)」と「controlled executor lane(#1284)」の 2 つの認可経路が併存する状態になる。
#1284 の ## Out of Scope に「local_main_branch_guard.py の既存 raw gh allowlist の変更・deprecate(follow-up Issue)」と明記されており、本 Issue はその follow-up として、2 経路の併存を解消し controlled executor lane に一本化する。
In Scope
scripts/agent-guards/local_main_branch_guard.pyのis_github_issue_mutation_commandは、gh issue createを維持しつつ rawgh issue editの allow 部分を deprecate する(gh issue createは controlled executor lane の対象外のため維持)is_github_remote_ops_commandの rawgh issue comment分岐を deprecate する(gh issue close/gh issue reopen/gh pr *の既存 allow は変更しない)- raw
gh issue commentの block 対象には、少なくとも--body、--body-file tmp/...、-F tmp/...、--body-file -、--editor、--web、--edit-last、--delete-last、--create-if-noneを含める - deprecate 後、raw
gh issue edit/ rawgh issue commentが hook で block されることを確認する adversarial テストを.claude/hooks/tests/test_local_main_branch_guard.pyとtests/codex/test_local_main_branch_guard.pyに追加・更新する - controlled executor 経由の
issue_body.update/issue_comment.publish/contract_snapshot.publishが deprecate 後も引き続き allow されることを確認する adversarial テストを追加する - raw
gh issue edit/ rawgh issue commentを must-allow としていた既存ケースを、新方針に合わせて must-block または controlled executor 経由の呼び出し形式に置き換える REASON_GH_MUTATIONなどの block stderr /HOOK_COMMAND_REPAIR_HINT_V1が、rawgh issue edit/ rawgh issue comment/tmp/<body>.mdを approved path として案内しないように更新する- post-merge-cleanup 関連コードに raw
gh issue edit/ rawgh issue comment/--body-file tmp/の利用がないことを、許可済みテスト内の静的監査で検証する - 新規・変更テストの
.github/ci/python-test-plan.jsonへの登録(既存 directory-covered で十分な場合は変更不要)
Out of Scope
worktree_scope_guard.pyの変更(実装: Issue metadata mutation を worktree ではなく controlled metadata executor 経由にする #1284 で追加済みの exact command class allow はそのまま利用する)controlled_skill_mutation_policy.py/controlled_skill_mutation_exec.pyexecutor 本体の変更edit-issue/issue-authorskill 手順の transaction script 化(実装: edit-issue transaction script を追加し issue-author の shell 手順と context load を削減する #1287)- PreToolUse hook chain の fast-path / telemetry dedupe(実装: PreToolUse hook の read-only / exact-executor fast-path と telemetry dedupe を追加する #1289)
- GitHub CLI や REST API の仕様変更対応そのもの
Acceptance Criteria
- AC1:
is_github_issue_mutation_commandがgh issue edit <N> --repo squne121/loop-protocol --body-file tmp/x.mdを deprecate 後は allow しない(False を返す) - AC2:
is_github_issue_mutation_commandがgh issue create --repo squne121/loop-protocol --title "t" --body-file tmp/x.mdを引き続き allow する(True を返す) - AC3:
is_github_remote_ops_commandが rawgh issue commentを deprecate 後は allow しない(False を返す)。対象には--body、--body-file tmp/x.md、-F tmp/x.md、--body-file -、--editor、--web、--edit-last、--delete-last、--create-if-none --edit-last --body xを含む - AC4:
is_github_remote_ops_commandがgh issue close 100/gh issue reopen 100/gh pr comment 100 --body-file tmp/x.md/ selectedgh pr editを引き続き allow する(True を返す) - AC5: 実 PreToolUse hook 経路(
.claude/hooks/local_main_branch_guard.shに stdin JSON を渡す subprocess harness)で rawgh issue edit/ rawgh issue commentが block(exit 2)されることを確認する must-block adversarial テストが存在する - AC6: 実 PreToolUse hook 経路で controlled executor 経由コマンド(
controlled_skill_mutation_exec.py --command-id issue_body.update/issue_comment.publish/contract_snapshot.publish)が引き続き allow(exit 0)されることを確認する must-allow adversarial テストが存在する - AC7: 既存の
.claude/hooks/tests/test_local_main_branch_guard.pyの全テストが PASS する(rawgh issue edit/ rawgh issue commentを must-allow としていた既存ケースは新方針に合わせて更新済み) - AC8:
tests/codex/test_local_main_branch_guard.pyが Claude 側と同じ raw Issue mutation block / allowed non-Issue paths / controlled executor allow の parity matrix を検証し、全テストが PASS する - AC9: raw
gh issue edit/ rawgh issue commentが block されたとき、stderr /HOOK_COMMAND_REPAIR_HINT_V1は rawgh issue edit、rawgh issue comment、tmp/<body>.mdを approved path として提示しない - AC10: post-merge-cleanup 関連コードに raw
gh issue edit/ rawgh issue comment/--body-file tmp/の利用がないことを静的監査テストで確認する(gh issue close/gh issue reopenは許可) - AC11:
.github/ci/python-test-plan.jsonで.claude/hooks/tests/test_local_main_branch_guard.pyとtests/codex/test_local_main_branch_guard.pyが実行対象に含まれる、または既存 directory coverage により対象化されていることを確認する
Runtime Verification Applicability
decision: immediate
rationale: VC は新規テスト名の `rg` existence gate、`.claude/hooks/tests/test_local_main_branch_guard.py` と `tests/codex/test_local_main_branch_guard.py` の pytest 実行、および CI plan 登録確認であり、実装直後にローカルで即時実行・判定可能なため。
applicable_acs:
- AC1
- AC2
- AC3
- AC4
- AC5
- AC6
- AC7
- AC8
- AC9
- AC10
- AC11
execution_environment: repo root の Ubuntu 24.04 / WSL2 で `rg -n ...` と `uv run --locked pytest ...` を実行する
skip_conditions: なし。依存ファイルや CI plan が存在しない場合は fail として扱う
fallback_policy: ローカル実行が環境起因で失敗した場合は、同じ VC を CI required check で再実行し、失敗ログと head SHA を Issue/PR に記録する
artifact_requirements:
- pytest stdout/stderr
- 対象 test nodeid
- CI plan 登録確認結果
- 実行 head SHAVerification Commands
# AC1
$ rg -n "issue_edit_deprecated" .claude/hooks/tests/test_local_main_branch_guard.py
# AC2
$ rg -n "issue_create_still_allowed" .claude/hooks/tests/test_local_main_branch_guard.py
# AC3
$ rg -n "issue_comment_deprecated" .claude/hooks/tests/test_local_main_branch_guard.py
# AC4
$ rg -n "remote_ops_still_allowed" .claude/hooks/tests/test_local_main_branch_guard.py
# AC5
$ rg -n "must_block_raw_issue_" .claude/hooks/tests/test_local_main_branch_guard.py
# AC6
$ rg -n "must_allow_controlled_executor_metadata_commands" .claude/hooks/tests/test_local_main_branch_guard.py
# AC7
$ uv run --locked pytest .claude/hooks/tests/test_local_main_branch_guard.py
# AC8
$ rg -n "issue_metadata_mutation_parity" tests/codex/test_local_main_branch_guard.py
# AC9
$ rg -n "repair_hint_does_not_suggest_raw_issue_mutation" .claude/hooks/tests/test_local_main_branch_guard.py
# AC10
$ rg -n "post_merge_cleanup_does_not_use_raw_issue_body_or_comment_mutation" .claude/hooks/tests/test_local_main_branch_guard.py
# AC11
$ uv run --locked pytest .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.py
- .claude/hooks/tests/test_local_main_branch_guard.py
- tests/codex/test_local_main_branch_guard.py
- .github/ci/python-test-plan.json
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
なし
Scope Delta(該当時のみ記載)
- Anchor comment: 実装: local_main_branch_guard の raw gh issue edit/comment allowlist を controlled executor lane へ移行して deprecate する #1291 (comment)
- raw
gh issue comment --body/--body-file/-F/ editor-web-edit/delete 系も block 対象として明示 tests/codex/test_local_main_branch_guard.pyを Allowed Paths と AC に追加し、Claude/Codex parity を実装契約へ格上げ- block stderr /
HOOK_COMMAND_REPAIR_HINT_V1の禁止経路案内排除を AC9 に追加 - post-merge-cleanup の raw Issue body/comment mutation 不使用を AC10 に追加
Delivery Rule
1 Issue = 1 PRで完結させる- 実装は専用 worktree(
git worktree add ...)で行い、root/default branch から直接 mutation しない - PR は Draft で作成し、
Closes #<本Issue番号>を記載する - 本 Issue は 実装: Issue metadata mutation を worktree ではなく controlled metadata executor 経由にする #1284 の実装完了・マージ後に着手する(
Depends on #1284)
Notes for Reviewer
- deprecate の実装方式(関数を False 固定に変更 / 関数削除 / feature flag 縮退)は実装時の技術判断とし、AC1・AC3・AC5 の振る舞い(raw allow が block に転じる)を満たせば手段は問わない。
- 実装は「blocklist を足す」よりも、allowlist 側から raw Issue body/comment mutation を削除する形を優先する。
gh issue editは body 以外の title / labels / assignees / project / milestone / sub-issue / parent / issue type も変更可能な広い CLI であるため、Issue body 更新目的の allowlist としては過権限と扱う。
Activity
squne121 commentedon Jul 2, 2026
判定: REQUEST_CHANGES
#1291 の方向性自体は正しいです。#1284 / PR #1295 で
issue_body.update、issue_comment.publish、contract_snapshot.publishがcontrolled_skill_mutation_exec.pyに集約され、入力ファイル名前空間、schema、repo binding、stale-write precondition、readback、marker、postcondition まで設計されています。ただし、#1291 の現在の契約はその目的を完全には閉じていません。実装に入る前に Issue 本文を修正した方がよいです。
Blocker 1:
gh issue comment --bodyが残ると「Issue comment mutation の単一路線化」が成立しない#1291 は raw
gh issue editと rawgh issue comment --body-fileの廃止を要求していますが、現行is_github_remote_ops_command()はgh issue comment <N> --body ...と--body-file tmp/...の両方を allow しています。外部仕様上も
gh issue commentは単なる「安全なコメント作成」ではなく、--edit-last、--delete-last、--create-if-none、--editor、--web、--body-file -などを持つ状態変更 CLI です。([GitHub CLI]1)したがって、
--body-fileだけを塞いでも、raw Issue comment mutation の第二経路は残ります。#1284 のissue_comment.publishは marker precheck、remote readback、body hash 照合、postcondition を実装しているので、Issue comment は raw CLI ではなく executor 経由に統一すべきです。修正案:
Blocker 2: Allowed Paths が Codex parity を壊す
local_main_branch_guard.pyは Claude と Codex の双方で使われる共有ロジックです。ファイル冒頭でも Claude hook と Codex hook の shared core と明示されています。一方、Codex 側テストは現在、raw
gh issue edit ... --repo ... --body-file tmp/...が allow されることを期待しています。また、
gh issue comment 123 --body-file tmp/body.txtも allow と期待しています。#1291 の Allowed Paths は
.claude/hooks/tests/test_local_main_branch_guard.pyだけを許可し、tests/codex/test_local_main_branch_guard.pyを含めていません。このまま実装すると、共有実装を変えた瞬間に Codex parity テストが赤くなるか、CI が Codex テストを見ていないという別の品質問題になります。
修正案:
Blocker 3: AC6 が「新しい metadata command id」を検証していない
#1291 の AC6 は controlled executor 経由が allow されることを要求していますが、既存
.claude側テストで確認されているのは legacy のtermination_report.publishだけです。#1291 の対象は #1284 の metadata lane なので、少なくとも
issue_body.updateとissue_comment.publishの exact executor invocation を local_main real hook で検証する必要があります。policy 側には 3 つの新 command id と per-command schema が既に存在します。追加すべき AC:
contract_snapshot.publishも #1284 lane の一部なので、可能なら同じく dry-run allow を入れるべきです。Blocker 4: block 時の recovery hint が禁止経路を案内している
_emit_block_stderr()はREASON_GH_MUTATIONの場合、現在も"rtk gh issue edit <issue> --repo squne121/loop-protocol --body-file tmp/<body>.md"を suggested command として出します。#1291 後はこれが禁止経路になります。Claude Code の hook では exit code 2 が PreToolUse tool call をブロックし、stderr がモデルへの修復情報になるため、誤った修復ヒントは実害があります。([Claude Platform Docs]2)
修正案:
#1287 は issue-author 側の edit-issue transaction を導入する Issue ですが、現時点では open なので、#1291 の immediate approved path は executor lane として書く方が安全です。
Blocker 5: post-merge-cleanup 検証が契約として弱い
#1291 は「既存 post-merge-cleanup 用途は close/reopen のみか確認する」と書いていますが、Allowed Paths には post-merge-cleanup 実装もそのテストも入っていません。
実装を変更せずに済ませるなら、許可済みテスト内で静的 grep する契約にすべきです。
追加すべきテスト:
gh issue close/gh issue reopenは現行 allowlist で明示的に許可されているため、維持方針は実装と整合しています。実装品質を上げるための具体的変更
evaluate()は現在、is_github_issue_mutation_command()を Step 9.6b で allow し、is_github_remote_ops_command()を Step 9.7a で allow してから、最後に unlistedghmutation を block します。そのため、実装は「blocklist を足す」よりも、allowlist 側から Issue body/comment mutation を削除する形にすべきです。
推奨差分の方向:
gh issue editは body だけでなく title、labels、assignees、project、milestone、sub-issue、parent、issue type まで変更できる広い CLI なので、body 更新目的の allowlist としては過権限です。([GitHub CLI]3)GitHub REST API の Update issue も endpoint 自体は body 以外の title/state/labels/assignees などを受けるため、executor 側で body-only に固定し、stale precondition と readback を持つ現在の #1284 実装方針が妥当です。([GitHub Docs]4)
追加すべき敵対的テスト行列
最低限、この matrix を Claude/Codex 両方で持つべきです。
Python の
subprocessは argument sequence を渡す方が quote/escape を任せられると説明しており、shell=Trueは明示的に shell injection 対策責任を呼びます。executor がsubprocess.run([...], shell=False)に寄せている点は維持すべきです。([Python documentation]5) ([Python documentation]5)Non-blocking hardening
controlled_skill_mutation_exec.pyの_verify_git_remote_origin()は repo slug を末尾 regex で抽出して比較しています。これは #1291 の Allowed Paths 外なので今回の blocker にはしませんが、将来の hardening として host も
github.comに固定する strict parser に寄せた方がよいです。#1284 の review でも repo binding / authority 境界は主要論点でした。Issue 本文への推奨パッチ
現状の #1291 は「raw
gh issue editを消す」Issue としては近いですが、「Issue body/comment mutation を controlled executor に一本化する」Issue としては未完成です。特にgh issue comment --body、Codex parity、repair hint の 3 点は merge 前に契約へ入れるべきです。squne121 commentedon Jul 2, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 2, 2026
Contract Review Result
squne121 commentedon Jul 2, 2026
impl-review-loop: 完了 (2026-07-02T23:31:00Z)
test: harden local main guard metadata coverage (#1291)
squne121 commentedon Jul 3, 2026
impl-review-loop: 継続対応完了 (2026-07-03T10:34:44Z)
fix: raw issue metadata mutation を controlled executor に一本化 (#1298)
squne121 commentedon Jul 3, 2026
post-merge-cleanup: 完了 (2026-07-03T10:42:54Z)
/home/squne/projects/LOOP_PROTOCOL/.claude/worktrees/issue-1291-local-main-guard-gh-mutationworktree-issue-1291-local-main-guard-gh-mutationmainclean、origin/mainと一致