Overview
Repo Intelligence is Loom’s context-aware code understanding system. It indexes your repository, extracts symbols, and generates relevance-ranked maps to help the AI understand your codebase structure.Core Components
1. File Index (Loom.RepoIntel.Index)
An ETS-based in-memory index of all files in your repository.
What It Tracks
Language Detection
Supports 15+ languages via file extension:| Language | Extensions |
|---|---|
| Elixir | .ex, .exs |
| JavaScript | .js, .jsx, .mjs |
| TypeScript | .ts, .tsx |
| Python | .py |
| Ruby | .rb |
| Rust | .rs |
| Go | .go |
| And more… | See lib/loom/repo_intel/index.ex:46 |
Skipped Files
The index automatically skips:API Usage
2. Symbol Extraction (Loom.RepoIntel.TreeSitter)
Extracts functions, classes, modules, and types from source code.
Two-Tier Strategy
- Tree-sitter (AST-based) - If
tree-sitterCLI is available - Enhanced regex fallback - If tree-sitter is unavailable
Tree-sitter provides more accurate extraction but requires the
tree-sitter CLI to be installed. The regex fallback works well for most cases.Supported Languages
- Elixir (modules, functions, macros, types, specs)
- JavaScript/TypeScript (functions, classes, interfaces, types, enums)
- Python (classes, functions, async functions)
- Ruby (classes, modules, methods, attributes)
- Go (functions, methods, structs, interfaces)
- Rust (functions, structs, enums, traits, impls)
Example: Elixir Symbols
Caching
Symbol extraction results are cached in ETS by file path and mtime:View caching logic
View caching logic
3. Repository Map (Loom.RepoIntel.RepoMap)
Generates a ranked, token-budgeted map of your repository for the AI.
Relevance Ranking
Files are scored based on:-
Intrinsic importance
- Entry points (e.g.,
application.ex) score 20 - Config files (e.g.,
mix.exs) score 18 - Router files score 15
- Files in
lib/score 10 - Files in
test/score 5
- Entry points (e.g.,
- Mentioned in conversation - +100 bonus
- Keyword matches - +10 per keyword
Map Generation
The map is structured markdown within a token budget:Relevance labels:
- high - Score ≥ 100 (mentioned or critical files)
- medium - Score 10-99
- low - Score < 10
4. File Watcher (Loom.RepoIntel.Watcher)
Monitors the file system for changes and auto-updates the index.
Features
- OS-level notifications via
FileSystemlibrary (inotify/FSEvents/polling) - Debouncing - Collects changes for 200ms before processing
- Gitignore support - Respects
.gitignorepatterns - PubSub broadcasting - Notifies subscribers of repo changes
Change Processing
Gitignore Parsing
The watcher parses.gitignore and converts glob patterns to regex:
5. Context Packer (Loom.RepoIntel.ContextPacker)
Packs ranked files into a token-budgeted context string with tiered detail:
- High relevance (score ≥ 100): Full file content
- Medium relevance (score 10-99): Symbols only
- Low relevance (score < 10): Filename only
lib/loom/application.ex (relevance: medium)
module: Loom.Application (line 1) function: start (line 6)lib/loom/config.ex
Example Workflow
Repo map is injected into system prompt
The LLM receives:
- Base system prompt
- Repo map (files matching “session” and “error”)
- Decision context
- Conversation history
Performance Considerations
Indexing Speed
- Initial scan - ~1000 files/second on SSD
- Incremental refresh - ~5000 files/second (only stat checks)
- ETS lookups - Microseconds (read concurrency enabled)
Memory Usage
ETS tables use ~100 bytes per file entry:- 10,000 files ≈ 1 MB
- 100,000 files ≈ 10 MB
- 10,000 source files ≈ 5 MB
Optimization Tips
Add large generated directories to .gitignore
Add large generated directories to .gitignore
Skip indexing build artifacts, dependencies, etc.:
Use incremental refresh over full rebuild
Use incremental refresh over full rebuild
Tune the repo map token budget
Tune the repo map token budget
Lower budgets = faster generation, less context:
Clear the symbol cache periodically
Clear the symbol cache periodically
If memory usage is a concern:The cache will rebuild lazily as symbols are extracted.
Advanced Usage
Custom Symbol Extraction
Add support for a new language:Ranking Customization
Override the base scoring:Query Patterns
Use glob patterns for complex queries:Troubleshooting
Index is empty after startup
Index is empty after startup
Check if the project path is set correctly:
Watcher not detecting changes
Watcher not detecting changes
-
Verify the watcher is running:
-
Check if the file is gitignored:
-
Try manual refresh:
Repo map is always empty
Repo map is always empty
Ensure files exist and are indexed:
Symbol extraction returns empty list
Symbol extraction returns empty list
-
Check if tree-sitter is installed:
-
Verify the language is supported:
-
Check the regex patterns for your language in
tree_sitter.ex
Future Enhancements
- LSP integration - Use Language Server Protocol for precise symbols
- Call graph analysis - Track function dependencies
- Semantic search - Embed code snippets for similarity search
- Cross-reference tracking - Find all usages of a symbol
- Git blame integration - Show recent changes and authors
- Incremental parsing - Only re-parse changed functions, not entire files
Next Steps
Context Window
See how repo maps fit into the context budget
Sessions
Learn how sessions use repo intelligence