# OpenMemex — Design Document (protocol v0.2)

**Status:** FROZEN — protocol v0.2 (2026-09-26). Decisions D1–D90 are settled (log: [docs/design/decisions.md](design/decisions.md)); open questions are tracked at the end of this document.
**Author:** Stone, with 小沐
**Changelog vs v1:** incorporates round-3 review from Perplexity, Grok, Gemini, ChatGPT, DeepSeek.
Key changes: Design Principles section; `role` separated from `type`; two iron rules;
scope/visibility/provenance/confidence split; ISO 8601 times + `schema_version`;
bidirectional supersede chain; `importance` replaces numeric priority; explicit pull;
versioned-append sync (no silent LWW); embeddings as optional capability; v1→v2 migration;
Decisions log; Prior Art; solo-dev adoption path.

> Note: "protocol v0.2" versions the **protocol**, not the plugin. The protocol will outlive any
> single implementation.

---

## Design Principles

1. **Memory is data by default, never instructions by default.** A memory only becomes an instruction
   through an explicit, reviewable gate (§3.3).
2. **Local is always the source of personal truth.** The `personal` scope never syncs, never uploads.
3. **Markdown is the source of truth; every index is rebuildable.** Lose the DB, rebuild from files.
4. **Nothing leaves the machine without explicit user action.** Promotion and sync are always opt-in.
5. **Core must never silently resolve semantic memory conflicts.** Surface them; let humans decide.
6. **Adapters translate; they never implement memory logic.** All memory logic lives in Core.
7. **Memory is the entrance of knowledge, not its final form.** Terminal states are docs / ADRs /
   AGENTS.md instructions — memory is how knowledge gets captured and found.
8. **Distill conversations; do not archive them.** The default unit of memory is the useful
   conclusion from a conversation, not the full transcript: what was learned, how it was resolved,
   and where the authoritative source lives.
9. **Portable second brain, not a walled garden.** Long-form personal notes are valid memories when
   the user explicitly saves them; Markdown keeps them readable, exportable, and movable to other
   tools or machines.

---

## 1. Vision & Positioning

**OpenMemex is an open, local-first memory layer and interoperable protocol for AI coding agents.**

- **Tagline:** *"Capture knowledge once, make it available to every AI agent."*
- **Local-first, open source (Apache-2.0).** No cloud SaaS, no account, no mandatory network calls.
- **The pain it kills:** every developer's AI learns in isolation. Dev A spends three days debugging an
  environment quirk with AI help; dev B rediscovers it next week. Hard-won knowledge should flow
  **personal → team → organization** instead of evaporating with each session.
- **MCP is an interface, not the identity.** MCP / CLI / REST / SDK are access layers over the protocol,
  so the project is never locked to one transport or one agent tool (opencode, VS Code Copilot, Cursor,
  Claude Code, Windsurf, …).
- **Second-brain lens:** for individuals, OpenMemex can also be a local Markdown second brain for
  AI-assisted work — similar in spirit to users asking AI to save notes into Obsidian or Notion, but
  with agent recall, scopes, review, and redaction built in from the start.
- **Company lens:** at organizational scale the same pain is tribal knowledge — senior engineers'
  hard-won experience evaporates when they move on, and every incident gets re-debugged by someone
  new. The current phase therefore prioritizes *capture*: valuable knowledge must land in memory
  first, because team/org sharing, onboarding, and incident learning all build on that foundation.
  (No capture, nothing to inherit.)

### Non-goals

- Not a cloud SaaS. Not an account system.
- Not a replacement for documentation (§12).
- No automatic exfiltration (§4).

---

## 2. Architecture: Core / Interfaces / Providers

```
┌──────────────────────────────────────────────────────────┐
│                     MEMORY CORE (pure TS)                  │
│  store    markdown source of truth + rebuildable index   │
│  retrieve hybrid search · rerank · conflict resolution   │
│           injection policy                               │
│  capture  tools · keyword triggers · implicit (opt-in)   │
│  sync     git transport · merge · pull/push/status       │
│  trust    redaction · admission barrier · audit          │
└──────────────────────────────────────────────────────────┘
        │ Interfaces (thin adapters, no memory logic)
        ├─ MCP server ........... primary cross-tool interface
        ├─ opencode plugin ...... v1 plugin, thinned to an adapter
        ├─ CLI .................. management, sync, promotion, resolve
        └─ (future) REST / SDK
        │ Providers (storage backends, swappable)
        ├─ LocalProvider ........ default; SQLite + files on disk
        ├─ GitProvider .......... repo-synced shared scopes
        └─ RemoteProvider ....... HTTP; remote-server sample in examples/
```

**Provider capability model** — every provider declares what it can do:

```ts
interface MemoryProviderCapabilities {
  read: boolean; write: boolean; delete: boolean;
  history: boolean;               // version / audit trail
  sync: "none" | "pull" | "push" | "bidirectional";
}
```

Core never knows about AWS/GCP/any-cloud. A future cloud deployment is *a custom `RemoteProvider`*,
not a core change. The auth layer of `RemoteProvider` is pluggable (token for the sample;
OIDC/SAML for enterprise later) so the sync protocol never needs rework for enterprise auth.

---

## 3. Data Model

One memory = one file. `id` = filename = ULID. No other ID scheme.

```yaml
id: 01K6AB3XZQ7WVD9J1M2N4P5Q6R7
schema_version: 2
scope: project            # personal | project | org  (ownership: WHO owns it)
                          # team, public → schema enum REJECTS writes (reserved)
scope_key: project__my-repo__9f2c1a4b8e3d   # storage identity (repo-derived, or "personal")
visibility: internal      # private | internal | shared (read access: WHO may read)
project_name: my-repo
type: decision            # content kind: what the memory IS (§3.2)
role: knowledge           # knowledge | instruction — how it may be USED (§3.3)
importance: normal        # low | normal | high (ranking hint; replaces 1–10 priority)
status: active            # active | superseded | deprecated | retracted | archived
tags: [auth, oauth]
aliases: ["oauth login flow"]   # optional: capture-time phrasing variants (D61)
source: user              # provenance: user | tool | keyword | inference | import
created_at: "2026-09-26T12:00:00Z"   # RFC 3339, never bare epoch
updated_at: "2026-09-26T12:00:00Z"
supersedes: null          # on the NEW memory → points BACK to what it replaces
superseded_by: null       # on the OLD memory → points FORWARD to its replacement
review_state: approved    # draft | proposed | approved | rejected | published (promotion)
proposed_by: stoneskin
approved_by: stoneskin
derived_from: null        # for propose-copies: the personal memory this came from
review_note: null
review_history: []        # append-only [{at, by, from, to, note}] audit trail
```

Field set as implemented (`src/store/markdown.ts`). Earlier drafts of this
example listed aspirational fields (`revision`, `trust_level`, `confidence`,
`via`, `expires_at`, `paths`, `related`, `canonical_ref`) that never shipped;
they are not part of protocol v0.2.

### 3.1 Type taxonomy (content kind)

`fact` `preference` `decision` `constraint` `todo` `knowledge` `howto` `gotcha`
`lesson` `observation` `reference`

`type` describes **what the content is** — single-valued, and it drives behavior
(lifecycle, review, rendering, retrieval). `role` describes **how it may be used**.
A `decision` with `role: knowledge` is retrievable history. Only `role: instruction` may enter
instruction context. (Separation adopted from review: mixing usage semantics into `type` was a design smell.)

One-line definitions:

- `fact` — a verifiable atomic statement (timezone, version number, path, account).
- `preference` — user likes, dislikes, working style.
- `decision` — a choice made + why; participates in supersede chains.
- `constraint` — a hard rule that must not be violated (release process, permission boundaries).
- `todo` — an actionable item with completion state.
- `knowledge` — declarative knowledge (how a system works, concept explanations).
- `howto` — steps to accomplish X.
- `gotcha` — a pitfall: don't do X because Y.
- `lesson` — a takeaway from experience, including incident postmortems (the incident id goes in `tags`).
- `observation` — noticed but not yet distilled.
- `reference` — a pointer to the authoritative doc via `canonical_ref`; the memory holds the summary.

A type earns its place only if the system treats it differently. If two candidates
share lifecycle, retrieval, and rendering, the loser becomes a tag. (D41 merged
`warning`→`gotcha`, `workflow`→`howto`, `incident`→`lesson`, `architecture`→`knowledge`.)

`tags` are retrieval hints, not a second type system: `type` says what the memory is, while tags say
which topics, tools, subsystems, paths, or incidents it relates to. Write paths should preserve
human-provided tags and may suggest simple normalized tags (for example `vscode`, `mcp`, `windows`,
`auth`, `onboarding`) to improve search without changing memory semantics.

### 3.2 Iron rules

- **Iron rule 1 — the instruction gate:** only memories with `role: instruction`
  AND `instruction_state: approved` AND `trust_level: trusted|reviewed` may enter an agent's
  instruction context. `source: inference` memories can NEVER auto-enter — they require human review.
  Org-level instructions additionally require a trusted owner. No privilege escalation: a `personal`
  memory can never become an instruction for anyone but its owner.
- **Iron rule 2 — personal scope guard:** a `personal`-scope memory with `role: instruction` must be
  explicitly marked, and `open-memex distill` must NEVER recommend it for AGENTS.md. (Prevents
  "I hate ESLint in this project" from becoming team policy.)

### 3.3 Lifecycle

`active → superseded | deprecated | retracted | archived`

