Use this skill to systematically split large files into smaller, maintainable modules.
Purpose
Refactor oversized files without changing behavior.
Target Selection
- Set a target path to either:
- a specific file, or
- a directory
- If a directory is provided, refactor the largest files first.
Recommended Workflow
- Read and outline the target file or directory structure.
- Evaluate dependencies to determine a safe refactor order.
- Propose a module split plan with clear responsibilities.
- Create new files and move code in small, verifiable steps.
- For very large files, divide the work across multiple phases.
- Preserve public APIs with re-exports or index/mod files.
- Update imports and references after each movement.
- Add or update tests that cover the split modules.
- After each phase, update documentation summarizing what moved and why.
- Publish a final migration report.
Guardrails
- No behavior changes unless explicitly requested.
- Prefer small, cohesive files; avoid creating new monoliths.
- Keep files under approximately 300-400 lines when practical.
- Keep module boundaries explicit and responsibility-focused.
Refactor Report Format
Include the following in completion reports:
- Target path
- Files created
- Files modified
- API surface changes (if any)
- Tests added or updated