refactor-safely

Guides behavior-preserving structural refactoring with impact analysis, caller migration, and verification.

7|3|Updated Sep 23, 2025
One-click install
npx skills add https://github.com/islamu-ngo/Event --skill refactor-safely-islamu-ngo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactor-safely
Source: https://github.com/islamu-ngo/Event/tree/main/.agents/skills/refactor-safely
Command: npx skills add https://github.com/islamu-ngo/Event --skill refactor-safely-islamu-ngo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Structural refactors like renames, moves, record/class conversions, and dependency cleanup often break callers, tests, or generated contracts when done without impact analysis. This Skill enforces a disciplined workflow that preserves observable behavior while changing code structure. ## Core Features & Use Cases - Impact-First Analysis: Uses knowledge-graph tools (minimal context, impact radius, affected flows) to map callers and tests before editing any symbol. - Expand-Contract Protocol: Splits wide refactors (database column renames, UUIDv7 identity migration, shared MediatR shape changes) into expand, batch-migrate, and contract phases so CI stays green. - Record/Class Conversion Rules: Classifies identity, equality, serialization, PATCH presence, and collection ownership before converting contracts, with generated C# contracts changed only through the owning generator. - Use Case: When renaming a shared domain type used across multiple projects, load this Skill to preview the rename, lock behavior with a failing regression test, migrate every caller outward, and verify with affected tests and architecture ratchets. ## Quick Start Ask the AI to load the refactor-safely skill and rename a shared domain class across all callers while preserving behavior and keeping tests green.

Frequently Asked Questions about refactor-safely

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

FAQPage Schema
How do I safely rename a class used across multiple projects?▼

Start with knowledge-graph impact analysis to find all callers and tests, then use LSP rename with a preview before editing. Lock current behavior with a failing regression test, apply the rename, and run affected tests plus architecture ratchets to confirm nothing broke.

What is the expand-contract pattern for large refactors?▼

Expand-contract splits a wide refactor into three phases: introduce the new form alongside the old one, migrate callers in bounded batches while CI stays green, then delete the obsolete form once zero callers remain. It avoids one giant risky atomic change.

When should I convert a C# class to a record?▼

Convert only after classifying identity, construction, equality, collection ownership, serialization, PATCH presence, and framework mutation behavior. Change the innermost owning contract first and migrate every caller outward without creating duplicate DTOs or transitional aliases.

Can I edit generated C# client contracts directly during a refactor?▼

No. Generated contracts like EventApiClient.g.cs must change through the owning generator tool and MSBuild, never by hand-editing the generated file. Manual edits are overwritten and break the generation pipeline.

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

Do not use it for feature work, one-line cleanups, or changes that intentionally alter observable behavior. If impact evidence reveals the change is actually feature behavior rather than structural transformation, stop and re-baseline the approach.