Skip to content

実装: issue-refinement preflight wrapper(run_refinement_preflight.py)を追加し planner 入力契約を固定化する #792

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#791"
goal_ref: "agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する"
change_kind: workflow

Parent Issue

#791

Parent Goal Ref

Current Validated Scope

  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py を新規追加する
  • .claude/skills/issue-refinement-loop/schemas/refinement_preflight_input.schema.json を新規追加する
  • .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json を新規追加する(strict: additionalProperties: false)
  • .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py と fixtures を新規追加する
  • .claude/skills/issue-refinement-loop/SKILL.md の planner 実行記述を wrapper 経由に置換する

Remaining Parent Gaps

Background

Issue #781 の refinement loop 実行ログで、agent が plan_refinement_loop.py を direct flags で実行して exit code 2 になり、--help 表示・SKILL/script 再読・gh 再取得を経て stdin 形式で再実行する無駄が観測された。planner の入力契約(stdin JSON / anchor comment / read plan)を agent が推測する余地をなくすため、Issue/comment fetch・anchor validation・planner stdin 組立・read plan 出力を一括化する決定論的 entrypoint を追加する。

  • plan_refinement_loop.py は判断ロジックの SSOT として残し、wrapper は planner を呼ぶ薄い adapter に限定する(二重 SSOT 化しない)
  • raw issue body / raw comments は artifact(.claude/artifacts/issue-refinement-loop/<N>/)に保存し、stdout には agent-friendly compact projection のみを出す。機械判定の正本は artifact JSON(refinement_preflight_result_v1.schema.json 準拠)とし、stdout は同 artifact の短縮投影に限定する(責務分離)
  • exit code 規約: 0 pass / 1 warn / 2 blocked / 3 environment_failure

Planner ↔ Wrapper Exit Code Mapping

planner(plan_refinement_loop.py)の既存契約: exit 0 = success(fail_closed.required == true の場合も exit 0)、exit 2 = invalid input、exit 3 = internal error。

条件 wrapper status wrapper exit
anchor comment が対象 issue に属さない blocked 2
gh 未導入・未認証・権限不足・API 失敗・非 JSON・timeout environment_failure 3
planner exit 2(invalid input) blocked 2
planner exit 3(internal error) environment_failure 3
planner exit 0 かつ fail_closed.required == true blocked 2
planner exit 0(通常) pass 0
planner exit 0 + human note 必要 warn 1

fail_closed.required == true を blocked / 2 とする理由: planner が判断できない状態は human stop 運用と整合させ、wrapper が自動続行しない。

Outcome

run_refinement_preflight.py と入力 schema・result schema(refinement_preflight_result_v1.schema.json)・pytest が追加され、issue-refinement-loop/SKILL.md の planner 直接起動記述が wrapper 1 コマンドに置換され、uv run pytest と pnpm 品質ゲートが全 PASS した状態のコミットが作成されている。

In Scope

  • run_refinement_preflight.py の新規実装
    • --issue-number <N> / --anchor-comment-url <URL>(複数可)/ --repo <owner/name> を受け取る
    • gh issue view / gh api による Issue 本文・コメント取得を本 script に集約する
    • anchor comment の構造検証: URL substring 判定を禁止し、以下をすべて確認する
      • URL の owner/repo が --repo と一致すること
      • issue number が --issue-number と一致すること
      • comment id が実在すること
      • comment の issue_url(REST レスポンスフィールド)が同一 issue を指すこと
      • PR review comment(別 endpoint)でないこと
      • 複数 anchor は stable sort + dedupe を行い、1 件でも mismatch なら全体 blocked
    • 不一致なら STATUS: blocked / BLOCKERS: ANCHOR_NOT_IN_ISSUE / exit 2 を返す
    • plan_refinement_loop.py に正しい stdin JSON を渡し、結果を agent-friendly stdout に整形する(stdout は artifact JSON の compact projection に限定)
    • raw issue snapshot / planner input は artifact JSON に保存する(.claude/artifacts/issue-refinement-loop/<issue_number>/。issue_number は int 正規化し、repo 名や URL から path を生成しない)
    • テスト用に --fixture <path>(gh 呼び出しを伴わない snapshot 入力)を提供する
    • commands[] は kind / argv: string[] / shell: false / source: "static_wrapper_template" フィールドのみ。shell command string を出力しない。issue/comment 由来文字列を argv に混ぜない
    • 内部実装: subprocess.run([...], shell=False, timeout=..., capture_output=True, text=True) に限定。planner 起動は uv run をネストせず sys.executable で sibling script を呼ぶ(publish_termination_report.py L123-125 と同方式)
  • result schema の外出し(schemas/refinement_preflight_result_v1.schema.json)
    • strict(additionalProperties: false)、最低限フィールド: schema_version: "refinement_preflight_result/v1" / status: pass|warn|blocked|environment_failure / issue_number / repo / planner_exit_code / planner_fail_closed / next_action / must_read[] / do_not_read[] / commands[] / blockers[] / artifacts{} / hashes{}
  • stdin schema の外出し(schemas/refinement_preflight_input.schema.json)
  • pytest(正常系 / anchor 不一致 / raw 出力抑制 / exit code 規約 / result schema 検証 / mapping 分岐網羅 / byte-stable fixture / argv-only commands / mock environment_failure)。テストは ACn6〜ACn12 の VC rg キーワード(refinement_preflight_result_v1 / exit_code_mapping / substring / sentinel / byte_stable / argv / environment_failure)をテストコード内に含める。
  • SKILL.md の planner 実行手順を wrapper 1 コマンド + 出力フィールド追従指示に置換する

