with one click
refactor
Analyze code for SOLID violations and suggest targeted improvements
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Analyze code for SOLID violations and suggest targeted improvements
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
| name | refactor |
| description | Analyze code for SOLID violations and suggest targeted improvements |
| argument-hint | <file_or_module> [--pattern <name>] |
| effort | medium |
| when_to_use | Use when a module has SOLID violations, code smells, or duplication to address. |
| disable-model-invocation | true |
Analyze code for SOLID violations and suggest targeted improvements.
Identify refactoring opportunities based on:
Determine the refactoring scope from user input:
# Get file/directory stats
if [ -f "$TARGET" ]; then
wc -l "$TARGET"
echo "Single file analysis"
elif [ -d "$TARGET" ]; then
find "$TARGET" -type f \( -name "*.ts" -o -name "*.js" -o -name "*.py" \) | wc -l
echo "Directory analysis"
fi
Look for:
# Find large files
find . -name "*.{ts,js,py}" -exec wc -l {} + 2>/dev/null | sort -rn | head -10
# Functions with high line count (approximate)
grep -rn "function\|def \|fn " --include="*.{ts,js,py,rs}" . | head -20
Look for:
Look for:
Look for:
Look for:
new Service())# Duplication patterns
grep -rn --include="*.{ts,js,py}" . 2>/dev/null | \
awk -F: '{print $3}' | sort | uniq -c | sort -rn | head -10
# Long parameter lists (> 4 params)
grep -rn "function.*,.*,.*,.*," --include="*.{ts,js}" . 2>/dev/null | head -10
# Deep nesting (4+ levels)
grep -rn "^\s\{16,\}" --include="*.{ts,js,py}" . 2>/dev/null | head -10
For each issue found, assess:
Target: [file/directory] Lines Analyzed: [count]
| Principle | Status | Issues Found |
|---|---|---|
| Single Responsibility | 🟡 | 3 large classes |
| Open/Closed | 🟢 | OK |
| Liskov Substitution | 🟢 | OK |
| Interface Segregation | 🔴 | 2 fat interfaces |
| Dependency Inversion | 🟡 | 5 direct instantiations |
UserServiceViolation: Single Responsibility Current: 450 lines handling auth + profile + notifications Suggested:
UserService.ts (450 lines)
↓ Extract
AuthService.ts (~150 lines)
ProfileService.ts (~150 lines)
NotificationService.ts (~100 lines)
Risk: Medium (update imports) Tests Needed: Update dependency injection in tests
Location: src/handlers/payment.ts:45
Current:
switch (paymentType) {
case 'card': // 50 lines
case 'bank': // 50 lines
case 'crypto': // 50 lines
}
Suggested: Strategy pattern with PaymentProcessor interface
Risk: Low (isolated change)
| Smell | Location | Severity |
|---|---|---|
| Long Method | api.ts:calculateTotal (120 lines) | 🟠 High |
| Duplicate Code | utils/*.ts (3 similar blocks) | 🟡 Medium |
| Deep Nesting | parser.ts:parse (6 levels) | 🟡 Medium |
validateEmail() to shared utils (used in 4 places)processOrder()Before applying suggestions:
Analyze specific file:
/refactor src/services/user.ts
Analyze directory:
/refactor src/api/
Focus on specific principle:
/refactor --focus=srp src/services/
With complexity threshold:
/refactor --threshold=high
$ARGUMENTS
Autonomous improvement loop: scan codebase metrics, scaffold experiment files, run agent-driven iterations until metric improves
Post-deploy monitoring: watch production after a deploy and alert on regressions
Systematic root-cause debugging: find the cause before writing any fix
Strategic product gate: challenge the brief, find the 10-star product hiding inside the request, before writing any code
Engineering architecture gate: lock architecture, diagrams, edge cases, and test matrix before writing implementation code
Orchestrates the complete planning pipeline: product direction (ceo-review) -> architecture (eng-review) -> implementation plan (start) -> validation (validate) -> execution (execute). Run stages individually or let the orchestrator coordinate the full flow.