agentleFS
rafaelobrafaelob/pragmatic-agent-skills/skills/refactoring-catalog/SKILL.md

refactoring-catalog

Skill23 starsChanged 8 days agoApache-2.0View on GitHub

Use to restructure code without changing behavior (duplication, unclear intent, coupling) when trusted tests cover it: small moves, stay green. Behavior change -> tdd. Untested code -> legacy-code-change.

Files
SKILL.md

Refactor only what improves the current change

Name the pain: duplicated knowledge, confusing intent, difficult change, excessive coupling or an untestable boundary. Similar code with independent domain meanings need not be unified. Do not refactor solely to meet an invented line limit, layer count or pattern preference.

This skill changes structure and never behavior; a behavior change, even a small one, is tdd work with its own failing test. Find adequate existing behavioral tests. Without reliable coverage of the affected contract, go to legacy-code-change (characterize, cut the smallest seam) and return here afterwards. Distinguish observed legacy behavior from a known defect; do not freeze a defect as a desired contract. Keep intentional behavior changes separately understandable.

Prefer extract, rename, move or simplify over introducing a new engine or framework. Read references/REFACTORING_MOVES_REFERENCE.md for the concrete moves (preconditions, mechanics, verification) once the pain is named. Use an existing codemod where appropriate -- read references/AUTOMATED_REFACTORING_TOOLS.md for the tool catalog by language before hand-writing an AST transform -- inspect its scope and preserve unrelated WIP. Short green-to-green moves are compatible with a coherent final commit; do not create a PR per micro-edit unless the workflow requires it.

Test stability through change

Behavioral tests should continue to pass when only implementation changes. Remove coupling to private method names or call order unless the order itself is contractual. Do not add tests for renamed helpers just to replace deleted brittle ones. Retire a test only after its protection is preserved elsewhere, its behavior was removed or its assertion was shown not to protect a relevant requirement.

Rerun affected checks after the structural move and applicable final gates at integration. For the interface decision that precedes the move, use codebase-design; for choosing which checks must stay green while it happens, use layered-testing-executor.

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.