Skip to content

feat(guard): gh mutation block に専用 reason_code を追加し telemetry 精度を向上する #1109

Closed

Description

@squne121

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 で block
  • gh pr checkout/edit/comment/merge/update-branch/review は gh_mutation_denied で block
  • gh issue view/list、gh pr view/list/status は readonly として allow
  • gh api の blanket allow は追加しない
  • Claude/Codex 両 hook test に同じ allow/deny matrix を追加

Remaining Parent Gaps

なし(スタンドアロン実装 Issue)

Outcome

以下がすべて満たされた状態で #1109 がクローズされている:

  1. gh_mutation_denied reason_code が追加され、gh mutation block に適用される
  2. gh issue view/list、gh pr view/list/status は allow のまま変わらない
  3. Claude と Codex 両方の hook test が同じ allow/deny matrix を持つ
  4. 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

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.py

Runtime 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.py
  • tests/codex/test_local_main_branch_guard.py
  • docs/dev/hook-boundaries.md
  • scripts/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

  1. added
    enhancement
    triage-required
    on Jun 21, 2026
  2. squne121 commented on Jun 21, 2026

    @squne121
    OwnerAuthor

    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

  3. added 5 commits that reference this issue on Jun 21, 2026
    1fff9d6
    e4964fe
    e9640a6
    eb9eb90
    f749960
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions