dsh-memu-memory 1.3.2 → 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.
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,35 @@
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
+
3
33
  ## [1.3.2] - 2026-11-10
4
34
 
5
35
  > 独立「关系图谱」页与确定性自动关联:记忆墙里的内嵌节点图升级为侧边栏独立页面(自研力导向引擎,移除 d3 运行时依赖);自动关联改为断言驱动(已确认实体提及 / 字段证据),默认只出候选,旧库可用脚本迁移。
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>
@@ -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
  |---|---|
@@ -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>
@@ -99,9 +99,9 @@
99
99
 
100
100
  **原地操作。** 点记忆卡片会从右侧滑出详情抽屉:完整正文,以及决定它行为的字段——标题、正文、标签、说出口径、置信度、未了之事——外加保存、归档、恢复,以及需要重编辑时的「在记忆浏览中打开」。已归档的记忆可以直接在抽屉里删除:第一次点击只是准备,第二次才真正删除。全局记忆在抽屉里只读,并给出跳转。筛选条件与滚动位置保持不动。带图片的卡片会把第一张可用附件作为封面,抽屉里展开完整图片组;`secret` 与 `never_say` 条目不会拿到像素 URL,只显示标签占位。
101
101
 
102
- **关系图与邻接列表一起看。** 「节点图」页签把关系画布与邻接列表并排显示(窄屏上下堆叠),焦点选择在上方,建边/实体/关系状态工具在下方;没有需要记得切换的模式。范围选择器除了私有库,还带一项**全局记忆**:节点是全局条目、边是 `related/refines/supports`,全局视图只读,移除边仍在全局记忆列表里完成。
102
+ **图谱单独一页。** 「关系图谱」是 WebUI 里一个全屏页面(`#/settings/graph`):左边画布、右边检视面板,列表视图在同页的**管理**页签下,用的是同一套筛选。来源(全部 / 仅自动 / 仅手动)、规则、记忆库与搜索都在收窄同一份数据,不是要记得切换的模式;设置里的「关系图谱」只有一个按钮,点了直达这一页。范围选择器仍然带一项**全局记忆**:节点是全局条目、边是 `related/refines/supports`,全局视图只读,移除边仍在全局记忆列表里完成。
103
103
 
104
- 图谱使用本地打包的 D3 力导向布局,后台数据刷新保留节点位置与视角。支持拖拽节点、空白处平移、滚轮/双指缩放、适应全图与关联高亮;标签自动避让,设置中可调整斥力、连线距离,以及关闭标签或动态布局。图谱布局只表达已记录的关联,不会推断或写入新的关系。实体可以直接在图谱里删除(仍被引用时会明确拒绝);永久删除一条记忆会连带清理指向它的边与孤立实体,孤立节点有启动扫描自动回收。节点图页还会列出**实体合并候选**(同 kind、名称包含或写法相近):只是建议,两次点击确认;合并把来源实体的记忆链接改指主节点、别名并入,不删除任何记忆。
104
+ 图谱用的是**自研的连续力导向引擎**,bundle 里没有第三方运行时:模拟一直活着,后台数据刷新保留节点位置与视角,一旦冷下来就不再申请帧,开着图谱不会白吃 GPU。拖动把节点钉在你松手的地方(松手不会被拽回),并且只有你碰到的那一簇继续模拟,其余冻结簇充当障碍物,动的簇无法穿过去。斥力、连线距离、向心力在面板里可调,标签自动避让,缩略图只在主画布重绘后才更新。缩到最小时节点在屏幕上必然会压在一起——间距是世界坐标里的,要拉开簇请用斥力/连线距离,而不是缩放。设置里的「关系图谱」只有一个按钮,点开就是 WebUI 的全屏图谱页,那里还能新增/编辑/删除节点,并按生成这条边的规则筛选。图谱布局只表达已记录的关联,不会推断或写入新的关系。实体可以直接在图谱里删除(仍被引用时会明确拒绝);永久删除一条记忆会连带清理指向它的边与孤立实体,孤立节点有启动扫描自动回收。节点图页还会列出**实体合并候选**(同 kind、名称包含或写法相近):只是建议,两次点击确认;合并把来源实体的记忆链接改指主节点、别名并入,不删除任何记忆。
105
105
 
106
106
  | 页面 | 用途 |
