agentsclimarketplace

Safe refactor

Skill roronoazoroshao369/vibe-coding-os/skills/core/safe-refactor

Vibe Coding OS — Claude/Codex/Cursor skill framework with 139 skills, 111 commands, 95 templates, 22 tracked sources, 28/28 validation gates PASS. Quality Shield, Engineering Discipline Pack, plugin marketplace.

Install
npx -y skills add roronoazoroshao369/vibe-coding-os --skill safe-refactor

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

4.9 KB, as published. Nobody here has run it

Skill: Safe Refactor

Purpose

Provide a 5-phase protocol for refactoring existing code without breaking behavior. Covers the full lifecycle: characterize → cover → extract → migrate → cleanup. The protocol guarantees that every refactor step is reversible, testable, and produces a measurable diff. Use when touching code that has existing behavior, callers, or tests you cannot break.

When to use

Use when:

  • A code smell is identified (long function, deep nesting, leaky abstraction, repeated logic) and the team has agreed to refactor.
  • An upstream API or contract is being changed.
  • A "while we're here" rewrite threatens to merge behavioral changes with structural changes.
  • Code needs to be split, renamed, moved across modules, or have its dependency direction reversed.

Do NOT use when:

  • The change is a bug fix (use bug-fix-lifecycle).
  • The change is a new feature (use write-reusable-skill or feature workflow).
  • The behavior itself is wrong — fix the behavior first, then refactor.

Inputs

  • The code to refactor (file path or diff).
  • Existing test coverage (or explicit acknowledgment that coverage is missing).
  • The smell or pattern being addressed (long function, deep coupling, etc.).
  • The target shape (what "good" looks like).
  • Rollback strategy if the refactor must be reverted.

Workflow

  1. Characterize — capture current behavior with tests, traces, or property assertions. If no tests exist, write characterization tests FIRST. Record observable outputs for representative inputs.
  2. Cover — confirm the characterization tests pass on the current code. Coverage must be ≥ 80% for the area being refactored before proceeding. If below 80%, stop and add coverage.
  3. Extract — perform the smallest safe change that moves toward the target shape. One rename, one extract-method, one move-class per commit. Each commit must leave tests green.
  4. Migrate — update callers, dependents, and contracts to use the new shape. Run the full test suite after each migration step. If any test fails, the refactor is wrong; revert and re-characterize.
  5. Cleanup — delete the old code path, remove dead branches, remove commented-out code. Final verification: characterization tests still pass + new tests for the new shape pass + no behavioral diff.

Outputs

  • A commit chain where each commit is independently revertible.
  • A diff summary: lines added, lines removed, files touched, public surface changed.
  • A characterization test suite that pins behavior before and after.
  • A rollback note: which commit to revert to if the refactor must be abandoned.

Failure modes

  • Refactoring without characterization tests — silent behavior change ships.
  • Mixing refactor with bug fixes — bug fix and structural change become inseparable; rollback becomes impossible.
  • Skipping the "each commit must leave tests green" rule — debugging a multi-step refactor mid-flight is expensive.
  • Confusing "the new shape is cleaner" with "the refactor is correct" — cleanliness is not a verification gate.
  • Leaving dead code "temporarily" — temporary becomes permanent; cleanup must happen in the same PR.
  • Not updating the registry/index — refactored paths become orphans; traceability gate fails.

Verification checklist

  • Characterization tests written and passing BEFORE any structural change.
  • Coverage of the refactored area is ≥ 80% before the refactor starts.
  • Each refactor commit leaves npm run validate:all green.
  • Each refactor commit leaves the characterization test suite green.
  • Public surface (exported names, public methods, route paths, CLI flags) is documented in the diff.
  • No behavioral diff: characterization tests pass on both old and new code.
  • Registry/index updated: skill paths in registry/skills.json, command paths in registry/commands.json, template paths in registry/templates.json all reflect the refactor.
  • npm run validate:traceability -- --strict-new passes (no new orphans introduced).
  • PR description lists: smell addressed, target shape, commits in the chain, rollback commit hash.

Related skills

  • skills/core/bug-fix-lifecycle/SKILL.md — for the "fix bug first" rule (refactor never carries a fix).
  • skills/core/verification-before-done/SKILL.md — 5-axis verification includes refactor-safety axis.
  • skills/core/quality-engine/SKILL.md — quality-engine runs after every refactor commit.
  • templates/refactor-plan.md — refactor PR worksheet.
  • commands/vibe-refactor.md — the canonical command to start a refactor.

Attribution

Pattern adapted from Michael Feathers' Working Effectively with Legacy Code (characterization tests) and Martin Fowler's Refactoring (commit-per-step discipline), in original wording.

Gives 0 of the 12 instructions most refactoring skills give

Counted across 521 of the 525 authors here whose files we hold, read 2026-08-06

  • run tests after each changein 59 of 521, across 56 files
  • write tests before refactoringin 27 of 521, across 24 files
  • preserve external behaviorin 26 of 521, across 22 files
  • remove dead codein 25 of 521, across 24 files
  • make small incremental changesin 20 of 521, across 17 files
  • break the implementation into tiny commitsin 18 of 521, across 5 files
  • ask the user about alternative optionsin 17 of 521, across 4 files
  • create a GitHub issue with the planin 17 of 521, across 4 files
  • explore the repository to verify assertionsin 17 of 521, across 4 files
  • interview the user about the refactorin 16 of 521, across 3 files
  • check the codebase for test coveragein 16 of 521, across 3 files
  • refactor one thing at a timein 16 of 521, across 12 files

Said here and by no other author read

  • ensure test coverage is at least 80 percent before proceeding
  • perform the smallest safe change per commit
  • run the full test suite after each migration step
  • revert and recharacterize if any test fails
  • update the registry index after refactoring
  • list smell addressed and rollback commit hash in PR description

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.