Skip to content

実装: pr-reviewer SubAgent の hooks frontmatter を block-style YAML に書き換え、fresh process での discovery 失敗を修正する #2414

Closed

Description

@squne121

Parent Issue

なし(単独改善)

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: null
goal_ref: "pr-reviewer SubAgent が fresh Claude Code process の canonical project discovery で正常にロードされること"
change_kind: bugfix

Parent Goal Ref

なし(単独改善。親 Issue を持たないため本セクションは該当なし)

Current Validated Scope

.claude/agents/pr-reviewer.md の hooks: frontmatter フィールドのみ。他の frontmatter フィールドおよび本文は対象外。

Remaining Parent Gaps

なし(単独改善のため親 Issue の gap 追跡は不要)。ただし scripts/agent-ops/verify_pr_reviewer_permission_boundary.py の --agents <json> workaround の要否再評価は本 Issue のスコープ外の follow-up 候補として Notes for Reviewer に記録する。

Outcome

.claude/agents/pr-reviewer.md の hooks: frontmatter を、意味的に完全に同一の内容を保ったまま block-style YAML(インデント形式)に書き換えたコミットを作成する。これにより、fresh Claude Code process(canonical main root、worktree 不使用)で Agent(subagent_type: "pr-reviewer") を呼び出した際に Agent type 'pr-reviewer' not found エラーが発生せず、pr-reviewer agent が runtime の available agent listing に正常に登場することを、**静的 YAML パース成功(AC1-AC3)に加え、実際の Claude Code runtime での discovery・spawn・completion(AC4、Scope Delta)**をもって完了とする。