Out of Scope

Acceptance Criteria

  • AC1: run_refinement_preflight.py が存在し、fixture 入力で STATUS / NEXT_ACTION / MUST_READ / COMMANDS / BLOCKERS / ARTIFACT を含む stdout を返すことが pytest で検証されている
  • AC2: 対象 Issue に属さない anchor comment URL を渡した fixture で exit code 2 と ANCHOR_NOT_IN_ISSUE blocker を返すことが pytest で検証されている
  • AC3: raw issue body / raw comments が stdout に含まれず artifact JSON に保存されることが pytest で検証されている
  • AC4a: .claude/skills/issue-refinement-loop/SKILL.md の Step 0f(planner 実行記述)が wrapper 1 コマンド例(uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py を含む)を含むことが rg で検証されている(baseline で fail する positive rg)
  • AC4b: .claude/skills/issue-refinement-loop/SKILL.md に scripts/plan_refinement_loop.py を直接起動する実行例が追加されていない(negation rg による static guard。plan_refinement_loop.py の SSOT 言及 prose は許容)
  • AC5: pnpm typecheck / lint / test / build が全 PASS する
  • AC6: result schema が存在し、stdout compact projection と artifact JSON が同一 status / blockers / next_action を表すことが pytest で検証されている
  • AC7: planner↔wrapper exit code mapping の全分岐(mapping table の各行)が pytest fixture で検証されている
  • AC8: anchor URL parser が構造検証であり substring 判定を含まないことがテストで検証されている
  • AC9: raw issue body / comment に仕込んだ sentinel 文字列が stdout に出ない(例外・schema validation error・gh stderr 経由でも)ことが pytest で検証されている
  • AC10: --fixture 実行がネットワーク・gh 認証に依存せず、同一 fixture から byte-stable な result artifact を生成することが pytest で検証されている
  • AC11: commands[] が argv 配列のみで shell string を含まないことが pytest で検証されている
  • AC12: gh 未導入・未認証・権限不足・非 JSON・timeout が environment_failure exit 3 になることが pytest(fixture/mock)で検証されている

Verification Commands

# AC1
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py -v
# AC2
$ rg -n "ANCHOR_NOT_IN_ISSUE" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
# AC3
$ rg -n "raw_issue_snapshot" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
# AC4a(baseline で fail する positive rg — ファイル未作成時は exit 2 が期待される baseline fail)
$ rg -n "uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight\.py" .claude/skills/issue-refinement-loop/SKILL.md
# AC4b(static guard: plan_refinement_loop.py の直接起動コマンド例が SKILL.md に存在しないことを検証)
$ ! rg -n '^\s*(?:\$ )?uv run python3\s+\.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop\.py\b' .claude/skills/issue-refinement-loop/SKILL.md
# AC5
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build
# AC6
$ rg -n "refinement_preflight_result_v1" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
# AC7
$ rg -n "exit_code_mapping" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
# AC8
$ rg -n "substring" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
# AC9
$ rg -n "sentinel" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
# AC10
$ rg -n "byte_stable" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
# AC11
$ rg -n "argv" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
# AC12
$ rg -n "environment_failure" .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py

Runtime Verification Applicability

decision: not_applicable
reason: >-
  本 Issue の変更対象はすべて Python script / JSON schema / pytest fixture であり、
  プロセス起動・ネットワーク通信・UI 描画を伴わない。
  静的解析(typecheck / lint)と unit test(pytest)で完結するため、
  runtime 動作検証(immediate / deferred)は不要と判定する。

Allowed Paths

  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py(新規)
  • .claude/skills/issue-refinement-loop/schemas/refinement_preflight_input.schema.json(新規)
  • .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json(新規)
  • .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py(新規)
  • .claude/skills/issue-refinement-loop/fixtures/(fixture 追加のみ)
  • .claude/skills/issue-refinement-loop/SKILL.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • plan_refinement_loop.py 本体の変更が必要と判明した場合(wrapper 側で吸収できない契約不整合)

Required Skills

なし

Scope Delta(任意)

Current Validated Scope はファイル単位の列挙、In Scope は挙動契約の列挙であり、対象ファイル集合は一致している(乖離はトークン粒度の差のみ)。

Delivery Rule

