agentleFS
yuefanxiaoyuefanxiao/code-review-adversarial/SKILL.md

code-review-adversarial

Skill4 starsChanged 3 months agoMITView on GitHub

Deep code review via a committee of specialized reviewers with PR-type-aware playbooks and convergence. Feature PRs → evaluate better alternatives; bugfix PRs → verify fix correctness + regression; design-heavy PRs (proto/contract only) → AIP/compatibility audit. Dispatches 2-4 reviewers from distinct stances, converges via collaborative arbiter, outputs structured verdict. Use for high-stakes PRs (concurrency, security, contract changes) or when the user asks for "深度评审", "对抗复核", "adversarial review", or "契约评审".

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. gregwebs/skills-sdlc★ 20same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If $ARGUMENTS is empty, stop and ask the user for a PR number or diff.

    line 48
  2. Very specific:

    Fetch PR metadata: Use your platform's CLI or API (gh pr, tea pr, GitLab API, etc.) → base ref, head ref, title, labels, body, …

    line 60
  3. Very specific:

    NEVER use origin/base...origin/head (three-dot symmetric diff).

    line 77
  4. Distinctive:

    Diff analysis: if existing tests modified (not new test files) → reclassify as feature/bugfix (refactor must not change test behavior)

    line 93
  5. Distinctive:

    Dispatch: Use the Agent tool to launch all selected personas in parallel (multiple tool calls in one message).

    line 123
  6. Very specific:

    Every verdict and finding disposition must be evidence-bound — backed by a file:line citation the coordinator can verify.

    line 199
  7. Distinctive:

    If agent terminated → re-dispatch via Agent tool with coordinator's ruling + conflict summary + code locations as new prompt.

    line 220
  8. Distinctive:

    Convergence complete: when: all surviving findings have a disposition (fix-in-pr / followup / rejected) AND all conflicts are arbitrated …

    line 235
  9. Very specific:

    Never auto-comment to PR: Default format is markdown (return text only).

    line 304
  10. Distinctive:

    Worktree cleanliness: never switch branches on a dirty tree.

    line 307

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

code-review-adversarial

Deep code review engine that dispatches a committee of specialized reviewers, converges their findings, and outputs a structured verdict. PR-type-aware: feature PRs are evaluated for better alternatives; bugfix PRs are evaluated for fix correctness + regression introduction.

