Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "impl-review-loop preparation の scope-rollup preflight を、canonical root(worktree 作成前)から実行される exact skill runtime executor(scope_rollup.run)と executor-owned private artifact lifecycle に集約し、raw shell `gh ... > /tmp/...` を安全な代替なしに許可しないようにする"
change_kind: workflow
preflight_scope: implementation
runtime_verification_applicability: immediate
baseline_expect: failParent Issue
none(単独改善)
Parent Goal Ref
- Goal: scope-rollup preflight の read-only GitHub inventory export を、fail-closed 境界を維持したまま完走可能にする。
- Desired Destination:
scope_rollup.runという exact command ID がcommand_registry.py/skill_runtime_command_policy.pyに登録され、local_main_branch_guard.pyはこの exact invocation のみを許可し、raw shell redirect は引き続き block する。
Current Validated Scope
scope_rollup.runexact command ID を.claude/skills/issue-refinement-loop/scripts/command_registry.pyとscripts/agent-guards/skill_runtime_command_policy.pyに登録する。run_scope_rollup_preflight.py(新規)が GitHub read-only inventory 取得・pagination 完走判定・SHA256/count 計算・planner 呼び出し・result finalize を、shell redirect を使わず単一 transaction として実行する。local_main_branch_guard.pyはscope_rollup.runの exact invocation のみを canonical root context で allow し、rawgh ... > /tmp/...を含む shell redirect は引き続き block する。- executor-owned private invocation directory(mode
0700)内でO_CREAT | O_EXCL | O_NOFOLLOWかつ mode0600の排他生成・atomic rename・fsync・cleanup を実装する。
Remaining Parent Gaps
- Codex
SubagentStopの capture provenance 復旧は 実装: Codex の SubagentStop scope-rollup capture を復旧する #1527 が所有する(本 Issue では変更しない)。 - scope-rollup の候補分類ロジック、capture sidecar schema、impl-review-loop preparation の Step 順序自体は本 Issue で変更しない。
#1543(allowed-paths review gate の path-argument false positive、同じlocal_main_branch_guard.pyを対象)との rebase /順序調整は実装着手前に確認する(Scope Collision Evidence 参照)。
背景(reframe 理由)
本 Issue は当初「local_main_branch_guard.py に absolute /tmp redirect の狭い例外を追加する」方式を提案していたが、OWNER anchor comment(#1547 のレビューコメント、REQUEST_CHANGES — reframe_in_place)で以下のマージブロッカーが指摘され、issue-refinement-loop の investigation でも事実確認済みである。
- 実行コンテキストの前提誤り: 本 Issue は「linked issue worktree 内で block される」ことを前提にしていたが、
impl-review-loopの現行 preparation 契約では scope-rollup preflight は worktree 作成前(canonical root checkout)に実行される。local_main_branch_guard.pyは cwd が primary root でない場合、artifact-export classifier に到達する前にlinked_issue_worktree_context/not_local_rootとして allow を返す。したがって旧 AC3 の「linked issue worktree fixture で AC1/AC2 を検証する」は変更対象の classifier を検証しない。 - 後続コマンドの再ブロック:
gh issue view/gh issue list/gh pr listの3コマンドを許可しても、直後のpython -cwrapper・$()command substitution・<input redirect・planner の> result.json 2>&1が同じ compound 検出ロジックで再ブロックされる。障害を解消せず停止位置を移動するだけになる。 - shell
>の安全性欠如: shell の>は destination を実行前に create/truncate するため、GitHub 側が read-only でもローカル filesystem には mutation が発生する。O_EXCL/O_NOFOLLOW/0o600保護がなく、既存ファイルの truncate・symlink・並行 invocation の競合を防げない。 - 既存アーキテクチャからの逸脱: このリポジトリには既に
command_registry.py/skill_runtime_command_policy.py/skill_runtime_exec.pyによる argv ベース exact executor(shell=False、redirection/substitution/compound operator 拒否)の設計がある。rawgh ... > /tmp/...を許可する第2の実行レーンを追加することは、この既存 SSOT と整合しない。
これらを受け、本 Issue は raw shell redirect の部分許可ではなく、scope_rollup.run exact executor + executor-owned private artifact lifecycle への集約に reframe する。
Outcome
canonical root(worktree 作成前のコンテキスト)から scope_rollup.run という exact command ID の invocation だけを local_main_branch_guard.py / skill_runtime_command_policy.py が許可し、raw gh ... > /tmp/... を含む任意の shell redirect・wrapper・GitHub mutation・非 trusted repo・path traversal は引き続き fail-close にする状態。scope_rollup.run executor は trusted repo / host / gh binary / argv / env を拘束し、GitHub read-only inventory(gh issue view / gh issue list / gh pr list)を pagination・timeout・byte cap 付きで取得し、executor-owned private invocation directory(mode 0700)内に排他的・原子的に生成した result JSON(mode 0600)を返し、success / failure / timeout のすべての経路で cleanup し、host・repo・issue number・invocation ID・gh realpath・version・query schema version・page count・item count・truncated: false・fetched timestamp・body SHA256・planner script SHA256 を記録した manifest を残す。
In Scope
scope_rollup.runexact command ID を.claude/skills/issue-refinement-loop/scripts/command_registry.pyとscripts/agent-guards/skill_runtime_command_policy.pyに登録し、command ID・issue number・trusted repository・canonical root cwd・default branch・script realpath・argv shape の完全一致を要求する。run_scope_rollup_preflight.py(新規):gh issue view/gh issue list/gh pr listの GitHub read-only inventory 取得、pagination 完走判定、SHA256/count 計算、planner 呼び出し、result finalize を、shell redirect を一切使わず単一の Python transaction として実行する。- executor-owned private invocation directory(
tempfile.mkdtemp()相当、mode0700)内に、O_CREAT | O_EXCL | O_NOFOLLOWかつ mode0600で.partファイルを作成し、同一 directory 内 atomic rename + flush + fsync で確定する。 ghの trusted binary absolute realpath・github.comhost 拘束、およびGH_HOST/GH_REPO/GH_FORCE_TTY/GH_PAGER/PAGER/GH_CONFIG_DIR/GH_DEBUG/GH_PATH/GH_PROMPT_DISABLEDの sanitize。- GitHub pagination(
hasNextPage/truncated/ page count / server-side total count)、timeout、最大ページ数、最大 item 数、最大 byte 数の実装と、未完走時のtruncated: truefail-close。 local_main_branch_guard.pyに、scope_rollup.runの exact invocation のみを canonical root context で allow する分岐を追加する(raw shell redirect 用の例外は追加しない)。- linked issue worktree context では、classifier に到達せず context routing(
linked_issue_worktree_context/not_local_root)が先に発生することを検証する回帰テストを追加する。 - 実 hook evaluator(Claude / Codex 双方の wrapper)を subprocess で実行し、allow/block と reason code を検証する regression test を追加する。
docs/dev/hook-boundaries.mdにscope_rollup.runexact executor の command / destination / safety boundary を明記する。.claude/agents/scope-rollup-runner.mdと.claude/skills/impl-review-loop/steps/preparation.mdを、新しい呼び出し形式(uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id scope_rollup.run ...)に整合させる。
producer/consumer 契約統一(PR #1560 OWNER レビュー fix_delta、実装フェーズで追記。Outcome/AC 自体は変更しない内部実装詳細):
run_scope_rollup_preflight.pyの CLI に--invocation-id/--requested-atを必須引数として追加し、呼び出し元(scope-rollup-runnerStep 1)が生成した値をそのまま使う(executor が独自に UUID / timestamp を生成しない)。local_main_branch_guard.py/skill_runtime_command_policy.pyの exact-match 判定も 8 token から 12 token 固定形状へ更新する。result_sha256の意味を「plan payload(self_validationを除いた plan 全体、candidates を含む)の canonical JSON エンコード(ensure_ascii=False, sort_keys=True, separators=(",", ":")) の sha256」に一意に固定する(producer/consumer で意味を統一)。raw_plan_locationはnull固定のまま維持しつつ、ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1.result.payloadに candidates を含む plan payload 全体を直接埋め込み、.claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py(consumer)がファイルを介さずにresult_sha256を独立再計算・検証できるようにする。run_scope_rollup_preflight.pyは planner(plan_issue_scope_rollup.py)の stdout を bounded streaming で in-memory capture し JSON parse する(--outputfile を使わない)。verify_scope_rollup_result.pyに in-memory 検証用のverify_payload()を追加し、executor と consumer(parser)の両方がファイルを介さず in-process で検証できるようにする。- executor-owned private invocation directory の排他 finalize を
os.rename(既存 destination を静かに置換しうる)からos.link()ベースの exclusive finalize(destination 存在時に必ず失敗)へ変更する。 ghtrusted binary 解決を固定 sanitized search dirs(/usr/bin,/usr/local/bin,/opt/homebrew/bin,/bin)からの realpath 解決 + owner 権限 + ancestor directory の world/group-writable(sticky bit なし)検査に強化する(PATH shadowing 対策)。- GitHub pagination の実測
page_count(ceil(item_count / 100))記録、およびgh api graphqlによる server-sidetotalCount独立クロスチェックを追加する。 - PR の
filesconnection がfiles(first: 100)に固定される問題(101 件目以降のファイルで overlap を見逃す false negative)に対し、changedFilesがフェッチ済みfiles件数を上回る PR についてのみgh api graphqlでその PR の files connection を cursor pagination し、完走できなければ transaction 全体を fail-close する。 - private invocation directory の cleanup 失敗(
shutil.rmtree例外・削除後もパスが残存)をignore_errors=Trueで握りつぶさず、cleanup_failedとして transaction failure に変換する。 ghsubprocess の stdout/stderr を bounded streaming で読み、上限超過時に process group を kill する(従来のsubprocess.run(capture_output=True)によるバッファ後検査から変更)。
Out of Scope
- raw shell
gh ... > /tmp/...を許可する compound-exception 方式(旧設計。今回明示的に採用しない)。 - generic な absolute
/tmpredirect の一般許可、repo 内tmp/allowlist の緩和、任意のgh api/gh issue/gh prcommand の許可。 >>、pipe、&&、;、command substitution、wrapper、environment override、path traversal の許可。- scope-rollup の候補分類ロジック、SubagentStop capture、capture sidecar schema、impl-review-loop preparation の Step 順序自体の変更。
- GitHub token・権限・hook registration・worktree layout の変更。
- Issue 本文タイトルの変更(
edit-issuev1 は controlled title executor を持たないため本 Issue では扱わない)。 skill_runtime_exec.pyを単一 registry SSOT としてscope_rollup.runを統合すること(PR 実装: scope-rollup の absolute tmp artifact export を local guard で許可する (Closes #1547) #1560 レビューで follow-up として指摘。直近で大規模変更が入ったばかりの既存ファイルへの再設計を要するため、本 Issue のスコープには含めない)。
Acceptance Criteria
- AC1: canonical root(worktree 作成前)context からの
scope_rollup.runexact invocation(正しい command ID・issue number・trusted repository・cwd・branch・script realpath・argv shape)のみがlocal_main_branch_guard.py/skill_runtime_command_policy.pyで allow され、rawgh ... > /tmp/...は引き続き block されることを、実 hook evaluator を subprocess 起動して検証する。 - AC2: unknown flag、duplicate flag、
--flag=value形式、URL operand、wrapper、環境変数 prefix、shell metacharacter、非 trusted repository、trustedghbinary 以外、GH_HOST/GH_REPO/GH_FORCE_TTY/ pager / debug / config / prompt 系 env の注入はすべて fail-close になることを実 hook evaluator で検証する。 - AC3: linked issue worktree fixture(
cwdが primary root ではない状態を固定した hook input)では、scope_rollup.runclassifier に到達せず context routing(linked_issue_worktree_context/not_local_root)が先に発生することを実 hook evaluator で検証する。既存のtmp/relative export policy を緩和しない。 - AC4:
run_scope_rollup_preflight.pyは GitHub inventory(gh issue view/gh issue list/gh pr list)の pagination を最後まで追い、hasNextPage=falseを確認できない場合はtruncated: trueとして fail-close することを、ページ超過を模した fixture で検証する。 - AC5:
run_scope_rollup_preflight.pyは output path を caller から受け取らず、executor-owned private invocation directory(mode0700)内にO_CREAT | O_EXCL | O_NOFOLLOWかつ mode0600で.partファイルを作成し、同一 directory 内 atomic rename + flush + fsync で確定することを、pre-existing file・symlink destination・並行 invocation 衝突の各 fixture で検証する。 - AC6:
run_scope_rollup_preflight.pyは success / failure(ghnonzero、malformed JSON)/ 実行時間超過のすべての経路で private artifact を cleanup し、残骸を残さないことを検証する。 - AC7: result manifest に host・repo・issue number・invocation ID・
ghrealpath・version・query schema version・page count・item count・truncated: false・fetched timestamp・body SHA256・planner script SHA256 が記録されることを検証する。 - AC8: planner の stdout/stderr が分離され、stderr warning が result JSON 本文へ混入しないことを検証する。
- AC9:
docs/dev/hook-boundaries.mdはscope_rollup.runexact executor の command / destination / safety boundary を明記する。
Runtime Verification Applicability
decision: immediate
reason: "問題は PreToolUse hook の command classification と executor の実 filesystem side effect にあるため、pure helper だけでなく hook evaluator と run_scope_rollup_preflight.py を subprocess で実行して allow/block reason・artifact lifecycle を確認する必要がある"
applicable_acs: [AC1, AC2, AC3, AC4, AC5, AC6, AC7, AC8]
execution_environment: "WSL2 Ubuntu 24.04、uv locked Python environment、temporary git worktree fixture、実 gh CLI stub"
skip_conditions: "uv または git が利用不能で hook evaluator / executor test を実行できない場合のみ。SKIP 理由と未検証 AC を記録し、PASS と扱わない"
fallback_policy: "manual main capture、generic `/tmp` exception、または static regex assertion だけを runtime PASS と扱わない"
artifact_requirements:
- "pytest の allow/block result と reason code"
- "private invocation directory の mode / 排他生成 / cleanup を確認した subprocess 実行ログ"
- "PR 本文の Runtime Verification Evidence に command class、reject variants、cleanup 経路の要約"Verification Commands
# AC1
# baseline-expect: fail
$ uv run --locked pytest tests/codex/test_scope_rollup_run_exact_executor.py::test_canonical_root_scope_rollup_run_is_allowed -q
# AC2
# baseline-expect: fail
$ uv run --locked pytest tests/codex/test_scope_rollup_run_exact_executor.py::test_scope_rollup_run_rejects_unsafe_variants -q
# AC3
# baseline-expect: fail
$ uv run --locked pytest tests/codex/test_scope_rollup_run_exact_executor.py::test_linked_worktree_context_precedes_classifier -q
# AC4
# baseline-expect: fail
$ uv run --locked pytest tests/codex/test_run_scope_rollup_preflight.py::test_pagination_truncation_fails_closed -q
# AC5
# baseline-expect: fail
$ uv run --locked pytest tests/codex/test_run_scope_rollup_preflight.py::test_private_artifact_exclusive_atomic_write -q
# AC6
# baseline-expect: fail
$ uv run --locked pytest tests/codex/test_run_scope_rollup_preflight.py::test_cleanup_across_all_exit_paths -q
# AC7
# baseline-expect: fail
$ uv run --locked pytest tests/codex/test_run_scope_rollup_preflight.py::test_manifest_fields_recorded -q
# AC8
# baseline-expect: fail
$ uv run --locked pytest tests/codex/test_run_scope_rollup_preflight.py::test_stdout_stderr_separation -q
# AC9
$ rg -n "scope_rollup.run" docs/dev/hook-boundaries.mdAllowed Paths
scripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/skill_runtime_command_policy.pyscripts/agent-guards/run_scope_rollup_preflight.py(新規).claude/skills/issue-refinement-loop/scripts/command_registry.pytests/codex/test_scope_rollup_run_exact_executor.py(新規)tests/codex/test_run_scope_rollup_preflight.py(新規)docs/dev/hook-boundaries.md.claude/agents/scope-rollup-runner.md.claude/skills/impl-review-loop/steps/preparation.md.github/ci/python-test-plan.json.claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py(PR 実装: scope-rollup の absolute tmp artifact export を local guard で許可する (Closes #1547) #1560 fix_delta で追加).claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.py(PR 実装: scope-rollup の absolute tmp artifact export を local guard で許可する (Closes #1547) #1560 fix_delta で追加).claude/skills/issue-refinement-loop/scripts/verify_scope_rollup_result.py(PR 実装: scope-rollup の absolute tmp artifact export を local guard で許可する (Closes #1547) #1560 fix_delta で追加)
Allowed Paths を旧案の3ファイルから拡張した理由: OWNER anchor comment の P0-2/P0-4 が指摘する通り、raw gh redirect の部分許可だけでは compound wrapper が後続コマンドで再ブロックされ、Outcome を達成できない。安全な transaction 化には exact command registry / runtime policy への登録、新規 executor script、および scope-rollup-runner.md / impl-review-loop/steps/preparation.md の呼び出し形式整合が不可欠であるため、Allowed Paths をこれらのファイルまで拡張する。過度な拡張(capture sidecar schema、impl-review-loop の Step 順序自体、candidate 分類ロジック)は Out of Scope に据え置き、必要になった場合は Stop Conditions に従い別 Issue に分離する。
さらに、実装フェーズの fix_delta 対応で .github/ci/python-test-plan.json を10件目の Allowed Paths として追加した。理由: 新規追加した2つの codex テストファイル(tests/codex/test_scope_rollup_run_exact_executor.py / tests/codex/test_run_scope_rollup_preflight.py、いずれも既存 Allowed Paths 内)を CI の実行対象として登録するために技術的に必須だった。この登録を行わないと node-backed-hook-tests job の uncovered_changed_test_files gate が fail し、新規追加テストが CI で一切実行されない状態になる。したがってこの追加は CI 実行網羅性を担保するための必須拡張であり、pr-reviewer からの REQUEST_CHANGES を受けて人間判断により承認された。
11〜13件目として、PR #1560 に対する OWNER の REQUEST_CHANGES(issuecomment-5008950312)P0-1 の producer/consumer 契約統一対応で3ファイルを追加した。理由: 契約統一(invocation_id/requested_at の echo・result_sha256 の意味統一・raw_plan_location: null に伴う consumer 側の payload-based 検証への移行)は run_scope_rollup_preflight.py(executor / producer)だけでなく、.claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py(consumer / parser)と .claude/skills/issue-refinement-loop/scripts/verify_scope_rollup_result.py(in-memory 検証を追加する verifier)の同時変更が技術的に不可欠であり、これらを変更せずに producer 側だけを直しても契約不整合(Step 3 へ進めない状態)が解消しないため。人間判断により承認された。
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 許可する command class、trusted repository、または destination filename policy の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- generic
/tmpredirect、wrapper、または GitHub mutation を許可しなければ Outcome を満たせない場合 - scope-rollup の候補分類ロジック、SubagentStop capture、capture sidecar schema、または impl-review-loop preparation の Step 順序自体の変更が必要になった場合
Required Skills
- Python
- Hook policy
- pytest
Required Design References
docs/dev/hook-boundaries.md#local_main_branch_guard.sh の fail-closed 維持方針docs/dev/workflow.md#Worktree 配置規約.claude/agents/scope-rollup-runner.md.claude/skills/impl-review-loop/steps/preparation.mdscripts/agent-guards/skill_runtime_command_policy.py(既存 exact executor パターンの参照実装).claude/skills/issue-refinement-loop/scripts/command_registry.py(既存 command registry パターンの参照実装)
Scope Delta(任意)
本 Issue の reframe により Allowed Paths を旧3ファイルから9ファイルへ拡張した。理由と根拠は上記「Allowed Paths」節末尾に明記した通り、OWNER anchor comment(issuecomment-5001943581)が指摘するマージブロッカー(P0-1〜P0-4)を解消するために必須の拡張である。
10件目として、実装フェーズの fix_delta 対応で .github/ci/python-test-plan.json を Allowed Paths に追加した。理由: 新規追加した2つの codex テストファイル(tests/codex/test_scope_rollup_run_exact_executor.py / tests/codex/test_run_scope_rollup_preflight.py、いずれも既存 Allowed Paths 内)を CI 実行対象として登録するために技術的に必須だった(登録しないと node-backed-hook-tests job の uncovered_changed_test_files gate が fail し、新規テストが CI で一切実行されない)。既存9ファイルの Scope Delta 記述は変更せず、この10件目を追記する形で維持する。
11〜13件目として、PR #1560 OWNER REQUEST_CHANGES 対応(producer/consumer 契約統一)で .claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py / .claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.py / .claude/skills/issue-refinement-loop/scripts/verify_scope_rollup_result.py を Allowed Paths に追加した。理由は上記「Allowed Paths」節末尾に明記の通り、producer 側の変更だけでは consumer 側の契約不整合が解消しないため。
Scope Collision Evidence
issue_overlap_preflight:
decision: overlap_requires_comment
policy_class: C1
related_issues: [1543, 1536, 1432, 1429]
overlapping_paths:
- scripts/agent-guards/local_main_branch_guard.py
- docs/dev/hook-boundaries.md
non_conflict_reason: "#1543 は allowed-paths review gate の path-argument false positive、#1536 は gh pr review publish lane、#1432 は session manifest diagnostics、#1429 は update-branch mutation laneを扱う。本 Issue は scope-rollup-runner に必要な read-only GitHub inventory を scope_rollup.run という単一 exact command 経由でのみ取得可能にする点に限定し、command class と destination をこの exact executor 一本に固定する。"
dependency_ordering: "#1543 は同じ local_main_branch_guard.py の tokenized argv 判定を扱うため、本 Issue の実装着手前に #1543 の状態を確認し、同一 classifier ロジックを並行編集しないよう rebase または順序調整する。PR 作成直前に overlap preflight を再実行し、drift または semantic overlap が出た場合は停止する。"Delivery Rule
- 1 Issue = 1 PR
- 作業前に fresh
CONTRACT_REVIEW_RESULT_V1 status: goを取得する。 - scope-rollup の read-only inventory export を
scope_rollup.runexact executor に集約する以外の guard policy は変更しない。
Activity
squne121 commentedon Jul 17, 2026
判定
REQUEST_CHANGES —
reframe_in_place。現状の #1547 は No-Go です。提案されている「
local_main_branch_guard.pyに absolute/tmpredirect の狭い例外を追加する」方式には、次のマージブロッカーがあります。問題が発生する実行コンテキストの前提が、現行 workflow と guard の制御フローに矛盾している
3つの
gh ... > /tmp/...を許可しても、直後のコマンドで再度停止するshell の
>による共有/tmp書き込みを「read-only」と扱っており、既存ファイルの切り詰め・競合を防げないリポジトリ内に既に存在する exact executor / command registry の安全設計に逆行する
現在の Allowed Paths では、workflow をエンドツーエンドで修正できない
対象 Issue は、linked issue worktree 内で scope-rollup inventory を
/tmp/scope_rollup_*.jsonに保存することを目的とし、guard、専用テスト、hook-boundaries 文書の3ファイルだけを変更対象にしています。現時点でコメントは0件です。マージブロッカー
P0-1. 実行コンテキストの前提が成立しておらず、AC3 は classifier を検証しない
#1547 は「linked issue worktree で block される」と記述しています。しかし
impl-review-loopの現行 preparation 契約では、scope-rollup preflight はworktree 作成前に実行されます。したがって canonical な実行場所は root checkout です。さらに
local_main_branch_guard.pyは、cwd が primary root でなければ、コマンド分類より先にlinked_issue_worktree_contextまたはnot_local_rootとして allow を返します。artifact-export classifier には到達しません。したがって、AC3 の「linked issue worktree fixture で AC1/AC2 の allow/block と reason code を検証する」は無効です。
safe command も unsafe command も、この classifier より前の context check で終了する
別の worktree guard が拒否する可能性はあるが、実装: scope-rollup の absolute tmp artifact export を local guard で許可する #1547 が変更する classifier の正当性は証明されない
実測された
compound_wrapper_blockedは、実際の hook payload の cwd が root だった、あるいは「linked worktree を指定したつもりでも Bash tool 自体は root から実行された」可能性が高い、というのがコードからの推論です必要な修正
再現 fixture には少なくとも以下を固定してください。
hook input の
cwdCLAUDE_PROJECT_DIRprimary worktree path
git rev-parse --show-toplevelhook flavor
実際に evaluator へ渡された command
composite hook 中のどの guard が reason code を返したか
テストは次の2系統に分離すべきです。
canonical root / pre-worktree context で exact executor の allow/block を検証
linked worktree contextでは、classifier に入らず context decision になることだけを検証
P0-2. 3つの export を許可しても、scope-rollup は完走しない
scope-rollup-runnerは最初に次の3件を raw shell redirect で取得します。gh issue viewgh issue listgh pr listその後、以下を実行します。
uv run python3 -c "import ...; ..."による SHA256 計算$()による command substitution< fileによる入力 redirectplanner 出力の
> result.json 2>&1つまり #1547 が許可しようとしている3コマンド以外にも、同じ root-context guard が拒否する shell metacharacter が残っています。
現行 guard は
;、$()、<、>、wrapper 等を compound command として fail-close します。artifact-export 例外は compound 判定より前にあるため、今回追加する3パターンだけが例外化されます。結果として、実装後の挙動は次になります。
さらに
> result.json 2>&1は planner の stderr を JSON 本文へ混入させます。exit 0 または exit 2 でも warning が1行出れば、結果ファイルは valid JSON ではなくなります。結論
#1547 は障害を解消せず、停止位置を後方へ移動するだけです。
正しい変更には少なくとも以下が必要ですが、すべて現在の Allowed Paths 外です。
.claude/agents/scope-rollup-runner.md.claude/skills/impl-review-loop/steps/preparation.mdscope-rollup transaction を実装する新規 wrapper
command registry / exact runtime policy
end-to-end integration test
したがって、現在の Allowed Paths と Stop Conditions のままでは Outcome を満たせません。
P0-3.
ghが read-only でも、shell>は破壊的ローカル書き込みBash はコマンド本体を実行する前に redirect を処理します。
>の destination が存在しなければ作成し、存在すればゼロ長へ切り詰めます。つまり、repo・host・GitHub 認証・gh実行自体の検証より先にローカル side effect が発生します。 (GNU)したがって、次の表現は正しくありません。
正確には次です。
現行 preparation の invocation ID は
date -u ...と PID の組み合わせです。一方 runner の入力契約は UUID または ISO8601+乱数を要求しており、契約と producer の生成方式も一致していません。flat な共有
/tmpと shell>の組み合わせでは、少なくとも以下が未制御です。stale regular file の上書き
pre-created path との競合
symlink destination
concurrent invocation の衝突
gh失敗時の空または部分ファイルmode が umask 依存
cleanup 不在
planner stderr の JSON 混入
同じリポジトリの
capture_scope_rollup_final_response.pyは、既にO_EXCL、O_NOFOLLOW、0600、flush、fsyncを用いた安全な生成方式を実装しています。#1547 の shell>は、この既存基準より明確に弱い実装です。Python 標準の
tempfile.mkstemp()/mkdtemp()も、ランダム名、排他的生成、作成ユーザーのみのアクセスを提供しています。 (Python documentation)P0-4. 既存 command registry の「shell string を組み立てない」契約に反する
このリポジトリには、今回の問題を解くための既存アーキテクチャがあります。
command_registry.pyは、operator / orchestrator-facing command について次を明示しています。argv 配列を使用する
shell string を hand-craft しない
redirection、substitution、compound operator を拒否する
shell: Falseを使う既存の
preflight.runは、まさに今回と同型のプロファイルです。canonical main root
default branch
github_read_onlyexact skill runtime
timeout
bounded artifact root
また、GitHub の複数ページ取得についても、既存 registry は
gh api --paginate --slurpを argv として登録しています。skill_runtime_command_policy.pyも次を既に実装しています。exact command ID
trusted repository
canonical root / default branch
exact token countと位置
--flag=value拒否metacharacter / leading env assignment 拒否
script realpath 検証
root no-worktree profile
#1547 の raw-string classifier 拡張は、この SSOT を再利用せず、より弱い第2の実行レーンを追加する設計です。
Major findings
P1-1.
ghの host・operand・環境変数が拘束されていないgh issue viewは issue number だけでなく URL も operand として受け入れます。また--repoは[HOST/]OWNER/REPO形式です。数値 issue とgithub.com/squne121/loop-protocolを厳密に拘束しなければ、guard と実際の CLI 解釈に差が生じます。 (GitHub CLI)GitHub CLI は以下の環境変数で挙動が変わります。
GH_HOSTGH_REPOGH_FORCE_TTYGH_PAGER/PAGERGH_CONFIG_DIRGH_DEBUGGH_PATHGH_PROMPT_DISABLED特に
GH_HOSTは host 未指定時の接続先を変え、GH_FORCE_TTYは redirect 中でも terminal-style output を強制できます。 (GitHub CLI)最低限、exact executor 内で次が必要です。
trusted
ghbinary の absolute realpathgithub.comの明示的 bindingrepo slug の完全一致
numeric issue operand
duplicate flag / alias / equals form / unknown flag の拒否
pager、TTY、debug、config、prompt、browser/editor 系 env の sanitize
stdout と stderr の分離
shell=False関連 Issue の設計方向も同じです。#1536 は単純な
gh pr reviewallowlist 追加を owner review で reject し、repo・host・binary・env・expected SHA・readback・idempotency を拘束する controlled publisher へ reframe しています。#1429 も rawgh apiではなく exact executor を唯一の経路にしています。P1-2.
--limit 1000は「全件取得」の証明にならないrunner は
gh issue list --limit 1000とgh pr list --limit 1000を「全件取得」と記述しています。しかし GitHub CLI の--limitは取得件数の最大値です。1000件を超えれば結果は打ち切られます。 (GitHub CLI)現在の marker には、以下がありません。
page count
server-side total count
hasNextPagetruncatedquery version
API version
fetch timeout / byte cap
したがって、1000件を超えた場合に不完全な inventory を「全件」として planner に渡す可能性があります。
実装は次のどちらかにすべきです。
GraphQL cursor / REST Link header を最後まで追い、
hasNextPage=falseを確認する上限到達時は
truncated: trueとして fail-close するGitHub の REST pagination は Link header を追って最終ページまで取得する方式です。直接 REST を使う場合は
X-GitHub-Api-Versionも固定すべきです。 (GitHub Docs)P1-3. producer の安全性を downstream parser で代替できない
既存 parser は final plan path について、temp root 配下、invocation ID、symlink parent、regular file、SHA 等を検証しています。これは consumer 側として妥当ですが、shell
>が先に既存ファイルを truncate した事実を後から取り消すことはできません。安全性は producer の create operation で確立する必要があります。
P1-4. 現行テストは filesystem side effect を検証していない
既存の artifact-export テストは helper / evaluator の分類を中心としており、実際の destination 作成、mode、collision、symlink、partial write、cleanup を検証していません。
#1547 の AC2 に文字列変種を追加するだけでは不十分です。少なくとも以下が必要です。
P1-5. 関連 Issue の設計水準より後退している
関連資産では、既に次の方向へ統一されています。
実装: allowed_paths_review_gate.py が issue-refinement-loop 配下パス引数で local_main_branch_guard.sh に false-positive block される問題を解消する #1543: whole-command substring 判定をやめ、tokenized argv で実行対象を判定
PR fix: review compact artifact の parent-local replay integrity binding を再設計する (#1532) #1535 のコメント: root checkout での false-positive が実際に記録され、follow-up Issue が要求されている (GitHub)
実装: pr-reviewer が gh pr review --comment を root checkout から実行できるようにする #1536: raw allowlist ではなく controlled transaction
実装: update_branch.py を canonical branch-update executor に統一し、入力・race・postcondition を自己検証する #1429: exact executor のみを正規経路にする
実装: SubAgent 起動 ledger の更新を runtime guard の誤検知から除外する #1502: exact-path 例外ではなく、型付き artifact state と transition policy
実装: Codex の SubagentStop scope-rollup capture を復旧する #1527: private、source-bound、readiness-bound artifact lifecycle
#1547 の「同じ source file だが他 Issue を待たない」という ordering は危険です。少なくとも #1543 との dependency / rebase 条件を設定し、同じ raw command classifier を並行して変更しない方がよいです。
推奨 reframe
推奨タイトル
推奨 Outcome
推奨実行レーン
outer invocation は既存形式に合わせます。
scope_rollup.runを以下へ登録するのが自然です。.claude/skills/issue-refinement-loop/scripts/command_registry.pyscripts/agent-guards/skill_runtime_command_policy.pyraw redirect 用の専用 branch を
local_main_branch_guard.pyに追加する必要はありません。推奨 artifact 実装
caller が output path を指定しない
UUIDv4 または executor-generated random ID
flat
/tmp/scope_rollup_*.jsonではなく private invocation directorydirectory mode
0700file mode
0600tempfile.mkstemp()またはO_CREAT | O_EXCL | O_NOFOLLOWalready-opened FD へ出力
stdout / stderr 分離
byte limit と timeout
JSON field / type / count 検証
.partから同一 directory 内で atomic renameflush +
fsyncsuccess / error / timeout 全経路で cleanup
retained result が必要なら lifecycle owner と削除時点を marker に記録
manifest に以下を記録:
host
repo
issue number
invocation ID
gh realpath / version
query schema version
page count
item count
truncated: falsefetched timestamps
body SHA256
planner script SHA256
改訂 Acceptance Criteria
canonical root / pre-worktree からの
scope_rollup.runexact invocation のみ allow され、rawgh ... > /tmp/...は引き続き block されるlinked worktree fixture は classifier の allow/block ではなく、context routing が classifier より先に行われることを検証する
command ID、issue number、trusted repo、cwd、branch、script realpath、argv shape が完全一致する
unknown flag、duplicate flag、
--flag=value、URL operand、wrapper、env prefix、metacharacter を拒否するtrusted
ghbinary とgithub.comを拘束し、GH_HOST、GH_REPO、GH_FORCE_TTY、pager、debug、config、prompt 系 env を sanitize するinventory は最後のページまで取得し、未完了なら
truncatedとして fail-close するtimeout、最大ページ数、最大 item 数、最大 byte 数を設定する
private directory / file mode、exclusive create、symlink・collision・non-regular file 拒否を runtime test する
planner stdout と stderr を分離し、warning が result JSON を破壊しない
GitHub fetch → hash/count → planner → verifier → marker の end-to-end subprocess test が成功する
failure / timeout / malformed JSON 時に final artifact と残骸を残さない
Claude / Codex の実 hook wrapper 双方で command class、reason code、stdout contract を検証する
必要な Allowed Paths
少なくとも次まで拡張が必要です。
scripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/skill_runtime_command_policy.pyscripts/agent-guards/skill_runtime_exec.py(policy 拡張が必要な場合).claude/skills/issue-refinement-loop/scripts/command_registry.py新規
run_scope_rollup_preflight.py.claude/agents/scope-rollup-runner.md.claude/skills/impl-review-loop/steps/preparation.mdexact policy / executor / hook integration tests
docs/dev/hook-boundaries.md投稿用レビューコメント
調査上の制約
対象 Issue 自体にはコメントがありません。関連 Issue の最新本文、PR #1535 の公開コメント、現行リポジトリ資産、GitHub CLI・Bash・Python・GitHub API の公式仕様を確認しました。ローカル clone は実行環境の DNS 制約で取得できなかったため pytest の実行までは行っていません。ただし、P0-1 と P0-2 はコード上の分岐順序と runner の連続コマンドが直接矛盾しており、動的再現の有無に依存しないブロッカーです。
この reframe 後なら実装 Issue として Go。現行 #1547 のままでは No-Go です。
# 判定REQUEST_CHANGES —
reframe_in_place。現状の #1547 は No-Go です。提案されている「
local_main_branch_guard.pyに absolute/tmpredirect の狭い例外を追加する」方式には、次のマージブロッカーがあります。gh ... > /tmp/...を許可しても、直後のコマンドで再度停止する>による共有/tmp書き込みを「read-only」と扱っており、既存ファイルの切り詰め・競合を防げない対象 Issue は、linked issue worktree 内で scope-rollup inventory を
/tmp/scope_rollup_*.jsonに保存することを目的とし、guard、専用テスト、hook-boundaries 文書の3ファイルだけを変更対象にしています。現時点でコメントは0件です。マージブロッカー
P0-1. 実行コンテキストの前提が成立しておらず、AC3 は classifier を検証しない
#1547 は「linked issue worktree で block される」と記述しています。しかし
impl-review-loopの現行 preparation 契約では、scope-rollup preflight はworktree 作成前に実行されます。したがって canonical な実行場所は root checkout です。さらに
local_main_branch_guard.pyは、cwd が primary root でなければ、コマンド分類より先にlinked_issue_worktree_contextまたはnot_local_rootとして allow を返します。artifact-export classifier には到達しません。したがって、AC3 の「linked issue worktree fixture で AC1/AC2 の allow/block と reason code を検証する」は無効です。
compound_wrapper_blockedは、実際の hook payload の cwd が root だった、あるいは「linked worktree を指定したつもりでも Bash tool 自体は root から実行された」可能性が高い、というのがコードからの推論です必要な修正
再現 fixture には少なくとも以下を固定してください。
cwdCLAUDE_PROJECT_DIRgit rev-parse --show-toplevelテストは次の2系統に分離すべきです。
P0-2. 3つの export を許可しても、scope-rollup は完走しない
scope-rollup-runnerは最初に次の3件を raw shell redirect で取得します。gh issue viewgh issue listgh pr listその後、以下を実行します。
uv run python3 -c "import ...; ..."による SHA256 計算$()による command substitution< fileによる入力 redirect> result.json 2>&1つまり #1547 が許可しようとしている3コマンド以外にも、同じ root-context guard が拒否する shell metacharacter が残っています。
現行 guard は
;、$()、<、>、wrapper 等を compound command として fail-close します。artifact-export 例外は compound 判定より前にあるため、今回追加する3パターンだけが例外化されます。結果として、実装後の挙動は次になります。
さらに
> result.json 2>&1は planner の stderr を JSON 本文へ混入させます。exit 0 または exit 2 でも warning が1行出れば、結果ファイルは valid JSON ではなくなります。結論
#1547 は障害を解消せず、停止位置を後方へ移動するだけです。
正しい変更には少なくとも以下が必要ですが、すべて現在の Allowed Paths 外です。
.claude/agents/scope-rollup-runner.md.claude/skills/impl-review-loop/steps/preparation.mdしたがって、現在の Allowed Paths と Stop Conditions のままでは Outcome を満たせません。
P0-3.
ghが read-only でも、shell>は破壊的ローカル書き込みBash はコマンド本体を実行する前に redirect を処理します。
>の destination が存在しなければ作成し、存在すればゼロ長へ切り詰めます。つまり、repo・host・GitHub 認証・gh実行自体の検証より先にローカル side effect が発生します。 ([GNU]1)したがって、次の表現は正しくありません。
正確には次です。
現行 preparation の invocation ID は
date -u ...と PID の組み合わせです。一方 runner の入力契約は UUID または ISO8601+乱数を要求しており、契約と producer の生成方式も一致していません。flat な共有
/tmpと shell>の組み合わせでは、少なくとも以下が未制御です。gh失敗時の空または部分ファイル同じリポジトリの
capture_scope_rollup_final_response.pyは、既にO_EXCL、O_NOFOLLOW、0600、flush、fsyncを用いた安全な生成方式を実装しています。#1547 の shell>は、この既存基準より明確に弱い実装です。Python 標準の
tempfile.mkstemp()/mkdtemp()も、ランダム名、排他的生成、作成ユーザーのみのアクセスを提供しています。 ([Python documentation]2)P0-4. 既存 command registry の「shell string を組み立てない」契約に反する
このリポジトリには、今回の問題を解くための既存アーキテクチャがあります。
command_registry.pyは、operator / orchestrator-facing command について次を明示しています。shell: Falseを使う既存の
preflight.runは、まさに今回と同型のプロファイルです。github_read_onlyまた、GitHub の複数ページ取得についても、既存 registry は
gh api --paginate --slurpを argv として登録しています。skill_runtime_command_policy.pyも次を既に実装しています。--flag=value拒否#1547 の raw-string classifier 拡張は、この SSOT を再利用せず、より弱い第2の実行レーンを追加する設計です。
Major findings
P1-1.
ghの host・operand・環境変数が拘束されていないgh issue viewは issue number だけでなく URL も operand として受け入れます。また--repoは[HOST/]OWNER/REPO形式です。数値 issue とgithub.com/squne121/loop-protocolを厳密に拘束しなければ、guard と実際の CLI 解釈に差が生じます。 ([GitHub CLI]3)GitHub CLI は以下の環境変数で挙動が変わります。
GH_HOSTGH_REPOGH_FORCE_TTYGH_PAGER/PAGERGH_CONFIG_DIRGH_DEBUGGH_PATHGH_PROMPT_DISABLED特に
GH_HOSTは host 未指定時の接続先を変え、GH_FORCE_TTYは redirect 中でも terminal-style output を強制できます。 ([GitHub CLI]4)最低限、exact executor 内で次が必要です。
ghbinary の absolute realpathgithub.comの明示的 bindingshell=False関連 Issue の設計方向も同じです。#1536 は単純な
gh pr reviewallowlist 追加を owner review で reject し、repo・host・binary・env・expected SHA・readback・idempotency を拘束する controlled publisher へ reframe しています。#1429 も rawgh apiではなく exact executor を唯一の経路にしています。P1-2.
--limit 1000は「全件取得」の証明にならないrunner は
gh issue list --limit 1000とgh pr list --limit 1000を「全件取得」と記述しています。しかし GitHub CLI の--limitは取得件数の最大値です。1000件を超えれば結果は打ち切られます。 (GitHub CLI)現在の marker には、以下がありません。
hasNextPagetruncatedしたがって、1000件を超えた場合に不完全な inventory を「全件」として planner に渡す可能性があります。
実装は次のどちらかにすべきです。
hasNextPage=falseを確認するtruncated: trueとして fail-close するGitHub の REST pagination は Link header を追って最終ページまで取得する方式です。直接 REST を使う場合は
X-GitHub-Api-Versionも固定すべきです。 ([GitHub Docs]6)P1-3. producer の安全性を downstream parser で代替できない
既存 parser は final plan path について、temp root 配下、invocation ID、symlink parent、regular file、SHA 等を検証しています。これは consumer 側として妥当ですが、shell
>が先に既存ファイルを truncate した事実を後から取り消すことはできません。安全性は producer の create operation で確立する必要があります。
P1-4. 現行テストは filesystem side effect を検証していない
既存の artifact-export テストは helper / evaluator の分類を中心としており、実際の destination 作成、mode、collision、symlink、partial write、cleanup を検証していません。
#1547 の AC2 に文字列変種を追加するだけでは不十分です。少なくとも以下が必要です。
ghnonzero / timeoutGH_HOST差し替えGH_FORCE_TTY/ pager 注入P1-5. 関連 Issue の設計水準より後退している
関連資産では、既に次の方向へ統一されています。
#1547 の「同じ source file だが他 Issue を待たない」という ordering は危険です。少なくとも #1543 との dependency / rebase 条件を設定し、同じ raw command classifier を並行して変更しない方がよいです。
推奨 reframe
推奨タイトル
推奨 Outcome
推奨実行レーン
outer invocation は既存形式に合わせます。
scope_rollup.runを以下へ登録するのが自然です。.claude/skills/issue-refinement-loop/scripts/command_registry.pyscripts/agent-guards/skill_runtime_command_policy.pyraw redirect 用の専用 branch を
local_main_branch_guard.pyに追加する必要はありません。推奨 artifact 実装
caller が output path を指定しない
UUIDv4 または executor-generated random ID
flat
/tmp/scope_rollup_*.jsonではなく private invocation directorydirectory mode
0700file mode
0600tempfile.mkstemp()またはO_CREAT | O_EXCL | O_NOFOLLOWalready-opened FD へ出力
stdout / stderr 分離
byte limit と timeout
JSON field / type / count 検証
.partから同一 directory 内で atomic renameflush +
fsyncsuccess / error / timeout 全経路で cleanup
retained result が必要なら lifecycle owner と削除時点を marker に記録
manifest に以下を記録:
truncated: false改訂 Acceptance Criteria
scope_rollup.runexact invocation のみ allow され、rawgh ... > /tmp/...は引き続き block される--flag=value、URL operand、wrapper、env prefix、metacharacter を拒否するghbinary とgithub.comを拘束し、GH_HOST、GH_REPO、GH_FORCE_TTY、pager、debug、config、prompt 系 env を sanitize するtruncatedとして fail-close する必要な Allowed Paths
少なくとも次まで拡張が必要です。
scripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/skill_runtime_command_policy.pyscripts/agent-guards/skill_runtime_exec.py(policy 拡張が必要な場合).claude/skills/issue-refinement-loop/scripts/command_registry.pyrun_scope_rollup_preflight.py.claude/agents/scope-rollup-runner.md.claude/skills/impl-review-loop/steps/preparation.mddocs/dev/hook-boundaries.md投稿用レビューコメント
調査上の制約
対象 Issue 自体にはコメントがありません。関連 Issue の最新本文、PR #1535 の公開コメント、現行リポジトリ資産、GitHub CLI・Bash・Python・GitHub API の公式仕様を確認しました。ローカル clone は実行環境の DNS 制約で取得できなかったため pytest の実行までは行っていません。ただし、P0-1 と P0-2 はコード上の分岐順序と runner の連続コマンドが直接矛盾しており、動的再現の有無に依存しないブロッカーです。
この reframe 後なら実装 Issue として Go。現行 #1547 のままでは No-Go です。
squne121 commentedon Jul 17, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jul 17, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jul 17, 2026
Contract Review Result
squne121 commentedon Jul 17, 2026
Contract Review Result
squne121 commentedon Jul 17, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedfix: PR #1560 CI blocker 3件を解消する(Ruff E501・Japanese Check・test plan r…
fix: preparation.md の見出し英語 prose に日本語補足を追記する (#1547)
fix: scope_rollup.run の producer/consumer 契約破断とartifact安全性を修正する (#1547)
fix: E501 line-length violation in run_scope_rollup_preflight.py (#1547)