@modusensus/dsh-mneme 0.1.6 → 0.2.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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Modusensus
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Modusensus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,207 +1,239 @@
1
- # dsh-mneme
2
-
3
- [![npm version](https://img.shields.io/npm/v/@modusensus/dsh-mneme?color=blue&label=npm)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
4
- [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
5
- [![dsh-plugin](https://img.shields.io/badge/dsh-plugin-awesome-orange)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
6
- [![tests](https://img.shields.io/badge/tests-136%20passed-success)](https://github.com/modusensus/dsh-mneme)
7
-
8
- > 给 DeepSeek Harness 的跨会话记忆插件:让 Agent 记住你、记住项目、自动整理记忆。**Mneme**(Μνήμη)——希腊记忆女神 Mnemosyne 之名,掌管记忆与梦境,正如 autoDream 在后台巩固记忆。
9
-
10
- `dsh-mneme` 是一个 [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/deepseek-harness) 插件,为 Agent 提供持久的跨会话记忆能力。它借鉴了 Claude **Dream 机制** 与 cc-haha / Claude Code 的 **autoDream** 实现思路——不仅**存储**记忆,还会**自动巩固**(去重、合并、冲突裁决、摘要生成),让记忆库越用越精炼。
11
-
12
- ## 功能
13
-
14
- ### 记忆存储(SQLite + Markdown 镜像)
15
-
16
- - **SQLite 主存储**:`~/.dsh/memory/memory.db`,`node:sqlite` 内置,零原生依赖
17
- - **Markdown 镜像**:`preferences.md` / `projects.md` / `decisions.md` / `history.md` / `summary.md`,人类可读、可手工编辑(**人工修改优先**合并回库)
18
- - **4+1 种记忆类型**:`preference`(偏好)/ `project`(项目)/ `decision`(决策)/ `history`(历史)/ `summary`(总览)
19
-
20
- ### 模型工具(6 个)
21
-
22
- | 工具 | 功能 |
23
- |------|------|
24
- | `memory_save` | 记录一条记忆(自动按标题去重合并) |
25
- | `memory_search` | 全文搜索(中文子串友好,可启用向量语义搜索) |
26
- | `memory_list` | 按类型分页列出 |
27
- | `memory_update` | 修改已有记忆 |
28
- | `memory_delete` | 删除记忆 |
29
- | `memory_forget` | 抑制注入(降权不删除,可恢复) |
30
-
31
- ### 自动注入 + 会话摘要
32
-
33
- - **自动注入**:新会话开局注入记忆摘要(`summary` 优先 + 少量高重要性条目)
34
- - **会话摘要**:`turn/end` 时用 LLM 提炼本次会话的偏好/决策/教训,自动入库(过滤 plugin 注入上下文,避免污染)
35
-
36
- ### autoDream 自动记忆整理 🧠
37
-
38
- - **触发**:记忆数 > 10 或总字符 > 5000 时,异步自动触发(不阻塞写入)
39
- - **决策清单式整理**:LLM 输出 `keep` / `merge` / `archive` / `conflict` 决策清单,服务端校验后逐条应用
40
- - `merge`:合并主题相近的条目,保留信息最完整者
41
- - `archive`:归档过时/冗余条目(可恢复,不物理删除)
42
- - `conflict`:裁决矛盾信息,胜者保留、败者归档并追加溯源注释
43
- - **摘要生成**:整理后生成"记忆库总览"(单一实例),作为下次会话的优先注入
44
- - **Fail-safe**:非法 LLM 输出(未知 id / 非法 action / 跨类型合并 / 越界 importance)拒绝整单,绝不破坏记忆库
45
-
46
- ### Web 记忆面板
47
-
48
- 官方设置面板 → 「记忆库设置」→「记忆」标签:按类型浏览、全文搜索;启用向量搜索后可用「语义」切换做向量召回。
49
-
50
- ### 用户设置(画像 / 规则)与自定义指令 ⚙️
51
-
52
- 官方设置面板 → 「记忆库设置」标签:
53
-
54
- - **用户画像**:一段自由文本描述用户自己(角色、背景、偏好),**每轮注入**到系统提示,让 Agent 始终遵循
55
- - **规则**:Agent 必须遵守的行为规则列表(如"回答先给结论"),同样每轮注入
56
- - **自定义指令**:注册斜杠命令(`/名称`),触发时把用户定义的指令内容交给 Agent。命令持久化到 SQLite,启动时自动注册到 DSH 命令表,增删实时生效
57
-
58
- > 画像与规则通过独立的 `[用户设置]` 注入区块(优先级高于记忆库),即使记忆为空也会注入。
59
-
60
- ### 向量搜索(语义搜索)🔎
61
-
62
- 可选能力:接入 OpenAI 兼容的 embeddings API,让搜索能命中**字面不同但语义相近**的记忆。
63
-
64
- **配置**:官方设置 → 「记忆库设置」→ 滚动到底部「向量搜索」区块:
65
-
66
- | 字段 | 说明 |
67
- |------|------|
68
- | `启用向量搜索` | 总开关;开启后记忆面板出现「语义」切换 |
69
- | `API 地址 (Base URL)` | OpenAI 兼容端点,如 `https://api.openai.com/v1`;也支持 SiliconFlow、智谱、本地 Ollama 等 |
70
- | `API Key` | 对应服务的密钥 |
71
- | `模型名` | embedding 模型,如 `text-embedding-3-small`、`text-embedding-v3`、`bge-m3` 等 |
72
-
73
- 保存配置后点「重建索引」,为已有记忆批量补建向量(新写入的记忆会自动嵌入)。之后在记忆面板输入查询并点「语义」,即可用向量召回语义相关结果;向量服务不可用时自动回退全文搜索。
74
-
75
- > ⚠️ 密钥仅保存在本机 `~/.dsh/memory/memory.db` 的 `user_settings` 表,不会上传,也不会写入代码仓库。
76
- > 需要 embedding 而非 rerank 模型:如阿里云 `text-embedding-v3` 可用,`qwen3-vl-rerank` 是 rerank 模型(不走 `/embeddings`)。
77
-
78
- ## 📦 安装
79
-
80
- ### 前置条件
81
-
82
- - [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)
83
- - Node 24+(`node:sqlite`)
84
-
85
- ### 安装步骤
86
-
87
- #### 方式一:npm 安装(推荐)
88
-
89
- dsh-mneme 是一个 **bundle**(声明了 `dsh.bundle` manifest),安装即自动激活,无需手动写配置:
90
-
91
- ```bash
92
- # 1. 安装插件(自动注册 bundle 层)
93
- dsh plugin --profile web add @modusensus/dsh-mneme
94
-
95
- # 2. 重启
96
- dsh web
97
- ```
98
-
99
- > 如需自定义配置(阈值、延迟等),可在 `~/.dsh/profiles/web/cordis.patch.yml` 中按 `id: dsh-mneme` 覆盖默认值(见下方配置表)。
100
-
101
- #### 方式二:从源码安装
102
-
103
- ```bash
104
- git clone https://github.com/modusensus/dsh-mneme.git
105
- cd dsh-mneme
106
- dsh plugin --profile web add .
107
- dsh web
108
- ```
109
-
110
- #### 自定义配置(可选)
111
-
112
- 默认配置即可用。如需调整,在 `~/.dsh/profiles/web/cordis.patch.yml` 中覆盖:
113
-
114
- ```yaml
115
- - id: dsh-mneme
116
- name: '@modusensus/dsh-mneme'
117
- config:
118
- memoryDir: ~/.dsh/memory
119
- autoInject: true
120
- autoSummarize: true
121
- maxInjectedItems: 5
122
- importanceThreshold: 3
123
- autoDream: true
124
- dreamThresholdCount: 10
125
- dreamThresholdChars: 5000
126
- dreamDelayMs: 2000
127
- ```
128
-
129
- ## ⚙️ 配置
130
-
131
- | | 默认值 | 说明 |
132
- |----|--------|------|
133
- | `memoryDir` | `~/.dsh/memory` | 记忆存储目录(SQLite + Markdown) |
134
- | `autoInject` | `true` | 会话启动自动注入记忆 |
135
- | `autoSummarize` | `true` | 会话结束自动提炼摘要 |
136
- | `maxInjectedItems` | `5` | 最多注入几条记忆 |
137
- | `importanceThreshold` | `3` | 注入的最低重要性(1-5) |
138
- | `autoDream` | `true` | 自动记忆整理开关 |
139
- | `dreamThresholdCount` | `10` | 触发整理的记忆条数阈值 |
140
- | `dreamThresholdChars` | `5000` | 触发整理的总字符阈值 |
141
- | `dreamDelayMs` | `2000` | 整理异步延迟(去抖) |
142
- | `dreamProvider` / `dreamModel` | 空 | dream 的 LLM 路由回退(默认用 agent 默认模型) |
143
-
144
- ## 🏗️ 架构
145
-
146
- ```
147
- ┌─────────────────────────────────────────────────┐
148
- │ 存储层:SQLite (archived/forgotten 状态) │
149
- + Markdown 镜像(人工可编辑,双向同步) │
150
- ├─────────────────────────────────────────────────┤
151
- │ 服务层:saveWithDedupe / injectCandidates │
152
- │ / mergeHumanEdits / onWrite 钩子 │
153
- ├─────────────────────────────────────────────────┤
154
- │ 模型接口:6 个工具 + 自动注入 + 会话摘要 │
155
- ├─────────────────────────────────────────────────┤
156
- │ autoDream:阈值调度 LLM 决策清单 │
157
- │ → 校验(fail-safe)→ 应用 摘要 │
158
- ├─────────────────────────────────────────────────┤
159
- │ Web 面板:设置面板内嵌 + 浏览/搜索(含向量) │
160
- └─────────────────────────────────────────────────┘
161
- ```
162
-
163
- **源码结构**:
164
-
165
- ```
166
- src/
167
- ├── store.js # SQLite 存储(CRUD、搜索、归档/遗忘、schema 迁移)
168
- ├── mirror.js # Markdown 镜像(渲染/解析,人工优先)
169
- ├── service.js # 领域逻辑(去重合并、注入筛选、写入钩子)
170
- ├── config.js # schemastery 配置 schema
171
- ├── tools.js # 6 个模型工具(defineTool)
172
- ├── inject.js # systemPrompt.context 动态注入
173
- ├── summarize.js # 会话结束 LLM 摘要
174
- ├── dream.js # autoDream 调度 + runDream(LLM 决策 + 摘要)
175
- ├── dream/decisions.js# 决策校验(fail-safe)+ 决策应用
176
- ├── embedding.js # OpenAI 兼容 embeddings 客户端 + 向量检索
177
- ├── api.js # HTTP 路由(Web 面板数据通道)
178
- └── index.js # 插件接线
179
- lib/
180
- ├── client.js # Web 面板(手写 ModuleLoader bundle)
181
- └── *.js # src 的同步分发产物
182
- test/ # 136 node:test 测试
183
- ```
184
-
185
- ## 🧪 开发
186
-
187
- ```bash
188
- cd dsh-mneme
189
- npm install # 安装 peer 依赖(以 devDependencies 形式,用于本地测试)
190
- npm test # 运行 136 个测试(--test-isolation=none 用于受限沙箱,禁止子进程 spawn)
191
- npm run sync # 把 src/ 同步到 lib/(发布时由 prepack 钩子自动执行)
192
- ```
193
-
194
- > 注:`npm test` 使用 `--test-isolation=none` 适配受限沙箱;普通环境可直接 `node --test`。
195
- > `lib/` 是 `src/` 的同步分发产物(`npm run sync`),其中 `lib/client.js` 为手写 Web 面板源码,不受同步影响。
196
-
197
- ## 📄 设计文档
198
-
199
- > 设计文档位于仓库根 `docs/`,链接以 `../docs/` 相对路径指向(GitHub 上从本目录打开可正常跳转)。
200
-
201
- - [记忆库设计](../docs/superpowers/specs/2026-08-13-dsh-memory-design.md)
202
- - [autoDream 设计](../docs/superpowers/specs/2026-08-13-dsh-memory-autodream-design.md)
203
- - [实施计划](../docs/superpowers/plans/2026-08-13-dsh-memory-autodream.md)
204
-
205
- ## 📜 License
206
-
207
- MIT
1
+ <p align="center"><strong>中文 | <a href="docs/SEMANTIC.md">English(语义增强)</a></strong></p>
2
+
3
+ # dsh-mneme
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@modusensus/dsh-mneme?color=blue&label=npm)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
6
+ [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
7
+ [![Awesome](https://awesome-dsh-plugin.com/badge.svg)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
8
+ [![tests](https://img.shields.io/badge/tests-198%20passed-success)](https://github.com/modusensus/dsh-mneme)
9
+
10
+ > DeepSeek Harness 的跨会话记忆插件:让 Agent 记住你、记住项目、自动整理记忆。**Mneme**(Μνήμη)——希腊记忆女神 Mnemosyne 之名,掌管记忆与梦境,正如 autoDream 在后台巩固记忆。
11
+
12
+ `dsh-mneme` 是一个 [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/deepseek-harness) 插件,为 Agent 提供持久的跨会话记忆能力。它借鉴了 Claude 的 **Dream 机制** 与 cc-haha / Claude Code 的 **autoDream** 实现思路——不仅**存储**记忆,还会**自动巩固**(去重、合并、冲突裁决、摘要生成),让记忆库越用越精炼。
13
+
14
+ ## 功能
15
+
16
+ ### 记忆存储(SQLite + Markdown 镜像)
17
+
18
+ - **SQLite 主存储**:`~/.dsh/memory/memory.db`,`node:sqlite` 内置,零原生依赖
19
+ - **Markdown 镜像**:`preferences.md` / `projects.md` / `decisions.md` / `history.md` / `summary.md`,人类可读、可手工编辑(**人工修改优先**合并回库)
20
+ - **4+1 种记忆类型**:`preference`(偏好)/ `project`(项目)/ `decision`(决策)/ `history`(历史)/ `summary`(总览)
21
+
22
+ ### 模型工具(6 个)
23
+
24
+ | 工具 | 功能 |
25
+ |------|------|
26
+ | `memory_save` | 记录一条记忆(自动按标题去重合并) |
27
+ | `memory_search` | 全文搜索(中文子串友好,可启用向量语义搜索) |
28
+ | `memory_list` | 按类型分页列出 |
29
+ | `memory_update` | 修改已有记忆 |
30
+ | `memory_delete` | 删除记忆 |
31
+ | `memory_forget` | 抑制注入(降权不删除,可恢复) |
32
+
33
+ ### 自动注入 + 会话摘要
34
+
35
+ - **自动注入**:新会话开局注入记忆摘要(`summary` 优先 + 少量高重要性条目)
36
+ - **会话摘要**:`turn/end` 时用 LLM 提炼本次会话的偏好/决策/教训,自动入库(过滤 plugin 注入上下文,避免污染)
37
+
38
+ ### autoDream 自动记忆整理 🧠
39
+
40
+ - **触发**:记忆数 > 10 或总字符 > 5000 时,异步自动触发(不阻塞写入)
41
+ - **决策清单式整理**:LLM 输出 `keep` / `merge` / `archive` / `conflict` 决策清单,服务端校验后逐条应用
42
+ - `merge`:合并主题相近的条目,保留信息最完整者
43
+ - `archive`:归档过时/冗余条目(可恢复,不物理删除)
44
+ - `conflict`:裁决矛盾信息,胜者保留、败者归档并追加溯源注释
45
+ - **摘要生成**:整理后生成"记忆库总览"(单一实例),作为下次会话的优先注入
46
+ - **Fail-safe**:非法 LLM 输出(未知 id / 非法 action / 跨类型合并 / 越界 importance)拒绝整单,绝不破坏记忆库
47
+ - **裁决审计**:每次运行写入 `dream_runs` 审计表(输入快照 sha256 digest + 完整输入快照 + 决策清单 + 逐 id 去向 + receipt),可离线回放;merge / conflict 幂等应用,重放/并发重复执行无累积副作用
48
+
49
+ ### Web 记忆面板
50
+
51
+ 官方设置面板 → 「记忆库设置」→「记忆」标签:按类型浏览、全文搜索;启用向量搜索后可用「语义」切换做向量召回。
52
+
53
+ ### 用户设置(画像 / 规则)与自定义指令 ⚙️
54
+
55
+ 官方设置面板 「记忆库设置」标签:
56
+
57
+ - **用户画像**:一段自由文本描述用户自己(角色、背景、偏好),**每轮注入**到系统提示,让 Agent 始终遵循
58
+ - **规则**:Agent 必须遵守的行为规则列表(如"回答先给结论"),同样每轮注入
59
+ - **自定义指令**:注册斜杠命令(`/名称`),触发时把用户定义的指令内容交给 Agent。命令持久化到 SQLite,启动时自动注册到 DSH 命令表,增删实时生效
60
+
61
+ > 画像与规则通过独立的 `[用户设置]` 注入区块(优先级高于记忆库),即使记忆为空也会注入。
62
+
63
+ ### 向量搜索(语义搜索)🔎
64
+
65
+ 可选能力:接入 OpenAI 兼容的 embeddings API,让搜索能命中**字面不同但语义相近**的记忆。
66
+
67
+ **配置**:官方设置 → 「记忆库设置」→ 滚动到底部「向量搜索」区块:
68
+
69
+ | 字段 | 说明 |
70
+ |------|------|
71
+ | `启用向量搜索` | 总开关;开启后记忆面板出现「语义」切换 |
72
+ | `API 地址 (Base URL)` | OpenAI 兼容端点,如 `https://api.openai.com/v1`;也支持 SiliconFlow、智谱、本地 Ollama 等 |
73
+ | `API Key` | 对应服务的密钥 |
74
+ | `模型名` | embedding 模型,如 `text-embedding-3-small`、`text-embedding-v3`、`bge-m3` 等 |
75
+
76
+ 保存配置后点「重建索引」,为已有记忆批量补建向量(新写入的记忆会自动嵌入)。之后在记忆面板输入查询并点「语义」,即可用向量召回语义相关结果;向量服务不可用时自动回退全文搜索。
77
+
78
+ > ⚠️ 密钥仅保存在本机 `~/.dsh/memory/memory.db` 的 `user_settings` 表,不会上传,也不会写入代码仓库。
79
+ > 需要 embedding 而非 rerank 模型:如阿里云 `text-embedding-v3` 可用,`qwen3-vl-rerank` 是 rerank 模型(不走 `/embeddings`)。
80
+
81
+ ### 语义增强(Semantic)🧠
82
+
83
+ v0.2 起新增**完全离线的语义记忆引擎**(本地模型 + 精排 + 聚类):
84
+
85
+ - **本地 Embedding**:三后端可选——ONNX(`Xenova/bge-small-zh-v1.5`,离线)/ Ollama / OpenAI 兼容,失败自动逐级降级,最差回退关键词搜索
86
+ - **Rerank 精排**:`Xenova/bge-reranker-base` 对召回候选交叉编码精排,提升 Top-K 准确率
87
+ - **autoDream 语义增强**:对记忆向量聚类(`clusterMemories`),自动发现主题相近 / 疑似矛盾的记忆,巩固更精准
88
+ - **搜索流水线**:混合召回(关键词 + 向量)→ Rerank → Top-K
89
+
90
+ 配置只需在 `cordis.patch.yml` 里设置 `embedProvider`(默认 `openai`,保持 v0.1 行为;改为 `local` 即离线)。升级无需迁移数据。
91
+
92
+ > 📖 详见 [语义增强架构](docs/SEMANTIC.md) · [本地模型部署指南](docs/LOCAL_MODEL.md) · [从 v0.1 升级说明](docs/MIGRATION.md)
93
+
94
+ ## 📦 安装
95
+
96
+ ### 前置条件
97
+
98
+ - [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)
99
+ - Node 24+(`node:sqlite`)
100
+
101
+ ### 安装步骤
102
+
103
+ #### 方式一:npm 安装(推荐)
104
+
105
+ dsh-mneme 是一个 **bundle**(声明了 `dsh.bundle` manifest),安装即自动激活,无需手动写配置:
106
+
107
+ ```bash
108
+ # 1. 安装插件(自动注册 bundle 层)
109
+ dsh plugin --profile web add @modusensus/dsh-mneme
110
+
111
+ # 2. 重启
112
+ dsh web
113
+ ```
114
+
115
+ > 如需自定义配置(阈值、延迟等),可在 `~/.dsh/profiles/web/cordis.patch.yml` 中按 `id: dsh-mneme` 覆盖默认值(见下方配置表)。
116
+
117
+ #### 方式二:从源码安装
118
+
119
+ ```bash
120
+ git clone https://github.com/modusensus/dsh-mneme.git
121
+ cd dsh-mneme
122
+ dsh plugin --profile web add .
123
+ dsh web
124
+ ```
125
+
126
+ #### 自定义配置(可选)
127
+
128
+ 默认配置即可用。如需调整,在 `~/.dsh/profiles/web/cordis.patch.yml` 中覆盖:
129
+
130
+ ```yaml
131
+ - id: dsh-mneme
132
+ name: '@modusensus/dsh-mneme'
133
+ config:
134
+ memoryDir: ~/.dsh/memory
135
+ autoInject: true
136
+ autoSummarize: true
137
+ maxInjectedItems: 5
138
+ importanceThreshold: 3
139
+ autoDream: true
140
+ dreamThresholdCount: 10
141
+ dreamThresholdChars: 5000
142
+ dreamDelayMs: 2000
143
+ ```
144
+
145
+ ## ⚙️ 配置
146
+
147
+ | 键 | 默认值 | 说明 |
148
+ |----|--------|------|
149
+ | `memoryDir` | `~/.dsh/memory` | 记忆存储目录(SQLite + Markdown |
150
+ | `autoInject` | `true` | 会话启动自动注入记忆 |
151
+ | `autoSummarize` | `true` | 会话结束自动提炼摘要 |
152
+ | `maxInjectedItems` | `5` | 最多注入几条记忆 |
153
+ | `importanceThreshold` | `3` | 注入的最低重要性(1-5) |
154
+ | `autoDream` | `true` | 自动记忆整理开关 |
155
+ | `dreamThresholdCount` | `10` | 触发整理的记忆条数阈值 |
156
+ | `dreamThresholdChars` | `5000` | 触发整理的总字符阈值 |
157
+ | `dreamDelayMs` | `2000` | 整理异步延迟(去抖) |
158
+ | `dreamProvider` / `dreamModel` | 空 | dream 的 LLM 路由回退(默认用 agent 默认模型) |
159
+ | `embedProvider` | `openai` | 语义后端:`openai`(默认,兼容 v0.1)/ `local`(ONNX 离线)/ `ollama` |
160
+ | `localEmbedModel` | `Xenova/bge-small-zh-v1.5` | 本地 ONNX embedding 模型 |
161
+ | `localEmbedDimension` | `512` | 本地 embedding 向量维度 |
162
+ | `localEmbedBatchSize` | `8` | 本地 embedding 批大小(1-64) |
163
+ | `ollamaBaseUrl` | `http://localhost:11434` | Ollama 服务地址 |
164
+ | `ollamaModel` | `nomic-embed-text` | Ollama embedding 模型 |
165
+ | `rerankEnabled` | `true` | 是否启用 Rerank 精排 |
166
+ | `rerankModel` | `Xenova/bge-reranker-base` | Rerank 交叉编码模型 |
167
+ | `rerankScoreThreshold` | `0.1` | Rerank 分数阈值(低于丢弃) |
168
+
169
+ ## 🏗️ 架构
170
+
171
+ ```
172
+ ┌─────────────────────────────────────────────────┐
173
+ │ 存储层:SQLite (archived/forgotten 状态) │
174
+ + Markdown 镜像(人工可编辑,双向同步) │
175
+ ├─────────────────────────────────────────────────┤
176
+ │ 服务层:saveWithDedupe / injectCandidates │
177
+ │ / mergeHumanEdits / onWrite 钩子 │
178
+ ├─────────────────────────────────────────────────┤
179
+ │ 模型接口:6 个工具 + 自动注入 + 会话摘要 │
180
+ ├─────────────────────────────────────────────────┤
181
+ │ autoDream:阈值调度 LLM 决策清单 │
182
+ │ → 校验(fail-safe)→ 应用 摘要 │
183
+ ├─────────────────────────────────────────────────┤
184
+ │ Web 面板:设置面板内嵌 + 浏览/搜索(含向量) │
185
+ └─────────────────────────────────────────────────┘
186
+ ```
187
+
188
+ **源码结构**:
189
+
190
+ ```
191
+ src/
192
+ ├── store.js # SQLite 存储(CRUD、搜索、归档/遗忘、schema 迁移)
193
+ ├── mirror.js # Markdown 镜像(渲染/解析,人工优先)
194
+ ├── service.js # 领域逻辑(去重合并、注入筛选、写入钩子)
195
+ ├── config.js # schemastery 配置 schema
196
+ ├── tools.js # 6 个模型工具(defineTool)
197
+ ├── inject.js # systemPrompt.context 动态注入
198
+ ├── summarize.js # 会话结束 LLM 摘要
199
+ ├── dream.js # autoDream 调度 + runDream(LLM 决策 + 摘要)
200
+ ├── dream/decisions.js# 决策校验(fail-safe)+ 决策应用
201
+ ├── embedding.js # OpenAI 兼容 embeddings 客户端 + 向量检索
202
+ ├── api.js # HTTP 路由(Web 面板数据通道)
203
+ └── index.js # 插件接线
204
+ lib/
205
+ ├── client.js # Web 面板(手写 ModuleLoader bundle)
206
+ └── *.js # src 的同步分发产物
207
+ test/ # 198 个 node:test 测试(含审计与三轴线压测不变量)
208
+ scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压测 · sync-lib.js 同步
209
+ ```
210
+
211
+ ## 🧪 开发
212
+
213
+ ```bash
214
+ cd dsh-mneme
215
+ npm install # 安装 peer 依赖(以 devDependencies 形式,用于本地测试)
216
+ npm test # 运行 198 个测试
217
+ npm run stress # 三轴线压测:长会话检索 / 冲突仲裁 / 多 Agent 并发(离线 mock LLM)
218
+ npm run sync # 把 src/ 同步到 lib/(发布时由 prepack 钩子自动执行)
219
+ ```
220
+
221
+ > 压测(`npm run stress`)三条轴线:**长会话检索**(Recall@k、陈旧残留率)、**冲突裁决**(可重放仲裁集:审计快照 hash + receipt + 幂等回放)、**多 Agent 并发**(丢更新、重复合并、事务/崩溃恢复)。每次 autoDream 运行都会写入审计表 `dream_runs`(输入快照 digest + 决策清单 + 逐 id 去向 + receipt),让高通过率下也能定位静默错误。
222
+
223
+ > 注:`npm test` 使用 `--test-isolation=none` 适配受限沙箱;普通环境可直接 `node --test`。
224
+ > `lib/` 是 `src/` 的同步分发产物(`npm run sync`),其中 `lib/client.js` 为手写 Web 面板源码,不受同步影响。
225
+
226
+ ## 📄 设计文档
227
+
228
+ > 设计文档位于仓库根 `docs/`,链接以 `../docs/` 相对路径指向(GitHub 上从本目录打开可正常跳转)。
229
+
230
+ - [记忆库设计](../docs/superpowers/specs/2026-08-13-dsh-mneme-design.md)
231
+ - [autoDream 设计](../docs/superpowers/specs/2026-08-13-dsh-mneme-autodream-design.md)
232
+ - [实施计划](../docs/superpowers/plans/2026-08-13-dsh-memory-autodream.md)
233
+ - [语义增强架构](docs/SEMANTIC.md)
234
+ - [本地模型部署指南](docs/LOCAL_MODEL.md)
235
+ - [从 v0.1 升级说明](docs/MIGRATION.md)
236
+
237
+ ## 📜 License
238
+
239
+ MIT
package/cordis.patch.yml CHANGED
@@ -1,15 +1,15 @@
1
- # dsh-mneme bundle patch — the layer applied when a profile lists this bundle.
2
- # Installed via: dsh plugin --profile <name> add @modusensus/dsh-mneme
3
- - insert:
4
- - id: dsh-mneme
5
- name: '@modusensus/dsh-mneme'
6
- config:
7
- memoryDir: ~/.dsh/memory
8
- autoInject: true
9
- autoSummarize: true
10
- maxInjectedItems: 5
11
- importanceThreshold: 3
12
- autoDream: true
13
- dreamThresholdCount: 10
14
- dreamThresholdChars: 5000
15
- dreamDelayMs: 2000
1
+ # dsh-mneme bundle patch — the layer applied when a profile lists this bundle.
2
+ # Installed via: dsh plugin --profile <name> add @modusensus/dsh-mneme
3
+ - insert:
4
+ - id: dsh-mneme
5
+ name: '@modusensus/dsh-mneme'
6
+ config:
7
+ memoryDir: ~/.dsh/memory
8
+ autoInject: true
9
+ autoSummarize: true
10
+ maxInjectedItems: 5
11
+ importanceThreshold: 3
12
+ autoDream: true
13
+ dreamThresholdCount: 10
14
+ dreamThresholdChars: 5000
15
+ dreamDelayMs: 2000