code-review-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Review Expert
代码评审专家
Overview
概述
Perform a structured review of the current git changes with focus on SOLID, architecture, removal candidates, and security risks. Default to review-only output unless the user asks to implement changes.
对当前git变更开展结构化评审,重点关注SOLID原则、架构、可移除代码候选以及安全风险。默认仅输出评审结果,除非用户要求实现变更。
Severity Levels
严重等级
| Level | Name | Description | Action |
|---|---|---|---|
| P0 | Critical | Security vulnerability, data loss risk, correctness bug | Must block merge |
| P1 | High | Logic error, significant SOLID violation, performance regression | Should fix before merge |
| P2 | Medium | Code smell, maintainability concern, minor SOLID violation | Fix in this PR or create follow-up |
| P3 | Low | Style, naming, minor suggestion | Optional improvement |
| 等级 | 名称 | 描述 | 处置方式 |
|---|---|---|---|
| P0 | 关键 | 安全漏洞、数据丢失风险、正确性缺陷 | 必须阻止合并 |
| P1 | 高 | 逻辑错误、严重SOLID原则违例、性能回退 | 应在合并前修复 |
| P2 | 中 | 代码坏味道、可维护性隐患、轻微SOLID原则违例 | 可在本PR中修复或创建后续任务处理 |
| P3 | 低 | 样式、命名、微小建议 | 可选改进项 |
Workflow
工作流
1) Preflight context
1) 前置上下文检查
- Use ,
git status -sb, andgit diff --statto scope changes.git diff - If needed, use or
rgto find related modules, usages, and contracts.grep - Identify entry points, ownership boundaries, and critical paths (auth, payments, data writes, network).
Edge cases:
- No changes: If is empty, inform user and ask if they want to review staged changes or a specific commit range.
git diff - Large diff (>500 lines): Summarize by file first, then review in batches by module/feature area.
- Mixed concerns: Group findings by logical feature, not just file order.
- 使用、
git status -sb和git diff --stat确定变更范围。git diff - 必要时使用或
rg查找相关模块、调用情况和契约。grep - 识别入口点、所有权边界和关键路径(认证、支付、数据写入、网络)。
边界情况:
- 无变更:如果为空,告知用户并询问是否要评审暂存变更或特定提交区间。
git diff - 大量变更(>500行):先按文件汇总,再按模块/功能领域分批评审。
- 混合关注点:按逻辑功能分组展示发现,而非仅按文件顺序。
2) SOLID + architecture smells
2) SOLID + 架构坏味道检查
- Load for specific prompts.
references/solid-checklist.md - Look for:
- SRP: Overloaded modules with unrelated responsibilities.
- OCP: Frequent edits to add behavior instead of extension points.
- LSP: Subclasses that break expectations or require type checks.
- ISP: Wide interfaces with unused methods.
- DIP: High-level logic tied to low-level implementations.
- When you propose a refactor, explain why it improves cohesion/coupling and outline a minimal, safe split.
- If refactor is non-trivial, propose an incremental plan instead of a large rewrite.
- 加载获取具体提示。
references/solid-checklist.md - 重点查找:
- SRP:承载无关职责的过载模块。
- OCP:需要频繁修改来新增行为而非通过扩展点实现的模块。
- LSP:打破预期或需要类型检查的子类。
- ISP:包含大量未使用方法的宽接口。
- DIP:高层逻辑与底层实现强绑定的情况。
- 当你提出重构建议时,要解释为什么它能提升内聚/降低耦合,并给出最小化、安全的拆分方案。
- 如果重构复杂度较高,建议采用渐进式方案而非大规模重写。
3) Removal candidates + iteration plan
3) 可移除代码候选 + 迭代计划
- Load for template.
references/removal-plan.md - Identify code that is unused, redundant, or feature-flagged off.
- Distinguish safe delete now vs defer with plan.
- Provide a follow-up plan with concrete steps and checkpoints (tests/metrics).
- 加载获取模板。
references/removal-plan.md - 识别未使用、冗余或已通过特性开关关闭的代码。
- 区分可立即安全删除和按计划延后处理的代码。
- 提供包含具体步骤和检查点(测试/指标)的后续跟进计划。
4) Security and reliability scan
4) 安全与可靠性扫描
- Load for coverage.
references/security-checklist.md - Check for:
- XSS, injection (SQL/NoSQL/command), SSRF, path traversal
- AuthZ/AuthN gaps, missing tenancy checks
- Secret leakage or API keys in logs/env/files
- Rate limits, unbounded loops, CPU/memory hotspots
- Unsafe deserialization, weak crypto, insecure defaults
- Race conditions: concurrent access, check-then-act, TOCTOU, missing locks
- Call out both exploitability and impact.
- 加载覆盖检查项。
references/security-checklist.md - 检查以下内容:
- XSS、注入(SQL/NoSQL/命令)、SSRF、路径遍历
- AuthZ/AuthN漏洞、缺失多租户检查
- 日志/环境变量/文件中的密钥泄露或API密钥
- 限流缺失、无限循环、CPU/内存热点
- 不安全的反序列化、弱加密、不安全默认配置
- 竞态条件:并发访问、先检查后执行、TOCTOU、缺失锁
- 同时说明可利用性和影响范围。
5) Code quality scan
5) 代码质量扫描
- Load for coverage.
references/code-quality-checklist.md - Check for:
- Error handling: swallowed exceptions, overly broad catch, missing error handling, async errors
- Performance: N+1 queries, CPU-intensive ops in hot paths, missing cache, unbounded memory
- Boundary conditions: null/undefined handling, empty collections, numeric boundaries, off-by-one
- Flag issues that may cause silent failures or production incidents.
- 加载覆盖检查项。
references/code-quality-checklist.md - 检查以下内容:
- 错误处理:吞掉的异常、过宽的catch语句、缺失错误处理、异步错误
- 性能:N+1查询、热点路径中的CPU密集型操作、缺失缓存、内存无限制增长
- 边界条件:null/undefined处理、空集合、数值边界、差一错误
- 标记可能导致静默失败或生产事故的问题。
6) Output format
6) 输出格式
Structure your review as follows:
markdown
undefined按照如下结构组织评审结果:
markdown
undefinedCode Review Summary
Code Review Summary
Files reviewed: X files, Y lines changed
Overall assessment: [APPROVE / REQUEST_CHANGES / COMMENT]
Files reviewed: X files, Y lines changed
Overall assessment: [APPROVE / REQUEST_CHANGES / COMMENT]
Findings
Findings
P0 - Critical
P0 - Critical
(none or list)
(none or list)
P1 - High
P1 - High
- [file:line] Brief title
- Description of issue
- Suggested fix
- [file:line] Brief title
- Description of issue
- Suggested fix
P2 - Medium
P2 - Medium
- (continue numbering across sections)
- ...
- (continue numbering across sections)
- ...
P3 - Low
P3 - Low
...
...
Removal/Iteration Plan
Removal/Iteration Plan
(if applicable)
(if applicable)
Additional Suggestions
Additional Suggestions
(optional improvements, not blocking)
**Inline comments**: Use this format for file-specific findings:::code-comment{file="path/to/file.ts" line="42" severity="P1"}
Description of the issue and suggested fix.
::
**Clean review**: If no issues found, explicitly state:
- What was checked
- Any areas not covered (e.g., "Did not verify database migrations")
- Residual risks or recommended follow-up tests(optional improvements, not blocking)
**行内注释**:针对特定文件的发现使用如下格式:::code-comment{file="path/to/file.ts" line="42" severity="P1"}
Description of the issue and suggested fix.
::
**无问题评审**:如果未发现任何问题,明确说明:
- 已检查的内容
- 未覆盖的领域(例如:"Did not verify database migrations")
- 残余风险或推荐的后续测试7) Next steps confirmation
7) 下一步确认
After presenting findings, ask user how to proceed:
markdown
---展示评审发现后,询问用户后续操作:
markdown
---Next Steps
Next Steps
I found X issues (P0: _, P1: _, P2: _, P3: _).
How would you like to proceed?
- Fix all - I'll implement all suggested fixes
- Fix P0/P1 only - Address critical and high priority issues
- Fix specific items - Tell me which issues to fix
- No changes - Review complete, no implementation needed
Please choose an option or provide specific instructions.
**Important**: Do NOT implement any changes until user explicitly confirms. This is a review-first workflow.I found X issues (P0: _, P1: _, P2: _, P3: _).
How would you like to proceed?
- Fix all - I'll implement all suggested fixes
- Fix P0/P1 only - Address critical and high priority issues
- Fix specific items - Tell me which issues to fix
- No changes - Review complete, no implementation needed
Please choose an option or provide specific instructions.
**重要提示**:在用户明确确认前,请勿执行任何变更。本流程优先评审。Resources
资源
references/
references/
| File | Purpose |
|---|---|
| SOLID smell prompts and refactor heuristics |
| Web/app security and runtime risk checklist |
| Error handling, performance, boundary conditions |
| Template for deletion candidates and follow-up plan |
| 文件 | 用途 |
|---|---|
| SOLID坏味道提示和重构启发式规则 |
| Web/应用安全和运行时风险检查清单 |
| 错误处理、性能、边界条件检查清单 |
| 可删除代码候选和后续计划模板 |