Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#2034"
goal_ref: >
#2034 の調査で確認された、grounded_research route における citation/source
provenance 喪失の2つの構造的欠陥(citation `[:1]` 切り詰め、AGY structured
output 未使用)を、provenance-bound structured event adapter で解消する
change_kind: implementationParent Issue
#2034(research-only、AC1-AC6充足・AC7は本Issue起票により充足)
Parent Goal Ref
- Goal: 調査: web-researcher の citation_count 0 fail-closed root cause を特定する #2034 の調査で確認された grounded_research route の citation/source provenance 喪失(citation
[:1]切り詰め、AGY structured output 未使用)の解消 - Desired Destination: grounded_research route が複数 source の evidence を fail-closed citation policy を弱めずに保持できる状態(調査: web-researcher の citation_count 0 fail-closed root cause を特定する #2034 のスコープ)
Current Validated Scope
_build_agy_inner_argv()/_validate_agy_invocation_argv()(run_gemini_headless.py:2698-2758)への--output-format {json,stream-json}allowlist 追加_extract_structured_citations()/_build_agy_grounded_research_metadata()(run_gemini_headless.py:3205-3517)の[:1]truncation 撤廃.claude/agents/web-researcher.mdの materialization 手順更新- 上記に対する positive/negative test 追加
Remaining Parent Gaps
-
WEB_RESEARCH_RESULT_V1.claims[].evidence[]への source-claim 関連付けの deterministic 実装。claim-source は 1:1 ではなく one-to-many/many-to-many(例: source A→claim1, source B→claim1,2, source C→claim2)であるため、単純な cardinality 保持では正しい対応付けにならない。stablesource_idを用いた relation schema(source record を複製せず claim evidence から参照する設計)の実装を別 follow-up Issue(未起票)に切り出す
Outcome
.claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py の grounded_research route において、以下2点が解消され、既存の fail-closed citation policy(generic URL 無条件拒否、Issue #1266/#1708確立)を弱めることなく複数 source の evidence が delegation_result/v1.grounded_research_evidence.sources[] まで保持される状態になる:
_build_agy_grounded_research_metadata()のcitation_evidence = structured_citations[:1]truncation が撤廃され、web_tool_call_count/search_query_countが実測値を反映する- AGY invocation が
--output-format json(またはstream-json)を利用可能になり、既存の_validate_agy_invocation_argv()位置allowlist(Issue 実装: AGY permission-bypass flag 拒否のfail-closed実装と再実行可能テストを追加する #1807)を維持したまま、structured tool-result由来のsource provenanceを保持できる
claim-source の 1:1 対応付けは one-to-many/many-to-many の実態と矛盾するため、本 Issue のスコープは provider boundary(AGY structured event adapter、delegation_result/v1.grounded_research_evidence.sources[] まで)に縮小する。WEB_RESEARCH_RESULT_V1.claims[].evidence[] への deterministic claim-source materialization は別 follow-up Issue(未起票、Remaining Parent Gaps に記載済み)に切り出す。
In Scope
_build_agy_inner_argv()/_validate_agy_invocation_argv()(run_gemini_headless.py:2698-2758)を拡張し、--output-format {json,stream-json}を allowlist に追加する(既存の flag-injection 対策の構造は維持する)- structured output 対応判定は runner が独自に
agy --helpを判定する設計にせず、preflight_agy.pyの既存 capability matrix(同一 binary 束縛)を runner が consume する設計とする - stream-json 使用時は
init/step_update/resultの protocol invariants を strict parser で検証し、malformed/truncated/duplicate terminal stream を fail-closed で拒否する _extract_structured_citations()/_build_agy_grounded_research_metadata()(run_gemini_headless.py:3205-3517)の[:1]truncation を撤廃し、複数 source を cardinality を保持したままcitation_evidenceに含める。web_tool_call_count/search_query_countを実測値(stream-jsonのtool_infoイベント数、またはtext modeでの既存hook event数)から算出する- structured output(json/stream-json)が利用できない環境・バージョンでは明示的に
capability_unavailablefailure_class を返し、旧来の stdout best-effort parsing へ silent fallback しない .claude/agents/web-researcher.mdの materialization 手順を、delegation_result/v1.grounded_research_evidence.sources[](provider boundary)を正しく参照する記述に更新する。claims[].evidence[] への claim-source 1:1 対応付けの決定的手順は本 Issue の Outcome に含めない(別 follow-up Issue に分離。Remaining Parent Gaps参照)- 上記変更に対する positive/negative test を
.claude/skills/gemini-cli-headless-delegation/tests/に追加する
Out of Scope
- citation_countを0→1にするだけの局所修正(#2034で明示的に不採用と結論済み)
- generic URLの無条件regex許可(
_extract_structured_citations()のfail-closed policyを弱める変更は禁止) - AGY/Gemini CLI本体(provider側実装)の修正
_validate_agy_invocation_argv()の-p/--model以外の任意flag許可(--output-formatの値域を明示的に列挙したallowlist拡張のみ許可し、任意文字列を通す変更は禁止。Issue #1807のflag-injection対策を弱めない)- claim-source の 1:1 対応付け・
WEB_RESEARCH_RESULT_V1.claims[].evidence[]への deterministic materialization(one-to-many/many-to-many の実態と矛盾するため別 follow-up Issue に分離。Remaining Parent Gaps参照)
Acceptance Criteria
- AC1:
_build_agy_inner_argv()が--output-format jsonまたはstream-jsonをargvに含められるようになっており、_validate_agy_invocation_argv()がこの2値のみを許可し他の値を引き続きrejectすることがテストで示されている - AC2:
_build_agy_grounded_research_metadata()のcitation_evidenceが[:1]に切り詰められず、複数sourceが存在する場合はcardinalityを保持したまま返されることがテストで示されている - AC3:
web_tool_call_count/search_query_countが実際の呼び出し回数を反映し、固定値1にならないことがテストで示されている - AC4: structured output非対応(
preflight_agy.pyのcapability matrixがunsupported/unavailable/evidence_invalidのいずれかを返す、または実行結果がparse不能)の場合にcapability_unavailable相当のfailure_classを返し、旧来のstdout scrapingへsilent fallbackしないことがテストで示されている - AC5:
_extract_structured_citations()は Vertex host に限定せずdata.sources/data.citations/data.grounding.sourcesの non-empty URL を無条件収集し、Vertex grounding-api-redirect 限定 regex は validated hook event はあるが structured citation がない場合の stdout fallback 専用として維持されるという既存の fail-closed trust policy が、変更後も維持されていることが既存テストの再実行で示されている
Verification Commands
pytest の未収集(no tests ran matching given pattern 等)や usage error は exit 4/5 であり、これは
Verification Infrastructure Failure(テストパス誤り・selector誤り・テスト未追加によるインフラ状態)
として扱い、AC failure とは区別する。AC failure の baseline は「収集成功後の assertion failure、
すなわち exit 1」のみを指す。AC1-AC4 は対象テスト関数がまだ存在しないため、実装者はまずテストを
追加し、追加直後に exit 1(収集成功・assertion failure)を確認してから実装を進めること。
# AC1
# --output-format allowlist(新規テストファイル test_agy_structured_output.py を追加する)
# baseline-expect: fail
# (テスト追加後は exit 1、テスト未追加時点の exit 4 は Verification Infrastructure Failure)
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_output_format_stream_json_allowlisted -q# AC2
# citation cardinality 保持(新規テストファイル test_agy_structured_output.py に追加する)
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_citation_evidence_cardinality_not_truncated_to_one -q# AC3
# web_tool_call_count / search_query_count が実測値を反映する
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_tool_call_count_reflects_actual_invocations -q# AC4
# capability SSOT(preflight_agy.py)を consume し、非対応時は capability_unavailable を返す(新規テストファイル test_agy_structured_output.py に追加する)
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_structured_output_capability_unavailable_returns_fail_closed -q# AC5
# 既存の fail-closed citation trust boundary が変更後も維持されている(既存テストの再実行)
# baseline-expect: pass
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py::test_generic_url_without_vertex_grounding_pattern_not_counted_as_citation .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py::test_validated_hook_event_with_real_grounding_citation_url_is_grounded -qClose gate(PR 提出前に実装者が手動実行し、結果を PR に記載する。baseline_vc_preflight による自動実行対象外とする。理由: 現行 tests/ 配下の実行に約2分を要し、かつ本 Issue のスコープと無関係な既存 failure(test_agy_provider.py::test_ac7_agy_github_research_dispatches_to_e2e_route)が baseline に既に存在するため、Issue-authoring 時点の静的 readiness check では自動実行しない):
uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/ -q
実装完了後、上記コマンドを実行し、本 Issue の変更に起因する新規 failure がないことを確認する。既存の無関係な pre-existing failure が残っている場合は、その旨と該当テスト名を PR 本文に明記し、本 Issue のスコープ外として扱う(別途 follow-up で対処する)。
Allowed Paths
- .claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py
- .claude/skills/gemini-cli-headless-delegation/scripts/preflight_agy.py
- .claude/skills/gemini-cli-headless-delegation/scripts/setup_check.py
- .claude/skills/gemini-cli-headless-delegation/tests/
- .claude/skills/gemini-cli-headless-delegation/tests/test_agy_capability_gate.py
- .claude/skills/gemini-cli-headless-delegation/tests/test_setup_check.py
- .claude/agents/web-researcher.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Python subprocess / argv builder パターン
- NDJSON / stream-json protocol parsing
- pytest
Required Design References
- .claude/agents/web-researcher.md(
WEB_RESEARCH_RESULT_V1スキーマ定義・citation_evidence の materialization 手順) - docs/dev/agy-cli-contract-20260701.md(AGY CLI argv contract。
--output-formatallowlist 拡張の前提)
Runtime Verification Applicability
decision: immediate
reason: >
外部 CLI (AGY) の structured-output protocol / NDJSON event schema /
version-specific runtime semantics を変更対象とし、#2034 で未実測の H5
を本 Issue で解決するため。
applicable_acs:
- AC1
- AC2
- AC3
- AC4
skip_conditions:
- "AGY CLI (`agy`) が実行環境に存在しない、または `preflight_agy.py` の capability matrix が supported 以外を返す場合は SKIP exit 77 とし、PASS へフォールバックしない"
- "AGY 認証(quota/auth/permission)が未設定で live invocation ができない場合は SKIP exit 77 とする"
execution_environment:
cli_tools:
- agy
- python3
- uv
auth_required: true
network_required: true
fallback_policy:
fallback_success_is_pass: false
notes: "structured output 非対応・parse failure 時の stdout best-effort fallback 経由の成功は PASS に変換しない(AC4 の capability_unavailable 判定を維持する)"
artifact_requirements:
- "preflight_agy.py capability matrix 出力(same-binary evidence: realpath/SHA-256/version)"
- "bounded live invocation の sanitized argv / event manifest(raw transcript・credential・絶対 HOME パスを含まない)"
- "pytest output"Notes for Reviewer
- 調査: web-researcher の citation_count 0 fail-closed root cause を特定する #2034(本Issue親)の調査で確定した2つの構造的欠陥(
citation_evidence[:1]切り詰め:run_gemini_headless.py:3489、argv allowlistが--output-formatを構造的に拒否:run_gemini_headless.py:2698-2758)の解消を目的とする。 _validate_agy_invocation_argv()はIssue #1807のflag-injection対策で意図的に厳格化されている。本Issueでの拡張は「値域を列挙したallowlist追加」に限定し、任意flag許可には広げないこと。- H5(structured outputがstdout best-effort parsingを置換できるか)は#2034では
inconclusiveだったため、本Issueの実装/spikeで実測してAC4のfail-closed設計に反映すること。 - P0-4(stream-json event model)補足: upstream の正式な event vocabulary は
init/step_update/resultのみであり、tool_infoは独立した event type ではなく各 tool call に付随する object である。--json-schemaはstream-json全体ではなく terminalresultevent にのみ適用される。strict parser は「exactly one init」「zero or more step_update」「exactly one terminal result(stream の最後の accepted event)」「非空stdout行は必ず1 JSON object」「malformed/truncated/duplicate terminal streamの拒否」「line byte数/event数/nesting depthの上限」「unknown event/step_typeに対するclosed policy」「invalid streamのprefixからのpartial success禁止」を満たすこと。1.1.9以前はinitが利用不能toolを広告し得たため、init.toolsだけをcapability authorityにしない。 - P1 群(実装時の追加防御、要約): (P1-1) stream-jsonのtool情報とtext modeのhook eventの二重計上を避け、
web_tool_call_attempt_count/web_tool_call_success_count等のcount semanticsを分離する。hookはsource payloadのauthorityにしない。(P1-2)tool_info.output等のraw NDJSON全文・parametersを永続化せず、redactionをpersistence前のcommon finalizerで実施し、line byte/event count/URL長等を上限管理する。(P1-3) capability probe(1 query/1 URL/short timeout)とproduction grounded research(bounded N tool calls/M source records/明示的truncation status)を分離し、silent truncationを禁止する。(P1-4)--output-format対応は汎用flag parserへ退化させず、route-specificなtyped argv builderとし、unknown value/duplicate flag/permission bypass option等のnegative testを追加する。(P1-5) structured route既定化はprovider == agy and tool_profile == grounded_research and capability == supportedに限定し、他profileの既存argv/stdout semanticsを回帰テストで維持する。これらはAC/VCへの新規追加は行わず、実装時の設計判断として本セクションに要約するに留める。
Activity
squne121 commentedon Aug 8, 2026
判定
REQUEST_CHANGES — P0 6件。現行の Issue 契約では実装開始不可です。
問題設定そのものは妥当です。現行コードには、複数 citation を
structured_citations[:1]で切り捨て、tool-call 数を実質的な真偽値へ潰している実装があり、_build_agy_inner_argv()/_validate_agy_invocation_argv()も--output-formatを受け付けない固定構造です。親 Issue #2034 でも、この欠陥は確認された一方、structured output が既存経路を置換できるかはinconclusiveのまま #2038 に委譲されています。ただし #2038 は、以下の独立した責務を一つの曖昧な契約へまとめています。
stream-jsonプロトコル解析WEB_RESEARCH_RESULT_V1の materializationこの状態では、citation の件数だけ増え、実際の claim-level evidence が誤対応したままでも AC を通せます。
P0 — 実装前に Issue 契約を修正すべき事項
P0-1. Verification Commands が成立しておらず、baseline failure を誤認する
Issue はテスト追加先と全 pytest コマンドを次のディレクトリへ向けています。
しかし現行リポジトリのテストルートは次です。
既存の
test_agy_invocation_argv_allowlist.py、test_agy_provenance_grounding_wiring.py、test_agy_capability_gate.pyなども後者にあります。Issue の Allowed Paths も誤ったscripts/tests/だけを許可しているため、正しい場所へテストを追加すると scope violation、契約どおりに追加すると既存テスト体系から分離されます。さらに AC5 の selector:
-k "generic_url_rejected or vertex_redirect_only"は、現行の実テスト名である以下のいずれにも一致しません。
したがって AC5 はポリシー検証ではなく、未収集終了になる可能性があります。
pytest では、テストが収集されて assertion が失敗した場合は exit 1、コマンド使用法の誤りは exit 4、テスト未収集は exit 5 です。現在の
baseline-expect: failはこの区別を要求していないため、パス誤りや selector 誤りを「期待した赤テスト」と誤認できます。([pytestドキュメント]1)必須修正
.../tests/へ修正する。-kの曖昧な部分一致ではなく、ファイル名と node ID を固定する。rg -n "cardinality"は削除する。単語が存在することは materialization の正しさを証明しない。P0-2.
Runtime Verification: not_applicableは親 Issue と外部 CLI の性質に矛盾する#2038 は runtime verification を「skill/script と agent prompt の変更のみ」として
not_applicableにしています。しかし変更対象は、外部配布物である AGY CLI の argv、出力形式、NDJSON event schema、tool payload を実際に解釈する runtime adapter です。親 #2034 は、installed AGY 1.1.11 が--output-formatを持つことまでしか確認できず、structured output の source provenance が十分かどうかを #2038 の live prototype に明示的に委譲しています。また、元の grounded-research 実装契約 #1266 は runtime verification を
immediateとし、mock/fixture のみでは close 不可、bounded な live AGY WebSearch evidence を必須としていました。AGY 1.1.8 で
json/stream-jsonが導入された後、1.1.9 ではstream-jsonのinitevent が実際には利用不能な tool を広告する不具合が修正されています。つまり、help text や自作 fixture だけでは runtime semantics を証明できません。([Google Antigravity]2)必須修正
最低限、同一 binary に束縛した以下の sanitized evidence が必要です。
init/step_update/resultevent 件数P0-3. Capability detection の既存 SSOT を破壊する
PR #1982/Issue #1941 は、
preflight_agy.pyを AGY capability detection の唯一の実装 SSOT とし、同一 binary identity への束縛、isolated runtime probe、cost-confirmation gate、sanitization、次の5値分類を導入しています。setup_check.pyもこの capability matrix を consume する設計です。対して #2038 は、runner 側で
agy --helpに--output-formatがあるかを独自判定する設計を要求しています。しかも Allowed Paths にpreflight_agy.py、setup_check.py、capability tests が含まれていません。これでは同じ AGY binary に対して二つの capability authority が生まれます。さらに AC4 は、以下を同じ
capability_unavailableへ潰しています。resultがないこれは capability と protocol evidence validity の混同です。
必須修正
preflight_agy.pyの capability matrix に、少なくとも以下の predicate を追加します。runner は独自に
agy --helpを呼ばず、同一 binary identity に束縛された capability result を consumeします。分類も分けるべきです。
そのため、Allowed Paths には最低でも次を追加する必要があります。
P0-4.
stream-jsonのイベントモデルを誤認しているIssue は
web_tool_call_countを「stream-json のtool_infoイベント数」から算出するとしています。これは upstream protocol と一致しません。Google の正式な changelog が保証している event vocabulary は次です。
tool_infoは独立した event type ではなく、各 tool call に付随する object です。また--json-schemaはstream-json全体ではなく、terminalresultevent にだけ適用されます。([Google Antigravity]2)したがって、現在の契約からは次が定まりません。
tool_infoがどの event/field に入るかstep_updateに複数 tool call が存在し得るかresultより後の event を許可するかinit/resultをどう扱うかresultがない場合の扱いまた AC1 の「
jsonまたはstream-json」も弱すぎます。公式資料はstream-jsonについて per-tool のtool_infoと correlation 可能な payload を明示していますが、通常のjsonが同等の per-call provenance を保持することまでは、この資料から確認できません。([Google Antigravity]2)必須修正
grounded-research route では、原則として
stream-jsonを必須にします。jsonを同等の選択肢に残すなら、同じ source/tool correlation が得られる live evidence と fixture を別途要求すべきです。strict parser の最低条件は次です。
1.1.9 以前の
initは利用不能 tool を広告し得たため、init.toolsだけを capability authority にしてはいけません。([Google Antigravity]2)P0-5. 「cardinality 保持」と「claim-source 対応」を同一視している
Issue は、複数の
citation_evidenceをWEB_RESEARCH_RESULT_V1.claims[].evidence[]へ「1:1で対応付ける」としています。これは一般には成立しません。例として、3 source が2 claimを支える場合、関係は次のような many-to-many です。
source 3件と evidence 3件という cardinality を維持しても、どの source がどの claim を裏付けるかは決まりません。全 source を全 claim へ複製すれば件数は増えますが、実際には裏付けていない source を evidence として誤表示する false grounding になります。
現行
WEB_RESEARCH_RESULT_V1の evidence 要素は概ね次だけです。source_id、tool_call_id、step_idx、args_sha256、query_idなど、wrapper の source record と claim evidence を機械的に結ぶキーがありません。web-researcher は SubAgent-owned SSOT ですが、現在の materialization は自然言語手順であり、親 #2034 も deterministic converter 不在をpartially_supportedと判定しています。web-researcher.mdに「cardinality」と書き、rgで単語を確認しても、この問題は解消しません。必須修正は二択です。
選択肢A: #2038 を provider boundary に縮小する
Outcome を次までに限定します。
WEB_RESEARCH_RESULTへの deterministic claim association は別 Issue に分けます。選択肢B: relation schema を実装する
少なくとも source record に次を持たせます。
claim evidence は source を複製するのではなく、参照します。
これは
WEB_RESEARCH_RESULT_V1の意味論変更になるため、暗黙に v1 を再解釈せず、schema version の更新または明示的な additive compatibility contract が必要です。P0-6. AC5 が既存の citation trust boundary を誤記している
Issue は
_extract_structured_citations()が「generic URL を拒否し、Vertex grounding-api-redirect のみ許可する」と記載しています。実装は異なります。現行
_extract_structured_citations()は structured data の次の field を読みます。そして各 entry の
urlが non-empty string なら収集します。関数単体では Vertex host に限定していません。Vertex redirect 専用 regex は、validated hook event はあるが structured citation がない場合の stdout fallback にだけ適用されます。そこでは free-form stdout の通常 URL を evidence へ昇格させないため、Vertex redirect shape に限定しています。
この区別を誤ったまま AC5 を実装すると、二つの危険があります。
正式な structured stream は canonical tool name、parameters、output を含む
tool_infoを提供します。したがって trust の根拠は URL hostname ではなく、「どの canonical tool call の output から得た source か」であるべきです。([Google Antigravity]2)修正すべき trust policy
URL validation も明文化すべきです。
http/httpsのみP1 — 実装時に必要な追加防御
P1-1. hook と stream の二重計上を防ぐ
Issue は件数を「stream-json の tool 情報、または text mode の hook event」から得るとしていますが、同じ tool call が両方に現れた場合の優先順位がありません。
正式な Hooks 仕様では、
PreToolUseはtoolCall.name/toolCall.args/stepIdxを持ちます。一方、PostToolUseはstepIdxと optional error を持つだけで、tool output 自体は返しません。従って hook は「実行が試みられたこと」の補助証跡にはなりますが、source payload の authority にはできません。([Google Antigravity]3)推奨 authority は次です。
件数も一つの曖昧な count ではなく、最低限分離します。
hook と stream の correlation が取れない場合は、最大値や合計値で誤魔化さず、明示的な provenance mismatch にすべきです。
P1-2.
tool_info.outputの保存・サイズ・秘密情報境界がないupstream の
tool_infoは parameters と output を含みます。そこには検索 query、ページ本文、認証エラー、内部 URL、長大な response が入る可能性があります。([Google Antigravity]2)現行 failure surface は
parsed_evidenceを結果に含められる構造です。このまま stream 全体を parsed evidence として保存すると、既存の「raw transcript を保存しない」という安全条件を迂回します。最低限、以下を契約化すべきです。
tool_info.parametersをそのまま永続化しないP1-3. 1件制限撤廃と quota-bound probe を分離する
現行コードの
[:1]には、#1266 の「1 query/1 URL の bounded live probe」という由来コメントがあります。ただし、これは production research の source cardinality と capability probe のコスト上限を混同した設計です。単に slice を削除すると、今度は source 数や output サイズが無制限になります。
次の二つを分けるべきです。
silent truncation は禁止し、上限到達時は例えば次を返します。
ただし critical claim の source が落ちた状態を
groundedとして成功扱いしてはいけません。P1-4. argv allowlist を汎用 flag parser に退化させてはいけない
現行 builder は実行 argv と audit表示 argv の共通 SSOTであり、validator は固定位置を検証することで、未知の permission-bypass flag や secret-bearing flag を構造的に拒否しています。
--output-format対応は、任意の trailing option を反復解析する実装にしてはいけません。推奨形は route-specific な typed builder です。例:
または model を先にするなら、その一つの順序だけを canonical とします。
negative test が必要です。
--output-format textを grounded route で拒否--output-format--model--output-formatで始まるケースは固定 slot の prompt として安全に受理P1-5. structured route を全 profile に波及させない
_build_agy_inner_argv()は複数 profile の共通経路です。既定でstream-jsonを追加すると、no_tools、proposal_only、local_asset_researchなどの既存 consumer が text stdout を期待している場合に破壊的変更になります。契約は次に限定すべきです。
それ以外の route は既存 argv/stdout semantics を維持し、回帰テストで不変を証明します。
推奨スコープ分割
現行 #2038 は一つの PR としては責務が広すぎます。次の二つへ分割する方が安全です。
Issue A: AGY structured-event adapter
対象:
stream-jsonparser到達点:
Issue B: deterministic claim-source materializer
対象:
WEB_RESEARCH_RESULTschema versioningsource_id到達点:
単一 Issue を維持するなら、少なくとも両方を実コードと end-to-end test で実装し、
web-researcher.mdの文言変更だけで後半を満たしたことにしてはいけません。修正版 Outcome 案
修正版 Acceptance Criteria
Capability SSOT
preflight_agy.pyが same-binary evidence でstream-json/tool_infocapability を5値分類し、runner がその結果を consumeする。Typed argv
grounded-research route だけが固定位置の
--output-format stream-jsonを使用し、unknown/duplicate/extra flag を fail-close する。Protocol parser
init → step_update* → resultを strict に検証し、malformed、truncated、duplicate terminal、result後eventを拒否する。Source provenance
source record が canonical tool call と
step_idx/fingerprint で対応し、model proseだけのURLは受理されない。Cardinality and bounds
複数 source を silent truncationせず保持し、deduplication・上限・上限超過statusが定義される。
Count semantics
attempted、successful、search、read、source、unique URL の件数がfixtureの実測値と一致する。
Failure taxonomy
unsupported/unavailable/evidence_invalid/incomplete/no_citations/auth/quota/query_error を混同しない。
Security
prompt、credential、raw transcript、raw tool output、repo absolute path が result/error/artifact に残らない。
Claim relation
scopeに残す場合、複数claim・複数source fixtureで正しい many-to-many associationを検証し、unknown/orphan
source_idを拒否する。Runtime evidence
current installed AGY binaryで bounded live run を実行し、sanitized event manifest と derived source recordsを保存する。mock-onlyではclose不可。
Regression
grounded-research 以外の profile の argv/stdout semantics が変化していない。
Full suite
skill配下の全テストが成功する。
修正版 Verification Commands 案
baseline は、上記収集が成功した後の assertion failure、すなわち exit 1 のみを期待値とします。exit 4/5 は baseline failure として受理しません。([pytestドキュメント]1)
総合判断
#2038 が対象としている実不具合は存在します。しかし現在の Issue は、
tool_infoを event とみなす protocol 誤認を含んでいます。
このまま実装すると、citation 件数だけ増えた false-green、source と claim の誤対応、または正当な通常URLの全廃棄のいずれかへ進む可能性が高いです。Issue 本文を先に改稿し、provider adapter と claim materializer を分離した後に実装へ進むのが妥当です。
squne121 commentedon Aug 8, 2026
Contract Review Result
squne121 commentedon Aug 8, 2026
issue-refinement-loop: approved
反映した修正(iteration ごと)
Parent Goal Ref/Current Validated Scope/Remaining Parent Gaps/Required Skills/Stop Conditions/Required Design References)を追加。preflight のmissing_required_sectionblocker を解消。.claude/skills/gemini-cli-headless-delegation/scripts/tests/→.claude/skills/gemini-cli-headless-delegation/tests/に修正(codebase-investigator の fact-check で実在パスを確認)test_generic_url_without_vertex_grounding_pattern_not_counted_as_citation等)へ修正not_applicable→immediateへ変更preflight_agy.py/setup_check.py/ 関連テストを追加し capability SSOT 統合方針を明記_extract_structured_citations())に整合させて修正VERDICT: needs-fix(C11:decision: immediateに対し AC へのruntime-verification: trueタグ欠落)<!-- runtime-verification: true -->タグを追加。review 結果:VERDICT: approve(blockers: 0)Final Gate
CONTRACT_REVIEW_ONCE_RESULT_V1.status: go(mode: static, source: all_checks_pass, body_sha256: sha256:42dc47ad21d040ac5f68832b13ed0b087b66b0f800bbe0f652c5d16702bc9216)Follow-up Materialization
blocked-by #2038、dedupe_key:follow-up:squne121/loop-protocol:issuecomment-5226138774:claim-source-materializer)実装: structured output capability の Runtime Verification (decision: im…
docs: web-researcher.md の #2038 追記見出しに日本語を併記する (#2038)
squne121 commentedon Aug 8, 2026
implement-issue: 実装完了 (2026-08-08T14:20:00Z)
.claude/worktrees/issue-2038-agy-structured-outputworktree-issue-2038-agy-structured-output## Runtime Verification Evidence(動作検証の証跡)参照fix_delta: AGY structured output の production wiring 未到達バグと two-stage…
fix_delta: legacy grounded_research 経路で hook 未corroboration の stdout …
実装: grounded_research route の citation truncation と AGY structured ou…