agentleFS
anandartinanandartin/celestial-skills/skills/safe-refactoring-engineering/AGENTS.md

celestial-skills / safe-refactoring-engineering

AGENTS.md1 starsChanged 18 days agoApache-2.0View on GitHub

Restructure code in small steps that never change behaviour, each one checked by tests, so the design improves without new bugs. Generated from the Celestial engineering practice “Safe refactoring”.

The file

We split this AGENTS.md into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    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:

    Never refactor code that has no tests covering it.

    line 24
  2. Distinctive:

    Keep each refactoring pull request focused on one structural goal.

    line 25

≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md 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
AGENTS.md

AGENTS.md — Safe refactoring

Restructure code in small steps that never change behaviour, each one checked by tests, so the design improves without new bugs.

How to do it

  1. Name the goal — Write one sentence on the structure you want and why, for example 'move pricing rules out of the controller so the new tax rule has one home'.
  2. Secure a safety net — Run the tests that cover the code. If coverage is thin, add characterisation tests that pin current behaviour, including odd behaviour, before changing anything.
  3. Separate refactoring from behaviour change — Do the refactor on its own branch or in its own commits. Feature or bug-fix changes come after, in separate commits.
  4. Take one small step — Apply one named move: rename, extract function, inline, move module, introduce parameter. Prefer the editor's automated refactorings where they exist.
  5. Run tests after every step — Run the relevant tests and the type checker. If anything fails, undo the step rather than debugging forward.
  6. Commit each green step — Commit after each working step with a message naming the move. Small commits make bisecting and review simple.
  7. Keep public interfaces stable — When a widely used function or API must change, add the new form, migrate callers, then remove the old form in a later step.
  8. Review the diff as pure structure — Before the pull request, read the diff and confirm no logic, output or test expectation changed. Note any deliberate exception.

Checklist (before a pull request)

  • Tests covering the touched code passed before and after the refactor
  • No test expectations were changed except renames that follow the code
  • Refactoring commits contain no feature or bug-fix changes
  • Each commit builds and passes tests on its own
  • Old interfaces kept during migration are marked deprecated with a removal plan
  • Type checker and linter report no new errors

Rules

  • Never refactor code that has no tests covering it; add characterisation tests first. (Without a safety net you cannot tell a refactor from a rewrite.)
  • Keep each refactoring pull request focused on one structural goal. (Reviewers can verify behaviour is unchanged only when the diff has one purpose.)
  • Benchmark before and after when refactoring a hot path. (Cleaner code can still be slower, and that is a behaviour change users notice.)
  • Preserve error types, messages and status codes callers rely on. (Callers often branch on errors, so changing them breaks contracts silently.)

Checks

GateToolThresholdWhen
Behaviour unchangedFull test suite + snapshot or contract testsAll pass with no changed expectationsEvery refactoring pull request

Generated from the Celestial engineering practice “Safe refactoring”.

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.