archie-code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode review
代码审查
Two-axis review of one Task's diff:
- Spec — does the code faithfully implement the leaf's and the Task's acceptance criteria?
spec.md - Standards — does it follow the repo's conventions, cover its units the way the framework requires, and stay clear of the smell baseline?
Both axes run as parallel sub-agents so they do not pollute each other's context, and this skill aggregates what they return. A change can pass one and fail the other, so the two are never merged.
You find; the engineer fixes. Every finding travels back as text and the working tree leaves this run exactly as it arrived — a reviewer who fixes has reviewed its own code by the time it reports.
通过两个维度审查单个任务的代码差异:
- 规范维度 — 代码是否忠实地实现了分支的文件及任务的验收标准?
spec.md - 标准维度 — 代码是否遵循仓库约定、按照框架要求覆盖单元测试,且未触及代码异味基准?
两个维度由并行子Agent分别执行,避免互相干扰上下文,本技能会汇总它们的返回结果。代码变更可能通过其中一个维度但未通过另一个,因此两个维度的结果永远不会合并。
你负责发现问题;工程师负责修复。所有发现结果以文本形式反馈,工作目录在本次审查结束后与初始状态完全一致——若审查者自行修复问题,那么在提交报告时相当于审查了自己编写的代码。
1. Fix the diff
1. 修复代码差异
You are handed a Task reference () or its path, and the run's baseline SHA. The reference resolves down the numbered directories under : is child of child of the root, is inside it, and the leaf's sits beside the folder.
3.2#1.archie/3.20203#1tasks/01-<slug>.mdspec.mdtasks/The diff is plus the untracked files lists. Confirm the baseline resolves and the diff is non-empty before going further: a bad ref or an empty diff should fail here, not inside two parallel sub-agents.
git diff <baseline>git status --porcelain你会收到任务引用(如)或其路径,以及本次运行的基准SHA。任务引用可通过下的编号目录解析:对应根目录下子目录中的子目录,对应其中的文件,分支的文件位于文件夹旁。
3.2#1.archie/3.20302#1tasks/01-<slug>.mdspec.mdtasks/代码差异为的输出,加上列出的未跟踪文件。在继续操作前需确认基准SHA有效且代码差异非空:无效引用或空差异应在此环节直接终止,而非进入两个并行子Agent。
git diff <baseline>git status --porcelain2. Find the standards files
2. 查找标准文件
The Spec axis already knows its two documents: the task file and the leaf's , which are the only contracts. The Standards axis needs whatever this repo documents about how code is written — , , , a coding-standards file — so find those, and carry the step 3 rule sets whether or not any exist.
spec.mdAGENTS.mdCLAUDE.mdCONTRIBUTING.md规范维度已明确其参考的两份文档:任务文件和分支的,这是仅有的依据。标准维度需要仓库中所有关于代码编写规范的文档——如、、或编码标准文件——需找到这些文件,无论是否存在,都需携带步骤3中的规则集。
spec.mdAGENTS.mdCLAUDE.mdCONTRIBUTING.md3. The two rule sets the Standards axis always carries
3. 标准维度始终携带的两套规则
These hold even in a repo that documents nothing, so they are pasted into the Standards sub-agent's prompt in full — it has no other access to them.
即使仓库中没有任何文档,这些规则依然适用,因此会完整粘贴到标准子Agent的提示词中——子Agent无法通过其他途径获取这些规则。
The test rules
测试规则
- One integration test, at the Spec's seam. A test parked at a lower or more convenient seam — a helper, an internal function, a place that was simply easier to wire — is a finding even when it passes.
- Every unit the diff modified has a unit test. A unit merely read is out of scope; pulling it in metastasises the suite.
- Each unit test asserts behaviour at its unit's boundary — what it returns, what it emits, what it calls on its collaborators. Apply the rename test: a test that would break when a symbol is renamed or a helper extracted is testing implementation, and it is rejected. Assertions on private state, call counts of internal helpers, and snapshots of internal shape fail the same way.
- 在规范的边界处编写一个集成测试。若测试位于更低层级或更便捷的边界(如辅助函数、内部函数,或仅为便于连接的位置),即使测试通过,也会被视为问题。
- 代码差异中修改的每个单元都应有对应的单元测试。仅被读取的单元不在范围内;将其纳入测试会导致测试套件范围不必要地扩大。
- 每个单元测试需断言单元边界的行为——即单元的返回值、输出内容,以及对协作对象的调用。应用重命名测试法:若重命名符号或提取辅助函数会导致测试失败,则该测试是对实现细节的测试,应被拒绝。对私有状态的断言、对内部辅助函数调用次数的断言,以及对内部结构的快照断言均不符合要求。
The smell baseline
代码异味基准
Twelve smells from Fowler's Refactoring, ch. 3, stated in full below. Two rules bind them:
- The repo and the Spec override. Where either endorses the shape a smell would flag, suppress it — they are the authority, this list is the backstop.
- Always a judgement call, labelled as one ("possible Feature Envy") rather than reported as a breach, and never blocking. Skip anything the repo's lint and typecheck already enforce — the gates ran before this review.
Each reads what it is → how to fix:
- Mysterious Name — a function, variable or type whose name does not reveal what it does or holds. → rename it; if no honest name comes, the design is murky.
- Duplicated Code — the same logic shape in more than one hunk or file of this diff. → extract the shape, call it from both.
- Feature Envy — a method reaching 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 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 or
switch-cascade on the same type recurring across the change. → replace with polymorphism, or one map both sites share.if - Shotgun Surgery — one logical change forcing scattered edits across many files in the diff. → gather what changes together into one module.
- Divergent Change — one file edited for several unrelated reasons. → split so each module changes for one reason.
- Speculative Generality — abstraction, parameters or hooks added for needs the Task does not have. → delete it; inline back until a real need shows.
- Message Chains — long navigation the caller should not depend on. → hide the walk behind one method on the first object.
a.b().c().d() - Middle Man — a class or function that mostly delegates onward. → cut it, call the real target direct.
- Refused Bequest — a subclass or implementer ignoring or overriding most of what it inherits. → drop the inheritance, use composition.
以下是Fowler所著《重构》第3章中的12种代码异味,完整描述如下。需遵循两条规则:
- 仓库约定和规范优先。若仓库约定或规范认可某代码异味所标记的代码形式,则忽略该异味——仓库约定和规范是权威,此列表仅作为兜底。
- 始终需主观判断,标记为“疑似XX异味”而非直接判定为违规,且永远不会阻止流程。跳过仓库的代码检查工具(lint)和类型检查已强制执行的内容——这些检查在本次审查前已完成。
每种异味包含定义 → 修复方案:
- 神秘命名 — 函数、变量或类型的名称无法清晰表明其功能或用途。 → 重命名;若无法找到准确的名称,则说明设计存在模糊性。
- 重复代码 — 代码差异的多个代码块或文件中存在相同的逻辑结构。 → 提取该结构,在两处调用。
- 特性依恋 — 某个方法对另一个对象的数据访问远多于对自身数据的访问。 → 将该方法移至其所依恋的数据所属的对象中。
- 数据泥团 — 相同的几个字段或参数频繁一起出现,意味着需要创建一个新类型。 → 将它们打包为一个类型,传递该类型。
- 基本类型偏执 — 使用基本类型或字符串代替应拥有独立类型的领域概念。 → 为该概念创建一个小型独立类型。
- 重复的分支判断 — 代码变更中多次出现针对同一类型的相同或
switch分支判断。 → 用多态替换,或使用一个双方共享的映射表。if - 霰弹式修改 — 一个逻辑变更需要在代码差异的多个文件中进行零散修改。 → 将需要修改的内容集中到一个模块中。
- 发散式修改 — 一个文件因多个不相关的原因被修改。 → 拆分文件,使每个模块仅因一个原因变更。
- 臆想性通用性 — 为任务不需要的需求添加了抽象、参数或钩子。 → 删除这些内容;将其内联,直到出现真实需求。
- 消息链 — 过长的链式调用,调用者不应依赖此类导航。 → 在第一个对象后隐藏链式调用,提供一个方法封装。
a.b().c().d() - 中间人 — 某个类或函数主要负责转发调用。 → 移除该类/函数,直接调用真实目标。
- 拒绝继承 — 子类或实现类忽略或重写了其继承的大部分内容。 → 放弃继承,使用组合模式。
4. Dispatch both sub-agents in parallel
4. 并行调度两个子Agent
The Spec sub-agent's prompt carries the diff command, the path to the task file and the path to , and this brief:
spec.mdReport: (a) acceptance criteria or Spec requirements that are missing or only partly built; (b) behaviour in the diff nobody asked for — scope creep, or work reaching into another Task's territory; (c) requirements that look built but where the implementation looks wrong. Quote the criterion or the Spec line behind each finding, and name the file and line. The task file and theare the contracts, so judge against what they say rather than against anything you infer from elsewhere in the repo. Where a criterion is too ambiguous to judge, say so as a finding and give the reading you reviewed against. Under 400 words.spec.md
The Standards sub-agent's prompt carries the diff command, the standards files you found, and both rule sets from step 3 pasted in full, and this brief:
Report, per file or hunk: (a) every place the diff breaks a documented repo standard, citing the file and the rule; (b) every place it breaks one of the test rules; (c) any baseline smell you spot, named, quoting the hunk. Documented standards and the test rules can be hard findings; baseline smells are always judgement calls, and a documented repo standard overrides the baseline. Skip anything the repo's tooling enforces. Under 400 words.
规范子Agent的提示词包含代码差异命令、任务文件路径、路径,以及以下简要说明:
spec.md报告内容需包含:(a) 缺失或仅部分实现的验收标准或规范要求;(b) 代码差异中存在的未被要求的行为——范围蔓延,或涉及其他任务的工作;(c) 看似已实现但存在错误的需求。每个发现需引用对应的验收标准或规范内容,并注明文件及行号。任务文件和是唯一依据,需根据其内容判断,而非从仓库其他部分推断。若某标准过于模糊无法判断,需将其列为发现,并说明你审查时采用的解读方式。报告字数不超过400字。spec.md
标准子Agent的提示词包含代码差异命令、找到的标准文件,以及步骤3中完整粘贴的两套规则,以及以下简要说明:
按文件或代码块报告:(a) 代码差异中违反仓库已记录标准的所有位置,需引用文件及规则;(b) 违反测试规则的所有位置;(c) 你发现的任何基准代码异味,需命名并引用代码块。已记录的仓库标准和测试规则可作为明确问题;基准代码异味始终为主观判断,且已记录的仓库标准优先于基准。跳过仓库工具已强制执行的内容。报告字数不超过400字。
5. Aggregate
5. 汇总结果
md
_Reviewed:_ {Task reference} — {Task title}md
_审查对象:_ {Task reference} — {Task title}Spec
规范维度
{the Spec sub-agent's report, verbatim or lightly cleaned}
{规范子Agent的报告,原文或稍作整理}
Standards
标准维度
{the Standards sub-agent's report, verbatim or lightly cleaned}
Findings: {N} on Spec, {N} on Standards — worst on each axis: {…} / {…}
**Report the axes separately, in their own order.** One merged ranking lets a clean Standards report bury a missing requirement, or a pile of smells bury a Spec that is fully met. Name the worst finding *within* each axis and pick no winner between them.{标准子Agent的报告,原文或稍作整理}
发现问题数: 规范维度{N}个,标准维度{N}个 — 各维度最严重问题:{…} / {…}
**需分别报告两个维度的结果,保持各自顺序**。合并排名可能导致规范维度缺失需求的问题被标准维度的良好报告掩盖,或规范维度完全符合要求的情况被大量代码异味掩盖。需列出每个维度内最严重的问题,不得在两个维度间分出优劣。