Repository navigation
feat(guard): gh mutation block に専用 reason_code を追加し telemetry 精度を向上する #1109
Copy link
Copy link
Closed
Labels
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: null
goal_ref: "gh issue/pr mutation block に専用 reason_code gh_mutation_denied を追加し、telemetry 精度と recovery hint を正確化する"
change_kind: code背景
Issue #107 の impl-review-loop 実行中、gh issue close 107 が local_main_branch_guard.py により block されたが、返却された reason_code が unparseable_branch_mutation だった。これは実際の原因(GitHub mutation denied)を表しておらず、agent が「simple git command に直せばよい」と誤解する telemetry 問題。
PR #1100 の non-blocking observation として #1109 が起票済み。本 Issue でその実装を行う。
Outcome
gh issue/pr の readonly allowlist 外 command は gh_mutation_denied として block され、stderr recovery hint も GitHub write wrapper / rtk / approved issue workflow へ誘導する文言になる。readonly gh issue view/list、gh pr view/list/status は従来どおり allow される。
Current Validated Scope
scripts/agent-guards/local_main_branch_guard.pyにREASON_GH_MUTATION = "gh_mutation_denied"を追加gh issue edit/comment/close/reopen/delete/lock/unlockはgh_mutation_deniedで blockgh pr checkout/edit/comment/merge/update-branch/reviewはgh_mutation_deniedで blockgh issue view/list、gh pr view/list/statusは readonly として allowgh apiの blanket allow は追加しない- Claude/Codex 両 hook test に同じ allow/deny matrix を追加
Remaining Parent Gaps
なし(スタンドアロン実装 Issue)
Outcome
以下がすべて満たされた状態で #1109 がクローズされている:
gh_mutation_deniedreason_code が追加され、gh mutation block に適用されるgh issue view/list、gh pr view/list/statusは allow のまま変わらない- Claude と Codex 両方の hook test が同じ allow/deny matrix を持つ
- recovery hint が GitHub mutation 文脈の文言になる
In Scope
scripts/agent-guards/local_main_branch_guard.pyへの reason_code 追加.claude/hooks/tests/test_local_main_branch_guard.pyのテスト追加tests/codex/test_local_main_branch_guard.pyのテスト追加(存在する場合)docs/dev/hook-boundaries.mdの最小更新(必要な場合のみ)scripts/check_hook_boundaries.pyの確認(存在する場合)
Out of Scope
- branch mutation / compound command / tmp wrapper / deterministic checker の挙動変更
gh apiの blanket allow 追加- 他の guard 機能の追加・変更
- 実装: agent context budget inventory を導入し AGENTS/CLAUDE/skills/hooks/subagents/rules/scripts の重複読みに上限を設ける #1093、実装: local_main_branch_guard の Claude/Codex read-only parity と script allowlist を整備する #1089 スコープの変更
Acceptance Criteria
- AC1:
REASON_GH_MUTATION = "gh_mutation_denied"が追加される - AC2:
gh issue close/comment/edit/reopen/delete/lock/unlockはgh_mutation_deniedで block される - AC3:
gh pr checkout/edit/comment/merge/update-branch/reviewはgh_mutation_deniedで block される - AC4:
gh issue view/list、gh pr view/list/statusは readonly として allow される - AC5:
gh apiの blanket allow は追加されない - AC6: Claude/Codex 両 hook test に同じ allow/deny matrix がある
- AC7: stderr recovery hint が GitHub mutation 用の文言になる(例:
recovery: use the approved rtk/skill wrapper or run GitHub mutation from the designated issue workflow)
Verification Commands
# AC1-AC7: gh mutation deny / gh readonly allow のテスト
uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -k "gh_readonly or gh_deny or gh_mutation" -q
# 全体テスト(regression 確認)
uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -q
# hook boundary 確認(スクリプトが存在する場合)
uv run python3 scripts/check_hook_boundaries.pyRuntime Verification Applicability
decision: not_applicable
reason: "guard script の unit test で動作検証する。runtime hook 実行は不要"Allowed Paths
scripts/agent-guards/local_main_branch_guard.py.claude/hooks/tests/test_local_main_branch_guard.pytests/codex/test_local_main_branch_guard.pydocs/dev/hook-boundaries.mdscripts/check_hook_boundaries.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- 既存 branch mutation / compound command detection 挙動の変更が必要な場合
- Claude/Codex parity が崩れ、修正が Allowed Paths 外に及ぶ場合
Required Skills
- Python (scripts/agent-guards/local_main_branch_guard.py の編集)
- pytest
Activity
squne121 commentedon Jun 21, 2026
CONTRACT_REVIEW_RESULT_V1
status: go
issue_number: 1109
repo: squne121/loop-protocol
reviewed_at: 2026-06-21T12:49:00Z
body_sha256: sha256:9a823e63b28b8a6cf861b356292c6ffea41ea7a3e10cb126c6a5a9e4d0cebab6
checks:
template_compliance: pass
state_label: pass (triage-required は state/needs-human ではないため非ブロック)
allowed_paths_present: pass
vc_present: pass
stop_conditions_complete: pass
ac_verifiability:
status: warn
note: "VC コメントが # ACn 形式でなく # AC1-AC7 形式のため AC_UNKNOWN マッピング。実装品質に影響しないが PR review 時に注意"
product_spec_check:
applicability: not_applicable
decision: pass
worktree_branch_collision:
status: clean
proposed_worktree: .claude/worktrees/issue-1109-gh-mutation-reason-code
proposed_branch: worktree-issue-1109-gh-mutation-reason-code
vc_preflight:
status: go_with_notes
classifications:
- vc_index: 1
raw_command: "uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -k "gh_readonly or gh_deny or gh_mutation" -q"
exit_code: 0
classification: expected_pass
scope_class: regression_gate
decision: go
note: "baseline で 24 tests pass / 211 deselected。実装後に新 gh_mutation_denied テストが追加されパス数増加予定"
- vc_index: 2
raw_command: "uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -q"
exit_code: 0
classification: expected_pass
scope_class: regression_gate
decision: go
note: "baseline で 235 tests pass"
- vc_index: 3
raw_command: "uv run python3 scripts/check_hook_boundaries.py"
exit_code: null
classification: blocked
category: command_not_allowed
decision: optional_blocked
note: "VC preflight allowlist 外。Issue 本文に '(スクリプトが存在する場合)' と明記された optional VC のため非ブロック。実装後に PR review で確認"
next_action: proceed_to_implement
blocked_reasons: []
contract_snapshot:
outcome: "gh issue/pr mutation block に専用 reason_code gh_mutation_denied を追加し、telemetry 精度と recovery hint を正確化する"
acceptance_criteria:
- "AC1: REASON_GH_MUTATION = gh_mutation_denied が追加される"
- "AC2: gh issue close/comment/edit/reopen/delete/lock/unlock は gh_mutation_denied で block される"
- "AC3: gh pr checkout/edit/comment/merge/update-branch/review は gh_mutation_denied で block される"
- "AC4: gh issue view/list、gh pr view/list/status は readonly として allow される"
- "AC5: gh api の blanket allow は追加されない"
- "AC6: Claude/Codex 両 hook test に同じ allow/deny matrix がある"
- "AC7: stderr recovery hint が GitHub mutation 用の文言になる"
verification_commands:
- "uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -k gh_readonly or gh_deny or gh_mutation -q"
- "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 (optional)"
allowed_paths:
- scripts/agent-guards/local_main_branch_guard.py
- .claude/hooks/tests/test_local_main_branch_guard.py
- tests/codex/test_local_main_branch_guard.py
- docs/dev/hook-boundaries.md
- scripts/check_hook_boundaries.py
worktree: .claude/worktrees/issue-1109-gh-mutation-reason-code
branch: worktree-issue-1109-gh-mutation-reason-code
runtime_verification_applicability: not_applicable
feat(guard): add gh_mutation_denied reason_code for gh issue/pr mutat…
docs: hook-boundaries.md に gh_mutation_denied reason_code を追記(#1109 B1)
feat(guard): add gh_mutation_denied reason_code for gh issue/pr mutat…
docs: hook-boundaries.md に gh_mutation_denied reason_code を追記(#1109 B1)
feat(guard): add gh_mutation_denied reason_code for gh issue/pr mutat…