Skip to content

Commit 51f63b9

Browse files
committed
Add local personal memory
Signed-off-by: Alejandro Blanco-M <alecuba16@gmail.com>
1 parent affa223 commit 51f63b9

15 files changed

Lines changed: 1084 additions & 27 deletions

File tree

Makefile.cbm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ CYPHER_SRCS = src/cypher/cypher.c
173173
# MCP server module (new)
174174
MCP_SRCS = src/mcp/mcp.c src/mcp/index_supervisor.c
175175

176+
MEMORY_SRCS = src/personal_memory/memory.c
177+
176178
# Discover module (new)
177179
DISCOVER_SRCS = \
178180
src/discover/language.c \
@@ -293,7 +295,7 @@ TRE_CFLAGS = -std=c11 -g -O1 -w -Ivendored/tre
293295
YYJSON_SRC = vendored/yyjson/yyjson.c
294296

295297
# All production sources
296-
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)
298+
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)
297299
EXISTING_C_SRCS = $(EXTRACTION_SRCS) $(LSP_SRCS) $(TS_RUNTIME_SRC) \
298300
$(GRAMMAR_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) $(SQLITE_WRITER_SRC)
299301

@@ -688,7 +690,7 @@ SYSROOT = $(shell xcrun --show-sdk-path 2>/dev/null)
688690
SYSROOT_FLAG = $(if $(SYSROOT),-isysroot $(SYSROOT),)
689691

690692
# Our source files (excluding vendored, grammars, tree-sitter runtime)
691-
LINT_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(CYPHER_SRCS) $(MCP_SRCS) \
693+
LINT_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(CYPHER_SRCS) $(MCP_SRCS) $(MEMORY_SRCS) \
692694
$(DISCOVER_SRCS) $(GRAPH_BUFFER_SRCS) $(PIPELINE_SRCS) $(SIMHASH_SRCS) $(SEMANTIC_SRCS) \
693695
$(TRACES_SRCS) $(WATCHER_SRCS) $(CLI_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) \
694696
$(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

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

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

185185
### Distribution & operation
186186
- **Single static binary, zero infrastructure**: SQLite-backed, persists to `~/.cache/codebase-memory-mcp/`
187+
- **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
187188
- **Auto-sync**: Background watcher detects file changes and re-indexes automatically
188189
- **Route nodes**: REST endpoints are first-class graph entities
189190
- **CLI mode**: `codebase-memory-mcp cli search_graph '{"name_pattern": ".*Handler.*"}'`
@@ -205,6 +206,20 @@ Commit a single compressed file to your repo and your teammates skip the reindex
205206

206207
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.
207208

209+
## Personal Repo Memory
210+
211+
Use `manage_memory` when you want ADR-style knowledge to stay local and private.
212+
213+
- **Storage**: local SQLite `memory.db` under the user data dir, separate from repo files
214+
- **Override**: set `CBM_MEMORY_DIR=/path/to/private/memory`
215+
- **No upload**: `manage_memory` never writes `.codebase-memory/` or changes tracked files
216+
- **Branch aware**: memory is keyed by repo identity, branch, and document type; feature branches can keep overlays while `main` keeps base memory
217+
- **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="...")`
218+
- **Branch promotion**: after branch work, copy branch memory into base with `manage_memory(mode="promote", branch="feature")`
219+
- **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")`
220+
221+
`manage_adr(scope="personal", ...)` is also accepted as a compatibility path to the same personal store.
222+
208223
## How It Works
209224

210225
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.
@@ -357,7 +372,7 @@ Add to `~/.claude/.mcp.json` (global) or project `.mcp.json`:
357372
}
358373
```
359374

360-
Restart your agent. Verify with `/mcp` — you should see `codebase-memory-mcp` with 14 tools.
375+
Restart your agent. Verify with `/mcp` — you should see `codebase-memory-mcp` with 15 tools.
361376

362377
</details>
363378

@@ -428,6 +443,7 @@ codebase-memory-mcp cli --raw search_graph '{"label": "Function"}' | jq '.result
428443
| `get_architecture` | Codebase overview: languages, packages, routes, hotspots, clusters, ADR. |
429444
| `search_code` | Grep-like text search within indexed project files. |
430445
| `manage_adr` | CRUD for Architecture Decision Records. |
446+
| `manage_memory` | Local personal repo memory outside source repos. |
431447
| `ingest_traces` | Ingest runtime traces to validate HTTP_CALLS edges. |
432448

433449
## Graph Data Model
@@ -469,14 +485,39 @@ codebase-memory-mcp config list # show all settings
469485
codebase-memory-mcp config set auto_index true # auto-index on session start
470486
codebase-memory-mcp config set auto_index_limit 50000 # max files for auto-index
471487
codebase-memory-mcp config set auto_watch false # don't register background git watcher (default: true)
488+
codebase-memory-mcp config set auto_update false # disable startup update checks
489+
codebase-memory-mcp config get memory_dir # local personal memory directory
490+
codebase-memory-mcp config set memory_enabled true # opt in to local per-repo memory
491+
codebase-memory-mcp config set memory_dir ~/private/cbm # override personal memory dir
472492
codebase-memory-mcp config reset auto_index # reset to default
473493
```
474494

