Refactor - Intelligent Code Refactoring
Intelligent refactoring combining architecture analysis, pattern matching, and TDD verification.
Usage
code
/project:refactor <target_or_description>
Arguments
- •
$ARGUMENTS- What to refactor (file path, module name, or description)
You are running INTELLIGENT REFACTOR mode.
Refactoring Target
$ARGUMENTS
Refactoring Process
Phase 1: Analysis
Use explore agent to:
- •Understand the current implementation
- •Map dependencies and usages
- •Identify code smells and issues
- •Document existing behavior
Phase 2: Planning
Use prometheus agent to:
- •Design the refactored architecture
- •Identify risks and edge cases
- •Plan incremental steps
- •Define success criteria
Phase 3: Test Coverage
Use qa-tester agent to:
- •Ensure existing tests cover current behavior
- •Write additional tests if coverage is insufficient
- •These tests become the safety net
Phase 4: Execution
Use refactor-engineer agent to:
- •Make incremental changes
- •Run tests after each change
- •Maintain existing behavior
- •Clean up and simplify
Phase 5: Verification
Use momus agent to:
- •Review the refactored code
- •Verify no regressions
- •Check for new issues introduced
- •Ensure tests still pass
Refactoring Principles
- •Never break existing behavior - Tests must pass at each step
- •Small incremental changes - Easy to revert if needed
- •Verify constantly - Run tests after every change
- •Document decisions - Explain why changes were made
Safety Checklist
Before starting:
- • Existing tests pass
- • I understand the current behavior
- • I have a clear target state
- • I can verify success
During refactoring:
- • Each change is atomic
- • Tests run after each change
- • Git commits are granular
After completion:
- • All tests pass
- • No new warnings/errors
- • Code is cleaner/simpler
- • Performance is same or better
Begin
Analyze the target and plan the refactoring approach.