simplify-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSimplify Code
代码简化
Review all changed files for reuse, quality, and efficiency. Fix any issues found.
审查所有变更文件的复用性、质量和效率,修复发现的所有问题。
Step 1: Determine the Diff Command
步骤1:确定Diff命令
Determine the appropriate diff command (e.g. , , ) based on the current git state. If the caller specifies which diff command to use, use that. Do NOT run the diff yourself — each review agent will run it independently to keep the diff out of the main agent's context.
git diffgit diff --cachedgit diff HEADIf 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命令(例如、、)。如果调用者指定了要使用的diff命令,则使用该命令。请勿自行运行diff——每个审查Agent将独立运行它,以避免diff进入主Agent的上下文。
git diffgit diff --cachedgit diff HEAD如果没有git变更,则审查用户提到的或本次对话中你之前编辑过的最近修改的文件。
Step 2: Launch Four Review Agents in Parallel
步骤2:并行启动四个审查Agent
Use the Agent tool to launch all four agents concurrently in a single message. Every Agent tool call must set . Instruct each agent to run the diff command itself to obtain the diff.
model: "opus"使用Agent工具在一条消息中同时启动所有四个Agent。每个Agent工具调用必须设置。指示每个Agent自行运行diff命令以获取diff内容。
model: "opus"Agent 1: Code Reuse Review
Agent 1:代码复用审查
For each change:
- 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.
- Flag any new function that duplicates existing functionality. Suggest the existing function to use instead.
- 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.
针对每一处变更:
- 搜索现有工具和辅助函数,以替代新编写的代码。在代码库的其他地方寻找类似模式——常见位置包括工具目录、共享模块和变更文件的相邻文件。
- 标记任何重复现有功能的新函数。建议改用现有函数。
- 标记任何可使用现有工具的内联逻辑——手动实现的字符串处理、手动路径处理、自定义环境检查、临时类型守卫以及类似模式都是常见的候选对象。
Agent 2: Code Quality Review
Agent 2:代码质量审查
Review the same changes for hacky patterns:
- Redundant state: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
- Parameter sprawl: adding new parameters to a function instead of generalizing or restructuring existing ones
- Copy-paste with slight variation: near-duplicate code blocks that should be unified with a shared abstraction
- Leaky abstractions: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
- Stringly-typed code: using raw strings where constants, enums (string unions), or branded types already exist in the codebase
- Unnecessary JSX nesting: wrapper Boxes/elements that add no layout value — check if inner component props (flexShrink, alignItems, etc.) already provide the needed behavior
针对相同变更审查不规范模式:
- 冗余状态:重复现有状态的状态、可推导的缓存值、可直接调用的观察者/副作用
- 参数膨胀:为函数添加新参数而非泛化或重构现有参数
- 复制粘贴并稍作修改:近乎重复的代码块,应通过共享抽象统一
- 抽象泄露:暴露应封装的内部细节,或打破现有抽象边界
- 字符串类型代码:在代码库已存在常量、枚举(字符串联合)或品牌类型的情况下使用原始字符串
- 不必要的JSX嵌套:未添加布局价值的包装Box/元素——检查内部组件属性(flexShrink、alignItems等)是否已提供所需行为
Agent 3: Efficiency Review
Agent 3:效率审查
Review the same changes for efficiency:
- Unnecessary work: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns
- Missed concurrency: independent operations run sequentially when they could run in parallel
- Hot-path bloat: new blocking work added to startup or per-request/per-render hot paths
- Unnecessary existence checks: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
- Memory: unbounded data structures, missing cleanup, event listener leaks
- Overly broad operations: reading entire files when only a portion is needed, loading all items when filtering for one
针对相同变更审查效率问题:
- 不必要的操作:冗余计算、重复文件读取、重复网络/API调用、N+1模式
- 错失并发机会:可并行运行的独立操作却按顺序执行
- 热路径冗余:在启动或每个请求/渲染的热路径中添加新的阻塞操作
- 不必要的存在性检查:在操作前预先检查文件/资源是否存在(TOCTOU反模式)——直接操作并处理错误
- 内存问题:无界数据结构、缺失清理、事件监听器泄漏
- 过度宽泛的操作:仅需部分内容时读取整个文件,仅需过滤单个项目时加载所有条目
Agent 4: Clarity and Standards Review
Agent 4:清晰度与规范审查
Review the same changes for clarity, standards, and balance:
- Project standards: coding conventions from CLAUDE.md not followed — import sorting, naming conventions, component patterns, error handling patterns, module style
- Unnecessary complexity: deep nesting, redundant abstractions, unclear variable or function names, comments that describe obvious code, nested ternary operators (prefer switch/if-else chains)
- Unclear code: choose clarity over brevity — explicit code is better than overly compact code. Consolidate related logic, but not at the cost of readability
- Over-simplification: overly clever solutions that are hard to understand, too many concerns combined into single functions or components, "fewer lines" prioritized over readability (dense one-liners, nested ternaries), helpful abstractions removed that were aiding code organization
- Dead weight: unnecessary comments, redundant code, abstractions that add indirection without value
针对相同变更审查清晰度、规范和平衡性:
- 项目规范:未遵循CLAUDE.md中的编码约定——导入排序、命名规范、组件模式、错误处理模式、模块风格
- 不必要的复杂性:深层嵌套、冗余抽象、不清晰的变量或函数名称、描述明显代码的注释、嵌套三元运算符(优先使用switch/if-else链)
- 不清晰的代码:优先选择清晰度而非简洁性——显式代码优于过度紧凑的代码。整合相关逻辑,但不要以可读性为代价
- 过度简化:难以理解的过度巧妙解决方案,将过多关注点合并到单个函数或组件中,优先考虑“更少代码行数”而非可读性(密集的单行代码、嵌套三元运算符),移除了有助于代码组织的有用抽象
- 冗余内容:不必要的注释、冗余代码、仅增加间接性而无价值的抽象
Step 3: Fix Issues
步骤3:修复问题
Wait for all four agents to complete. Aggregate their findings, run the diff command to get the current diff, then apply each fix directly, skipping false positives. Only edit files — do not stage, build, or test.
When done, briefly summarize what was fixed (or confirm the code was already clean).
等待所有四个Agent完成审查。汇总它们的发现,运行diff命令获取当前diff,然后直接应用每个修复,跳过误报。仅编辑文件——不要暂存、构建或测试。完成后,简要总结修复内容(或确认代码已清理完毕)。