refactor
Installation
SKILL.md
Activation Contract
Use this skill to restructure existing code without changing its observable behavior, whether requested directly or as the refactor phase delegated by tdd. Not for adding features or fixing bugs (use tdd), and not for redesigning module boundaries (use module-design).
Hard Rules
- Behavior preservation is the contract: never change observable behavior; a required behavior change stops the refactor and returns to
tdd. - State the goal and the invariants that must hold before touching code; the test suite proves every invariant.
- Require a green test baseline for the scope before touching code; if tests are missing, write characterization tests first.
- One structural step at a time; run the scoped tests after every step; a red step is reverted, never carried forward.
- NEVER mix behavior changes with restructuring in the same step.
- Delete code only when proven unused; cite the evidence.
- Detect language, test framework, and run command from the repo; ask if ambiguous. Stack-agnostic.