Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "agent-retrospectiveのadvisory observer/evaluator invocationでBash経由のrepository/GitHub mutationが実runtime tool boundaryで拒否されるようにする"
change_kind: codeParent Issue
none
Parent Goal Ref
- Goal: なし(単独改善)
- Desired Destination: なし(単独改善)
Current Validated Scope
.claude/skills/agent-retrospective/scripts/run_retrospective.py の DelegatedAgentPermissionPolicy / invoke_agent / build_agent_invocation_argv。新規 PreToolUse hook スクリプトと、それを注入する --settings 配線。.claude/skills/agent-retrospective/scripts/tests/ 配下の既存テスト拡張。
Remaining Parent Gaps
なし(単独改善)
Outcome
.claude/skills/agent-retrospective/scripts/run_retrospective.py が codebase-investigator 等の Bash 保持 observer を headless subprocess として起動する際、新設した PreToolUse hook(--settings 経由で注入)が実際に claude CLI の tool boundary へ配線され、git commit/git push/git merge/git rebase/git reset/branch 作成系/gh pr merge/gh issue close 等の mutation コマンドを実行前に拒否する。一方で git show <sha>:<path> | sha256sum のような read-only pipeline investigation は成功する。この状態が disposable な一時 git repository 上での実 claude CLI launcher canary(mock ではなく実 subprocess)で確認され、対応する regression test が .claude/skills/agent-retrospective/scripts/tests/ に追加され、Draft PR が作成され CI が green である。
Runtime Verification Applicability
- decision: immediate
- reason: security/isolation を強化する変更であり
docs/dev/runtime-verification-policy.mdの immediate 運用に従う
In Scope
- 新規 PreToolUse hook スクリプト(
.claude/skills/agent-retrospective/scripts/配下)を追加し、DelegatedAgentPermissionPolicyが持つ既存の denylist 定数(_DENIED_BASH_METACHAR_TOKENS/_DENIED_BASH_STANDALONE_COMMANDS/_DENIED_BASH_VERB_PAIRS/_DENIED_INLINE_EXEC_INTERPRETERS等)を再利用しつつ、pipeline-aware(|/;/&&/||で区切った各 segment を個別検証し、`・$(は無条件拒否)な判定へ拡張する run_retrospective.pyのinvoke_agent()/build_agent_invocation_argv()から、run-scoped temp dir に書き出した--settings <一時ファイル>を経由してこの hook を実際のclaudeCLI subprocess へ注入する配線を追加する(Bash を保持する observer 呼び出しにのみ適用)- codebase-investigator の retrospective 呼び出し向けに、read-only な git/gh/coreutils コマンド(
git show/git log/git diff/git blame/git rev-parse/sha256sum/wc/head/cat/gh issue view/gh pr view/gh apiの GET 系等)を許可し、mutating verb(commit/push/merge/rebase/reset/checkout -b/branch -d 等、gh pr merge/close/edit/comment 等)を拒否する allowlist+denylist を実装する - P0 regression test: 「Bash 保持 observer が
git merge相当の mutation を選択しても実行前に拒否される」ことを実際の subprocess 経由で検証するテストを追加する - disposable な一時 git repository 上での実 Claude Code launcher canary(read-only 成功 / mutation 拒否 / sentinel ブランチ・ファイル不変を確認)
- 可能なら Claude-GPT launcher 経由でも同等の canary を実施し、実行不能なら environment/capability gap として PR に記録する
Out of Scope
- Issue 実装: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する #2397 / PR feat: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する #2398(
command_not_allowedの failure classification。別モジュール・別 semantic intent と dedupe 調査済み、本 Issue へ統合しない) - PR feat: structural repair actionをcontrolled consumerへ接続する #2400 / feat: route structural repair actions #2408(structural repair action の consumer/dispatch 接続。無関係と確認済み)
- PR fix: pr-reviewer の hooks frontmatter を block-style YAML に書き換える #2415(pr-reviewer hooks frontmatter の構文修正。無関係と確認済み)
.claude/agents/codebase-investigator.mdのtoolsfrontmatter から Bash tool そのものを削除すること(issue-refinement-loop 等の他 workflow の AGY delegation を破壊するため).claude/agents/retrospective-runtime-observer.md/.claude/agents/web-researcher.mdへの変更(既にdisallowedToolsに Bash が含まれており対象外)- semantic contract(Issue/PR 内容の goal・AC)を変更する権限を auto mode へ委譲すること
Acceptance Criteria
- AC1: 新設 PreToolUse hook が
--settings経由で実際にclaude -p --agent codebase-investigatorの subprocess へ注入され、disposable な一時 git repository 上でgit merge/git commit/git push/git reset/git rebase相当の Bash コマンドが実行前に拒否されることを、実 subprocess launcher canary(mock ではない)で確認する - AC2: 同じ設定下で、
git show <sha>:<path> | sha256sumのような read-only pipeline コマンドが引き続き成功することを同じ canary で確認する - AC3:
DelegatedAgentPermissionPolicyの Bash 検証ロジックがinvoke_agent()の実行パスから実際に呼び出されている(dead code ではない)ことを、production call graph を辿るテストで確認する - AC4: 通常用途(issue-refinement-loop 等、agent-retrospective 経由でない)の codebase-investigator 呼び出しがこの変更の影響を受けないことを、既存テストの再実行で確認する
- AC5:
.claude/skills/agent-retrospective/scripts/tests/に P0 regression test(Bash 保持 observer が git merge 相当の mutation を選んでも拒否される)が追加され、PASS する
Verification Commands
# AC1
$ uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_bash_mutation_denial_canary.py -v
# AC2
$ uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_bash_readonly_pipeline_allowed_canary.py -v
# AC3
$ rg -n "policy.check_bash" .claude/skills/agent-retrospective/scripts/run_retrospective.py
# AC4
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -v
# AC5
$ uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/ -k bash_mutation -vAllowed Paths
.claude/skills/agent-retrospective/scripts/run_retrospective.py.claude/skills/agent-retrospective/scripts/(新規 hook スクリプト追加用).claude/skills/agent-retrospective/scripts/tests/.claude/skills/agent-retrospective/references/.claude/skills/agent-retrospective/SKILL.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- canonical main 上で mutation canary を再現しようとしそうになった場合(disposable repository に限定する)
Required Skills
- Python(subprocess / argv 構築 / shlex)
- Claude Code CLI headless invocation(
--settings/--disallowedTools/ PreToolUse hooks) - pytest
Required Design References
docs/adr/0007-agent-retrospective-boundaries.mddocs/dev/agent-skill-boundaries.mddocs/dev/runtime-verification-policy.md
Scope Delta(任意)
N/A
Delivery Rule
1 Issue = 1 PR。dedicated worktree で作業し、Draft PR を作成する。
Notes for Reviewer
- 本 Issue は 2026-08-30 の
agent-retrospective実行中に実際に発生した incident(reflog:merge origin/worktree-issue-2240-agent-retrospective-plugin: Fast-forwardによりローカル main が破損、git reset --hard origin/mainで復旧済み・作業喪失なし)の post-mortem として起票している。 --disallowedToolsの scoped rule(Bash(git commit *)等)は文字列 prefix match の既知バイパスがあるため、単独の防御手段にせず、PreToolUse hook を一次防御とする設計を推奨する(Claude Code 公式ドキュメント調査結果に基づく)。
Activity
fix: bash guardをcapability allowlist方式に再設計しAGY/process substitution/g…