agentleFS
MesteriisMesteriis/Engineering-Bible-AI/skills/refactoring/SKILL.md

refactoring

Skill0 starsChanged 4 months agoMITView on GitHub

Improves structure without behavior changes, using tests and focused slices; not for features unless behavior change is explicit.

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 47 edited versions we read keep these.

  • 9

    Distinctive

    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:

    Prefer small mechanical steps.

    line 16
  2. Distinctive:

    Keep tests green between steps when possible.

    line 17
  3. Distinctive:

    Do not mix broad refactoring with feature changes unless necessary.

    line 18
  4. Distinctive:

    Do not rename public APIs casually.

    line 19
  5. Distinctive:

    Do not move code across architectural boundaries without understanding dependencies.

    line 20
  6. Distinctive:

    Keep imports and dependency direction sane.

    line 44
  7. Distinctive:

    Do not split files mechanically by line count.

    line 47
  8. Distinctive:

    avoid circular imports/dependencies.

    line 55
  9. Distinctive:

    keep private helpers private.

    line 56

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

Skill: refactoring

Purpose

Improve structure without changing behavior unless behavior change is explicitly requested.

Refactoring Rules

  • Refactor only when it serves the task.
  • Identify behavior that must remain unchanged.
  • Prefer small mechanical steps.
  • Keep tests green between steps when possible.
  • Do not mix broad refactoring with feature changes unless necessary.
  • Do not rename public APIs casually.
  • Do not move code across architectural boundaries without understanding dependencies.

When Refactoring Is Justified

Refactoring is justified when it improves:

  • correctness;
  • maintainability;
  • cohesion;
  • boundary clarity;
  • testability;
  • safety;
  • removal of duplication of knowledge;
  • reduction of large/god files;
  • isolation of infrastructure details.

Large File Refactoring

For large files:

  1. Identify responsibilities.
  2. Identify public API surface.
  3. Identify tests or behavior contracts.
  4. Extract cohesive units.
  5. Keep imports and dependency direction sane.
  6. Validate after each meaningful slice.

Do not split files mechanically by line count. Split by responsibility.

Safe Extraction Checklist

Before extraction:

  • know callers;
  • preserve public names or provide compatibility where required;
  • avoid circular imports/dependencies;
  • keep private helpers private;
  • move tests or add tests for extracted behavior;
  • preserve errors and logging behavior unless intentionally changed.

Reporting

Report:

  • behavior preserved;
  • responsibilities extracted;
  • files moved/changed;
  • validation;
  • risks.

Extended References

For deeper refactoring work, read:

  • ../../engineering/07_complexity_budget.md
  • ../../engineering/08_engineering_smells.md
  • ../../engineering/11_refactoring_catalog.md

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.