Skip to content

実装: agent-retrospectiveのadvisory observer invocationでBash経由のrepository/GitHub mutationが実runtime tool boundaryで拒否されるようにする #2419

Closed

Description

@squne121

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: code

Parent 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 を実際の claude CLI 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

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 -v

Allowed 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.md
  • docs/dev/agent-skill-boundaries.md
  • docs/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 公式ドキュメント調査結果に基づく)。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions