dsh-memu-memory 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/AGENTS.md +6 -3
  2. package/CHANGELOG.md +57 -0
  3. package/README.md +8 -7
  4. package/README.zh.md +8 -5
  5. package/assets/screenshots/drawer.jpg +0 -0
  6. package/assets/screenshots/mobile.jpg +0 -0
  7. package/assets/screenshots/relations.jpg +0 -0
  8. package/assets/screenshots/settings.jpg +0 -0
  9. package/assets/screenshots/stats.jpg +0 -0
  10. package/assets/screenshots/webui-dark.jpg +0 -0
  11. package/assets/screenshots/webui-memory.jpg +0 -0
  12. package/docs/client-conventions.md +11 -0
  13. package/docs/contributing.md +6 -4
  14. package/docs/env-and-commands.md +12 -1
  15. package/docs/memory-semantics.md +8 -2
  16. package/docs/troubleshooting.md +24 -6
  17. package/lib/auto-link/apply.js +249 -0
  18. package/lib/auto-link/candidates.js +155 -0
  19. package/lib/auto-link/decide.js +304 -0
  20. package/lib/auto-link/normalize.js +99 -0
  21. package/lib/auto-link/policy.js +42 -0
  22. package/lib/auto-link/suppression.js +101 -0
  23. package/lib/auto-link/terminology.js +265 -0
  24. package/lib/binding-diagnostics.js +2 -2
  25. package/lib/client.js +1509 -72
  26. package/lib/graph.js +269 -18
  27. package/lib/memory.js +11 -0
  28. package/lib/memu.js +7 -6
  29. package/lib/private-links.js +105 -137
  30. package/lib/private.js +138 -38
  31. package/lib/rpc.js +73 -8
  32. package/lib/state.js +7 -2
  33. package/lib/tools.js +4 -2
  34. package/lib/webui/graph-LICENSE.txt +1 -62
  35. package/lib/webui/graph-view.bundle.js +1 -1
  36. package/lib/webui/graph-view.js +921 -126
  37. package/lib/webui/standalone.js +3 -3
  38. package/package.json +1 -2
  39. package/scripts/build-graph.mjs +35 -7
  40. package/scripts/check-all.mjs +2 -0
  41. package/scripts/check-graph-browser.mjs +106 -23
  42. package/scripts/make-readme-shots.mjs +59 -0
  43. package/scripts/rebuild-auto-links.mjs +252 -0
  44. package/tests/audit-regression.test.mjs +11 -8
  45. package/tests/auto-link-candidates.test.mjs +161 -0
  46. package/tests/auto-link-decide.test.mjs +512 -0
  47. package/tests/auto-link-migration.test.mjs +133 -0
  48. package/tests/browser.test.mjs +27 -0
  49. package/tests/client-render.test.mjs +178 -6
  50. package/tests/consolidation-fork.test.mjs +148 -0
  51. package/tests/cycle.test.mjs +1 -1
  52. package/tests/graph-view.test.mjs +221 -22
  53. package/tests/graph.test.mjs +5 -0
  54. package/tests/help-page.test.mjs +3 -3
  55. package/tests/memu-resident-route.test.mjs +130 -0
  56. package/tests/private-links.test.mjs +81 -45
  57. package/tests/stubs/child-process-spy.mjs +14 -0
  58. package/tests/tools.test.mjs +24 -18
package/AGENTS.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  给**改这个仓库的人和 agent** 的**索引**:只答「去哪份文件找」。细节全在 `docs/`,本文件刻意短。
4
4
 
5
- 仓库事实:纯 JS、ESM、**无构建步骤**;源码与测试**全 CRLF**;全量测试 + 验收 50 条(均由脚本核对);版本见 `package.json`;MIT。
5
+ 仓库事实:纯 JS、ESM、**只有一个构建步骤**——图谱引擎 bundle(改 `lib/webui/graph-view.js` 必须 `npm run build:graph`,浏览器加载的是产物不是源码);源码与测试**全 CRLF**;全量测试 + 验收 50 条(均由脚本核对);版本见 `package.json`;MIT。
6
6
 
7
7
  2026-10-28:包名 `dsh-memu-memory`(目录仍由用户手动改名)。旧 `/dsh-memu` 路由兼容正式前缀;旧数据目录在没有新 `state.json` 时原地使用,不自动搬迁。WebUI 的 MemU 记忆墙与九页设置是同一个 SettingsPage,仅一个入口。旧「整理失败也标记已睡」的口径作废,失败必须退避重试。能力与限制 → `README.md`。
8
8
 
@@ -52,6 +52,7 @@
52
52
  日期到点没唤醒 → T3.21 时效提示没出现 → T3.22
53
53
  实体合并 / 怕丢记忆 → T3.23
54
54
  失败一轮后锚点/日期没了 → T3.24
55
+ 图谱改了没生效 / 缩到最小打架 → T3.27
55
56
  ```
56
57
 
57
58
  ---
@@ -62,9 +63,11 @@
62
63
  node --check lib/<改过的文件>.js # 语法(源码是 ESM,别用 require 试)
63
64
  npm test # 全量;真实引擎用例默认跳过
64
65
  node scripts/acceptance-local.mjs # 50/50
65
- npm run check # node --check + i18n + package.json + 文档预算
66
+ npm run check # node --check + i18n + package.json + 文档预算 + 图谱 bundle 漂移
66
67
  ```
67
68
 
69
+ **图谱引擎是唯一的产物**:改 `lib/webui/graph-view.js` 后先 `npm run build:graph` 再验证——单测 import 源码、浏览器加载 bundle,不重打包就是「测试全绿、页面照旧」(→ `docs/troubleshooting.md` §3.27)。
70
+
68
71
  **结果口径**:以 `node --test` 输出的 `ℹ tests / pass / fail / skipped` 为准。用例数变了先问「是不是我加的」,失败先问「是不是并发写了同一个库」——这仓库真会多个会话同时改它。测试数字只作**带日期快照**引用(2026-11-06 实测 1473 tests / 1471 pass / 0 fail / 2 skipped;两条真实引擎用例按设计跳过,历史 1293/1291/1287/1280/1277/1273/1210/505/493/463/409/392 等不再代表当前),不当成当前保证。提交前逐条对 `docs/contributing.md` §10。
69
72
 
70
73
  ---
@@ -77,7 +80,7 @@ npm run check # node --check + i18n + package.json + 文
77
80
  | `docs/contributing.md` | §4 改动流程(四步 / 验证三件套 / 连带清单 / 文档同步)+ §5 六个扩展点 + §10 提交前清单 |
78
81
  | `docs/host-api.md` | §6.1 / 6.2 / 6.4–6.8:embedding、workspaceRegistry、历史会话与标题、fork/followup、定时器、RPC+slot+折叠、预设工具面真机证据边界 |
79
82
  | `docs/host-adaptation.md` | 宿主版本适配手册:事实来源、memu 的宿主面清单、新版本检查流程、隔离真机搭法、0.2.2-rc.1 实测记录与陷阱 |
80
- | `docs/client-conventions.md` | §7:两个壳一份实现、颜色 token、控件纪律、数据与刷新、文案与结构 |
83
+ | `docs/client-conventions.md` | §7:两个壳一份实现、颜色 token、控件纪律、数据与刷新、文案与结构、图谱工作台(§7.6) |
81
84
  | `docs/memory-semantics.md` | §8:三层、写入规则、全局记忆、注入(含预设会话首步 `<memory-guide>` 一次性投放)、提示词管理 |
82
85
  | `docs/env-and-commands.md` | §9:Windows 跑命令的 env、CRLF 补丁法、本地 link、引擎安装与回滚、本地向量受管运行时的安装/状态命令(§9.5)、MemU CLI 事实 |
83
86
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # 更新日志 / Changelog
2
2
 
