move-only-decomposition
Skill1 starsChanged 30 days agoMITView on GitHub
Decompose a file that is near the line ceiling without changing behaviour, and prove the move. Use when a loc/threshold sensor warns at or above the decomposition band, when `do-harness split` refuses because the file is under the hard ceiling, when an inline test module is what makes a file large, or when reviewing a refactor whose diff is almost entirely moved code. Triggers: "loc warning", "450 lines", "500-line ceiling", "extract module", "move code", "move-only diff", "split refuses".
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- codacy-analysis-cliSkill
- codacy-cloud-cliSkill
- codacy-code-reviewSkill
- configure-codacy-cloudSkill
- configure-codacySkill
- crates-io-name-checkSkill
- event-modelerSkill
- fail-closed-proxySkill
- harnessSkill
- htn-plannerSkill
- issue-to-prSkill
- nested-build-isolationSkill
- npm-github-publishSkill
- pr-triageSkill
- setup-coverageSkill
- skill-creatorSkill
- skill-distillerSkill
- spike-runnerSkill
- tokio-performanceSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 44
Keep the module *name* (tests) so test identities (module::tests::case) survive.
- Distinctive: line 58
Never split purely by line count, and never mix a rename or a behaviour fix into the move — the proof below cannot distinguish your …
- Very specific: line 67
Delete the old declaration: two mod declarations for one file body is a compile error, and a stale inline copy is worse.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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.
Files
Move-Only Decomposition
A file in the warning band is a feedforward signal: decompose deliberately before it reaches the hard ceiling, where the change stops being reviewable and starts being urgent.
Step 1 — find the band, then ignore the mechanical tool
do-harness loc --warn # files at or above the decomposition thresholddo-harness split only acts on files that already exceed the hard ceiling; for a
file inside the warning band it answers "already under the ceiling" and does
nothing. In the band you choose the seam yourself — that is the point, because a
line-count-driven split produces a module nobody wants.
Step 2 — pick a cohesive seam
Best seams, in order of how little they disturb reviewers:
The inline
#[cfg(test)] mod tests. It is already a unit, and moving it changes no production code:#[cfg(test)] #[path = "<stem>_tests.rs"] mod tests;Keep the module name (
tests) so test identities (module::tests::case) survive; the#[path]attribute — not a rename — is what the layout change is for. Child modules reach the parent's private items, so moved tests keep using the fixtures they already had.A behaviour group. A set of functions that already share a subject (database commands, one language's scaffolding) becomes a submodule; keep the public path stable with a re-export:
mod db; pub use db::{InitDbOpts, init_db, maintenance, seed};- Constants that belong to one behaviour, moved next to it.
Never split purely by line count, and never mix a rename or a behaviour fix into the move — the proof below cannot distinguish your improvement from a mistake.
Step 3 — keep the mechanics honest
- Fix relative paths:
include_str!("../templates/x")becomesinclude_str!("../../templates/x")when the code moves one directory deeper. - A moved item keeps its visibility unless the new path needs less: prefer
pub(super)/pub useover widening everything. - Delete the old declaration: two
moddeclarations for one file body is a compile error, and a stale inline copy is worse.
Step 4 — prove the move
Raw line comparison is useless: cargo fmt re-wraps whatever it likes. Compare
token streams with all whitespace collapsed, then let the compiler and tests
speak:
import re, sys
def tokens(path):
return " ".join(open(path, encoding="utf-8").read().split())
def tokens_body(text):
return " ".join(text.split())
src, dest = sys.argv[1], sys.argv[2]
old = re.search(r"mod tests \{\n(.*)\n\}$", open(src, encoding="utf-8").read(), re.S).group(1)
print("tokens preserved =", tokens_body(old) == tokens(dest))Then: cargo fmt, the affected test target, cargo clippy -- -D warnings, and
do-harness loc --warn to show the band cleared. A dropped or re-ordered line
surfaces as a failed assertion or an unused-import warning; anything else means
the move was not move-only.
Anti-patterns
- Splitting by line count alone. Choosing the largest block instead of a cohesive one produces a module with no reason to exist and reviewers who cannot see the seam.
- Proving the move by diffing text line by line.
cargo fmtre-wraps, so line comparison reports false differences and hides real ones; collapse whitespace first and confirm with the test suite. - Folding a rename or a fix into the move. The move stops being provable and the review stops being cheap.
- Leaving the inline copy behind. The file keeps its size and the new module is dead code.
Gotchas
- A file whose inline test module is most of its length is a one-step fix: the production code never moves.
- Re-exports keep call sites unchanged, which is what makes a large-looking diff safe to review.
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
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.

