Skip to content

実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する #248

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#391"
goal_ref: "gemini-cli-headless-delegation の file evidence を commit 固定・excerpt hash 付きの REPO_EVIDENCE_REF_V1 として返し、orchestrator が再利用前に決定論的に検証できるようにする"
change_kind: workflow
contract_change_level: schema_additive

Parent Issue

#391(issue-refinement-loop を script-first / thin entrypoint 化し OPEN 改善 Issue を段階統合する)

Parent Goal Ref

  • Goal: SubAgent-owned contract migration の一部として、codebase-investigator が返す repo file evidence の精度保証を gemini-cli-headless-delegation 側の output contract に SSOT 化する
  • Desired Destination: orchestrator は schema を再定義せず consumer / validator として振る舞い、file:line 精度保証は delegation skill の REPO_EVIDENCE_REF_V1 で担保される

Current Validated Scope

  • gemini-cli-headless-delegation の output contract に REPO_EVIDENCE_REF_V1 を追加する(主変更先: .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md / result-surface.md)
  • REPO_EVIDENCE_REF_V1 は file evidence について commit_sha(40-char SHA)/ path / start_line / end_line / permalink / excerpt_sha256 / anchor_text(human fallback)/ verified_at を持つ
  • mutable branch URL(blob/main / tree/main 等)を file evidence として禁止する(commit SHA 固定 permalink のみ許容)
  • anchor_text(section 見出し / symbol 名)は人間向け fallback であり正本ではない(同名見出し・section 移動に弱いため)
  • line range / excerpt hash が検証不能な場合、verification_status: inconclusive を要求し caller は authoritative な file:line として扱わない
  • .claude/agents/codebase-investigator.md は schema を再定義せず、REPO_EVIDENCE_REF_V1 への cross-link と「inconclusive を verified に昇格しない」「verification metadata 欠如の evidence を authoritative な file:line として扱わない」「委譲失敗時は fail-close し自力 fallback 調査しない」の consumer-side 受け取りルールだけを置く
  • .claude/skills/issue-refinement-loop/SKILL.md の ANCHOR_COMMENT_FACT_CHECK_RESULT_V1.evidence[] は、kind: file のとき自由文字列 ref ではなく REPO_EVIDENCE_REF_V1 構造を要求する additive rule を追加する
  • 軽量 validator(fixture / script)で mutable URL と excerpt hash mismatch を reject できることを示す

Remaining Parent Gaps

Outcome

gemini-cli-headless-delegation の output contract に REPO_EVIDENCE_REF_V1 が commit_sha / path / start_line / end_line / permalink / excerpt_sha256 / anchor_text / verified_at を必須フィールドとして定義され、mutable branch URL(blob/main 等)が file evidence として禁止され、codebase-investigator.md / issue-refinement-loop/SKILL.md が schema を再定義せず cross-link / consumer-validation のみで参照しており、軽量 validator が mutable URL と hash mismatch を reject でき、pnpm typecheck && pnpm lint && pnpm test && pnpm build が全 PASS している状態。