3
+ ## [1.3.3] - 2026-11-13
4
+
5
+ > 小修复与体验优化版本:关系图谱最小缩放下「节点打架 / 闪现」的根因修掉(分离阈值曾跟缩放挂钩),开着图谱不再白吃 GPU,宿主设置页导航不再被掰竖;记忆库与记忆浏览新增「立即整理」与库内搜索;图谱产物纳入 `npm run check` 漂移闸门,README 截图与图注重录。
6
+
7
+ ### 关系图谱
8
+
9
+ - **修掉最小缩放打架**:硬分离阈值原写为 `24 / clamp(viewScale, .06, 5)`,缩到最小(k≈.06)等于要求每对节点保持 400 世界像素间距,斥力与弹簧在 alpha 落地板后已经消失,于是每帧只剩分离力互推、永不收敛。现在阈值只看**世界坐标 + 节点半径**,完全重合时按 id 哈希给确定方向岔开;`viewScale` / `setScale` 一并删除——物理拿不到相机才是根本解。真实浏览器复测(60 节点、k=0.06、点「重新布局」):每 250ms 最大位移 5.92 → 0.02 屏幕像素,静置后漂移 0.06px。
10
+ - 「重新布局」同时重记弹簧原长,避免新位置配旧原长又拉成一团。
11
+ - **冷下来零帧**:模拟落回 alpha 地板后不再申请下一帧,呼吸微动也只在模拟活着时画——WebUI 开着图谱 GPU 占用一路爬升的问题随之消失。
12
+ - 最小缩放的命中迟滞:相邻节点在屏幕上只差 1–2px 时,悬停不再随 1px 抖动来回跳。
13
+ - 缩略图只在主画布真正重绘后才更新(`onPaint` 计数),不再与画布各画各的。
14
+ - 设置里的「关系图谱」改为**一个按钮**,点击直达 WebUI 全屏图谱页;`is-graph-wide` 只在独立外壳生效,宿主设置页保持原本的横排导航。
15
+
16
+ ### 记忆库与记忆浏览
17
+
18
+ - 新增「立即整理」:记忆库每一行、记忆浏览页头各一个按钮,两段确认。它复用侧边栏同一条通道——`listSessions`(本次起返回每个会话绑定的 `libraryId`)筛出该库的会话,再逐个调用 `generatePrivate`,**不新增 RPC 方法**;单轮最多起 5 个整理,其余留给下一次扫描,回执说明已开始 / 在跑 / 失败条数。
19
+ - 「当前记忆库」下方新增搜索框:按标题、正文、ID、标签即时过滤当前已加载的库,页签计数与「命中 / 总数」同步,切换记忆库自动清空;关系视图下不显示。
20
+
21
+ ### 工程与文档
22
+
23
+ - `npm run check` 新增 **graph bundle 漂移闸门**:`node scripts/build-graph.mjs --check` 把源码重打包到内存与 `lib/webui/graph-view.bundle.js` 逐字节比对。此前改完引擎忘了 `npm run build:graph`,浏览器加载的还是旧产物,会出现「单测全绿、页面照旧」(单测 import 源码,浏览器加载 bundle)。生产安装没有 esbuild 时该项自动 skip,不算失败。
24
+ - 新增 `scripts/make-readme-shots.mjs`:对着隔离数据预览用无头浏览器重录 README 的七张截图;本轮截图与图注已更新(关系图谱独立成页、自研连续力导向引擎、bundle 无第三方运行时),并清掉了残留的「D3 力导向」表述。
25
+ - 文档:`AGENTS.md` 仓库事实改为「只有一个构建步骤」并加 §3.27 指针;`docs/client-conventions.md` 新增 §7.6 图谱工作台约定(物理不读相机、改引擎必重打包、冷下来零帧、命中迟滞、外壳归属、最小缩放必然压住不是 bug、整理不新增 RPC);`docs/troubleshooting.md` 新增 §3.27;`docs/contributing.md` §4.1–§4.4 补构建步骤与截图连带项。
26
+
27
+ ### 测试
28
+
29
+ - 引擎:`relayout cools down and separates instead of shoving nodes forever`(位移逐窗衰减 + 零重合 + 物理拿不到相机)、`a cooled layout stops requesting frames even while motion is enabled`、`hover keeps its target through 1px jitter at minimum zoom`。
30
+ - 客户端渲染:`the immersive graph shell stays with the standalone WebUI`、`the manual consolidation button rides the sidebar channel, not a new RPC`、`the browse search box filters the loaded library in place`。
31
+ - `listSessions` 返回库绑定由 `tests/browser.test.mjs` 覆盖。
32
+
33
+ ## [1.3.2] - 2026-11-10
34
+
35
+ > 独立「关系图谱」页与确定性自动关联:记忆墙里的内嵌节点图升级为侧边栏独立页面(自研力导向引擎,移除 d3 运行时依赖);自动关联改为断言驱动(已确认实体提及 / 字段证据),默认只出候选,旧库可用脚本迁移。
36
+
37
+ ### 关系图谱(WebUI)
38
+
39
+ - 新增独立「关系图谱」导航页(在「MemU 记忆」之后);「MemU 记忆」页不再内嵌节点图,只保留记忆墙。
40
+ - 引擎换为自研力导向(空间网格近程斥力 + 连线弹簧 + 可选向心力),**移除 d3-force 运行时依赖**;持续轻微呼吸,空闲降频,管理视图/页面隐藏自动暂停。
41
+ - 拖动节点即固定(fx/fy),邻居被弹簧链牵动,松手不回弹;拖动期间只模拟所连簇,其他簇冻结但作为障碍排斥,避免重合;Shift 拖整簇、右键解固定、双击聚焦。
42
+ - 力参数滑杆(斥力 / 连线距离 / 向心力),规则筛选(提及 / 冲突 / 取代 / 同键 / 引文),标签随缩放渐隐,全高画布与缩略图;配色跟随 DSH token。
43
+ - 管理视图支持新增/删除节点:可新增记忆或实体(「全部记忆库」模式下可选目标库);删除为两段确认,实体被引用时再确认一次即连同关联边删除。
44
+ - 管理视图支持编辑已有节点:记忆可改标题/内容/层级(层级只开放后端允许的路径——短期升长期、永久可降级,提升为永久仍须走带 pin 理由的写入口),实体可改名称与别名(保存时带回当前别名,避免被整体替换清空);保存走 `updateMemory` / `renameEntity`,写完立即重取图。
45
+ - 旧版自动边(无 `evidence.rule`)在规则筛选里归入「旧版自动」桶,老数据不再显示「没有规则」;过滤与边标签统一走可读规则名。
46
+
47
+ ### 自动关联
48
+
49
+ - `autoLinkMode` 默认 `suggest`:本地零 Token 出候选、不写边,候选在关系图谱页审核;`deterministic` 只写断言型边。
50
+ - 确定性边只来自:已确认实体的 `entity-mention`,以及 `conflicts_with` / `supersedes` / 同 `fact_key` 的字段证据;词面相似、共享 token、向量永远不建边。
51
+ - 实体确认/改名/合并/删除即时维护提及边;删除的自动边写入抑制表防复活。
52
+ - 新增 `memu_private_link_suggest` 工具与按本轮 id 的增量刷新;新增 `node scripts/rebuild-auto-links.mjs`(默认 dry-run,`--apply` 先备份再清理重建旧统计边)。
53
+
54
+ ### 其它
55
+
56
+ - 常驻 Python worker 统一用于所有路由:API 模式不再每条命令冷启动解释器。
57
+ - `getGraph` 为旧自动边补稳定的 `rule:'auto'` 显示桶;节点图规则筛选按显示层 rule 过滤。
58
+ - 依赖:移除 `d3-force`,graph bundle 无第三方运行时依赖(许可证文件同步)。
59
+
3
60
  ## [1.3.1] - 2026-11-08
4
61
 
5
62
  > 整理成本与注入瘦身:worker 只留写工具、回执本地合成、批量写、最小整理回合顺延;注入侧修 guide 预算与锚点重投;工具返回值脱敏与分页。
package/README.md CHANGED
@@ -46,7 +46,7 @@ All screenshots are the real WebUI on isolated example data, not anyone's memori
46
46
  <td align="center"><img src="assets/screenshots/drawer.jpg" width="470" alt="In-place memory drawer"><br/><em>Edit, archive or restore without leaving the wall</em></td>
47
47
  </tr>
48
48
  <tr>
49
- <td align="center"><img src="assets/screenshots/relations.jpg" width="470" alt="Graph and adjacency list"><br/><em>Relationship graph and adjacency list in one view</em></td>
49
+ <td align="center"><img src="assets/screenshots/relations.jpg" width="470" alt="Relationship graph studio"><br/><em>Full-screen relationship graph · canvas and inspector</em></td>
50
50
  <td align="center"><img src="assets/screenshots/settings.jpg" width="470" alt="Settings"><br/><em>Injection, budgets, retention and automation</em></td>
51
51
  </tr>
52
52
  <tr>
@@ -63,7 +63,7 @@ All screenshots are the real WebUI on isolated example data, not anyone's memori
63
63
  - **Three layers, one timeline.** `short_term` drafts expire after 72 hours by default; `long_term` is the body of ordinary memory; `must_remember` needs a reason and a source, decays over 365 days with a 0.35 strength floor, and can be *marginalized* but never auto-deleted to make room.
64
64
  - **Recall is a moment, not a dump.** The first turn after a session starts (or after compaction) gets an anchor block with budgets for pinned, core and global memory. After that, each user turn gets at most one recall. Deduplication and a token budget are enforced in code, not left to the prompt. Anchor and recall entries are **title cards**: title, id and semantic tags only. The body stays in the drawer and behind `memu_private_recall` / `memu_global_recall`, so the same budget exposes far more memories without pasting text the model never asked for.
65
65
  - **A private lexicon writes itself.** The consolidation worker extracts stable, evidenced slang, memes and project terms with one term per entry. Ordinary entries become active immediately (no human review queue), while sensitive triggers and sensitive edits stay user-only. The lexicon page is a card flow with active/archived tabs, edit, archive/restore and two-step permanent delete. A **global lexicon** sits beside the per-library ones: every conversation reads it, only you write it. With same-domain cross-library recall on, the anchor, this-turn match and `memu_lexicon_search` merge those libraries too — the page still browses one book at a time.