107
107
  |---|---|
@@ -335,11 +335,12 @@ npm run build:graph # 修改图谱源码后重建随包分
335
335
  node scripts/acceptance-local.mjs # 50 条自动验收
336
336
  node scripts/migrate-visibility.mjs # 报告(--apply 才重写)仍存着旧 session 级别的库
337
337
  node --import ./tests/loader-register.mjs scripts/preview.mjs --port 7789
338
+ node scripts/make-readme-shots.mjs # 对着上面这个预览重录本文档的截图
338
339
  ```
339
340
 
340
341
  预览会在隔离示例数据上启动真实 WebUI:`http://127.0.0.1:7789/dsh-memu-memory/ui#/settings/memories`。
341
342
 
342
- 预览运行后,可在另一终端执行 `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`。
343
344
 
344
345
  测试包含两条可选真实引擎集成用例:curator 写入需设置 `DSH_MEMU_TEST_ENGINE_PYTHON`,备份 venv/WAL 需设置 `DSH_MEMU_BACKUP_REAL_ENGINE=1`,默认按设计跳过;50 条自动验收全部通过。可选引擎已在隔离目录安装并跑通锁定 wheel 的 smoke;embedding 测试使用本机确定性服务,只证明协议可用,不证明语义质量。
345
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/` 或验收脚本 |
@@ -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,6 +371,7 @@ 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
 
package/lib/client.js CHANGED
@@ -270,6 +270,8 @@ window.__ModuleLoader__.load({
270
270
  mergeReasonContainment: '名称包含',
271
271
  mergeReasonDistance: '写法相近',
272
272
  openMemu: '打开 MemU WebUI',
273
+ openGraphStudio: '打开关系图谱',
274
+ openGraphStudioHint: '在 WebUI 中打开完整关系图谱(浏览器拦下新标签页时在应用内打开)',
273
275
  saved: '已保存',
274
276
  copied: '已复制',
275
277
  copyFailed: '复制失败,请手动选择文本',
@@ -677,6 +679,9 @@ window.__ModuleLoader__.load({
677
679
  memoryContent: '记忆内容',
678
680
  add: '写入',
679
681
  browserIndexOnly: '显示本地索引,正文以此为准。',
682
+ browseSearch: '搜索本库',
683
+ browseSearchPlaceholder: '按标题、正文、ID 或标签过滤当前记忆库…',
684
+ browseSearchClear: '清空',
680
685
  // Enum display labels. Stored values stay English; only these flip with locale.
681
686
  layerLongTerm: '长期记忆',
682
687
  layerAnchor: '锚点记忆',
@@ -776,6 +781,11 @@ window.__ModuleLoader__.load({
776
781
  privateCount: '私有记忆',
777
782
  pinned: '永久记忆',
778
783
  bound: '绑定对话',
784
+ consolidateNow: '手动整理',
785
+ consolidateHint: '为本库绑定的对话发起整理(与侧边栏同一通道,每次最多 5 个,正在整理的会跳过)。整理会产生模型调用成本。',
786
+ consolidateNone: '该库没有可整理的绑定对话',
787
+ consolidateDone: '已发起整理 {started} 个对话(正在整理 {running},失败 {failed}){rest}',
788
+ consolidateRest: ',还有 {n} 个可再点一次',
779
789
  globalMemory: '全局记忆',
780
790
  prompts: '提示词',
781
791
  promptCustom: '自定义',
@@ -1199,6 +1209,8 @@ window.__ModuleLoader__.load({
1199
1209
  mergeReasonContainment: 'Name contained',
1200
1210
  mergeReasonDistance: 'Similar spelling',
1201
1211
  openMemu: 'Open MemU WebUI',
1212
+ openGraphStudio: 'Open relationship graph',
1213
+ openGraphStudioHint: 'Open the full relationship graph in the WebUI (opens in-app when the browser blocks a new tab)',
1202
1214
  saved: 'Saved',
1203
1215
  copied: 'Copied',
1204
1216
  copyFailed: 'Copy failed; select the text manually',
@@ -1606,6 +1618,9 @@ window.__ModuleLoader__.load({
1606
1618
  memoryContent: 'Memory content',
1607
1619
  add: 'Write',
1608
1620
  browserIndexOnly: 'Showing the local index, the authoritative copy.',
1621
+ browseSearch: 'Search this library',
1622
+ browseSearchPlaceholder: 'Filter the current library by title, body, id or tags…',
1623
+ browseSearchClear: 'Clear',
1609
1624
  layerLongTerm: 'Long-term',
1610
1625
  layerAnchor: 'Anchor',
1611
1626
  layerMustRemember: 'Permanent',
@@ -1704,6 +1719,11 @@ window.__ModuleLoader__.load({
1704
1719
  privateCount: 'Private',
1705
1720
  pinned: 'Permanent',
1706
1721
  bound: 'Sessions',
1722
+ consolidateNow: 'Consolidate now',
1723
+ consolidateHint: 'Start consolidation for conversations bound to this library (same channel as the sidebar; up to 5 per click, ones already running are skipped). Consolidation costs model calls.',
1724
+ consolidateNone: 'No bound conversations to consolidate in this library',
1725
+ consolidateDone: 'Started {started} conversations ({running} already running, {failed} failed){rest}',
1726
+ consolidateRest: ' — {n} more, click again',
1707
1727
  globalMemory: 'Global memory',
1708
1728
  prompts: 'Prompts',
1709
1729
  promptCustom: 'Custom',
@@ -3096,7 +3116,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3096
3116
  // chrome=false 时外壳(rail / 参数弹层 / 状态栏)由 Graph Studio 工作台自己画,
3097
3117
  // 画布与引擎保持同一份实现:拖动、pin、弹簧链、簇作用域都不变。
3098
3118
  function GraphCanvas({ graph, focus, onFocus, t, chrome = true, options: controlledOptions = null,
3099
- apiRef = null, onZoom = null }) {
3119
+ apiRef = null, onZoom = null, paintRef = null }) {
3100
3120
  const ref = React.useRef(null)
3101
3121
  const tooltipRef = React.useRef(null)
3102
3122
  const viewRef = React.useRef(null)
@@ -3122,6 +3142,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3122
3142
  const view = module.createGraphView(canvas, {
3123
3143
  onFocus: id => latest.current.onFocus(id),
3124
3144
  onZoom: value => { setZoom(value); zoomNotify.current?.(value) },
3145
+ // 主画布每重绘一次计一格:缩略图只在计数变化时才拷贝,空闲期零开销。
3146
+ onPaint: () => { if (paintRef) paintRef.current = (paintRef.current || 0) + 1 },
3125
3147
  tooltip: tooltipRef.current,
3126
3148
  reducedMotion: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches,
3127
3149
  emptyLabel: latest.current.t('graphEmpty'),
@@ -3247,13 +3269,20 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3247
3269
  : node.kind !== 'memory' ? (node.status === 'provisional' ? 'provisional' : 'entity') : 'memory'
3248
3270
  const gsColor = node => GS_NODE_COLORS[gsKind(node)]
3249
3271
 
3250
- function GraphStudioMinimap({ active, t }) {
3272
+ function GraphStudioMinimap({ active, t, paintRef = null }) {
3251
3273
  const ref = React.useRef(null)
3252
3274
  React.useEffect(() => {
3253
3275
  if (!active || typeof document === 'undefined') return undefined
3276
+ let last = -1
3254
3277
  const paint = () => {
3255
3278
  const target = ref.current
3256
3279
  if (!target?.getContext) return
3280
+ // 主画布这一帧没重绘就不拷贝:空闲期缩略图不再每秒拷三次大画布纹理。
3281
+ if (paintRef) {
3282
+ const tick = paintRef.current || 0
3283
+ if (tick === last) return
3284
+ last = tick
3285
+ }
3257
3286
  const source = document.querySelector('.dshm-gs-stage canvas.dshm-graph-canvas')
3258
3287
  const context = target.getContext('2d')
3259
3288
  if (!source || !context) return
@@ -3332,6 +3361,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3332
3361
  const addTargetLib = mergedScope ? (addLib || libraries[0]?.id || '') : (showGlobal ? '' : graphLibrary)
3333
3362
  const apiRef = React.useRef(null)
3334
3363
  const searchRef = React.useRef(null)
3364
+ // 主画布重绘计数:缩略图只在计数变化时才拷贝纹理。
3365
+ const paintRef = React.useRef(0)
3335
3366
  const beat = `${revision ?? ''}:${stamp ?? ''}`
3336
3367
  const notify = message => setToast(message)
3337
3368
 
@@ -3675,9 +3706,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3675
3706
 
3676
3707
  const stage = h('main', { className: 'dshm-gs-stage' },
3677
3708
  h(GraphCanvas, { graph: canvasGraph, focus, onFocus: setFocus, t, chrome: false,
3678
- options: canvasOptions, apiRef, onZoom: setZoom }),
3709
+ options: canvasOptions, apiRef, onZoom: setZoom, paintRef }),
3679
3710
  canvasTools,
3680
- minimap ? h(GraphStudioMinimap, { active: true, t }) : null,
3711
+ minimap ? h(GraphStudioMinimap, { active: true, t, paintRef }) : null,
3681
3712
  h('div', { className: `dshm-gs-toast${toast ? ' show' : ''}`, role: 'status' }, toast),
3682
3713
  error ? h('div', { className: 'dshm-gs-toast show', role: 'alert' }, error) : null,
3683
3714
  !visibleEdges.length && nodes.length
@@ -5404,6 +5435,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5404
5435
  // stayed in the same list with a different tag, so the mess you were trying to
5405
5436
  // tidy up never actually left. Two lists, and only the archived one offers delete.
5406
5437
  const [browseView, setBrowseView] = React.useState('active')
5438
+ // 当前库内的即时过滤:列表本来就已取回(browseLibrary),不再加一次 RPC。
5439
+ const [browseQuery, setBrowseQuery] = React.useState('')
5407
5440
  // Permanent deletion is two clicks, and only for the row that was armed.
5408
5441
  const [deleteArmed, setDeleteArmed] = React.useState('')
5409
5442
  React.useEffect(() => {
@@ -6017,6 +6050,38 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
6017
6050
  setPage(PAGE.browser)
6018
6051
  void openBrowser(libraryId)
6019
6052
  }
6053
+ // 手动整理复用侧边栏同一条通道:generatePrivate(会话维度、force 语义一致),
6054
+ // 不新增端点。一次点击最多发起 5 个对话——整理是真金白银的模型调用,
6055
+ // 不能一键把整库几十个会话全点着;剩下的再按一次即可。
6056
+ // 计数全部取每个调用的返回值(ok / running / error),不估算。
6057
+ const consolidateLibrary = async (libraryId) => {
6058
+ if (!libraryId || !confirmAction('consolidate:' + libraryId)) return
6059
+ setBusy(true)
6060
+ try {
6061
+ const res = await call('listSessions', { limit: 200 })
6062
+ const targets = (res?.sessions || []).filter(row => row.libraryId === libraryId)
6063
+ if (!targets.length) { setError(t('consolidateNone')); return }
6064
+ let started = 0, running = 0, failed = 0
6065
+ for (const row of targets.slice(0, 5)) {
6066
+ try {
6067
+ const one = await call('generatePrivate', { sessionId: row.id })
6068
+ if (one?.ok === true) started++
6069
+ else if (one?.running) running++
6070
+ else failed++
6071
+ } catch { failed++ }
6072
+ }
6073
+ const rest = Math.max(0, targets.length - 5)
6074
+ setNotice(t('consolidateDone')
6075
+ .replace('{started}', String(started))
6076
+ .replace('{running}', String(running))
6077
+ .replace('{failed}', String(failed))
6078
+ .replace('{rest}', rest > 0 ? t('consolidateRest').replace('{n}', String(rest)) : ''))
6079
+ } catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
6080
+ }
6081
+ const consolidateButton = (libraryId, style = S.ghost) => h(Button, {
6082
+ style, disabled: busy || !libraryId, title: t('consolidateHint'),
6083
+ onClick: () => { void consolidateLibrary(libraryId) },
6084
+ }, actionLabel('consolidate:' + libraryId, t('consolidateNow')))
6020
6085
  const addMemory = async () => {
6021
6086
  if (!browseLibId || !newMem.content.trim()) return
6022
6087
  setBrowseBusy(true)
@@ -7039,6 +7104,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7039
7104
  h('strong', null, lib.name || lib.id),
7040
7105
  h('div', { style: S.muted }, lib.id)),
7041
7106
  h('div', { style: { display: 'flex', gap: 6, flexShrink: 0 } },
7107
+ consolidateButton(lib.id),
7042
7108
  h(Button, { onClick: () => openBrowserFromLibrary(lib.id) }, t('browse')),
7043
7109
  h(Button, { onClick: () => archiveLibrary(lib.id), disabled: busy }, t('archive')))),
7044
7110
  h('div', { style: S.muted }, `${t('scope')}: ${lib.scopeKey || '—'}`),
@@ -7408,7 +7474,11 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7408
7474
 
7409
7475
  const browsePool = file => file.status === 'pending_review' ? 'review' : file.status === 'archived' ? 'archived'
7410
7476
  : ['suppressed', 'expired', 'superseded'].includes(file.status) || file.expiresAt && Date.parse(file.expiresAt) <= Date.now() ? 'inactive' : 'active'
7411
- const archShown = browseFiles.filter(file => browsePool(file) === browseView)
7477
+ const browseQueryText = browseQuery.trim().toLowerCase()
7478
+ const browseMatched = file => !browseQueryText
7479
+ || [file.title, file.content, file.id, ...(Array.isArray(file.tags) ? file.tags : [])]
7480
+ .some(value => String(value || '').toLowerCase().includes(browseQueryText))
7481
+ const archShown = browseFiles.filter(file => browsePool(file) === browseView && browseMatched(file))
7412
7482
  // An archived row is a body you are deciding about, not a draft you are editing:
7413
7483
  // no title/content/tag fields, just enough to recognise it plus the two exits.
7414
7484
  const renderArchivedMemory = (f) => h('div', { key: f.id, style: S.item },
@@ -7463,6 +7533,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7463
7533
  title: t('browser'),
7464
7534
  desc: t('descBrowser'),
7465
7535
  right: h('div', { style: { display: 'flex', gap: 8, flexShrink: 0 } },
7536
+ consolidateButton(browseLibId),
7466
7537
  h(Button, { onClick: () => importLibraryNow(), disabled: !browseLibId || browseBusy, style: S.ghost, title: t('importHint') }, t('importJson')),
7467
7538
  h(Button, { onClick: () => exportLibraryNow(), disabled: !browseLibId, style: S.ghost }, t('export')),
7468
7539
  h(Button, { onClick: () => exportLibraryNow({ includeAttachments: true }), disabled: !browseLibId, title: t('exportZip') }, t('exportZip')),
@@ -7473,15 +7544,29 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7473
7544
  h('select', {
7474
7545
  style: { ...S.input, flex: 1 }, value: browseLibId,
7475
7546
  title: (state.libraries || []).find((lib) => lib.id === browseLibId)?.scopeKey || t('currentLibrary'),
7476
- onChange: (e) => setBrowseLibId(e.target.value),
7547
+ onChange: (e) => { setBrowseLibId(e.target.value); setBrowseQuery('') },
7477
7548
  }, (state.libraries || []).map((l) => h('option', { key: l.id, value: l.id }, libraryOptionLabel(l, state.libraries || []))))),
7549
+ browseView === 'relations' ? null : h('div', { style: S.row },
7550
+ h('span', { style: S.label }, t('browseSearch')),
7551
+ h('input', {
7552
+ style: { ...S.input, flex: 1 }, type: 'search', value: browseQuery,
7553
+ placeholder: t('browseSearchPlaceholder'), 'aria-label': t('browseSearch'),
7554
+ onChange: (e) => setBrowseQuery(e.target.value),
7555
+ }),
7556
+ browseQuery
7557
+ ? h('span', { style: S.muted, role: 'status' },
7558
+ `${archShown.length} / ${browseFiles.filter(file => browsePool(file) === browseView).length}`)
7559
+ : null,
7560
+ browseQuery
7561
+ ? h(Button, { style: S.ghost, onClick: () => setBrowseQuery(''), title: t('browseSearchClear') }, t('browseSearchClear'))
7562
+ : null),
7478
7563
  browseSource === 'index'
7479
7564
  ? h('div', { style: { ...S.muted, marginTop: 6 } }, t('browserIndexOnly'))
7480
7565
  : null,
7481
7566
  h('div', { className: 'dshm-nav-list is-row', role: 'tablist', style: { marginTop: 10 } },
7482
7567
  [['active', t('browseActiveTab')], ['archived', t('browseArchivedTab')], ['review', t('poolReview')], ['inactive', t('poolInactive')], ['relations', t('relations')]].map((pair) => {
7483
7568
  const value = pair[0]
7484
- const count = browseFiles.filter(file => browsePool(file) === value).length
7569
+ const count = browseFiles.filter(file => browsePool(file) === value && browseMatched(file)).length
7485
7570
  return h('button', {
7486
7571
  key: value,
7487
7572
  type: 'button',
@@ -7758,10 +7843,17 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7758
7843
  } }))
7759
7844
  // 关系图谱独立成页:库/全局选择器由 GraphStudioPanel 自持,刷新随 SettingsPage
7760
7845
  // 已有的心跳(revision/stamp)走 beat,页内不再开第二套轮询。
7761
- const graphBlock = h(GraphStudioPanel, {
7762
- call, libraries: state.libraries || [], revision: state.revision, stamp: state.stamp, t,
7763
- navHidden: graphNavHidden, onToggleNav: () => setGraphNavHidden(value => !value),
7764
- })
7846
+ // §7.1「两个壳一份实现」:完整工作室只在独立 WebUI 里渲染。宿主设置页/侧栏
7847
+ // 里这一页只给一个按钮,点了直接打开 WebUI 的关系图谱页,不再嵌第二份画布。
7848
+ const graphBlock = standalone
7849
+ ? h(GraphStudioPanel, {
7850
+ call, libraries: state.libraries || [], revision: state.revision, stamp: state.stamp, t,
7851
+ navHidden: graphNavHidden, onToggleNav: () => setGraphNavHidden(value => !value),
7852
+ })
7853
+ : h(Section, { title: t('pageGraph'), desc: t('descGraph'), icon: GlyphChart },
7854
+ h('div', { style: S.row },
7855
+ h(Button, { primary: true, title: t('openGraphStudioHint'),
7856
+ onClick: () => openWebUiPage('graph') }, t('openGraphStudio'))))
7765
7857
  // 词典页:sourceMemoryId →「来源记忆 ↗」复用全局记忆页的 wallFocus 接力棒,
7766
7858
  // 跳到 MemU 记忆页并直接打开对应条目的抽屉。
7767
7859
  const lexiconBlock = h(LexiconPanel, {
@@ -7980,7 +8072,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7980
8072
  // top segments). The indicator is one absolutely-positioned element moved by
7981
8073
  // a transform, so the active item animates without per-item flicker.
7982
8074
  const active = pageDefs[page] || pageDefs[0]
7983
- const graphWide = page === PAGE.graph
8075
+ // 沉浸式只给独立 WebUI 的完整工作室用。宿主设置页里这一页现在只是一个按钮,
8076
+ // 不能再套 is-graph-wide:那会把本来横排的导航强制成 158px 竖排。
8077
+ const graphWide = standalone && page === PAGE.graph
7984
8078
  return h('div', {
7985
8079
  className: `dshm-root${graphWide ? ' is-graph-wide' : ''}${graphWide && graphNavHidden ? ' is-graph-navless' : ''}`,
7986
8080
  'data-dshm-surface': embedded ? 'sidebar' : 'dialog',
package/lib/rpc.js CHANGED
@@ -1221,7 +1221,12 @@ async function dispatch(ctx, endpoint, payload = {}) {
1221
1221
  return { ok: true, scopeMissing: libraryScopeMissing(result.library), archived: archivedLibraryView() }
1222
1222
  }
1223
1223
  case 'listSessions': {
1224
- return { sessions: await recentSessions(ctx, payload?.limit) }
1224
+ const sessions = await recentSessions(ctx, payload?.limit)
1225
+ // 手动整理按钮需要「这个库绑了哪些对话」。绑定表里本来就有 libraryId
1226
+ // (boundSessions 计数用的就是它),这里只补一个只读字段:不新增端点、
1227
+ // 不动鉴权,整理仍然走会话维度的 generatePrivate(与侧边栏同一通道)。
1228
+ const bindings = loadState().sessions || {}
1229
+ return { sessions: sessions.map(row => ({ ...row, libraryId: bindings[row.id]?.libraryId || null })) }
1225
1230
  }
1226
1231
  case 'listPrivate': {
1227
1232
  const sessionId = requireSessionId(payload)