agentleFS
rpraharajrpraharaj/ai-engineer/skills/refactor-safely/SKILL.md

refactor-safely

Skill1 starsChanged 15 days agoMITView on GitHub

Behavior-preserving cleanup — lock behavior with tests, refactor mechanically, re-run the same tests. Use when the user asks to refactor, clean up, simplify, or restructure without changing behavior.

19 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use audit-test-suite, change-data-safely and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • yaohuangguanSkill

    audit-test-suite

    Find where an existing test suite is weak and decide what to test next, ranked by risk. Use this when asked to add missing tests, find gaps, raise coverage, assess test quality or see which areas are thin, even if the request only mentions a coverage percentage.

    Also in 3 projects that use this

  • yaohuangguanSkill

    change-data-safely

    Change a database schema or stored data without breaking running code or losing data. Use this for any migration, new or changed column, backfill, bulk update, delete, index, or change to a stored format, including in small projects. Data mistakes are often impossible to undo.

    Also in 3 projects that use this

  • SauravSrivastavSkill

    debug-failure

    Diagnose a failing test, command, or runtime behavior using evidence and produce a minimal verified fix.

    Also in 3 projects that use this

  • NVIDIASkill

    debug-issue

    Use when the user asks to debug, investigate, or fix a GitHub issue or supplies a repository bug report.

    Also in 5 projects that use this

  • +6 more from yaohuangguan

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read AGENTS.md if present.

    line 14
  2. Very specific:

    If coverage is too thin to notice a break, add characterization tests first with write-tests (assert current behavior, including odd edges).

    line 20
  3. Very specific:

    Run those tests once. That green run is the baseline.

    line 22
  4. Distinctive:

    No new framework, no new caching, no "while we are here" feature flags.

    line 33
  5. Distinctive:

    Run Test (and Lint / Typecheck if known) from AGENTS.md.

    line 46
  6. Very specific:

    Do not commit unless asked.

    line 56

“Common” is measured: kept by at least 6 in 10 of the 17 edited versions of this file we could read. “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

Refactor safely

Change structure, not behavior. If the user also wants new behavior, stop and send that part to shape-work / implement-change. Do not mix the two in one diff.

Read AGENTS.md if present.

Step 1 — Pin behavior

Name the unit (files, package, endpoint) and the behavior that must stay true. Prefer existing tests that already cover it.

If coverage is too thin to notice a break, add characterization tests first with write-tests (assert current behavior, including odd edges). Do not "improve" those assertions until after the refactor.

Run those tests once. That green run is the baseline. If they are red, this is debug, not a refactor.

Step 2 — Plan the moves

List mechanical steps. Each step should be boring. Climb Minimum path in engineering-bar: delete dead flexibility, replace hand-rolls with stdlib/native, inline a one-implementation abstraction.

  • Extract a helper that already exists inlined
  • Move a type to the layer that owns it
  • Collapse a duplicate
  • Rename inside the unit (update all callers in the same change)

No new framework, no new caching, no "while we are here" feature flags. Never delete trust-boundary checks or data-loss handling to look smaller.

Load engineering-bar (paths in that skill). The bar's structure rules apply; its correctness rule here means same results, not new acceptance checks.

Step 3 — Refactor

One cluster of moves, then re-run the same tests. Do not take the suite red across many unrelated files.

Stay inside the named unit plus its callers. Do not reformat files you did not otherwise touch.

Step 4 — Prove sameness

  1. Re-run the characterization / existing tests. They must pass.
  2. Run Test (and Lint / Typecheck if known) from AGENTS.md.
  3. Diff review: every change should be structural. If a conditional's meaning changed, revert that part or admit it is a behavior change and stop.

Done

  1. Behavior that was pinned
  2. Moves made (files)
  3. Tests run (baseline + after) and results
  4. Any leftover cleanup you did not do

Do not commit unless asked. If the user wants this shipped: ready-to-merge then commit.

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.