Skip to content

実装: baseline_vc_preflight に VC 品質ガードを追加する #648

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "baseline_vc_preflight が Verification Commands の品質問題(rg option mismatch・broad search・compound command・unexpected pass)を contract review 時(implementation handoff 前)に検出し、甘い VC を完了扱いにしない"
change_kind: code

Parent Issue

none(単独改善)

Parent Goal Ref

  • Goal: VC が「実行可能」「対象が狭い」「baseline で誤 pass しない」「compound command に依存しない」ことを contract review 時に機械検証する
  • Desired Destination: rg --include="*.md" のような rg option mismatch、Allowed Paths より広い broad search、shlex 解析後の shell operator を含む compound command、既存資産への偶発ヒットを preflight で検出できる

Current Validated Scope

  • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py に VC 品質分類の追加(rg option mismatch / 広域検索 / 複合コマンド / 偶発 pass の検出強化)
  • .claude/skills/issue-contract-review/tests/ へ rg option mismatch / broad_search_path_unbounded(Allowed Paths 超過) / compound_command_disallowed(shell operator 検出) / unexpected pass の fixture / pytest 追加
  • 必要に応じて .claude/skills/issue-contract-review/SKILL.md の preflight blocker taxonomy 追記

Remaining Parent Gaps

なし

Outcome

baseline_vc_preflight.py が rg --include="*.md" のような rg_option_mismatch、Allowed Paths より広い broad_search_path_unbounded、shlex 解析後に shell operator token として現れる compound_command_disallowed、既存資産への偶発ヒットによる unexpected_pass を blocked として返し、それを検証する pytest が PASS している状態。

Background

Issue 本文の VC は review-issue / issue-contract-review / test-runner が逐語実行する前提だが、現状は以下の品質問題が起きうる。

  • rg --include="*.md" のように GNU grep 的な想定が混ざった rg コマンドが残る(rg では -g/--glob または -t/--type を使う)
  • Allowed Paths より広いパスへの検索で、対象ファイルと無関係な既存記述に偶発ヒットして baseline pass する
  • && / || / 裸の | を含む compound command が 1 VC に混在し、成功判定が曖昧になる

本 Issue では authoring guidance の prose 追加ではなく、baseline_vc_preflight.py 自体の blocker 分類を強化して「甘い VC を open issue に入れない」側へ倒す。

既存 taxonomy(SKILL.md)には unexpected_pass・compound_command_disallowed が既に定義されている。本 Issue はこれらの 発火条件・fixture・優先順位を補強する ものであり、新しい top-level JSON schema は追加しない。

