agentleFS
agentkitcoagentkitco/agentkit-dev-skills/skills/safe-refactor/SKILL.md

safe-refactor

Skill0 starsChanged 14 days agoMITView on GitHub

Refactor in small, verified steps, with behavior locked by tests before any change. Use when asked to refactor, clean up, rename, extract or restructure code without changing behavior.

26 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use verify-and-stop, investigate-first and 10 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.
  • JuliusBrusseeSkill

    verify-and-stop

    Prove existing work meets acceptance conditions without expanding scope. Use for validation-only tasks, completion checks, focused gate runs, and last-mile proof.

    Also in 8 projects that use this

  • JuliusBrusseeSkill

    investigate-first

    Diagnose ambiguous failures before editing. Use for unknown causes, intermittent behavior, performance regressions, or investigations needing evidence-ranked hypotheses.

    Also in 7 projects that use this

  • +10 more from JuliusBrussee

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 24 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Close gaps: If the code to change has no tests, write characterization tests first: run the code with realistic inputs, record what it …

    line 18
  2. Very specific:

    Check the blast radius: Search for callers and dependents (rg), including tests, scripts, docs and config that mention the names you will …

    line 19
  3. Distinctive:

    After every step: run the relevant tests plus type check or lint.

    line 24

“Common” is measured: kept by at least 6 in 10 of the 24 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 without changing behavior

Goal: improve structure while behavior stays identical, proven after every step.

Before touching code

  1. State the goal and the boundary in two lines: what gets better (readability, duplication, testability) and what must not change (public API, output format, performance envelope). Confirm with the user if the boundary is unclear.
  2. Find the safety net. Locate the tests that cover the code. Run them and record the baseline (pass count, any pre-existing failures). Pre-existing failures are not yours to fix silently; list them.
  3. Close gaps. If the code to change has no tests, write characterization tests first: run the code with realistic inputs, record what it currently does (even if odd), and assert exactly that. Commit or save these before refactoring.
  4. Check the blast radius. Search for callers and dependents (rg), including tests, scripts, docs and config that mention the names you will change. Public or exported symbols need a deprecation path or an explicit go-ahead.

During

  • One kind of change per step: rename, or extract, or move, or inline. Never mix a refactor with a bug fix or a feature.
  • After every step run the relevant tests plus type check or lint. If red, undo the step (git restore or revert your last edit) and try a smaller step. Do not debug forward through a broken refactor.
  • Keep diffs reviewable. Aim for steps a person can review in minutes. Prefer several small commits if the user wants commits.
  • Do not "improve" while you are here: unrelated formatting, dependency bumps and style changes go in a separate list at the end.
  • Preserve behavior including error messages, ordering, logging and edge cases, unless the user says otherwise.

Finish

Report: the steps taken, tests run and results, what you deliberately did not change, bugs or smells you noticed but left alone, and any behavior you are not sure is preserved (for example, code with no coverage that you could not exercise).

Stop and ask when

  • Tests cannot be run, or the baseline is red for reasons you cannot explain.
  • The change needs a public API break.
  • You find a real bug in the code being moved. Report it; fix it as its own change.

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.