Design doc: DESIGN.md (in this skill's directory) — full design rationale, research references, and decision records.

Reference files (loaded on demand):

  • references/type-playbooks.md — per-PR-type review checklists
  • references/reviewer-personas.md — reviewer persona prompt templates
  • references/convergence-protocol.md — convergence and arbitration rules

When to use

  • High-stakes PR: concurrency, security, API/contract changes
  • User explicitly asks for adversarial / multi-agent / deep review
  • Feature PR where solution quality matters (is there a better approach?)
  • Bugfix PR where correctness and regression risk matter

When NOT to use

  • Routine PR quick pass (use a single reviewer)
  • Pure merge/rebase with no logic changes
  • User wants fast feedback, not deep analysis (this is expensive: 2-4 sub-agents)

Arguments

Parse $ARGUMENTS loosely:

  • PR target (required): PR #<N>, #<N>, <N>, or full PR URL (GitHub/GitLab/Gitea).
  • reviewers:<comma-list> — manually specify personas (overrides type-based auto-selection). Accepted tokens: design, correctness, security, root-cause, regression, behavior, test-coverage, perf, devils-advocate.
  • devils-advocate or --devils-advocate — enable devil's advocate persona (high-stakes PRs).
  • max-rounds:<N> — convergence round limit (default: 2).
  • format:<markdown|json|comment> — output mode (default: markdown). comment asks user before posting.
  • pr-type:<type> — manually specify PR type, overrides auto-classification. Accepted: feature, bugfix, refactor, performance, chore, docs, test.

If $ARGUMENTS is empty, stop and ask the user for a PR number or diff.


Workflow

Phase 0: Baseline(基线锁定)

确定 PR 真正改了哪些文件,防止 diff 污染。产出 correct-diff.patch 作为所有 reviewer 的评审基线。Phase 0 不限制 reviewer 能探索哪些文件——那是自由探索(Phase 2)。

基线必须 unpolluted — 如果连评审对象都搞错了,后面所有评审都是空中楼阁。

  1. Fetch PR metadata. Use your platform's CLI or API (gh pr, tea pr, GitLab API, etc.) → base ref, head ref, title, labels, body, changed_files count.
  2. Lock merge-base (critical — prevents diff pollution):
    git fetch origin "$BASE_REF" "$HEAD_REF"
    BASE=$(git merge-base origin/"$BASE_REF" origin/"$HEAD_REF")
  3. Generate correct diff (two-dot, NOT three-dot):
    git diff "$BASE..origin/$HEAD_REF" > /tmp/<pr>/correct-diff.patch
  4. Verify file count matches PR metadata:
    git diff --name-only "$BASE..origin/$HEAD_REF" | wc -l
    # Must match changed_files from the PR metadata. Mismatch → abort, report anomaly.

Hard constraints:

  • NEVER use origin/base...origin/head (three-dot symmetric diff). Use merge-base two-dot only.
  • File count mismatch → abort, report the discrepancy.

Output: correct-diff.patch — the clean review baseline, passed to all reviewers.


Phase 1: PR Type Classification

Goal: Determine PR type → select reviewer personas + load checklist.

Classification (priority descending):

  1. PR labels: contains bug → bugfix; contains feature → feature
  2. Conventional Commits prefix: feat/fix/refactor/perf/chore/docs/test
  3. PR title keywords: "fix"/"修复" → bugfix; "add"/"新增"/"feat" → feature
  4. Diff analysis: if existing tests modified (not new test files) → reclassify as feature/bugfix (refactor must not change test behavior)

Design-heavy detection:

DESIGN_LINES=$(git diff "$BASE..origin/$HEAD_REF" -- '*.proto' '*.md' | grep -cE '^[+-]')
IMPL_LINES=$(git diff "$BASE..origin/$HEAD_REF" -- '*.go' '*.ts' '*.py' '*.java' '*.rs' | grep -cE '^[+-]')
# proto+md 占比 > 70% 且实现代码 < 30% → design-heavy: true

Persona selection: 按类型和 design-heavy 选角色。权威映射表(含 design-heavy override)在 references/reviewer-personas.md 的「角色与 PR 类型的映射速查」章节——读那里,不在这里重复。每个选中的 persona 读 references/personas/<name>.md。

Fallback: unrecognized types → use feature's personas (strictest).

Output: pr_type + design-heavy: bool + selected persona list + loaded checklist from references/type-playbooks.md.


Phase 2: Reviewer Dispatch

Goal: Dispatch persona committee in parallel. Each persona covers one dimension.

Prompt assembly — 固定内容在前,变化内容在后(最大化 prompt cache 命中):

[1. 通用约束]        ← 共享前缀(所有角色相同),from references/reviewer-personas.md
[2. correct-diff.patch]  ← 共享前缀
[3. PR 元数据]       ← 共享前缀(title / description / issue link)
[4. personas/<name>.md]  ← 变化部分,放最后。只读该角色文件

Dispatch: Use the Agent tool to launch all selected personas in parallel (multiple tool calls in one message). Each agent gets:

  • The assembled prompt (通用约束 + diff + 元数据 + 角色专有)
  • correct-diff.patch content as review baseline
  • PR metadata (title, description, issue link if any)
  • Repo path for free exploration

Output schema (each reviewer returns this — 8 fields, enforced):

{
  "persona": "<role-name>",
  "verdict": "ready | ready-with-fixes | not-ready",
  "findings": [
    {
      "severity": "P0|P1|P2|P3",
      "type": "correctness|design|security|root-cause|regression",
      "file": "<path>",
      "line": <N>,
      "issue": "<one-line description>",
      "evidence": "<file:line + reasoning>",
      "confidence": <1-10>
    }
  ],
  "verified_correct": ["<confirmed-correct points>"]
}

in_diff / finding_category etc. are NOT filled by reviewers — Triage Filter (Phase 3) determines them automatically from file paths.


Phase 3: Triage Filter

Goal: Discard invalid findings before convergence. Every surviving finding must be diff-anchored — it either points at a diff line, or proves the diff broke something outside it. Findings that float free of the diff are noise; drop them.

Step 1: Infer component scope

# Infer components from diff file paths
git diff --name-only "$BASE..origin/$HEAD_REF" | \
  sed 's|^\([^/]*\)/.*|\1|' | sort -u
# Example: api bss dashboard
#
# Further细分 (e.g. dashboard → backend / ui):
# api/                          → api
# bss/bss-invoice-service/      → bss-invoice-service
# dashboard/dashboard-backend/  → dashboard-backend

Output: component-scope set (e.g. {api, bss-invoice-service, dashboard-backend}).

Step 2: Apply discard rules

RuleConditionRationale
component out-of-scopefinding's file belongs to a component NOT in component-scopePR semantic boundary — a backend PR doesn't review frontend, regardless of call-chain depth
scope violationfinding's file is outside diff AND finding is an "improvement" type (not "diffusion-impact")Improvement suggestions not allowed on out-of-diff files; diffusion-impact (compile error, interface break) is allowed
no citationfinding has no file:lineCan't locate = invalid
layer violationbugfix PR receives L3 finding ("consider alternatives"); refactor PR receives "add feature"PR type determines allowed layers
already fixedfinding points to code already fixed in this PRStale
implementation-speculation (design-heavy only)finding hypothesizes about implementation behavior that doesn't exist yet (e.g. "this function should handle nil" when there's no implementation)Design-heavy PR has no implementation code; critiquing hypothetical implementation is premature — that's the next PR's job

Two scope rules — the distinction:

  • component out-of-scope: file belongs to a completely unrelated component (backend PR reviewing frontend) → discard regardless of finding type. This is the PR's semantic boundary.
  • scope violation: file is outside diff but within a related component → only discard "improvement" type; keep "diffusion-impact" type. This allows reviewers to catch "the diff broke another file in the same component".

