Skip to content

fix(#1228): allow read-only preflight.run without linked worktree - #1231

Merged
squne121 merged 7 commits into
mainfrom
worktree-issue-1228-preflight-no-worktree-readonly
Jun 28, 2026
Merged

squne121 merged 7 commits into
mainfrom
worktree-issue-1228-preflight-no-worktree-readonly

Conversation

@squne121

@squne121 squne121 commented Jun 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

この PR の変更概要です。

  • preflight.run だけを対象に、linked worktree と LOOP_ISSUE_NUMBER なしでも local root の default branch から read-only preflight を起動できるようにしました。
  • exact argv / repo binding / direct preflight block / artifact root 外 write fail-close は維持し、root allow を一般化しないまま guard 責務をそろえました。
  • no-worktree 条件を実 hook 経路で検証する pytest harness を追加し、guard allow 後に actual executor が artifact 配下へ preflight.json を出力できることまで固定しました。
  • preflight.run だけを root no-worktree 例外にする allowlist と policy invariant check を追加し、docs も現仕様へ同期しました。

受け入れ条件の達成状況

  • AC1a local_main_branch_guard 経路で no-worktree / no-env の exact preflight.run が allow
  • AC1b worktree_scope_guard 経路でも同条件の exact preflight.run が block されない
  • AC1c direct run_refinement_preflight.py root 実行は block 維持
  • AC1d non-exact executor argv は block 維持
  • AC1e artifact root 外 write は fail-close 維持
  • AC2 .claude/hooks/tests/test_local_main_branch_guard.py
  • AC3 tests/codex/test_local_main_branch_guard.py
  • AC4 uv run pytest .claude/hooks/tests/test_worktree_scope_guard.py -k "skill_runtime_executor" -v
  • AC5 pnpm typecheck
  • AC6 pnpm lint
  • AC7 pnpm test
  • AC8 pnpm build

検証コマンド結果

  • uv run pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py -v を実行し、新規 harness 17 件が PASS
  • uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -v を実行し、root guard 回帰がないことを確認
  • uv run pytest tests/codex/test_local_main_branch_guard.py -v を実行し、Codex parity が PASS
  • uv run pytest .claude/hooks/tests/test_worktree_scope_guard.py -k "skill_runtime_executor" -v を実行し、worktree scope parity が PASS
  • pnpm typecheck を実行し、型チェックが PASS
  • pnpm lint を実行し、lint が PASS
  • pnpm test を実行し、既存テスト群が PASS
  • pnpm build を実行し、ビルドが PASS
  • uv run --locked ruff check --select E,F --ignore E402 .claude/scripts scripts schemas .claude/skills を実行し、CI と同じ Ruff 条件で PASS

Checks

主要なリポジトリ検証結果です。

  • pnpm typecheck PASS(型チェック通過)
  • pnpm lint PASS(静的解析通過)
  • pnpm test PASS(既存テスト通過)
  • pnpm build PASS(ビルド通過)

Allowed Paths 遵守

Schema Change Applicability

スキーマ変更の有無を明示します。

  • decision: not_schema_change
  • reason: command policy と hook guard の挙動変更であり、producer-consumer 境界をまたぐ machine-readable schema の追加・改名・型変更はありません。

Schema Consumer Inventory

この PR は not_schema_change 判定のため、schema consumer inventory は不要です。

N/A。not_schema_change のため schema consumer inventory は不要です。

Safety Claim Matrix

安全境界に関する主張と未制御範囲を表にまとめます。

Claim Implemented? Not controlled Evidence Follow-up
preflight.run のみ no-worktree / no-env 例外を許可 yes N/A guard parity テスト、新規 harness、policy invariant check の PASS N/A
direct preflight と non-exact argv は引き続き root block yes N/A AC1c / AC1d の pytest PASS N/A
repo tree outside allowed artifact root への変更は fail-close を維持 yes N/A AC1e の pytest PASS N/A

Notes

補足情報と issue 連携情報です。

Closes #1228(Issue 自動クローズ用)

@github-actions

github-actions Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1231 closed).

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "0b882d303533ce2638f65d5edf84f3822be5c7d6"
merge_ready: false
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "BEHIND"
blockers: []
required_auto_actions:

  • kind: update_branch
    executor: implementation-worker
    skill: implement-issue.update_branch
    blocking_merge_ready: true
    mechanical: true
    expected_head_sha: "0b882d303533ce2638f65d5edf84f3822be5c7d6"
    auto_fix_applied: []
    follow_up_issue_requests: []
    allowed_paths_gate:
    status: ok
    allowed_paths_gate_source: review_subagent

@squne121

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES 相当。
方向性は #1228 の目的に合っていますが、現状のままマージすると「no-worktree read-only preflight」の安全境界を、実装・テスト・ドキュメントで一貫して保証できているとは言い切れません。

PR #1231 は open / draft、7 files、+301 / -17、head は 875467f... です。CI は現 head で主要 workflow が success ですが、既存レビューコメントは reviewed_head_sha: 0b882d... の古い head に対するもので、merge_ready: false / BEHIND / update_branch required のままです。現 head でレビュー判定を更新すべきです。

良い点

実装の中核は妥当です。#1228 は、local root / default branch / no linked worktree / no LOOP_ISSUE_NUMBER でも exact preflight.run を read-only profile として通し、direct preflight・non-exact argv・wrong repo・artifact 外 write を維持ブロックする要求です。

現 PR は parse_exact_skill_runtime_command() の exact token contract を維持し、uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number <N> --repo squne121/loop-protocol の形、flag 順序、--flag=value 拒否、positive int issue、trusted repo を維持しています。

また executor 側は shell=False、sanitized env、trusted PATH、registry validation、artifact path symlink guard、child 実行後の unauthorized repo change 検査を維持しています。これは Python の subprocess 推奨とも整合します。Python 公式 docs でも subprocess は既定で shell を暗黙起動せず、shell metacharacter を argv として安全に渡せる一方、shell=True では呼び出し側が shell injection を防ぐ責任を負います。 ([Python documentation]1)

ブロッカー / 修正要求

1. docs/dev/agent-skill-boundaries.md が #1228 後の仕様と矛盾している

コードは preflight.run について active issue worktree 要求をスキップするようになっています。command_allows_root_no_worktree(parsed) が true なら、is_exact_skill_runtime_executor_command() は active issue / worktree catalog を見ずに allow します。

executor 側も同様に、preflight.run の場合は resolve_active_issue() を呼ばず、active_issue_mismatch / active_issue_worktree_missing を要求しない分岐になっています。

しかし docs はまだ「active issue worktree は catalog で一意に解決できる entry のみを許可」「executor は repo と issue_number を active worktree context に束縛」と書いています。これは #1228 の no-worktree allow と正面衝突します。

修正: Privileged Skill Runtime Command Boundary を #1228 仕様に更新してください。少なくとも preflight.run だけは「issue number は exact argv 由来」「active worktree binding は不要」「repo / cwd / default branch / exact argv / registry / artifact-only repo write postcondition は維持」と明記する必要があります。

2. 新規 harness の positive test が false-green になり得る

test_skill_runtime_preflight_no_worktree.py の _make_repo() は temp repo に .gitignore と README.md だけを作ります。scripts/agent-guards/skill_runtime_exec.py、registry、preflight script は入れていません。

それにもかかわらず、positive tests はその temp repo 上で guard に exact command を渡して returncode == 0 を見るだけです。つまり「実際に executor が存在し、registry と child preflight が成立する」ことは確認していません。

一方、fixture を入れる _install_skill_runtime_exec_fixture() は存在しますが、artifact 外 write test でしか使われていません。

Claude Code hooks は PreToolUse で tool call 前の JSON を受け、exit code 2 でブロックできます。つまり guard テストは「allow/block 判定」としては意味がありますが、#1228 の Outcome にある「refinement preflight が read-only で起動する状態」まではこの positive test だけでは証明できません。([Claude Platform Docs]2) ([Claude Platform Docs]2)

修正: positive tests でも _install_skill_runtime_exec_fixture(repo) を使い、少なくとも以下を確認してください。

# guard allow
bash .claude/hooks/local_main_branch_guard.sh < payload

# その後 actual executor が artifact 配下へ preflight.json を出せる
python3 scripts/agent-guards/skill_runtime_exec.py \
  --command-id preflight.run \
  --issue-number 1228 \
  --repo squne121/loop-protocol

3. AC1d の negative coverage が薄い

#1228 は non-exact executor argv、direct preflight、mutation / compound、wrong repo、artifact 外 write まで adversarial harness で固定する要求です。

現 harness の non-exact negative は duplicate --command-id 1件だけです。direct preflight と artifact 外 write はありますが、Issue 本文が要求した missing / extra flag、--flag=value、leading env、metachar、pipe / redirect / compound、wrong repo、non-default branch、detached root などが no-worktree profile の実経路で足りません。

既存 local guard test には noncanonical lexical form や strict remote parser の回帰はありますが、今回追加した no-worktree/no-env profile 専用の adversarial harness としては不足です。

修正: test_skill_runtime_preflight_no_worktree.py に parametrized negative cases を追加してください。最低限:

wrong command_id
missing --repo
extra arg
duplicate --issue-number
--command-id=preflight.run
LOOP_ISSUE_NUMBER=1228 uv run ...
uv run ... ; git status
uv run ... | cat
uv run ... > tmp/out
--repo evil/repo
current branch != default
detached HEAD

shlex は shell-like split には使えますが、Python 公式 docs は非 POSIX shell での正確性を保証しないと警告しています。したがって、現行の「metachar / leading env を先に拒否し、exact token sequence を固定し、実行は list argv + shell=False」という方針は維持すべきです。([Python documentation]3)

4. command_allows_root_no_worktree() が薄すぎる

関数名は「read-only preflight root profile」を示しますが、実体は parsed.command_id == "preflight.run" だけです。

現在は parser、policy、registry validation が周辺で守っているため即危険ではありません。実際、policy は preflight.run の required_cwd、required_branch、allowed_write_roots、network_effect を定義し、registry validation も execution_class / cwd_policy / required_cwd / required_branch / network_effect / exact argv template を検査しています。

ただし将来 preflight.run の registry entry が drift した場合、「no-worktree allow の根拠」が command id だけに見えます。

修正: 次のどちらかを推奨します。

ROOT_NO_WORKTREE_ALLOWED_COMMAND_IDS = frozenset({"preflight.run"})

にして、関数名を is_root_no_worktree_exception_command_id() のように弱い意味へ変更する。あるいは、helper 内で policy invariant まで確認する形にしてください。

5. Safety Claim の「artifact root 外 write」は repo-tree scope と明記すべき

実装は repo root 内の snapshot と git status --porcelain=v1 --untracked-files=all --ignored=matching -z を比較して、artifact root 外の repo 変更を検出しています。これは repo contamination 防止としては良い設計です。Git の porcelain -z は path を NUL 終端で返すため、機械処理にも適しています。 ([Git]4) (Git)

ただしこれは OS 全体の filesystem sandbox ではありません。repo root 外への write を一般に防ぐ仕組みではなく、「repo tree の artifact root 外変更」を fail-close する仕組みです。

修正: PR body / Safety Claim Matrix では、artifact root 外 write ではなく repo tree outside allowed artifact root と書く方が正確です。OS-level write sandbox を主張しないでください。

6. Closes #1228 は standalone で入れる

PR body には「closing keyword は文中の Closes #1228 を使います」とありますが、GitHub の自動クローズは supported keyword syntax を PR description / commit message に入れ、default branch に merge される必要があります。([GitHub Docs]5)

修正: PR body の末尾に code span ではなく、単独行で入れてください。

Closes #1228

Codex / Claude Code に投げる修正プロンプト

対象: https://github.com/squne121/loop-protocol/pull/1231

PR #1231 を REQUEST_CHANGES 対応してください。目的は #1228 の no-worktree/no-env read-only preflight.run profile を安全境界を緩めずに完成させることです。

必須修正:

1. docs/dev/agent-skill-boundaries.md の Privileged Skill Runtime Command Boundary を #1228 仕様に更新する。
   - preflight.run だけは exact argv の --issue-number を issue source とする。
   - active issue worktree / LOOP_ISSUE_NUMBER は no-worktree root preflight profile では不要。
   - canonical root / default branch / trusted repo / exact argv / registry validation / github_read_only / repo-tree artifact-only postcondition は維持。
   - OS-level filesystem sandbox ではなく repo tree outside allowed artifact root の fail-close であることを明記。

2. scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py の positive tests を false-green にしない。
   - local_main_branch_guard / worktree_scope_guard の positive no-worktree tests でも _install_skill_runtime_exec_fixture(repo) を使う。
   - guard allow だけでなく actual skill_runtime_exec.py が artifact 配下に preflight.json を作ることも確認する。

3. AC1d の adversarial negative cases を no-worktree/no-env profile の実 hook 経路で追加する。
   - wrong command_id
   - missing / extra / duplicate flags
   - --flag=value
   - leading env assignment
   - shell metachar / pipe / redirect / compound
   - wrong repo
   - non-default branch
   - detached HEAD
   - direct run_refinement_preflight.py block 維持

4. command_allows_root_no_worktree() を command_id だけで read-only profile と誤読されない形にする。
   - rename するか、ROOT_NO_WORKTREE_ALLOWED_COMMAND_IDS と policy invariant assertion を追加する。
   - preflight.run 以外への一般化は禁止。

5. PR body を更新する。
   - standalone の `Closes #1228` を追加。
   - Safety Claim Matrix の artifact claim を repo-tree scope に正確化。
   - 現 head SHA で検証結果を更新。

6. 検証:
   - uv run pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py -v
   - uv run pytest .claude/hooks/tests/test_local_main_branch_guard.py -v
   - uv run pytest tests/codex/test_local_main_branch_guard.py -v
   - uv run pytest .claude/hooks/tests/test_worktree_scope_guard.py -k "skill_runtime_executor" -v
   - pnpm typecheck
   - pnpm lint
   - pnpm test
   - pnpm build
   - uv run --locked ruff check --select E,F --ignore E402 .claude/scripts scripts schemas .claude/skills

破壊的操作、秘密情報、外部課金、権限不足のみ停止条件。その他は人間承認不要で修正・検証・PR本文更新まで進めてください。

現時点では「CI success」だけでは不足です。安全境界を扱う PR なので、docs の仕様矛盾、false-green positive test、AC1d negative coverage 不足を潰してから Ready for review にするのが妥当です。

@squne121
squne121 marked this pull request as ready for review June 28, 2026 13:12
@squne121
squne121 merged commit 1f1c723 into main Jun 28, 2026
18 checks passed
@squne121
squne121 deleted the worktree-issue-1228-preflight-no-worktree-readonly branch June 28, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: issue-refinement-loop の control-plane を local root から起動できない guard 前提を read-only preflight profile で解消する

1 participant