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

第一阶段:识别变更

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

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

Use the Task 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传递完整的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
审查相同变更中的不良模式:
  1. 冗余状态:重复现有状态的状态、可推导的缓存值、可直接调用的观察者/副作用
  2. 参数膨胀:向函数添加新参数而非泛化或重构现有参数
  3. 复制粘贴并小幅修改:近乎重复的代码块,应通过共享抽象统一
  4. 抽象泄漏:暴露应封装的内部细节,或打破现有抽象边界
  5. 字符串类型代码:在代码库已存在常量、枚举(字符串联合)或品牌类型的情况下使用原始字符串
  6. 不必要的JSX嵌套:未添加布局价值的包装Box/元素——检查内部组件属性(flexShrink、alignItems等)是否已提供所需行为

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

第三阶段:修复问题

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完成任务。汇总它们的发现并直接修复每个问题。如果发现是误报或不值得处理,记录下来并跳过——无需质疑发现,直接跳过即可。
完成后,简要总结修复内容(或确认代码已无问题)。