Mirage
Path-Aware Code Intelligence Engine for Rust
"An agent may only speak if it can reference a graph artifact."
⚠️ Requires Magellan
Mirage requires Magellan to function.
Magellan provides the AST-based control flow graph (CFG) data that Mirage analyzes. You must run magellan watch on your codebase before using Mirage.
# Install Magellan first
# Watch your project (builds CFG)
# Now Mirage can analyze
The Code Intelligence Toolset
Mirage is part of a coordinated toolset built on sqlitegraph. All tools share a common SQLite graph database and are designed to work together for AI-assisted code understanding.
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Magellan │ ───► │ llmgrep │ ───► │ Mirage │
│(Symbols & │ │ (Semantic │ │(CFG & Paths)│
│ Call Graph)│ │ Search) │ │ │
└─────────────┘ └─────────────┘ └─────────────┘
│ │ │
└────────────────────┴─────────────────────┘
│
┌──────▼──────┐
│ sqlitegraph │
│ (Database) │
└─────────────┘
│
┌──────▼──────┐
│ splice │
│(Edit using │
│ spans) │
└─────────────┘
| Tool | Purpose | Repository | Install |
|---|---|---|---|
| sqlitegraph | Graph database foundation | github.com/oldnordic/sqlitegraph | cargo add sqlitegraph |
| Magellan | Call graph indexing, symbol navigation | github.com/oldnordic/magellan | cargo install magellan |
| llmgrep | Semantic code search | github.com/oldnordic/llmgrep | cargo install llmgrep |
| Mirage | CFG analysis, path enumeration | github.com/oldnordic/mirage | cargo install mirage-analyzer |
| splice | Precision code editing | github.com/oldnordic/splice | cargo install splice |
What is Mirage?
Mirage analyzes control-flow graphs extracted by Magellan to answer questions like:
- What execution paths exist through this function?
- What code MUST execute on any path from entry to exit?
- Which blocks are unreachable (dead code)?
- What is the impact of changing this code?
What Mirage is NOT
- ❌ A search tool (use llmgrep)
- ❌ An embedding or semantic search tool
- ❌ A linter or static analysis tool
- ❌ A code completion engine
- ❌ A call graph indexer (use Magellan)
What Mirage IS
- ✅ CFG analysis from Magellan's AST-based data
- ✅ Path enumeration with BLAKE3 caching
- ✅ Dominance analysis (dominators, post-dominators, frontiers)
- ✅ Loop detection (natural loops within functions)
- ✅ Dead code detection (unreachable blocks)
- ✅ Impact analysis (blast zones, program slicing)
- ✅ Inter-procedural analysis (hotspots, call graph condensation)
Installation
The binary is installed as mirage:
Or build from source:
Quick Start
1. Install the Toolset
# Install all tools for complete workflow
2. Index Your Project
# Magellan watches your source and builds CFG
Magellan will:
- Parse your source code with tree-sitter
- Build AST-based control flow graphs for each function
- Store everything in a SQLite database
3. Analyze with Mirage
# Check database status
# Show all execution paths through a function
# Find unreachable code
# Visualize control flow
|
CLI Commands
| Command | Description |
|---|---|
status |
Database statistics and CFG availability |
paths |
Enumerate execution paths through a function |
cfg |
Visualize control-flow graph (human/dot/json) |
dominators |
Dominance relationships (must-pass-through analysis) |
loops |
Detect natural loops within functions |
unreachable |
Find dead code (unreachable blocks) |
patterns |
Recover if/else and match branching patterns |
frontiers |
Compute dominance frontiers |
verify |
Verify cached path is still valid |
blast-zone |
Impact analysis from a block or path |
cycles |
Detect call graph SCCs and function loops |
slice |
Program slicing (backward/forward) |
hotspots |
Risk scoring based on paths and dominance |
Global Options
| Option | Description |
|---|---|
--db <DB> |
Path to database (default: .codemcp/codegraph.db) |
--output <FORMAT> |
Output: human, json, pretty |
-h, --help |
Print help |
-V, --version |
Print version |
Examples
Path Enumeration
# All paths through a function
# Only error-returning paths
# Limit exploration depth
# JSON output for scripting
|
Dominance Analysis
# Show dominance tree
# What MUST execute before this block?
# Post-dominators (what must execute after)
# Inter-procedural (call graph level)
Impact Analysis
# What does this block affect?
# What affects this function? (backward slice)
# What does this function affect? (forward slice)
# High-risk functions
Database Schema
Mirage extends the Magellan database with:
| Table | Purpose |
|---|---|
cfg_blocks |
Basic blocks within functions (from Magellan) |
cfg_paths |
Enumerated execution paths with BLAKE3 IDs |
cfg_dominators |
Dominance relationships |
The default database location is .codemcp/codegraph.db. This is shared with Magellan.
Requirements
- Rust 1.77+
- Magellan — Required for CFG extraction
- sqlitegraph — Included automatically as dependency
License
GPL-3.0-or-later
Related Projects
- sqlitegraph — Graph database library
- Magellan — Call graph indexer
- llmgrep — Semantic search
- splice — Precision editing