Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasestate/queuedQueued for implementationworkflowWorkflow / skill automation changes
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#244"
goal_ref: "baseline_vc_preflight.py の VC format contract を fenced bash block として確定し、unsafe command 実行 policy を明文化・強制する"
change_kind: workflowParent Issue
#244 — 導入: Issue/PR body authoring 機械検証化 親トラッカー
Parent Goal Ref
- Goal: Issue body 由来コマンドの安全な実行境界と、VC 抽出フォーマットの canonical 仕様を確定する
- Desired Destination: baseline_vc_preflight.py が安全・明確な contract で動作し、導入: Issue/PR body authoring 機械検証化 親トラッカー — validator・linter・preflight スクリプトによる体系的品質保証 #244 Track B の品質保証が完結する
Current Validated Scope
.claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py:classify_static_command()追加、allowlist/denylist 実装、unsupported shell syntax の blocked 分類、error schema 構造化.claude/skills/issue-contract-review/SKILL.md: category table へのunsupported_shell_syntax追加、canonical VC format 明記.claude/skills/issue-contract-review/tests/: command safety・blocked classification・error schema の unit test 追加
Remaining Parent Gaps
- validate_issue_body.py / authoring linter の実装(導入: Issue/PR body authoring 機械検証化 親トラッカー — validator・linter・preflight スクリプトによる体系的品質保証 #244 Track A)
- canonical VC format の authoring SSOT 変更(
.claude/skills/create-issue/references/body-authoring.md等)— 別 Issue
Background
PR #354(merged 2026-05-24)で baseline_vc_preflight.py は実装済みだが、以下の未解決課題がある。
- VC format contract の不一致: Issue feat: baseline VC preflight helper script を issue-contract-review と impl-review-loop で共有する #234 元契約は「
-リスト形式 +# AC<N>マーカー」を指定していたが、実装はextract_fenced_bash_blocks()で fenced bash block を抽出する。この差分を明文化しないと、Issue authoring 側と preflight 側が断絶する。 - unsafe command 実行 policy が未整備:
subprocess.run(shell=False)は採用済みだが、Issue body 由来の任意コマンドを allowlist/denylist で制限する policy がない。shlex.split()+shell=Falseは shell injection を減らすが、rm、git push、curl、bash -cのような危険な argv[0] そのものを止めない。 - command substitution の fail-open 分類:
$(...), backtick,${...}を検出してもexpected_fail→goに分類するため、実行前に blocked にならない。 - error schema が構造化されていない:
errors: ["string"]形式は修正 agent に不親切。{kind, rule, message, minimal_context, fix_hint}形式に統一が必要。 unsupported_shell_syntaxcategory が未定義: SKILL.md category table と script の category enum に存在せず、contract drift が残る。
Outcome
baseline_vc_preflight.py が以下を満たす状態になる。
- fenced bash block を canonical VC format として SKILL.md に明記されている
- command allowlist / denylist / mutation policy が実装・文書化されている(allowlist 外は default blocked)
$(...), backtick,${...}はrun_command()を呼ばずunsupported_shell_syntax / blockedに分類される- extraction error が
{kind, rule, message, minimal_context, fix_hint}形式で出力される - SKILL.md category table と script category enum が
unsupported_shell_syntaxを含み一致する
In Scope
baseline_vc_preflight.py: 実行前 static classification の追加(classify_static_command())、allowlist/denylist 実装、unsupported shell syntax を blocked 分類、error schema 構造化issue-contract-review/SKILL.md: category table へのunsupported_shell_syntax追加、「fenced bash VC が canonical」明記baseline_vc_preflight.pyの unit test 追加(command allowlist/denylist, blocked classification, error schema)
Out of Scope
- CI/CD への組み込み
- GitHub Actions workflow の変更
- bullet-list VC format の後方互換サポート(別 Issue で判断)
--allow-mutatingフラグの実装(scope 外)- canonical VC format の authoring SSOT 変更(
.claude/skills/create-issue/references/body-authoring.md等)— 本 Issue はissue-contract-review側の暫定明文化のみ。authoring SSOT との整合は別 Issue で対応する
Acceptance Criteria
- AC1:
$(...), backtick,${...}を含む VC コマンドはrun_command()を呼ばず、classification=blocked, category=unsupported_shell_syntax, decision=blockedになる - AC2:
bash,sh,zsh,python -c,python3 -c,node -e,curl,wget,rm,mv,cp,chmod,git push,git commit,gh api,gh issue edit,pnpm add,npm installはrun_command()を呼ばずcategory=unsafe_command または command_not_allowed, decision=blockedになる - AC3: allowlist に含まれないコマンドは default で
command_not_allowed / blockedになる - AC4:
errors[]の全要素が{kind, rule, message, minimal_context, fix_hint}を持つ object である(string 要素は schema test で検出・拒絶される) - AC5:
issue-contract-review/SKILL.mdの category table にunsupported_shell_syntaxが追加され、script の category enum と一致する - AC6: 追加したロジックに対応する unit test が pass する
- AC7:
issue-contract-review/SKILL.mdに「VC は## Verification Commandsセクション内の fenced bash block が canonical」と明記される
Verification Commands
# AC1
$ uv run pytest .claude/skills/issue-contract-review/tests/ -v -k "test_command_substitution_is_blocked_without_execution or test_backtick_is_blocked_without_execution or test_parameter_expansion_is_blocked_without_execution"
# AC2
$ uv run pytest .claude/skills/issue-contract-review/tests/ -v -k "test_shell_invocation_is_blocked or test_python_dash_c_is_blocked or test_network_commands_are_blocked or test_git_mutation_is_blocked or test_filesystem_mutation_is_blocked"
# AC3
$ uv run pytest .claude/skills/issue-contract-review/tests/ -v -k "test_unknown_command_is_blocked_by_default"
# AC4
$ uv run pytest .claude/skills/issue-contract-review/tests/ -v -k "test_extraction_errors_are_structured or test_error_schema_rejects_string_errors"
# AC5
$ uv run pytest .claude/skills/issue-contract-review/tests/ -v -k "test_skill_category_table_mentions_unsupported_shell_syntax"
# AC6
$ uv run pytest .claude/skills/issue-contract-review/tests/ -v
# AC7
$ rg "fenced bash.*canonical|canonical.*fenced bash|canonical VC format|fenced bash ブロック.*canonical" .claude/skills/issue-contract-review/SKILL.mdAllowed Paths
.claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py.claude/skills/issue-contract-review/tests/.claude/skills/issue-contract-review/SKILL.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合(authoring SSOT の変更を含む)
--allow-mutatingフラグ実装など In Scope 外の追加が必要になった場合- bullet-list VC 互換の scope 判断が必要になった場合
- canonical VC format の authoring SSOT 変更(
.claude/skills/create-issue/references/body-authoring.md等)が必要と判明した場合 → 停止して別 Issue 起票を推奨 - allowlist の精度(過剰 block / 過少 block)について人間判断が必要と判明した場合
- error schema の JSON Schema 定義を別ファイル分離する必要が出た場合
Runtime Verification Applicability
decision: not_applicable
reason: 本 Issue は .claude/skills/ 配下の script/test の変更のみ。実行環境での動的検証は不要。
Required Skills
- Python 3 / pytest
- subprocess 安全性 / shlex 解析
- JSON Schema 設計
Source
- origin_issue: feat: baseline VC preflight helper script を issue-contract-review と impl-review-loop で共有する #234 (superseded)
- origin_anchor_comment: feat: baseline VC preflight helper script を issue-contract-review と impl-review-loop で共有する #234 (comment)
- dedupe_key:
baseline-vc-preflight-contract-and-safety-policy
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasestate/queuedQueued for implementationworkflowWorkflow / skill automation changes
Activity
squne121 commentedon May 30, 2026
結論: #514 は方向性は正しいが、このまま実装Issueとして流すと不十分です
判定は REFINE / REQUEST_CHANGES。
理由は、#514 が解こうとしている問題は「ドキュメント表現の整理」ではなく、Issue本文由来コマンドを実行する信頼境界の設計だからです。現行
baseline_vc_preflight.pyはshlex.split()後にsubprocess.run(..., shell=False)で実行しますが、これは shell injection を減らすだけで、rm、git push、curl、bash -cのような危険な実行対象そのものを止めるものではありません。現行コードにも allowlist らしきものは見当たらず、argv = shlex.split(command)の後にそのままsubprocess.run(argv, ..., shell=False)へ渡しています。([GitHub]1)#514 の問題意識自体は正しいです。Issueは、PR #354 で
baseline_vc_preflight.pyは実装済みだが、VC形式契約の不一致、unsafe command policy 不在、$(...)/ backtick /${...}の fail-open 分類、errors: ["string"]の非構造化という未解決課題を明示しています。([GitHub]2) ただし、Acceptance Criteria がまだ「文字列が存在するか」寄りで、危険コマンドが実行前に確実に止まることを証明しきれていません。([GitHub]2)致命的ブロッカー
B1.
shell=Falseを安全境界と誤認しているPython公式ドキュメントは、
argsは通常 sequence で渡すことを推奨し、shell=Trueの場合は shell injection に注意せよとしています。一方で、shell=Falseは「shell メタ文字が shell で解釈されない」だけで、任意の実行ファイルを安全化する仕組みではありません。([Python documentation]3) OWASP も、OSコマンドを避けられない場合は「コマンド自体を allowlist で検証し、引数も positive validation する」ことを要求しています。([OWASP Cheat Sheet Series]4)したがって #514 は、単に
bash,sh,curl,wget,rm,mv,git push,gh apiを denylist するだけでは弱いです。実行可能な command family を allowlist で限定し、それ以外はcommand_not_allowed / blockedにするべきです。最低限の方針:
B2. 現行の command substitution 分類が #514 のゴールと正面衝突している
#514 は
$(...), backtick,${...}をunsupported_shell_syntax / blockedにしたいと書いています。([GitHub]2) しかし現行コードはhas_command_substitution(command)が true の場合、expected_fail / expected_baseline_fail / goを返しています。これは #514 の中心目的と逆です。([GitHub]1)修正方針:
この分岐は
run_command()より前に置く必要があります。PR #354 の敵対的レビューでも「実行前 fail-closed」が重要ブロッカーとして扱われ、compound command を run 前に止める修正が入った経緯があります。([GitHub]5)B3.
unsupported_shell_syntaxが schema / SKILL.md に存在しない現行
issue-contract-review/SKILL.mdの category 一覧はfile_not_found_expected,file_not_found_unrunnable,env_missing_dep,expected_baseline_fail,compound_command_disallowed,timeout,unexpected_pass,unknownなどで、unsupported_shell_syntaxは定義されていません。([GitHub]6) 現行コード側の docstring でも category enum にunsupported_shell_syntaxはありません。([GitHub]1)#514 では、以下を同時に更新しないと contract drift が残ります。
B4.
errors[]構造化のACが弱い現行コードは retrieval / extraction error を
errors: [文字列]で返しています。例としてerrors: [error_code or "failed_to_retrieve_issue_body"]、errors: ["Verification Commands section not found"]、errors: ["No verification commands extracted from Verification Commands section"]が残っています。([GitHub]1) #514 の要求は{kind, rule, message, minimal_context, fix_hint}なので、単にfix_hint|minimal_contextをrgで確認するACでは不十分です。([GitHub]2)必要な出力例:
{ "kind": "extraction_error", "rule": "VC001_NO_FENCED_BASH_BLOCK", "message": "No fenced bash block found under ## Verification Commands.", "minimal_context": "## Verification Commands\n...", "fix_hint": "Add a fenced ```bash block containing one command per line." }加えて、retrieval error と extraction error は分けるべきです。
gh_auth_failedやbody_file_not_foundは extraction ではなく input/retrieval error です。B5. canonical VC format の正本更新先が不足している
#514 は「fenced bash block を canonical VC format として SKILL.md と feature spec に明記」と言っていますが、Allowed Paths は
issue-contract-review/SKILL.md、script、tests だけです。([GitHub]2) 一方、#234 の旧契約は-リスト形式 +# AC<N>マーカーを明示していました。([GitHub]7) #329 では parser grammar が## Verification Commands内の fenced bash block に寄っています。([GitHub]8)ここを
issue-contract-review/SKILL.mdだけで直すと、authoring 側の正本と review 側の実行器だけがズレたままになります。親 #244 は、Issue/PR body authoring を validator / linter / preflight script で機械検証し、AIに渡す修正コンテキストを failing rule + minimal_context に限定することを目標にしています。([GitHub]9) したがって、本当に canonical を確定するなら、少なくとも authoring 側の参照文書または validator 側との整合確認が必要です。修正案:
#514 に追加すべき Acceptance Criteria
現行ACは
rgで文字列存在を確認するものが多く、危険挙動を証明できません。以下を入れるべきです。テスト名例:
実装設計の推奨
classify_result(exit_code, ...)に押し込むのではなく、実行前分類と実行後分類を分けるべきです。そのうえで main loop はこうするべきです。
shlexは Unix shell 向けであり、非POSIX shellやWindows shellでは安全性が保証されない旨が Python docs に明記されています。([Python documentation]10) このプロジェクトで Linux/WSL 前提にするなら、その前提も SKILL.md に明記してください。貼り付け用レビューコメント
squne121 commentedon May 30, 2026
Contract Snapshot (2026-05-30T13:47:11Z)
Contract Summary
uv run pytest(baseline fail = tests not found = expected)、AC7:rg(no match = expected).claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py,.claude/skills/issue-contract-review/tests/,.claude/skills/issue-contract-review/SKILL.md.claude/worktrees/issue-514-baseline-vc-preflight-py-vc-format-contrworktree-issue-514-baseline-vc-preflight-py-vc-format-contrsqune121 commentedon May 30, 2026
implement-issue: 実装完了 ($(date -u +%Y-%m-%dT%H:%M:%SZ))
fix(#514): update test_human_judgment_not_collapsed_to_needs_fix for …
squne121 commentedon May 30, 2026
implement-issue: iteration 1 修正完了 (2026-05-30T14:04:38Z)
worktree-issue-514-baseline-vc-preflight-py-vc-format-contrtest_human_judgment_not_collapsed_to_needs_fixをcommand_not_allowed分類も受け入れるよう更新squne121 commentedon May 30, 2026
impl-review-loop 完了 (iteration 1)
LOOP_VERDICT: APPROVE — PR #523 が pr-review-judge により承認されました。
実装サマリ
classify_static_command()追加:$(...), backtick,${...}およびbash/sh/curl/wget/rm/git push等をrun_command()呼び出し前に blocked 分類errors[]を構造化オブジェクト{kind, rule, message, minimal_context, fix_hint}に変更SKILL.mdに fenced bash block = canonical VC format 明記、unsupported_shell_syntaxを category table に追加tests/test_vc_format_and_command_policy.py)検証結果
511191f418f4da6b1f55581418caacf053d6618bPR
#523
次のアクション
PR のマージは人間が判断してください。merge_state_status: BEHIND のため、マージ前に branch update を推奨します。
fix(#514): iteration 2 — pnpm/git/gh exact allowlist, mkdir removal, …
fix(#514): baseline_vc_preflight.py に VC format contract と unsafe com…