Skip to content

Commit 86dcd5f

Browse files
committed
Add local personal memory
Signed-off-by: Alejandro Blanco-M <alecuba16@gmail.com>
1 parent 3ee05c1 commit 86dcd5f

15 files changed

Lines changed: 1081 additions & 27 deletions

File tree

Makefile.cbm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ CYPHER_SRCS = src/cypher/cypher.c
184184
# MCP server module (new)
185185
MCP_SRCS = src/mcp/mcp.c
186186

187+
MEMORY_SRCS = src/personal_memory/memory.c
188+
187189
# Discover module (new)
188190
DISCOVER_SRCS = \
189191
src/discover/language.c \
@@ -304,7 +306,7 @@ TRE_CFLAGS = -std=c11 -g -O1 -w -Ivendored/tre
304306
YYJSON_SRC = vendored/yyjson/yyjson.c
305307

306308
# All production sources
307-
PROD_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(CYPHER_SRCS) $(MCP_SRCS) $(DISCOVER_SRCS) $(GRAPH_BUFFER_SRCS) $(PIPELINE_SRCS) $(SIMHASH_SRCS) $(SEMANTIC_SRCS) $(TRACES_SRCS) $(WATCHER_SRCS) $(GIT_SRCS) $(CLI_SRCS) $(UI_SRCS) $(YYJSON_SRC)
309+
PROD_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(CYPHER_SRCS) $(MCP_SRCS) $(MEMORY_SRCS) $(DISCOVER_SRCS) $(GRAPH_BUFFER_SRCS) $(PIPELINE_SRCS) $(SIMHASH_SRCS) $(SEMANTIC_SRCS) $(TRACES_SRCS) $(WATCHER_SRCS) $(GIT_SRCS) $(CLI_SRCS) $(UI_SRCS) $(YYJSON_SRC)
308310
EXISTING_C_SRCS = $(EXTRACTION_SRCS) $(LSP_SRCS) $(TS_RUNTIME_SRC) \
309311
$(GRAMMAR_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC)
310312

@@ -692,7 +694,7 @@ SYSROOT = $(shell xcrun --show-sdk-path 2>/dev/null)
692694
SYSROOT_FLAG = $(if $(SYSROOT),-isysroot $(SYSROOT),)
693695

694696
# Our source files (excluding vendored, grammars, tree-sitter runtime)
695-
LINT_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(CYPHER_SRCS) $(MCP_SRCS) \
697+
LINT_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(CYPHER_SRCS) $(MCP_SRCS) $(MEMORY_SRCS) \
696698
$(DISCOVER_SRCS) $(GRAPH_BUFFER_SRCS) $(PIPELINE_SRCS) $(SIMHASH_SRCS) $(SEMANTIC_SRCS) \
697699
$(TRACES_SRCS) $(WATCHER_SRCS) $(CLI_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) \
698700
$(ZSTD_SRCS) $(SQLITE_WRITER_SRC) $(MAIN_SRC)

README.md

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
**The fastest and most efficient code intelligence engine for AI coding agents.** Full-indexes an average repository in milliseconds, the Linux kernel (28M LOC, 75K files) in 3 minutes. Answers structural queries in under 1ms. Ships as a single static binary for macOS, Linux, and Windows — download, run `install`, done.
1818

