code-review
固定起点和 HEAD 之间的双轴审查:
- Standards:代码是否符合这个仓库记录的编码规范?
- Spec:代码是否符合最初 issue 或规格的要求?
两个轴由并行子代理分别审查,避免互相影响上下文;之后由本 skill 汇总结果。每个子代理都要从全新的上下文窗口开始。
issue 跟踪工具的说明应该已经提供给你。如果没有,告诉读者运行 /setup-matt-pocock-skills。
1. 固定起点
Section titled “1. 固定起点”用户指定的内容就是固定起点,可以是提交 SHA、分支名、标签、main、HEAD~5 等。如果用户没指定,就询问。
记录一次 diff 命令:git diff <fixed-point>...HEAD。三个点表示以合并基点为比较起点。也记录提交列表:git log <fixed-point>..HEAD --oneline。
继续之前,确认这个引用能解析(git rev-parse <fixed-point>),而且 diff 不为空。引用错误或 diff 为空,都应在这里报错,不要等到启动两个并行子代理后才发现。
2. 找到规格来源
Section titled “2. 找到规格来源”按以下顺序查找最初的规格:
- 从提交信息里的 issue 引用开始查找(例如
#123、Closes #45、GitLab!67),并通过跟踪文档中的流程获取内容。 - 用户传入的路径。
- 在
docs/、specs/或.scratch/下,查找与分支名或功能匹配的规格文件。 - 如果都没找到,就询问用户在哪里能找到规格。如果用户说没有规格,Spec 子代理会跳过审查并报告「no spec available」。
3. 找到规范来源
Section titled “3. 找到规范来源”在仓库中搜索所有说明代码编写规范的文件。如果有 CODING_STANDARDS.md 或 CONTRIBUTING.md,必须将它们列入清单。
除了仓库文档,Standards 轴还要应用下面这组固定的 Fowler 代码异味基线,来自《重构》第 3 章。适用以下两条规则:
- 仓库规范优先。文档化的仓库规范始终优先。如果它认可某种做法,就不要按基线把它标为异味。
- 始终是判断意见。每种异味都是带标签的启发式判断(例如「可能是 Feature Envy」),不是硬性违规。和其他规范一样,工具已强制执行的内容就跳过。
逐项检查 diff,并按照「是什么 → 如何修复」来判断:
- Mysterious Name:函数、变量或类型的名称无法说明它的用途或内容。→ 给它改名;如果找不到恰当名称,说明设计还不清晰。
- Duplicated Code:改动中的多个代码块或文件出现相同的逻辑结构。→ 提取共用逻辑,让两处都调用它。
- Feature Envy:某个方法读取另一个对象的数据,远多于自己的数据。→ 把方法移到它依赖的数据所在对象上。
- Data Clumps:相同的几个字段或参数总是一起传递,像是在等待组成一个类型。→ 把它们封装成一个类型,再传递这个类型。
- Primitive Obsession:用基本类型或字符串表示本该有独立类型的领域概念。→ 为这个概念定义一个小类型。
- Repeated Switches:改动中多次出现针对同一类型的相同
switch或if链。→ 换成多态,或让两处共用一张映射表。 - Shotgun Surgery:一个逻辑改动迫使 diff 中多个文件散落着改动。→ 把相关改动集中到一个模块。
- Divergent Change:一个文件或模块因为多个不相关的原因而被修改。→ 拆开,让每个模块只为一个原因而变化。
- Speculative Generality:添加的抽象、参数或钩子并非规格所需。→ 删除它们,改回内联,直到确实有需要。
- Message Chains:
a.b().c().d()这样冗长的连续调用,让调用方依赖了过多细节。→ 在第一个对象上提供一个方法,把这段调用隐藏起来。 - Middle Man:某个类或函数基本只负责转交调用。→ 删除它,直接调用真正的目标。
- Refused Bequest:子类或实现类忽略或重写了继承的大部分内容。→ 去掉继承,改用组合。
4. 并行启动两个子代理
Section titled “4. 并行启动两个子代理”同时在前台发起两个子代理调用,并汇总它们返回的报告。
Standards 子代理的提示词应包含:
- 完整的 diff 命令和提交列表。
- 第 3 步找到的规范文件列表,以及完整粘贴的第 3 步异味基线(子代理无法获取其他位置的内容)。
- 任务说明:「按相关文件或代码块报告:(a) 每一处违反文档规范的地方,并指出规范文件和规则;(b) 发现的任何基线异味,并引用代码块。区分硬性违规和判断意见:违反文档规范可以是硬性违规,基线异味始终只是判断意见;文档化的仓库规范优先。跳过工具已强制执行的内容。400 词以内。」
Spec 子代理的提示词应包含:
- diff 命令和提交列表。
- 规格路径或获取到的规格内容。
- 任务说明:「报告:(a) 规格要求中缺失或只完成一部分的内容;(b) 改动中未经要求的行为(范围蔓延);(c) 看似已实现、但实现可能有误的要求。每条发现都引用相应的规格原文。400 词以内。」
如果找不到规格,就跳过 Spec 子代理,并在最终报告中说明。
分别用 ## Standards 和 ## Spec 作为标题,呈现两份报告,可以原样引用,也可以稍作整理。不要合并或重新排序发现,因为这两个轴刻意保持独立(见「为什么分成两个轴」)。
最后用一行总结每个轴发现的总数,以及各轴最严重的问题(如果有)。不要在两个轴之间选出一个总冠军,那会破坏分轴审查的目的。
为什么分成两个轴
Section titled “为什么分成两个轴”一项改动可能在一个轴上通过,在另一个轴上失败:
- 代码遵守所有规范,却实现错了东西:Standards 通过,Spec 失败。
- 代码准确实现了 issue 的要求,却违反仓库约定:Spec 通过,Standards 失败。
分开报告,可以避免一个轴的通过掩盖另一个轴的问题。
原文链接和 commit
Section titled “原文链接和 commit”读者可以点名用它,模型也可以自己调用它。它在 Claude Code 插件里。
沿固定起点审查 diff,分别检查仓库规范和规格符合度,再汇总两份独立报告。
Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes: Standards (does the code follow this repo's documented coding standards?) and Spec (does the code match what the originating issue/spec asked for?). Runs both reviews in parallel sub-agents and reports them side by side. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to "review since X".- 仓库 mattpocock/skills
- 文件
skills/engineering/code-review/SKILL.md - 提交
d81f3a1 - 说明页
docs/engineering/code-review.md - 同目录文件
skills/engineering/code-review/agents/openai.yaml
英文 SKILL.md
---name: code-reviewdescription: "Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes: Standards (does the code follow this repo's documented coding standards?) and Spec (does the code match what the originating issue/spec asked for?). Runs both reviews in parallel sub-agents and reports them side by side. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to \"review since X\"."---
Two-axis review of the diff between `HEAD` and a fixed point the user supplies:
- **Standards**: does the code conform to this repo's documented coding standards?- **Spec**: does the code faithfully implement the originating issue / spec?
Both axes run as **parallel sub-agents** so they don't pollute each other's context, then this skill aggregates their findings. Start every sub-agent with a fresh context window.
The issue tracker should have been provided to you. If not, tell the user to run `/setup-matt-pocock-skills`.
## Process
### 1. Pin the fixed point
Whatever the user said is the fixed point (a commit SHA, branch name, tag, `main`, `HEAD~5`, etc.). If they didn't specify one, ask for it.
Capture the diff command once: `git diff <fixed-point>...HEAD` (three-dot, so the comparison is against the merge-base). Also note the list of commits via `git log <fixed-point>..HEAD --oneline`.
Before going further, confirm the fixed point resolves (`git rev-parse <fixed-point>`) and the diff is non-empty. A bad ref or empty diff should fail here, not inside two parallel sub-agents.
### 2. Identify the spec source
Look for the originating spec, in this order:
1. Issue references in the commit messages (`#123`, `Closes #45`, GitLab `!67`, etc.), fetched via the workflow in the tracker doc.2. A path the user passed as an argument.3. A spec file under `docs/`, `specs/`, or `.scratch/` matching the branch name or feature.4. If nothing is found, ask the user where the spec is. If they say there isn't one, the **Spec** sub-agent will skip and report "no spec available".
### 3. Identify the standards sources
Search the repo for every file that documents how code should be written. When `CODING_STANDARDS.md` or `CONTRIBUTING.md` exists, it must be on the list.
On top of whatever the repo documents, the Standards axis always carries the **smell baseline** below: a fixed set of Fowler code smells (_Refactoring_, ch.3) that applies even when a repo documents nothing. Two rules bind it:
- **The repo overrides.** A documented repo standard always wins; where it endorses something the baseline would flag, suppress the smell.- **Always a judgement call.** Each smell is a labelled heuristic ("possible Feature Envy"), never a hard violation. Like any standard here, skip anything tooling already enforces.
Each smell reads *what it is* → *how to fix*; match it against the diff:
- **Mysterious Name**: a function, variable, or type whose name doesn't reveal what it does or holds. → rename it; if no honest name comes, the design's murky.- **Duplicated Code**: the same logic shape appears in more than one hunk or file in the change. → extract the shared shape, call it from both.- **Feature Envy**: a method that reaches into another object's data more than its own. → move the method onto the data it envies.- **Data Clumps**: the same few fields or params keep travelling together (a type wanting to be born). → bundle them into one type, pass that.- **Primitive Obsession**: a primitive or string standing in for a domain concept that deserves its own type. → give the concept its own small type.- **Repeated Switches**: the same `switch`/`if`-cascade on the same type recurs across the change. → replace with polymorphism, or one map both sites share.- **Shotgun Surgery**: one logical change forces scattered edits across many files in the diff. → gather what changes together into one module.- **Divergent Change**: one file or module is edited for several unrelated reasons. → split so each module changes for one reason.- **Speculative Generality**: abstraction, parameters, or hooks added for needs the spec doesn't have. → delete it; inline back until a real need shows.- **Message Chains**: long `a.b().c().d()` navigation the caller shouldn't depend on. → hide the walk behind one method on the first object.- **Middle Man**: a class or function that mostly just delegates onward. → cut it, call the real target direct.- **Refused Bequest**: a subclass or implementer that ignores or overrides most of what it inherits. → drop the inheritance, use composition.
### 4. Spawn both sub-agents in parallel
Issue both sub-agent calls together, in the foreground, and aggregate the reports they return.
**Standards sub-agent prompt** should include:
- The full diff command and commit list.- The list of standards-source files you found in step 3, **plus the smell baseline from step 3** pasted in full (the sub-agent has no other access to it).- The brief: "Report, per file/hunk where relevant, (a) every place the diff violates a documented standard: cite the standard (file + the rule); and (b) any baseline smell you spot: name it and quote the hunk. Distinguish hard violations from judgement calls: documented-standard breaches can be hard, but baseline smells are always judgement calls, and a documented repo standard overrides the baseline. Skip anything tooling enforces. Under 400 words."
**Spec sub-agent prompt** should include:
- The diff command and commit list.- The path or fetched contents of the spec.- The brief: "Report: (a) requirements the spec asked for that are missing or partial; (b) behaviour in the diff that wasn't asked for (scope creep); (c) requirements that look implemented but where the implementation looks wrong. Quote the spec line for each finding. Under 400 words."
If the spec is missing, skip the Spec sub-agent and note this in the final report.
### 5. Aggregate
Present the two reports under `## Standards` and `## Spec` headings, verbatim or lightly cleaned. Do **not** merge or rerank findings, because the two axes are deliberately separate (see _Why two axes_).
End with a one-line summary: total findings per axis, and the worst issue _within each axis_ (if any). Don't pick a single winner across axes: that's the reranking the separation exists to prevent.
## Why two axes
A change can pass one axis and fail the other:
- Code that follows every standard but implements the wrong thing → **Standards pass, Spec fail.**- Code that does exactly what the issue asked but breaks the project's conventions → **Spec pass, Standards fail.**
Reporting them separately stops one axis from masking the other.非官方学习站,与 Matt Pocock 和 AI Hero 没有隶属关系。本站不提供可安装的中文技能包。
技能原文采用 MIT 许可。Copyright (c) 2026 Matt Pocock