Repository navigation
Description
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: mixedParent 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・rtkwrapper・限定された 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 allowgh 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/...は innergh 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/4814545233gh api --method GET repos/squne121/loop-protocol/issues/comments/4814545233gh issue view 1170 --repo squne121/loop-protocol --json title,body,url,labelsecho "https://github.com/squne121/loop-protocol/issues/1170#issuecomment-4814071263"Allow: rtk wrapper read-only / approved envelope
rtk --helprtk gain --historyrtk gh issue view 1170 --repo squne121/loop-protocolrtk gh issue edit 1170 --repo squne121/loop-protocol --body-file tmp/issue_1170_body.mdBlock: actual branch mutation / destructive GitHub ops / unsafe wrapper payload
git checkout feature/foogit switch feature/foogit branch -M maingit reset --hard HEAD~1git checkout -b issue-1198git switch -c issue-1198gh pr checkout 123gh pr merge 123 --delete-branchgh api repos/squne121/loop-protocol/issues/1198/comments -f body='x'gh api --method PATCH repos/squne121/loop-protocol/issues/comments/4814545233rtk gh api -f body='x' repos/squne121/loop-protocol/issues/1198/commentsrtk proxy bash -lc 'git switch issue-1198'rtk unknown-subcommandVerification 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 buildImplementation Notes
-
local_main_branch_guardshould 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 として扱うが、rtkprefix を理由に bypass allow してはならない。rtk --help/rtk gain/rtk sessionは専用 rule で allowrtk gh issue edit ...は unwrap して innergh issue editclassifier に委譲rtk gh api ...は unwrap して exact GET allowlist に合う場合のみ allowrtk proxy <command>は inner command を安全に構造解析できる場合のみ許可し、解析不能ならrtk_proxy_requires_reviewなどで fail-close
-
GitHub metadata operations should be separated from local checkout mutation:
gh issue view: allowgh api repos/.../issues/comments/<id>GET: allowgh 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 pathAllowed Paths
.claude/hooks/**.codex/**scripts/**tools/**tests/**docs/dev/**package.jsonpnpm-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
Activity
squne121 commentedon Jun 27, 2026
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 apiblanket 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 は次のように絞るべきです。
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 を外して innergh 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 は#を含んでいません。また Pythonshlex.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:
B4.
rtkwrapper の trust boundary が未定義#1198 は
rtk --helpとrtk gh issue edit ...を allow したいように読めますが、rtkが何者か、repo-local script なのか、PATH 上の executable なのか、shell alias なのか、どの subcommand が安全かが定義されていません。現行の主要分類順を見る限り、rtkを innerghとして構造的に分類する段はなく、未知 command は最後に allow されてreadonly_command扱いになります。これは telemetry と policy の両方で悪いです。修正方針:
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 createは current branch が未 push の場合に push/fork 先を尋ね得るため、remote metadata 操作として雑に allow してはいけません。(GitHub CLI)#1198 の修正版スコープ案
この Issue は次の 1 PR に絞ると安全です。
追加すべき AC
最終結論
#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 するのではなく、rtkenvelope を監視・分類するべきです。rtk README でも hook-based agents がgit statusなどをrtk git statusに rewrite すると説明され、対応コマンドには Git mutation や GitHub CLI、rtk proxy <command>が含まれます。(GitHub) (GitHub) (GitHub)#1198 に入れるべき設計変更
rtk allowedは以下の意味に限定するのが安全です。つまり:
追加 AC 案
rtk には
rtk gain --history、rtk gain --all --format json、rtk sessionがあり、採用状況や履歴を確認できます。ただしこれは事後分析用です。実行前の safety gate はlocal_main_branch_guard側でrtkを unwrap して判定する必要があります。(GitHub)Issue 本文への差し替え文
結論として、#1198 は 「rtk を許可する Issue」ではなく、「rtk を first-class wrapper として監視可能にする Issue」 に寄せるのが正しいです。これなら rtk 導入効果を維持しつつ、
git switchやgh api POSTがrtk経由で guard を抜ける問題を防げます。squne121 commentedon Jun 27, 2026
Contract Review Result
fix(hooks): restore issue #1198 implementation diff for PR #1212
Trim PR #1212 to #1198 scope only
fix(hooks): local_main_branch_guard false-positive mitigation for issue