Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: research
parent_issue: "none"
goal_ref: "SubAgent の Bash/Write/Edit tool 経由の操作が pre-existing untracked file を意図せず削除・上書きすることを防ぐ既存の仕組みが repository 内にあるかを調査し、無ければ対応方針を決定する"
change_kind: research-onlyParent Issue
なし(単独改善)
Outcome
SubAgent の Bash/Write/Edit tool 呼び出し経由での pre-existing untracked file の意図しない削除・上書きに対する防止策の対応方針が決定され、本 Issue 本文または comment に調査結果(既存の仕組みの有無・追加すべき hook/guard の候補)が記録された上で、方針が「実装が必要」の場合は実装 follow-up Issue が起票され本 Issue から link されている状態。方針が「実装不要(許容リスク)」の場合はその判断理由が本 Issue に記録され、本 Issue が close 可能な状態。
In Scope
.claude/hooks/配下の PreToolUse/PostToolUse hook 設定に、SubAgent のBash(rm等破壊的コマンド)やWrite/Edittool 呼び出しに対して pre-existing untracked file の削除・上書きを検知・拒否する仕組みが既に存在するかどうかの調査scripts/agent-guards/controlled_skill_mutation_exec.pyが持つ postcondition guard(pre-existing untracked file 削除検知パターン。_compare_repo_transition/test_rejects_deleted_preexisting_untracked_file参照)が、controlled_skill_mutation_exec.py経由の mutation 以外(SubAgent が直接使う Bash/Write/Edit)にも適用可能・拡張可能かどうかの技術調査- 既存の近縁 Issue(実装: temp residue の再検査付き削除 executor を追加する #1616: temp residue 再検査付き削除 executor、実装: active issue worktree 外への Write/Edit/Bash mutation を hook で遮断する #960: active issue worktree 外への Write/Edit/Bash mutation を hook で遮断、CLOSED、実装: controlled_skill_mutation_exec の postcondition が事前存在 untracked ファイルを誤検知する不具合を修正する #2163:
controlled_skill_mutation_exec.pyの postcondition 誤検知修正、CLOSED)との scope 差分の明確化 - 対応方針の選択肢比較(例: 既存 postcondition guard パターンを SubAgent tool 境界へ拡張する / 新規 hook を追加する / 運用ガイドライン強化に留める)と推奨案の提示
Out of Scope
- hook/guard の実コード実装(方針決定後に別 implementation Issue で行う)
- 今回誤削除されたと自己申告された
.codebase-investigator-context-2677.md自体の復元・追跡(当該ファイルは.claude/agents/codebase-investigator.mdの設計上/tmp配下に生成されるべき transient artifact であり、repo root への存在自体が本来の設計と異なる) .claude/agents/codebase-investigator.md側のCONTEXT_FILE生成先変更(別件)
Acceptance Criteria
-
.claude/hooks/配下の hook 設定を確認し、SubAgent の Bash/Write/Edit tool 呼び出しに対する pre-existing untracked file 削除・上書き防止の既存カバレッジ有無が本 Issue 本文または comment に記載されている -
scripts/agent-guards/controlled_skill_mutation_exec.pyの postcondition guard パターンが SubAgent tool 境界へ拡張可能かどうかの技術的所見が本 Issue 本文または comment に記載されている - 対応方針(hook 追加 / guard 拡張 / 運用強化のみ / 対応不要)が決定され、判断理由とともに本 Issue に記録されている
- 対応方針が「実装が必要」の場合、実装 follow-up Issue が起票され本 Issue からリンクされている。「実装不要」の場合、その理由が本 Issue に明記されている
Verification Commands
$ gh issue view THIS_ISSUE_NUMBER --json body,comments上記コマンドの出力に、調査結果・対応方針が本文または comment に記録されていることを確認する(THIS_ISSUE_NUMBER は本 Issue の番号に置換する)。
$ gh issue list --search "FOLLOW_UP_ISSUE_TITLE_KEYWORD" --state open --json number,title,url実装が必要な場合、上記コマンドの出力に follow-up Issue が起票され本 Issue と相互リンクしていることを確認する(FOLLOW_UP_ISSUE_TITLE_KEYWORD は follow-up Issue のタイトルキーワードに置換する)。
Allowed Paths
- 読み取り専用。リポジトリ変更なし(既定)
- 調査対象として
.claude/hooks/およびscripts/agent-guards/controlled_skill_mutation_exec.pyを参照可能(変更は行わない)
Stop Conditions
- Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
- Allowed Paths 外への書き込みを試みた場合は即停止
- 権限不足(permission denied)により操作が完了できない場合は即停止
- 成果物の書き込みに失敗した場合(I/O エラー等)は即停止
Handoff Contract
Current Objective: SubAgent tool 境界での pre-existing untracked file 保護 guard gap の調査と対応方針決定Bounded Current Context: 実装: get_ci_failed_log.py の KNOWN_TOKEN_PATTERN を新形式 ghs_ App installation token に対応させる #2728 レビュー中に前回 issue-creator SubAgent による誤削除インシデントを契機として codebase-investigator による bounded read-only investigation を実施済み(本 Issue 背景参照)Open Questions:.claude/hooks/に該当 hook が既に存在するか、controlled_skill_mutation_exec.pyの guard を SubAgent tool 境界へ拡張する設計が妥当かNext Action: 調査実施者が上記 In Scope の各項目を確認し AC を満たすArtifact Refs: 本 Issue 本文の Background セクション、Issue 実装: get_ci_failed_log.py の KNOWN_TOKEN_PATTERN を新形式 ghs_ App installation token に対応させる #2728
Background
Issue #2728 のレビュー中、前回サイクルで issue-creator SubAgent がリポジトリ直下の pre-existing untracked file .codebase-investigator-context-2677.md を rm -f で誤削除したと自己申告した。今回 codebase-investigator SubAgent による bounded read-only investigation で以下を確認した(current main、squne121/loop-protocol)。
.codebase-investigator-context-*.mdの canonical producer は.claude/agents/codebase-investigator.mdであり、/tmp配下に timestamp 付きファイル名で生成する transient artifact として設計されている。つまりこのファイル種別は本来リポジトリ直下(repo root)に存在すべきものではない。- Issue 調査: authority_transport.consume の外側 timeout と内側予算の不整合を調査し対応方針を決定する #2677 は本ファイル名パターンとは無関係な別内容の OPEN Issue("調査: authority_transport.consume の外側 timeout と内側予算の不整合を調査し対応方針を決定する")であり、このファイルの producer/owner ではない。
scripts/agent-guards/controlled_skill_mutation_exec.pyには、skill mutation execution context において pre-existing untracked file の削除を検知・拒否する postcondition guard が存在する(test_rejects_deleted_preexisting_untracked_fileでテスト済み。判定ロジックは_compare_repo_transition参照)。- しかし、この guard は
controlled_skill_mutation_exec.py経由の mutation にのみ適用され、SubAgent が直接使うBash(rm等)やWrite/Edittool 経由の操作には適用されない。つまり SubAgent が task scope 外の pre-existing untracked file を、skill mutation guard を経由せずに削除できてしまう boundary gap が存在する。 gh issue list --searchで "SubAgent untracked file delete guard" 等を検索したが、この具体的な gap を扱う既存 OPEN/CLOSED Issue は見つからなかった。近い関連 Issue として 実装: temp residue の再検査付き削除 executor を追加する #1616(temp residue 再検査付き削除 executor、OPEN)、実装: active issue worktree 外への Write/Edit/Bash mutation を hook で遮断する #960(active issue worktree 外への Write/Edit/Bash mutation を hook で遮断、CLOSED)、実装: controlled_skill_mutation_exec の postcondition が事前存在 untracked ファイルを誤検知する不具合を修正する #2163(controlled_skill_mutation_exec.pyの postcondition 誤検知修正、CLOSED)があるが、いずれも本件(SubAgent レベルでの pre-existing untracked file 削除保護の欠如)とは scope が異なる。
今回具体的な実害(重要ファイルの喪失)は確認されていない(削除されたファイル自体が /tmp 配下に生成されるべき transient artifact だった可能性が高い)が、一般化すると任意の pre-existing untracked file(人間の作業中ファイル等)が同様に削除されうる guard gap であるため、優先度は低いが follow-up として調査 Issue を起票する。
Source
- Issue 実装: get_ci_failed_log.py の KNOWN_TOKEN_PATTERN を新形式 ghs_ App installation token に対応させる #2728 のレビュー中に、前回 issue-creator SubAgent による
.codebase-investigator-context-2677.mdの誤削除インシデントを契機にissue-refinement-loopから発見・起票。
Notes for Reviewer
- Scope overlap preflight(
check_issue_overlap.py)の結果はdecision: overlap_requires_comment(policy class C1)。理由は.claude/hooksおよびscripts/agent-guards/controlled_skill_mutation_exec.pyを Allowed Paths の参照先として記載したため、これらのパスを実際に変更した既存 Issue(実装: edit-issue の native relationship pagination reader を controlled executor に一本化し totalCount 検証を追加する #1916, 実装: secret_boundary_guard の grep ERE portability を改善する #1735, 実装: scope-rollup-runner capture の timestamp 誤変換と非verbatim転記による fail-closed 反復を解消する #1661, 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601, 実装: launcher command 共有 parser(argv boundary 保持・cwd/project_root 対応)を抽出し全 consumer の invocation contract を移行する #1595, 実装: .claude/settings.json の Edit(path) ルールの path anchoring を project root / home directory 相対に正規化する #1573, 実装: session_manifest_coordinator.sh 経由の legacy-state diagnostic e2e 可観測性を検証する #1432, 実装: PR body hygiene 更新は update_pr.py wrapper 経由に限定する #964, 実装: playtest-log の JSON Schema / validator の追加 #420, 実装: rate limit / API error 由来の停止を StopFailure hook でログ保存し resume playbook を整備する #225, 実装: normal Stop による未完了 LOOP_STATE を一度だけ補正する Stop hook safety net を導入する #224, 実装: .claude/skills 配下スクリプトの executable bit を監査し CI guard を追加する #205, 実装: codebase-investigator Bash/Read hook fail-close 技術的ガードを追加する #159 等)と文字列一致した。本 Issue の Allowed Paths は既定どおり読み取り専用(リポジトリ変更なし)であり、実 Git conflict は発生しない(導入: AIエージェント運用をminimal harnessへ縮退し、過剰なcontrol-planeを廃止する #1860 Owner Decision により起票停止理由にはしない)。
Activity