simplify

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Simplify: Code Review and Cleanup

简化:代码审查与清理

Review all changed files for reuse, quality, and efficiency. Fix any issues found.
审查所有变更文件的可复用性、质量和效率,修复发现的所有问题。

Phase 1: Identify Changes

阶段1:识别变更

Run
git diff
(or
git diff HEAD
if there are staged changes) to see what changed. If there are no git changes, review the most recently modified files that the user mentioned or that you edited earlier in this conversation.
运行
git diff
(如果存在暂存变更则运行
git diff HEAD
)查看修改内容。如果没有git变更,则审查用户提到的、或是本次对话中你先前编辑过的最近修改的文件。

Phase 2: Launch Three Review Agents in Parallel

阶段2:并行启动三个审查Agent

Use the Agent tool to launch all three agents concurrently in a single message. Pass each agent the full diff so it has the complete context.
使用Agent工具在单条消息中同时启动三个Agent,向每个Agent传入完整的diff内容,确保其拥有完整上下文。

Agent 1: Code Reuse Review

Agent 1:代码复用审查

For each change:
  1. Search for existing utilities and helpers that could replace newly written code. Look for similar patterns elsewhere in the codebase — common locations are utility directories, shared modules, and files adjacent to the changed ones.
  2. Flag any new function that duplicates existing functionality. Suggest the existing function to use instead.
  3. Flag any inline logic that could use an existing utility — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar patterns are common candidates.
针对每一项变更:
  1. 搜索现有工具函数与辅助方法,判断是否可以替代新编写的代码。在代码库其他位置查找相似模式,常见位置包括工具目录、共享模块、与变更文件相邻的文件。
  2. 标记所有重复现有功能的新函数,建议使用已有函数替代。
  3. 标记所有可以使用现有工具函数的内联逻辑——手动实现的字符串处理、手动路径处理、自定义环境检查、临时类型守卫以及类似模式都是常见的可优化对象。

Agent 2: Code Quality Review

Agent 2:代码质量审查

Review the same changes for hacky patterns:
  1. Redundant state: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
  2. Parameter sprawl: adding new parameters to a function instead of generalizing or restructuring existing ones
  3. Copy-paste with slight variation: near-duplicate code blocks that should be unified with a shared abstraction
  4. Leaky abstractions: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
  5. Stringly-typed code: using raw strings where constants, enums (string unions), or branded types already exist in the codebase
  6. Unnecessary JSX nesting: wrapper Boxes/elements that add no layout value — check if inner component props (flexShrink, alignItems, etc.) already provide the needed behavior
  7. Unnecessary comments: comments explaining WHAT the code does (well-named identifiers already do that), narrating the change, or referencing the task/caller — delete; keep only non-obvious WHY (hidden constraints, subtle invariants, workarounds)
针对相同变更检查不规范的实现模式:
  1. 冗余状态:重复现有状态的状态、可推导得出的缓存值、可以改为直接调用的观察者/副作用
  2. 参数膨胀:为函数新增参数,而非泛化或重构现有参数
  3. 小幅修改的复制粘贴代码:几乎重复的代码块,应该通过共享抽象进行统一
  4. 泄露的抽象:暴露了本应封装的内部细节,或是打破了现有抽象边界
  5. 字符串类型滥用代码:在代码库已存在常量、枚举(string unions)或 branded 类型的场景下使用原始字符串
  6. 不必要的JSX嵌套:没有任何布局价值的包裹Box/元素——检查内部组件属性(flexShrink、alignItems等)是否已经提供了所需的行为
  7. 不必要的注释:解释代码做了什么的注释(命名良好的标识符已经能实现该作用)、记录变更过程的注释、关联任务/调用方的注释——直接删除;仅保留解释非显而易见的原因的注释(隐藏的约束、易被忽略的不变量、临时解决方案)

Agent 3: Efficiency Review

Agent 3:效率审查

Review the same changes for efficiency:
  1. Unnecessary work: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns
  2. Missed concurrency: independent operations run sequentially when they could run in parallel
  3. Hot-path bloat: new blocking work added to startup or per-request/per-render hot paths
  4. Recurring no-op updates: state/store updates inside polling loops, intervals, or event handlers that fire unconditionally — add a change-detection guard so downstream consumers aren't notified when nothing changed. Also: if a wrapper function takes an updater/reducer callback, verify it honors same-reference returns (or whatever the "no change" signal is) — otherwise callers' early-return no-ops are silently defeated
  5. Unnecessary existence checks: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
  6. Memory: unbounded data structures, missing cleanup, event listener leaks
  7. Overly broad operations: reading entire files when only a portion is needed, loading all items when filtering for one
针对相同变更检查效率问题:
  1. 不必要的工作:冗余计算、重复文件读取、重复网络/API调用、N+1查询模式
  2. 未利用的并发能力:可以并行运行的独立操作被串行执行
  3. 热点路径膨胀:在启动流程、按请求/按渲染的热点路径中新增了阻塞操作
  4. 重复的无效应更新:轮询循环、定时器或事件处理器中无条件触发的状态/存储更新——添加变更检测守卫,确保没有变更时不会通知下游消费者。另外:如果包裹函数接收更新器/reducer回调,验证其支持相同引用返回(或是任意「无变更」信号)——否则调用方的提前返回无操作会被静默失效
  5. 不必要的存在性检查:操作前预先检查文件/资源是否存在(TOCTOU反模式)——直接执行操作并处理错误即可
  6. 内存问题:无边界的数据结构、缺失的清理逻辑、事件监听器泄露
  7. 范围过大的操作:仅需要部分内容时读取了整个文件,仅需要过滤单个条目时加载了所有条目

Phase 3: Fix Issues

阶段3:修复问题

Wait for all three agents to complete. Aggregate their findings and fix each issue directly. If a finding is a false positive or not worth addressing, note it and move on — do not argue with the finding, just skip it.
When done, briefly summarize what was fixed (or confirm the code was already clean).
等待三个Agent全部执行完成,汇总它们的发现结果,直接修复每一个问题。如果某项发现是误报或者不值得处理,标注后跳过即可——不要争论发现的合理性,直接跳过。
完成后,简要总结修复的内容(或是确认代码已经符合规范)。