Design-heavy 补充规则: 当 design-heavy: true 时,「implementation-speculation」规则激活——丢弃所有对「尚未存在的实现行为」的推测性 finding。保留契约层 finding(兼容性、命名、字段编号、AIP 合规、错误码完备性)。判据:finding 引用的文件是 .proto/.md/接口定义 → 保留;引用的是 .go/.ts 等实现文件且该文件不在 diff 内(说明实现还没写)→ 丢弃。

Output: surviving findings + discarded findings (with discard reason, for transparency).


Phase 4: Convergence

Goal: Converge multiple reviewers' surviving findings into a consistent verdict.

Every verdict and finding disposition must be evidence-bound — backed by a file:line citation the coordinator can verify. No evidence, no verdict. Load references/convergence-protocol.md for full rules. Summary:

Step 1: Build finding matrix

Group all surviving findings by "same issue" (same file:line + same defect).

Step 2: Converge by group type

Group typeDefinitionAction
independentonly one reviewer reported itaccept directly
intersection2+ reviewers reported same issue, severity agrees (±1)high-confidence accept, take highest severity
conflict2+ reviewers reported same issue, severity disagrees (≥2 levels) or verdict contradictscoordinator must arbitrate

Step 3: Arbitrate conflicts

Coordinator reads code, independently judges. If code facts are insufficient → convergence round (Step 4).

Step 4: Convergence round (if needed)

  1. Prefer SendMessage to wake surviving agents (saves tokens, preserves context).
  2. If agent terminated → re-dispatch via Agent tool with coordinator's ruling + conflict summary + code locations as new prompt.
  3. Send the convergence-round prompt template (from references/convergence-protocol.md).
  4. Guardrails: max 2 rounds (default). Check stability after each round. Unresolved at limit → label "unresolved", list both sides, don't force-merge.

Step 5: Determine verdict

Count surviving findings (post-Triage + post-Convergence):

has P0              → not-ready
has P1, no P0       → ready-with-fixes
only P2/P3          → ready-with-fixes
no findings         → ready

Convergence complete when: all surviving findings have a disposition (fix-in-pr / followup / rejected) AND all conflicts are arbitrated AND unresolved disagreements (if any) are explicitly labeled.


Output

Based on format argument:

format: markdown (default)

产出评审报告的 markdown 文本,返回给调用方。不自动发 PR comment。 如果调用方想把报告发到 PR,由调用方决定,或用 AskUserQuestion 询问用户后再发。

format: json

Return structured JSON to the caller (no PR comment posted):

{
  "pr_type": "<type>",
  "verdict": "<ready|ready-with-fixes|not-ready>",
  "reviewers": [{"persona": "...", "verdict": "...", "findings_count": N}],
  "findings": [
    {
      "id": "F1",
      "severity": "P1",
      "type": "root-cause",
      "persona": "root-cause-auditor",
      "file": "...",
      "line": N,
      "issue": "...",
      "disposition": "fix-in-pr|followup|rejected",
      "consensus": "independent|intersection|arbiter-ruled|unresolved",
      "confidence": N
    }
  ],
  "triage": {"discarded": [{"reason": "...", "detail": "..."}]},
  "convergence": {"rounds": N, "conflicts_resolved": N, "unresolved": []}
}

format: comment

产出精简 markdown 并询问用户确认后再发 PR comment。绝不自动发布。

硬约束: 必须先用 AskUserQuestion 询问用户「是否将评审报告发布到 PR?」,用户确认后才发。用户拒绝则只返回报告文本。

报告模板(精简版,只含决策必需信息):

## 对抗评审报告

**Verdict**: <ready/ready-with-fixes/not-ready>(PR 类型: <type>,置信度: <high/medium/low>)

### Finding 表
| # | 严重度 | 位置 | 问题 | 处理 |
|---|--------|------|------|------|

(如有 P0/P1 冲突仲裁)
- <finding> → <裁决>:<一句话理由>

(如仅 P2/P3)
> 残留 <N> 项 P2/P3(<类型>),建议 follow-up 跟踪,不阻塞合入。

Safety rules

  • Never auto-comment to PR. Default format is markdown (return text only). Even in format: comment mode, you MUST ask the user via AskUserQuestion before posting. The user says no → return text only.
  • Do not merge unless the user explicitly asks AND verdict is ready/ready-with-fixes AND all blocking findings are addressed.
  • Do not push fixes to someone else's PR.
  • Worktree cleanliness: never switch branches on a dirty tree.
  • Diff baseline integrity: Phase 0's merge-base lock is non-negotiable. If you can't verify the file count, stop and report.

Parameters

ParameterDefaultDescription
reviewersauto by PR typeManually specify personas (e.g. reviewers:design,security)
devils-advocateoffEnable devil's advocate (high-stakes PRs)
max-rounds2Convergence round limit
formatmarkdownOutput: markdown (text only, default) / json (structured return) / comment (ask user before posting to PR)
pr-typeauto-classifyManually specify PR type (overrides auto)

Design rationale

Full design decisions and research references: see DESIGN.md §2 (in this skill's directory).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.