refactoring

Plans behavior-preserving code restructuring with reversible baselines and characterization tests.

3|Updated Nov 8, 2014
One-click install
npx skills add https://github.com/mintuz/.dotfiles --skill refactoring-mintuz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactoring
Source: https://github.com/mintuz/.dotfiles/tree/main/agents/.agents/skills/refactoring
Command: npx skills add https://github.com/mintuz/.dotfiles --skill refactoring-mintuz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Restructuring working code without breaking it is risky: hidden behaviors get lost, unrelated changes get swept into commits, and failed refactors become long debugging sessions. This Skill provides a disciplined workflow for refactoring code that already passes its tests, ensuring observable behavior stays identical. ## Core Features & Use Cases - Reversible Baseline Workflow: Records a restorable state and the known test result (green or a documented failing set) before any structural change, so a broken slice costs one restore instead of a debugging session. - Characterization Tests: Traces call paths and pins observable behaviors (signatures, error types, ordering, retry counts) with passing tests before moving any code. - Priority Classification: Categorizes findings as Critical, High, Nice, or Skip so only worthwhile structural improvements are made, and blocks speculative code and behavior changes disguised as refactors. - Use Case: After a TDD green phase, you notice magic numbers and a 40-line function. The Skill guides you to record the baseline, pin behavior with tests, extract constants and helpers in one slice, and verify the suite matches the recorded result. ## Quick Start Ask the AI to plan a safe refactoring of the working code in your current module using the refactoring skill, keeping all observable behavior unchanged.

Frequently Asked Questions about refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code without changing its behavior?▼

Refactor safely by first recording a reversible baseline and the current test result, then writing characterization tests that pin observable behavior before moving code. Apply one structural slice at a time and re-run the focused and regression tests after each step.

What are characterization tests in refactoring?▼

Characterization tests are tests that record the current observable behavior of existing code before you restructure it. They assert things callers depend on, such as public signatures, error types, ordering, and retry counts, and must pass against the unchanged implementation first.

When should I not refactor code?▼

Do not refactor when the structure is already clear, the change is only a style preference, or it would alter observable behavior, since that is a feature requiring test-first delivery. Also avoid premature optimization and code that is good enough for the current phase.

Can I refactor when some tests are already failing?▼

Yes, but you must record the exact set of failing tests in the baseline, and that set must be unchanged after the refactor. Restore green first when possible, and fix those failures as a separate change, never inside the refactor.

How do I decide which code smells to fix first?▼

Use the priority classification: fix Critical issues like mutations and knowledge duplication immediately, address High items like magic numbers and long functions in the current session, defer Nice items, and skip code that is already clean.