Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#646"
goal_ref: "issue-refinement-loop の終了レポートを guard 互換 renderer ライブラリとして新設し、TERMINATION_REPORT_RENDER_RESULT_V1 JSON を返す deterministic template + dry-run + 上限付き再生成を実装する"
change_kind: codeParent Issue
Parent Goal Ref
- Goal:
issue-refinement-loopの終了レポート(human_escalation / needs-fix / max_iterations)を guard 互換 template から生成し、投稿前 dry-run guard に失敗したら本文回避ではなく再生成へ戻す - Desired Destination: 終了レポートは deterministic template から生成され、投稿前に同一 classifier で dry-run され、失敗時は上限付きで再生成し、上限超過時は公開投稿せず reason_code を local artifact / stderr に残す
Current Validated Scope
.claude/skills/issue-refinement-loop/scripts/render_termination_report.pyの新設(3 種終了レポートの deterministic 生成 + dry-run + 上限付き再生成).claude/skills/issue-refinement-loop/references/termination-policy.mdへの dry-run guard / 再生成上限 / 非投稿 reason_code の規約追記- 対応する unit test の追加
- 本 Issue は renderer ライブラリの新設のみを対象とする。callsite integration(loop 本体の Step 5 への組み込み)は follow-up Issue に委譲する
TERMINATION_REPORT_RENDER_RESULT_V1JSON のみを stdout に出力し、投稿可能 markdown 本文を stdout / stderr に出さないprose_boundary_policyの公開 API(classify_block等)のみを import し、guard 判定 regex / block classifier を再実装しない- attempt 1: normal deterministic template、attempt 2: fallback minimal template の最大 2 試行のみ(LLM / ask / network / gh command なし)
- GFM fence injection への防御(dynamic fence)
Remaining Parent Gaps
- shadow / enforce mode は child-4 に委譲する
- 公開 mutation route matrix の整備は child-2 に委譲する
Outcome
.claude/skills/issue-refinement-loop/scripts/render_termination_report.py が、human_escalation / approved の終了レポートを guard 互換の deterministic template から生成し、TERMINATION_REPORT_RENDER_RESULT_V1 JSON を stdout に返す。termination_reason(approved / human_escalation / superseded_by_decision)と termination_cause(needs_fix_at_iteration_limit / max_iterations_exceeded 等)を分離した構造を持つ。生成後に child-0 #653 の prose_boundary_policy 公開 API で dry-run guard を実行し、失敗した場合は 1 回だけ fallback minimal template に切り替え、なお失敗なら publishable=false、body=null、固定 reason_code を返す。stdout は常に machine JSON のみ、stderr は diagnostics のみ。GFM fence injection を防ぐ dynamic fence を使用する。無制限 regeneration / LLM / ask / gh command を呼ばないことが unit test で固定される。termination-policy.md に本フローが規約として記載される。callsite integration は follow-up Issue に委譲する。
Background
#646 の reviewer Blocker 6 は、終了レポートの dry-run guard 失敗時の上限が無く、無制限再生成や人間確認への逃げが起きうると指摘している。実際に #646 の refinement では、checker が要求する英語見出しや必須 marker <!-- LOOP_HANDOFF_RESULT_V1 --> を guard が prose として block する現象が観測された。本 Issue は終了レポート生成を deterministic template + 上限付き dry-run へ寄せて解消する。child-0(#653)の prose classifier SSOT を dry-run に使う。
In Scope
- 3 種終了レポートの deterministic template 生成関数
- 投稿前 dry-run guard(child-0 SSOT の classifier 使用)
- 上限付き(1 回)template-safe regeneration
- 上限超過時の公開非投稿と reason_code 出力
- 無制限 regeneration / ask escape hatch を持たないことのテスト
TERMINATION_REPORT_RENDER_RESULT_V1schema の定義(publishable / body / reason_code / attempts / classifier フィールド)termination_reason(approved / human_escalation / superseded_by_decision)とtermination_cause(needs_fix_at_iteration_limit / max_iterations_exceeded / human_judgment_required 等)の分離- stdout: machine JSON のみ / stderr: diagnostics のみ の出力契約
prose_boundary_policy公開 API のみ import(分類 regex を再実装しない)- attempt 1: normal template、attempt 2: fallback minimal template の最大 2 試行
- GFM fence(
```/~~~)/ HTML marker(<!-- LOOP_HANDOFF_RESULT_V1 -->)/ 英語 stack trace を含む adversarial input に対する dynamic fence - simulated replay evidence(GitHub mutation が発火しない証跡)
Out of Scope
- prose classifier SSOT 自体の変更(child-0 実装(#646): prose / code / machine-readable / heading / tmp draft / public output 分類の prose boundary policy SSOT 化 #653 で確定)
- heading_policy(child-1)
- 公開 mutation route matrix(child-2)
- shadow / enforce mode(child-4)
issue-refinement-loopの loop 判定ロジック(planner SSOT)の変更- callsite integration(issue-refinement-loop Step 5 への render_termination_report.py 組み込みは follow-up Issue に委譲)
approved終了の LOOP_HANDOFF_RESULT_V1 投稿経路の実装(callsite 未接続のため)
Acceptance Criteria
- AC1:
render_termination_report.pyが存在し、TERMINATION_REPORT_RENDER_RESULT_V1JSON を stdout に返す - AC2:
publishable=trueかつbody != nullの場合のみ公開投稿用 body が存在する。publishable=falseのときbodyはnull - AC3: renderer は
prose_boundary_policyの公開関数(classify_block等)のみを import し、guard 判定 regex / block classifier を再実装しない - AC4: template は deterministic であり、attempt 1(normal template)と attempt 2(fallback minimal template)の最大 2 試行のみを実行する。LLM / ask / network / gh command を呼ばない
- AC5: 2 試行後も guard fail の場合、
publishable=false、body=null、固定reason_codeを返す - AC6: stderr / local artifact にも投稿可能 markdown 本文を出さない
- AC7:
needs-fix/max_iterationsはtermination_reasonではなくtermination_causeとして扱い、termination_reasonはapproved/human_escalation/superseded_by_decisionのみとする - AC8: GFM fence(
```/~~~)/ HTML marker(<!-- LOOP_HANDOFF_RESULT_V1 -->)/ 英語 stack trace を含む adversarial input でも template 構造が壊れない(dynamic fence 使用) - AC9: simulated replay evidence を PR に添付し、GitHub mutation が発火していないことを示す(RVA: simulated replay required; no real GitHub mutation)
- AC10: 既存の issue-refinement-loop テストが回帰なく PASS する
Verification Commands
# AC1
# preflight-scope: pr_review_only
$ rg -n "human_escalation|needs-fix|max_iterations" .claude/skills/issue-refinement-loop/scripts/render_termination_report.py
# AC1
# preflight-scope: pr_review_only
$ rg -n "TERMINATION_REPORT_RENDER_RESULT_V1" .claude/skills/issue-refinement-loop/scripts/render_termination_report.py
# AC2
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -q -k "termination_report"
# AC3
# preflight-scope: pr_review_only
$ rg -n "from.*prose_boundary_policy import|import prose_boundary_policy" .claude/skills/issue-refinement-loop/scripts/render_termination_report.py
# AC3
# preflight-scope: pr_review_only
$ rg -cn "re\.compile|re\.search|re\.match" .claude/skills/issue-refinement-loop/scripts/render_termination_report.py
# AC4
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -q -k "no_llm or no_ask or no_network or attempts"
# AC5
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -q -k "guard_fail_publishable_false or limit_exceeded"
# AC6
$ rg -n "dry.run|再生成|reason_code|TERMINATION_REPORT_RENDER_RESULT_V1" .claude/skills/issue-refinement-loop/references/termination-policy.md
# AC7
# preflight-scope: pr_review_only
$ rg -n "termination_reason.*needs.fix|termination_reason.*max_iterations" .claude/skills/issue-refinement-loop/scripts/render_termination_report.py
# AC7
# preflight-scope: pr_review_only
$ rg -n "termination_cause" .claude/skills/issue-refinement-loop/scripts/render_termination_report.py
# AC8
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -q -k "fence or adversarial or injection"
# AC9
# preflight-scope: pr_review_only
$ rg -n "TERMINATION_REPORT_RENDER_RESULT_V1|publishable|body.*null|reason_code" .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py
# AC10
$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -qAllowed Paths
- .claude/skills/issue-refinement-loop/scripts/render_termination_report.py
- .claude/skills/issue-refinement-loop/references/termination-policy.md
- .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py
- .claude/skills/create-issue/scripts/prose_boundary_policy.py(読み取り参照のみ。変更不可)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(終了レポート種別 / 再生成上限 / reason_code)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Python(pytest / unittest)
- issue-refinement-loop の終了 marker / 終了レポート仕様の理解
- guard classifier の dry-run 連携
Scope Delta(任意)
N/A
Delivery Rule
- 1 Issue = 1 PR
- Draft PR で開始、レビュー後にマージ
- child-0(実装(#646): prose / code / machine-readable / heading / tmp draft / public output 分類の prose boundary policy SSOT 化 #653)と child-1(実装(#646): canonical / bilingual heading 除外と heading_policy を checker / guard で共有 #654)のマージ後に着手する(prose_boundary_policy SSOT 依存)
- callsite integration は follow-up Issue に委譲する(実装(#646): issue-refinement-loop 終了レポートの guard 互換 renderer ライブラリ新設 #656 完了後に起票)
Source(重複排除キー)
follow-up:squne121/loop-protocol:issue/646:child-3-termination-report-dry-run
関連
- 導入: guard-japanese-prose と issue contract authoring boundary の統合修正 #646(親 Issue / 配信ロールアップ追跡)
- 実装(#646): prose / code / machine-readable / heading / tmp draft / public output 分類の prose boundary policy SSOT 化 #653(child-0 / 散文境界ポリシー SSOT、前提 Issue)
Runtime Verification Applicability
rva_schema_version: v1
applicability: deferred
decision: deferred
reason: "render_termination_report.py の終了レポート生成・dry-run・上限付き再生成・非投稿経路は unit test で決定論的に検証できる。ただし GitHub mutation が発火しないことは simulated replay evidence で確認する(実 GitHub 投稿は不要)"
deferred_destination:
destination_type: pr_evidence
destination_ref: "PR 本文の Evidence セクション"
deferred_verification_condition: "simulated termination input で renderer stdout JSON / publishable=false 証跡 / classifier failure 証跡 / GitHub mutation 非発火証跡を PR に添付する"
Activity
squne121 commentedon Jun 6, 2026
判定:REQUEST_CHANGES
Issue #656 は、親 Issue #646 の Blocker 6「終了レポートを deterministic template → same guard dry-run → bounded regeneration → 失敗時 no public post + reason_code」に対応する方向性としては妥当です。#656 自体も、child-0 #653 の SSOT classifier を使い、1回だけ再生成し、それでも失敗したら公開本文を返さない、という契約を明記しています。([GitHub]1)
ただし、現状の Issue 契約のまま実装すると、**「テストだけ通る未接続レンダラ」「非終端状態の終了レポート化」「guard 失敗時の本文漏洩」「親 #646 の runtime evidence 未充足」**が残ります。実装着手前に Issue を修正すべきです。
致命的ブロッカー
B1.
render_termination_report.pyが実運用に接続されない可能性が高い#656 の Allowed Paths は、新規
render_termination_report.py、termination-policy.md、テストだけです。([GitHub]1)一方、現在の
issue-refinement-loop/scriptsには planner 系スクリプトしかなく、終了レポート投稿経路にこの新規 renderer を呼ばせる既存変更点が Issue 上に定義されていません。([GitHub]2)これは実装事故になります。PR が「renderer と unit test を追加しました」で終わると、実際の loop は従来どおり危険な本文を生成・投稿し得ます。
修正案
#656 の scope に次を追加してください。
既存 callsite を今回変更しないなら、Issue 名を「renderer library の追加」に縮小し、別 Issue で wiring を必須化すべきです。
B2.
needs-fix/max_iterationsを「終了レポート種別」として扱う設計が危険#656 は report type として
human_escalation/needs-fix/max_iterationsを並べています。([GitHub]1)しかし現在の
termination-policy.mdでは、needs-fix + max_iterationsはhuman_escalationにルーティングされる条件であり、終端 reason はapproved/human_escalation/superseded_by_decisionの体系に寄っています。([GitHub]3)このままだと、本来は loop 継続判断である
needs-fixを終端コメントとして投稿する実装が入り得ます。修正案
termination_reasonとtermination_causeを分けるべきです。#656 の対象が失敗系のみなら、
approvedを out-of-scope と明記してください。逆に「終了レポート全体」を扱うなら、既存LOOP_HANDOFF_RESULT_V1/FOLLOW_UP_MATERIALIZATION_RESULT_V1との互換性を AC に入れる必要があります。([GitHub]3)B3. guard 失敗時の出力契約が弱く、本文漏洩を防げない
#656 は「上限超過時に no public body returned、reason_code を local artifact/stderr」と書いています。([GitHub]1)
しかし、CLI が stdout に markdown 本文を一度でも出す設計だと、呼び出し側が誤ってその本文を GitHub に投稿できます。
Claude Code hooks では、コマンド hook は stdin で JSON を受け取り、exit code / stdout / stderr / JSON で制御する設計です。特に exit code 2 はブロック、JSON output は exit 0 のとき処理されるため、exit code と JSON を混在させる設計は明確に決める必要があります。([Claude Code]4)
修正案
renderer の stdout は常に machine JSON のみにしてください。
{ "schema": "TERMINATION_REPORT_RENDER_RESULT_V1", "publishable": false, "body": null, "reason_code": "termination_report_guard_failed_after_regeneration_limit", "attempts": 2, "classifier": { "name": "prose_boundary_policy", "passed": false } }公開可能なときだけ:
{ "schema": "TERMINATION_REPORT_RENDER_RESULT_V1", "publishable": true, "body": "<markdown body>", "reason_code": null }stderr は diagnostics のみに限定し、投稿可能な markdown 本文を絶対に出さない、という AC を追加すべきです。
B4. 「child-0 SSOT classifier を使う」が API レベルで未定義
#653 は
prose_boundary_policy.pyを新設し、validate_japanese_content.pyの分類をそこへ委譲する scope でした。([GitHub]5)PR #658 でも SSOT 化自体は merge 済みですが、レビュー上では
split_markdown_blocksの完全 SSOT 化が別 Issue #659 に切り出され、GFM fence 周辺の限界が明示されています。([GitHub]6)#656 側で「同一 classifier」とだけ書くと、実装者が以下のどれでも通せてしまいます。
validate_japanese_content.pyの private 関数を叩く修正案
Issue に exact API 契約を追加してください。
さらに、
split_markdown_blocksの未解決分は #659 依存にするか、#656 側で「fence 埋め込みを避ける / dynamic fence を使う」方針を明記すべきです。B5. 「template-safe regeneration」が未定義で、LLM 再生成の抜け道になる
#656 は「1回だけ template-safe regeneration」と書いていますが、何を変える再生成なのか定義されていません。([GitHub]1)
deterministic template が guard に落ちるなら、同じ入力から同じ本文を出す限り再生成しても再失敗します。ここに LLM を挟むと、親 #646 の「no ask / deterministic repair signal」方針と衝突します。([GitHub]7)
修正案
再生成は有限個の deterministic template variant に限定してください。
テストでは
attempts <= 2、input()/ ask 相当 / subprocess 投稿呼び出しがないことを検証すべきです。B6. 親 #646 の runtime verification 条件と #656 が矛盾している
親 #646 は child-0〜child-4 について、CI unit tests に加えて shadow または Claude Code replay evidence を PR evidence として要求しています。([GitHub]7)
#656 は child-3 ですが、Runtime Verification Applicability を
not_applicableとしています。([GitHub]1)これは親 Issue の closure criteria を満たさない可能性があります。
修正案
実 GitHub 投稿は不要です。ただし、少なくとも次を PR evidence に要求してください。
not_applicableではなく、simulated replay required; no real GitHub mutationが妥当です。B7. Markdown / GFM fence injection への備えが不足
GFM の fenced code block は、開始 fence と同じ文字で、かつ同じ長さ以上の closing fence で閉じます。閉じられない fence は文書末尾まで code block になります。([GitHub Docs]8)
終了レポートは reviewer comment や blocker summary を取り込む可能性があるため、入力に ````` や
<!-- LOOP_HANDOFF_RESULT_V1 -->が含まれると、template の YAML / markdown 構造を壊せます。#658 のレビューでも、4-backtick fence を 3-backtick で誤って閉じる問題が指摘され、follow-up に回されています。([GitHub]6)
修正案
renderer には dynamic fence を実装し、外部テキストをそのまま template 構造に混ぜないでください。
追加すべき adversarial test:
追加の改善点
VC の grep が曖昧
#656 の VC にある
needs.fixは regex の.が任意1文字になるため、意図が曖昧です。([GitHub]1)needs[-_]fixまたはneeds-fix|needs_fixにしてください。pytest のテスト名依存が強い
pytest は
test_*.py/*_test.pyの discovery とassertに基づいて動きます。([pytestドキュメント]9)-k "limit_exceeded_no_publish and reason_code"のような VC は、実装者がテスト名を合わせるだけで中身が弱くなります。VC には具体的な期待値も書くべきです。修正後の AC 案
#656 の AC は次のように置き換えるのが安全です。
採用判断
この Issue は、親 #646 の方針を実装する重要 Issue としては必要です。
ただし現状のままだと、guard 互換 renderer という部品は作れても、実際の公開投稿経路の安全性を保証できません。
最小修正は次の4点です。
TERMINATION_REPORT_RENDER_RESULT_V1の stdout JSON 契約を固定termination_reasonとtermination_causeを分離この修正なしなら、#656 は実装 Issue として merge 不可です。
[-]実装(#646): issue-refinement-loop 終了レポートの guard 互換 dry-run と上限付き再生成[/-][+]実装(#646): issue-refinement-loop 終了レポートの guard 互換 renderer ライブラリ新設[/+]squne121 commentedon Jun 6, 2026
Issue Refinement Loop 終了レポート(人間エスカレーション)
Issue #656 の refinement loop が最大反復回数(3 回)に達しました。VC preflight の機械チェックが最終反復でブロックしています。
全反復のブロッカー履歴
残存ブロッカー(反復 2 終了時点)
パス指定が広すぎる(9 件)
check_issue_contract.pyが VC 内のrgコマンドのパスを「広すぎる」と判定しています。具体的なファイルパスを指定していますが、Allowed Paths との照合方式に解釈差異があります。バックスラッシュ付きパイプ(4 件)
VC 内の
rgコマンドのパターンに\|が含まれています。|に修正してください。対象箇所はprose_boundary_policy importの検索パターンとtermination_reason系のパターンです。推奨アクション
残存問題はいずれも機械的な修正です。
\|を|に置換(4 箇所)人間が Issue 本文を直接修正するか、ループを再実行してください。
アンカーコメント対応状況
B1〜B7 の全ブロッカーは反復 0→1 の書き換えで反映済みです。
squne121 commentedon Jun 6, 2026
コントラクトレビュー: BLOCKED (2026-06-06T00:45:00Z)
不足項目
1. AC マーカー形式の不一致(全 VC が
AC_UNKNOWN)パーサが認識する AC マーカー形式:
# AC1または# AC1:のみ(行末まで)現在の Issue では
# AC1 - 日本語説明形式を使用しており、説明付きサフィックスは認識されません。修正方法: AC 番号行を
# AC1のみの行にする(説明はその次の行に# descriptionとして記載)。例:
# AC2, AC5 - ...のような複数 AC 指定もパーサ非対応です。各コマンドに単一 AC マーカーを付けてください。2. 未作成ファイルへの rg コマンドが
human_judgment分類render_termination_report.py(実装対象の新規ファイル)を指定したrgコマンドは baseline ではexit_code=2(No such file or directory)を返します。classifier はrg exit_code=2をunknown/human_judgmentとして分類します(exit_code=1= no match の場合のみexpected_baseline_fail/go)。修正方法: 新規作成ファイルを対象とする rg コマンドには
# preflight-scope: pr_review_onlyマーカーを追加する(VC の意味論は変わらず、PR レビュー時に検証される)。例:
推奨アクション
issue-refinement-loopの起動を推奨します(承認後に実行可能です)。修正スコープ(VC セクションのみ、Issue 意味論の変更なし):
# ACN形式(説明なし単一行)に統一render_termination_report.py/test_render_termination_report.pyを対象とする rg・pytest コマンドに# preflight-scope: pr_review_onlyを追加termination-policy.mdを対象とする AC6 rg コマンドも同様に対応(ファイル既存のため不要かもしれないが確認が必要)squne121 commentedon Jun 6, 2026
コントラクトスナップショット (2026-06-06T00:50:29Z)
コントラクト要約
render_termination_report.pyが終了レポートを guard 互換 deterministic template から生成し、TERMINATION_REPORT_RENDER_RESULT_V1JSON を返す.claude/skills/issue-refinement-loop/scripts/render_termination_report.py(新設).claude/skills/issue-refinement-loop/references/termination-policy.md(規約追記).claude/skills/issue-refinement-loop/tests/test_render_termination_report.py(新設).claude/skills/create-issue/scripts/prose_boundary_policy.py(読み取り参照のみ).claude/worktrees/issue-656-issue-refinement-loop-guard-rendererworktree-issue-656-issue-refinement-loop-guard-renderersqune121 commentedon Jun 6, 2026
implement-issue: 実装完了 (2026-06-06T01:02:29Z)
.claude/worktrees/issue-656-issue-refinement-loop-guard-rendererworktree-issue-656-issue-refinement-loop-guard-rendererfix(#656): B1/B2/B3 blocker fence injection hardening + B4 CI coverage
squne121 commentedon Jun 6, 2026
PR #688 の人間レビュー REQUEST_CHANGES 対応完了。commit: 2720c8f
修正概要:
B1 -
_make_dynamic_fence()を blocker rendering に使用:_render_normal_template()の blockers_summary 出力を箇条書き形式から json.dumps と dynamic fence で包んだ literal block 形式に変更した。B2 - adversarial input regression tests 追加: tilde fence injection、triple backtick injection、HTML marker injection、改行込みスタックトレース、5 バッククォートシーケンスの 5 ケースを追加。各テストで _run_guard(body) が ok を返すこと、shell_command / vc_command block が現れないことを確認する。
B3 - blockers_summary 要素型の厳密 validation: 全要素が str であることを確認(None・dict・int を拒否)、issue_number / iteration は type() チェックで bool を拒否。テスト 7 件追加。
N1 - render() 先頭で _validate_input() を呼び出し: import 経由の直接呼び出しでも validation が完結する。
B4 - CI workflow に pytest ステップ追加: python-test ジョブに .claude/skills/issue-refinement-loop/tests/ の pytest ステップを追加した。
検証結果: 全 275 テスト pass。pnpm typecheck / lint / test / build も全て pass した。
feat(#656): render_termination_report.py guard-compatible renderer 新設 (…
squne121 commentedon Jun 6, 2026
PR #688 マージ後クリーンアップ完了 (2026-06-06T05:10:00Z)
クリーンアップ完了。follow-up Issue #692(callsite integration)を起票済み。親 Issue #646 は他の子 Issue が未完了のため open 継続。