Perform safe refactoring protected by existing tests: **$ARGUMENTS**
Perform safe refactoring protected by existing tests: **$ARGUMENTS**
/plugin marketplace add hculap/better-code/plugin install tdd-dev@better-codePerform safe refactoring protected by existing tests: $ARGUMENTS
Extract from arguments:
src/utils.tscalculateTotalextract validation logicResolve the refactor target:
If looks like a file path (contains / or .):
If looks like a symbol (single word, camelCase, PascalCase):
If descriptive text:
Determine planning behavior based on flags:
--skip-plan flag: Skip planning, proceed directly to refactoring--plan flag: Force planning before refactoringIf planning is enabled (via --plan flag or user choice):
Critical: Refactoring requires GREEN state to begin.
Pre-Refactor Check:
Tests: X passed, 0 failed
Status: GREEN ✓ (safe to refactor)
Relevant tests covering target:
- [test 1]
- [test 2]
- [test 3]
If tests are failing:
Cannot refactor - tests are failing.
Failing tests:
- [test names]
Fix failing tests first, then retry refactor.
Use /tdd-dev:bug to fix issues with TDD.
Analyze the target code for improvements:
Code smells to address:
Proposed changes:
Present analysis:
Refactoring Analysis: [target]
Current Issues:
1. [issue]: [description]
2. [issue]: [description]
Proposed Refactorings:
1. [refactoring]: [benefit]
2. [refactoring]: [benefit]
Proceed with refactoring? (Each step verified by tests)
For each proposed refactoring:
Refactoring Step [N]: [description]
Change: [what was modified]
Tests: X passed, 0 failed
Status: GREEN ✓ (refactoring safe)
Apply as appropriate:
If any test fails after a change:
Refactoring REVERTED: [step description]
Reason: Test failure after change
Failing test: [test name]
Options:
1. Try smaller refactoring step
2. Skip this refactoring
3. Investigate test coupling
During refactoring:
Refactoring: [target]
Step [N]/[total]: [transformation]
Before: [brief description]
After: [brief description]
Tests: PASS ✓
When refactoring is complete:
Refactoring Complete: [target]
Changes Applied:
1. [change 1]
2. [change 2]
3. [change 3]
Files Modified: [list]
Tests: X passed, 0 failed
Final Status: GREEN ✓
Code quality improved while maintaining all behavior.
If behavior change is needed:
Note: Requested change appears to modify behavior, not just structure.
This requires a test change. Use:
- /tdd-dev:feature for new behavior
- /tdd-dev:bug for fixing incorrect behavior
Continue with structure-only refactoring? (y/n)
If target code lacks test coverage:
Warning: Limited test coverage for [target]
Existing tests may not catch regressions.
Options:
1. Add tests first (recommended)
2. Proceed carefully with manual verification
3. Abort refactoring
Recommendation: Use /tdd-dev:feature to add test coverage first.
Begin safe refactoring process.