Skip to content

実装: local hook の unparseable_branch_mutation 誤判定で issue-refinement-loop が停止する問題を解消する #1198

Closed
1 of 1 issue completed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "Codex local hook が read-only / non-branch-mutating な操作を branch mutation と誤判定し、issue-refinement-loop / ssot-discovery / edit-issue の正規導線を阻害している"
change_kind: mixed

Parent Issue

none(単独改善)

Parent Goal Ref

  • Goal: Codex / Claude / local hook guardrail の安全性を維持したまま、false positive による agent workflow 停止を減らす
  • Desired Destination: local_main_branch_guard が実際の branch mutation だけを block し、GitHub URL fragment・read-only command・rtk wrapper・限定された GitHub remote op を誤って unparseable_branch_mutation と判定しない状態

Current Validated Scope

現行ログでは、Codex v0.142.3 の ~/projects/LOOP_PROTOCOL root で issue-refinement-loop 実行中に PreToolUse hook が多数 error: hook exited with code 1 を返し、さらに local_main_branch_guard が reason_code: unparseable_branch_mutation で block している。対象操作は gh issue view / gh api repos/.../issues/comments/... / rtk --help / rtk gh issue edit ... --body-file ... / issue comment URL fragment を含む preflight 周辺であり、local branch を変更する意図はない。ログ上でも current branch は default branch のままで、hook の recovery は “use simple (non-compound) git commands from local root” となっている。

また、現時点では root cause を URL fragment 単独と断定せず、Codex hook runner が渡す raw event payload と tool_input.command の抽出差分も含めて再現 fixture で切り分ける必要がある。

Remaining Parent Gaps

なし

Problem

local_main_branch_guard は local root checkout を default branch に維持する目的の guard だが、現状では以下の non-mutating / non-branch-mutating 操作まで branch mutation として扱っている可能性がある。

  • GitHub issue/comment URL fragment を含む argv

    • 例: https://github.com/squne121/loop-protocol/issues/1170#issuecomment-...
  • gh issue view

  • gh api repos/squne121/loop-protocol/issues/comments/<id> の read-only GET

  • rtk --help

  • rtk gh issue edit ... --repo squne121/loop-protocol --body-file tmp/...

  • skill / docs / current-focus などの read-only file inspection

  • Codex hook runner が渡す tool input の raw event / command extract 差分

その結果、以下が起きる。

  • issue-refinement-loop の preflight が直接実行できない
  • 正規 skill path から deterministic fallback へ逸脱する
  • hook の failed が hook 名・理由なしで連続し、原因調査コストが高い
  • PermissionRequest hook / Stop hook でも error: hook exited with code 1 が発生し、終了時の信頼性が下がる
  • agent が安全のための guardrail を回避対象として扱い始めるリスクがある

Outcome

local_main_branch_guard の classifier / diagnostics / regression fixtures / docs が更新され、local root default branch 保護を維持したまま issue-refinement-loop preflight と edit-issue workflow が false positive block されず、実 branch mutation は引き続き block される状態。

追加で以下を満たす。

  • gh api は blanket allow せず、exact GET issue-comment endpoint だけを対象化する
  • rtk は bypass allow ではなく first-class wrapper として監視し、inner command を既存 classifier に委譲する
  • diagnostics は hook / parser / matched rule を構造化して返し、unknown command を readonly_command と混同しない
  • raw hook event fixture に基づく再現が先に成立する

In Scope

  • local_main_branch_guard の判定ロジック修正

  • branch mutation 判定を string grep から allow/deny classifier へ寄せる

  • #issuecomment-* など URL fragment を branch mutation 構文として扱わない

  • gh issue view / gh api repos/.../issues/comments/<id> / gh issue edit --body-file の扱いを明確化

  • rtk <inner command> wrapper 配下の実コマンド解析

  • hook failure 時の diagnostics 改善

    • hook name
    • event kind
    • parsed command kind
    • matched rule id
    • parser stage
    • block / warn / allow decision
    • wrapper / inner command provenance
  • raw hook event regression fixtures の追加

  • true-positive / false-positive regression tests の追加

  • docs への local hook false-positive recovery 追記

