agentleFS
sunholo-datasunholo-data/ailang/.agents/skills/codebase-organizer/SKILL.md

codebase-organizer

Skill38 starsChanged 6 days agoApache-2.0View on GitHub

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.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Only commit when tests pass

    line 109
  2. Distinctive:

    Commit with descriptive message:

    line 125
  3. Distinctive:

    If split creates circular dependency:

    line 139
  4. Distinctive:

    Use interfaces to break dependency

    line 144
  5. Distinctive:

    Test file not updated to match new structure

    line 153

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  • "Check file sizes" / "report file sizes"
  • "Split this file" / "refactor large file"
  • "Organize the codebase"
  • "Make files AI-friendly"

File Size Targets

SizeStatusAction
200-500 linesSweet spotNone needed
500-800 linesAcceptableConsider splitting
>800 linesCRITICALMust 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:
    • Expression parsing vs statement parsing
    • Type inference vs type checking
    • Different AST node types
    • Public API vs internal helpers
  3. Plan file names (match to primary functions):
    • expressions.go → parseExpression(), parseCall()
    • statements.go → parseStatement(), parseLetDecl()
    • helpers.go → utility functions
  4. 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:

  • Tightly coupled functions
  • Helper functions used by one main function
  • Functions that share complex state

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:
    • Extract shared code to new file (e.g., types.go)
    • Use interfaces to break dependency
    • Restructure to have one-way dependency
    • Merge files if truly inseparable (<800 lines combined)

Test Failures

Common issues after split:

  • Missing import in new file
  • Function moved but still referenced in old location
  • Test file not updated to match new structure

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:

  • 0 files over 800 lines
  • <5 files between 500-800 lines
  • Average file size: 300-400 lines
  • 100% test pass rate maintained

Important Reminders

  • ALWAYS run tests before and after refactoring
  • NEVER commit if tests fail
  • One refactoring at a time (easier to debug)
  • Show plan before executing (get user approval)
  • Keep related functions together (maintain cohesion)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.