Codebase organizer

From sunholo-data/ailang · View interactive version

Codebase organizer is an AI agent skill from the GitHub repository sunholo-data/ailang. 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.

How to use this skill

Skill file

Codebase Organizer

Maintain optimal file sizes for AI-assisted development by splitting large files into focused modules.

Quick Start

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

When to Use This Skill

Invoke when user says:

File Size Targets

| Size | Status | Action |

|------|--------|--------|

| 200-500 lines | Sweet spot | None needed |

| 500-800 lines | Acceptable | Consider splitting |

| >800 lines | CRITICAL | Must split |

Workflow

Step 1: Status Check

# 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

Step 2: Plan the Split

Before ANY refactoring:

  1. Run baseline tests: make test
  2. Identify natural boundaries:
  1. Plan file names (match to primary functions):
  1. Check for circular dependency risks

Step 3: Execute Split

# 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:

Step 4: Validate

# 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:

  1. DO NOT COMMIT
  2. Analyze failure (missing import? broken reference?)
  3. Fix issue
  4. Re-run tests
  5. Only commit when tests pass

Step 5: Document & Commit

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)
..."

Error Handling

Circular Dependency

If split creates circular dependency:

  1. Identify cycle: File A imports B, File B imports A
  2. Solutions:

Test Failures

Common issues after split:

Example Session

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.

Success Metrics

After refactoring:

Important Reminders

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.