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 前検出」で完走できる状態
Current Validated Scope
scripts/agent_ops_inventory.pyを新規追加し、issue-refinement/pr-review/workflow-implementation/product-implementation/agent-ops-reviewの task-kind 別 read plan を決定論的に出力するtests/test_agent_ops_inventory.pyとtests/fixtures/agent-ops/を追加し、task-kind 別 include/exclude・missing file warn・artifact containment・stdout guard を検証するCLAUDE.md/AGENTS.mdに agent ops task の read plan 例外を最小追記する
Remaining Parent Gaps
- SessionStart hook からの自動起動(parent 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 の hook 規律 child で検討)
Background
CLAUDE.md の既定読込順はゲーム実装 task には妥当だが、Issue refinement / hook / skill 整備のような agent ops task では product docs や src/ の過読を招きやすい。そこで task-kind ごとに MUST_READ と初期読込除外対象を決定論的に出す inventory script を追加し、agent が CLAUDE.md 読了後に追加で読む文脈を絞り込めるようにする。
この Issue の効果は「ランタイムが自動投入する初期 context を削ること」ではなく、agent が追加で読む product docs / src/ / playtest docs を抑制することに限定する。stdout は compact result のみを返し、raw evidence / raw inventory / raw log は artifact 側へ隔離する。
Outcome
agent_ops_inventory.py と pytest・fixtureが追加され、--task-kind issue-refinement が issue-refinement-loop 周辺の最小 MUST_READ と初期読込除外対象を返し、--task-kind agent-ops-review が .agents/skills/**・.claude/skills/**・.codex/**・hooks・tests/fixtures/codex-agent-config/expected-runtime-contract.json を含む tracked metadata-only inventory artifact を出力する。CLAUDE.md / AGENTS.md には read plan 例外が追記され、Codex profile の品質ゲートが全 PASS する。
In Scope
agent_ops_inventory.pyの新規実装- 入力:
--task-kind issue-refinement|pr-review|workflow-implementation|product-implementation|agent-ops-review、--repo-root - task-kind ごとの
MUST_READと初期読込除外対象(DO_NOT_READ_INITIAL_ONLYまたは同等の machine-readable field)を出力する agent-ops-reviewでは.agents/skills/**、.claude/skills/**、.codex/**、hooks、tests/fixtures/codex-agent-config/expected-runtime-contract.jsonを inventory/read 対象に含めるagent_ops_inventory.pyでの.agents/skills/**検出はtests/fixtures/codex-agent-config/expected-runtime-contract.jsonとcheck_codex_agent_config.pyの route/surface 契約から同期し、手書きリストにしない- tracked files の metadata のみを artifact 化し、file contents は保存しない
- 欠落した期待ファイルは
STATUS: warn以上、critical route surface 欠落はSTATUS: blockedとして返す
- 入力:
- pytest(task-kind 別 read plan / missing file warn / stdout schema / artifact containment /
.agents/skills/**inclusion / security guard) tests/fixtures/codex-agent-config/expected-runtime-contract.jsonとcheck_codex_agent_config.pyとの.agents/skills/**surface 同期を検証する pytest を追加するCLAUDE.mdの「まず読む順序」への agent ops task 例外追記AGENTS.mdへの同等の最小追記
Out of Scope
- agent に追加読込を禁止する強制機構
- repository 全体の dependency graph 作成
- product docs の削除・移動
- 各 SKILL.md 本文の変更
- custom subagent の初期 context 注入方式そのものの変更
Acceptance Criteria
- AC1:
PlanSpecregistry(task-kind→include/exclude の機械可読 SSOT)を実装し、--task-kind issue-refinementの出力でMUST_READが issue-refinement-loop の SKILL / scripts / 対象 agent 定義の最小集合になっていることが pytest で検証されている - AC2:
--task-kind issue-refinementの出力で初期読込除外対象にdocs/product/とsrc/が含まれ、追加読込禁止ではないことが machine-readable に表現されている - AC3:
--task-kind agent-ops-reviewが.agents/skills/**とtests/fixtures/codex-agent-config/expected-runtime-contract.jsonを含む inventory artifact JSON を生成する - AC4: 期待ファイル欠落 fixture で
STATUS: warn以上が返り、critical route surface 欠落はSTATUS: blockedに上がることが pytest で検証されている - AC5: stdout は artifact path のみを
EVIDENCEとして返し、2048 UTF-8 bytes 以内でscripts/check_agent_friendly_stdout.pyに通る。pytest 内でも stdout fixture をcheck_agent_friendly_stdout.pyに通して検証する(独自実装禁止) - AC6: artifact 対象は
git ls-files -z由来の tracked repo-relative path のみ。artifact JSON フィールドはpath/exists/kind/trackedに限定し、mtime・absolute path・file contents は禁止。..・absolute path・symlink escape・untracked file 混入は pytest で fail。0600 permission・secret-like string 非含有を満たす - AC7:
CLAUDE.mdとAGENTS.mdに agent ops task の read plan 例外が追記されている - AC8:
rtk pnpm typecheck/rtk pnpm lint/rtk pnpm test/rtk pnpm buildが全 PASS する
Verification Commands
# AC1
$ uv run pytest tests/test_agent_ops_inventory.py -v
# AC2
$ rg -n "DO_NOT_READ_INITIAL_ONLY|DEFER_READ|initial_exclusion_not_absolute_forbid" tests/test_agent_ops_inventory.py scripts/agent_ops_inventory.py
# AC3
$ rg -n "\.agents/skills/|expected-runtime-contract\.json|agent-ops-review" scripts/agent_ops_inventory.py tests/test_agent_ops_inventory.py
# AC4
$ rg -n "STATUS: warn|STATUS: blocked|critical route surface" tests/test_agent_ops_inventory.py
# AC5
$ uv run pytest tests/test_agent_ops_inventory.py -v -k "stdout"
# AC6
$ rg -n "0600|symlink|absolute path|containment|tracked metadata" scripts/agent_ops_inventory.py tests/test_agent_ops_inventory.py
# AC7
$ rg -n "agent_ops_inventory|read plan" CLAUDE.md AGENTS.md
# AC8
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildAllowed Paths
- scripts/agent_ops_inventory.py(新規)
- tests/test_agent_ops_inventory.py(新規)
- tests/fixtures/agent-ops/(新規)
- CLAUDE.md(read plan 例外の追記のみ)
- AGENTS.md(read plan 例外の追記のみ)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(task-kind、stdout key、artifact schema、security guard)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
CLAUDE.md/AGENTS.mdの読む順序変更が product task の既存境界を壊すと判明した場合
Required Skills
なし
Scope Delta(任意)
implementationtask-kind をworkflow-implementation/product-implementationに分割し、agent-ops-reviewの inventory 対象に.agents/skills/**と agent parity fixture を追加する
Delivery Rule
1 Issue = 1 PR、worktree 上で実装し Draft PR を作成するCLAUDE.md/AGENTS.mdへの追記は各 10 行以内を目安とし、詳細は script の--helpと artifact schema に置く- artifact 保存先は tmp artifact dir または git 混入回避を明示した worktree-local path に限定し、repo tracked file として commit しない
Notes for Reviewer
.agents/skills/**は Codex custom agent の repo-local discovery surface、.claude/skills/**は canonical body 側であるEVIDENCEは artifact path のみとし、raw evidence を stdout に返さないDO_NOT_READ_INITIAL_ONLY相当のキーは「初期読込除外」であり、追加読込禁止ではない
Runtime Verification Applicability
decision: not_applicable
reason: "workflow/docs/test/script 中心の contract refinement であり、本 Issue 単体で UI やゲーム挙動の runtime verification を成立させる対象ではない"
Activity
squne121 commentedon Jun 12, 2026
判定
REQUEST_CHANGES。
#796 は方向性としては妥当ですが、現行 main と関連 PR の状態を前提にすると、Issue contract が古く、実装すると「決定論的に見えるが不完全な read plan」を作る危険があります。#796 自体にコメントはなく、少なくとも Issue 本文上では実装 PR へのリンクも確認できませんでした。親 #791 は、agent ops の token/context 浪費、subagent raw output 還流、late preflight 検出を解消する child 群の一つとして #796 を位置付けています。
Blocker 1:
.agents/skills/**が抜けている#796 の
agent-ops-reviewは.claude/**/.codex/**/ hooks / scripts を inventory 対象にしていますが、PR #807 以降の現行設計では.agents/skills/が Codex custom agent の repo-local discovery surface です。docs/dev/agent-runtime-ops.mdも.agents/skills/を Codex discovery surface、.claude/skills/を canonical body 側として明記しています。さらにscripts/check_codex_agent_config.pyはruntime_followup_routeを.agents/skills/<token>/SKILL.mdに写像し、fixture でも issue-author / issue-reviewer / pr-reviewer 系が.agents/skills/**を期待しています。このままだと、#796 の inventory は Claude 側と Codex TOML だけを見て、Codex が実際に発見する thin bridge を見落とします。
agent-ops-reviewの対象に.agents/skills/**とtests/fixtures/codex-agent-config/expected-runtime-contract.jsonを明示してください。Allowed Paths に追加する必要があるのは「変更する場合」だけですが、少なくとも read/inventory 対象としては必須です。Blocker 2: 「CLAUDE.md 例外」で初期ロード削減は達成できない
#796 は
CLAUDE.md/AGENTS.mdに agent ops task の read plan 例外を追記する設計ですが、Claude Code の公式ドキュメント上、custom subagent は fresh isolated context を持つ一方で、初期 context に system prompt、task message、CLAUDE.md/ memory、git status、preloaded skills が入ります。CLAUDE.mdと git status を読み込まないのは built-in の Explore / Plan subagent だけで、任意の custom subagent に「CLAUDE.md を最初から読まない」frontmatter はありません。([Claude API Docs]1)したがって #796 の効果は「ランタイムが勝手に読み込む初期 context の削減」ではなく、CLAUDE.md 読了後に agent が追加で読む product docs / src / playtest docs を抑制することに限定して書くべきです。ここを誤ると、効果測定で「思ったほど token が減らない」問題になります。
Blocker 3:
MUST_READの「最小集合」が未定義でテスト不能#796 は
--task-kind issue-refinement|pr-review|implementation|agent-ops-reviewを定義していますが、各 task-kind のMUST_READを何から導出するかが曖昧です。特にimplementationは、ゲーム実装・workflow 実装・docs-only 実装で必要文脈が大きく異なります。#796 自身も「product docs を必要とする task-kind では除外しすぎない」と書いていますが、この条件は script から判定できません。修正案は、
implementationをそのまま扱わず、少なくとも次のどちらかに寄せることです。implementationではissue_kind/change_kind/ Allowed Paths を読んでworkflow-implementationとproduct-implementationに内部分類するworkflow-implementation/product-implementationに分けるまた、
MUST_READはコード中の散在リストではなく、PlanSpec的な registry に寄せ、pytest では task-kind ごとの exact include/exclude を検証してください。Blocker 4:
DO_NOT_READは命名が強すぎるIssue 本文では
DO_NOT_READを「初期 context から意図的に除外」であり、blocked や人間指示があれば追加読込可と説明しています。ただし、キー名だけ見ると downstream agent が絶対禁止と解釈しやすい。これは agent ops では危険です。必要時に product docs を読むべき implementation task を過剰に遮断する恐れがあります。固定 contract を変えられるなら
DEFER_READまたはDO_NOT_READ_INITIAL_ONLYに改名する方が安全です。変えないなら artifact にread_policy: "initial_exclusion_not_absolute_forbid"を持たせ、stdout のSUMMARYでも「追加読込禁止ではない」ことを短く出してください。Blocker 5: stdout と artifact の安全境界が弱い
#796 は stdout キーに
EVIDENCEを含めていますが、既存のrun_refinement_preflight.pyは raw issue body / comments をEVIDENCEとして stdout に出さない、と明示しています。既存の compact result 系も artifact path だけを返す設計で、raw body / raw diff / raw log を main context に返さない方針です。agent_ops_inventory.pyも同じ方針にしてください。EVIDENCEは artifact path のみ、stdout は 2KB 以下、raw inventory / raw file list / raw command logs は artifact 側に隔離。既にscripts/check_agent_friendly_stdout.pyが UTF-8 byte limit、raw diff/log、ANSI、巨大 code fence を検査できます。#796 の AC にこの linter を追加すべきです。Blocker 6:
.claude/artifacts/agent-ops/の扱いが git / secret 境界と衝突する#796 は inventory artifact を
.claude/artifacts/agent-ops/に保存するとしていますが、現行.gitignoreには.claude/artifacts/が無視対象として載っていません。.claude/settings.local.jsonなどの local-only 設定は ignore されていますが、.claude/**を雑に inventory すると、未追跡・ローカル・secret-adjacent なファイルを拾うリスクがあります。既存の artifact security test は、artifact の containment、
../ absolute path 拒否、0600 permission、secret-like string 検出を検証しています。#796 も同等の AC を持つべきです。特にagent-ops-reviewは.claude/**/.codex/**/ hooks を横断するため、原則git ls-filesベースで tracked files の metadata のみ inventory し、file contents は保存しない方が安全です。Blocker 7: Verification Commands が現行 checker と衝突する
#796 の Verification Commands は
$prefix なしで書かれています。一方、check_vc_scope.pyは## Verification Commandsの fenced block 内で$なしのコマンドをVC_MISSING_DOLLAR_PREFIXとして warn にします。さらに
AGENTS.mdは Codex 実行ではrtkを使い、rtkwrapper がある場合は directpnpmを避けるよう要求しています。#796 の AC6 は directpnpm typecheck/lint/test/buildになっており、Codex 実行契約と食い違います。修正例:
Claude 実行と Codex 実行の両対応にするなら、Issue 本文に「Codex では
rtk pnpm、Claude/manual ではpnpm可」と明記してください。高品質化する実装方針
agent_ops_inventory.pyは、単なる path list printer ではなく、以下の契約にしてください。実装上の要点は次の通りです。
--repo-rootはPath.resolve()し、artifact path は repo root 配下に containment check する../ absolute path / symlink escape を拒否するpath,exists,kind, 必要ならsha256程度に限定する.agents/skills/**、.claude/skills/**、.codex/agents/**、hooks、agent parity fixture を current reality として含めるSTATUS: warnにし、critical route surface 欠落はSTATUS: blockedに上げる.agents/skillsinclusion を検証する公式 Codex 側でも、AGENTS.md は run/session ごとに instruction chain として読み直され、近い階層の AGENTS.md が優先されます。したがって
AGENTS.md追記は 1〜3 行に抑え、詳細は script の--helpと artifact schema に置く方が安全です。([OpenAI Developer]2)推奨する Issue 修正
#796 は実装着手前に、最低限これを追記・修正してください。
agent-ops-reviewinventory 対象に.agents/skills/**とtests/fixtures/codex-agent-config/expected-runtime-contract.jsonを追加implementationtask-kind を分割、または issue contract から内部分類する仕様を追加EVIDENCEは artifact path のみ、raw evidence stdout 禁止を明記DO_NOT_READは初期読込除外であり絶対禁止ではないことを machine-readable に固定$prefix を付け、Codex ではrtk pnpmを使う.claude/artifacts/agent-ops/に生成する artifact が git に混入しない運用を決める。.gitignoreを触れないなら、テストは tmp repo / tmp artifact dir で完結させるこの修正なしに実装すると、#791 の「token/context 浪費削減」には寄与しても、Codex discovery surface の欠落・artifact 漏洩・過剰な read 抑制という新しい運用負債を作る可能性が高いです。
squne121 commentedon Jun 12, 2026
issue-refinement-loop を anchor comment に基づいて 1 周で更新し、live body を再検証しました。
check_issue_contract.py:verdict: approvecontract_readiness_check.py --mode static:status: gocheck_vc_scope.py:STATUS: PASSFOLLOW_UP_MATERIALIZATION_RESULT_V1:
squne121 commentedon Jun 12, 2026
CodexCLI作業ログ
squne121 commentedon Jun 13, 2026
判定
REQUEST_CHANGES(実装前レビューとして)。
#796 は、初回コメントの主要指摘を受けて
.agents/skills/**追加、task-kind 分割、stdout/artifact 境界、artifact security、rtk pnpm化まで反映済みで、refinement-loop 側でもapprove / go / PASSになっています。とはいえ、これは Issue 本文の静的整合が通ったという意味であり、「安全に token/context を削減できる実装契約」まではまだ弱いです。#796 は parent #791 の child で、目的は agent ops の token/context 浪費を preflight・compact contract・hook 規律で削減することです。周辺には #793、#794、#797、#798、#799 があり、#796 はその中でも「静的 read plan / inventory」を担当するべきです。
ブロッカー
1. 「初期 context 削減」と誤解される余地がまだ危険
Claude Code の custom subagent は fresh context で動きますが、通常の custom subagent は
CLAUDE.md/ memory / git status などを初期 context に含みます。Codex も run/session ごとにAGENTS.mdを読んで instruction chain を作ります。したがって #796 の効果は ランタイム初期ロード削減ではなく、CLAUDE.md / AGENTS.md 読了後の追加読込を絞ることに限定されます。ここを計測・宣伝文句で誤ると、実装後に「token が期待ほど減らない」問題になります。([Claude API Docs]1) ([OpenAI Developers]2)要求変更: Outcome / Summary / tests に「initial context は削れない。追加読込の deterministic read plan を返すだけ」と明記してください。
2.
.agents/skills/**は単なる include ではなく、validator 由来で導出すべきPR #807 以降、Codex の repo-local discovery surface は
.agents/skills/*/SKILL.md、canonical body は.claude/skills/*/SKILL.mdという二層構造です。repo docs も同じ境界を明記しており、validator はruntime_followup_routeを.agents/skills/<token>/SKILL.mdに写像して exact match を見ています。要求変更:
agent_ops_inventory.pyで.agents/skills/**を手書きリストにしないでください。tests/fixtures/codex-agent-config/expected-runtime-contract.jsonとcheck_codex_agent_config.pyの route/surface 契約に同期する検証を入れるべきです。手書き registry だけだと、PR #807 系の変更に追随できず、また “決定論的だが古い inventory” になります。3.
MUST_READの「最小集合」は registry + matrix test がないと偽装できる現行 #796 は task-kind を
issue-refinement/pr-review/workflow-implementation/product-implementation/agent-ops-reviewに分割済みです。これは改善ですが、敵対的に見るとrgで文字列が存在するだけでも AC を通せます。要求変更:
PlanSpec相当の registry を固定し、pytest で task-kind ごとの exact include/exclude を検証してください。特にproduct-implementationだけはdocs/product//src/を安易にDO_NOT_READ_INITIAL_ONLYに入れてはいけません。逆にissue-refinement/agent-ops-reviewでは product docs を初期 defer する、という差分を fixture で固定すべきです。4. artifact security は “metadata-only” の定義が弱い
#796 は tracked metadata-only inventory を要求していますが、metadata でも漏洩面があります。たとえば未追跡の
.claude/artifacts/**、local-only 設定、secret-adjacent なファイル名、mtime、ローカル絶対パスを artifact に入れると、stdout に出さなくても保存物が危険になります。初回レビューでもgit ls-filesベース・file contents 非保存・0600・secret-like 検査が要求されていました。要求変更: artifact 対象は
git ls-files -z由来の tracked repo-relative path のみにしてください。artifact JSON には少なくともpath,exists,kind,tracked程度に限定し、mtime・absolute path・file contents は禁止。..、absolute path、symlink escape、untracked file 混入は pytest で fail にするべきです。5. stdout guard は既存 checker を再利用し、独自実装しない
#794 系で
scripts/check_agent_friendly_stdout.pyが既に UTF-8 byte limit、raw diff、raw log、ANSI escape、巨大 code fence を検出します。#796 はこの checker をそのまま consume すべきで、同じ判定をagent_ops_inventory.py内に再実装すると drift します。要求変更: AC5 は
uv run python3 scripts/check_agent_friendly_stdout.py ... --max-bytes 2048実行だけでなく、pytest 内でも stdout fixture を checker に通してください。rg "2048"のような文字列検査は補助に落とすべきです。6. AGENTS.md / CLAUDE.md 追記は 1〜3 行でよい
Codex Skills は progressive disclosure で、最初は
name/description/ path を見て、必要時に fullSKILL.mdを読む設計です。AGENTS.md も run/session の instruction chain に入るため、ここへ長い read-plan 表や schema 説明を置くと、#796 の目的に反して毎回の context を増やします。([OpenAI Developers]3) ([OpenAI Developers]2)要求変更:
AGENTS.md/CLAUDE.mdには「agent ops task ではscripts/agent_ops_inventory.py --task-kind ...を先に実行する」程度だけ追記し、詳細は--helpと artifact schema に置くべきです。実装品質ライン
最低限、以下を満たす PR でないと approve しない方がよいです。
最終コメント案
#796 は 方向性は妥当です。特に初回レビュー後に
.agents/skills/**、task-kind 分割、stdout/artifact 境界、artifact security、rtk pnpm化まで取り込んだ点は正しいです。ただし、現状のまま実装に入ると、
rgで AC を満たしているように見せるだけの read-plan printer になる危険があります。実装 PR では、PlanSpecregistry、実 CLI 実行 pytest、tracked metadata-only artifact、既存 stdout checker の再利用、.agents/skillsvalidator 契約との同期まで必須にしてください。推奨アクション: #796 の本文に「初期 context は削減できない」「registry + matrix test 必須」「metadata-only の禁止項目」「既存 stdout checker consume」「AGENTS/CLAUDE 追記は極小」の 5 点を追加してから実装 PR を切る。
squne121 commentedon Jun 13, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 14, 2026
CONTRACT_REVIEW_RESULT_V1
squne121 commentedon Jun 14, 2026
実装完了
Draft PR を作成しました: #903
実装内容
scripts/agent_ops_inventory.py(新規): PlanSpec registry + agent-ops-review inventory artifact generatortests/test_agent_ops_inventory.py(新規): 48 テスト(47 passed, 1 skipped)tests/fixtures/agent-ops/(新規): fixture JSON 2 件CLAUDE.md/AGENTS.md: agent ops read plan 例外を追記AC 検証結果
implement(#796): agent_ops_inventory.py で task-kind 別最小読込を決定論化する
fix(#796): apply PR review fixes 1-6 to agent_ops_inventory
implement(#796): agent_ops_inventory.py で task-kind 別最小読込を決定論化する (#903)