agentleFS
suleymanbyztsuleymanbyzt/agent-helm/skills/safe-refactor/SKILL.md

safe-refactor

Skill1 starsChanged 3 months agoMITView on GitHub

Use when restructuring, cleaning up, or reorganizing existing code without changing its behavior. Enforces a test safety net before touching anything and proof that behavior was preserved.

10 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use caveman-explore, surgical-patch and 2 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

    caveman-explore

    Read-only repository explorer for cold-start orientation, broad cross-file localization, or when a direct search failed. Skip it when the exact file or symbol is already named. Returns path:line citations only; its reads stay out of main context.

    Also in 3 projects that use this

  • JuliusBrusseeSkill

    surgical-patch

    Fix bugs and small behavior changes at the narrowest responsible layer. Use when regression proof, preserved surrounding behavior, and task-relevant tests matter.

    Also in 3 projects that use this

  • MicrosoftSkill

    caveman

    Ultra-compressed response style that reduces output token count while preserving technical accuracy, with intensity levels and auto-clarity safety rules

    Also in 3 projects that use this

  • +1 more from JuliusBrussee

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the code, its callers, and its edge cases.

    line 17
  2. Distinctive:

    No safety net, no refactor.

    line 26
  3. Very specific:

    After every step: run the tests.

    line 33
  4. Very specific:

    If you discover an actual bug mid-refactor, stop, report it, and handle it as a separate bug-fix task.

    line 35
  5. Distinctive:

    Do not mix refactoring with feature work or bug fixes in one change.

    line 49
  6. Distinctive:

    Do not delete "weird" code you don't understand — it is load-bearing until proven otherwise.

    line 50
  7. Distinctive:

    Do not widen the scope mid-refactor.

    line 52

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

Safe Refactor

Goal: change the structure, prove the behavior did not change.

A refactor that changes behavior is not a refactor — it is an unreviewed functional change. Refactoring is at least L2: send the Plan message and wait for approval before starting.

Steps

  1. Understand the current behavior. Read the code, its callers, and its edge cases. List the invariants — the things that must still be true afterwards (outputs, side effects, error behavior, performance characteristics that matter).
  2. Build the safety net BEFORE changing code.
    • Find the existing tests that cover this code. Run them; confirm green.
    • Where behavior is untested, add characterization tests: tests that pin down what the code does today — including odd behavior. You are documenting reality, not fixing it.
    • No safety net, no refactor.
  3. Plan small steps. Break the refactor into steps that each keep the tests green. Prefer many small mechanical moves over one big rewrite.
  4. Refactor. After every step: run the tests. If a test goes red, the last step broke behavior — fix the step, do not "adjust" the test. If you discover an actual bug mid-refactor, stop, report it, and handle it as a separate bug-fix task. Do not silently fix it inside the refactor.
  5. Verify preservation. Full test suite green. Diff reviewed: only structural changes, no logic drift, no accidental behavior change. Run the verify-work skill.
  6. Record. Journal entry: docs/agent-journal/YYYY-MM-DD-refactor-<slug>.md (format: Why / Safety net / Steps taken / Proof behavior preserved).

Do not

  • Do not mix refactoring with feature work or bug fixes in one change.
  • Do not delete "weird" code you don't understand — it is load-bearing until proven otherwise. Investigate first.
  • Do not widen the scope mid-refactor. New scope = new proposal.

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.