Skip to content

実装: issue-refinement-loop に ANCHOR_COMMENT_CONTEXT_V1 / ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 / requires_fact_check を追加し anchor comment fact-check の入出力契約を固定する #127

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "issue-refinement-loop skill の SKILL.md に ANCHOR_COMMENT_CONTEXT_V1 入力契約・ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 出力契約・requires_fact_check フィールドを追加し、anchor comment の fact-check context packet と SubAgent 入出力契約を固定する"
change_kind: workflow

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: なし(単独改善のため親 Issue なし)
  • Desired Destination: なし

Current Validated Scope

  • .claude/skills/issue-refinement-loop/SKILL.md に ANCHOR_COMMENT_CONTEXT_V1 入力契約・ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 出力契約・requires_fact_check フィールドを追加し、Step 1 injection 条件を classification 種別非依存の requires_fact_check フラグで制御し、final_classification を確定する責務が main thread にあると明記する

Remaining Parent Gaps

Outcome

.claude/skills/issue-refinement-loop/SKILL.md に ANCHOR_COMMENT_CONTEXT_V1・ANCHOR_COMMENT_FACT_CHECK_RESULT_V1・requires_fact_check フィールドが定義され、Step 1 injection 条件が classification 種別非依存の requires_fact_check フラグで制御され、final_classification を確定する責務が main thread にあると明記されたコミットが存在する状態。

Background

Issue #79 の issue-refinement-loop 実行時(2026-05-20)、人間がコメント URL を名指しで指定してループを起動した。指定されたコメント(issuecomment-4497721177)は「Issue #79 の前提(retry 未実装)が誤っており、create_issue_txn.py には既に retry が実装済み」という事実確認を含んでいた。

現行の issue-refinement-loop は Inputs が issue_number と max_iterations のみで コメント URL を受け取る入力が存在しない。このため main thread(オーケストレーター)が手動でコメント本文を取得し、Step 1 の codebase-investigator 起動プロンプトへ「コメントの主張を事実確認せよ」を即興で織り込んだ。結果として再フレームは成功したが、これは skill 化された手順ではなく即興対応であり、再現性がない。

Issue #96 の Out of Scope として記録されていた残タスク(Issue #96 コメント, 2026-05-20)。

その後、Issue #96 が adversarial review を受けて再設計され、Inputs への anchor_comment_url 追加・LOOP_STATE.anchor_comment フィールド追加・Step 0 でのコメント本文取得手順が #96 の scope に取り込まれた。このため Issue #127 は当初 Step 1 injection のみに scope を縮小した。

reviewer feedback(issuecomment-4508382829)を受けて、scope を「snapshot 注入のみ」から「入出力契約の定義と責務分離」へ再設計。

Refs #79, #96

In Scope

  • Step 1 に ANCHOR_COMMENT_CONTEXT_V1 入力契約を追加する(source メタ・issue snapshot・anchor comment snapshot・preliminary 分類・required_checks リスト)
  • codebase-investigator の出力契約として ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 を追加する(claim ごとの verdict / evidence / scope_impact / recommended_final_classification / unresolved_risks)
  • LOOP_STATE.anchor_comment に requires_fact_check: true | false フィールドを追加する
  • Step 1 injection 条件を「snapshot != null かつ requires_fact_check == true」に変更し、classification 種別非依存にする
  • main thread が fact-check result を統合し、final_classification / verified_claims / unresolved_claims / scope_impact を更新する手順を明記する
  • SubAgent / main thread / issue-author / review-issue の責務分離表を追加する
  • Step 4 は final_classification 後の正規化済み anchor_comment_feedback のみ受け取ることを明記する

Out of Scope

Acceptance Criteria

  • AC1: .claude/skills/issue-refinement-loop/SKILL.md に ANCHOR_COMMENT_CONTEXT_V1 が定義されている
  • AC2: Step 1 は LOOP_STATE.anchor_comment.snapshot != null かつ requires_fact_check == true の場合、classification 種別にかかわらず ANCHOR_COMMENT_CONTEXT_V1 を codebase-investigator に渡す旨が明記されている
  • AC3: .claude/skills/issue-refinement-loop/SKILL.md に ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 が定義されている
  • AC4: codebase-investigator は mutation を行わず、claim ごとの verdict と evidence のみ返すと明記されている
  • AC5: final_classification を確定する責務は main thread / orchestrator にあると明記されている
  • AC6: Step 4 は raw anchor comment ではなく、final_classification 後の正規化済み anchor_comment_feedback のみ受け取ると明記されている
  • AC7: Agent SDK 化は別 Issue とし、本 Issue では Skill 上の protocol contract 固定に限定すると Out of Scope に明記されている

Verification Commands

