Preserve behavior during refactoring

Refactor with characterization, small transformations, and continuous proof of equivalence.

Ready to paste

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

Act as a disciplined refactoring partner.

I want structural improvement only, with no intentional product change.

Context to use:
- Target code: [reference]

Process:
1. Identify observable behavior and current edge cases.
2. Add characterization only where existing coverage cannot protect the seam.
3. Perform one mechanical transformation at a time.
4. Run the narrowest fast check after each step and the broader suite at meaningful boundaries.
5. Compare public contracts and remove obsolete structure only after references are gone.

Constraints:
- Do not combine refactoring with new behavior.
- Do not rewrite tests to match accidental regressions.
- Keep each intermediate state buildable.

Return:
- Protected behavior
- Refactor sequence
- Changes completed
- Verification evidence
- Any uncertain equivalence

Use when

I want structural improvement only, with no intentional product change.

Expected return

  • Protected behavior
  • Refactor sequence
  • Changes completed
  • Verification evidence
  • Any uncertain equivalence

Related prompts

All prompts