Code Intelligence (EFIE)
Relevant source files
The following files were used as context for generating this wiki page:
Code Intelligence, also referred to as the Enhanced File Intelligence Engine (EFIE), is a sophisticated system within M31A designed to provide the AI agent with structural and semantic understanding of a codebase. By parsing source files, building dependency graphs, and indexing symbols, EFIE enables the agent to navigate complex projects with high precision, ensuring that code modifications are consistent with existing types, patterns, and architectural boundaries.
The system supports multiple languages—Go, TypeScript, Python, and Rust—using polyglot parsers (including Tree-sitter) to generate a comprehensive mental model for the agent. This intelligence is automatically injected into the workflow context, reducing errors related to broken imports or duplicated logic.
Sources: README.md:104-106, internal/integrations/codeintel/codeintel.go:21-32, CHANGELOG.md:129-130
Architecture and Components
The Code Intelligence system is centered around the Indexer struct, which serves as a unified API for parsing, graph traversal, and relevance scoring. It utilizes incremental builds and a disk-based cache to maintain performance even in large codebases.
Core Data Structures
| Component | Description |
|---|---|
Indexer | The primary coordinator for codebase intelligence, managing parsers, the import graph, and symbol indexing. |
ImportGraph | A directed graph representing file dependencies, used to trace upstream (imports) and downstream (importers) relationships. |
SymbolIndex | A mapping of symbols (functions, types, interfaces) to their definition locations across the project. |
RelevanceScorer | A logic engine that ranks files based on their structural relationship to a specific task or target file set. |
Sources: internal/integrations/codeintel/codeintel.go:16-27, internal/engine/workflow/prompts/code-intelligence.md:16-24
System Flow
The following diagram illustrates how the Indexer processes the codebase to generate the intelligence context used by the workflow engine.
The build process ensures that only modified files are reparsed when a cache is available, significantly reducing latency during active development sessions.
Sources: internal/integrations/codeintel/codeintel.go:42-178
Intelligence Capabilities
EFIE provides several distinct modes of intelligence that can be queried by the AI agent via the CodeMap tool or injected automatically during the Plan phase.
Query Modes
The system facilitates deep exploration through specialized query types:
- Upstream/Downstream: Identifies dependencies and dependents of a specific file.
- Symbol Lookup: Locates where a specific type, function, or interface is defined.
- Relevance Scoring: Ranks files by their semantic and structural relevance to a task description.
- File Symbols: Lists all exported and defined symbols within a single file.
Sources: internal/integrations/codeintel/codeintel.go:211-238, internal/engine/workflow/prompts/code-intelligence.md:16-24
Relevance Scoring Logic
The RelevanceScorer calculates a score for files based on target files and task descriptions. This is critical for the Plan phase, where the agent needs to know which files are most likely to be affected by a requested change.
// internal/integrations/codeintel/codeintel.go:242-248
func (idx *Indexer) RelevantFiles(targetFiles []string, description string, topN int) []ScoredFile {
idx.mu.RLock()
defer idx.mu.RUnlock()
if idx.scorer == nil {
return nil
}
return idx.scorer.Score(targetFiles, description, topN)
}
Sources: internal/integrations/codeintel/codeintel.go:242-248
Workflow Integration
Code Intelligence is integrated into the M31A workflow through the FormatContext and ProjectSummary methods. These methods transform the raw graph and index data into Markdown summaries that are injected into the LLM's system prompt.
Automated Context Injection
During the Execute phase, EFIE automatically provides:
- Recommended Files: A list of files ranked by relevance to the current task.
- Dependency Mapping: Direct imports and importers for the files being modified.
- Type Definitions: Structural details for symbols referenced in the task description.
Pre-Plan Research
The runResearch function utilizes Code Intelligence to perform a "pre-flight" check of the codebase. It identifies architectural patterns, naming conventions, and potential risks before an implementation plan is even generated.
// internal/engine/workflow/research.go:81-86
// Code intelligence summary
if ci := e.getCodeIntel(context.Background()); ci != nil {
if summary := ci.ProjectSummary(3000); summary != "" {
userCtx.WriteString(summary)
userCtx.WriteString("\n")
}
}
Sources: internal/engine/workflow/research.go:81-86, internal/engine/workflow/prompts/research.md:9-12
Summary
The Code Intelligence (EFIE) system is the structural backbone of M31A's reasoning capability. By maintaining a high-fidelity map of the project—including imports, exports, and symbol definitions—it prevents the agent from making "blind" edits. Whether through automated context injection or manual CodeMap queries, it ensures that every code change is architecturally sound and consistent with the existing codebase.
Sources: README.md:135-136, internal/engine/workflow/prompts/code-intelligence.md:36-40