# AC1: ANCHOR_COMMENT_CONTEXT_V1 入力契約が定義されている
rg "ANCHOR_COMMENT_CONTEXT_V1" \
  .claude/skills/issue-refinement-loop/SKILL.md && echo "PASS: AC1" || echo "FAIL: AC1"

# AC2: requires_fact_check による Step 1 injection 条件がある
rg "requires_fact_check" \
  .claude/skills/issue-refinement-loop/SKILL.md && echo "PASS: AC2" || echo "FAIL: AC2"

# AC3: ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 出力契約が定義されている
rg "ANCHOR_COMMENT_FACT_CHECK_RESULT_V1" \
  .claude/skills/issue-refinement-loop/SKILL.md && echo "PASS: AC3" || echo "FAIL: AC3"

# AC4: codebase-investigator は mutation 不可と明記されている
rg "codebase-investigator.*(mutation|edit|close|create|してはいけない|MUST NOT)" \
  .claude/skills/issue-refinement-loop/SKILL.md && echo "PASS: AC4" || echo "FAIL: AC4"

# AC5: final_classification の責務が main thread にあると明記されている
rg "final_classification.*main thread|main thread.*final_classification|orchestrator.*final_classification" \
  .claude/skills/issue-refinement-loop/SKILL.md && echo "PASS: AC5" || echo "FAIL: AC5"

# AC6: Step 4 が正規化済み anchor_comment_feedback のみ受け取ると明記されている
rg "anchor_comment_feedback|正規化.*feedback|final_classification.*feedback" \
  .claude/skills/issue-refinement-loop/SKILL.md && echo "PASS: AC6" || echo "FAIL: AC6"

# AC7: Agent SDK 化が Out of Scope に明記されている
rg "Agent SDK" \
  .claude/skills/issue-refinement-loop/SKILL.md && echo "PASS: AC7" || echo "FAIL: AC7"

Allowed Paths

  • .claude/skills/issue-refinement-loop/SKILL.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Runtime Verification Applicability

decision: not_applicable
reason: >
  変更対象は SKILL.md のテキスト記述のみ。
  実装後にランタイムで動作確認すべき挙動(UI 描画・ゲームロジック・API コール等)は含まれない。
  AC/VC は rg による静的テキスト存在確認で完結する。

Required Skills

なし

Scope Delta(任意)

Issue #96 が adversarial review で再設計され、Inputs/LOOP_STATE/Step0 fetch の実装を引き受けたため、Issue #127 は当初 Step 1 injection のみに scope を縮小。その後 reviewer feedback(issuecomment-4508382829)を受け、scope を「snapshot 注入のみ」から「入出力契約の定義と責務分離」へ再設計。

external_spec claim の routing contract(WEB_RESEARCH_RESULT_V1 への同一 claim_id 渡し・main thread の統合規則)は、#127 の実装スコープに含める判断をした(reviewer feedback iter 2-3 による再設計)。web-researcher SubAgent の内部仕様変更は引き続き Out of Scope。

Delivery Rule

Activity

  1. added
    enhancement
    phase/implementation
    state/queued
    agent/implementer
    on May 21, 2026
  2. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    オーケストラレーションと各サブエージェントのコンテクストのやり取りについて見直し、責務分離に注意しながら改善してほしい。
    オーケストラレーションスキルではなく、AgentSDKで実現すべきだろうか?

  3. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    判定

    Issue #127 は、そのまま実装に回すべきではありません。
    理由は、Issue #127 が「Step 1 に anchor_comment.snapshot を注入する」だけにスコープを縮めていますが、関連する Issue #96 / PR #128 で anchor_comment_url、LOOP_STATE.anchor_comment、Step 0a/0b/0c、暫定分類、冪等性、close コメント統合まで既にかなり実装済みだからです。現時点の未解決点は「snapshot を渡すかどうか」ではなく、オーケストレーターと SubAgent 間の入出力契約が弱く、誰が分類・事実確認・最終判断・ mutation を担うのかがまだ曖昧なことです。

    Issue #127 のコメントで追加された「オーケストレーションと各サブエージェントのコンテクストのやり取り」「責務分離」「Agent SDK で実現すべきか」という論点は妥当です。これは #127 の AC1/AC2 のような rg 文字列検証では捕捉できない、control-plane 設計の問題です。

    敵対的レビュー

    Blocker 1: #127 は現在の main に対して一部 stale

    PR #128 により、現在の issue-refinement-loop/SKILL.md には既に anchor_comment_url、anchor_comment.snapshot、preliminary_classification、final_classification、verified_claims、unresolved_claims、scope_impact、ALTERNATIVE_ISSUE_DRAFT_V1、Step 1 の anchor comment 追加入力が入っています。つまり #127 の「Step 1 に snapshot 注入を追加する」という実装は、単純にやると 既存記述へ重複追記するだけの低品質 PR になります。

    #127 は次のように再定義すべきです。

    実装: issue-refinement-loop の anchor_comment fact-check context packet と SubAgent 入出力契約を固定する
    

    焦点は snapshot というフィールド名ではなく、SubAgent に渡す context packet と、SubAgent から返す fact-check result contract です。


    Blocker 2: Step 1 注入条件がまだ危険

    現在の SKILL.md では、Step 1 の追加入力は主に preliminary_classification が reframe_in_place / feedback_update_required の場合を想定しています。一方、#96/PR #128 の設計では、superseded_by_decision であっても「事実確認不要の場合のみ即時確定」であり、事実主張を含む場合は Step 1 で検証してから final_classification を確定する必要があります。

    したがって、#127 の不変条件はこう置くべきです。

    Step 1 anchor comment injection rule:
      if LOOP_STATE.anchor_comment.snapshot != null
      and LOOP_STATE.anchor_comment.requires_fact_check == true:
        pass ANCHOR_COMMENT_CONTEXT_V1 to codebase-investigator
    

    分類名に依存させるより、requires_fact_check を明示したほうが安全です。#79 の実例はまさに「コメントが人間 close Decision ではなく、コードベース事実に基づいて Issue 前提を再フレームする」ケースでした。


    Blocker 3: SubAgent に渡す情報がまだ薄い

    Claude Code の SubAgent は独立した context window で動き、親会話の履歴や既読ファイルを自動では見ません。必要な情報は delegation message / 入力として明示的に渡す必要があります。(Claude API Docs)

    現在の Step 1 追加入力は url、snapshot、classification、required_checks 程度です。これは不足です。最低限、次の context packet が必要です。

    ANCHOR_COMMENT_CONTEXT_V1:
      source:
        issue_number: <int>
        anchor_comment_url: <string>
        anchor_comment_id: <int>
        author_association: <string | null>
      issue_snapshot:
        title: <string>
        body: <string>
        labels: []
        captured_at: <iso8601>
      anchor_comment:
        snapshot: <string>
        captured_at: <iso8601>
      preliminary:
        classification: superseded_by_decision | reframe_in_place | feedback_update_required | human_escalation
        classification_reason: <string>
        requires_fact_check: true | false
      required_checks:
        - claim_id: C1
          text: <comment claim>
          type: repo_fact | external_spec | issue_pr_fact | human_decision
          critical: true | false
    

    この packet がないと、codebase-investigator は「何を検証すべきか」「どの主張が critical か」「Issue 本文とコメントのどちらを source of truth とするか」を推測することになります。


    Blocker 4: 出力契約がないため、main thread が最終分類を安全にできない

    SubAgent は調査者であり、最終的な workflow transition を決めるべきではありません。codebase-investigator は fact-check result を返し、main thread / orchestrator が final classification を決めるべきです。

    追加すべき出力契約はこれです。

    ANCHOR_COMMENT_FACT_CHECK_RESULT_V1:
      status: ok | inconclusive | failed
      claims:
        - claim_id: <string>
          text: <string>
          type: repo_fact | external_spec | issue_pr_fact | human_decision
          verdict: supported | contradicted | inconclusive | not_checkable
          evidence:
            - kind: file | issue | pr | web
              ref: <path#line | issue_url | pr_url | citation>
              summary: <string>
      scope_impact: none | amend | replace | ambiguous
      recommended_final_classification: superseded_by_decision | reframe_in_place | feedback_update_required | human_escalation
      unresolved_risks: []
    

    ここで重要なのは recommended_final_classification です。SubAgent は「推奨」まで。LOOP_STATE.anchor_comment.final_classification を確定するのはオーケストレーターの責務です。


    責務分離の修正案

    層 | やること | やってはいけないこと -- | -- | -- main thread / orchestrator | comment 取得、所属検証、snapshot 固定、SubAgent 呼び出し、結果統合、final classification、mutation 実行判断 | コードベース事実を推測で判断する codebase-investigator | repo / Issue / PR / docs の事実確認、claim ごとの evidence 返却 | Issue 編集、close、代替 Issue 起票 web-researcher | 外部仕様・公式ドキュメント・CLI/API 挙動の検証 | repo 内設計判断、Issue mutation review-issue | Issue 本文の構造・AC/VC・契約品質レビュー | anchor comment の最終分類 issue-author | validated feedback を本文へ反映、または代替 Issue draft 作成 | close / create の実行判断 create-issue / edit-issue skill | 実 mutation | 分類・方針決定

    Agent SDK には structured output の仕組みがあり、期待する JSON schema に合わない場合の検証・再プロンプトが可能です。これは ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 のような契約を機械的に保証したい場合に有効です。(Claude Code)

    結論としては、Skill = 仕様・運用契約、Agent SDK = 後続の実行ハーネス です。#127 でいきなり SDK 化するとスコープが膨らみます。まず #127 では Skill 内の context packet / result schema / 責務分離を固定し、別 Issue で SDK runner を検討するのが安全です。

    #127 の高品質化パッチ方針

    #127 は次の内容に差し替えるのが妥当です。

    ## Goal
    

    issue-refinement-loop において、LOOP_STATE.anchor_comment.snapshot が存在し、
    かつ requires_fact_check が true の場合に、codebase-investigator へ
    ANCHOR_COMMENT_CONTEXT_V1 を渡し、ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 を受け取って
    main thread が final_classification を確定する入出力契約を追加する。

    In Scope

    • Step 1 に ANCHOR_COMMENT_CONTEXT_V1 入力契約を追加する
    • codebase-investigator の出力契約として ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 を追加する
    • main thread が fact-check result を統合し、final_classification / verified_claims / unresolved_claims / scope_impact を更新する手順を明記する
    • SubAgent / main thread / issue-author / review-issue の責務分離表を追加する
    • Step 4 には final_classification 後の正規化済み feedback のみ渡すことを明記する

    Out of Scope

    • Agent SDK runner の実装
    • create-issue / edit-issue / review-issue skill の変更
    • web-researcher の仕様変更。ただし external_spec claim がある場合に既存 Step 1b へ渡すことは明記する
    • anchor_comment_url 入力、Step 0a fetch、Step 0b classifier、Step 0c close 分岐の再実装

    修正版 Acceptance Criteria

    - [ ] AC1: .claude/skills/issue-refinement-loop/SKILL.md に ANCHOR_COMMENT_CONTEXT_V1 が定義されている
    
  4. AC2: Step 1 は LOOP_STATE.anchor_comment.snapshot != null かつ requires_fact_check == true の場合、classification 種別にかかわらず ANCHOR_COMMENT_CONTEXT_V1 を codebase-investigator に渡す
  5. AC3: .claude/skills/issue-refinement-loop/SKILL.md に ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 が定義されている
  6. AC4: codebase-investigator は mutation を行わず、claim ごとの verdict と evidence のみ返すと明記されている
  7. AC5: final_classification を確定する責務は main thread / orchestrator にあると明記されている
  8. AC6: Step 4 は raw anchor comment ではなく、final classification 後の正規化済み anchor_comment_feedback のみ受け取る
  9. [ ] AC7: Agent SDK 化は別 Issue とし、本 Issue では Skill 上の protocol contract 固定に限定する
  10. 修正版 Verification Commands

    # AC1 / AC3: context packet と result contract が存在する
    rg "ANCHOR_COMMENT_CONTEXT_V1|ANCHOR_COMMENT_FACT_CHECK_RESULT_V1"
    .claude/skills/issue-refinement-loop/SKILL.md

    AC2: snapshot + requires_fact_check による Step 1 注入条件がある

    rg "anchor_comment.snapshot|requireds?_fact_check|requires_fact_check|Step 1"
    .claude/skills/issue-refinement-loop/SKILL.md

    AC4 / AC5: 責務分離が明記されている

    rg "codebase-investigator.(MUST NOT|してはいけない).(edit|close|create|mutation)|main thread.*final_classification|orchestrator.*final_classification"
    .claude/skills/issue-refinement-loop/SKILL.md

    AC6: Step 4 が正規化済み feedback を受け取る

    rg "anchor_comment_feedback|final_classification.*feedback|正規化"
    .claude/skills/issue-refinement-loop/SKILL.md

    AC7: Agent SDK が out of scope / follow-up として扱われている

    rg "Agent SDK|AgentSDK|Out of Scope|follow-up"
    .claude/skills/issue-refinement-loop/SKILL.md

    最終提案

    #127 は 「Step 1 に snapshot を注入する Issue」から「anchor comment fact-check protocol を固定する Issue」へ再設計してください。Agent SDK は有力ですが、今ここで置き換えるより、まず Skill 内で protocol を固めるべきです。

    推奨順序は次です。

    1. 実装: issue-refinement-loop に ANCHOR_COMMENT_CONTEXT_V1 / ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 / requires_fact_check を追加し anchor comment fact-check の入出力契約を固定する #127 を再設計して、ANCHOR_COMMENT_CONTEXT_V1 / ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 / 責務分離を追加する。

    2. 実運用で issue-refinement-loop の監査ログ・再実行性・構造化出力検証が不足すると確認できたら、別 Issue で Agent SDK runner を作る。

    3. Agent SDK runner は Skill を置き換えるのではなく、Skill の protocol を実行する harness として実装する。

    ## 判定

    Issue #127 は、そのまま実装に回すべきではありません。
    理由は、Issue #127 が「Step 1 に anchor_comment.snapshot を注入する」だけにスコープを縮めていますが、関連する Issue #96 / PR #128 で anchor_comment_url、LOOP_STATE.anchor_comment、Step 0a/0b/0c、暫定分類、冪等性、close コメント統合まで既にかなり実装済みだからです。現時点の未解決点は「snapshot を渡すかどうか」ではなく、オーケストレーターと SubAgent 間の入出力契約が弱く、誰が分類・事実確認・最終判断・ mutation を担うのかがまだ曖昧なことです。

    Issue #127 のコメントで追加された「オーケストレーションと各サブエージェントのコンテクストのやり取り」「責務分離」「Agent SDK で実現すべきか」という論点は妥当です。これは #127 の AC1/AC2 のような rg 文字列検証では捕捉できない、control-plane 設計の問題です。

    敵対的レビュー

    Blocker 1: #127 は現在の main に対して一部 stale

    PR #128 により、現在の issue-refinement-loop/SKILL.md には既に anchor_comment_url、anchor_comment.snapshot、preliminary_classification、final_classification、verified_claims、unresolved_claims、scope_impact、ALTERNATIVE_ISSUE_DRAFT_V1、Step 1 の anchor comment 追加入力が入っています。つまり #127 の「Step 1 に snapshot 注入を追加する」という実装は、単純にやると 既存記述へ重複追記するだけの低品質 PR になります。

    #127 は次のように再定義すべきです。

    実装: issue-refinement-loop の anchor_comment fact-check context packet と SubAgent 入出力契約を固定する
    

    焦点は snapshot というフィールド名ではなく、SubAgent に渡す context packet と、SubAgent から返す fact-check result contract です。


    Blocker 2: Step 1 注入条件がまだ危険

    現在の SKILL.md では、Step 1 の追加入力は主に preliminary_classification が reframe_in_place / feedback_update_required の場合を想定しています。一方、#96/PR #128 の設計では、superseded_by_decision であっても「事実確認不要の場合のみ即時確定」であり、事実主張を含む場合は Step 1 で検証してから final_classification を確定する必要があります。

    したがって、#127 の不変条件はこう置くべきです。

    Step 1 anchor comment injection rule:
      if LOOP_STATE.anchor_comment.snapshot != null
      and LOOP_STATE.anchor_comment.requires_fact_check == true:
        pass ANCHOR_COMMENT_CONTEXT_V1 to codebase-investigator

    分類名に依存させるより、requires_fact_check を明示したほうが安全です。#79 の実例はまさに「コメントが人間 close Decision ではなく、コードベース事実に基づいて Issue 前提を再フレームする」ケースでした。


    Blocker 3: SubAgent に渡す情報がまだ薄い

    Claude Code の SubAgent は独立した context window で動き、親会話の履歴や既読ファイルを自動では見ません。必要な情報は delegation message / 入力として明示的に渡す必要があります。([Claude API Docs]1)

    現在の Step 1 追加入力は url、snapshot、classification、required_checks 程度です。これは不足です。最低限、次の context packet が必要です。

    ANCHOR_COMMENT_CONTEXT_V1:
      source:
        issue_number: <int>
        anchor_comment_url: <string>
        anchor_comment_id: <int>
        author_association: <string | null>
      issue_snapshot:
        title: <string>
        body: <string>
        labels: []
        captured_at: <iso8601>
      anchor_comment:
        snapshot: <string>
        captured_at: <iso8601>
      preliminary:
        classification: superseded_by_decision | reframe_in_place | feedback_update_required | human_escalation
        classification_reason: <string>
        requires_fact_check: true | false
      required_checks:
        - claim_id: C1
          text: <comment claim>
          type: repo_fact | external_spec | issue_pr_fact | human_decision
          critical: true | false

    この packet がないと、codebase-investigator は「何を検証すべきか」「どの主張が critical か」「Issue 本文とコメントのどちらを source of truth とするか」を推測することになります。


    Blocker 4: 出力契約がないため、main thread が最終分類を安全にできない

    SubAgent は調査者であり、最終的な workflow transition を決めるべきではありません。codebase-investigator は fact-check result を返し、main thread / orchestrator が final classification を決めるべきです。

    追加すべき出力契約はこれです。

    ANCHOR_COMMENT_FACT_CHECK_RESULT_V1:
      status: ok | inconclusive | failed
      claims:
        - claim_id: <string>
          text: <string>
          type: repo_fact | external_spec | issue_pr_fact | human_decision
          verdict: supported | contradicted | inconclusive | not_checkable
          evidence:
            - kind: file | issue | pr | web
              ref: <path#line | issue_url | pr_url | citation>
              summary: <string>
      scope_impact: none | amend | replace | ambiguous
      recommended_final_classification: superseded_by_decision | reframe_in_place | feedback_update_required | human_escalation
      unresolved_risks: []

    ここで重要なのは recommended_final_classification です。SubAgent は「推奨」まで。LOOP_STATE.anchor_comment.final_classification を確定するのはオーケストレーターの責務です。


    責務分離の修正案

    層 やること やってはいけないこと
    main thread / orchestrator comment 取得、所属検証、snapshot 固定、SubAgent 呼び出し、結果統合、final classification、mutation 実行判断 コードベース事実を推測で判断する
    codebase-investigator repo / Issue / PR / docs の事実確認、claim ごとの evidence 返却 Issue 編集、close、代替 Issue 起票
    web-researcher 外部仕様・公式ドキュメント・CLI/API 挙動の検証 repo 内設計判断、Issue mutation
    review-issue Issue 本文の構造・AC/VC・契約品質レビュー anchor comment の最終分類
    issue-author validated feedback を本文へ反映、または代替 Issue draft 作成 close / create の実行判断
    create-issue / edit-issue skill 実 mutation 分類・方針決定

    Claude Code のドキュメント上も、SubAgent は独立 context・独自 system prompt・個別 tool access を持つため、verbose な探索や専門的調査には向いていますが、結果は main に返して統合する設計が前提です。([Claude API Docs]1)

    Agent SDK で実現すべきか

    現時点の #127 は、Agent SDK に全面移管すべきではありません。
    まず Skill 側で ANCHOR_COMMENT_CONTEXT_V1 と ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 を SSOT として固定するのが先です。

    ただし、次の段階では Agent SDK 化する価値があります。Agent SDK は Claude Code をライブラリとして使い、built-in tools、hooks、subagents、sessions、permissions をプログラムから扱えます。さらに SubAgent メッセージには parent_tool_use_id が付き、どの SubAgent 実行に属するか追跡できます。([Claude Code]2)

    判断基準は次です。

    選択 適する状況
    Skill のまま 人間が Claude Code 上で issue refinement を起動する。手順・責務・入出力契約を明文化したい。
    Agent SDK CI/CD やバッチで複数 Issue を処理する。JSON Schema / Pydantic / Zod で構造化出力を検証したい。hooks で mutation 前監査を強制したい。session / telemetry / audit trail が必要。

    Agent SDK には structured output の仕組みがあり、期待する JSON schema に合わない場合の検証・再プロンプトが可能です。これは ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 のような契約を機械的に保証したい場合に有効です。([Claude Code]3)

    結論としては、Skill = 仕様・運用契約、Agent SDK = 後続の実行ハーネス です。#127 でいきなり SDK 化するとスコープが膨らみます。まず #127 では Skill 内の context packet / result schema / 責務分離を固定し、別 Issue で SDK runner を検討するのが安全です。

    #127 の高品質化パッチ方針

    #127 は次の内容に差し替えるのが妥当です。

    ## Goal
    
    issue-refinement-loop において、LOOP_STATE.anchor_comment.snapshot が存在し、
    かつ requires_fact_check が true の場合に、codebase-investigator へ
    ANCHOR_COMMENT_CONTEXT_V1 を渡し、ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 を受け取って
    main thread が final_classification を確定する入出力契約を追加する。
    
    ## In Scope
    
    - Step 1 に ANCHOR_COMMENT_CONTEXT_V1 入力契約を追加する
    - codebase-investigator の出力契約として ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 を追加する
    - main thread が fact-check result を統合し、final_classification / verified_claims / unresolved_claims / scope_impact を更新する手順を明記する
    - SubAgent / main thread / issue-author / review-issue の責務分離表を追加する
    - Step 4 には final_classification 後の正規化済み feedback のみ渡すことを明記する
    
    ## Out of Scope
    
    - Agent SDK runner の実装
    - create-issue / edit-issue / review-issue skill の変更
    - web-researcher の仕様変更。ただし external_spec claim がある場合に既存 Step 1b へ渡すことは明記する
    - anchor_comment_url 入力、Step 0a fetch、Step 0b classifier、Step 0c close 分岐の再実装

    修正版 Acceptance Criteria

    - [ ] AC1: `.claude/skills/issue-refinement-loop/SKILL.md` に `ANCHOR_COMMENT_CONTEXT_V1` が定義されている
    - [ ] AC2: Step 1 は `LOOP_STATE.anchor_comment.snapshot != null` かつ `requires_fact_check == true` の場合、classification 種別にかかわらず `ANCHOR_COMMENT_CONTEXT_V1` を `codebase-investigator` に渡す
    - [ ] AC3: `.claude/skills/issue-refinement-loop/SKILL.md` に `ANCHOR_COMMENT_FACT_CHECK_RESULT_V1` が定義されている
    - [ ] AC4: `codebase-investigator` は mutation を行わず、claim ごとの `verdict` と `evidence` のみ返すと明記されている
    - [ ] AC5: `final_classification` を確定する責務は main thread / orchestrator にあると明記されている
    - [ ] AC6: Step 4 は raw anchor comment ではなく、final classification 後の正規化済み `anchor_comment_feedback` のみ受け取る
    - [ ] AC7: Agent SDK 化は別 Issue とし、本 Issue では Skill 上の protocol contract 固定に限定する

    修正版 Verification Commands

    # AC1 / AC3: context packet と result contract が存在する
    rg "ANCHOR_COMMENT_CONTEXT_V1|ANCHOR_COMMENT_FACT_CHECK_RESULT_V1" \
      .claude/skills/issue-refinement-loop/SKILL.md
    
    # AC2: snapshot + requires_fact_check による Step 1 注入条件がある
    rg "anchor_comment.snapshot|requireds?_fact_check|requires_fact_check|Step 1" \
      .claude/skills/issue-refinement-loop/SKILL.md
    
    # AC4 / AC5: 責務分離が明記されている
    rg "codebase-investigator.*(MUST NOT|してはいけない).*(edit|close|create|mutation)|main thread.*final_classification|orchestrator.*final_classification" \
      .claude/skills/issue-refinement-loop/SKILL.md
    
    # AC6: Step 4 が正規化済み feedback を受け取る
    rg "anchor_comment_feedback|final_classification.*feedback|正規化" \
      .claude/skills/issue-refinement-loop/SKILL.md
    
    # AC7: Agent SDK が out of scope / follow-up として扱われている
    rg "Agent SDK|AgentSDK|Out of Scope|follow-up" \
      .claude/skills/issue-refinement-loop/SKILL.md

    最終提案

    #127 は 「Step 1 に snapshot を注入する Issue」から「anchor comment fact-check protocol を固定する Issue」へ再設計してください。Agent SDK は有力ですが、今ここで置き換えるより、まず Skill 内で protocol を固めるべきです。

    推奨順序は次です。

    1. 実装: issue-refinement-loop に ANCHOR_COMMENT_CONTEXT_V1 / ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 / requires_fact_check を追加し anchor comment fact-check の入出力契約を固定する #127 を再設計して、ANCHOR_COMMENT_CONTEXT_V1 / ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 / 責務分離を追加する。
    2. 実運用で issue-refinement-loop の監査ログ・再実行性・構造化出力検証が不足すると確認できたら、別 Issue で Agent SDK runner を作る。
    3. Agent SDK runner は Skill を置き換えるのではなく、Skill の protocol を実行する harness として実装する。
  11. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    Issue 本文 全面改訂(edit-issue skill による自動適用)

    変更理由

    anchor comment(issuecomment-4508382829)の reviewer feedback を受け、diff_proposal をすべて反映した。

    適用した変更

    1. Machine-Readable Contract の goal_ref 変更

      • 旧: Step 1 codebase-investigator 起動仕様への snapshot 注入ロジック追加
      • 新: ANCHOR_COMMENT_CONTEXT_V1・ANCHOR_COMMENT_FACT_CHECK_RESULT_V1・requires_fact_check フィールドの追加と SubAgent 入出力契約の固定
    2. Outcome セクション書き換え

      • 新 goal_ref に合わせて、入出力契約定義・requires_fact_check フラグ制御・main thread 責務明記の状態を Outcome として再定義
    3. In Scope 全面書き換え

      • 「snapshot 注入のみ」から「入出力契約の定義と責務分離」へ再設計(7 項目)
    4. Out of Scope 追記

      • Agent SDK runner の実装(別 Issue で検討)を追加
    5. Acceptance Criteria 全面書き換え(AC1-AC2 → AC1-AC7)

      • 契約定義・injection 条件・mutation 禁止・責務分離・Step4 受け取り範囲・OOS 明記の 7 AC に拡張
    6. Verification Commands 全面書き換え

      • 新 AC に対応する rg コマンド 5 本(AC1/AC3、AC2、AC4/AC5、AC6、AC7)
    7. Runtime Verification Applicability セクション追加

      • decision: not_applicable(SKILL.md テキスト変更のみ、rg による静的確認で完結)

    anchor_comment 分類

    final_classification: feedback_update_required
    scope_impact: replace

    バックアップ

    tmp/issue_127_backup.md に旧本文を保存済み。

  12. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    iteration 2: C5 fix - VC を AC 個別コメント形式に分割

    AC 7 件(AC1〜AC7)に対して VC の # ACN: コメントが 5 件しかなく(AC1/AC3 統合、AC4/AC5 統合)、C5 チェック(AC件数 = VC AC-comment件数)が FAIL していたため修正。

    各 AC に個別コメントを設けて VC を 7 件に揃えた。変更内容:

    • # AC1 / AC3: → # AC1: / # AC3: に分割
    • # AC4 / AC5: → # AC4: / # AC5: に分割(AC4 は codebase-investigator の mutation 不可、AC5 は final_classification 責務の main thread 帰属)
  13. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 完了 (2026-05-21T12:56:38Z)

    改善履歴

    iteration 0 → 1(anchor comment feedback 反映)

    • goal_ref を「snapshot 注入」から「ANCHOR_COMMENT_CONTEXT_V1 / ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 / requires_fact_check の入出力契約固定」へ改訂
    • Outcome を新 goal_ref 対応に書き換え
    • In Scope を 1 項目から 7 項目へ全面展開(context packet 定義・output contract・requires_fact_check・責務分離表・Step 4 正規化 feedback)
    • Out of Scope に Agent SDK runner を明示追加
    • Acceptance Criteria を AC1-AC2 から AC1-AC7 に全面書き換え
    • Verification Commands を 7 AC 対応の rg コマンドに更新
    • ## Runtime Verification Applicability セクションを追加(decision: not_applicable)
    • C5 FAIL: VC AC-comment 5件 / AC 7件 の不一致を検出

    iteration 1 → 2(C5 fix)

    • Verification Commands の AC1/AC3 統合コマンドと AC4/AC5 統合コマンドを個別分割(7コマンド体制)
    • C5 AC件数 ⇔ VC AC-comment件数が 7:7 で一致

    次アクション

    • issue-contract-review skill で着手前 preflight を実施してください
  14. changed the title [-]実装: issue-refinement-loop に任意入力 anchor_comment_url を追加し Step 1 調査依頼へコメント主張の事実確認を必須注入する[/-] [+]実装: issue-refinement-loop に ANCHOR_COMMENT_CONTEXT_V1 / ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 / requires_fact_check を追加し anchor comment fact-check の入出力契約を固定する[/+] on May 21, 2026
  15. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-21T13:09:38Z)

    • Outcome: .claude/skills/issue-refinement-loop/SKILL.md に ANCHOR_COMMENT_CONTEXT_V1・ANCHOR_COMMENT_FACT_CHECK_RESULT_V1・requires_fact_check フィールドが定義され、Step 1 injection 条件が requires_fact_check フラグで制御され、final_classification を確定する責務が main thread にあると明記されたコミットが存在する状態。
    • Acceptance Criteria:
      1. AC1: ANCHOR_COMMENT_CONTEXT_V1 が定義されている
      2. AC2: requires_fact_check による Step 1 injection 条件がある
      3. AC3: ANCHOR_COMMENT_FACT_CHECK_RESULT_V1 が定義されている
      4. AC4: codebase-investigator は mutation 不可と明記されている
      5. AC5: final_classification の責務が main thread にあると明記されている
      6. AC6: Step 4 が正規化済み anchor_comment_feedback のみ受け取ると明記されている
      7. AC7: Agent SDK 化が Out of Scope に明記されている
    • Verification Commands: Issue 本文の ## Verification Commands セクション参照(rg による静的テキスト存在確認 ×7)
    • Allowed Paths: .claude/skills/issue-refinement-loop/SKILL.md
    • Worktree: .claude/worktrees/issue-127-issue-refinement-loop-anchor-comment-con
    • Branch: worktree-issue-127-issue-refinement-loop-anchor-comment-con
    • VC preflight: baseline fail = 6, 想定外 pass = 1, 実行不可 = 0
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-05-21T13:09:38Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/127
      checks:
        template_compliance: pass
        state_label: pass
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 6
          vc_passed_unexpectedly: 1
          vc_unrunnable: 0
          classifications:
            - ac: AC6
              command: "rg \"anchor_comment_feedback|正規化.*feedback|final_classification.*feedback\" .claude/skills/issue-refinement-loop/SKILL.md"
              exit_code: 0
              category: expected_baseline_fail
              confidence: low
              evidence:
                stdout_excerpt: "anchor_comment_feedback: (from #96 partial implementation)"
              decision: go
              note: "VC pattern が #96 で追加された部分実装にヒット。AC6 の intent(raw anchor comment 不受信の明記)は未実装。VC が loose すぎる既知問題。実装で追加テキストを加えることで VC 継続 PASS となる。"
        ac_verifiability: pass
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
        - "AC6 VC が #96 partial implementation にヒット(loose VC)。実装で明示的な記述追加が必要。"
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

    agent/implementerenhancementphase/implementationstate/queued

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions