Repository navigation
Description
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: workflowParent Issue
Parent Goal Ref
- Goal: agent ops(issue refinement / subagent handoff / hooks)の token・context 浪費を決定論的 script と compact contract で削減する
- Desired Destination: refinement loop が「失敗 preflight 0 回・compact stdout ≤ 2KB + artifact・VC scope 不備の author 前検出」で完走できる状態(parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 のスコープ)
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
- VC scope checker / compact contract / read plan generator / hook 規律 / transcript summarizer / parity linter(parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の他 child issue で対応)
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
- URL の owner/repo が
- 不一致なら
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.pyL123-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{}
- strict(
- 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
plan_refinement_loop.pyの判断ロジック変更- GitHub Issue 本文の mutation
- reviewer / author SubAgent の品質判断・出力契約変更(parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の別 child)
- SKILL.md 全体の thin 化・LOOP_STATE 外出し(perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割 #293 child として別途対応)
- global な task-kind read planning の定義(本 wrapper は issue-refinement-loop preflight result のみを所有する。MUST_READ / DO_NOT_READ は planner 由来の local instruction に限る。実装: agent ops inventory / read plan generator(agent_ops_inventory.py)を追加し task-kind 別の最小読込を決定論化する #796 が共有 read-plan schema を導入した場合は consume するか field 名非衝突を保つ)
- 実装: VC scope preflight checker(check_vc_scope.py)を issue-refinement-loop に追加する #793 / 実装: issue-reviewer / issue-author に compact subagent result contract を導入し raw 出力の main 還流を止める #794 / 実装: agent ops inventory / read plan generator(agent_ops_inventory.py)を追加し task-kind 別の最小読込を決定論化する #796 / 実装: Claude / Codex hook の stdout policy と compaction 時 loop state 保存・復元 hint を fixture 検証付きで整備する #797 との責務衝突範囲(本 Issue の変更が衝突する場合は Stop Condition として人間判断へ返す)
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_ISSUEblocker を返すことが 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.pyRuntime 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
1 Issue = 1 PR、worktree 上で実装し Draft PR を作成する.claude/skills/issue-refinement-loop/SKILL.mdを Allowed Paths に含む OPEN Issue(実装: create-issue / issue-refinement-loop に Allowed Paths 全件の実在プリフライトを追加する #32 / 実装: issue-refinement-loop Step 0b に複合シグナルの決定論的絞り込み規約を追加する #138 / perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割 #293 child D)とマージ順を直列化する。本 Issue を先行させ、後続 Issue は本 Issue マージ後に rebase する
Notes for Reviewer
- 出典: parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の分析レポート「I. Prioritized implementation issues / Issue 1」
- wrapper の stdout budget は
check_agent_friendly_stdout.py(parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の compact contract child)導入後にそちらの fixture でも検証する想定 - AC4a / AC4b は二本立て: AC4a は wrapper コマンド例の正方向検証(新規ファイル追加後に green)、AC4b は
plan_refinement_loop.py直起動を将来も追加しないための静的 guard - anchor validation は REST
issue_urlフィールドによる構造検証であり、URL substring 判定は禁止(web fact-check 済み: issue comments REST レスポンスにissue_urlが含まれ、PR review comment は別 endpoint)
Activity
squne121 commentedon Jun 10, 2026
結論
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 に以下を追加してください。
最低限の result schema は次を持つべきです。
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)検証条件は最低限これです。
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)推奨:
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)修正すべき検証例:
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 に次を追記すべきです。
追加すべき受け入れ条件
現行 AC1〜AC5 では不足です。以下を追加してください。
GitHub CLI を CI や Actions 上で使う場合は
GH_TOKENと必要 permission を明示する必要があります。GitHub の REST API 利用では CLI からgh apiを使える一方、認証・権限不足は普通に失敗条件になります。(GitHub Docs)実装方針の推奨
最小構成はこれで十分です。
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点を本文に追記してください。
REFINEMENT_PREFLIGHT_RESULT_V1schema を追加するplanner exit code /
fail_closed/ wrapper status の mapping table を追加するanchor comment validation を構造検証として定義する
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 に以下を追加してください。
最低限の result schema は次を持つべきです。
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:
blocked2gh未インストール・未認証・API失敗・非JSONenvironment_failure32blockedまたはenvironment_failureを明文化2or33environment_failure30かつfail_closed.required=trueblocked20かつ通常 planpass00だが human note が必要warn1特に
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)検証条件は最低限これです。
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)推奨:
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)修正すべき検証例:
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 に次を追記すべきです。
追加すべき受け入れ条件
現行 AC1〜AC5 では不足です。以下を追加してください。
GitHub CLI を CI や Actions 上で使う場合は
GH_TOKENと必要 permission を明示する必要があります。GitHub の REST API 利用では CLI からgh apiを使える一方、認証・権限不足は普通に失敗条件になります。([GitHub Docs]6)実装方針の推奨
最小構成はこれで十分です。
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点を本文に追記してください。
REFINEMENT_PREFLIGHT_RESULT_V1schema を追加するfail_closed/ wrapper status の mapping table を追加する#792 自体には公開ページ上で branch / PR は紐づいていません。関連して確認すべき実装履歴は、#781 を閉じた PR #787 と、そこで見つかった negation VC 問題を分離した #789 です。([GitHub]1)
squne121 commentedon Jun 10, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 10, 2026
ClaudeCodeの作業ログ
squne121 commentedon Jun 10, 2026
Contract Snapshot (2026-06-10T23:12:44Z)
run_refinement_preflight.py+ 入力/result schema + pytest を追加し、issue-refinement-loop/SKILL.mdの planner 直接起動記述を wrapper 1 コマンドに置換、品質ゲート全 PASS のコミットを作成する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.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.claude/worktrees/issue-792-issue-refinement-preflight-wrapper-run-rworktree-issue-792-issue-refinement-preflight-wrapper-run-rHuman-judgment override(go 判定根拠)
rgexit 2 は対象テストファイル(新規作成予定・未存在)への参照によるもの。新規ファイル作成 Issue の期待される baseline fail(既知パターン: #docs-creation preflight 偽陽性)→ gopnpm lintexit 1 は untracked ローカルディレクトリ.claude/skills/.system/(repo 非追跡)の汚染による偽陽性。--ignore-pattern '.claude/skills/.system/**'で exit 0 を確認済み。untracked のため worktree へ非伝播 → gosqune121 commentedon Jun 10, 2026
実装完了
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 コマンド例に置換(変更)検証結果
AC達成状況
uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.pyコマンド例追加確認plan_refinement_loop.py直接起動例の不在を negation rg で確認Related coordination
feat: add run_refinement_preflight.py wrapper for issue-refinement-lo…