Adaptive Code Review
Review code changes with model depth proportional to change complexity. No wasted opus tokens on trivial diffs.
Step 1: Collect Signals
Run these commands to gather diff signals:
CODEBLOCK0
Extract:
- - lineschanged: total added + deleted
- fileschanged: number of files
- dirs_changed: number of unique top-level directories touched (cross-module indicator)
Then scan for high-risk patterns — only in code files (exclude .md/.txt/.json/.yaml from grep):
CODEBLOCK1
- - risk_hits: count of matches (0 if only docs/config changed)
Step 2: Route
| Condition | Depth | Model |
|---|
| lineschanged < 50 AND fileschanged <= 1 AND riskhits == 0 | fast | haiku |
| lineschanged < 200 AND dirschanged <= 1 AND riskhits <= 2 |
medium | sonnet |
| Everything else (>200 lines OR dirs
changed >= 2 OR riskhits > 2) |
deep | opus |
Announce the routing decision:
CODEBLOCK2
Step 3: Dispatch
Fast (haiku)
Spawn agent with
model: "haiku", subagent_type of your code-review agent:
Prompt focus: formatting, naming conventions, obvious bugs, unused imports. Skip architecture analysis. Keep it under 30 seconds.
Medium (sonnet)
Spawn agent with
model: "sonnet", subagent_type of your code-review agent:
Standard code review: correctness, error handling, test coverage, code quality.
Deep (opus)
Spawn agent with
model: "opus", subagent_type of your code-review agent:
Full review: architecture, security, performance, cross-module impact. If language-specific reviewers exist (python-reviewer, go-reviewer, database-reviewer), spawn them in parallel.
Step 4: Report
Present results with depth label so the user knows what level of review was applied:
CODEBLOCK3
If fast review finds anything concerning, suggest upgrading: "Fast review flagged potential issues. Run /adaptive-review --deep for thorough analysis."
Overrides
User can force depth:
- -
/adaptive-review --fast — force fast regardless of signals - INLINECODE5 — force deep regardless of signals
- INLINECODE6 — force medium
自适应代码审查
根据变更复杂度,以相应深度的模型审查代码变更。琐碎的差异不会浪费Opus令牌。
第一步:收集信号
运行以下命令收集差异信号:
bash
获取差异统计信息(相对于HEAD~1或origin/main,视情况而定)
BASE=$(git merge-base HEAD origin/main 2>/dev/null || echo HEAD~1)
git diff --stat $BASE..HEAD
git diff --numstat $BASE..HEAD
提取:
- - lineschanged:新增+删除的总行数
- fileschanged:文件数量
- dirs_changed:涉及的唯一顶级目录数量(跨模块指标)
然后扫描高风险模式——仅在代码文件中(从grep中排除.md/.txt/.json/.yaml):
bash
git diff $BASE..HEAD -- .ts .js .py .go .rs .java .c .cpp .rb .sh | grep -ciE (password|secret|token|auth|session|cookie|sql|inject|exec\(|eval\(|lock|mutex|semaphore|atomic|concurrent|unsafe)
- - risk_hits:匹配次数(如果仅文档/配置文件变更则为0)
第二步:路由
| 条件 | 深度 | 模型 |
|---|
| lineschanged < 50 且 fileschanged <= 1 且 riskhits == 0 | 快速 | haiku |
| lineschanged < 200 且 dirschanged <= 1 且 riskhits <= 2 |
中等 | sonnet |
| 其他情况(>200行 或 dirs
changed >= 2 或 riskhits > 2) |
深度 | opus |
宣布路由决策:
审查深度:[快速|中等|深度](N行,N个文件,N个目录,N个风险命中)
第三步:调度
快速(haiku)
使用 model: haiku 生成代理,子代理类型为你的代码审查代理:
提示重点:格式、命名规范、明显错误、未使用的导入。跳过架构分析。控制在30秒内完成。
中等(sonnet)
使用 model: sonnet 生成代理,子代理类型为你的代码审查代理:
标准代码审查:正确性、错误处理、测试覆盖率、代码质量。
深度(opus)
使用 model: opus 生成代理,子代理类型为你的代码审查代理:
全面审查:架构、安全性、性能、跨模块影响。如果存在特定语言的审查器(python-reviewer、go-reviewer、database-reviewer),则并行生成。
第四步:报告
使用深度标签呈现结果,以便用户了解应用的审查级别:
自适应审查:[快速|中等|深度]
信号:{lines}行,{files}个文件,{dirs}个目录,{risk_hits}个风险命中
[审查器输出]
如果快速审查发现任何问题,建议升级:快速审查标记了潜在问题。运行 /adaptive-review --deep 进行彻底分析。
覆盖选项
用户可以强制指定深度:
- - /adaptive-review --fast — 忽略信号强制快速审查
- /adaptive-review --deep — 忽略信号强制深度审查
- /adaptive-review --medium — 强制中等审查