Out of Scope

  • local root checkout での実 branch switch を許可する変更
  • git checkout / git switch / git reset --hard / git branch -M などの危険操作を緩和する変更
  • gh api の blanket allow
  • gh issue edit の既存 allow 条件(--repo squne121/loop-protocol + --body-file tmp/...)を弱める変更
  • Claude / Codex 本体の挙動変更
  • GitHub issue refinement の仕様変更
  • agent approval policy 全体の再設計
  • secret / credential / network 権限の拡大

Acceptance Criteria

  • AC1: local_main_branch_guard が https://github.com/...#issuecomment-... を含む argv を unparseable_branch_mutation として block しない
  • AC2: gh issue view <n> --repo squne121/loop-protocol --json ... が local branch mutation と判定されない
  • AC3: gh api repos/squne121/loop-protocol/issues/comments/<id> または gh api --method GET repos/squne121/loop-protocol/issues/comments/<id> の exact read-only 取得だけが allow され、--method POST|PATCH|PUT|DELETE、-f/-F/--input、graphql は block される
  • AC4: rtk --help / rtk gain / rtk gain --history / rtk session が local branch mutation と判定されない
  • AC5: rtk <inner> は wrapper として unwrap され、rtk gh issue edit <n> --repo squne121/loop-protocol --body-file tmp/... は inner gh issue edit の既存 classifier 結果を踏襲する
  • AC6: git checkout <branch> / git switch <branch> / git branch -M <name> / git reset --hard <ref> は引き続き block される
  • AC7: hook failure 時に hook_name / event_kind / decision / reason_code / rule_id / command_kind / parser_stage / argv_redacted を含む診断が返る
  • AC8: PermissionRequest hook / Stop hook が同じ parser 例外で落ちず、event-not-applicable または no-command として安全に処理される
  • AC9: issue-refinement-loop の preflight を local root default branch 上で実行しても false-positive block しないことが raw fixture または等価 harness で再現確認できる
  • AC10: false-positive regression fixture と true-positive regression fixture が raw hook event fixture と command fixture の両方で追加されている
  • AC11: hook の parser が unknown command を即 block / review する場合でも、unparseable_branch_mutation や readonly_command ではなく unknown_command_requires_review などの区別可能な reason_code を返す
  • AC12: 既存の local root checkout default-branch 保護の意図と、GitHub remote write policy を本 Issue では拡張しないことが docs に明記されている
  • AC13: Codex の raw PreToolUse fixture に含まれる issue comment URL fragment が block されない
  • AC14: parser は raw event JSON から command extract までを再現可能に扱い、# を URL fragment として保持する
  • AC15: gh pr checkout <n> / gh pr merge <n> --delete-branch / git checkout -b <name> / git switch -c <name> は block fixture に含まれる
  • AC16: rtk gh api -f body=... / rtk gh api --method PATCH ... / rtk proxy bash -lc 'git switch <branch>' / rtk <unknown> は block または review される

Suggested Fixtures

Raw hook event fixtures

tests/fixtures/hooks/ に少なくとも以下を追加する。

  • PreToolUse raw JSON fixture
  • PermissionRequest raw JSON fixture
  • Stop raw JSON fixture

上記 fixture には issue comment URL fragment や rtk wrapper を含む実例を最小化して保存する。

Allow: URL fragment / read-only GitHub metadata

gh api repos/squne121/loop-protocol/issues/comments/4814545233
gh api --method GET repos/squne121/loop-protocol/issues/comments/4814545233
gh issue view 1170 --repo squne121/loop-protocol --json title,body,url,labels
echo "https://github.com/squne121/loop-protocol/issues/1170#issuecomment-4814071263"

Allow: rtk wrapper read-only / approved envelope