66
- - **Private links are algorithm-first.** After consolidation, a zero-token pass connects memories that share a rare name or alias in the same context/track and creates/reuses an entity hub (for example `yuike`). Uncertain pairs are handed to the consolidation worker for an evidence-based decision. Links are metadata (`source: 'auto'`), shown with an “Auto” badge in the graph and removable; they never rewrite a body, write a vector or delete anything.
66
+ - **Private links come from assertions, not statistics.** `autoLinkMode` defaults to *candidates only*: a local zero-token pass ranks names into a review queue and writes nothing. Once you confirm an entity, its names and aliases are matched against memory text (`entity-mention`); `conflicts_with` / `supersedes` / the same `fact_key` add field-evidence edges. Lexical similarity, shared tokens and vectors never create an edge. Confirming, renaming, merging or deleting an entity maintains its edges immediately, and a removed auto edge is suppressed so it cannot come back. Links are metadata, shown with an “Auto” badge in the graph; they never rewrite a body, write a vector or delete anything. Existing libraries migrate with `node scripts/rebuild-auto-links.mjs` (dry-run first, `--apply` takes a backup).
67
67
  - **A date is either an anniversary or one day.** `MM-DD` recurs every year (a birthday); `YYYY-MM-DD` fires the day before and the day itself, then is spent. Relative wording (今天 / 明天 / 下周X / 月底) is resolved against the turn's scene time and stored as an absolute date; a memory that says "tomorrow" is stored as the dated form, so an appointment does not come back every year.
68
68
  - **Memory fades unevenly.** Recency, access count, peak and end effects, primacy, habituation and flashbulb accuracy feed one strength score. Mood is described by four components (joy / anger / sorrow / fear, summing to 1) plus arousal (intensity) and dominance (sense of control); a compound mood such as jealousy is a named mix of the four, not a new axis. Mood only reorders recall: it never enters the injected text and never rewrites a memory body. Gating is the OR of three independent conditions — the dominant share is >= 0.35, |arousal - 0.35| >= 0.1, or |dominance| >= 0.25; when none holds, both multipliers are exactly 1. Older entries carry no emotion and keep the old valence path; the four axes are never inferred back from valence. A vivid memory can be more confident than it is accurate, and the UI says so.
69
69
  - **Provenance is a fact, not a style.** Every entry carries `source` / `source_kind` (`user_said` / `assistant_said` / `told` / `imagined` / `inferred` / `tool`), `speaker_id`, `confidence`, `accuracy`, and disclosure rules. A vague recollection cannot impersonate a quote, and the assistant's own promises or plans cannot be filed as something the user said.
@@ -100,9 +100,9 @@ The sidebar has exactly **one** entry: **MemU WebUI**. The memory wall and all s
100
100
 
101
101
  **In-place work.** Clicking a memory card opens a right-side drawer with the full text and the fields that decide how it behaves — title, content, tags, disclosure, confidence, open loop — plus save, archive, restore and "open in the browser" for heavier work. Archived memories can be deleted in the same drawer; the first click only arms it and the second confirms. Global memories are read-only in the drawer and link to their own page. Filters and scroll position stay where they were. Cards that carry images use the first usable attachment as a cover, and the drawer opens the full gallery; `secret` and `never_say` entries never receive a pixel URL, so they show a label instead.
102
102
 
103
- **Graph and list together.** The **Relations** tab renders the graph canvas and the adjacency list side by side (stacked on narrow screens), with the focus selector above them and link/entity/relationship tools below. There is no mode switch to forget. The scope selector also carries a **Global memory** entry: nodes are global entries and edges are `related/refines/supports`; the global view is read-only, and edges are removed from the global memory list.
103
+ **One page for the graph.** **Relations** is its own full-screen page in the WebUI (`#/settings/graph`): the canvas on the left, the inspector on the right, and a **Manage** tab for the list view with the same filters. Source (all / automatic only / manual only), rule, library and search all narrow one shared dataset instead of switching modes, and Settings → Relations is a single button that opens that page. The scope selector still carries a **Global memory** entry: nodes are global entries and edges are `related/refines/supports`; the global view is read-only, and edges are removed from the global memory list.
104
104
 
105
- The locally bundled D3 force layout preserves positions and the camera across background data refreshes. Drag nodes, pan the background, zoom with the wheel or pinch, fit the graph, and highlight neighbors. Labels avoid collisions; graph settings adjust repulsion, link distance, labels and live layout. Layout only visualizes recorded links: it never infers or writes relationships. The graph page also lists **entity merge candidates** (same kind, contained or near-identical spellings) — suggestions only, confirmed by two clicks, and merging redirects links and folds aliases into the main node without deleting any memory.
105
+ The graph runs on a **self-written continuous force engine** — no third-party runtime is bundled. It stays alive while you work, preserves node positions and the camera across background data refreshes, and stops requesting frames the moment it cools down, so an open graph costs no idle GPU. Dragging pins a node exactly where you drop it (release never yanks it back), and only the cluster you touched keeps simulating: frozen clusters act as obstacles the moving one cannot slide through. Repulsion, link distance and centering are adjustable in the panel, labels avoid collisions, and the minimap repaints only after the canvas does. Zoomed all the way out the nodes necessarily merge on screen — separation lives in world coordinates, so spread clusters with repulsion/link distance instead of the zoom. Settings → Relations is a single button that opens the full-screen graph page in the WebUI, where you can also add, edit and delete nodes, and filter edges by the rule that produced them. The layout only visualizes recorded links: it never infers or writes relationships. The graph page also lists **entity merge candidates** (same kind, contained or near-identical spellings) — suggestions only, confirmed by two clicks, and merging redirects links and folds aliases into the main node without deleting any memory.
106
106
 
107
107
  | Page | What it is for |
108
108
  |---|---|
@@ -239,8 +239,8 @@ Folder policy is a **ceiling, not an initial value**: turning a folder switch of
239
239
  | `memu_private_update` | Edit, without bypassing pin admission, review or visibility rules |
240
240
  | `memu_private_archive` | Archive; never delete |
241
241
  | `memu_private_unpin` | Marginalize a permanent memory with a first-person reason, quota and cooldown |
242
- | `memu_private_link` | Link memories/entities with evidence, or update a relationship snapshot; also adjudicates `memu_private_link_suggest` candidates; cannot delete edges |
243
- | `memu_private_link_suggest` | Run the local high-confidence linking/entity-hub pass for ids written this consolidation and return only uncertain candidate pairs |
242
+ | `memu_private_link` | Link memories/entities with evidence, or update a relationship snapshot; also adjudicates uncertain `memu_private_link_suggest` candidates; cannot delete edges |
243
+ | `memu_private_link_suggest` | Refresh deterministic edges (confirmed-entity mentions and field evidence) for ids written this consolidation and return only uncertain candidate pairs |
244
244
  | `memu_lexicon_search` | Search active lexicon terms this conversation can see: bound library + global lexicon (+ same-domain libraries when cross-library recall is on); archived and tombstoned terms stay hidden |
245
245
  | `memu_lexicon_propose` | Add or update a lexicon term in the bound library (never the global lexicon); ordinary entries become active immediately, sensitive triggers remain user-only |
246
246
  | `memu_global_recall` / `memu_global_list` | Read the global layer by domain |
@@ -347,11 +347,12 @@ npm run build:graph # rebuild shipped offline assets after
347
347
  node scripts/acceptance-local.mjs # 50 automated acceptance checks
348
348
  node scripts/migrate-visibility.mjs # report (add --apply to rewrite) libraries that still store the removed session level
349
349
  node --import ./tests/loader-register.mjs scripts/preview.mjs --port 7789
350
+ node scripts/make-readme-shots.mjs # re-record the screenshots above against that preview
350
351
  ```
351
352
 
352
353
  The preview serves the real WebUI against isolated example data at `http://127.0.0.1:7789/dsh-memu-memory/ui#/settings/memories`.
353
354
 
354
- With the preview running, use `npm run test:graph-browser -- http://127.0.0.1:7789/dsh-memu-memory/ui#/settings/memories` in another terminal to check 200 nodes, desktop/narrow layouts, dragging, refresh stability, themes and load retries. Run `npx playwright install chromium` once, or set `GRAPH_BROWSER_CHANNEL=msedge` on Windows to use installed Edge. Stress data is intercepted only in the test browser and never written to memory. No CDN is needed at runtime; bundled D3 licenses are in `lib/webui/graph-LICENSE.txt`.
355
+ With the preview running, use `npm run test:graph-browser -- http://127.0.0.1:7789/dsh-memu-memory/ui#/settings/memories` in another terminal to check 200 nodes, desktop/narrow layouts, dragging, refresh stability, themes and load retries. Run `npx playwright install chromium` once, or set `GRAPH_BROWSER_CHANNEL=msedge` on Windows to use installed Edge. Stress data is intercepted only in the test browser and never written to memory. No CDN is needed at runtime; the bundle carries no third-party runtime code, which `lib/webui/graph-LICENSE.txt` records.
355
356
 
356
357
  The suite includes two optional real-engine integration cases: curator writing requires `DSH_MEMU_TEST_ENGINE_PYTHON`, and the backup venv/WAL case requires `DSH_MEMU_BACKUP_REAL_ENGINE=1`; both are skipped by default. The 50 automated acceptance checks pass. The optional engine was installed and smoke-tested in an isolated directory with the pinned wheel; embedding tests use a local deterministic server, which proves the protocol, not semantic quality.
