Skip to content

実装: docs/dev/agent-skill-boundaries.md に Loop Sequencing & Preconditions セクションを追加する #44

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "agent-skill-boundaries に loop sequencing 表を追加し前提依存を SSOT 化する"
change_kind: workflow

Parent Issue

なし(単独改善)

Parent Goal Ref

Current Validated Scope

docs/dev/agent-skill-boundaries.md に以下の 4 セクションを追加する:

  1. Loop Sequencing & Preconditions: phase / required_subagent_or_skill / required_input / required_output / stop_condition / handoff_contract の列を持つフェーズ表
  2. Mandatory SubAgent Contract: 各フェーズで必須の SubAgent/skill 一覧(issue-contract-review / implementation-worker / test-runner / pr-review-judge 等)と APPROVE 禁止条件
  3. SubAgent Execution Ledger: YAML schema 定義(schema: subagent_execution_ledger/v1)と PR 本文への summary 方針
  4. Hook-based Ledger Optional Design: SubagentStart / SubagentStop / PostToolUse(Agent) / Stop hook の設計概要(実装は別 Issue)

Remaining Parent Gaps

なし

Outcome

docs/dev/agent-skill-boundaries.md に (1) Loop Sequencing & Preconditions フェーズ表、(2) Mandatory SubAgent Contract 一覧、(3) SubAgent Execution Ledger YAML schema、(4) Hook-based Ledger 設計概要 が追加され、main にマージされ、rg "Loop Sequencing\|SubAgent Execution Ledger\|Mandatory SubAgent" docs/dev/agent-skill-boundaries.md | wc -l が 3 以上を返す状態。

In Scope

  • docs/dev/agent-skill-boundaries.md への以下 4 セクション追加:
    • Loop Sequencing & Preconditions: フェーズ表(phase / required_subagent_or_skill / required_input / required_output / stop_condition / handoff_contract)
    • Mandatory SubAgent Contract: 必須 SubAgent/skill 一覧と APPROVE 禁止条件
    • SubAgent Execution Ledger: YAML schema(subagent_execution_ledger/v1)と PR 本文 summary 方針
    • Hook-based Ledger Optional Design: hooks の設計概要(SubagentStart / SubagentStop / PostToolUse(Agent) / Stop)

Out of Scope

  • 各 loop SKILL.md の変更
  • CLAUDE.md への loop 起動順序追記
  • post-merge-cleanup の sequencing(並列軸のため別表または別セクション、必要時別 Issue)

Acceptance Criteria

  • AC1: Loop Sequencing & Preconditions セクションに phase / required_subagent / required_input / required_output / stop_condition / ledger_key の列がある
  • AC2: フェーズ表に少なくとも以下の phase が含まれる: issue_contract_preflight / runtime_preflight / implementation / post_commit_verification / pr_body_update / semantic_review / pre_merge_judgment
  • AC3: 各 phase に必須 SubAgent または skill が 1 つ以上定義されている
  • AC4: SubAgent Execution Ledger の YAML schema(schema: subagent_execution_ledger/v1 を含む)が docs に定義されている
  • AC5: test-runner 未実行、SKIP-only、fallback PASS、stale head_sha のいずれかを PR review blocker とする規則が書かれている

Verification Commands

  • rg -n "phase|required_subagent|required_input|required_output|ledger_key" docs/dev/agent-skill-boundaries.md — # AC1: フェーズ表列確認
  • rg -n "issue_contract_preflight|runtime_preflight|implementation|post_commit_verification|pr_body_update|semantic_review|pre_merge_judgment" docs/dev/agent-skill-boundaries.md | wc -l | awk '$1 >= 7 {print "OK"; exit} {print "FAIL"; exit 1}' — # AC2: 7 phase 記載
  • rg -n "issue-contract-review|implementation-worker|test-runner|pr-reviewer|pr-review-judge" docs/dev/agent-skill-boundaries.md — # AC3: 必須 SubAgent 記載
  • rg -n "subagent_execution_ledger/v1" docs/dev/agent-skill-boundaries.md — # AC4: ledger schema 記載
  • rg -n "test-runner.*未実行|SKIP-only|fallback.*PASS|stale.*head_sha|APPROVE.*禁止" docs/dev/agent-skill-boundaries.md — # AC5: APPROVE 禁止条件記載

Runtime Verification Applicability

decision: not_applicable
reason: |
  本 Issue は docs/dev/agent-skill-boundaries.md へのドキュメント追加のみ。
  実行時動作(UI/CLI/API/ゲームエンジン)を変更しないため runtime verification は不要。

Allowed Paths

  • docs/dev/agent-skill-boundaries.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • 各 loop SKILL.md の変更が必要になった場合(別 Issue 化)
  • CLAUDE.md / .claude/rules/ への波及が必要になった場合
  • 新規 Issue の起票が必要と判断した場合
  • 外部サービス利用・権限昇格が必要になった場合
  • nested SubAgent delegation が必要になった場合
  • 既存テスト大規模改変が必要になった場合

Required Skills

なし

Notes for Reviewer

観測元: PR #38 観測メモ section E。Issue #33 の進行で「refinement で contract を磨くと impl-review が短縮される」体感を SSOT 化したい。

