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: "#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/agents/issue-reviewer.md/.claude/agents/issue-author.mdの出力契約を compact schema に置換する.codex/agents/issue-reviewer.toml/.codex/agents/issue-author.tomlに shared schema 名と artifact path 必須を明記する.claude/skills/issue-refinement-loop/scripts/compact_review_result.py/compact_author_result.pyを新規追加するscripts/check_agent_friendly_stdout.pyを新規追加する.claude/skills/issue-refinement-loop/SKILL.mdの Step 2 / Step 4 consumer をISSUE_REVIEW_RESULT_COMPACT_V1/ISSUE_AUTHOR_RESULT_COMPACT_V1に更新する(Allowed Paths に追加)
Remaining Parent Gaps
- SubagentStop hook での digest artifact 化(parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の hook 規律 child で対応)
- Claude/Codex agent 定義の schema 名 parity 検証(parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の parity linter child で対応)
Background
Issue #781 の refinement loop で issue-reviewer / issue-author が合計 7 回起動し、表示上約 158k display tokens の subagent 出力が発生した。subagent 出力が raw のまま main context に戻ると subagent 隔離の意味が薄れる。既存の OUTPUT_BUDGET_V1(#296、CLOSED)は prompt-level の soft constraint であり、本 Issue はこれを決定論的 schema + 変換 script + fixture 検査に強化する(仕様変更ではなく機械化)。効果測定 research #312 とは独立して進められる。
- reviewer 出力は
ISSUE_REVIEW_RESULT_COMPACT_V1(STATUS/VERDICT/SUMMARY/BLOCKERS/NEXT_ACTION/MUST_READ/EVIDENCE/ARTIFACT)に限定する - author 出力は
ISSUE_AUTHOR_RESULT_COMPACT_V1(mutation 結果を body hash / comment URL / artifact path で返す)に限定する - full review / candidate body は
.claude/artifacts/issue-refinement-loop/<N>/に保存し、main context には artifact path のみ返す - subagent の最終応答は compact script の stdout のみとし、raw review / body / diff / log を main context に返してはならない
Outcome
reviewer / author の Claude / Codex agent 定義が compact result schema のみを出力契約とし、compact_review_result.py / compact_author_result.py / check_agent_friendly_stdout.py と pytest・fixture が追加され、stdout 2048 UTF-8 bytes 制限と raw 出力禁止が fixture で PASS した状態のコミットが作成されている。
In Scope
compact_review_result.py: raw review text を入力にISSUE_REVIEW_RESULT_COMPACT_V1stdout と full artifact JSON を生成する(verdict / evidence 欠落時は exit 2)compact_author_result.py: author 実行結果をISSUE_AUTHOR_RESULT_COMPACT_V1に変換する(body hash / artifact path 必須)scripts/check_agent_friendly_stdout.py: stdout fixture が schema 準拠・--max-bytes 2048(UTF-8 bytes で計測)以下・raw diff(diff --git/@@hunk)/ raw log(Traceback/npm ERR!/ ANSI escape sequence)を含まないことを検査する CI 可能な linter.claude/agents/issue-reviewer.md/issue-author.md: 出力契約セクションを compact schema 参照に置換し、raw issue body / raw comments / raw diff / raw logs の main 返却を禁止する。issue-author.mdは mutation 前にcheck_vc_scope.pyを必ず実行し、blocked 結果は mutation を禁止、warn 結果は compact output に明記する.codex/agents/issue-reviewer.toml/issue-author.toml: shared schema 名・full output artifact path 必須・check_vc_scope.py利用(author の mutation 前)を明記する.claude/skills/issue-refinement-loop/SKILL.md: Step 2 / Step 4 の consumer contract をISSUE_REVIEW_RESULT_COMPACT_V1/ISSUE_AUTHOR_RESULT_COMPACT_V1に更新する- artifact write:
.claude/artifacts/issue-refinement-loop/<N>/配下のみ許可、../ absolute path 拒否、atomic write、0600 permission 相当、stdout への secret-like 文字列(token / key / cookie / Authorization header 風文字列)出力禁止 - pytest / fixture(日本語テキスト・2048 bytes pass / 2049 bytes fail・raw diff fail・traceback fail・ANSI escape fail・path traversal fail・必須フィールド欠落 fail を含む)
Out of Scope
- subagent の利用停止・起動回数 / max_iterations の削減(perf(claude): issue-refinement-loop を軽量化する(max_iterations=1 デフォルト / SubAgent 条件付き) #295 で対応済み)
- model selection / reasoning effort の変更
- OUTPUT_BUDGET_V1 の仕様変更・効果測定(perf(#296): OUTPUT_BUDGET_V1 効果測定 — SubAgent 代表実行での output_chars/lines 測定 #312 の責務)
- SubagentStop hook の追加(parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の hook 規律 child)
- schema の正本を
docs/dev/agent-skill-boundaries.mdへ追記すること(compact scripts の constants と tests でのみ保持する)
Acceptance Criteria
- AC0:
check_vc_scope.py(実装: VC scope preflight checker(check_vc_scope.py)を issue-refinement-loop に追加する #793 成果物)が main にマージされており、.claude/agents/issue-author.mdと.codex/agents/issue-author.tomlの両方で mutation 前に実行される。blocked 結果は mutation を禁止し、warn 結果は compact output に明記される - AC1:
.claude/agents/issue-reviewer.mdと.codex/agents/issue-reviewer.tomlがISSUE_REVIEW_RESULT_COMPACT_V1を出力契約として参照している - AC2:
.claude/agents/issue-author.mdと.codex/agents/issue-author.tomlがISSUE_AUTHOR_RESULT_COMPACT_V1を出力契約として参照している - AC3:
compact_review_result.pyが raw review fixture から compact stdout と full artifact JSON を生成し、verdict 欠落時に exit 2 を返すことが pytest で検証されている - AC4:
scripts/check_agent_friendly_stdout.pyが 2049 bytes 超(UTF-8)/ raw diff / raw log / ANSI escape を含む fixture を fail させ、日本語テキストを含む 2048 UTF-8 bytes 以下の準拠 fixture を pass させることが pytest で検証されている - AC5: subagent の最終応答は compact script の stdout のみとする。raw review / body / diff / log が main context に返るケースを fixture が fail させることが pytest で検証されている
- AC6:
.claude/skills/issue-refinement-loop/SKILL.mdの Step 2 / Step 4 consumer contract がISSUE_REVIEW_RESULT_COMPACT_V1/ISSUE_AUTHOR_RESULT_COMPACT_V1を参照している - AC7: artifact write が
.claude/artifacts/issue-refinement-loop/<N>/配下のみ、../ absolute path を拒否し、atomic write・0600 permission 相当・stdout への secret-like 文字列出力禁止が fixture で検証されている - AC8: pnpm typecheck / lint / test / build が全 PASS する
Verification Commands
# AC0
$ rg -n "check_vc_scope" .claude/agents/issue-author.md .codex/agents/issue-author.toml
# AC1
$ rg -n "ISSUE_REVIEW_RESULT_COMPACT_V1" .claude/agents/issue-reviewer.md .codex/agents/issue-reviewer.toml
# AC2
$ rg -n "ISSUE_AUTHOR_RESULT_COMPACT_V1" .claude/agents/issue-author.md .codex/agents/issue-author.toml
# AC3
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_compact_review_result.py -v
# AC4
$ uv run pytest tests/test_check_agent_friendly_stdout.py -v
# AC5
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_compact_author_result.py -v
# AC6
$ rg -n "ISSUE_REVIEW_RESULT_COMPACT_V1|ISSUE_AUTHOR_RESULT_COMPACT_V1" .claude/skills/issue-refinement-loop/SKILL.md
# AC7
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_artifact_security.py -v
# AC8
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildRuntime Verification Applicability
applicability: immediate
decision: immediate
rationale: pytest fixture で compact stdout・artifact security・raw 出力禁止を自動検証できる。pnpm 品質ゲートも即時実行可能。Allowed Paths
- .claude/agents/issue-reviewer.md
- .claude/agents/issue-author.md
- .codex/agents/issue-reviewer.toml
- .codex/agents/issue-author.toml
- .claude/skills/issue-refinement-loop/SKILL.md
- .claude/skills/issue-refinement-loop/scripts/compact_review_result.py(新規)
- .claude/skills/issue-refinement-loop/scripts/compact_author_result.py(新規)
- .claude/skills/issue-refinement-loop/tests/test_compact_review_result.py(新規)
- .claude/skills/issue-refinement-loop/tests/test_compact_author_result.py(新規)
- .claude/skills/issue-refinement-loop/tests/test_artifact_security.py(新規)
- .claude/skills/issue-refinement-loop/fixtures/(fixture 追加のみ)
- scripts/check_agent_friendly_stdout.py(新規)
- tests/test_check_agent_friendly_stdout.py(新規)
- tests/fixtures/agent-stdout/(新規)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- 既存 OUTPUT_BUDGET_V1 規約(docs/dev/agent-skill-boundaries.md)との矛盾が見つかり規約側の変更が必要になった場合
Required Skills
なし
Scope Delta
.claude/skills/issue-refinement-loop/SKILL.mdを Allowed Paths に追加(consumer contract 名 COMPACT_V1 への更新を明示的な破壊的変更として扱うため).claude/skills/issue-refinement-loop/tests/test_artifact_security.pyを Allowed Paths に追加(artifact security 検証のため)
Delivery Rule
1 Issue = 1 PR、worktree 上で実装し Draft PR を作成する- Depends on 実装: VC scope preflight checker(check_vc_scope.py)を issue-refinement-loop に追加する #793 merge(
check_vc_scope.pyが main にマージされていることを前提とする) .claude/agents/issue-reviewer.md/issue-author.mdを触る他 OPEN Issue があればマージ順を直列化する
Notes for Reviewer
- schema の正本は compact scripts の constants と tests でのみ保持する。
docs/dev/agent-skill-boundaries.mdへの追記は本 Issue のスコープ外 .claude/skills/issue-refinement-loop/SKILL.mdを Allowed Paths に追加し、consumer contract 名変更(COMPACT_V1 移行)を破壊的変更として明示した- 2048 bytes 制限は UTF-8 bytes で検証する(日本語文字列を含む fixture を用意する)
- raw diff / raw log 禁止条件:
diff --git・@@hunk・Traceback・npm ERR!・ANSI escape sequence・巨大 code fence を fixture 化する - perf(#296): OUTPUT_BUDGET_V1 効果測定 — SubAgent 代表実行での output_chars/lines 測定 #312 は効果測定。本 Issue は deterministic enforcement のみを扱い、削減効果の測定は perf(#296): OUTPUT_BUDGET_V1 効果測定 — SubAgent 代表実行での output_chars/lines 測定 #312 に委譲する
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 11, 2026
判定
REQUEST_CHANGES。#794 は方向性は正しいですが、現状のIssue契約のまま実装に入ると危険です。
特にまずいのは、「compact script を追加する」だけでは raw subagent output が main context に返ることを防げない点です。#794 の目的は #781 で発生した「issue-reviewer / author 7回起動、約158k display tokens」の再発防止であり、単なる後処理ツール追加では目的を満たしません。#794 自体は compact schema、artifact path、stdout 2048 bytes、raw diff/log 禁止、fixture test を掲げていますが、出力契約・既存skillとの互換・#793 preflight との整合がまだ甘いです。([GitHub]1)
#794 本体には現時点で紐づくPR/branchは表示されておらず、実質的な関連実装は依存先 #793 / PR #802 側です。#794 は Delivery Rule で #793 merge 後を前提にしていますが、取得時点では #793 と PR #802 はまだ open でした。PR #802 は最終的に check 類が通り approve されていますが、redaction / artifact permission は「制御済みではない」非ブロッカーとして残っています。([GitHub]1)
ブロッカー
1. #794 自身の Verification Commands が #793 の規律に違反している
#793 の checker は Verification Commands 配下のコマンド行について、
$prefix を期待し、非$の command-like line をVC_MISSING_DOLLAR_PREFIXとして扱う設計です。一方、#794 の Verification Commands はrg .../uv run pytest .../pnpm ...が$なしで列挙されています。#794 は #793 の author pre-mutation checker に依存するIssueなのに、自分の契約がそのcheckerで警告対象になる可能性があります。([GitHub]2)修正: #794 の Verification Commands はすべて
$prefix 付きに正規化するべきです。これは実装前のIssue本文修正で済むため、先に直してください。2. schema の Single Source of Truth が Allowed Paths と矛盾している
#794 の Notes は、schema source を
docs/dev/agent-skill-boundaries.mdまたは skill 側 schema に置く可能性を残しています。しかし Allowed Paths にはdocs/dev/agent-skill-boundaries.mdもschemas/も含まれていません。つまり実装者は、のどれかに陥ります。実装: issue-reviewer / issue-author に compact subagent result contract を導入し raw 出力の main 還流を止める #794 の AC は schema 名の
rg確認に寄っており、実体としてのschema定義を保証していません。([GitHub]1)修正: どちらかに決めるべきです。
compact_review_result.py/compact_author_result.pyの constants と tests でのみ保持し、Issue本文からdocs/dev/agent-skill-boundaries.md可能性を削除する。.claude/skills/issue-refinement-loop/schemas/compact-results.schema.jsonを Allowed Paths に追加し、Claude / Codex agent はその schema name と artifact path だけを参照する。3. compact script が「subagent final output」を支配しないと意味がない
#794 は
compact_review_result.py/compact_author_result.pyを追加し、full review / candidate body を artifact に逃がし、main context には artifact path だけ返す設計です。しかし、Issue本文のままだと「script を追加して fixture test する」ことは読めても、subagent の最終応答が必ず script stdout になることまでは契約されていません。これでは subagent が先に raw review を返し、その後に compact artifact を作るだけの失敗モードが残ります。([GitHub]1)Claude Code の subagent は task description / invocation によって呼び出され、SubagentStart / SubagentStop hook などの lifecycle hook も別機構として存在します。したがって #794 は「hook enforcement は #797」と割り切るのはよいですが、少なくとも agent contract 上で final answer は compact script のstdoutだけと明記しないと、main context 汚染を閉じられません。([Claude API Docs]3)
修正: AC に次を追加してください。
4. 既存の
REVIEW_ISSUE_RESULT_V1/ISSUE_AUTHOR_RESULT_V1と互換性が壊れる可能性がある既存の
.claude/agents/issue-reviewer.mdはREVIEW_ISSUE_RESULT_V1を出す契約で、deterministic_checksやdiff_proposalなどを含む設計です。.claude/skills/issue-refinement-loop/SKILL.md側も Step 2 / Step 4 でREVIEW_ISSUE_RESULT_V1/ author result を前提にしています。#794 がISSUE_REVIEW_RESULT_COMPACT_V1/ISSUE_AUTHOR_RESULT_COMPACT_V1に単純置換すると、既存 orchestrator の読み取り前提とズレます。([GitHub]4)修正: どちらかを明確化してください。
SKILL.mdも Allowed Paths に入れ、Step 2 / Step 4 の consumer contract を更新し、互換テストを追加する。現状の Allowed Paths には
.claude/skills/issue-refinement-loop/SKILL.mdがありません。なので、契約名を変えるなら scope が足りません。5. Claude author 側の
check_vc_scope.pyintegration が明示されていない#794 は Codex 側 agent toml について shared schema name / artifact path /
check_vc_scope.pyuse を書いていますが、Claude 側.claude/agents/issue-author.mdに対して VC scope checker を pre-mutation に差し込むことがACとして十分に明示されていません。既存の Claude issue-author には contract hygiene repair の pre-mutation hook 相当の手順があり、ここに #793 checker を差し込むのが自然です。([GitHub]1)修正: AC に明記してください。
6. artifact に raw body / raw review を保存するなら redaction・permission が未解決
#794 は full review / candidate body を
.claude/artifacts/issue-refinement-loop/<N>/に保存し、main context には artifact path のみ返す設計です。しかし PR #802 の最終レビューでも、artifact redaction / file permission は「制御済みではない」扱いでした。#794 はさらに raw output / body を artifact 化するIssueなので、この未解決点は非ブロッカーではなく設計要件に昇格します。([GitHub]1)最低限必要な仕様:
../ absolute path を拒否。0600相当。非ブロッカーだが直した方がよい点
2048 bytesは 文字数ではなくUTF-8 bytes で検証する必要があります。日本語を含む stdout fixture を追加してください。raw diff/logの禁止条件が曖昧です。diff --git、@@hunk、Traceback、npm ERR!、巨大 code fence、ANSI escape sequence を fixture 化してください。.codex/agents/*.tomlに置けますが、child agent の sandbox / approval などは親runtime overrideを受けます。重要な保証を TOML の記述だけに頼らず、script / tests / output checker で閉じるべきです。([OpenAI Developer]6)SKILL.mdを必要時に読む設計なので、長いschemaやfixture説明を agent 定義に直書きせず、schema/reference/script に逃がす方が目的に合っています。([OpenAI Developer]7)Issue本文への具体的な修正案
追加すべき Acceptance Criteria
Verification Commands はこう直す
そのままIssueコメントに貼るなら
squne121 commentedon Jun 11, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 11, 2026
ClaudeCode作業ログ
squne121 commentedon Jun 11, 2026
Contract Snapshot (2026-06-11T12:12:02Z)
Contract Summary
Outcome:
.claude/agents/issue-reviewer.md/issue-author.mdと.codex/agents/issue-reviewer.toml/issue-author.tomlが compact result schema のみを出力契約とし、compact_review_result.py / compact_author_result.py / check_agent_friendly_stdout.py と pytest・fixture が追加され、stdout 2048 UTF-8 bytes 制限と raw 出力禁止が fixture で PASS した状態のコミットが作成されているAcceptance Criteria: AC0〜AC8(8項目)
Verification Commands(baseline: expected_fail=8, expected_pass=4, blocked=0):
rg -n "check_vc_scope" .claude/agents/issue-author.md .codex/agents/issue-author.tomlrg -n "ISSUE_REVIEW_RESULT_COMPACT_V1" .claude/agents/issue-reviewer.md .codex/agents/issue-reviewer.tomlrg -n "ISSUE_AUTHOR_RESULT_COMPACT_V1" .claude/agents/issue-author.md .codex/agents/issue-author.tomluv run pytest .claude/skills/issue-refinement-loop/tests/test_compact_review_result.py -vuv run pytest tests/test_check_agent_friendly_stdout.py -vuv run pytest .claude/skills/issue-refinement-loop/tests/test_compact_author_result.py -vrg -n "ISSUE_REVIEW_RESULT_COMPACT_V1" .claude/skills/issue-refinement-loop/SKILL.md/rg -n "ISSUE_AUTHOR_RESULT_COMPACT_V1" ...uv run pytest .claude/skills/issue-refinement-loop/tests/test_artifact_security.py -vpnpm typecheck / lint / test / buildAllowed Paths:
.claude/agents/issue-reviewer.md/issue-author.md.codex/agents/issue-reviewer.toml/issue-author.toml.claude/skills/issue-refinement-loop/SKILL.md.claude/skills/issue-refinement-loop/scripts/compact_review_result.py(新規).claude/skills/issue-refinement-loop/scripts/compact_author_result.py(新規).claude/skills/issue-refinement-loop/tests/test_compact_review_result.py(新規).claude/skills/issue-refinement-loop/tests/test_compact_author_result.py(新規).claude/skills/issue-refinement-loop/tests/test_artifact_security.py(新規).claude/skills/issue-refinement-loop/fixtures/(fixture 追加のみ)scripts/check_agent_friendly_stdout.py(新規)tests/test_check_agent_friendly_stdout.py(新規)tests/fixtures/agent-stdout/(新規)Worktree:
.claude/worktrees/issue-794-issue-reviewer-issue-author-compact-subaBranch:
worktree-issue-794-issue-reviewer-issue-author-compact-subaVC preflight: baseline fail = 8, 想定外 pass = 0, 実行不可 = 0, regression_gate pass = 4
squne121 commentedon Jun 11, 2026
implement-issue: 実装完了 (2026-06-11T12:28:03Z)
.claude/worktrees/issue-794-issue-reviewer-issue-author-compact-subaworktree-issue-794-issue-reviewer-issue-author-compact-subafix: apply B1-B8 review fixes to compact scripts and agent contracts (#…
feat: add compact subagent result contract for issue-reviewer/author (#…