357
358
 
package/README.zh.md CHANGED
@@ -46,7 +46,7 @@
46
46
  <td align="center"><img src="assets/screenshots/drawer.jpg" width="470" alt="原地详情"><br/><em>不离开记忆墙就能编辑、归档、恢复</em></td>
47
47
  </tr>
48
48
  <tr>
49
- <td align="center"><img src="assets/screenshots/relations.jpg" width="470" alt="关系图与邻接列表"><br/><em>关系图与邻接列表在同一视图里</em></td>
49
+ <td align="center"><img src="assets/screenshots/relations.jpg" width="470" alt="关系图谱工作台"><br/><em>全屏关系图谱 · 画布与检视面板</em></td>
50
50
  <td align="center"><img src="assets/screenshots/settings.jpg" width="470" alt="设置"><br/><em>注入、预算、留存与自动化</em></td>
51
51
  </tr>
52
52
  <tr>
@@ -68,6 +68,7 @@
68
68
  - **矛盾不会被悄悄合并。** 普通矛盾仍进入 `pending_review`:不注入、不召回,只出现在复核队列,等人或整理作业裁决。写入方明确把两种说法标成同一事实的版本(`conflicts_with`)时,两条都保持 active、一起召回并注入一张冲突卡;显式 `supersedes` 才退休旧条,正文不删。
69
69
  - **秘密不进自动召回。** `secret`、群聊频道、角色、世界线、剧情分支与 `knownBy` 共同约束读写;`secret` 永远不会被自动注入,但同文件夹里**主动检索仍然读得到**——它挡的是「自己冒出来」,不是保险箱。真正把同一文件夹里的两段对话隔开的是 `context` 作用域(`channelId` / `characterId` / `worldId` / `branchId`);两边都没填就是同一个作用域,这正是「文件夹」的含义。旧的 `visibility: 'session'` 级别已删除:读到就按 `shared` 处理、`context` 原样保留,仍存着该级别的库用 `node scripts/migrate-visibility.mjs` 重写(`--apply` 才写,先备份)。
70
70
  - **人与故事是有结构的。** 群聊用稳定的 `speakerId` / `channelId`,不拿显示名当身份;RP 用 `characterId` / `worldId` / `branchId` 隔离知识。关系边有理由和置信度,实体改名不动记忆正文,关系当前状态(熟悉、信任、温度、边界、承诺)是带证据和历史快照。
71
+ - **关联只来自已确认的实体与字段证据。** 设置里的「自动关联」默认只出候选、不写边;你确认过的实体名/别名才会把已有记忆的提及连起来(`entity-mention`),冲突/取代/同 `fact_key` 的相邻版本则建立字段证据边。词面相似、共享 token 与向量永远不建边;候选队列在节点图页审核。旧库的统计噪声边用 `node scripts/rebuild-auto-links.mjs` 先 dry-run、确认后 `--apply`(自动备份)清理;删掉的自动边会写进抑制表,不会复活。
71
72
  - **图片是指针加描述,不是假装能看图。** 附件按 SHA-256 去重、有配额、分三级留存;没有描述时只记「收到一张图片」,绝不编造画面。
72
73
  - **整理在后台。** 整理跑在种子 fork 子会话里,不会在你的待发区多出一轮;失败退避重试,不伪记成功。
73
74
 
@@ -98,9 +99,9 @@
98
99
 
99
100
  **原地操作。** 点记忆卡片会从右侧滑出详情抽屉:完整正文,以及决定它行为的字段——标题、正文、标签、说出口径、置信度、未了之事——外加保存、归档、恢复,以及需要重编辑时的「在记忆浏览中打开」。已归档的记忆可以直接在抽屉里删除:第一次点击只是准备,第二次才真正删除。全局记忆在抽屉里只读,并给出跳转。筛选条件与滚动位置保持不动。带图片的卡片会把第一张可用附件作为封面,抽屉里展开完整图片组;`secret` 与 `never_say` 条目不会拿到像素 URL,只显示标签占位。
100
101
 
101
- **关系图与邻接列表一起看。** 「节点图」页签把关系画布与邻接列表并排显示(窄屏上下堆叠),焦点选择在上方,建边/实体/关系状态工具在下方;没有需要记得切换的模式。范围选择器除了私有库,还带一项**全局记忆**:节点是全局条目、边是 `related/refines/supports`,全局视图只读,移除边仍在全局记忆列表里完成。
102
+ **图谱单独一页。** 「关系图谱」是 WebUI 里一个全屏页面(`#/settings/graph`):左边画布、右边检视面板,列表视图在同页的**管理**页签下,用的是同一套筛选。来源(全部 / 仅自动 / 仅手动)、规则、记忆库与搜索都在收窄同一份数据,不是要记得切换的模式;设置里的「关系图谱」只有一个按钮,点了直达这一页。范围选择器仍然带一项**全局记忆**:节点是全局条目、边是 `related/refines/supports`,全局视图只读,移除边仍在全局记忆列表里完成。
102
103
 
103
- 图谱使用本地打包的 D3 力导向布局,后台数据刷新保留节点位置与视角。支持拖拽节点、空白处平移、滚轮/双指缩放、适应全图与关联高亮;标签自动避让,设置中可调整斥力、连线距离,以及关闭标签或动态布局。图谱布局只表达已记录的关联,不会推断或写入新的关系。实体可以直接在图谱里删除(仍被引用时会明确拒绝);永久删除一条记忆会连带清理指向它的边与孤立实体,孤立节点有启动扫描自动回收。节点图页还会列出**实体合并候选**(同 kind、名称包含或写法相近):只是建议,两次点击确认;合并把来源实体的记忆链接改指主节点、别名并入,不删除任何记忆。
104
+ 图谱用的是**自研的连续力导向引擎**,bundle 里没有第三方运行时:模拟一直活着,后台数据刷新保留节点位置与视角,一旦冷下来就不再申请帧,开着图谱不会白吃 GPU。拖动把节点钉在你松手的地方(松手不会被拽回),并且只有你碰到的那一簇继续模拟,其余冻结簇充当障碍物,动的簇无法穿过去。斥力、连线距离、向心力在面板里可调,标签自动避让,缩略图只在主画布重绘后才更新。缩到最小时节点在屏幕上必然会压在一起——间距是世界坐标里的,要拉开簇请用斥力/连线距离,而不是缩放。设置里的「关系图谱」只有一个按钮,点开就是 WebUI 的全屏图谱页,那里还能新增/编辑/删除节点,并按生成这条边的规则筛选。图谱布局只表达已记录的关联,不会推断或写入新的关系。实体可以直接在图谱里删除(仍被引用时会明确拒绝);永久删除一条记忆会连带清理指向它的边与孤立实体,孤立节点有启动扫描自动回收。节点图页还会列出**实体合并候选**(同 kind、名称包含或写法相近):只是建议,两次点击确认;合并把来源实体的记忆链接改指主节点、别名并入,不删除任何记忆。
104
105
 
105
106
  | 页面 | 用途 |
106
107
  |---|---|
@@ -237,7 +238,8 @@ npx --package dsh-memu-memory dsh-memu-memory-setup
237
238
  | `memu_private_update` | 编辑,但不能绕过永久准入、复核或可见性规则 |
238
239
  | `memu_private_archive` | 归档,不删除 |
239
240
  | `memu_private_unpin` | 用第一人称理由、配额和冷却边缘化一条永久记忆 |
240
- | `memu_private_link` | 用证据连接记忆/实体,或更新关系快照;不能删边 |
241
+ | `memu_private_link` | 用证据连接记忆/实体,或更新关系快照;可裁决 `memu_private_link_suggest` 的不确定候选;不能删边 |
242
+ | `memu_private_link_suggest` | 为本轮整理写入的 id 刷新确定性边(已确认实体提及 / 字段证据),只返回不确定候选 |
241
243
  | `memu_global_recall` / `memu_global_list` | 按 domain 读取全局记忆 |
242
244
  | `memu_status` | 存储健康、同步心跳、召回状态与图片回合状态 |
243
245
 
@@ -333,11 +335,12 @@ npm run build:graph # 修改图谱源码后重建随包分
333
335
  node scripts/acceptance-local.mjs # 50 条自动验收
334
336
  node scripts/migrate-visibility.mjs # 报告(--apply 才重写)仍存着旧 session 级别的库
335
337
  node --import ./tests/loader-register.mjs scripts/preview.mjs --port 7789
338
+ node scripts/make-readme-shots.mjs # 对着上面这个预览重录本文档的截图
336
339
  ```
337
340
 
338
341
  预览会在隔离示例数据上启动真实 WebUI:`http://127.0.0.1:7789/dsh-memu-memory/ui#/settings/memories`。
339
342
 
