Repository navigation
Description
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: bugfixParent 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"]、timeout5)PostToolUse: matcher"Read"に対し1個のhandler(command同上、args["observe-reference-read"]、timeout5)
- 書き換え後、静的な YAML 妥当性確認(Python
yaml.safe_load()/ Node.jsyamlパッケージ)と、修正前後の意味内容が変わっていないことの 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
- PR feat: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する #2398(Issue 実装: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する #2397)の feature diff には一切触れない
pr_reviewer_guard.pyのロジック変更hooks:以外の frontmatter フィールド(name/description/tools/disallowedTools/model/effort/permissionMode/skills)の変更- upstream Claude Code 自体への修正提案
verify_pr_reviewer_permission_boundary.py等の既存 runtime probe スクリプトの再設計(将来的に--agents <json>workaround が不要になった可能性があるという指摘のみ Notes for Reviewer に残す。本 Issue では変更しない)- 各 hook handler group(
PreToolUse配下の9個の handler 等)を完全な nested block-style(1 handler = 複数行)へさらに展開すること。AC4 の runtime-smoke evidence が PASS すれば、現在の「トップレベルは block-style、各 handler group は単一物理行の flow-style」という mixed-style 実装のままで良い(将来の可読性改善は別Issue候補とする)
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 REACHABLEAllowed 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
- 参照元: squne121/loop-protocol Issue 実装: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する #2397 / PR feat: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する #2398 の impl-review-loop 再開作業中に発見された control-plane blocker。PR feat: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する #2398 の feature diff とは完全に独立。
- severity: blocking(pr-reviewer SubAgent が使えないと canonical impl-review-loop の Step 4 が進行不能なため)
- 原因調査の詳細: Claude Code 2.1.251 の fresh process(canonical main root、worktree 不使用)で
claude -d "agents,hooks" -p "hi" --debug-file <path> --max-turns 1を実行し、以下のログで直接確認した:隔離した一時ディレクトリでの bisection により、原因は[WARN] Failed to parse YAML frontmatter in <repo>/.claude/agents/pr-reviewer.md: YAML Parse error: Unexpected token [ERROR] YAML frontmatter in <repo>/.claude/agents/pr-reviewer.md failed to parse and was ignored: YAML Parse error: Unexpected tokenhooks:の multi-line flow-style YAML({/[を開いた直後に改行を挟み複数物理行にまたがる記法)にあることを特定した。1つの物理行にまとめた flow-style、または block-style へ書き換えるといずれも正常にパースされることを確認済み。sanity check として元の記法を同じ隔離環境で再テストし、確実に同じエラーを再現できることも確認済み。 - 以下は原因ではないことを確認済み:
hooks:フィールド自体は公式仕様でサポートされている/upstream Custom agents in .claude/agents/ not discovered when running from git worktree anthropics/claude-code#25816(worktree からの custom agent discovery 失敗)は v2.1.47 で修正済みで無関係(今回は worktree ではなく canonical main root で再現)/.claude/settings.jsonにpr-reviewerを明示的に deny する記述はない/name: pr-reviewerの重複定義は存在しない。 - Scope Collision (C1): 実装: SubAgent 発火前に bounded local context bundle を生成し Claude/Codex の両 loop で consume する #1909(
実装: SubAgent 発火前に bounded local context bundle を生成し Claude/Codex の両 loop で consume する)が.claude/agents/pr-reviewer.mdを含む広範な agent frontmatter 群を Allowed Paths に持つが、変更意図は本 Issue と独立(実装: SubAgent 発火前に bounded local context bundle を生成し Claude/Codex の両 loop で consume する #1909 は context bundle 配線、本 Issue はhooks:YAML 記法のみ)。non_conflict_reason: 編集対象セクションが競合しない(本 Issue はhooks:frontmatter のみ、実装: SubAgent 発火前に bounded local context bundle を生成し Claude/Codex の両 loop で consume する #1909 は本文/他フィールド)。dependency ordering: なし(並行実装可能。マージ順序はどちらが先でも可)。 - 参考情報(本 Issue では対応しないが記録):
scripts/agent-ops/verify_pr_reviewer_permission_boundary.pyは upstream Custom agents in .claude/agents/ not discovered when running from git worktree anthropics/claude-code#25816(worktree discovery 失敗、v2.1.47 で修正済み)への workaround として--agents <json>injection を使っているが、現行バージョンでは worktree discovery 自体は正常に動作する可能性が高く、この workaround が今も必要か将来的に見直す価値がある。 - Scope Delta 参照元: OWNER 敵対的レビュー(PR fix: pr-reviewer の hooks frontmatter を block-style YAML に書き換える #2415 review)https://github.com/squne121/loop-protocol/pull/2415#issuecomment-5466641709(P1 blocking: 実 consumer での動作証明が欠落)
worktree-agent-runtime-smokeの interactive lane が child SubAgent の spawn+completion 証明に現状使えない理由の詳細は Issue 実装: SubAgent 定義変更時の candidate-head bootstrap review を worktree-agent-runtime-smoke で自動回復する #2416 を参照(本Issue起票前の実地検証で、hooksを持たない agent でも同一の失敗パターンを再現し、pr-reviewer固有ではなくlane構造自体の制約であることを確認済み)- 現在の実装(
hooks:トップレベルのみ block-style、各 handler group は単一物理行の flow-style)についての「将来 handler 追加時に同種事故を再導入しやすい」という P2 指摘(同レビュー)は、本 Scope Delta では対応しない(Out of Scope に追記)。AC4 の runtime-smoke evidence が PASS すれば、現在の mixed-style 実装のままで merge blocker にしない。
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
squne121 commentedon Aug 30, 2026
implement-issue: 実装完了 (2026-08-30T01:00:38Z)
.claude/worktrees/issue-2414-pr-reviewer-hooks-block-styleworktree-issue-2414-pr-reviewer-hooks-block-stylefix: pr-reviewer hooks を単一物理行 flow-style handler で行数圧縮する