定向代码审查
targeted-review
发现驱动的定向代码审查。通过 patch-explainer 理解补丁,通过 codebase-analysis 理解周边代码,然后查阅 bug 模式目录(references/categories/ 下约 11 个类别)。仅挑选 diff 信号与补丁匹配的类别,以及“look for”提示与实际代码形态匹配的条目,按审查重点(函数/文件/特性)分组,并生成并行子代理——每个子代理都有紧凑的范围和经过挑选的清单。适用于中大型补丁(50-1000 行代码),可作为整补丁集成式审查或整文件深度审查的聚焦替代方案。触发条件包括:“review this patch/diff/change”、“find bugs in this change”、“scoped review”、“what could go wrong here”、“review using findings”,或主动进行 PR 审查。
- License 许可
- Apache-2.0
- 所属仓库
- apache/cassandra
- 最近更新
- 2026-11-14
- Stars
- ★ 1.0w
- Forks
- 4.1k
01 前言 Front Matter
- name
- targeted-review
- version
- 1.0.0
- description
- Findings-driven targeted code review. Understands the patch via patch-explainer and surrounding code via codebase-analysis, then consults a catalog of bug patterns (~11 categories under references/categories/). Picks only categories whose diff-signals match the patch and items whose "look for" hints match actual code shapes, groups them by review focus (function/file/feature), and spawns parallel subagents — each with a tight scope and selective checklist. Use for medium-to-large patches (50-1000 LOC) as a focused alternative to whole-patch ensemble or whole-file deep review. Triggers on: "review this patch/diff/change", "find bugs in this change", "scoped review", "what could go wrong here", "review using findings", or proactive PR review.
02 资源文件 14
- 参考文档references/categories/api-contracts-and-completeness.md22.3 KB
- 参考文档references/categories/boundaries-and-numbers.md20.7 KB
- 参考文档references/categories/concurrency-and-locking.md17.0 KB
- 参考文档references/categories/conditions-and-predicates.md17.9 KB
- 参考文档references/categories/INDEX.md17.2 KB
- 参考文档references/categories/io-and-crash-safety.md13.3 KB
- 参考文档references/categories/lifecycle-and-ordering.md19.3 KB
- 参考文档references/categories/null-and-type-safety.md15.7 KB
- 参考文档references/categories/refactor-aftermath.md12.3 KB
- 参考文档references/categories/serialization-and-versioning.md18.2 KB
- 参考文档references/categories/state-and-resource-cleanup.md16.6 KB
- 参考文档references/categories/validation-and-input-handling.md18.2 KB
- 参考文档references/report-format.md3.9 KB
- 参考文档references/subagent-prompt-template.md4.6 KB
03 SKILL.md 正文
Targeted Review
A meta-review skill. It does not encode bug patterns directly — it orchestrates other skills and a categorized findings catalog into a tight, evidence-driven review.
What it does
+------------------+
| Input patch |
+--------+---------+
|
+-----------+-----------+
| |
+---------v---------+ +---------v-----------+
| patch-explainer | | codebase-analysis |
| (sub-skill) | | (sub-skill, scoped) |
| what changed, | | invariants, callers,|
| flow, assumptions | | parallel paths |
+---------+---------+ +---------+-----------+
| |
+-----------+-----------+
|
+---------------v----------------+
| Pick categories + items |
| × 3-5 independent iterations |
| (each draw surfaces different |
| items from the same catalog) |
+---------------+----------------+
|
+--------v---------+
| Pool & prioritize|
| (items from 2+ |
| iterations → |
| higher priority)|
+--------+---------+
|
+--------v---------+
| Group items by |
| review focus |
| (file/func/feat) |
+--------+---------+
|
+------------+------------+
| | |
+-------v---+ +-----v-----+ +---v-------+
| review | | review | | review |
| subagent | | subagent | | subagent |
| scope A | | scope B | | scope C |
+-------+---+ +-----+-----+ +---+-------+
| | |
+------------+------------+
|
+--------v---------+
| Merge & report |
+------------------+
When to use this skill
- A patch or diff is on the table for review (single commit, multi-commit branch, or staged changes)
- The user wants more focus than
shallow-reviewprovides (six fixed lenses on the whole patch) but doesn't want to commit todeep-review's file-by-file deep pass - A
*-findings/corpus exists or the categorized catalog underreferences/categories/is sufficient — the categories alone are usable; project corpora improve coverage - Medium-to-large patches where dispatching focused subagents avoids overwhelming a single reviewer
When NOT to use this skill
- Trivial 1-3 line changes — direct review is faster
- Pure refactors with no behavior change —
shallow-reviewsymmetry pass is enough - The user wants a single comprehensive write-up of one file — use
deep-reviewinstead
Workflow
You will go through seven phases. Phases 1a and 1b run in parallel. Phases 2-6 are sequential.
Phase 1a: Understand the patch — call the patch-explainer skill
Invoke the patch-explainer skill on the patch. Use the Skill tool. You want patch-explainer
to produce its standard analysis (purpose, before/after diagrams, flow, assumptions,
failure modes).
If the patch is already provided as a file path, point patch-explainer at it. If you only
have a commit ref, ask for git show <ref> or read it from git diff. For multi-commit
branches, it is fine to feed the cumulative diff.
Capture patch-explainer's full output. You will refer to it in Phases 3-5.
Phase 1b: Understand the surroundings — call the codebase-analysis skill
In parallel with 1a, invoke the codebase-analysis skill in targeted mode on the
affected subsystem only — not the whole repo. Pass it:
- The list of files touched by the patch
- The subsystem name if obvious (e.g., "the journal replay subsystem")
- A directive to focus on: invariants, lifecycle, parallel implementations, and recent bug history in the affected area
You want codebase-analysis to produce a scoped analysis/system-analysis.md that gives
you the context the patch sits inside — what the surrounding code expects, where parallel
paths exist, what historical bugs touched this area.
If invoking the full skill is too heavy for a small patch, instead spawn a research subagent with this prompt: "Read these files: {touched files}. Summarize: (a) the invariants the surrounding code maintains, (b) any parallel implementations or sibling classes, (c) callers of the modified methods, (d) any recent bug-fix commits in this area. Under 400 words." This is a lighter alternative that retains the spirit of codebase-analysis. Prefer the full skill when the area is unfamiliar or large.
Phase 2: Pick categories — 3-5 independent iterations
Category selection and item picking are speculative: you're making probabilistic judgments about which patterns might apply, and a single pass will reliably miss some. Run 3-5 independent iterations of Phases 2+3, each starting from scratch with the same patch and context but without looking back at what prior iterations chose. Treat each iteration like a fresh read — you are more likely to notice different things each time.
For each iteration, read references/categories/INDEX.md — it lists all 11 categories
with their descriptions and diff signals in one file (~200 lines). For each category, ask:
does the patch contain ANY of the diff signals listed?
- If yes → mark as load
- If no → skip
Typically 3-7 categories load per iteration. If you would load more than 8, re-examine. If fewer than 2, the patch is probably too small for this skill.
Phase 3: Pick items within each loaded category (one pass per iteration)
Within each iteration, read the full content of each loaded category file. For each
finding (### F-NN: title + body + **Look for:** {hint}), ask:
- Does the "Look for" hint match a code shape that actually appears in this patch?
- Does the patch context (from patch-explainer + codebase-analysis) make this finding plausibly applicable — not just a keyword match?
If yes to both → keep the item. If no → drop.
Be selective: a category typically has 25-40 findings; keep 3-12 per category per iteration. Repeat for all iterations before moving to Phase 3b.
Phase 3b: Pool and prioritize across iterations
After all iterations are complete, merge the item lists:
- An item selected in 2 or more iterations is a strong candidate — mark it priority.
- An item selected in only one iteration is still in scope — mark it speculative.
- Discard nothing yet; let the subagents decide.
The iteration count next to an item is a confidence signal for the subagents, not a gate. A speculative item can still turn into a real bug; a priority item can still be a false alarm.
Phase 4: Group items by review focus
Now you have a pooled list of selected items across categories and iterations. Group them by review focus — what part of the change a single reviewer should examine. A focus is one of:
- A specific function or method (
MyClass.replay()) - A specific file or small group (
FooSerializer.javaand its siblingFooDeserializer.java) - A feature, behavior, or concept ("the new fsync coordination", "the version-gated dispatch path")
- A specific cross-cutting concern in the patch ("any place we read the new
dirtyflag")
Aim for 2-5 foci per patch. Each focus should have 5-15 checklist items drawn from across the categories — not too few (subagent has nothing to do) and not too many (subagent gets overwhelmed). Include each item's priority annotation (priority / speculative) so the subagent knows where to focus first.
If multiple foci would receive the same checklist item, that's fine — the same pattern can apply at multiple sites. Tag each item with the category it came from so the subagent knows the rationale.
Phase 5: Spawn focused review subagents
For each focus, spawn one review subagent in parallel using the Agent tool. Use the
template in references/subagent-prompt-template.md. The subagent prompt must contain:
- The patch (path, or pasted, or ref)
- A 100-word summary of patch-explainer's findings (relevant slice only — not the full output)
- A 100-word summary of codebase-analysis's findings (relevant slice only)
- The focus statement (what part of the change to review)
- The checklist items, each with: category, priority annotation, finding text, and look-for hint
- Instructions on how to gather evidence (read source, grep, check parallel paths) and what confidence to assign
Each subagent should produce: a list of findings, with location, confidence, and what evidence was checked.
Run all subagents in a single tool call (parallel). They are independent.
Phase 6: Merge and report
When all subagents return, merge findings:
- Deduplicate — same code location + similar reasoning → one finding, both subagents credited
- Rank by confidence — High first, then Medium, then Low
- Cross-reinforce — if a finding was raised by multiple subagents, or if multiple findings cluster on the same lifecycle/state, boost confidence
- Three-point check each surviving finding:
- The code construct actually exists in the diff (not inferred from absence alone)
- The bug is plausible given the visible context (not speculative)
- The finding is actionable (the reader can tell what to change)
Use the format in references/report-format.md.
Reference files
| Reference | When to read |
|---|---|
references/subagent-prompt-template.md |
Phase 5, when spawning each review subagent |
references/report-format.md |
Phase 6, when merging and presenting findings |
references/categories/INDEX.md |
Phase 2 — single-file scan of all category descriptions + diff signals |
references/categories/<name>.md |
Phase 3 — full body of each loaded category, picked from INDEX |
The categories in references/categories/ are project-agnostic patterns mined from real
bug fixes across distributed-systems projects (Cassandra, Kafka, Iceberg). They describe
generalized code-level shapes, not project-specific issues.
How this differs from related skills
| Skill | Scope | Pattern source | Subagent dispatch |
|---|---|---|---|
shallow-review (cassandra-edge-case-explorer) |
Whole patch | 6 fixed lenses (~100 items total) | One subagent per lens, fixed |
deep-review |
User-named files | 444-pattern catalog | One subagent per file, full catalog |
targeted-review (this) |
Whole patch, focus-decomposed | ~11 categories (300+ findings) — selectively loaded | One subagent per focus, selectively populated checklist |
mega-review |
Large branches | Orchestrates the above | Multi-pass |
Use targeted-review when:
- The patch spans 50-1000 LOC
- You want to spend tokens on what matters for THIS patch, not on a fixed catalog
- You have a
*-findings/corpus or are reviewing systems-level code that benefits from the curated categories
Pitfalls and guardrails
- Don't skip Phase 1. Calling patch-explainer and codebase-analysis is what lets you pick categories and items intelligently. Without that grounding, you'll loose-match on keywords and overwhelm subagents.
- Don't look at prior iterations while picking. The whole value of multiple iterations is independent draws. If you anchor on the first iteration's selections, you get one draw repeated instead of several independent ones.
- Don't load every category "just in case". The whole value is selection. If you match more than 8 categories in an iteration, you've probably been too generous.
- Don't pass the full catalog to subagents. Each subagent gets only the items selected for its focus. Passing all items defeats the purpose.
- Don't substitute findings for understanding. A finding that "matches a code shape" is a hypothesis to verify — the subagent confirms or refutes by reading the code, not by trusting the pattern. Mark uncertain findings as Low confidence.
- The checklist is the menu, not the order. A subagent should also report bugs it notices that aren't on the checklist — the checklist primes attention, it doesn't cap it.
04 同仓库更多 Skills
Bug复现程序编写
write-reproducer
为任何项目编写最小化、可靠的 bug 复现程序(repro)。使用时机:(1) bug 报告或 issue 需要一个能够可靠演示失败的测试;(2) 将描述的失败场景转换为可运行代码;(3) 将现有复杂测试最小化为必要的触发条件。涵盖完整的复现工作流:失败特征化、范围选择、编写复现程序、验证其因正确的原因失败,以及最小化到尽可能小的触发条件。
TLA+形式化验证
tla-plus
创建、运行和验证 TLA+ 与 PlusCal 形式化规约。用于对分布式系统、协议、并发算法和状态机进行建模。可以从代码编写规约、发现规约与实现之间的分歧、识别并发 bug 和不变量违规。当用户要求“write a TLA+ spec”、“model check”、“verify protocol”、“find race conditions”或“formal verification”时使用。
快速并行代码审查
shallow-review
使用 6 个专家代理并行开展浅层(快速)集成式 bug 查找审查。每个专家通过不同视角审查同一补丁:逻辑与类型、边界与 I/O、并发与状态、资源与序列化、缺失分析以及 API 完整性。发现的问题会被合并并去重。最适合:补丁的快速初审、diff 分诊、广泛的表层 bug 扫描。如需以文件为中心、包含完整模式目录和代码库调查的更深入审查,请改用 deep-review 技能。
代码补丁可视化解析
patch-explainer
深度代码分析,通过 ASCII 可视化展示代码结构、流程和状态转换。适用于分析补丁/diff、解释类或子系统、理解代码架构、审查变更中的不一致之处,或被要求可视化代码的工作原理时。提供前后对比图、数据/控制流、并发分析、假设条件和失败模式。触发词:explain this patch/code/class、how does X work、show me the flow、visualize this change、代码审查请求,或在 PR 审查期间主动分析。
大型补丁多轮深度代码审查
mega-review
针对大型补丁(1000+ 行代码)的多轮深度代码审查,最大化真实 Bug 的检出率。并行编排 targeted-review、shallow-review 和 deep-review,覆盖所有高风险(HIGH)和中风险(MEDIUM)文件与提交:从整体上理解特性,按文件和提交拆分,对每个 HIGH/MEDIUM 文件运行深度审查,在同一范围内运行定向审查,并对每个提交执行浅层审查,随后进行交叉一致性检查。适用场景:审查大型补丁(特性分支、多提交或单个大型 diff,1000+ 行代码);进行彻底的合并前审查;或当浅层审查因补丁规模过大而漏掉 Bug 时。触发词:"review this branch"、"review these commits"、"review this feature"、"mega review"、"thorough review"、"full review of X commits",或当用户指定提交范围或特性进行审查时。
Git 代码热力图分析
heatmap
使用 Git 热力图分析识别高变动量的文件和代码行,作为深入审查或 Bug 排查的候选对象。适用于 PR 审查、安全审计、Bug 排查或任何代码分析任务。