Large File Refactor
This skill is coordination-exempt: skip the ai-coord gate for its declared work.
If these instructions are already present in the conversation from a slash or dollar invocation, follow them directly;
do not invoke this skill again through a skill tool.
Use LOC thresholds to discover candidates, then decide whether a split is justified by cohesion, coupling, ownership,
and change risk. Test files use a relaxed 2000 LOC discovery threshold.
Arguments
path: Optional file or directory to scan. Default: current working directory.
--include-generated: Include generated, vendored, dependency, and build-output paths that are skipped by default.
Workflow
Resolve the skill directory, then run the helper from the target repository:
uv run "<skill-dir>/scripts/large-file-refactor.py" [path] [--include-generated]
Preserve the helper's Markdown table as the exhaustive report. Do not omit matching rows, even when the refactor plan
only covers a subset.
If the helper reports no threshold matches, stop after the report. A match is a candidate, not proof that the file
should be split.
Draft a refactor plan for the 3 largest files only, unless the user explicitly requested another count.
For each candidate, rank split value by mixed responsibilities, change frequency/risk, coupling, and testability. Use
whichever semantic symbol/reference tooling is available; prefer Serena when installed:
- Inspect symbol overviews, references, imports, and relevant history.
- Use the evidence to choose extraction boundaries, target module names, migration order, and test coverage.
Do not implement the refactor unless the user separately asks for execution.
Refactor Plan Format
For each selected file, include:
- Current role: the file's apparent responsibility and why line count is a symptom.
- Semantic pass: the exact symbol/reference/history inspection to run before moving code.
- Split proposal: 2-5 target modules or files with responsibilities.
- Migration order: small, reviewable steps that preserve public behavior.
- Verification: narrow tests, type checks, builds, or smoke checks that prove the split.
Lead each plan with one explicit verdict: ### ✂ Split justified, ### 🧱 Keep intact, or
### ⚠️ Generated — change the generator. Use a compact evidence table for repeated criteria. When proposing a split,
show the source and target modules as a tree only when it clarifies ownership.
If a selected file is generated or vendored because --include-generated was used, plan against the generator, schema,
or upstream source instead of hand-splitting generated output.
Guard Rails
- Treat the table as source of truth for size ranking only; rank refactor priority separately.
- Keep the plan cohesive; do not split solely to reduce line count.
- Prefer existing project module boundaries and naming conventions.
- Call out when the helper used its portable LOC estimate instead of
tokei.
Completion
Complete with the exhaustive threshold report plus evidence-ranked plans only for candidates whose cohesion or change
risk justifies a split. Lead with ### 🔎 Large-file scan — <candidate count>, state when a large file should remain
intact and why, and surface the portable-LOC fallback as ⚠️ Approximate counts when used. Keep the helper's exhaustive
table, paths, LOC values, and commands exact and undecorated.
1---
2argument-hint: "[path] [--include-generated]"
3coordination: exempt
4disable-model-invocation: true
5name: large-file-refactor
6description:
7 Discover large source-file refactor candidates and propose cohesion- and risk-driven split plans using available
8 semantic tooling.
9---
10
11# Large File Refactor
12
13This skill is coordination-exempt: skip the ai-coord gate for its declared work.
14
15If these instructions are already present in the conversation from a slash or dollar invocation, follow them directly;
16do not invoke this skill again through a skill tool.
17
18Use LOC thresholds to discover candidates, then decide whether a split is justified by cohesion, coupling, ownership,
19and change risk. Test files use a relaxed 2000 LOC discovery threshold.
20
21## Arguments
22
23- `path`: Optional file or directory to scan. Default: current working directory.
24- `--include-generated`: Include generated, vendored, dependency, and build-output paths that are skipped by default.
25
26## Workflow
27
281. Resolve the skill directory, then run the helper from the target repository:
29
30 ```sh
31 uv run "<skill-dir>/scripts/large-file-refactor.py" [path] [--include-generated]
32 ```
33
342. Preserve the helper's Markdown table as the exhaustive report. Do not omit matching rows, even when the refactor plan
35 only covers a subset.
36
373. If the helper reports no threshold matches, stop after the report. A match is a candidate, not proof that the file
38 should be split.
39
404. Draft a refactor plan for the 3 largest files only, unless the user explicitly requested another count.
41
425. For each candidate, rank split value by mixed responsibilities, change frequency/risk, coupling, and testability. Use
43 whichever semantic symbol/reference tooling is available; prefer Serena when installed:
44
45 - Inspect symbol overviews, references, imports, and relevant history.
46 - Use the evidence to choose extraction boundaries, target module names, migration order, and test coverage.
47
486. Do not implement the refactor unless the user separately asks for execution.
49
50## Refactor Plan Format
51
52For each selected file, include:
53
54- Current role: the file's apparent responsibility and why line count is a symptom.
55- Semantic pass: the exact symbol/reference/history inspection to run before moving code.
56- Split proposal: 2-5 target modules or files with responsibilities.
57- Migration order: small, reviewable steps that preserve public behavior.
58- Verification: narrow tests, type checks, builds, or smoke checks that prove the split.
59
60Lead each plan with one explicit verdict: `### ✂ Split justified`, `### 🧱 Keep intact`, or
61`### ⚠️ Generated — change the generator`. Use a compact evidence table for repeated criteria. When proposing a split,
62show the source and target modules as a tree only when it clarifies ownership.
63
64If a selected file is generated or vendored because `--include-generated` was used, plan against the generator, schema,
65or upstream source instead of hand-splitting generated output.
66
67## Guard Rails
68
69- Treat the table as source of truth for size ranking only; rank refactor priority separately.
70- Keep the plan cohesive; do not split solely to reduce line count.
71- Prefer existing project module boundaries and naming conventions.
72- Call out when the helper used its portable LOC estimate instead of `tokei`.
73
74## Completion
75
76Complete with the exhaustive threshold report plus evidence-ranked plans only for candidates whose cohesion or change
77risk justifies a split. Lead with `### 🔎 Large-file scan — <candidate count>`, state when a large file should remain
78intact and why, and surface the portable-LOC fallback as `⚠️ Approximate counts` when used. Keep the helper's exhaustive
79table, paths, LOC values, and commands exact and undecorated.