memorix 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,265 @@
1
+ # Memorix Configuration Guide
2
+
3
+ Memorix is designed around one simple idea:
4
+
5
+ - `memorix.yml` controls behavior
6
+ - `.env` stores secrets
7
+
8
+ Everything else exists for compatibility or advanced overrides.
9
+
10
+ The recommended model is:
11
+
12
+ - keep your day-to-day defaults in `~/.memorix`
13
+ - add project files only when a repo needs overrides
14
+ - let project config override global defaults instead of treating every repo as a fresh setup
15
+
16
+ ---
17
+
18
+ ## Two Files, Two Roles
19
+
20
+ ### `memorix.yml`
21
+
22
+ Use `memorix.yml` for structured project behavior:
23
+
24
+ - LLM provider and model defaults
25
+ - embedding mode
26
+ - Git-Memory settings
27
+ - session injection behavior
28
+ - server and dashboard settings
29
+ - team or hub-mode options
30
+
31
+ Default location:
32
+
33
+ - user defaults: `~/.memorix/memorix.yml`
34
+
35
+ Optional override location:
36
+
37
+ - project root: `./memorix.yml`
38
+
39
+ ### `.env`
40
+
41
+ Use `.env` for secrets only:
42
+
43
+ - API keys
44
+ - base URLs
45
+ - provider tokens
46
+
47
+ Default location:
48
+
49
+ - user defaults: `~/.memorix/.env`
50
+
51
+ Optional override location:
52
+
53
+ - project root: `./.env`
54
+
55
+ ---
56
+
57
+ ## Resolution Order
58
+
59
+ ### Behavior settings
60
+
61
+ For normal configuration values, Memorix resolves in this order:
62
+
63
+ 1. environment variables
64
+ 2. project `memorix.yml` overrides
65
+ 3. user `~/.memorix/memorix.yml` defaults
66
+ 4. legacy `~/.memorix/config.json`
67
+ 5. hardcoded defaults
68
+
69
+ ### Secrets
70
+
71
+ For secrets loaded through dotenv, Memorix resolves in this order:
72
+
73
+ 1. system environment variables from the shell or MCP host config
74
+ 2. project `.env` overrides
75
+ 3. user `~/.memorix/.env` defaults
76
+
77
+ This means host-provided env vars always win.
78
+
79
+ ---
80
+
81
+ ## Minimal Example
82
+
83
+ If you want to initialize these files interactively, run:
84
+
85
+ ```bash
86
+ memorix init
87
+ ```
88
+
89
+ The init wizard now lets you choose between:
90
+
91
+ - `Global defaults` for personal multi-project workflows
92
+ - `Project config` for repo-specific overrides
93
+
94
+ `memorix.yml`
95
+
96
+ ```yml
97
+ llm:
98
+ provider: openai
99
+ model: gpt-4o-mini
100
+
101
+ embedding:
102
+ provider: off
103
+
104
+ git:
105
+ autoHook: true
106
+ ingestOnCommit: true
107
+ skipMergeCommits: true
108
+
109
+ behavior:
110
+ formationMode: active
111
+ sessionInject: minimal
112
+
113
+ server:
114
+ transport: stdio
115
+ dashboard: true
116
+ ```
117
+
118
+ `.env`
119
+
120
+ ```bash
121
+ MEMORIX_LLM_API_KEY=sk-...
122
+ MEMORIX_EMBEDDING_API_KEY=sk-...
123
+ MEMORIX_LLM_BASE_URL=https://api.openai.com/v1
124
+ MEMORIX_EMBEDDING_BASE_URL=https://api.openai.com/v1
125
+ ```
126
+
127
+ If you do not need LLM or embedding features yet, you can leave `.env` empty and Memorix will still work.
128
+
129
+ ---
130
+
131
+ ## Key Sections in `memorix.yml`
132
+
133
+ ### `llm`
134
+
135
+ Used for optional LLM-enhanced behavior such as:
136
+
137
+ - formation quality uplift
138
+ - compression
139
+ - reranking
140
+ - smarter deduplication
141
+
142
+ Common keys:
143
+
144
+ - `provider`
145
+ - `model`
146
+ - `baseUrl`
147
+
148
+ ### `embedding`
149
+
150
+ Controls semantic search mode.
151
+
152
+ Common values:
153
+
154
+ - `off`
155
+ - `api`
156
+ - `fastembed`
157
+ - `transformers`
158
+ - `auto`
159
+
160
+ `auto` now prefers a configured remote embedding API first.
161
+
162
+ - if `MEMORIX_EMBEDDING_API_KEY` or another supported API key is present, Memorix will use the remote `/v1/embeddings` provider first
163
+ - only if API embedding is unavailable will it fall back to local `fastembed`, then `transformers`
164
+ - this keeps semantic search on the API path by default while preserving local fallback behavior
165
+
166
+ When using API embeddings with optional dimension shortening:
167
+
168
+ - `MEMORIX_EMBEDDING_DIMENSIONS` is treated as part of the embedding configuration identity
169
+ - Memorix keeps API embedding cache entries and probed dimension metadata isolated per `baseUrl + model + requestedDimensions`
170
+ - changing from shortened dimensions back to native dimensions no longer reuses stale cached vectors or stale probe results
171
+
172
+ ### `git`
173
+
174
+ Controls Git-Memory behavior.
175
+
176
+ Common keys:
177
+
178
+ - `autoHook`
179
+ - `ingestOnCommit`
180
+ - `maxDiffSize`
181
+ - `skipMergeCommits`
182
+ - `excludePatterns`
183
+ - `noiseKeywords`
184
+
185
+ ### `behavior`
186
+
187
+ Controls runtime behavior.
188
+
189
+ Common keys:
190
+
191
+ - `sessionInject`
192
+ - `syncAdvisory`
193
+ - `autoCleanup`
194
+ - `formationMode`
195
+
196
+ ### `server`
197
+
198
+ Controls transport and dashboard behavior.
199
+
200
+ Common keys:
201
+
202
+ - `transport`
203
+ - `port`
204
+ - `dashboard`
205
+ - `dashboardPort`
206
+
207
+ ---
208
+
209
+ ## Diagnosing Active Config
210
+
211
+ Run:
212
+
213
+ ```bash
214
+ memorix status
215
+ ```
216
+
217
+ `memorix status` shows:
218
+
219
+ - which config files exist
220
+ - which `.env` files were loaded
221
+ - where important values came from
222
+ - whether env vars overrode YAML
223
+
224
+ This is the fastest way to debug “why is Memorix using this value?”
225
+
226
+ ---
227
+
228
+ ## Legacy Config
229
+
230
+ Memorix still supports:
231
+
232
+ - `~/.memorix/config.json`
233
+
234
+ This exists mainly for backward compatibility with older TUI-based configuration flows.
235
+
236
+ For new setups, prefer:
237
+
238
+ - `memorix.yml`
239
+ - `.env`
240
+
241
+ ---
242
+
243
+ ## Recommended Team Conventions
244
+
245
+ For most teams, keep it simple:
246
+
247
+ - keep your personal defaults in `~/.memorix/memorix.yml`
248
+ - commit `memorix.yml` only when the repo needs shared overrides
249
+ - do **not** commit `.env`
250
+ - reserve project-level config for shared behavior or repo-specific overrides
251
+
252
+ This gives you:
253
+
254
+ - reproducible project behavior
255
+ - local secret isolation
256
+ - cleaner onboarding for new contributors
257
+
258
+ ---
259
+
260
+ ## Related Docs
261
+
262
+ - [Setup Guide](SETUP.md)
263
+ - [Git Memory Guide](GIT_MEMORY.md)
264
+ - [Architecture](ARCHITECTURE.md)
265
+ - [Development Guide](DEVELOPMENT.md)
@@ -0,0 +1,358 @@
1
+ # Memorix 设计决策记录
2
+
3
+ > 最后更新: 2026-03-09 (v1.0.0)
4
+ > 记录所有重要的架构和设计决策及其背后的理由
5
+
6
+ ---
7
+
8
+ ## 决策编号规则
9
+ - `ADR-XXX`: Architecture Decision Record (架构决策)
10
+ - 按时间顺序编号
11
+
12
+ ---
13
+
14
+ ## ADR-001: 采用 MCP Protocol 而非自定义协议
15
+
16
+ **状态**: 已采纳
17
+
18
+ **背景**: 需要让 Memorix 与多种 AI Agent (Cursor, Windsurf, Claude Code 等) 通信。
19
+
20
+ **决策**: 使用 MCP (Model Context Protocol) 作为通信协议。
21
+
22
+ **理由**:
23
+ - MCP 是 Anthropic 制定的开放标准,被多数 AI IDE 支持
24
+ - stdio 传输模式简单可靠,无需 HTTP 服务器
25
+ - 已有 `@modelcontextprotocol/sdk` 官方 SDK
26
+ - 兼容 MCP Official Memory Server 的工具命名
27
+
28
+ **影响**:
29
+ - 日志必须输出到 `stderr` (stdout 被 MCP 协议占用)
30
+ - 工具必须返回 `{ content: [{ type: 'text', text: ... }] }` 格式
31
+ - 不能主动推送消息给 Agent,只能响应工具调用
32
+
33
+ ---
34
+
35
+ ## ADR-002: 双存储模型 (Knowledge Graph + Observations)
36
+
37
+ **状态**: 已采纳
38
+
39
+ **背景**: MCP Official Memory Server 只有知识图谱,表达能力有限。
40
+
41
+ **决策**: 采用双存储:
42
+ - Knowledge Graph (MCP 兼容): Entity + Relation
43
+ - Structured Observations (claude-mem 启发): 带类型、事实、概念的丰富记录
44
+
45
+ **理由**:
46
+ - Knowledge Graph 适合存储实体关系 (who/what)
47
+ - Observations 适合存储事件和上下文 (when/why/how)
48
+ - 两者通过 `entityName` 关联
49
+ - 保持与 MCP Official Memory Server 工具 API 100% 兼容
50
+
51
+ **权衡**:
52
+ - 增加了存储复杂度
53
+ - 需要两套持久化机制 (JSONL vs JSON)
54
+ - observation 的 entity 引用可能与图谱不同步
55
+
56
+ ---
57
+
58
+ ## ADR-003: 3层渐进式披露
59
+
60
+ **状态**: 已采纳
61
+
62
+ **背景**: AI Agent 的上下文窗口有限,全量返回记忆会浪费 token。
63
+
64
+ **决策**: 采用 claude-mem 的 3层渐进式披露:
65
+ - L1 Search: 紧凑索引 (~50-100 tokens/条)
66
+ - L2 Timeline: 时间线上下文
67
+ - L3 Detail: 完整详情 (~500-1000 tokens/条)
68
+
69
+ **理由**:
70
+ - claude-mem 验证了此模式的有效性 (27K stars, ~10x token 节省)
71
+ - Agent 可以先浏览索引,再按需获取详情
72
+ - Token 预算管理让 Agent 控制成本
73
+
74
+ **影响**:
75
+ - 需要 3 个 MCP 工具而非 1 个搜索工具
76
+ - Agent 需要学习使用 Progressive Disclosure 工作流
77
+ - 在工具描述中嵌入了 Progressive Disclosure 使用提示
78
+
79
+ ---
80
+
81
+ ## ADR-004: Orama 作为搜索引擎
82
+
83
+ **状态**: 已采纳
84
+
85
+ **背景**: 需要全文搜索和向量搜索能力。
86
+
87
+ **考虑的方案**:
88
+ | 方案 | 优点 | 缺点 |
89
+ |------|------|------|
90
+ | SQLite FTS5 | 成熟, 持久化 | 无向量搜索, 需要 native addon |
91
+ | Orama | 纯 JS, 支持向量, 轻量 | 内存中, 重启需重建 |
92
+ | Meilisearch | 功能丰富 | 需要额外进程 |
93
+ | pgvector | 强大的向量搜索 | 太重, 需要 PostgreSQL |
94
+
95
+ **决策**: 采用 Orama。
96
+
97
+ **理由**:
98
+ - 纯 JavaScript, 零 native 依赖
99
+ - 内置 BM25 全文搜索
100
+ - 支持向量搜索 (可选)
101
+ - 可嵌入到进程中, 无需额外服务
102
+ - 通过 npx 安装时无编译步骤
103
+
104
+ **权衡**:
105
+ - 内存中运行 — 重启需要重建索引 (`reindexObservations`)
106
+ - 大量数据时内存占用可能较高
107
+ - Orama 的某些 where 过滤行为不太直观
108
+
109
+ ---
110
+
111
+ ## ADR-005: 全局共享数据目录
112
+
113
+ **状态**: 已采纳
114
+
115
+ **背景**: 需要让不同 Agent 共享同一个项目的记忆数据。
116
+
117
+ **决策**: 数据存储在 `~/.memorix/data/<projectId>/`。
118
+
119
+ **理由**:
120
+ - 所有 Agent 都可以访问同一个目录
121
+ - projectId 基于 Git remote URL, 保证同一项目的唯一性
122
+ - 不污染项目目录
123
+ - 不需要用户额外配置
124
+
125
+ **权衡**:
126
+ - 多个 Agent 同时写入可能冲突 (无文件锁)
127
+ - 非 Git 项目的 projectId 可能不稳定 (基于目录名)
128
+ - 用户数据不跟随 Git (需要手动备份)
129
+
130
+ ---
131
+
132
+ ## ADR-006: 可选 Embedding (优雅降级)
133
+
134
+ **状态**: 已采纳
135
+
136
+ **背景**: 向量搜索显著提升搜索质量,但 fastembed 有 ~30MB 模型下载。
137
+
138
+ **决策**: Embedding 作为可选功能,不安装时自动降级为纯全文搜索。
139
+
140
+ **理由**:
141
+ - 降低入门门槛 — npx 即用
142
+ - 全文搜索 (BM25) 对于大多数场景已足够好
143
+ - 需要向量搜索的高级用户可以安装 fastembed
144
+ - 避免首次启动时的长时间模型下载
145
+
146
+ **实现**:
147
+ - `getEmbeddingProvider()` 尝试动态 import
148
+ - Schema 根据 provider 是否存在动态调整
149
+ - 搜索自动选择 fulltext 或 hybrid 模式
150
+
151
+ ---
152
+
153
+ ## ADR-007: Hooks 系统实现隐式记忆
154
+
155
+ **状态**: 已采纳
156
+
157
+ **背景**: 依赖 Agent 主动调用 `memorix_store` 不可靠 — Agent 可能忘记存储重要信息。
158
+
159
+ **决策**: 实现 Hooks 系统,自动从 Agent 的操作中抓取值得记忆的信息。
160
+
161
+ **架构**: `stdin JSON → Normalizer → Pattern Detector → Handler → Store`
162
+
163
+ **理由**:
164
+ - 不依赖 Agent 的记忆意识
165
+ - 通过模式检测过滤噪音,只记录有价值的信息
166
+ - 30秒冷却期防止信息过载
167
+ - 多 Agent 格式统一化确保跨平台兼容
168
+
169
+ **权衡**:
170
+ - 增加了实现复杂度
171
+ - 模式检测可能有误报/漏报
172
+ - 不同 Agent 的 Hook 接入方式差异大
173
+ - 需要维护每个 Agent 的格式适配
174
+
175
+ ---
176
+
177
+ ## ADR-008: 指数衰减的记忆保留
178
+
179
+ **状态**: 已采纳
180
+
181
+ **背景**: 随着时间推移,记忆会越来越多,需要管理过期记忆。
182
+
183
+ **决策**: 采用指数衰减 + 免疫机制。
184
+
185
+ **公式**: `score = base × e^(-age/retention) × accessBoost`
186
+
187
+ **理由**:
188
+ - 指数衰减符合人类记忆的遗忘曲线
189
+ - 高重要性和高访问频率的记忆自然保留
190
+ - 免疫机制保护关键知识不被遗忘
191
+ - 三区域分类 (Active/Stale/Archive) 提供清晰的生命周期
192
+
193
+ **当前限制**:
194
+ - 只有报告功能,没有实际的自动归档/删除
195
+ - `high` 重要性默认免疫 — 这意味着 gotcha/decision/trade-off 永远存在
196
+ - 未来需要添加 `memorix_compact` 工具来实际归档
197
+
198
+ ---
199
+
200
+ ## ADR-009: JSONL 格式存储知识图谱
201
+
202
+ **状态**: 已采纳
203
+
204
+ **背景**: MCP Official Memory Server 使用单文件 JSON 存储整个图谱。
205
+
206
+ **决策**: 使用 JSONL (JSON Lines) 格式分开存储 entities 和 relations。
207
+
208
+ **理由**:
209
+ - 每行一个记录,便于追加写入
210
+ - 与 MCP Official Memory Server 的数据模型兼容
211
+ - 便于外部工具处理 (grep, jq)
212
+ - 文件损坏时只影响单行而非整个文件
213
+
214
+ **权衡**:
215
+ - 读取需要逐行解析
216
+ - 不支持原子更新(需要全文重写)
217
+ - 与 MCP Official Server 的单文件 JSON 格式不完全相同
218
+
219
+ ---
220
+
221
+ ## ADR-010: 实体自动抽取 (MAGMA 启发)
222
+
223
+ **状态**: 已采纳
224
+
225
+ **背景**: 用户提供的概念和文件列表通常不完整。
226
+
227
+ **决策**: 使用正则表达式从 observation 内容中自动抽取实体。
228
+
229
+ **理由**:
230
+ - 灵感来自 MemCP 的 RegexEntityExtractor (MAGMA 论文)
231
+ - 零额外依赖 — 纯正则匹配
232
+ - 自动丰富的概念和文件列表提升搜索召回率
233
+ - 因果语言检测帮助推断关系类型
234
+
235
+ **权衡**:
236
+ - 正则表达式的准确率有限 (可能误匹配)
237
+ - 不支持中文标识符
238
+ - 无法理解语义关系 — 只做词汇级别匹配
239
+ - 未来可以考虑用 LLM 替代正则做更智能的抽取
240
+
241
+ ---
242
+
243
+ ## ADR-011: 跨 Agent 工作空间同步
244
+
245
+ **状态**: 已采纳
246
+
247
+ **背景**: 用户经常在多个 AI IDE 之间切换,每次都要重新配置 MCP servers、规则等。
248
+
249
+ **决策**: 实现一键式工作空间迁移 — MCP configs + Rules + Workflows + Skills。
250
+
251
+ **理由**:
252
+ - 这是 Memorix 独有的差异化功能
253
+ - 减少用户在 Agent 之间切换的摩擦
254
+ - 集中管理避免配置不一致
255
+ - 支持选择性同步 (`items` 参数)
256
+
257
+ **实现要点**:
258
+ - 每个 Agent 一个 MCP 配置适配器 (parse ↔ generate)
259
+ - 每个 Agent 一个规则格式适配器
260
+ - Workflow 格式转换
261
+ - Skills 目录复制
262
+ - Apply 操作带备份和回滚
263
+
264
+ ---
265
+
266
+ ## ADR-012: CLI 使用 Citty 框架
267
+
268
+ **状态**: 已采纳
269
+
270
+ **背景**: 需要一个轻量级 CLI 框架来定义命令。
271
+
272
+ **考虑的方案**: Commander, Yargs, Citty, CAC
273
+
274
+ **决策**: 使用 Citty (UnJS 生态)。
275
+
276
+ **理由**:
277
+ - 轻量级, 无额外依赖
278
+ - TypeScript 原生支持
279
+ - 与 UnJS 生态其他工具 (如 Nitro, Nuxt) 一致
280
+ - 支持子命令定义
281
+ - 自动生成 help 信息
282
+
283
+ ---
284
+
285
+ ## ADR-013: 工具合并 (41 → 22 默认)
286
+
287
+ **状态**: 已采纳 (v1.0.0)
288
+
289
+ **背景**: 工具数量膨胀到 41 个,超出多数 IDE 的工具槽位限制。
290
+
291
+ **决策**:
292
+ - Team 工具: 13 个合并为 4 个 (使用 `action` 参数模式)
293
+ - KG 工具: 9 个改为可选 (通过 `~/.memorix/settings.json` 启用)
294
+ - Export+Import: 2 个合并为 1 个 `memorix_transfer`
295
+
296
+ **理由**:
297
+ - 多数用户不需要知识图谱工具,默认隐藏减少器噪
298
+ - `action` 参数模式是 MCP 工具的最佳实践(减少工具数量,保留功能)
299
+ - 22 个默认工具在所有 IDE 工具槽位限制内
300
+
301
+ ---
302
+
303
+ ## ADR-014: 团队协作 (team-state.json)
304
+
305
+ **状态**: 已采纳 (v1.0.0)
306
+
307
+ **背景**: 多个 Agent 在同一工作区并行工作时,缺乏协调机制。
308
+
309
+ **决策**: 基于文件的团队状态共享,包含 4 个工具:注册/文件锁/任务板/消息。
310
+
311
+ **理由**:
312
+ - 文件锁防止多 Agent 同时编辑同一文件
313
+ - 任务板让 Agent 之间分工协作
314
+ - 消息、任务与轮询共同提供显式的异步协作,而不是假设跨 IDE 实时通信
315
+ - `team-state.json` 简单可靠,无需额外服务
316
+
317
+ **生产加固**:
318
+ - Inbox 上限 200 条,自动淡化旧消息
319
+ - 文件锁 10min TTL 自动释放
320
+ - Agent 离开时自动释放所有锁 + 清空 Inbox
321
+ - 孤儿任务自动救援
322
+
323
+ ---
324
+
325
+ ## ADR-015: 启动自动清理
326
+
327
+ **状态**: 已采纳 (v1.0.0)
328
+
329
+ **背景**: 用户往往忘记手动运行 `memorix_retention` 和 `memorix_consolidate`。
330
+
331
+ **决策**: 在 `deferredInit` 中自动执行:
332
+ 1. `archiveExpired()` — 归档过期记忆
333
+ 2. 有 LLM: `deduplicateMemory()` — 语义去重
334
+ 3. 无 LLM: `executeConsolidation()` — Jaccard 相似度合并
335
+
336
+ **理由**:
337
+ - 零人工维护,用户无需知道记忆管理细节
338
+ - 配置了 LLM 的用户想要更高质量,每次仅消耗几百 token
339
+ - 在 MCP 握手后的后台任务中执行,不影响主流程
340
+
341
+ ---
342
+
343
+ ## ADR-016: LLM 增强模式 (可选)
344
+
345
+ **状态**: 已采纳 (v0.11.0)
346
+
347
+ **背景**: 纯启发式去重质量有限,LLM 可以提供更智能的记忆管理。
348
+
349
+ **决策**: 可选 LLM 集成,提供三项能力:
350
+ - **叙述压缩**: 存储前压缩冗余内容 (~27% token 节省)
351
+ - **搜索重排序**: 按语义相关性重新排序 (60% 查询改善)
352
+ - **写入时去重**: 写入时检测重复和冲突
353
+
354
+ **理由**:
355
+ - 所有 LLM 功能均为可选,不配置时默认用启发式引擎
356
+ - 智能过滤确保 LLM 仅在有意义时被调用
357
+ - 支持 OpenAI/Anthropic/OpenRouter 及任何兼容接口
358
+ - 配置优先级: 环境变量 > `~/.memorix/config.json` > 自动检测