Repository navigation
Closed
1 / 11 of 1 issue completed
Copy link
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "高頻度の git read-only probe を script 化し、shell quoting 事故と guard noise を減らす"
change_kind: workflowParent Issue
none
Parent Goal Ref
- Goal: 高頻度の git read-only probe を script 化し、shell quoting 事故と guard noise を減らす
- Desired Destination: branch / worktree の read-only probe を shell format 文字列や compound command なしで実行でき、post-merge-cleanup などの手順から raw shell probe が減っている状態
Current Validated Scope
scripts/agent-ops/git_ref_probe.pyとscripts/agent-ops/git_worktree_probe.pyを追加するgit_worktree_probe.pyは既存scripts/agent-ops/worktree_catalog.pyを SSOT として再利用するpost-merge-cleanupskill・rule・guard docs を probe script 前提に更新する- deterministic checker allow と probe script 用テストを追加する
Remaining Parent Gaps
- hook failure transcript noise compaction は別 Issue で扱う
- instruction surface audit や retro index 集約は別 Issue で扱う
Outcome
branch / remote-tracking ref / worktree catalog の read-only 確認が Python probe script の JSON 出力に置き換わり、shell quoting や compound command に依存した raw git probe を post-merge-cleanup 周辺の正本手順から排除できている状態。
In Scope
git_ref_probe.pyとgit_worktree_probe.pyの新規追加git_worktree_probe.pyからworktree_catalog.pyの parser / schema を再利用する- skill / rule / docs から raw
git for-each-refや rawgit worktree list --porcelainの shell 例を probe script に置換する - guard 側の deterministic checker allow と pytest fixture 追加
Out of Scope
- git mutation の script 化
git branch -d/-Dやgit worktree removeの executor 化- arbitrary shell passthrough の許可
- hook transcript noise compaction や resume capsule の実装
Acceptance Criteria
- AC1:
post-merge-cleanupskill の read-only probe 手順から rawgit for-each-ref/ rawgit worktree list --porcelainの shell 使用例が削除され、scripts/agent-ops/git_ref_probe.py/scripts/agent-ops/git_worktree_probe.py呼び出しへ置き換わる - AC2:
git_ref_probe.pyはGIT_REF_PROBE_RESULT_V1JSON を stdout に 1 object のみ出力し、少なくともbranch,local.exists,local.ref,local.oid,remote.mode,remote.ref,remote.exists,remote.oid,upstream.configured,upstream.track,errorsを返す。remote.modeはorigin_branchまたはconfigured_upstreamのどちらかに固定され、実装・docs・tests で同一意味を持つ - AC3:
git_worktree_probe.pyはscripts/agent-ops/worktree_catalog.pyの parser / catalog schema を再利用し、GIT_WORKTREE_PROBE_RESULT_V1JSON を stdout に 1 object のみ出力する。entriesは既存WORKTREE_CATALOG_ENTRY_V1と互換で、少なくともworktree_realpath,branch_ref,head,detached,exists_on_diskを扱える - AC4: probe scripts は stdout JSON-only、stderr 最大 5 行、raw command / env / secret-like absolute path を stderr に出さない。Git subprocess は
shell=Falseの argv list、capture_output=True、timeout 付きで実行する - AC5: pytest fixture / 回帰テストとして少なくとも local branch exists/missing、remote-tracking exists/missing、configured upstream missing or gone、detached worktree、path with whitespace、invalid branch name を追加する
- AC6:
.claude/hooks/worktree_scope_guard.pyとscripts/agent-guards/local_main_branch_guard.pyがuv run python3 scripts/agent-ops/git_ref_probe.py --branch main --jsonおよびuv run python3 scripts/agent-ops/git_worktree_probe.py --jsonを deterministic checker として許可し、unknown flag / duplicate flag /--flag=value/ extra positional / shell metachar / wrapper / newline chain / bare git mutation は引き続き deny する。検証は dedicated contract test で両 guard の parity を確認できる - AC7:
AGENTS.md/.claude/rules/project-constitution.md/docs/dev/hook-boundaries.md/.claude/skills/post-merge-cleanup/SKILL.mdが「複雑な git read-only probe は script 優先」「hook は fail-closed local guardrail であり security boundary ではない」という方針に整合する
Verification Commands
# AC1
$ uv run pytest tests/agent_ops/test_probe_docs_contract.py -k post_merge_cleanup
# AC2
$ uv run pytest tests/agent_ops/test_git_ref_probe.py -k json_contract
# AC3
$ uv run pytest tests/agent_ops/test_git_worktree_probe.py -k json_contract
# AC4
$ uv run pytest tests/agent_ops/test_git_ref_probe.py -k stderr
# AC5
$ uv run pytest tests/agent_ops/test_git_ref_probe.py -k fixtures
# AC6
$ uv run pytest tests/agent_ops/test_probe_guard_contract.py -k deterministic_checker
# AC7
$ uv run pytest tests/agent_ops/test_probe_docs_contract.py -k policy_alignmentAllowed Paths
scripts/agent-ops/git_ref_probe.pyscripts/agent-ops/git_worktree_probe.pyscripts/agent-ops/worktree_catalog.py.claude/skills/post-merge-cleanup/SKILL.md.claude/rules/project-constitution.mdAGENTS.mddocs/dev/hook-boundaries.md.claude/hooks/worktree_scope_guard.pyscripts/agent-guards/local_main_branch_guard.py.claude/hooks/tests/test_worktree_scope_guard.pytests/codex/test_local_main_branch_guard.pytests/agent_ops/test_git_ref_probe.pytests/agent_ops/test_git_worktree_probe.pytests/agent_ops/test_probe_docs_contract.pytests/agent_ops/test_probe_guard_contract.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Python 3
- Git
Scope Delta(任意)
- anchor comment
#issuecomment-4815640481を反映し、Allowed Paths / AC / VC の不整合を修正 - AC6 の Verification Command を dedicated contract test 前提へ更新し、baseline preflight が
vc_no_tests_collectedで停止しないよう補強
Runtime Verification Applicability
- decision: not_applicable
- reason: read-only probe script・guard・docs・pytest の変更で完結し、動作検証は JSON CLI と pytest で確認できる
- if immediate: N/A
- if deferred: N/A
Delivery Rule
1 Issue = 1 PR。git mutation を含めず、read-only probe のみを script 化する。
Sub-issues
Collapse Sub-issuesSub-issues
Loading 1 sub-issues
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 27, 2026
判定: REQUEST_CHANGES
Issue #1197 の方向性は正しいです。
git ref/worktreeの read-only probe を Python script 化し、shell quoting・compound command・hook transcript noise を減らす狙いは、#1047 系の「agent 周辺制御を deterministic script に寄せる」方針と整合します。#1197 本文も、git_ref_probe.py/git_worktree_probe.py追加、post-merge-cleanup更新、deterministic checker allow、fixture 追加まで明記しています。ただし、現状の Issue 契約のまま実装すると AC を満たせません。特に Allowed Paths と AC6 が矛盾しています。Issue #1197 自体のコメントは 0 件でした。
P0 ブロッカー
1. AC6「guard が probe script を deterministic checker として許可」が Allowed Paths 上で実装不能
#1197 は AC6 で「guard が probe script の exact command class を deterministic checker として許可する」としていますが、Allowed Paths に 実際の guard 本体が入っていません。現行
local_main_branch_guard.pyのDETERMINISTIC_CHECKER_ALLOWLISTは空で、is_deterministic_checker_command()はuv run python3 <script>かつ allowlist の exact path に一致する場合だけ許可します。さらに
worktree_scope_guard.py側も、main root から active issue worktree 存在時に通せる agent-ops script を_AGENT_OPS_ALLOWED_SCRIPTSで閉じており、現状はcleanup_exec.py/guard_preflight.py/materialize_cleanup_contract.pyのみです。git_ref_probe.pyとgit_worktree_probe.pyは含まれていません。worktree_scope_guardの exact allow は script realpath・argv shape・cwd main root・default branch をすべて検証する実装なので、テストだけ追加しても実 hook 経路は通りません。修正案: Allowed Paths に最低限これを追加してください。
または、probe command policy を共有 module に切り出すなら、その module と両 guard の import 更新も Allowed Paths に入れる必要があります。
2. Verification Commands が参照する test file が Allowed Paths に無い
#1197 の Verification Commands には
tests/agent_ops/test_git_ref_probe.pyが出てきますが、Allowed Paths にはそのファイルがありません。このままだと、AC4 / AC5 の probe script 回帰テストを追加した瞬間に Allowed Paths 違反になります。
修正案: Allowed Paths に追加。
3.
git_worktree_probe.pyが既存 SSOT と drift する危険が高いリポジトリには既に
scripts/agent-ops/worktree_catalog.pyがあり、worktree_scope_guard/guard_preflight/cleanup_execが同じ worktree catalog parser を使うための SSOT として導入されています。コメント上も、git worktree list --porcelain -zを使って path の newline/quoting ambiguity を避ける設計です。既存 parser は
WORKTREE_CATALOG_ENTRY_V1としてworktree_realpath/branch_ref/git_common_dir/detached/headを扱っています。Git 公式仕様でも、
git worktree list --porcelain -zは attribute line を NUL 終端にし、worktreeが常に最初の属性になり、detachedのような boolean attribute は true のときだけ出る形式です。(Git)修正案:
git_worktree_probe.pyは独自 parser を持たず、原則worktree_catalog.pyを import してください。もしlocked/prunable/exists_on_diskなどを追加で必要とするなら、scripts/agent-ops/worktree_catalog.pyも Allowed Paths に入れて、既存 SSOT を拡張する方が安全です。4.
remote existence / remote OIDの定義が曖昧#1197 の AC2 は「branch existence / local OID / remote existence / remote OID」としていますが、ここでいう remote が以下のどれか不明です。
refs/remotes/origin/<branch>origin/HEADから見た default branchGit の
for-each-refは upstream 関連 atom を持ち、%(upstream:track)は upstream が unknown の場合に[gone]を出せます。(Git) ただし、これは「configured upstream」の状態であって、単純なorigin/<branch>の存在とは別です。修正案: AC2 を以下のように明文化してください。
branch 名は
git check-ref-format --branch相当で検証すべきです。Git 公式 docs は--branch <branchname-shorthand>を branch name 検証用として説明し、不正な refname では non-zero status になるとしています。(Git)5. AC1 の検証が hollow
AC1 は「
post-merge-cleanupskill から rawgit for-each-refの shell 使用例を削除」としていますが、Verification Commands はworktree_scope_guard.py -k deterministic_checkerだけです。これは docs から raw shell probe が消えたことを検証しません。修正案: docs drift を検出する専用 pytest を追加してください。
例:
必要なら
git worktree list --porcelainの raw shell 例も禁止対象にしてください。ただし、script 実装内の argv-list subprocess は対象外にします。6. stderr 5 行制限だけでは不十分
AC4 は「probe script の stderr は最大 5 行」としていますが、read-only probe script の品質条件としては不足です。必要なのは stdout JSON-only と bounded structured diagnostics です。
Python の
subprocess.run()はargssequence、capture_output=True、timeout=をサポートします。capture_output=Trueは stdout/stderr を PIPE にし、timeout超過時は child process を kill/wait したうえでTimeoutExpiredを再 raise します。([Python documentation]4) ([Python documentation]4)修正案: AC4 をこう強化してください。
7. #1196 との接続条件が弱い
#1197 は post-merge-cleanup 周辺 probe の script 化です。一方、直近の #1196 は branch-only cleanup resume を扱っており、「worktree が存在しない」状態を disk path / worktree catalog / branch catalog / local ref existence に分解しています。
Git 公式 docs でも、作業ツリーを手動削除した場合は管理情報が残り、後で prune されると説明されています。また
worktree removeは clean な worktree だけ削除し、dirty/submodule 付きは force が必要です。([Git]1)したがって
git_worktree_probe.pyが post-merge-cleanup の正本 probe になるなら、最低限以下を JSON に含めるべきです。{ "schema": "GIT_WORKTREE_PROBE_RESULT_V1", "entries": [ { "schema": "WORKTREE_CATALOG_ENTRY_V1", "worktree_realpath": "...", "branch_ref": "refs/heads/...", "head": "...", "detached": false, "exists_on_disk": true, "locked": false, "prunable": false } ], "queries": { "by_branch_ref": { "branch_ref": "refs/heads/issue-1197-...", "match_count": 1 }, "by_path": { "worktree_realpath": "...", "in_catalog": true, "exists_on_disk": true } } }現行
worktree_catalog.pyはlocked/prunableを保持していないので、この情報まで要るなら SSOT 側の拡張を Issue scope に含めるべきです。P1 改善
git_ref_probe.pyはshow-ref --verify --hashベースがよいgit show-refは local refs を表示し、--verifyは exact ref path を要求し、--hashは OID のみを出力できます。不存在は error code で判定できます。([Git]5)推奨 probe strategy:
ただし
git for-each-ref --shell/--pythonは placeholder を host language literal として quote する option で、eval 前提の例が出る領域です。#1197 の目的が shell quoting 事故削減なら、--shell/eval系の使い方は採用しない方がよいです。([Git]2)hook docs の記述は「security boundary」ではなく「fail-closed local guardrail」に合わせる
docs/dev/hook-boundaries.mdは、hook は fail-closed local guardrail であって security boundary ではなく、hook failure は transcript を汚染し得る、と明記しています。#1197 の docs 更新は、probe script を「安全な権限昇格」ではなく、read-only probe の argv grammar 固定・JSON 正規化・stderr 縮小として説明すべきです。
Issue #1197 への追記案
Codex / Claude Code 実行プロンプト
この Issue は「実装着手前に契約修正」が必要です。現状のまま Codex/Claude に投げると、Allowed Paths 違反か、AC6 未達のどちらかになります。
squne121 commentedon Jun 27, 2026
Contract Review Result
squne121 commentedon Jun 27, 2026
AGENT_RUN_REPORT_V1
fix(#1197): fix ruff violations (F841, E741, E402)
feat(#1197): git ref/worktree probe scripts を実装し hook allowlist に登録
fix(#1197): fix ruff violations (F841, E741, E402)
fix(#1197): commit ruff auto-fixes (F401 unused imports)
fix(#1197): register tests/agent_ops/ in python-test-plan.json
feat(#1197): git ref/worktree probe scripts を実装し hook allowlist に登録
fix(#1197): fix ruff violations (F841, E741, E402)
fix(#1197): commit ruff auto-fixes (F401 unused imports)
fix(#1197): register tests/agent_ops/ in python-test-plan.json
fix(#1197): B1/B2/B3/H1 — argv validation, show-ref, configured_upstream
test(#1197): update test_probe_guard_contract for B1 argv validation
fix(#1197): NB1 — remove probe entries from issue1198-command-matrix.…
fix: check_hook_boundaries drift 空集合への追随と probe scripts 記述復元(#2262 it…
fix: hook-boundaries.md 見出しの日本語比率不足を解消(#2262 iteration 4)
fix: repository-wide の stale hook wiring claim(PreToolUse/.codex/hook…