Scope Delta(PR #2415 への OWNER 敵対的レビュー、#2415 (comment) 反映)

初版の AC1〜AC3 は静的 YAML パース検証(PyYAML 等価性・Node.js 厳密パース)のみであり、Issue の Outcome が要求する「fresh Claude Code process の canonical project discovery で正常にロードされる」ことを直接証明していなかった(false-green のリスク)。実際、一般的な YAML parser が受理する構造を Claude Code 自身の frontmatter consumer が拒否する、というのが本 Issue の根本原因であるため、一般的な YAML parser での検証だけでは不十分である。

.claude/skills/worktree-agent-runtime-smoke の structured lane を使い、candidate head に対して実際に Claude Code process を起動し、pr-reviewer が discovery され、Agent tool 経由で実際に spawn・completion されることを、subagent_causal_evidence.causal_evidence_source == hook_id_correlated(marker 文字列のみに依存しない hook-ID 相関済み evidence)で証明する AC4 を追加する。

Runtime Verification Applicability

decision: immediate
reason: "ローカル環境で uv run python3 / node による YAML パース比較・厳密パース確認、および実際の Claude Code process による discovery/spawn/completion 確認(AC4)が本 Issue 内で完結して実行できるため"
applicable_acs:
  - AC1
  - AC2
  - AC3
  - AC4
execution_environment:
  cli_tools: [python3, uv, node, claude]
  auth_required: false
  network_required: false
skip_conditions:
  - "uv または node コマンドがローカル環境に存在しない場合は AC1-AC3 を exit 77 で SKIP とし、証跡に不在理由を記録する"
  - "claude 実行ファイルがローカル環境に存在しない、または herdr/runtime-smoke capability が利用不能な場合は AC4 を exit 77 で SKIP とし、証跡に不在理由を記録する"
fallback_policy:
  fallback_success_is_pass: false
artifact_requirements:
  - "各 VC の実行結果(stdout の EQUAL / PARSE_OK / block_style 文字列と exit code)"
  - "AC4: worktree-agent-runtime-smoke の summary.md(causal_evidence_source / exit_code を含む)"

In Scope

  • .claude/agents/pr-reviewer.md の hooks: フィールドを、以下の意味を保ったまま block-style YAML へ書き換える:
    • PreToolUse: matcher "Bash" に対し、9個のhook handler(git commit/git push/git worktree/gh pr review/gh pr comment/gh pr merge/gh issue edit/gh issue comment/gh issue close それぞれに対応する if 条件、command は全て ${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py、args は全て ["deny"]、timeout は全て 5)
    • SessionStart: hooks 配下に1個のhandler(command同上、args ["observe-identity"]、timeout 5)
    • PostToolUse: matcher "Read" に対し1個のhandler(command同上、args ["observe-reference-read"]、timeout 5)
  • 書き換え後、静的な YAML 妥当性確認(Python yaml.safe_load() / Node.js yaml パッケージ)と、修正前後の意味内容が変わっていないことの diff 確認を行う
  • (Scope Delta) .claude/skills/worktree-agent-runtime-smoke の structured lane(--mode structured)を使い、candidate head(本 Issue の worktree)に対し実際に Claude Code process を起動し、pr-reviewer を Agent tool 経由で実際に spawn し completion まで確認する。marker 文字列は spawn された child(pr-reviewer)自身が出力する語を用い、subagent_causal_evidence.causal_evidence_source == hook_id_correlated かつ exit_code == 0 を成功条件とする(interactive lane は child SubAgent の spawn+completion 証明には現状使えないため使用しない。理由: Issue 実装: SubAgent 定義変更時の candidate-head bootstrap review を worktree-agent-runtime-smoke で自動回復する #2416 参照)

Out of Scope

Acceptance Criteria

  • AC1: .claude/agents/pr-reviewer.md の hooks: フィールドが block-style YAML(インデント形式)で記述されている
  • AC2: 修正後の hooks: の内容を Python の yaml.safe_load() でパースした結果が、修正前の内容を同様にパースした結果と完全に等価(dict として同一)である
  • AC3: 修正後のファイル全体が、Node.js の yaml パッケージ(厳密パーサ)でエラーなくパースできる
  • AC4(Scope Delta): 実際の Claude Code process(structured lane)が candidate head の .claude/agents/pr-reviewer.md から pr-reviewer を discovery し、Agent tool 経由で実際に spawn・completion できることを、subagent_causal_evidence.causal_evidence_source == hook_id_correlated かつ exit_code == 0 の runtime-smoke evidence で確認する

Verification Commands

# AC1
$ python3 -c $'text=open(".claude/agents/pr-reviewer.md").read()\nfm=text.split("---")[1]\nlines=[l for l in fm.splitlines() if l.strip().startswith("hooks:")]\nprint("block_style" if lines and lines[0].strip()=="hooks:" else "flow_style_or_missing")'
# AC2
$ python3 -c $'import yaml\nold_hooks = {"PreToolUse": [{"matcher": "Bash", "hooks": [\n  {"type": "command", "if": "Bash(git commit *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5},\n  {"type": "command", "if": "Bash(git push *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5},\n  {"type": "command", "if": "Bash(git worktree *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5},\n  {"type": "command", "if": "Bash(gh pr review *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5},\n  {"type": "command", "if": "Bash(gh pr comment *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5},\n  {"type": "command", "if": "Bash(gh pr merge *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5},\n  {"type": "command", "if": "Bash(gh issue edit *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5},\n  {"type": "command", "if": "Bash(gh issue comment *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5},\n  {"type": "command", "if": "Bash(gh issue close *)", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["deny"], "timeout": 5}\n]}], "SessionStart": [{"hooks": [{"type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["observe-identity"], "timeout": 5}]}], "PostToolUse": [{"matcher": "Read", "hooks": [{"type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/pr_reviewer_guard.py", "args": ["observe-reference-read"], "timeout": 5}]}]}\ntext = open(".claude/agents/pr-reviewer.md").read()\nfm = text.split("---")[1]\nnew_hooks = yaml.safe_load(fm)["hooks"]\nprint("EQUAL" if new_hooks == old_hooks else "MISMATCH")'
# AC3
$ node -e $'function r(){\nconst yaml=require("yaml")\nconst fs=require("fs")\nconst text=fs.readFileSync(".claude/agents/pr-reviewer.md","utf8")\nconst fm=text.split("---")[1]\nyaml.parse(fm)\nreturn "PARSE_OK"\n}\nconsole.log(r())'
# AC4
$ uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py --runtime claude --mode structured --worktree "$(pwd)/.claude/worktrees/issue-2414-pr-reviewer-hooks-block-style" --prompt-file tmp/runtime-smoke/pr-reviewer-discovery-ac4.md --output-dir artifacts/runtime-smoke/pr-reviewer-discovery-ac4 --timeout-seconds 300 --max-turns 30 --agent-type pr-reviewer --require-min-subagents 1 --expect-marker REACHABLE

Allowed Paths

  • .claude/agents/pr-reviewer.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • 同一ファイルへの意図しない意味変更(hooks の matcher/if/command/args/timeout のいずれかが変わった)を検出した場合は作業を停止し、diff を提示してから続行を確認する
  • hooks: 以外の frontmatter フィールドに変更が生じた場合は作業を停止する
  • AC2 の等価性確認スクリプトが MISMATCH を返した場合は commit せず修正する
  • AC3 の Node.js パースがエラーになった場合は commit せず修正する
  • AC4 の runtime-smoke evidence が causal_evidence_source: hook_id_correlated 以外(marker_only_insufficient / no_evidence)、または exit_code != 0 を返した場合は、marker 設計(child自身の出力語を使っているか)を見直した上で再実行し、それでも解消しない場合は human judgment を仰ぐ
  • PR feat: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する #2398 の feature diff と競合する変更が必要になった場合は作業を停止し、別 Issue へ切り出すか本 Issue の scope を見直す

Required Skills

なし

Required Design References

  • code.claude.com/docs/en/sub-agents(hooks frontmatter の block-style 記法の公式例)
  • code.claude.com/docs/en/hooks
  • .claude/skills/worktree-agent-runtime-smoke/SKILL.md

Delivery Rule

  • 1 Issue = 1 PR を原則とする
  • worktree での作業を推奨する
  • Draft PR を既定とする

Notes for Reviewer

scope_delta:
  status: approved_by_trusted_anchor
  anchor_comment_url: "https://github.com/squne121/loop-protocol/pull/2415#issuecomment-5466641709"
  anchor_author_association: OWNER
  allowed_path_deltas: []
  reason: "PR #2415 への OWNER 敵対的レビュー(P1 blocking)が、静的YAML parse検証だけでは実consumer(Claude Code)での動作証明にならないと指摘し、AC4(実runtime discovery/spawn/completion)の追加を要求したため"

Activity

  1. added
    phase/implementation
    agent/implementer
    on Aug 30, 2026
  2. squne121 commented on Aug 30, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-08-30T01:00:38Z)

    • PR: fix: pr-reviewer の hooks frontmatter を block-style YAML に書き換える #2415
    • Worktree: .claude/worktrees/issue-2414-pr-reviewer-hooks-block-style
    • Branch: worktree-issue-2414-pr-reviewer-hooks-block-style
    • Verification: AC1=block_style / AC2=EQUAL / AC3=PARSE_OK(すべて PASS)
    • pnpm typecheck/lint/test/build: 対象ファイル(.claude/agents/pr-reviewer.md)はいずれのパイプラインにも含まれず無影響(tsconfig include=src のみ、eslint に markdown plugin なし、vitest 対象外)
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  3. added a commit that references this issue on Aug 30, 2026
    99ae2be
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/implementerphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions