agentleFS
tejastn10tejastn10/workbench/skills/quality/extract-module/SKILL.md

extract-module

Skill1 starsChanged 2 months agoMITView on GitHub

Split a file or module that's grown too big — find the real seams, pull out a cohesive piece with a narrow interface, move the tests with it, keep every commit green. Behaviour-preserving only. Use when asked to "split this file", "extract X into its own module", "this file is too big", or a review flags a god-object.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 2

    Distinctive

    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:

    Don't split by line count — split by cohesion.

    line 12
  2. Distinctive:

    If nothing has a clean seam, the file may be fine as-is.

    line 22

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

Extract a module

Behaviour must not change. Every commit compiles and passes tests.

Find the seam

Don't split by line count — split by cohesion. Look for:

  • A cluster of functions that only talk to each other and share private state.
  • A set of functions that all take the same 2–3 parameters (they want to be a type with methods, or a module with that state closed over).
  • A concern that has its own vocabulary (parsing, formatting, a protocol, a cache).
  • Code the rest of the file only calls through 1–2 entry points — that's the interface of the new module.

If nothing has a clean seam, the file may be fine as-is. A big file of unrelated small functions is a naming problem, not a structure problem.

Do it

  1. Name the new module for what's in it, not generically (billing-period, not utils). Match the project's layout — for NestJS, a new feature module gets its own v1/ folders and module-local constants.ts (design/scaffold-nestjs-module).
  2. Move, don't rewrite. Cut the code, paste it, fix imports. Resist improving it in the same pass.
  3. Keep the interface narrow — export only what callers use. Everything else stays unexported.
  4. Move the tests that cover the extracted code into a spec beside it. Don't leave them testing through the old file.
  5. One commit (refactor: extract <module> from <file>), green.
  6. Then — a separate commit/PR for any cleanup the extraction revealed.

Anti-patterns

  • ❌ Splitting by size with no cohesive seam.
  • ❌ Rewriting logic during the move.
  • ❌ A wide interface that exposes internals "just in case".
  • ❌ Tests left behind, still coupled to the old module.
  • ❌ Bundling the extraction with a behaviour 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.