refactor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

description: Two-pass code refinement - clarity then architecture


描述:双阶段代码优化——先清晰化再架构优化

REFACTOR

代码重构

"Simplicity is the ultimate sophistication." — da Vinci
“简单是终极的复杂。” —— 达芬奇

Philosophy

理念

Fight entropy. Leave the codebase better than you found it.
Every shortcut becomes someone else's burden. Every hack compounds into technical debt. You are not just refactoring code—you are shaping the future of this project.
对抗熵增。让代码库比你接手时更优秀。
每一个捷径都会成为他人的负担。每一个投机取巧的写法都会累积成技术债务。你不只是在重构代码——你正在塑造这个项目的未来。

Role

角色定位

You are the senior engineer. Codex does the refactoring; you review and ship.
Codex writes first draft. You review and ship.
你是资深工程师。Codex负责执行重构;你负责审核并交付。
Codex撰写初稿。你审核并交付。

Objective

目标

Post-implementation refinement: simplify code, improve module depth.
实现后优化:简化代码,提升模块深度。

Process

流程

Codex Does the Refactoring

Codex执行重构

Delegate the actual refactoring to Codex:
bash
codex exec "REFACTOR: Simplify [file/module]. Focus on clarity, naming, reduced nesting. Follow CLAUDE.md standards. Run pnpm typecheck after." \
  --output-last-message /tmp/codex-refactor.md 2>/dev/null
Review what Codex produces. Fix issues if needed, then commit.
将实际的重构工作委托给Codex:
bash
codex exec "REFACTOR: Simplify [file/module]. Focus on clarity, naming, reduced nesting. Follow CLAUDE.md standards. Run pnpm typecheck after." \
  --output-last-message /tmp/codex-refactor.md 2>/dev/null
审核Codex生成的内容。如有需要修复问题,然后提交代码。

Mission

核心任务

Two-pass refinement:
  1. Clarity — Simplify code without changing behavior
  2. Architecture — Improve module depth and information hiding
双阶段优化:
  1. 清晰化 —— 在不改变代码行为的前提下简化代码
  2. 架构优化 —— 提升模块深度与信息隐藏能力

Phase 1: Simplification

第一阶段:代码简化

Launch
code-simplifier:code-simplifier
agent.
Goals: clarity, naming, reduced nesting, consolidated logic, project standards from CLAUDE.md.
Commit:
refactor: simplify implementation
启动
code-simplifier:code-simplifier
Agent。
目标:提升清晰性、规范命名、减少嵌套、合并逻辑、遵循CLAUDE.md中的项目标准。
提交信息:
refactor: simplify implementation

Phase 2: Deep Module Review

第二阶段:深度模块审核

Launch
ousterhout
agent to review for Ousterhout's design principles.
Looking for:
  • Shallow modules or pass-through methods
  • Leaky abstractions exposing implementation details
  • Change amplification risk (small change → many edits)
  • Cognitive load issues (too much to hold in head)
If high-impact issues found:
  1. Implement suggested refactorings
  2. Commit:
    refactor: improve module depth
启动
ousterhout
Agent以根据Ousterhout设计原则进行审核。
检查要点:
  • 浅层次模块或透传方法
  • 暴露实现细节的抽象泄漏
  • 变更放大风险(微小改动需要多处编辑)
  • 认知负荷问题(内容过多难以记忆)
如果发现高影响问题:
  1. 实施建议的重构方案
  2. 提交信息:
    refactor: improve module depth

Completion

完成标准

Report what was simplified and any architectural improvements made.
报告已完成的代码简化工作以及所有架构层面的改进。