skills/large-file-refactorer/SKILL.md
Scans codebase for large files and orchestrates refactoring workflows using a test-first protocol
npx skillsauth add alcyone-labs/agent-skills large-file-refactorerInstall 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.
Expert agent for identifying oversized code files and orchestrating safe refactoring via test-first protocols.
Request: Find/refactor large files
A. Discovery
- Determine threshold (default 500 lines)
- Glob: **/*.{ts,js,tsx,jsx,py,rb,go}
- Filter: exclude generated, node_modules, dist, lock files, configs
B. Analysis
- Read each large file (wc -l)
- Identify classes/functions/imports
- Check test coverage (exists? *.test.ts *.spec.ts)
- Score: P0 (core logic, no tests) > P1 (frequent imports) > P2 (utilities, tests) > P3 (skip)
C. Presentation
- Report: X files above threshold
- Group by priority (P0-P3)
- Ask: "Process all high-priority? All? Select specific?"
D. Orchestration (per approved file)
- Load references/refactoring-protocol/README.md
- Execute 5-phase protocol:
1. Assessment
2. Test Coverage (CRITICAL - no skip)
3. Refactoring
4. Verification
5. Documentation
- Wait for verification pass before next file
E. Reporting
- Summary: analyzed, above threshold, refactored, skipped, duration
- Per-file breakdown: before/after lines, files created, test coverage change
- Recommendations: CI limits, pre-commit hooks, design guidelines
| Format | Examples | Default | |-------------|----------------------|---------| | Lines | "500 lines", "500" | 500 | | Kilobytes | "50KB", "50kb" | 50KB | | Characters | "50 chars" | 5000 |
*.generated.ts, *.d.ts, *.generated.jsnode_modules/, vendor/, dist/, build/*.min.js, *.bundle.jspackage-lock.json, yarn.lock, pnpm-lock.yamltsconfig.json, .eslintrc*, .oxfmtrc.json, aquaria.config.json| Priority | Criteria | Action | |----------|-----------------------------------------------|--------------------------| | P0 | Core business logic, high complexity, no tests | Process immediately | | P1 | Frequently imported, moderate complexity | Process after P0 | | P2 | Utility functions, good test coverage | Process if user approves | | P3 | Generated or low-value code | Skip with explanation |
| Tool | Purpose |
|--------|---------------------------------------|
| glob | Find all code files |
| bash | Check file sizes (wc -l), run tests |
| grep | Search for patterns during analysis |
| read | Quick inspection of file structure |
If refactoring fails:
If glob/bash fails:
Input: "Find files larger than 300 lines and refactor the important ones"
Process:
**/*.{ts,tsx,js,jsx}wc -l | awk '$1 > 300'Output:
# Large File Refactoring Report
## Summary
- Files analyzed: 150
- Files above threshold: 12
- Files refactored: 7 (P0-P1)
- Files skipped: 5 (P2 deferred, P3 excluded)
- Total time: 2h 15m
## Files Successfully Refactored
### src/core/UserManager.ts (800 lines)
**Before**: Single file with 800 lines, 3 classes, 15 functions
**After**: Split into 4 files (total 800 lines)
- `UserRepository.ts` (200 lines) - Data access
- `UserValidator.ts` (150 lines) - Validation
- `UserService.ts` (270 lines) - Business logic
- `UserManager.ts` (180 lines) - Orchestrator
**Test Coverage**: Before 0% → After 92% (35 new tests)
**Status**: ✅ All tests passing
Input: "Check src/ directory for large files (dry run only)"
Process:
src/**/*.{ts,js} onlyOutput:
## Found 8 files exceeding 500 lines in src/
### High Priority (P0-P1) - Recommend Refactoring
1. **src/core/UserManager.ts** (800 lines) - Core auth logic, no tests
2. **src/controllers/OrderController.ts** (650 lines) - High complexity, partial tests
### Medium Priority (P2) - Ask Before Processing
3. **src/utils/StringUtils.ts** (520 lines) - Utilities, good tests
Would you like me to:
- Process all high-priority files automatically?
- Process all files?
- Select specific files to refactor?
Input: "I'm worried about breaking tests during refactoring"
Process:
npm test if user agreesOutput:
✅ Baseline test run complete
- Total tests: 247
- Passing: 238 (96%)
- Failing: 9 (4%) - documented known issues
Will proceed with refactoring, maintaining current failure baseline.
No new failures will be introduced.
development
Builds precise production-ready custom Agent Skills following AgentSkills.io guidelines. Use when user requests to create, refine or package Skills
development
Best practices for using simple-logger in TypeScript applications
tools
Implement Sauve-specific Jazz extension behavior on top of worker-authority architecture and typed popup-worker protocol
tools
Test Chrome extensions (Manifest V3) headlessly with Playwright — load unpacked extensions, extract the extension ID, test popups/content scripts/background, run reliably in CI, and use the correct headless mode that actually supports extensions.