dsh-lm-memory 0.18.0-rc.2 → 0.18.1

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/README.md CHANGED
@@ -156,9 +156,9 @@ claude mcp add lm_memory -s user -- node /path/to/lm-memory/server/memory-server
156
156
 
157
157
  ### DSH
158
158
 
159
- 测试候选版 `0.18.0-rc.2` 已发布到 GitHub Release,尚未发布到 npm。先核对 DSH 版本满足 `>=0.2.2-rc.3 <0.3.0`;在隔离环境打开 **插件 → 添加插件**,输入 `file:` 加下载到的 `dsh-lm-memory-0.18.0-rc.2.tgz` 绝对路径(Windows 例:`file:C:/LM-Test/dsh-lm-memory-0.18.0-rc.2.tgz`),按宿主提示重启。包只包含插件;安装依赖可能需要联网,且插件仍需要独立 Node.js ≥22.16。不要因此同意不明构建脚本或版本兼容豁免。
159
+ 正式版 `0.18.1`(GitHub Release 附安装包;npm 同名版本同步发布)。先核对 DSH 版本满足 `>=0.2.2-rc.3 <0.3.0`;在隔离环境打开 **插件 → 添加插件**,输入 `file:` 加下载到的 `dsh-lm-memory-0.18.1.tgz` 绝对路径(Windows 例:`file:C:/LM-Test/dsh-lm-memory-0.18.1.tgz`),按宿主提示重启。包只包含插件;安装依赖可能需要联网,且插件仍需要独立 Node.js ≥22.16。不要因此同意不明构建脚本或版本兼容豁免。
160
160
 
161
- rc.2 的默认行为与 rc.1 相同。新增的按 Git 仓库隔离的项目记忆、用户确认结论/修复经验、事实有效日期,全部是显式开启的候选功能,默认关闭,说明与限制见 `docs/project-memory.md`。
161
+ 0.18.1 的默认行为与 0.17.3 相同:按 Git 仓库隔离的项目记忆、用户确认结论/修复经验、事实有效日期、任务候选提示,全部需要显式开启,默认关闭,说明与限制见 `docs/project-memory.md`。
162
162
 
163
163
  以下是已发布稳定版示例。profile 的 `package.json` 加依赖(建议用 tag 固定版本):
164
164
 
@@ -192,6 +192,31 @@ extract: true # false = 关闭自动提炼
192
192
 
193
193
  自动候选提示与 `refresh` 变更热流相互独立。启用方式、隐私与验收边界见[任务召回指针实验](docs/task-recall-experiment.md)。
194
194
 
195
+ ### 项目记忆(可选)
196
+
197
+ 按 Git 仓库隔离记忆,默认关闭:
198
+
199
+ ```yaml
200
+ projectMemory: true # 项目库按真实 Git 根隔离;个人库独立命名空间
201
+ confirmedOutcomes: true # 允许「确认结论:/确认修复:」把上一轮助手原句存为项目事实/经验
202
+ allowRemote: true # 允许项目模式投递提炼作业(默认不外发)
203
+ ```
204
+
205
+ 开启后工具分成 `mcp__lm_personal__memory_*`(个人通用)和 `mcp__lm_project__memory_*`(当前仓库),编号各自独立;会话首次使用时绑定,之后不可改绑;未绑定会话、子代理、非 Git 目录一律拒绝,不回退旧全局库。项目模式不启动旧 MCP、旧采集和 Viewer。
206
+
207
+ 旧库不会自动迁移,个人库从空开始。需要带走历史时手动跑一次(只复制、不删除原库,可重复执行):
208
+
209
+ ```bash
210
+ # 从仓库检出运行
211
+ node scripts/migrate-to-personal.mjs --dry-run # 只看条数
212
+ node scripts/migrate-to-personal.mjs
213
+
214
+ # 从 npm 安装的运行(脚本随包发布)
215
+ node node_modules/dsh-lm-memory/scripts/migrate-to-personal.mjs --dry-run
216
+ ```
217
+
218
+ 细节与已验收边界见[项目记忆](docs/project-memory.md)。
219
+
195
220
  key 从环境变量或 `~/.dsh/.credentials.yaml` 同名条目读取。没有 key 时自动提炼跳过但任务保留,重试 5 次后归档到 `extraction-jobs/failed/`,检索和手动写入不受影响。内置 provider 映射:zai-coding-cn、deepseek-official、deepseek-api-key、agnes。
196
221
 
