agentleFS
jhonatan-oliveiradevjhonatan-oliveiradev/agent-skills/skills/planning-safe-refactors/SKILL.md

planning-safe-refactors

Skill1 starsChanged 3 months agoMITView on GitHub

Use when a structural refactor crosses multiple modules, dependencies, data flows, or deployments and cannot be completed safely as one atomic change without a large blast radius.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use controlled dual operation only when justified.

    line 18
  2. Distinctive:

    Remove legacy code only after all callers and data paths are migrated and the new path has enough evidence in production-like conditions.

    line 19
  3. Distinctive:

    avoid mixing unrelated cleanup.

    line 26
  4. Distinctive:

    Use Branch by Abstraction when consumers need to migrate gradually behind a stable abstraction.

    line 31
  5. Distinctive:

    Do not add an abstraction when the entire change is already small, local, and safely atomic.

    line 33
  6. Distinctive:

    Before declaring the refactor complete, verify that:

    line 36
  7. Distinctive:

    no intended caller still reaches the legacy path.

    line 38

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Planning Safe Refactors

Core principle

Preserve behavior while changing structure in small, observable steps. Replace big-bang rewrites with a migration path that keeps the system releasable and gives every slice a rollback or containment strategy.

Refactor plan

  1. State the target change and the behaviors that must not change. Separate structural goals from feature work.
  2. Map the blast radius: callers, dependencies, data ownership, runtime flows, tests, deployments, and operational dashboards affected by the change.
  3. Establish characterization evidence around critical behavior before changing the structure. Add regression tests at the boundary that must remain stable.
  4. Find or create a seam. Introduce the smallest interface, adapter, routing point, or compatibility layer that lets old and new structures coexist without changing consumers all at once.
  5. Order migration slices so each one can ship independently. Prefer moving one caller, capability, or data path at a time.
  6. Define verification and rollback for every slice. State what proves equivalence, which telemetry to inspect, and how to return traffic or callers to the old path.
  7. Use controlled dual operation only when justified. Feature flags, shadow reads, comparison runs, or compatibility adapters should have an owner and a removal condition.
  8. Remove legacy code only after all callers and data paths are migrated and the new path has enough evidence in production-like conditions.

Slice quality

A safe slice should:

  • have one observable structural objective;
  • preserve the external contract or version it intentionally;
  • keep main releasable;
  • avoid mixing unrelated cleanup;
  • identify its verification evidence;
  • make the next slice easier rather than creating a second permanent architecture.

Patterns

Use Branch by Abstraction when consumers need to migrate gradually behind a stable abstraction. Use a Strangler Fig approach when a larger legacy capability can be replaced incrementally behind routing or capability boundaries.

Do not add an abstraction when the entire change is already small, local, and safely atomic. Migration scaffolding is temporary complexity and must earn its cost.

Verification

Before declaring the refactor complete, verify that:

  • old and new behavior match for the protected contracts;
  • no intended caller still reaches the legacy path;
  • temporary flags/adapters have an explicit removal decision;
  • obsolete code, configuration, metrics, and tests are removed only after migration evidence is complete.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.