agentleFS
shinzoxDshinzoxD/knackbox/skills/coding/refactor-planning/SKILL.md

refactor-planning

Skill0 starsChanged 5 months agoApache-2.0View on GitHub

Plan safe refactors that preserve behavior — seams, steps, tests,

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Choose a seam: Prefer the smallest boundary that lets you move one concept at a time (function extract, interface, module split).

    line 26
  2. Distinctive:

    Never combine user-visible behavior change with structural refactor in the same step.

    line 69
  3. Distinctive:

    Prefer many small PR-sized steps over one "big bang" rewrite.

    line 71
  4. Distinctive:

    Do not invent framework APIs or file layouts you have not seen.

    line 72
  5. Distinctive:

    If the right answer is "don't refactor yet," say so and propose a smaller improvement.

    line 77
  6. Distinctive:

    Strangler vs rewrite: default to strangler (new path beside old, switch traffic, delete old) for systems in production.

    line 83

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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

Refactor Planning

Refactoring is behavior-preserving change under test. Plan first so the work is reviewable, reversible, and does not mix product changes with structure.

Workflow

  1. State the goal and non-goals. What pain (readability, coupling, test friction, performance seam) and what must not change for users.
  2. Characterize the current design. Boundaries, ownership of state, call graph hotspots, and the worst coupling.
  3. Choose a seam. Prefer the smallest boundary that lets you move one concept at a time (function extract, interface, module split).
  4. Lock behavior. List existing tests that protect the seam; add characterization tests before moving code when coverage is thin.
  5. Sequence the steps. Each step should leave main green and deployable.
  6. Define done and rollback. How you know it worked; how to undo mid-way.

Output format

## Refactor plan: <target>

**Goal:** …
**Non-goals:** …
**Risk:** low | medium | high — why

### Current shape
2–5 bullets on how it works today and the main smell.

### Target shape
What modules/types exist after; one sentence on the new invariant.

### Safety net
- Existing tests to run: …
- Characterization tests to add first: …

### Steps
1. [safe] …
2. [safe] …
3. …

### Verification
Commands and behaviors to check after each step / at the end.

### Rollback
How to stop or revert without half-migrated state.

### Out of scope
Product changes deliberately deferred.

Rules

  1. Never combine user-visible behavior change with structural refactor in the same step. Split into two PRs when needed.
  2. Prefer many small PR-sized steps over one "big bang" rewrite.
  3. Do not invent framework APIs or file layouts you have not seen; mark assumptions.
  4. Name the tests that must pass after every step. If none exist, the first step is tests, not renames.
  5. Flag data migrations, serialization formats, and public APIs as high risk.
  6. If the right answer is "don't refactor yet," say so and propose a smaller improvement.

Edge cases

  • No tests: characterization tests + manual script first; shrink scope.
  • Strangler vs rewrite: default to strangler (new path beside old, switch traffic, delete old) for systems in production.
  • Performance-motivated: require a measurement plan; structure-only plans that claim speedups without metrics are incomplete.
  • User already has a partial refactor: replan from current branch state, not from ideal greenfield.

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.