Monitor and refactor large files into smaller, AI-friendly modules. Use when user asks to check file sizes, split large files, or organize the codebase. Ensures tests pass before and after refactoring.
Maintain optimal file sizes for AI-assisted development by splitting large files into focused modules.
Most common usage:
# Check file sizes
make report-file-sizes
# If files >800 lines found:
# 1. Analyze structure
# 2. Plan split
# 3. Execute with test validation
Invoke when user says:
| Size | Status | Action | |------|--------|--------| | 200-500 lines | Sweet spot | None needed | | 500-800 lines | Acceptable | Consider splitting | | >800 lines | CRITICAL | Must split |
# Find all large files
make report-file-sizes
# Or manually:
find internal -name "*.go" -exec wc -l {} \; | awk '$1 > 500 {print}' | sort -rn
Output format:
=== File Size Report ===
CRITICAL (>800 lines):
internal/types/typechecker_core.go: 2736 lines
internal/parser/parser.go: 2518 lines
WARNING (500-800 lines):
internal/eval/eval_core.go: 765 lines
Before ANY refactoring:
Run baseline tests: make test
Identify natural boundaries:
Plan file names (match to primary functions):
expressions.go → parseExpression(), parseCall()statements.go → parseStatement(), parseLetDecl()helpers.go → utility functionsCheck for circular dependency risks
# 1. Create new files with clear names
# 2. Move related functions together (maintain cohesion)
# 3. Update imports in all affected files
# 4. Keep main struct in pkg.go
Keep together:
# MUST run after every split
make test # All tests must pass
make lint # No linting errors
make check-file-sizes # Verify all <800 lines
If tests fail:
Update package documentation:
// Package parser implements AILANG source code parsing.
//
// # Architecture
//
// The parser is split into several files:
// - parser.go: Main struct and entry points
// - expressions.go: Expression parsing
// - statements.go: Statement parsing
Commit with descriptive message:
git add internal/path/*.go
git commit -m "Split path/file.go into N files (AI-friendly)
- parser.go: Main struct (200 lines)
- expressions.go: Expression parsing (450 lines)
..."
If split creates circular dependency:
types.go)Common issues after split:
User: "Check codebase organization"
Response:
Running make report-file-sizes...
=== File Size Report ===
CRITICAL (>800 lines):
internal/parser/parser.go: 2518 lines
WARNING (500-800 lines):
internal/eval/eval_core.go: 765 lines
Recommendation: Split internal/parser/parser.go into ~6 focused files.
Would you like me to analyze and propose a split plan?
User: "Yes, split parser.go"
Response:
Analyzing internal/parser/parser.go (2518 lines)...
Proposed split:
parser.go (200 lines) - Main struct, entry points
expressions.go (450 lines) - Expression parsing
statements.go (400 lines) - Declaration parsing
types.go (300 lines) - Type annotation parsing
patterns.go (350 lines) - Pattern parsing
modules.go (300 lines) - Module system
helpers.go (200 lines) - Utilities
Proceed? Tests will run before and after.
After refactoring:
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer