refactor

Refactor code to fix DRY, SOLID, and structure violations while preserving behavior.

1|Updated May 12, 2026
One-click install
npx skills add https://github.com/mystilleef/spae-framework --skill refactor-mystilleef
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/mystilleef/spae-framework/tree/main/skills/refactor
Command: npx skills add https://github.com/mystilleef/spae-framework --skill refactor-mystilleef

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Codebases accumulate duplication, oversized classes, and tangled dependencies that slow development and hide bugs. This Skill performs disciplined, semantics-preserving refactoring that removes DRY, SOLID, and structural violations without changing observable behavior. ## Core Features & Use Cases - Violation Catalog: Detects 24 named code smells across DRY, SRP, OCP, LSP, ISP, DIP, KISS, YAGNI, idiomatic, hygiene, and structure categories, each paired with a specific fix and pitfall warning. - Gated Workflow: Follows a GATE → ORIENT → PLAN → ACT → VERIFY → REPORT loop that requires a passing test suite before and after every transformation. - Safety Constraints: Enforces zero behavioral change, forbids editing build configs or suppressing linter diagnostics, and reverts edits if the suite cannot return to green. - Use Case: Point it at a module with duplicated logic and a god class; it extracts shared functions, splits responsibilities one transformation at a time, and reports a terse execution summary. ## Quick Start Ask the agent to refactor the current uncommitted changes or a specific file to remove duplication and SOLID violations while keeping all tests passing.

Frequently Asked Questions about refactor

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

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

Confirm the existing test suite passes first, then apply one transformation at a time such as Extract Function or Move Logic to Correct Layer, running the full suite after each step. If any criterion fails, backtrack to the last known-good state and retry.

How to fix SOLID violations in a codebase?▼

Detect violations using a catalog of signals: god classes indicate SRP issues, type-dispatch conditionals indicate OCP issues, and concrete instantiation in domain logic indicates DIP issues. Apply the paired fix such as splitting classes, replacing conditionals with polymorphism, or injecting abstractions.

When should I extract duplicated code into a shared function?▼

Apply the Rule of Three: extraction triggers at the third instance of duplicated logic. Security and validation logic are the exception and warrant unification at two or more occurrences to avoid divergent behavior.

Can refactoring proceed if the test suite is already failing?▼

No. Failing code must be stabilized before refactoring begins, since the suite serves as the authoritative baseline. The refactor aborts if no green baseline exists, and every pass must end with the suite green or the edits reverted.

What should I do when refactoring exposes a pre-existing bug?▼

Treat the exposed bug as out-of-scope. Revert the edits that surfaced it, report the bug as a separate finding, and never fix it in the same pass, since refactoring must never mix behavior changes with structural changes.