agentleFS
DobroslavRadosavljevicDobroslavRadosavljevic/cabrakan/.agents/skills/reorganize/SKILL.md

reorganize

Skill1 starsChanged 3 months agoMITView on GitHub

Splits oversized files and groups related code into a coherent folder tree. One concern per file; related modules sit together under domain folders; names stay descriptive. Use when the user asks to reorganize code, split a large file, untangle mixed modules, extract related files into folders, clean a messy tree, or stop unrelated logic from living in one place — not for shortening names, behavior changes, or general smell cleanup.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. 0 are common, 19 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 19

    Distinctive

    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:

    Do not shorten names for scannability.

    line 11
  2. Distinctive:

    Before/after trees: references/examples.md

    line 18
  3. Distinctive:

    Ask once if the boundary is ambiguous.

    line 24
  4. Distinctive:

    Default to propose (read-only split/move map).

    line 26
  5. Very specific:

    Read project layout or ownership guidance if present (AGENTS.md, CONTRIBUTING, nested module docs, package exports).

    line 31
  6. Distinctive:

    Put siblings that change together in the same folder (and subfolders when the set is large).

    line 58
  7. Distinctive:

    Do not rename solely to shorten

    line 69
  8. Distinctive:

    Do not invent cryptic 2–3 letter abbreviations

    line 70
  9. Distinctive:

    Add a subfolder when a cluster has a shared identity

    line 77
  10. Distinctive:

    Do not add empty scaffolding folders "for later"

    line 78
  11. Very specific:

    Do not nest utils/helpers/lib chains

    line 79
  12. Distinctive:

    After a split, internals may import siblings.

    line 91
  13. Very specific:

    Prefer a folder with a real entry file over a new barrel.

    line 95
  14. Distinctive:

    Call out what must not move (applied migrations, public SDK paths, persisted resource IDs, framework route files, generated output) unless …

    line 111
  15. Distinctive:

    Do not flag a name for being long if it is accurate.

    line 146
  16. Distinctive:

    Do not flag a cohesive long file (single mapper, single protocol codec).

    line 147
  17. Distinctive:

    Prefer split/move over rewriting logic

    line 151
  18. Distinctive:

    Keep unrelated worktree changes untouched

    line 153
  19. Distinctive:

    Read-only unless the user requests implementation

    line 154
  20. Distinctive:

    Use the project's existing quality commands for touched files or packages only (format, lint, typecheck, tests).

    line 159
  21. Distinctive:

    If schema, migrate, or generated-path artifacts moved, run the project's usual migration or codegen step for that surface.

    line 163
  22. Very specific:

    When this skill runs inside a multi-agent implementation or repair workflow, each subagent runs only targeted checks for its assigned …

    line 216
  23. Distinctive:

    If no multi-agent harness is available, run the same targeted checks in chat.

    line 220

“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

Reorganize

Make file trees cohesive: related code lives together; unrelated code does not share a file or folder; large files split into a readable tree.

Do not shorten names for scannability. Prefer clear, descriptive folder and file names that match what the code owns.

Load after first steps:

  • Model: references/organization-model.md
  • Split rules: references/split-heuristics.md
  • Before/after trees: references/examples.md

Scope

  1. User-provided path first (package, feature, file, or subtree).
  2. Current git changes if no path is given and the diff is organization-shaped.
  3. Ask once if the boundary is ambiguous.

Default to propose (read-only split/move map). Only rewrite files when the user says apply / migrate / implement.

First Steps

  1. Read project layout or ownership guidance if present (AGENTS.md, CONTRIBUTING, nested module docs, package exports).
  2. Glob the target tree. Record large files (LOC), mixed folders, and public entrypoints (package.json exports, route files, SDK barrels already in use).
  3. Load the three references above.
  4. Compare against 1–2 sibling folders of similar role (optional, for local conventions like public/ / private/ trust buckets).
  5. Inventory each hotspot file: export groups, section comments, types vs runtime vs UI vs I/O. That inventory is the split seed.

Principles

1. One primary concern per file

A file owns one job: one type family, one workflow, one UI surface, one adapter. Split when it mixes unrelated export groups or grows past ~250–400 LOC with continued growth expected.

A long file that is still one concern (exhaustive mapper, generated-looking table, single state machine) may stay. Length alone is not a defect — mixed jobs are.

Name split pieces after what they own. Do not dump leftovers into helpers, misc, shared2, or utils.ts.

2. Related code shares a parent

Put siblings that change together in the same folder (and subfolders when the set is large). Prefer a domain tree over a flat dump of unrelated files, and over scattering related modules across distant roots.