340
- 预览运行后,可在另一终端执行 `npm run test:graph-browser -- http://127.0.0.1:7789/dsh-memu-memory/ui#/settings/memories`,验证 200 节点、桌面/窄屏、拖拽、刷新稳定性、主题与加载重试。首次使用需执行 `npx playwright install chromium`;Windows 也可设置 `GRAPH_BROWSER_CHANNEL=msedge` 使用已安装的 Edge。压力数据仅在测试浏览器内拦截,不写入记忆库。图谱运行时不依赖 CDN,D3 许可随资源保存在 `lib/webui/graph-LICENSE.txt`。
343
+ 预览运行后,可在另一终端执行 `npm run test:graph-browser -- http://127.0.0.1:7789/dsh-memu-memory/ui#/settings/memories`,验证 200 节点、桌面/窄屏、拖拽、刷新稳定性、主题与加载重试。首次使用需执行 `npx playwright install chromium`;Windows 也可设置 `GRAPH_BROWSER_CHANNEL=msedge` 使用已安装的 Edge。压力数据仅在测试浏览器内拦截,不写入记忆库。图谱运行时不依赖 CDN,bundle 内不含第三方运行时代码,这一点记录在 `lib/webui/graph-LICENSE.txt`。
341
344
 
342
345
  测试包含两条可选真实引擎集成用例:curator 写入需设置 `DSH_MEMU_TEST_ENGINE_PYTHON`,备份 venv/WAL 需设置 `DSH_MEMU_BACKUP_REAL_ENGINE=1`,默认按设计跳过;50 条自动验收全部通过。可选引擎已在隔离目录安装并跑通锁定 wheel 的 smoke;embedding 测试使用本机确定性服务,只证明协议可用,不证明语义质量。
343
346
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -43,4 +43,15 @@
43
43
  - `tests/client-render.test.mjs` 把 7 个页面和侧边栏各渲染一遍:渲染期抛错或文本出现 `[object Object]` 即失败。
44
44
  - WebUI 打开路径只有一条 `openWebUiPage()`(先新标签,被拦截再用应用内 overlay)。**禁止同标签导航兜底**——会卸载宿主 SPA,「返回」变成整页刷新。
45
45
 
46
+ ### 7.6 关系图谱工作台(`lib/webui/graph-view.js` + `GraphStudioPanel`)
47
+
48
+ - **物理不许读相机。** 力导向里的斥力、弹簧原长、硬分离阈值一律用**世界坐标 + 节点半径**;把缩放塞进物理(曾经的 `24 / clamp(viewScale, .06, 5)`)在最小缩放等于要求 400 世界像素间距,节点每帧互推、永不收敛,用户看到的就是「缩到最小后打架 / 闪现」。缩放只影响**绘制**与**命中半径**。`tests/graph-view.test.mjs` 钉死两件事:`setScale` 之类把相机交给物理的入口不许回来,`relayout()` 后位移必须逐窗衰减且不留重合。
49
+ - **改引擎必须重打包。** 浏览器加载的是 `lib/webui/graph-view.bundle.js`,不是源码;`npm run build:graph` 忘了跑,源码修复在真实页面上根本不存在,而单测照绿(它 import 的是源码)。`npm run check` 现在比对两者字节,漂移即红。
50
+ - **冷下来就要零帧。** 渲染循环只在 `layout.active`(alpha 高于地板)或交互期申请下一帧;呼吸微动也只在模拟活着时画。每帧无条件 `requestAnimationFrame` 会让 GPU 占用一路爬升且不回落。
51
+ - **命中判定带迟滞。** 最小缩放下相邻节点在屏幕上只差 1–2px,纯「最近距离」会在两者之间反复跳;`hit(p, prefer)` 必须优先保留上一个目标(`tests/graph-view.test.mjs` 用 1px 抖动断言)。
52
+ - **`is-graph-wide` 只属于独立外壳**(`standalone && page === PAGE.graph`)。那套样式为全屏画布把导航改成 158px 竖排,套到宿主设置页上就会把原本横排的导航整片掰竖。宿主那一页只给一个按钮,点了走 `openWebUiPage('graph')`。
53
+ - **缩到最小节点必然在屏幕上压在一起**:绘制半径有 2.5px 下限,而世界间距不变。这不是 bug,别去动物理补偿;要拉开簇就用「斥力 / 连线距离」滑杆,它们改的才是世界尺度。
54
+ - **缩略图只跟主画布重绘**:`createGraphView` 的 `onPaint` 计数不变就不 `drawImage`,否则缩略图按自己的节奏重画,和主画布对不上。
55
+ - **整理入口不新增 RPC**:「立即整理」= `listSessions`(带 `libraryId`)筛出该库绑定的会话,再逐个调用侧边栏同一个 `generatePrivate`,两段确认。UI 专用的写方法同时也是一条模型能调的写路径,能复用就别新开。
56
+
46
57
  ---
@@ -8,7 +8,7 @@
8
8
 
9
9
  1. **定位链路**:先用 §2.2 那条链找到「这个行为在哪一步决定」,再读那个函数,不要从 UI 往下猜。
10
10
  2. **最小改动**:一次只改一个语义,schema/文案/UI 不混在一个提交里——出了事无法二分。
11
- 3. **三层验证**(§4.2):语法 → 针对性单测 → 全量 + 验收 + 自检。**只跑自己新写的测试不够**,这个仓库多数回归是被别的文件抓到的。
11
+ 3. **三层验证**(§4.2):语法 → 针对性单测 → 全量 + 验收 + 自检。**只跑自己新写的测试不够**,这个仓库多数回归是被别的文件抓到的。改过 `lib/webui/graph-view.js` 的话,验证之前先 `npm run build:graph`:浏览器加载的是 bundle,单测加载的是源码,不重打包就会出现「测试全绿、页面照旧」。
12
12
  4. **同步文档**(§4.4)。文档与代码不一致本身就是缺陷:读者照文档做就会出现「做了却不对」。
13
13
 
14
14
  ### 4.2 验证三件套
@@ -17,7 +17,7 @@
17
17
  node --check lib/<改过的文件>.js # 语法(源码是 ESM,别用 require 试)
18
18
  npm test # 全量;真实引擎用例默认跳过
19
19
  node scripts/acceptance-local.mjs # 50/50;视觉证据只证明本次已审查,UI 改动仍须重新看图
