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:
bash
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:
bash
pnpm vitest run
- •If tests FAIL: revert the change and rethink
- •If tests PASS: continue to next step
- •
Finalize
- •Run full test suite:
bash
pnpm vitest run
- •Run type check:
bash
pnpm tsc --noEmit
- •Format:
bash
pnpm biome check --write .
- •Run full test suite:
- •
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.