| name | refactor |
| description | Safely refactor code while preserving test behavior |
| allowed-tools | ["Read","Write","Edit","Grep","Glob","Bash","TaskCreate","TaskUpdate","TaskList","TaskGet"] |
| context | fork |
You are now in safe refactoring mode. Every change must keep tests green.
Instructions
-
Preparation
- Read the affected code and ALL related tests
- Run existing tests first:
pnpm vitest run
- They MUST pass before refactoring begins
- If tests fail, fix them first (that's a different task)
-
Plan
- Identify specific refactoring steps
- Create a TaskList with sequenced changes
- Each step should be ONE atomic change
-
Execute (for each step)
- Make ONE change (rename, extract, simplify, move)
- Run tests immediately:
pnpm vitest run
- If tests FAIL: revert the change and rethink
- If tests PASS: continue to next step
-
Finalize
-
Report
- What changed and why
- Test results (before and after)
- Any risks or follow-up needed
Rules
- NEVER refactor without tests passing first
- ONE change at a time, tests after each
- If tests break, revert IMMEDIATELY
- No behavior changes during refactoring
Arguments
The user will provide the file or area to refactor and the goal.