Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
change_kind: code
stage: 1
blocked_by: []
parent_issue: none
dedupe_key: "ops-improvement:loop-protocol:guard-parity:2026-06"Background
#985 の issue-refinement-loop 実行中、local root main 上で uv run python3 .claude/skills/.../run_refinement_preflight.py、gh ... | head、git show ... 2>&1 | head などの調査・deterministic checker 実行が unparseable_branch_mutation で遮断された。結果として agent は /tmp wrapper へ迂回し、stale /tmp/command_registry.py を拾って追加の失敗を起こした。
#1069 / #1072 と #1075 / #1079 で read-only pipeline と branch-safe maintenance の修正は進んでいるが、Claude/Codex parity、deterministic script execution、fd-duplication pipeline、gh readonly 分類の境界がまだ一体の regression suite になっていない。
Preconditions
- 実装: CodexCLI read-only Bash hook noise guard を追加する #1069 / PR fix(codex): allow readonly bash pipelines (#1069) #1072 は closed。Codex read-only pipeline classifier と allow/deny matrix は既存実装として扱い、再実装しない。
- 実装: Normalize branch-safe classifier telemetry for git fetch and git worktree prune #1075 / PR fix(guards): split branch-safe maintenance telemetry (#1075) #1079 は closed。
git fetch/git worktree pruneはreadonly_commandではなくbranch_safe_maintenance_commandとして扱う既存 contract を維持する。 - 実装: existing enemy_chaser を new taxonomy へ非破壊移行する #985 preflight failure は本 Issue の regression anchor として扱う。
Parent Issue
none
Parent Goal Ref
- Goal: Claude Code / Codex CLI の local root guard が、表示系 read-only、branch-safe maintenance、deterministic checker script、危険な wrapper/mutation を一貫して分類し、/tmp wrapper 迂回を不要にする
- Desired Destination:
uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py --issue-number 985 --repo squne121/loop-protocolが /tmp wrapper なしで通り、CI regression suite が Claude/Codex parity を保証する状態
Classification Contract
display_readonly_commandrg,grep,cat,head,tail,wcgit status/log/show/diff/branch --show-current/rev-parse/ls-files/worktree list- exact
gh issue view/list,gh pr view/list/status(単体 or pipeline 起点として許可)
branch_safe_maintenance_commandgit fetch,git worktree prune- display read-only ではない。pipeline 起点にしない。
deterministic_checker_command- exact allowlist の deterministic script のみ
- 初期対象:
.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py - wildcard
.claude/skills/**/scripts/*.pyは禁止。exact path + argv prefix で定義する。
mutation_or_wrapper_command(fail-closed)&&,||,;, command substitution, backtick- file write redirection (
>,>>,2>)、heredoc、process substitution python -c,node -e,bash -lc,/tmp/*.py, publisher/updater/repair scripts
Current Validated Scope
scripts/agent-guards/local_main_branch_guard.pyの read-only / branch-safe-maintenance / deterministic-checker / mutation 分類更新.claude/hooks/local_main_branch_guard.shおよび.codex/hooks/local_main_branch_guard.shの parity 修正.claude/hooks/tests/test_local_main_branch_guard.pyとtests/codex/test_local_main_branch_guard.pyの regression fixture 追加.claude/settings.json/.codex/hooks.jsonの exact path script allowlist 追加docs/dev/hook-boundaries.mdの分類定義更新scripts/check_hook_boundaries.pyの Claude hook drift 検出
Remaining Parent Gaps
なし(このIssue単独で完結)
Outcome
Claude Code / Codex CLI の local root guard が、display_readonly / branch_safe_maintenance / deterministic_checker / mutation を一貫して分類し、/tmp wrapper 迂回を不要にする。AC1-AC14 すべての regression fixture が PASS する状態。
In Scope
- display read-only コマンド分類の Claude/Codex parity
git fetch/git worktree pruneを branch-safe maintenance として分類- narrow pipeline (
| head、| tail、| wc -l) の許可 2>&1 | headの fd-duplication を read-only 先頭 segment 直後に限り許可(write redirection は fail-closed のまま)gh issue view/list、gh pr view/list/statusを display_readonly pipeline 起点として許可、mutation 系ghcommand は deny matrix に追加.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.pyの exact path allowlist(wildcard 禁止)deterministic_checker_commandreason_code の追加(readonly_commandとの分離)- Claude hook boundaries drift 検出(
scripts/check_hook_boundaries.py) - Codex hook inventory drift 検出(
scripts/session-recording/validate-codex-hooks.mjs) /tmpwrapper 回避 + PYTHONPATH stale regression test
Out of Scope
- hook 以外の permission システム変更
- Codex upstream の変更
- 他 skill の実装変更
gh apiの blanket allow(mutation endpoint が混在するため)
Acceptance Criteria
- AC1: display read-only コマンド(
rg、grep、cat、head、tail、wc、git status、git log、git show、git diff、git branch --show-current、git rev-parse、git ls-files、git worktree list)は Claude/Codex 両方で同一 reason_code に分類される - AC2:
git fetch/git worktree pruneはreadonly_commandではなくbranch_safe_maintenance_commandに分類される - AC3:
rg ... | head -n 20、git status --short | head -n 20はdisplay_readonly_commandとして許可される - AC4:
&&、||、;、command substitution、file write redirection(> file、>> file、2> file)、wrapperpython -c経由の mutation は fail-closed - AC5:
.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.pyは exact path + argv prefix の allowlist で許可される(wildcard.claude/skills/**/scripts/*.pyは禁止) - AC6: publisher / issue updater / mutation script は allowlist されない(明示 deny fixture が存在する)
- AC7:
/tmpwrapper を使わずrun_refinement_preflight.py --issue-number 985が repo root から直接実行できる regression test が存在する - AC8: Codex hook inventory:
node scripts/session-recording/validate-codex-hooks.mjs .codex/hooks.jsonが Codex hook drift を fail-closed で検出する - AC9:
uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -qが PASS する - AC10:
git diff --stat 2>&1 | head -n 20は fd-duplication として許可される。> file、>> file、2> file、heredoc、process substitution は fail-closed のまま維持される - AC11:
gh issue view <N>、gh issue list、gh pr view <N>、gh pr list、gh pr statusを pipeline 起点として許可する。gh issue edit/comment/close、gh pr checkout/merge/update-branchは fail-closed となる deny fixture が存在する - AC12:
run_refinement_preflight.pyはreadonly_commandではなくdeterministic_checker_commandreason_code を返す - AC13: Claude hook boundaries:
uv run python3 scripts/check_hook_boundaries.pyが.claude/settings.jsonとdocs/dev/hook-boundaries.mdの drift を fail-closed で検出する - AC14: PYTHONPATH=/tmp に stale
command_registry.pyを置いた状態でも repo-local script/import を使う regression test が存在する。python -c、bash -lc、/tmp/*.pyは fail-closed。
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- 破壊的操作・秘密情報・外部課金が必要になった場合
Required Skills
- bash/shell script parsing
- hook architecture (PreToolUse)
- Python test framework (pytest)
Verification Commands
# AC1
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -k "readonly"# AC2
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -k "branch_safe_maintenance"# AC3
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -k "readonly_pipeline"# AC4
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -k "compound or mutation_fail"# AC5
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -k "exact_allowlist"# AC6
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -k "publisher_deny or mutation_deny"# AC7
$ uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py --issue-number 985 --repo squne121/loop-protocol# AC8
$ node scripts/session-recording/validate-codex-hooks.mjs .codex/hooks.json# AC9
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -q# AC10
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -k "fd_duplication"# AC11
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -k "gh_readonly or gh_deny"# AC12
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -k "deterministic_checker_command"# AC13
$ uv run python3 scripts/check_hook_boundaries.py# AC14
$ uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -k "pythonpath_stale or tmp_wrapper"# canonical gates
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildAllowed Paths
scripts/agent-guards/local_main_branch_guard.pyscripts/check_hook_boundaries.py.claude/hooks/local_main_branch_guard.sh.codex/hooks/local_main_branch_guard.sh.claude/hooks/tests/tests/codex/scripts/session-recording/validate-codex-hooks.mjs.codex/hooks.json.claude/settings.jsondocs/dev/hook-boundaries.mdpyproject.toml.claude/skills/issue-refinement-loop/tests/conftest.py
Runtime Verification Applicability
- decision: deferred
- reason: hook 変更は実装後の pytest + 手動実行で検証
- deferred_destination: AC9 の uv run pytest PASS かつ AC7 の preflight が /tmp なしで通ること
- deferred_verification_condition: AC9 pytest が PASS し、AC7 の preflight が /tmp なしで通ること
Related Issues
- 実装: CodexCLI read-only Bash hook noise guard を追加する #1069 / PR fix(codex): allow readonly bash pipelines (#1069) #1072: Codex read-only Bash hook noise guard
- 実装: Normalize branch-safe classifier telemetry for git fetch and git worktree prune #1075 / PR fix(guards): split branch-safe maintenance telemetry (#1075) #1079: branch-safe maintenance telemetry split
- 実装: existing enemy_chaser を new taxonomy へ非破壊移行する #985: 本改善のトリガーとなった issue-refinement-loop 実行
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 21, 2026
判定
REQUEST_CHANGES / Issue contract 修正後に着手可。
#1089 の狙いは妥当です。#1069/#1072 で Codex 側の read-only pipeline classifier、#1075/#1079 で
git fetch/git worktree pruneの branch-safe maintenance telemetry 分離が進んでおり、#1089 はその後続として Claude/Codex parity・deterministic checker allowlist・docs・regression suite をまとめ直す Issue です。#1089 自体は open かつコメント 0 件なので、今の段階で contract を締める価値があります。ただし、現状の #1089 は 「必要な統合 Issue」ではあるが、このまま実装 agent に渡すと false green になりやすいです。特に
2>&1 | head、gh ... | head、.claude/skills/issue-refinement-loop/scripts/*.pyallowlist、Claude/Codex hook semantics、/tmpwrapper 回避の再現条件がまだ曖昧です。重大ブロッカー
1. AC3 の
2>&1 | headは現行 parser と矛盾している#1089 は
git diff --stat 2>&1 | head -n 20を許可対象にしていますが、現行classify_readonly_pipeline()は redirection token<,<<,<<<,>,>>を検出すると即 fail-closed です。つまり、今の実装延長では2>&1 | headは高確率でunparseable_branch_mutationのままです。ここは AC を分けるべきです。
単に
_SHELL_METACHAR_REから>を外す実装は禁止です。Pythonshlexは shell 風 tokenization には使えますが、公式 docs でも「完全な shell parser ではない」ため、独自の構文検査が必要です。([Python documentation]1)2. Background の
gh ... | headが AC に入っていない#1089 の Background は
gh ... | headがブロックされたことをトリガーに含めていますが、現行DISPLAY_READONLY_PATTERNSはrg/grep/cat/head/tail/wcと一部gitコマンドだけで、gh issue view/listやgh pr view/list/statusはis_readonly_command()に含まれていません。一方、drifted root 用 allowlist には
gh issue view/listとgh pr view/list/statusが入っています。つまり単独gh pr viewは場面によって許可され得るのに、pipeline classifier の first segment としては read-only 扱いされません。修正案:
gh apiは GET 以外・body 付き・mutation endpoint が混在するため、雑にgh api * | headを read-only に入れると危険です。3. deterministic checker allowlist が「不足」と「広すぎ」の両方を抱えている
現行
.claude/settings.jsonの Bash allow にはedit-issue、post-merge-cleanup、create-issueの skill scripts はありますが、#1089 が直接要求している.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.pyは含まれていません。一方で、#1089 の AC5 は
.claude/skills/**/scripts/*.pyのような広い allowlist に逃げると危険です。run_refinement_preflight.pyは deterministic entrypoint ではありますが、GitHub API データを集め、planner input を作り、.claude/artifacts/issue-refinement-loop/<issue_number>/に result / raw snapshot / planner input を書く script です。これは display read-only ではなく、deterministic checker / artifact producer として別分類すべきです。修正案:
reason_code も
readonly_commandではなく、例えば次を追加した方がよいです。4. 現行 guard の default allow が
readonly_commandを返す現行
evaluate()は末尾の default allow でREASON_READONLYを返しています。つまり、branch mutation として検出されず、drifted/detached でもない default root 上の unclassified command が、telemetry 上はreadonly_commandになり得ます。#1089 で
uv run python3 ...run_refinement_preflight.pyを通す場合、ここに依存して通すと「deterministic checker を readonly と誤分類する」ことになります。#1075/#1079 でgit fetchを readonly から分離した意味が薄れます。#1079 はgit fetch/git worktree pruneをbranch_safe_maintenance_commandに分け、readonly pipeline から外す方向で閉じています。修正案:
5. Claude/Codex parity は core function だけでは証明できない
local_main_branch_guard.pyは Claude と Codex の shared core と明記されています。ただし wrapper と hook event semantics は同一ではありません。Claude wrapper は
LOCAL_MAIN_BRANCH_GUARD_FLAVOR=claudeを export して Python guard に stdin を渡します。 Codex wrapper はLOCAL_MAIN_BRANCH_GUARD_FLAVOR=codexを export し、PreToolUse / PermissionRequest 両方に使われます。さらに Codex hooks は複数 matching hook が実行され、同一 event の command hooks は並行起動されます。したがって
local_main_branch_guardだけが no-op になっても、他 hook のstatusMessageや出力ノイズは消えません。([OpenAI Developers]2)Claude Code 側も PreToolUse の decision / exit code contract があり、exit 2 は block 扱いです。Codex 側の PreToolUse / PermissionRequest では event-specific JSON shape や deny/no-decision の扱いが別に存在します。([Claude API Docs]3) ([Claude API Docs]3) ([OpenAI Developers]2) ([OpenAI Developers]2)
修正案:
6. AC8 の hook inventory validator が曖昧
Codex 側には
validate-codex-hooks.mjsがあり、現在の.codex/hooks.jsonに対してPreToolUse ^Bash$の 3 hooks とPermissionRequest ^Bash$の 2 hooks を exact に検証しています。Claude 側は
docs/dev/hook-boundaries.mdが.claude/settings.jsonの hook boundary SSOT で、scripts/check_hook_boundaries.pyが drift を検出する設計です。#1089 の AC8 は「Claude/Codex hook inventory validator が drift を検出する」と書いていますが、現状は Codex validator と Claude hook-boundaries validator が別物です。ここを曖昧にすると、どちらか一方だけ直して AC8 達成扱いにされます。
修正案:
7.
/tmpwrapper 回避 regression が弱い#1089 のトリガーは、#985 の preflight 実行中に local root guard が
uv run python3 .claude/skills/.../run_refinement_preflight.py等を止め、agent が/tmpwrapper に迂回し、stale/tmp/command_registry.pyを拾ったことです。#985 側のレビューでも contract 修正が必要な状態だったため、#1089 の regression は「#985 preflight が直接通る」だけでは不足です。必要な regression:
WEB調査からの設計補正
git fetchは.git/FETCH_HEADを書き、refspec により local refs を更新し得ます。tag prune などもあり、read-only ではありません。([Git]4)git worktree pruneも$GIT_DIR/worktrees配下の stale administrative files を削除する command です。([Git]5)したがって #1079 の
branch_safe_maintenance_command分離は正しいです。#1089 ではこの分類を再びreadonly_commandに畳み込まないことを強く固定すべきです。また、Codex hooks は公式 docs 上も guardrail であり、完全な shell enforcement boundary ではありません。
PreToolUseがすべての shell call を捕捉するわけではなく、非 shell / 非 MCP の経路は別です。([OpenAI Developers]2)そのため #1089 の安全主張は「完全な permission system」ではなく、local root guard の deterministic false block / false allow を減らす regression suite に限定するのが正確です。
Issue 本文への追記案
修正版 Verification Commands
GitHub に貼るレビューコメント案
この修正を入れれば、#1089 は #1072/#1079 の後続統合 Issue としてかなり強くなります。現状のままだと、
2>&1とgh pipelineと deterministic script allowlist の曖昧さで、また/tmpwrapper 迂回や reason_code 誤分類が再発する可能性があります。squne121 commentedon Jun 21, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedfix(#1089): rename test methods to match VC k-filters (fd_duplication…
squne121 commentedon Jun 21, 2026
Contract Review Result
fix(#1089): add conftest.py to restore sys.path in importlib mode
squne121 commentedon Jun 21, 2026
Contract Review Result(Scope Delta 反映版)
fix(#1089): add conftest.py to refinement-loop tests for importlib mode
squne121 commentedon Jun 21, 2026
Contract Review Result(Scope Delta v3 反映版)
squne121 commentedon Jun 21, 2026
test
squne121 commentedon Jun 21, 2026
delete this test comment
squne121 commentedon Jun 21, 2026
impl-review-loop 完了報告
最終状態
実装内容
local_main_branch_guard.pyに Claude/Codex parity 修正を全面適用_FD_DUP_STDERR_STDOUT_REによる fd-duplication normalizationDETERMINISTIC_CHECKER_ALLOWLISTとREASON_DETERMINISTIC_CHECKERreason_codeGH_MUTATION_DENY_PATTERNSで gh mutation fail-closed/tmp wrapper/python -cfail-closed (Step 9.6)次のステップ
PR #1100 はマージ待ち状態です。人間によるマージで Issue #1089 が close されます。
fix(#1089): gh mutation allowlist-closed + project tmp policy tests +…
feat(#1089): guard-parity — fd-dup, gh readonly/deny, deterministic_c…