home / skills / a5c-ai / babysitter / refactoring-assistant

This skill suggests refactoring patterns and guides their application to improve code quality, maintainability, and migration readiness.

npx playbooks add skill a5c-ai/babysitter --skill refactoring-assistant

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
2.7 KB
---
name: refactoring-assistant
description: Suggest and guide application of refactoring patterns to improve code quality
allowed-tools: ["Bash", "Read", "Write", "Grep", "Glob", "Edit"]
---

# Refactoring 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

```json
{
  "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 needs
- `codemod-executor`: Automates refactorings

## Related Agents

- `code-transformation-executor`: Executes suggested refactorings

Overview

This skill suggests and guides application of refactoring patterns to improve code quality, maintainability, and migration readiness. It diagnoses refactoring opportunities and produces actionable, prioritized suggestions with clear steps and estimated impact. The assistant is designed for JavaScript projects but supports multi-language guidance through IDE and code-intelligence integrations.

How this skill works

The skill analyzes code structure, call chains, and inheritance to identify candidates for extract, move, rename, inline, and pull-up/push-down refactorings. It recommends specific targets (file, element, line), explains rationale, lists step-by-step changes, estimates impact on complexity and testability, and highlights risks. Suggestions follow a standard JSON schema so they can be consumed by automation tools or human reviewers.

When to use it

  • Before or during a migration to reduce coupling and clarify module boundaries
  • When addressing accumulated technical debt or code smells detected by static analysis
  • During code review to propose safe, incremental improvements
  • When applying or validating design patterns across a codebase
  • To prepare legacy code for automated transformation or modernization

Best practices

  • Prioritize high-impact, low-risk refactorings and schedule them with associated tests
  • Apply one refactoring type at a time per change to keep commits reviewable
  • Run and update unit and integration tests after each refactor step
  • Use IDE or codemod tooling for mechanical edits and rely on the assistant for design guidance
  • Document rationale and link suggestions to tickets to preserve context

Example use cases

  • Extract a long method into smaller, testable functions and suggest interfaces for reuse
  • Move a utility method from a UI component into a shared service to reduce coupling
  • Rename confusing identifiers across modules and propagate updates safely
  • Inline trivial wrappers that add unnecessary indirection to simplify call paths
  • Pull up common members into an abstract base to consolidate behavior and reduce duplication

FAQ

Can the assistant run refactorings automatically?

It produces deterministic, machine-readable suggestions ready for automation. Execution requires integration with a refactoring executor or IDE tooling.

How does it assess risk and estimated impact?

Risk and impact are inferred from dependency analysis, test coverage signals, and the scope of affected files; each suggestion includes explicit risks and impact notes.