In Scope

  • baseline_vc_preflight.py に rg_option_mismatch / broad_search_path_unbounded / compound_command_disallowed / unexpected_pass 強化の実装を追加する
  • rg argv[0] が rg である場合に限り --include / --include=... を rg_option_mismatch として blocker にする(--include-zero は対象外、grep --include は対象外)
  • rg の検索 path が Allowed Paths より広い、または path 未指定・repo root・docs root 等の場合を broad_search_path_unbounded として blocked にする(Allowed Paths が広域 docs を明示している場合は除外)
  • shlex 解析後に shell operator token(&& / || / 裸の | / ; / redirect)として現れる場合を compound_command_disallowed として blocked にする(quoted regex 内の foo|bar は compound とみなさない。foo\|bar は 実装: VC コマンドの正規表現メタ文字を shell pipe と誤判定しない検証を追加する #589 の regex_literal_pipe_suspected 挙動を維持する)
  • 既存資産に偶発ヒットして baseline pass する fixture を追加し、既存 unexpected_pass 分類が発火することを確認する
  • 上記分類を fixture pytest で固定する

Out of Scope

  • body-authoring.md への広範な authoring guidance 追記
  • 既存 open issue 本文の一括修正
  • guard-japanese-prose.sh の prose 判定
  • runtime verification policy の変更
  • 新しい top-level JSON schema の追加(既存 taxonomy 内での分類値の使用に限定する)

Acceptance Criteria

  • AC1: rg コマンドに --include / --include=... が含まれる場合、rg_option_mismatch として blocked になる。--include-zero は対象外。grep --include は対象外(rg に対する option mismatch のみ)
  • AC2: rg の検索 path が Allowed Paths より広い、または path 未指定・repo root・docs root 等の場合、broad_search_path_unbounded として blocked になる。Allowed Paths が広域 docs を明示している場合は除外される
  • AC3: shlex 解析後に shell operator token(&& / || / 裸の | / ;)として現れる場合、compound_command_disallowed として blocked になる。quoted regex alternation foo|bar は compound とみなさない。既存の regex_literal_pipe_suspected(実装: VC コマンドの正規表現メタ文字を shell pipe と誤判定しない検証を追加する #589)の挙動を壊さない
  • AC4: 既存資産への偶発ヒットで baseline exit_code=0 になるが VC が対象成果物を識別できない fixture を追加し、既存の unexpected_pass 分類として blocked になる(新しい top-level schema は追加しない)
  • AC5: AC1〜AC4 の分類を検証する fixture pytest が PASS する(test_rg_include_is_rg_option_mismatch_blocked / test_rg_include_zero_is_not_rg_option_mismatch / test_grep_include_is_not_rg_option_mismatch / test_regex_alternation_pipe_is_not_compound / test_shell_pipeline_is_compound_command_disallowed / test_rg_without_path_is_repo_wide_broad_search / test_rg_docs_root_is_broad_when_allowed_paths_are_specific / test_rg_specific_allowed_file_is_not_broad / test_existing_asset_hit_is_unexpected_pass を含む)

Verification Commands

# AC1
$ uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k "rg_include or rg_option_mismatch" -v
# AC2
$ uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k "broad_search or path_unbounded" -v
# AC3
$ uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k "compound or pipeline or alternation" -v
# AC4
$ uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k "unexpected_pass or existing_asset" -v
# AC5
$ uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -v
# 品質ゲート
$ pnpm typecheck
# 品質ゲート
$ pnpm lint
# 品質ゲート
$ pnpm test
# 品質ゲート
$ pnpm build
# 品質ゲート
$ uv run pytest .claude/skills/issue-contract-review/tests/ -v

Allowed 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 外の変更が必要と判明した場合
  • In Scope の固定契約(preflight JSON schema / blocker category 名)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

  • Python / pytest
  • ripgrep (rg) CLI semantics
  • Python shlex モジュール(shell operator token 解析)

Scope Delta(任意)

N/A

Delivery Rule

  • 1 Issue = 1 PR
  • Draft PR 既定

Runtime Verification Applicability

  • decision: not_applicable
  • reason: Python preflight script / tests / skill contract の変更のみであり、静的・ユニットテストで完結する

参考 Issue / Refs

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    area/ai-ops
    on Jun 3, 2026
  2. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    判定

    Issue #648 は方向性は正しいですが、このまま実装に渡すのは危険です。
    特に AC3 の | ブロック指定 と AC2 の docs/ 全体検索ブロック指定 が粗く、既存の関連 Issue で直した挙動を壊す可能性があります。結論としては 要件修正後に実装 が妥当です。

    Issue #648 自体は、baseline_vc_preflight に VC 品質ガードを追加し、rg --include="*.md"、docs/ 全体検索、compound command、既存資産への偶発 hit を検出する目的です。対象は .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py、同 tests、必要に応じて SKILL.md です。([GitHub]1) GitHub 上では、現時点で #648 に直接紐づく Branch/PR は表示されていません。([GitHub]1)


    致命的指摘

    1. AC3 は Issue #589 と衝突している

    #648 は && / || / | を含む compound command を blocker にするとしています。([GitHub]1)
    しかし #589 では、quoted regex の | を shell pipe と誤判定しないことが明確に要求されています。rg -n "foo|bar" は regex alternation であり、shell pipeline ではありません。#589 はさらに、rg -n "foo\|bar" のような literal pipe 疑いを regex_literal_pipe_suspected として扱う設計まで含んでいます。([GitHub]2)

    外部仕様上も、Rust regex の x|y は alternation です。([Docs.rs]3) 一方、escaped ASCII punctuation は literal 扱いなので \| は literal pipe になります。([Docs.rs]3)

    修正すべき AC3:

    AC3:
    shell operator token として shlex 解析後に現れる && / || / | / ; / redirect を
    compound_command_disallowed として block する。
    ただし quoted regex 内の foo|bar は compound とみなさない。
    foo\|bar は #589 の regex_literal_pipe_suspected の扱いを維持する。
    

    Python shlex は punctuation_chars=True により ();<>|& を shell punctuation として token 化できます。([Python documentation]4) したがって、生文字列検索で | を探す実装は禁止です。


    2. AC2 の “docs/ 全体検索 = broad search” は雑すぎる

    #648 は docs/ 全体や repo-wide path を broad search として blocker/要修正分類にするとしています。([GitHub]1)
    これは意図としては正しいですが、docs/ が常に悪いわけではありません。docs-only Issue では docs/ 配下の検証が正当な場合があります。#236 でも、問題は docs/ そのものではなく、rg | wc -l >= N のような 低識別力 VC です。([GitHub]5)

    実装方針はこう切るべきです。

    broad_search_path_unbounded:
    - rg に path 引数がない
    - path が . / repo root / docs/ / .claude/ など広すぎる
    - Allowed Paths より広い範囲を検索している
    - glob/type 指定だけで対象成果物を限定できていない
    
    例外:
    - Issue の Allowed Paths が docs/ 配下全体を明示している
    - 回帰ゲート用の既知コマンド
    - 個別ファイルまたは明示サブディレクトリ + 狭い glob に限定されている
    

    docs/ という文字列だけで blocker にすると、正当なドキュメント修正 Issue まで壊します。


    3. rg --include 検出は argv ベース・rg 限定で実装すべき

    #648 は rg --include="*.md" を blocker にする要求です。([GitHub]1)
    これは妥当です。ripgrep では GNU grep 的な --include ではなく、include/exclude には -g/--glob を使います。([Debian Manpages]6) また file type 制限には -t/--type が用意されています。([Debian Manpages]6)

    ただし実装で "include" の substring 検索をすると誤爆します。ripgrep には --include-zero という別オプションがあり、これは GNU grep の --include とは無関係です。([Debian Manpages]6)

    実装ルール:

    if argv[0] basename == "rg":
      block only:
        --include
        --include=...
      optionally:
        --exclude
        --exclude=...
        --exclude-dir
        --exclude-dir=...
    category: rg_option_mismatch
    hint: use -g/--glob or -t/--type
    

    grep --include まで blocker にしてはいけません。あくまで rg に対する option mismatch です。


    高リスク指摘

    4. unexpected_pass は既に SKILL.md の taxonomy に存在する

    #648 は unexpected_pass 相当分類の追加を求めていますが、現在の SKILL.md には既に unexpected_pass が分類として記載されています。([GitHub]7)
    したがって #648 は「分類名を追加する Issue」ではなく、既存分類が実際に発火する条件・fixture・優先順位を補強する Issue と明記すべきです。

    修正文言:

    既存 taxonomy の unexpected_pass を維持し、
    baseline 実行 exit_code=0 かつ VC が対象成果物を識別できない場合に
    blocked/unexpected_pass として返す。
    新しい top-level schema は追加しない。
    

    #648 の Stop Conditions でも JSON schema の後方互換性が要求されているため、既存 schema 内で分類値を増やす/使う方針に限定すべきです。([GitHub]1)


    5. #648 自身の Verification Commands が弱い

    #648 の VC は rg -n "include|option mismatch|rg" ... のような存在確認が中心です。([GitHub]1)
    これはまさに #648 が防ぎたい 偶発 pass の温床です。コメント、docstring、未使用関数、テスト名だけでも pass します。

    差し替えるべき VC は、grep ではなく fixture ベースの pytest です。

    uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -q

    最低限、次のテストを要求すべきです。

    test_rg_include_is_rg_option_mismatch_blocked
    test_rg_include_zero_is_not_rg_option_mismatch
    test_grep_include_is_not_rg_option_mismatch
    test_regex_alternation_pipe_is_not_compound
    test_shell_pipeline_is_compound_command_disallowed
    test_rg_without_path_is_repo_wide_broad_search
    test_rg_docs_root_is_broad_when_allowed_paths_are_specific
    test_rg_specific_allowed_file_is_not_broad
    test_existing_asset_hit_is_unexpected_pass
    

    #201 でも、--paths 指定で discovery script が自明 PASS する問題が実害として扱われています。([GitHub]8) #648 の VC が token existence check のままだと、同じ失敗を繰り返します。


    6. Scope が “起票前” と言いながら issue-contract-review に閉じている

    #648 は「起票前に検出」と書いていますが、Allowed Paths は issue-contract-review の preflight 実装と tests、必要に応じて SKILL.md に限定されています。([GitHub]1)
    一方、#589 では issue body authoring や test-runner の verbatim 実行まで含めて扱っていました。([GitHub]2)

    ここは要件が曖昧です。

    • 本当に起票前に止めるなら、create-issue / body-authoring / contract readiness 側も対象に入れるべき。
    • issue-contract-review の preflight だけなら、「起票前」ではなく「implementation handoff 前」または「contract review 時」と書くべき。

    この曖昧さを残すと、実装者が Allowed Paths を超えて Stop Conditions に引っかかるか、逆に必要な統合箇所を触らずに完了扱いにします。


    関連 Issue から見た設計方針

    #648 は単独 Issue として扱うべきではありません。少なくとも次を明示的に Refs に入れるべきです。

    Refs #201
    Refs #578
    Refs #589
    Refs #236
    

    理由は以下です。


    推奨する Issue #648 修正版

    追加カテゴリ

    rg_option_mismatch
    broad_search_path_unbounded
    compound_command_disallowed
    unexpected_pass
    

    compound_command_disallowed と unexpected_pass は既存 taxonomy に合わせる。新しい JSON schema は追加しない。

    優先順位

    1. unsupported_shell_syntax
    2. unsafe_command / command_not_allowed
    3. rg_option_mismatch
    4. compound_command_disallowed
    5. regex_literal_pipe_suspected
    6. trivially_pass
    7. broad_search_path_unbounded
    8. execution result based expected_fail / unexpected_pass / human_judgment
    

    ただし compound_command_disallowed は shlex 解析後の shell operator token に限定すること。

    修正 AC 案

    AC1:
    rg command に --include / --include=... が含まれる場合、
    rg_option_mismatch として blocked。
    --include-zero は対象外。
    
    AC2:
    rg の検索 path が Allowed Paths より広い、または path 未指定/repo root/docs root 等の場合、
    broad_search_path_unbounded として blocked。
    ただし Allowed Paths が広域 docs を明示している場合は除外。
    
    AC3:
    shell operator token として && / || / | / ; / redirect が出現する場合、
    compound_command_disallowed として blocked。
    quoted regex alternation foo|bar は compound としない。
    既存の regex_literal_pipe_suspected 挙動を壊さない。
    
    AC4:
    baseline 実行が exit_code=0 でも、既存資産への偶発 hit で VC が対象成果物を識別できない fixture を
    unexpected_pass として blocked に分類する。
    
    AC5:
    上記を fixture pytest で検証する。
    token grep だけの VC は不可。
    

    最終評価

    この Issue は実装価値あり。ただし現状のままでは “VC 品質ガードを作る Issue” 自体が低品質 VC で完了できてしまう。

    着手条件は次の4点です。

    1. AC3 を 実装: VC コマンドの正規表現メタ文字を shell pipe と誤判定しない検証を追加する #589 非回帰仕様に修正する。
    2. AC2 の broad search を deterministic な path/Allowed Paths 判定に落とす。
    3. rg --include は argv ベース・rg 限定で検出する。
    4. VC を rg 存在確認から fixture pytest に差し替える。

    この修正なしに implementer へ渡すと、quoted regex pipe の既存修正を壊すか、docs/ を雑に blocker 化して正当な Issue を止める可能性が高いです。

  3. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-06-06T00:19:00Z)

    • Outcome: baseline_vc_preflight.py が rg_option_mismatch / broad_search_path_unbounded / compound_command_disallowed / unexpected_pass 強化を実装し、それを検証する pytest が PASS している状態
    • Acceptance Criteria:
      1. AC1: rg --include / --include=... → rg_option_mismatch blocked(--include-zero / grep --include は除外)
      2. AC2: rg の検索 path が Allowed Paths より広い・path 未指定・repo root・docs root → broad_search_path_unbounded blocked(Allowed Paths が広域 docs を明示している場合は除外)
      3. AC3: shlex 解析後の shell operator token (&& / || / 裸の | / ;) → compound_command_disallowed blocked(quoted regex alternation は除外・実装: VC コマンドの正規表現メタ文字を shell pipe と誤判定しない検証を追加する #589 挙動維持)
      4. AC4: 既存資産への偶発ヒットで baseline exit_code=0 だが対象成果物を識別できない fixture → unexpected_pass blocked
      5. AC5: AC1〜AC4 を検証する fixture pytest が PASS する(指定 9 テスト名を含む)
    • Verification Commands:
      • AC1: uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k "rg_include or rg_option_mismatch" -v
      • AC2: uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k "broad_search or path_unbounded" -v
      • AC3: uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k "compound or pipeline or alternation" -v
      • AC4: uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k "unexpected_pass or existing_asset" -v
      • AC5: uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -v
      • 品質ゲート: pnpm typecheck / pnpm lint / pnpm test / pnpm build / uv run pytest .claude/skills/issue-contract-review/tests/ -v
    • Allowed Paths:
      • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
      • .claude/skills/issue-contract-review/tests/
      • .claude/skills/issue-contract-review/SKILL.md
    • Worktree: .claude/worktrees/issue-648-baseline-vc-preflight-vc
    • Branch: worktree-issue-648-baseline-vc-preflight-vc
    • VC preflight: baseline fail = 5, 想定外 pass = 0, 実行不可 = 0, regression gate = 5 (pass)
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-06T00:19:00Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/648
      body_sha256: "sha256:fad4cf9007645419be688c2931834e68fdecbeb69643da112031fab6bfeae147"
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 5
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 5
          vc_skipped: 0
          classifications:
            - ac: AC1
              command: "uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k \"rg_include or rg_option_mismatch\" -v"
              exit_code: 4
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC2
              command: "uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k \"broad_search or path_unbounded\" -v"
              exit_code: 4
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC3
              command: "uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k \"compound or pipeline or alternation\" -v"
              exit_code: 4
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC4
              command: "uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -k \"unexpected_pass or existing_asset\" -v"
              exit_code: 4
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC5
              command: "uv run pytest .claude/skills/issue-contract-review/tests/test_vc_quality_guards.py -v"
              exit_code: 4
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC_UNKNOWN
              command: "pnpm typecheck"
              exit_code: 0
              classification: expected_pass
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
            - ac: AC_UNKNOWN
              command: "pnpm lint"
              exit_code: 0
              classification: expected_pass
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
            - ac: AC_UNKNOWN
              command: "pnpm test"
              exit_code: 0
              classification: expected_pass
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
            - ac: AC_UNKNOWN
              command: "pnpm build"
              exit_code: 0
              classification: expected_pass
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
            - ac: AC_UNKNOWN
              command: "uv run pytest .claude/skills/issue-contract-review/tests/ -v"
              exit_code: 0
              classification: expected_pass
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings: []
  4. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-06-06)

  5. added 2 commits that reference this issue on Jun 5, 2026
  6. added a commit that references this issue on Jun 5, 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/implementerarea/ai-opsenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions