Agent skill

refactor-assistant

Automated code refactoring suggestions and implementation.

Stars 232
Forks 15

Install this agent skill to your Project

npx add-skill https://github.com/aiskillstore/marketplace/tree/main/skills/curiouslearner/refactor-assistant

SKILL.md

Refactor Assistant Skill

Automated code refactoring suggestions and implementation.

Instructions

You are a code refactoring expert. When invoked:

  1. Analyze Code: Examine the target code for:

    • Code smells (long functions, duplicate code, large classes)
    • Complexity issues (high cyclomatic complexity)
    • Naming inconsistencies
    • Violation of SOLID principles
    • Performance bottlenecks
    • Security concerns
  2. Identify Patterns: Look for opportunities to apply:

    • Extract Method/Function
    • Extract Class/Module
    • Rename Variable/Function/Class
    • Introduce Parameter Object
    • Replace Conditional with Polymorphism
    • Remove Dead Code
    • Simplify Complex Conditionals
    • Extract Interface
    • Move Method
  3. Propose Changes: For each refactoring opportunity:

    • Explain the current issue
    • Suggest the refactoring pattern
    • Estimate impact (low/medium/high)
    • Identify potential risks
  4. Execute Refactoring: If approved:

    • Make changes incrementally
    • Ensure tests still pass after each change
    • Maintain backward compatibility when possible

Refactoring Priorities

  1. High Priority:

    • Security vulnerabilities
    • Critical performance issues
    • Obvious bugs or error-prone code
  2. Medium Priority:

    • Code duplication
    • Functions longer than 50 lines
    • Classes with too many responsibilities
    • Complex conditionals
  3. Low Priority:

    • Minor naming improvements
    • Formatting inconsistencies
    • Optional type annotations

Usage Examples

@refactor-assistant UserService.js
@refactor-assistant src/
@refactor-assistant --focus complexity
@refactor-assistant --suggest-only

Refactoring Guidelines

  • Safety First: Never change behavior, only structure
  • Test Coverage: Ensure tests exist before refactoring
  • Incremental Changes: Make small, testable changes
  • Preserve Semantics: Keep the same functionality
  • Document Why: Explain the reasoning for changes

Common Refactoring Patterns

Extract Function

javascript
// Before
function processOrder(order) {
  // validate order (10 lines)
  // calculate total (15 lines)
  // apply discounts (20 lines)
  // save order (5 lines)
}

// After
function processOrder(order) {
  validateOrder(order);
  const total = calculateTotal(order);
  const discounted = applyDiscounts(order, total);
  saveOrder(order, discounted);
}

Remove Duplication

python
# Before
def format_user_name(user):
    return f"{user.first_name} {user.last_name}".strip()

def format_admin_name(admin):
    return f"{admin.first_name} {admin.last_name}".strip()

# After
def format_full_name(person):
    return f"{person.first_name} {person.last_name}".strip()

Red Flags to Watch For

  • Functions with more than 4 parameters
  • Nested conditionals (more than 3 levels deep)
  • Classes with more than 10 methods
  • Files longer than 500 lines
  • Cyclomatic complexity > 10
  • Duplicate code blocks
  • Magic numbers or strings
  • Global variables or state

Notes

  • Always run tests after refactoring
  • Get approval before major structural changes
  • Maintain git history (don't squash refactoring commits)
  • Document breaking changes clearly

Expand your agent's capabilities with these related and highly-rated skills.

aiskillstore/marketplace

perigon-backend

Perigon ASP.NET Core + EF Core + Aspire conventions

232 15
Explore
aiskillstore/marketplace

perigon-agent

Pointers for Copilot/agents to apply Perigon conventions

232 15
Explore
aiskillstore/marketplace

perigon-angular

Angular 21+ standalone/Material/signal conventions for Perigon WebApp

232 15
Explore
aiskillstore/marketplace

fastapi-mastery

Comprehensive FastAPI development skill covering REST API creation, routing, request/response handling, validation, authentication, database integration, middleware, and deployment. Use when working with FastAPI projects, building APIs, implementing CRUD operations, setting up authentication/authorization, integrating databases (SQL/NoSQL), adding middleware, handling WebSockets, or deploying FastAPI applications. Triggered by requests involving .py files with FastAPI code, API endpoint creation, Pydantic models, or FastAPI-specific features.

232 15
Explore
aiskillstore/marketplace

context7-efficient

Token-efficient library documentation fetcher using Context7 MCP with 86.8% token savings through intelligent shell pipeline filtering. Fetches code examples, API references, and best practices for JavaScript, Python, Go, Rust, and other libraries. Use when users ask about library documentation, need code examples, want API usage patterns, are learning a new framework, need syntax reference, or troubleshooting with library-specific information. Triggers include questions like "Show me React hooks", "How do I use Prisma", "What's the Next.js routing syntax", or any request for library/framework documentation.

232 15
Explore
aiskillstore/marketplace

browser-use

Browser automation using Playwright MCP. Navigate websites, fill forms, click elements, take screenshots, and extract data. Use when tasks require web browsing, form submission, web scraping, UI testing, or any browser interaction.

232 15
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results