agentic/code/frameworks/sdlc-complete/skills/decompose-file/SKILL.md
Analyze large source files and produce decomposition plans, optionally executing refactoring with import updates and test verification
npx skillsauth add jmagly/aiwg decompose-fileInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Analyze a large source file and produce a concrete decomposition plan, optionally executing the refactoring with import updates and test verification.
Alternate expressions and non-obvious activations (primary phrases are matched automatically from the skill description):
When /codebase-health identifies files exceeding agent-friendly thresholds (300 LOC warning, 500 LOC error), this skill provides guided decomposition. It analyzes file structure, identifies logical groupings, maps internal dependencies, proposes a split plan, and optionally executes the refactoring.
The doc-splitter skill handles documentation splitting. This skill handles source code splitting — a fundamentally different problem requiring dependency analysis, import rewiring, and test verification.
When triggered, this skill:
Analyze file structure:
Map internal dependencies:
Propose split plan:
Show dependency graph:
Execute refactoring (if --execute or user approves):
| Language | Strategy | Boundaries |
|----------|----------|------------|
| TypeScript/JavaScript | AST via function/class/export declarations | export, class, function, const |
| Python | AST via ast module | class, def, top-level assignments |
| Go | Package-level function/type declarations | func, type, var blocks |
| Rust | mod, fn, struct, impl blocks | Module and impl boundaries |
| Java | Class and method declarations | class, interface, enum |
For unsupported languages or when AST parsing is unavailable:
// --- Section Name ---)Decomposition Plan for src/extensions/registry.ts (847 lines)
Current Structure:
1. Imports and type definitions (lines 1-45)
2. ExtensionRegistry class (lines 47-320)
2a. Constructor and initialization (lines 47-85)
2b. register() — registers an extension (lines 87-145)
2c. lookup() — finds extension by name (lines 147-210)
2d. listByType() — returns extensions of a type (lines 212-260)
2e. unregister() — removes an extension (lines 262-320)
3. Validation functions (lines 322-480)
3a. validateExtension() (lines 322-390)
3b. validateManifest() (lines 392-440)
3c. checkDependencies() (lines 442-480)
4. Discovery helpers (lines 482-620)
5. Deployment logic (lines 622-847)
Proposed Split:
1. src/extensions/registry.ts (185 lines)
— ExtensionRegistry class (core registration, lookup, list, unregister)
— Imports from: validation, discovery, deployment
2. src/extensions/extension-validator.ts (160 lines)
— validateExtension(), validateManifest(), checkDependencies()
— No internal dependencies
3. src/extensions/extension-discovery.ts (140 lines)
— discoverExtensions(), globForType(), resolveExtensionPath()
— Imports from: extension-validator
4. src/extensions/extension-deployer.ts (227 lines)
— deployToProvider(), buildProviderConfig(), writeDeploymentFiles()
— Imports from: registry, extension-validator
Dependency Graph:
registry → extension-validator
registry → extension-discovery
registry → extension-deployer
extension-discovery → extension-validator
extension-deployer → registry, extension-validator
Circular Dependencies: NONE ✓
All proposed files under 300 LOC warning threshold ✓
| Argument | Required | Default | Description |
|----------|----------|---------|-------------|
| <file-path> | Yes | — | File to decompose |
| --max-lines <n> | No | 300 | Target max lines per output file |
| --dry-run | No | true | Show plan without executing |
| --execute | No | false | Execute the plan automatically |
| --language <lang> | No | auto-detect | Override language detection |
| --strategy <type> | No | auto | function, class, or responsibility |
| --preserve-exports | No | true | Maintain backward-compatible re-exports |
When --execute is used:
┌─────────────────────────────────────────────┐
│ 1. ANALYZE │
│ • Parse file structure │
│ • Identify logical sections │
│ • Map dependencies │
└──────────────┬──────────────────────────────┘
▼
┌─────────────────────────────────────────────┐
│ 2. PLAN │
│ • Propose split into N files │
│ • Verify no circular dependencies │
│ • Show plan to user │
└──────────────┬──────────────────────────────┘
▼
┌─────────────────────────────────────────────┐
│ 3. EXECUTE │
│ • Create new files with content │
│ • Add purpose statements │
│ • Update original file (re-exports) │
└──────────────┬──────────────────────────────┘
▼
┌─────────────────────────────────────────────┐
│ 4. REWIRE │
│ • Find all imports of original file │
│ • Update to point to new modules │
│ • Handle re-exports for compat │
└──────────────┬──────────────────────────────┘
▼
┌─────────────────────────────────────────────┐
│ 5. VERIFY │
│ • Run tests │
│ • Check for import errors │
│ • Report pass/fail │
└─────────────────────────────────────────────┘
User: "decompose src/extensions/registry.ts"
Skill analyzes the file and produces:
- Current structure map with line ranges
- Proposed split into 4 files
- Dependency graph
- Verification: no circular dependencies
Output shows the plan without making changes.
User: "/decompose-file src/extensions/registry.ts --execute"
Skill:
1. Analyzes and shows plan
2. Creates 4 new files
3. Updates registry.ts to re-export for compatibility
4. Finds 23 files importing from registry.ts
5. Updates imports to point to specific modules
6. Runs test suite: 247 passed, 0 failed ✓
Output:
"Decomposition complete. 1 file (847 lines) → 4 files (avg 178 lines).
All tests passing. 23 import statements updated."
User: "/decompose-file src/services/user-service.ts --strategy class --max-lines 200"
Skill splits by class boundaries, targeting 200 lines per output file.
File src/utils/helper.ts is 85 lines — below the warning threshold (300).
No decomposition needed. Use --max-lines to override if desired.
⚠ Proposed split would create circular dependency:
module-a → module-b → module-a
Suggestions:
1. Extract shared code into a common module
2. Merge module-a and module-b sections
3. Use dependency injection to break the cycle
Adjusted plan: [shows revised plan]
🚫 Tests failed after decomposition.
Failures:
test/unit/registry.test.ts:42 — Cannot find module './registry'
Root cause: Import path not updated in test file.
Fix: Updating test imports...
Re-running tests: 247 passed, 0 failed ✓
This skill uses:
agent-friendly-code rule: Target thresholds for output file sizesagent-generation-guardrails rule: Prevents creating new large files during splitexecutable-feedback rule: Runs tests after execution to verify no breakageanti-laziness rule: Does not skip the split because it is complex/codebase-health command: Identifies candidates for decomposition.aiwg/working/decompose-{filename}-{date}.mddata-ai
Report which research-corpus radar sidecars are overdue for refresh. Computes staleness (days since last refresh vs the cadence window) for every radar, sorted most-overdue-first. Runs via `aiwg corpus radar-status`.
data-ai
Aggregate research-corpus radar sidecars into a corpus or per-cluster freshness report — totals, overdue count, per-cluster / per-GRADE / per-trajectory breakdowns, an overdue table, and per-radar rationale snippets. Runs via `aiwg corpus radar-report`.
testing
Scaffold radar/freshness sidecars for research-corpus REFs. Pulls title/authors from the citation sidecar and GRADE from the analysis doc, defaults the refresh cadence from GRADE and the cluster from a corpus-local map, and stamps documentation/radar/REF-XXX-radar.md. Runs via `aiwg corpus radar-init`.
data-ai
Compute an entity's publication trajectory — per-year paper counts, topic drift, hot-streak detection (≥3 consecutive A-grade years), and career phase. Runs via `aiwg corpus profile-temporal`.