Activity

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

    @squne121
    OwnerAuthor

    #131 refinement-loop からの追記 (2026-05-21)

    PR #81 の振り返り(#131 / issuecomment-4507583353、検証済み)で、impl-review-loop に実装とレビューを委ねた際、runtime 検証や PR レビューの SubAgent 責務が曖昧で「test-runner を実際に呼んだのか」が事後に追えなかった。

    本 Issue(agent-skill-boundaries.md の Loop Sequencing & Preconditions セクション追加)に、ChatGPT 提案6 の観点を取り込むことを推奨:

    • フェーズ → 必須 SubAgent の契約化: Issue 実装前 = issue-contract-review、外部 CLI / 認証あり = runtime preflight、実装 = implementation-worker、各コミット後 = test-runner、PR本文更新 = pr-body 保守、semantic review = adversarial reviewer、merge 直前 = pr-review-judge。
    • SubAgent Execution Ledger: PR 本文に各 SubAgent の実行結果(pass / partial / request_changes / blocked 等)を YAML で記載し、どの SubAgent を実際に通したかを事後検証可能にする。

    親トラッカー: #131

  3. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    例えばClaudeCode hookを使ってSubAgentの呼び出しをworktreeなどに記録できないか?
    あとはエージェントスキルを使ってオーケストラレーションを実現しているが、hookを使ってSubAgentの発火を実現できないか?そこまでいったらAgentSDKのほうが現実的か?

  4. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    結論

    Issue #44 は、現状のままだと REQUEST_CHANGES です。
    理由は、#131 で露呈した失敗の本質が「順序表がない」ではなく、必須SubAgentの実行契約・証跡・PR本文自己申告の検証不能性だからです。

    Issue #44 の現行スコープは docs/dev/agent-skill-boundaries.md に「Loop Sequencing & Preconditions」を追加し、issue-refinement-loop / issue-contract-review / impl-review-loop の順序・前提・典型イテレーション数を表にするものです。ACも見出し・skill名・表項目の存在確認に留まっています。(GitHub)
    一方 #131 は、PR #81 で「SKIP exit 0 / fallback PASS」「read-only transport 過大主張」「schema破壊」「PR本文全面置換」「敵対的レビュー後も人間がハルシネーション検出」という、より重い停止条件不備を親トラッカー化しています。(GitHub)

    したがって #44 は、単なる順序表ではなく、Loop Sequencing + Mandatory SubAgent Contract + Execution Ledger に拡張すべきです。


    関連Issue / PRから見た事実関係

    PR #81 は ACP transport 実装PRで、10 commits を経て 2026-05-21 に merge されています。(GitHub)
    コミット履歴を見ると、初回実装後に AC7 検証再設計、敵対的レビュー1回目、2回目、3回目、4回目の修正が重なっており、これは通常の「1回の実装→検証→レビュー」で収束していないことを示します。(GitHub)

    PR #81 のレビュー途中では、AC coverage 欠落と Allowed Paths 逸脱が blocker として出ており、その後 iteration 2 で APPROVE になっています。(GitHub)
    しかしその後の人間レビューでは、「clientCapabilities.fs=false は Gemini CLI の全I/O禁止を証明しない」「cwd=os.getcwd() が delegation contract を壊す」など、安全境界と再現性に関する重大ブロッカーが指摘されています。(GitHub)

    #85 は、PR #81 の verify_acp_roundtrip.sh が gemini 未導入、jq 未導入、_acp_fallback: true のいずれも exit 0 で PASS 扱いしていたことを明記し、SKIP exit 77 / fallback FAIL exit 1 / artifact 出力へ再設計するIssueです。(GitHub)
    #83 はその再発防止として、test-runner が SKIP / fallback を検出して PARTIAL verdict + human_review_required を返し、pr-review-judge が APPROVE を禁じる責務を持つべきだとしています。(GitHub)

    #87 は「CI pass をVC代替証跡として扱う」改善ですが、Out of Scope に impl-review-loop 側の test-runner 実行明示と test-runner agent 定義変更が残っています。(GitHub)
    つまり #44 の追記は、#87 だけでは埋まらない “test-runner が実際に呼ばれたか” の台帳化 を担当すべきです。


    敵対的レビュー

    Blocker 1: #44 のACが弱すぎる

    現行ACは「見出しがある」「3 skill名がある」「前提・典型・引き継ぎの語がある」程度です。これでは、#131 の提案6である フェーズ → 必須SubAgent契約化 と SubAgent Execution Ledger を満たしません。(GitHub)

    最低限、ACを以下に変えるべきです。

    - [ ] AC1: `Loop Sequencing & Preconditions` に phase / required_subagent / required_input / required_output / stop_condition / ledger_key の列がある
    - [ ] AC2: 少なくとも以下の phase が表に含まれる
      - issue_contract_preflight
      - runtime_preflight
      - implementation
      - post_commit_verification
      - pr_body_update
      - semantic_review
      - pre_merge_judgment
    - [ ] AC3: 各 phase に必須 SubAgent または skill が 1つ以上定義されている
    - [ ] AC4: `SubAgent Execution Ledger` の YAML schema が docs に定義されている
    - [ ] AC5: `test-runner` 未実行、SKIP-only、fallback PASS、stale head_sha のいずれかを PR review blocker とする規則が書かれている
    

    Blocker 2: 「順序表」と「実行証跡」が混同されている

    Loop Sequencing は 設計上の期待順序 です。Execution Ledger は 実際に実行された証拠 です。
    この2つを同じ表に混ぜると、また PR #81 と同じく「PR本文にそう書いてあるから通した」問題になります。

    分けるべきです。

    subagent_execution_ledger:
      schema: subagent_execution_ledger/v1
      pr: 81
      head_sha: "<reviewed_head_sha>"
      entries:
        - phase: issue_contract_preflight
          required: true
          agent: issue-contract-review
          status: pass
          evidence:
            comment_url: "..."
            transcript_ref: "..."
        - phase: post_commit_verification
          required: true
          agent: test-runner
          status: partial
          commit_sha: "..."
          verdict_ref: "TEST_VERDICT_MACHINE/v1"
          runtime_verification:
            skipped_count: 1
            fallback_detected: false
          human_review_required: true
    

    PR本文にはこの要約を置いてよいですが、正本は hook / transcript / comment / artifact から再構成できる形にするべきです。

    Blocker 3: impl-review-loop の責務がまだ過大

    現行の impl-review-loop は control-plane に限定すると言いながら、実際には「どのSubAgentを呼ぶべきか」「どの証跡をPR本文へ残すか」「どこで停止するか」まで暗黙判断しています。impl-review-loop の現行説明でも、実装→検証→PRレビューをSubAgentに委譲する3ステップループで、LOOP_VERDICTがAPPROVEになるまで反復するとされています。(GitHub)

    #131 を受けるなら、impl-review-loop は判断者ではなく、ledger completeness gate を持つルーターに寄せるべきです。

    具体的には、APPROVE条件をこう変更します。

    APPROVE may terminate the loop only if:
    1. pr-review-judge verdict == APPROVE
    2. required phases in subagent_execution_ledger are complete
    3. test-runner entry exists for the reviewed head_sha
    4. runtime verification entries are not SKIP-only unless explicit deferred contract exists
    5. PR body has not lost required sections
    

    Blocker 4: 「各コミット後 = test-runner」は重すぎる可能性がある

    #131 の追記案では「各コミット後 = test-runner」とありますが、これは運用上やや硬すぎます。PR #81 のように merge main / conflict fix / docs-only commit が混じると、全コミット単位の test-runner 義務はノイズになります。

    よりよい契約はこれです。

    test-runner must run after each material implementation delta.
    A material delta is:
    - source code change
    - verification script change
    - schema / contract change
    - runtime behavior change
    - dependency / settings / permission boundary change
    

    Docs-only, merge-only, PR-body-only commits may skip test-runner,
    but the ledger must record skip_reason.

    これなら「実行したか追えない」問題と「過剰実行」の両方を避けられます。


    Claude Code hooksでSubAgent呼び出しを記録できるか

    できます。これはかなり現実的です。

    Claude Code の hooks には SubagentStart と SubagentStop があり、SubagentStart では agent_id と agent_type、SubagentStop では agent_transcript_path と last_assistant_message を受け取れます。(Claude API Docs)
    また、親セッションは通常、SubAgentの中間ツール呼び出しを見ず、最終結果だけを受け取るため、実行証跡が欲しいなら transcript / hook / artifact 側で補う必要があります。(Claude Code)

    推奨構成はこれです。

    {
    "hooks": {
    "SubagentStart": [
    {
    "matcher": "",
    "hooks": [
    {
    "type": "command",
    "command": ".claude/hooks/subagent-ledger.sh start"
    }
    ]
    }
    ],
    "SubagentStop": [
    {
    "matcher": "",
    "hooks": [
    {
    "type": "command",
    "command": ".claude/hooks/subagent-ledger.sh stop"
    }
    ]
    }
    ],
    "PostToolUse": [
    {
    "matcher": "Agent",
    "hooks": [
    {
    "type": "command",
    "command": ".claude/hooks/subagent-ledger.sh parent-agent-result"
    }
    ]
    }
    ]
    }
    }

    出力先は、作業worktree内なら例えば以下です。

    .claude/worktrees/issue-44-/.agent-ledger/subagents.jsonl
    .claude/worktrees/issue-44-
    /.agent-ledger/ledger.yaml

    ただし、repo本体に常時コミットするのは避けたほうがいいです。transcript path や prompt 断片、ローカルパス、場合によっては秘密情報に近いものが混ざるためです。#136 でも、session記録ツールは transcript / prompt / tool calls / token usage / file contents を commit と紐付けられる一方、secret redaction は best-effort で shadow branch に未redaction snapshotが残る制約があると整理されています。(GitHub)

    したがって、PR本文には ledger summary + hash + artifact path までに留めるのが妥当です。


    hooksでSubAgentの発火を実現できるか

    結論は、限定的には可能だが、主オーケストレーションに使うべきではないです。

    Claude Code の hooks は「決定論的にシェルコマンドを走らせる」仕組みで、project rules の強制やログ記録には向いています。(Claude API Docs)
    一方で、command hook は / コマンドや tool call を直接トリガーできません。hookが返す additionalContext は Claude に読ませるリマインダーであって、強制的なSubAgent起動命令ではありません。(Claude API Docs)

    type: "agent" の hook は存在し、hook発火時にSubAgentをspawnして検証できます。ただし公式ドキュメント上も experimental で、production workflow では command hook を優先せよとされています。(Claude API Docs)

    したがって用途を分けるべきです。

    用途 hooksでやるべきか 理由
    SubAgent開始/終了の記録 Yes SubagentStart / SubagentStop がある
    Agent tool実行結果のPR ledger化 Yes PostToolUse on Agent で拾える
    Bash/gh/gitの危険操作ブロック Yes PreToolUse は permission mode より前に走り、denyできる
    test-runner未実行時のStopブロック 条件付きYes Stop hookでledger completenessを検査可能
    実装→検証→レビューの本体オーケストレーション No hookはslash command/tool callを直接起動できず、agent hookはexperimental
    複数SubAgentの厳密なワークフロー制御 Agent SDK寄り 状態管理・再試行・権限・セッションをコードで扱うべき

    Agent SDKのほうが現実的か

    “発火” ではなく “オーケストレーション” を実装したいなら、Agent SDK のほうが現実的です。

    Claude Agent SDK は Built-in tools、Hooks、Subagents、MCP、Permissions、Sessions を扱えるとされています。(Claude API Docs)
    つまり、impl-review-loop を単なるSkillプロンプトではなく、外部の決定論的オーケストレーターに寄せたい場合はSDKが向いています。

    ただし、今すぐ #44 で SDK 化するのはスコープ過大です。
    #44 では以下までが妥当です。

    1. agent-skill-boundaries.md に必須SubAgent契約と ledger schema を追加

    2. hooks は 記録・検査・ブロック 用として設計案だけ記載

    3. SDK化は別Issueに切る

    SDK化Issueを切るなら、タイトルは例えばこれです。

    調査/実装: impl-review-loop を Skill orchestration から Agent SDK orchestration へ移行する条件を評価する
    

    評価観点は以下で十分です。

    - Skill orchestration で維持する責務
    - hook ledger で補完する責務
    - Agent SDK に移すべき責務
    - Claude Code UI内運用との互換性
    - worktree / branch / PR body / GitHub comment / transcript の対応表
    - failure recovery: max_iterations, blocked, stale head_sha, runtime SKIP, fallback
    

    #44 に入れるべき実装パッチ方針

    Issue #44 の Current Validated Scope を、次のように増やすのがよいです。

    ## Current Validated Scope
    

    docs/dev/agent-skill-boundaries.md に以下を追加する:

    1. Loop Sequencing &amp; Preconditions

      • phase
      • required_subagent_or_skill
      • required_input
      • required_output
      • stop_condition
      • handoff_contract
    2. Mandatory SubAgent Contract

      • issue implementation 前: issue-contract-review
      • runtime / external CLI / auth あり: runtime preflight
      • 実装: implementation-worker
      • material implementation delta 後: test-runner
      • PR本文更新: open-pr / PR body maintenance owner
      • semantic review: pr-reviewer / pr-review-judge
      • merge直前: pr-review-judge + ledger completeness check
    3. SubAgent Execution Ledger

      • PR本文に summary YAML を置く
      • 正本は hook / transcript / GitHub comment / artifact から再構成可能にする
      • self-reported ledger only では APPROVE しない
    4. Hook-based Ledger Optional Design

      • SubagentStart
      • SubagentStop
      • PostToolUse(Agent)
      • Stop ledger completeness check

    ACも存在確認ではなく、構造確認にするべきです。

    # AC1: phase table columns
    rg -n "phase|required_subagent|required_input|required_output|ledger_key" docs/dev/agent-skill-boundaries.md

    AC2: mandatory agents

    rg -n "issue-contract-review|implementation-worker|test-runner|pr-reviewer|pr-review-judge" docs/dev/agent-skill-boundaries.md

    AC3: ledger schema

    rg -n "subagent_execution_ledger/v1|phase:|agent:|status:|evidence:" docs/dev/agent-skill-boundaries.md

    AC4: hook design

    rg -n "SubagentStart|SubagentStop|PostToolUse|Agent|Stop hook" docs/dev/agent-skill-boundaries.md

    AC5: approve禁止条件

    rg -n "test-runner.*未実行|SKIP-only|fallback PASS|stale head_sha|APPROVE.*禁止" docs/dev/agent-skill-boundaries.md


    最終判断

    #44 は採用すべきですが、現行の「Loop Sequencing表を追加するだけ」のIssueとして実装すると、#131 の再発防止には足りません。

    推奨は次です。

    #44: docs/dev/agent-skill-boundaries.md に

    • Loop Sequencing & Preconditions
    • Mandatory SubAgent Contract
    • SubAgent Execution Ledger schema
    • hook-based ledger design
      を追加する

    hookについては、SubAgent呼び出しの記録には使う。
    SubAgentの強制発火・本体オーケストレーションには使わない。
    そこまでやるなら、Skillではなく Agent SDK 化を別Issueで検討する、という整理が一番壊れにくいです。

    ## 結論

    Issue #44 は、現状のままだと REQUEST_CHANGES です。
    理由は、#131 で露呈した失敗の本質が「順序表がない」ではなく、必須SubAgentの実行契約・証跡・PR本文自己申告の検証不能性だからです。

    Issue #44 の現行スコープは docs/dev/agent-skill-boundaries.md に「Loop Sequencing & Preconditions」を追加し、issue-refinement-loop / issue-contract-review / impl-review-loop の順序・前提・典型イテレーション数を表にするものです。ACも見出し・skill名・表項目の存在確認に留まっています。([GitHub]1)
    一方 #131 は、PR #81 で「SKIP exit 0 / fallback PASS」「read-only transport 過大主張」「schema破壊」「PR本文全面置換」「敵対的レビュー後も人間がハルシネーション検出」という、より重い停止条件不備を親トラッカー化しています。([GitHub]2)

    したがって #44 は、単なる順序表ではなく、Loop Sequencing + Mandatory SubAgent Contract + Execution Ledger に拡張すべきです。


    関連Issue / PRから見た事実関係

    PR #81 は ACP transport 実装PRで、10 commits を経て 2026-05-21 に merge されています。([GitHub]3)
    コミット履歴を見ると、初回実装後に AC7 検証再設計、敵対的レビュー1回目、2回目、3回目、4回目の修正が重なっており、これは通常の「1回の実装→検証→レビュー」で収束していないことを示します。([GitHub]4)

    PR #81 のレビュー途中では、AC coverage 欠落と Allowed Paths 逸脱が blocker として出ており、その後 iteration 2 で APPROVE になっています。([GitHub]3)
    しかしその後の人間レビューでは、「clientCapabilities.fs=false は Gemini CLI の全I/O禁止を証明しない」「cwd=os.getcwd() が delegation contract を壊す」など、安全境界と再現性に関する重大ブロッカーが指摘されています。([GitHub]3)

    #85 は、PR #81 の verify_acp_roundtrip.sh が gemini 未導入、jq 未導入、_acp_fallback: true のいずれも exit 0 で PASS 扱いしていたことを明記し、SKIP exit 77 / fallback FAIL exit 1 / artifact 出力へ再設計するIssueです。([GitHub]5)
    #83 はその再発防止として、test-runner が SKIP / fallback を検出して PARTIAL verdict + human_review_required を返し、pr-review-judge が APPROVE を禁じる責務を持つべきだとしています。([GitHub]6)

    #87 は「CI pass をVC代替証跡として扱う」改善ですが、Out of Scope に impl-review-loop 側の test-runner 実行明示と test-runner agent 定義変更が残っています。([GitHub]7)
    つまり #44 の追記は、#87 だけでは埋まらない “test-runner が実際に呼ばれたか” の台帳化 を担当すべきです。


    敵対的レビュー

    Blocker 1: #44 のACが弱すぎる

    現行ACは「見出しがある」「3 skill名がある」「前提・典型・引き継ぎの語がある」程度です。これでは、#131 の提案6である フェーズ → 必須SubAgent契約化 と SubAgent Execution Ledger を満たしません。([GitHub]1)

    最低限、ACを以下に変えるべきです。

    - [ ] AC1: `Loop Sequencing & Preconditions` に phase / required_subagent / required_input / required_output / stop_condition / ledger_key の列がある
    - [ ] AC2: 少なくとも以下の phase が表に含まれる
      - issue_contract_preflight
      - runtime_preflight
      - implementation
      - post_commit_verification
      - pr_body_update
      - semantic_review
      - pre_merge_judgment
    - [ ] AC3: 各 phase に必須 SubAgent または skill が 1つ以上定義されている
    - [ ] AC4: `SubAgent Execution Ledger` の YAML schema が docs に定義されている
    - [ ] AC5: `test-runner` 未実行、SKIP-only、fallback PASS、stale head_sha のいずれかを PR review blocker とする規則が書かれている

    Blocker 2: 「順序表」と「実行証跡」が混同されている

    Loop Sequencing は 設計上の期待順序 です。Execution Ledger は 実際に実行された証拠 です。
    この2つを同じ表に混ぜると、また PR #81 と同じく「PR本文にそう書いてあるから通した」問題になります。

    分けるべきです。

    subagent_execution_ledger:
      schema: subagent_execution_ledger/v1
      pr: 81
      head_sha: "<reviewed_head_sha>"
      entries:
        - phase: issue_contract_preflight
          required: true
          agent: issue-contract-review
          status: pass
          evidence:
            comment_url: "..."
            transcript_ref: "..."
        - phase: post_commit_verification
          required: true
          agent: test-runner
          status: partial
          commit_sha: "..."
          verdict_ref: "TEST_VERDICT_MACHINE/v1"
          runtime_verification:
            skipped_count: 1
            fallback_detected: false
          human_review_required: true

    PR本文にはこの要約を置いてよいですが、正本は hook / transcript / comment / artifact から再構成できる形にするべきです。

    Blocker 3: impl-review-loop の責務がまだ過大

    現行の impl-review-loop は control-plane に限定すると言いながら、実際には「どのSubAgentを呼ぶべきか」「どの証跡をPR本文へ残すか」「どこで停止するか」まで暗黙判断しています。impl-review-loop の現行説明でも、実装→検証→PRレビューをSubAgentに委譲する3ステップループで、LOOP_VERDICTがAPPROVEになるまで反復するとされています。([GitHub]8)

    #131 を受けるなら、impl-review-loop は判断者ではなく、ledger completeness gate を持つルーターに寄せるべきです。

    具体的には、APPROVE条件をこう変更します。

    APPROVE may terminate the loop only if:
    1. pr-review-judge verdict == APPROVE
    2. required phases in subagent_execution_ledger are complete
    3. test-runner entry exists for the reviewed head_sha
    4. runtime verification entries are not SKIP-only unless explicit deferred contract exists
    5. PR body has not lost required sections
    

    Blocker 4: 「各コミット後 = test-runner」は重すぎる可能性がある

    #131 の追記案では「各コミット後 = test-runner」とありますが、これは運用上やや硬すぎます。PR #81 のように merge main / conflict fix / docs-only commit が混じると、全コミット単位の test-runner 義務はノイズになります。

    よりよい契約はこれです。

    test-runner must run after each material implementation delta.
    A material delta is:
    - source code change
    - verification script change
    - schema / contract change
    - runtime behavior change
    - dependency / settings / permission boundary change
    
    Docs-only, merge-only, PR-body-only commits may skip test-runner,
    but the ledger must record skip_reason.
    

    これなら「実行したか追えない」問題と「過剰実行」の両方を避けられます。


    Claude Code hooksでSubAgent呼び出しを記録できるか

    できます。これはかなり現実的です。

    Claude Code の hooks には SubagentStart と SubagentStop があり、SubagentStart では agent_id と agent_type、SubagentStop では agent_transcript_path と last_assistant_message を受け取れます。([Claude API Docs]9)
    また、親セッションは通常、SubAgentの中間ツール呼び出しを見ず、最終結果だけを受け取るため、実行証跡が欲しいなら transcript / hook / artifact 側で補う必要があります。([Claude Code]10)

    推奨構成はこれです。

    {
      "hooks": {
        "SubagentStart": [
          {
            "matcher": "",
            "hooks": [
              {
                "type": "command",
                "command": ".claude/hooks/subagent-ledger.sh start"
              }
            ]
          }
        ],
        "SubagentStop": [
          {
            "matcher": "",
            "hooks": [
              {
                "type": "command",
                "command": ".claude/hooks/subagent-ledger.sh stop"
              }
            ]
          }
        ],
        "PostToolUse": [
          {
            "matcher": "Agent",
            "hooks": [
              {
                "type": "command",
                "command": ".claude/hooks/subagent-ledger.sh parent-agent-result"
              }
            ]
          }
        ]
      }
    }

    出力先は、作業worktree内なら例えば以下です。

    .claude/worktrees/issue-44-*/.agent-ledger/subagents.jsonl
    .claude/worktrees/issue-44-*/.agent-ledger/ledger.yaml
    

    ただし、repo本体に常時コミットするのは避けたほうがいいです。transcript path や prompt 断片、ローカルパス、場合によっては秘密情報に近いものが混ざるためです。#136 でも、session記録ツールは transcript / prompt / tool calls / token usage / file contents を commit と紐付けられる一方、secret redaction は best-effort で shadow branch に未redaction snapshotが残る制約があると整理されています。([GitHub]11)

    したがって、PR本文には ledger summary + hash + artifact path までに留めるのが妥当です。


    hooksでSubAgentの発火を実現できるか

    結論は、限定的には可能だが、主オーケストレーションに使うべきではないです。

    Claude Code の hooks は「決定論的にシェルコマンドを走らせる」仕組みで、project rules の強制やログ記録には向いています。([Claude API Docs]12)
    一方で、command hook は / コマンドや tool call を直接トリガーできません。hookが返す additionalContext は Claude に読ませるリマインダーであって、強制的なSubAgent起動命令ではありません。([Claude API Docs]12)

    type: "agent" の hook は存在し、hook発火時にSubAgentをspawnして検証できます。ただし公式ドキュメント上も experimental で、production workflow では command hook を優先せよとされています。([Claude API Docs]9)

    したがって用途を分けるべきです。

    用途 hooksでやるべきか 理由
    SubAgent開始/終了の記録 Yes SubagentStart / SubagentStop がある
    Agent tool実行結果のPR ledger化 Yes PostToolUse on Agent で拾える
    Bash/gh/gitの危険操作ブロック Yes PreToolUse は permission mode より前に走り、denyできる
    test-runner未実行時のStopブロック 条件付きYes Stop hookでledger completenessを検査可能
    実装→検証→レビューの本体オーケストレーション No hookはslash command/tool callを直接起動できず、agent hookはexperimental
    複数SubAgentの厳密なワークフロー制御 Agent SDK寄り 状態管理・再試行・権限・セッションをコードで扱うべき

    Agent SDKのほうが現実的か

    “発火” ではなく “オーケストレーション” を実装したいなら、Agent SDK のほうが現実的です。

    Claude Agent SDK は Built-in tools、Hooks、Subagents、MCP、Permissions、Sessions を扱えるとされています。([Claude API Docs]13)
    つまり、impl-review-loop を単なるSkillプロンプトではなく、外部の決定論的オーケストレーターに寄せたい場合はSDKが向いています。

    ただし、今すぐ #44 で SDK 化するのはスコープ過大です。
    #44 では以下までが妥当です。

    1. agent-skill-boundaries.md に必須SubAgent契約と ledger schema を追加
    2. hooks は 記録・検査・ブロック 用として設計案だけ記載
    3. SDK化は別Issueに切る

    SDK化Issueを切るなら、タイトルは例えばこれです。

    調査/実装: impl-review-loop を Skill orchestration から Agent SDK orchestration へ移行する条件を評価する
    

    評価観点は以下で十分です。

    - Skill orchestration で維持する責務
    - hook ledger で補完する責務
    - Agent SDK に移すべき責務
    - Claude Code UI内運用との互換性
    - worktree / branch / PR body / GitHub comment / transcript の対応表
    - failure recovery: max_iterations, blocked, stale head_sha, runtime SKIP, fallback

    #44 に入れるべき実装パッチ方針

    Issue #44 の Current Validated Scope を、次のように増やすのがよいです。

    ## Current Validated Scope
    
    `docs/dev/agent-skill-boundaries.md` に以下を追加する:
    
    1. `Loop Sequencing & Preconditions`
       - phase
       - required_subagent_or_skill
       - required_input
       - required_output
       - stop_condition
       - handoff_contract
    
    2. `Mandatory SubAgent Contract`
       - issue implementation 前: `issue-contract-review`
       - runtime / external CLI / auth あり: runtime preflight
       - 実装: `implementation-worker`
       - material implementation delta 後: `test-runner`
       - PR本文更新: `open-pr` / PR body maintenance owner
       - semantic review: `pr-reviewer` / `pr-review-judge`
       - merge直前: `pr-review-judge` + ledger completeness check
    
    3. `SubAgent Execution Ledger`
       - PR本文に summary YAML を置く
       - 正本は hook / transcript / GitHub comment / artifact から再構成可能にする
       - self-reported ledger only では APPROVE しない
    
    4. `Hook-based Ledger Optional Design`
       - `SubagentStart`
       - `SubagentStop`
       - `PostToolUse(Agent)`
       - `Stop` ledger completeness check

    ACも存在確認ではなく、構造確認にするべきです。

    # AC1: phase table columns
    rg -n "phase|required_subagent|required_input|required_output|ledger_key" docs/dev/agent-skill-boundaries.md
    
    # AC2: mandatory agents
    rg -n "issue-contract-review|implementation-worker|test-runner|pr-reviewer|pr-review-judge" docs/dev/agent-skill-boundaries.md
    
    # AC3: ledger schema
    rg -n "subagent_execution_ledger/v1|phase:|agent:|status:|evidence:" docs/dev/agent-skill-boundaries.md
    
    # AC4: hook design
    rg -n "SubagentStart|SubagentStop|PostToolUse|Agent|Stop hook" docs/dev/agent-skill-boundaries.md
    
    # AC5: approve禁止条件
    rg -n "test-runner.*未実行|SKIP-only|fallback PASS|stale head_sha|APPROVE.*禁止" docs/dev/agent-skill-boundaries.md

    最終判断

    #44 は採用すべきですが、現行の「Loop Sequencing表を追加するだけ」のIssueとして実装すると、#131 の再発防止には足りません。

    推奨は次です。

    #44: docs/dev/agent-skill-boundaries.md に
    - Loop Sequencing & Preconditions
    - Mandatory SubAgent Contract
    - SubAgent Execution Ledger schema
    - hook-based ledger design
    を追加する
    

    hookについては、SubAgent呼び出しの記録には使う。
    SubAgentの強制発火・本体オーケストレーションには使わない。
    そこまでやるなら、Skillではなく Agent SDK 化を別Issueで検討する、という整理が一番壊れにくいです。

  5. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop iteration 1 — 本文更新

    • anchor comment (4509382237) final_classification: feedback_update_required
    • scope_impact: amend
    • 変更内容:
      • Outcome: 拡張後スコープ(4 セクション追加)を反映した記述に書き換え
      • Current Validated Scope: 4 セクション構造(Loop Sequencing / Mandatory SubAgent Contract / SubAgent Execution Ledger / Hook-based Ledger Design)に拡張
      • In Scope: 上記 4 セクションを明記
      • Acceptance Criteria: 存在確認 3 項目 → 構造確認・schema 確認・APPROVE 禁止条件確認の 5 項目に強化
      • Verification Commands: AC 追加に合わせて 5 コマンドに更新
      • Runtime Verification Applicability: legacy C9 対応として decision: not_applicable で追加
    • 不変: Allowed Paths / Out of Scope / Stop Conditions / Required Skills / Parent Issue / Remaining Parent Gaps / Notes for Reviewer
    • 次アクション: review-issue で再確認
  6. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 完了 (2026-05-21T14:55:47Z)

    • iteration: 1
    • verdict: approve
    • termination_reason: approved
    • anchor_comment: 実装: docs/dev/agent-skill-boundaries.md に Loop Sequencing & Preconditions セクションを追加する #44 (comment)
    • final_classification: feedback_update_required (OWNER squne121 の AC 強化・スコープ拡張要求)
    • 改善履歴:
      • Outcome: 4 セクション追加(Loop Sequencing / Mandatory SubAgent Contract / SubAgent Execution Ledger / Hook-based Ledger Design)を反映
      • Current Validated Scope: 4 セクション構造に拡張
      • In Scope: 列名・schema 名・hook 名を明記した 4 セクション詳細に拡張
      • Acceptance Criteria: 存在確認 3 項目 → 構造確認・schema 確認・APPROVE 禁止条件確認の 5 項目に強化
      • Verification Commands: 3 コマンド → 5 コマンドに更新(AC 対応)
      • Runtime Verification Applicability: decision: not_applicable で追加(legacy C9 対応)
    • 次アクション: issue-contract-review を起動して着手前 preflight を実行してください
  7. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-21T15:06:49Z)

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-05-21T15:06:49Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/44
      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: 3
          vc_passed_unexpectedly: 2
          vc_unrunnable: 0
          classifications:
            - ac: AC1
              command: "rg -n 'phase|required_subagent|required_input|required_output|ledger_key' docs/dev/agent-skill-boundaries.md"
              exit_code: 1
              category: expected_baseline_fail
              confidence: high
              decision: go
            - ac: AC2
              command: "rg -n 'issue_contract_preflight|...' | wc -l | awk..."
              exit_code: 1
              category: expected_baseline_fail
              confidence: high
              decision: go
            - ac: AC3
              command: "rg -n 'issue-contract-review|implementation-worker|test-runner|...'"
              exit_code: 0
              category: unknown
              confidence: high
              evidence:
                note: "既存ファイルに同名 skill がすでに別セクションで記載されているため baseline pass。VC が広すぎる。"
              decision: go_with_warning
            - ac: AC4
              command: "rg -n 'subagent_execution_ledger/v1'"
              exit_code: 1
              category: expected_baseline_fail
              confidence: high
              decision: go
            - ac: AC5
              command: "rg -n 'test-runner.*未実行|SKIP-only|fallback.*PASS|stale.*head_sha|APPROVE.*禁止'"
              exit_code: 0
              category: unknown
              confidence: medium
              evidence:
                note: "L127 の既存テーブル行に 'fallback PASS の場合は APPROVE しない' が存在。VC が広すぎる。"
              decision: go_with_warning
        ac_verifiability: pass
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
        - "AC3/VC3: rg パターンが広すぎて既存セクションの skill 名にもマッチ。実装後の verification では section-anchored パターンを推奨。"
        - "AC5/VC5: 'fallback.*PASS' が L127 既存行にマッチ。新セクション追加後も判定は機能するが VC 精度は低い。"

    Contract 確定事項

    • Outcome: docs/dev/agent-skill-boundaries.md に Loop Sequencing & Preconditions フェーズ表・Mandatory SubAgent Contract・SubAgent Execution Ledger schema・Hook-based Ledger 設計概要が追加される
    • Allowed Paths: docs/dev/agent-skill-boundaries.md のみ
    • Worktree: .claude/worktrees/issue-44-loop-sequencing-preconditions
    • Branch: worktree-issue-44-loop-sequencing-preconditions
    • VC preflight: baseline fail = 3, 想定外 pass = 2 (VC 広すぎ警告あり), 実行不可 = 0

    VC3・VC5 は既存コンテンツにもマッチするため、post-implementation 検証では手動で section 文脈を確認する。

  8. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-05-21T15:10:57Z)

  9. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-05-21T15:15:21Z)

    最終 LOOP_STATE

    LOOP_STATE:
      issue_number: 44
      contract_snapshot_url: https://github.com/squne121/loop-protocol/issues/44#issuecomment-4509582770
      iteration: 0
      max_iterations: 5
      worktree: .claude/worktrees/issue-44-loop-sequencing-preconditions
      branch: worktree-issue-44-loop-sequencing-preconditions
      last_step: judgment
      last_loop_verdict: APPROVE
      blockers_history: []
      external_research_skip_basis: internal-only docs change — no external spec lookups needed
      termination_reason: approved
  10. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    PR #184 REQUEST_CHANGES 対応完了 (iteration 1)

    commit: f71ca43

    修正内容

    Blocker 対応
    B1: required: true の意味が文書内で矛盾 APPROVE禁止条件5 を全 required phase 列挙(issue_contract_preflight, implementation, post_commit_verification, pr_body_update, semantic_review, pre_merge_judgment)に拡張。runtime_preflight は immediate のときのみ required とする旨を明記
    B2: docs-only skip と schema・contract変更が衝突 normative docs(SKILL.md / agents/*.md / CLAUDE.md / rules/** / policy.md / schema・contract定義 docs)を material delta とみなし skip 不可または human_review_required 必須と明記
    B3: PR本文 Ledger が追加した規約に違反 summary を required_total / required_pass / required_pending / required_blocked / required_skipped_with_waiver に変更し、pending > 0 の場合 human_review_required: true を必須化
    B4: Stop hook を hard gate と誤読させる記述 Stop hook は in-session soft gate と明記し、hard gate は pr-review-judge / CI / pre-merge script / branch protection に置くことを明示
    B5: #83 / #87 との schema 語彙不整合 post_commit_verification entry に verification_source / ci_check_ref / applicability / verification_skipped_count / runtime_ac_results を追加

    Verification Commands 結果

    • AC1: pass
    • AC2: OK (>= 7 行)
    • AC3: pass
    • AC4: pass
    • AC5: pass

    品質ゲート

    • typecheck: pass
    • lint: pass
    • test: 35/35 passed
    • build: pass
    • pytest: 21/21 passed
  11. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    PR #184 ledger 修正完了 (iteration 2)

    PR 本文の SubAgent Execution Ledger を以下の通り修正しました。

    BL-1: head_sha 更新

    • 修正前: head_sha: "b0cc63b"
    • 修正後: head_sha: "f71ca43ac736c156e633bbd4e126dc9e3d3ef43c"

    BL-2: human_review_required + summary フィールド名修正

    • human_review_required: false → human_review_required: true(semantic_review / pre_merge_judgment が pending のため)
    • summary を旧形式(required_complete / skipped)から新形式に変更:
      • required_total: 6
      • required_pass: 4
      • required_pending: 2
      • required_blocked: 0
      • required_skipped_with_waiver: 0
      • human_review_required: true

    変更対象: PR 本文のみ(worktree ファイル変更なし)
    PR: #184

  12. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-05-21T21:37:25Z)

    最終 LOOP_STATE

    LOOP_STATE:
      issue_number: 44
      contract_snapshot_url: https://github.com/squne121/loop-protocol/issues/44#issuecomment-4509582770
      iteration: 2
      max_iterations: 5
      worktree: .claude/worktrees/issue-44-loop-sequencing-preconditions
      branch: worktree-issue-44-loop-sequencing-preconditions
      last_step: judgment
      last_loop_verdict: APPROVE
      blockers_history:
        - iteration: 0
          source: human_review
          comment_url: https://github.com/squne121/loop-protocol/pull/184#issuecomment-4509715313
          blockers:
            - required:true 定義と APPROVE禁止条件の不一致
            - docs-only skip と normative docs 例外の衝突
            - PR本文 Ledger summary が規約違反
            - Stop hook を hard gate と誤読させる記述
            - '#83/#87 との schema 語彙不整合'
        - iteration: 1
          source: pr-review-judge
          blockers:
            - PR body ledger の head_sha が stale (b0cc63b → f71ca43)
            - pending phase なのに human_review_required: false
      termination_reason: approved
  13. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    implement-issue: iteration 3 修正完了 (2026-05-22T06:48:00Z)

    PR #184 の REQUEST_CHANGES (iteration 3) 5 blockers を解消しました。

    修正内容

    • B2: docs/dev/agent-skill-boundaries.md に evidence フィールド (source_kind/source_ref/observed_head_sha/produced_at/source_sha256) を各 ledger エントリに追加。APPROVE 禁止条件 7 として「non-PR-body evidence 必須」を明文化。
    • B4: Hook 用途表に「Agent hook による検査用 SubAgent 起動 = 原則 No / experimental」行を追加。Stop hook の説明に hard gate ではない旨を明記。
    • B5: waiver schema (required_when/decision/approver/reason/evidence_ref/followup_issue/expires_at) を追加。Required phase の skip/partial は waiver なしに APPROVE 禁止を明文化。
    • B1: PR 本文の head_sha を 1f733dff17ea087bfb9f26317ac9ddf8ba94d3cd に更新。
    • B3: section-anchored VC を実行して結果を PR 本文に追記(AC1/AC3/AC5/AC4 全 PASS)。

    コミット

    1f733dff17ea087bfb9f26317ac9ddf8ba94d3cd — fix: B2/B4/B5 — evidence schema・waiver schema・agent hook 注釈を追加する

    品質ゲート

    コマンド 結果
    pnpm typecheck pass
    pnpm lint pass
    pnpm test pass (5/5, 4 files)
    pnpm build pass
    uv run pytest pass (21/21)
  14. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    iteration 4 修正完了

    blocker B6 対応: PR #184 本文に ## Schema Change Applicability と ## Schema Consumer Inventory セクションを追加しました。

    追加内容

    • schema_change_applicability: schema_change(新規 schema subagent_execution_ledger/v1 追加)
    • compatibility: additive(既存 consumer なし)
    • Schema Consumer Inventory テーブル: 既存 consumer なし、producer 候補 impl-review-loop、consumer 候補 pr-review-judge / test-runner

    変更箇所

    • PR 本文のみ更新(worktree 内ファイル変更なし)
    • head_sha: 1f733df(変更なし)

    PR: #184

  15. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了(最終)(2026-05-21T22:02:07Z)

    最終 LOOP_STATE

    LOOP_STATE:
      issue_number: 44
      contract_snapshot_url: https://github.com/squne121/loop-protocol/issues/44#issuecomment-4509582770
      iteration: 4
      max_iterations: 5
      worktree: .claude/worktrees/issue-44-loop-sequencing-preconditions
      branch: worktree-issue-44-loop-sequencing-preconditions
      last_step: judgment
      last_loop_verdict: APPROVE
      blockers_history:
        - iteration: 0 (human): required:true 矛盾・docs-only/schema衝突・PR body ledger 規約違反・Stop hook soft gate・#83/#87 語彙不整合
        - iteration: 1 (AI): PR body head_sha stale・human_review_required 誤り
        - iteration: 2 (human): ledger/TEST_VERDICT stale・self-reported ledger 依存・section-anchored VC 先送り・hook表 experimental 未記載・waiver schema 欠落
        - iteration: 3 (AI): Schema Consumer Inventory に rg コマンド出力欠落
      termination_reason: approved
  16. squne121 commented on May 21, 2026

    @squne121
    OwnerAuthor

    post-merge-cleanup: 完了 (2026-05-21T22:09:29Z)

    • status: ok
    • 次アクション: なし(standalone issue)
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      follow_up_issues:
        - request_dedupe_key: "follow-up:squne121/loop-protocol:pr/184:schema-governance-known-schemas-registration"
          issue_number: 193
          issue_url: "https://github.com/squne121/loop-protocol/issues/193"
          status: created
    
      note_only_observations: []

    cleanup 内容

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