cs-refactor

Guides behavior-preserving code refactoring through scan, design, and apply phases with human checkpoints.

Updated Jun 8, 2026
One-click install
npx skills add https://github.com/wildlily1021/XW_Software --skill cs-refactor-wildlily1021
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cs-refactor
Source: https://github.com/wildlily1021/XW_Software/tree/main/.agents/skills/cs-refactor
Command: npx skills add https://github.com/wildlily1021/XW_Software --skill cs-refactor-wildlily1021

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? AI-driven refactoring often fails in two ways: it changes observable behavior because it lacks context about real constraints, or it takes on too much scope and loses track of earlier decisions. This Skill inserts a structured scan-design-apply workflow between "wanting to optimize" and "editing code", so refactoring stays behavior-equivalent and reviewable. ## Core Features & Use Cases - Three-phase gated workflow: scan produces a quantified optimization checklist for user selection, design maps each item to a numbered refactoring method, and apply executes one step at a time with mandatory human sign-off. - Refusal routing: seven pre-checks stop the process when the request mixes in behavior changes, lacks test coverage, spans modules, is style-only, targets generated code, or is too large, and route the user to the right workflow instead. - Method library: a four-layer catalog (L1 safe migration, L2 Fowler-style code refactors, L3 structural splits, L4 performance) with applicability, steps, risks, and verification for each method. - Use Case: A user says "this 400-line Vue monitor component is too long". The Skill scans the component, lists measurable issues (line counts, cyclomatic complexity, mixed container/presentational logic), lets the user pick items, then applies component splitting and composable extraction step by step with tests run after each step. ## Quick Start Ask the AI to refactor a specific file or component, for example: "Refactor the serial monitor component, it's too long and mixes data logic with rendering."

Frequently Asked Questions about cs-refactor

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

FAQPage Schema
How do I refactor a large Vue component without breaking behavior?▼

Run the scan phase to list measurable issues like line count over 300 or mixed container and presentation logic, then select items and apply component splitting or composable extraction one step at a time. Each step runs tests and requires your confirmation before proceeding.

What is the difference between the standard refactor flow and fastforward mode?▼

Fastforward mode handles single-function or one-to-three-point changes with existing test coverage, skipping the scan and design documents. Anything spanning multiple files, changing public interfaces, or lacking tests must use the full three-phase flow.

When does the refactoring process refuse to proceed?▼

It stops when the request mixes in behavior changes, the target lacks test coverage, problems span modules, issues are purely stylistic, files are generated or third-party, scope exceeds 15 files or 3000 lines, or fewer than three worthwhile items are found.

Can I refactor code that has no tests?▼

Not directly. The workflow requires writing characterization tests first, which record current outputs for real inputs as assertions, so every subsequent refactoring step can prove behavior equivalence against the captured baseline.

What refactoring methods does the method library cover?▼

The library covers four layers: safe migration patterns like Parallel Change and Strangler Fig, classic Fowler refactors like Extract Function and Guard Clauses, structural splits like component and service layer extraction, and performance techniques like memoization, N+1 elimination, and list virtualization.