agentleFS
gurinderugurinderu/craft/skills/refactoring/SKILL.md

refactoring

Skill1 starsChanged 40 days agoMITView on GitHub

Disciplined refactoring — change structure without changing behavior, in tiny reversible steps under green tests. Use when restructuring code, paying down a smell, or preparing messy code for a change. Language-agnostic. Triggers: refactor, code smell, technical debt, extract function, make this testable.

69 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use ci-cd, logging 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.
  • JohnJBorenSkill

    ci-cd

    CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies

    Also in 5 projects that use this

  • diego-tobalinaSkill

    logging

    Logging best practices for Java (SLF4J/Logback) and Node.js (Winston/Pino). Use for structured logging, log levels, and avoiding sensitive data exposure.

    Also in 4 projects that use this

  • AWSSkill

    planning

    Discovers user intent and generates a structured, step-by-step plan for model customization workflows. This skill must always be activated alongside any other skill when the user's request relates to model customization — including fine-tuning, training, building, customizing, reviewing data, or getting advice on approach, regardless of domain. Do not skip this skill even if the immediate ask is narrow (e.g., reviewing data format or a single workflow step), because planning discovers the full scope of work needed. Also activate when the user wants to resume, continue, or modify an existing plan.

    Also in 8 projects that use this

  • dkprogSkill

    dependency-management

    Apply when wiring dependencies, integrating external services, or designing interfaces between modules. Ensures loose coupling through dependency injection, interface segregation, and proper abstraction boundaries.

    Also in 3 projects that use this

  • javalenciacaiSkill

    multi-agent-orchestration

    Design and coordinate multi-agent systems where specialized agents work together to solve complex problems. Covers agent communication, task delegation, workflow orchestration, and result aggregation. Use when building coordinated agent teams, complex workflows, or systems requiring specialized expertise across domains.

    Also in 3 projects that use this

  • harrissohail6Skill

    database-design

    Database schema design and SQL best practices. Use when designing tables, writing queries, or optimizing database performance.

    Also in 5 projects that use this

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 61 edited versions we read keep these.

  • 1

    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:

    Don't refactor on a red bar, mid-debugging, or "while I'm in here" alongside a feature — separate the commits.

    line 30
  2. Very specific:

    Keep behavior identical: don't "improve" an error type or a public signature mid-refactor — that's a behavior/API change, do it separately …

    line 74

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

Refactoring

Refactoring is changing how code is structured without changing what it does. The discipline is what separates it from "rewriting and hoping": tiny reversible steps, behavior held constant, tests green the whole way.

The two rules

1. NEVER refactor and change behavior in the same step.
2. NEVER refactor without a test safety net that's currently GREEN.

Mixing structure and behavior changes means a failing test can't tell you which one broke it. Refactoring without tests is just editing — you have no way to know you preserved behavior.

When to Use

  • Restructuring code that works but is hard to read/change
  • Paying down a specific smell
  • "Making the change easy, then making the easy change" — refactor first to fit a new feature, then add the feature (two separate steps/commits)

Don't refactor on a red bar, mid-debugging, or "while I'm in here" alongside a feature — separate the commits.

The loop

1. GREEN    — confirm the tests pass now. No tests? Write characterization
              tests first that pin current behavior.
2. ONE STEP — apply a single, named transformation (below).
3. GREEN    — run the tests again immediately. Still green → keep; red → revert this step.
4. COMMIT   — small commits between steps so every step is reversible.
5. REPEAT   — until the smell is gone.

Small steps make mistakes cheap: when a step goes red, you revert seconds of work, not an hour's.

Characterization tests first

Refactoring legacy code with no tests? Don't trust your reading of it — pin its actual current behavior with tests first (even ugly ones, even snapshot/insta tests of the output), then refactor under them. The safety net is the precondition, not an afterthought (→ rust-testing).

Named transformations

Refactor by recognizable moves, not freehand edits:

  • Extract function / variable — name a chunk of logic or a sub-expression.
  • Inline — the reverse, when the indirection costs more than it gives.
  • Rename — make the name tell the truth (the cheapest, highest-value refactor).
  • Introduce type — replace a primitive/bool/stringly-typed value with a newtype/enum (→ rust-traits, rust-idioms).
  • Replace conditional with dispatch — a sprawling match/if on a tag → enum dispatch or a trait (→ rust-traits).
  • Extract trait / module — pull a seam so the unit becomes testable (→ rust-architecture).
  • Slide statements / split loop — group related code; one loop per concern.

Rust-specific

  • Let the compiler drive: rename/extract and lean on rustc's errors to find every call site — the type system makes many refactors mechanically safe.
  • cargo clippy suggests refactors (needless clones, complex matches) — --fix applies the safe ones (→ rust-idioms).
  • Restructuring to satisfy the borrow checker (split borrows, ownership moves) is its own kind of refactor → rust-ownership.
  • Keep behavior identical: don't "improve" an error type or a public signature mid-refactor — that's a behavior/API change, do it separately (→ rust-errors, semver in rust-ecosystem).

Boundaries

  • The test safety net (characterization, snapshot, property) → rust-testing; specs as the behavior contract → specs.
  • Which smells to target / the Good→Bad catalog → rust-idioms (anti-patterns).
  • Extracting seams/ports as a larger structural move → rust-architecture.

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.