Source

  • 観察事実(調査: AI agent session 記録ツール(EntireCLI 等)導入の是非と運用前提を決定する #136 refinement loop 実走時, 2026-05-23):
    • codebase-investigator に docs/dev/agent-skill-boundaries.md L604-L633 Hook-based Ledger Optional Design を context として渡した
    • SubAgent 側でその line range を流用したが、実ファイル上の実際の位置(L741 周辺)と一致しないという指摘が issue-author から発生
    • issue-author が自前で実ファイルを確認し line number を修正したが、本来は delegation skill の output 時点で line accuracy を保証すべき
  • 観察事実(実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する #248 anchor comment, 2026-05-25):
    • 人間コメント: 「成果物の品質は委譲先 gemini-cli-headless-delegation で達成すべき。codebase-investigator は cross-link / fallback 出力契約に留めるべき」
    • 既存 OWNER コメント(#issuecomment-4534616564): REQUEST_CHANGES。blob/main の mutable URL は GitHub permalink doc(Getting permanent links to files)でも branch head 変更により内容が変わると明示されており、commit SHA 固定 permalink を要求すべき
    • .claude/agents/codebase-investigator.md は disallowedTools に Grep / Glob を含み、自身で Read/Grep/Glob を直接実行しない契約(gemini-cli-headless-delegation 委譲必須)。よって「codebase-investigator が出力直前に再確認」は prose 規約だけでは実装不能で、delegation 側の output contract と main thread / deterministic validator の受信後検証に寄せる必要がある

Background

#136 で delegation 経由の codebase-investigator が docs/dev/agent-skill-boundaries.md L604-L633 という古い line range をそのまま evidence として返した結果、issue-author が修正対応する必要があった。これは delegation skill の output contract に file evidence の精度保証が明文化されていないことが原因。

責務境界として、現行 codebase-investigator は「実調査は必ず gemini-cli-headless-delegation 経由」「自身は Read/Grep/Glob を直接実行しない」「リクエスト構築・委譲・結果整形に専念」と定義されているため、evidence の実生成者は委譲先である。よって精度保証 SSOT は gemini-cli-headless-delegation 側に置くのが自然であり、codebase-investigator 側に厚い品質ルールを置くと「実行者ではない層に品質責務を持たせる」反パターンになる。

また、GitHub の blob/main / tree/main 参照は branch head の更新により内容が変わるため、固定版の参照には commit ID を含む permalink を使う必要がある(GitHub 公式 docs より)。anchor section 名 は人間向け fallback として有用だが、同名見出し・見出し変更・section 移動に弱いため正本にしてはならない。

#391 / #394 は SubAgent-owned contract migration の親 Issue / 実装 Issue であり、#248 を明示的に統合対象としている。本 Issue は単独改善ではなく schema_additive な contract 追加 Issue として進める。

In Scope

  • .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md に REPO_EVIDENCE_REF_V1 を追加(applicable profiles: local_asset_research / github_research / proposal_only when emitting evidence-like file references)
  • .claude/skills/gemini-cli-headless-delegation/references/result-surface.md に file evidence 出力例(verified / inconclusive)を追加
  • REPO_EVIDENCE_REF_V1 の必須フィールド定義: commit_sha(40-char)/ path / start_line / end_line / permalink(commit SHA 固定)/ excerpt_sha256 / anchor_text(optional human fallback)/ verification_status(verified / inconclusive)/ verification_method / verified_at
  • mutable branch URL(blob/main / tree/main 等)を file evidence として禁止する規約
  • anchor_text を人間向け fallback と明記し、line range と独立した正本にしない規約
  • line range / excerpt hash が検証不能な場合に verification_status: inconclusive を要求し、caller-provided stale line range を再確認なしに流用しない規約
  • Fallback Handoff Contract(delegation 失敗時に status: failed / failure_reason / warnings / next_action を返し、未検証 evidence を捏造しない)を usage-contract に追加
  • .claude/agents/codebase-investigator.md に Evidence Handling Rule(受け取り側ルール)追加: REPO_EVIDENCE_REF_V1 への cross-link / inconclusive を verified に昇格しない / verification metadata 欠如 evidence を authoritative な file:line として扱わない / 委譲失敗時は fail-close(schema は再定義しない)
  • .claude/skills/issue-refinement-loop/SKILL.md の ANCHOR_COMMENT_FACT_CHECK_RESULT_V1.evidence[] に対する additive rule: kind: file のとき ref 自由文字列ではなく REPO_EVIDENCE_REF_V1 構造を要求(既存 kind: issue|pr|comment|web の自由文字列 ref は維持。後方互換)
  • docs/dev/agent-skill-boundaries.md への cross-link 追加(責務境界の明示のみ)
  • 軽量 validator(fixture または script)で mutable URL と excerpt hash mismatch を reject できることを示す(テストまたは VC レベル)

Out of Scope

  • 全 SubAgent 共通の evidence 精度保証(本 Issue は file evidence に限定。issue/pr/comment/web evidence は対象外)
  • 自動 line drift 検知ツール実装(本 Issue は contract と検証 hook のみ)
  • 既存 OPEN Issue 本文の line number 一斉 audit
  • codebase-investigator を実調査主体に変更する設計変更(委譲先正本の原則は維持)
  • Agent SDK 化(REPO_EVIDENCE_REF_V1 を typed tool として実装することは別 Issue で扱う)
  • web-researcher 側の citation 精度保証ルール波及(実装: web-researcher / gemini-cli-headless-delegation に grounding failure retry と direct fallback 判定を集約する #247 / 別 Issue スコープ)

Acceptance Criteria

  • AC1: .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md に REPO_EVIDENCE_REF_V1 が定義されており、commit_sha(40-char SHA)/ path / start_line / end_line / permalink / excerpt_sha256 / verification_status / verification_method / verified_at が必須フィールドとして列挙されている
  • AC2: usage-contract.md に mutable branch URL(blob/main / tree/main)を file evidence として禁止する規約が記述されている
  • AC3: usage-contract.md に anchor_text が任意の human fallback であり line range と独立した正本ではないことが明記されている
  • AC4: usage-contract.md に line range / excerpt hash 検証不能時の verification_status: inconclusive 取り扱いと、caller-provided stale line range を再確認なしに流用しない規約が記述されている
  • AC5: usage-contract.md または result-surface.md に Fallback Handoff Contract(status: failed / failure_reason / warnings / next_action / 未検証 evidence 禁止)が記述されている
  • AC6: result-surface.md に REPO_EVIDENCE_REF_V1 の verified 例と inconclusive 例の両方が出力例として含まれている
  • AC7: .claude/agents/codebase-investigator.md に Evidence Handling Rule が追加されており、schema を再定義せず REPO_EVIDENCE_REF_V1 を参照し、inconclusive を verified に昇格しない / verification metadata 欠如 evidence を authoritative な file:line として扱わない / 委譲失敗時は fail-close する受け取り側ルールが記述されている
  • AC8: .claude/skills/issue-refinement-loop/SKILL.md に ANCHOR_COMMENT_FACT_CHECK_RESULT_V1.evidence[] の kind: file について REPO_EVIDENCE_REF_V1 構造を要求する additive rule が記述されている(既存 kind: issue|pr|comment|web の ref 自由文字列は維持)
  • AC9: docs/dev/agent-skill-boundaries.md に責務境界の cross-link が追加されている(schema 本体は記載しない)
  • AC10: 軽量 validator(fixture / script)で mutable URL(blob/main 等)と excerpt hash mismatch を reject できる(VC レベルで検証可能)

Post-implementation regression gates(AC ではなく Delivery Rule の必須再実行): pnpm typecheck / pnpm lint / pnpm test / pnpm build をすべて pass させる。これらは CLAUDE.md の最低限の確認コマンドであり baseline で既に pass しているため、本 Issue の AC(baseline-fail-then-pass 形式)には含めない。PR 提出前に再実行する。

Verification Commands

# AC1:
$ rg "^### REPO_EVIDENCE_REF_V1|^## REPO_EVIDENCE_REF_V1" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md
$ rg "commit_sha:.*40-char|excerpt_sha256:|verification_status:" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md

# AC2:
$ rg "mutable branch URL.*forbidden|blob/main.*禁止|mutable.*URL.*禁止" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md

# AC3:
$ rg "anchor_text.*human fallback|anchor_text.*not authoritative|anchor_text.*正本ではない" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md

# AC4:
$ rg "stale.*line.*範囲.*再確認なし.*禁止|stale line range.*MUST NOT|caller-provided.*stale" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md

# AC5:
$ rg "## Fallback Handoff Contract" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md

# AC6:
$ rg "verification_status:\s*verified" .claude/skills/gemini-cli-headless-delegation/references/result-surface.md
$ rg "verification_status:\s*inconclusive" .claude/skills/gemini-cli-headless-delegation/references/result-surface.md

# AC7:
$ rg "## Evidence Handling Rule|### Evidence Handling Rule" .claude/agents/codebase-investigator.md
$ rg "inconclusive を verified に昇格しない|REPO_EVIDENCE_REF_V1" .claude/agents/codebase-investigator.md

# AC8:
$ rg "REPO_EVIDENCE_REF_V1 を要求|REPO_EVIDENCE_REF_V1 構造を要求" .claude/skills/issue-refinement-loop/SKILL.md

# AC9:
$ rg "REPO_EVIDENCE_REF_V1" docs/dev/agent-skill-boundaries.md

# AC10:
$ test -f .claude/skills/gemini-cli-headless-delegation/tests/test_repo_evidence_ref.py
# 実装後に追加: uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_repo_evidence_ref.py

Post-implementation Regression Gates(AC 外・Delivery Rule の必須再実行)

pnpm typecheck
pnpm lint
pnpm test
pnpm build

これらは CLAUDE.md / project-constitution.md で常時必須の品質ゲート。baseline で既に pass しているため Issue AC には含めず、PR 提出前に再実行する。

Allowed Paths

  • .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md(主変更先 — REPO_EVIDENCE_REF_V1 本体定義)
  • .claude/skills/gemini-cli-headless-delegation/references/result-surface.md(出力例追加)
  • .claude/skills/gemini-cli-headless-delegation/tests/test_repo_evidence_ref.py(新規・validator fixture / test)
  • .claude/skills/gemini-cli-headless-delegation/scripts/validate_repo_evidence_ref.py(新規・validator スクリプト、test 採用時は省略可)
  • .claude/agents/codebase-investigator.md(cross-link と受け取り側ルールのみ。schema 本体を書かない)
  • .claude/skills/issue-refinement-loop/SKILL.md(ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 additive rule のみ。schema 再定義しない)
  • docs/dev/agent-skill-boundaries.md(責務境界の cross-link のみ)

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合(特に codebase-investigator の tools / disallowedTools 変更や、gemini-cli-headless-delegation の実行 script 改修が要求される場合)
  • REPO_EVIDENCE_REF_V1 の必須フィールド集合が AC で固定した範囲を超えて変動する場合
  • 既存 ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 の kind: issue|pr|comment|web 既存 ref 自由文字列を破壊する非互換変更が必要になった場合(schema_additive 原則違反)
  • 新規 Issue の起票が必要と判断した場合(line drift auto-detection / web-researcher citation 規約波及 / Agent SDK 化等のスコープ拡大)
  • 後続 Phase / 別スコープへの波及が判明した場合(perf(claude): issue-refinement-loop を script-first / thin entrypoint 化し OPEN 改善 Issue を段階統合する #391 Phase 0 routing で preserve / absorb 判定が変更された場合)
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • Outcome / Scope / AC が VC で検証できない形式に崩れた場合
  • 再確認のために repo の全ファイルを毎回 grep するような重い手順を採用した場合(cost 過大 — excerpt_sha256 による局所検証に限定する)
  • mutable URL 禁止規約を validator で機械的に検出できない設計に陥った場合

Runtime Verification Applicability

runtime_verification:
  decision: not_applicable
  rationale: 本 Issue は output contract(usage-contract.md / result-surface.md)と consumer-side cross-link / additive schema rule の追加であり、ランタイム挙動を直接変更しない。VC は静的 grep / fixture validator / 既存品質ゲート(pnpm typecheck/lint/test/build)で全 AC を決定論的に検証できる。`runtime-verification: true` タグを付与しない。

Handoff Contract

Required Skills

  • gemini-cli-headless-delegation の usage-contract / result-surface 編集(schema 追加)
  • issue-refinement-loop の ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 additive rule 編集
  • 軽量 validator(pytest fixture または python script)

Delivery Rule

Activity

  1. squne121 commented on May 23, 2026

    @squne121
    OwnerAuthor

    create-issue transaction partial-failure

    Issue: #248
    Failure stage: label-apply
    Message: label-apply failed

    Requested:

    • labels: kind/implementation, area/ai-ops, area/sub-agent
    • parent: (none)
    • dependencies: (none)
      Completed steps: create

    Failure context: command=gh issue edit --repo squne121/loop-protocol 248 --add-label kind/implementation,area/ai-ops,area/sub-agent
    output=failed to update #248: 'area/sub-agent' not found
    failed to update 1 issue
    matching_issue_numbers=[248]
    issue_number=248

    Recovery hint: stage 'label-apply' encountered an unexpected failure.
    Generic guidance: verify the issue state manually and re-run the transaction if safe.
    gh issue view 248 --repo squne121/loop-protocol --json number,title,labels,state
    idempotent re-run: depends on the specific failure

    Please recover deterministically before re-running the create issue transaction.

  2. added
    kind/implementation
    area/ai-ops
    on May 23, 2026
  3. squne121 commented on May 25, 2026

    @squne121
    OwnerAuthor

    人間からのコメントです。
    「.claude/agents/codebase-investigator.md に「Evidence Accuracy Rule」セクション追加(file:line 再確認手順・anchor section 名併記要件・inconclusive 取り扱いルール)」とありますが成果物の品質ってエージェントスキルで担保されませんか?codebase-investigatorがメインのメインプランである委譲先 .claude/skills/gemini-cli-headless-delegation で達成するべきと思うし gemini-cli-headless-delegation からのFallback 先として最低限の作業手順および出力契約を記載する?

  4. squne121 commented on May 25, 2026

    @squne121
    OwnerAuthor

    結論:人間コメントは妥当です。#248 はスコープを組み替えた方がよいです。

    Issue #248 の現状は「.claude/agents/codebase-investigator.md に Evidence Accuracy Rule を追加」が主になっていますが、現行の codebase-investigator は「実調査は必ず gemini-cli-headless-delegation 経由」「自身は Read/Grep/Glob を直接実行しない」「リクエスト構築・委譲・結果整形に専念」と定義されています。つまり、evidence の実生成者は codebase-investigator ではなく、委譲先の gemini-cli-headless-delegation / Gemini 実行系です。

    そのため、修正方針はこうするのが自然です。

    判断

    #248 は「codebase-investigator 固有の品質ルール追加」ではなく、gemini-cli-headless-delegation の output contract 強化に寄せるべきです。

    理由は3つあります。

    1. gemini-cli-headless-delegation は delegation_request_v1 / delegation_result_v1、tool_profile、result_surface などの契約を持つ shared skill で、出力構造の正本になっています。
    2. codebase-investigator は委譲結果を整形するだけなので、ここに強い evidence 精度ルールを書くと、実行者ではない層に品質責務を持たせることになります。
    3. Issue 実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する #248 の問題事象は「古い file:line を evidence として返した」ことであり、これは local_asset_research / github_research の出力契約として「line は再確認済みでなければならない」「確認不能なら inconclusive」と定義すべき問題です。

    推奨する修正スコープ

    Issue #248 は以下のように再定義するのがよいです。

    変更主対象

    • .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md
    • 必要なら .claude/skills/gemini-cli-headless-delegation/references/result-surface.md
    • .claude/agents/codebase-investigator.md は cross-link / caller-side enforcement の最小追記だけ

    追加すべき契約

    gemini-cli-headless-delegation 側に Evidence Accuracy Contract を追加する。

    内容は以下で足ります。

    ## Evidence Accuracy Contract
    
    Applicable profiles:
    - local_asset_research
    - github_research
    - proposal_only when it emits evidence-like file references
    
    Rules:
    - Any evidence item that includes `file:line` or `file:line-line` MUST be verified against the repository state visible to the delegation run immediately before final output.
    - Evidence MUST include an anchor identifier when available:
      - markdown heading name
      - symbol name
      - function/class/method name
      - issue/PR/comment URL fragment
    - If exact line verification is not possible, the evidence MUST NOT present the line as verified.
    - Use `verification_status: inconclusive` and include the nearest stable anchor instead.
    - Never copy caller-provided stale line ranges into final evidence without re-verification.

    出力契約は、例えばこうする。

    {
      "evidence": [
        {
          "path": "docs/dev/agent-skill-boundaries.md",
          "line_range": "L741-L770",
          "anchor": "Hook-based Ledger Optional Design",
          "verification_status": "verified",
          "verification_method": "repo_readonly_tool",
          "summary": "..."
        }
      ]
    }

    確認不能時:

    {
      "evidence": [
        {
          "path": "docs/dev/agent-skill-boundaries.md",
          "line_range": null,
          "anchor": "Hook-based Ledger Optional Design",
          "verification_status": "inconclusive",
          "verification_method": "anchor_only",
          "summary": "Exact line range could not be verified; use anchor section instead."
        }
      ]
    }

    codebase-investigator 側に残すべきこと

    codebase-investigator.md には、厚いルールではなく受け取り側の検査ルールだけ置くのがよいです。

    ## Evidence Handling Rule
    
    This agent does not own evidence generation accuracy.
    Evidence accuracy is governed by `gemini-cli-headless-delegation`'s Evidence Accuracy Contract.
    
    When formatting delegated results:
    - Preserve `anchor`, `verification_status`, and `verification_method`.
    - Do not upgrade `inconclusive` evidence to verified.
    - Do not copy caller-provided file:line references unless the delegated result marks them as verified.
    - If delegated evidence lacks verification metadata, report it as `status: inconclusive` rather than treating it as authoritative.

    これなら、codebase-investigator は「成果物の品質を担保する主体」ではなく、委譲先の契約を壊さず転送・整形する主体になります。

    Fallback について

    ここは人間コメントの通り、codebase-investigator が勝手に自力調査へ fallback する設計にはしない方がよいです。現行ファイルでも、委譲不可時は fail-close し、自力での代替調査は禁止されています。

    ただし、gemini-cli-headless-delegation 側または boundaries doc に、fallback handoff contract を追加するのは有効です。

    例:

    ## Fallback Handoff Contract
    
    If delegation fails:
    - Return `status: failed`
    - Include `failure_reason`, `warnings`, and `next_action`
    - Do not fabricate evidence
    - Do not emit unverified file:line references
    - Suggest caller-owned fallback:
      - manual repo inspection
      - main-thread minimal investigation
      - issue split if verified evidence cannot be produced

    つまり、fallback は「codebase-investigator が裏で実行する代替手順」ではなく、caller / orchestrator に返す明示的な handoff contractとして定義するのが安全です。

    人間コメントへの返答案

    そのまま貼るなら、以下がよいです。

    指摘は妥当です。現行の codebase-investigator は実調査を必ず `gemini-cli-headless-delegation` 経由で行い、自身は request 構築・委譲・結果整形に専念する設計なので、evidence の file:line 精度保証を codebase-investigator 固有ルールとして厚く持たせるのは責務境界として不自然です。
    
    #248 は、主対象を `.claude/skills/gemini-cli-headless-delegation` 側の output contract 強化に変更するのがよいと考えます。
    
    具体的には、`gemini-cli-headless-delegation` の usage/result contract に Evidence Accuracy Contract を追加し、以下を定義します。
    
    - file:line / file:line-line を evidence として出す場合は、出力直前に repo 状態に対して再確認済みであること
    - anchor section / symbol / heading などの安定 anchor を併記すること
    - line range が確認不能な場合は verified として扱わず `verification_status: inconclusive` とすること
    - caller から渡された古い line range を再確認なしに流用しないこと
    - evidence item に `path`, `line_range`, `anchor`, `verification_status`, `verification_method`, `summary` を持たせること
    
    `codebase-investigator.md` 側には、Evidence Accuracy Rule 本体ではなく、委譲結果を整形する際の受け取りルールだけを置きます。
    
    - `anchor` / `verification_status` / `verification_method` を落とさない
    - `inconclusive` を verified に昇格しない
    - verification metadata がない evidence は authoritative な file:line として扱わない
    - 委譲失敗時は現行通り fail-close し、自力 fallback 調査はしない
    
    Fallback については、`codebase-investigator` 内で直接調査へ切り替えるのではなく、`gemini-cli-headless-delegation` から caller / orchestrator へ返す `Fallback Handoff Contract` として、最低限の失敗理由・next_action・未検証 evidence を出さない制約を明文化するのがよいです。
    
    したがって #248 は、Allowed Paths / AC を以下の方向へ修正するのが適切です。
    
    - 主変更先: `.claude/skills/gemini-cli-headless-delegation/references/usage-contract.md`
    - 必要に応じて: `.claude/skills/gemini-cli-headless-delegation/references/result-surface.md`
    - 補助変更: `.claude/agents/codebase-investigator.md` は cross-link と受け取り時の非昇格ルールのみ
    - `docs/dev/agent-skill-boundaries.md` は責務境界の cross-link 追加に限定
    
    この形なら、成果物品質は shared skill の output contract で担保され、codebase-investigator はオーケストレーション/整形責務に閉じられます。

    Issue #248 はクローズではなくスコープ修正が適切です。現行案のままだと責務が codebase-investigator に寄り過ぎています。

  5. squne121 commented on May 25, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES。#248 はこのまま単独 PR 化しない方がよいです。

    狙いは妥当です。file:line の古い evidence を Agent が信じる問題は、#136 実走時の観察から再発性があります。ただし #248 は change_kind: docs としながら、実際には ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 の schema 拡張、main thread の consumer 検証、codebase-investigator の出力契約変更まで含んでいます。これは docs-only ではなく SubAgent I/O contract 変更です。

    主要なブロッカー

    1. main thread 受信時点のリポジトリと一致 という保証目標が弱い

    GitHub の通常の blob/main/...#Lx-Ly 参照は、branch head が動くと内容が変わります。GitHub 公式 docs も、branch head のファイル内容は新しい commit により変わり得るため、固定版を参照するには branch 名ではなく commit ID を URL に入れる、と説明しています。([GitHub Docs]1)

    したがって #248 の保証対象は、main thread 受信時点 ではなく、少なくとも以下にすべきです。

    REPO_EVIDENCE_REF_V1:
      kind: github_file
      repo: squne121/loop-protocol
      commit_sha: <40-char sha>
      path: docs/dev/agent-skill-boundaries.md
      start_line: 741
      end_line: 770
      permalink: https://github.com/squne121/loop-protocol/blob/<commit_sha>/docs/dev/agent-skill-boundaries.md#L741-L770
      anchor_text: "Hook-based Ledger Optional Design"
      excerpt_sha256: sha256:<hash>
      verified_at: <iso8601>

    anchor section 名 は人間向け fallback として有用ですが、同名見出し・見出し変更・section 移動に弱いので、正本にしてはいけません。

    2. codebase-investigator は直接 Grep/Glob できないため、「出力直前に再確認」はそのままだと実装不能に近い

    現行 codebase-investigator.md は、実調査を必ず gemini-cli-headless-delegation 経由で Gemini に委譲し、自身は Read/Grep/Glob を直接実行しない契約です。disallowedTools にも Grep / Glob が入っています。

    つまり #248 の「file:line を含む evidence は出力直前に再確認する」は、codebase-investigator の prose に書くだけでは不足です。選択肢は二つです。

    1. Gemini delegation request / result contract 側に line verification を要求する
    2. main thread / deterministic script が受信後に commit_sha + excerpt_hash を検証する

    後者の方が堅いです。Agent の自己申告ではなく、機械的検証に寄せるべきです。

    3. 既存 ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 は evidence ref が自由文字列で、精度保証に向いていない

    現行 schema は evidence[].ref: <path#line | issue# | pr# | comment_url | web citation> という自由文字列です。ここに anchor を足すだけでは、commit 固定・line range drift・本文 excerpt 一致を検証できません。

    anchor 追加ではなく、file evidence 専用の構造化 object を定義する方がよいです。issue / pr / comment / web evidence と file evidence を同じ ref 文字列で扱う設計が、今回の不具合の根です。

    4. #391 / #394 と衝突している

    #391 は issue-refinement-loop を thin entrypoint / SubAgent-owned contract へ段階移行する親 Issue で、#247 / #248 を「SubAgent 契約に直結するため Phase 1〜3 の設計に影響する」と明示しています。

    さらに #394 は Phase 3 として、codebase-investigator: evidence accuracy / repo fact claim / line anchor contract を参照可能にし、#248 との重複判断を行うことを AC にしています。

    従って、#248 は単独改善ではなく、#394 の設計入力として preserve するか、schema-additive contract change issue に格上げすべきです。

    5. #247 と同じ責務分離パターンに揃えるべき

    #247 は web-researcher / gemini-cli-headless-delegation / issue-refinement-loop の retry / grounding / result schema 責務を整理し、orchestrator を consumer / cross-link 境界に限定しています。

    #248 も同型です。issue-refinement-loop に詳細な line accuracy 手順を置くのではなく、codebase-investigator 側または専用 reference に SSOT contract を置き、orchestrator は consume / validate / route だけにすべきです。

    技術調査からの改善方針

    Claude Code の subagent は .claude/agents/ に置く Markdown + YAML frontmatter で、project 固有の subagent は version control に入れてチームで共有する想定です。([Claude API Docs]2) また、subagent の frontmatter には tools / disallowedTools / model 等があり、実効挙動を変えます。([Claude API Docs]2)

    Claude Code skills は SKILL.md を entrypoint にし、supporting files を持てます。公式 docs は、複雑な skill は supporting files に分け、main body は簡潔に保つべきで、skill content は読み込まれると context に残り続けると説明しています。([Claude API Docs]3)([Claude API Docs]3)

    このため、#248 の実装先は次が適切です。

    .claude/agents/codebase-investigator.md
      - Evidence Accuracy Rule の短いリンクだけ
    
    .claude/skills/issue-refinement-loop/references/repo-evidence-ref-v1.md
      - REPO_EVIDENCE_REF_V1 の詳細 contract
      - valid / invalid examples
      - consumer validation rule
    
    .claude/skills/issue-refinement-loop/SKILL.md
      - schema を再定義せず、reference を consume するだけ
    

    #248 の修正文案

    Issue 本文は次の方向に直すべきです。

    contract_schema_version: v1
    issue_kind: implementation
    parent_issue: "#391"
    goal_ref: "codebase-investigator の file evidence を commit 固定・excerpt hash 付きの REPO_EVIDENCE_REF_V1 として返し、orchestrator が再利用前に検証できるようにする"
    change_kind: workflow
    contract_change_level: schema_additive

    Current Validated Scope 差し替え案

    - `.claude/agents/codebase-investigator.md` に Evidence Accuracy Rule を追加する。ただし詳細 schema は再定義せず、`REPO_EVIDENCE_REF_V1` を参照する。
    - `.claude/skills/issue-refinement-loop/references/repo-evidence-ref-v1.md` を追加し、file evidence の構造化 contract を定義する。
    - `ANCHOR_COMMENT_FACT_CHECK_RESULT_V1.evidence[]` の `kind: file` について、`ref` 自由文字列ではなく `repo_evidence_ref` を要求する additive rule を定義する。
    - main thread は Issue 本文へ line 情報を流用する前に、`commit_sha`, `path`, `start_line`, `end_line`, `excerpt_sha256` を検証する。

    Acceptance Criteria 差し替え案

    - [ ] `REPO_EVIDENCE_REF_V1` が定義され、`commit_sha`, `path`, `start_line`, `end_line`, `permalink`, `excerpt_sha256` を必須にしている
    - [ ] `blob/main` / `tree/main` のような mutable branch URL を file evidence として禁止している
    - [ ] `anchor_text` は任意の human fallback であり、正本ではないことを明記している
    - [ ] line range または excerpt hash が検証不能な場合、claim verdict は `inconclusive` になる
    - [ ] `codebase-investigator` は schema を再定義せず、Evidence Accuracy Rule から `REPO_EVIDENCE_REF_V1` を参照している
    - [ ] `issue-refinement-loop` は SubAgent 内部手順を再定義せず、consumer validation のみを持つ
    - [ ] fixture または軽量 validator が、mutable URL と hash mismatch を reject できる

    実装順の推奨

    1. perf(claude): issue-refinement-loop を script-first / thin entrypoint 化し OPEN 改善 Issue を段階統合する #391 Phase 0 で 実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する #248 を preserve または absorb into #394 に分類
    2. 実装: issue-refinement-loop の SubAgent-owned contract migration を行う #394 の中で REPO_EVIDENCE_REF_V1 を SubAgent-owned contract として追加
    3. 実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する #248 は、独立 PR ではなく 実装: issue-refinement-loop の SubAgent-owned contract migration を行う #394 の AC3 を具体化する設計入力にする
    4. 急ぐ場合のみ、実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する #248 を contract_change_level: schema_additive に変更して単独化する

    最終コメント案

    REQUEST_CHANGES.
    
    この Issue の問題意識は妥当ですが、現状の scope は docs-only ではなく SubAgent I/O contract 変更です。`ANCHOR_COMMENT_FACT_CHECK_RESULT_V1.evidence[].ref` の自由文字列に `anchor` を足すだけでは、line drift を機械的に検出できません。
    
    GitHub の file line evidence は `blob/main` ではなく commit SHA 固定 permalink を使い、`path`, `start_line`, `end_line`, `quoted_excerpt/excerpt_sha256` を持つ `REPO_EVIDENCE_REF_V1` として構造化すべきです。`anchor section 名` は human fallback に留め、正本にしないでください。
    
    また、現行 `codebase-investigator` は実調査を `gemini-cli-headless-delegation` に委譲し、自身では Grep/Glob を直接実行しない契約なので、「出力直前に再確認」と prose に書くだけでは保証になりません。main thread または deterministic validator が受信後に commit/ref/excerpt を検証する設計に寄せるべきです。
    
    #391 / #394 が SubAgent-owned contract migration として #248 を明示的に統合対象にしているため、本 Issue は単独改善ではなく、#394 の design input として preserve/absorb 判断するのが安全です。単独で進めるなら `change_kind: docs` を撤回し、`contract_change_level: schema_additive` として `REPO_EVIDENCE_REF_V1` の追加 Issue に格上げしてください。
  6. changed the title [-]improve: codebase-investigator の evidence に line number 精度の保証ルールを加える[/-] [+]contract: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する[/+] on May 25, 2026
  7. squne121 commented on May 25, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 完了 (2026-05-25T13:33:03Z)

    • iteration: 1(review cycle 2 周: 初回 needs-fix(C4 / C5 整形)→ 修正後 approve)
    • verdict: approve
    • termination_reason: approved
    • 改善履歴:
      • scope 組み換え: 主変更先を .claude/agents/codebase-investigator.md から .claude/skills/gemini-cli-headless-delegation/references/ に移し、codebase-investigator は cross-link / 受け取り側ルールのみに限定(OWNER コメント #issuecomment-4534616564 の REQUEST_CHANGES 方針を反映)
      • schema 強化: REPO_EVIDENCE_REF_V1 を導入し、commit_sha / excerpt_sha256 固定・mutable URL(blob/main 等)禁止・anchor_text は human fallback のみとする contract に置き換え
      • 責務境界明示: change_kind: workflow / contract_change_level: schema_additive / parent_issue: #391 を Machine-Readable Contract に追加
      • AC / VC 整形: AC1〜AC11 番号付与、VC コマンドに $ プレフィックス付与、AC ↔ VC 1:1 対応
      • Out of Scope 拡張: Agent SDK 化 / web-researcher citation 規約波及 / line drift auto-detect / 一斉 audit を明示的に除外
      • Stop Conditions 強化: schema_additive 原則違反となる非互換変更や codebase-investigator tools 変更を明示停止条件に追加
    • 次アクション:
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      follow_up_issues: []
      note_only_observations:
        - dedupe_key: "repo-evidence-ref-v1:web-researcher-citation"
          source_url: "https://github.com/squne121/loop-protocol/issues/248"
          source_note_id: "refinement-loop-2026-05-25"
          summary: "web-researcher 側の citation 精度保証(grounded_research の web evidence について commit/snapshot 相当の固定参照)は本 Issue Out of Scope。#247 grounding failure retry と統合検討する派生改善候補として記録のみ。"
        - dedupe_key: "repo-evidence-ref-v1:excerpt-sha256-normalization"
          source_url: "https://github.com/squne121/loop-protocol/issues/248"
          source_note_id: "refinement-loop-2026-05-25"
          summary: "excerpt_sha256 の正規化規約(trailing newline / 改行コード CRLF→LF / 末尾空白)は実装着手時の Open Question。validator 仕様に直結するため #394 実装フェーズで確定させる。"
  8. changed the title [-]contract: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する[/-] [+]実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する[/+] on May 25, 2026
  9. squne121 commented on May 25, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-25T13:38:03Z)

    • Outcome: gemini-cli-headless-delegation の output contract に REPO_EVIDENCE_REF_V1 を schema_additive で追加し、file evidence の commit_sha 固定 / excerpt_sha256 / mutable URL 禁止 / anchor_text の human fallback 化 / inconclusive 取り扱いを SSOT 化する。codebase-investigator / issue-refinement-loop は cross-link と consumer-side validation のみで参照する。
    • Acceptance Criteria: AC1〜AC10(番号は本文参照)。AC11 相当の pnpm 品質ゲートは Delivery Rule の post-implementation regression として AC 外に分離。
    • Verification Commands: 本文 ## Verification Commands の AC1〜AC10 を baseline で実行 → 全 13 件が expected_baseline_fail(exit 1)として go 判定。post-implementation gates として pnpm typecheck / pnpm lint / pnpm test / pnpm build を PR 提出前に実行。
    • Allowed Paths:
      • .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md(主変更先)
      • .claude/skills/gemini-cli-headless-delegation/references/result-surface.md
      • .claude/skills/gemini-cli-headless-delegation/tests/test_repo_evidence_ref.py(新規)
      • .claude/skills/gemini-cli-headless-delegation/scripts/validate_repo_evidence_ref.py(新規・test 採用時は省略可)
      • .claude/agents/codebase-investigator.md(cross-link / 受け取り側ルールのみ)
      • .claude/skills/issue-refinement-loop/SKILL.md(additive rule のみ)
      • docs/dev/agent-skill-boundaries.md(責務境界 cross-link)
    • Worktree: .claude/worktrees/issue-248-add-repo-evidence-ref-v1
    • Branch: worktree-issue-248-add-repo-evidence-ref-v1
    • VC preflight: baseline fail = 13, 想定外 pass = 0, 実行不可 = 0
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-05-25T13:38:03Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/248
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 13
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          classifications: [{"ac": "AC1", "command": "rg \"^### REPO_EVIDENCE_REF_V1|^## REPO_EVIDENCE_REF_V1\" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC1", "command": "rg \"commit_sha:.*40-char|excerpt_sha256:|verification_status:\" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC2", "command": "rg \"mutable branch URL.*forbidden|blob/main.*禁止|mutable.*URL.*禁止\" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC3", "command": "rg \"anchor_text.*human fallback|anchor_text.*not authoritative|anchor_text.*正本ではない\" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC4", "command": "rg \"stale.*line.*範囲.*再確認なし.*禁止|stale line range.*MUST NOT|caller-provided.*stale\" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC5", "command": "rg \"## Fallback Handoff Contract\" .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC6", "command": "rg \"verification_status:\\s*verified\" .claude/skills/gemini-cli-headless-delegation/references/result-surface.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC6", "command": "rg \"verification_status:\\s*inconclusive\" .claude/skills/gemini-cli-headless-delegation/references/result-surface.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC7", "command": "rg \"## Evidence Handling Rule|### Evidence Handling Rule\" .claude/agents/codebase-investigator.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC7", "command": "rg \"inconclusive を verified に昇格しない|REPO_EVIDENCE_REF_V1\" .claude/agents/codebase-investigator.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC8", "command": "rg \"REPO_EVIDENCE_REF_V1 を要求|REPO_EVIDENCE_REF_V1 構造を要求\" .claude/skills/issue-refinement-loop/SKILL.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC9", "command": "rg \"REPO_EVIDENCE_REF_V1\" docs/dev/agent-skill-boundaries.md", "exit_code": 1, "category": "expected_baseline_fail", "confidence": "high", "decision": "go"}, {"ac": "AC10", "command": "test -f .claude/skills/gemini-cli-headless-delegation/tests/test_repo_evidence_ref.py", "exit_code": 1, "category": "file_not_found_expected", "confidence": "high", "decision": "go"}]
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
          conditions:
            docs_product_requires_spec_evidence:
              status: n/a
              evidence: []
            tasks_md_not_direct_source:
              status: n/a
              evidence: []
            specify_not_canonical:
              status: n/a
              evidence: []
            diff_first_rationale_present:
              status: n/a
              evidence: []
            generated_task_trace_present:
              status: n/a
              evidence: []
            task_dependencies_materialized:
              status: n/a
              evidence: []
          blocked_reasons: []
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings: []
  10. added 3 commits that reference this issue on May 25, 2026
  11. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    CLOSE_DECISION_V1

    CLOSE_DECISION_V1:
      generated_at: "2026-05-28T00:00:00Z"
      generated_by: issue-395-sweep
      issue_number: 248
      decision: completed
      state_reason: completed
      evidence: "REPO_EVIDENCE_REF_V1 を canonical SSOT として references/ に参照し再定義を排除。#394 PR で実装済み"
      absorbed_by:
        - pr: https://github.com/squne121/loop-protocol/pull/418
          issue: 394
      sweep_source: https://github.com/squne121/loop-protocol/issues/395
  12. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    CLOSE_DECISION_V1_CORRECTION

    CLOSE_DECISION_V1:
      generated_at: "2026-05-28T12:00:00Z"
      generated_by: issue-395-sweep-correction
      issue: "#248"
      decision: absorbed
      github_state: CLOSED
      github_state_reason: completed
      absorbed_by:
        - pr: "#418"
          issue: "#394"
      evidence:
        - type: ssot_migrated
          ref: "https://github.com/squne121/loop-protocol/pull/418"
      residual_gaps: []

    訂正理由: 前回コメントの decision: completed は #395 Outcome の語彙外。正しくは decision: absorbed(absorbed by #394)。REPO_EVIDENCE_REF_V1 が references/ に canonical SSOT として SSOT 化済み。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/ai-opskind/implementationphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions