Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "PR #1072 の post-merge follow-up として、branch-safe maintenance commands を readonly と混同しない telemetry に分離し、pipeline/read-only classifier と consumer compatibility を fail-closed に固定する"
change_kind: codeParent Issue
none
Parent Goal Ref
- Goal: PR fix(codex): allow readonly bash pipelines (#1069) #1072 で導入した local root branch guard の allow/block 行動を維持しつつ、
git fetch/git worktree pruneを true read-only command とは別 reason_code で観測できるようにする - Desired Destination:
git fetchとgit worktree pruneが guard telemetry では branch-safe maintenance として報告され、readonly pipeline classifier は display read-only command のみに限定され、既存 consumer が unknown reason_code 追加で壊れないことをテストで確認できる状態
Background
- PR fix(codex): allow readonly bash pipelines (#1069) #1072 では local root branch guard に限定的な read-only pipeline classifier が入った。
- その結果、
git fetchやgit worktree pruneのような branch-safe maintenance command までreadonly_commandと見える語彙が残っている。 - owner comment
#issuecomment-4760842373では、単に文字列を追加するのではなく、reason_code 名・pipeline semantics・consumer compatibility まで contract で固定するよう求めている。 - ワークアラウンドとして issue コメントだけで注記する案は採らない。guard telemetry の誤解を deterministic に解消する。
Source
- kind: post_merge_cleanup
- url: fix(codex): allow readonly bash pipelines (#1069) #1072
- note_id: "4760766472"
- dedupe_key: follow-up:squne121/loop-protocol:pr/1072:branch-safe-telemetry-split
- anchor_comment_url: 実装: Normalize branch-safe classifier telemetry for git fetch and git worktree prune #1075 (comment)
Current Validated Scope
scripts/agent-guards/local_main_branch_guard.pyの reason_code / classifier 実装を、display read-only と branch-safe maintenance で分離する.claude/hooks/tests/test_local_main_branch_guard.pyにgit fetch/git worktree pruneの reason_code 回帰、readonly parity 回帰、pipeline fail-closed 回帰を追加する- allow/block 行動は変えず、telemetry vocabulary・pipeline routing・consumer compatibility だけを tighten する
Remaining Parent Gaps
なし
Outcome
scripts/agent-guards/local_main_branch_guard.py と .claude/hooks/tests/test_local_main_branch_guard.py が更新され、git fetch と git worktree prune は readonly_command ではない branch-safe maintenance reason_code で allow される。display read-only command の既存表示は維持され、git fetch | head -n 1 と git worktree prune | head -n 1 は readonly pipeline に分類されず fail-closed のままで、追加した guard regression test が PASS している状態。
In Scope
scripts/agent-guards/local_main_branch_guard.pyで display read-only classifier と branch-safe maintenance classifier を分離するscripts/agent-guards/local_main_branch_guard.pyでgit fetch/git worktree pruneを pipeline readonly allowlist へ再注入しないことを固定する.claude/hooks/tests/test_local_main_branch_guard.pyに branch-safe maintenance reason_code 回帰、readonly command 回帰、pipeline fail-closed 回帰、hook_flavorparity 回帰を追加するLOCAL_MAIN_BRANCH_GUARD_RESULT_V1.reason_codeの enum 追加が key set / value type 変更を伴わないことを、この 2 file 内のテストで確認する
Out of Scope
git fetch/git worktree pruneの allow/block 判定そのものの変更- 他の guard / wrapper / validator の telemetry 定義の横断変更
- read-only 以外の git / gh / pnpm command の再分類
tests/codex/**や docs への波及修正- pipeline allowlist の一般化や新しい maintenance pipeline 分類の導入
Implementation Constraints
git fetch/git worktree pruneは display read-only command として扱わないREADONLY_PATTERNS = DISPLAY_READONLY_PATTERNS + ...のような再結合は禁止する- readonly pipeline classifier の先頭 segment は display read-only command のみ許可し、branch-safe maintenance command を混ぜない
- branch-safe maintenance は通常の単独 command としてのみ allow し、pipeline では fail-closed を維持する
LOCAL_MAIN_BRANCH_GUARD_RESULT_V1.reason_codeには新 enum value を追加してよいが、JSON key set / value type は変えない- 追加する pytest 名は verification から機械的に見つけられるように、
branch_safe_maintenance/readonly_parity/pipeline_fail_closed/hook_flavor_parity/result_schema_compatibilityのいずれかを test 名に含める
Schema / Consumer Compatibility
LOCAL_MAIN_BRANCH_GUARD_RESULT_V1.reason_codeに branch-safe maintenance 用 enum value を追加する- 既存
readonly_commandconsumer がgit fetch/git worktree pruneを true read-only と仮定していないことを、少なくとも.claude/hooks/tests/test_local_main_branch_guard.pyで fail-closed に確認する hook_flavor="claude"とhook_flavor="codex"の両方で同じ reason_code を返すことを regression で固定する- unknown reason_code を扱えない別 consumer や追加 Allowed Paths が必要と判明した場合は stop する
Acceptance Criteria
- AC1:
scripts/agent-guards/local_main_branch_guard.pyに display read-only と branch-safe maintenance を分離した distinct reason_code が定義されている - AC2:
scripts/agent-guards/local_main_branch_guard.pyでgit fetchとgit worktree pruneは allow されるがreadonly_commandではなく branch-safe maintenance reason_code を返す - AC3:
scripts/agent-guards/local_main_branch_guard.pyでgit status、git diff --stat、git log、git worktree listは引き続きreadonly_commandを返す - AC4: readonly pipeline classifier は display read-only command のみに限定され、
git fetch | head -n 1とgit worktree prune | head -n 1は readonly pipeline に分類されない - AC5:
.claude/hooks/tests/test_local_main_branch_guard.pyに branch-safe maintenance 回帰、readonly parity 回帰、pipeline fail-closed 回帰、hook_flavorparity 回帰を表す named test が追加され、guard test file 全体が PASS する - AC6:
LOCAL_MAIN_BRANCH_GUARD_RESULT_V1の key set / value type は変えず、reason_code enum 追加だけであることを確認する named test が追加されている
Verification Commands
# AC1
$ rg -n 'branch_safe_maintenance' scripts/agent-guards/local_main_branch_guard.py# AC2
$ rg -n 'branch_safe_maintenance' .claude/hooks/tests/test_local_main_branch_guard.py# AC3
$ rg -n 'readonly_parity' .claude/hooks/tests/test_local_main_branch_guard.py# AC4
$ rg -n 'pipeline_fail_closed' .claude/hooks/tests/test_local_main_branch_guard.py# AC5
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -q -k "branch_safe_maintenance or readonly_parity or pipeline_fail_closed or hook_flavor_parity or result_schema_compatibility"# AC6
$ rg -n 'result_schema_compatibility' .claude/hooks/tests/test_local_main_branch_guard.pyAllowed Paths
- /home/squne/projects/LOOP_PROTOCOL/scripts/agent-guards/local_main_branch_guard.py
- scripts/agent-guards/local_main_branch_guard.py
- /home/squne/projects/LOOP_PROTOCOL/.claude/hooks/tests/test_local_main_branch_guard.py
- .claude/hooks/tests/test_local_main_branch_guard.py
Runtime Verification Applicability
decision: not_applicable
reason: "本 Issue は deterministic な command classifier / reason_code / pytest regression の修正であり、画面操作や browser runtime 証跡を要求しない"Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- allow/block 行動の変更が必要になった場合
- branch-safe maintenance の判定をこの 2 file だけでは consumer compatibility まで安全に固定できないと判明した場合
- readonly pipeline classifier に branch-safe maintenance command を混ぜないと要件を満たせないと判明した場合
Required Skills
- Python
- pytest
Delivery Rule
- 1 Issue = 1 PR
- issue 専用 worktree で実装する
- Draft PR を既定とする
Scope Delta
N/A
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
squne121 commentedon Jun 21, 2026
判定: #1075 は必要。ただし、このまま実装すると「理由コードだけ増やしたが分類境界は曖昧なまま」になるリスクが高いです。
#1075 の出自は妥当です。Issue 本文は PR #1072 の post-merge follow-up として、
git fetch/git worktree pruneをreadonlyと誤読される telemetry から分離する目的を明示しています。#1075 自体には現時点でコメントはありません。PR #1072 側の議論を見ると、直接の発火点は comment
#4760766472です。そこでは、PR #1072 の pipeline classifier 方針自体は概ね妥当としつつ、git fetch/git worktree pruneがREASON_READONLYに畳み込まれている点を「telemetry / policy naming として不正確」と指摘し、follow-up issue に分離することを求めています。重大ブロッカー
1.
branch_safe_commandという名前がまだ広すぎる#1075 は
branch_safe_commandの追加を AC1 にしていますが、この語は広すぎます。git fetchとgit worktree pruneは「branch checkout を動かさない maintenance」ではありますが、「安全なコマンド」一般ではありません。将来git restore、git checkout -- <path>、gh pr viewなどまで同じ語彙に吸い込まれると、また分類負債になります。より正確には、reason code は次のどちらかに寄せるべきです。
公式 Git docs 上でも、
git fetchは remote-tracking branch や.git/FETCH_HEADを更新し得るため pure read-only ではありません。さらにデフォルトで自動メンテナンスを走らせる挙動もあります。([Git]1)git worktree pruneも$GIT_DIR/worktrees配下の管理情報を削除するコマンドです。([Git]2)2. 現行コードは「分けたように見えて、最後に再結合している」
現行
local_main_branch_guard.pyはDISPLAY_READONLY_PATTERNSとNON_BRANCH_MUTATING_PATTERNSを分けていますが、直後にREADONLY_PATTERNS = DISPLAY_READONLY_PATTERNS + NON_BRANCH_MUTATING_PATTERNSとして再結合しています。つまりgit fetch/git worktree pruneは引き続きis_readonly_command()経由でreadonly_commandになります。さらに
evaluate()では、readonly pipeline classifier でも通常 readonly 判定でもreason_code=REASON_READONLYを返しています。#1075 の狙いはここに直撃しているので、単に constant を足すだけでは不足です。必要な修正は最低限これです。
そのうえで
evaluate()の通常コマンド分類は、is_readonly_command()とis_branch_safe_maintenance_command()を別々に評価して、別 reason_code を返すべきです。3. pipeline 内の
git fetch | headをどう扱うかが未定義現行
classify_readonly_pipeline()は、先頭 segment にis_readonly_command(first_segment)を要求します。今のis_readonly_command()にはgit fetchが含まれているため、理屈上はgit fetch | head -n 1が readonly pipeline として許可され得ます。#1075 は
git fetch/git worktree pruneの allow/block 行動は変えない、としていますが、pipeline 経由の挙動を明記していません。ここは危険です。Git docs 上fetchは副作用を持つため、出力をheadに絞っただけで readonly と見なすべきではありません。(Git)推奨は次です。
どうしても pipeline を許可するなら、readonly pipeline ではなく
branch_safe_maintenance_pipelineのように別分類すべきです。ただし #1075 の範囲では、そこまで広げない方が安全です。4. 出力 schema / consumer inventory がない
local_main_branch_guard.pyの header ではLOCAL_MAIN_BRANCH_GUARD_RESULT_V1のreason_codeが明示的な出力項目です。現在の reason code 一覧にはreadonly_commandはありますが、branch-safe 系はありません。#1075 の Stop Conditions には「固定契約(キー集合・スキーマ・型定義)の変更が必要なら停止」とあります。しかし reason_code の enum 値追加は、キー集合ではなくても downstream consumer にとっては contract change です。最低限、Issue に次を追加してください。
5.
.claude側だけのテスト指定では Codex parity が弱い#1075 の Allowed Paths は
scripts/agent-guards/local_main_branch_guard.pyと.claude/hooks/tests/test_local_main_branch_guard.pyに限定されています。 しかしこの shared core は Claude / Codex の両方で使われます。PR #1072 の Codex 側テストには readonly pipeline classifier の positive / negative matrix が既にあり、そこではREASON_READONLYを前提にしています。#1075 の実装が通常コマンドの
git fetch/git worktree pruneだけを分離するなら、Codex test を変えなくても成立する可能性はあります。ただしhook_flavor="codex"でも同じ reason_code になることは、少なくとも.claude側テスト内でhook_flavorparameterize して確認すべきです。修正後の Acceptance Criteria 案
現在の AC は弱いです。
rg -n "branch_safe_command"と test name の存在だけでは、誤実装でも通ります。差し替えるなら、次の AC が必要です。
実装方針
evaluate()の分類順は以下が安全です。ただし pipeline classifier は
DISPLAY_READONLY_PATTERNSのみを参照させるべきです。Pythonshlexは shell 風の字句解析には使えますが、公式 docs でも「完全な shell parser ではないので独自 error checks が必要」とされています。現行実装の fail-closed 方向は正しいため、maintenance command を pipeline allow に混ぜない方がよいです。([Python documentation]3)Codex hook については、OpenAI docs 上でも
PreToolUseは guardrail であり完全な enforcement boundary ではなく、単純な shell call 以外の経路は捕捉し切れません。また複数 matching hooks は同時に走るため、1 hook の分類名変更で全体の安全性が上がるわけではありません。今回の修正は「安全境界の強化」ではなく「telemetry の誤語彙修正」と位置づけるべきです。([OpenAI Developers]4) ([OpenAI Developers]4)結論
#1075 は実装すべきです。ただし、現 Issue のままだと「
branch_safe_commandという文字列を足しただけ」で終わる危険があります。実装前に、Issue 本文へ次を追記するのが妥当です。
この条件を満たすなら、#1075 は PR #1072 の設計負債を小さく閉じる良い follow-up です。逆にここを曖昧にしたまま実装すると、次は「branch-safe とは何か」をめぐる再分類 Issue が必要になります。
squne121 commentedon Jun 21, 2026
Contract Review Result
squne121 commentedon Jun 21, 2026
Issue 本文更新
pytest -kへ変更しましたpytestだと現状ベースラインで通ってしまうため、未実装なら落ちる形に調整しています確認結果
guard-issue-body.py: passissue_contract_hygiene_autofix.py: no changecontract_readiness_check.py: gofix(guards): split branch-safe maintenance telemetry (#1075) (#1079)
squne121 commentedon Jun 21, 2026
PR #1079 が 2026-06-21 に main へマージされ、issue contract の Outcome/AC を満たしたため close します。post-merge-cleanup として linked issue を手動で整合させます。