| name | refactor |
| description | Improve structure, readability, modularity, and maintainability without changing behavior, while preserving safety with tests. |
Refactor
Use this to clean up code, reduce duplication, split modules, simplify abstractions, and improve architecture incrementally.
Workflow
- Define what stays behaviorally unchanged.
- Identify pain points: duplication, long functions, mixed responsibilities, poor naming, hidden coupling.
- Propose the smallest sequence of safe refactors.
- Keep tests green after each step.
- Stop when the design is clearly better, not theoretically perfect.
Rules
- Refactor for clarity, not cleverness.
- Prefer incremental extraction over rewrites.
- Keep public contracts stable unless explicitly changing them.
- Add characterization tests before invasive refactors.
Output format
- Current problems
- Refactor plan
- Safe order of changes
- Risks and validation