refactoring-assistant
npx machina-cli add skill a5c-ai/babysitter/refactoring-assistant --openclawRefactoring Assistant Skill
Suggests appropriate refactoring patterns and guides their application to improve code quality, maintainability, and migration readiness.
Purpose
Enable guided refactoring for:
- Code quality improvement
- Design pattern application
- Migration preparation
- Technical debt reduction
- Maintainability enhancement
Capabilities
1. Extract Method/Class Suggestions
- Identify extraction candidates
- Suggest method boundaries
- Recommend class decomposition
- Guide interface extraction
2. Move Method Recommendations
- Detect misplaced methods
- Suggest target classes
- Analyze dependencies
- Guide safe relocation
3. Rename Refactoring
- Suggest meaningful names
- Propagate renames safely
- Handle cross-references
- Update documentation
4. Inline Refactoring
- Identify inline candidates
- Remove unnecessary indirection
- Simplify call chains
- Reduce complexity
5. Pull Up/Push Down Member
- Analyze inheritance hierarchies
- Suggest member movement
- Optimize class hierarchies
- Improve polymorphism
6. Design Pattern Application
- Recognize pattern opportunities
- Guide pattern implementation
- Suggest appropriate patterns
- Validate pattern application
Tool Integrations
| Tool | Purpose | Integration Method |
|---|---|---|
| IDE Refactoring | Automated refactoring | CLI / API |
| Sourcery | AI-powered suggestions | CLI |
| Sourcegraph Cody | Code intelligence | API |
| IntelliJ IDEA | Java refactoring | CLI |
| VS Code | Multi-language | Extension API |
Output Schema
{
"analysisId": "string",
"timestamp": "ISO8601",
"suggestions": [
{
"type": "extract-method|move-method|rename|inline|design-pattern",
"priority": "high|medium|low",
"target": {
"file": "string",
"element": "string",
"line": "number"
},
"description": "string",
"rationale": "string",
"steps": ["string"],
"estimatedImpact": {
"complexity": "string",
"maintainability": "string",
"testability": "string"
},
"risks": ["string"]
}
],
"patterns": {
"applicable": ["string"],
"opportunities": []
}
}
Integration with Migration Processes
- code-refactoring: Primary refactoring guidance
- technical-debt-remediation: Debt reduction strategies
Related Skills
code-smell-detector: Identifies refactoring needscodemod-executor: Automates refactorings
Related Agents
code-transformation-executor: Executes suggested refactorings
Source
git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/code-migration-modernization/skills/refactoring-assistant/SKILL.mdView on GitHub Overview
The Refactoring Assistant suggests targeted refactoring patterns and guides their application to boost code quality, maintainability, and migration readiness. It covers extract/move/rename/inline actions and design-pattern applications to reduce technical debt and improve maintainability.
How This Skill Works
The assistant analyzes code to identify refactoring candidates, proposes concrete patterns and steps, and helps you apply them with tool integrations (IDE refactoring, Sourcery, Sourcegraph Cody, etc.). It emphasizes validating changes through tests and documentation updates to ensure safe migrations.
When to Use It
- When methods become too long or complex, consider Extract Method to improve readability and testability.
- When a class grows large with low cohesion, consider Extract Class or Move Method to better-suited targets.
- When names are vague or misleading, use Rename Refactoring and propagate changes across references and docs.
- When indirection adds complexity, apply Inline Refactoring to simplify call chains.
- When inheritance and polymorphism could be optimized, use Pull Up/Push Down and Design Pattern Application to restructure and improve design.
Quick Start
- Step 1: Run a code-smell detector to surface refactoring candidates (e.g., long methods, large classes, vague names).
- Step 2: Select a candidate and choose a refactoring type (extract, move, rename, inline, design-pattern).
- Step 3: Use integrated tools (IDE Refactoring, Sourcery, Sourcegraph Cody) to apply changes and run tests to verify safety.
Best Practices
- Start with high-impact, low-risk patterns (e.g., Extract Method, Rename) and gradually tackle more invasive changes.
- Analyze dependencies and interfaces before moving or extracting code to avoid ripple effects.
- Run and update tests after each refactoring to catch regressions early.
- Document refactor decisions and rationale to support migration and future maintenance.
- Leverage integrated tooling (IDE Refactoring, Sourcery, Sourcegraph Cody) to automate repetitive steps and enforce consistency.
Example Use Cases
- Extract a 250-line method into smaller, focused methods to improve readability and testability.
- Move Misplaced methods into the class where they best belong, reducing cross-class dependencies.
- Rename a set of utility methods to clearer, domain-aligned names and propagate changes across all call sites and docs.
- Inline a thin wrapper function to remove unnecessary indirection and simplify the call stack.
- Apply a Design Pattern (e.g., Strategy or Factory) to encapsulate configurable behavior and improve extensibility.