Repository navigation
Closed
Labels
Description
背景
PR #1100 で gh issue/pr mutation を allowlist-closed 方式に変更した結果、gh issue close / gh issue create / gh issue edit が guard
にブロックされるようになった。これは user_github_ops_policy(GitHub Issue/PR 操作は
allow)と衝突する regression。
問題
guard の本来の意図は「ローカル git state を変更するコマンド」をブロックすること。gh issue close は git state と無関係なのにブロックされている。
修正方針
DISPLAY_READONLY_PATTERNS に加え GH_OPS_ALLOW_PATTERNS を追加:
GH_OPS_ALLOW_PATTERNS = [
r"^gh\s+issue\s+(close|create|edit|comment|reopen)(\s|$)",
r"^gh\s+pr\s+(create|comment|edit)(\s|$)",
]is_gh_mutation_command() でこのリストを allowlist に追加。
Parent Issue
none(PR #1100 の follow-up として独立 Issue)
Parent Goal Ref
- Goal: guard の allowlist-closed 方式が GitHub Issue/PR 操作(gh issue close/create/edit 等)を誤ってブロックしない
- Desired Destination:
is_gh_mutation_command()がGH_OPS_ALLOW_PATTERNSを持ち、GitHub ops を通過させる
Outcome
scripts/agent-guards/local_main_branch_guard.py の is_gh_mutation_command() が gh issue close/create/edit/comment/reopen および gh pr create/comment/edit を block せず通過させる。gh pr merge / gh pr checkout は引き続き block される。
Runtime Verification Applicability
- decision: not_applicable
- reason: guard ロジックの変更は pytest ユニットテストで静的に検証可能。ランタイム起動は不要
In Scope
scripts/agent-guards/local_main_branch_guard.pyにGH_OPS_ALLOW_PATTERNSを追加is_gh_mutation_command()をGH_OPS_ALLOW_PATTERNSで拡張- 対応するテスト追加(AC1〜AC4 のカバレッジ)
Out of Scope
- guard の他のブロックロジックの変更
gh pr merge/gh pr checkoutの動作変更- allowlist-closed 方式そのものの廃止
Current Validated Scope
scripts/agent-guards/local_main_branch_guard.pyのis_gh_mutation_command()のみを変更する- テストは
tests/codex/test_local_main_branch_guard.pyおよび.claude/hooks/tests/test_local_main_branch_guard.pyに追加する
Remaining Parent Gaps
- なし(本 Issue で完結)
Acceptance Criteria
- AC1:
gh issue close 1089が allow される - AC2:
gh issue createが allow される - AC3:
gh pr mergeは引き続き block される - AC4:
gh pr checkoutは引き続き block される
Allowed Paths
scripts/agent-guards/local_main_branch_guard.pytests/codex/test_local_main_branch_guard.py.claude/hooks/tests/test_local_main_branch_guard.py
Verification Commands
# AC1
# baseline-expect: fail
$ uv run pytest tests/codex/test_local_main_branch_guard.py -v -k "gh_issue_close_is_denied"# AC2
# baseline-expect: fail
$ uv run pytest tests/codex/test_local_main_branch_guard.py -v -k "unlisted_gh_mutations_are_blocked"# AC3
# baseline-expect: pass
$ uv run pytest tests/codex/test_local_main_branch_guard.py -v -k "gh_pr_merge_is_denied"# AC4
# baseline-expect: pass
$ uv run pytest tests/codex/test_local_main_branch_guard.py -v -k "gh_pr_checkout_is_denied"Stop Conditions
実装中にこれらの状況が発生したら直ちに作業を停止し、Issue comment に状況を記録して人間の判断を待つ:
- Allowed Paths 外のファイルへの変更が必要になった
- guard の他のブロックロジックに副作用が発生した
- AC1〜AC4 以外の既存テストが新たに失敗した
- スコープ外の機能追加が必要と判明した
- 設計上の不整合が発見された
- セキュリティ上の懸念が発生した
Required Skills
- Python(scripts/agent-guards/ の guard ロジック)
- pytest(テスト追加・実行)
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
issue_number: 1108
type: implementation
status: ready
outcome: "is_gh_mutation_command() で gh issue/pr GitHub ops を GH_OPS_ALLOW_PATTERNS allowlist に追加し user_github_ops_policy regression を修正する"
allowed_paths:
- scripts/agent-guards/local_main_branch_guard.py
- tests/codex/test_local_main_branch_guard.py
- .claude/hooks/tests/test_local_main_branch_guard.py
verification_commands:
- "uv run pytest tests/codex/test_local_main_branch_guard.py -v -k 'gh_issue_close_is_denied'"
- "uv run pytest tests/codex/test_local_main_branch_guard.py -v -k 'unlisted_gh_mutations_are_blocked'"
- "uv run pytest tests/codex/test_local_main_branch_guard.py -v -k 'gh_pr_merge_is_denied'"
- "uv run pytest tests/codex/test_local_main_branch_guard.py -v -k 'gh_pr_checkout_is_denied'"Source
follow-up:squne121/loop-protocol:pr/1100:gh-ops-regression-fix
Activity
squne121 commentedon Jun 21, 2026
判定: REQUEST_CHANGES
#1108 の問題提起自体は妥当です。
local_main_branch_guardの本来目的が「local root の Git checkout / branch state を壊す操作の遮断」なら、gh issue closeのような GitHub Issue 操作まで一律 block するのは過剰です。#1108 は PR #1100 後にgh issue close/create/editが block され、user_github_ops_policyと衝突した regression と説明しています。#1108 自体に追加コメントはありません。ただし、現在の #1108 の修正案をそのまま実装するのは危険です。
GH_OPS_ALLOW_PATTERNSを足してgh issue/prmutation を「block 対象外」にするだけだと、read-only / local-git-safe / remote-GitHub-mutation / interactive / branch-dependent の区別が崩れます。#1089 は明示的にgh issue view/listとgh pr view/list/statusだけを display read-only とし、gh issue edit/comment/closeやgh pr checkout/merge/update-branchを fail-closed にする contract でした。主要な衝突点
PR #1100 は #1089 の contract に沿って、
gh readonly 許可 / gh mutation fail-closedを実装した PR です。PR 本文でも AC11 としてDISPLAY_READONLY_PATTERNS拡張と mutation deny を掲げています。現在の実装では、
DISPLAY_READONLY_PATTERNSにgh issue view/listとgh pr view/list/statusだけが入り、is_gh_mutation_command()はそれ以外のgh issue/prを block する設計です。さらにテストも、
gh issue edit、gh issue close、gh pr merge、gh pr update-branchを block する前提で書かれています。別の completeness fixture ではgh issue createやgh pr createも block 対象です。#1108 を通すなら、これは単なる regression fix ではなく、#1089 の security/ops policy reversal として扱うべきです。重大ブロッカー
1.
gh pr createは「Issue/PR metadata 操作」では済まない#1108 は
gh pr createを allow 予定に含めていますが、これはかなり危険です。GitHub CLI の公式マニュアルでは、現在の branch が fully pushed でない場合、gh pr createはどこへ push するかを尋ね、fork や push を発生させ得ます。--headを使うと fork/push の挙動を回避できますが、bare なgh pr createは local branch state と remote write の両方に絡みます。(GitHub CLI)したがって、#1108 の初回修正で
gh pr createを allow するのはやめるべきです。必要なら別 Issue に分離し、少なくとも--head OWNER:branch --base main --title ... --body ... --repo squne121/loop-protocolのような非対話・明示 branch 指定だけを検討対象にしてください。2.
gh pr editは current branch 推定に依存し得るgh pr editは引数なしだと current branch の PR を選択します。つまり local checkout state に依存します。さらに base branch、reviewer、project、label など複数の PR metadata を変更できます。(GitHub CLI)gh pr editを allow するなら、baregh pr editは block し、PR number / URL を必須にするべきです。#1108 のr"^gh\s+pr\s+(create|comment|edit)"は広すぎます。3.
comment/edit/createには対話・削除・ファイル読込オプションがあるgh issue commentとgh pr commentには--delete-last、--edit-last、--editor、--web、--body-fileなどがあります。単純にcommentを allow すると、コメント追加だけでなく削除・編集・外部エディタ起動・ファイル読込をまとめて許可します。(GitHub CLI)gh issue createも bare 実行では対話入力に入り得ますし、--body-file、--editor、--web、project 追加などがあります。project 操作には追加 scope も必要です。(GitHub CLI)したがって、
GH_OPS_ALLOW_PATTERNSは「subcommand 名」だけで許可してはいけません。flag matrix まで固定してください。4.
gh pr mergeとgh pr checkoutを block 維持する根拠は強い#1108 の AC3/AC4 は正しいです。
gh pr checkoutは PR branch を checkout するコマンドであり、公式例でも branch switch を伴います。(GitHub CLI)gh pr mergeは GitHub 上で merge するだけでなく、--delete-branchにより local / remote branch の削除も含み得ます。これは local root guard の対象外にしてよい操作ではありません。(GitHub CLI)5. docs と hook-boundaries の更新が必須
docs/dev/hook-boundaries.mdは #1089 後の正本として、gh issue view/listとgh pr view/list/statusだけを readonly とし、gh mutation コマンド(edit/close/merge 等)を fail-closed と明記しています。#1108 はこの正本と衝突します。したがって実装だけ直すと、
scripts/check_hook_boundaries.pyの設計思想とドキュメント正本が乖離します。#1108 の Allowed Paths にはdocs/dev/hook-boundaries.mdと必要ならscripts/check_hook_boundaries.pyを入れるべきです。6. Codex parity テストが不足する
Claude 側テストには
gh issue close/create/editの deny fixture がありますが、Codex 側はgh pr checkoutdeny と read-only pipeline 中心で、新しい GitHub remote ops allow matrix はありません。#1089 の主眼は Claude/Codex parity でした。#1108 で shared core だけを直して Claude 側だけテストするのは、同じ種類の regression を再発させます。
推奨する設計
DISPLAY_READONLY_PATTERNSに足してはいけません。gh issue close/create/edit/comment/reopenは read-only ではなく、remote GitHub mutation です。新しい分類を作るべきです。評価順は概ね次が安全です。
readonly pipeline classifier
compound / wrapper / redirection fail-closed
shlex tokenization
git global option fail-closed
display readonly allow
branch-safe maintenance allow
/tmp/python -cfail-closedsafe GitHub remote ops allow
all other
gh issue/prmutation fail-closedbranch mutation detection
drifted/detached strict allowlist
default allow
safe GitHub remote opsは raw regex ではなく token ベースで判定してください。最低限、次をチェックするべきです。#1108 の AC 書き換え案
現行 AC は粗すぎます。以下に置き換えるのが安全です。
区分 | コマンド | 判定 -- | -- | -- allow | gh issue close 1089 --repo squne121/loop-protocol --reason completed | github_remote_ops_command allow | gh issue comment 1089 --repo squne121/loop-protocol --body "..." | github_remote_ops_command allow | gh issue reopen 1089 --repo squne121/loop-protocol --comment "..." | github_remote_ops_command allow 条件付き | gh issue create --repo squne121/loop-protocol --title "..." --body "..." | 非対話形式のみ block | bare gh issue create | 対話入力のため block block | gh issue comment 1089 --delete-last | destructive comment mutation block | gh issue comment 1089 --editor / --web | interactive / external UI block | gh issue edit 1089 --body-file secret.txt | file-read 経由の mutation block | gh pr create | push/fork/current branch 依存のため初回除外 block | bare gh pr edit | current branch 依存 block | gh pr checkout 123 | local checkout mutation block | gh pr merge 123 | merge / branch delete risk block | gh issue develop 123 --checkout | local checkout mutation block | gh api ... | endpoint/method/body 混在のため別 Issue追加すべきテスト
最低限、以下を追加してください。
テスト内容は次の matrix が必要です。
PreToolUse / PermissionRequest の両イベントで parity
最終結論
#1108 は「PR #1100 の副作用を直す Issue」としては必要です。ただし、現在の修正案は GitHub remote ops を read-only / non-mutation に誤分類する危険な巻き戻し です。
実装方針は次に限定してください。
gh issue close/comment/reopenなど、post-merge-cleanup に実際必要な操作だけをgithub_remote_ops_commandとして許可する。DISPLAY_READONLY_PATTERNSには入れない。gh pr create/gh pr editは初回修正から外すか、非対話・明示 repo・明示 branch の厳格条件を別 Issue で扱う。実装: local_main_branch_guard の Claude/Codex read-only parity と script allowlist を整備する #1089 で追加された deny fixture / hook-boundaries docs / Codex parity test を同時更新する。
この条件を満たさない PR は、false block の修正ではなく false allow の導入になります。
## 判定: REQUEST_CHANGES#1108 の問題提起自体は妥当です。
local_main_branch_guardの本来目的が「local root の Git checkout / branch state を壊す操作の遮断」なら、gh issue closeのような GitHub Issue 操作まで一律 block するのは過剰です。#1108 は PR #1100 後にgh issue close/create/editが block され、user_github_ops_policyと衝突した regression と説明しています。#1108 自体に追加コメントはありません。ただし、現在の #1108 の修正案をそのまま実装するのは危険です。
GH_OPS_ALLOW_PATTERNSを足してgh issue/prmutation を「block 対象外」にするだけだと、read-only / local-git-safe / remote-GitHub-mutation / interactive / branch-dependent の区別が崩れます。#1089 は明示的にgh issue view/listとgh pr view/list/statusだけを display read-only とし、gh issue edit/comment/closeやgh pr checkout/merge/update-branchを fail-closed にする contract でした。主要な衝突点
PR #1100 は #1089 の contract に沿って、
gh readonly 許可 / gh mutation fail-closedを実装した PR です。PR 本文でも AC11 としてDISPLAY_READONLY_PATTERNS拡張と mutation deny を掲げています。現在の実装では、
DISPLAY_READONLY_PATTERNSにgh issue view/listとgh pr view/list/statusだけが入り、is_gh_mutation_command()はそれ以外のgh issue/prを block する設計です。さらにテストも、
gh issue edit、gh issue close、gh pr merge、gh pr update-branchを block する前提で書かれています。別の completeness fixture ではgh issue createやgh pr createも block 対象です。#1108 を通すなら、これは単なる regression fix ではなく、#1089 の security/ops policy reversal として扱うべきです。重大ブロッカー
1.
gh pr createは「Issue/PR metadata 操作」では済まない#1108 は
gh pr createを allow 予定に含めていますが、これはかなり危険です。GitHub CLI の公式マニュアルでは、現在の branch が fully pushed でない場合、gh pr createはどこへ push するかを尋ね、fork や push を発生させ得ます。--headを使うと fork/push の挙動を回避できますが、bare なgh pr createは local branch state と remote write の両方に絡みます。([GitHub CLI]1)したがって、#1108 の初回修正で
gh pr createを allow するのはやめるべきです。必要なら別 Issue に分離し、少なくとも--head OWNER:branch --base main --title ... --body ... --repo squne121/loop-protocolのような非対話・明示 branch 指定だけを検討対象にしてください。2.
gh pr editは current branch 推定に依存し得るgh pr editは引数なしだと current branch の PR を選択します。つまり local checkout state に依存します。さらに base branch、reviewer、project、label など複数の PR metadata を変更できます。([GitHub CLI]2)gh pr editを allow するなら、baregh pr editは block し、PR number / URL を必須にするべきです。#1108 のr"^gh\s+pr\s+(create|comment|edit)"は広すぎます。3.
comment/edit/createには対話・削除・ファイル読込オプションがあるgh issue commentとgh pr commentには--delete-last、--edit-last、--editor、--web、--body-fileなどがあります。単純にcommentを allow すると、コメント追加だけでなく削除・編集・外部エディタ起動・ファイル読込をまとめて許可します。([GitHub CLI]3)gh issue createも bare 実行では対話入力に入り得ますし、--body-file、--editor、--web、project 追加などがあります。project 操作には追加 scope も必要です。([GitHub CLI]4)したがって、
GH_OPS_ALLOW_PATTERNSは「subcommand 名」だけで許可してはいけません。flag matrix まで固定してください。4.
gh pr mergeとgh pr checkoutを block 維持する根拠は強い#1108 の AC3/AC4 は正しいです。
gh pr checkoutは PR branch を checkout するコマンドであり、公式例でも branch switch を伴います。([GitHub CLI]5)gh pr mergeは GitHub 上で merge するだけでなく、--delete-branchにより local / remote branch の削除も含み得ます。これは local root guard の対象外にしてよい操作ではありません。([GitHub CLI]6)5. docs と hook-boundaries の更新が必須
docs/dev/hook-boundaries.mdは #1089 後の正本として、gh issue view/listとgh pr view/list/statusだけを readonly とし、gh mutation コマンド(edit/close/merge 等)を fail-closed と明記しています。#1108 はこの正本と衝突します。したがって実装だけ直すと、
scripts/check_hook_boundaries.pyの設計思想とドキュメント正本が乖離します。#1108 の Allowed Paths にはdocs/dev/hook-boundaries.mdと必要ならscripts/check_hook_boundaries.pyを入れるべきです。6. Codex parity テストが不足する
Claude 側テストには
gh issue close/create/editの deny fixture がありますが、Codex 側はgh pr checkoutdeny と read-only pipeline 中心で、新しい GitHub remote ops allow matrix はありません。#1089 の主眼は Claude/Codex parity でした。#1108 で shared core だけを直して Claude 側だけテストするのは、同じ種類の regression を再発させます。
推奨する設計
DISPLAY_READONLY_PATTERNSに足してはいけません。gh issue close/create/edit/comment/reopenは read-only ではなく、remote GitHub mutation です。新しい分類を作るべきです。評価順は概ね次が安全です。
/tmp/python -cfail-closedgh issue/prmutation fail-closedsafe GitHub remote opsは raw regex ではなく token ベースで判定してください。最低限、次をチェックするべきです。#1108 の AC 書き換え案
現行 AC は粗すぎます。以下に置き換えるのが安全です。
gh issue close 1089 --repo squne121/loop-protocol --reason completedgithub_remote_ops_commandgh issue comment 1089 --repo squne121/loop-protocol --body "..."github_remote_ops_commandgh issue reopen 1089 --repo squne121/loop-protocol --comment "..."github_remote_ops_commandgh issue create --repo squne121/loop-protocol --title "..." --body "..."gh issue creategh issue comment 1089 --delete-lastgh issue comment 1089 --editor/--webgh issue edit 1089 --body-file secret.txtgh pr creategh pr editgh pr checkout 123gh pr merge 123gh issue develop 123 --checkoutgh api ...追加すべきテスト
最低限、以下を追加してください。
uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -q uv run python3 scripts/check_hook_boundaries.py pnpm typecheck pnpm lint pnpm test pnpm buildテスト内容は次の matrix が必要です。
最終結論
#1108 は「PR #1100 の副作用を直す Issue」としては必要です。ただし、現在の修正案は GitHub remote ops を read-only / non-mutation に誤分類する危険な巻き戻し です。
実装方針は次に限定してください。
gh issue close/comment/reopenなど、post-merge-cleanup に実際必要な操作だけをgithub_remote_ops_commandとして許可する。DISPLAY_READONLY_PATTERNSには入れない。gh pr create/gh pr editは初回修正から外すか、非対話・明示 repo・明示 branch の厳格条件を別 Issue で扱う。この条件を満たさない PR は、false block の修正ではなく false allow の導入になります。
squne121 commentedon Jun 21, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 21, 2026
CONTRACT_REVIEW_RESULT_V1
→ implement-issue へ handoff 可能
squne121 commentedon Jun 21, 2026
Draft PR を作成しました: #1120
fix(guard): hooks/tests の gh issue/pr allow 系テストを更新 (#1108)