Gravity test: if several files import each other densely, they belong under one parent. If they never change together and share no types, they do not.

3. Names stay descriptive

  • Folder and file names should say the domain or aspect clearly
  • Multi-word kebab-case is fine: password-reset.ts, invoice-summary.ts
  • Do not rename solely to shorten
  • Do not invent cryptic 2–3 letter abbreviations
  • Repeating a parent in a leaf is acceptable when it disambiguates (events/event-kinds.ts) — cohesion beats brevity

4. Depth serves grouping, not ceremony

  • Split a flat folder when it mixes domains
  • Add a subfolder when a cluster has a shared identity
  • Do not add empty scaffolding folders "for later"
  • Do not nest utils/helpers/lib chains
  • Respect existing trust boundaries (public/ / private/ / internal/) — reorganize inside them; do not flatten them away

5. Extract, do not rewrite behavior

Moves and splits preserve public exports, types, and call sites. New files are mechanical extractions plus import updates — not redesigns, API changes, or drive-by refactors.

6. Dependency direction

After a split, internals may import siblings; avoid new cycles. Extract shared types/constants first, then leaf helpers, then workflows, then a thin facade if a public path must remain.

Prefer a folder with a real entry file over a new barrel. Add index.ts / index.js only when that subtree already uses barrels.

Workflow

Propose (default)

  1. Map current tree (abbreviated). List hotspot files with LOC and mixed export groups.
  2. Flag friction using references/split-heuristics.md.
  3. Propose a target tree using references/organization-model.md and references/examples.md, adapted to this archetype (package vs feature vs UI — do not force data-layer folder names onto UI).
  4. Emit an old → new path table. For splits, list which exports/sections go to which file. Note any compatibility re-export at the old path.
  5. Call out what must not move (applied migrations, public SDK paths, persisted resource IDs, framework route files, generated output) unless the user explicitly asks.
  6. Order the apply steps so types/constants move before dependents.

Apply (only when asked)

- [ ] Extract shared types/constants first (break cycles before they start)
- [ ] Create/move/split files per the map
- [ ] Update imports, package exports, and path aliases as needed
- [ ] Keep a thin re-export at the old public path only when that import path
      is a published contract; otherwise delete the old file
- [ ] Move colocated tests with their sources; split tests to match sources
- [ ] Update nearest ownership/layout docs if paths changed
- [ ] Delete emptied leftovers
- [ ] Run the project's targeted format/lint/typecheck/tests for touched areas

Preserve behavior. Do not rename applied migrations or external contracts.

Defects To Flag

  • Files that mix unrelated export groups (schema + HTTP + UI + cron in one module)
  • Files past ~250–400 LOC that keep growing and mix jobs
  • Flat directories with many unrelated domains as siblings
  • Related modules split across distant folders without a shared parent
  • utils/, helpers/, common/, misc/ dumping grounds
  • A single foo.ts / foo.service.ts that should be a foo/ folder of related pieces
  • Deep trees where every segment is a vague layer name (core/common/shared)
  • Empty or speculative folders
  • Tests that still cover five source files in one blob after the source split

Do not flag a name for being long if it is accurate. Do not flag a cohesive long file (single mapper, single protocol codec).

Fix Rules

  • Prefer split/move over rewriting logic
  • Match local archetype conventions while applying cohesion rules
  • Keep unrelated worktree changes untouched
  • Read-only unless the user requests implementation
  • One reviewable pass per cluster; do not reorganize the whole repo unasked

Verification

Use the project's existing quality commands for touched files or packages only (format, lint, typecheck, tests). Prefer targeted checks over full-repo gates unless the split spans shared contracts.

If schema, migrate, or generated-path artifacts moved, run the project's usual migration or codegen step for that surface.

Review Output

## Scope

[path]

## Current (abbrev)

[tree]

## Hotspots

| File | LOC | Mixed groups |
| ---- | --- | ------------ |

## Friction

1. …

## Target

[tree]

## Split / move map

| Before | After | What moves |
| ------ | ----- | ---------- |

## Apply order

1. types/constants …
2. leaves …
3. facades / import updates …

## Do not move

- …

## Compatibility

Old public path kept as re-export? yes/no — why

## Apply?

Propose only / ready to apply when asked

Multi-Agent Verification

When this skill runs inside a multi-agent implementation or repair workflow, each subagent runs only targeted checks for its assigned files/package/surface and reports broader gate needs. The orchestrator owns the project's full quality gate sequence and routes final-gate failures back to responsible subagents. If no multi-agent harness is available, run the same targeted checks in chat.

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.