agentsclimarketplace

Refactoring to patterns

Skill bostonaholic/team/skills/refactoring-to-patterns

Fowler's refactoring methodology — loaded by the implementer agent when working with existing code to recognize code smells and apply proven transformationsFrom its SKILL.md

Install
npx -y skills add bostonaholic/team --skill refactoring-to-patterns

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 11 stars11 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

3.9 KB, as published. Nobody here has run it

Refactoring to Patterns

Change internal structure without changing observable behavior. Every step leaves all tests passing. Never refactor while also adding features — separate the two activities into separate commits.

When to refactor

  • Before making a change that the current structure makes hard. Two small moves beat one large dangerous move.
  • On the third duplication. Rule of Three: tolerate it the second time.
  • Before debugging code you cannot understand. Clarify, then fix.

Do not refactor when tests are failing (fix them first), when the code works and no change is imminent, or when a deadline is live — note the smell and move on.

Smell → refactoring

SmellReach for
Long MethodExtract Method; Replace Temp with Query; Decompose Conditional
Duplicate CodeExtract Method; Extract Class; Pull Up Method; Form Template Method
Large ClassExtract Class; Extract Subclass; Extract Interface
Long Parameter ListIntroduce Parameter Object; Preserve Whole Object
Divergent Change (one class, several reasons to change)Extract Class along each reason
Shotgun Surgery (one change, many classes)Move Method / Move Field; Inline Class
Feature Envy (method more interested in another class's data)Move Method
Primitive ObsessionReplace Data Value with Object; Replace Type Code with Class or Subclasses
Conditional ComplexityReplace Conditional with Polymorphism; Introduce Null Object; Decompose Conditional
Middle Man (half its methods just forward)Remove Middle Man; Inline Method

Two smells carry rules the catalog above does not make obvious:

Mixed levels of abstraction. A function that alternates between high-level orchestration ("save the order, charge the card, send the receipt") and low-level primitives ("format the price as fixed-width 8 chars") forces readers to swap mental contexts. Extract the low-level work into a helper named at the surrounding level. A function calls functions one level of abstraction below its own — never two or more at once.

Constructor doing work. Any of three shapes: instantiating dependencies inside methods (new HttpClient() inside fetchUser()), taking per-call work parameters in the constructor (new ReportGenerator(2024, 1, 1, 2024, 12, 31)), or doing I/O and static lookups in the constructor. All three leave no seam for tests to substitute collaborators. The fix is one rule: construct with collaborators, call with work. Long-lived dependencies (HTTP client, DB, clock, logger) are injected through the constructor; per-call parameters (date ranges, query strings, request bodies) go on the method; constructors assign and return, doing no work at all. Production wires real collaborators; tests substitute fakes at construction.

Safe refactoring procedure

  1. Confirm tests pass before starting. Failing tests stop the refactor.
  2. Make the smallest possible structural change. One refactoring at a time.
  3. Run tests after each change. On a break, undo immediately — never proceed with broken tests.
  4. Commit when tests pass. Each passing checkpoint is a safe point.
  5. Repeat until the code is in the desired shape.

In the implementer role

  • Read the code before changing it. Identify smells before writing.
  • Refactor in its own commit, first — then add the feature.
  • Refactor only what you touch. Opportunistic refactoring of distant code is scope creep.
  • Name the smell and the refactoring in the commit. refactor: extract user validation into UserValidator (Long Method).
  • When in doubt, leave it. A refactoring that breaks tests is worse than the smell it was trying to fix.

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Gives 1 of the 12 instructions most refactoring skills give

Counted across 545 of the 587 authors here whose files we hold, read 2026-09-06

  • Run tests after each changehere, and in 61 of 545, across 59 files
  • Run tests before refactoringin 42 of 545
  • Revert immediately if tests failin 31 of 545, across 28 files
  • Perform refactoring in small stepsin 30 of 545, across 29 files
  • Write characterization tests for untested codein 21 of 545, across 19 files
  • Remove dead code and unused importsin 20 of 545
  • Identify code smellsin 20 of 545
  • Perform one refactoring at a timein 19 of 545
  • Commit after each successful refactoringin 17 of 545, across 15 files
  • Verify all tests pass after refactoringin 17 of 545
  • Keep refactoring separate from behavior changesin 16 of 545, across 14 files
  • Run the full test suitein 16 of 545

Said here and by no other author read

  • make the smallest possible structural change
  • extract low-level work into helpers
  • pass per-call parameters to methods
  • name the smell and refactoring in the commit

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once.

Keep looking

Skills are one crate of 626,194. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.