Skip to content

Commit 4aa854f

Browse files
Grivnclaude
andcommitted
Add store isolation design section to DESIGN docs
Document data directory layout, store resolution priority chain, isolation boundary (DB isolated, prompts shared), automatic migration strategy, and the lightweight design principle. EN/ZH synced. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 80294c1 commit 4aa854f

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

docs/DESIGN.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This document describes Mnemon's design philosophy, core concepts, system archit
1616
- [2. Design Philosophy](#2-design-philosophy)
1717
- [3. Core Concepts](#3-core-concepts)
1818
- [4. System Architecture](#4-system-architecture)
19+
- [4.1 Data Directory Layout](#41-data-directory-layout)
20+
- [4.2 Store Isolation](#42-store-isolation)
1921
- [5. MAGMA Four-Graph Model](#5-magma-four-graph-model)
2022
- [6. Write Pipeline: Remember](#6-write-pipeline-remember)
2123
- [7. Read Pipeline: Smart Recall](#7-read-pipeline-smart-recall)
@@ -307,6 +309,52 @@ mnemon/
307309
└── Makefile # Build, install, test
308310
```
309311

312+
### 4.1 Data Directory Layout
313+
314+
```
315+
~/.mnemon/
316+
├── active # Current default store name (plain text)
317+
├── prompt/ # Shared across all stores
318+
│ ├── guide.md # Behavioral guide (recall/remember rules)
319+
│ └── skill.md # Skill definition (command reference)
320+
└── data/ # Each store has its own isolated directory
321+
├── default/
322+
│ └── mnemon.db # SQLite database (WAL mode)
323+
├── work/
324+
│ └── mnemon.db
325+
└── <name>/
326+
└── mnemon.db
327+
```
328+
329+
**Isolation boundary**: Each store contains an independent `mnemon.db` — insights, edges, and oplog are fully isolated. Prompt files (`guide.md`, `skill.md`) are shared — behavioral rules are universal, memory data is private.
330+
331+
### 4.2 Store Isolation
332+
333+
Mnemon supports named stores for lightweight data isolation between different agents, projects, or scenarios.
334+
335+
**Why named stores instead of just `--data-dir`?**
336+
337+
`--data-dir` overrides the entire base directory — a blunt instrument that requires the caller to manage full paths. Named stores provide semantic clarity (`MNEMON_STORE=work` vs `--data-dir ~/.mnemon-work`) and work naturally with environment variables, which are the standard isolation mechanism for concurrent processes.
338+
339+
**Resolution priority** (highest to lowest):
340+
341+
```
342+
--store flag > MNEMON_STORE env > ~/.mnemon/active file > "default"
343+
```
344+
345+
This layered design serves different scenarios:
346+
347+
| Mechanism | Scenario |
348+
|-----------|----------|
349+
| `--store` flag | One-off CLI override, scripting |
350+
| `MNEMON_STORE` env | Per-process isolation — different agents use different stores |
351+
| `active` file | Persistent user preference — `mnemon store set work` |
352+
| `"default"` | Zero-config — works out of the box |
353+
354+
**Automatic migration**: When the new `data/` directory doesn't exist but a legacy `~/.mnemon/mnemon.db` does, mnemon automatically moves it to `data/default/mnemon.db`. Users upgrading from older versions experience a seamless transition.
355+
356+
**Design principle — lightweight and bounded**: Store isolation addresses a necessary data separation concern without growing into a multi-tenant system. There are no access controls, no cross-store queries, no store metadata beyond the name. This keeps the feature bounded — Mnemon is a memory daemon, not a knowledge base platform.
357+
310358
---
311359

312360
## 5. MAGMA Four-Graph Model

docs/zh/DESIGN.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Mnemon 是一个为 LLM 智能体设计的持久化记忆系统。它基于 [MAG
1616
- [2. 设计哲学](#2-设计哲学)
1717
- [3. 核心概念](#3-核心概念)
1818
- [4. 系统架构](#4-系统架构)
19+
- [4.1 数据目录布局](#41-数据目录布局)
20+
- [4.2 记忆体隔离](#42-记忆体隔离)
1921
- [5. MAGMA 四图模型](#5-magma-四图模型)
2022
- [6. 写入管线:Remember](#6-写入管线remember)
2123
- [7. 读取管线:Smart Recall](#7-读取管线smart-recall)
@@ -307,6 +309,52 @@ mnemon/
307309
└── Makefile # 构建、安装、测试
308310
```
309311

312+
### 4.1 数据目录布局
313+
314+
```
315+
~/.mnemon/
316+
├── active # 当前默认记忆体名(纯文本)
317+
├── prompt/ # 所有记忆体共享
318+
│ ├── guide.md # 行为引导(recall/remember 规则)
319+
│ └── skill.md # 技能定义(命令参考)
320+
└── data/ # 每个记忆体拥有独立目录
321+
├── default/
322+
│ └── mnemon.db # SQLite 数据库(WAL 模式)
323+
├── work/
324+
│ └── mnemon.db
325+
└── <name>/
326+
└── mnemon.db
327+
```
328+
329+
**隔离边界**:每个记忆体包含独立的 `mnemon.db` — 洞察、边、操作日志完全隔离。Prompt 文件(`guide.md``skill.md`)共享 — 行为规则是通用的,记忆数据是私有的。
330+
331+
### 4.2 记忆体隔离
332+
333+
Mnemon 支持命名记忆体(store),为不同 agent、项目或场景提供轻量数据隔离。
334+
335+
**为什么用命名记忆体而非只靠 `--data-dir`**
336+
337+
`--data-dir` 覆盖整个基础目录 — 需要调用者管理完整路径,语义不清晰。命名记忆体提供语义明确的标识(`MNEMON_STORE=work` 对比 `--data-dir ~/.mnemon-work`),并且天然适配环境变量 — 这是并发进程间隔离的标准机制。
338+
339+
**解析优先级**(从高到低):
340+
341+
```
342+
--store 标志 > MNEMON_STORE 环境变量 > ~/.mnemon/active 文件 > "default"
343+
```
344+
345+
分层设计服务于不同场景:
346+
347+
| 机制 | 场景 |
348+
|------|------|
349+
| `--store` 标志 | 一次性 CLI 覆盖、脚本 |
350+
| `MNEMON_STORE` 环境变量 | 按进程隔离 — 不同 agent 使用不同记忆体 |
351+
| `active` 文件 | 持久化用户偏好 — `mnemon store set work` |
352+
| `"default"` | 零配置 — 开箱即用 |
353+
354+
**自动迁移**:当 `data/` 目录不存在但旧版 `~/.mnemon/mnemon.db` 存在时,mnemon 自动将其移动到 `data/default/mnemon.db`。老用户升级无感知。
355+
356+
**设计原则 — 轻量且有界**:记忆体隔离解决的是必要的数据分离需求,不会膨胀为多租户系统。没有访问控制、没有跨 store 查询、除名称外没有 store 元数据。保持功能有界 — Mnemon 是记忆守护进程,不是知识库平台。
357+
310358
---
311359

312360
## 5. MAGMA 四图模型

0 commit comments

Comments
 (0)