197
222
  ### 使用反馈约定
@@ -214,6 +239,8 @@ LoCoMo runner 的凭据走 `BENCH_BASE_URL` / `BENCH_API_KEY` / `BENCH_LLM`,
214
239
  - 图谱每次写操作全量重建(数百条毫秒级,数千条要换增量方案),对答案质量的收益没有消融数据,也不参与默认召回。
215
240
  - 双语嵌入只是按查询语言路由,不是跨语言召回。bge-small 的窗口约 512 token,超长记忆(500 字以上)尾部语义会丢——两条 850 字、只有尾部城市不同的文本,向量完全一样。长内容拆开存。
216
241
  - 单用户单机,无同步。删除的介质级擦除和备份清理不做。viewer 图谱页不支持触摸和键盘。
242
+ - 项目记忆按物理路径识别仓库:移动或重新 clone 会变成新项目,旧库需要手工再用(迁移脚本可以拷进个人库)。项目模式不启动 Viewer,管理走工具。项目只在 macOS 上验证过,Windows 未实测(依赖硬链接做原子绑定、用 lstat 识别软链/junction,失败时一律拒绝而不是降级)。
243
+ - 自动召回是词面匹配:改述、同义、无引号的中文提问基本不会命中,命中率低是有意为之的保守取舍,不是故障。
217
244
 
218
245
  ## 常见问题
219
246
 
package/cordis.patch.yml CHANGED
@@ -14,6 +14,15 @@
14
14
  # baseURL: ""
15
15
  # apiKeyEnv: ZAI_CODING_CN_API_KEY
16
16
  # 已知可映射 provider:zai-coding-cn / deepseek-official / deepseek-api-key / agnes
17
+ #
18
+ # 以下是默认关闭的候选能力,需要时取消对应注释(细节见 docs/project-memory.md):
19
+ # projectMemory: true # 按 Git 仓库隔离的项目记忆;开启后不再启动旧 MCP/旧采集/Viewer
20
+ # confirmedOutcomes: true # 配合 projectMemory:允许用「确认结论:/确认修复:」把上一轮助手原句存为项目事实/经验
21
+ # allowRemote: true # 配合 projectMemory:允许把复盘作业交给模型提炼(默认不外发)
22
+ # taskRecall: # 实验:任务相关候选编号提示,需同时列精确会话 ID
23
+ # enabled: true
24
+ # sessionIds:
25
+ # - session-替换为测试会话的准确ID
17
26
  - id: mcp-lm-memory
18
27
  name: '@deepseek-ai/dsh-mcp-client'
19
28
  inject: [lmMemoryStartup]
@@ -1,12 +1,12 @@
1
1
  # 项目记忆(开发中)
2
2
 
3
- 项目模式开发开关 `projectMemory: true` 默认关闭。它不迁移旧库,也不把旧库当个人记忆。当前只在隔离测试环境开启;未发布或启用到现有 profile。
3
+ 项目模式开关 `projectMemory: true`,**默认关闭**,关闭时行为与旧版一致。它不会自动迁移旧库,也不会把旧库当个人记忆;需要带走历史时显式运行 `scripts/migrate-to-personal.mjs`(只复制、不删除源库、可重复执行、跳过已取代与已删除条目)。
4
4
 
5
5
  - `mcp__lm_personal__memory_*` 访问独立的个人通用库,`mcp__lm_project__memory_*` 访问当前会话的项目库。两库的数字 ID 各自独立;所有写入、召回、来源、反馈、修正、删除、置顶等记忆工具走同一路由。
6
6
  - 项目身份使用会话创建时的宿主目录解析出的真实 Git checkout 根,不由工具参数、当前 shell cwd 或仓库名决定。同名仓库、不同 checkout 分开;嵌套仓库使用自身根。当前实现按物理路径识别,移动 checkout 不会自动关联旧的库。
7
7
  - 新会话第一次项目调用以原子操作绑定项目,持久保存;之后只接受同一绑定。旧的未绑定会话、fork、子 Agent、非 Git 位置或无可信会话不能访问项目库。不退回旧全局库。此约束针对插件入口,不限制用户或 Agent 通过其余宿主文件权限直接访问本机文件。
8
8
  - 项目模式不启动旧 MCP、旧全局捕获或 Viewer;用对应作用域的工具管理。绑定成功后,停会/销毁时的捕获和变更推送只用当前项目目录。项目模式默认不外发,只有明确设置 `allowRemote: true` 且系统未禁外发才允许投递提炼作业。个人库只走显式工具。手工配置的其他 MCP 或共享 `current.md` 注入不是此插件所能撤销,测试 profile 不得同时启用它们。
