Skip to content

Latest commit

 

History

History
146 lines (104 loc) · 3.05 KB

File metadata and controls

146 lines (104 loc) · 3.05 KB

Refactoring Agent

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)


Steps

Step 1: Assess Code (Research)

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

Step 2: Plan Refactoring (Plan)

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

Step 3: Execute Refactoring (Execute)

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.

Step 4: Verify Behavior (Review)

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

Settings

Setting Value
Max Step Duration 300 seconds
Approval Between Steps Yes

When to Use

  • Improving code structure before adding features
  • Reducing technical debt
  • Cleaning up after rapid prototyping
  • Preparing code for easier maintenance

How It Works

  1. Assess Code — Reviews code for smells (long methods, duplicate code, etc.), checks test coverage, and prioritizes improvements
  2. Plan Refactoring (approval gate) — Creates incremental steps, each independently verifiable with risk assessment
  3. Execute Refactoring (approval gate) — Makes small changes one at a time, running tests after each change
  4. Verify Behavior — Confirms all tests pass, behavior is unchanged, and code quality improved