Notes for Reviewer

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jun 10, 2026
  2. squne121 commented on Jun 10, 2026

    @squne121
    OwnerAuthor

    結論

    Issue #792 は実装価値がありますが、現状のまま着手すると plan_refinement_loop.py の失敗を wrapper 側の新しい曖昧さに移すだけです。判定は REQUEST_CHANGES 相当です。

    #792 は、#781 の refinement loop で planner CLI の呼び出し推測・失敗・再読・再実行が発生したことを受け、run_refinement_preflight.py を追加して gh issue view / gh api から issue/comment を取得し、planner 入力を生成し、stdout を STATUS / NEXT / MUST_READ / DO_NOT_READ / COMMANDS / BLOCKERS に整える提案です。狙い自体は #791 の「zero failed preflight」「compact stdout」「raw subagent output削減」と整合します。(GitHub)

    ただし既存の #392 で plan_refinement_loop.py はすでに SSOT として、stdin schema、stdout schema、exit code、fail_closed の意味、責務境界を持っています。#792 はこの既存契約との接続仕様が未定義です。ここを先に固定しないと、wrapper が第二の planner になります。(GitHub)


    主要ブロッカー

    1. wrapper の出力 schema がない

    #792 は refinement_preflight_input.schema.json の追加を求めていますが、肝心の wrapper 出力、つまり REFINEMENT_PREFLIGHT_RESULT_V1 相当の schema がありません。stdout に uppercase field を出すだけでは、agent と test がまた自然言語パースに戻ります。JSON Schema 側は additionalProperties: false で未知キーを拒否できるため、wrapper result も strict schema にすべきです。(GitHub)

    修正案: Allowed Paths に以下を追加してください。

    .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json
    

    最低限の result schema は次を持つべきです。

    schema_version: "refinement_preflight_result/v1"
    status: "pass" | "warn" | "blocked" | "environment_failure"
    issue_number
    repo
    planner_exit_code
    planner_fail_closed
    next_action
    must_read[]
    do_not_read[]
    commands[]
    blockers[]
    artifacts{}
    hashes{}
    

    stdout はこの JSON artifact の短縮投影に限定し、完全な機械判定は artifact を読む設計にするべきです。


    2. exit code の意味が planner と wrapper で衝突している

    既存 planner は 0 = success、2 = invalid input、3 = internal error で、fail_closed: true でも exit code は 0 という契約です。#792 は wrapper 側で 0 pass / 1 warn / 2 blocked / 3 environment failure を導入しようとしています。これは悪くありませんが、mapping table が必須です。(GitHub)

    追加すべき mapping:

    条件 | wrapper status | wrapper exit -- | -- | -- anchor comment が対象 issue に属さない | blocked | 2 gh 未インストール・未認証・API失敗・非JSON | environment_failure | 3 planner exit 2 | blocked または environment_failure を明文化 | 2 or 3 planner exit 3 | environment_failure | 3 planner exit 0 かつ fail_closed.required=true | blocked | 2 planner exit 0 かつ通常 plan | pass | 0 planner exit 0 だが human note が必要 | warn | 1

    特に fail_closed を pass 扱いにすると、現行 SKILL.md の「fail_closed は human stop」という運用と食い違います。(GitHub)


    3. anchor comment validation が甘いと、誤Issue・誤PRコメントを拾う

    #792 は --anchor-comment-url を複数受け取り、anchor が issue に属さない場合に ANCHOR_NOT_IN_ISSUE で block する方針です。これは重要ですが、URL substring 判定では不足です。gh issue view --comments --json は issue 本文や comments を取得できますし、gh api は REST endpoint を直接叩けるので、comment id から .issue_url を検証する実装にすべきです。(GitHub)

    検証条件は最低限これです。

    - URL の owner/repo が --repo と一致する
    - URL の issue number が --issue-number と一致する
    - comment id が実在する
    - comment の issue_url が同一 owner/repo/issues/{issue_number}
    - pull request review comment ではない
    - 複数 anchor は stable sort + dedupe
    - 1件でも mismatch なら全体を blocked
    

    GitHub issue/comment 本文は信頼できない入力なので、COMMANDS に raw body/comment 由来の文字列を混ぜないことも明記してください。


    4. COMMANDS 出力は shell injection と誤実行の温床

    #792 の wrapper は agent に次のコマンドを提示する設計ですが、GitHub issue/comment は外部入力です。COMMANDS は「実行してよい静的テンプレート」だけに制限し、issue 本文やコメントから拾った文字列を command に埋め込まない契約が必要です。#781 の反省は「agent が CLI を推測して失敗した」ことであり、次は「wrapper が危険な CLI を組み立てた」になってはいけません。(GitHub)

    推奨:

    commands[].kind: "run_planner" | "read_artifact" | "stop_for_human"
    commands[].argv: string[]
    commands[].shell: false
    commands[].source: "static_wrapper_template"
    

    Python 実装は subprocess.run([...], shell=False, timeout=..., capture_output=True, text=True) に限定。wrapper 内から planner を起動するなら uv run をネストせず、sys.executable で同一 Python 環境の plan_refinement_loop.py を実行する方が安全です。外側の SKILL.md だけが uv run python3 run_refinement_preflight.py ... を示す形でよいです。uv run は project environment と lockfile を使ってコマンドを実行する用途なので、ユーザー向けエントリポイントに寄せるのが自然です。(Astral Docs)


    5. AC4 の rg -c 検証はまた誤検知を作る

    #792 の AC4 は「SKILL.md に planner 直起動例が残っていないこと」を rg -c "uv run python3 ...plan_refinement_loop.py" で見る設計ですが、#789 はまさに rg -F の部分一致で negation VC が壊れた問題を扱っています。ここは同じ失敗パターンです。(GitHub)

    修正すべき検証例:

    ! rg -n '^\s*(?:\$ )?uv run python3\s+\.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop\.py\b' \
      .claude/skills/issue-refinement-loop/SKILL.md
    

    plan_refinement_loop.py という語の説明・SSOT言及は残してよい。消すべきなのは人間/agentが実行する直起動コマンド例です。


    6. #793 / #794 / #796 / #797 と stdout・read plan が衝突する

    #792 は MUST_READ / DO_NOT_READ / COMMANDS / BLOCKERS を出す一方、#793 は VC scope preflight、#794 は compact subagent result、#796 は read plan / inventory、#797 は hook stdout compaction を担当しています。各 issue が独自に compact stdout 方言を作ると、また agent 側で自然言語解釈が増えます。(GitHub)

    #792 に次を追記すべきです。

    This wrapper owns only issue-refinement-loop preflight result.
    It must not define global task-kind read planning.
    MUST_READ/DO_NOT_READ are planner-derived local instructions only.
    If #796 introduces a shared read-plan schema, this wrapper must either consume it or keep field names non-conflicting.
    

    追加すべき受け入れ条件

    現行 AC1〜AC5 では不足です。以下を追加してください。

    AC6: refinement_preflight_result_v1.schema.json が存在し、stdout の compact projection と artifact JSON が同一 status/blockers/next_action を表す。
    

    AC7: planner exit code と wrapper exit code の mapping table が SKILL.md または script docstring に明記され、pytest fixture で全分岐を検証する。

    AC8: anchor URL parser は owner/repo/issue_number/comment_id を構造的に検証し、substring 判定を使わない。

    AC9: raw issue body/comment に含めた sentinel 文字列が stdout に出ない。例外・schema validation error・gh stderr 経由でも stdout に出ない。

    AC10: --fixture 実行はネットワーク・gh 認証に依存せず、同一 fixture から byte-stable な result artifact を生成する。

    AC11: COMMANDS は argv 配列のみを出力し、shell command string を出さない。issue/comment 由来文字列を argv に混ぜない。

    AC12: gh 未導入、未認証、permission不足、API非JSON、timeout をすべて environment_failure exit 3 として扱う。

    GitHub CLI を CI や Actions 上で使う場合は GH_TOKEN と必要 permission を明示する必要があります。GitHub の REST API 利用では CLI から gh api を使える一方、認証・権限不足は普通に失敗条件になります。(GitHub Docs)


    実装方針の推奨

    最小構成はこれで十分です。

    run_refinement_preflight.py

    1. argparse で --issue-number / --repo / --anchor-comment-url[] / --fixture を読む
    2. fixture があれば fixture JSON だけを読む
    3. fixture がなければ gh issue view --json number,title,body,labels,comments,url で snapshot 作成
    4. anchor comment id を gh api または comments snapshot で構造検証
    5. planner input schema に変換
    6. plan_refinement_loop.py を shell=False で起動
    7. planner output schema を検証
    8. wrapper result schema に変換
    9. raw snapshot / planner input / planner output / result artifact を artifact dir に保存
    10. stdout は compact projection のみ

    artifact path は .claude/artifacts/issue-refinement-loop/<issue_number>/... に限定し、issue_number は int として正規化してください。repo や anchor URL から path を生成すると path traversal の余地が出ます。


    最終判定

    この Issue は “wrapper を作る” だけなら妥当ですが、現状の acceptance criteria は wrapper の失敗モードを閉じていません。

    マージ可能な Issue にするには、少なくとも次の4点を本文に追記してください。

    1. REFINEMENT_PREFLIGHT_RESULT_V1 schema を追加する

    2. planner exit code / fail_closed / wrapper status の mapping table を追加する

    3. anchor comment validation を構造検証として定義する

    4. stdout compact projection と artifact JSON の責務分離を明記する

    #792 自体には公開ページ上で branch / PR は紐づいていません。関連して確認すべき実装履歴は、#781 を閉じた PR #787 と、そこで見つかった negation VC 問題を分離した #789 です。(GitHub)

    ## 結論

    Issue #792 は実装価値がありますが、現状のまま着手すると plan_refinement_loop.py の失敗を wrapper 側の新しい曖昧さに移すだけです。判定は REQUEST_CHANGES 相当です。

    #792 は、#781 の refinement loop で planner CLI の呼び出し推測・失敗・再読・再実行が発生したことを受け、run_refinement_preflight.py を追加して gh issue view / gh api から issue/comment を取得し、planner 入力を生成し、stdout を STATUS / NEXT / MUST_READ / DO_NOT_READ / COMMANDS / BLOCKERS に整える提案です。狙い自体は #791 の「zero failed preflight」「compact stdout」「raw subagent output削減」と整合します。([GitHub]1)

    ただし既存の #392 で plan_refinement_loop.py はすでに SSOT として、stdin schema、stdout schema、exit code、fail_closed の意味、責務境界を持っています。#792 はこの既存契約との接続仕様が未定義です。ここを先に固定しないと、wrapper が第二の planner になります。([GitHub]2)


    主要ブロッカー

    1. wrapper の出力 schema がない

    #792 は refinement_preflight_input.schema.json の追加を求めていますが、肝心の wrapper 出力、つまり REFINEMENT_PREFLIGHT_RESULT_V1 相当の schema がありません。stdout に uppercase field を出すだけでは、agent と test がまた自然言語パースに戻ります。JSON Schema 側は additionalProperties: false で未知キーを拒否できるため、wrapper result も strict schema にすべきです。([GitHub]1)

    修正案: Allowed Paths に以下を追加してください。

    .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json
    

    最低限の result schema は次を持つべきです。

    schema_version: "refinement_preflight_result/v1"
    status: "pass" | "warn" | "blocked" | "environment_failure"
    issue_number
    repo
    planner_exit_code
    planner_fail_closed
    next_action
    must_read[]
    do_not_read[]
    commands[]
    blockers[]
    artifacts{}
    hashes{}
    

    stdout はこの JSON artifact の短縮投影に限定し、完全な機械判定は artifact を読む設計にするべきです。


    2. exit code の意味が planner と wrapper で衝突している

    既存 planner は 0 = success、2 = invalid input、3 = internal error で、fail_closed: true でも exit code は 0 という契約です。#792 は wrapper 側で 0 pass / 1 warn / 2 blocked / 3 environment failure を導入しようとしています。これは悪くありませんが、mapping table が必須です。([GitHub]2)

    追加すべき mapping:

    条件 wrapper status wrapper exit
    anchor comment が対象 issue に属さない blocked 2
    gh 未インストール・未認証・API失敗・非JSON environment_failure 3
    planner exit 2 blocked または environment_failure を明文化 2 or 3
    planner exit 3 environment_failure 3
    planner exit 0 かつ fail_closed.required=true blocked 2
    planner exit 0 かつ通常 plan pass 0
    planner exit 0 だが human note が必要 warn 1

    特に fail_closed を pass 扱いにすると、現行 SKILL.md の「fail_closed は human stop」という運用と食い違います。([GitHub]3)


    3. anchor comment validation が甘いと、誤Issue・誤PRコメントを拾う

    #792 は --anchor-comment-url を複数受け取り、anchor が issue に属さない場合に ANCHOR_NOT_IN_ISSUE で block する方針です。これは重要ですが、URL substring 判定では不足です。gh issue view --comments --json は issue 本文や comments を取得できますし、gh api は REST endpoint を直接叩けるので、comment id から .issue_url を検証する実装にすべきです。([GitHub]1)

    検証条件は最低限これです。

    - URL の owner/repo が --repo と一致する
    - URL の issue number が --issue-number と一致する
    - comment id が実在する
    - comment の issue_url が同一 owner/repo/issues/{issue_number}
    - pull request review comment ではない
    - 複数 anchor は stable sort + dedupe
    - 1件でも mismatch なら全体を blocked
    

    GitHub issue/comment 本文は信頼できない入力なので、COMMANDS に raw body/comment 由来の文字列を混ぜないことも明記してください。


    4. COMMANDS 出力は shell injection と誤実行の温床

    #792 の wrapper は agent に次のコマンドを提示する設計ですが、GitHub issue/comment は外部入力です。COMMANDS は「実行してよい静的テンプレート」だけに制限し、issue 本文やコメントから拾った文字列を command に埋め込まない契約が必要です。#781 の反省は「agent が CLI を推測して失敗した」ことであり、次は「wrapper が危険な CLI を組み立てた」になってはいけません。([GitHub]1)

    推奨:

    commands[].kind: "run_planner" | "read_artifact" | "stop_for_human"
    commands[].argv: string[]
    commands[].shell: false
    commands[].source: "static_wrapper_template"
    

    Python 実装は subprocess.run([...], shell=False, timeout=..., capture_output=True, text=True) に限定。wrapper 内から planner を起動するなら uv run をネストせず、sys.executable で同一 Python 環境の plan_refinement_loop.py を実行する方が安全です。外側の SKILL.md だけが uv run python3 run_refinement_preflight.py ... を示す形でよいです。uv run は project environment と lockfile を使ってコマンドを実行する用途なので、ユーザー向けエントリポイントに寄せるのが自然です。([Astral Docs]4)


    5. AC4 の rg -c 検証はまた誤検知を作る

    #792 の AC4 は「SKILL.md に planner 直起動例が残っていないこと」を rg -c "uv run python3 ...plan_refinement_loop.py" で見る設計ですが、#789 はまさに rg -F の部分一致で negation VC が壊れた問題を扱っています。ここは同じ失敗パターンです。([GitHub]1)

    修正すべき検証例:

    ! rg -n '^\s*(?:\$ )?uv run python3\s+\.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop\.py\b' \
      .claude/skills/issue-refinement-loop/SKILL.md

    plan_refinement_loop.py という語の説明・SSOT言及は残してよい。消すべきなのは人間/agentが実行する直起動コマンド例です。


    6. #793 / #794 / #796 / #797 と stdout・read plan が衝突する

    #792 は MUST_READ / DO_NOT_READ / COMMANDS / BLOCKERS を出す一方、#793 は VC scope preflight、#794 は compact subagent result、#796 は read plan / inventory、#797 は hook stdout compaction を担当しています。各 issue が独自に compact stdout 方言を作ると、また agent 側で自然言語解釈が増えます。([GitHub]5)

    #792 に次を追記すべきです。

    This wrapper owns only issue-refinement-loop preflight result.
    It must not define global task-kind read planning.
    MUST_READ/DO_NOT_READ are planner-derived local instructions only.
    If #796 introduces a shared read-plan schema, this wrapper must either consume it or keep field names non-conflicting.
    

    追加すべき受け入れ条件

    現行 AC1〜AC5 では不足です。以下を追加してください。

    AC6: refinement_preflight_result_v1.schema.json が存在し、stdout の compact projection と artifact JSON が同一 status/blockers/next_action を表す。
    
    AC7: planner exit code と wrapper exit code の mapping table が SKILL.md または script docstring に明記され、pytest fixture で全分岐を検証する。
    
    AC8: anchor URL parser は owner/repo/issue_number/comment_id を構造的に検証し、substring 判定を使わない。
    
    AC9: raw issue body/comment に含めた sentinel 文字列が stdout に出ない。例外・schema validation error・gh stderr 経由でも stdout に出ない。
    
    AC10: --fixture 実行はネットワーク・gh 認証に依存せず、同一 fixture から byte-stable な result artifact を生成する。
    
    AC11: `COMMANDS` は argv 配列のみを出力し、shell command string を出さない。issue/comment 由来文字列を argv に混ぜない。
    
    AC12: `gh` 未導入、未認証、permission不足、API非JSON、timeout をすべて `environment_failure` exit 3 として扱う。
    

    GitHub CLI を CI や Actions 上で使う場合は GH_TOKEN と必要 permission を明示する必要があります。GitHub の REST API 利用では CLI から gh api を使える一方、認証・権限不足は普通に失敗条件になります。([GitHub Docs]6)


    実装方針の推奨

    最小構成はこれで十分です。

    run_refinement_preflight.py
      1. argparse で --issue-number / --repo / --anchor-comment-url[] / --fixture を読む
      2. fixture があれば fixture JSON だけを読む
      3. fixture がなければ gh issue view --json number,title,body,labels,comments,url で snapshot 作成
      4. anchor comment id を gh api または comments snapshot で構造検証
      5. planner input schema に変換
      6. plan_refinement_loop.py を shell=False で起動
      7. planner output schema を検証
      8. wrapper result schema に変換
      9. raw snapshot / planner input / planner output / result artifact を artifact dir に保存
      10. stdout は compact projection のみ
    

    artifact path は .claude/artifacts/issue-refinement-loop/<issue_number>/... に限定し、issue_number は int として正規化してください。repo や anchor URL から path を生成すると path traversal の余地が出ます。


    最終判定

    この Issue は “wrapper を作る” だけなら妥当ですが、現状の acceptance criteria は wrapper の失敗モードを閉じていません。

    マージ可能な Issue にするには、少なくとも次の4点を本文に追記してください。

    1. REFINEMENT_PREFLIGHT_RESULT_V1 schema を追加する
    2. planner exit code / fail_closed / wrapper status の mapping table を追加する
    3. anchor comment validation を構造検証として定義する
    4. stdout compact projection と artifact JSON の責務分離を明記する

    #792 自体には公開ページ上で branch / PR は紐づいていません。関連して確認すべき実装履歴は、#781 を閉じた PR #787 と、そこで見つかった negation VC 問題を分離した #789 です。([GitHub]1)

  3. squne121 commented on Jun 10, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jun 10, 2026

    @squne121
    OwnerAuthor

    ClaudeCodeの作業ログ

    ❯ https://github.com/squne121/loop-protocol/issues/792#issuecomment-4675137388
      を対象に issue-refinement-loop を人間承認不要で行って。
    
    ● issue-refinement-loop skill を起動します。対象は issue #792 のコメント
      https://github.com/squne121/loop-protocol/issues/792#issuecomment-4675137388
      、人間承認不要モードです。
    
    ● Skill(issue-refinement-loop)
      ⎿  Successfully loaded skill
    
    ● Step 0 を開始します。Issue #792 本文と anchor comment を取得します。
    
    ● Bash(gh issue view 792 --repo squne121/loop-protocol --json number,title,state,labels,body
          | head -c 12000)
      ⎿  {
           "body": "## Machine-Readable Contract\n\n```yaml\ncontract_schema_version: v1\ni
         ssue_kind: implementation\nparent_issue: \"#791\"\ngoal_ref: \"agent ops の token/
         … +72 lines (ctrl+o to expand)
    
    ● Bash(gh api repos/squne121/loop-protocol/issues/comments/4675137388 --jq '{id, user:
          .user.login, created_at, updated_at, body}' | head -c 12000)
      ⎿  {"body":"\u003chtml\u003e\n\u003cbody\u003e\n\u003c!--StartFragment--\u003e\u003ch
         tml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003e\u003ch2\u003e結論\u003c
         /h2\u003e\u003cp\u003e\u003cstrong\u003eIssue #792
         は実装価値がありますが、現状のま
         … +123 lines (ctrl+o to expand)
    
    ● Bash(mkdir -p artifacts/issue-refinement-loop/792 && gh api
          repos/squne121/loop-protocol/issues/comments/4675137388 >
          artifacts/issue-refinement-loop/792/anchor_comm…)
      ⎿  LEN 20802
         . wrapper の出力 schema がない
         … +182 lines (ctrl+o to expand)
    
      Read 1 file, listed 1 directory (ctrl+o to expand)
    
    ● anchor comment の author は squne121(人間)です。Step 0 の scope rollup preflight と Step
      0f の planner 実行を準備します。
    
    ● Bash(uv run python3
          .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py --help 2>&1 |
          head -40; echo ---; uv run python3 .claude/skills/issue-ref…)
      ⎿  usage: plan_issue_scope_rollup.py [-h] --issues-json ISSUES_JSON --prs-json
                                           PRS_JSON [--current-issue CURRENT_ISSUE]
                                           [--repo REPO] [--output OUTPUT]
         … +56 lines (ctrl+o to expand)
    
    ● scope rollup preflight 用に OPEN Issues/PRs を取得し、planner 入力も組み立てます。
    
    ● Bash(gh issue list --repo squne121/loop-protocol --state open --limit 200 --json
          number,title,body,labels > artifacts/issue-refinement-loop/792/open_issues.json && g…)
      ⎿  (No output)
    
      Read 2 files (ctrl+o to expand)
    
    ● Bash(uv run python3 - <<'EOF' > artifacts/issue-refinement-loop/792/planner_input.json
          import json…)
      ⎿  exit=0
         {
           "fail_closed": {
         … +38 lines (ctrl+o to expand)
    
    ● 2 agents finished (ctrl+o to expand)
       ├ codebase-investigator (repo claims fact-check #792) · 16 tool uses · 30.0k tokens
       │ ⎿  Done
       └ web-researcher (外部仕様 fact-check #792) · 19 tool uses · 35.7k tokens
         ⎿  Done
    
    ● issue-reviewer(review-issue #792 実行)
      ⎿  Done (5 tool uses · 31.9k tokens · 1m 19s)
      (ctrl+o to expand)
    
    ● Bash(pnpm lint 2>&1 | tail -20)
      ⎿    593:5   error  'console' is not defined          no-undef
    
         /home/squne/projects/LOOP_PROTOCOL/.claude/skills/.system/openai-docs/scripts/reso
         … +17 lines (ctrl+o to expand)
    
    ● issue-author(Issue #792 本文 rewrite)
      ⎿  Done (13 tool uses · 42.9k tokens · 2m 40s)
      (ctrl+o to expand)
    
    ● worker の自己申告を独立検証します(sha 照合と主要マーカー確認)。
    
    ● Bash(gh issue view 792 --repo squne121/loop-protocol --json body --jq '.body' >
          artifacts/issue-refinement-loop/792/body_after_rewrite1.md && sha256sum
          artifacts/iss…)
      ⎿  28938757749492dd5b57104625f2319dee46cb338cad155fda29ca0dcb3f7618  artifacts/issue-
         refinement-loop/792/body_after_rewrite1.md
         16
         … +19 lines (ctrl+o to expand)
    
    ● issue-reviewer(review-issue #792 再実行)
      ⎿  Done (7 tool uses · 34.6k tokens · 1m 18s)
      ⎿  28938757749492dd5b57104625f2319dee46cb338cad155fda29ca0dcb3f7618  artifacts/issue-
         refinement-loop/792/body_after_rewrite1.md
         16
         … +19 lines (ctrl+o to expand)
    
    ● issue-reviewer(review-issue #792 再実行)
      ⎿  Done (7 tool uses · 34.6k tokens · 1m 18s)
      (ctrl+o to expand)
    
    ● Bash(npx eslint . --ignore-pattern '.claude/skills/.system/**' 2>&1 | tail -5; echo
          "eslint_exit=$?")
      ⎿  eslint_exit=0
    
    ● Bash(uv run python3 .claude/skills/issue-refinement-loop/scripts/decide_rewrite_route.py
          --help 2>&1 | head -30)
      ⎿  {
           "error": "Invalid JSON input: Expecting value: line 1 column 1 (char 0)",
           "route": null
         }
    
    ● Bash(sed -n '1,80p' .claude/skills/issue-refinement-loop/scripts/decide_rewrite_route.py)
      ⎿  #!/usr/bin/env python3
         """
         decide_rewrite_route.py
         … +77 lines (ctrl+o to expand)
    
    ● Bash(sed -n '93,148p' artifacts/issue-refinement-loop/792/body_after_rewrite1.md)
      ⎿  ## Acceptance Criteria
    
         - [ ] AC1: `run_refinement_preflight.py` が存在し、fixture 入力で `STATUS` / `NEXT
         … +52 lines (ctrl+o to expand)
    
    ● issue-author(Issue #792 VC 修正 rewrite)
      ⎿  Done (9 tool uses · 35.9k tokens · 2m 29s)
      (ctrl+o to expand)
    
    ● 独立検証と rewrite router を実行し、iteration 2 の review に進みます。
    
    ● Bash(gh issue view 792 --repo squne121/loop-protocol --json body --jq '.body' >
    ● Bash(sed -n '93,148p' artifacts/issue-refinement-loop/792/body_after_rewrite1.md)
      ⎿  ## Acceptance Criteria
    
         - [ ] AC1: `run_refinement_preflight.py` が存在し、fixture 入力で `STATUS` / `NEXT
         … +52 lines (ctrl+o to expand)
    
    ● issue-author(Issue #792 VC 修正 rewrite)
      ⎿  Done (9 tool uses · 35.9k tokens · 2m 29s)
      (ctrl+o to expand)
    
    ● 独立検証と rewrite router を実行し、iteration 2 の review に進みます。
    
    ● Bash(gh issue view 792 --repo squne121/loop-protocol --json body --jq '.body' >
          artifacts/issue-refinement-loop/792/body_after_rewrite2.md && rg -n '^#
          AC(6|7|8|9|10…)
      ⎿  Error: Exit code 2
         127:# AC6
         129:# AC7
         131:# AC8
         133:# AC9
         135:# AC10
         137:# AC11
         139:# AC12
         177:## Scope Delta(任意)
         178-
         … +6 lines (ctrl+o to expand)
    
      Read 1 file (ctrl+o to expand)
    
    ● Bash(prev=$(sha256sum artifacts/issue-refinement-loop/792/body_after_rewrite1.md | cut -d'
          ' -f1)
          cur=$(sha256sum artifacts/issue-refinement-loop/792/body_after_rewr…)
      ⎿  {
           "schema_version": "route_result/v1",
           "route": "proceed_to_review",
         … +10 lines (ctrl+o to expand)
    
    ● route: proceed_to_review。iteration 2 の review を実行します。
    
    ● issue-reviewer(review-issue #792 最終確認)
      ⎿  Done (6 tool uses · 46.9k tokens · 2m 8s)
      (ctrl+o to expand)
    
    ● Bash(echo '{"termination_reason":"approved","issue_number":792}' | uv run python3
          .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py --issue-…)
      ⎿  [publish_termination_report] comment posted for issue #792
    
    ● Bash(gh issue view 792 --repo squne121/loop-protocol --json comments --jq
          '.comments[-1].url')
      ⎿  https://github.com/squne121/loop-protocol/issues/792#issuecomment-4675308977
    
    ● refinement loop 完了です(verdict: approve、iteration 2/3、termination_reason:
      approved)。
    
      - 更新済み Issue: https://github.com/squne121/loop-protocol/issues/792
      - 終了レポート:
      https://github.com/squne121/loop-protocol/issues/792#issuecomment-4675308977
    
      要点:
      - anchor comment(人間 REQUEST_CHANGES)の 4 必須事項をすべて本文へ反映: result
      schema(refinement_preflight_result_v1.schema.json)の追加、planner↔wrapper exit code
      mapping table、anchor comment の構造検証(issue_url 照合・substring 禁止)、stdout compact
      projection と artifact JSON の責務分離。AC6〜AC12 と #793/#794/#796/#797
      との責務境界も追記。
      - repo 調査で、SKILL.md には planner 直接起動例が元々存在せず旧 AC4 の negation VC が
      baseline で vacuous だったことが判明したため、AC4 を positive rg + static guard
      の二本立て(AC4a/AC4b)に作り直しました。
      - iteration 2 で C5/LP010(AC6〜AC12 の per-AC VC コメント欠落)を修正。pnpm lint の
      baseline 失敗は untracked .claude/skills/.system/ による環境汚染で、ignore-pattern 付き
      eslint exit 0 を独立確認済み(本文の欠陥ではない)。
      - scope rollup は #793/#794/#795 と fixtures/SKILL.md 共有の collision
      を検出しましたが、anchor comment 自体が責務境界の明文化を指示しており本文反映済みのため
      proceed と判断。follow-up 起票候補は 0 件です。
    
    ✻ Brewed for 21m 7s
    
  5. squne121 commented on Jun 10, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-06-10T23:12:44Z)

    • Outcome: run_refinement_preflight.py + 入力/result schema + pytest を追加し、issue-refinement-loop/SKILL.md の planner 直接起動記述を wrapper 1 コマンドに置換、品質ゲート全 PASS のコミットを作成する
    • Acceptance Criteria: AC1–AC3, AC4a, AC4b, AC5–AC12(Issue 本文参照)
    • Verification Commands: uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py -v、AC2/AC3/AC6–AC12 の rg キーワード検証、AC4a positive rg / AC4b negation rg、AC5 pnpm typecheck/lint/test/build
    • Allowed Paths: .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py(新規)/ schemas/refinement_preflight_input.schema.json(新規)/ schemas/refinement_preflight_result_v1.schema.json(新規)/ tests/test_refinement_preflight.py(新規)/ fixtures/(fixture 追加のみ)/ SKILL.md
    • Worktree: .claude/worktrees/issue-792-issue-refinement-preflight-wrapper-run-r
    • Branch: worktree-issue-792-issue-refinement-preflight-wrapper-run-r
    • VC preflight: baseline fail = 3, 想定外 pass = 0, 実行不可 = 0, expected_pass(regression gate) = 3, human_judgment = 9(下記 override 参照)

    Human-judgment override(go 判定根拠)

    • AC2/AC3/AC6–AC12 の rg exit 2 は対象テストファイル(新規作成予定・未存在)への参照によるもの。新規ファイル作成 Issue の期待される baseline fail(既知パターン: #docs-creation preflight 偽陽性)→ go
    • AC5 pnpm lint exit 1 は untracked ローカルディレクトリ .claude/skills/.system/(repo 非追跡)の汚染による偽陽性。--ignore-pattern '.claude/skills/.system/**' で exit 0 を確認済み。untracked のため worktree へ非伝播 → go
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-06-10T23:12:44Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/792
      body_sha256: b696118dc089799c2d07f296d93bd8d710789dd2e7f83b5188a2a9d4b4f4af08
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          status: pass
          vc_failed_as_expected: 3
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 3
          vc_skipped: 0
          human_judgment_overrides:
            - acs: [AC2, AC3, AC6, AC7, AC8, AC9, AC10, AC11, AC12]
              raw_decision: human_judgment
              override_decision: go
              rationale: "rg exit 2 = 新規作成予定ファイル未存在の expected baseline fail"
            - acs: [AC5-lint]
              raw_decision: blocked
              override_decision: go
              rationale: "untracked .claude/skills/.system/ 汚染の偽陽性。ignore-pattern で exit 0、worktree 非伝播"
        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
        runtime_verification_applicability: not_applicable
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
        - "baseline_vc_preflight.py が AC4a/AC4b マーカー(英数字 suffix 付き)を AC3 配下に集約して解析した。分類結果は全件 go のため routing への影響なし"
  6. squne121 commented on Jun 10, 2026

    @squne121
    OwnerAuthor

    実装完了

    PR #801 を作成しました: #801

    実装内容

    • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py — planner wrapper entrypoint(新規)
    • .claude/skills/issue-refinement-loop/schemas/refinement_preflight_input.schema.json — 入力スキーマ(新規)
    • .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json — 結果スキーマ strict(新規)
    • .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py — pytest 42件(AC1–AC12)(新規)
    • .claude/skills/issue-refinement-loop/fixtures/preflight_*.json — テスト fixture 5件(新規)
    • .claude/skills/issue-refinement-loop/SKILL.md — Step 0f を wrapper 1 コマンド例に置換(変更)

    検証結果

    uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py -v
    → 42 passed (AC1–AC12 全対応)
    
    pnpm typecheck / lint / test / build
    → 全 PASS (477 vitest / 21 files)
    

    AC達成状況

    • AC1: pytest で STATUS/NEXT_ACTION/COMMANDS/ARTIFACT stdout 出力確認
    • AC2: ANCHOR_NOT_IN_ISSUE blocker / exit 2 テスト通過
    • AC3: raw_issue_snapshot が artifact に書き込まれ stdout に漏洩しないことを確認
    • AC4a: SKILL.md に uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py コマンド例追加確認
    • AC4b: plan_refinement_loop.py 直接起動例の不在を negation rg で確認
    • AC5: pnpm 全ゲート PASS
    • AC6–AC12: rg キーワード(refinement_preflight_result_v1 / exit_code_mapping / substring / sentinel / byte_stable / argv / environment_failure)全て テストコード内に存在確認

    Related coordination

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/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions