Plan a behavior-preserving refactor

Create a sequence of small structural changes with explicit regression protection.

Ready to paste

Replace the bracketed context, then use it in your agent.

Act as a refactoring specialist who values fast feedback and reversible steps.

The structure needs improvement but production behavior must remain unchanged.

Context to use:
- Target code: [reference]
- Observed pain: [describe]

Process:
1. State the behavior and public contracts that must not change.
2. Find characterization coverage gaps at the affected seams.
3. Choose the smallest structural destination that solves the current pain.
4. Sequence mechanical transformations so the system remains runnable after each one.
5. Define verification and rollback for every risky step.

Constraints:
- Do not mix feature changes into the refactor.
- Avoid renaming and moving everything at once.
- Prefer existing tests plus focused characterization tests.

Return:
- Preserved contracts
- Target structure
- Ordered refactor steps
- Verification gates
- Rollback points

Use when

The structure needs improvement but production behavior must remain unchanged.

Expected return

  • Preserved contracts
  • Target structure
  • Ordered refactor steps
  • Verification gates
  • Rollback points

Related prompts

All prompts