dsh-mnemon 0.1.0

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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +169 -0
  3. package/README.md +169 -0
  4. package/cordis.patch.yml +15 -0
  5. package/docs/README.md +8 -0
  6. package/docs/en/README.md +39 -0
  7. package/docs/en/architecture.md +129 -0
  8. package/docs/en/assets/project-architecture.svg +182 -0
  9. package/docs/en/configuration.md +204 -0
  10. package/docs/en/development.md +178 -0
  11. package/docs/en/getting-started.md +147 -0
  12. package/docs/en/interfaces.md +159 -0
  13. package/docs/en/operations.md +151 -0
  14. package/docs/en/project-overview.md +247 -0
  15. package/docs/en/roadmap.md +41 -0
  16. package/docs/en/storage-model.md +179 -0
  17. package/docs/en/workflows.md +290 -0
  18. package/docs/zh-CN/README.md +39 -0
  19. package/docs/zh-CN/architecture.md +129 -0
  20. package/docs/zh-CN/assets/project-architecture.svg +182 -0
  21. package/docs/zh-CN/assets/screenshots/conversation-recall.png +0 -0
  22. package/docs/zh-CN/assets/screenshots/conversation-writeback.png +0 -0
  23. package/docs/zh-CN/assets/screenshots/documents-markdown.png +0 -0
  24. package/docs/zh-CN/assets/screenshots/entities-context.png +0 -0
  25. package/docs/zh-CN/assets/screenshots/memory-content.png +0 -0
  26. package/docs/zh-CN/assets/screenshots/overview-memory-graph.png +0 -0
  27. package/docs/zh-CN/assets/screenshots/recall-agent-answer.png +0 -0
  28. package/docs/zh-CN/assets/screenshots/runtime-memory.png +0 -0
  29. package/docs/zh-CN/configuration.md +204 -0
  30. package/docs/zh-CN/development.md +178 -0
  31. package/docs/zh-CN/getting-started.md +147 -0
  32. package/docs/zh-CN/interfaces.md +159 -0
  33. package/docs/zh-CN/operations.md +151 -0
  34. package/docs/zh-CN/project-overview.md +247 -0
  35. package/docs/zh-CN/roadmap.md +41 -0
  36. package/docs/zh-CN/storage-model.md +179 -0
  37. package/docs/zh-CN/workflows.md +290 -0
  38. package/lib/client.js +6288 -0
  39. package/lib/client.js.map +1 -0
  40. package/lib/index.js +4453 -0
  41. package/lib/types/client/MnemonLogo.d.ts +7 -0
  42. package/lib/types/client/MnemonLogo.d.ts.map +1 -0
  43. package/lib/types/client/MnemonLogo.js +6 -0
  44. package/lib/types/client/MnemonLogo.js.map +1 -0
  45. package/lib/types/client/MnemonSettingsCard.d.ts +9 -0
  46. package/lib/types/client/MnemonSettingsCard.d.ts.map +1 -0
  47. package/lib/types/client/MnemonSettingsCard.js +109 -0
  48. package/lib/types/client/MnemonSettingsCard.js.map +1 -0
  49. package/lib/types/client/MnemonView.d.ts +11 -0
  50. package/lib/types/client/MnemonView.d.ts.map +1 -0
  51. package/lib/types/client/MnemonView.js +1239 -0
  52. package/lib/types/client/MnemonView.js.map +1 -0
  53. package/lib/types/client/api.d.ts +68 -0
  54. package/lib/types/client/api.d.ts.map +1 -0
  55. package/lib/types/client/api.js +80 -0
  56. package/lib/types/client/api.js.map +1 -0
  57. package/lib/types/client/index.d.ts +4 -0
  58. package/lib/types/client/index.d.ts.map +1 -0
  59. package/lib/types/client/index.js +36 -0
  60. package/lib/types/client/index.js.map +1 -0
  61. package/lib/types/client/locales.d.ts +1054 -0
  62. package/lib/types/client/locales.d.ts.map +1 -0
  63. package/lib/types/client/locales.js +1062 -0
  64. package/lib/types/client/locales.js.map +1 -0
  65. package/lib/types/client/settings.d.ts +17 -0
  66. package/lib/types/client/settings.d.ts.map +1 -0
  67. package/lib/types/client/settings.js +49 -0
  68. package/lib/types/client/settings.js.map +1 -0
  69. package/lib/types/commands.d.ts +6 -0
  70. package/lib/types/commands.d.ts.map +1 -0
  71. package/lib/types/commands.js +100 -0
  72. package/lib/types/commands.js.map +1 -0
  73. package/lib/types/config-values.d.ts +4 -0
  74. package/lib/types/config-values.d.ts.map +1 -0
  75. package/lib/types/config-values.js +4 -0
  76. package/lib/types/config-values.js.map +1 -0
  77. package/lib/types/config.d.ts +49 -0
  78. package/lib/types/config.d.ts.map +1 -0
  79. package/lib/types/config.js +55 -0
  80. package/lib/types/config.js.map +1 -0
  81. package/lib/types/contracts.d.ts +272 -0
  82. package/lib/types/contracts.d.ts.map +1 -0
  83. package/lib/types/contracts.js +2 -0
  84. package/lib/types/contracts.js.map +1 -0
  85. package/lib/types/documents.d.ts +149 -0
  86. package/lib/types/documents.d.ts.map +1 -0
  87. package/lib/types/documents.js +503 -0
  88. package/lib/types/documents.js.map +1 -0
  89. package/lib/types/guidance.d.ts +9 -0
  90. package/lib/types/guidance.d.ts.map +1 -0
  91. package/lib/types/guidance.js +18 -0
  92. package/lib/types/guidance.js.map +1 -0
  93. package/lib/types/index.d.ts +15 -0
  94. package/lib/types/index.d.ts.map +1 -0
  95. package/lib/types/index.js +45 -0
  96. package/lib/types/index.js.map +1 -0
  97. package/lib/types/lifecycle.d.ts +75 -0
  98. package/lib/types/lifecycle.d.ts.map +1 -0
  99. package/lib/types/lifecycle.js +380 -0
  100. package/lib/types/lifecycle.js.map +1 -0
  101. package/lib/types/memory-bodies.d.ts +47 -0
  102. package/lib/types/memory-bodies.d.ts.map +1 -0
  103. package/lib/types/memory-bodies.js +160 -0
  104. package/lib/types/memory-bodies.js.map +1 -0
  105. package/lib/types/process.d.ts +14 -0
  106. package/lib/types/process.d.ts.map +1 -0
  107. package/lib/types/process.js +65 -0
  108. package/lib/types/process.js.map +1 -0
  109. package/lib/types/review-activity.d.ts +33 -0
  110. package/lib/types/review-activity.d.ts.map +1 -0
  111. package/lib/types/review-activity.js +37 -0
  112. package/lib/types/review-activity.js.map +1 -0
  113. package/lib/types/rpc.d.ts +12 -0
  114. package/lib/types/rpc.d.ts.map +1 -0
  115. package/lib/types/rpc.js +225 -0
  116. package/lib/types/rpc.js.map +1 -0
  117. package/lib/types/runner.d.ts +29 -0
  118. package/lib/types/runner.d.ts.map +1 -0
  119. package/lib/types/runner.js +150 -0
  120. package/lib/types/runner.js.map +1 -0
  121. package/lib/types/runtime-memory.d.ts +104 -0
  122. package/lib/types/runtime-memory.d.ts.map +1 -0
  123. package/lib/types/runtime-memory.js +415 -0
  124. package/lib/types/runtime-memory.js.map +1 -0
  125. package/lib/types/service.d.ts +173 -0
  126. package/lib/types/service.d.ts.map +1 -0
  127. package/lib/types/service.js +508 -0
  128. package/lib/types/service.js.map +1 -0
  129. package/lib/types/settings.d.ts +6 -0
  130. package/lib/types/settings.d.ts.map +1 -0
  131. package/lib/types/settings.js +75 -0
  132. package/lib/types/settings.js.map +1 -0
  133. package/lib/types/storage-scope.d.ts +39 -0
  134. package/lib/types/storage-scope.d.ts.map +1 -0
  135. package/lib/types/storage-scope.js +179 -0
  136. package/lib/types/storage-scope.js.map +1 -0
  137. package/lib/types/subagent.d.ts +97 -0
  138. package/lib/types/subagent.d.ts.map +1 -0
  139. package/lib/types/subagent.js +619 -0
  140. package/lib/types/subagent.js.map +1 -0
  141. package/lib/types/tools.d.ts +8 -0
  142. package/lib/types/tools.d.ts.map +1 -0
  143. package/lib/types/tools.js +328 -0
  144. package/lib/types/tools.js.map +1 -0
  145. package/package.json +111 -0
