Behavior-Preserving Refactor
Refactor a module to improve its structure, readability, or design WITHOUT changing observable behavior — the defining constraint is that the tests stay green throughout. Plans the refactor FIRST — the target structure, the seams to introduce, the safe step sequence, and the green-tests guardrail — then refactors in small reversible steps, then a reviewer confirms behavior is unchanged and the code is genuinely cleaner. Covers extract-function/module, dependency seams, removing duplication, naming, and test-green-as-invariant refactoring.
How it runs
| # | Step | Who runs it | What happens |
|---|---|---|---|
| 1 | Plan the refactor | Planner | lock target structure, steps, green-tests guardrail |
| 2 | Refactor | Developer | apply small reversible steps, tests green throughout |
| 3 | Verify behavior preserved | Reviewer | confirm tests green and code is genuinely cleaner |
| 4 | Evaluate | Reviewer | Grade the deliverable against every acceptance criterion. All pass → finish; any fail → loop back and fix the gap. |
| 5 | Finish | Developer | All acceptance criteria met. Stamp a short summary and report DONE. |
Say something like "refactor this module" or "clean up the code" or "improve code structure" or "behavior-preserving refactor" or "reduce duplication" in chat to start it.