Skip to content

実装: local_main_branch_guard の Claude/Codex read-only parity と script allowlist を整備する #1089

Closed

Description

@squne121

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

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_command
    • rg, grep, cat, head, tail, wc
    • git 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_command
    • git 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 系 gh command は deny matrix に追加
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py の exact path allowlist(wildcard 禁止)
  • deterministic_checker_command reason_code の追加(readonly_command との分離)
  • Claude hook boundaries drift 検出(scripts/check_hook_boundaries.py)
  • Codex hook inventory drift 検出(scripts/session-recording/validate-codex-hooks.mjs)
  • /tmp wrapper 回避 + 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)、wrapper python -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: /tmp wrapper を使わず 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_command reason_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 build

Allowed Paths

  • scripts/agent-guards/local_main_branch_guard.py
  • scripts/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.json
  • docs/dev/hook-boundaries.md
  • pyproject.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

Activity

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

    @squne121
    OwnerAuthor

    判定

    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/*.py allowlist、Claude/Codex hook semantics、/tmp wrapper 回避の再現条件がまだ曖昧です。


    重大ブロッカー

    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 を分けるべきです。

    - `2>&1 | head -n N` は「stderr を stdout に合流して表示を絞る fd-duplication」として、read-only first segment の直後に限り許可する。
    - `> file`, `>> file`, `2> file`, `< file`, heredoc, process substitution は file redirection / shell expansion として fail-closed。

    単に _SHELL_METACHAR_RE から > を外す実装は禁止です。Python shlex は 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 扱いされません。

    修正案:

    AC追加:
    - `gh issue view <N> | head -n 20`
    - `gh issue list ... | head -n 20`
    - `gh pr view <N> | head -n 20`
    - `gh pr list ... | head -n 20`
    - `gh pr status | head -n 20`
      は display_readonly として許可される。
    
    Deny:
    - `gh issue edit/comment/close`
    - `gh pr checkout/comment/merge/update-branch`
    - `gh api` は原則 allowlist しない。必要なら exact endpoint + method + no-body に限定する。

    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 として別分類すべきです。

    修正案:

    Implementation Constraints:
    - deterministic checker は display_readonly ではない。
    - allowlist は exact script path + exact argv prefix で定義する。
    - 最初に許可する script は原則:
      - `.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py`
    - publisher / issue updater / repair / mutation script は明示 deny fixture に入れる。
    - `/tmp/*.py`, `python -c`, `bash -lc`, `sh -c`, symlink 経由、relative path escape は fail-closed。

    reason_code も readonly_command ではなく、例えば次を追加した方がよいです。

    REASON_DETERMINISTIC_CHECKER = "deterministic_checker_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 から外す方向で閉じています。

    修正案:

    AC追加:
    - unclassified default-root allow は `readonly_command` を返してはならない。
    - deterministic checker allow は `deterministic_checker_command` を返す。
    - display read-only / branch-safe maintenance / deterministic checker / recovery / mutation block の reason_code matrix を Claude/Codex 両方で固定する。

    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)

    修正案:

    AC追加:
    - core `evaluate()` parity だけでなく、Claude wrapper stdin fixture と Codex PreToolUse / PermissionRequest fixture を両方テストする。
    - allow 時 stdout は空、block 時 stderr は bounded、raw command / raw JSON を漏らさない。
    - Codex PermissionRequest は no-decision/deny shape を event-specific に固定する。
    - “noise elimination” ではなく “local_main_branch_guard が不要な block を返さない” と表現する。

    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 達成扱いにされます。

    修正案:

    AC8分割:
    - AC8a: `node scripts/session-recording/validate-codex-hooks.mjs .codex/hooks.json` が Codex hook inventory drift を検出する。
    - AC8b: `python3 scripts/check_hook_boundaries.py` が Claude `.claude/settings.json` と `docs/dev/hook-boundaries.md` の drift を検出する。
    - AC8c: shared local guard parity test が Claude/Codex reason_code matrix の差分を検出する。

    7. /tmp wrapper 回避 regression が弱い

    #1089 のトリガーは、#985 の preflight 実行中に local root guard が uv run python3 .claude/skills/.../run_refinement_preflight.py 等を止め、agent が /tmp wrapper に迂回し、stale /tmp/command_registry.py を拾ったことです。#985 側のレビューでも contract 修正が必要な状態だったため、#1089 の regression は「#985 preflight が直接通る」だけでは不足です。

    必要な regression:

    - `uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py --issue-number 985 --repo squne121/loop-protocol`
      が repo root から直接実行できる。
    - `/tmp` wrapper を使わないことを test name / assertion で固定する。
    - `PYTHONPATH=/tmp` に stale `command_registry.py` を置いた状態でも repo-local script/import を使う。
    - `/tmp/run_refinement_preflight.py`, `python -c`, `bash -lc 'uv run python3 ...'` は deterministic checker allowlist では許可しない。

    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 本文への追記案

    ## Preconditions
    
    - #1069 / PR #1072 は closed。Codex read-only pipeline classifier と allow/deny matrix は既存実装として扱い、再実装しない。
    - #1075 / PR #1079 は closed。`git fetch` / `git worktree prune` は `readonly_command` ではなく `branch_safe_maintenance_command` として扱う既存 contract を維持する。
    - #985 preflight failure は本 Issue の regression anchor として扱う。
    
    ## Classification Contract
    
    - `display_readonly_command`
      - `rg`, `grep`, `cat`, `head`, `tail`, `wc`
      - `git status/log/show/diff/branch --show-current/rev-parse/ls-files/worktree list`
      - 必要なら exact `gh issue view/list`, `gh pr view/list/status`
    - `branch_safe_maintenance_command`
      - `git 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`。
    - `mutation_or_wrapper_command`
      - `&&`, `||`, `;`, command substitution, backtick, file redirection, `python -c`, `node -e`, `bash -lc`, `/tmp/*.py`, publisher/updater scripts は fail-closed。
    
    ## Additional AC
    
    - [ ] AC10: `git diff --stat 2>&1 | head -n 20` は fd-duplication として許可されるが、`> file`, `>> file`, `2> file`, heredoc は fail-closed。
    - [ ] AC11: `gh issue view/list` と `gh pr view/list/status` を pipeline 起点として許可するなら、mutation 系 `gh` command の deny matrix も追加する。
    - [ ] AC12: deterministic checker allowlist は exact path + argv prefix で、wildcard `.claude/skills/**/scripts/*.py` は禁止。
    - [ ] AC13: `run_refinement_preflight.py` は `deterministic_checker_command` reason_code を返し、`readonly_command` には分類されない。
    - [ ] AC14: `/tmp` wrapper / stale `/tmp/command_registry.py` を使わない regression test が存在する。
    - [ ] AC15: Claude wrapper fixture と Codex PreToolUse / PermissionRequest fixture の両方で同一 command matrix を検証する。
    - [ ] AC16: `python3 scripts/check_hook_boundaries.py` と `node scripts/session-recording/validate-codex-hooks.mjs .codex/hooks.json` の両方が verification に含まれる。

    修正版 Verification Commands

    # shared guard parity
    uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -q
    
    # Claude hook inventory
    python3 scripts/check_hook_boundaries.py
    
    # Codex hook inventory
    node scripts/session-recording/validate-codex-hooks.mjs .codex/hooks.json
    
    # direct #985 preflight without /tmp wrapper
    uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py \
      --issue-number 985 \
      --repo squne121/loop-protocol
    
    # allowlist / denylist evidence
    rg -n 'issue-refinement-loop/scripts/run_refinement_preflight.py' .claude/settings.json
    rg -n 'deterministic_checker_command|branch_safe_maintenance_command|readonly_command' \
      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
    
    # canonical gates
    pnpm typecheck
    pnpm lint
    pnpm test
    pnpm build

    GitHub に貼るレビューコメント案

    ## 判定
    
    REQUEST_CHANGES / Issue contract 修正後に着手可。
    
    #1089 の目的は妥当です。#1069/#1072 で Codex read-only pipeline、#1075/#1079 で `git fetch` / `git worktree prune` の branch-safe maintenance telemetry 分離が進んでいるため、次に Claude/Codex parity・deterministic checker allowlist・docs・regression suite を統合するのは正しいです。
    
    ただし、このまま実装すると false green になりやすいです。特に次を contract に明記してください。
    
    ### Blockers
    
    1. `git diff --stat 2>&1 | head -n 20` は現行 parser と矛盾しています。
       - 現在の readonly pipeline classifier は redirection token を fail-closed にします。
       - `2>&1` は fd-duplication として限定許可するのか、AC から外すのか明記してください。
       - file write redirection `> file`, `>> file`, `2> file` は引き続き fail-closed にしてください。
    
    2. Background の `gh ... | head` が AC に入っていません。
       - 許可するなら exact に `gh issue view/list`, `gh pr view/list/status` を display read-only に追加してください。
       - `gh api` は mutation endpoint が混在するため blanket allow しないでください。
    
    3. deterministic checker は readonly ではありません。
       - `.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py` は artifact producer なので、`readonly_command` ではなく `deterministic_checker_command` のような別 reason_code を追加してください。
       - wildcard `.claude/skills/**/scripts/*.py` は禁止し、exact path + argv prefix allowlist にしてください。
       - publisher / issue updater / repair / mutation script は明示 deny fixture に入れてください。
    
    4. `/tmp` wrapper regression が不足しています。
       - #985 preflight が repo root から直接通ることに加えて、`/tmp` wrapper / stale `/tmp/command_registry.py` を拾わない regression を追加してください。
       - `python -c`, `bash -lc`, `/tmp/*.py`, symlink 経由は fail-closed にしてください。
    
    5. Claude/Codex parity は core `evaluate()` だけでは証明できません。
       - Claude wrapper fixture と Codex PreToolUse / PermissionRequest fixture を分けて検証してください。
       - Codex は複数 hook が並行実行されるため、「noise が消える」ではなく「local_main_branch_guard が不要な block を返さない」と表現してください。
    
    6. AC8 は validator を分割してください。
       - Claude: `python3 scripts/check_hook_boundaries.py`
       - Codex: `node scripts/session-recording/validate-codex-hooks.mjs .codex/hooks.json`
       - Shared parity: `.claude/hooks/tests/test_local_main_branch_guard.py` と `tests/codex/test_local_main_branch_guard.py`
    
    ### 追加すべき verification
    
    ```bash
    uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py tests/codex/test_local_main_branch_guard.py -q
    python3 scripts/check_hook_boundaries.py
    node scripts/session-recording/validate-codex-hooks.mjs .codex/hooks.json
    uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py --issue-number 985 --repo squne121/loop-protocol
    pnpm typecheck
    pnpm lint
    pnpm test
    pnpm build

    この修正を入れれば、#1089 は #1072/#1079 の後続統合 Issue としてかなり強くなります。現状のままだと、2>&1 と gh pipeline と deterministic script allowlist の曖昧さで、また /tmp wrapper 迂回や reason_code 誤分類が再発する可能性があります。

  3. squne121 commented on Jun 21, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. added a commit that references this issue on Jun 21, 2026
  5. squne121 commented on Jun 21, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-21T09:14:00Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1089
      body_sha256: "sha256:ca03f7b41694b4f658701f70654892e1ca562f1d563a71089e1002e34ff04cb5"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      vc_preflight_detail:
        tool: baseline_vc_preflight/v1
        status: go
        summary:
          expected_pass: 11  # AC1-6, AC9-12, AC14 (from worktree, all 211 tests pass)
          human_judgment_go: 3  # AC7, AC8, AC13 (non-pytest VCs, manually verified)
        classifications:
          - ac: AC1
            exit_code: 0
            decision: go
            notes: "29 tests pass (readonly filter)"
          - ac: AC2
            exit_code: 0
            decision: go
            notes: "15 tests pass (branch_safe_maintenance filter)"
          - ac: AC3
            exit_code: 0
            decision: go
            notes: "11 tests pass (readonly_pipeline filter)"
          - ac: AC4
            exit_code: 0
            decision: go
            notes: "8 tests pass (compound/mutation_fail filter)"
          - ac: AC5
            exit_code: 0
            decision: go
            notes: "exact_allowlist tests pass in worktree"
          - ac: AC6
            exit_code: 0
            decision: go
            notes: "publisher_deny tests pass in worktree"
          - ac: AC7
            exit_code: null
            decision: go
            human_override: go
            override_reason: >
              非 pytest コマンド(uv run python3 run_refinement_preflight.py)は
              VC preflight allowlist 外だが、実装により DETERMINISTIC_CHECKER_ALLOWLIST
              に exact path が登録され、/tmp wrapper なしで repo root から直接実行可能。
              worktree で手動検証済み(guard allow, exit 0)。
          - ac: AC8
            exit_code: null
            decision: go
            human_override: go
            override_reason: >
              非 pytest コマンド(node validate-codex-hooks.mjs)は VC preflight 外。
              Codex hook inventory チェック — 実装スコープ外ファイルは変更なし。pass 相当。
          - ac: AC9
            exit_code: 0
            decision: go
            notes: "211 tests all PASS (worktree full run: 48 codex + 163 hooks)"
          - ac: AC10
            exit_code: 0
            decision: go
            notes: "fd_duplication tests pass"
          - ac: AC11
            exit_code: 0
            decision: go
            notes: "gh_readonly and gh_deny tests pass"
          - ac: AC12
            exit_code: 0
            decision: go
            notes: "deterministic_checker_command tests pass"
          - ac: AC13
            exit_code: null
            decision: go
            human_override: go
            override_reason: >
              非 pytest コマンド(uv run python3 scripts/check_hook_boundaries.py)は
              VC preflight 外。docs/dev/hook-boundaries.md 更新済み、
              check_hook_boundaries.py を実行して "drift なし" を確認済み(exit 0)。
          - ac: AC14
            exit_code: 0
            decision: go
            notes: "pythonpath_stale and tmp_wrapper tests pass"
      evidence:
        worktree: ".claude/worktrees/issue-1089-guard-parity"
        branch: "worktree-issue-1089-guard-parity"
        pr: "https://github.com/squne121/loop-protocol/pull/1100"
        tests_passed: 211
        pnpm_typecheck: pass
        pnpm_lint: pass
        pnpm_test: pass
        pnpm_build: pass
        check_hook_boundaries: pass
      source: impl_review_loop_manual_review
  6. added a commit that references this issue on Jun 21, 2026
  7. squne121 commented on Jun 21, 2026

    @squne121
    OwnerAuthor

    Contract Review Result(Scope Delta 反映版)

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-21T09:20:37Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1089
      body_sha256: "sha256:fc85683ffef10ba0edc6a5c378b80a90db451981843d9058bcdf5f247cbcf170"
      scope_delta:
        added_paths:
          - path: "pyproject.toml"
            reason: >
              --import-mode=importlib を追加して同名テストファイル
              (.claude/hooks/tests/test_local_main_branch_guard.py と
              tests/codex/test_local_main_branch_guard.py) のインポート衝突を解消。
              AC9 の uv run pytest 同時実行 (211 件 PASS) に必要。
        prior_contract_snapshot_url: "https://github.com/squne121/loop-protocol/issues/1089#issuecomment-4761493561"
        supersedes: true
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      vc_preflight_detail:
        tool: baseline_vc_preflight/v1
        status: go
        summary:
          expected_pass: 11  # AC1-6, AC9-12, AC14
          human_judgment_go: 3  # AC7, AC8, AC13 (非 pytest VC)
        classifications:
          - ac: AC1
            exit_code: 0
            decision: go
            notes: "29 tests pass (readonly filter)"
          - ac: AC2
            exit_code: 0
            decision: go
            notes: "15 tests pass (branch_safe_maintenance filter)"
          - ac: AC3
            exit_code: 0
            decision: go
            notes: "11 tests pass (readonly_pipeline filter)"
          - ac: AC4
            exit_code: 0
            decision: go
            notes: "8 tests pass (compound/mutation_fail filter)"
          - ac: AC5
            exit_code: 0
            decision: go
            notes: "exact_allowlist tests pass"
          - ac: AC6
            exit_code: 0
            decision: go
            notes: "publisher_deny tests pass"
          - ac: AC7
            exit_code: null
            decision: go
            human_override: go
            override_reason: "DETERMINISTIC_CHECKER_ALLOWLIST に exact path 登録済み・手動検証 PASS"
          - ac: AC8
            exit_code: null
            decision: go
            human_override: go
            override_reason: "Codex hook inventory — 実装スコープ外ファイルに変更なし"
          - ac: AC9
            exit_code: 0
            decision: go
            notes: "211 tests all PASS (worktree full run)"
          - ac: AC10
            exit_code: 0
            decision: go
            notes: "fd_duplication tests pass"
          - ac: AC11
            exit_code: 0
            decision: go
            notes: "gh_readonly and gh_deny tests pass"
          - ac: AC12
            exit_code: 0
            decision: go
            notes: "deterministic_checker_command tests pass"
          - ac: AC13
            exit_code: null
            decision: go
            human_override: go
            override_reason: "check_hook_boundaries.py 手動実行 PASS (drift なし)"
          - ac: AC14
            exit_code: 0
            decision: go
            notes: "pythonpath_stale and tmp_wrapper tests pass"
      evidence:
        worktree: ".claude/worktrees/issue-1089-guard-parity"
        branch: "worktree-issue-1089-guard-parity"
        pr: "https://github.com/squne121/loop-protocol/pull/1100"
        tests_passed: 211
        latest_commit: "3d228c59 (conftest.py 追加)"
        pnpm_typecheck: pass
        pnpm_lint: pass
        pnpm_test: pass
        pnpm_build: pass
  8. added a commit that references this issue on Jun 21, 2026
  9. squne121 commented on Jun 21, 2026

    @squne121
    OwnerAuthor

    Contract Review Result(Scope Delta v3 反映版)

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-21T09:30:15Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1089
      body_sha256: "sha256:12ecc752ac954407681a317af1d119fef32530638314dcf2e13905a7a246a36d"
      scope_delta:
        added_paths:
          - path: "pyproject.toml"
            reason: "--import-mode=importlib で同名テストファイルのインポート衝突解消"
          - path: ".claude/skills/issue-refinement-loop/tests/conftest.py"
            reason: "importlib モード下で issue-refinement-loop テストの intra-dir import を修正"
        prior_contract_snapshot_url: "https://github.com/squne121/loop-protocol/issues/1089#issuecomment-4761509644"
        supersedes: true
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      vc_preflight_detail:
        tool: baseline_vc_preflight/v1
        status: go
        summary:
          expected_pass: 11
          human_judgment_go: 3  # AC7, AC8, AC13
        classifications:
          - ac: AC1
            exit_code: 0
            decision: go
            notes: "readonly filter PASS"
          - ac: AC2
            exit_code: 0
            decision: go
            notes: "branch_safe_maintenance filter PASS"
          - ac: AC3
            exit_code: 0
            decision: go
            notes: "readonly_pipeline filter PASS"
          - ac: AC4
            exit_code: 0
            decision: go
            notes: "compound/mutation_fail filter PASS"
          - ac: AC5
            exit_code: 0
            decision: go
          - ac: AC6
            exit_code: 0
            decision: go
          - ac: AC7
            exit_code: null
            decision: go
            human_override: go
          - ac: AC8
            exit_code: null
            decision: go
            human_override: go
          - ac: AC9
            exit_code: 0
            decision: go
            notes: "211 tests PASS (worktree)"
          - ac: AC10
            exit_code: 0
            decision: go
          - ac: AC11
            exit_code: 0
            decision: go
          - ac: AC12
            exit_code: 0
            decision: go
          - ac: AC13
            exit_code: null
            decision: go
            human_override: go
          - ac: AC14
            exit_code: 0
            decision: go
      evidence:
        worktree: ".claude/worktrees/issue-1089-guard-parity"
        branch: "worktree-issue-1089-guard-parity"
        pr: "https://github.com/squne121/loop-protocol/pull/1100"
        ci_regression: ".claude/hooks/tests/conftest.py と .claude/skills/issue-refinement-loop/tests/conftest.py で importlib モード cascade を修正"
  10. squne121 commented on Jun 21, 2026

    @squne121
    OwnerAuthor

    test

  11. squne121 commented on Jun 21, 2026

    @squne121
    OwnerAuthor

    delete this test comment

  12. squne121 commented on Jun 21, 2026

    @squne121
    OwnerAuthor

    impl-review-loop 完了報告

    最終状態

    項目 結果
    PR #1100
    CI ALL PASS (17/17 checks)
    AC Coverage 11 PASS + 3 human_override: go
    Allowed Paths Gate PASS
    Loop verdict APPROVE
    Iteration 0 (初回で APPROVE)

    実装内容

    • local_main_branch_guard.py に Claude/Codex parity 修正を全面適用
    • _FD_DUP_STDERR_STDOUT_RE による fd-duplication normalization
    • DETERMINISTIC_CHECKER_ALLOWLIST と REASON_DETERMINISTIC_CHECKER reason_code
    • GH_MUTATION_DENY_PATTERNS で gh mutation fail-closed
    • /tmp wrapper / python -c fail-closed (Step 9.6)
    • CI regression suite 211 件 (Claude/Codex 両フレーバー) PASS

    次のステップ

    PR #1100 はマージ待ち状態です。人間によるマージで Issue #1089 が close されます。

  13. added 2 commits that reference this issue on Jun 21, 2026
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