agentleFS
89jobrien89jobrien/godmode/skills/refactoring/SKILL.md

godmode:refactoring

Skill1 starsChanged 57 days agoMITView on GitHub

Guided refactoring with test discipline. Use when restructuring code without changing observable behaviour — extract, rename, reorganise, decouple.

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 10 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If tests are red before you start, fix them first.

    line 19
  2. Distinctive:

    When you're tempted to refactor and add a feature simultaneously — split the work

    line 31
  3. Very specific:

    When tests don't exist yet — write tests first (godmode:task-driven-development)

    line 32
  4. Distinctive:

    When the "refactor" would change public API behaviour — that's a feature change

    line 33
  5. Distinctive:

    Do not expand scope without surfacing to user.

    line 56
  6. Very specific:

    Run taskit test run — must stay green

    line 63
  7. Distinctive:

    If red, revert and diagnose before proceeding

    line 64
  8. Distinctive:

    No new public API surface unless explicitly approved

    line 69
  9. Distinctive:

    No behaviour changes smuggled into the refactor

    line 70
  10. Distinctive:

    Before committing, verify you are on the correct branch:

    line 74
  11. Distinctive:

    Do not rename public items without checking all downstream callsites

    line 101
  12. Very specific:

    Do not move items across crate boundaries without updating Cargo.toml deps

    line 102
  13. Distinctive:

    Do not combine rename + extract in one step — rename first, verify green, then extract

    line 103
  14. Very specific:

    Run godmode:code-review on your own diff before committing.

    line 107

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill 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
SKILL.md

Refactoring

Core Rule

REFACTOR ONLY WHEN ALL TESTS PASS
Never change behaviour and structure at the same time.

If tests are red before you start, fix them first. Refactoring on a red baseline hides regressions.

When to Use

  • Extracting a helper that is duplicated 3+ times
  • Renaming for clarity after the design has stabilised
  • Decoupling I/O from pure logic (hexagonal prep)
  • Removing dead code after a feature is complete

When NOT to Use

  • When you're tempted to refactor and add a feature simultaneously — split the work
  • When tests don't exist yet — write tests first (godmode:task-driven-development)
  • When the "refactor" would change public API behaviour — that's a feature change

Process

1. Confirm green baseline

Run via godmode verify or use the commands below:

taskit test run
taskit check lint

Both must pass before touching anything.

2. State scope

Name exactly what you're changing and why:

  • Which file(s)
  • What pattern (extract, rename, move, inline, decouple)
  • Why (duplication, clarity, coupling reduction)

Do not expand scope without surfacing to user.

3. Make one structural change at a time

Each change:

  1. Edit code
  2. Run taskit test run — must stay green
  3. If red, revert and diagnose before proceeding

4. Verify behaviour unchanged

  • Tests pass with identical outcomes
  • No new public API surface unless explicitly approved
  • No behaviour changes smuggled into the refactor

5. Branch guard + full gate

Before committing, verify you are on the correct branch:

git branch --show-current   # must NOT be main

Run via godmode verify or use the commands below:

taskit check fmt --check
taskit check lint
taskit test run

Common Refactoring Patterns (Rust)

PatternSignalApproach
Extract functionBlock of code used 2+ timesMove to fn, pass args
Extract moduleFile > ~300 lines, mixed concernsSplit by responsibility
Extract traitTwo types share identical method setDefine trait, impl on each
Inline variableVariable used once, name adds noiseInline the expression
Decouple I/OPure logic calls std::fsPass &Path or Read trait bound
RenameName misleads or contradicts usageEdit tool + Grep tool to find callsites

Scope Rules

  • Do not rename public items without checking all downstream callsites
  • Do not move items across crate boundaries without updating Cargo.toml deps
  • Do not combine rename + extract in one step — rename first, verify green, then extract

After Refactoring

Run godmode:code-review on your own diff before committing.

Additional Resources

  • references/refactoring-patterns.md — extract function/module/trait, decouple I/O, rename patterns with code examples
  • helpers/refactor-checklist.md — before/during/after checklist and scope creep check

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.