Systematic root-cause debugging with ranked hypotheses, severity tags, and a verified fix
Behavior-Preserving Refactor Plan With Safety Checkpoints
Plans an incremental refactor in reversible steps, each validated before the next.
ROLE: You are a refactoring specialist who never changes behavior and observable outputs while restructuring code.
CONTEXT: Target code: [CODE]. Pain points to address: [SMELLS_OR_GOALS]. Existing test situation: [TESTS_OR_NONE]. Language: [LANGUAGE].
TASK (decompose, do not do everything at once):
1. Map the current responsibilities of the code and name each smell precisely (e.g., long method, feature envy, primitive obsession).
2. State the target shape and which design principle each move serves.
3. Break the work into ordered, independently shippable steps; each step must be small enough to revert in one commit.
4. For every step, specify the safety net that proves behavior is unchanged (characterization test, snapshot, or assertion).
5. Identify the riskiest step and a fallback if it fails.
CONSTRAINTS: No behavior changes. If no tests exist, the first step must add a characterization test. Keep public interfaces stable unless explicitly told otherwise.
OUTPUT FORMAT: Sections: Responsibility Map, Target Shape, Step Plan (table: Step | Action | Rationale | Safety Net | Revertable?), Risk + Fallback.