Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#293"
goal_ref: "claude/AI 運用の usage コスト削減"
change_kind: workflowParent Issue
Parent Goal Ref
- Goal: issue-refinement-loop 軽量化・deterministic reviewer Haiku 化・OUTPUT_BUDGET_V1 全 SubAgent 導入・巨大 SKILL.md 分割の 4 施策で claude/AI 運用コストを削減する
- Desired Destination: 施策 A〜D が
.claude/配下に反映され、usage ホットスポットが削減されている状態(parent perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割 #293 のスコープ)
Current Validated Scope
.claude/skills/issue-refinement-loop/SKILL.mdを thin control-plane(trigger / routing / 最小 workflow / 出力契約)に縮小する- LOOP_STATE summary・routing 判断・termination report 例を schema / reference / script に外出しする
.claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.pyを新規追加する(既存decide_rewrite_route.pyの改修で足りる場合は改修でよい)
Remaining Parent Gaps
- 施策 D の残り対象(
issue-contract-review/post-merge-cleanup/impl-review-loopの SKILL.md thin 化)は別 child issue で対応する
Background
parent #293 の施策 D(巨大 SKILL.md thin entrypoint + references/ 分割)のうち issue-refinement-loop 分を実装する。blocker だった #264(gemini-cli-headless-delegation の thin 化、先行事例)は CLOSED 済み。
Issue #781 の refinement loop 実行ログ分析(#791 参照)で、issue-refinement-loop/SKILL.md(289 行)に LOOP_STATE の長い YAML 例・termination report 例・routing 判断の自然言語手順が残っており、loop 1 巡ごとに長い自然言語手順の読込が発生していることが確認された。
- runtime state は
.claude/artifacts/issue-refinement-loop/<issue_number>/loop_state.current.jsonに外出しし、agent は script が出す compactSTATUS/NEXT_ACTIONのみ追従する - loop continuation 判断(needs_fix 継続 / max iteration / human escalation)は
decide_next_loop_action.pyが決定論的に返す - モデル判断として残すもの: 矛盾する人間コメントの解決、外部公式 docs 要否、終了後の人間向け要約
Outcome
issue-refinement-loop/SKILL.md が thin control-plane に縮小され、LOOP_STATE schema(schemas/loop_state.schema.json)・reference(references/loop-state.md)・next action 判断 script(decide_next_loop_action.py)に手順情報が外出しされ、既存 + 新規の pytest と pnpm 品質ゲートが全 PASS した状態のコミットが作成されている。
In Scope
- SKILL.md から以下を削除し参照に置換する
- LOOP_STATE summary の YAML 例(schema / reference へ移動)。SKILL.md から
## LOOP_STATE Summaryブロック・インライン LOOP_STATE キー一覧を完全削除し、schemas/loop_state.schema.jsonとreferences/loop-state.mdへの参照のみを残す - reviewer / author routing の自然言語判断手順(
decide_next_loop_action.pyへ移動)。SKILL.md から needs-fix / approve / max_iterations の自然言語分岐を完全削除し、判断 SSOT をdecide_next_loop_action.py/references/に統一する。SKILL.md が許可するのは「decide_next_loop_action.pyを呼ぶ」「stdout のSTATUS/NEXT_ACTIONに従う」の 2 行のみ - termination report の本文例(既存
render_termination_report.py/ reference へ寄せる)
- LOOP_STATE summary の YAML 例(schema / reference へ移動)。SKILL.md から
schemas/loop_state.schema.jsonの新規追加とreferences/loop-state.mdの新規追加decide_next_loop_action.pyの新規追加(入力: loop state JSON(input schema version v1)/ compact review result(status/verdict enum)/ max iterations。コマンドは argv array(shell string 不可)。出力:STATUS/NEXT_ACTION/COMMANDS/BLOCKERS(stdout budget < 2000 bytes)。loop_state の更新は行わず読み取り専用。exit code:0 pass/1 warn/2 human_escalation/3 inconsistent_state。優先順位:inconsistent_state>human_escalation)- 上記の pytest(schema 検証 / next action 判定 / iteration 上限 / 不整合 state: issue_number mismatch / invalid enum / missing required / negative iteration)
Out of Scope
- 他 skill(
issue-contract-review/post-merge-cleanup/impl-review-loop)の SKILL.md 分割(施策 D の残り、別 child) plan_refinement_loop.pyの判断ロジック変更- Issue contract schema(contract_schema_version)の破壊的変更
- max_iterations デフォルト値の変更(perf(claude): issue-refinement-loop を軽量化する(max_iterations=1 デフォルト / SubAgent 条件付き) #295 で対応済み)。SKILL.md に
default_max_iterations: 3が残っている場合は停止して contract drift を報告すること(perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割 #293/perf(claude): issue-refinement-loop を軽量化する(max_iterations=1 デフォルト / SubAgent 条件付き) #295 完了状態との矛盾を silent に保存しない)
Acceptance Criteria
- AC1:
.claude/skills/issue-refinement-loop/SKILL.mdに## LOOP_STATE SummaryブロックおよびインラインLOOP_STATE:キー一覧が残っておらず、schemas/loop_state.schema.jsonとreferences/loop-state.mdへの参照に置換されている。Verification Command は SKILL.md 側を negated チェックし、schema 内容の検証は pytest(AC2)に委譲する - AC2:
schemas/loop_state.schema.jsonが存在し、pytest で current loop state fixture が schema 検証を PASS する - AC3:
decide_next_loop_action.pyが compact review result fixture から next action を決定し、iteration 上限超過で human escalation(exit 2)を返すことが pytest で検証されている - AC4: SKILL.md 内に
uv runを伴わないpython3 .claude/skills/issue-refinement-loop/scripts/実行例が存在しない(rgがヒット 0 件となる) - AC5: 既存の issue-refinement-loop tests を含め pnpm typecheck / lint / test / build と
uv run pytestが全 PASS する
Runtime Verification Applicability
decision: immediate
applicable_acs:
- AC2
- AC3
- AC5
execution_environment:
cli_tools:
- uv
- python3
- node
- pnpm
auth_required: false
network_required: false
skip_conditions:
- "local repository checkout が存在しない場合は environment blocked として扱う"
fallback_policy:
fallback_success_is_pass: false
notes: "fallback 経由の成功を PASS に変換しない"
artifact_requirements:
- "uv run pytest output(test_loop_state_schema.py)"
- "uv run pytest output(test_decide_next_loop_action.py)"
- "pnpm typecheck / lint / test / build output"Verification Commands
# AC1
$ ! rg -n 'LOOP_STATE:' .claude/skills/issue-refinement-loop/SKILL.md
$ rg -n 'schemas/loop_state\.schema\.json|references/loop-state\.md' .claude/skills/issue-refinement-loop/SKILL.md
# AC2
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_loop_state_schema.py -v
# AC3
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action.py -v
# AC4
$ ! rg -n 'python3 \.claude/skills/issue-refinement-loop/scripts/' .claude/skills/issue-refinement-loop/SKILL.md
# AC5
$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -v
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildAllowed Paths
- .claude/skills/issue-refinement-loop/SKILL.md
- .claude/skills/issue-refinement-loop/schemas/loop_state.schema.json(新規)
- .claude/skills/issue-refinement-loop/references/loop-state.md(新規)
- .claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py(新規。既存 decide_rewrite_route.py の改修を選ぶ場合はそのファイルも可)
- .claude/skills/issue-refinement-loop/scripts/decide_rewrite_route.py
- .claude/skills/issue-refinement-loop/tests/test_loop_state_schema.py(新規)
- .claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action.py(新規)
- .claude/skills/issue-refinement-loop/tests/test_loop_policy.py(既存テスト更新)
- .claude/skills/issue-refinement-loop/tests/test_thin_entrypoint.py(既存テスト更新)
- .claude/skills/issue-refinement-loop/fixtures/**(fixture 追加のみ)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- SKILL.md 縮小により既存 orchestrator 動作(plan consume / termination publish)が再現できないと判明した場合
Required Skills
なし
Scope Delta(任意)
test_loop_policy.pyを Allowed Paths に追加(既存テスト更新、AC5 適合)test_thin_entrypoint.pyを Allowed Paths に追加(既存テスト更新、AC5 適合)
Delivery Rule
1 Issue = 1 PR、worktree 上で実装し Draft PR を作成する- Depends on 実装: issue-refinement preflight wrapper(run_refinement_preflight.py)を追加し planner 入力契約を固定化する #792 merge(preflight wrapper が SKILL.md の planner 実行記述を先に置換するため、本 Issue はその後に rebase して着手する)
.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)ともマージ順を直列化する
Notes for Reviewer
- 出典: 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の分析レポート「I. Prioritized implementation issues / Issue 4」および parent perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割 #293 施策 D
- 本 Issue 完了時に parent perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割 #293 の Child Issues リスト(D 行)へ本 Issue 番号を反映する
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 11, 2026
判定: REQUEST_CHANGES
方向性は正しいです。
issue-refinement-loop/SKILL.mdを thin control-plane にして、LOOP_STATE・routing・termination 例を schema/reference/script へ逃がす方針は、親 #293 の usage cost 削減スコープと整合しています。#795 自体もその範囲を明示しています。([GitHub]1)ただし、この Issue は 実装契約としてまだ弱い です。このまま実装させると、「SKILL.md から YAML 例を消したが、routing 判断はまだ自然言語で残る」「schema はあるが状態遷移は未定義」「テストは max iteration だけ通る」程度の PR で閉じられるリスクが高いです。
ブロッカー
1. AC1 の検証コマンドが目的と逆を向いている
AC1 は「SKILL.md に LOOP_STATE YAML example が残っていないこと」ですが、Issue の Verification Command は
schemas/loop_state.schema.json側でLOOP_STATEを探しています。これは SKILL.md から消えたことを証明しません。#795 の AC1/Verification Commands は修正必須です。([GitHub]1)修正案:
2.
max_iterationsdefault の整合性が危険親 #293 では measure A として
max_iterationsdefault 3→1 が既に完了済み扱いです。一方、私が確認したmain表示上のissue-refinement-loop/SKILL.mdにはmax_iterationsdefault 3 が残っていました。#795 は max iteration default 変更を Out of Scope にしていますが、現状が本当に 3 なら、#295/#293 の完了状態と矛盾します。([GitHub]2)#795 に次を追加してください。
3. routing 判断の SSOT が曖昧
#795 は routing 判断を
decide_next_loop_action.pyに出すと言っていますが、現行 SKILL.md 側には needs-fix 時の auto continuation 判断など、自然言語の分岐が残っています。これを残したまま script を追加すると、人間にも agent にも「SKILL.md と script のどちらが正か」が曖昧になります。([GitHub]1)AC に次を追加すべきです。
4.
decide_next_loop_action.pyの入出力契約が不足Issue では
STATUS/NEXT_ACTION/COMMANDS/BLOCKERSと exit code が示されていますが、以下が未定義です。loop_state.current.jsonを script が読むだけか、更新もするのかhuman_escalationとinconsistent_stateが同時に成立する場合の優先順位#792 の
run_refinement_preflight.pyは compact stdout と artifact を分け、commands を argv array として扱う実装方針を既に入れています。#795 も同じ設計原則に合わせるべきです。([GitHub]3)5. Allowed Paths の fixture 指定が #802 と同じ罠を踏む可能性がある
#793 の checker 仕様では Verification Commands の
$prefix、Allowed Paths、barepython3などを検出する設計になっています。さらに #802 のレビューでは、tests/fixtures/のような末尾スラッシュ指定が recursive と扱われず、fixture ファイルが Allowed Paths 外と判定される問題が出ています。#795 の Allowed Paths もfixtures/(fixture 追加のみ)型なので、同じ失敗を再現しやすいです。([GitHub]4)修正案:
6. Verification Commands に
$prefix を付けるべき#793 の checker 仕様では、Verification Commands 内の実行コマンドは
$prefix を前提に解析されます。#795 のコマンド群は、今後 #793/#802 系の checker が入ると無駄に落ちる可能性があります。([GitHub]4)#795 の VC はすべて次の形式に寄せるべきです。
高品質化のための追加 AC
最低限、次を #795 に追加した方がよいです。
JSON Schema は、未指定プロパティをデフォルトで許可します。閉じた契約にしたいなら
additionalProperties: falseが必要ですが、将来拡張したいならschema_versionとextensionsのような明示領域を用意するべきです。([JSON Schema]5)修正版 Verification Commands 案
uv runは Python command/script を project environment 上で実行する用途に合っています。Python 内から子プロセスを呼ぶ場合は、Python 公式 docs 上もsubprocess.run()が推奨され、timeout/capture_output 等を持つため、#792 と同じくshell=False+ argv array + timeout を要求するのが妥当です。([Astral Docs]6)技術設計上の注意
Claude Skills の docs は、
SKILL.md本体を簡潔にし、大きな reference/examples/scripts は別ファイル化する設計を推奨しています。また、supporting files は必要時だけ参照させる前提です。したがって #795 の方向性自体は正しいですが、SKILL.md から削った情報を reference に雑に移すだけでは不十分で、「SKILL.md に何を残すか」「script/schema が何を決めるか」の境界を AC で固定する必要があります。([Claude Code]7)また、Claude Skills の
allowed-toolsは安全境界ではなく事前許可の指定に近い扱いです。#795 の成果物は workflow control-plane なので、権限や安全性を frontmatter に期待せず、script 側の入力検証・allowed paths・argv-only command generation で閉じるべきです。([Claude Code]7)推奨コメント案
squne121 commentedon Jun 11, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 11, 2026
Contract Snapshot (2026-06-11T11:50:36Z)
issue-refinement-loop/SKILL.mdが thin control-plane に縮小され、LOOP_STATE schema・reference・next action 判断 script に手順情報が外出しされ、既存 + 新規の pytest と pnpm 品質ゲートが全 PASS した状態のコミットが作成されている## LOOP_STATE Summaryブロック・インラインLOOP_STATE:キー一覧が残っておらず、schema/reference への参照に置換schemas/loop_state.schema.jsonが存在し pytest で schema 検証 PASSdecide_next_loop_action.pyが compact review result fixture から next action を決定し、iteration 上限超過で exit 2 を返すことが pytest で検証uv run非伴走のpython3 .claude/skills/issue-refinement-loop/scripts/実行例が存在しないuv run pytestが全 PASS## Verification Commandsの fenced bash block 参照.claude/skills/issue-refinement-loop/SKILL.md.claude/skills/issue-refinement-loop/schemas/loop_state.schema.json(新規).claude/skills/issue-refinement-loop/references/loop-state.md(新規).claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py(新規).claude/skills/issue-refinement-loop/scripts/decide_rewrite_route.py.claude/skills/issue-refinement-loop/tests/test_loop_state_schema.py(新規).claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action.py(新規).claude/skills/issue-refinement-loop/fixtures/**.claude/worktrees/issue-795-issue-refinement-loop-skill-md-thin-contworktree-issue-795-issue-refinement-loop-skill-md-thin-contpnpm lintが.claude/skills/.system/(untracked)による lint 汚染で blocked だが、worktree 非伝播のため go 判定。実装 worktree では pass となることが確認されているsqune121 commentedon Jun 11, 2026
実装完了
PR #804 を Draft で作成しました。
変更内容
issue-refinement-loop/SKILL.mdから## LOOP_STATE SummaryブロックとインラインLOOP_STATE:キー一覧を削除し、以下の専用アーティファクトへ外出しした。schemas/loop_state.schema.jsonreferences/loop-state.mdscripts/decide_next_loop_action.pyfixtures/loop_state_v1_fixture.jsontests/test_loop_state_schema.pytests/test_decide_next_loop_action.pytests/test_loop_policy.pytests/test_thin_entrypoint.pyAC 検証結果
LOOP_STATE:が SKILL.md から除去、schema/reference 参照に置換test_loop_state_schema.py13テスト全PASStest_decide_next_loop_action.py16テスト(max_iterations超過→exit 2含む)全PASSuv runなし bare python3 呼び出しなし(pytest で negative lookbehind 検証済み)uv run pytest519テスト全PASS、pnpm typecheck/lint/test/build全PASSsqune121 commentedon Jun 11, 2026
squne121 commentedon Jun 11, 2026
post-merge-cleanup: 完了 (2026-06-11T12:49:46Z)
実行内容
.claude/worktrees/issue-795-issue-refinement-loop-skill-md-thin-cont削除済みworktree-issue-795-issue-refinement-loop-skill-md-thin-cont削除済み