dsh-memu-memory 1.3.3 → 1.3.5
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 +6 -1
- package/CHANGELOG.md +41 -3
- package/README.md +1 -7
- package/README.zh.md +1 -7
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/mobile.jpg +0 -0
- package/assets/screenshots/relations.jpg +0 -0
- package/assets/screenshots/settings.jpg +0 -0
- package/assets/screenshots/stats.jpg +0 -0
- package/assets/screenshots/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +10 -0
- package/docs/contributing.md +1 -0
- package/docs/memory-semantics.md +17 -0
- package/docs/troubleshooting.md +41 -0
- package/lib/binding-diagnostics.js +2 -2
- package/lib/client.js +34 -21
- package/lib/consolidation-snapshot.js +101 -5
- package/lib/consolidation-worker.js +1 -1
- package/lib/cycle.js +19 -1
- package/lib/index.js +83 -2
- package/lib/inject.js +26 -6
- package/lib/private.js +450 -165
- package/lib/rpc.js +8 -0
- package/lib/state.js +14 -1
- package/lib/turn-log.js +522 -0
- package/lib/webui/standalone.css +4 -29
- package/lib/worker-pool.js +741 -0
- package/package.json +1 -1
- package/scripts/acceptance-local.mjs +6 -5
- package/scripts/check-idle-compositing.mjs +61 -0
- package/scripts/prune-turnlogs.mjs +30 -0
- package/tests/consolidation-snapshot.test.mjs +89 -1
- package/tests/injection-rollback.test.mjs +34 -0
- package/tests/loader.mjs +2 -0
- package/tests/salience-domain.test.mjs +139 -0
- package/tests/settings-coverage.test.mjs +97 -0
- package/tests/stubs/dsh-session-query.js +26 -0
- package/tests/turn-log.test.mjs +474 -0
- package/tests/webui.test.mjs +19 -0
- package/tests/worker-lifecycle.test.mjs +1046 -0
- package/docs/recall-benchmark.md +0 -238
package/AGENTS.md
CHANGED
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
8. **不碰共享 `/api`**:RPC 只走 `/dsh-memu-memory` 前缀(`webServer.register` + `connection.requestRejection`)。
|
|
23
23
|
9. **日志与提示词里不放 API key。**
|
|
24
24
|
10. **注入失败 fail-open,但必须留可观测信号。** 吞掉异常是允许的,但**不许把真实故障一起吞**:fail-open 必配 `logger.warn` + binding 上的 `lastRecallError`(侧边栏可见),单测断言**召回到的 id**,不能只断言「消息插进去了」。**不能靠「没报错就是好了」。** 成因与守卫 → `docs/troubleshooting.md` §3.1。
|
|
25
|
+
11. **跑批与复测的输出一律重定向文件**(`> logs/x.log 2>&1`),禁用 `| tail` 管道——管道只留尾巴,故障段不可回查。清理宿主数据必须先确认宿主进程完全退出(活宿主的内存态会回写覆盖清理结果)。
|
|
26
|
+
12. **整理快照必须做持久日志交叉核对**:`captureSessionSnapshot` 的活视图(observeSession/readSession)落后于持久日志时,用 `sessionPersistence` + `readColdSessionLog` 冷读并取更长的日志(source `persisted-ahead`);只信活视图 = 外部追加不可见 → 快照冻结/整理洪水。`host`/`custom` 模型模式也不得探测父会话 route(resume 会把父会话钉成活视图)。成因链与排错路线 → `docs/troubleshooting.md` §3.29。
|
|
25
27
|
|
|
26
28
|
---
|
|
27
29
|
|
|
@@ -53,6 +55,7 @@
|
|
|
53
55
|
实体合并 / 怕丢记忆 → T3.23
|
|
54
56
|
失败一轮后锚点/日期没了 → T3.24
|
|
55
57
|
图谱改了没生效 / 缩到最小打架 → T3.27
|
|
58
|
+
WebUI 开着 GPU 占用高 / 时钟钉高档 → T3.28
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
---
|
|
@@ -80,12 +83,14 @@ npm run check # node --check + i18n + package.json + 文
|
|
|
80
83
|
| `docs/contributing.md` | §4 改动流程(四步 / 验证三件套 / 连带清单 / 文档同步)+ §5 六个扩展点 + §10 提交前清单 |
|
|
81
84
|
| `docs/host-api.md` | §6.1 / 6.2 / 6.4–6.8:embedding、workspaceRegistry、历史会话与标题、fork/followup、定时器、RPC+slot+折叠、预设工具面真机证据边界 |
|
|
82
85
|
| `docs/host-adaptation.md` | 宿主版本适配手册:事实来源、memu 的宿主面清单、新版本检查流程、隔离真机搭法、0.2.2-rc.1 实测记录与陷阱 |
|
|
83
|
-
| `docs/client-conventions.md` | §7:两个壳一份实现、颜色 token、控件纪律、数据与刷新、文案与结构、图谱工作台(§7.6) |
|
|
86
|
+
| `docs/client-conventions.md` | §7:两个壳一份实现、颜色 token、控件纪律、数据与刷新、文案与结构、图谱工作台(§7.6)、合成负载(§7.7) |
|
|
84
87
|
| `docs/memory-semantics.md` | §8:三层、写入规则、全局记忆、注入(含预设会话首步 `<memory-guide>` 一次性投放)、提示词管理 |
|
|
85
88
|
| `docs/env-and-commands.md` | §9:Windows 跑命令的 env、CRLF 补丁法、本地 link、引擎安装与回滚、本地向量受管运行时的安装/状态命令(§9.5)、MemU CLI 事实 |
|
|
86
89
|
|
|
87
90
|
**W8(助手重复提示)已决定不做,不再重做。** 理由:120 次合成 A/B 未证明改善重复回答率,事实词面完整性反而下降。证据文档已删除,不得据此宣称“已证明任何防复读技术无效”。
|
|
88
91
|
|
|
92
|
+
**整理执行器(实验功能)**:设置 → 记忆维护 →「整理执行器」,`fork`(默认,每窗新 fork)/ `worker`(持久 worker,按 200k 字符 / 16 窗换新)。作用、差异与回滚 → `docs/memory-semantics.md` §8.18。
|
|
93
|
+
|
|
89
94
|
节号跨文件不变:看到「(§8.4)」就去 `docs/memory-semantics.md` 找 §8.4。
|
|
90
95
|
|
|
91
96
|
## 5. 三条容易记反的
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# 更新日志 / Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.5] - 2026-11-14
|
|
4
|
+
|
|
5
|
+
> 修复宿主对同一条用户消息给出两次 `agent/pre-step` 时的重复注入:第二次召回会把已投候选全去重、注入 0 条,还多推一格 memoryClock。现在按真实用户消息 id 幂等,一条消息只注入一次;回合回滚时清标记,真重试仍会重投。
|
|
6
|
+
|
|
7
|
+
### 注入
|
|
8
|
+
|
|
9
|
+
- **一条用户消息只跑一次注入**:`registerInjection` 记录 `lastInjectedUserMessageId`;同一 session 收到同一条用户消息的第二次 enter 决策时只保留 guide 检查,不再召回。压缩后的 reinject(`reinjectPending`)不参与该幂等。
|
|
10
|
+
- **回滚清标记**:`rollbackInjectionForTurn` 撤回本轮账目时一并删除标记,宿主重试同一条消息仍会正常注入。
|
|
11
|
+
|
|
12
|
+
### 文档与测试
|
|
13
|
+
|
|
14
|
+
- `docs/troubleshooting.md` 新增 §3.30(症状 / 根因 / 守卫)与症状速查入口。
|
|
15
|
+
- `tests/injection-rollback.test.mjs` 新增两条:两次 enter 决策只注入一次(memoryClock 不前进、去重账目不增加);回合回滚后重试重投。
|
|
16
|
+
|
|
17
|
+
## [1.3.4] - 2026-11-14
|
|
18
|
+
|
|
19
|
+
> 整理执行器(实验功能)与增量回合日志:设置页可选 fork / 持久 worker(worker 按 200k 字符 / 16 窗换新,窗内批量写);整理快照增加持久日志交叉核对,修掉外部追加不可见导致的整理冻结;WebUI 空闲合成负载归零。产品文档移除 benchmark 记录与文档(测试资产不进产品文档)。
|
|
20
|
+
|
|
21
|
+
### 整理(实验功能)
|
|
22
|
+
|
|
23
|
+
- **设置页可选「整理执行器」**:设置 → 记忆维护 →「整理执行器」,红色「实验功能」标记。`fork`(默认)= 每个窗口新建一次整理会话;`worker` = 跨窗复用同一后台会话,按模型上下文分档换新(≤128k 上下文 → 120k 字符/8 窗,其余 → 200k 字符/16 窗),新 epoch 用交接包接续。切换从下一窗生效,无需重启;「恢复默认」回到 fork,数据层没有依赖。
|
|
24
|
+
- **窗口内批量写**:worker 任务书要求把本窗新增条目合并成一次 `memu_private_remember_batch` 提交,只有 1 条时才逐条写;更新也合并在同一轮。原有「批量参数畸形 → 下一轮退回逐条写」的回退保留。
|
|
25
|
+
- **增量回合日志(`lib/turn-log.js`)**:按回合落盘,作为持久 worker 的上下文缓存;`consolidationTurnLog=off` 时退回现场压缩。配套 `scripts/prune-turnlogs.mjs` 清理旧日志。
|
|
26
|
+
|
|
27
|
+
### 整理可靠性
|
|
28
|
+
|
|
29
|
+
- **快照冷日志交叉核对**:`captureSessionSnapshot` 的活视图落后于持久日志时,用 `sessionPersistence` + `readColdSessionLog` 冷读取更长的一份(source `persisted-ahead`,60s TTL 缓存),避免外部追加不可见导致的快照冻结与整理洪水。
|
|
30
|
+
- **不无意义 resume**:`consolidationModelMode` 为 `host` / `custom` 时不再探测父会话 route,避免把父会话钉成活视图。
|
|
31
|
+
|
|
32
|
+
### WebUI
|
|
33
|
+
|
|
34
|
+
- **空闲合成负载归零**:装饰层去掉无限动画与常驻 `will-change`,`backdrop-filter` 只保留 topbar 与 boot 卡,缩略图改由主画布 `onPaint` 驱动;新增 `scripts/check-idle-compositing.mjs` 真机数帧(空闲 fps > 2 即 FAIL)与 `tests/webui.test.mjs` 静态守卫。
|
|
35
|
+
|
|
36
|
+
### 文档
|
|
37
|
+
|
|
38
|
+
- `docs/memory-semantics.md` 新增 §8.18:整理执行器的作用、fork 与 worker 的差异、epoch/交接/批量写边界与回滚方式。
|
|
39
|
+
- `docs/troubleshooting.md` 新增 §3.28(WebUI 空闲合成负载)与 §3.29(外部追加导致快照冻结);`docs/client-conventions.md` 新增 §7.7(合成负载约定)。
|
|
40
|
+
- `AGENTS.md` §4 增加实验功能指针;移除 benchmark 实测引用。
|
|
41
|
+
- `README.md` / `README.zh.md` 移除 Benchmark/基准测试章节与交叉引用;`CHANGELOG.md` 移除历史 benchmark 成绩记录;删除 `docs/recall-benchmark.md`。测试与 harness 代码保留在仓库内,产品文档不再包含 benchmark 记录。
|
|
42
|
+
|
|
3
43
|
## [1.3.3] - 2026-11-13
|
|
4
44
|
|
|
5
45
|
> 小修复与体验优化版本:关系图谱最小缩放下「节点打架 / 闪现」的根因修掉(分离阈值曾跟缩放挂钩),开着图谱不再白吃 GPU,宿主设置页导航不再被掰竖;记忆库与记忆浏览新增「立即整理」与库内搜索;图谱产物纳入 `npm run check` 漂移闸门,README 截图与图注重录。
|
|
@@ -82,7 +122,7 @@
|
|
|
82
122
|
|
|
83
123
|
## [1.3.0] - 2026-11-08
|
|
84
124
|
|
|
85
|
-
> 整理成本与可靠性:worker 工具面 14 → 6、remember/update schema 压缩、窗口 500 事件 / 每窗上限 8 条;新增本地零 Token 的“必写候选”与跨窗顺延;回执对账改为以库 diff 为权威,`snapshot-failed`
|
|
125
|
+
> 整理成本与可靠性:worker 工具面 14 → 6、remember/update schema 压缩、窗口 500 事件 / 每窗上限 8 条;新增本地零 Token 的“必写候选”与跨窗顺延;回执对账改为以库 diff 为权威,`snapshot-failed` 不再被当成完成。
|
|
86
126
|
|
|
87
127
|
### 整理成本
|
|
88
128
|
|
|
@@ -169,7 +209,6 @@
|
|
|
169
209
|
|
|
170
210
|
### 评测
|
|
171
211
|
|
|
172
|
-
- [chat-memory-benchmark](https://github.com/Ornn8/chat-memory-benchmark) 714 题完整卷(2026-11-06,`dys-router / deepseek-v4.1-flash`,high 思考强度):通过 **653 / 714(91.46%)**;同轮**实测记忆成本 ¥16.05**,含非记忆开销的总成本 ¥24.45(谷价,总 token 75,517,851)。
|
|
173
212
|
- 全量 **1473 tests / 1471 pass / 0 fail / 2 skipped**、acceptance 50/50、`npm run check` 全绿。
|
|
174
213
|
- 升级兼容:旧条目缺新字段按空处理,不强制迁移;`disclosure` 行为有变(`never_say` / `only_if_asked` 不再自动注入),需要它们自动出现的旧用法请改回 `can_tell`。
|
|
175
214
|
|
|
@@ -185,7 +224,6 @@
|
|
|
185
224
|
- **召回缓存(`lib/recall-cache.js`)**:`managedRecall` 成功语义召回段进程内 LRU(256 条 / 120s),键含 `memoryRevision()`(全部索引/状态落盘自增,写后无 stale)+ 向量代数 + domain/sessionId/context 等九分量;fail-open + `warn` 留痕,降级/fallback 结果一律不缓存。显式召回命中率 ~0 属正确行为(touchAccess 参与 decay 加成)。文档见 `docs/memory-semantics.md` §8.12。
|
|
186
225
|
- **冲突检测增强**:新增 `polarityAt` 子句级否定作用域(双重否定、对比结构分段、无关子句隔离),`globalConflictCheck` 改用共享锚点双侧极性对比(无共享词回退整文本口径);修复「截止日期 5月1日,别忘了」类无关子句否定与「不是不喜欢」双重否定两类误报。`negationPolarity` 原口径与导出不变。
|
|
187
226
|
- **修复:整理 fork 在 DSH 0.2.2-rc.1 上必挂**——rc.1 的种子校验(`assertAssistantSettlementShape`)要求 `assistant/message.data.stream` 是数组,而插件种子清噪曾直接删除该字段,导致 0.2.2-rc.1 上每个整理 fork 种子被拒("invalid settlement fields";**1.2.6 已发布版同样中招**——`host-adaptation.md` §5.4 声明的未测面被内部真机评测实证)。修复:种子携带**空 stream 数组**(清噪初衷不变——分块日志不进种子;旧宿主不校验该字段,惰性兼容)。新增 `scripts/check-seed-compat.mjs`(用目标宿主自己的 dsh-session 包验证种子兼容性),列入宿主适配检查表必跑项。
|
|
188
|
-
- **基准台(`scripts/bench-recall.mjs`)**:确定性合成语料前后对照。终局:全量 **1406 tests / 1404 pass / 0 fail / 2 skipped**、acceptance 50/50;簇构建较 1.2.6 快约 3%(5041→~4900ms);Recall@10 与基线持平(0.7650 vs 0.7675,差 1/400 条,MRR 0.4200 vs 0.4218)——合成基准只能当回归门。
|
|
189
227
|
- **守卫**:新增 4 个测试文件共 58 条(tokenizer-v2 17、dynamic-rrf 11、recall-cache 14、negation-polarity 14、边界带守卫 2);阈值常量零改动。
|
|
190
228
|
|
|
191
229
|
### RP/混合提示词:生活日常采集线
|
package/README.md
CHANGED
|
@@ -30,11 +30,7 @@ It is **local-first by default**. The default `agent` backend stores full text i
|
|
|
30
30
|
> [!WARNING]
|
|
31
31
|
> **Early-stage software.** This plugin is still early and may contain unforeseen errors, bugs or breaking changes. Back up your data, and please [report an issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) or send a pull request — feedback helps the project improve.
|
|
32
32
|
|
|
33
|
-
> **Status:** 1.3.
|
|
34
|
-
|
|
35
|
-
## Benchmark
|
|
36
|
-
|
|
37
|
-
The public [chat-memory-benchmark](https://github.com/Ornn8/chat-memory-benchmark) full 714-question run (2026-11-06, `dys-router / deepseek-v4.1-flash`, high reasoning) passed **653 / 714 (91.46%)**. The run's actual measured memory cost was **¥16.05**; the full run, including non-memory overhead, cost **¥24.45** (75,517,851 tokens total, at the provider's off-peak rate) — measured end to end, not extrapolated from a single session.
|
|
33
|
+
> **Status:** 1.3.5. The first public release was 1.0.0. The manual now lives in [`docs/`](docs/), with [`AGENTS.md`](AGENTS.md) as a short index. Back up `~/.dsh/dsh-memu-memory` before upgrades, and read [Compatibility & limits](#compatibility--limits) before storing data you cannot re-create.
|
|
38
34
|
|
|
39
35
|
## Screenshots
|
|
40
36
|
|
|
@@ -90,8 +86,6 @@ Four real long sessions from this machine were replayed read-only (no new chat)
|
|
|
90
86
|
|
|
91
87
|
Below-threshold turns on the two small sessions can still wake through starvation; on the 2,000+ event sessions they do not. None of the four had new human input after its real cursor, so none would fork again immediately.
|
|
92
88
|
|
|
93
|
-
End-to-end accuracy and the measured cost of the 714-question run are in [Benchmark](#benchmark).
|
|
94
|
-
|
|
95
89
|
## One WebUI
|
|
96
90
|
|
|
97
91
|
The sidebar has exactly **one** entry: **MemU WebUI**. The memory wall and all settings live in the same navigation, with deep links such as `#/settings/memories`, `#/settings/folders` and `#/settings/stats`. The interface follows the browser locale (Chinese or English).
|
package/README.zh.md
CHANGED
|
@@ -30,11 +30,7 @@
|
|
|
30
30
|
> [!WARNING]
|
|
31
31
|
> **早期版本提示。** 本插件仍处于早期阶段,可能存在无法预见的错误、bug 或不兼容变更。请先备份数据;欢迎[提交 Issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) 或 PR 帮助改进。
|
|
32
32
|
|
|
33
|
-
> **状态:** 1.3.
|
|
34
|
-
|
|
35
|
-
## 基准测试
|
|
36
|
-
|
|
37
|
-
公开的 [chat-memory-benchmark](https://github.com/Ornn8/chat-memory-benchmark) 714 题完整卷(2026-11-06,`dys-router / deepseek-v4.1-flash`,high 思考强度)通过 **653 / 714(91.46%)**。同一轮**实测记忆成本为 ¥16.05**;包含非记忆开销的总成本为 **¥24.45**(总 token 75,517,851,谷价),均为端到端实测,不是按单次会话外推。
|
|
33
|
+
> **状态:** 1.3.5。首个公开发布版本为 1.0.0。细节文档已迁到 [`docs/`](docs/),[`AGENTS.md`](AGENTS.md) 只做索引。升级前请备份 `~/.dsh/dsh-memu-memory`;如果要存无法重建的数据,请先读[兼容性与边界](#兼容性与边界)。
|
|
38
34
|
|
|
39
35
|
## 界面
|
|
40
36
|
|
|
@@ -89,8 +85,6 @@
|
|
|
89
85
|
|
|
90
86
|
两条小会话的未达分数回合仍可能因饥饿唤醒;2000 条事件以上的大会话不会。四个会话在真实游标之后都没有新的真人输入,因此不会立即再 fork。
|
|
91
87
|
|
|
92
|
-
714 题完整卷的通过率与实测成本见[基准测试](#基准测试)。
|
|
93
|
-
|
|
94
88
|
## 一个 WebUI
|
|
95
89
|
|
|
96
90
|
侧边栏只留**一个**入口:**MemU WebUI**。记忆墙与全部设置在同一套导航内,支持深链,如 `#/settings/memories`、`#/settings/folders`、`#/settings/stats`。
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -54,4 +54,14 @@
|
|
|
54
54
|
- **缩略图只跟主画布重绘**:`createGraphView` 的 `onPaint` 计数不变就不 `drawImage`,否则缩略图按自己的节奏重画,和主画布对不上。
|
|
55
55
|
- **整理入口不新增 RPC**:「立即整理」= `listSessions`(带 `libraryId`)筛出该库绑定的会话,再逐个调用侧边栏同一个 `generatePrivate`,两段确认。UI 专用的写方法同时也是一条模型能调的写路径,能复用就别新开。
|
|
56
56
|
|
|
57
|
+
### 7.7 合成负载(GPU 占用)
|
|
58
|
+
|
|
59
|
+
WebUI 的 GPU 问题几乎从来不是算力,是**空闲期仍在持续产帧**:合成器每帧有活干,时钟就降不下来(外部实测:开面板 GPU 时钟 765→1950MHz、功耗 29→72W,util 却只有三四成;关面板立刻回落)。
|
|
60
|
+
|
|
61
|
+
- **装饰层不许有无限动画。** 全屏模糊光斑、品牌图标浮动、状态点脉冲这类 `animation: … infinite` 会让合成器永远不睡。要动效只给交互触发的一次性动画;boot 遮罩例外(ready 后 900ms 移除)。`will-change` likewise 不许常驻在装饰层上。
|
|
62
|
+
- **模糊只给小 chrome。** `backdrop-filter` 只允许 topbar 与 boot 卡;rail、卡片、抽屉、全屏遮罩一律不用——背后只要有东西在动,这些面每帧重算模糊,成本相乘。遮罩用纯色 scrim 就够。
|
|
63
|
+
- **缩略图/副画布由主画布 `onPaint` 驱动**,不许自己 `setInterval` 轮询;主画布冷下来不重绘,副画布就一帧不画。
|
|
64
|
+
- **改完要量**:`node scripts/check-idle-compositing.mjs`(先起预览)用 CDP screencast 数帧 + `document.getAnimations()`,空闲 fps > 2 即 FAIL。静态守卫在 `tests/webui.test.mjs` 的 `the shell keeps no always-on compositor drivers`。
|
|
65
|
+
- **对照环境要先验**:若桌面本身被别的进程钉住时钟(不开浏览器也高频),真 GPU 前后对照在那台机器上无效;以帧计数为准,或到「关面板立刻回落」的宿主上复测。
|
|
66
|
+
|
|
57
67
|
---
|
package/docs/contributing.md
CHANGED
|
@@ -44,6 +44,7 @@ npm run check # node --check + i18n 键对齐 + package.j
|
|
|
44
44
|
|---|---|
|
|
45
45
|
| 任何行为变化 | `README.md` 的能力/限制段(写「谁受益」不写「改了哪个函数」)+ `docs/troubleshooting.md` §3 对应小节的「会坏在哪」 |
|
|
46
46
|
| UI 界面变化 | 两份 README 的截图也是产物:起预览后 `node scripts/make-readme-shots.mjs` 重录 `assets/screenshots/*.jpg`,并核对图注文字还描述得对(1.3.3 之前就漏过「关系图谱」独立成页,图注仍写着「与邻接列表同视图」) |
|
|
47
|
+
| UI 动效 / 模糊 / 副画布 | 合成负载(§7.7):装饰层不许无限动画、模糊只给小 chrome、副画布由 `onPaint` 驱动;改完跑 `node scripts/check-idle-compositing.mjs` 数空闲帧 | `webui`(静态守卫) |
|
|
47
48
|
| 设计决策 / 取舍 | `README.md` 限制段 + `docs/memory-semantics.md` §8(**只写为什么,不写施工流水**) |
|
|
48
49
|
| 影响验收方式 | 能自动化的进 `scripts/acceptance-local.mjs`,行为级的进 `tests/`;都进不了说明还没想清楚 |
|
|
49
50
|
| 新增能力 / 数据结构 | `README.md` 能力表 + `tests/` 或验收脚本 |
|
package/docs/memory-semantics.md
CHANGED
|
@@ -228,3 +228,20 @@
|
|
|
228
228
|
**可观测性**:`getState` 增加 `recallCache` 段(`hits/misses/evictions/errors/staleSkipped/generations/...`);`staleSkipped` 统计 TTL 过期、代数清理与按 query 失效时被丢弃的缓存条目。
|
|
229
229
|
|
|
230
230
|
守卫:`tests/temporal.test.mjs`、`tests/memory-fields.test.mjs`、`tests/fact-version.test.mjs`、`tests/inject-conflict.test.mjs`、`tests/speaker-provenance.test.mjs`、`tests/commitment.test.mjs`、`tests/query-decompose.test.mjs`、`tests/recall-intent.test.mjs`、`tests/injection-intent-budget.test.mjs`、`tests/memory-chain.test.mjs`。
|
|
231
|
+
|
|
232
|
+
### 8.18 整理执行器(实验功能):fork 与持久 worker
|
|
233
|
+
|
|
234
|
+
**作用**:决定私有记忆整理在后台以什么形态执行。入口是设置 → 记忆维护 →「整理执行器」(带红色「实验功能」标记),键为 `consolidationRunner`:`fork`(默认)或 `worker`。切换从下一窗生效,不需要重启;「恢复默认」回到 `fork`。两条路径写同一套账本与库,回滚不涉及数据迁移(turn-log 只是缓存,账本与库才是权威)。
|
|
235
|
+
|
|
236
|
+
**fork(默认)**:每个整理窗口新建一次后台整理会话,窗口结束即弃。上下文最干净、单窗开销稳定,是现有生产路径与回滚路径。
|
|
237
|
+
|
|
238
|
+
**worker(实验)**:跨窗复用同一个后台 worker 会话。
|
|
239
|
+
|
|
240
|
+
- **换新**:acquire 时按模型上下文分档检查预算——≤128k 上下文 → 120k 字符 / 8 窗,其余 → 200k 字符 / 16 窗;字符预算或窗口上限到顶、scope 变化、空闲超时、回合失败、连续两次超时都会退役换新。
|
|
241
|
+
- **交接**:除 scope 变化外,新 epoch 用交接包接续——已结算尾部(≤20k 字符)+ 已写入摘要(最近 20 条 id + 标题)+ 记忆目录头;未结算的增量仍按窗口原文下发。尾部只是跨窗指代的参考,不是正确性防线;去重仍由目录、已写入摘要与库级去重兜底。
|
|
242
|
+
- **批量写**:任务书要求把本窗新增条目合并成一次 `memu_private_remember_batch`,只有 1 条时才逐条 `remember`,更新也放在同一轮;批量参数畸形时下一轮退回逐条写(`consolidationSingleOnly`),不会把整窗判死。
|
|
243
|
+
- **代价**:worker 的会话内上下文会随窗口累积,token 总量取决于换新节奏;fork 没有这段累积。
|
|
244
|
+
|
|
245
|
+
**边界**:worker 仍运行在父预设的 system prompt 下(宿主没有公开 API 可替换),身份靠任务书缓解而不是消除;工具面只有 remember / remember_batch / update;失败窗口保持 pending,按原有退避重试。
|
|
246
|
+
|
|
247
|
+
守卫:`tests/worker-lifecycle.test.mjs`(分档、预算、退役、交接、工具面)、`tests/settings-coverage.test.mjs`(`consolidationRunner` 可设置且默认值合法)、`tests/ui-defaults.test.mjs`。
|
package/docs/troubleshooting.md
CHANGED
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
本地向量模型装不上 / 切不过去 / 召回 400 → §3.25
|
|
37
37
|
整理超时(fork 预算不够)→ §3.26
|
|
38
38
|
图谱改了没生效 / 缩到最小打架 / 导航被掰竖 → §3.27
|
|
39
|
+
WebUI 开着 GPU 占用高 / 时钟钉高档 → §3.28
|
|
40
|
+
长链跑批库不增长 / 考试大面积「不知道」→ §3.29
|
|
41
|
+
同一条用户消息每轮注入两次 / 第二次召回 0 条 → §3.30
|
|
39
42
|
```
|
|
40
43
|
|
|
41
44
|
## 3. 出过的问题:症状 → 落点 → 守卫
|
|
@@ -337,6 +340,22 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
|
|
|
337
340
|
|
|
338
341
|
**守卫**:`tests/graph-view.test.mjs` 的 `relayout cools down and separates instead of shoving nodes forever`(位移逐窗衰减 + 零重合 + 物理拿不到相机)、`a cooled layout stops requesting frames even while motion is enabled`(冷下来零帧,GPU 不再爬升)、`hover keeps its target through 1px jitter at minimum zoom`(命中迟滞);`tests/client-render.test.mjs` 的 `the immersive graph shell stays with the standalone WebUI`(宿主页保持横排 + 一个入口按钮)。`npm run check` 的 `graph bundle` 拦产物漂移。
|
|
339
342
|
|
|
343
|
+
### 3.28 WebUI 开着 GPU 占用高 / 时钟钉在高档 / 风扇转
|
|
344
|
+
|
|
345
|
+
**症状**:打开 WebUI 后 Electron/浏览器 GPU 进程占用翻倍、GPU 时钟从低频钉到接近满载、功耗上涨,而利用率并不高;关掉面板立刻回落,可重复。典型读数(外部测试者,1.3.3):GPU 12.7%→24.8%,时钟 765→1950MHz(满 2100),功耗 29→72W,util 仅 37–44%。**这是持续合成,不是算力占用**:合成器每帧都有活干,时钟就降不下来。
|
|
346
|
+
|
|
347
|
+
**落点**(1.3.3 实测,按贡献排):
|
|
348
|
+
- **装饰层的无限动画**。`standalone.css` 的 `.ambient i` 曾是全屏 `filter: blur(74px)` + `will-change: transform` + `ambient-drift 52s infinite alternate`:一个永远在动的全屏模糊层,合成器永远不睡。同族还有 `.brand-icon` 的 `brand-float 7s infinite`、`.sync-pill i` 的 `dot-pulse 2.8s infinite`。实测空闲产帧 ~99fps,`document.getAnimations()` 列出 5 条 running;**图谱页冷却后也照跑**,因为光斑层在整页背后。
|
|
349
|
+
- **大面 backdrop-filter**。抽屉遮罩 `.dshm-drawer-backdrop` 的全屏 `blur(3px)`、独立壳的 rail / 卡片 / 抽屉 `blur(16–22px)`:背后只要有东西在动(上一条),这些面每帧都要重算模糊,成本相乘。
|
|
350
|
+
- **缩略图轮询**。`GraphStudioMinimap` 曾 `setInterval(paint, 600)`;即使加了「主画布没重绘就不拷贝」的闸门,定时器本身仍常开。现改由主画布 `onPaint` 直接驱动,零定时器。
|
|
351
|
+
- 心跳 `useMemoryBeat` **不是**元凶:marker 不变就 return,不会每 2.5s 重渲染(外部猜测的第 3 条在当前代码不成立)。
|
|
352
|
+
|
|
353
|
+
**现在**:装饰层静态(光斑保留观感、去掉动画与 will-change);模糊只留在小 chrome(topbar)与 boot 卡(boot 900ms 后移除);抽屉遮罩改纯色 scrim;缩略图由 `onPaint` 驱动。实测同三态空闲产帧 99fps → **0.2fps(6 秒 1 帧)**,running 动画清单为空。
|
|
354
|
+
|
|
355
|
+
**怎么自己量**:`node scripts/check-idle-compositing.mjs`(先起预览)用 CDP screencast 数帧 + `document.getAnimations()`;空闲 fps > 2 即 FAIL。**注意对照环境**:若桌面本身被别的进程钉住时钟(本机对照:不开浏览器也 2250MHz),真 GPU 的前后对照在这台机器上无效,要以帧计数为准,或到「关面板立刻回落」的那台宿主上复测。
|
|
356
|
+
|
|
357
|
+
**守卫**:`tests/webui.test.mjs` 的 `the shell keeps no always-on compositor drivers`(无限动画只许出现在 boot;ambient 不许 will-change/animation;backdrop-filter 只许 topbar/boot-card;共享 UI 不许全屏模糊;缩略图不许轮询)+ `scripts/check-idle-compositing.mjs` 真机数帧。
|
|
358
|
+
|
|
340
359
|
|
|
341
360
|
## 守卫索引表
|
|
342
361
|
|
|
@@ -372,6 +391,8 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
|
|
|
372
391
|
| §3.25 | 本地向量模型装不上 / 切不过去 / 召回 400 | `tests/embedding-catalog.test.mjs`(三条目指纹钉死、只有非对称前缀需要角色通道)、`tests/local-embedding-protocol.test.mjs`、`tests/local-embedding-worker.test.mjs`(前缀进推理、裸 id 拒且不入推理)、`tests/local-embedding-env.test.mjs`(对称模型 model 串逐字节不变)。 |
|
|
373
392
|
| §3.26 | 整理超时(fork 预算) | `tests/consolidation-fork.test.mjs`:预算随事件数缩放(0/100/200/935/5000/非法值),显式 `maxWaitMs` 仍生效,超时不推进 `lastSleepSeq`。 |
|
|
374
393
|
| §3.27 | 图谱改了没生效 / 缩到最小打架 / 导航被掰竖 | `npm run check` 的 `graph bundle`(源码与 bundle 逐字节比对);`tests/graph-view.test.mjs` 的 relayout 收敛、冷启动零帧、最小缩放命中迟滞;`tests/client-render.test.mjs` 的独立外壳归属。 |
|
|
394
|
+
| §3.28 | WebUI 开着 GPU 占用高 / 时钟钉高档 | `tests/webui.test.mjs` 的 `the shell keeps no always-on compositor drivers`(无限动画只许 boot、ambient 静态、模糊只许小 chrome、缩略图不轮询);`scripts/check-idle-compositing.mjs` 真机数帧(空闲 fps > 2 即 FAIL)。 |
|
|
395
|
+
| §3.30 | 同一条用户消息每轮注入两次 | `tests/injection-rollback.test.mjs` 的 one-pass 幂等与回滚清标记两条(同一消息 id 只注入一次;回滚后重试重投)。 |
|
|
375
396
|
|
|
376
397
|
## 附录 A · 模块地图(原 §2.1)
|
|
377
398
|
|
|
@@ -490,6 +511,8 @@ section 的 `text(context)` 能拿到 `context.agent`,所以 system prompt **
|
|
|
490
511
|
8. **不碰共享 `/api`**:RPC 只走 `/dsh-memu-memory` 前缀(`webServer.register` + `connection.requestRejection`)。
|
|
491
512
|
9. **日志与提示词里不放 API key。**
|
|
492
513
|
10. **注入失败 fail-open,但必须留可观测信号。** 抛错不许改变宿主的 turn 错误语义(吞掉是允许的),代价是真实故障一起被吞:`inject.js` 若把 pre-step 的 `agent` 当 `exec` 传给 `buildRecall`(正确形状 `{ agent }`,§6.3),`no bound session` 就只被空 catch 吃掉——**每回合召回静默失效、只剩锚点、日志一个字都没有**。所以 fail-open 必配 `logger.warn` + binding 上的 `lastRecallError`(侧边栏可见),单测断言**召回到的 id**,不能只断言「消息插进去了」。**不能靠「没报错就是好了」。**
|
|
514
|
+
11. **跑批与复测的输出一律重定向文件**(`> logs/x.log 2>&1`),禁用 `| tail` 管道——管道只留尾巴,故障段不可回查。清理宿主数据必须先确认宿主进程完全退出(活宿主的内存态会回写覆盖清理结果)。
|
|
515
|
+
12. **整理快照必须做持久日志交叉核对**:`captureSessionSnapshot` 的活视图(observeSession/readSession)落后于持久日志时,用 `sessionPersistence` + `readColdSessionLog` 冷读并取更长的日志(source `persisted-ahead`);只信活视图 = 外部追加不可见 → 快照冻结/整理洪水。`host`/`custom` 模型模式也不得探测父会话 route(resume 会把父会话钉成活视图)。成因链与排错路线 → §3.29。
|
|
493
516
|
|
|
494
517
|
---
|
|
495
518
|
|
|
@@ -545,3 +568,21 @@ section 的 `text(context)` 能拿到 `context.agent`,所以 system prompt **
|
|
|
545
568
|
- **实体确认后没有提及边**:确认只匹配已确认实体的名字/别名;检查名字是否 <2 字、记忆是否 archived/pending_review/secret、实体是否 archived(archived 不可确认)、抑制表是否有同名 (from,to,kind) 键(删过的边会写 `|*` 通配,换 rule 也不复活)、以及 `autoLinkMode` 是否为 `off`(off 连确认也不写)。worker 通过 `memu_private_link` 新建的实体默认 provisional,需要用户在审核区确认。
|
|
546
569
|
- **worker 没裁决不确定候选**:`memu_private_link_suggest` 现在只刷新确定性边并返回统计候选卡,不自动连;worker 未调用或证据不足就保持不连(宁漏勿错)。`lib/private.js` 的结算兜底同样只跑确定性判定,不会把统计候选偷偷连上。自动关联失败只写 warn,不影响整理成功。
|
|
547
570
|
- **要不要数据库/向量重算**:自动关联只是 `links[]` 元数据,不改正文、不写向量;移除边不会触发重建。实体删除仍按既有规则(有引用时需显式 force,避免悬空)。
|
|
571
|
+
|
|
572
|
+
### 3.29 长链跑批整库不增长 / 考试大面积「不知道」(S7 整理 → S1 快照冻结 → S3 账本洪水)
|
|
573
|
+
|
|
574
|
+
**症状**:persona 全链复测通过率腰斩;失败判分理由几乎全是「答不知道、否认已有事实」(无编造/越界);库条数远低于全链累积预期(实测 59 ck 只写出 4 条,涉事事实关键词全零命中)。
|
|
575
|
+
|
|
576
|
+
**根因(2026-11-14 复现实测)**:跑批脚本的 `seed-session.mjs` **直接重写** `session.v4.jsonl.zstd` 追加历史(不走网关 RPC)。宿主的 `observeSession`/`readSession` 都是 live-preferred:会话一旦是活对象,两者都读活视图、不再看持久日志,外部改写完全不可见。把种子会话钉成活对象的是 inherit 模式的 `inheritedAgentOptions` resume 回退;`host`/`custom` 模式本不需要父 route,旧代码却照样探测。于是追加 372 轮后活视图仍冻结在 6 事件 → 每窗恒等 → already-consolidated 洪水 → 游标不推进。**连带**:turn-log 录制器只收 `session/event`,直接改文件同样看不到。跑批侧 `consolidateAll` 又把 already-consolidated 当完成,不校验 `throughSeq`,把可检测故障变成静默腰斩。
|
|
577
|
+
|
|
578
|
+
**守卫**:`captureSessionSnapshot` 在活视图落后于持久日志时,用 `sessionPersistence` + 宿主公开导出的 `readColdSessionLog` 冷读,取更长的一份(source `persisted-ahead`;60 秒 TTL 缓存,正常活会话不受影响)。`consolidationModelMode` 为 `host`/`custom` 时不探测父会话 route,避免无意义 resume。跑批的 `consolidateAll` 对 skipped 结果校验 `through >= targetSeq`,连续 3 次落后判定 `stale` 并终止本轮。
|
|
579
|
+
|
|
580
|
+
### 3.30 同一条用户消息每轮注入两次(第二次召回 0 条)
|
|
581
|
+
|
|
582
|
+
**症状**:WebUI 时间线里每条用户消息后出现两条「上下文注入 · plugin:dsh-memu-memory」;召回记录成对出现(例如 13:41:41 注入 4 条 / 0 条,13:45:14 / 13:45:15),turn 号成对跳(221→222、223→224)。不报错,第二次只是纯空跑。
|
|
583
|
+
|
|
584
|
+
**根因**:宿主对同一条真实用户消息给出两次 `agent/pre-step` enter 决策;插件把每次 pre-step 都当成新的一轮,重新召回。第一次已把候选记入 `injectedIds`,第二次候选全被去重,注入 0 条,同时把 memoryClock 多推一格。
|
|
585
|
+
|
|
586
|
+
**现在**:`registerInjection` 按真实用户消息 id 幂等(`binding.lastInjectedUserMessageId`)——一条消息只跑一次注入;`turn/end` 失败且注入没进转录时,`rollbackInjectionForTurn` 清掉标记,真重试仍会重投;压缩后的 reinject(`reinjectPending`)不受影响。
|
|
587
|
+
|
|
588
|
+
**守卫**:`tests/injection-rollback.test.mjs` 的 `the same real user message gets one injection pass when the host emits two enter decisions`、`a rolled-back turn clears the one-pass marker so a real retry injects again`。
|
|
@@ -54,9 +54,9 @@ 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:982', 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
|
-
{ layer: 'cache', file: 'lib/state.js:
|
|
59
|
+
{ layer: 'cache', file: 'lib/state.js:1233', 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' },
|
|
61
61
|
])
|
|
62
62
|
|
package/lib/client.js
CHANGED
|
@@ -421,6 +421,11 @@ window.__ModuleLoader__.load({
|
|
|
421
421
|
consolidationReasoningMedium: '中',
|
|
422
422
|
consolidationReasoningHigh: '高',
|
|
423
423
|
consolidationReasoningHint: '只影响后台整理 worker。抽测中 medium 的整理成本最低,通过数不低于 off/high;off 在该路由下仍会产生推理。',
|
|
424
|
+
consolidationRunner: '整理执行器',
|
|
425
|
+
consolidationRunnerFork: '每窗新 fork(默认)',
|
|
426
|
+
consolidationRunnerWorker: '持久 worker(省上下文)',
|
|
427
|
+
consolidationRunnerHint: 'fork 每窗新建一次整理会话,上下文最干净;worker 跨窗复用同一会话,按 200k 字符/16 窗换新,整理 token 约少一半,但会话内上下文会累积。切换从下一窗生效,无需重启。',
|
|
428
|
+
consolidationRunnerExperimental: '实验功能',
|
|
424
429
|
consolidationModeInherit: '继承当前会话',
|
|
425
430
|
consolidationModeHost: '指定宿主模型',
|
|
426
431
|
consolidationModeCustom: '自定义接入点',
|
|
@@ -1360,6 +1365,11 @@ window.__ModuleLoader__.load({
|
|
|
1360
1365
|
consolidationReasoningMedium: 'Medium',
|
|
1361
1366
|
consolidationReasoningHigh: 'High',
|
|
1362
1367
|
consolidationReasoningHint: 'Only affects the background consolidation worker. In the sampled run, medium had the lowest consolidation cost and no fewer passes than off/high; off still produced reasoning on this route.',
|
|
1368
|
+
consolidationRunner: 'Consolidation runner',
|
|
1369
|
+
consolidationRunnerFork: 'Fresh fork per window (default)',
|
|
1370
|
+
consolidationRunnerWorker: 'Persistent worker (less context)',
|
|
1371
|
+
consolidationRunnerHint: 'fork starts a new consolidation session every window (cleanest context); worker reuses one session across windows and rotates every 200k chars / 16 windows — roughly half the consolidation tokens, at the cost of accumulating context inside the session. Applies from the next window; no restart needed.',
|
|
1372
|
+
consolidationRunnerExperimental: 'Experimental',
|
|
1363
1373
|
consolidationModeInherit: 'Inherit the conversation',
|
|
1364
1374
|
consolidationModeHost: 'Pick a host model',
|
|
1365
1375
|
consolidationModeCustom: 'Custom endpoint',
|
|
@@ -2072,8 +2082,8 @@ window.__ModuleLoader__.load({
|
|
|
2072
2082
|
browser: the list keeps its filters, scroll position and context. */
|
|
2073
2083
|
.dshm-wall-views{margin:2px 0 4px}
|
|
2074
2084
|
.dshm-wall-graph{margin-top:4px}
|
|
2075
|
-
.dshm-drawer-backdrop{position:fixed;inset:0;z-index:80;display:flex;justify-content:flex-end;background:rgba(10,14,22,.38)
|
|
2076
|
-
.dshm-drawer{width:min(480px,100%);height:100%;overflow-y:auto;display:flex;flex-direction:column;gap:10px;padding:22px;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,inherit);border-left:1px solid var(--dsw-alias-border-l1,#ddd);box-shadow:-24px 0 60px -34px rgba(0,0,0,.45);animation:dshm-drawer-in .3s cubic-bezier(.22,1,.36,1)
|
|
2085
|
+
.dshm-drawer-backdrop{position:fixed;inset:0;z-index:80;display:flex;justify-content:flex-end;background:rgba(10,14,22,.38);animation:dshm-fade-in .2s ease both}
|
|
2086
|
+
.dshm-drawer{width:min(480px,100%);height:100%;overflow-y:auto;display:flex;flex-direction:column;gap:10px;padding:22px;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,inherit);border-left:1px solid var(--dsw-alias-border-l1,#ddd);box-shadow:-24px 0 60px -34px rgba(0,0,0,.45);animation:dshm-drawer-in .3s cubic-bezier(.22,1,.36,1) backwards}
|
|
2077
2087
|
.dshm-drawer-head{display:flex;align-items:flex-start;gap:10px}
|
|
2078
2088
|
.dshm-drawer-title{margin:4px 0 6px;font-size:17px;font-weight:650;line-height:1.3;overflow-wrap:anywhere}
|
|
2079
2089
|
.dshm-drawer-meta{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
|
@@ -2424,7 +2434,10 @@ html[data-standalone]:has(.dshm-root.is-graph-navless) .stage{padding-left:28px;
|
|
|
2424
2434
|
.dshm-x:hover{opacity:1;background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.1));color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
2425
2435
|
.dshm-x:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#2563eb);outline-offset:1px}
|
|
2426
2436
|
|
|
2427
|
-
|
|
2437
|
+
/* 入场动画用 backwards 而非 both:both 会在动画结束后仍保留末帧的 transform
|
|
2438
|
+
(哪怕是单位矩阵),Chromium 据此给元素建立 containing block,把内部
|
|
2439
|
+
position:fixed 的抽屉遮罩困在页面列里——遮罩盖不住顶栏/侧栏、抽屉整体偏移。 */
|
|
2440
|
+
.dshm-page{min-width:0;display:flex;flex-direction:column;gap:13px;animation:dshm-page-in .26s cubic-bezier(.22,1,.36,1) backwards}
|
|
2428
2441
|
.dshm-head{margin:2px 0 5px}
|
|
2429
2442
|
.dshm-overline{font-size:10.5px;font-weight:700;letter-spacing:.18em;text-transform:uppercase;color:var(--dsw-alias-brand-primary,#2563eb);opacity:.9}
|
|
2430
2443
|
.dshm-h1{margin:4px 0 0;font-size:21px;font-weight:700;letter-spacing:-.01em}
|
|
@@ -2434,7 +2447,7 @@ html[data-standalone]:has(.dshm-root.is-graph-navless) .stage{padding-left:28px;
|
|
|
2434
2447
|
and hover that inline styles cannot express. */
|
|
2435
2448
|
.dshm-card{transition:transform .28s ease,box-shadow .28s ease,border-color .28s ease}
|
|
2436
2449
|
.dshm-card:hover{transform:translateY(-2px);box-shadow:0 10px 28px -12px rgba(0,0,0,.28)}
|
|
2437
|
-
.dshm-rise{animation:dshm-rise-in .34s cubic-bezier(.22,1,.36,1)
|
|
2450
|
+
.dshm-rise{animation:dshm-rise-in .34s cubic-bezier(.22,1,.36,1) backwards;animation-delay:calc(var(--d,0) * 38ms)}
|
|
2438
2451
|
.dshm-card-head{display:flex;align-items:flex-start;gap:11px}
|
|
2439
2452
|
.dshm-logrow.is-failed{border-left:2px solid var(--dsw-alias-state-error-primary,#c0392b);background:color-mix(in srgb,var(--dsw-alias-state-error-primary,#c0392b) 7%,transparent)}
|
|
2440
2453
|
.dshm-logrow.is-failed .dshm-logmsg{color:var(--dsw-alias-state-error-primary,#c0392b)}
|
|
@@ -3116,7 +3129,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3116
3129
|
// chrome=false 时外壳(rail / 参数弹层 / 状态栏)由 Graph Studio 工作台自己画,
|
|
3117
3130
|
// 画布与引擎保持同一份实现:拖动、pin、弹簧链、簇作用域都不变。
|
|
3118
3131
|
function GraphCanvas({ graph, focus, onFocus, t, chrome = true, options: controlledOptions = null,
|
|
3119
|
-
apiRef = null, onZoom = null,
|
|
3132
|
+
apiRef = null, onZoom = null, onPaint = null }) {
|
|
3120
3133
|
const ref = React.useRef(null)
|
|
3121
3134
|
const tooltipRef = React.useRef(null)
|
|
3122
3135
|
const viewRef = React.useRef(null)
|
|
@@ -3142,8 +3155,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3142
3155
|
const view = module.createGraphView(canvas, {
|
|
3143
3156
|
onFocus: id => latest.current.onFocus(id),
|
|
3144
3157
|
onZoom: value => { setZoom(value); zoomNotify.current?.(value) },
|
|
3145
|
-
//
|
|
3146
|
-
onPaint: () => {
|
|
3158
|
+
// 主画布每重绘一次通知一次:缩略图由它直接驱动,不自己轮询。
|
|
3159
|
+
onPaint: () => { onPaint?.() },
|
|
3147
3160
|
tooltip: tooltipRef.current,
|
|
3148
3161
|
reducedMotion: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches,
|
|
3149
3162
|
emptyLabel: latest.current.t('graphEmpty'),
|
|
@@ -3269,29 +3282,24 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3269
3282
|
: node.kind !== 'memory' ? (node.status === 'provisional' ? 'provisional' : 'entity') : 'memory'
|
|
3270
3283
|
const gsColor = node => GS_NODE_COLORS[gsKind(node)]
|
|
3271
3284
|
|
|
3272
|
-
function GraphStudioMinimap({ active, t,
|
|
3285
|
+
function GraphStudioMinimap({ active, t, notifyRef = null }) {
|
|
3273
3286
|
const ref = React.useRef(null)
|
|
3274
3287
|
React.useEffect(() => {
|
|
3275
3288
|
if (!active || typeof document === 'undefined') return undefined
|
|
3276
|
-
let last = -1
|
|
3277
3289
|
const paint = () => {
|
|
3278
3290
|
const target = ref.current
|
|
3279
3291
|
if (!target?.getContext) return
|
|
3280
|
-
// 主画布这一帧没重绘就不拷贝:空闲期缩略图不再每秒拷三次大画布纹理。
|
|
3281
|
-
if (paintRef) {
|
|
3282
|
-
const tick = paintRef.current || 0
|
|
3283
|
-
if (tick === last) return
|
|
3284
|
-
last = tick
|
|
3285
|
-
}
|
|
3286
3292
|
const source = document.querySelector('.dshm-gs-stage canvas.dshm-graph-canvas')
|
|
3287
3293
|
const context = target.getContext('2d')
|
|
3288
3294
|
if (!source || !context) return
|
|
3289
3295
|
context.clearRect(0, 0, target.width, target.height)
|
|
3290
3296
|
try { context.drawImage(source, 0, 0, target.width, target.height) } catch {}
|
|
3291
3297
|
}
|
|
3298
|
+
// 只由主画布的 onPaint 驱动:空闲期主画布不重绘,缩略图就一帧不画。
|
|
3299
|
+
// 曾经这里是 setInterval(paint, 600),即使加了计数闸门也仍是一个常开定时器。
|
|
3300
|
+
if (notifyRef) notifyRef.current = paint
|
|
3292
3301
|
paint()
|
|
3293
|
-
|
|
3294
|
-
return () => clearInterval(timer)
|
|
3302
|
+
return () => { if (notifyRef) notifyRef.current = null }
|
|
3295
3303
|
}, [active])
|
|
3296
3304
|
return h('div', { className: 'dshm-gs-minimap' },
|
|
3297
3305
|
h('h4', null, t('gsMinimap')),
|
|
@@ -3361,8 +3369,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3361
3369
|
const addTargetLib = mergedScope ? (addLib || libraries[0]?.id || '') : (showGlobal ? '' : graphLibrary)
|
|
3362
3370
|
const apiRef = React.useRef(null)
|
|
3363
3371
|
const searchRef = React.useRef(null)
|
|
3364
|
-
//
|
|
3365
|
-
const
|
|
3372
|
+
// 缩略图的画笔登记处:主画布 onPaint 直接叫它,空闲期零定时器。
|
|
3373
|
+
const minimapPaint = React.useRef(null)
|
|
3366
3374
|
const beat = `${revision ?? ''}:${stamp ?? ''}`
|
|
3367
3375
|
const notify = message => setToast(message)
|
|
3368
3376
|
|
|
@@ -3706,9 +3714,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
3706
3714
|
|
|
3707
3715
|
const stage = h('main', { className: 'dshm-gs-stage' },
|
|
3708
3716
|
h(GraphCanvas, { graph: canvasGraph, focus, onFocus: setFocus, t, chrome: false,
|
|
3709
|
-
options: canvasOptions, apiRef, onZoom: setZoom,
|
|
3717
|
+
options: canvasOptions, apiRef, onZoom: setZoom, onPaint: () => minimapPaint.current?.() }),
|
|
3710
3718
|
canvasTools,
|
|
3711
|
-
minimap ? h(GraphStudioMinimap, { active: true, t,
|
|
3719
|
+
minimap ? h(GraphStudioMinimap, { active: true, t, notifyRef: minimapPaint }) : null,
|
|
3712
3720
|
h('div', { className: `dshm-gs-toast${toast ? ' show' : ''}`, role: 'status' }, toast),
|
|
3713
3721
|
error ? h('div', { className: 'dshm-gs-toast show', role: 'alert' }, error) : null,
|
|
3714
3722
|
!visibleEdges.length && nodes.length
|
|
@@ -7059,6 +7067,11 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
7059
7067
|
h('option', { value: 'deterministic' }, t('autoLinkDeterministic')),
|
|
7060
7068
|
h('option', { value: 'off' }, t('autoLinkOff')))),
|
|
7061
7069
|
h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('autoLinkHint')),
|
|
7070
|
+
h(Field, { label: h('span', { style: { color: V.danger } }, t('consolidationRunner'), h('span', { style: { marginLeft: 6, fontWeight: 600 } }, t('consolidationRunnerExperimental'))) },
|
|
7071
|
+
h('select', { style: S.input, value: settings.consolidationRunner || 'fork', onChange: (e) => setSetting('consolidationRunner', e.target.value) },
|
|
7072
|
+
h('option', { value: 'fork' }, t('consolidationRunnerFork')),
|
|
7073
|
+
h('option', { value: 'worker' }, t('consolidationRunnerWorker')))),
|
|
7074
|
+
h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('consolidationRunnerHint')),
|
|
7062
7075
|
h(Field, { label: t('consolidationModelMode') },
|
|
7063
7076
|
h('select', { style: S.input, value: consolidationMode, onChange: (e) => setSetting('consolidationModelMode', e.target.value) },
|
|
7064
7077
|
h('option', { value: 'inherit' }, t('consolidationModeInherit')),
|
|
@@ -162,6 +162,77 @@ export function snapshotHash(events, fromSeq, throughSeq) {
|
|
|
162
162
|
return hash.digest('hex')
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
// —— 外部追加恢复:活视图落后于持久日志 ————————————————————————————————
|
|
166
|
+
// sessionQuery 的 observeSession / readSession 都是 live-preferred:同一会话在宿主
|
|
167
|
+
// 里有活对象时,它们读活对象,不再看持久日志。宿主的活会话只随它自己的事件流增长;
|
|
168
|
+
// 如果另一个进程/导入路径直接改写了会话日志(bench 的 seed-session 就是直接重写
|
|
169
|
+
// session.v4.jsonl.zstd 来追加历史),活视图会冻结在旧前缀。这里只在活视图确实
|
|
170
|
+
// 落后于持久日志时改用冷读结果;正常活会话(含尚未落盘的尾部)永远保留活视图。
|
|
171
|
+
const COLD_PROBE_TTL_MS = 60_000
|
|
172
|
+
const COLD_PROBE_CACHE_LIMIT = 64
|
|
173
|
+
const coldProbeCache = new Map()
|
|
174
|
+
|
|
175
|
+
function lastSeqOf(events) {
|
|
176
|
+
const list = Array.isArray(events) ? events : []
|
|
177
|
+
for (let i = list.length - 1; i >= 0; i -= 1) {
|
|
178
|
+
const seq = Number(list[i]?.seq)
|
|
179
|
+
if (Number.isSafeInteger(seq)) return seq
|
|
180
|
+
}
|
|
181
|
+
return -1
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function rememberColdProbe(sessionId, liveLast, coldLast) {
|
|
185
|
+
coldProbeCache.set(sessionId, { liveLast, coldLastSeq: coldLast, at: Date.now() })
|
|
186
|
+
if (coldProbeCache.size <= COLD_PROBE_CACHE_LIMIT) return
|
|
187
|
+
const oldest = coldProbeCache.keys().next().value
|
|
188
|
+
if (oldest !== undefined) coldProbeCache.delete(oldest)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function defaultLoadColdLogModule() {
|
|
192
|
+
return import('@deepseek-ai/dsh-session-query')
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 持久日志比活视图更靠后时,返回冷读的完整日志;否则 null。
|
|
197
|
+
*
|
|
198
|
+
* 只在活视图路径调用。冷读模块(readColdSessionLog)来自宿主公开导出;拿不到持久
|
|
199
|
+
* 化服务或模块时静默降级,绝不影响现有快照路径。短 TTL 缓存避免正常长会话每窗
|
|
200
|
+
* 都做一次整份冷读:冷日志不领先时,60 秒内不重复探测。
|
|
201
|
+
*/
|
|
202
|
+
export async function reconcilePersistedAhead({
|
|
203
|
+
persistence = null, sessionId = null, liveEvents = [], liveHeader = null,
|
|
204
|
+
signal, loadModule = defaultLoadColdLogModule,
|
|
205
|
+
} = {}) {
|
|
206
|
+
if (!persistence || typeof persistence.open !== 'function' || !sessionId) return null
|
|
207
|
+
const key = String(sessionId)
|
|
208
|
+
const liveLast = lastSeqOf(liveEvents)
|
|
209
|
+
const cached = coldProbeCache.get(key)
|
|
210
|
+
if (cached && cached.coldLastSeq <= liveLast && Date.now() - cached.at < COLD_PROBE_TTL_MS) return null
|
|
211
|
+
let mod = null
|
|
212
|
+
try { mod = await loadModule() } catch { return null }
|
|
213
|
+
if (typeof mod?.readColdSessionLog !== 'function') return null
|
|
214
|
+
let log = null
|
|
215
|
+
try { log = await mod.readColdSessionLog(persistence, sessionId, signal) } catch { return null }
|
|
216
|
+
if (!Array.isArray(log?.events)) return null
|
|
217
|
+
const coldLast = lastSeqOf(log.events)
|
|
218
|
+
if (!Number.isSafeInteger(coldLast)) return null
|
|
219
|
+
rememberColdProbe(key, liveLast, coldLast)
|
|
220
|
+
if (coldLast <= liveLast) return null
|
|
221
|
+
// 同一逻辑会话的身份必须一致;不一致说明不是同一份日志,宁可保留活视图。
|
|
222
|
+
try {
|
|
223
|
+
if (liveHeader && typeof mod.assertSessionHeadersCompatible === 'function') {
|
|
224
|
+
mod.assertSessionHeadersCompatible(liveHeader, log.header)
|
|
225
|
+
}
|
|
226
|
+
} catch { return null }
|
|
227
|
+
return {
|
|
228
|
+
source: 'persisted-ahead',
|
|
229
|
+
events: log.events,
|
|
230
|
+
header: log.header || {},
|
|
231
|
+
inheritedEventCount: log.inheritedEventCount,
|
|
232
|
+
cursor: coldLast,
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
165
236
|
function unavailable(reasonCode, message) {
|
|
166
237
|
return { ok: false, code: 'unavailable', reasonCode, retryable: false, error: message }
|
|
167
238
|
}
|
|
@@ -199,11 +270,16 @@ function buildSnapshot({ sessionId, source, events, header, inheritedEventCount,
|
|
|
199
270
|
* code: 'deferred' —— 现在拿不到安全前缀(回合未闭合/半步),下次再试
|
|
200
271
|
* code: 'failed' —— 读失败,可重试
|
|
201
272
|
*/
|
|
202
|
-
export async function captureSessionSnapshot(ctx, sessionId, { signal } = {}) {
|
|
273
|
+
export async function captureSessionSnapshot(ctx, sessionId, { signal, loadColdLogModule } = {}) {
|
|
203
274
|
if (!sessionId) return unavailable('no-session-id', 'a snapshot needs a session id')
|
|
204
275
|
let sessionQuery = null
|
|
205
276
|
try { sessionQuery = ctx?.get?.('sessionQuery') || null } catch { sessionQuery = null }
|
|
206
277
|
if (!sessionQuery) return unavailable('no-session-query', 'the host exposes no sessionQuery service; a safe snapshot cannot be taken')
|
|
278
|
+
const persistence = (() => { try { return ctx?.get?.('sessionPersistence') || null } catch { return null } })()
|
|
279
|
+
const persistedAhead = (events, header) => reconcilePersistedAhead({
|
|
280
|
+
persistence, sessionId, liveEvents: events, liveHeader: header, signal,
|
|
281
|
+
...(loadColdLogModule ? { loadModule: loadColdLogModule } : {}),
|
|
282
|
+
})
|
|
207
283
|
|
|
208
284
|
if (typeof sessionQuery.observeSession === 'function') {
|
|
209
285
|
let lease = null
|
|
@@ -226,6 +302,18 @@ export async function captureSessionSnapshot(ctx, sessionId, { signal } = {}) {
|
|
|
226
302
|
// 租约必须还回去,否则 prepared 条目会一直被 refs 钉在缓存里。
|
|
227
303
|
try { lease?.[Symbol.dispose]?.(lease) } catch {}
|
|
228
304
|
}
|
|
305
|
+
// 活视图可能被宿主的缓存钉住,而持久日志已被外部追加(bench 种子写入)。
|
|
306
|
+
// 只在持久日志确实更靠后时切换,正常活会话不受影响。
|
|
307
|
+
if (source === 'lease-live') {
|
|
308
|
+
const ahead = await persistedAhead(events, header)
|
|
309
|
+
if (ahead) {
|
|
310
|
+
events = ahead.events
|
|
311
|
+
header = ahead.header
|
|
312
|
+
cursor = ahead.cursor
|
|
313
|
+
inheritedEventCount = ahead.inheritedEventCount
|
|
314
|
+
source = ahead.source
|
|
315
|
+
}
|
|
316
|
+
}
|
|
229
317
|
const safe = safePrefix(events, { requireClosedTurn: source === 'lease-live' })
|
|
230
318
|
if (!safe.ok) {
|
|
231
319
|
return deferred(safe.reasonCode, safe.reasonCode === 'no-closed-turn'
|
|
@@ -248,10 +336,18 @@ export async function captureSessionSnapshot(ctx, sessionId, { signal } = {}) {
|
|
|
248
336
|
} catch (error) {
|
|
249
337
|
return failed('read-failed', error)
|
|
250
338
|
}
|
|
251
|
-
|
|
339
|
+
let events = Array.isArray(snapshot?.events) ? [...snapshot.events] : []
|
|
340
|
+
let header = snapshot?.session || {}
|
|
341
|
+
let inheritedEventCount = snapshot?.inheritedEventCount
|
|
342
|
+
// readSession 也是 live-preferred;同一条外部追加恢复路径。
|
|
343
|
+
const ahead = await persistedAhead(events, header)
|
|
344
|
+
if (ahead) {
|
|
345
|
+
events = ahead.events
|
|
346
|
+
header = ahead.header
|
|
347
|
+
inheritedEventCount = ahead.inheritedEventCount
|
|
348
|
+
}
|
|
252
349
|
const safe = safePrefix(events, { requireClosedTurn: false })
|
|
253
350
|
if (!safe.ok) return deferred(safe.reasonCode, 'the stored transcript is not complete enough to snapshot (' + safe.reasonCode + ')', { observedEvents: events.length })
|
|
254
|
-
const header = snapshot?.session || {}
|
|
255
351
|
return {
|
|
256
352
|
ok: true,
|
|
257
353
|
events: safe.events,
|
|
@@ -261,7 +357,7 @@ export async function captureSessionSnapshot(ctx, sessionId, { signal } = {}) {
|
|
|
261
357
|
source: 'validated-log',
|
|
262
358
|
events: safe.events,
|
|
263
359
|
header,
|
|
264
|
-
inheritedEventCount
|
|
360
|
+
inheritedEventCount,
|
|
265
361
|
cursor: safe.throughSeq,
|
|
266
362
|
safe,
|
|
267
363
|
}),
|
|
@@ -271,4 +367,4 @@ export async function captureSessionSnapshot(ctx, sessionId, { signal } = {}) {
|
|
|
271
367
|
return unavailable('no-snapshot-api', 'sessionQuery exposes neither observeSession nor readSession; consolidation cannot read a safe snapshot')
|
|
272
368
|
}
|
|
273
369
|
|
|
274
|
-
export default { CONSOLIDATION_SNAPSHOT_VERSION, captureSessionSnapshot, safePrefix, snapshotHash, toolPairing, lastClosedTurnSeq, eventSeq }
|
|
370
|
+
export default { CONSOLIDATION_SNAPSHOT_VERSION, captureSessionSnapshot, reconcilePersistedAhead, safePrefix, snapshotHash, toolPairing, lastClosedTurnSeq, eventSeq }
|