Safely refactors code to improve structure without changing behavior. Follows incremental refactoring methodology.
Category: Development Skills: refactoring, code-review, test-driven-development Approval Required: Yes (between steps)
Goal: Understand the code and identify what needs improvement.
Prompt:
You are preparing to refactor code.
## Code to Refactor
{{input}}
## Your Goal
Understand the code and identify what needs improvement.
## Instructions
Use get_skill('refactoring') for methodology.
1. Review the code provided above
2. Identify code smells
3. Understand existing test coverage
4. Prioritize improvements
## Output
- Code smells identified
- Current test coverage
- Refactoring priorities
- Risk assessment
Goal: Create a safe, incremental refactoring plan.
Prompt:
You are planning the refactoring steps.
## Code Assessment
{{previous_output}}
## Your Goal
Create a safe, incremental refactoring plan.
## Instructions
1. Break refactoring into small steps
2. Ensure each step is independently verifiable
3. Order by dependency
4. Plan test runs after each step
## Output
Numbered refactoring steps, each with:
- What to change
- How to verify
- Risk level
Goal: Improve code structure without changing behavior.
Prompt:
You are performing the refactoring.
## Refactoring Plan
{{previous_output}}
## Original Code
{{input}}
## Your Goal
Improve code structure without changing behavior.
## Instructions
Following refactoring methodology:
1. Make one small change at a time
2. Run tests after each change
3. Commit after each successful change
4. Stop if tests fail
## Output
Refactored code with notes on changes made.
Goal: Confirm behavior is unchanged.
Prompt:
You are verifying the refactoring didn't break anything.
## Refactored Code
{{previous_output}}
## Your Goal
Confirm behavior is unchanged.
## Instructions
1. Run all tests
2. Check for any behavior changes
3. Verify code quality improved
4. Document the improvements
## Output
- Test results
- Behavior verification
- Improvements achieved
| Setting | Value |
|---|---|
| Max Step Duration | 300 seconds |
| Approval Between Steps | Yes |
- Improving code structure before adding features
- Reducing technical debt
- Cleaning up after rapid prototyping
- Preparing code for easier maintenance
- Assess Code — Reviews code for smells (long methods, duplicate code, etc.), checks test coverage, and prioritizes improvements
- Plan Refactoring (approval gate) — Creates incremental steps, each independently verifiable with risk assessment
- Execute Refactoring (approval gate) — Makes small changes one at a time, running tests after each change
- Verify Behavior — Confirms all tests pass, behavior is unchanged, and code quality improved