refactor-code

Restructure a specific code target while preserving caller-visible behavior and external contracts.

Updated May 19, 2026
One-click install
npx skills add https://github.com/wenyue/SmartKit --skill refactor-code-wenyue
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactor-code
Source: https://github.com/wenyue/SmartKit/tree/main/docs/zh-CN/skills/refactor-code
Command: npx skills add https://github.com/wenyue/SmartKit --skill refactor-code-wenyue

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It guides safe, behavior-preserving refactoring of a concrete code target, ensuring internal restructuring never changes what supported callers or external consumers observe, and routing out-of-scope requests to the right workflow before any write happens. ## Core Features & Use Cases - Pre-write triage: Classifies requests before writing, handing pure renames to rename-code, open-ended architecture exploration to improve-codebase-architecture, and substantive interface decisions to codebase-design, while rejecting out-of-scope behavior or contract changes. - Boundary establishment: Identifies supported call boundaries, invariants, external contracts, affected callers, owners of generated surfaces, and the minimum preservation evidence needed before restructuring. - Evidence-based verification: Runs discriminating preservation checks and owner-required surface checks after restructuring, returning completed, failed, blocked, handed-off, or out-of-scope outcomes with a structured handoff. - Use Case: You want to split a bloated internal module into cohesive units without changing its public API. The Skill confirms the boundaries, restructures the internals, migrates internal callers, retires dead code, and proves behavior is unchanged with targeted tests. ## Quick Start Ask the agent to refactor a specific module or class to remove a named structural problem while keeping its public behavior and external contracts unchanged.

Frequently Asked Questions about refactor-code

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

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

Define the supported call boundaries and their observable behavior first, then restructure only internal implementations and internal callers. Run discriminating preservation checks and owner-required surface checks to prove behavior, invariants, and external contracts remain unchanged.

What is the difference between refactoring and renaming code?▼

Pure symbol or tracked-path renames, including public names and externally observable paths, belong to a dedicated rename workflow that owns compatibility decisions. Refactoring covers internal restructuring that keeps caller-visible behavior and contracts intact.

When should a refactoring request be rejected as out of scope?▼

Any non-rename change to caller-visible behavior or external contracts is out of scope, including public interfaces, persistence, protocols, integrations, and user-visible behavior. Those changes must go through a different workflow.

Can refactoring modify generated code surfaces?▼

Generated surfaces can only change through their established owner, and only when the required operations are authorized. Without that ownership path or authorization, the work stops with a blocked result before any write.

What happens if refactoring checks fail after changes are written?▼

If required checks cannot pass or run, preservation evidence loses discriminating power, or no in-scope fix exists, the result is failure. Useful state and evidence are preserved, and no rollback permissions are assumed.