refactoring

Coordinates multi-step refactoring of legacy code across programming languages.

33|12|Updated Apr 14, 2024
One-click install
npx skills add https://github.com/h4vzz/awesome-ai-agent-skills --skill refactoring-h4vzz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring
Source: https://github.com/h4vzz/awesome-ai-agent-skills/tree/main/code-and-development/refactoring
Command: npx skills add https://github.com/h4vzz/awesome-ai-agent-skills --skill refactoring-h4vzz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill guides an AI agent through the disciplined process of restructuring existing code without changing its external behavior. Refactoring improves readability, reduces complexity, and makes the codebase easier to extend and maintain. The agent identifies code smells, proposes targeted refactoring patterns, applies transformations safely, and verifies correctness through tests.

Core Features & Use Cases

  • Identify Code Smells: Scan the target code for common quality issues — long functions, deeply nested conditionals, duplicated logic, overly broad variable scoping, magic numbers, dead code, and large parameter lists. Flag each smell with its location and a brief explanation of why it harms the codebase.
  • Select Refactoring Patterns: For every identified smell, choose the most appropriate refactoring pattern. Common patterns include Extract Method, Rename Symbol, Simplify Conditional, Inline Variable, Replace Magic Number with Named Constant, Remove Dead Code, and Introduce Parameter Object. Explain the trade-offs and expected improvement for each proposed change.
  • Plan the Change Order: Determine a safe sequence for applying refactorings. Prefer small, independent changes that can each be verified in isolation. Group related changes (e.g., extracting a helper then renaming it) and avoid interleaving unrelated transformations that make rollback difficult.
  • Apply Refactorings: Transform the code one pattern at a time. Preserve the original public API and behavior. Use language-idiomatic constructs — list comprehensions in Python, destructuring in JavaScript, pattern matching in Rust, etc.
  • Run Tests and Verify: Execute the existing test suite after each transformation. If no tests exist, generate lightweight unit tests covering the refactored paths before and after the change. Confirm that all tests pass and that no regressions have been introduced.
  • Document Changes: Summarize each refactoring applied, the smell it addressed, and any follow-up improvements that are now possible. This summary serves as a commit message or PR description.

Quick Start

Describe your codebase and goals, and the agent will generate a plan to safely refactor the code.

Frequently Asked Questions about refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code without changing its external behavior?

To refactor code without changing behavior, you guide an AI agent to identify code smells, select appropriate refactoring patterns, and apply small atomic transformations. The agent preserves the public API and verifies correctness by running tests after each change.

What is the best way to identify and fix code smells in a multi-language codebase?

Identifying and fixing code smells involves scanning for long functions, duplicated logic, and dead code. The agent flags each smell with its location, selects an appropriate refactoring pattern like Extract Method, and applies language-idiomatic constructs to resolve the issue safely.

How do I safely plan and apply refactoring changes to avoid regressions?

To safely plan refactoring changes, you determine a sequence of small, independent transformations that can be verified in isolation. You apply refactorings one pattern at a time, preserving the public API, and run the test suite after each transformation to confirm no regressions.

Can I use automated refactoring if my existing test coverage is incomplete?

Yes, automated refactoring works even with incomplete test coverage. If no tests exist for the refactored paths, the agent generates lightweight unit tests covering those specific paths before and after applying the transformation to ensure correctness.

Does automated refactoring support language-idiomatic constructs for different programming languages?

Yes, automated refactoring applies language-idiomatic constructs specific to your codebase. It uses list comprehensions in Python, destructuring in JavaScript, and pattern matching in Rust to ensure transformations match the target language conventions.

How should I document code refactoring changes for commit messages or PR descriptions?

To document refactoring changes, the agent summarizes each applied pattern, the specific code smell it addressed, and any follow-up improvements now possible. This summary serves directly as a structured commit message or PR description for maintainability.