Agent skill · lobehub

split-large-file

Refactor a source file over 800 lines into a directory of cohesive modules without changing behavior, test-first. Use when asked to split, decompose, or shrink a large file (拆分大文件, 拆文件, 重构大文件); with no file given, pick one.

What it needs

About 5k tokens when loaded.

What this skill does

Split a Large File Split one file into a directory of modules without changing behavior. Where the pieces go, what they are named, and where tests live are owned by source-layout; read it first. This skill owns the procedure: lock behavior with tests, move, extract, then split the tests. The split changes no behavior. If you find a bug on the way, note it and fix it in a separate commit or PR after the split. 1. Pick the file Given a file, use it. Otherwise build a shortlist: The shortlist still contains data tables and generated code; filter it by reading. Prefer a file with: A real extraction boundary: hand-written logic with separable state, sub-domains, or stages, not a lookup table. A repeatable verification surface: behavior that unit or integration tests can observe (including the real-database tests testing requires for models), not one that needs a browser session or live third-party calls. A reviewable scope: one PR can hold the split. When this repository is mounted as a submodule, split a file of the submodule only through a PR to the submodule. Use recent churn (git log --since=3.months --oneline -- <file> wc -l) only to break ties. State the choice and the reason before starting. 2. Read and plan Read the whole file and its tests. Find every reference with rg on the module path and basename across source roots: imports, re-exports, dynamic import(), vi.mock('…/Foo'), explicit extensions, and package entry mappings. Write a short plan before editing: the real boundaries (state, reuse, render update, sub-domain, pipeline stage — see react and source-layout §3) and the module each becomes; the directory layout from source-layout §4, with expected line counts; duplicated branches that will collapse into one module, if any; each behavior the split moves or merges, mapped to the test that will guard it. When a boundary or layout decision is unclear, ask an independent reviewer (a different-vendor harness when available) to critique the plan. 3. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills lobehub/split-large-file

View the source on GitHub

Browse the @skills marketplace