A high-performance learning system for Claude Code that improves context injection through pattern recognition, reinforcement learning, and causal reasoning.
Features • Installation • Quick Start • CLI Commands • Benchmarks
MANA transforms Claude Code into a continuously learning assistant by:
- 🔍 Extracting patterns from interactions via hooks
- 📈 Learning from trajectories to understand what works
- ⚡ Injecting context in under 10ms for real-time assistance
- 🔄 Adapting patterns across sessions and projects
- 🧬 Reasoning causally about why patterns succeed together
- 🌐 Synchronizing knowledge across workspaces with encryption
| Feature | Description |
|---|---|
| Pattern Learning | Automatically extracts and stores successful patterns from Claude Code sessions |
| Context Injection | Pre-hook system injects relevant patterns before tool execution (<10ms) |
| Trajectory Analysis | Learns from entire conversation flows, not just individual commands |
| Failure Analysis | Root cause analysis of failed operations with Reflexion-style learning |
MANA implements 9 RL algorithms for adaptive pattern optimization:
| Algorithm | Type | Best For |
|---|---|---|
| 📊 Q-Learning | Off-policy TD | Classic, effective baseline |
| 🎯 SARSA | On-policy TD | Safer exploration |
| 🧠 DQN | Deep Q-Network | Function approximation |
| 🎲 Policy Gradient | REINFORCE | Direct policy optimization |
| 🎭 Actor-Critic | Value + Policy | Lower variance training |
| 🚀 PPO | Proximal Policy | Stable, sample efficient |
| 🔮 Decision Transformer | Sequence Modeling | Return-conditioned RL |
| 🌳 MCTS | Monte Carlo Tree Search | Simulation-based planning |
| 🏗️ Model-Based | Dynamics Learning | Sample efficient MPC |
Pattern A ──[Causes]──► Pattern B
│ │
└──[Enables]────────────┘
- Do-Calculus interventions with confidence intervals
- Confounder detection using Pearl's backdoor criterion
- Multi-hop causal chains via BFS pathfinding
- Relation types: Causes, Enables, Prevents, Correlates, Precedes, DerivedFrom, Contradicts
- Lift interpretation: >1.5 = synergy, <0.5 = conflict
Leverages simsimd for vectorized operations:
- 4-8x speedup on x86 (AVX2/AVX-512)
- 3-5x speedup on ARM (NEON)
- Sub-microsecond similarity for 384-dim vectors
- Supports: Cosine, Euclidean, Dot Product, Inner Product
| Backend | Use Case | Features |
|---|---|---|
| 📁 Git | Simple, offline | Gitea/GitLab compatible |
| ☁️ S3 | Scalable | MinIO, SeaweedFS support |
| 🗄️ Supabase | Teams | Real-time collaboration |
| 🔗 P2P | Decentralized | CRDT merge, mesh network |
Security: AES-256-GCM encryption, Argon2 key derivation, path sanitization, secret redaction
- Track why patterns were selected
- Full reasoning chains with justification
- Verify provenance integrity
- Human-readable explanations
- Rust 1.70+ (2021 edition)
- SQLite 3.x (bundled)
cd mana
cargo build --release# Enable S3 sync support
cargo build --release --features s3
# Enable Supabase team collaboration
cargo build --release --features supabase
# Enable all features
cargo build --release --all-featuresmana initmana daemon startmana statusmana patterns list# Context injection (pre-hook)
mana inject --tool bash
# Process session end
mana session-end
# Manual consolidation
mana consolidate
# View statistics
mana stats# List all patterns
mana patterns list
# Search patterns
mana patterns search "docker build"
# Show pattern details
mana patterns show <pattern_id>
# Export/Import patterns
mana patterns export --output patterns.json
mana patterns import --input patterns.json# View causal graph stats
mana causal stats
# Run do-calculus intervention
mana causal intervention <treatment_id> <outcome_id>
# Find causal chains
mana causal chains <from_id> <to_id>
# Detect confounders
mana causal confounders <treatment_id> <outcome_id># Transfer patterns from another project
mana transfer from /path/to/source
# List transferable patterns
mana transfer list /path/to/source
# Transfer RL policy
mana transfer policy /path/to/source# Initialize sync with a backend
mana sync init --backend git --remote git@github.com:user/patterns.git
mana sync init --backend s3 --bucket my-mana-bucket
mana sync init --backend supabase --url https://xxx.supabase.co
# Push/Pull patterns
mana sync push
mana sync pull
# Check sync status
mana sync status# Create a team
mana team create "My Team"
# List teams
mana team list
# Invite members
mana team invite <team_id> user@email.com
# Share patterns with team
mana team share <team_id> <pattern_ids># Start daemon (background)
mana daemon start
# Start in foreground (debug)
mana daemon start --foreground
# Stop daemon
mana daemon stop
# View daemon logs
mana daemon logs --tail# Check health status
mana health status
# Prune low-quality patterns
mana health prune
mana health prune --dry-run # Preview only
# Relearn from scratch
mana relearn# Explain why a pattern was selected
mana provenance explain <pattern_id>
# Show full provenance
mana provenance show <pattern_id>
# Justify recent actions
mana provenance justify <action>
# Verify integrity
mana provenance verify| Metric | Target | Description |
|---|---|---|
| ⚡ Context Injection | <10ms | Time to inject relevant patterns |
| 🔍 Pattern Search | <0.5ms | HNSW approximate nearest neighbor |
| 💾 Similarity Cache Hit | <10μs | In-memory cache lookup |
| 📝 Session-End Parse | <20ms | Log parsing and analysis |
| 🚀 Binary Startup | <50ms | Cold start time |
| 🧮 SIMD Vector Ops | <1μs | 384-dimensional vectors |
# Run SIMD benchmark suite
mana bench simd
# Run full benchmark suite (requires criterion)
cargo benchBenchmark: 384-dimensional vectors
┌────────────────────┬───────────┬──────────┐
│ Metric │ Scalar │ SIMD │
├────────────────────┼───────────┼──────────┤
│ Cosine Similarity │ 12.3 μs │ 0.8 μs │
│ Euclidean Distance │ 10.1 μs │ 0.6 μs │
│ Dot Product │ 8.7 μs │ 0.5 μs │
│ Batch (1000 pairs) │ 11.2 ms │ 1.4 ms │
└────────────────────┴───────────┴──────────┘
Speedup: 8-15x on AVX-512
Context Injection Pipeline:
┌─────────────────────────────────────────────────────┐
│ 1. Socket connect .......... 0.1ms │
│ 2. Query parse ............. 0.2ms │
│ 3. Embedding lookup ........ 1.2ms │
│ 4. HNSW search ............. 0.4ms │
│ 5. Causal filtering ........ 0.8ms │
│ 6. Pattern ranking ......... 0.3ms │
│ 7. Response serialize ...... 0.2ms │
├─────────────────────────────────────────────────────┤
│ TOTAL ...................... 3.2ms (target: <10ms) │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ MANA System │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Hooks │ │ Daemon │ │ Storage │ │
│ │ ────────── │ │ ────────── │ │ ────────── │ │
│ │ • Pre-hook │───►│ • Socket │───►│ • SQLite │ │
│ │ • Post-hook │ │ • Cache │ │ • HNSW Index │ │
│ │ • Session │ │ • Background │ │ • Embeddings │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Learning │ │ Causal │ │ Sync │ │
│ │ ────────── │ │ ────────── │ │ ────────── │ │
│ │ • RL Suite │◄──►│ • Do-calc │◄──►│ • Git │ │
│ │ • Transfer │ │ • Chains │ │ • S3 │ │
│ │ • Reflexion │ │ • Lift │ │ • Supabase │ │
│ │ • Trajectory │ │ • Confound │ │ • P2P/CRDT │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
mana/
├── src/
│ ├── main.rs # CLI interface (2,576 lines)
│ ├── daemon/ # Background service
│ ├── embeddings/ # Vector embeddings & HNSW
│ ├── hooks/ # Claude Code integration
│ ├── learning/ # RL algorithms & transfer
│ ├── reflection/ # Pattern effectiveness
│ ├── storage/ # SQLite, causal, patterns
│ └── sync/ # Multi-workspace sync
├── tests/ # Integration tests
├── benches/ # Criterion benchmarks
└── docs/ # Documentation
MANA uses TOML configuration at .mana/config.toml:
[general]
log_level = "info"
[daemon]
socket_path = ".mana/daemon.sock"
cache_size = 1000
[learning]
min_success_rate = 0.6
prune_threshold = 0.3
[sync]
backend = "git"
auto_sync = true
encrypt = true
[embeddings]
model = "minilm"
dimensions = 384| Document | Description |
|---|---|
| ARCHITECTURE.md | Core mission & system design |
| CAUSAL_SYSTEM_SUMMARY.md | Causal reasoning overview |
| TRANSFER_QUICKSTART.md | Transfer learning guide |
| HEALTH_MONITORING.md | Health & pruning |
| SIMD_INTEGRATION.md | SIMD acceleration |
| PROVENANCE_IMPLEMENTATION.md | Explainability system |
| CHANGELOG.md | Version history |
# Debug build
cargo build
# Release build (optimized)
cargo build --release
# With all features
cargo build --release --all-features# Run all tests
cargo test
# Run specific test
cargo test causal
# Run with output
cargo test -- --nocapture# Run Criterion benchmarks
cargo bench
# Run built-in SIMD benchmark
cargo run --release -- bench simd[profile.release]
lto = true # Link-time optimization
codegen-units = 1 # Better optimization
panic = "abort" # Smaller binary
strip = true # Strip symbolsMIT License - see LICENSE for details.
- Claude Code by Anthropic for the integration hooks
- instant-distance for HNSW implementation
- simsimd for SIMD-accelerated vector operations
- rusqlite for embedded SQLite
- Pearl's causal inference framework for reasoning foundations
Built with 🦀 Rust for maximum performance