19-
High-quality parsing through [tree-sitter](https://tree-sitter.github.io/tree-sitter/) AST analysis across all 158 languages, enhanced with [**Hybrid LSP** semantic type resolution](#hybrid-lsp) for Python, TypeScript / JavaScript / JSX / TSX, PHP, C#, Go, C, C++, Java, Kotlin, and Rust — producing a persistent knowledge graph of functions, classes, call chains, HTTP routes, and cross-service links. 14 MCP tools. Zero dependencies. Plug and play across 11 coding agents.
19+
High-quality parsing through [tree-sitter](https://tree-sitter.github.io/tree-sitter/) AST analysis across all 158 languages, enhanced with [**Hybrid LSP** semantic type resolution](#hybrid-lsp) for Python, TypeScript / JavaScript / JSX / TSX, PHP, C#, Go, C, C++, Java, Kotlin, and Rust — producing a persistent knowledge graph of functions, classes, call chains, HTTP routes, and cross-service links. 15 MCP tools. Zero dependencies. Plug and play across 11 coding agents.
2020

2121
> **Research** — The design and benchmarks behind this project are described in the preprint [*Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP*](https://arxiv.org/abs/2603.27277) (arXiv:2603.27277). Evaluated across 31 real-world repositories: 83% answer quality, 10× fewer tokens, 2.1× fewer tool calls vs. file-by-file exploration.
2222
@@ -37,7 +37,7 @@ High-quality parsing through [tree-sitter](https://tree-sitter.github.io/tree-si
3737
- **11 agents, one command**`install` auto-detects Claude Code, Codex CLI, Gemini CLI, Zed, OpenCode, Antigravity, Aider, KiloCode, VS Code, OpenClaw, and Kiro — configures MCP entries, instruction files, and pre-tool hooks for each.
3838
- **Built-in graph visualization** — 3D interactive UI at `localhost:9749` (optional UI binary variant).
3939
- **Infrastructure-as-code indexing** — Dockerfiles, Kubernetes manifests, and Kustomize overlays indexed as graph nodes with cross-references. `Resource` nodes for K8s kinds, `Module` nodes for Kustomize overlays with `IMPORTS` edges to referenced resources.
40-
- **14 MCP tools** — search, trace, architecture, impact analysis, Cypher queries, dead code detection, cross-service HTTP linking, ADR management, and more.
40+
- **15 MCP tools** — search, trace, architecture, impact analysis, Cypher queries, dead code detection, cross-service HTTP linking, ADR and personal memory management, and more.
4141

4242
## Quick Start
4343

@@ -136,7 +136,7 @@ Removes all agent configs, skills, hooks, and instructions. Does not remove the
136136

137137
### Graph & analysis
138138
- **Architecture overview**: `get_architecture` returns languages, packages, entry points, routes, hotspots, boundaries, layers, and clusters in a single call
139-
- **Architecture Decision Records**: `manage_adr` persists architectural decisions across sessions
139+
- **Architecture Decision Records**: `manage_adr` persists project ADRs; `manage_memory` stores personal repo memory locally outside source repos
140140
- **Louvain community detection**: Discovers functional modules by clustering call edges
141141
- **Git diff impact mapping**: `detect_changes` maps uncommitted changes to affected symbols with risk classification
142142
- **Call graph**: Resolves function calls across files and packages (import-aware, type-inferred)
@@ -176,6 +176,7 @@ Removes all agent configs, skills, hooks, and instructions. Does not remove the
176176

177177
### Distribution & operation
178178
- **Single static binary, zero infrastructure**: SQLite-backed, persists to `~/.cache/codebase-memory-mcp/`
179+
- **Personal memory**: Local repo knowledge lives in `manage_memory` under the user data dir; it is never written to the repo unless you explicitly export artifacts
179180
- **Auto-sync**: Background watcher detects file changes and re-indexes automatically
180181
- **Route nodes**: REST endpoints are first-class graph entities
181182
- **CLI mode**: `codebase-memory-mcp cli search_graph '{"name_pattern": ".*Handler.*"}'`
@@ -197,6 +198,20 @@ Commit a single compressed file to your repo and your teammates skip the reindex
197198

198199
The result is similar in spirit to graphify's `graphify-out/` directory, but as a single compressed file with explicit two-tier export, integrity-checked import, and zero merge friction.
199200

201+
## Personal Repo Memory
202+
203+
Use `manage_memory` when you want ADR-style knowledge to stay local and private.
204+
205+
- **Storage**: local SQLite `memory.db` under the user data dir, separate from repo files
206+
- **Override**: set `CBM_MEMORY_DIR=/path/to/private/memory`
207+
- **No upload**: `manage_memory` never writes `.codebase-memory/` or changes tracked files
208+
- **Branch aware**: memory is keyed by repo identity, branch, and document type; feature branches can keep overlays while `main` keeps base memory
209+
- **LLM workflow**: call `manage_memory(mode="get")` at session start, investigate with graph tools if empty/stale, then update with `manage_memory(mode="update", content="...")`
210+
- **Branch promotion**: after branch work, copy branch memory into base with `manage_memory(mode="promote", branch="feature")`
211+
- **Maintenance**: list entries with `manage_memory(mode="list")`, remove one branch/doc with `manage_memory(mode="delete", branch="...")`, inspect paths with `manage_memory(mode="settings")`
212+
213+
`manage_adr(scope="personal", ...)` is also accepted as a compatibility path to the same personal store.
214+
200215
## How It Works
201216

202217
codebase-memory-mcp is a **structural analysis backend** — it builds and queries the knowledge graph. It does **not** include an LLM. Instead, it relies on your MCP client (Claude Code, or any MCP-compatible agent) to be the intelligence layer.
@@ -349,7 +364,7 @@ Add to `~/.claude/.mcp.json` (global) or project `.mcp.json`:
349364
}
350365
```
351366

352-
Restart your agent. Verify with `/mcp` — you should see `codebase-memory-mcp` with 14 tools.
367+
Restart your agent. Verify with `/mcp` — you should see `codebase-memory-mcp` with 15 tools.
353368

354369
</details>
355370

@@ -420,6 +435,7 @@ codebase-memory-mcp cli --raw search_graph '{"label": "Function"}' | jq '.result
420435
| `get_architecture` | Codebase overview: languages, packages, routes, hotspots, clusters, ADR. |
421436
| `search_code` | Grep-like text search within indexed project files. |
422437
| `manage_adr` | CRUD for Architecture Decision Records. |
438+
| `manage_memory` | Local personal repo memory outside source repos. |
423439
| `ingest_traces` | Ingest runtime traces to validate HTTP_CALLS edges. |
424440

425441
## Graph Data Model
@@ -458,14 +474,39 @@ Layered: hardcoded patterns (`.git`, `node_modules`, etc.) → `.gitignore` hier
458474
codebase-memory-mcp config list # show all settings
459475
codebase-memory-mcp config set auto_index true # auto-index on session start
460476
codebase-memory-mcp config set auto_index_limit 50000 # max files for auto-index
477+
codebase-memory-mcp config set auto_update false # disable startup update checks
478+
codebase-memory-mcp config get memory_dir # local personal memory directory
479+
codebase-memory-mcp config set memory_enabled true # opt in to local per-repo memory
480+
codebase-memory-mcp config set memory_dir ~/private/cbm # override personal memory dir
461481
codebase-memory-mcp config reset auto_index # reset to default
462482
```
463483

484+
Default memory config:
485+
- `memory_enabled=false`: `manage_memory` storage is opt-in. When not configured, existing project ADR/index behavior is unchanged.
486+
- `memory_default_scope=project`: LLM workflows keep project-scoped behavior unless local personal memory is explicitly enabled.
487+
- `memory_dir=<user data dir>`: global user-home memory DB location, override with config or `CBM_MEMORY_DIR`. The path must be absolute and outside the source repo.
488+
489+
### Personal memory privacy and storage boundaries
490+
491+
`manage_memory` is opt-in, local-only personal storage. It is intentionally separate from project indexes and source repos. Enable it with `codebase-memory-mcp config set memory_enabled true` or by passing an external config with `memory_enabled=true`:
492+
493+
- **Where data lives:** one SQLite DB named `memory.db` under `memory_dir`. Defaults are macOS `~/Library/Application Support/codebase-memory-mcp`, Linux `~/.local/share/codebase-memory-mcp`, Windows `%LOCALAPPDATA%/codebase-memory-mcp`. `CBM_MEMORY_DIR` or `config set memory_dir ...` can override this with an absolute path outside the repo.
494+
- **Repo boundary:** write/read/delete operations are rejected when `memory_dir` is relative or inside the current project root. The tool reports `storage_boundary_error` and does not create `memory.db`.
495+
- **No external transmission:** `manage_memory` does not upload memory, does not write to git, does not call network APIs, and does not sync to the repo. Responses redact repo identity and storage keys. Paths are redacted unless `reveal_paths=true` is passed to `mode="settings"`.
496+
- **No sensitive-data logging:** memory content, storage keys, repo IDs, and memory paths are not logged by the memory tool. Content is returned only to the caller for explicit `get`/`sections` requests.
497+
- **Delete semantics:** `mode="delete"` removes only the selected repo/branch/doc row from `memory.db`. It does not delete other branches, other repos, the DB file, SQLite free pages, filesystem backups, or user copies.
498+
- **Promote/sync semantics:** `mode="promote"` is a local-only copy from the current branch doc to the base branch doc in the same `memory.db`. `mode="sync"` is disabled and returns `sync_disabled`; there is no network sync feature.
499+
500+
Default update config:
501+
- `auto_update=true`: MCP startup checks GitHub for newer releases and shows a one-shot notice.
502+
- Set `auto_update=false` to disable network update checks. Manual `codebase-memory-mcp update` still works.
503+
464504
### Environment Variables
465505

466506
| Variable | Default | Description |
467507
|----------|---------|-------------|
468508
| `CBM_CACHE_DIR` | `~/.cache/codebase-memory-mcp` | Override the database storage directory. All project indexes and config are stored here. |
509+
| `CBM_MEMORY_DIR` | macOS: `~/Library/Application Support/codebase-memory-mcp`; Linux: `~/.local/share/codebase-memory-mcp`; Windows: `%LOCALAPPDATA%/codebase-memory-mcp` | Override local personal memory storage with an absolute path outside the repo. `manage_memory` writes `memory.db` here and does not touch the repo. |
469510
| `CBM_DIAGNOSTICS` | `false` | Set to `1` or `true` to enable periodic diagnostics output to `/tmp/cbm-diagnostics-<pid>.json`. |
470511
| `CBM_DOWNLOAD_URL` | *(GitHub releases)* | Override the download URL for updates. Used for testing or self-hosted deployments. |
471512
| `CBM_LOG_LEVEL` | `info` | Set the minimum log level. Accepted values (case-insensitive): `debug`, `info`, `warn`, `error`, `none` — or their numeric equivalents `0``4` matching the internal enum. Logs go to stderr; stdout is reserved for MCP JSON-RPC. |
@@ -475,6 +516,9 @@ codebase-memory-mcp config reset auto_index # reset to default
475516
```bash
476517
# Store indexes in a custom directory
477518
export CBM_CACHE_DIR=~/my-projects/cbm-data
519+
520+
# Store personal memory in a private directory
521+
export CBM_MEMORY_DIR=~/private/cbm-memory
478522
```
479523

480524
## Custom File Extensions
@@ -497,7 +541,7 @@ Project config overrides global for conflicting extensions. Unknown language val
497541

498542
## Persistence
499543

500-
SQLite databases stored at `~/.cache/codebase-memory-mcp/`. Persists across restarts (WAL mode, ACID-safe). To reset: `rm -rf ~/.cache/codebase-memory-mcp/`.
544+
Project index SQLite databases are stored at `~/.cache/codebase-memory-mcp/`. Personal memory is stored separately in the user data dir or an absolute, repo-external `CBM_MEMORY_DIR`. Both persist across restarts (WAL mode, ACID-safe). To reset indexes: `rm -rf ~/.cache/codebase-memory-mcp/`. To reset personal memory, remove `memory.db` from `manage_memory(mode="settings", reveal_paths=true)` output.
501545

502546
## Troubleshooting
503547

@@ -556,7 +600,7 @@ Also supported (not yet benchmarked): Ada, Agda, Apex, Assembly (NASM), Astro, A
556600
```
557601
src/
558602
main.c Entry point (MCP stdio server + CLI + install/update/config)
559-
mcp/ MCP server (14 tools, JSON-RPC 2.0, session detection, auto-index)
603+
mcp/ MCP server (15 tools, JSON-RPC 2.0, session detection, auto-index)
560604
cli/ Install/uninstall/update/config (10 agents, hooks, instructions)
561605
store/ SQLite graph storage (nodes, edges, traversal, search, Louvain)
562606
pipeline/ Multi-pass indexing (structure → definitions → calls → HTTP links → config → tests)

docs/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"featureList": [
5757
"Indexes 158 programming languages via vendored tree-sitter grammars",
5858
"Hybrid LSP semantic type resolution for Python, TypeScript/JavaScript, PHP, C#, Go, C/C++, Java, Kotlin, and Rust",
59-
"14 MCP tools for structural search, call-path tracing, and Cypher graph queries",
59+
"15 MCP tools for structural search, call-path tracing, and Cypher graph queries",
6060
"Semantic vector code search via bundled nomic-embed-code embeddings (no API key, fully local)",
6161
"Semantic graph edges (SEMANTICALLY_RELATED) and near-clone detection (SIMILAR_TO, MinHash + LSH)",
6262
"Cross-service linking for HTTP, gRPC, GraphQL, tRPC, and pub/sub channels with confidence scoring",
@@ -699,8 +699,8 @@ <h3>3D graph visualization</h3>
699699
<p>An optional UI binary serves an interactive 3D graph at <code>localhost:9749</code> to explore nodes, edges, and clusters visually.</p>
700700
</div>
701701
<div class="feature">
702-
<h3>14 MCP tools</h3>
703-
<p><code>search_graph</code>, <code>trace_path</code>, <code>detect_changes</code>, <code>query_graph</code> (Cypher), <code>get_architecture</code>, <code>get_code_snippet</code>, <code>manage_adr</code>, and 7 more.</p>
702+
<h3>15 MCP tools</h3>
703+
<p><code>search_graph</code>, <code>trace_path</code>, <code>detect_changes</code>, <code>query_graph</code> (Cypher), <code>get_architecture</code>, <code>get_code_snippet</code>, <code>manage_adr</code>, <code>manage_memory</code>, and 7 more.</p>
704704
</div>
705705
<div class="feature">
706706
<h3>Cypher graph queries</h3>
@@ -728,7 +728,7 @@ <h3>Change-impact analysis</h3>
728728
</div>
729729
<div class="feature">
730730
<h3>Architecture Decision Records</h3>
731-
<p><code>manage_adr</code> persists architectural decisions alongside the graph, so design rationale survives across sessions and teammates.</p>
731+
<p><code>manage_adr</code> persists project ADRs; <code>manage_memory</code> is opt-in and stores personal repo memory in a local <code>memory.db</code> under the user data directory or <code>CBM_MEMORY_DIR</code>. Personal memory paths must be absolute and outside the source repo; the tool does not upload, sync to the network, write to git, or log memory content.</p>
732732
</div>
733733
</div>
734734
</section>

docs/llms.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- License: MIT, open source.
88
- Languages: 158 (158 vendored tree-sitter grammars compiled into the binary).
99
- Hybrid LSP type resolution: 9 language families (Python, TypeScript/JavaScript/JSX/TSX, PHP, C#, Go, C/C++, Java, Kotlin, Rust) — a lightweight C implementation of language type-resolution algorithms, structurally inspired by and compatible with major language servers including tsserver, pyright, gopls, Roslyn, Eclipse JDT, and rust-analyzer.
10-
- MCP tools: 14 (search_graph incl. semantic_query vector search, trace_path (alias: trace_call_path), query_graph (Cypher), detect_changes, get_architecture, get_code_snippet, manage_adr, and more).
10+
- MCP tools: 15 (search_graph incl. semantic_query vector search, trace_path (alias: trace_call_path), query_graph (Cypher), detect_changes, get_architecture, get_code_snippet, manage_adr, manage_memory, and more).
1111
- Semantic search: natural-language code discovery via bundled nomic-embed-code embeddings (768-dim, compiled into the binary); 11-signal combined scoring; fully local, no API key.
1212
- Semantic & similarity edges: SEMANTICALLY_RELATED (vocabulary-mismatch matches) and SIMILAR_TO (MinHash + LSH near-clone / duplicate detection).
1313
- Cross-repo intelligence: CROSS_* edges link nodes across multiple repos indexed in one store; multi-galaxy 3D layout and cross-repo architecture summary.

scripts/smoke-invariants.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ inv_mcp_initialize() {
446446
}
447447

448448
# ── Invariant 4: tools/list returns all expected tools ─────────────────────
449-
# Cross-check against the canonical 14-tool list (TOOLS[] in src/mcp/mcp.c).
450-
EXPECTED_TOOLS="index_repository search_graph query_graph trace_path get_code_snippet get_graph_schema get_architecture search_code list_projects delete_project index_status detect_changes manage_adr ingest_traces"
451-
EXPECTED_TOOL_COUNT=14
449+
# Cross-check against the canonical 15-tool list (TOOLS[] in src/mcp/mcp.c).
450+
EXPECTED_TOOLS="index_repository search_graph query_graph trace_path get_code_snippet get_graph_schema get_architecture search_code list_projects delete_project index_status detect_changes manage_adr manage_memory ingest_traces"
451+
EXPECTED_TOOL_COUNT=15
452452
inv_tools_list() {
453453
if ! mcp_alive; then
454454
fail "tools-list" "server not alive"

0 commit comments

Comments
 (0)