495+
Default memory config:
496+
- `memory_enabled=false`: `manage_memory` storage is opt-in. When not configured, existing project ADR/index behavior is unchanged.
497+
- `memory_default_scope=project`: LLM workflows keep project-scoped behavior unless local personal memory is explicitly enabled.
498+
- `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.
499+
500+
### Personal memory privacy and storage boundaries
501+
502+
`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`:
503+
504+
- **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.
505+
- **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`.
506+
- **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"`.
507+
- **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.
508+
- **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.
509+
- **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.
510+
511+
Default update config:
512+
- `auto_update=true`: MCP startup checks GitHub for newer releases and shows a one-shot notice.
513+
- Set `auto_update=false` to disable network update checks. Manual `codebase-memory-mcp update` still works.
514+
475515
### Environment Variables
476516

477517
| Variable | Default | Description |
478518
|----------|---------|-------------|
479519
| `CBM_CACHE_DIR` | `~/.cache/codebase-memory-mcp` | Override the database storage directory. All project indexes and config are stored here. |
520+
| `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. |
480521
| `CBM_DIAGNOSTICS` | `false` | Set to `1` or `true` to enable periodic diagnostics output to `/tmp/cbm-diagnostics-<pid>.json`. |
481522
| `CBM_DOWNLOAD_URL` | *(GitHub releases)* | Override the download URL for updates. Used for testing or self-hosted deployments. |
482523
| `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. |
@@ -486,6 +527,9 @@ codebase-memory-mcp config reset auto_index # reset to default
486527
```bash
487528
# Store indexes in a custom directory
488529
export CBM_CACHE_DIR=~/my-projects/cbm-data
530+
531+
# Store personal memory in a private directory
532+
export CBM_MEMORY_DIR=~/private/cbm-memory
489533
```
490534

491535
## Custom File Extensions
@@ -514,7 +558,7 @@ Project config overrides global for conflicting extensions. An entry whose langu
514558

515559
## Persistence
516560

517-
SQLite databases stored at `~/.cache/codebase-memory-mcp/`. Persists across restarts (WAL mode, ACID-safe). To reset: `rm -rf ~/.cache/codebase-memory-mcp/`.
561+
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.
518562

519563
## Troubleshooting
520564

@@ -573,7 +617,7 @@ Also supported (not yet benchmarked): Ada, Agda, Apex, Assembly (NASM), Astro, A
573617
```
574618
src/
575619
main.c Entry point (MCP stdio server + CLI + install/update/config)
576-
mcp/ MCP server (14 tools, JSON-RPC 2.0, session detection, auto-index)
620+
mcp/ MCP server (15 tools, JSON-RPC 2.0, session detection, auto-index)
577621
cli/ Install/uninstall/update/config (10 agents, hooks, instructions)
578622
store/ SQLite graph storage (nodes, edges, traversal, search, Louvain)
579623
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
@@ -458,9 +458,9 @@ inv_mcp_initialize() {
458458
}
459459

460460
# ── Invariant 4: tools/list returns all expected tools ─────────────────────
461-
# Cross-check against the canonical 14-tool list (TOOLS[] in src/mcp/mcp.c).
462-
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"
463-
EXPECTED_TOOL_COUNT=14
461+
# Cross-check against the canonical 15-tool list (TOOLS[] in src/mcp/mcp.c).
462+
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"
463+
EXPECTED_TOOL_COUNT=15
464464
inv_tools_list() {
465465
if ! mcp_alive; then
466466
fail "tools-list" "server not alive"

0 commit comments

Comments
 (0)