PR 全面代码审查
pr-review
全面的 PR 前审查编排器。针对当前分支已提交的差异运行命名的专项子智能体,按需检查简化情况,并使用专门的发现项验证器逐一核验规范化后的 Critical/Important 候选发现项,随后结合内置的 `references/review-criteria.md` 门禁策略,综合生成 Critical / Important / Suggestions / Strengths。在创建拉取请求前作为重量级质量门禁使用。是旧版 bash `triple-review` 编排器的预期继任者。
- License 许可
- MIT
- 所属仓库
- toku345/dotfiles
- 最近更新
- 2026-11-14
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- pr-review
- description
- Comprehensive pre-PR review orchestrator. Runs named specialist subagents on the current branch's committed diff, conditionally checks simplification, verifies each normalized Critical/Important candidate with a dedicated finding-verifier, then synthesizes Critical / Important / Suggestions / Strengths using the bundled `references/review-criteria.md` gate policy. Use before creating a pull request as a heavy quality gate. Intended successor to the legacy bash `triple-review` orchestrator.
02 资源文件 6
- 参考文档references/base-resolution-runtime-contract.json2.3 KB
- 参考文档references/finding-verifier-contract.json3.8 KB
- 参考文档references/review-criteria.md4.5 KB
- 参考文档references/severity-rules.json4.1 KB
- 参考文档references/v2-runtime-contract.json1.9 KB
- 脚本scripts/validate_finding_evidence.py7.5 KB
03 SKILL.md 正文
pr-review
Goal
Run a comprehensive specialist review of the current branch's changes against its base, then synthesize findings into a single actionable report.
Review Criteria
Use the bundled references/review-criteria.md as the source of truth for severity normalization, output budgeting, and re-review behavior. The short global AGENTS.md / CLAUDE.md policy explains when to choose built-in review versus heavy gates; this skill file and its bundled reference define how $pr-review gates a change once invoked.
Apply these high-level constraints throughout the Procedure:
- Optimize for merge decisions, not finding count.
- Do not put nits, style preferences, speculative rewrites, or weakly grounded concerns into the fix queue.
- Important findings are capped at 5 in the final aggregation; Suggestions are capped at 3.
- If evidence is incomplete but the risk may be severe, state the missing verification explicitly instead of silently dropping the finding.
- Re-review verifies prior Critical/Important findings and should not extend the loop with new nits, style feedback, or optional refactors.
- Critical findings require
blocking: yes,impact_scope,verified_assumptions, and nounverified_assumptionsneeded for the blocker claim. - Post-verification
needs-verificationwith non-emptymissingVerificationdowngrades a Critical candidate to Important; it remains visible, but not as a proven blocker. Other verdicts carryingmissingVerification, orneeds-verificationwithout it, are invalid verifier outputs and must fail closed. - Stop the review loop when Critical and Important are both 0; do not re-run only for Suggestions.
Preconditions
Environment note: this skill must be invoked from a terminal directly (codex exec ...), not from within an enclosing Claude Code session. The nested-bwrap permission failure documented in ~/.codex/history.jsonl (2026-03) makes nested invocation infinite-spawn-retry. The skill cannot reliably self-detect this; the caller takes responsibility.
Run these checks in order. If any fails, abort with the indicated actionable error and do not proceed to the Procedure section.
-
V1/V2 runtime contract — Before running any shell or Git command and before invoking any collaboration tool, inspect the tool definitions exposed to this session. Runtime contract sentinel:
PR_REVIEW_RUNTIME_CONTRACT_V1_V2.-
If collaboration tools are deferred, use the runtime's tool-discovery mechanism to resolve and inspect their definitions. Tool discovery is allowed here; a probe spawn is not. Do not infer the contract from feature flags, model name, tool namespace, profile name, or a prior session.
-
Admit exactly one coherent family and record the selected adapter for the entire run:
- The V1 adapter requires
spawn_agent(agent_type,message)with both arguments required and anagent_idin the successful result, targetedwait_agent(targets), andclose_agent(agent_id). Itsspawn_agentmust not accepttask_nameorfork_turns. - The V2 adapter requires
spawn_agent(task_name,message,agent_type?,fork_turns?,model?,reasoning_effort?)withtask_nameandmessagerequired, untargetedwait_agent(timeout_ms?),list_agents(path_prefix?), andinterrupt_agent(target). Itswait_agentmust not accepttargets;close_agentmust not be part of this family.send_message(target,message)andfollowup_task(target,message)may also be present and do not make the schema mixed, but the orchestrator must not use them for review-result transport or synchronization, and specialists must not use them under the control-plane ban. Althoughagent_type,fork_turns,model, andreasoning_effortare optional in the tool schema, every pr-review specialist spawn must set the exactagent_typeand explicitly setfork_turnsto"none"; omitmodelandreasoning_effortto inherit the parent.
- The V1 adapter requires
-
Optional unrelated, non-discriminating fields may be present in either family and do not by themselves make it mixed. Admission is determined by the required and forbidden control fields above; any added field that conflicts with those discriminators, or changes result identity or wait/cleanup semantics, is unknown and incompatible.
-
Missing, unresolved, incomplete, mixed, or unknown definitions are not compatible. Do not combine tools from different families or use a generic/default agent fallback.
-
If no coherent adapter can be selected, abort before repository inspection with this exact message:
ERROR: $pr-review requires one coherent Codex multi-agent V1 or V2 schema, but this session exposes missing, mixed, incomplete, or unknown collaboration tools. No specialist was spawned and no review was performed. Tool exposure is fixed for the lifetime of this session. Start a new Codex process from the repository under review: codex exec --profile review -C '<repo-root>' '$pr-review --base <same-base>' If the review-profile command still does not expose one exact supported schema, stop and report compatibility drift. Do not fall back to default agents. -
For both adapters, before repository inspection read
references/base-resolution-runtime-contract.json, require sentinelPR_REVIEW_BASE_RESOLUTION_CONTRACT_V2, and use its operation allowlist, classification precedence, retry limit, invocation-fingerprint, immutable-OID values, andallow_no_prtransition sequence as the machine-readable base-resolution contract. Record whether the shell tool exposessandbox_permissions=require_escalated; absence does not invalidate the immutable-OID path, but any later sandbox-denied operation that needs escalation must fail closed before specialist spawn. Abort before repository inspection if the contract is missing, malformed, unsupported, or conflicts with this prose. -
For both adapters, before repository inspection read
references/finding-verifier-contract.json, require sentinelPR_REVIEW_FINDING_VERIFIER_CONTRACT_V1, and use its candidate, task, scope, output, verdict, and integrity values as the machine-readable finding-verifier contract. Abort before repository inspection if the contract is missing, malformed, unsupported, or conflicts with this prose. -
For V2 only, call
list_agentsimmediately after selection and require a fresh agent tree: the current orchestrator entry may exist, but it must have no descendant. Abort before repository inspection if listing fails, a descendant already exists, or the current tree cannot be identified unambiguously. This prevents this run from adopting, interrupting, or confusing another run's tasks. -
For V2 only, before repository inspection read
references/v2-runtime-contract.json, require sentinelPR_REVIEW_V2_SCHEDULER_CONTRACT_V4, and use its timing, spawn, result, reconciliation, cleanup, and aggregation values as the machine-readable scheduler contract. Abort before repository inspection if the file is missing, malformed, unsupported, or conflicts with this prose.
-
-
Clean worktree — Run
git status --porcelain --untracked-files=normal. If the command fails, abort with the command output and do not review an unknown worktree state. If output is non-empty (uncommitted tracked changes or untracked-non-ignored files), abort with:"Worktree has uncommitted changes: <list>. The review covers committed branch diff only; uncommitted changes would be silently excluded. To inspect staged, unstaged, and untracked changes first, run
codex review --uncommitted. Commit or stash all listed changes, then retry$pr-review. (See ADR 0020.)" -
Base ref resolution — Determine
$BASEfrom one of three sources, in priority order. For the allowlistedgh pr view,git fetch, andgit remote set-head origin --autooperations below, always try the ordinary sandbox first. Retry only a sandbox/transport denial (socket: operation not permitted, a sandbox-caused DNS/connect denial, blocked TLS/service access, or EROFS/EACCES on required.gitmetadata) by reissuing the exact original executable, argv, cwd, and ordinary environment once withsandbox_permissions=require_escalated. Never request a persistent prefix approval. Approval metadata and the sandbox field are the only permitted fingerprint differences. Do not elevate an ordinary Git ref/remote/SSH-auth error, a GitHub API error, or an ambiguous failure. If escalation is unavailable, denied, or fails, abort before specialist spawn and recommend an immutable base OID.- (a) If the user prompt provides an explicit base (for example,
--base developor "review against develop"), use that verbatim and skip allghchecks below. If the explicit base is an immutable commit/OID, set$BASE_REFto that value and do not rungh, fetch, or any elevated command. Otherwise treat it as an origin branch name only after it passesgit check-ref-format --branch "$BASE"and does not start with-or+, contain:, or contain another refspec/control separator; reject anything else before runninggit fetch. For a valid branch name, rungit fetch --quiet origin "refs/heads/$BASE"through the scoped retry policy before validation, abort if it still fails, set$BASE_REF=FETCH_HEAD, and resolve$BASE_COMMITimmediately before any later fetch can overwriteFETCH_HEAD. Do not pass$BASEas a raw refspec. Do not proceed from existing local refs alone. If the caller needs offline execution, pass an immutable base commit. - (b) If the user prompt includes
--allow-no-pror$ALLOW_NO_PRis set to1/true, skipghentirely. Rungit fetch --quiet originthrough the scoped retry policy; if it still fails, abort instead of reviewing a possibly stale default branch. Rungit remote set-head origin --autothrough the same policy; if it still fails, abort instead of trusting a stale localorigin/HEADsymref. Rungit symbolic-ref --quiet --short refs/remotes/origin/HEAD; if it fails or returns an empty value, abort instead of guessing a base. Strip the leadingorigin/from the captured value, use the result as$BASE, use the full capturedorigin/<branch>ref as$BASE_REF, and add a**Degraded coverage**: no PR base, fell back to default branchline to the Output. - (c) Otherwise use the required PR lookup itself as the only GitHub auth/network probe; do not run the origin-unscoped
gh auth status:- Run
gh pr view --json baseRefName,baseRefOid --jq '[.baseRefName,.baseRefOid] | @tsv'in the ordinary sandbox. - If it fails with the explicit "no pull request found for the current branch" result, treat only that as the no-PR case. Otherwise run the same operation once in the ordinary sandbox with only
GH_DEBUG=apiadded as a discriminator. - Give a proven sandbox/transport denial precedence over credential-looking text. On such a denial, retry the original non-debug
gh pr viewinvocation once withsandbox_permissions=require_escalated. If the discriminator or elevated attempt reaches GitHub and proves HTTP 401 / bad credentials, abort with:"Stale
ghauth detected. Rungh auth loginand retry — the skill cannot resolve PR base ref without authenticated gh." - If the discriminator remains ambiguous, escalation is unavailable/denied, or the elevated command fails for any other reason, abort with a sanitized classification and the immutable-OID escape hatch. Do not persist or reproduce raw debug headers, responses, credential text, or tokens.
- If the successful authoritative result contains exactly two non-empty tab-separated fields (branch name and base commit OID), use the branch name as
$BASE. Validate it with the same explicit-branch safety rules (git check-ref-format --branch "$BASE", no leading-/+, no:or other refspec/control separator). Then rungit fetch --quiet origin "refs/heads/$BASE"through the scoped retry policy. ResolveFETCH_HEAD^{commit}and verify it exactly equals the returnedbaseRefOid; if it differs, abort with both OIDs. Set$BASE_REF=FETCH_HEADonly after that verification. - If a successful result does not contain exactly two non-empty tab-separated fields, abort with sanitized output and do not infer a base from malformed data. Never fall back to
origin/HEADafter an unexpectedgh pr viewfailure.
- Run
If none of (a)–(c) yields a base, abort with:
"No PR found for the current branch and no explicit base provided. By default the skill requires an open PR (Issue #186 fix) so all specialists share the same base ref. Either create a draft PR first, provide an explicit base in your prompt, or pass
--allow-no-pr/ setALLOW_NO_PR=1to fall back to the default branch (residual scope-divergence risk acknowledged)."Sandbox compatibility by base path:
- Explicit immutable commit/OID bases do not require network access or
.gitmetadata writes after the initial clean-worktree check; this is the only supported offline/read-only invocation path. - Explicit branch-name bases require network access and
git fetchwritingFETCH_HEAD; sandbox denial may use the bounded scoped retry above. --allow-no-prrequires network access,git fetch, andgit remote set-head origin --auto; sandbox denial may use the same bounded scoped retry.- Auto-PR base resolution requires
gh pr view, network access, and a verified fetch of the reported base branch; sandbox denial may use the bounded scoped retry, but offline runs remain unsupported. - If callers need offline/read-only review, they must supply an immutable base commit OID.
- (a) If the user prompt provides an explicit base (for example,
-
Base ref validation — Pin the already resolved
$BASE_REFto an immutable commit before collecting any diff:- If
gh pr viewreturnedbaseRefOid, keep$BASE_REF=FETCH_HEADafter the verified fetch/OID comparison; do not resolve the OID against a possibly stale local object database without fetching the PR base branch first. - If an explicit branch base was fetched, keep
$BASE_REF=FETCH_HEAD; do not replace it with a local branch or local remote-tracking ref. - If
--allow-no-prselected the default branch, keep$BASE_REFas the fetchedorigin/<branch>ref. - Otherwise use the explicit immutable base as
$BASE_REF. - Run
BASE_COMMIT=$(git rev-parse --verify "$BASE_REF^{commit}")immediately after assigning$BASE_REFand record the exact output for all later collection and specialist prompts. If it fails, abort with:"Base ref
<base>does not resolve to a commit. Check the base name or fetch the ref, then retry."
- If
Procedure
After preconditions pass:
-
Collect the review inputs and classify the diff:
- Run
git rev-parse HEADas an independent, preceding tool call and wait for it to complete before starting any other collection. Do not put HEAD recording in the same parallel tool call as status, log, file-list, or diff collection. - Require that call to succeed and record its commit OID as immutable
$HEAD_REF. If HEAD recording fails or does not return a commit OID, abort without starting collection. - After recording
$HEAD_REF, use that immutable OID for every later log, file-list, and diff command. Do not use symbolicHEADfor those commands. - Run
git status --short,git log --no-decorate "$BASE_COMMIT..$HEAD_REF",git diff --name-only "$BASE_COMMIT"..."$HEAD_REF", andgit diff "$BASE_COMMIT"..."$HEAD_REF". - Require every command to exit successfully. If any collection command fails, abort loudly instead of reviewing partial input.
- If the diff is genuinely empty, run the Final worktree guard immediately, then say
No committed changes relative to <base>; nothing to review.and stop rather than emitting a normal green review. Do not skip the final worktree or HEAD checks on the empty-diff path. - Always write the exact full diff to a temp file, compute its byte count and SHA-256, and include the path, byte count, and SHA-256 in the specialist prompt. Use a BSD/GNU-compatible suffix-free
mktemptemplate with the randomXs at the end, such asdiff_packet=$(mktemp "${TMPDIR:-/tmp}/pr-review-diff.XXXXXX"); do not use a suffixed template such aspr-review-diff.XXXXXX.diff, which can collide on BSDmktemp. Abort ifmktemp, diff writing, byte counting, or hashing fails. The diff packet is authoritative; any inline diff text is only a convenience excerpt. If a specialist cannot read the referenced packet or the packet hash does not match, it must return a fatal coverage error. - Use
git diff --name-onlyonly for path-based categories:test_paths: path components or basenames that are tests, such astests/,test/,__tests__/,*.test.*,*.spec.*,*_test.go,*_spec.rb,*.bats, or basenames beginning withtest_; do not classify ordinary runtime files as tests merely because they containtestin a role name such aspr-test-analyzeroperational_paths: review/runtime assets such asprivate_dot_codex/skills/**/SKILL.md,private_dot_codex/agents/*.toml,.github/workflows/**,.claude/hooks/**,.chezmoiscripts/**,dot_local/bin/**, and managed shell/config files whose content affects tool behaviordocs_paths: passive prose docs such asdocs/,*.md, orREADME*, excluding any path already classified asoperational_pathscode_paths: changed paths that are not passive docs-only assets, plus alloperational_paths
- Inspect the full diff hunks for content-based categories:
comment_changes: any added or removed comment line in source files, including mixed code+comment hunksdocs_or_comments:docs_pathsnon-empty orcomment_changesnon-emptytype_changes: hunks introducingclass/interface/type/struct/enum/trait/dataclass/ schema definitions, plus hunks modifying lines inside an existing type or schema definition block
When in doubt, include the specialist (over-coverage is cheaper than missed findings).
- Run
-
Build the Stage 1 specialist set and spawn it in parallel via
spawn_agent.- Every specialist spawn must select the exact custom role with
agent_type = "<specialist-name>"; omission and generic/default role fallback are forbidden in either adapter. - Do not set
modelorreasoning_effortunless intentionally overriding the parent's selection; those inherit from the parent when omitted. - Record the complete
expected_stage1set before spawning so completeness can be checked before aggregation. It contains the three always-on roles plus up to four conditional roles, for a maximum of 7. - Pass each spawn the following structured prompt:
- Target description:
Pre-PR review of branch <current> against <$BASE> - The resolved
$BASE_REF - The recorded
$BASE_COMMIT - The recorded
$HEAD_REF - The list of changed files (categorized)
git status --shortgit log --no-decorate "$BASE_COMMIT..$HEAD_REF"- The diff packet path, byte count, and SHA-256 (always supplied)
- Optional inline excerpt from
git diff "$BASE_COMMIT"..."$HEAD_REF"; the packet remains authoritative if output is truncated - Scope contract: review only the orchestrator-provided
$BASE_COMMIT...$HEAD_REFcommitted branch diff. Do not substitute unqualifiedgit diff, unstaged changes, a PR re-detection, a different base commit, a different HEAD, or another inferred scope. If the diff, file list, base commit, HEAD ref, or packet hash is missing or inconsistent, return a fatal coverage error. - Coverage sentinel contract: the first output line must be either
COVERAGE_OK <specialist> $BASE_COMMIT...$HEAD_REF <packet_sha256>orFATAL_COVERAGE_ERROR <specialist>: <reason>. Missing, malformed, or non-first-line sentinels are unusable output. - Review-only contract: do not edit files, create files, apply patches, run formatters that write files, or otherwise dirty the worktree. Return markdown findings or suggestions only.
- Control-plane contract:
Do not call any collaboration/subagent tools; return only your final review response. - Finding quality contract: every finding must include
blocking: yes/no,impact_scope,verified_assumptions, andunverified_assumptions. Useblocking: yesonly for clear merge blockers in the committed diff. Machine-local or ignored state, local-only performance regressions, developer-workflow-only false-greens, advisory observability gaps, and assumption-dependent risks should beblocking: nounless the committed diff proves a wider blocker.
- Target description:
Always spawn:
code-reviewersecurity-revieweradversarial-reviewer
Conditionally spawn (based on categorization):
pr-test-analyzer— ifcode_pathsis non-empty, especially whentest_pathsis emptycomment-analyzer— only ifdocs_or_commentsnon-emptysilent-failure-hunter— ifcode_pathsis non-empty (the hunter suppresses noise internally; default-on avoids heuristic false negatives such as shell|| true)type-design-analyzer— only iftype_changesnon-empty
Dispatch the recorded set through the selected adapter:
- The V1 adapter keeps
pending_stage1in deterministic order,running_stage1keyed by returnedagent_id, andcompleted_stage1keyed by role. Run at most 6 Stage 1 agents concurrently. When one yields a final usable result, record it, callclose_agentfor that ID, and fill the freed slot. Never omit a scheduled role because of capacity. - The V2 adapter derives a lowercase alphanumeric
run_tokenfrom the random suffix of the already-created diff-packetmktemppath; reject an empty or unsafe token. Name each taskprr_<run_token>_s<stage>_<role-with-hyphens-replaced-by-underscores>_a<attempt>, and verify before spawning that the name is absent. Every spawn must setfork_turns="none". Keep deterministic pending, running, and usable maps and run a maximum of 3 children concurrently.- Save the exact canonical task path returned by each successful spawn; the local task name alone is never an identity. Before each spawn and after each wait notification, use
list_agentsto verify every non-usable canonical task and the tree shape. - If
spawn_agentreports an error, immediately list status. If exactly the requested new name now exists and it did not exist before the call, adopt its canonical path and track it. If it is absent and the result is an explicit capacity error, retry once, only after a slot is available, with a newattemptname. A pre-existing name, more than one match, an absent task after any other/ambiguous error, or failure of the single retry is fatal. Never retry the same name. - After each notification, run one ordered reconciliation cycle: harvest and validate all newly delivered run-owned finals; call
list_agentsfor one successful full-tree snapshot; harvest every envelope delivered at that tool boundary; evaluate all tracked tasks and descendants; then refill only if no fatal evidence exists. Never refill between those steps. Fill every freed slot immediately after its child becomes usable under Step 3, even while two other children remain running; do not wait for the current batch to finish. A scheduled role that cannot be spawned after a usable child frees capacity makes the stage fail closed.
- Save the exact canonical task path returned by each successful spawn; the local task name alone is never an identity. Before each spawn and after each wait notification, use
- Every specialist spawn must select the exact custom role with
-
Await all Stage 1 specialists before proceeding.
-
Start one monotonic 30-minute Stage 1 deadline before the first spawn. Neither progress, an interim message, a retry, nor a wait call resets it.
-
The V1 adapter treats targeted
wait_agentas polling, not a barrier: keep the remainingagent_idset, callwait_agentwith those IDs andtimeout_ms = min(600000, remaining stage budget), record only final usable results, close completed IDs, fill capacity, and repeat until all expected roles are complete. -
The V2 adapter follows this state machine for each canonical task:
State Evidence Next action running canonical path has running status wait or inspect a delivered envelope final-seen one matched FINAL_ANSWERpayload, no accepted lifecycle evidenceretain the payload and reconcile status completed-seen completed status, no final payload allow a 60-second delivery grace, bounded by the stage deadline retired-seen task is absent from a successful full-tree snapshot after either observed-running evidence or a valid matching final allow the same bounded delivery grace when the final is still pending usable valid final payload plus completed status or qualified retirement retain evidence and fill capacity fatal error/interrupted status, disappearance without observed-running or a valid matching final, parent-interrupted retirement, invalid evidence, or expired deadline/grace clean up and abort wait_agent is notification-only; never treat its return as a task result or barrier.list_agents is status-only; never extract review text from it. The only authoritative review body is thePayloadof a delivered envelope whoseMessage TypeisFINAL_ANSWERand whoseSenderexactly equals a saved canonical task path. The envelope'sTask nameidentifies the recipient (normally/root), not the child, and must never be used as sender identity.- Ignore interim
MESSAGEenvelopes and do not reset any deadline. Validate a matching final immediately: an empty body, malformed/missing first-line sentinel,FATAL_COVERAGE_ERROR, role/scope/hash mismatch, or stated inability to verify the packet is fatal before refill. Record the first valid matching final payload byte-for-byte. Ignore an identical duplicateFINAL_ANSWER; a conflicting duplicate for the same canonical task is fatal. A final payload from an unknown or merely name-matched sender is not usable. - Bound each notification poll to
min(60000 ms, remaining stage budget, earliest active delivery-grace budget), then run the ordered reconciliation cycle. Never make a blocking wait longer than 60 seconds. If the result is below the tool's 10000 ms minimum, do not issue a wait that would cross the budget; inspect already-delivered envelopes and current status, then fail when the applicable deadline expires if evidence is still incomplete. - Treat
completedas normal lifecycle evidence. As a V2 compatibility fallback, also accept qualified retirement when a successful full-tree snapshot omits the exact saved canonical task after either (a) that task was previously observed withrunningstatus or (b) a valid matchingFINAL_ANSWERfrom that canonical sender was already recorded. The final-backed path is allowed only because the recognized V2 runtime deliversFINAL_ANSWERat child-turn completion. Both paths require that the parent has never calledinterrupt_agenton the task and that no run-global fatal evidence exists. A spawn result, a failed/incomplete list, mere name matching, or disappearance before both observed running and a valid matching final is not retirement evidence and is fatal. If the runtime's child-turn-completion semantics or schema is not established, fail closed instead of applying the fallback. Any descendant other than a saved, tracked top-level specialist is an unexpected descendant and is fatal. - If completed status or qualified retirement arrives first, start one per-task grace at that earliest lifecycle-evidence timestamp. The valid final must arrive strictly before
grace_start + 60000 msand before the stage deadline; equality or later is fatal. If the final payload arrives first, keep reconciling until completed status, qualified retirement, or the stage deadline. Later evidence never resets grace. - Retain the first valid payload, lifecycle evidence, and canonical identity even after a task becomes usable and until stage aggregation. Continue validating later run-owned envelopes and statuses: ignore a byte-identical duplicate final, but make a conflicting duplicate, later observed error/interrupted status, or any other fatal evidence abort the stage. Run one final ordered reconciliation cycle before aggregation.
-
Fail closed before aggregation if any expected specialist fails to spawn, errors, times out, returns empty output, or produces unusable output. On any abnormal exit after a spawn, stop dispatching pending roles; cleanup start is monotonic fatal and a later final cannot restore usability. The V1 adapter closes every remaining running V1 ID. The V2 adapter performs one final notification/status drain without extending the applicable deadline, then calls
interrupt_agentonly on a still-running run-owned top-level task or a still-running unexpected descendant beneath one of its saved canonical paths. Never interrupt the orchestrator or an unrelated path. Finally list status again and require that no run-owned task or owned descendant remains running; if cleanup cannot be confirmed, report cleanup failure together with the original fatal reason. Do not aggregate any partial result during cleanup. -
Fail closed before Stage 2 or aggregation if any specialist output is missing a first-line
COVERAGE_OK ...orFATAL_COVERAGE_ERROR ...sentinel, or if theCOVERAGE_OKsentinel does not match the expected specialist name,$BASE_COMMIT...$HEAD_REFscope, and packet SHA-256. -
Fail closed before Stage 2 or aggregation if any specialist output reports a fatal coverage error, missing/inconsistent scope, inability to read the diff packet, packet hash mismatch, or otherwise says it was unable to verify the packet or reviewed scope.
-
Partial aggregation is forbidden: every required role must be usable and pass coverage validation. If a future workflow wants partial results, require an explicit opt-in plus a visible degraded-coverage banner.
-
Each successful specialist returns the coverage sentinel followed by markdown findings.
-
-
Scan Stage 1 output and normalize severity before Stage 2:
- Apply
references/review-criteria.mdbefore trusting specialist labels. Specialist labels are useful signals, but final severity must still satisfy the bundled criteria. - Read
references/severity-rules.jsonand classify each finding with its escalation table. The table is shared verbatim with the Claude-side/pr-reviewskill; when the escalation rules change, edit the table, not skill prose.- A finding is Critical when it matches any rule in the table's
critical.any_ofAND satisfiescritical.guard(a concrete merge-blocking risk from the committed branch diff).- Treat a specialist Critical label as a candidate, not final severity. Re-check
blocking,impact_scope,verified_assumptions, andunverified_assumptions; do not keep Critical when the blocker depends on unverified assumptions. - Downgrade local-only, ignored generated state, developer-workflow-only false-green, local-only performance, or advisory observability findings to Important or Suggestion unless the committed diff proves an authoritative gate or merge outcome will be wrong.
- Treat a specialist Critical label as a candidate, not final severity. Re-check
- A finding that did not qualify as Critical is Important when it matches any rule in
important.any_ofAND satisfiesimportant.guard. - Treat remaining advisory findings as Suggestions unless the specialist explicitly marks them as positive observations, per the table's
suggestionrule.
- A finding is Critical when it matches any rule in the table's
- Do not promote nits, style preferences, speculative rewrites, or weakly grounded concerns into Critical or Important.
- If evidence is incomplete but the risk may be severe, keep the item with the missing verification stated explicitly instead of silently dropping it.
- Deduplicate findings that describe the same root cause while retaining all source-specialist names. From the remaining normalized Critical and Important findings, build the complete Stage 3 candidate list. Suggestions and positive observations are not verifier candidates.
- Give candidates deterministic IDs
f001,f002, ... in this order: Critical before Important, then first source specialist's Stage 1 dispatch order, then that specialist's finding appearance order. Each candidate must contain all fields required by the finding-verifier contract. Record the complete expected candidate-ID set before Stage 2; do not change IDs or membership based on Stage 2 output.
- Apply
-
Stage 2 — conditional
code-simplifierpass:- If Stage 1 surfaced no Critical findings, record
expected_stage2 = {code-simplifier}, then spawncode-simplifierwith the same target description,$BASE_REF,$BASE_COMMIT,$HEAD_REF, changed-file list,git status --short,git log --no-decorate "$BASE_COMMIT..$HEAD_REF", diff packet path, byte count, SHA-256, Scope contract, Coverage sentinel contract, review-only contract, and control-plane contract, plus a brief Stage 1 summary so it knows what's already flagged. Request advisory simplification findings only. - Use the selected adapter without switching families and keep Stage 2 at one active specialist. The V1 adapter uses the returned
agent_id, targeted waits, andclose_agent. The V2 adapter uses the samerun_token, a stage-2/attempt task name, exact customagent_type,fork_turns="none", saved canonical identity, spawn-error reconciliation, matchedFINAL_ANSWERpayload, accepted lifecycle evidence, ordered tree reconciliation, and run-ownedinterrupt_agentcleanup from Steps 2–3. - Apply the same first-line
COVERAGE_OK .../FATAL_COVERAGE_ERROR ...sentinel validation, packet SHA-256 validation, and fatal coverage error handling to Stage 2 output before final aggregation. - Start one monotonic 10-minute Stage 2 deadline before its spawn. The V1 adapter uses the existing targeted-wait/close loop. The V2 adapter applies the same canonical-identity state machine, completed-or-qualified-retirement lifecycle evidence, ordered reconciliation, duplicate handling, 60-second delivery grace, and poll bound of
min(60000 ms, remaining stage budget, earliest active delivery-grace budget); none may extend the Stage 2 deadline. - If the scheduled specialist fails to spawn, errors, times out, returns empty output, or produces unusable output, perform the selected adapter's run-owned cleanup and fail closed before final aggregation. Partial aggregation is forbidden here too.
- Otherwise, skip Stage 2 — polishing code with Critical issues is wasted effort.
- If Stage 1 surfaced no Critical findings, record
-
Stage 3 — verify normalized Critical/Important candidates:
- Stage 3 is evidence verification, not another review. Use
finding-verifierwith exactly one candidate per task. It must not discover new findings, reclassify severity, edit files, execute changed code, or use collaboration tools. Stage 2 output never adds candidates and Stage 2 is not re-run after verification. - If the recorded candidate set is empty, spawn nothing and record an empty verification summary. Otherwise dispatch every candidate through the selected adapter with exact custom
agent_type = "finding-verifier"; omission and generic/default fallback are forbidden. Pass the single complete candidate,references/finding-verifier-contract.json,$BASE_REF,$BASE_COMMIT,$HEAD_REF, changed-file list, git log, authoritative packet path, byte count, and SHA-256, plus the immutable-scope, read-only, and control-plane contracts. Do not pass unrelated findings. - The V1 adapter keeps deterministic pending/running/completed candidate maps keyed by candidate ID, runs at most 3 verifier tasks concurrently, accepts only the returned
agent_id, and uses the same targeted-wait and close rules as Stage 1. The V2 adapter uses the samerun_token, a maximum of 3 children,fork_turns="none", and exact task namesprr_<run_token>_s3_finding_verifier_<candidate_id>_a<attempt>. It applies the same canonical sender, spawn reconciliation, lifecycle, ordered reconciliation, delivery-grace, duplicate, deadline, and owned-cleanup rules as Stage 1. - Start one monotonic 30-minute Stage 3 deadline before the first spawn. Neither progress nor retries reset it. For V2, each notification poll remains bounded by
min(60000 ms, remaining stage budget, earliest active delivery-grace budget). - Require exactly one usable result for the exact expected candidate-ID set. Each result's first line must match
VERIFICATION_OK finding-verifier <candidate_id> $BASE_COMMIT...$HEAD_REF <packet_sha256>, followed by a single JSON object matching the contract. Every evidence item must contain exactly a non-empty repository-relativepath, a positive integer or positive line-rangeline, and a non-emptyobservation; reject absolute/traversal/control-character paths, placeholder values, zero/negative lines, and extra fields.FATAL_VERIFICATION_ERROR, unknown/duplicate/missing candidate IDs, scope/hash mismatch, malformed JSON, invalid fields, invalid verdict shape, task failure, timeout, or partial delivery fails closed before aggregation. - Before applying any verdict, serialize each parsed result JSON object to a dedicated temp file outside the worktree using a quoted heredoc delimiter, then run the bundled
scripts/validate_finding_evidence.pywith the repository root, exact recorded$HEAD_REF, and result-file path. The validator resolves each path as a literal entry in the immutable$HEAD_REFGit tree, accepts only regular text blobs, and requires the cited line or inclusive range to fit within that blob's logical line count. Require exit 0 and exact stdoutEVIDENCE_OK finding-verifier <candidate_id> $HEAD_REF <evidence_count>. A missing script, write or execution failure, nonzero exit, unexpected stdout, absent/non-file/binary path, out-of-bounds line, or evidence-count mismatch is fatal before verdict application. Never validate against the current worktree and never interpolate an evidence path into a shell command. - Apply verdicts without changing finding identity:
confirmedretains the normalized severity;refutedremoves the candidate from the fix queue but keeps it visible under Refuted Findings;needs-verificationrequires non-emptymissingVerification, downgrades Critical to Important, and retains Important as Important.confirmedandrefutedrequire non-empty evidence and emptymissingVerification. Any other combination is invalid and fails closed.
- Stage 3 is evidence verification, not another review. Use
-
Final worktree guard:
- Run
git status --porcelain --untracked-files=normalagain after all specialists complete and before aggregation, or before the empty-diff early exit. - If the command fails, abort with the command output and do not aggregate against an unknown worktree state.
- If output is non-empty, abort with:
"Review subagents or concurrent tooling changed the worktree: <list>. These changes were not part of the reviewed committed diff. Revert, commit, or stash them, then retry."
- Run
git rev-parse HEADagain and compare it with the recorded$HEAD_REF. If it differs, abort with:"HEAD changed during review: started at
<old>, now<new>. The completed specialist results do not cover the current commit. Re-run the review."
- Run
-
Aggregate all retained specialist findings into the Output Format below. Preserve the originating specialist name and candidate ID in each verified Critical/Important bullet so the reader can trace lineage. Include every refuted candidate and its verifier summary under Refuted Findings; refuted items do not count toward Critical or Important totals. Always include the stop condition in Recommended Action:
Critical 0 / Important 0means stop; Suggestions alone do not justify another gate run. On the second and later pass, focus on prior Critical/Important resolution. On the third and later pass, if Critical/Important findings keep appearing or changing without stable blocker evidence, call out possible review churn and return the decision to a human maintainer.
Output format
# PR Review: <branch> vs <base>
<degraded-coverage line if applicable>
## Verification Summary
- Confirmed: X; Needs verification: Y; Refuted: Z
## Critical Issues (X found)
- [<candidate-id> / <specialist>]: <description> [<file>:<line>]
- Impact scope: ...
- Verified assumptions: ...
- Unverified assumptions: ...
- Why it matters: ...
- Suggested fix: ...
## Important Issues (X shown, top 5)
- [<candidate-id> / <specialist>]: <description> [<file>:<line>]
- Impact scope: ...
- Missing verification: <if any>
## Suggestions (X shown, max 3)
- [<specialist>]: <description> [<file>:<line>]
## Refuted Findings
- [<candidate-id> / <specialist>]: <original description>
- Verifier summary: ...
## Strengths
- <positive observations from specialists>
## Recommended Action
1. Fix Critical issues first
2. Address Important issues
3. Consider Suggestions
4. Re-run review after fixes to verify prior Critical/Important findings
5. Stop when Critical 0 / Important 0; do not re-run for Suggestions only
6. If this is the third or later pass and Critical/Important findings still churn, escalate to human judgment
See also
- Design Doc:
docs/design/codex-pr-review.md(dotfiles repo) - ADR 0020: clean-worktree invariant (Precondition 1 origin)
- Issue #186: scope-alignment fix (Precondition 2 origin)
- ADR 0023 (planned): final decision record
04 同仓库更多 Skills
代码原理讲解
teach
通过探究代码、变更与子系统的工作原理及其设计原因来进行讲解,并按用户的节奏施教。适用于明确的教学请求(teach me this、help me understand this implementation、この実装を教えて、仕組みと設計背景を知りたい),以及评审或修改前的理解需求。不要对每个事实性问题或以实现为主的请求都触发。
PR 审查教练
pr-review-coach
仅支持日语的 PR 理解教练。当用户想要准备自己的审查、理解分支差异、梳理要提出的问题,或在执行合并门禁前建立审查判断力时使用。首轮需显式提供 --base <ref-or-commit>,后续回答轮次从本地状态恢复。每次最多提出一个问题,并将可恢复的本地状态存储在目标工作树之外。仅限单智能体;不派生专项审查员,不产生 Critical/Important/Suggestions 门禁发现项,也不决定是否可以合并。
日语文章校对
writing-proofreader
日语博客与技术文章的校对技能。基于 Fumitaka 的文体指南,检查表达、结构与语气,并提出改进建议。适用于「校对一下」「审查一下」「检查文章」「看看我写的文章」「能帮我看看博客吗」「有没有哪里不对」「发布前确认一下」「这篇文章你觉得怎么样?」等与文章或博客质量检查相关的各类请求。当用户要求对 Markdown 或纯文本文章进行校对时,务必参考此技能。文章中的「推敲」「修改」「批改」等表述同样会触发本技能。
PR 前评审质量闸门
pr-review
Claude 侧的 PR 前评审闸门。解析分支的 base ref(gh PR view 或显式 --base),固定一份权威的 diff 包,然后启动 pr-review 动态工作流(~/.claude/workflows/pr-review.js),该工作流最多分派 8 位评审专家(code-reviewer、security-reviewer、adversarial-reviewer、pr-test-analyzer、comment-analyzer、silent-failure-hunter、type-design-analyzer、code-simplifier),覆盖不足则失败关闭,并核验 Critical/Important 级别的发现。在创建拉取请求前用作大型变更的质量闸门——尤其适用于 Codex CLI 的 `$pr-review` 技能不可用的情况。触发词:「pre-PR review」「PR 前レビュー」「レビュー gate を回して」「run the pr-review gate」。
Codex CLI 计划评审指南
codex-usage
介绍使用 Codex CLI 进行实现计划评审的条件与步骤,以及 `/codex:adversarial-review` / `/codex:rescue` 的区分使用。在大型变更的计划完成时,或考虑调查委派、尝试其他方案、后台执行时参考。
苏格拉底式设计头脑风暴
brainstorming
通过苏格拉底式对话敲定需求与设计,再确定实现方针的头脑风暴技能。在「头脑风暴」「想考虑设计」「该怎么实现」「想咨询架构」「设计咨询」「实现前先梳理」「想确定方针」等请求时触发。在实现前通过苏格拉底式对话细化设计;提出 2~3 个方案,并将关键决策记录为 ADR。