Repository navigation
feat(#1193): governed Python invocation policy を uv run --locked に統一する - #1227
Conversation
governed surfaces 上の dependency-bearing Python invocation を `uv run --locked` policy に機械拘束し、direct interpreter は stdlib_only / bootstrap の理由付き例外 registry に限定する。 - scripts/ci/check_python_invocation_policy.py: governed surface (.github/workflows/** / .github/actions/** / docs/dev/** / .claude/skills/**/SKILL.md / package.json) を file-glob + text pattern で走査。 pytest 許可形は `uv run --locked pytest` のみ、script 許可形は `uv run --locked python[3] <repo-relative .py>` のみ。`uv python install` 等の uv subcommand と Japanese prose の false positive を除外。 - scripts/ci/python_invocation_policy_exceptions.json: exact_argv_pattern / reason / scope (stdlib_only|bootstrap) を必須とする例外 registry。schema validate を fail-closed 化。 - scripts/ci/tests/test_python_invocation_policy.py + fixtures: AC1-AC9 の positive / negative / adversarial テスト。 - governed surface の現行 violation を全移行 (AC7 repo_scan_clean=0): SKILL.md / docs/dev/** / check-hook-integrity.yml / package.json を `uv run --locked` 化し、check-japanese.yml / ci.yml verdict step / session-recording-policy.md の bare interpreter は stdlib_only 例外に登録。 - .github/workflows/ci.yml python-test job に checker static step を pytest 群の 前に追加。 - docs/dev/test-lane-policy.md に CI_TEST_PERFORMANCE_DECISION_V1 (#1193) を記録。 Closes #1193 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-1227/ The preview will be removed when this PR is closed. |
…--locked へ移行 control-plane の独立検証で AC4 例外 registry の policy hole を検出した。 kill_switch_runtime_smoke.py (import yaml, HARD) と check_session_recording_policy.py (import yaml) が stdlib_only 例外として 誤登録され、その bare python3 <script> 呼び出しを policy 違反として 検出せず素通りさせていた。dependency-bearing invocation を uv run --locked に拘束する Issue Outcome に反する穴。 - python_invocation_policy_exceptions.json から上記 2 例外を削除 (例外素通りでなく migration で AC7 violation 0 を達成) - bare 呼び出し 3 件を uv run --locked python3 へ移行: ci.yml Kill Switch smoke / package.json session-recording:smoke / session-recording-policy.md doc 実行例 - registry self-audit: 残る 7 例外の target は全て stdlib-only を確認 - adversarial test 2 件追加 (yaml 依存例外の不在 / 未登録時の violation 検出) - test-lane-policy.md CI_TEST_PERFORMANCE_DECISION_V1(#1193) を更新 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
iteration-1 で SKILL.md を `uv run --locked python3` へ移行した結果、固定幅否定 先読み `(?<!uv run )python3 ...` が `--locked ` 直前の python3 を bare と誤検出し python-test が fail していた。matcher を positive 検証へ書き換え、`uv run python3` と `uv run --locked python3` の両形を許容する(bare 検出の意図は保持)。 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LOOP_VERDICT_V2 (impl-review-loop)verdict: APPROVE レビュー要旨(opus reviewer + control-plane 独立検証)
follow-up(本 PR スコープ外・記載済み): |
結論REQUEST_CHANGES。 PR #1227 の方向性は正しいですが、現状の checker は「policy gate」としてはまだ甘いです。特に #1193 / 親 #1145 の要求は「dependency-bearing Python invocation を P0-1:
|
…osed splitter
OWNER REQUEST_CHANGES (#issuecomment-4825421642) P0-1〜P0-4 / AC14-AC18:
- registry schema を id/scope/exact_argv(array,完全列)/reason/proof へ移行し
broad python3 - / python3 -c prefix entry を削除。既存 stdlib_only/bootstrap
script 例外を governed surface 上の実 argv 完全列 exact_argv variant
(proof=stdlib_import_scan) として再登録 (AC4a/AC4d/AC17, 14 entries)。
- heredoc body / python3 -c code を AST import scan し非 stdlib 依存を violation 化。
uv run --locked python -c / - は許可 (AC14/AC4b)。
- 1行/run: block を quote・substitution・${{ }} 認識で全 simple command へ分割し
classify (AC15)。command/process substitution は内部コマンドを再帰分類。
- shlex 失敗時の .split() fallback を廃止し未対応文法を unsupported_shell_grammar
に fail-closed (AC16)。外部 shell parser は不採用 (理由を test-lane-policy.md に記録)。
- Markdown は shell 言語 fenced block のみ走査 (yaml/json/markdown block は対象外)。
- edit-issue/SKILL.md の uv run python3 -c "import yaml" を --locked へ migrate。
AC7: --strict で governed surface violation 0 (69 files, 14 exceptions)。
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- AC4a exception_schema を新 schema(id/scope/exact_argv/reason/proof + callsite-bound surface/locator + duplicate id)へ更新。AC4d exact_argv_prefix を exact full-argv 一致(余剰/並べ替え/duplicate/path-qualified 不一致)へ更新。 - AC14 heredoc_c_dependency / AC15 compound_command / AC16 unsupported_shell_grammar / AC17 exact_argv_variant / AC18 adversarial(6 ケース)を追加。 - AC4b に stdlib_import_scan proof の AST 受理/棄却テストを追加。 - iter_yaml_run: `- run:` inline 形も解釈するよう run_line_re を更新。 72 passed。 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
squne121
left a comment
There was a problem hiding this comment.
LOOP_VERDICT_V2 (impl-review-loop, iteration 3 — OWNER REQUEST_CHANGES 対応)
verdict: APPROVE
reviewed_head_sha: 64e678b
merge_ready: true
mergeability: { mergeable: MERGEABLE, merge_state_status: CLEAN }
linked_issue: 1193
allowed_paths_gate:
schema: ALLOWED_PATHS_GATE_RESULT_V1
status: ok
producer_role: review_subagent
worker_report_used_as_canonical: false
changed_files_count: 25
violations: []
contract_source_kind: issue_comment
contract_source_id: "4825948455"
expected_contract_fingerprint: { body_sha256: "sha256:eeb3784b..." }
recompute_method: manual_deterministic_review_subagent
tooling_note: "allowed_paths_review_gate.py は契約の mid-path glob '.claude/skills/**/SKILL.md' を解釈できず false indeterminate を返したため、review_subagent が git diff base...head の 25 ファイルを Allowed Paths に対し決定論的に再計算(全件適合・0 violations)。control-plane も独立に同結果を確認済み。"
blockers: []
required_auto_actions: []
OWNER review (#issuecomment-4825421642) P0 対応サマリ(head 64e678b で独立検証済み)
- P0-1/AC4a/AC14: registry を schema_version 2(id/scope/exact_argv(完全列)/reason/proof)へ移行、broad
python3 -/python3 -cprefix 例外を削除(14 exact_argv entries、全 proof=stdlib_import_scan)。heredoc body /-ccode を AST import scan し非 stdlib import は violation。_check_exception_proofが登録済み stdlib_only 例外の対象 script も再 AST 検証(text-only でない)。 - P0-2/AC15: 1 行/
run:block を&&/||/;/|/&で分割し全 simple command を classify(先頭/後続/;後とも検出)。 - P0-3/AC16: shlex 解析不能・unterminated/unbalanced は
unsupported_shell_grammarviolation(fail-closed、.split()fallback 廃止)。command/process substitution は再帰分類で内部の隠れ違反を検出(false green 防止)。 - P0-4/AC4d/AC17: exact full-argv 一致(reorder/duplicate/path-qualified/余剰 token は不一致)。bootstrap も exact argv variant。
- AC18: adversarial 6 ケースが exact violation type を assert(ungameable)。
- CI(64e678b): ci_verdict_summary=all_pass、python-test(checker --strict step + 72 tests)SUCCESS、typecheck/lint/test/build/actionlint/check-hook-integrity SUCCESS。
OWNER への申し送り(最終判断を仰ぐ項目)
- AC16 解釈: P0-3 の文面は
$(...)/<(...)の一律 fail-closed と読めるが、実 CI が$(...)を正当利用し AC7=0 と両立しないため、OWNER の核心意図(false green にならない・parse 不能は fail-closed)に沿って「substitution は再帰分類で隠れ違反を検出し、unterminated/unbalanced のみ fail-closed」とした。AC16 をこの解釈に精緻化し contract Scope Delta に記録済み(fresh go body_sha256 eeb3784b)。この解釈の妥当性の最終判断を仰ぐ。 - P1 drift(follow-up 起票済み):
.claude/settings.jsonallowlist の--locked追従=#1229、AGENTS.mdprobe 実行例の--locked統一=#1232。いずれも #1193 の Allowed Paths 外のため本 PR スコープ外。 - reviewer tooling gap(非 blocking):
allowed_paths_review_gate.pyが mid-path**glob を解釈できず false indeterminate を返す。別途 tooling follow-up 推奨。
結論: impl-review-loop は merge-ready(draft_pr_ready)。最終 merge 判断は OWNER に委ねる。
概要
本 PR は #1193 を解決する。Closes #1193
governed surfaces 上の dependency-bearing Python invocation を
uv run --lockedpolicy に機械拘束し、direct interpreter を stdlib_only / bootstrap の理由付き例外 registry に限定する。親 #1145 の「全 invocation をuv run --lockedに統一」目標に沿う。iteration-3 修正(OWNER REQUEST_CHANGES P0 対応・checker 堅牢性強化)
OWNER レビュー(#issuecomment-4825421642)の P0-1〜P0-4 と追加 AC14-AC18 を実装した。registry schema(固定契約)の変更は OWNER の明示要求に基づく。実装は
scripts/ci/配下の既存 Allowed Paths 内で完結する。id/scope/exact_argv(argv トークンの完全列=prefix ではなく全トークン exact 一致)/reason/proof(stdlib_import_scan|code_hash|heredoc_body_ast_scan|no_target)へ移行した。broadpython3 -/python3 -cprefix エントリは削除した。既存の stdlib_only / bootstrap script 例外は、governed surface 上の実 argv 完全列を列挙した exact_argv variant(proof: stdlib_import_scan、計 14 エントリ)として再登録した。callsite-bound(heredoc /-c)エントリはsurface/locatorを必須とする schema 制約を追加した。例外照合は exact full-argv 一致とし、path-qualified executable・option 並べ替え・duplicate・余剰 token はすべて不一致(exception 不成立)として扱う。-cの AST import scan: directpython3 -(heredoc)の body とpython3 -cの code string をastで import 解析し、非 stdlib import(再帰的に stdlib-only と確認できる repo-local module は除く)を含む場合は violation(heredoc_c_dependency)とする。scope: stdlib_onlyscript 例外も check 時に対象 script を AST 確認し、非 stdlib import を含めば exception 不成立(exception_proof_failed)とする。uv run --locked python -c/-(heredoc)は lockfile 下で依存解決されるため許可する。run:block を&&/||/;/|で分割し(quote・substitution・${{ }}認識)、全 simple command を classify する(先頭 1 invocation のみの判定を廃止)。command / process substitution$(...)/<(...)は内部コマンドを再帰分類し、隠れた違反が false green にならないようにする。shlex.split()失敗時の.split()fallback を廃止した。閉じない / 未対応の shell 文法を含む launcher-bearing な simple command はunsupported_shell_grammarviolation として fail-closed に報告する。docs/dev/test-lane-policy.mdの「invocation policy checker の shell 文法解析方針」セクションに記録した。-k adversarialで収集可能な 6 ケース(heredoc 本体import yaml/python3 -c "import yaml"/... && python3 scripts/not_registered.py後続 / 先頭 /uv run --locked pytest -q; uv run pytest -q後続 non-locked / command・process substitution が false green にならない)を追加した。--strictで governed surface violation 0(69 files / 14 exceptions)を維持した。新たに検出された 1 件の実 violation(.claude/skills/edit-issue/SKILL.mdのuv run python3 -c "import yaml"— non-locked で yaml 依存)はuv run --locked python3 -cへ migrate した。governed だが Allowed Paths 外のファイルに新規 violation は検出されなかった(context-mode-rollback.md / hook-boundaries.md 等の inlinepython3 -cは prose / stdlib のため非 violation)。新 registry exact_argv / proof 一覧(14 エントリ)
python3 scripts/ci/python_test_plan.py --emit scope-argv --check-paths --format json... --emit run-argv --mode parallel --format nul... --emit run-argv --mode parallel... --emit workers --format lines... --emit scheduler --format lines... --emit serial-lane-argv --format nulpython3 scripts/ci/codex_execpolicy_matrix.py --npm-prefix ... --artifact ...python3 .claude/scripts/secret_exposure_scanner.py --local tests/fixtures/session-recording/valid --fail-on-finding... --local tests/fixtures/session-recording/invalid... --local .claude/scripts --exclude ... --fail-on-findingpython3 .claude/skills/create-issue/scripts/validate_japanese_content.py --threshold 0.1... --file $file --threshold 0.1python3 .claude/skills/pr-review-judge/scripts/ci_verdict_summary_v2.py --expected-head-sha ... --output ...... --output ... --artifact-id ... --artifact-url ... --artifact-digest ...全 14 エントリの target script は AST import scan で(再帰的に)stdlib-only であることを
--strict実行時に検証している。proof: stdlib_import_scanが non-stdlib import を検出すれば該当例外は不成立となり violation 化する。iteration-3 で新規検出した violation の扱い
.claude/skills/edit-issue/SKILL.mdL121uv run python3 -c "import yaml ..."(non-locked, yaml 依存)uv run --locked python3 -cへ migratepython3 - <<'PY'heredoc(約 18 件)python3 scripts/ci/python_test_plan.py等の direct scriptiteration-1 / iteration-2 修正(履歴)
iteration-1: control-plane の独立検証で AC4 例外 registry の policy hole(yaml 依存 script 2 件の stdlib_only 誤登録)を検出し、例外削除 +
uv run --lockedmigration で AC7 violation 0 を達成した。iteration-2: SKILL.md 移行に伴う guard test の誤検出と PR Body Japanese Check を修正した。詳細は本 PR のコミット履歴を参照。変更内容(最新)
scripts/ci/check_python_invocation_policy.py: governed surface を file-path glob で走査し、全 simple command を classify する fail-closed checker。pytest 許可形はuv run --locked pytestのみ。script 許可形はuv run --locked python[3] <repo-relative .py>のみ。direct interpreter は exact full-argv + proof(AST import scan)でのみ許可。heredoc /-cの inline code は AST 解析し非 stdlib 依存を violation 化。command / process substitution は再帰分類、未対応文法はunsupported_shell_grammarで fail-closed。Markdown は shell 言語(```bash等)の fenced block のみ走査。scripts/ci/python_invocation_policy_exceptions.json:id/scope/exact_argv(完全列)/reason/proofを必須とする例外 registry(14 エントリ、schema_version: 2)。必須欠落・unknown scope/proof・duplicate id・callsite-bound の surface/locator 欠落で schema validation が fail-closed。scripts/ci/tests/test_python_invocation_policy.py+scripts/ci/fixtures/python_invocation_policy/**: AC1-AC9 + AC14-AC18 の positive / negative / adversarial テスト(72 件)。docs/dev/test-lane-policy.md:CI_TEST_PERFORMANCE_DECISION_V1(実装: governed Python invocation を uv run --locked policy へ拘束する #1193)と、外部 shell parser を採用しない fail-closed custom splitter 方針を記録。.github/workflows/ci.ymlpython-test job に checker static step(--strict)を pytest 群の前に追加。Scope Delta(人間承認済み)
契約で承認された追加 Allowed Paths(governed-but-unallowed 解消・AC7=0 達成のため)を移行に使用した:
.github/workflows/check-hook-integrity.yml/docs/dev/agent-session-hotspots.md/docs/dev/schema-governance.md/docs/dev/workflow.md/docs/dev/session-recording-policy.md。checker 堅牢性強化(OWNER REQUEST_CHANGES・人間判断)として registry schema・AST scan・全 command 走査・fail-closed・AC14-AC18 を追加した。CI_TEST_PERFORMANCE_DECISION_V1(証跡)
完全版は
docs/dev/test-lane-policy.mdのCI_TEST_PERFORMANCE_DECISION_V1 (#1193)セクションを参照。検証結果(iteration-3)
-k surface_registry-k pytest/-k locked_python_m_pytest-k python_script/-k unlocked_script-k exception_registry/-k exception_schema-k governed_surface/-k schema_validation-k exact_argv_prefix-k parseruv run --locked pytest <file>-k fixture_exclusion/markdown_policy_example/false_positive-k repo_scan_clean/ checker--strict-k ssot_targets_preserved/performance_decision_recorded-k heredoc_c_dependency-k compound_command-k unsupported_shell_grammar-k exact_argv_variant-k adversarialpnpm typecheck/lint/test(1156 tests) /build既存 guard test
test_decide_next_loop_action.py(33 件)も PASS。Ruff(--select E,F --ignore E402)もscripts/ci配下で pass。既知の波及(follow-up 必須・本 PR スコープ外)
.claude/settings.jsonの Bash permission allowlist はBash(uv run python3 .claude/skills/<edit-issue|post-merge-cleanup|create-issue>/scripts/*.py *)を前提としている。SKILL.md をuv run --locked python3 ...へ移行した結果、これら 3 skill の script 呼び出しが auto-approve から外れ permission prompt が発生する被覆縮退が生じる。.claude/settings.jsonとAGENTS.mdは Allowed Paths 外のため本 PR では変更していない。follow-up 推奨: allowlist に
Bash(uv run --locked python3 .claude/skills/<edit-issue|post-merge-cleanup|create-issue>/scripts/*.py *)を追加して auto-approve 被覆を回復する。Follow-up(merge 前の追跡対象)
OWNER review P1 の drift は後続 Issue として起票済み:
.claude/settings.jsonallowlist は #1229、AGENTS.mdprobe 実行例は #1232。いずれも #1193 の Allowed Paths 外のため本 PR スコープ外。本 PR の本文と差分は Claude Code により生成された。
🤖 Generated with Claude Code