rtk --help
rtk gain --history
rtk gh issue view 1170 --repo squne121/loop-protocol
rtk gh issue edit 1170 --repo squne121/loop-protocol --body-file tmp/issue_1170_body.md

Block: actual branch mutation / destructive GitHub ops / unsafe wrapper payload

git checkout feature/foo
git switch feature/foo
git branch -M main
git reset --hard HEAD~1
git checkout -b issue-1198
git switch -c issue-1198
gh pr checkout 123
gh pr merge 123 --delete-branch
gh api repos/squne121/loop-protocol/issues/1198/comments -f body='x'
gh api --method PATCH repos/squne121/loop-protocol/issues/comments/4814545233
rtk gh api -f body='x' repos/squne121/loop-protocol/issues/1198/comments
rtk proxy bash -lc 'git switch issue-1198'
rtk unknown-subcommand

Verification Commands

# AC5
# AC7
# AC11
# AC12
$ pnpm typecheck
# AC5
# AC7
# AC11
# AC12
$ pnpm lint
# AC1
# AC2
# AC3
# AC4
# AC5
# AC6
# AC7
# AC8
# AC9
# AC10
# AC11
# AC13
# AC14
# AC15
# AC16
$ pnpm test
# AC12
$ pnpm build

Implementation Notes

  • local_main_branch_guard should parse the intended command structurally instead of matching arbitrary raw text.

  • raw hook event から tool_input.command を抽出する段と、その後の command classifier を分離し、どの段で失敗したか diagnostics で追えるようにする。

  • URL fragments beginning with # must be treated as URL data, not shell comment / branch / ref syntax.

  • rtk は trusted CLI proxy として扱うが、rtk prefix を理由に bypass allow してはならない。

    • rtk --help / rtk gain / rtk session は専用 rule で allow
    • rtk gh issue edit ... は unwrap して inner gh issue edit classifier に委譲
    • rtk gh api ... は unwrap して exact GET allowlist に合う場合のみ allow
    • rtk proxy <command> は inner command を安全に構造解析できる場合のみ許可し、解析不能なら rtk_proxy_requires_review などで fail-close
  • GitHub metadata operations should be separated from local checkout mutation:

    • gh issue view: allow
    • gh api repos/.../issues/comments/<id> GET: allow
    • gh issue edit: branch mutation ではないが、既存の remote write policy / --repo / --body-file 制約を維持する
  • diagnostics は少なくとも hook_name, event_kind, decision, reason_code, rule_id, command_kind, argv_redacted, parser_stage, root_state, wrapper, inner_argv_redacted, decision_source を出力できる形に整理する。

  • unknown command / parse failure は readonly_command に落とさず、review or deny 用の distinct reason_code に分類する。

Runtime Verification Applicability

decision: deferred
reason: local hook runtime behavior changes. Must verify with real Codex/Claude hook invocation or an equivalent fixture harness.
deferred_destination: implementation PR or follow-up verification comment with fixture harness evidence
deferred_verification_condition: local hook classifier change is merged and a real Codex/Claude hook invocation or equivalent harness can be executed on the updated path