- `superseded`: replaced by a newer memory; bidirectional chain (`supersedes` / `superseded_by`).
  Retrieval returns only the newest of a chain.
- **Chain integrity:** Core validates that `supersedes`/`superseded_by` are pairwise consistent on every
  read. If one side is missing (e.g. hand-edited markdown), Core auto-completes it and logs a warning —
  a broken chain must never silently degrade retrieval.
- `deprecated`: known-invalid; kept as a warning ("don't do X anymore").
- `retracted`: withdrawn as wrong; excluded from retrieval, kept for audit.
- `archived`: out of scope; excluded from retrieval.
- `review_state` (promotion workflow) is orthogonal to `status` (freshness).

### 3.4 Dedup on write

Content hash + fuzzy match against existing memories. A superseding write does **not** overwrite:
the old memory becomes `status: superseded` with `superseded_by` pointing forward. History preserved;
queries rank `active` first.

### 3.5 Conversation distillation

OpenMemex does **not** store raw AI chat transcripts by default. A captured memory should usually be
a short, human-approved artifact distilled from the conversation: the final conclusion, important
facts, why the answer matters later, and how the issue was resolved. Good distilled memory candidates
answer some combination of:

- What did we learn or decide?
- What solved the problem, including key commands, files, links, or steps?
- What mistake or gotcha should the next developer avoid?
- Which scope owns it: `personal`, `project`, or future `org`?
- If the information already exists in project docs, where is the authoritative doc?

If stable knowledge already lives in a project document, prefer a `type: reference` memory with
`canonical_ref` pointing at that document over duplicating the full content. Memory should help the
agent find and apply authoritative docs, not become an outdated second copy of them.

Model-suggested captures use `source: inference` and should default to reviewable draft state. The
agent may propose 1-3 distilled memories at checkpoints or task end, but humans decide whether to
save them and which scope they belong to. The product goal is remembering the right conclusion at
the right scope, not remembering everything.

Long-form notes are still valid when the user explicitly asks to save a long note, write-up, meeting
summary, research log, or troubleshooting record. In that case OpenMemex behaves like a Markdown
second-brain target: store the note as user-authored content, preserve the body, tag it for retrieval,
and keep the same scope/privacy rules. The distinction is intent: implicit/model-suggested capture
distills; explicit "save this note" may preserve long-form text.

### 3.6 Session working state

open-memex stores durable knowledge, not the state of an interrupted task. A fresh session resuming mid-task currently re-derives "where the work stands" from the agent's own reading — the gap memryzed names as its third layer (per-repository session state). The working-state note closes it without turning scratch state into knowledge:

