dsh-memu-memory 1.4.0 → 1.4.2
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/AGENTS.md +2 -0
- package/CHANGELOG.md +36 -0
- package/README.md +4 -1
- package/README.zh.md +4 -1
- package/docs/client-conventions.md +3 -0
- package/docs/mcp-porting.md +146 -0
- package/docs/memory-semantics.md +4 -2
- package/docs/troubleshooting.md +40 -0
- package/lib/binding-diagnostics.js +1 -1
- package/lib/client.js +223 -120
- package/lib/consolidation-worker.js +11 -3
- package/lib/curator.js +16 -4
- package/lib/cycle.js +75 -4
- package/lib/engine.js +68 -0
- package/lib/index.js +4 -2
- package/lib/inject.js +142 -8
- package/lib/memory.js +123 -21
- package/lib/port-surface.js +82 -0
- package/lib/private.js +49 -13
- package/lib/prompts/private-consolidation.coding.md +3 -1
- package/lib/prompts/private-consolidation.md +2 -0
- package/lib/prompts/private-consolidation.mixed.md +2 -0
- package/lib/prompts/private-consolidation.rp.md +2 -0
- package/lib/prompts/system-guide.coding.md +8 -2
- package/lib/prompts/system-guide.md +6 -0
- package/lib/prompts/system-guide.mixed.md +11 -0
- package/lib/prompts/system-guide.rp.md +6 -0
- package/lib/rpc.js +19 -5
- package/lib/tools.js +25 -0
- package/lib/turn-log.js +34 -11
- package/lib/worker-pool.js +11 -7
- package/package.json +2 -1
- package/tests/browser.test.mjs +21 -0
- package/tests/client-export.test.mjs +1 -0
- package/tests/client-render.test.mjs +1 -0
- package/tests/consolidation-fork.test.mjs +20 -1
- package/tests/curator-probe.test.mjs +19 -1
- package/tests/engine.test.mjs +60 -0
- package/tests/help-page.test.mjs +1 -0
- package/tests/inject-guide.test.mjs +108 -1
- package/tests/new-session-gate.test.mjs +1 -0
- package/tests/port-surface.test.mjs +138 -0
- package/tests/prompts.test.mjs +30 -0
- package/tests/react-snapshot.test.mjs +1 -0
- package/tests/salience-domain.test.mjs +34 -0
- package/tests/settings-beat.test.mjs +1 -0
- package/tests/sidebar-beat.test.mjs +1 -0
- package/tests/stale-maintenance.test.mjs +131 -0
- package/tests/turn-log.test.mjs +13 -0
- package/tests/webui.test.mjs +8 -1
package/AGENTS.md
CHANGED
|
@@ -36,6 +36,7 @@ fork cwd 残留死路径兜底 dataDir;保持宿主原权限,不自动覆盖
|
|
|
36
36
|
| 改现有行为 / 加新东西 / 提交前自检 | `docs/contributing.md` |
|
|
37
37
|
| **DSH 发新版本、要适配新宿主** | `docs/host-adaptation.md`(检查表 / 真机搭法 / 已知陷阱) |
|
|
38
38
|
| **哪个宿主构建核对到哪一步 / 某个宿主面在各版本长什么样** | `docs/host-versions.md` §13(台账 / 事实矩阵 / 变更账本) |
|
|
39
|
+
| **要把记忆搬到 MCP / 别的宿主** | `docs/mcp-porting.md`(工具面与存储层走 `dsh-memu-memory/port`;注入与 UI 搬不走) |
|
|
39
40
|
| 忘了宿主 API 长什么样 | `docs/host-api.md`;三种 exec 形状在 `docs/troubleshooting.md` 附录 D |
|
|
40
41
|
| 动 UI | `docs/client-conventions.md` |
|
|
41
42
|
| 改记忆语义 / 提示词正文 | `docs/memory-semantics.md` |
|
|
@@ -58,6 +59,7 @@ fork cwd 残留死路径兜底 dataDir;保持宿主原权限,不自动覆盖
|
|
|
58
59
|
失败一轮后锚点/日期没了 → T3.24
|
|
59
60
|
图谱改了没生效 / 缩到最小打架 → T3.27
|
|
60
61
|
WebUI 开着 GPU 占用高 / 时钟钉高档 → T3.28
|
|
62
|
+
引擎装完一直 installing、current=none、召回只走关键词 → T3.49
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
---
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# 更新日志 / Changelog
|
|
2
2
|
|
|
3
|
+
## [1.4.2] - 2026-11-28
|
|
4
|
+
|
|
5
|
+
> 四件事:记忆墙在 300 条处硬截断(真实库 423 条,读者永远看不到最新那部分);
|
|
6
|
+
> 列表顺序不可信(引擎与索引都不排,刚写的记忆会跑到中间);浏览页几百张可编辑卡片
|
|
7
|
+
> 一次性挂载、且正文被截断后仍可编辑(改一个字就把尾部写丢);引擎安装被杀后状态永久
|
|
8
|
+
> 停在 `installing`(rc.5 home 卡了两天,语义召回静默降级成关键词,没有任何错误信号)。
|
|
9
|
+
> 另新增移植入口 `dsh-memu-memory/port`,让 MCP server / 脚本能复用工具面与读写层。
|
|
10
|
+
|
|
11
|
+
- **记忆墙整库流式加载**:`browseWall` 增加 `offset` 分页(上限 5000),客户端按每批 300 条边拉边渲染,批间让出一帧;`items.length < total` 不再被当作"到头"。原先客户端固定传 `limit:300`、服务端再 `Math.min(1000, …)`,真实库 423 条于是永久只显示 300 条。实测 423 条分 2 批读完、排序单调、id 无重复。客户端加批数上限 40(12000 条)防"库被持续写入时 total 一直变大"的活锁。
|
|
12
|
+
- **列表新到旧**:`lib/memory.js:privateListRaw` 只有跨库分支排过序,单库(侧栏与浏览库走的就是这条)直接吐引擎/索引原始顺序。现在 `privateListView` 统一按 `updatedAt || createdAt` 降序、tie-break id,engine 与 index 两条返回路径都过一遍。
|
|
13
|
+
- **浏览页大批量**:卡片抽成 `BrowserMemoryCard`(`React.memo`),草稿下沉到卡片内部——此前 400+ 张卡的表单挂在父组件上,**每敲一个字都重渲染整个列表**。列表先挂 60 张、IntersectionObserver 滚到底 +120 自动追加;切池/搜索/换库时重置批数。动作回调走 ref 转发保持引用稳定,否则 memo 每次父渲染都失效。
|
|
14
|
+
- **正文按需补全**:列表投影新增 `truncated` 标记;卡片聚焦正文时用 `getMemory` 补拉全文(拉取期间输入框只读,避免在截断版上先打字),失败退回截断显示并 `console.warn`。此前正文被截到 4000 字却仍可编辑,改一个字保存就会把尾部写丢。
|
|
15
|
+
- **移植入口 `dsh-memu-memory/port`**(`lib/port-surface.js` + `exports["./port"]`):`collectToolSpecs()` 用只收集不注册的假 ctx 拿到宿主那 14 个工具规格(`name`/`description`/`parameters`/`execute`,跑完还原 `registrationReport`,不影响 `memu_status`);`toInputSchema()` 把宿主值 schema 方言的属性级 `required: true` 提升为 JSON Schema 的 `required: [...]`;其余为记忆读写与库/索引的 re-export。适配器只依赖这个入口,不必读 `tools.js` 里三十段内联闭包。
|
|
16
|
+
- **召回支持显式库**:`privateRecall` 接受 `libraryId`,把函数体内的取数口径统一成 `scope = binding ?? 最小只读 scope`。有会话时 `scope === binding`(逐字等价,2033 条既有用例零回归);无会话时跨库聚合、情绪、场景时间退回中性值,跳过并发换库校验,并且**强制校验库存在与文件夹开关**——否则一个拼错的 id 会静默返回空(`loadPrivateIndex` 对未知库给空索引),既违反「召回为空必须留信号」,也绕过用户在设置里关掉的开关。
|
|
17
|
+
- **引擎中断自愈**:新增 `lib/engine.js:reconcileInterruptedInstall()`,挂在 `engineStatus()`(界面一查就自愈)与 `ensureEngine()`(重装前先收尾)。三条判据同时成立才动手:`status==='installing'`、本进程未持锁且 `install.lock` 不存在、`updatedAt` 超 30 分钟没变(与过期锁阈值同数)。动作:落成 `failed`/`step=interrupted` + 可读原因,并清理 `venv.tmp-*`——**只删 tmp,绝不碰正式 `venv-*`**。`installInFlight` 标志放在 `acquireLock`/`releaseLock` 内部,因为三个受锁流程(安装/切版本/删版本)共用同一把锁。
|
|
18
|
+
- **无会话写路径同样受文件夹开关约束**:`resolveLibrary` 在 `binding` 为 null 时退到库所属文件夹策略(新增 `assertLibraryEnabled`)。此前 `assertScopeEnabled(null)` 直接返回,于是用户在设置里关掉的库,换个入口(MCP/脚本)又能写、又能读——同一份数据在宿主里被禁、在别处仍然开着。
|
|
19
|
+
- 守卫:`tests/port-surface.test.mjs` 新增 8 条(14 个规格的形状与幂等、`toInputSchema` 的 required 提升、无会话召回、无会话无库仍拒绝、未知库报错、显式库不跨库、有会话路径不变、只给 libraryId 能写);`tests/engine.test.mjs` 新增 4 条(死安装收尾并清 tmp、正式 venv 不被误删、新鲜安装不误判、持锁不收尾、ready 不降级);`tests/browser.test.mjs` 新增 2 条(新到旧排序、截断标记 + `getMemory` 取回全文);`tests/webui.test.mjs` 新增 offset 分页断言并把 403 回退守卫改匹配 `stream(firstLibraryId)`;7 个测试文件的 React 替身补 `memo`(生产 React 有、替身漏了)。
|
|
20
|
+
- 文档:`docs/client-conventions.md` §7.4 三条新口径(整库流式、新到旧、正文按需补全)、新增 `docs/mcp-porting.md`(能复用/搬不走/适配器骨架/配置坑)、`docs/troubleshooting.md` §3.49(安装卡在 installing)与症状速查表、`AGENTS.md` 索引两行。
|
|
21
|
+
- 全量 2035 tests / 2033 pass / 0 fail / 2 skipped;`acceptance-local` 50/50;`npm run check` all passed。
|
|
22
|
+
|
|
23
|
+
## [1.4.1] - 2026-11-26
|
|
24
|
+
|
|
25
|
+
> 两件事:通道复用会话 id 时规则消息会整段缺席(真机 24 回合没有 `<memory-guide>`);
|
|
26
|
+
> 按域变体只有"怎么查"没有"什么时候写",于是私聊里从不下笔。
|
|
27
|
+
|
|
28
|
+
- **同名新会话重新投放规则与锚点**:dsh-channel 用确定性会话 id(`qq-dm-<uid>`)跨重启复用,宿主重建同名空转录后 binding 仍是上一代的,`guideRulesKey`/`anchorPushed` 让 `guideAdmission`/`ensureUnifiedGuide` 的稳态判据把 guide 与锚点永久跳过——实测 `qq-dm-1299772830` 新会话 16:22 建立、第 1 回合就有记忆块,规则消息直到第 25 回合 20:50 才出现。现在 `lib/inject.js:syncSessionIncarnation` 每次 pre-step 比对宿主会话身份(`session.createdAt`;宿主不暴露时退回「回合号回到 1 + 首条消息 id」兜底,同一代内稳定),换代就清 `guideRulesKey`/`guideMessageAt`/`anchorPushed`/`lastInjectedUserMessageId`、置 `reinjectPending`,活动日志记「同名新会话:一次性投放已重置」。
|
|
29
|
+
- **切换记忆领域重新投放**:`injectedDomain` 记录在 binding 上,与 `domainOf(binding)` 不一致时清 `guideRulesKey`/`guideMessageAt`/`anchorPushed`/`anniversariesShown`/`openLoopRemindedAt`/`textureKey` 并置 `reinjectPending`(`lib/inject.js:syncDomainDelivery`,活动日志「记忆领域切换:一次性投放已重置」)。此前切域只靠 `rulesKey` 换 guide,锚点与按域过滤的纪念日/未了之事仍按"一会话一次"被旧领域的记账压着;两个领域落到同一份基础稿时 guide 也不会重投。
|
|
30
|
+
- **逾期与过时的整理收尾**:此前两类"只提醒不结案"——逾期承诺在注入里天天提示但 `commitment.status` 永远是 `open`(整理提示词只教"写承诺");`expired` 短期草稿退出召回后永久占索引,没有保留期。现在:①`[memory-catalog]` 后附**欠账单列**(`lib/memory.js:overdueOpenCommitments`,最多 8 条,含 due、已逾期天数、对谁/做什么),整理页四稿与 worker 任务书都要求"先清欠账再查过时"——按本窗证据写 `done`/`cancelled`/`expired`,没证据就保留并写明仍欠着;`valid_to` 已过或已被明确取代的旧条目改 `status=archived` 或补正窗口,旧正文保留。②`lib/cycle.js:runOverdueReviewPass` 对逾期 ≥7 天的 open 承诺写一条 `check` 活动日志(同一条 7 天不重复,节流表 `state.cycle.overdueReviewAt`),只提示、不改状态——承诺是否兑现不能被清理策略替人裁决。③`lib/memory.js:archiveExpiredDrafts`:`expired` 草稿在保留期(30 天)后改标 `archived`,不删除,正文仍可升回 `long_term`。
|
|
31
|
+
- **编码域种子放宽**:fork 种子以前对 coding 也用 2 分 salience 过滤,"改这个函数"这类只有工具调用的改动会被整回合丢掉;工具结果截 1100 字、调用参数截 500 字,diff 与错误签名常只剩开头,worker 路径的 turn-log 工具行更是只留 160 字。现在 coding:`candidateSeedEvents` 弱词阈值 1、带 `tool/call` 的回合一律保留、回合上限 120(默认 60);`compactSeedEvents` 工具结果 2200 字 / 调用参数 1000 字;turn-log 工具行 600 字 / 参数 400 字(`turnLogLimits('coding')`,记录器、worker 增量与缺口重建同口径);turn-log 关闭/重建失败时的兜底压缩与远端整理转录也按域(`condenseLimitsFor('coding')`:结果 1400 / 参数 700,默认 400/300)。整窗仍有 ≤500 事件、单条 12k 文本、turn-log 4000 字/条的总闸。
|
|
32
|
+
- **编程整理频率与"修改重点"**:fork/worker 的任务书以前是 RP 口径——价值排序把工程结论排进「其他明确事实」并受「普通事实最多 3 条」限制,`content` 要求 50–150 字「人物、地点、原话」;与编码整理稿自己的 150–350 字结构要求冲突,编码域于是写得少、也只剩"修复了某问题"这种摘要。现在 `buildWorkerBrief({domain})` 对 `coding` 使用工程排序(根因与修复理由 = 接口/不变量变化 = 环境与版本约束 = 被否决方案 > 验证结论与测试范围 > 需求/验收变化 > 偏好 > 其余),`content` 150–350 字按「结论 / 作用范围与定位(路径 + 符号)/ 条件与原因 / 验证状态」、标题写结论本身;编码整理稿的「最多 3 条、宁可少写一条」改为「每窗最多 8 条、前两类必须写」,与 RP 同口径。`rp/general/mixed` 的原口径不变。守卫:`tests/prompts.test.mjs` 按域断言任务书排序、长度与标题要求。
|
|
33
|
+
- **规则消息补工具分工表**:首步 `<memory-guide>` 以前只在零星句子里提到 recall/remember,`rp`/`mixed` 连写入工具名都没有,模型没有"哪个工具什么时候用"的统一入口。四个领域稿(`general` 基础稿 + `rp`/`coding`/`mixed` 变体)现在都带同一张表:`memu_private_recall` / `memu_global_recall`、`memu_private_remember`(+`_batch`) / `memu_private_update`、`memu_private_list` / `memu_status` 的时机,以及 `memu_private_archive`/`memu_private_unpin` 只在用户明确要求时、`memu_private_link*`/`memu_lexicon_*` 不在对话里主动调。`project:*` 等无变体领域回退基础稿。渲染后 full message:coding 963 / mixed 1015 / rp 1327 / general 1685 token,都在 `injectionTotalTokens` 默认 2000 内;规则正文变化会换 `rulesKey`,存量会话下一步首步自动重投一次。
|
|
34
|
+
- **guide 与召回解耦**:`ensureUnifiedGuide` 以前在 `injectForStep` 的 try 内,召回抛错(真机:`inbound queue is full`)会把规则消息一起吞掉。现在 catch 分支仍尝试投放 rules,故障只落 `lastRecallError` + warn。
|
|
35
|
+
- **按域 guide 补写入条款**:`system-guide.rp.md` / `.coding.md` / `.mixed.md` 各补一段「什么时候写」——值得记的三类、用 `memu_private_remember`/`memu_private_update` 的口径、不每回合写、其余交给闲时整理。此前只有通用稿讲写入(`domainLayered` 是整篇替换),实测 27 回合的 RP 私聊 `memu_*` 工具调用 0 次。coding 稿加完渲染约 907 token,仍在 `injectionTotalTokens` 默认 2000 之内。
|
|
36
|
+
- 守卫:`tests/inject-guide.test.mjs` 新增四条——同名新会话重投规则与锚点、无 `createdAt` 时回合号复位只重置一次且重入不重复、召回抛错仍投 guide、切域重投规则/锚点并清掉纪念日与未了之事的记账;`tests/stale-maintenance.test.mjs` 新增四条——保留期归档、逾期门槛、周期提示只写一次且不改状态、目录欠账单列;`tests/prompts.test.mjs` 新增两条——逐域断言工具分工表(八个工具 + batch 指引 + 整理侧工具边界)、按域断言整理任务书的排序/长度/标题口径;`tests/turn-log.test.mjs`、`tests/salience-domain.test.mjs`、`tests/consolidation-fork.test.mjs`、`tests/curator-probe.test.mjs` 各加一条编码域额度用例(工具行 600/参数 400、工具回合与弱词保留、种子 2200/1000、兜底 1400/700)。全量 2022 tests / 2020 pass / 0 fail / 2 skipped。
|
|
37
|
+
- 文档:`docs/troubleshooting.md` §3.47 与症状速查表、`docs/memory-semantics.md` §8.4、中英 README 的兼容性段。
|
|
38
|
+
|
|
3
39
|
## [1.4.0] - 2026-11-26
|
|
4
40
|
|
|
5
41
|
> 三件事一起收:按域终于看得见筛得动;中文人名被 n-gram 滑窗切成两个节点的成因在提名侧堵住;
|
package/README.md
CHANGED
|
@@ -327,7 +327,10 @@ the idle window starts from real message activity or the agent's return to idle.
|
|
|
327
327
|
- **No cloud sync, no accounts, no cross-device sync.** This is a local plugin with no server-side identity.
|
|
328
328
|
- **Images without vision:** without an optional caption/vision endpoint, an image memory is a pointer plus what a person wrote about it. The plugin does not claim to see pixels.
|
|
329
329
|
- **Poisoned v4 sessions:** historical `format v4 message requires a producer-owned source kind` rows can be diagnosed but not rewritten; the plugin never edits private session files.
|
|
330
|
-
- **Agent presets:** a conversation whose preset (`i-am-yuike`, `yuike-standard`, …) carries its own `cordis.yml` composes its model-facing plugins from that list alone, and its scope never delivers `agent/pre-step` to this plugin. At runtime `lib/preset-scope.js` attaches an injection listener to that agent's own context, so **anchor and recall delivery works**. All conversations now receive the memory rules as one `<memory-guide rules="…">` plugin message on the first step of a turn; the plugin no longer registers a system-prompt section, and the message is replaced after a domain/prompt change or a compaction (`rulesKey` / `guideLost`). The **final tool list** is a third, separate question: it follows the preset's own plugin list and the host scope, and it cannot be inferred from whether this plugin is listed — observations in this repo record both "no `memu_*` tools" and `memu_private_*` present in some presets' tool chains. **Per-preset tool availability still needs a real-host check (W3)**; until then do not read this as "presets have no tools", nor as "listing the plugin is enough". The plugin never edits anyone's preset files.
|
|
330
|
+
- **Agent presets:** a conversation whose preset (`i-am-yuike`, `yuike-standard`, …) carries its own `cordis.yml` composes its model-facing plugins from that list alone, and its scope never delivers `agent/pre-step` to this plugin. At runtime `lib/preset-scope.js` attaches an injection listener to that agent's own context, so **anchor and recall delivery works**. All conversations now receive the memory rules as one `<memory-guide rules="…">` plugin message on the first step of a turn; the plugin no longer registers a system-prompt section, and the message is replaced after a domain/prompt change or a compaction (`rulesKey` / `guideLost`). The rules message carries a **tool timing map** (recall/global_recall, remember(+batch)/update, list/status, and archive/unpin only on an explicit user request) in all four domains: `general`, `rp`, `coding` and `mixed`. The **final tool list** is a third, separate question: it follows the preset's own plugin list and the host scope, and it cannot be inferred from whether this plugin is listed — observations in this repo record both "no `memu_*` tools" and `memu_private_*` present in some presets' tool chains. **Per-preset tool availability still needs a real-host check (W3)**; until then do not read this as "presets have no tools", nor as "listing the plugin is enough". The plugin never edits anyone's preset files.
|
|
331
|
+
- **Reused session ids in IM channels, and domain switches:** `dsh-channel` and similar surfaces reuse a deterministic id (`qq-dm-<uid>`) across restarts, and the host can re-create a same-id session with an empty transcript. The plugin compares the host session identity (`session.createdAt`; when the host does not expose it, a turn number back at 1 plus the first message id) against the stamp kept on the binding, and on a new incarnation it clears the previous incarnation's `guideRulesKey` / `anchorPushed` so the rules and the anchor are delivered again (1.4.1+). Before this, such a conversation could run its whole life without a `<memory-guide>` message. **Switching the memory domain** re-delivers too: the rules message, the anchor, today's anniversaries, open loops and the time-of-day line are all domain-filtered, so a domain change resets them and they are delivered again for the new domain. Guide delivery is also decoupled from recall: a recall exception no longer swallows the rules message.
|
|
332
|
+
- **Overdue and stale cleanup:** a short-term draft leaves recall at its deadline and is archived 30 days later (never deleted; the body can still be promoted back to `long_term`). Overdue promises surface at most three per turn, dated open loops once a day, and the consolidation brief ships an "overdue" section so the worker can close them from transcript evidence (`done`/`cancelled`/`expired`); the periodic sweep only writes a hint and never changes a status. Entries whose `valid_to` has passed leave recall and are archived or re-windowed during consolidation. Whether a promise was kept is a factual question — the plugin does not answer it for you.
|
|
333
|
+
- **Coding consolidation detail:** the fork seed keeps every coding turn that touched a tool (up to 120 turns, default 60), 2,200 chars of a tool result and 1,000 chars of call arguments; the worker path's turn-log keeps 600-char tool lines and 400-char arguments (default 160/120), and the turn-log-off fallback compaction keeps 1,400/700 (default 400/300). RP/general keep their original caps, and the 500-event window, 12k per-message text and 4,000-char per-record limits still bound everything.
|
|
331
334
|
- **Consolidation worker (C 包, 2026-10-30).** An idle or manual pass now works from a *fixed snapshot*: it takes the public `sessionQuery.observeSession()` lease (falling back to `readSession()` when the host offers no lease), cuts at the last complete `turn/end`, and drops unpaired tool calls and half steps — a live transcript whose last turn is still open is **deferred**, never consolidated. A job is settled only by a structured completion receipt that is cross-checked against the library index (an id the library does not contain is not a success, and a rewrite of an existing id counts as an update, not a new memory). Checked / pending / in-flight ranges and a lease are persisted separately in `consolidation.json`, so a crash, a timeout or a failed turn leaves the range pending instead of looking consolidated. **Limits:** the worker still runs inside the parent preset's own system prompt — it receives an explicit "you are a background consolidation worker, not this character" brief, which reduces but does not remove persona carry-over, because the host has no public API to replace that prompt; and when the conversation's tool surface carries no `memu_private_remember` / `memu_private_update` (or exposes memory only through PTC), consolidation reports `unavailable` (`worker-tools-missing` / `worker-tools-ptc-only`) rather than forking a worker that could not write. The parent's library, scope, domain and memory context are re-checked before dispatch, on every worker tool call, and again before any result is credited.
|
|
332
335
|
- **Consolidation coverage is conservative lexical evidence.** A matching date or a couple of shared terms does not prove a candidate was written. The local check also requires text coverage, retained characters/words and values, and matching clause polarity; uncertain candidates stay in carry. It can retain a paraphrase that was already saved, and it does not claim semantic equivalence.
|
|
333
336
|
- **"Tomorrow" is resolved at write time.** A relative day (今天 / 明天 / 后天 / today / tomorrow) together with a month-day settles into one dated memory; a memory that only says "sometime next month" keeps no date rather than inventing one. A date that was already written as `MM-DD` is not rewritten — the fix applies to new writes.
|
package/README.zh.md
CHANGED
|
@@ -316,7 +316,10 @@ return { content: originalContent, meta: { ...originalMeta, memoryInbound: batch
|
|
|
316
316
|
- **没有云同步、账号或跨设备同步。** 这是本地插件,没有服务端身份。
|
|
317
317
|
- **没有视觉时:** 图片记忆只是「指针 + 人写的描述」。插件不会声称看过像素。
|
|
318
318
|
- **v4 污染会话:** 历史 `format v4 message requires a producer-owned source kind` 行只能诊断,不能改写;插件不会编辑私有会话文件。
|
|
319
|
-
- **人格预设(agent preset):** 预设(`i-am-yuike`、`yuike-standard` 等)自带 `cordis.yml`,会话的模型可见插件集只由那份清单决定,它的 scope 也不会把 `agent/pre-step` 送到本插件。运行时 `lib/preset-scope.js` 会把注入监听挂到该 agent 自己的 ctx 上,所以**锚点与召回的送达是能用的**。所有会话现在都通过回合首步的一条 `<memory-guide rules="…">` 插件消息接收记忆规则;插件不再注册 system prompt 段,规则在切域、改稿或压缩后由 `rulesKey`/`guideLost`
|
|
319
|
+
- **人格预设(agent preset):** 预设(`i-am-yuike`、`yuike-standard` 等)自带 `cordis.yml`,会话的模型可见插件集只由那份清单决定,它的 scope 也不会把 `agent/pre-step` 送到本插件。运行时 `lib/preset-scope.js` 会把注入监听挂到该 agent 自己的 ctx 上,所以**锚点与召回的送达是能用的**。所有会话现在都通过回合首步的一条 `<memory-guide rules="…">` 插件消息接收记忆规则;插件不再注册 system prompt 段,规则在切域、改稿或压缩后由 `rulesKey`/`guideLost` 替换。规则消息里带**工具分工表**(recall/global_recall、remember(+batch)/update、list/status 的时机,以及归档与取消置顶只在用户明确要求时调用),`general`/`rp`/`coding`/`mixed` 四个领域都有。**最终工具面**是第三件事,由该预设自己的清单与宿主 scope 决定——不能从「有没有列上本插件」推断,仓库里的观察既有「没有 `memu_*` 工具」,也有某些预设的工具链里存在 `memu_private_*`。**逐预设的真实工具名单仍需真机核实(W3)**;在那之前,别读成「预设都没有工具」,也别读成「列上插件就一定可用」。插件不会改任何人的预设文件。
|
|
320
|
+
- **通道复用会话 id + 切域重投:** IM 通道(`dsh-channel` 等)用确定性会话 id(`qq-dm-<uid>`)跨重启复用,宿主重建同名新会话时转录是空的。插件按宿主会话身份(`session.createdAt`;宿主不暴露时看回合号是否回到 1 加首条消息 id)比对绑定上的会话戳,换代就清掉上一代的 `guideRulesKey`/`anchorPushed` 并重新投放规则与锚点(1.4.1 起);在此之前,这类会话可能整段都收不到 `<memory-guide>`。**切换记忆领域**同样重投:规则消息、锚点、当日纪念日、未了之事与时段氛围都按领域过滤,切域后全部按新领域重新投一次。规则消息的投放也与召回解耦:召回抛错不再连带吞掉它。
|
|
321
|
+
- **逾期与过时的收尾:** 短期草稿到期即退出召回,再保留 30 天后自动归档(不删除,正文仍可升回 `long_term`);逾期承诺每回合最多提示 3 条、带日期的未了之事每天最多提一次,整理任务书会带上"欠账单列"要求按转录证据结案(`done`/`cancelled`/`expired`),周期扫描只写提示、永不改状态;`valid_to` 已过的条目不进召回,整理时归档或补正窗口。承诺是否兑现是事实问题,插件不替你裁决。
|
|
322
|
+
- **编码域的整理精度:** 种子保留对编码域更宽——带工具调用的回合一律保留(上限 120,默认 60),工具结果保留 2200 字、调用参数 1000 字;worker 路径的 turn-log 工具行 600 字、参数 400 字(默认 160/120),turn-log 关闭时的兜底压缩 1400/700(默认 400/300)。RP/通用域保持原额度;整窗仍受 500 事件、12k 文本/条、4000 字/条记录的总闸。
|
|
320
323
|
- **相对日期在写入时结算:** 「今天 / 明天 / 后天 / today / tomorrow」加上一个月日落成带年份的日期;只说「下个月某天」的记忆不产生日期,也不替它编一个。已经按 `MM-DD` 写进去的旧条目不会被改写——这条只对新写入生效。
|
|
321
324
|
- **不在范围:** 云端 MemU 联调、旧条目的 source 回填、已写坏 v4 消息的自动修复。
|
|
322
325
|
|
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
- **保存/设置类改动必须通知**:`notifyMemoryWrite(kind, libraryId)` 先跑同窗口监听(毫秒),再向 `BroadcastChannel("dsh-memu-memory")` 广播 `{ type: "memory-write", kind, libraryId, at }`,让另一份文档(WebUI 新标签 / overlay iframe / 另一个宿主窗口)立刻重取;本地已刷新的写(设置保存、复位、后端切换、文件夹策略)用 `broadcastMemoryWrite` 只通知别人,避免刷两遍。接收端只跑本地监听 / 重渲染,**不广播回去**、**不从消息取数据**——消息只叫醒心跳,事实永远从 RPC 取。
|
|
36
36
|
- **一切轮询走心跳**:面板同步一律 `useMemoryBeat`,不各写 `setInterval`。心跳载荷**只许** `{ revisionOnly: true }`,返回**只许** `{ revision, stamp }`。
|
|
37
37
|
- 侧边栏首屏只允许 **1 个 RPC**(`getSidebarState`)且不读记忆全文;其余分页懒加载,列表项预览就地截断。
|
|
38
|
+
- **记忆墙整库流式加载**:`browseWall` 按 `offset` 分批(每批 300)边拉边上屏,**不要在 300 条处截断**——`total` 是整库条数,`items.length < total` 只是「还没拉完」。浏览页卡片分批挂载(先 60 张,滚到底 +120),卡片草稿下沉在 `BrowserMemoryCard` 内部并 `React.memo`,输入时不得重渲染整个列表(几百张卡时那是逐键卡顿的根因)。
|
|
39
|
+
- 列表排序口径 = **新到旧**(`updatedAt || createdAt` 降序,tie-break id),服务端 `privateListView` 统一排;引擎与索引都不保证顺序,界面不要自己另排一套。
|
|
40
|
+
- **正文按需补全**:列表返回的 `content` 只是截断预览,`truncated: true` 时卡片聚焦正文必须先用 `getMemory` 补拉全文(拉取期间输入框只读)。绝不能让截断版进编辑路径——那等于用户改一个字就丢掉尾部。
|
|
38
41
|
- 筛选是**两个独立维度,各自独占**:池(在用 / 已归档)× 层(全部 / 永久 / 长期 / 短期 / 锚点)。**所有选项恒定列出,没有记忆显示 0**;归档不是叠加开关。两池同一次读取全拿到,切换/归档/恢复只改状态重绘。
|
|
39
42
|
- 反面语义设置项(如 `newSessionPromptDismissed`)在 WebUI 必须 `settingRow(..., { invert: true })`,否则开关显示与宿主页面相反。
|
|
40
43
|
- **跨库聚合视图不带 sessionId**:记忆墙「全部记忆库」(`browseWall` 无 libraryId)与词典页「全部词典」(`lexiconList` 传 `libraryId:'all'`)都是管理面聚合读,会话凭据表达不了多库授权——省略 sessionId 走宿主 capability;宿主 403 时退回单库并禁用聚合选项(`multiBlocked` / `allBlocked`),不让整页空。聚合里的写操作按条目所属库路由(词典 `bookOf`),不能拿保留作用域名(`all`)去写。
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# 移植到 MCP / 其它宿主
|
|
2
|
+
|
|
3
|
+
给**想把这个插件搬到 MCP server、CLI 或别的 agent 宿主的人**看的。目标只有一个:让适配器复用这里的记忆实现,而不是 fork 一份再各改各的。
|
|
4
|
+
|
|
5
|
+
结论先放前面:**工具面和存储层已经可以复用,注入层和界面层不可能复用**——这不是工程量问题,是协议边界。
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. MCP 能接手什么,接不了什么
|
|
10
|
+
|
|
11
|
+
| 插件里的东西 | MCP 能否接手 | 说明 |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| 记忆读写、召回、库管理 | ✅ 能 | 走 `dsh-memu-memory/port`,见 §2 |
|
|
14
|
+
| 工具声明的 name / description / inputSchema | ✅ 能 | `collectToolSpecs()` 直接给,`toInputSchema()` 转格式 |
|
|
15
|
+
| MemU 引擎(Python CLI) | ✅ 能 | 引擎本来就用 `MEMU_*` 环境变量自持配置,不依赖宿主 |
|
|
16
|
+
| **逐轮自动注入** | ❌ 不能 | MCP 只有 tools/resources/prompts;`agent/pre-step` 那种「每轮往上下文插一条消息」没有对应通道 |
|
|
17
|
+
| **会话身份** | ❌ 不能 | `tools/call` 只发 `{ name, arguments }`,没有 `_meta`、没有 sessionId、没有 cwd |
|
|
18
|
+
| **宿主模型路由** | ❌ 不能 | MCP server 是外部进程,拿不到宿主的 `llm` 服务;得自己配 key |
|
|
19
|
+
| **WebUI / 设置页** | ❌ 不能 | 那是宿主 RPC + slot + React 组件 |
|
|
20
|
+
|
|
21
|
+
所以现实的做法是**双形态**:MCP server 提供工具,宿主插件保留注入与界面。两边共用 `port` 入口和同一份数据目录。
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 2. 现成入口:`dsh-memu-memory/port`
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
const {
|
|
29
|
+
collectToolSpecs, toInputSchema, // 工具声明
|
|
30
|
+
privateRecall, privateList, privateRemember, privateUpdate, privateArchive,
|
|
31
|
+
privateDelete, globalRecall, globalList, // 记忆读写
|
|
32
|
+
listLibraries, getLibrary, loadPrivateIndex, // 库与索引
|
|
33
|
+
} = await import('dsh-memu-memory/port')
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`lib/port-surface.js` 只做 re-export 加一个纯函数,不含状态逻辑。**适配器只依赖它,不要 import `lib/index.js`**——那是宿主插件入口,注册的是 ctx 服务、注入钩子和 RPC。
|
|
37
|
+
|
|
38
|
+
### 工具声明怎么拿
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const specs = collectToolSpecs() // 14 个:私有读写 + 词典 + 全局 + status
|
|
42
|
+
// specs[i] = { name, description, parameters, execute, output, timeoutMs, ... }
|
|
43
|
+
|
|
44
|
+
const tools = specs.map((spec) => ({
|
|
45
|
+
name: spec.name,
|
|
46
|
+
description: spec.description,
|
|
47
|
+
inputSchema: toInputSchema(spec.parameters),
|
|
48
|
+
}))
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`parameters` 是**宿主的值 schema 方言**,和标准 JSON Schema 只差一处:必填写成属性上的 `required: true`,而 JSON Schema 要父级 `required: [...]`。`toInputSchema()` 就是干这个的,别再自己写一遍。
|
|
52
|
+
|
|
53
|
+
`collectToolSpecs()` 内部用一个只收集不注册的假 ctx 跑一遍 `registerTools`,跑完还原注册报告,所以**调用它不会影响 `memu_status` 的注册清单**。
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 3. 最小的适配器骨架
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
61
|
+
import { collectToolSpecs, toInputSchema, privateRecall, privateRemember } from 'dsh-memu-memory/port'
|
|
62
|
+
|
|
63
|
+
const LIBRARY = process.env.MEMU_LIBRARY_ID // 适配器自己的作用域来源
|
|
64
|
+
|
|
65
|
+
const server = new McpServer({ name: 'memu', version: '1.0.0' })
|
|
66
|
+
|
|
67
|
+
for (const spec of collectToolSpecs()) {
|
|
68
|
+
server.tool(spec.name, spec.description, toInputSchema(spec.parameters), async (args) => {
|
|
69
|
+
// 无会话调用:显式传 libraryId,不要用 spec.execute(args, {})(见 §4)
|
|
70
|
+
const result = await runWithoutHost(spec.name, args)
|
|
71
|
+
return { content: [{ type: 'text', text: typeof result === 'string' ? result : JSON.stringify(result) }] }
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function runWithoutHost(name, args) {
|
|
76
|
+
if (name === 'memu_private_recall') {
|
|
77
|
+
const scored = await privateRecall({ libraryId: LIBRARY, query: args.query, topK: args.topK })
|
|
78
|
+
return scored.files.map((file) => `${file.name} ${file.entry?.title || ''}`).join('\n') || '(无命中)'
|
|
79
|
+
}
|
|
80
|
+
if (name === 'memu_private_remember') {
|
|
81
|
+
return await privateRemember({ libraryId: LIBRARY, content: args.content, title: args.title })
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`${name} 还没有无会话实现`)
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**先说清楚**:上面这 14 个工具里,目前只有读写/库管理这批能直接无会话调用;`memu_status`、词典工具、`link_suggest` 这些要么依赖会话诊断,要么需要补充作用域参数。移植时按需逐个接,别指望一次全通。
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 4. 三个必须知道的边界(都是刻意的)
|
|
92
|
+
|
|
93
|
+
**① 无会话的 `privateRecall` 只读显式指定的那一个库。**
|
|
94
|
+
跨库聚合、情绪衰减、场景时间全部退回中性值。要跨库请自己按库循环——别指望它替你扫全部库。
|
|
95
|
+
|
|
96
|
+
**② 带边界标记的记忆对无会话调用方不可见。**
|
|
97
|
+
`contextVisible` 在没有 `memoryContext` 时会拒绝有 `channelId` / `characterId` / `worldId` 边界的条目。这是**安全默认**:没有身份就不给看跨角色隐私。要走通就得让适配器自己提供等价的身份维度(目前没有公开入口)。
|
|
98
|
+
|
|
99
|
+
**③ `spec.execute(args, {})` 不会抛错,而是返回一段错误文本。**
|
|
100
|
+
因为 `toolBase` 统一做了 fail-open 包装,实测返回 `"dsh-memu-memory error: no bound session"`。适配器**不要**把 `spec.execute` 直接当 MCP handler,否则每个调用都会"成功"返回一句错误。handler 请走 §3 那种显式库函数。
|
|
101
|
+
|
|
102
|
+
**④ 无会话不做会话级授权,但库级约束仍然生效。**
|
|
103
|
+
`libraryId` 必须真实存在(否则 `unknown library`),且该库所属文件夹在设置里被关掉时会拒绝读写(`private memory is disabled for this folder`)。换句话说:能拿到 `libraryId` 就能操作那一个库,但**不会**因为「调用方没有会话」而绕开用户关掉的开关。这是刻意的——适配器不该替用户重新打开他关掉的记忆。
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 5. MCP 配置的两个坑
|
|
108
|
+
|
|
109
|
+
**环境变量会被清洗。** DSH 的 MCP stdio 客户端 spawn 子进程时,会删掉所有匹配 `/KEY|PASSWORD|SECRET|TOKEN/i` 的环境变量名——`MEMU_API_KEY` 正好中招。所以必须显式传:
|
|
110
|
+
|
|
111
|
+
```yaml
|
|
112
|
+
- id: mcp-memu
|
|
113
|
+
name: '@deepseek-ai/dsh-mcp-client'
|
|
114
|
+
config:
|
|
115
|
+
serverName: memu
|
|
116
|
+
transport: stdio
|
|
117
|
+
command: node
|
|
118
|
+
args: ['D:/path/to/memu-mcp/server.js']
|
|
119
|
+
expandTemplates: true
|
|
120
|
+
env:
|
|
121
|
+
MEMU_API_KEY: '${credential:MEMU_API_KEY}'
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
不这么做,引擎会静默落到无 key 状态(召回降级、整理不可用),而界面上看不出原因。
|
|
125
|
+
|
|
126
|
+
**工具名会带前缀。** 在 DSH 里它们显示为 `mcp__memu__memu_private_recall`。前缀是 `mcp__<serverName>__`,建议 `serverName: memu`。
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 6. 别做的事
|
|
131
|
+
|
|
132
|
+
- **别为了 MCP 去抽象 `ctx`。** 那会牵动 600KB 的 `client.js` 和整条注入路径,收益为零。
|
|
133
|
+
- **别给工具加 `sessionId` 参数。** 那是把宿主概念漏进协议,而且模型根本不知道自己的 sessionId。
|
|
134
|
+
- **别试图用 MCP 复刻注入。** `agent/pre-step` 往上下文插消息这件事,MCP 协议里没有对应物;写 `AGENTS.md` 也不行——DSH 的 `agent-instructions` 不监视外部编辑,只在成功的 `read`/`write`/`edit` 或恢复会话时才重新对账。
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 7. 相关代码位置
|
|
139
|
+
|
|
140
|
+
| 想改什么 | 去哪 |
|
|
141
|
+
|---|---|
|
|
142
|
+
| 工具定义与 handler | `lib/tools.js`(`registerTools` / `collectToolSpecs`) |
|
|
143
|
+
| 召回、读写、库解析 | `lib/memory.js`(`privateRecall` 的 `scope` 分支是给无会话调用方的) |
|
|
144
|
+
| 移植入口 | `lib/port-surface.js` |
|
|
145
|
+
| 引擎与凭据 | `lib/memu.js`、`lib/memu-config.js`、`requirements.lock` |
|
|
146
|
+
| 宿主集成点全貌 | `lib/index.js`(服务注册)、`lib/inject.js`(注入)、`lib/rpc.js`(WebUI) |
|
package/docs/memory-semantics.md
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
### 8.4 注入
|
|
42
42
|
|
|
43
|
-
- 静态 guide 与动态记忆都走 plugin 消息;当前版本不再注册本插件的 system prompt 段。所有会话(含 `persona` `complete: true`)统一由 `lib/inject.js` 的 `ensureUnifiedGuide` 在**回合首步**投放一条 `<memory-guide rules="…">` 插件消息;`rulesKey` 由协议版本、domain 和实际渲染正文计算,domain/覆盖/默认稿变化或压缩丢失(`guideLost`)时在下一个合法首步替换,同一规则不逐回合重复。旧 binding 只有 `guideMessageAt`、没有 `guideRulesKey` 时视为旧版,补投一次;失败 fail-open
|
|
43
|
+
- 静态 guide 与动态记忆都走 plugin 消息;当前版本不再注册本插件的 system prompt 段。所有会话(含 `persona` `complete: true`)统一由 `lib/inject.js` 的 `ensureUnifiedGuide` 在**回合首步**投放一条 `<memory-guide rules="…">` 插件消息;`rulesKey` 由协议版本、domain 和实际渲染正文计算,domain/覆盖/默认稿变化或压缩丢失(`guideLost`)时在下一个合法首步替换,同一规则不逐回合重复。旧 binding 只有 `guideMessageAt`、没有 `guideRulesKey` 时视为旧版,补投一次;失败 fail-open,不写新版本。**规则消息本身带工具分工**:查(`memu_private_recall` / `memu_global_recall`)、写(`memu_private_remember`,多条走 `memu_private_remember_batch`)、补(`memu_private_update`:合并/纠正/补窗口/给承诺结案)、看(`memu_private_list` / `memu_status`)各在什么时机用,以及归档/取消置顶(`memu_private_archive` / `memu_private_unpin`)只在用户明确要求时、`memu_private_link*` 与 `memu_lexicon_*` 不在对话里主动调。四个领域变体(`general` 用基础稿,`rp` / `coding` / `mixed` 用变体,其余无变体的 `project:*` 领域回退基础稿)都覆盖这张表,`tests/prompts.test.mjs` 逐域钉住。**同名新会话**:通道(如 dsh-channel 的 `qq-dm-<uid>`)重启后会用同一个 id 重建空转录,binding 却还是上一代的,稳态判据会把 guide 与锚点永久跳过(真机 24 回合无规则消息)。`syncSessionIncarnation` 因此记录宿主会话身份(`session.createdAt`;宿主不暴露时用「回合号回到 1 + 首条消息 id」兜底),身份变化时清掉 `guideRulesKey`/`anchorPushed`/`lastInjectedUserMessageId` 并置 `reinjectPending`;guide 的投放也不再位于召回异常之内,召回故障不连带吞掉规则消息。**切域同理**:绑定上记 `injectedDomain`,与 `domainOf(binding)` 不一致时清 `guideRulesKey`/`guideMessageAt`/`anchorPushed`/`anniversariesShown`/`openLoopRemindedAt`/`textureKey` 并置 `reinjectPending`——这些一次性提醒都按领域过滤,切到新领域后必须重新投,guide 即使两个领域回退到同一份基础稿也照样重投。
|
|
44
44
|
- 首轮锚点 + 每用户回合最多一次;记忆块**紧跟在人类消息之后**(`index + 1`),不再前插到用户消息之前——通道驱动(`channel-*`)的回合也走同一落点。此前它们退到 inbound 路径被追加到批次末尾,于是锚点落在工具调用之后,读起来就像"回复完才拿到上下文"。长工具回合仅有新的真实人类消息批次时追加一次,普通工具步骤不触发。**短句也召回**:召回门槛下限是 2 字(`minUserChars` 仍可调高),否则 QQ 里常见的「摸摸」「现在有点饿」会让首步一条记忆都没有——这正是"锚点总在下一条模型消息之后"的成因。人类消息按来源判定:`channel-*` 算;插件消息、`runtime-context` / `skill-catalog` / `time-context` / `progress-rules` / `agent-instructions` / `user-approval` 与 `tool*` 不算。
|
|
45
45
|
- **回合中途补充召回(受控)**:位置不变式在工具步不成立(那一步的批次里没有人类消息),所以它单独成一类:带 `[回合中途补充 · 这不是用户新说的话]` 标记、追加在批次末尾、独立预算 `midTurnTokens`(默认 400)、每回合最多 `midTurnMaxPerTurn`(默认 2)次、冷却 `midTurnCooldownMs`(默认 60s)。触发用**增量**证据并复用 `active-memory` 计分口径(去重后的工具单元 + 单条封顶字符 + 步数):默认 `midTurnMinSteps=4` 且(`midTurnMinUnits=3` 或 `midTurnMinChars=6000`);刚过线只投一行提示卡(让模型自己调 `memu_private_recall`),明显过线(`midTurnFullUnits=6` 且 `midTurnFullChars=15000`)才投正文召回;连续两次空召回停止本回合。`midTurnRecall: false` 关闭。
|
|
46
46
|
- **待接纳提案有落盘凭据**:`injectionAdmissions` 是进程内 Map,宿主重启或「同一 home 由另一个进程观察」时提案会凭空消失,接纳永远不发生(qq-dm 实测:333 个回合里 `acceptedMemoryMessages` 一次都没出现,同库 qq-group 正常)。现在提案同时写一份最小凭据到 binding 的 `pendingInjections`(按消息内容 digest 匹配,最多 8 条),观察端换进程也能补完接纳;迟到的接纳会把时钟抬到 `max(当时时钟, lastInjectedTurn, inbound.clock)`,否则 `markInjectedRefs` 会按「时钟必须前进」拒掉全部 effects。回合一收立即作废这份凭据(`finishInjectionTurn`),避免迟到的同内容消息复活已丢弃的提案。接纳失败一律落一条 warn 记录(`注入消息未被接纳 · <reason>`,同会话同原因 60 秒合并),原因取 `proposal-missing` / `proposal-<status>` / `digest-mismatch` / `snapshot-stale`——硬规则 10 的观测信号。
|
|
@@ -109,7 +109,8 @@
|
|
|
109
109
|
- 触发:`settings.sleepConsolidation` 开着时,每 5 分钟扫一遍(`lib/cycle.js` 的 `runSleepPass`)。候选有三条腿:① 空闲 ≥ `sleepAfterIdleMinutes`(**默认 2 分钟**,`lib/state.js` 的 `DEFAULT_SETTINGS`);② **水位**——账本里 pending 积压 ≥ 200 事件,不依赖空闲;③ 新活动但水位不足时的**探针**(最多每 15 分钟一次,读转录并评估,不 fork)。排序是 backlog → idle → probe,扫描每次最多处理 **2 个**会话。
|
|
110
110
|
- 应用启动后 8 秒补跑一次(`STARTUP_SWEEP_MS`),因为定时器只在应用开着时存在:一段对话如果是在应用关着的时候结束的,它永远等不到那个「空闲窗口」——用户一回来发消息,`lastTurnAt` 就被顶新了。
|
|
111
111
|
- **有新回合 ≠ 该写记忆。** 进 fork 之前先做两道本地评估(只看 `lastSleepSeq` 之后的转录):① `assessConsolidationValue` 的硬门槛——没有任何人类消息(只有插件通知、工具结果、心跳)→ 跳过;只有一条**纯应答**(「谢谢」「好的」「ok」「收到」,且没有任何工具调用)→ 跳过。**这里刻意不按字数判断**:字数少的偏好句(「我不吃香菜」)比一千字的闲聊更该留,长度是坏代理。② 水位优先级高于 `assessWake` 加权分:pending ≥ 200 事件或 ≥10 个真人回合直接整理;水位以下才走 `score = 0.35*min(H/3,2) + 0.45*min(C/4000,2) + 0.20*min(U/20,2)`(`H` 真人回合、`C` 真人文字 + 助手正文 + 去重工具结果、`U` 去重有效工具单元),默认 `activeMemoryMinScore = 0.8`、`activeMemoryStarvationMinutes = 15`。
|
|
112
|
-
- **每次只种一窗。** `requestPrivateConsolidation` 只把 `lastSleepSeq` 之后的增量切成一个 ≤500 事件、尾部对齐完整回合的窗口(`selectConsolidationWindow`);种子经 `compactSeedEvents` 清噪:只留真人消息 / 助手正文 / 工具调用与结果,删 reasoning、`source.replayState`、`data.stream`、插件召回、`runtime-context`、`request/header` 等后台事件;工具结果截 1200 字、重复输出只留一份。窗口开头插一条 `[memory-catalog]` 已有记忆目录(最多 18 条:id + 标题 + layer + status),worker
|
|
112
|
+
- **每次只种一窗。** `requestPrivateConsolidation` 只把 `lastSleepSeq` 之后的增量切成一个 ≤500 事件、尾部对齐完整回合的窗口(`selectConsolidationWindow`);种子经 `compactSeedEvents` 清噪:只留真人消息 / 助手正文 / 工具调用与结果,删 reasoning、`source.replayState`、`data.stream`、插件召回、`runtime-context`、`request/header` 等后台事件;工具结果截 1200 字、重复输出只留一份。窗口开头插一条 `[memory-catalog]` 已有记忆目录(最多 18 条:id + 标题 + layer + status),worker 用它合并/去重,不再为旧库重读历史。目录后面另有**欠账单列**(`overdueOpenCommitments`,最多 8 条:id + 标题 + due + 已逾期天数 + 对谁/做什么),因为按更新时间截断的目录很可能漏掉旧承诺,而整理必须看见它们;整理页与 worker 任务书都要求"先清欠账再查过时"——open 且已过 due_at 的承诺按本窗证据结案(`done`/`cancelled`/`expired`),没有证据就保留并写明仍欠着;`valid_to` 已过或已被明确取代的旧条目改 `status=archived` 或补正窗口,旧正文保留。周期兜底只提示不裁决:`runOverdueReviewPass` 对逾期 ≥7 天的 open 承诺写一条 `check` 活动日志(同一条 7 天内不重复,标记存 `state.cycle.overdueReviewAt`);过期草稿在 `shortTermTtlHours` 之后再留 30 天(`EXPIRED_DRAFT_RETENTION_DAYS`),超期由 `archiveExpiredDrafts` 改标 `archived` —— 不删除,正文仍可在归档视图里升回 `long_term`。剩余事件留到下一次扫描,`lastSleepSeq` 只随对账回执前进。
|
|
113
|
+
- **种子按域保留(1.4.1)**:fork 种子以前对 coding 也用 2 分 salience 过滤,"改这个函数"这类只带工具调用的改动会被整回合丢掉;工具结果截 1100 字、调用参数截 500 字,diff 与错误签名常常只剩开头。现在 coding:`candidateSeedEvents` 弱词阈值 1、带 `tool/call` 的回合一律保留、回合上限 120(默认 60);`compactSeedEvents` 工具结果 2200 字 / 调用参数 1000 字。worker 路径的 turn-log 同口径按域给额度:编码域工具行 600 字 / 参数 400 字(默认 160/120,`turnLogLimits`,记录器与缺口重建同源),整条记录仍 4000 字封顶,整窗仍有 ≤500 事件与单条 12k 文本的总闸。turn-log 关闭或缺口重建失败时的兜底压缩(`condenseEvents`)与远端整理转录也按域:coding 工具结果 1400 字 / 参数 700 字(默认 400/300,`condenseLimitsFor`)。
|
|
113
114
|
- **近期触发过记忆就不 fork。** `runSleepPass` 先看 `suppressionReason`:距上次整理不足 `activeMemoryCooldownMinutes`(默认 0)或距上次**注入过记忆**不足 `activeMemoryRecallCooldownMinutes`(默认 15 分钟)→ 跳过并发 `check` 日志。探针/水位可绕过「刚注入过」这一条(它们先评估、不直接 fork);被抑制或低分跳过的回合返回 `settled: false`,不推进 `lastSleepSeq`/`lastSleepAt`。
|
|
114
115
|
- **寒暄与无新事件是终态。** `small-talk` / `no-human-turn` / `no-new-events` 返回 `settled: true` 并写入 `lastSleepAt`,下一次真人消息到达前不再重扫同一段;政策跳过不计入 `ran`(没有 worker 回执)。
|
|
115
116
|
- **同一快照失败有上限(仅自动触发)。** `failJob` 按窗口 `snapshotHash` 记 `failures`;连续 2 次失败后下一次**自动**请求返回 `skipped: 'snapshot-failed'`(`settled: true`),不再重复付同一段的 fork 成本。手动整理(`force: true`)是明确的一次再决定,不受该上限约束;新事件也会改变哈希,让自动路径重新获得机会。
|
|
@@ -117,6 +118,7 @@
|
|
|
117
118
|
- 会话被删:host 对 `readSession` 报 `session "…" not found`,这是**不变量**而不是瞬时故障。`runSleepPass` 一旦看到就把 binding 标 `sessionGone: true` 并清掉重试计数,此后直接跳过(以前会按 2 的幂退避、封顶 1 小时,永远重试);同名会话后来真的收到新消息时(`lib/inbound.js`)会清掉这个标记。**"读不出来"不是"被删了"**:转录读失败(例如 `ENOENT`)由快照层显式标成可重试(`lib/consolidation-snapshot.js` 的 `failed()` → `retryable: true`),`runSleepPass` 只按退避重试、不打 `sessionGone`——`isGoneSessionError` 只认宿主那句 `session "…" not found` / `no such session`。
|
|
118
119
|
- 手动「整理这场对话」(RPC `generatePrivate`)带 `force: true`,跳过上面两道评估与抑制:用户已经决定了。若游标已经到末尾,手动整理只重查最后 ≤300 个事件,不再重放整段历史。
|
|
119
120
|
- **必写候选跨窗顺延。** 每窗本地抽 salience ≥3 的轮次(最多 8 条)作为必写清单;本窗没写进库的候选记入账本 `carry`,下一窗优先带 4 条、其余名额留给新候选。核验是纯本地保守证据比对,不额外调模型:日期从文本重合证据中剔除;至少 2 个有效 token,重合数须达 min(3, 候选 token 数) 且覆盖率 ≥55%,候选里的汉字 / Latin 词必须在同一条新增或更新记忆中出现,数值集合须包含候选值,共享 token 的子句否定极性须一致。日期相同、少量重词、不同动作或数值、相反极性不再单独算覆盖;不足以证明时保留在 carry。它仍是词法近似,不能证明任意改写的语义等价,因此可能保守保留已写入的改写候选;最后一窗也会在同一份任务书里看到顺延候选,不需要为补写再开一次整窗 fork。
|
|
121
|
+
- **任务书按域分叉(1.4.1)**:`buildWorkerBrief({ domain })` 以前是 RP 口径——价值排序把工程结论排进「其他明确事实」并受「普通事实最多 3 条」限制,`content` 要求 50–150 字「人物、地点、原话」,与编码整理稿自己的 150–350 字结构要求直接冲突。现在 `coding` 用工程排序(根因与修复理由 = 接口/不变量变化 = 环境与版本约束 = 被否决方案 > 验证结论与测试范围 > 需求/验收变化 > 偏好 > 其余),`content` 150–350 字按「结论 / 作用范围与定位(路径 + 符号)/ 条件与原因 / 验证状态」排、标题写结论;编码整理稿的「最多 3 条、宁可少写」也改为「每窗最多 8 条、前两类必须写」。rp/general/mixed 保持原口径。
|
|
120
122
|
|
|
121
123
|
---
|
|
122
124
|
|
package/docs/troubleshooting.md
CHANGED
|
@@ -52,6 +52,8 @@ WebUI 开着 GPU 占用高 / 时钟钉高档 → §3.28
|
|
|
52
52
|
mac 一键安装引擎报 dlopen 签名错 / 事后引擎目录是空的 → §3.31
|
|
53
53
|
插件内部报错要取证与一键修复 / 启动弹窗 → §3.45
|
|
54
54
|
库从列表消失但仍在写入 / 召回正常 → §3.46
|
|
55
|
+
同名新会话整段没有规则消息 / 锚点迟到很久 → §3.47
|
|
56
|
+
欠账一直提醒却不结案 / 过期草稿越积越多 → §3.48
|
|
55
57
|
```
|
|
56
58
|
|
|
57
59
|
## 3. 出过的问题:症状 → 落点 → 守卫
|
|
@@ -812,3 +814,41 @@ grep tests 里的硬编码清单。守卫:全量 `npm test` 1676/1674 pass / 0
|
|
|
812
814
|
**怎么确认**:`state.json` 里看 `archived` / `archivedBy` / `lastUsedAt` 三者是否自相矛盾;宿主日志搜 `archived library` 与 `kept library`。修好后旧数据在下一轮 sweep(启动后 8 秒或每 5 分钟)或下一条消息时自动复活。
|
|
813
815
|
|
|
814
816
|
**守卫**:`tests/cycle.test.mjs` —— 在用库跨三轮 sweep 不归档且仍在列表、无人用的库照常归档并记 `archivedBy='sweep'`、误归档在用库被复活、用户归档不被复活、purge 不把在用库列入候选、删除在用库被拒(解绑后放行)、快路径复活。
|
|
817
|
+
|
|
818
|
+
### 3.47 同名新会话整段没有规则消息 / 锚点迟到很久(通道复用会话 id)
|
|
819
|
+
|
|
820
|
+
**症状**:IM 通道(dsh-channel 等)的私聊/群聊里,回合首步有 `[open loop]` 与逐轮召回,却始终没有 `<memory-guide>`,`===== memory anchor =====` 也很久以后才偶然出现一次。`state.json` 里该会话的 `guideRulesKey` 有值、`guideMessageAt` 比宿主会话对象的 `createdAt` 还早,`lastInjectedTurn` 远大于当前转录的回合数。真机(2026-11-26,`qq-dm-1299772830`):新会话对象 16:22 建立,第 1 回合就有记忆块,规则消息直到第 25 回合 20:50 才出现。
|
|
821
|
+
|
|
822
|
+
**落点**:通道用确定性会话 id(`bridge.ts` 的 `qq-dm-<uid>`)跨重启复用,宿主重建同名新会话后转录是空的,而 memu 的 binding 按 id 持久,`guideRulesKey` / `anchorPushed` 还是上一代的。`guideAdmission` / `ensureUnifiedGuide` 的稳态判据只看 binding(`steady && guides.length === 0 → skip`),而 `agent/pre-step` 只给本步批次、看不见历史,于是新转录的首回合被当成「规则早就在」而永久跳过;只有压缩置 `guideLost`、规则/领域变了或回合失败回滚删 key 才会补投。同链缺陷:`ensureUnifiedGuide` 原先在 `injectForStep` 的 try 内,召回抛错(如 `inbound queue is full`)会把规则消息一起吞掉,那一回合记忆块与规则双双缺席。
|
|
823
|
+
|
|
824
|
+
**现在(1.4.1 起)**:`lib/inject.js:syncSessionIncarnation` 每次 pre-step 用宿主会话身份(`session.createdAt`,宿主不暴露时退回「回合号回到 1 + 首条消息 id」)比对 binding 上的 `sessionStamp`;换代就清掉 `guideRulesKey` / `guideMessageAt` / `anchorPushed` / `lastInjectedUserMessageId` 并置 `reinjectPending`,活动日志记一行「同名新会话:一次性投放已重置」。兜底戳只在同一代内稳定,宿主对同一首步重入不会重复重置。guide 的投放移出召回 try,召回故障只写 `lastRecallError` 与 warn,不再带走规则消息。同一入口的 `syncDomainDelivery` 处理**切域**:`injectedDomain` 与当前 `domainOf(binding)` 不一致时清 `guideRulesKey` / `guideMessageAt` / `anchorPushed` / `anniversariesShown` / `openLoopRemindedAt` / `textureKey` 并置 `reinjectPending`——纪念日与未了之事都按领域过滤,切到新领域后必须重投;guide 即使两个领域落到同一份基础稿也照样重投。
|
|
825
|
+
|
|
826
|
+
**怎么确认**:`state.json` 里看 `sessionStamp` 与当前转录是否同代(有 `createdAt` 时以它为准)、`injectedDomain` 与 `domainOf(binding)` 是否一致;活动日志搜「同名新会话」与「记忆领域切换」。规则/锚点恢复后,`guideMessageAt` 会被下一次接纳刷新。
|
|
827
|
+
|
|
828
|
+
**守卫**:`tests/inject-guide.test.mjs` —— 同名新会话重投规则与锚点、无 `createdAt` 时回合号复位只重置一次且重入不重复、召回抛错仍投 guide、切域重投规则/锚点并清掉纪念日与未了之事的记账。
|
|
829
|
+
|
|
830
|
+
### 3.48 欠账一直提醒却不结案 / 过期草稿越积越多
|
|
831
|
+
|
|
832
|
+
**症状**:`[commitment]` 卡每天还在提示"已逾期 N 天",但库里那条 `commitment.status` 一直是 `open`;或者归档视图里的 `expired` 草稿越积越多,召回又永远看不到它们。
|
|
833
|
+
|
|
834
|
+
**落点**:这是两条"只提醒不结案"的链。承诺逾期只有注入提醒(`dueCommitments` 与 overdue 兜底腿),整理提示词只教"写 `commitment`",没教"按证据结案",于是欠账永远 open。短期草稿过期只改 `status=expired` 退出召回(`isMemoryEligible` 的即时拦截 + `expireShortTerm` 清扫),注释里的"保留供升级"没有期限——`expired` 草稿会永久占索引,只能人工删。
|
|
835
|
+
|
|
836
|
+
**现在(1.4.1 起)**:`[memory-catalog]` 后带**欠账单列**(`overdueOpenCommitments`,最多 8 条),整理页与 worker 任务书要求"先清欠账再查过时"——open 且已过 `due_at` 的承诺按本窗证据写 `done`/`cancelled`/`expired`,没有证据就保留并写明仍欠着;`valid_to` 已过或已被明确取代的旧条目改 `status=archived` 或补正窗口。周期兜底只提示:`runOverdueReviewPass` 对逾期 ≥7 天的 open 承诺写一条 `check` 活动日志(同一条 7 天内不重复,节流表在 `state.cycle.overdueReviewAt`),**不改 status**;过期草稿在 TTL 之后再留 30 天,由 `archiveExpiredDrafts` 改标 `archived`(不删除,正文仍可升回 `long_term`)。口径见 `docs/memory-semantics.md` §8.9。
|
|
837
|
+
|
|
838
|
+
**怎么确认**:活动日志搜「欠账待结案」「过期草稿归档」;`state.json` 的 `cycle.overdueReviewAt` 是节流表;承诺是否结案只看 `commitment.status`(应被整理改成 `done`/`cancelled`/`expired`,周期任务永远不动它)。想让某条提前结案,直接让 agent 调 `memu_private_update` 或整理一次。
|
|
839
|
+
|
|
840
|
+
**守卫**:`tests/stale-maintenance.test.mjs` —— 保留期归档(旧的归档、窗口内不动、legacy 回退 `expiresAt`、活草稿不碰)、逾期判定门槛(open/逾期天数/marginalized/done)、周期提示只写一次且不改状态、目录欠账单列包含 id/due/天数/对象。
|
|
841
|
+
|
|
842
|
+
### 3.49 引擎安装卡在 installing 几天不动(current=none)
|
|
843
|
+
|
|
844
|
+
**症状**:面板与 `memu_status` 一直显示 `engine installing`、`current=none`;语义召回彻底降级成关键词(关键词仍能捞到,所以看着「好像还能用」);重启宿主也不变。2026-11-26 的 rc.5 home 就这样停了两天,`step=installing-deps:python` 之后再没动过。
|
|
845
|
+
|
|
846
|
+
**落点**:安装进程被杀(宿主重启、断电、任务管理器结束进程)时,`state.json` 永久停在 `installing`——没有 error、没有 `current.json`、`venv.tmp-*` 残骸留在版本目录里。`engineStatus` 的判据是 `current ? 'ready' : state.status || 'idle'`,于是界面只能反复显示 "installing",没有任何「它其实已经死了」的信号。
|
|
847
|
+
|
|
848
|
+
**现在(1.4.1 起)**:`engineStatus()` 与 `ensureEngine()` 都先跑 `reconcileInterruptedInstall()`。三条判据同时成立才收尾:`status === 'installing'`、本进程没有持锁且 `install.lock` 不存在、`updatedAt` 超过 30 分钟没变(与 `acquireLock` 的过期锁阈值同一个数)。收尾动作:落成 `failed` + `step=interrupted` + 可读原因(中文,带卡住步骤与分钟数),并删除 `venv.tmp-*` 残骸——**只删 tmp,绝不碰正式 `venv-*`**(那可能正是 `current.json` 指向的可用引擎)。收尾后重装从干净状态开始。
|
|
849
|
+
|
|
850
|
+
**怎么确认**:`engine/state.json` 的 `status` / `step` / `error`;`logs/install.log` 最后一行是否停在 `Installing collected packages`(那就是 pip 中途被杀的现场);`engine/<version>/venv.tmp-*` 是否还在。
|
|
851
|
+
|
|
852
|
+
**应急恢复**:若不想等重装,可复用另一个 home 已装好的 venv——把 `engine/<版本>/venv-*` 整目录复制过来,写 `current.json`(`version` / `venv` / `python` / `commands`),再把 `state.json` 置 `ready`,最后用 `verifyEngine(current.python, { expectedVersion })` 验证。注意两个 home 用的 Python 可能不同(受管运行时 3.12.14 vs 系统 Python),`requirements.lock` 的实测基准是 **3.12.14**。
|
|
853
|
+
|
|
854
|
+
**守卫**:`tests/engine.test.mjs` 四条用例 —— 死安装被收尾成 `failed` 且 tmp 被清理(同时断言正式 venv 不被误删)、新鲜安装不被误判、持锁时不收尾、`ready` 引擎不被降级。
|
|
@@ -54,7 +54,7 @@ export const RUNTIME_STATE = Object.freeze([
|
|
|
54
54
|
{ layer: 'temporary-map', file: 'lib/inbound.js:13', name: 'calls', keyedBy: 'sessionId', clearedBy: 'tool/result or turn/end' },
|
|
55
55
|
{ layer: 'temporary-map', file: 'lib/inbound.js:14', name: 'sessions', keyedBy: 'sessionId', clearedBy: 'session/disposed (releaseInboundSession)' },
|
|
56
56
|
{ layer: 'temporary-map', file: 'lib/media.js:19', name: 'captures', keyedBy: 'sessionId', clearedBy: 'capture settle' },
|
|
57
|
-
{ layer: 'temporary-map', file: 'lib/private.js:
|
|
57
|
+
{ layer: 'temporary-map', file: 'lib/private.js:1075', name: 'inFlight', keyedBy: 'sessionId', clearedBy: 'consolidation settle' },
|
|
58
58
|
{ layer: 'temporary-map', file: 'lib/curator.js:56', name: 'jobs', keyedBy: 'job id', clearedBy: 'curation settle' },
|
|
59
59
|
{ layer: 'cache', file: 'lib/state.js:1538', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
|
|
60
60
|
{ layer: 'cache', file: 'lib/paths.js:52', name: 'readFailures', keyedBy: 'absolute file', clearedBy: 'a later successful read' },
|