9
- - 项目自动召回仍默认关闭;显式开启、会话 ID 在名单内且允许模型上下文外发时,仅读当前绑定项目并提示项目工具及编号,不扫个人库、不续租。安装版探针已在同样授权的 A/B 会话中问同一个锚点,只有拥有该记忆的 A 收到提示。尚未验证真实模型任务收益或真实模型自动提炼效果。
9
+ - 项目自动召回仍默认关闭;显式开启、会话 ID 在名单内且允许模型上下文外发时,仅读当前绑定项目并提示项目工具及编号,不扫个人库、不续租。安装版探针已在同样授权的 A/B 会话中问同一个锚点,只有拥有该记忆的 A 收到提示。**真实模型下的任务收益仍未验证**,所以门禁不达标就保持关闭。
10
10
  - `confirmedOutcomes: true`(默认关闭)允许用户把紧邻上一条助手回复的完整一行逐字写成 `确认结论:原句` 或 `确认修复:原句`,分别存为项目事实或经验。只存该行和用户确认原话,不转发确认消息给提炼模型,不读取或自动采信工具输出。来源证明的是用户确认,不是系统独立验证。安装版探针已验证真实项目续聊后的修复入库,另一项目查不到。
11
11
 
12
12
  ## 有效日期与跨会话修正
@@ -26,3 +26,6 @@
26
26
 
27
27
  - `node --test tests/project-*.test.mjs` 验证 Git 身份、持久绑定和三个真实 SQLite/MCP 后端的路由;工具契约快照与真实服务逐项比对。
28
28
  - `node scripts/eval/dsh-project-memory-smoke.mjs` 用已安装的 DSH、临时 HOME、两个真实 Git 仓库及 loopback 模型协议桩,验证首次工具发现、A/B 同号读写、个人库跨项目读取和旧全局库未打开。
29
+ - `node scripts/eval/dsh-package-smoke.mjs <包.tgz>` 验证**打包产物**本身(含迁移脚本随包发布):解包后装进 profile 的 `node_modules`,由已安装 DSH 加载,项目工具注册、写入与召回往返成功,且不生成旧库。
30
+ - `node --test tests/migrate-personal.test.mjs` 验证迁移只带 active 条目、保留事件日期与置顶、重复执行为幂等、源库不被改动。
31
+ - 真实模型:用 `glm-5.3-flash` 对一段真实发布流程对话做提炼,产出 2 条经验 + 1 条会话摘要,经统一提交入口入库后可按「发布流程 暂存验收」「完整回归」召回,日期与来源均在。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lm-memory",
3
- "version": "0.18.0-rc.2",
3
+ "version": "0.18.1",
4
4
  "description": "本地优先的 Agent 长期记忆:MCP server(SQLite+FTS5+双语语义+遗忘曲线+统一提交入口)+ DSH 采集插件(外发前脱敏/事件时间锚/会话指纹二采)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,6 +20,7 @@
20
20
  "files": [
21
21
  "plugin",
22
22
  "server",
23
+ "scripts/migrate-to-personal.mjs",
23
24
  "cordis.patch.yml",
24
25
  "docs"
25
26
  ],
@@ -1,5 +1,4 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { link, lstat, mkdir, readFile, realpath, unlink, writeFile } from 'node:fs/promises';
1
+ import { lstat, mkdir, readFile, realpath, writeFile } from 'node:fs/promises';
3
2
  import path from 'node:path';
4
3
 
5
4
  // Call only with the Host-owned identity, not a tool argument. Refuse links
@@ -48,14 +47,11 @@ export async function bindProjectSession(memoryDir, sessionId, identity, { creat
48
47
  try { accepted = await matches(); }
49
48
  catch (error) {
50
49
  if (error.code !== 'ENOENT' || !create) return null;
51
- const temp = path.join(registry, `.binding-${randomUUID()}`);
52
- await writeFile(temp, expected, { flag: 'wx', mode: 0o600 });
53
50
  try {
54
- // Atomic first writer wins; existing readers never see a partial file.
55
- try { await link(temp, binding); }
56
- catch (conflict) { if (conflict.code !== 'EEXIST') throw conflict; }
57
- accepted = await matches();
58
- } finally { await unlink(temp).catch(() => {}); }
51
+ // Exclusive create is atomic on every platform; no hard link needed.
52
+ await writeFile(binding, expected, { flag: 'wx', mode: 0o600 });
53
+ } catch (conflict) { if (conflict.code !== 'EEXIST') throw conflict; }
54
+ accepted = await matches();
59
55
  }
60
56
  return accepted ? await projectDirectory(base, identity) : null;
61
57
  } catch { return null; }