- **One ephemeral note per project.** A single Markdown file per project scope, at `working-state/<scope_key>.md` under the storage root — beside the store, never inside `memories/`, never committed to a repo. Frontmatter: `updated_at`, `ttl_days` (default 7, configurable). Body, short by design: task summary (one paragraph), open files (paths), last commands, where the work stands, next step. A scratch note, not a transcript.
- **Written at wrap-up, by the agent.** The agent writes or refreshes it when a session wraps up — via the host's Stop hook where one exists (opencode, Claude Code), otherwise on an explicit user command. The human can edit it directly; it is a plain file. *(D90 correction, 2026-11-03: the opencode plugin API has no Stop hook — implement opencode's write path as the "explicit user command" branch via instruction + tool (the surfaced block teaches the agent to refresh on the user's wrap-up signal); Claude Code's Stop hook arrives with the Phase 2C native plugin.)*
- **Surfaced at session start, outside the review ladder.** The note is shown alongside the §7 compact summary at session start. It is scratch state, not knowledge: it never enters the review ladder, never becomes a memory on its own, and the §7 Core disclaimer does not apply to it (it is the user's own recent work state, not retrieved historical knowledge). If something in it is worth keeping, the normal checkpoint-proposal flow (D61) proposes it as a distilled-memory candidate — that rule resolves the overlap with retrospective distillation: the note is the raw material, the ladder is the gate.
- **Expiry.** A note older than its TTL is ignored at session start. Expired notes are reported by `audit` (reports only, never auto-deletes — the D57 posture); the next wrap-up write overwrites.

---

## 4. Scopes, Visibility & Namespaces

**Scope = ownership** (who owns it). **Visibility = read access** (who may read it). Defined separately.

| Scope      | Owner | Lives where | Synced? |
|------------|-------|-------------|---------|
| `personal` | you | this machine only | **never** |
| `project`  | repo collaborators | `<repo>/.ai/open-memex/` | via git (opt-in per repo) |
| `org`      | org members | dedicated org memory repo | via git |

Legal combinations: `personal/*` (any visibility, stays local); `project/{internal,shared}`;
`org/{internal,shared}`. `visibility: private` inside a shared scope is a logical boundary
today, not a physical one: `export` excludes private memories by default (D40), and the
`personal` scope never leaves the machine — but a private file placed under
`<repo>/.ai/open-memex/` still travels with git, so review before you push. Physical
isolation of private memories into a local-only cache directory remains planned
(see docs/SCOPES.md); `.gitignore` and pre-commit scanning are defense in depth, not
the boundary.

**Namespace:** `repo_id` (`git-origin-sha256:…`, falling back to a normalized cwd hash) identifies
the same project across machines — carried over from v1's scope-key design.

`team` and `public` scopes are **reserved**: the schema enum rejects writes to them. Rationale for
keeping them reserved: `project` scope already expresses team sharing; a distinct `team` scope needs
a clear semantic difference (e.g. cross-repo team) before it earns existence.

---

## 5. Knowledge Promotion Flow

Explicit promotion only — never automatic sync.

```
personal observation
   │  memory propose <id> --to project
   ▼
proposed ──► reviewed ──► approved ──► published/shared
                │              │
             rejected      (PR review = the mechanism for project scope)
   │
   │  curator promotes upward later
   ▼
org repo (cross-project; curated)
```

**Operations-level contract:**
- `open-memex propose` stages the memory file(s) for review. Default: generates the file set and prints
  the `gh pr create` command for the human to run (no surprise branches). Solo/no-CI path:
  `open-memex propose --local-approve` (records `approved_by` = self, skips PR).
- Core is **not** bound to GitHub PRs — `review_state` transitions are provider-agnostic; GitHub PR
  is one review backend.
- The curator role is a documented convention, not a permission system (until Phase 5 signals).

**AGENTS.md distillation** (assisted, human-approved): `open-memex distill` proposes promoting stable,
high-confidence `role: instruction` memories into AGENTS.md. A human always approves. AGENTS.md is the
slow-changing distilled core; memory is the fast-changing long tail. (Per iron rule 2, personal-scope
instructions are never candidates.)

**Maturity narrative** (for README): Observation → Memory → Verified Memory → Shared Knowledge.

---

## 6. Repository Layout

```
<project-repo>/
├── .ai/open-memex/            # default (D23); configurable (alt: .ai/memory/)
│   ├── 01K6AB….md           # one memory = one file ("reduces unrelated merge conflicts…")
│   └── …
├── AGENTS.md                # constitution + ONE pointer line to the memory system
├── README.md                # human-facing; no memories
└── docs/                    # human-authored formal docs (ADRs, guides)
```

- The in-repo directory name is **configurable** (`memoryDir` in config): default
  `.ai/open-memex/` (D23 — `.ai/` namespace + brand clarity, no collisions),
  alternatives `.open-memex/` and `.ai/memory/`.
- `index.db` is **never committed** — rebuildable from markdown.
- Org repo layout (Phase 4): `company-memory/{engineering,architecture,decisions,lessons,policies}/…`
- AGENTS.md pointer: `> Project memory lives in .open-memex/ — query it with memory_search before answering.`

---

## 7. Retrieval

- **Baseline (v2.0): FTS5/BM25 + CJK lexical.** Default CJK handling: **bigram query segmentation +
  FTS5** — simplest fully-offline default, no new dependencies. The tokenizer is **configurable**
  (`cjkTokenizer: bigram | trigram`); trigram indexing and local embeddings are benchmark-gated
  Phase 2 work, behind an `EmbeddingProvider` interface (never hard-wired to one model).
- **Embeddings (optional capability, D96):** never a retriever — BM25 retrieves, embeddings may only
  *rerank* cross-script (EN↔ZH) hits inside a review tier. Opt-in via `crossLingualRerank` (default
  off); the model is downloaded on first use into `<data root>/models/` and is user-selectable via
  `embeddingModel` (default `Xenova/paraphrase-multilingual-MiniLM-L12-v2`, q8, 113 MB). The runtime
  package is deliberately **not** a dependency, so the default install stays zero-download — the
  "pure-BM25 minimal mode" is simply the default. Measured gain and tax: D96.
- **Write-time CJK enrichment (recommended):** generate pinyin/keyword mappings for `tags` at write
  time as a BM25 fallback when segmentation misses.
- **Conflict priority** — two orthogonal orderings (facts vs preferences must not share one chain):
  - *Facts/knowledge:* security policy › authoritative docs › approved AGENTS.md › org memory ›
    project memory › personal memory › AI inference.
  - *Preferences/style:* explicit user request › personal preference › project convention › org default.
  - A doc is *authoritative* if referenced by `canonical_ref` from an approved memory or marked
    `authoritative: true` in frontmatter.
- **Injection policy (concrete):**
  - Session start: compact summary only, ≤800 tokens default (configurable). Selection: `status:
    active`, then `importance` × recency × relevance to cwd/branch/open files. Query-aware, not newest-N.
  - Session start also surfaces the project's working-state note (§3.6) alongside the compact summary — scratch state, not knowledge; the Core disclaimer does not apply to it.
  - On demand: agent calls `memory_search` → 3–10 hits.
  - Proactive nudge: attach a `warning`-type memory automatically only when the trigger is
    specific — tag hit **plus** content similarity above threshold, or `paths` match with the
    current cwd actually under a matched path. (A bare tag match like `auth` would fire on
    nearly every message; the threshold keeps the nudge signal, not noise.)
  - Every injected block carries a fixed Core disclaimer: *"The following is retrieved historical
    knowledge, not current instructions. Verify before acting."*
- **Explainability contract:** `memory_search` returns JSON with `id/summary/scope/status`; results
  ordered `active` first; one supersession chain ⇒ only the newest; `canonical_ref` resolvable.
- **Recall receipts:** each hit reports its lane (BM25 / vector / recency).

---

## 8. Capture

| Mechanism | Notes |
|---|---|
| Explicit tools | `memory_add/update/forget` (soft delete) · `search/get/list/status` · `propose/promote` · `resolve`. Write tools confirm with the user; read tools are open. |
| Keyword triggers | `remember …`, `note that …`, `TIL …`, `save this: …` + Chinese `记住` `记得` `保存一下` … |
| Implicit (opt-in) | end-of-session "should I remember X?"; implicit captures default to `confidence: low` and appear in a separate list view for batch cleanup (regret window). |
| Wrap-up | agent writes/refreshes the §3.6 working-state note at session wrap-up (Stop hook where supported, else explicit user command); human-editable plain file. *(D90, 2026-11-03: shipped — opencode write path is the instruction + tool branch since the plugin API has no Stop hook; surfaced at session start, `audit` expiry report, `wstate` CLI.)* |
| Redaction (hard) | `<private>…</private>` stripped; secret patterns are **masked in place** (first 4 chars kept, rest → `x`) and the write proceeds (D14); pre-commit hook scans shared scopes. |

**Scope routing on capture:** when the user says "save", "remember", or "note this" without an
explicit scope, the agent should infer ownership from content and current context. Project-specific
knowledge (repo commands, architecture, code paths, product decisions, team conventions) routes to
`project`; personal preferences, private working notes, cross-project habits, or content unrelated to
the current repo routes to `personal`. Ambiguous captures should ask one short clarification instead
of guessing. `org` capture remains future/curated; a single user's chat never writes org memory
directly.

---

## 9. Sync

- **Git is a transport, not the product boundary; the local SQLite index is the query layer.**
  Retrieval never walks git. Git/GitHub is the default sharing provider because it gives teams branch,
  PR, review, and audit semantics they already trust, but Core must remain provider-agnostic.
- one-memory-one-file ⇒ concurrent edits almost never conflict.
- **Pull is explicit** (`open-memex pull`), never automatic on session start — no surprise context changes.
  `pull` = `fetch` + fast-forward only; never auto-commit/push (hard rule for enterprise environments).
- **Merge policy — three conflict classes:**
  - *file conflict* (same file, both sides edited): `open-memex resolve` assists YAML-frontmatter merges.
  - *semantic conflict* (two memories assert contradictory facts): **Core never silently resolves** —
    both stay `active`, flagged for human review.
  - *lifecycle conflict* (both sides supersede differently): surfaced, human decides the chain.
- **Offline-first:** every write lands locally first; sync is idempotent reconciliation, not a
  transactional push. Airplane-mode writes queue and reconcile on next `push`.
- **Repo identity across rename/fork/migration:** `repo_id` follows the git origin; on drift, the CLI
  offers `open-memex migrate` (explicit, never automatic — same rule as v1's scope-key migration).
- **Git unavailable:** projects without git (or with unreachable remotes) remain fully usable.
  `personal` scope works everywhere; `project` scope degrades to local-only and `open-memex status`
  annotates it as such. Sync commands fail with a clear message, never with a broken state.
- **Portability:** because Markdown is the source of truth, memories should be exportable without
  depending on git. A future `open-memex export` command can archive selected scopes/types/tags into a
  portable zip/tar bundle (markdown + manifest) for moving to another computer or importing into
  another application. Export excludes `visibility: private` memories by default; `--all` / `-a`
  includes everything, for a full personal migration to a new machine. API-backed exporters/providers (Notion, Obsidian-compatible vaults, internal
  knowledge systems, enterprise stores) are extension paths over the same memory files and admission
  rules, not separate products.

---

## 10. Remote Sample — explicitly non-production reference

`examples/remote-server/` — a **minimal, explicitly non-production** reference implementation proving the
`RemoteProvider` interface: Node + SQLite + HTTP, docker-compose, pluggable auth (token for the demo),
`search`/`get`/`pull`/`propose` endpoints — **`propose`, not unreviewed write** — plus an append-only
audit log. No fine-grained ACL, no HA, no backup, no encryption: LAN-only by design.

**Sync semantics:** versioned append + conflict detection; conflicts return `409 Conflict`.
Last-write-wins is **demo-only** and must not appear in any production provider.
Remote candidates are re-admitted through the local admission barrier before indexing.
Truth stays in local markdown; the remote is a sync relay.

---

## 11. Trust & Security

- **Admission barrier — trigger points (explicit):** (a) at write — tool / keyword / import;
  (b) before writing any externally-sourced content to local markdown storage (covers sync pull,
  remote candidates, and lazy indexing alike — the point is the *write to markdown*, not the
  indexing step). "Retrieved memories are never re-ingested" is enforced at
  these points, not as a slogan.
- **Security Principle #1:** memory is data by default, never instructions (§3.2 iron rules enforce it).
- **Prompt-injection screening on shared files is heuristic, not a security boundary.** The real
  boundary is the data/instruction separation (role gate), not detection.
- **Provenance on every memory:** `source` + `confidence` + `via` + namespaced author identity.
- **Audit log** for all shared-scope writes (who promoted what, when).
- Shared scopes get secret scanning in CI/pre-commit — memory files in a company repo are a new
  exfiltration surface; treat them like code.

---

## 12. Relationship to AGENTS.md / README / docs

| Artifact | Answers | Author | Churn |
|---|---|---|---|
| AGENTS.md | "How should AI work here?" — static instructions | human (curated) | low |
| README / docs / ADR | "What is this project?" — formal knowledge | human | low |
| **OpenMemex** | "What did we learn?" — decisions, lessons, preferences | AI-captured, human-reviewed | high |
| org memory | "What does the company know across projects?" | curated | medium |

**Routing rule:** *"Must every agent edit obey it?" → AGENTS.md. Formal long-lived knowledge → docs.
A decision/lesson/preference retrieved per task → memory. Holds across projects → org memory.*

Memory stores summaries and points at docs via `canonical_ref` — never copies them.

---

## 13. Protocol Compatibility & Versioning

- Frontmatter schema is versioned (`schema_version`); JSON Schema published per version.
- MCP tool schemas, CLI contract, and `MemoryProviderCapabilities` are part of the protocol.
- Backward-compat rule: vN readers must read vN-1 files; writers write current version; migrations are
  explicit CLI commands, never silent.

## 14. Failure Modes

- Unparseable YAML ⇒ file quarantined (logged, skipped), never crashes indexing.
- SQLite locked ⇒ reads serve stale index + warning; writes queue locally.
- Remote unavailable ⇒ local cache serves with a `freshness` indicator; sync retries explicitly.
- Schema mismatch ⇒ explicit `open-memex migrate`, never silent upgrade.

## 15. Privacy & Data Retention

- `memory_forget` hard-deletes locally; `expires_at` is garbage-collected.
- Session/retrieval/audit logs are retained on a short rotation; full prompts are never logged unless
  diagnostics mode is on.
- **Git-history warning:** deleting a file does not purge it from git history. Secrets committed to a
  shared memory repo require history rewriting — the pre-commit hook exists to prevent this, not fix it.

## 16. Comparison / Prior Art

| Project | Approach | OpenMemex differs by |
|---|---|---|
| squirrel-memory | `.memory.md` in own repo + MCP | protocol-first; type/role iron rule; promotion flow |
| @ixmachina/memory | private GitHub repo, Markdown+YAML (git = storage + transport) | markdown as source of truth; git is one transport among several; local SQLite is the query layer |
| mcp-memory | single-file Python MCP, ripgrep over git | full lifecycle + scopes + trust model |
| basic-memory | markdown-first, Obsidian-compatible | agent-instruction safety (role gate); org topology |

Differentiators: the instruction/data iron rule, the knowledge promotion flow, and local-first as a
principle rather than a deployment option.

## 17. Adoption Path (solo dev, 5 minutes)

```
npx open-memex init     # ~/.open-memex, default config, MCP snippet for your IDE
npx open-memex mcp      # start MCP server; prints config for opencode/Cursor/VS Code/Claude Code
```

Zero-config is survival for an open-source project. The opencode plugin remains one adapter among many.

---

## 18. Roadmap

- **Phase 0 — Design freeze + validation (now).** Freeze this doc (protocol v0.2). Verify: company
  VS Code MCP-server support; corporate Copilot local-tool support. **Hard gate before Phase 2.**
  *Status (2026-11-02): 部分实现 — design frozen; VS Code validation evidenced, corporate-Copilot validation has no recorded artifact.*
- **Phase 1 — Local hardening (1–2 wks).** CJK default (bigram+FTS5) · v1→v2 migration · dedup +
  lifecycle · redaction hardening · scope docs. No external dependencies.
  *Status (2026-11-02): 已实现 — all five items shipped (0.3.0–0.8.1).*
- **Phase 2A — MCP server (shipped 2026-09-27, D15).** Core/adapters split
  (`src/tools/ops.ts`) · MCP server (`src/mcp.ts`, stdio) exposing all twelve memory tools —
  read-only-first phasing dropped per D15 · query-aware injection stays host-side.
  Ships in **`0.3.0-alpha`** (with bin/npx user-friendliness polish per §17 adoption path).
  *Status (2026-11-02): 已实现 — shipped 2026-09-27 (0.3.0).*
- **Phase 2B — Team sync.** GitProvider · `propose/promote/resolve` · in-repo dir · 1–2 colleague pilot
  (pilot project selection is maintainer-private, not tracked in this doc).
  Ships in **`0.4.0`** (was labeled `0.3.0-beta` before 0.3.0 shipped as stable).
  Embeddings/rerank run as a **parallel benchmark-gated experiment**, not on the critical path.
  *Status (2026-11-02): 部分实现 — mechanisms shipped in 0.4.0; the 1–2 colleague pilot has no completion evidence (TEST-PLAN §G unchecked).*
- **Phase 2C — Native agent plugins (candidates, not committed).** Claude Code plugin and/or
  Codex plugin as hook-enhanced paths over the same MCP tool surface (`SessionStart` →
  context injection, `UserPromptSubmit` → keyword-triggered search, `Stop`/`PostToolUse` →
  capture); per D16, no host-specific extraction intelligence — opencode is likewise
  supported as a plain MCP consumer. Gated on real-world signal from 0.3.0-alpha MCP
  dogfooding.
  *Status (2026-11-02): 未实现 — candidate, not committed; Claude Code / Codex have only the MCP-consumer path.*

### Agent integration matrix

| Agent | Integration path | Native hooks? | Status |
|---|---|---|---|
| opencode | native plugin (`src/index.ts`) | ✅ keyword capture + first-turn injection | shipped (Phase 1) |
| VS Code Copilot | MCP server + `.github/copilot-instructions.md` | ❌ — VS Code extension API cannot intercept Copilot Chat (researched 2026-09-27); an extension would add no hook capability, so not worth building | shipped (0.3.0) |
| Cursor | MCP server + rules | ❌ no chat plugin API | shipped (0.3.0) |
| Claude Code | MCP server today; plugin + hooks candidate | ✅ `SessionStart` / `UserPromptSubmit` / `PostToolUse` | Phase 2C candidate |
| Codex (CLI/IDE) | MCP server (`[mcp_servers]` in config.toml / `codex mcp add`) today; plugin + hooks + marketplace candidate | ✅ hooks mirror Claude Code's | Phase 2C candidate |

### Competitive landscape (for future positioning)

Coding-agent memory is crowded; open-memex's wedge is **zero-cloud, zero-account,
zero-embedding-download**, with repo-native markdown as source of truth (maintainer
requirement: personal data never touches third-party services). Benchmarks to track:

*Note (2026-11-02): figures below are a Sep 2026 snapshot and already stale in places (e.g. Mem0 ~50k+★ then, ~68k★ by 2026-10-28) — re-verify before quoting publicly.*

| Product | Scale / backing (Sep 2026) | Shape | Gap vs open-memex |
|---|---|---|---|
| Mem0 | ~50k+★, $24M Series A (YC) | universal memory SDK/API, vector+graph, cloud-first | cloud dependency; not repo-native for coding agents |
| Letta (ex-MemGPT) | ~24k★, $10M seed | stateful agent platform, memory blocks | agent runtime, not a drop-in coding-agent memory |
| Zep / Graphiti | ~20–30k★, $12M seed | temporal knowledge graph, enterprise | heavy infra; overkill as a coding vault |
| Cognee | ~15–30k★, $7.5M seed | graph ECL pipelines | ingest-oriented, no coding-agent hooks |
| Supermemory | ~15k★, $2.6M seed | consumer second-brain + SaaS API | cloud SaaS |
| atlaso-labs/codex | Codex marketplace | long-term memory plugin for Codex (hooks + MCP + cloud-sync upsell) | **direct comparable** for a future Codex plugin; their cloud upsell vs our local-first |

(Star counts / funding as of Sep 2026 — re-verify before quoting publicly.)
- **Phase 3 — Org layer.** Org memory repo · `examples/remote-server/` ·
  curator convention ✅ `docs/CURATOR.md` (2026-09-29, pulled forward) ·
  distill-to-AGENTS.md assist ✅ `open-memex distill-agents` (2026-09-29, pulled forward) ·
  export/import archive command ✅ `open-memex export` / `import` (2026-09-29, pulled forward, D40).
- **0.5.0 (stable, 2026-09-29).** Init UX pass: `init --global` user-level editor
  wiring (D45) · bare-init auto-detect wires all installed editors (D46) · JSONC
  configs left untouched with a paste-ready snippet (D47) · `uninstall` reverses
  `init` without touching memory data (D48) · empty config files treated as
  blank, not corrupt (D49).
- **0.5.1 (stable).** `--help` accuracy: `mcp` help states the server exposes 11
  tools (a superset of the opencode plugin's five memory tools); install hints point
  at the stable line instead of `@alpha` (F27).
- **0.6.0 (in development).** Close the install→init gap (D50): postinstall
  prints the `open-memex init` pointer (never prompts — CI-safe); bare
  `open-memex` on a fresh machine offers to run init on a TTY. Close the
  init→first-use gap (D51): init ends with a one-line next-step hint
  (`open-memex add` + ask the agent to recall it). Agent-prompt clarity pass
  (D52): rewrite both agent-facing prompts (MCP handshake + init template) so
  agents execute them correctly. Push-not-poll outbox (D53): the checkpoint
  mechanism is retired — the server reports the outbox draft count at session
  start and appends it to mutating tool results when non-zero. Install→init
  reminder fix (F28): one-line stderr nudge on every CLI entry point until
  init runs (npm swallows postinstall stdout).
- **Phase 4 — Future, signal-gated.** Cloud `RemoteProvider` customization only on: multi-private-repo
  sharing needs, fine-grained ACL, audit/compliance mandates · optional API-backed exporters/providers
  for enterprise knowledge systems.
- **Near-term backlog — committed direction, not yet built (2026-10-07).** Stone's rule: anything said as "later" is written down here. D77-L2 ✅ built 2026-11-03 (0.9.0-alpha.2): per-memory `retrieved_count`/`useful_count` (`useful_self` vs `useful_team`) + `memory_useful` tool, counters in a `memory_usage` table beside the rebuildable index. D77-L3 ✅ built 2026-11-04 (0.9.0-alpha.3): `memory_status`/`sync-status` reuse report — per-scope rates, top reused, zero-reuse "zombies". D77: external bench — LongMemEval-S run 2026-10-07 (`scripts/bench-longmemeval.ts`, 470 questions, recall_any@k: R@5 97.0% / MRR 0.909 per-question, R@5 40.6% on a pooled 22k corpus; ahead of agentmemory’s BM25-only, level with their BM25+vector). MemoryAgentBench still open as a second external data point. D79 follow-up SUPERSEDED → built as **D80** (2026-10-07): index-time synonym/translation expansion shipped; 41-query fixture recall@5 0.854 → 0.976, MRR 0.791 → 0.859. Embedding-model configurability (Stone 2026-10-07): the multilingual model is his personal need (EN↔ZH), not everyone’s — the model must be user-configurable. Timing: (1) NOW in the bench only — a `--model` flag to measure the multilingual tax (multilingual vs English-only on English data), which decides the DEFAULT. (2) AT SHIP TIME — `embedding.model` in `MyOMemoryConfig` + `SETTABLE_KEYS`, model-agnostic storage from day one (dim + model id stored with vectors, cache dir), download UX and `doctor` checks. Not before the gate passes: building config UX for a layer we haven’t decided to ship is premature. If multilingual tax ≈ 0, default multilingual (covers everyone); else default English-only with a docs note.D78: curate+submit — pre-submit lint, then confidence-tier auto-curation (auto-apply / batch-confirm / explicit human). **First slice built 2026-11-13 (0.10.0-alpha.3, D93):** deterministic auto-apply (exact duplicates / empty bodies / title whitespace), report-only lint and near-duplicates, `--no-curate`, `curate undo`. **Second slice built 2026-11-20 (0.11.0-alpha.1, D95) — closed:** batch-confirm (one screen, accept-all/decline-all, nothing written before the decision), semantic merges (≥ 0.9, never auto) and splits (both halves kept), type/tag inference (high confidence + `source: keyword` auto, everything else batch), `curate undo --batch <id>`, `curate stats`; threshold learning from those counters is the remaining follow-up, not part of D78's surface. D79 follow-ups: feedback-weighted ranking ✅ first slice built 2026-11-11 (0.10.0-alpha.2, D92): opt-in `feedbackWeighting`, near-tied BM25 band reordered by `reuse_rate` only for `retrieved_count >= 3`, explain trace, fixture R@1 0.660 → 0.702 / MRR 0.804 → 0.825; embeddings gate decision against the published baseline; reranker evaluation. Cross-lingual embedding rerank (Stone 2026-10-16, from obsidian-mind comparison): ablation showed multilingual vectors beat BM25 by +12pp R@5 on the cross-lingual slice — the one gap lexical can't cover. Design as opt-in rerank for EN↔ZH queries only, not a default path; local stays BM25-first per the retrieval split above. TDQS nit (separate PR): tighten search/list `type` to `z.enum`. Retrieval eval: grow the fixture (project-scope tier cases) as retrieval logic evolves. Retrieval split — local vs share server (Stone 2026-10-07): the two environments emphasize different mechanisms. Local (personal machine): BM25 + curated index-time expansion as the primary — deterministic, zero model download (D7), fast on CPU, index bloat bounded by the small corpus; embeddings opt-in only. Share server (team/org, enterprise): embeddings + ANN + reranker as the primary — server-grade compute with models resident, corpus too large and multi-author for any curated map; the curated map stays as a precision layer plus org glossary. The server additionally aggregates D77 useful_count across users into feedback-weighted ranking (already in D79 follow-ups) — a signal a single machine can never have. Bottom-up loop: curated pairs that many users converge on locally become org-glossary candidates. Economics flip: N users each downloading a model vs one model amortized on the server. OptMem lessons (Stone 2026-10-16, from kafkaup's OptMem post): three friction-reduction ideas worth stealing from the minimalist end of the spectrum. (1) **Token cost as spec** — measure and publish open-memex's prompt/token overhead in the README, the way OptMem advertises its "426-token prompt"; acquisition copy, not just engineering. (2) **`wake` convention** — document a session-start ritual (one `memory_recall` call at the beginning of every session), mirroring OptMem's `memo wake`; the MCP tools exist but the habit isn't specified. (3) **Capture length nudge** — a soft length cap or conciseness hint at capture time, inspired by OptMem's 280-byte hard cap; forces conciseness at write time, cheap to implement, aligned with the distill-to-AGENTS.md direction (D40). Three-tier memory zones (Stone 2026-10-18, from Westenberg "I Deleted My Second Brain" + his own reflection): the second brain should have zones like cache vs database, not "keep everything" vs "delete everything". **Hot** (active zone, cache-like: small, curated, always in context — D81 aliases, WHAT-level) · **Warm** (compost/incubation: not active but not cold; periodic review, rotted items deleted — this is "forget on purpose" as engineering) · **Cold** (full archive, searchable, not resident). The hard part is the **promotion/demotion policy** — what moves between zones, when, by what rule (the cache-replacement problem for knowledge; "useful" ≠ "recently used"). Capture restraint is a separate gate: not everything deserves to enter even cold storage. Spec the policy before building the zones. Auto-capture design brief (Stone 2026-10-19, from ai-memory comparison): open-memex wants auto-capture but under the restraint philosophy (not ai-memory's capture-everything). Five design questions: (1) **End-session trigger** — what hooks does opencode actually expose? (check before designing; ai-memory built finalize-session fallback for harnesses without SessionEnd); candidates: native hook / idle timeout / explicit command / context-near-full. (2) **Distillation** — rules first (what happened: git diff, tool calls, decision sentences; zero LLM), interpretation layer (what it means) left to human/LLM. (3) **Save-value triage** — three tiers: clearly valuable → save; clearly noise → drop; ambiguous → ask human. Boundary principle: **rather over-ask than over-save** (polluted retrieval costs more than a missed memory). (4) **Routing** — four exits: project memory / personal memory / AGENTS.md proposal (distill-agents exists) / discard; keep v1 routing rules simple. (5) **Human interaction** — one batch confirmation at session end ("save these 3? [y/n/edit]"), never per-item popups. Relations: D73 keyword capture is turn-level (no conflict); `wake` convention is session-start (this is session-end — the other bookend); three-tier zones govern where auto-captured items land. Cross-agent study (Stone 2026-10-19): open-memex has cross-agent on the roadmap — study how ai-memory does it (handoff claim-once semantics, lifecycle hooks per harness, VSCode support via MCP-only) before designing ours; borrow the semantics, not the push-injection behavior (discoverability > injection). Injection cost discipline (Stone 2026-10-19, from Harness² paper arXiv:2610.14224): "ALWAYS-ON PROSE IS THE EXPENSIVE OPTION" — every always-on word competes with the agent's output budget. Current session-start injection (8 project + 5 personal) is the expensive path; direction: move "important but not needed every turn" memories to on-demand (tool/skill-triggered loading), keep only truly every-turn items resident. Tolerable now, better not to tolerate. Component cost ladder for reference: SKILL (default, zero-cost until invoked) > SCRIPT > SUBAGENT > PLUGIN ("prose can be skipped, a hook cannot") > ALWAYS-ON TEXT (last resort). Read-less compression (Stone 2026-10-19, from caveman https://github.com/JuliusBrussee/caveman): the execution layer of injection cost discipline — compress what the agent READS before it reaches context, not just what we inject. Caveman's measured numbers: 33.2% fewer input tokens per session (CSV 98.9%, logs 98.5%, YAML 99.1%, JSON 98.5% per-file; HTML has no compressor yet). Direction for open-memex: a pre-retrieval compression pass on tool outputs and retrieved passages (structured data → compact form), originals stay on disk and pullable on demand. Two design principles borrowed: (1) never compress the user's own prompt/input (Adobe CAVEWOMAN finding: cavemanning user prompts makes answers worse); (2) leave code/tool calls/payloads verbatim — compress the wrapper, not the payload. Caveats: caveman's own rules cost ~1,160 input tokens fixed; per-request billing (Copilot-style) nullifies the saving — compression pays off on per-token billing only. Knowledge upkeep as a first-class direction (Stone 2026-10-23; external validation: Hedy Zhang's FDE field retrospective on enterprise AI knowledge bases, X article 2026-10-22 — enterprise knowledge bases die on unowned upkeep, not on retrieval: stale answers served silently, conflicts with no owner, updates nobody owns after delivery). The mechanisms already exist (supersede chains, lifecycle states, `audit` health check, curator convention); the direction is driving the human cost of upkeep toward zero: (1) staleness signals — age, contradiction with newer captures, D77 zero-reuse counters — feeding a standing review queue instead of waiting for someone to remember to run `audit`; (2) a conflict inbox — semantic conflicts and broken chains as a persistent todo; (3) the endgame is D78 confidence-tier auto-curation (auto-apply the safe tier, batch-confirm the rest). Success metric: the base stays trustworthy on minutes-per-week of human attention, not a curator shift. README pitches the shipped half of this as core concept 4 (Knowledge stays current) plus a "When facts change" comparison row. Session working state note (D89, 2026-11-02) → BUILT, shipped 2026-11-03 as D90: 12th tool `memory_workingstate` on both hosts, session-start surfacing, `audit` expiry report, `wstate` CLI; opencode write path is instruction + tool (plugin API has no Stop hook).

- **Build order after D77-L3 (2026-11-04, Stone approved; (1) shipped 2026-11-06).** Once PR #74 (D77-L3 reuse report) merges, the queue is: (1) §20 / D88 deterministic half — **shipped 0.9.0-alpha.6 (D91)**: `graph build` (structural edges only), compiled outline injected at session start, `graph neighbours` / `graph path` / `graph outline` / `graph lint` CLI (orphans / dangling / stale; missing-page alerts are part of the LLM half, still open); no LLM, no ranking change. Remaining under §20: **the LLM half** — semantic insights, missing-page alerts that propose new memories (through the D61 propose-first flow), compiled wiki pages — D78's pre-submit integration of the lint report shipped in D93 (0.10.0-alpha.3). **Spec drafted 2026-11-26 — see `docs/design/llm-half.md` (draft PR; reviewed by thinktank standard tier 2026-11-26, judge picked grok-4.7, verdict REVISE; revised same day per Stone + thinktank; v1 = semantic edges + missing-page proposals, wiki pages deferred to v1.1).** Admissibility check + verdict ingress built 2026-11-26 (0.12.0-alpha.1, D97): `graph verdict` stages a verdict only after the deterministic check (endpoints active, spans verbatim, one-sentence relation quoting both spans, contradicts resolution), `graph verdicts` lists the review queue, and `memory_add` / `memory_propose` refuse structured verdicts; candidate generation and review-accept still open. (2) D79 feedback-weighted ranking — **first slice shipped 0.10.0-alpha.2 (D92)**: fixture + baseline landed first, then an opt-in reuse-signal band reorder (`retrieved_count >= 3`, `reuse_rate`, 0.75 near-tie band); no embedding/cross-lingual rerank yet. (3) D78 curate+submit — **first slice shipped 0.10.0-alpha.3 (D93)**: pre-submit lint + deterministic auto-apply (exact duplicate / empty body / title) + `curate undo`, fixture 9→6 lint findings. **Second slice shipped 0.11.0-alpha.1 (D95): 已实现** — one batch-confirm screen (semantic merges ≥ 0.9, splits that keep both halves, uncertain type/tag inferences; no flag = stop before writing, `--accept-batch` / `--decline-batch`), high-confidence type/tag inference auto-applied only on `source: keyword`, `curate undo --batch <id>`, `curate stats` feedback counters (data only - thresholds still fixed), fixture now pins the accepted and declined batches plus the whole-batch undo. (4) Embeddings gate decision (bench `--model` measures the multilingual tax) + opt-in cross-lingual rerank for EN↔ZH queries only; local stays BM25-first. — **已实现 0.11.0-alpha.2 (D96)**: gate re-measured on the fixture (BM25 R@1 0.660 / R@5 0.979 / MRR 0.804 → cross-lingual slice R@1 0% / MRR 0.431 → 33.3% / 0.597, same-language slice untouched; pooled ceiling unchanged), verdict **opt-in only**, `crossLingualRerank` default false + `embeddingModel`, q8 model 112.8 MB / 0.76 s / 497 MB RSS / 3.1 ms per query published in D96; RRF/general fusion explicitly still open (needs its own gate). (5) OptMem small items — **shipped 0.10.0-alpha.4 (D94)**: token cost measured (`scripts/token-cost.ts`, chars/4 estimate) and published in the READMEs; `wake` ritual documented (README en+zh, Agent Skill, MCP handshake - docs only, no new surface); capture length nudge at 500 chars (hint appended to the save result, never a refusal; keyword 2000-char hard cap unchanged, over-cap drops now surface in the D73 hand-off note). (6) Three-tier memory zones policy spec (Hot/Warm/Cold promotion/demotion rules) before building; §20's compiled outline already covers part of Hot. **Spec drafted 2026-11-26 — see `docs/design/three-tier-zones.md` (draft PR; reviewed by thinktank standard tier 2026-11-26, judge picked grok; revised 4× same day per Stone + thinktank).** (7) Auto-capture design — answer the five open questions first (notably which session-end trigger opencode exposes). **Spec drafted 2026-11-26 — see `docs/design/auto-capture.md` (draft PR; reviewed by thinktank standard tier 2026-11-26, judge picked minimax-m3, verdict REVISE; revised same day per Stone + thinktank).** Then measurement/candidates: MemoryAgentBench second external data point; Phase 2C native plugins (candidate, not committed); D9 LAN reference server likely dropped; D2/D11 iron-rule gate is a known safety gap awaiting a build/drop decision. Non-code track: Phase 2B 1–2 colleague pilot (needs people, not code). Dependency chain: §20 lint → D78; D77-L2 counters → D79; gate decision → rerank. Tension to respect: §20's resident outline must stay compact per the injection-cost discipline (2026-10-19) — "important but not every turn" stays on-demand.

- **Phase 5 — Candidates recorded 2026-10-04 (not committed).** From the competitor scan (D75): an offline FTS5 retrieval eval with a published recall number (gates any semantic-layer decision) [promoted to next build, D77] · per-client trust levels on the review ladder · cold-start Markdown import into outbox drafts · `doctor` check that each editor's MCP registration points at the intended data root (mis-rooted servers are a real failure mode elsewhere). Sequencing and scope TBD per candidate.
- **Phase 5 — Candidates recorded 2026-10-11 (not committed).** From the XERJ review (xerj-org/xerj, Apache-2.0; founder Ivan N requested open-memex D81 for the XERJ Corpus Hub — agreed 2026-10-11, attribution + repo link): schema-first querying (`xerj_map` — agent fetches the field map before writing query DSL; candidate: a schema/describe helper ahead of `memory_search` to cut dead queries) · token-budgeted MCP results (their `token_budget.rs` — truncate to a token budget, not a fixed row limit) · hybrid retrieval as the scale answer (BM25 + vector kNN with fused ranking, e.g. RRF — the reference pattern for the eventual embedding layer; our lexical ceiling is already measured at R@5 40.6% pooled) · NL-to-validated-query planning (`xerj_plan` — natural language in, validated query out; candidate: a query lint/validate step before search executes) · evidence-carrying memory links (typed links with evidence + confidence, soft-retire never hard-delete — same spirit as our review-state ladder; prior art for a future memory-graph direction) · honest isolation docs (state what a namespace guarantees and does NOT — query-level vs trust boundary; same spirit as our Limitations section) · cost-accounted evals (report tokens + dollars per approach, as in their case studies — the format for proving "memory makes agents cheaper"). Sequencing and scope TBD per candidate.
- **Phase 5 — Candidates recorded 2026-10-12 (not committed).** From the mattpocock/skills review (writing-for-agents: context pointers, two loads, information hierarchy, completion criteria): a "writing-for-memory" authoring checklist (`docs/writing-for-memory.md`) — trigger branches per entry, tldr+body layered storage, capture criteria (self-contained, dated, D2 role discipline), curation bar (real-session + D77 reuse counters), glossary as first-class memory. Sequencing and scope TBD; implement after the China trip.
- **Phase 5 — Candidates recorded 2026-10-24 (not committed).** From the RAW-RAG paper (arXiv:2610.30755, 22 Oct 2026; code: Litmeb/RAW-RAG): naive dense retrieval + cross-encoder reranking over raw history beats 12 agentic memory systems on 6 of 7 benchmark–model settings across LoCoMo / LongMemEval / MEME / MemoryAgentBench; ablations make reranking the hardest single lever (removing it −3.92, CI excludes zero) and show added complexity (atomic facts, summaries, graph expansion) hurting on MemoryAgentBench. Assessment: baseline claim strong, "structure is useless" claim medium, generalization to interactive agents weak (paper's own scope limit). (1) **Naive-RAG baseline in the retrieval gate** — every retrieval change must beat a well-specified RAW-RAG baseline on the same fixture before its complexity ships (measurement before mechanism, applied to baselines); MemoryAgentBench is the open second external data point from D77 — reuse its 14 sources / 2,071 questions as the second bench. (2) **Reranker gate, not default** — run BM25 + local small cross-encoder rerank on the D77 fixture and let the gate decide; local CPU + configurable model are preconditions (D7 zero-model-download for local). (3) **Raw-evidence anchors for distilled memories** — recall returns conclusion + source excerpt via canonical_ref (§3.5), so the reader can expand to original text on demand; no change to the no-raw-transcript default. (4) **Retrieve wide, then narrow** — widen the recall pool (e.g. top-50) and let lane fusion + rerank narrow to the injected 3–10, targeting the pooled-corpus gap (D77: per-question R@5 97.0% vs pooled 40.6%). (5) **Path-carrying recall for supersede chains** — when a hit is superseded, return the new conclusion plus the one-hop change reason, not the conclusion alone. Explicitly NOT adopted: storing full raw conversation history (conflicts with §3.5 no-transcript default and capture restraint); LLM-driven extraction / knowledge graphs as default write paths (require a design-doc update first, per AGENTS.md); generalizing benchmark claims to interactive agents. Sequencing and scope TBD per candidate.
- **Phase 5 — Candidates recorded 2026-10-25 (not committed).** From Tantivy (quickwit-oss/tantivy, Rust Lucene-style full-text library; via @realchendahuang post 2026-10-24; research pass over README, ARCHITECTURE.md, docs.rs): the comparison is Tantivy vs the current SQLite FTS5 + D80 index-time expansion + bigram cjk column, not Tantivy vs hand-rolled BM25. (1) **Chinese search-mode segmentation experiment** — index compound words plus their components (jieba cut_for_search style) against the current unigram + overlapping-bigram cjk column; bigrams are over-splitting (high recall, low precision, bloated column), word + components move toward precision while keeping partial-query recall; gate on the retrieval-eval fixture (R@5/MRR) before any default change; constraint check first: a jieba-style dependency breaks the deliberate zero-native-tokenizer design (cjk.ts runs on both sqlite runtimes). (2) **Field norms as a first-class diagnostic** — the D83 expansions-column length-norm dilution is a field-norm problem, not a weighting problem; Tantivy's per-field 1-byte log-scale fieldnorm confirms the diagnosis; no encoding change (FTS5 already normalizes per column). (3) **Columnar aggregation for the reuse report** — D77-L3 counts by scope/status/age bucket should come from a column scan, not a re-search (Tantivy's fast-field pattern). (4) **Tombstone + background reclaim as confirmed discipline** — Tantivy never mutates published segments (tombstone bitset now, merge reclaims later, manifest swap for visibility); this validates the existing soft-delete + supersede chain, and explains the wipe-path FTS5 'delete' corruption workaround as the cost of in-place mutation — no change, discipline confirmed. (5) **Fuzzy (Levenshtein 1) typo tolerance, low priority** — prefix match + synonym expansion already cover most morphological variation; agent queries rarely need typo tolerance. Already covered, not counted as borrowings: separate stores (inverted match / column filter / fetch content only for displayed hits), per-column snippet + matchedVia attribution (D83), immutable + soft-delete lifecycle. Explicitly NOT adopted: migrating to Tantivy itself (stack + dependency cost, no fixture win shown). Unverified in this pass: which modes tantivy-jieba exposes and jieba-rs dictionary size (algorithm verified from sibling jieba implementations only); Tantivy's BM25 k1/b constants (only "same as Lucene" confirmed). Sequencing and scope TBD per candidate.
- **Phase 5 — Candidates recorded 2026-11-29 (not committed).** From meow's long-term memory subsystem design post (@meow2149, shared 2026-11-29, https://x.com/meow2149/status/2126748351265968611 — read via the TwStalker mirror; x.com blocks the cloud browser): a nine-part harness memory design — (1) admission, (2) hierarchical memory (L0 core + navigation index, L1 structured facts, L2 raw records), (3) dual-path writing, (4) active retrieval, (5) background consolidation ("Dreaming"), (6) temporal memory & forgetting, (7) scoping & governance, (8) procedural memory (Skills), (9) a local-first SQLite storage architecture. It overlaps open-memex's own architecture closely (local-first, SQLite as the single source of truth, Markdown as a rebuildable view, FTS5 BM25, vectors as an opt-in layer) — the borrowings below map onto open items, not a new direction. (1) **Hierarchical memory + progressive disclosure + a fixed token budget for L0** — the shape the three-tier zones policy needs; check against the drafted `docs/design/three-tier-zones.md` (2026-11-26) before writing anything new. (2) **Promotion by evidence + reuse demand, not recall count alone** — the criterion to check the zones spec's promotion/demotion rules (§5) against; demotion never deletes. (3) **Admission: stated vs observed vs inferred** — unverified inferences stay candidates, never confirmed facts; retention authorization and cross-session use authorization managed separately — input to the auto-capture spec's triage (`docs/design/auto-capture.md` §5 Q3), which already has three classes. (4) **session_search (retrieve historical sessions + raw evidence)** — the missing design justification for a `memory_recall`-style tool (13-tool line; still a candidate, needs its own design call). (5) **RRF as the default fusion** — D96 already measured naive RRF better than BM25 on the fixture (MRR 0.864 vs 0.804) and deliberately left it unshipped; this post is one more argument for running the RRF gate, not for shipping fusion without one. (6) **Permissions constrain the candidate range before Top-K recall**, not as a post-filter — the review-tier direction, stated as a principle. (7) **Bitemporal facts (valid time + transaction time) + tombstone-first deletion** — open-memex's supersede chain is single-dimensional and `forget` has no mark-first-then-reclaim semantics; a real gap, sequencing TBD. (8) **Recall Feedback Loop guard** — re-extracted / re-consolidated memories must not count as new independent evidence; D77/D79's explicit-signals-only guardrail already defends this — outside confirmation of it, not a new requirement. (9) **Persistent memory poisoning as a threat model** — prompt injection reaching memory through extraction / consolidation / recall is not in open-memex's threat model; derived memories inheriting source category + permission constraints is the matching control. Explicitly NOT adopted: procedural memory (Skill distillation) — that is the skill system's job, not the memory system's; migrating to sqlite-vec (vectors already live in `embedding_vectors` BLOBs per D96, no change); storing full raw conversation history (conflicts with §3.5 no-transcript default and capture restraint). Design post, not a measured system — every borrowing above goes through a gate / fixture before it ships (measurement before mechanism). Sequencing and scope TBD per candidate.
- **Phase 5 — Candidates recorded 2026-11-29 (not committed).** From Google's Self-Improvement Memory paper (arXiv:2611.18856, submitted 2026-11-13; Xin Yu et al., Google Cloud AI / DeepMind / Penn State; read from the arXiv HTML 2026-11-29; Chinese video explainer https://youtu.be/xr27lNV-sKM): CRSI — Continual Recursive Self-Improvement: harness optimization continues after a benchmark or policy-model change while preserving a compatible executable interface, with the policy model's weights frozen; only the harness (prompts, tools, context rules, execution control) evolves. SIM is a structured record for the harness optimizer (the proposer and selector that propose and choose harness edits), NOT for the task-solving policy and NOT user memory: entries are grouped by recurring harness problem (a root-cause hypothesis); each attempt stores the modification and its rationale, predicted AND observed outcomes, and provenance (domain, benchmark, policy, round); predictions are recorded before evaluation and checked afterward; only the chosen candidate is recorded, including edits that regress or fail to fix the predicted tasks; entries with identical root-cause text merge without dropping their histories; proposer and selector read the complete SIM each round, with no retrieval or truncation. Measured, not a design post: coding, ten paired continuations, mean +2.36 points over harness-only continuation (95% CI [1.05, 3.68], p=0.003, 9 of 10 pairs); best in all six cross-dataset settings; cross-model Opus-to-Gemini +3.60–11.33 points; Problem-Only Memory (root causes only) loses to Full SIM in all four domains. Generation chain: CRSI beats fresh RSI on Gemini 3.5 Flash (+3.5) and 3.8 Flash (+1.6) but finishes 0.8 points lower on Gemini 4 Argon. Limitations (paper's own): independent repetitions focus on coding only, other domains one run per condition; compatible harness interfaces required; optimizer planning and search procedures fixed. (1) **curation_feedback learning pass** — D78's `curation_feedback` table is observational only, no learning pass yet; SIM's schema (rationale + predicted vs observed outcome + provenance, grouped by recurring problem, append-only) is the shape for that pass: record why each merge/split was accepted or rejected and what happened, so the next curate round reuses it. (2) **Verdict records** — D97's `graph_verdict_queue`: attach rationale + predicted/observed outcome to each verdict; merge repeated verdicts about the same edge/problem without dropping history; adopt the predict-before-evaluate discipline as a calibration check on verdicts. (3) **Counters alone are not enough** — the Problem-Only ablation is measured evidence that rationale + outcome records beat root-cause-only, supporting D79's explicit-signals-only guardrail and the meow point (promotion by evidence + reuse demand, not recall count alone). (4) **Provenance per record + the Argon warning** — SIM keeps domain/benchmark/policy/round per attempt; verdicts should keep which model recorded them; the Argon inversion (−0.8) warns that memory recorded under one model generation can become friction under the next — do not reuse verdicts across model changes blindly. (5) **Unified synthesis for multi-model serving** — one harness built from feedback of all three models (Grok 4.20, Claude Opus 5.5, Gemini 3.8) matched separately evolved per-model harnesses on held-out text classification (75.24 vs 75.20); a candidate pattern if open-memex ever serves multiple models from one store. Explicitly NOT adopted: SIM as a memory architecture for open-memex itself (different object — harness-optimizer memory vs user/project memory); whole-SIM-in-prompt with no retrieval (does not scale to open-memex volumes; BM25 + opt-in rerank stays); the video's "never forget again" framing and its permissions/versioning claims (not in the paper). Single-paper evidence, coding-heavy repetitions, no code release linked — every borrowing above goes through a gate / fixture before it ships (measurement before mechanism). Sequencing and scope TBD per candidate.

## 19. Migration v1 → v2

- Scope rename: v1 `user` → v2 `personal` (automatic mapping; `project` unchanged).
- Times: epoch ms → RFC 3339. `priority: N` → `importance: low|normal|high` (1–3 low, 4–7 normal, 8–10 high).
- `type: instruction` (if any v1 memory used it) → `type: <content-kind>` + `role: instruction`.
- Index is discarded and rebuilt from markdown files. `open-memex migrate --dry-run` previews everything.
- Legacy paths: v1 `.my-o-memory/` repo dirs and `~/.my-o-memory/` config are moved to the
  v2 locations (in-repo `.ai/open-memex/`; data root per §4/paths — `OPEN_MEMEX_HOME`, else
  `%APPDATA%\open-memex` or `$XDG_DATA_HOME/open-memex`) by `open-memex migrate --to-v2`,
  with the pre-migration tree kept as a dated backup.

---

## 20. Knowledge Graph & Compiled Wiki (v0.3 candidate)

> v0.3 candidate (D88). Does not change the frozen v0.2 protocol; the graph/wiki is a derived layer. Full text: [docs/design/knowledge-graph.md](design/knowledge-graph.md).

*Status (2026-11-06): 部分实现 — the deterministic half shipped in 0.9.0-alpha.6 (D91): structural edges (supersedes / derived-from / body-mention / shared-tag with EXTRACTED/INFERRED provenance), `graph build|neighbours|path|lint`, auto-refresh on write, and the compiled outline injected at session start. Project scope only; CLI only (MCP stays at 13 tools). Still unbuilt: the LLM half (semantic insights, missing-page proposals, compiled wiki pages). See [docs/design/knowledge-graph.md](design/knowledge-graph.md) §20 status.*

---

## Decisions (append-only)

The decision log lives in [docs/design/decisions.md](design/decisions.md). Append-only — new decisions append there with the next D-number; never rewrite history, never renumber.


## Open Questions

_Pruned 2026-10-04 (D75): entries decided in D56/D57/D61/D68 and the shipped layers of the retrieval-robustness question were removed — the decisions are the record. What remains below is genuinely open._

- **Non-programmer users: PMs, BAs, and entry points (open, 2026-10-03):** the current experience assumes a programmer's toolchain — terminal, npm install, editor plugin, git branches, PR review. Project managers and BAs have none of that, and their most likely entry points are not the VS Code chat window: at most an agentic CLI (opencode, Claude Code), more probably Teams chat, MS Copilot, or another chat surface calling the same MCP server. The mechanics must hide behind two confirmations ("remember this?" / "share with the team?") — scope/promote/supersede/outbox vocabulary is a programmer dialect they should never have to learn. Three roles to design for, in increasing order of build cost: (1) **sources** — their meetings and decisions are the highest-value project memory, captured by someone else's agent with attribution in `source`; needs nothing new. (2) **curators** — "is this true? is it safe to share?" is business-truth review, which BAs are often better placed to do than programmers; GitHub's web PR review is the only existing no-CLI door, and CURATOR.md would need a plain-language path for reviewers who have never touched git. (3) **direct users** — capture sources shift from chat commands to meeting transcripts, email, and tickets; and without git there is no courier: a shared-folder transport is mechanically easy (memories are Markdown files) but has no PR-equivalent review step, so a substitute review flow has to be designed. Also weigh: stakeholder/customer facts carry PII and retention weight that code conventions never do, so "is it safe to share" becomes a compliance question, not a hygiene one. If a company ever gives every employee one unified agent entry point (a work buddy / AI team mate), most of this audience split dissolves — the question is what open-memex should assume until then: heterogeneous entry points, one memory service behind them.
  *Status (2026-11-02): 未实现 — only the sources role needs nothing new; curators and direct users unbuilt, no Teams/M365 entry.*

- **Retrospective distillation: mining host transcripts after the fact (open, 2026-10-03):** open-memex captures only in-session (keyword triggers, explicit `memory_add`) and keeps **no transcript** — so anything not captured during the conversation is gone once it ends. Hosts with durable memory (e.g. Muse) avoid this loss with two layers open-memex skipped: full transcript retention plus background distillation. The gap is architectural, not a timing detail: the raw material for a second chance does not exist on our side. But the hosts themselves already retain it — opencode persists sessions and messages in its local store; Claude Code keeps JSONL transcripts under `~/.claude/projects/`; VS Code Copilot's chat state is locked in workspace storage (readable, fragile, not a first target). Candidate direction: a "replay distillation" flow that exports a past session's transcript and has an agent mine it in a dedicated review session, with every extracted candidate landing as an **outbox draft** for human review — never a direct save. Boundaries that keep this inside the existing design: open-memex builds no transcript store of its own (borrow the host's), mining judgment is the agent's LLM work (we provide the export and the queue, not an extractor), fully local, mined drafts carry their provenance (`source` marks them as distilled, from which session). Open sub-questions: host adapters per tool (opencode store format, Claude Code JSONL), how the user picks sessions to mine (by date? by project? "everything since last sync"?), and whether the proactive-capture criteria (open question above) should be the mining rubric verbatim — likely yes.
  *Status (2026-11-02): 未实现 — no transcript replay/mining flow; open-memex keeps no transcript by design.*

- **Novice experience: the 60-second magic moment and the plain-language layer (open, 2026-10-03; trimmed 2026-10-04):** the privacy model is now stated in plain words at init (D56). Still open: init offering to save one sample memory and immediately having the user's agent answer a question with it — the user *sees* recall work before being asked to trust it — and a plain-language layer over the review ladder ("saved on this computer" / "shared with the team") with outbox/submit/promote vocabulary becoming the advanced view. This is the same vocabulary wall the PM/BA question above hits from the other side.
  *Status (2026-11-02): 部分实现 — init privacy statement (D56) and one-line hint (D51) shipped; the 60-second magic moment and plain-language review ladder unbuilt.*

- **Retrieval evaluation: measure recall before choosing a semantic layer (open, 2026-10-04):** the retrieval-robustness question closed with all three cheap layers shipped (D56 query construction; D61 agent-side expansion + capture-time aliases), and embeddings stayed deferred *by judgment, without numbers*. A comparable project (agent-memory) publishes an offline recall@5 of 0.98 and wears it as a badge. open-memex should build the same kind of small, fixed eval — a query set over a seeded store, recall@k / MRR for the current FTS5 pipeline — and publish the number. The semantic-layer decision then gets a gate: if FTS5 + aliases is good enough, embeddings stay deferred; if a query class measurably fails, that class defines what an optional local-embedding layer must beat. Eval first, architecture second. **Update (2026-10-07):** the eval shipped (D77, `scripts/retrieval-eval.ts`, baseline recall@1 0.81 / recall@5 0.95 / MRR 0.87); query-time synonym expansion landed as retrieval layer 4 (D79) — embeddings stay deferred, now with numbers behind the judgment.
  *Update (2026-11-02): fixture numbers have since moved to R@1 0.750 / R@5 0.977 / MRR 0.857 (D80/D81/D83); the conclusion (eval shipped, embeddings deferred on numbers) still holds.*
  *Status (2026-11-02): 部分实现 — eval harness shipped (D77 layer 1) and embeddings deferred on numbers; MemoryAgentBench second data point still open.*

- **Per-client trust levels (open, 2026-10-04):** the review ladder is currently global: every host's writes face the same gates. A comparable tool (auxly) sets a trust level per agent — one agent's writes land immediately, another's queue for approval, a third is read-only. That maps naturally onto open-memex, since the ladder already exists; the open questions are the config surface (per host? per MCP client name? how does the server learn the client's identity reliably?), the default for unknown clients, and whether trust should also gate *reads* of the personal scope. Signal to watch: one user running several agents with different autonomy expectations.
  *Status (2026-11-02): 未实现 — no per-client trust config; the review ladder is global.*

- **Cold-start import: index what the user already has (open, 2026-10-04):** adoption today starts from an empty store. Comparable tools index the user's existing notes (memtomem) or import other memory systems' exports (remnic: mem0 / ChatGPT / Claude). Candidate first steps, cheapest first: (1) import a folder of plain Markdown notes as personal-scope outbox drafts — never direct saves, the review gate stays the front door; (2) named-export importers once (1) proves the pipeline. Open sub-questions: chunking policy for long notes (one file ≠ one memory), dedup against existing memories, and provenance marking (`source: import`).
  *Status (2026-11-02): 部分实现 — bundle import/export shipped (0.4.0); importing a folder of plain Markdown notes as outbox drafts unbuilt.*

- **The three Copilots: three integration surfaces (open, 2026-10-05):** "Copilot" is three different products with three different extension models, and open-memex's posture differs per surface. (Stone's machines: home has all three; the work machine has no Microsoft Copilot app.)
  - **GitHub Copilot (editor, developer) — decided / shipped:** `open-memex init --client vscode|cursor|…` writes the MCP server entry; all 11 tools via MCP; the Agent Skill + instruction files drive proactive capture. This is the production path today.
  - **Microsoft Copilot (Windows consumer app; formerly "Windows Copilot") — open, unverified:** the app itself claims MCP registration via `%LocalAppData%\Microsoft\Copilot\mcp\mcp.json` (a `servers` array with `id` / `type: "stdio"` / `command` / `args` / `cwd`), but no public documentation exists for this path, and it is not the same thing as the OS-level On-Device Agent Registry (ODR, `odr.exe` + MSIX manifest) — the documented mechanism, still in public preview. Two verified technical constraints for any implementation: (1) on Windows the npm global bin is `open-memex.cmd`, which cannot be spawned without a shell — the entry must be `cmd /c open-memex mcp` (or `node` pointed at `dist/mcp.js`); (2) the MCP server resolves project scope from the process cwd, so a global assistant config needs a deliberate "home base" `cwd`, not a source checkout. No Skills/instructions layer loads here (Copilot Studio Skills packages are M365-only), so proactive capture degrades to "save when asked". Deferred until verified on a real machine (write file → restart app → tools appear in the tool list); if verified, implement as a new `init --client windows-copilot` target.
  - **Microsoft 365 Copilot (enterprise) — open, reframed 2026-10-05:** extension runs through Copilot Studio (agents, Skills packages, declarative agents, Graph connectors) — tenant-cloud surfaces, not local stdio — and this is where the non-programmer audience actually lives (the "MS Copilot" named in the non-programmer question above meant the consumer app; in practice, company non-programmers are on M365 Copilot, so this surface is not optional if we want that audience). The question is no longer *whether* but *how*: personal memory stays local-first and never touches the tenant; team/project memory — shared by design — is served by a company-hosted team-tier endpoint that Copilot Studio agents call as a remote MCP server (Copilot Studio supports MCP over URL). Pointing tenant agents at individual laptops is a non-starter (laptops aren't servers) and an IP mess under Roper-style assignment terms — work memory belongs on the company side, personal memory never leaves the machine, and that split is the clean story. Until the team tier exists, the no-new-infrastructure path is asymmetric participation: non-programmers contribute as attributed sources (captured by others' agents) and review as curators on GitHub web, reading via inventory reports.
  *Status (2026-11-02): 部分实现 — GitHub Copilot shipped; Microsoft Copilot unverified, M365 team-tier endpoint does not exist.*

- **Enterprise / pro edition: team server + remote MCP (open, 2026-10-05):** the M365 question above reframes the enterprise surface as a *team-tier* endpoint: personal memory stays local-first, team/project memory is served company-hosted and called by Copilot Studio agents as a remote MCP server. The packaging question is whether that team tier ships as an open-memex "enterprise/pro" edition (hosted service or deployable server + remote MCP) or stays a documented deployment pattern companies run themselves. Adoption insight from large-company anecdotes: internally-built programmer tools get pulled in by BAs/QAs/POs on their own — the wedge is developers, and the non-programmer entry point may not need to be built up front; it arrives via the team surface (M365/Teams) once the team server exists. Open: packaging and monetization model (Stone's current goal for open-memex is personal influence, not user count or revenue — an enterprise edition is a support burden, so timing and shape need a deliberate decision); hosting and auth model for the team server; how the personal/team split is enforced at the protocol level.
  - *Refinement (2026-10-05): the entry point is not built, it is placed.* Employees already live in team chat — asking questions, getting work done. A team-chat AI agent (e.g. a Copilot Studio agent in Teams backed by the team memory server) becomes the entry point by standing where the questions already get asked. Adoption is pull, not push: the agent answers and does work in the chat, and usage follows. This dissolves the "non-programmer entry point" problem rather than solving it — there is no separate door to build.
  - *Interface constraint (2026-10-16, from tool/skill/MCP boundary audit):* design the MCP interface for dual use from the start — internal agents and external agents (Copilot Studio, team chat) consume the same tools. Reserve org scope alongside project/personal; the review ladder's single-reviewer assumption will need multi-reviewer semantics. No code changes now; the constraint is recorded so the team tier doesn't require an interface rework later.
  *Status (2026-11-02): 未实现 — no team server; packaging, hosting/auth, and protocol split all undecided.*

---

*End of draft v2.*