20
- npm run check # node --check + i18n 键对齐 + package.json 可解析
20
+ npm run check # node --check + i18n 键对齐 + package.json 可解析 + 文档预算 + 图谱 bundle 漂移
21
21
  ```
22
22
 
23
23
  **结果口径**:以 `node --test` 输出的 `ℹ tests / pass / fail / skipped` 为准。用例数变了先问「是不是我加的」,失败先问「是不是并发写了同一个库」——这仓库真会多个会话同时改它。文档里出现的测试数字一律当作**带日期的快照**:2026-11-01 实测 1293 tests / 1291 pass / 0 fail / 2 skipped(curator 真实引擎与备份 venv/WAL 两条为 opt-in,按设计跳过);更早的 1287 / 1280 / 1277 / 1273 / 1210 / 505 / 392 / 321 / 327 / 333 等是历史快照或转述,不能当作当前保证。**计时与日期敏感的断言要按「整包并行 + 一天中的任何时刻」写**:`tests/sidebar.test.mjs` 的大库首屏用 1500ms(空载 378–448ms,整包并行曾到 1808ms,500ms 测的是机器的空闲程度),`tests/client-render.test.mjs` 的短条目过期时刻用相对时间(曾 pin 在当天 09:30Z,下午必红)。
@@ -34,6 +34,7 @@ npm run check # node --check + i18n 键对齐 + package.j
34
34
  | UI 任何东西 | §7 全部约定、zh/en 两字典、`renderXxxItem` 拆分 | `client-render`、`webui`、`new-session-gate` |
35
35
  | 提示词正文 | 各类型页变体、`{{变量}}` 是否都在 vars、`files` 白名单 | `prompts` |
36
36
  | 引擎/安装 | Python 顺序、镜像顺序、prune 白名单、备份内容、切换回滚 | `engine`、`backup` |
37
+ | 图谱引擎 `lib/webui/graph-view.js` | 改完必须 `npm run build:graph`:浏览器只加载 `graph-view.bundle.js`,源码修复不重打包等于没修(`npm run check` 比对两者,漂移即红;生产安装没有 esbuild,该项自动 skip) | `graph-view` |
37
38
  | 设置项 | `DEFAULT_SETTINGS`、设置页控件、WebUI `settingRow`、反面语义 `invert`、`memoryStamp` 覆盖 | `state`、`config`、`sidebar-beat` |
38
39
  | 统计计数 | `bumpStats` 调用点(只有语义动作能加)、90 天裁剪、零值与降级、`getStats` 不建库 | `stats`、`client-render` |
39
40
 
@@ -42,6 +43,7 @@ npm run check # node --check + i18n 键对齐 + package.j
42
43
  | 改动类别 | 要更新的文档 |
43
44
  |---|---|
44
45
  | 任何行为变化 | `README.md` 的能力/限制段(写「谁受益」不写「改了哪个函数」)+ `docs/troubleshooting.md` §3 对应小节的「会坏在哪」 |
46
+ | UI 界面变化 | 两份 README 的截图也是产物:起预览后 `node scripts/make-readme-shots.mjs` 重录 `assets/screenshots/*.jpg`,并核对图注文字还描述得对(1.3.3 之前就漏过「关系图谱」独立成页,图注仍写着「与邻接列表同视图」) |
45
47
  | 设计决策 / 取舍 | `README.md` 限制段 + `docs/memory-semantics.md` §8(**只写为什么,不写施工流水**) |
46
48
  | 影响验收方式 | 能自动化的进 `scripts/acceptance-local.mjs`,行为级的进 `tests/`;都进不了说明还没想清楚 |
47
49
  | 新增能力 / 数据结构 | `README.md` 能力表 + `tests/` 或验收脚本 |
@@ -75,9 +77,9 @@ npm run check # node --check + i18n 键对齐 + package.j
75
77
 
76
78
  ### 5.3 新增一个 RPC 方法
77
79
 
78
- <!-- rpc-method-count: 97 -->
80
+ <!-- rpc-method-count: 101 -->
79
81
 
80
- 1. `lib/rpc.js` 的 `switch` 加 case(共 95 个方法,按功能分组,别乱插)。
82
+ 1. `lib/rpc.js` 的 `switch` 加 case(共 101 个方法,按功能分组,别乱插)。
81
83
  2. 返回**形状稳定**:客户端 `call()` 直接解构,列表类给 `{items, total}` 而不是裸数组。
82
84
  3. `revisionOnly` 分支只回 `{revision, stamp}`、**不要求 sessionId**(三端轮询,设置页与独立页没会话)、**不塞业务数据**(每 2.5 秒一次);顺带 `noteMemoryBeat()`,`memu_status` 靠它分「没写」与「没人轮询」。
83
85
  4. 写成功后 `bumpMemoryRevision()`/`notifyMemoryWrite()`(§7);能让 `state.json` 或索引落盘的写,`state.js` 自动记写事件供 `memu_status` 展示。
@@ -30,6 +30,17 @@ npm run replay
30
30
 
31
31
  `scripts/replay.mjs`:不走测试框架,按生产代码路径端到端重放七条链路(事实级去重工具层、PTC 整理成功/失败、整理提醒与日志页数据、侧边栏提醒块真实渲染、向量计数账本+戳、MemU 记忆页分组/多选/查看跳转)。只有 MemU 引擎子进程换成内存桩,其余全是真实模块;退出码 0 = 全部检查点通过。改动整理/去重/向量计数/提醒任一链路后跑一次,比单测更接近「用户点下去会发生什么」。
32
32
 
33
+ ### 9.1.2 自动关联迁移(v3)
34
+
35
+ ```bash
36
+ node scripts/rebuild-auto-links.mjs # 默认 dry-run:只读索引/实体,打印旧 auto 边、实体分级计划与“确认前 N 个队列实体”的提及边预估
37
+ node scripts/rebuild-auto-links.mjs --apply # 先整库备份,再删全部 source:'auto' 旧边、落实体状态、为已确认实体重建确定性边
38
+ node scripts/rebuild-auto-links.mjs --library lib_x --json
39
+ node scripts/rebuild-auto-links.mjs --include-archived # 连归档库一起处理(默认只跑未归档库)
40
+ ```
41
+
42
+ 迁移后把设置里的 `autoLinkMode` 从 `suggest` 切到 `deterministic`;候选确认在节点图页「待确认实体」。脚本只删 `source:'auto'` 边,非 auto(手动/worker)边、正文、向量、附件与 `link-suppression.json` 一律不动;apply 在同一轮里为**已确认**实体重建确定性边(设计 §14 原文要求 S3 不建边,实现把 S3+S4 的“已确认”部分合并,未确认的名字仍等人工),apply 后重跑 dry-run 应显示 legacy 0。回滚 = 恢复 `backups/` 里最近一次备份(脚本没有独立 rollback 子命令)。单个库的实体文件损坏只记进 `failures` 并继续跑其余库,`--json` 的 `ok` 为 false、进程退出码非 0。建议在 DSH 关闭时运行(S0 的“冻结整理”没有单独开关,脚本只负责备份)。
43
+
33
44
  ### 9.2 本地 link 到 DSH profile
34
45
 
35
46
  `~/.dsh/profiles/<profile>/package.json` 里 `"dsh-memu-memory": "link:D:/Code/dsh-plugin/dsh-memu-memory"` 并加入 `dsh.profile.bundles`。是符号链接 → 改源码即刻生效(无 bundle 缓存)。`lstat` 验证是否 symlink(§3.10)。
@@ -51,7 +62,7 @@ npm run replay
51
62
  - `memu-cli` 是 **PyPI 上的 Python 包,不是 npm 包**;锁定 `0.11.0b3`。
52
63
  - 发布版 `memu --help` 只有 `retrieve, search, list-files, commit`;源码里的 `memorize prepare/commit` **尚未发布**,**不要依赖 `memorize`**——当可选能力(启动探测 `memu memorize --help`,成功才注册入口,失败隐藏不报错)。
53
64
  - 必需命令 `retrieve` / `list-files` / `commit`;必需 flag `--json` / `--db` / `--provider` / `--embed-model` / `--api-key` / `--base-url`。**所有 CLI 字符串只在 `lib/memu.js`**。
54
- - 本地向量模式下插件**常驻一个解释器**(`lib/memu.js` 的 resident engine):启动时 `import memu.cli` 一次,随后 `retrieve` / `list-files` / `commit` 通过 JSON 行协议调用同一个 `main(argv)`,省掉每条命令约 2 s 的导入链;每条命令结束显式 `database.close()`,空闲期不占 sqlite 句柄。远端 API 路由仍按命令新起进程;插件卸载或引擎安装/切换前关闭常驻进程,异常退出时下一条命令冷启动(见 `docs/troubleshooting.md` §3.26)。
65
+ - 本地向量模式下插件**常驻一个解释器**(`lib/memu.js` 的 resident engine):启动时 `import memu.cli` 一次,随后 `retrieve` / `list-files` / `commit` 通过 JSON 行协议调用同一个 `main(argv)`,省掉每条命令约 2 s 的导入链;每条命令结束显式 `database.close()`,空闲期不占 sqlite 句柄。远端 API 路由复用同一个常驻进程(每条命令单独传 base URL/key/model/db 的 env);插件卸载或引擎安装/切换前关闭常驻进程,异常退出时下一条命令冷启动(见 `docs/troubleshooting.md` §3.26)。
55
66
 
56
67
  ```bash
57
68
  python -m memu retrieve "query" --json --db <db>
@@ -60,7 +60,7 @@
60
60
  - **职责分工**:`system-guide.*` 是唯一常驻规则,只写领域行为、检索时机、回答口径;`private-policy.*` 保留为字段规约参考,不再投放,避免两套常驻文本互相漂移。
61
61
  - **只有三个 key 分域**:`system-guide`、`private-policy`、`private-consolidation`;`global-curator` 不分域。
62
62
  - **远程与本地共用一份 `private-consolidation`**:正文讲「记什么、字段怎么填」,差异只有输出协议(`CONSOLIDATION_CONTRACTS.local` 调工具 / `.remote` 返回 JSON,代码追加)。不要拆第二份。
63
- - **1.2.2 起整理稿负责标题质量**:title 按「只看标题就知道具体事实」写(8–40 字、具体关键词、集合稿覆盖全部来源),`global-curator` 同一口径。词典/关联的工具调用属于**本地工作流**:领域整理稿与远程 JSON 路径共用,因此不写 `memu_*` 工具名;领域稿只保留「可抽什么词」的差异,稳定复用的黑话/梗/术语先 `memu_lexicon_search` 再 `memu_lexicon_propose`、写完用 `memu_private_link_suggest` 裁决候选的工具流程只出现在 local worker brief。远程契约明确「没有工具」,title 长度同样是 8–40 字。
63
+ - **1.2.2 起整理稿负责标题质量**:title 按「只看标题就知道具体事实」写(8–40 字、具体关键词、集合稿覆盖全部来源),`global-curator` 同一口径。词典/关联的工具调用属于**本地工作流**:领域整理稿与远程 JSON 路径共用,因此不写 `memu_*` 工具名;领域稿只保留「可抽什么词」的差异,稳定复用的黑话/梗/术语先 `memu_lexicon_search` 再 `memu_lexicon_propose`、写完调用 `memu_private_link_suggest` 刷新确定性边(已确认实体提及 / 字段证据)并取得不确定候选、需要时用 `memu_private_link` 显式裁决的工具流程只出现在 local worker brief。远程契约明确「没有工具」,title 长度同样是 8–40 字。
64
64
  - RP 与 coding 是**内容**差异:coding 记事实(决定、约束、踩过的坑、工程偏好),召回当「可能过期的事实」,与代码冲突时以代码为准;rp 记经验(具体瞬间、半句原话、身体感觉、没说出口的话),允许模糊记错,不确定就标低 `confidence`。rp/mixed 同时收对方主动给出的**现实生活事实**(作息、行程、口味、健康、家人朋友、在忙的事):`about_user` 平实短条(30–80 字),不需要「瞬间+影响」模板,剧情与现实条分开写、不互相合并;单次提及低 confidence 或 `short_term`,重复出现才升 `long_term`(`寒暄不留`的口径只拦寒暄本身,不拦寒暄里夹带的事实)。
65
65
  - **KV cache**:section 文本随 domain 变,但同一会话内恒定,缓存不受影响;中途改 domain 会让该会话失效一次缓存。别在文档里写「文本恒定」。
66
66
 
@@ -159,7 +159,13 @@
159
159
 
160
160
  **词典生命周期。** 公开状态只有 `active` / `archived`:用户新建、模型 `memu_lexicon_propose`、curator 带证据抽取都直接 active;`archiveLexiconTerm` / `restoreLexiconTerm` 负责可逆退场,删除只属于管理面。`rejected` 只作为 legacy 墓碑/指纹留在数据里,UI、注入、检索与计数都看不到;`pending` 只作为旧版本迁移输入:新提案 → active(敏感 → archived),revision 草稿 → archived。敏感 trigger 的新建/修改只能由用户完成,模型/curator 得到 typed 拒绝;非用户修改普通 active 词条的敏感字段也直接拒绝,不再生成 pending revision。RPC 的 `lexiconReview` 已删除(方法数见 `docs/contributing.md` 的 rpc-method-count 标记)。**哪些词条进得来**是另一层:全局词典 + 同域跨库,见 §8.16。
161
161
 
162
- **私有自动关联。** 整理结算后 `lib/private-links.js` 只做本地算法:同库、同 context/track、可见非 secret、标题共享稀有 name-like token、pairScore < 0.82 且无冲突时,建立 memory↔memory `relation` 并写 `source:'auto'`;≥2 条记忆共享该 token 时复用/创建实体枢纽(人物信号 → `person`,无信号的拉丁名保守 → `thing`,CJK 无信号或 kind 冲突 → 不确定候选)。高置信写库在算法侧完成;1.3.1 起整理 worker 不再接收 `link_suggest`,不确定候选只留在本地算法结果里,需要时由主会话用 `memu_private_link` 裁决;不另起整理、不重读转录。算法/写入失败只记 warn,不能让已经成功的整理失败;自动关联不改正文、不写向量、不删除,边可在关系图移除。worker 写工具为 remember/remember_batch/update,读工具为空(记忆目录与本地召回由插件在种子开头注入),但「有没有写能力」仍只由 remember/update 判定。
162
+ **私有自动关联(v3 确定性版)。** 写边只有一条路径:`lib/auto-link/` 的纯函数判定。`settings.autoLinkMode` 三档:`suggest`(默认)只生成候选、**自动整理不写边**,但你显式确认实体仍会补挂(§14 S4 的迁移流程);`deterministic` 自动整理也写由证据推出的确定性边;`off` 全关——连确认/新建/改名/合并触发的提及维护也不写。判定表只有两类:① `entity-mention`——记忆标题/正文按 NFKC+大小写/标点归一化后命中一个 **confirmed** 实体的名字/别名(CJK 子串 ≥2 字,Latin 词边界,`yuike` 不命中 `yuikeee`),产出 `memory→entity` 边;② 字段证据——`conflicts_with` / `supersedes` / 同 `fact_key`+同上下文签名的相邻版本,产出 memory↔memory 的 `conflict` / `supersede` / `fact-key` 边。两类边固定 `confidence: 1.0`、`schemaVersion: 2`,带 `evidence.rule`(枚举 `entity-mention` / `conflict` / `supersede` / `fact-key` / `worker-quote`)。词面相似度、共享 token、向量与所有统计量**永不建边**;它们只参与 `anchor-candidates.json` 的候选排序。
163
+
164
+ **实体生命周期。** `provisional`(默认)不产生任何边,`confirmed` 才允许 R1,`archived` 视同不可用。手工创建(UI/RPC)直接 confirmed;worker 经 `memu_private_link` 点名只创建 provisional 实体与一条非 auto 边(`allowWorkerAssertion` 是 v3 预留开关,本版不读取)。确认/改名/合并/删除都会级联:确认立即跑一次增量提及(不等下次整理);rename 重算该实体的提及边;merge 把来源实体的 `evidence.entityId` 改指主节点并继承 confirmed;delete(force)回收 auto 边并把 `(from,to,kind,rule)` 写进 `index/<lib>.link-suppression.json`。带 `conflicts_with` / `supersedes` / 同 `fact_key` 配对的写入,以及复核接受(replace 会把旧条目改成 superseded)也会立即重算受影响条目的字段证据边,不等下一次整理。用户在关系图删除 auto 边同样写抑制键,后续重算不会复活。
165
+
166
+ **候选队列与迁移。** `anchor-candidates.json` 是派生物:CJK 2–4gram / Latin token 的 df/titleDf/边界/凝聚/PMI/LLR 只用于排序;Tier 1 是有表面证据(引号/名字引导/标识符/用户维护词典)的候选,Tier 2 仅统计特征。没有 status 的旧实体按 DESIGN §9.3 分级:只有 `origin ∈ {user,agent,worker}` 或被非 auto 边引用才保留 confirmed,其余落 provisional。`scripts/rebuild-auto-links.mjs`(默认 dry-run,`--apply` 先整库备份)删除全部 `source:'auto'` 旧边、落实体状态,并为已确认实体重建确定性边;确认与 dry-run 幂等后再把 `autoLinkMode` 切到 `deterministic`。
167
+
168
+ **召回治理与失败隔离。** `recallRelations` 的 top-2 扩展显式排除 `evidence.rule === 'entity-mention'`——提及是事实索引不是关系,`confidence=1.0` 不能挤掉手动边与字段证据;字段证据边照常参与。判定层纯函数、无 IO/时钟/随机;写库失败只 warn,绝不让已经成功的整理失败;`links[]` 仍只是元数据,不改正文、不写向量、不删记忆。worker 写工具为 remember/remember_batch/update,读工具为空(记忆目录与本地召回由插件在种子开头注入),但「有没有写能力」仍只由 remember/update 判定。
163
169
 
164
170
  ### 8.14 日期联动、到点唤醒与实体合并(1.2.3)
165
171
 
@@ -35,6 +35,7 @@
35
35
  鉴权 / 401/403 行为说不清 → §3.20
36
36
  本地向量模型装不上 / 切不过去 / 召回 400 → §3.25
37
37
  整理超时(fork 预算不够)→ §3.26
38
+ 图谱改了没生效 / 缩到最小打架 / 导航被掰竖 → §3.27
38
39
  ```
39
40
 
40
41
  ## 3. 出过的问题:症状 → 落点 → 守卫
@@ -323,6 +324,19 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
323
324
 
324
325
  **守卫**:`tests/consolidation-fork.test.mjs` 的 `the consolidation wait budget scales with the transcript`、`the seed keeps conversation only, renumbers from zero, and strips replay/stream noise`、`a long tail is cut to one closed-turn window with a remainder`、`the same failed snapshot stops re-forking after the failure cap`,以及 `a fork still running at the deadline reports a timeout instead of silence`。
325
326
 
327
+ ### 3.27 关系图谱:改了引擎没生效 / 缩到最小节点打架 / 导航被掰竖
328
+
329
+ **症状**:三种都来自 1.3.2→1.3.3 这一段。① 明明改了 `lib/webui/graph-view.js`,页面行为一点没变;② 进入关系图谱、缩到最小、点「重新布局」,节点开始互相顶、位置反复闪;③ 在宿主设置页点「关系图谱」,左侧导航整片变成 158px 竖排。
330
+
331
+ **落点**:
332
+ - ①**产物不同步**。图谱引擎是全仓库唯一有构建产物模块:浏览器注入的是 `lib/webui/graph-view.bundle.js`,而 `tests/graph-view.test.mjs` import 的是**源码**——所以「测试全绿 + 页面照旧」是这条路的特征签名。改完必须 `npm run build:graph`;`npm run check` 的 `graph bundle` 项比对两者字节,漂移即红(生产安装没有 esbuild,该项自动 skip,不算失败)。
333
+ - ②**缩放被塞进了物理**。硬分离阈值当年写成 `24 / clamp(viewScale, .06, 5)`:k=.06 时等于命令每对节点保持 400 世界像素,弹簧与斥力在 alpha 落地板后已经没了,于是每帧只剩分离力在互推,整图永远收敛不了。现在阈值只看世界坐标与节点半径(`own = radius + 8`,`minSep = own + other.radius`),重合到 `<.01` 时用 id 哈希给确定方向岔开;`relayout()` 同时重记弹簧原长,否则新位置配旧原长,松手后又拉回一团。`viewScale`/`setScale` 已删——物理拿不到相机才是根本解。
334
+ - ③**全屏外壳没分家**。`.dshm-root.is-graph-wide` 是为独立 WebUI 的全屏画布写的,判定要 `standalone && page === PAGE.graph`;只看 page 就会连宿主设置页一起改竖排。
335
+
336
+ **用户侧的取舍**:缩到最小(k=.06)时整图只占几十像素,绘制半径有 2.5px 下限,**屏幕上必然压在一起**,这不是还在打架——判据是「位移是否逐窗衰减到 0」。要真的拉开簇,用「斥力 / 连线距离」滑杆,它们改的是世界尺度。
337
+
338
+ **守卫**:`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
+
326
340
 
327
341
  ## 守卫索引表
328
342
 
@@ -357,12 +371,13 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
357
371
  | §3.24 | 失败一轮后锚点/日期再不出现 | `tests/injection-rollback.test.mjs`(6 条:撤回+重投、completed 不重复、迟到事件撤不动、已进转录的 500 类失败不误撤、投放前取消撤回、纪念日复提时钟一起撤)。 |
358
372
  | §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 串逐字节不变)。 |
359
373
  | §3.26 | 整理超时(fork 预算) | `tests/consolidation-fork.test.mjs`:预算随事件数缩放(0/100/200/935/5000/非法值),显式 `maxWaitMs` 仍生效,超时不推进 `lastSleepSeq`。 |
374
+ | §3.27 | 图谱改了没生效 / 缩到最小打架 / 导航被掰竖 | `npm run check` 的 `graph bundle`(源码与 bundle 逐字节比对);`tests/graph-view.test.mjs` 的 relayout 收敛、冷启动零帧、最小缩放命中迟滞;`tests/client-render.test.mjs` 的独立外壳归属。 |
360
375
 
361
376
  ## 附录 A · 模块地图(原 §2.1)
362
377
 
363
378
  ### 2.1 模块地图
364
379
 
365
- <!-- rpc-method-count: 97 -->
380
+ <!-- rpc-method-count: 101 -->
366
381
 
367
382
  | 文件 | 职责 / 什么时候碰它 |
368
383
  |---|---|
@@ -376,12 +391,13 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
376
391
  | `lib/private.js` | 私有整理:当前对话、历史 fork、notice 消息 |
377
392
  | `lib/curator.js` / `lib/cycle.js` | 全局 curator 与 `pending_review`;空闲整理 pass(过期/降级/晋升/自动整理) |
378
393
  | `lib/mood.js` / `lib/budget.js` / `lib/snippet.js` | 情绪价与峰值;token 换算(中文≈1 字符/token、英文≈3.4,任何 token 都走它);注入片段裁剪 |
379
- | `lib/rpc.js` / `lib/client.js` / `lib/webui.js` + `lib/webui/standalone.js` | `/dsh-memu-memory` 的 95 个方法(旧路由别名同一鉴权);九页设置 + 侧边栏 `MemoryTab` + `useMemoryBeat`;独立壳挂载同一 SettingsPage,不复制实现 |
394
+ | `lib/rpc.js` / `lib/client.js` / `lib/webui.js` + `lib/webui/standalone.js` | `/dsh-memu-memory` 的 101 个方法(旧路由别名同一鉴权);九页设置 + 侧边栏 `MemoryTab` + `useMemoryBeat`;独立壳挂载同一 SettingsPage,不复制实现 |
380
395
  | `lib/graph.js` / `lib/context.js` / `lib/media.js` | 关系边与实体;说话人/频道/角色/世界线/知情边界;附件采集、缩略图、受保护路由、ZIP |
381
396
  | `lib/prompts.js` + `lib/prompts/` | 提示词加载/覆盖/恢复/domain 变体解析 |
382
397
  | `lib/engine.js` / `lib/memu.js` / `lib/memu-config.js` | Python 引擎安装探测切换回滚;MemU CLI 适配(**所有 CLI 字符串只在这里**);`~/.memu/config.env` 的 embedding |
383
398
  | `lib/stats.js` | 私有库旁路计数(`written/injected/recalled/archived`,90 天滚动);读失败只降级页面,不碰记忆 |
384
- | `lib/lexicon.js` / `lib/private-links.js` | 词典条目与 `active/archived` 生命周期、注入行渲染;整理后的本地自动关联候选与枢纽 |
399
+ | `lib/lexicon.js` / `lib/private-links.js` | 词典条目与 `active/archived` 生命周期、注入行渲染;私有自动关联的旧候选纯函数(统计不再写边) |
400
+ | `lib/auto-link/` / `scripts/rebuild-auto-links.mjs` | 确定性判定(confirmed 实体提及 / 字段证据)、suppression、候选队列与旧实体分级;迁移脚本(dry-run/apply,apply 先备份) |
385
401
  | `lib/freshness.js` / `lib/salient-wake.js` | 时间敏感信号的只读判定(喂 `<memory-freshness>` 提示);用宿主 `ctx.schedule` 排「到点唤醒」一次性任务(默认关闭) |
386
402
  | `lib/remote-summary.js` | 远程摘要 |
387
403
 
@@ -523,7 +539,9 @@ section 的 `text(context)` 能拿到 `context.agent`,所以 system prompt **
523
539
  - **词典词条没注入**:按顺序查——是否 `archived`(不注入、不检索,可恢复);是否 `secret`(不进锚点摘要,但用户点名时 B 通道可解释);context/knownBy 是否匹配;是否在 30 分钟冷却内;是否被锚点摘要 top8/敏感词单列的名额挤掉。词典没有 pending 人审状态;新词条直接 active。
524
540
  - **模型说写了词典但没生效**:`memu_lexicon_propose` 命中 archived 词条会返回 notOwned(不复活);修改敏感字段会被 typed 拒绝;sensitive trigger 只能由用户在词典页管理。检查活动日志/工具回执,不要假设 pending。
525
541
  - **旧库里的 pending 词条去哪了**:周期巡检(`runVisibilityMigrationPass` → `migrateLexiconLibraries`)把 pending 新提案转 active、敏感转 archived、pending revision 转 archived;rejected 保留为内部墓碑。迁移只写有变化的文件;损坏的词典文件不会被当空库覆盖,报 `LEXICON_CORRUPT` 并保持只读。
526
- - **私有自动关联没出现**:算法宁漏勿错。检查两条记忆是否同库、同 context/track、都可见且非 secret;标题是否共享稀有 name-like token(英文 ≥3 字母,或低频 CJK 名称;通用词被停用词表挡掉);pairScore 是否 ≥0.82(重复应走 update/合并)、是否有冲突、是否已有同向 link;每轮还有 2 条/entry、5 条/轮、2 个实体/轮的上限。边上的「自动」Tag 与 `source:'auto'` 是算法写的,可在关系图移除。
527
- - **实体枢纽名称重复(Yuike / yuike)**:算法按 NFKC/大小写/空白/标点归一化复用实体;`memu_private_link` 的 `entity` 参数也按同一规则复用同名实体。若已存在但 kind 冲突,会拒绝并提示改用既有 kind,而不是静默建第二个。
528
- - **worker 没裁决不确定候选**:`memu_private_link_suggest` 只返回候选卡,不自动连;worker 未调用或证据不足就保持不连(宁漏勿错)。`lib/private.js` 的结算兜底只重跑高置信算法,不会把不确定候选偷偷连上。自动关联失败只写 warn,不影响整理成功。
542
+ - **私有自动关联没写边**:先看设置 `autoLinkMode`——默认 `suggest` 只出候选、不写任何边(v3 迁移默认)。切到 `deterministic` 后也只写两类边:已确认实体的提及、字段证据;统计相似度永远不写。确认入口在节点图页「待确认实体」,确认后会立即补挂提及边。实体仍是 provisional、名字只有 1 个字、记忆已归档/待复核/secret、或命中 suppression 时都不会有边。
543
+ - **旧库还挂着一堆自动边**:先跑 `node scripts/rebuild-auto-links.mjs` 看 dry-run(列出 legacy auto 边与旧实体分级计划);确认后 `--apply`(自动先做整库备份)删除全部 `source:'auto'` 旧边,并为已确认实体重建确定性边;再跑一次 dry-run 应显示 legacy 0。
544
+ - **删掉的自动边又回来了**:删除动作会把 `(from,to,kind)` 写进 `index/<lib>.link-suppression.json`(精确 rule + `|*` 通配);检查该文件是否被手动清掉或从旧备份恢复。命中抑制键的边不会在下次整理/重算时重建。**想主动恢复**:节点图页「解除删除标记」(RPC `clearLinkSuppression`);deterministic 模式下会顺带全量重算一次,被删的边按现有证据重建。
545
+ - **实体确认后没有提及边**:确认只匹配已确认实体的名字/别名;检查名字是否 <2 字、记忆是否 archived/pending_review/secret、实体是否 archived(archived 不可确认)、抑制表是否有同名 (from,to,kind) 键(删过的边会写 `|*` 通配,换 rule 也不复活)、以及 `autoLinkMode` 是否为 `off`(off 连确认也不写)。worker 通过 `memu_private_link` 新建的实体默认 provisional,需要用户在审核区确认。
546
+ - **worker 没裁决不确定候选**:`memu_private_link_suggest` 现在只刷新确定性边并返回统计候选卡,不自动连;worker 未调用或证据不足就保持不连(宁漏勿错)。`lib/private.js` 的结算兜底同样只跑确定性判定,不会把统计候选偷偷连上。自动关联失败只写 warn,不影响整理成功。
529
547
  - **要不要数据库/向量重算**:自动关联只是 `links[]` 元数据,不改正文、不写向量;移除边不会触发重建。实体删除仍按既有规则(有引用时需显式 force,避免悬空)。