Allowed Paths

  • .claude/hooks/**
  • .codex/**
  • scripts/**
  • tools/**
  • tests/**
  • docs/dev/**
  • package.json
  • pnpm-lock.yaml

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • hook の所在が repo 外で、Issue 実装対象として version control できないと判明した場合
  • local root default branch 保護を弱めないと修正できない場合
  • gh issue edit などの GitHub metadata write approval policy まで再設計が必要になった場合
  • Codex / Claude 本体側の bug で、repo 側 hook では回避不能と判明した場合
  • secret / credential / external service 権限の追加が必要になった場合

Required Skills

なし

Delivery Rule

1 Issue = 1 PR。local root default branch では実 branch mutation を行わず、必要なら dedicated worktree で実装し、Draft PR を既定とする。

Scope Delta(任意)

N/A

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jun 26, 2026
  2. squne121 commented on Jun 27, 2026

    @squne121
    OwnerAuthor

    you asked

    message time: 2026-06-27 08:57:14

    #1198
    内容について関連Issue、PR、コメントを参照した上で敵対的レビューして。
    取り扱う技術や配布物の実装をWEB調査し高品質化してほしい。


    chatgpt response

    対象 Issue の本文・コメント・関連 PR/Issue を確認し、実装対象の外部仕様や現行実装も照合します。まず GitHub 側の文脈を取得し、その後に技術調査でレビュー観点を補強します。

    Issue #1198 はコメントなしで、本文だけにスコープ・AC・fixture がかなり詳細に書かれています。次に、同じ hook / issue-refinement-loop / unparseable_branch_mutation 周辺の既存 Issue/PR を横断して重複・抜けを確認します。

    判定: REQUEST_CHANGES

    #1198 の問題提起は妥当です。local_main_branch_guard が「local root checkout の branch drift 防止」を目的にしているなら、gh issue view、コメント URL、rtk --help、read-only な gh api まで unparseable_branch_mutation として止めるのは過剰です。ただし、Issue 本文は false positive 修正 と GitHub remote mutation の許可拡張 と rtk wrapper trust policy を混ぜています。このまま実装すると、過去に #1108/#1124 で踏んだ「read-only / remote write / local branch mutation の混同」を再発させます。#1198 自体にコメントはありません。

    関連文脈上も、これは単発の hook バグではありません。#1014/PR #1041 で root checkout を default branch に固定する guard が導入され、#1089 で Claude/Codex read-only parity が整備され、#1108/#1120/#1118/#1124 で gh issue/pr の read-only・remote ops・destructive 操作分類が段階的に分離されています。特に #1118 は gh api blanket allow を避け、gh issue view/list と gh pr view/list/status だけを readonly として維持する方向でした。

    ブロッカー

    B1. gh api を「read-only」として扱う AC3 が危険

    #1198 は gh api repos/.../issues/comments/<id> を local branch mutation ではないとして allow したい、という粒度なら正しいです。しかし gh api 全体を allow する設計に見えると危険です。GitHub CLI の gh api は通常 GET ですが、field を追加すると POST に切り替わり、-F key=@file はファイル内容を読み、--input <file> も request body をファイルや stdin から渡せます。公式例にも issue comment 投稿があります。(GitHub CLI) (GitHub CLI)

    修正方針: AC3 は次のように絞るべきです。

    allow:
      gh api repos/squne121/loop-protocol/issues/comments/<digits>
      gh api --method GET repos/squne121/loop-protocol/issues/comments/<digits>
    
    block:
      gh api -f/-F/--field/--raw-field/--input ...
      gh api --method POST|PATCH|PUT|DELETE ...
      gh api graphql ...
      gh api repos/<other>/<repo>/...
      gh api .../issues/<n>/comments -f body=...
    

    reason_code も readonly_command ではなく、github_api_readonly_command など別分類にするのがよいです。

    B2. gh issue edit --body-file は「branch mutation ではない」が「remote write + file read」です

    #1198 の AC5 は rtk gh issue edit <n> --repo ... --body-file ... を branch mutation と判定しない、という意味では正しいです。しかし gh issue edit は issue 本文だけでなく labels、milestone、project、type、relationship なども変更できます。さらに --body-file はファイルまたは stdin から本文を読みます。--repo で別 repository も対象にできます。(GitHub CLI) (GitHub CLI)

    現行実装には、gh issue create/edit を --repo squne121/loop-protocol、--body-file tmp/...、非対話 flag 禁止、tmp/ confinement で許可する classifier が既にあります。#1198 はこれを弱めてはいけません。

    修正方針: rtk gh issue edit は「rtk を外して inner gh issue edit を既存 classifier に再帰分類する」と明記してください。rtk gh issue edit 1198 --body-file /etc/passwd、--body-file -、--repo other/repo、--web、--editor は block fixture 必須です。

    B3. URL fragment の根因がまだ特定されていない

    #1198 は #issuecomment-* を branch/ref/comment 構文として誤判定していると書いていますが、現行 local_main_branch_guard.py の shell metachar regex は # を含んでいません。また Python shlex.split() は既定で comments=False なので、# を shell comment として扱いません。 (Python documentation)

    つまり、単純に「# を許可する」修正では実バグに当たらない可能性があります。Codex hook runner が渡す raw JSON payload、tool_input.command の実文字列、PermissionRequest/Stop の schema 差分を fixture 化しないと、実装者は違う場所を直す恐れがあります。現行 hook は stdin JSON から tool_input.command だけを取り出し、空なら allow します。

    追加 AC:

    AC追加: Codex v0.142.3 の実ログから最小化した PreToolUse / PermissionRequest / Stop JSON fixture を tests/fixtures/hooks/ に保存し、同 fixture で false positive を再現してから修正する。
    

    B4. rtk wrapper の trust boundary が未定義

    #1198 は rtk --help と rtk gh issue edit ... を allow したいように読めますが、rtk が何者か、repo-local script なのか、PATH 上の executable なのか、shell alias なのか、どの subcommand が安全かが定義されていません。現行の主要分類順を見る限り、rtk を inner gh として構造的に分類する段はなく、未知 command は最後に allow されて readonly_command 扱いになります。これは telemetry と policy の両方で悪いです。

    修正方針:

    allow:
      rtk --help                      -> rtk_help_command
      rtk gh issue edit ...           -> unwrap once, classify as gh issue edit
    
    block/review:
      rtk sh -c ...
      rtk bash ...
      rtk gh api ...                  -> exact GET allowlist に合う場合のみ allow
      rtk <unknown>                   -> unknown_wrapper_requires_review
    

    rtk の absolute path / provenance を要求するか、少なくとも command -v rtk 結果を diagnostic に出す fixture を追加してください。

    B5. diagnostics AC7 が弱い

    #1198 は hook name、parsed command kind、argv、rule id、decision を要求していますが、現行 stderr は reason_code、branch kind、recovery、hook flavor 程度です。parsed argv や rule id は出ていません。

    追加 AC はこの程度まで固定すべきです。

    {
      "schema": "LOCAL_MAIN_BRANCH_GUARD_DIAGNOSTIC_V1",
      "event_kind": "PreToolUse|PermissionRequest|Stop",
      "hook_name": "local_main_branch_guard",
      "decision": "allow|block|not_applicable",
      "reason_code": "...",
      "rule_id": "gh_api_exact_issue_comment_get|rtk_unwrap_gh_issue_edit|...",
      "command_kind": "github_api_readonly|github_issue_mutation|rtk_wrapper|branch_mutation|unknown",
      "argv_redacted": ["gh", "api", "repos/squne121/loop-protocol/issues/comments/<id>"],
      "parser_stage": "json_event|command_extract|shlex|classifier",
      "root_state": "default|drifted|detached_or_unknown"
    }

    raw URL や body text、file contents、branch 名の生値は出さず、既存の branch kind redaction 方針を維持するのが妥当です。

    B6. block fixture が不足している

    #1198 の block fixture は git checkout / git switch / git branch -M / git reset --hard だけです。gh pr checkout は公式に Git checkout を行うコマンドで、gh pr merge --delete-branch は local/remote branch delete を含み得ます。これらは local root guard の負例に入れるべきです。(GitHub CLI) (GitHub CLI)

    追加 fixture:

    gh pr checkout 123
    gh pr checkout 123 --branch issue-123
    gh pr checkout 123 --detach
    gh pr merge 123 --delete-branch
    gh pr create
    gh pr create --dry-run
    git checkout -b issue-1198
    git switch -c issue-1198
    git switch --detach HEAD
    git branch -m issue-1198
    git clean -fd

    gh pr create は current branch が未 push の場合に push/fork 先を尋ね得るため、remote metadata 操作として雑に allow してはいけません。(GitHub CLI)

    #1198 の修正版スコープ案

    この Issue は次の 1 PR に絞ると安全です。

    Goal:
      local_main_branch_guard の parser false positive と diagnostics を直す。
      GitHub remote write policy は既存 #1124 分類を再利用し、拡張しない。
    
    Must:
      - raw Codex hook JSON fixture で再現する
      - URL fragment を argv data として扱う
      - gh issue view/list, gh pr view/list/status は既存 readonly
      - gh api は exact GET issue-comment endpoint のみ allow
      - rtk は wrapper として一段だけ unwrap し、inner command を既存 classifier に委譲
      - unknown command を readonly_command と記録しない
      - diagnostics V1 を追加する
      - PermissionRequest/Stop は event_not_applicable または no-command allow として落とさない
    
    Must not:
      - gh api blanket allow
      - gh issue edit の条件緩和
      - gh pr create/checkout/merge の許可
      - unknown rtk の default allow
      - root default branch 保護の緩和
    

    追加すべき AC

    AC13: raw Codex PreToolUse fixture に含まれる issue comment URL fragment は block されない。
    AC14: shlex parse では comments=False / commenters="" 相当を維持し、# は URL fragment として扱う。
    AC15: gh api allow は exact GET repos/squne121/loop-protocol/issues/comments/<digits> のみ。
    AC16: gh api with -f/-F/--input/--method POST|PATCH|PUT|DELETE/graphql は block。
    AC17: rtk --help は allow、reason_code=rtk_help_command。
    AC18: rtk gh issue edit は inner gh issue edit classifier と同じ allow/block 結果になる。
    AC19: unknown rtk subcommand は unknown_wrapper_requires_review で block または no-decision。
    AC20: default allow の reason_code は readonly_command ではなく unknown_non_branch_command などに分離する。
    AC21: diagnostics V1 に hook_name/rule_id/command_kind/parser_stage/argv_redacted/event_kind を含める。
    AC22: PermissionRequest/Stop fixture は parser exception で exit 1/2 にならない。
    

    最終結論

    #1198 は採用価値があります。ただし、現状のまま実装すると gh api と rtk を通じた remote write/file-read の許可拡大、および unknown command を readonly 扱いする telemetry 汚染 を再発させます。まず raw hook fixture で再現性を固定し、gh api は exact GET allowlist、rtk は wrapper unwrap、diagnostics は schema 化、remote mutation policy は既存 #1124 分類へ委譲、という形に書き換えるべきです。


    you asked

    message time: 2026-06-27 10:20:47

    https://github.com/rtk-ai/rtk は許可。rtkが包括するコマンドを監視したい。


    chatgpt response

    了解。前回レビューの B4 は前提修正します。

    修正後の方針: rtk 自体は許可。ただし rtk は Bash command を rtk <command> に rewrite/proxy し、git add/commit/push、git pull、gh pr/issue、test runner、Docker/Kubernetes、AWS、curl/wget、rtk proxy <command> まで包むため、rtk を bypass allow するのではなく、rtk envelope を監視・分類するべきです。rtk README でも hook-based agents が git status などを rtk git status に rewrite すると説明され、対応コマンドには Git mutation や GitHub CLI、rtk proxy <command> が含まれます。(GitHub) (GitHub) (GitHub)

    #1198 に入れるべき設計変更

    rtk allowed は以下の意味に限定するのが安全です。

    rtk executable / rtk hook rewrite は許可する。
    ただし local_main_branch_guard は rtk を terminal command としてそのまま default allow しない。
    rtk <inner argv...> を unwrap し、inner command を既存 classifier に通す。
    判定結果には rtk envelope 情報を diagnostics と telemetry に残す。
    

    つまり:

    allow:
      rtk --help
      rtk gain
      rtk gain --history
      rtk session
      rtk git status
      rtk git log -n 10
      rtk gh issue view 1198 --repo squne121/loop-protocol
      rtk gh issue list --repo squne121/loop-protocol
    
    classify by inner command:
      rtk gh issue edit ...       -> gh issue edit classifier
      rtk gh api ...              -> gh api exact allowlist classifier
      rtk git switch ...          -> branch mutation classifier
      rtk git checkout ...        -> branch mutation / path restore classifier
      rtk git push                -> remote write classifier / separate policy
      rtk proxy <command>         -> unwrap proxy payload, otherwise block/review
    
    block:
      rtk git checkout feature/foo
      rtk git switch issue-1198
      rtk gh pr checkout 123
      rtk gh pr merge 123 --delete-branch
      rtk gh api -f body=...
      rtk proxy bash -lc 'git switch issue-1198'
    

    追加 AC 案

    AC13: `rtk` は trusted executable として認識され、`rtk --help` / `rtk gain` / `rtk session` は block されない。
    
    AC14: `rtk <inner>` は wrapper として unwrap され、inner argv が local_main_branch_guard の既存 classifier に渡される。
    
    AC15: `rtk git status` / `rtk git log` / `rtk gh issue view` は allow され、diagnostics に wrapper=rtk, inner_kind=readonly を記録する。
    
    AC16: `rtk git checkout <branch>` / `rtk git switch <branch>` / `rtk gh pr checkout <n>` は block され、reason は rtk ではなく inner branch mutation に由来する。
    
    AC17: `rtk gh issue edit <n> --repo squne121/loop-protocol --body-file tmp/...` は既存 `gh issue edit` policy と同じ条件で allow/block される。
    
    AC18: `rtk gh api` は blanket allow しない。exact GET issue/comment endpoint のみ allow し、`-f/-F/--input/--method POST|PATCH|PUT|DELETE/graphql` は block する。
    
    AC19: `rtk proxy <command>` は raw passthrough + tracking 経路なので、inner command を安全に構造解析できる場合だけ allow。解析不能なら `rtk_proxy_requires_review` で block/no-decision。
    
    AC20: diagnostics V1 に `wrapper: "rtk"`, `inner_argv_redacted`, `inner_command_kind`, `rtk_subcommand`, `rule_id`, `decision_source` を追加する。
    
    AC21: rtk 自身の履歴確認コマンド `rtk gain --history`, `rtk gain --all --format json`, `rtk session` を運用監査手順 docs に追加する。ただし guard 判定の source of truth にはしない。
    

    rtk には rtk gain --history、rtk gain --all --format json、rtk session があり、採用状況や履歴を確認できます。ただしこれは事後分析用です。実行前の safety gate は local_main_branch_guard 側で rtk を unwrap して判定する必要があります。(GitHub)

    Issue 本文への差し替え文

    ### rtk wrapper policy
    
    `rtk` は trusted CLI proxy として許可する。rtk hook rewrite 自体を false positive block してはならない。
    
    ただし `rtk` は `git` / `gh` / test runner / package manager / container / network command / `rtk proxy <command>` を包括するため、`rtk` prefix を理由に bypass allow してはならない。`local_main_branch_guard` は `rtk <inner argv...>` を wrapper envelope として認識し、inner command を既存 classifier に再帰分類する。
    
    Required diagnostics:
    
    - `wrapper: rtk`
    - `rtk_subcommand`
    - `inner_argv_redacted`
    - `inner_command_kind`
    - `matched_rule_id`
    - `decision_source: rtk_unwrap_classifier`
    - `decision: allow|block|review`
    
    `rtk gain --history` / `rtk gain --all --format json` / `rtk session` は監査・retrospective 用に利用するが、事前 guard 判定の source of truth にはしない。

    結論として、#1198 は 「rtk を許可する Issue」ではなく、「rtk を first-class wrapper として監視可能にする Issue」 に寄せるのが正しいです。これなら rtk 導入効果を維持しつつ、git switch や gh api POST が rtk 経由で guard を抜ける問題を防げます。

  3. squne121 commented on Jun 27, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-27T04:11:29Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1198
      body_sha256: "sha256:414d7b68186b059467adf0bc9f5db4bc708876268f587ac6a844798b7ea40695"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
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

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions