Refactor Skill - Unified Agent v2.0
Lazy-loaded skill - Only loaded when explicitly invoked via
/studio refactor
🛠️ Standard Tool Kit
✅ RECOMMENDED: grepai search "pattern" | /toolkit search "query"
✅ FOR READING: Read tool (optimized for file access)
✅ FOR EDITING: Edit tool (precise string replacement)
✅ FOR WRITING: Write tool (new file creation)
Tool Selection Guide
| Need | Tool | Example |
|---|---|---|
| Search code | grepai search or /toolkit search |
Find patterns across files |
| Read file | Read tool |
Access file contents |
| Edit code | Edit tool |
Replace specific strings |
| Create file | Write tool |
New file with content |
Quick Reference
| Mode | Usage | Best For |
|---|---|---|
--quick |
Auto-fix low-risk items | Safe, fast improvements |
--full |
Complete refactoring workflow | Comprehensive changes |
--analyze |
Analysis only | Understanding code health |
--profile |
Performance profiling | Optimization work |
--security |
OWASP Top 10 scan | Security audits |
--types |
TypeScript improvement | Type safety |
Examples
# Quick cleanup for low-risk items
/studio refactor --quick
# Complete workflow on recent changes
/studio refactor --full --scope=recent
# Performance profiling
/studio refactor --profile --scope=all
# Security audit on auth module
/studio refactor --security --scope=directory:src/auth
# Type safety improvement
/studio refactor --types --scope=recent
Scope Options
| Scope | Description | Example |
|---|---|---|
recent |
Recent changes only | Default mode |
file:PATH |
Specific file | --scope=file:src/auth/jwt.ts |
directory:PATH |
Entire directory | --scope=directory:src/features/auth |
all |
Entire codebase | --scope=all |
bug |
Bug fixing | --scope=bug "TypeError in auth" |
Mode Details
--quick (Quick Mode)
Purpose: Auto-fix low-risk items with confidence
When to Use:
- Risk score < 30
- Complexity < 8
- Test coverage > 80%
What it does:
- Identifies safe improvements
- Applies refactoring patterns
- Tests after each change
- Commits verified changes
--full (Full Mode - Default)
Purpose: Complete refactoring workflow
Workflow:
- ANALYZE - Detect issues
- REVIEW - Classify and prioritize
- RESOLVE - Apply changes
- VERIFY - Validate results
--analyze (Analysis Only)
Purpose: Understand code health without changes
Analysis includes:
- Complexity metrics (cyclomatic, cognitive)
- Duplication detection
- Code smell identification
- Maintainability assessment
--profile (Performance Profiling)
Purpose: Identify and fix performance bottlenecks
When to Use:
- Functions are slow
- Memory usage is high
- Need optimization metrics
Workflow:
- Measure current performance
- Identify bottlenecks
- Apply optimizations
- Verify improvement
--security (Security Scanning)
Purpose: Detect and fix security vulnerabilities
OWASP Top 10 Checked:
- Injection attacks (SQL, NoSQL, XSS)
- Authentication/Authorization issues
- Sensitive data exposure
- Cryptographic failures
- Dependency vulnerabilities
Severity Levels:
- P0 - Critical (immediate fix)
- P1 - High (fix ASAP)
- P2 - Medium (fix soon)
- P3 - Low (fix when possible)
--types (TypeScript Improvement)
Purpose: Improve type safety and eliminate any
What it does:
- Replaces
anywith proper types - Adds Zod validation at boundaries
- Removes unsafe type assertions
- Improves type coverage
Success Criteria:
- Zero
anyin production code - Type coverage ≥ 95%
tsc --strictpassing
Core Principles
- Safety First - Validate all changes before implementation
- Incremental - Small, verifiable steps
- Evidence-Based - Use metrics to guide decisions
- Test Continuously - Run tests after each change
- Document Thoroughly - Explain what and why
Success Criteria
Universal
- ✅ All tests passing
- ✅ No type errors
- ✅ Complexity reduced
- ✅ No regressions
- ✅ Documentation complete
Mode-Specific
| Mode | Additional Criteria |
|---|---|
--profile |
Performance improved ≥ 20% |
--security |
All P0/P1 vulnerabilities fixed |
--types |
Zero any, coverage ≥ 95% |
Best Practices
- Always analyze first - Understand issues before acting
- Validate changes - Never skip validation step
- Start with quick wins - Build momentum
- Test continuously - After each small change
- Commit logically - Small, reviewable commits
- Document thoroughly - Explain reasoning
Full Documentation
For complete documentation including advanced patterns, subagent collaboration, and configuration options, see the main refactor skill.
Version: 2.0.0 | Lazy Load: Enabled