@@ -0,0 +1,290 @@
1
+ # Lifecycle and Core Workflows
2
+
3
+ [简体中文](../zh-CN/workflows.md) | **English** | [Documentation Center](./README.md)
4
+
5
+ ## Per-Turn Context
6
+
7
+ The plugin registers two system prompt sections:
8
+
9
+ - `mnemon:routing`: when `routingGuidance=true`, provides concise boundaries for tiered queries;
10
+ - `mnemon:runtime-memory`: reads the latest `USER.md` and `MEMORY.md` whenever a prompt is assembled and includes admission rules for saving content.
11
+
12
+ Lifecycle hooks do not unconditionally read the Memory Space catalog or run recall at the start of every turn:
13
+
14
+ ```text
15
+ agent/session-start
16
+ -> mark primePending
17
+
18
+ agent/pre-step(step=1)
19
+ -> cancel pending/running background review for a new turn
20
+ -> mark Prime once
21
+ -> optionally append one short recall/writeback cue
22
+ -> main Agent decides whether to call a memory tool
23
+ ```
24
+
25
+ Prime only initializes routing state; it does not run asynchronous CLI status queries.
26
+
27
+ ## Root Agent Recall
28
+
29
+ ```text
30
+ Root Agent calls mnemon_recall(query)
31
+ |
32
+ v
33
+ MnemonSubagentCoordinator
34
+ |
35
+ | spawn + recall persona
36
+ | allow: memory_bodies, recall, related
37
+ v
38
+ Recall worker lists the catalog
39
+ |
40
+ v
41
+ select active Memory Space(s) by name + description
42
+ |
43
+ v
44
+ call mnemon_recall from the worker
45
+ |
46
+ v
47
+ MnemonService searches selected Store(s)
48
+ |
49
+ v
50
+ normalize and attach memoryBodyId / memoryBodyName
51
+ |
52
+ v
53
+ structured output, Host caps results at 12
54
+ |
55
+ v
56
+ Root Agent receives evidence, not the raw routing trace
57
+ ```
58
+
59
+ If the user has already supplied current facts, or the repository can answer directly, the Agent should not recall merely to “show memory.” When relationship explanations are needed, first use the complete `memoryBodyId + id` returned by recall, then run related.
60
+
61
+ ## Web Retrieval and Agent Queries
62
+
63
+ The Web “Recall” page follows a different path from model tools:
64
+
65
+ ```text
66
+ Direct search
67
+ -> RPC read channel
68
+ -> MnemonService.search directly
69
+ -> raw evidence
70
+
71
+ Agent search
72
+ -> the same deterministic direct search
73
+ -> spawn a worker with no Mnemon tools
74
+ -> answer only from supplied evidence
75
+ -> Host filters citations to actual memoryBodyId/id pairs
76
+ ```
77
+
78
+ The “Entities” and “Content” pages also read the deterministic service directly and do not start a recall worker. “Content” uses a graph snapshot and does not increment Mnemon recall access counts.
79
+
80
+ ## Explicit Long-Term Writes
81
+
82
+ The long-term write flow for the root Agent or `/mnemon remember` is:
83
+
84
+ ```text
85
+ durable candidate
86
+ |
87
+ v
88
+ spawn write worker
89
+ |
90
+ +-- list Memory Spaces
91
+ +-- choose the narrowest suitable scope
92
+ +-- recall when duplicate/conflict checking is useful
93
+ +-- create a new scope only for a recurring distinct domain
94
+ +-- remember / link / forget / merge as requested
95
+ v
96
+ structured receipt
97
+ ```
98
+
99
+ The Host generates IDs for new Memory Spaces. A successful write to an inactive target activates it. Merging a source database is non-destructive.
100
+
101
+ Runtime `add` / `replace` / `remove` and Document `create` / `update` do not need a model to perform storage I/O; they enter the deterministic control layer through the coordinator. Only capacity maintenance and archiving start dedicated workers.
102
+
103
+ ## Runtime add: Normal Path
104
+
105
+ ```text
106
+ request
107
+ -> normalize content
108
+ -> acquire in-process queue and file lock
109
+ -> reload memories.json
110
+ -> validate unique match / duplicate / capacity
111
+ -> write temporary JSON and Markdown projections
112
+ -> rename projections
113
+ -> rename memories.json as the commit marker
114
+ -> return compact receipt
115
+ ```
116
+
117
+ `replace` and `remove` must match exactly one item through `old_text`. Capacity maintenance is triggered automatically only when `add` overflows.
118
+
119
+ ## USER.md Capacity Maintenance
120
+
121
+ ```text
122
+ USER add exceeds 4 KiB
123
+ |
124
+ v
125
+ snapshot revision + committed entries
126
+ |
127
+ v
128
+ spawn no-tool local compactor
129
+ |
130
+ v
131
+ return compacted entries + sourceIndexes
132
+ |
133
+ v
134
+ Host validates:
135
+ - every source index appears exactly once
136
+ - no duplicate or out-of-range index
137
+ - importance is not lowered
138
+ - candidate fits the Host byte budget
139
+ - revision is still current
140
+ |
141
+ +-- invalid/conflict -> preserve original data
142
+ |
143
+ v
144
+ deterministic UTF-8 packing
145
+ |
146
+ v
147
+ retry pending add
148
+ ```
149
+
150
+ The user profile is never sent to Memory Spaces. The worker has no tool permissions.
151
+
152
+ ## MEMORY.md Archival and Compaction
153
+
154
+ ```text
155
+ MEMORY add exceeds 10 KiB
156
+ |
157
+ v
158
+ snapshot revision + committed entries
159
+ |
160
+ v
161
+ spawn archive worker
162
+ allow: memory_bodies, recall, remember, body_create
163
+ |
164
+ v
165
+ route semantic clusters and archive or duplicate-check them
166
+ |
167
+ v
168
+ return action + target spaces + compacted candidates
169
+ |
170
+ v
171
+ Host validates structure, action, revision and byte budget
172
+ |
173
+ +-- failure/conflict -> preserve hot memory
174
+ |
175
+ v
176
+ pack candidates by importance
177
+ |
178
+ v
179
+ retry pending add
180
+ ```
181
+
182
+ The worker persona requires every committed entry to be represented in long-term storage or verified as a duplicate; this is an LLM-supervised policy. The Host's hard guarantees are structural, revision, and capacity validation, so semantic coverage should not be described as a database-level proof.
183
+
184
+ If a revision conflict occurs after a successful long-term write, the hot memory is preserved while the long-term layer may also contain a copy. The plugin prioritizes preventing data loss and does not attempt to roll back a completed Mnemon write across the database and file system.
185
+
186
+ ## Document Creation, Update, and Archiving
187
+
188
+ ```text
189
+ create/update request
190
+ |
191
+ v
192
+ capacityPlan using rendered UTF-8 bytes
193
+ |
194
+ +----+----+
195
+ | |
196
+ fits overflow
197
+ | |
198
+ v v
199
+ commit select least-recently-used active Document
200
+ |
201
+ v
202
+ snapshot document + revision
203
+ |
204
+ v
205
+ spawn archive worker
206
+ |
207
+ v
208
+ write/verify concise Mnemon cold reference
209
+ with title, summary, planned path, SHA-256
210
+ |
211
+ +----+----+
212
+ | |
213
+ failed receipt ok
214
+ | |
215
+ v v
216
+ keep active revision check
217
+ |
218
+ +----+----+
219
+ | |
220
+ conflict current
221
+ | |
222
+ v v
223
+ keep active move file to archived
224
+ |
225
+ v
226
+ retry original mutation
227
+ ```
228
+
229
+ Manual archiving uses the same “index first, move second” path. When the Mnemon index succeeds but a revision conflict occurs, the index is not rolled back, so a safe duplicate reference may remain while the active original text is never lost.
230
+
231
+ ## Deterministic Activity Scoring and Background Review
232
+
233
+ Completed turns accumulate four signals:
234
+
235
+ ```text
236
+ score =
237
+ min(floor(totalUserCharacters / 50), 3)
238
+ + completedTurnCount
239
+ + min(floor(completedToolResults / 5), 2)
240
+ + toolDiversityScore
241
+
242
+ toolDiversityScore:
243
+ unique tools < 3 -> 0
244
+ unique tools = 3 -> 1
245
+ unique tools >= 4 -> 2
246
+
247
+ eligible when score >= 5
248
+ ```
249
+
250
+ Reaching the threshold does not guarantee a write:
251
+
252
+ ```text
253
+ completed turn
254
+ |
255
+ v
256
+ score >= 5 ? -- no --> retain activity for later turns
257
+ |
258
+ yes
259
+ |
260
+ v
261
+ wait idleReviewMs (default 30 s)
262
+ |
263
+ +-- new turn --> cancel timer/worker, retain activity
264
+ |
265
+ v
266
+ confirm Agent is idle and turn/end exists
267
+ |
268
+ v
269
+ fork completed parent checkpoint
270
+ |
271
+ v
272
+ conservative maintenance decision
273
+ - at most one hot-memory mutation by persona
274
+ - at most one Document create/update by persona
275
+ - no direct long-term remember/forget tools
276
+ |
277
+ +-- completed, including skip -> clear activity
278
+ |
279
+ +-- failed/aborted ------------> retain activity
280
+ ```
281
+
282
+ “At most one” is currently enforced by the worker persona, not by a Host mutation counter. Background watermarks are not yet persisted, so a Host restart loses accumulated signals that have not been processed.
283
+
284
+ ## How Configuration Switches Interact
285
+
286
+ - `recallMode=off`: stops injecting recall cues; explicit `mnemon_recall` remains available.
287
+ - `writebackMode=off`: disables writeback cues and scored background review; explicit writes are still governed by `writeEnabled`.
288
+ - `lifecycleEnabled=false`: disables lifecycle reminders and review without removing explicit tools or Web entry points.
289
+ - `routingGuidance=false`: removes only the additional routing section; the Runtime Memory section remains registered.
290
+ - `writeEnabled=false`: removes semantic write tools and write RPC, and rejects write commands; it does not guarantee a read-only file-system mount.
@@ -0,0 +1,39 @@
1
+ # dsh-mnemon 文档中心
2
+
3
+ **简体中文** | [English](../en/README.md) | [返回项目首页](../../README.md)
4
+
5
+ 这组文档以当前代码实现为事实源。根 README 用于快速理解;这里展开设计理由、边界、事务流程、配置和运维方式。
6
+
7
+ ## 建议阅读路径
8
+
9
+ 1. [项目介绍](./project-overview.md):项目定位、Mnemon 与 DSH 的集成边界、三层模型、总体架构与适用场景。
10
+ 2. [快速开始](./getting-started.md):安装、首次配置与基本验证。
11
+ 3. [架构设计](./architecture.md):DSH Host、Web Client、控制层、子 Agent 与 Mnemon CLI 的边界。
12
+ 4. [存储与三层记忆模型](./storage-model.md):Runtime、Documents、Memory Spaces 的语义和目录结构。
13
+ 5. [生命周期与核心流程](./workflows.md):召回、写入、后台审查、容量整理和归档。
14
+ 6. [配置参考](./configuration.md):全部配置、默认值、优先级和 provider 要求。
15
+ 7. [WebUI、工具、命令与 RPC](./interfaces.md):所有用户与模型入口。
16
+ 8. [运维、安全与故障排查](./operations.md):锁、权限、备份、恢复和已知限制。
17
+ 9. [开发与验证](./development.md):模块结构、测试、构建和发布检查。
18
+ 10. [Roadmap](./roadmap.md):尚未完成的可靠性、运维和国际化工作。
19
+
20
+ ## 术语
21
+
22
+ | 中文 | English | 含义 |
23
+ |---|---|---|
24
+ | 记忆体 | Memory Space | 一个 Mnemon 原生命名 Store 及其独立 `mnemon.db` |
25
+ | 运行时热记忆 | Runtime Memory / hot memory | 每轮直接注入的紧凑用户画像和工作记忆 |
26
+ | 项目档案 | Project Documents | 由插件托管的完整 Markdown 项目知识 |
27
+ | 活跃档案 | Active Document | 参与默认近场检索的档案 |
28
+ | 归档 | Archive | 已建立长期索引、不计 active 容量的原文 |
29
+ | 沉淀 | Distill / supervised writeback | 经 LLM 判断、查重和路由后的持久写入 |
30
+ | 召回 | Recall | 从已激活记忆体读取历史证据 |
31
+
32
+ 品牌名、命令、工具名、配置键、RPC endpoint 和代码符号保持原样,不翻译。
33
+
34
+ ## 文档边界
35
+
36
+ - 当前用户指令和仓库事实高于历史记忆。
37
+ - `state/` 目前是预留目录;后台审查水位仍只存在于 Host 进程内。
38
+ - 主要 Web 工作台已提供中文和英文;命令输出、工具卡和部分后端诊断尚未全部国际化。
39
+ - `docs/sedimentation-research.md` 是历史研究记录,不是规范或用户手册。
@@ -0,0 +1,129 @@
1
+ # 架构设计
2
+
3
+ **简体中文** | [English](../en/architecture.md) | [文档中心](./README.md)
4
+
5
+ ## 定位
6
+
7
+ `dsh-mnemon` 是 DSH 与 Mnemon 之间的集成和监督层,不是新的数据库引擎:
8
+
9
+ - DSH 提供主 Agent、生命周期事件、subagent provider、工具、命令、设置和 Web 扩展点;
10
+ - 插件提供三层知识控制面、路由策略、事务屏障和 UI;
11
+ - 本地 `mnemon` CLI 提供命名 Store、SQLite 持久化、四类图、召回、关系和软删除。
12
+
13
+ ## 组件图
14
+
15
+ [![dsh-mnemon 运行时架构](./assets/project-architecture.svg)](./assets/project-architecture.svg)
16
+
17
+ 图中实线表示确定性数据或控制路径,紫色虚线表示 LLM 监督路径。Runtime Memory 和 Documents 直接使用受管文件;只有 Memory Spaces 通过 `MnemonRunner` 调用本地 Mnemon CLI。点击图片可以查看原始 SVG。
18
+
19
+ ## Host 组合根
20
+
21
+ `src/index.ts::apply()` 按以下顺序组装插件:
22
+
23
+ ```text
24
+ settings.register("mnemon")
25
+ -> resolveConfig
26
+ -> createRunner
27
+ -> MnemonService
28
+ -> RuntimeMemoryController
29
+ -> DocumentManager
30
+ -> StorageScopeInspector
31
+ -> MnemonSubagentCoordinator
32
+ -> MnemonLifecycle
33
+ -> tools / commands / prompt sections
34
+ -> register RPC when a Web connection exists
35
+ ```
36
+
37
+ Host 声明依赖 `tools`、`settings`、`commands`、`agents` 和 `subagents`。Web client 另外依赖 slots、connection 和 DSH locale 服务。
38
+
39
+ ## 主 Agent 与 worker 的双路径
40
+
41
+ 同名 `mnemon_*` 工具根据调用者是否为 subagent 分流,防止递归委派:
42
+
43
+ ```text
44
+ root Agent calls mnemon_recall
45
+ -> coordinator starts a bounded recall worker
46
+ -> worker calls mnemon_memory_bodies and mnemon_recall
47
+ -> tool sees origin=subagent
48
+ -> call reaches MnemonService directly
49
+ -> structured evidence returns to root Agent
50
+ ```
51
+
52
+ 长期语义写入、关系、软删除以及记忆体创建/更新/合并采用相同模式。运行时记忆和 Documents 的普通变更先经过 coordinator,但通常由确定性控制层直接提交;只有容量维护或归档需要额外 worker。
53
+
54
+ ## 两类子 Agent
55
+
56
+ ### `spawn`
57
+
58
+ `spawn` 使用新的隔离上下文。插件为每类任务提供:
59
+
60
+ - 固定 persona;
61
+ - 最小工具白名单;
62
+ - DSH 支持子集内的结构化输出 schema;
63
+ - `maxDepth: 1`;
64
+ - 可取消的 signal 和有界 token 预算。
65
+
66
+ 它用于召回、长期语义写入、证据限定问答、热记忆整理和 Document 归档。
67
+
68
+ ### `fork`
69
+
70
+ 评分后台审查必须使用名为 `fork` 且 `inheritsParentContext=true` 的 provider。它只继承已经完成的父 checkpoint,用于判断是否需要维护热记忆或最多一份项目档案。它不是用户任务的延续,也不会把审查推理注入主对话。
71
+
72
+ 当前审查白名单不包含 `mnemon_remember`、`mnemon_forget` 或记忆体维护工具,因此后台审查不会直接修改长期记忆体。
73
+
74
+ ## 控制面与数据面
75
+
76
+ ```text
77
+ LLM-owned judgment Host-owned guarantees
78
+ ------------------ ---------------------
79
+ what is worth keeping input validation
80
+ which Memory Space fits path boundary
81
+ whether two items are duplicates process timeout/cancel
82
+ how to summarize a Document file lock + atomic rename
83
+ whether a reusable artifact exists UTF-8 capacity accounting
84
+ revision conflict rejection
85
+ read/write RPC authority
86
+ ```
87
+
88
+ 必须区分“persona 约束”和“Host 硬保证”。例如 MEMORY 归档 worker 被要求覆盖每条已提交热记忆,但 Host 只能硬校验结构化 action、revision 和字节预算;USER 压缩的 source coverage 则由 Host 逐项验证。
89
+
90
+ ## Web 边界
91
+
92
+ WebUI 不启动系统进程,也不直接打开 SQLite:
93
+
94
+ ```text
95
+ browser component
96
+ -> typed client wrapper
97
+ -> DSH RPC authority check
98
+ -> Host validation
99
+ -> controller / service / bounded worker
100
+ -> local CLI or managed files
101
+ ```
102
+
103
+ 读通道要求 `trusted-host`,记忆写通道和设置通道要求 `loopback`。`writeEnabled=false` 时 Host 不注册记忆写通道。
104
+
105
+ ## 国际化
106
+
107
+ `src/client/locales.ts` 以中文键集定义 `MnemonKey`,英文词典必须满足同一键集合;`src/client/index.ts` 把两套词典注册到 DSH locale。主要 Web 页面和设置卡随 DSH 全局语言即时切换,并复用全局明暗主题。
108
+
109
+ 当前命令输出、工具卡标题、持久化的兼容默认记忆体名称和部分后端错误仍是单语,这是 Roadmap 中的已知缺口。
110
+
111
+ ## 关键模块
112
+
113
+ | 模块 | 职责 |
114
+ |---|---|
115
+ | `src/index.ts` | Host 组合与注册 |
116
+ | `src/config.ts` | 配置 schema、默认值和解析 |
117
+ | `src/process.ts` | 无 shell 的有界进程执行 |
118
+ | `src/runner.ts` | CLI 发现、参数、序列化和 JSON 解析 |
119
+ | `src/service.ts` | 长期记忆应用门面 |
120
+ | `src/memory-bodies.ts` | Memory Space 目录元数据 |
121
+ | `src/runtime-memory.ts` | 热记忆事实源与投影 |
122
+ | `src/documents.ts` | Documents 控制面 |
123
+ | `src/subagent.ts` | worker 编排与容量事务 |
124
+ | `src/lifecycle.ts` | per-root-Agent 生命周期 |
125
+ | `src/review-activity.ts` | 确定性审查评分 |
126
+ | `src/tools.ts` | 模型工具及 root/worker 分流 |
127
+ | `src/rpc.ts` | Web 读写通道 |
128
+ | `src/storage-scope.ts` | 三种存储范围的只读盘点 |
129
+ | `src/client/*` | Web 工作台、设置和 locale |
@@ -0,0 +1,182 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1600" height="1040" viewBox="0 0 1600 1040" role="img" aria-labelledby="title description" lang="zh-CN">
2
+ <title id="title">dsh-mnemon 运行时架构</title>
3
+ <desc id="description">DSH Web、主 Agent 和工具命令进入 dsh-mnemon 控制与监督层,再分别连接运行时热记忆、项目档案和 Mnemon 长期记忆体。</desc>
4
+ <style>
5
+ text { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif; fill: #172033; }
6
+ .canvas { fill: #f7f9fc; }
7
+ .section { fill: #f0f3f8; stroke: #d7deea; stroke-width: 1.5; }
8
+ .card { fill: #ffffff; stroke: #d7deea; stroke-width: 1.5; filter: url(#shadow); }
9
+ .card-hot { fill: #fff3df; stroke: #c66a09; }
10
+ .card-doc { fill: #e8f1ff; stroke: #2563be; }
11
+ .card-long { fill: #e2f7ef; stroke: #087c5b; }
12
+ .title { font-size: 34px; font-weight: 720; letter-spacing: -0.6px; }
13
+ .subtitle { font-size: 17px; fill: #647086; }
14
+ .section-title { font-size: 17px; font-weight: 700; fill: #6558d9; letter-spacing: 0.4px; }
15
+ .node-title { font-size: 21px; font-weight: 700; }
16
+ .node-copy { font-size: 15px; fill: #647086; }
17
+ .node-code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 14px; fill: #647086; }
18
+ .store-title { font-size: 23px; font-weight: 740; }
19
+ .store-copy { font-size: 15px; fill: #647086; }
20
+ .pill { fill: #f0f3f8; stroke: #d7deea; }
21
+ .pill-text { font-size: 13px; font-weight: 650; fill: #647086; }
22
+ .flow { fill: none; stroke: #aeb9ca; stroke-width: 2.5; marker-end: url(#arrow); }
23
+ .flow-hot { stroke: #c66a09; marker-end: url(#arrow-hot); }
24
+ .flow-doc { stroke: #2563be; marker-end: url(#arrow-doc); }
25
+ .flow-long { stroke: #087c5b; marker-end: url(#arrow-long); }
26
+ .flow-supervised { stroke: #6558d9; stroke-dasharray: 8 7; marker-end: url(#arrow-accent); }
27
+ .flow-label { font-size: 13px; font-weight: 650; fill: #647086; }
28
+ .legend { font-size: 13px; fill: #647086; }
29
+ .legend-line, .bus-line { marker-end: none; }
30
+ .bar-hot { fill: #c66a09; }
31
+ .bar-doc { fill: #2563be; }
32
+ .bar-long { fill: #087c5b; }
33
+ </style>
34
+ <defs>
35
+ <filter id="shadow" x="-10%" y="-20%" width="120%" height="150%">
36
+ <feDropShadow dx="0" dy="7" stdDeviation="10" flood-color="#21314d" flood-opacity="0.08"/>
37
+ </filter>
38
+ <marker id="arrow" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
39
+ <path d="M 0 0 L 10 5 L 0 10 z" fill="#aeb9ca"/>
40
+ </marker>
41
+ <marker id="arrow-hot" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
42
+ <path d="M 0 0 L 10 5 L 0 10 z" fill="#c66a09"/>
43
+ </marker>
44
+ <marker id="arrow-doc" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
45
+ <path d="M 0 0 L 10 5 L 0 10 z" fill="#2563be"/>
46
+ </marker>
47
+ <marker id="arrow-long" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
48
+ <path d="M 0 0 L 10 5 L 0 10 z" fill="#087c5b"/>
49
+ </marker>
50
+ <marker id="arrow-accent" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
51
+ <path d="M 0 0 L 10 5 L 0 10 z" fill="#6558d9"/>
52
+ </marker>
53
+ </defs>
54
+
55
+ <rect class="canvas" width="1600" height="1040" rx="24"/>
56
+ <text class="title" x="64" y="58">dsh-mnemon 运行时架构</text>
57
+ <text class="subtitle" x="64" y="87">DSH 负责监督与编排 · Mnemon 负责确定性长期存储 · 三层数据保留在本地</text>
58
+ <rect class="section" x="48" y="300" width="1504" height="394" rx="24"/>
59
+
60
+ <g aria-label="DSH 交互入口">
61
+ <rect class="card" x="64" y="124" width="430" height="126" rx="18"/>
62
+ <rect class="pill" x="88" y="146" width="96" height="27" rx="13.5"/>
63
+ <text class="pill-text" x="136" y="165" text-anchor="middle">DSH WEB</text>
64
+ <text class="node-title" x="88" y="204">记忆体工作台与插件设置</text>
65
+ <text class="node-copy" x="88" y="231">八个页面 · 中文/英文 · 全局明暗主题</text>
66
+
67
+ <rect class="card" x="585" y="124" width="430" height="126" rx="18"/>
68
+ <rect class="pill" x="609" y="146" width="112" height="27" rx="13.5"/>
69
+ <text class="pill-text" x="665" y="165" text-anchor="middle">ROOT AGENT</text>
70
+ <text class="node-title" x="609" y="204">当前任务与主上下文</text>
71
+ <text class="node-copy" x="609" y="231">当前指令和实时事实始终优先</text>
72
+
73
+ <rect class="card" x="1106" y="124" width="430" height="126" rx="18"/>
74
+ <rect class="pill" x="1130" y="146" width="142" height="27" rx="13.5"/>
75
+ <text class="pill-text" x="1201" y="165" text-anchor="middle">TOOLS · COMMANDS</text>
76
+ <text class="node-title" x="1130" y="204">模型工具与 /mnemon 命令</text>
77
+ <text class="node-copy" x="1130" y="231">显式召回、沉淀、关系、状态与维护</text>
78
+ </g>
79
+
80
+ <g aria-hidden="true">
81
+ <path class="flow" d="M279 250 V281 H1298 V350"/>
82
+ <path class="flow flow-supervised" d="M800 250 V350"/>
83
+ <path class="flow" d="M1321 250 V292 H800 V350"/>
84
+ <text class="flow-label" x="1042" y="276">typed RPC</text>
85
+ <text class="flow-label" x="815" y="302">工具调用</text>
86
+ </g>
87
+
88
+ <text class="section-title" x="80" y="337">DSH HOST · DSH-MNEMON 控制与监督层</text>
89
+
90
+ <g aria-hidden="true">
91
+ <path class="flow bus-line" d="M300 476 V498"/>
92
+ <path class="flow flow-supervised bus-line" d="M800 476 V498"/>
93
+ <path class="flow bus-line" d="M1300 476 V498"/>
94
+ <path class="flow bus-line" d="M245 498 H1300"/>
95
+ <path class="flow" d="M245 498 V520"/>
96
+ <path class="flow" d="M615 498 V520"/>
97
+ <path class="flow" d="M985 498 V520"/>
98
+ <path class="flow" d="M990 630 H1190"/>
99
+ </g>
100
+
101
+ <g aria-label="监督与权限组件">
102
+ <rect class="card" x="100" y="350" width="400" height="126" rx="17"/>
103
+ <text class="node-title" x="126" y="390">Prompt 与 Lifecycle</text>
104
+ <text class="node-copy" x="126" y="420">热记忆注入 · 短提示 · 活动评分</text>
105
+ <text class="node-code" x="126" y="448">pre-step · turn/end · idle review</text>
106
+
107
+ <rect class="card" x="600" y="350" width="400" height="126" rx="17"/>
108
+ <text class="node-title" x="626" y="390">Subagent Coordinator</text>
109
+ <text class="node-copy" x="626" y="420">spawn 隔离任务 · fork 已完成 checkpoint</text>
110
+ <text class="node-code" x="626" y="448">persona · allowlist · schema · depth=1</text>
111
+
112
+ <rect class="card" x="1100" y="350" width="400" height="126" rx="17"/>
113
+ <text class="node-title" x="1126" y="390">RPC 与权限边界</text>
114
+ <text class="node-copy" x="1126" y="420">trusted-host 读取 · loopback 写入</text>
115
+ <text class="node-code" x="1126" y="448">read · write · settings channels</text>
116
+ </g>
117
+
118
+ <g aria-label="确定性控制组件">
119
+ <rect class="card" x="80" y="520" width="330" height="110" rx="16"/>
120
+ <text class="node-title" x="104" y="559">Runtime Memory</text>
121
+ <text class="node-copy" x="104" y="587">JSON 事实源 · Markdown 投影</text>
122
+ <text class="node-code" x="104" y="612">lock · revision · UTF-8</text>
123
+
124
+ <rect class="card" x="450" y="520" width="330" height="110" rx="16"/>
125
+ <text class="node-title" x="474" y="559">Documents</text>
126
+ <text class="node-copy" x="474" y="587">索引 · 检索 · active / archived</text>
127
+ <text class="node-code" x="474" y="612">path boundary · LRU · SHA-256</text>
128
+
129
+ <rect class="card" x="820" y="520" width="330" height="110" rx="16"/>
130
+ <text class="node-title" x="844" y="559">Mnemon Service</text>
131
+ <text class="node-copy" x="844" y="587">记忆体路由 · 召回 · 关系 · 图谱</text>
132
+ <text class="node-code" x="844" y="612">active read · targeted write</text>
133
+
134
+ <rect class="card" x="1190" y="520" width="280" height="110" rx="16"/>
135
+ <text class="node-title" x="1214" y="559">CLI Runner</text>
136
+ <text class="node-copy" x="1214" y="587">参数数组 · 禁用 shell</text>
137
+ <text class="node-code" x="1214" y="612">serialized · timeout</text>
138
+ </g>
139
+
140
+ <g aria-hidden="true">
141
+ <path class="flow flow-hot" d="M245 630 V760"/>
142
+ <path class="flow flow-doc" d="M615 630 V724 H800 V760"/>
143
+ <path class="flow flow-long" d="M1330 630 V724 H1310 V760"/>
144
+ <text class="flow-label" x="262" y="718">每轮投影</text>
145
+ <text class="flow-label" x="632" y="714">受管 Markdown</text>
146
+ <text class="flow-label" x="1344" y="713">本地 CLI</text>
147
+ </g>
148
+
149
+ <g aria-label="三层本地存储">
150
+ <rect class="card card-hot" x="64" y="760" width="440" height="194" rx="20"/>
151
+ <rect class="bar-hot" x="88" y="784" width="9" height="48" rx="4.5"/>
152
+ <text class="store-title" x="116" y="809">运行时热记忆</text>
153
+ <text class="node-code" x="116" y="834">&lt;storageRoot&gt;/runtime</text>
154
+ <text class="store-copy" x="88" y="870">memories.json 是唯一事实源</text>
155
+ <text class="store-copy" x="88" y="898">USER.md 4 KiB · MEMORY.md 10 KiB</text>
156
+ <text class="store-copy" x="88" y="926">紧凑内容每轮直接进入主上下文</text>
157
+
158
+ <rect class="card card-doc" x="580" y="760" width="440" height="194" rx="20"/>
159
+ <rect class="bar-doc" x="604" y="784" width="9" height="48" rx="4.5"/>
160
+ <text class="store-title" x="632" y="809">项目档案</text>
161
+ <text class="node-code" x="632" y="834">&lt;storageRoot&gt;/documents</text>
162
+ <text class="store-copy" x="604" y="870">index.json · active/ · archived/</text>
163
+ <text class="store-copy" x="604" y="898">保留完整 Markdown 叙事与来源</text>
164
+ <text class="store-copy" x="604" y="926">先建立冷引用,再迁移原文</text>
165
+
166
+ <rect class="card card-long" x="1096" y="760" width="440" height="194" rx="20"/>
167
+ <rect class="bar-long" x="1120" y="784" width="9" height="48" rx="4.5"/>
168
+ <text class="store-title" x="1148" y="809">Mnemon 记忆体</text>
169
+ <text class="node-code" x="1148" y="834">&lt;storageRoot&gt;/data/&lt;space-id&gt;/mnemon.db</text>
170
+ <text class="store-copy" x="1120" y="870">独立 SQLite Store · active 读取边界</text>
171
+ <text class="store-copy" x="1120" y="898">temporal · semantic · causal · entity</text>
172
+ <text class="store-copy" x="1120" y="926">跨会话、按需、带来源的长期证据</text>
173
+ </g>
174
+
175
+ <g aria-label="图例">
176
+ <line x1="70" y1="996" x2="112" y2="996" class="flow legend-line"/>
177
+ <text class="legend" x="124" y="1001">确定性数据 / 控制路径</text>
178
+ <line x1="346" y1="996" x2="388" y2="996" class="flow flow-supervised legend-line"/>
179
+ <text class="legend" x="400" y="1001">LLM 监督路径</text>
180
+ <text class="legend" x="1532" y="1001" text-anchor="end">所有持久数据位于选定 storageRoot</text>
181
+ </g>
182
+ </svg>