refactoring-with-contract-preservation

Restructures code, documents, and data while preserving approved behavior, interfaces, and outputs.

Updated Jul 9, 2026
One-click install
npx skills add https://github.com/alsdmlals4-eng/Base --skill refactoring-with-contract-preservation-alsdmlals4-eng
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring-with-contract-preservation
Source: https://github.com/alsdmlals4-eng/Base/tree/main/skills/refactoring-with-contract-preservation
Command: npx skills add https://github.com/alsdmlals4-eng/Base --skill refactoring-with-contract-preservation-alsdmlals4-eng

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Refactoring often drifts into unintended feature changes, broken interfaces, or schema regressions. This Skill enforces a disciplined workflow that improves internal structure while keeping approved behavior, public interfaces, data compatibility, and outputs exactly as they were. ## Core Features & Use Cases - Baseline Contract Locking: Fixes normal, failure, and boundary behavior plus API, schema, output, and performance baselines before any change. - Guided Smell Audit and Refactor Modes: Follows the sequence baseline-contract, smell-audit, refactor, regression-validate, and report, with a detailed checklist in references for duplication, long units, deep conditionals, and tight coupling. - Regression Evidence Reporting: Produces a structured report separating structural improvements from behavior changes, with preservation evidence and remaining risks. - Use Case: When simplifying a tangled module or an overgrown document, use this Skill to extract functions, merge duplication, and rename unclear units while proving through tests and golden outputs that nothing observable changed. ## Quick Start Refactor this module to reduce duplication and simplify its conditionals while preserving all existing behavior, interfaces, and outputs, then show the regression evidence.

Frequently Asked Questions about refactoring-with-contract-preservation

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

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

Lock a baseline of normal, failure, and boundary behavior plus API, schema, and output expectations first. Then apply small transformations like extraction, renaming, and duplication merging, comparing actual results against the baseline at every step.

What is the difference between refactoring and pruning stale code?

Refactoring improves structure while preserving approved behavior and contracts. Removing unreachable or outdated material is a separate concern handled by a pruning workflow, and intentional feature changes require their own change contract.

Can refactoring be combined with feature changes in one PR?

No. Mixing structural improvements with feature additions, deletions, or policy changes in the same change set is explicitly disallowed, because it makes regression evidence and review unreliable.

What evidence proves a refactoring preserved behavior?

Preservation evidence includes existing tests, characterization tests, golden outputs, schema and API comparisons, storage compatibility checks, representative user flows, and performance baseline comparisons before and after the change.

When does a refactoring attempt fail the quality gate?

It fails when there is no baseline to explain behavior, when features or schemas are changed under the guise of refactoring, when tests are deleted to force a pass, or when the change only adds abstraction layers and file count.