| name | leindex-code |
| description | Token-efficient code analysis via 5-layer stack (AST, Call Graph, CFG, DFG, PDG). 82% savings (balanced mode) with semantic completeness. |
| allowed-tools | ["Bash"] |
| keywords | ["debug","refactor","understand","complexity","call graph","data flow","what calls","how complex","search","explore","analyze","dead code","architecture","imports"] |
LeIndex-Code: Complete Reference
Token-efficient code analysis with 82% token savings (balanced mode) while preserving semantic completeness for LLM usage.
Quick Reference
| Task | Command |
|---|
| Context extraction | from maestro.leindex import ContextExtractor |
| Semantic search | from maestro.leindex import semantic_search |
| AST analysis | from maestro.leindex import ASTAnalyzer |
| Call graph | from maestro.leindex import CallGraphAnalyzer |
Modes
Balanced Mode (Default) - 82% savings, LLM Actionable
Use for: Code generation, refactoring, implementation
from maestro.leindex import ContextExtractor
extractor = ContextExtractor(mode='balanced')
result = extractor.extract_for_file('src/api.py')
print(f"Savings: {result.savings_percent:.1f}%")
print(result.context.to_llm_string())
Ultra Mode - 98% savings, Exploration Only
Use for: Code exploration, search, impact analysis
extractor = ContextExtractor(mode='ultra')
result = extractor.extract_for_file('src/api.py')
Token Efficiency Comparison
| Mode | Savings | Semantic Quality | LLM Actionable | Use Case |
|---|
| Raw | 0% | Complete | ✓ Yes | Full file |
| Balanced | 82% | High | ✓ Yes | Code generation |
| Ultra | 98% | Low | ❌ No | Exploration only |
Key Insight: Balanced mode at 82% savings is the OPTIMAL balance for LLM-assisted coding. Ultra mode sacrifices too much semantic information (no signatures, no line numbers, no types) for LLM to accurately use the code.
Python API
from maestro.leindex import (
ASTAnalyzer,
CallGraphAnalyzer,
CFGAnalyzer,
DFGAnalyzer,
SlicingAnalyzer,
ContextExtractor,
get_relevant_context,
get_context_for_prompt,
SemanticIndex,
semantic_search,
build_semantic_index,
LeIndexMemoryBridge,
get_leindex_memory_bridge,
)
extractor = ContextExtractor(mode='balanced')
result = extractor.extract_for_file('maestro/leindex/__init__.py')
print(f"Savings: {result.savings_percent:.1f}%")
print(f"Quality: {result.get_quality_report()}")
results = semantic_search("authentication functions", "/path/to/project")
for entity, score in results:
print(f"{entity.name} in {entity.file} (score: {score:.2f})")