File size: 7,537 Bytes
c3a3710 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | # MnemoCore Integrations
Connect MnemoCore's persistent cognitive memory to your AI coding tools.
## Supported tools
| Tool | Method | Notes |
|------|--------|-------|
| **Claude Code** | MCP server + hooks + CLAUDE.md | Best integration β native tool access |
| **Gemini CLI** | GEMINI.md + wrapper script | Context injected at session start |
| **Aider** | Wrapper script (`--system-prompt`) | Context injected at session start |
| **Any CLI tool** | Universal shell scripts | Pipe context into any tool |
| **Open-source agents** | REST API (`mnemo_bridge.py`) | Minimal Python dependency |
---
## Quick setup
### Prerequisites
1. MnemoCore running: `uvicorn mnemocore.api.main:app --port 8100`
2. `HAIM_API_KEY` environment variable set
3. Python 3.10+ with `requests` (`pip install requests`)
### Linux / macOS
```bash
cd integrations/
bash setup.sh --all
```
### Windows (PowerShell)
```powershell
cd integrations\
.\setup.ps1 -All
```
### Manual: test the bridge first
```bash
export MNEMOCORE_URL=http://localhost:8100
export HAIM_API_KEY=your-key-here
python integrations/mnemo_bridge.py health
python integrations/mnemo_bridge.py context --top-k 5
python integrations/mnemo_bridge.py store "Fixed import error in engine.py" --tags "bugfix,python"
```
---
## Claude Code (recommended)
The setup script does three things:
### 1. MCP server β native tool access
Registers MnemoCore as an MCP server in `~/.claude/mcp.json`.
Claude Code gets four tools:
- `memory_query` β search memories
- `memory_store` β store a memory
- `memory_get` / `memory_delete` β manage individual memories
Claude will use these automatically when you instruct it to remember things,
or you can configure CLAUDE.md to trigger them on every session (see below).
**Verify:** Run `claude mcp list` β you should see `mnemocore` listed.
### 2. Hooks β automatic background storage
Two hooks are installed in `~/.claude/settings.json`:
- **PreToolUse** (`pre_session_inject.py`): On the first tool call of a session,
queries MnemoCore and injects recent context into Claude's awareness.
- **PostToolUse** (`post_tool_store.py`): After every `Edit`/`Write` call,
stores a lightweight memory entry in the background (non-blocking).
Hooks never block Claude Code β they degrade silently if MnemoCore is offline.
### 3. CLAUDE.md β behavioral instructions
The setup appends memory usage instructions to `CLAUDE.md`.
This tells Claude *when* to use memory tools proactively.
---
## Gemini CLI
```bash
# Option A: Use wrapper (injects context automatically)
alias gemini='bash integrations/gemini_cli/gemini_wrap.sh'
gemini "Fix the async bug in engine.py"
# Option B: Manual context injection
CONTEXT=$(integrations/universal/context_inject.sh)
gemini --system-prompt "$CONTEXT" "Fix the async bug in engine.py"
```
Also add instructions to your `GEMINI.md`:
```bash
cat integrations/gemini_cli/GEMINI_memory_snippet.md >> GEMINI.md
```
---
## Aider
```bash
# Option A: Use wrapper
alias aider='bash integrations/aider/aider_wrap.sh'
aider --model claude-3-5-sonnet-20241022 engine.py
# Option B: Manual
CONTEXT=$(integrations/universal/context_inject.sh "async engine")
aider --system-prompt "$CONTEXT" engine.py
```
---
## Universal / Open-source agents
Any tool that accepts a system prompt can use MnemoCore:
```bash
# Get context as markdown
integrations/universal/context_inject.sh "query text" 6
# Use in any command
MY_CONTEXT=$(integrations/universal/context_inject.sh)
some-ai-cli --system "$MY_CONTEXT" "do the task"
# Store a memory after a session
integrations/universal/store_session.sh \
"Discovered that warm tier mmap files grow unbounded without consolidation" \
"discovery,warm-tier,storage" \
"mnemocore-project"
```
### REST API (Python / any language)
```python
import os, requests
BASE = os.getenv("MNEMOCORE_URL", "http://localhost:8100")
KEY = os.getenv("HAIM_API_KEY", "")
HDR = {"X-API-Key": KEY}
# Query
r = requests.post(f"{BASE}/query", json={"query": "async bugs", "top_k": 5}, headers=HDR)
for m in r.json()["results"]:
print(m["score"], m["content"])
# Store
requests.post(f"{BASE}/store", json={
"content": "Found root cause of memory leak in consolidation worker",
"metadata": {"source": "my-agent", "tags": ["bugfix", "memory"]}
}, headers=HDR)
```
---
## Environment variables
| Variable | Default | Description |
|----------|---------|-------------|
| `MNEMOCORE_URL` | `http://localhost:8100` | MnemoCore API base URL |
| `HAIM_API_KEY` | β | API key (same as MnemoCore's `HAIM_API_KEY`) |
| `MNEMOCORE_TIMEOUT` | `5` | Request timeout in seconds |
| `MNEMOCORE_CONTEXT_DIR` | `~/.claude/mnemo_context` | Where hook writes context files |
---
## Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI Coding Tool β
β (Claude Code / Gemini CLI / Aider / Custom) β
ββββββββββββββββ¬βββββββββββββββββββββββ¬ββββββββββββββββ
β MCP tools β System prompt
β (Claude Code only) β (all tools)
βΌ βΌ
ββββββββββββββββββββββββ βββββββββββββββββββββββββββββ
β mnemocore MCP serverβ β mnemo_bridge.py CLI β
β (stdio transport) β β (lightweight wrapper) β
ββββββββββββ¬ββββββββββββ βββββββββββββββ¬ββββββββββββββ
β β
ββββββββββββββ¬ββββββββββββββββ
β HTTP REST
βΌ
ββββββββββββββββββββββββββ
β MnemoCore API β
β localhost:8100 β
β β
β ββββββββββββββββββββ β
β β HAIMEngine β β
β β HOT/WARM/COLD β β
β β HDV vectors β β
β ββββββββββββββββββββ β
ββββββββββββββββββββββββββ
```
---
## Troubleshooting
**MnemoCore offline:**
```bash
python integrations/mnemo_bridge.py health
# β MnemoCore is OFFLINE
# Start it: uvicorn mnemocore.api.main:app --port 8100
```
**API key error (401):**
```bash
export HAIM_API_KEY="your-key-from-.env"
python integrations/mnemo_bridge.py health
```
**Hook not triggering (Claude Code):**
```bash
# Check settings.json
cat ~/.claude/settings.json | python -m json.tool | grep -A5 hooks
```
**MCP server not found (Claude Code):**
```bash
# Verify mcp.json
cat ~/.claude/mcp.json
# Check PYTHONPATH includes src/
cd /path/to/mnemocore && python -m mnemocore.mcp.server --help
```
|