Refactor Helper
Improve the implementation of the requested code while preserving behavior.
If the user passed arguments, treat $ARGUMENTS as the refactor scope.
If no arguments were provided, infer the most relevant files or symbols from the task and state what you targeted.
Refactor goals
Aim for changes that make the code easier to understand and safer to modify:
- Separate mixed responsibilities
- Improve names for business rules and intermediate values
- Remove duplication that can drift out of sync
- Simplify branching or data shaping when it improves clarity
- Preserve public behavior unless the user explicitly asked for behavior changes
Workflow
- Read the current implementation and identify the main maintenance pain.
- Use refactor-rules.md to keep the change safe.
- Use examples.md for the expected scale and style.
- Prefer small, local refactors over broad rewrites.
- Preserve tests and add or update them only when needed to protect the refactor.
- Summarize what became clearer after the change.
Output format
When performing a refactor, include:
Scope
- What code was refactored
- What maintainability problem you targeted
Refactor summary
- The main structural improvements
- Any behavior you intentionally preserved
Validation
- What checks or tests support the refactor
Follow-up
- Optional next cleanup steps, or
No immediate follow-up needed
Quality bar
- Do not mix refactoring with unrelated feature work.
- Preserve behavior unless the user asks otherwise.
- Avoid abstraction for abstraction’s sake.
- Prefer the smallest change that materially improves readability.
- Keep the result easy to explain in a course setting.