@@ -0,0 +1,73 @@
1
+ // One-shot, opt-in copy of the existing global memory library into the
2
+ // project-mode personal store. Public MCP writes only: no schema copying, no
3
+ // direct SQLite edits, no deletion of the source. Re-running is safe because
4
+ // the target store drops identical content.
5
+ //
6
+ // Usage: node scripts/migrate-to-personal.mjs [--memory-dir DIR] [--dry-run]
7
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
8
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
9
+ import fs from 'node:fs';
10
+ import os from 'node:os';
11
+ import path from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+
14
+ const argv = process.argv.slice(2);
15
+ const argValue = name => { const i = argv.indexOf(name); return i >= 0 ? argv[i + 1] : undefined; };
16
+ const dryRun = argv.includes('--dry-run');
17
+ const memoryDir = path.resolve(argValue('--memory-dir')
18
+ ?? process.env.LM_MEMORY_DIR
19
+ ?? path.join(process.env.DSH_HOME ?? path.join(os.homedir(), '.dsh'), 'memory'));
20
+ const source = path.join(memoryDir, 'memory.db');
21
+ const target = path.join(memoryDir, 'personal-v1');
22
+
23
+ if (!fs.existsSync(source)) {
24
+ console.error(`no legacy database at ${source}`);
25
+ process.exit(2);
26
+ }
27
+
28
+ const { DatabaseSync } = process.getBuiltinModule('node:sqlite');
29
+ const legacy = new DatabaseSync(source, { readOnly: true });
30
+ const rows = legacy.prepare(`SELECT id,kind,content,tags,event_date,pinned FROM memories
31
+ WHERE status='active' ORDER BY id`).all();
32
+ legacy.close();
33
+
34
+ console.log(`source: ${source}`);
35
+ console.log(`target: ${target}`);
36
+ console.log(`active rows to copy: ${rows.length}`);
37
+ if (dryRun) { console.log('dry run: nothing written'); process.exit(0); }
38
+
39
+ fs.mkdirSync(target, { recursive: true, mode: 0o700 });
40
+ const client = new Client({ name: 'lm-memory-migrate', version: '1' });
41
+ await client.connect(new StdioClientTransport({
42
+ command: process.execPath,
43
+ args: [fileURLToPath(new URL('../server/memory-server.mjs', import.meta.url))],
44
+ env: { ...process.env, LM_MEMORY_DIR: target, LM_EMBED: '0' },
45
+ stderr: 'ignore',
46
+ }));
47
+
48
+ let copied = 0, existing = 0, refused = 0;
49
+ const failures = [];
50
+ for (const row of rows) {
51
+ const args = { content: row.content, kind: row.kind, tags: row.tags ?? '' };
52
+ if (/^\d{4}-\d{2}-\d{2}$/.test(row.event_date ?? '')) args.event_date = row.event_date;
53
+ let text;
54
+ try {
55
+ text = (await client.callTool({ name: 'memory_remember', arguments: args }, undefined, { timeout: 30_000 }))
56
+ .content?.[0]?.text ?? '';
57
+ } catch (error) { failures.push({ id: row.id, error: String(error.message).slice(0, 120) }); continue; }
58
+ const id = Number(/id=(\d+)/.exec(text)?.[1]);
59
+ if (text.startsWith('OK:') && id) {
60
+ copied++;
61
+ if (row.pinned) await client.callTool({ name: 'memory_pin', arguments: { id, action: 'pin' } });
62
+ } else if (text.startsWith('EXISTS')) existing++;
63
+ else if (text.startsWith('REFUSED')) refused++;
64
+ else failures.push({ id: row.id, error: text.slice(0, 120) });
65
+ }
66
+ await client.close();
67
+
68
+ console.log(`copied ${copied}, already present ${existing}, refused ${refused}, failed ${failures.length}`);
69
+ if (failures.length) {
70
+ for (const failure of failures.slice(0, 10)) console.error(` legacy #${failure.id}: ${failure.error}`);
71
+ process.exitCode = 1;
72
+ }
73
+ console.log('source database untouched; delete it yourself only after checking the target store');