agentleFS
Sequela02Sequela02/canasta/skills/workflow/refactor/SKILL.md

refactor

Skill0 starsChanged yesterdayMITView on GitHub

Change code structure without changing behavior: refactor, clean up, remove duplication or dead code, rename, move, or simplify. For a change in behavior, use tdd instead.

195 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use ascii-diagram, debug-fix 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.
  • SethGammonSkill

    ascii-diagram

    Generate perfectly aligned ASCII diagrams — architecture, flow, sequence, box-and-arrow. Uses a programmatic character-grid approach so alignment is guaranteed by math, not token prediction. Includes post-render verification.

    Also in 4 projects that use this

  • zebbernSkill

    debug-fix

    Find and fix a bug or issue — from any source (GitHub issue, error message, user report, or observed behavior)

    Also in 4 projects that use this

  • parcadeiSkill

    agent-context-isolation

    Agent Context Isolation

    Also in 3 projects that use this

  • parcadeiSkill

    agentica-infrastructure

    Reference guide for Agentica multi-agent infrastructure APIs

    Also in 3 projects that use this

  • +8 more from parcadei

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 170 edited versions we read keep these.

  • 7

    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. Very specific:

    If behavior must change, it is not a refactor: split it out and use tdd.

    line 9
  2. Distinctive:

    Never mix a behavior change into a refactor, not even a "small fix" you notice.

    line 17
  3. Distinctive:

    Use the compiler, type system, IDE, or AST tools for renames and moves instead of editing text by hand when they are available.

    line 21
  4. Distinctive:

    Do not add an abstraction, layer, or wrapper unless it removes demonstrated duplication, coupling, or confusion.

    line 26
  5. Distinctive:

    Make sure a check would catch drift.

    line 35
  6. Very specific:

    Leave mechanical rules (unused or wildcard imports, any, formatting) to the repository's linters and formatters.

    line 52
  7. Distinctive:

    Do not refactor generated code, applied migrations, third-party code, or configuration files.

    line 56
  8. Distinctive:

    After each transformation, run the narrowest check that could expose drift.

    line 61
  9. Distinctive:

    Keep structure and behavior in separate commits (Kent Beck's *Tidy First?*): a refactor commit contains no behavior change.

    line 71

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

A refactor changes structure and keeps observable behavior exactly the same. If behavior must change, it is not a refactor: split it out and use tdd.

Agent failure modes

Coding agents often change behavior while "refactoring" (in published studies, about one recommended refactoring in fourteen changed functionality or broke syntax). These rules override convenience:

  • Never mix a behavior change into a refactor, not even a "small fix" you notice. Report it, and if asked, do it as a separate change.
  • One named transformation at a time (extract function, inline, rename, move, replace conditional), each leaving the code buildable and its checks green.
  • Use the compiler, type system, IDE, or AST tools for renames and moves instead of editing text by hand when they are available.
  • Absence of static references does not prove code is dead: check configuration, reflection, registration, generated code, scripts, and entry points first.
  • Do not add an abstraction, layer, or wrapper unless it removes demonstrated duplication, coupling, or confusion.

Before editing

  1. Name the behavior that must not change: public APIs, outputs, persisted or serialized data, errors, ordering, side effects, authorization decisions, and performance where it is part of the contract.
  2. Find every consumer of the code you will touch.
  3. Make sure a check would catch drift. If the existing tests are weak around the code, add characterization tests first; they record current behavior, right or wrong.
  4. Name the structural problem you are fixing and stay inside it. Adjacent cleanup the user did not ask for gets mentioned, not done.

What to fix

  • Duplicated logic: one owner per behavior.
  • Dead code, commented-out code, and compatibility paths with no remaining consumer: delete them in the same change.
  • Wrappers and layers with a single caller that add nothing: inline them.
  • Swallowed exceptions: fail fast or handle the error deliberately.
  • Complex conditionals, unclear names, magic numbers.
  • Explanations made obsolete by the move: delete them rather than keep a historical copy beside the new owner.

Leave mechanical rules (unused or wildcard imports, any, formatting) to the repository's linters and formatters. If a rule you keep fixing has no linter, propose one instead of fixing it by hand every time.

Do not refactor generated code, applied migrations, third-party code, or configuration files.

Verify

  • After each transformation, run the narrowest check that could expose drift; then check affected dependents in proportion to their reach and risk.
  • Where tests are weak or the change crosses a boundary, compare before and after directly: characterization, differential, or trace evidence.
  • Review the final diff for accidental changes to defaults, constants, errors, ordering, transactions, async behavior, authorization, data shape, and resource use.

Commit and report

  • Keep structure and behavior in separate commits (Kent Beck's Tidy First?): a refactor commit contains no behavior change.
  • Report the behavior preserved, the transformations applied, the checks run and their results, and any residual uncertainty. If equivalence could not be established, say so and treat the work as a behavior 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.