# cli-memoria

> A shared memory for all my AI agents: ~300 Markdown notes in git, driven through a CLI with write rules enforced in code.

- Role: Solo project
- When: Oct 2026 – present
- Stack: TypeScript, Node.js, CLI, Git, SQLite FTS5, MCP, NixOS, Vitest
- Links: [Source on GitHub](https://github.com/PabloPC05/cli-memoria), [How it works inside](https://github.com/PabloPC05/cli-memoria/blob/main/docs/design.md)
- Image: [Diagram: Badulaque and the local shell use the memoria CLI (with an optional MCP server in the same repo); writes pass through code-enforced rules into Markdown notes in git, with a SQLite FTS5 index rebuilt from git](https://ppardocotos.com/_astro/cli-memoria.en.DyoyDRSF.svg)
- URL: https://ppardocotos.com/projects/cli-memoria

Every AI client keeps its own memory, and none knows what the others learned. **cli-memoria** centralises it on my own server: around **300 Markdown notes in git** that all my agents query and update through the **`memoria` CLI** (via [Badulaque](https://ppardocotos.com/projects/badulaque) or locally). Open source (Apache-2.0), powering my [self-hosted assistant](https://ppardocotos.com/projects/self-hosted-assistant).

## Three premises that shaped the architecture

<div class="decisiones una-col">
<div class="decision">
<div class="cab"><b>1. Keywords over embeddings</b><span class="tag ok">SQLite FTS5</span></div>
<span class="dato">Local embeddings fit easily (1.8 s / 0.2 ms) → dropped on evidence</span>
<p>When an agent actively searches, lexical retrieval beats vectors and hybrid fusion often hurts queries. The CLI tries exact phrases then keywords, returns summaries and change dates, and navigates long notes by section.</p>
</div>
<div class="decision">
<div class="cab"><b>2. Git underneath, hidden from agents</b><span class="tag ok">Auditable history</span></div>
<span class="dato">Overwriting erases the past · rewriting flattens temporal nuance</span>
<p>Agents never touch git, yet every write becomes a commit with author and reason, prevents concurrent overwrites and provides automatic modification dates.</p>
</div>
<div class="decision">
<div class="cab"><b>3. Rules in code, not in prompts</b><span class="tag ok">0 / 926 false blocks</span></div>
<span class="dato">389 real writes → 9 genuine pollution writes stopped · 142 tests</span>
<p>Rejects only <strong>newly introduced</strong> issues (invalid types, missing metadata, altering my verbatim quotes or undated present-tense mentions of retired tools) with a one-line fix hint.</p>
</div>
</div>

## How a write flows

<div class="flujo">
<div class="paso"><b>Agent (CLI)</b>Reads locally and sends writes without knowing git.</div>
<span class="flecha" aria-hidden="true">→</span>
<div class="paso caja"><b>Server + rules</b><ul><li>single writer queue</li><li>blocks new violations</li><li>protects verbatim quotes</li></ul></div>
<span class="flecha" aria-hidden="true">→</span>
<div class="paso"><b>Git + FTS5</b>Atomic commit and refreshed index.</div>
</div>

## Under the hood

- **Right-sized notes:** splitting overgrown notes (from up to 59,551 chars down below 11,000) lifted accuracy from **28/30 to 30/30** on real-data benchmarks.
- **Pure Markdown, no LFS or OCR:** binary documents live separately on the server and notes cite them by a stable ID that survives renames; when a scan needs reading, the agent inspects it on demand.
- **CLI first, optional MCP:** I use it day-to-day through the CLI (reading from a local checkout and routing writes directly to the server for concurrency and rules); the same repo also serves the stateless MCP endpoint (with per-agent static tokens) for clients without a shell.
- **Stack:** TypeScript on Node.js 24, built-in `node:sqlite` (FTS5), MCP SDK, NixOS module and unit, real-git, HTTP/MCP, end-to-end CLI and NixOS VM tests.

Full benchmarks — including discarded ideas like a tree index and local embeddings — plus supporting papers are in [this blog post](https://ppardocotos.com/blog/measuring-mcp-and-agent-memory).
