refactor-code

Restructure production code while preserving observable behavior and proving preservation with tests.

Updated Sep 3, 2026
One-click install
npx skills add https://github.com/JonusNattapong/A2A-MCP --skill refactor-code-jonusnattapong
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactor-code
Source: https://github.com/JonusNattapong/A2A-MCP/tree/main/src/agenttalk/skills/devkit/refactor-code
Command: npx skills add https://github.com/JonusNattapong/A2A-MCP --skill refactor-code-jonusnattapong

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Refactoring often introduces accidental behavior changes that are hard to detect and review. This Skill enforces a disciplined workflow for restructuring code—simplifying boundaries, reducing duplication, improving names and module layout—while explicitly proving that observable behavior stays unchanged. ## Core Features & Use Cases - Behavior-Preservation Scope: Requires stating upfront which observable behaviors, interfaces, data formats, and error behaviors must remain identical before any edit. - Incremental Mechanical Steps: Guides small, reviewable changes like renaming, extracting, inlining, and deduplicating without mixing in features or fixes. - Production-Handoff Evidence: Emits a structured evidence record with changed files, base/head refs, tests executed, residual risk, and required review lenses. - Use Case: When asked to clean up a tangled module in a repository, the Skill establishes a test baseline, refactors in small steps, reruns the same tests, and hands off a reviewable diff with proof nothing changed behaviorally. ## Quick Start Ask the agent to refactor the specified module to reduce duplication and improve naming without changing any behavior, and require a production-handoff evidence record when done.

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 behavior?▼

State the behavior-preservation scope first, covering observable behavior, public interfaces, data formats, and error behavior. Then make small mechanical edits like renaming, extracting, and deduplicating, and run the same tests before and after to prove preservation.

What is the difference between refactoring and bug fixing?▼

Refactoring restructures code with no intended behavior change, while bug fixes deliberately alter behavior. This Skill explicitly excludes bug fixes and feature work; behavior-changing work should be routed to a craft-code style workflow instead.

When should I not use a behavior-preserving refactoring workflow?▼

Avoid it for feature work, bug fixes, making failing CI checks green, writing broad test coverage as the main task, or reviewing an existing diff. It is only for narrowly scoped cleanup where preservation can be proven.

What if the existing tests fail before I start refactoring?▼

Do not refactor on a red baseline. Route the failing checks to a fix-ci style workflow first, since a broken baseline makes it impossible to prove the refactor preserved behavior.

How do I prove a refactor preserved behavior when tests are incomplete?▼

Add only the narrow characterization tests needed to prove the specific refactor, or hand broader test work to a test-coverage workflow. If exact proof is impossible, state the gap, why it remains acceptable, and what evidence was still collected.