360 Secure SkillHub
360 安全技能中心

code-review

该 Skill 按变更风险选择审查层级,使用独立模型评审与并行子智能体视角审查代码 PR,核验发现并生成绑定当前提交的审查回执;无 GitHub 或子智能体时可降级为本地 diff 和顺序评审。

分类:开发
conorbronsdon
conorbronsdon
热度 30.03
最近更新 2026-12-01 06:38:16

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add conorbronsdon/code-review
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
code-review
description
Risk-tiered, multi-agent review for code PRs in any repo, bound to the exact commit. Use when asked to "deep review this PR," "multi-agent review," "review
argument-hint
[pr-number-or-branch]

Code Review — Risk-Tiered, Exact-Commit PR Review

User-invokable orchestrator for code-PR review across any repo. Three ideas carry it:

  1. Size the review to the risk. What changed, and what reads it, decides how much review a PR gets.
  2. The sign-off comes from an independent reviewer. A model reviewing code its own family wrote shares that family's blind spots. Same-family subagents and Copilot are useful lenses. They are not the sign-off.
  3. Every review is bound to a commit. A review of an older head says nothing about the current one.

(Validation evidence and origin story: README.)

Fallbacks: no gh or not a GitHub repo → review the local diff (git diff <base>...HEAD) and skip the Copilot lane; no subagent tool → run the lenses one after another in the main thread; no second model family available → say so in the summary and report the review as same-family only. Never describe a same-family review as independent.


Invocation: deliberately model-invocable — "review this PR" phrasing is the trigger. Pushes and issue-creation inside the flow are confirmation-gated.

Step 1: Set the Tier

The review target is $ARGUMENTS (a PR number, branch, or URL). If empty, infer it from the conversation or ask.

gh pr view N --json files,additions,deletions,title,headRefOid

Set the tier from what the PR changes and what consumes it, not from the title or the file extension. A mixed PR takes its highest tier. When unsure, go up one.

Tier What changed Review before merge
Docs Prose people read and nothing parses or obeys: notes, plans, reports One reviewer that did not write the diff. Skip the lenses
Parsed text Files a script or an agent reads for meaning: skills, prompts, agent instructions, config, data files One independent reviewer on the exact head. Reread changed files after fixes
Code Executable code, tests, fixtures One independent reviewer on the exact head, plus one lens that matches the risk shape
High-stakes Auth, payments, crypto/wallet, deployment and CI config, dependencies, credential handling, anything that publishes, sends, deploys or spends Two independent reviewers from different routes on the exact head, plus the adversarial and operational lenses

Markdown is not automatically the docs tier. A skill or an instruction file is parsed text: an agent will obey it.

Escalate when the change grants a permission, acts outside the repository, or you cannot rule out that something reads the file.


Step 2: Build One Packet for the Exact Head

Record the head before anything else:

git rev-parse HEAD

Give every reviewer and every lens the same packet:

  1. Repo path (absolute), branch, and the HEAD SHA
  2. The changed-files list from Step 1 and the diff against the base
  3. What the change is meant to do, in one or two sentences, without your own verdict on whether it does
  4. The output contract: finding count first, then findings tagged Critical (blocks merge), Important (fix before merge) or Nit, each with a confidence rating and the file and line. Findings in code the PR did not touch are also marked Pre-existing
  5. A report cap of about 500 words

Keep your conclusions out of the packet. A reviewer handed the author's hypothesis tends to return it confirmed.

Check what the packet contains before it leaves the machine. Send private code only to a model route you are allowed to send it to, and never send credentials. If part of the context cannot go to a reviewer, leave that reviewer out and say so in the summary.


Step 3: Run the Independent Review and the Lenses in Parallel

The independent review. Send the packet to a reviewer from a different model family than the one that wrote the commits. If the PR mixes authors, the reviewer must be outside all of them. Give it read-only access or no tools at all. A reviewer that can edit the branch stops being a reviewer.

A fresh instance of the same family, started with no shared context and no tools, is acceptable for the docs tier only. One way to run it:

claude -p --model <model> --tools "" --setting-sources "" --no-session-persistence < packet.md > review.md

--setting-sources "" keeps your own settings, hooks and MCP servers out of the reviewer's context, so it sees the packet and nothing else. That means the packet has to carry the whole diff. If the diff is too large to fit, give the reviewer read-only tools (read, search, git show at the head) and name them explicitly, because an unspecified tool list usually means every tool.

The lenses. Three angles that empirically work. Pick by risk shape:

  • Adversarial — "Try to break it. What's the worst attack?" Finds security holes, abuse vectors, replay/race conditions, malformed-input handling.
  • Operational — "What fails in production at scale? Latency, cost, observability, timeouts, env config, retries, cold-start?" Finds the architectural misses line-level review cannot see (platform execution limits are the canonical class).
  • Reference-comparison — "Does this match the upstream reference impl exactly? Where does it diverge and why?" Use for third-party SDK / spec integration (Phantom deep-link, Stripe, OAuth providers, RPC clients).

Spawn all chosen subagents in a single tool-call batch so they run in parallel. Prompt templates live in patterns/subagent-prompts.md.

Copilot, when available, covers line-level issues:

gh pr edit N --add-reviewer copilot-pull-request-reviewer

Start everything at once. Do not wait for one verdict before sending the next request.


Step 4: Verify, Then Triage

A finding is a claim. Before it drives a change, open the file at HEAD and confirm it: the input, the expected behavior, the actual behavior, the line responsible. Reviewers describe bugs that were already fixed, misread the diff, and lean on tests that do not test what they say.

Then sort into three buckets:

Real findings — fix now. Push the fix to the PR branch. Pushing changes external state: unless the user already asked you to fix or babysit this PR, confirm before the first push of the session.

Stale re-flags — Copilot will sometimes re-flag findings against unmoved diff lines after fixes ship at HEAD. Always read the file at HEAD before re-fixing. If the fix is already there, drop a one-line reply on the comment ("Fixed at ") and move on. Do not re-fix.

Deferred (filed) — tests, refactors, or work outside scope. File as a GitHub issue (confirm with the user before creating it), link the issue number in the merge commit message, move on. Don't expand the PR.

Real bugs come first and fewer rounds second. Never drop a verified Critical or Important finding to save a round.


Step 5: Keep Reviews Bound to the Commit

Every push moves the head, and a review covers only the head it saw.

  • A small fix that only applies a finding: reread the changed files at the new head. No new round.
  • A structural fix, or new behavior: rerun the affected reviews on the new head.
  • Green tests never refresh a stale review. They answer a different question.
  • A reviewer that implements a fix does not sign off on it. The fix is new code and needs its own reviewer.

Cap Copilot at two rounds. By round 3 its signal-to-noise ratio collapses (about half stale re-flags). The cap applies to Copilot only. The independent review repeats until no verified Critical or Important finding is left on the current head.


Step 6: Record a Receipt

Post one comment on the PR (or include it in your summary when there is no PR) for each completed review:

Review receipt
- Reviewer: <model family and model ID, or "Copilot", or lens name>
- Head: <full SHA the reviewer saw>
- Independent of the authors: yes / no (same family)
- Verdict: clean | changes needed
- Findings: <count by severity>
- Verified against the files: <N of M confirmed>; not reproduced: <list, or "none">
- Not covered: <files or context the reviewer could not see, or "nothing">

A failed, empty or timed-out attempt is not a review. Record it as attempted and do not count it.

Before calling a PR ready, check three things against the current head SHA: the tier's independent review has a receipt for that SHA, no verified Critical or Important finding is open, and the repository's own checks ran on that same SHA. If any of the three names an older commit, the PR is not ready yet.

For the third check, merge-evidence runs a repository's checks on one exact commit and writes a receipt naming the head it tested. Any runner that records the head SHA works.


Step 7: When NOT to Use This Skill

  • Already-merged PRs → use Claude Code's built-in /security-review if you suspect a problem.
  • Docs-tier PRs (per Step 1) → one read by someone who did not write it. Skip the multi-agent overhead.
  • PRs where a paid multi-agent service was already run on the current head → don't double-spend. Check that its review names that head.

Empirical Evidence

Validation case (5 rounds on a high-stakes PR):

  • Copilot caught ~10 real line-level issues (null checks, error handling, type mismatches).
  • Subagents caught what Copilot missed across all 5 rounds:
    • P0: Vercel maxDuration not set — function would time out under realistic load. Architectural miss invisible at the line level.
    • Persistent-replay vector in the auth flow.
    • Transient poll tolerance (no retry budget on flaky upstream).
    • Env-configurable timeout (hardcoded value).
    • Structured logging (string-concat logs, unparseable in production).
    • bodyParser size limit (DoS surface).
  • Round 3+ pattern: Copilot re-flagged the same already-fixed lines. Confirmed the round-2 cap.

Subagents are not redundant with Copilot. They cover a different layer. Neither replaces a reviewer from another model family, which is why the tiers above ask for one.

(P0 in that write-up is what this skill now calls Critical.)


Cross-references

  • patterns/subagent-prompts.md — paste-ready prompt templates for the three angles.