dsh-memu-memory 1.2.5 → 1.2.7

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 (56) hide show
  1. package/AGENTS.md +3 -1
  2. package/README.md +3 -3
  3. package/README.zh.md +3 -3
  4. package/docs/contributing.md +1 -1
  5. package/docs/env-and-commands.md +1 -0
  6. package/docs/host-adaptation.md +318 -0
  7. package/docs/host-api.md +29 -5
  8. package/docs/memory-semantics.md +12 -7
  9. package/docs/troubleshooting.md +15 -9
  10. package/lib/binding-diagnostics.js +2 -2
  11. package/lib/client.js +291 -37
  12. package/lib/consolidation-ledger.js +46 -1
  13. package/lib/consolidation-worker.js +1 -0
  14. package/lib/curator-policy.js +98 -0
  15. package/lib/cycle.js +51 -17
  16. package/lib/fork-model.js +312 -0
  17. package/lib/index.js +8 -0
  18. package/lib/memory.js +36 -12
  19. package/lib/memu.js +318 -3
  20. package/lib/private.js +352 -70
  21. package/lib/prompts/private-consolidation.mixed.md +1 -0
  22. package/lib/prompts/private-consolidation.rp.md +1 -0
  23. package/lib/prompts/private-policy.mixed.md +1 -0
  24. package/lib/prompts/private-policy.rp.md +1 -1
  25. package/lib/recall-cache.js +204 -0
  26. package/lib/rpc.js +48 -7
  27. package/lib/salient-wake.js +38 -2
  28. package/lib/state.js +46 -6
  29. package/lib/text-retrieval.js +221 -28
  30. package/lib/tokenizer-v2.js +295 -0
  31. package/lib/webui/standalone.css +17 -1
  32. package/package.json +1 -1
  33. package/scripts/bench-recall.mjs +142 -0
  34. package/scripts/check-seed-compat.mjs +118 -0
  35. package/tests/absorb-review.test.mjs +2 -1
  36. package/tests/backend-compensation.test.mjs +1 -1
  37. package/tests/consolidation-fork.test.mjs +199 -7
  38. package/tests/curator-absorb.test.mjs +2 -1
  39. package/tests/curator-clusters.test.mjs +9 -2
  40. package/tests/curator-commit.test.mjs +2 -1
  41. package/tests/curator-link.test.mjs +2 -1
  42. package/tests/curator-pairing.test.mjs +52 -8
  43. package/tests/curator-review-mode.test.mjs +2 -1
  44. package/tests/cycle.test.mjs +2 -2
  45. package/tests/dynamic-rrf.test.mjs +179 -0
  46. package/tests/fork-model.test.mjs +345 -0
  47. package/tests/loader.mjs +3 -0
  48. package/tests/managed-memory.test.mjs +1 -1
  49. package/tests/negation-polarity.test.mjs +135 -0
  50. package/tests/recall-cache.test.mjs +290 -0
  51. package/tests/recall-dedup.test.mjs +1 -1
  52. package/tests/salient-wake.test.mjs +28 -1
  53. package/tests/stubs/dsh-llm-pi-ai.js +13 -0
  54. package/tests/stubs/dsh-schedule.js +35 -0
  55. package/tests/tokenizer-v2.test.mjs +142 -0
  56. package/tests/ui-defaults.test.mjs +1 -1
@@ -91,6 +91,8 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
91
91
 
92
92
  **守卫**:同库连续两次写后条目数对不上即可确认;并发用例见 `tests/storage.test.mjs`。
93
93
 
94
+ **召回缓存(1.2.7)不是本症状的成因**:写路径(remember/update/整理提交)都会推进 `memoryRevision()`,缓存键随之变化,同进程写后立即召回不会命中旧键。唯一残留窗口是**跨进程写**(第二窗口/独立进程改库):revision 是进程内的,另一进程最多多看 120s(TTL)旧召回,之后自动刷新;`bumpGeneration()` 可手动清。
95
+
94
96
  ### 3.5 面板不自动刷新(S8 心跳)
95
97
 
96
98
  **症状**:侧边栏 / 设置页要手点刷新才更新,心跳却一直在跑。
@@ -253,11 +255,11 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
253
255
 
254
256
  **症状**:开了 `salientWake='schedule'`,条目明天到期,第二天会话里什么都没发生;或者宿主的定时任务界面里根本没有 `memu:due:` 任务。
255
257
 
256
- **落点**:`lib/salient-wake.js` 是整理周期里的一个 pass(`lib/cycle.js`),所以先看周期有没有跑。按顺序排:① 设置真的存下了吗(`setSettings` 的 allowlist 漏 key 会静默丢弃,`state.json` 里应出现 `salientWake: 'schedule'`);② 宿主有没有 schedule 服务(`ctx.get('schedule')` 可能是 undefined,此时只 warn 一次并降级为被动注入);③ 时区(`salientWakeTimeZone` 留空跟随系统,填了无效 IANA 区就整轮跳过并记一条);④ 时刻(`HH:mm`,早于该时刻的当天槽位不补建,只排明天);⑤ 会话状态(`useLibrary=false`、归档会话、subagent 会话会被宿主拒或本插件主动跳过)。活动日志 `kind='wake'` 的 `detail.stage`(`service / timezone / index / list / cleanup / create / pass`)就是这条排查线。
258
+ **落点**:`lib/salient-wake.js` 是整理周期里的一个 pass(`lib/cycle.js`),所以先看周期有没有跑。按顺序排:① 设置真的存下了吗(`setSettings` 的 allowlist 漏 key 会静默丢弃,`state.json` 里应出现 `salientWake: 'schedule'`);② 宿主有没有 schedule 服务(`ctx.get('schedule')` 可能是 undefined,此时只 warn 一次并降级为被动注入);③ **宿主是哪一代 schedule API**——`0.2.2+` 是宿主级任务表(`create(request)` / `list→{items}` / `edit`),`0.2.0–0.2.1` 是会话级提醒(`create(sessionId,request)` / `list({sessionId})` / `delete`);旧宿主上 `scheduleFlavor()` 返回 `session`,pass 以 `skipped: 'schedule-api'` 降级并只 warn 一次,不会排程也不该排程;④ 时区(`salientWakeTimeZone` 留空跟随系统,填了无效 IANA 区就整轮跳过并记一条);⑤ 时刻(`HH:mm`,早于该时刻的当天槽位不补建,只排明天);⑥ 会话状态(`useLibrary=false`、归档会话、subagent 会话会被宿主拒或本插件主动跳过)。活动日志 `kind='wake'` 的 `detail.stage`(`service / schedule-api / timezone / index / list / cleanup / create / pass`)就是这条排查线。
257
259
 
258
260
  **已经建了任务但没开口**:投递是 `agent.followup`,宿主进程必须活着;那一回合的 `source.kind==='schedule'`,本插件的召回/纪念日块**不会**运行,能看到的只有唤醒 prompt 自带的内容(这是设计,见 `docs/host-api.md` §6.6)。用户手删的任务会在下一轮 sweep 重建——同一天已 `ended` 的才清理。
259
261
 
260
- **守卫**:`tests/salient-wake.test.mjs`(默认 off 不问宿主、无服务只 warn 一次、今天/明天各一条且 prompt 自包含、二次 sweep 幂等、ended 清理、paused 不动、subagent/归档/其它错误只跳过该会话、年度 `MM-DD` 不提前、无效时区不抛错)。真机验收项单独记录:造一条明天到期的条目 → 宿主 schedule UI 出现 `memu:due:` → 到点会话被唤醒 → 次日 sweep 清理。
262
+ **守卫**:`tests/salient-wake.test.mjs`(默认 off 不问宿主、无服务只 warn 一次、旧会话级 API 只 warn 一次且一次都不调用、`scheduleFlavor()` 两种形状、今天/明天各一条且 prompt 自包含、二次 sweep 幂等、ended 清理、paused 不动、subagent/归档/其它错误只跳过该会话、年度 `MM-DD` 不提前、无效时区不抛错)。真机验收项单独记录:造一条明天到期的条目 → 宿主 schedule UI 出现 `memu:due:` → 到点会话被唤醒 → 次日 sweep 清理。
261
263
 
262
264
  ### 3.22 时效提示没出现(S6 注入)
263
265
 
@@ -309,13 +311,17 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
309
311
 
310
312
  **症状**:整理提醒里出现「整理超时 · fork f-xxxxxx · timeout:consolidation timed out after Ns」,而对话本身一切正常、库里也可能已经多了几条记忆。
311
313
 
312
- **落点**:整理是一次**整段会话的 fork**——种子是截止快照的全部事件,worker 先读完整段转录才开始写,所以耗时随会话长度涨。2026-11-02 的真实读数(935 条事件的会话):开始后 **125 s 才写出第一条**,180 s 到点时只写完 3 条 → 超时;退避重试 131 s 完成。也就是说 180 s 的固定预算对大会话必然偏紧,**不是卡死、不是死锁,也不会丢已写入的记忆**。
314
+ **落点**:整理是一次**会话 fork**。2026-11-02 的真实读数(935 条事件的会话):开始后 **125 s 才写出第一条**,180 s 到点时只写完 3 条 → 超时;退避重试 131 s 完成。也就是说固定预算对大会话必然偏紧,**不是卡死、不是死锁,也不会丢已写入的记忆**。
315
+
316
+ **现在(2026-11-05 起)不再把整段转录种进 fork**:每次只种一个窗口(`CONSOLIDATION_WINDOW_EVENTS = 300` 事件,尾部按完整回合对齐),种子只保留真人消息 / 助手正文 / 工具调用与结果,去掉 reasoning、`source.replayState`、`data.stream`、插件召回、运行时上下文、`request/header` 等后台事件;工具结果截断到 1600 字并去重,重复角色卡只留第一份。窗口开头再放一条 `[memory-catalog]` 已有记忆目录(id + 标题 + layer + status),worker 用它去重/合并,不需要为了解旧库再读整段历史。剩余事件留给下一次扫描,游标只在回执对账后前进。
317
+
318
+ **触发与频率**:默认 `sleepAfterIdleMinutes = 2`;每 5 分钟扫描时还可能因为「pending ≥ 200 事件 / ≥10 个真人回合」的**水位**触发,不依赖空闲。新活动但水位不足时会做一次**探针**(读转录、评估,不起 fork),探针之间至少隔 15 分钟。寒暄 / 无新事件是终态:写入 `lastSleepAt`,下一条真人消息到达前不再重扫。同一快照连续失败 2 次后跳过(`snapshot-failed`),新事件会改变快照哈希,重新获得机会。
313
319
 
314
- **现在的做法**:预算按范围大小推(`consolidationWaitBudget(eventCount)`,政策 `120 s + 0.35 s/事件`,夹在 `[180 s, 600 s]`;斜率取自上面实测的 0.14–0.2 s/事件并留约 2 倍余量)。显式传 `maxWaitMs` 的调用方(测试、工具)仍然完全由调用方决定。「整理已开始」那条日志现在会写「预算 Ns」,失败行也会写「over N events」,所以下次看到超时能直接判断是不是范围太大。**超时仍然不会推进 `lastSleepSeq`**(没有回执就不算整理过),重试会重读同一段——这是 `§14.8`「先证明覆盖范围再推进」的代价,不能为了省时间改成部分推进。
320
+ **预算**:按**这一窗**的事件数推(`consolidationWaitBudget(windowEvents)`,政策 `120 s + 0.35 s/事件`,夹在 `[180 s, 600 s]`)。显式传 `maxWaitMs` 的调用方(测试、工具)仍然完全由调用方决定。「整理已开始」日志会写「窗口 N 条 / 父会话 M 条 / 新 F 条 / 还余 R / 预算 Ns」,失败行写「over N events」。**超时仍然不会推进 `lastSleepSeq`**(没有回执就不算整理过),重试只重跑当前窗口,不会再重读整段历史。
315
321
 
316
- **还能再快的两条路(未做,需拍板)**:① 把 fork 的种子换成脱敏压缩后的转录(远端路径 `condenseEvents` 已有先例,但 fork 的种子来自 `dsh-session.buildForkSeed`,要动得先确认能替换);② 常驻 MemU 进程,替掉「每次工具调用新起 python(导入链 2.05 s)」——这条同时能提速每轮召回与迁移重建。
322
+ **常驻 MemU 进程(2026-11-05)**:本地向量模式(`memoryBackend=api` + `vectorSource=local`)下只起一个 Python 解释器,`import memu.cli` 只付一次,`retrieve` / `list-files` / `commit` 走 JSON 行协议复用;每条命令结束显式关闭 database,不把 sqlite 句柄留到空闲期。远端 API 路由仍是每命令一个进程。插件卸载与引擎安装/切换前会关闭常驻进程;进程异常退出后下一条命令冷启动,召回照旧 fail-open。
317
323
 
318
- **守卫**:`tests/consolidation-fork.test.mjs` 的 `the consolidation wait budget scales with the transcript`(0/100/200/935/5000/非法值)与既有的 `a fork still running at the deadline reports a timeout instead of silence`(显式 30 ms 仍生效、超时不得推进游标)。
324
+ **守卫**:`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`。
319
325
 
320
326
 
321
327
  ## 守卫索引表
@@ -345,7 +351,7 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
345
351
  | §3.18 | 聊很久一条记忆都没写 | `tests/cycle.test.mjs`(阈值 / 启动补偿 / `sessionGone` 只标一次 / 寒暄不 fork / fork 失败必须退避)+ `tests/consolidation-value.test.mjs`(评估边界)+ `tests/consolidation-fork.test.mjs`(继承父模型路由 / 失败 turn 不推进 `lastSleepSeq`);手工看 `state.json` 的 `lastSleepAt`/`lastSleepSeq`/`sessionGone`/`sleepAttempts`/`lastSleepError`/`sleepRetryAt`。 |
346
352
  | §3.19 | 人格预设会话里完全没有记忆 | `tests/preset-scope.test.mjs`(同树跳过 / 兄弟树挂上 / 只挂一次 / agent 消失就卸载 / 子 agent 跳过);日志 `attached memory injection to preset conversation`;`state.json` 里该会话出现 binding。 |
347
353
  | §3.20 | 鉴权矩阵 / 401/403 副作用 | `tests/webui-auth.test.mjs`:两前缀各自 handler、401/403/放行、正文零拉取、`DSH_MEMU_HOME` 读写探针为 0、库/附件快照不变;真机凭据与宿主路由层未验证。 |
348
- | §3.21 | 日期到点没唤醒 | `tests/salient-wake.test.mjs`;活动日志 `kind:'wake'` 的 `detail.stage`(service/timezone/index/list/cleanup/create/pass)就是排查线,`state.json` 里先确认 `salientWake` 真的存下了。 |
354
+ | §3.21 | 日期到点没唤醒 | `tests/salient-wake.test.mjs`;活动日志 `kind:'wake'` 的 `detail.stage`(service/schedule-api/timezone/index/list/cleanup/create/pass)就是排查线,`state.json` 里先确认 `salientWake` 真的存下了;`0.2.0–0.2.1` 的会话级 schedule API 会以 `schedule-api` 降级,属预期。 |
349
355
  | §3.22 | 时效提示没出现 | `tests/freshness.test.mjs` + `tests/injection-chain.test.mjs`;前置条件(真有召回、开关、预算装得下)少一个就不出,不是 bug。 |
350
356
  | §3.23 | 实体合并 / 担心丢记忆 | `tests/entity-merge.test.mjs`(链接改指、别名 cap、快照冲突取舍、拒绝形状);合并只改指向,正文与条数不变。 |
351
357
  | §3.24 | 失败一轮后锚点/日期再不出现 | `tests/injection-rollback.test.mjs`(6 条:撤回+重投、completed 不重复、迟到事件撤不动、已进转录的 500 类失败不误撤、投放前取消撤回、纪念日复提时钟一起撤)。 |
@@ -356,7 +362,7 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
356
362
 
357
363
  ### 2.1 模块地图
358
364
 
359
- <!-- rpc-method-count: 95 -->
365
+ <!-- rpc-method-count: 97 -->
360
366
 
361
367
  | 文件 | 职责 / 什么时候碰它 |
362
368
  |---|---|
@@ -458,7 +464,7 @@ section 的 `text(context)` 能拿到 `context.agent`,所以 system prompt **
458
464
 
459
465
  ## 1. 硬规则(不放宽)
460
466
 
461
- 1. **不改 DSH 源码**,只用插件、公开 service、RPC、slot;只用公开扩展点。
467
+ 1. **不改 DSH 源码**,只用插件、公开 service、RPC、slot;只用公开扩展点。宿主差异一律用能力探测(新方法/字段存在性、返回值形状、逐级回退),不写版本号比较;旧宿主上的可选能力宁可降级并留一行日志,也不 fail closed。流程见 `docs/host-adaptation.md`。
462
468
  2. **不让主 agent 写全局记忆**:全局只由 curator 写,主 agent 只读。
463
469
  3. **记忆规则与动态记忆都走 plugin 消息**:当前版本不再注册 system prompt 段;静态 guide 在回合首步以 `<memory-guide rules="…">` 投放(`rulesKey` 处理切域/改稿/压缩丢失),动态记忆走独立 plugin 消息,保护 KV cache 并让注入可折叠。
464
470
  4. **不每步注入**:普通回合首步注入;长工具回合只在出现尚未处理的真实人类消息批次时追加一次。工具日志、心跳不算人类消息。
@@ -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:347', name: 'inFlight', keyedBy: 'sessionId', clearedBy: 'consolidation settle' },
57
+ { layer: 'temporary-map', file: 'lib/private.js:535', name: 'inFlight', keyedBy: 'sessionId', clearedBy: 'consolidation settle' },
58
58
  { layer: 'temporary-map', file: 'lib/curator.js:50', name: 'jobs', keyedBy: 'job id', clearedBy: 'curation settle' },
59
- { layer: 'cache', file: 'lib/state.js:1146', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
59
+ { layer: 'cache', file: 'lib/state.js:1186', 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
@@ -274,11 +274,24 @@ window.__ModuleLoader__.load({
274
274
  warning: '更新到未经验证的最新版可能导致 CLI 变化或记忆功能损坏。只安装插件声明的推荐版本。',
275
275
  memorySettings: '记忆设置',
276
276
  settingsTuning: '注入与召回',
277
+ settingsHeaderNote: '改动即时保存(约 0.25 秒后写盘);「恢复默认」需两次点击确认。',
278
+ settingsGroupRecall: '召回与注入',
279
+ settingsGroupRecallDesc: '每轮注入什么、注入多少:注入模式、召回条数、token 预算与去重。',
280
+ settingsGroupLifecycle: '记忆生命周期',
281
+ settingsGroupLifecycleDesc: '永久上限、短期保留、未了之事复提与归档清理节奏。',
282
+ settingsGroupCuration: '整理与唤醒',
283
+ settingsGroupCurationDesc: '空闲整理与全局自动提炼的节奏,以及日期到点唤醒。',
284
+ settingsGroupEngine: '引擎与后端',
285
+ settingsGroupEngineDesc: 'MemU 存储模式与引擎自动安装。',
286
+ settingsGroupSession: '会话与界面',
287
+ settingsGroupSessionDesc: '新会话提示、侧边栏设置入口与图片描述。',
288
+ settingsGroupIntegration: '集成',
289
+ settingsGroupIntegrationDesc: '对外暴露的消息工具白名单与视觉描述服务。',
277
290
  autoInject: '注入模式',
278
291
  privateTopK: '私有 topK',
279
292
  globalTopK: '全局 topK',
280
293
  crossLibraryRecall: '跨库召回(仅同领域)',
281
- crossLibraryRecallHint: '开启后,自动召回、memu_private_recall、memu_private_list 与侧栏私有列表会合并其它“同领域”私有记忆库;词典的锚点摘要、本回合匹配与 memu_lexicon_search 走同一个作用域。显式浏览某个库时仍只显示该库。写入仍只写当前库(全局词典只有你能写)。跨文件夹读取会改变隔离边界,默认关闭。',
294
+ crossLibraryRecallHint: '开启后,这些读取会合并其它「同领域」私有库:自动召回、memu_private_recall、memu_private_list、侧栏私有列表,以及词典的锚点摘要、本回合匹配与 memu_lexicon_search。\n显式浏览某个库时,仍只显示该库。\n写入不受影响,仍只写当前库;全局词典只有你能写。\n跨库读取改变隔离边界,默认关闭。',
282
295
  mustRememberCap: '永久记忆软上限',
283
296
  shortTermTtlHours: '短期记忆保留(小时,0=关闭)',
284
297
  anchorTokens: '锚点 token',
@@ -297,12 +310,34 @@ window.__ModuleLoader__.load({
297
310
  salientWakeSchedule: '到点唤醒会话',
298
311
  salientWakeHour: '唤醒时间(HH:mm)',
299
312
  salientWakeTimeZone: '唤醒时区(留空跟随系统)',
300
- salientWakeHint: '实验特性,默认关闭。唤醒走宿主定时任务投递,会替会话开一整轮;只有宿主进程活着才会触发,任务在宿主的定时任务界面可见、可手动删除。还没做过真机验收,建议先在测试库里试开。',
313
+ salientWakeHint: '实验特性,默认关闭:唤醒会替会话开一整轮,由宿主定时任务投递。\n只有宿主进程活着才会触发;任务在宿主的定时任务界面可见、可手动删除。\n还没做过真机验收,建议先在测试库里试开。',
301
314
  autoInstall: '自动安装引擎',
302
315
  sleepConsolidation: '空闲后整理记忆',
303
316
  sleepAfterIdleMinutes: '空闲多久后整理(分钟)',
304
317
  autoCurateEveryHours: '全局自动提炼间隔(小时,0=关闭)',
305
318
  autoCurateSessionLimit: '每次最多纳入的对话数',
319
+ consolidationModelMode: '整理模型',
320
+ consolidationModeInherit: '继承当前会话',
321
+ consolidationModeHost: '指定宿主模型',
322
+ consolidationModeCustom: '自定义接入点',
323
+ consolidationHostProvider: '宿主 Provider',
324
+ consolidationHostModel: '宿主模型',
325
+ consolidationProviderPick: '选择 provider',
326
+ consolidationModelPick: '选择模型',
327
+ consolidationCatalogLoading: '正在读取宿主模型目录…',
328
+ consolidationCatalogDegraded: '拿不到宿主模型目录(或目录为空),直接按 provider/model 手填。',
329
+ consolidationHostHint: '这里列出的是宿主已配置的 provider/route,整理 fork 直接指名它,不新建连接。',
330
+ consolidationKeyKeep: '已配置,留空保持不变',
331
+ consolidationKeyEmpty: '选填;本地网关可以没有 key',
332
+ consolidationCustomModel: '模型 ID',
333
+ consolidationCustomApiLabel: '线协议',
334
+ consolidationDiscover: '拉取模型列表',
335
+ consolidationDiscoverDone: '拉到 {n} 个模型',
336
+ consolidationDiscoverFailed: '拉取失败',
337
+ consolidationCustomHint: '每次整理前自动注册这个接入点(无需重启),失败自动降级回继承并在日志里说明;API key 只存本地,不进日志。',
338
+ consolidationCustomUnavailable: '这台宿主缺少挂载自定义接入点的能力(llm.registerAdapter 或 PiAiAdapter 不在),改用「指定宿主模型」或「继承当前会话」。',
339
+ curatorModel: '全局整理模型',
340
+ curatorModelHint: '全局记忆提炼用的模型,格式 provider/model,留空跟随当前会话;与上面的私有整理模型是两条路。',
306
341
  memoryMode: 'MemU 存储模式',
307
342
  memoryModeHint: 'local 把记忆留在本机;cloud 交给 MemU 官方后端,需要 ~/.memu/config.env 里的厂商凭据。',
308
343
  memoryBackend: '记忆后端',
@@ -1043,11 +1078,24 @@ window.__ModuleLoader__.load({
1043
1078
  warning: 'Unverified latest releases can change the CLI or break memory. Only the recommended version declared by the plugin is installed.',
1044
1079
  memorySettings: 'Memory settings',
1045
1080
  settingsTuning: 'Injection & recall',
1081
+ settingsHeaderNote: 'Edits save themselves about 0.25s after each change; Reset defaults asks for a second click.',
1082
+ settingsGroupRecall: 'Recall & injection',
1083
+ settingsGroupRecallDesc: 'What each turn injects and how much: injection mode, topK, token budgets, dedupe.',
1084
+ settingsGroupLifecycle: 'Memory lifecycle',
1085
+ settingsGroupLifecycleDesc: 'Permanent cap, short-term retention, open-loop reminders and archive cleanup.',
1086
+ settingsGroupCuration: 'Curation & wake',
1087
+ settingsGroupCurationDesc: 'Idle consolidation and global auto-curation cadence, plus salient-date wake.',
1088
+ settingsGroupEngine: 'Engine & backend',
1089
+ settingsGroupEngineDesc: 'MemU storage mode and engine auto-install.',
1090
+ settingsGroupSession: 'Session & interface',
1091
+ settingsGroupSessionDesc: 'New-session prompt, sidebar settings entry and image captioning.',
1092
+ settingsGroupIntegration: 'Integration',
1093
+ settingsGroupIntegrationDesc: 'External message tool allowlist and the vision caption service.',
1046
1094
  autoInject: 'Injection mode',
1047
1095
  privateTopK: 'Private topK',
1048
1096
  globalTopK: 'Global topK',
1049
1097
  crossLibraryRecall: 'Cross-library recall (same domain)',
1050
- crossLibraryRecallHint: 'When on, automatic recall, memu_private_recall, memu_private_list and the sidebar private list merge other private libraries that use the same domain; the lexicon anchor, this-turn match and memu_lexicon_search follow the same scope. An explicit library browser still shows only that library. Writes still go to the bound library only (the global lexicon is yours alone to write). Reading across folders changes the isolation boundary, so this is off by default.',
1098
+ crossLibraryRecallHint: 'When on, these reads merge other same-domain private libraries: automatic recall, memu_private_recall, memu_private_list, the sidebar private list, plus the lexicon anchor summaries, this-turn matching and memu_lexicon_search.\nExplicitly browsing a library still shows that library only.\nWrites are unaffected and still go to the current library; the global lexicon stays yours alone to write.\nReading across libraries changes the isolation boundary, so this is off by default.',
1051
1099
  mustRememberCap: 'Permanent memory cap',
1052
1100
  shortTermTtlHours: 'Short-term TTL in hours (0=off)',
1053
1101
  anchorTokens: 'Anchor tokens',
@@ -1066,12 +1114,34 @@ window.__ModuleLoader__.load({
1066
1114
  salientWakeSchedule: 'Wake the conversation',
1067
1115
  salientWakeHour: 'Wake time (HH:mm)',
1068
1116
  salientWakeTimeZone: 'Wake time zone (empty = system)',
1069
- salientWakeHint: 'Experimental and off by default. Delivery goes through the host scheduler and opens a full turn for the conversation. It only fires while the host process is alive, and the tasks are visible (and deletable) in the host schedule UI. Not yet verified on a real install — try it on a test library first.',
1117
+ salientWakeHint: 'Experimental and off by default: a wake opens a full turn for the conversation, delivered by the host scheduler.\nIt only fires while the host process is alive; tasks stay visible (and deletable) in the host schedule UI.\nNot yet verified on a real install — try it on a test library first.',
1070
1118
  autoInstall: 'Auto-install engine',
1071
1119
  sleepConsolidation: 'Consolidate after idle',
1072
1120
  sleepAfterIdleMinutes: 'Idle minutes before consolidating',
1073
1121
  autoCurateEveryHours: 'Auto global curation every N hours (0=off)',
1074
1122
  autoCurateSessionLimit: 'Max conversations per auto run',
1123
+ consolidationModelMode: 'Consolidation model',
1124
+ consolidationModeInherit: 'Inherit the conversation',
1125
+ consolidationModeHost: 'Pick a host model',
1126
+ consolidationModeCustom: 'Custom endpoint',
1127
+ consolidationHostProvider: 'Host provider',
1128
+ consolidationHostModel: 'Host model',
1129
+ consolidationProviderPick: 'Pick a provider',
1130
+ consolidationModelPick: 'Pick a model',
1131
+ consolidationCatalogLoading: 'Loading the host model catalog…',
1132
+ consolidationCatalogDegraded: 'Host catalog unavailable (or empty) — type provider/model directly.',
1133
+ consolidationHostHint: 'These are the providers/routes the host already configured; the consolidation fork names one of them directly, no new connection.',
1134
+ consolidationKeyKeep: 'Configured; leave blank to keep',
1135
+ consolidationKeyEmpty: 'Optional; local gateways may run without a key',
1136
+ consolidationCustomModel: 'Model ID',
1137
+ consolidationCustomApiLabel: 'Wire protocol',
1138
+ consolidationDiscover: 'Fetch model list',
1139
+ consolidationDiscoverDone: 'Found {n} models',
1140
+ consolidationDiscoverFailed: 'Fetch failed',
1141
+ consolidationCustomHint: 'The endpoint is re-registered before every consolidation (no restart needed); on failure the fork falls back to inherit with a log line. The API key stays on this machine and never enters logs.',
1142
+ consolidationCustomUnavailable: 'This host cannot mount a custom endpoint (llm.registerAdapter or PiAiAdapter missing); use "Pick a host model" or "Inherit the conversation".',
1143
+ curatorModel: 'Global curator model',
1144
+ curatorModelHint: 'Model for global memory curation, format provider/model; empty follows the current conversation — a separate path from the private consolidation model above.',
1075
1145
  memoryMode: 'MemU storage mode',
1076
1146
  memoryModeHint: 'local keeps memory on this machine; cloud hands storage to the MemU backend and needs vendor credentials in ~/.memu/config.env.',
1077
1147
  memoryBackend: 'Memory backend',
@@ -2303,18 +2373,17 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2303
2373
  return enumText(t, DOMAIN_LABELS, raw)
2304
2374
  }
2305
2375
 
2306
- // 情绪构成的短标签:同样的 valence 可能来自怒,也可能来自哀,一个数字分不出来。
2376
+ // 情绪构成:四轴按固定顺序完整输出(喜/怒/哀/惧),不截断、不重排。
2377
+ // 只显示 top-2 会让“喜0.6/哀0.4”看起来像只有两种情绪,而构成本来就是四维;
2378
+ // 同理,阈值过滤会把小分量的轴吞掉,看不出“四轴各是多少”。
2307
2379
  // 四轴固定且术语极短,就地映射,不为四个轴各加一个 i18n key。
2308
2380
  const EMOTION_TAG_LABELS = { joy: '喜', anger: '怒', sorrow: '哀', fear: '惧' }
2309
2381
  function emotionTagText(emotion) {
2310
2382
  if (!emotion || typeof emotion !== 'object') return ''
2311
- return Object.entries(EMOTION_TAG_LABELS)
2383
+ const axes = Object.entries(EMOTION_TAG_LABELS)
2312
2384
  .map(([axis, label]) => ({ label, share: Number(emotion[axis]) || 0 }))
2313
- .filter((item) => item.share >= 0.05)
2314
- .sort((a, b) => b.share - a.share)
2315
- .slice(0, 2)
2316
- .map((item) => `${item.label}${item.share.toFixed(1)}`)
2317
- .join('/')
2385
+ if (!axes.some((item) => item.share > 0)) return ''
2386
+ return axes.map((item) => `${item.label}${item.share.toFixed(2)}`).join('/')
2318
2387
  }
2319
2388
 
2320
2389
  const EMOTION_SOURCE_LABELS = {
@@ -3101,6 +3170,11 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3101
3170
  }
3102
3171
 
3103
3172
  const shown = detail ? { ...detail.item, ...(detail.file || {}) } : null
3173
+ // 详情抽屉与卡片共用同一份情绪行:四轴构成 + 激活/掌控/来源,缺哪段就少哪段。
3174
+ const affectText = shown
3175
+ ? [emotionTagText(shown.emotion) ? `${t('moodTag')} ${emotionTagText(shown.emotion)}` : '', emotionMetaText(shown, t)]
3176
+ .filter(Boolean).join(' · ')
3177
+ : ''
3104
3178
  const detailForm = detail && detail.file && !detail.readonly
3105
3179
  ? h('div', { className: 'dshm-drawer-form' },
3106
3180
  h('input', {
@@ -3145,7 +3219,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3145
3219
  h('div', { className: 'dshm-drawer-note' },
3146
3220
  t('decay') + ' ' + Math.round((Number(shown.decay) || 0) * 100) + '% · ' +
3147
3221
  (shown.updatedAt ? String(shown.updatedAt).slice(0, 16).replace('T', ' ') : '')),
3148
- emotionMetaText(shown, t) ? h('div', { className: 'dshm-drawer-note' }, emotionMetaText(shown, t)) : null)
3222
+ affectText ? h('div', { className: 'dshm-drawer-note' }, affectText) : null)
3149
3223
  : detail && detail.file && detail.readonly
3150
3224
  ? (() => {
3151
3225
  // 全局条目只读(spec §6.7 UI):详情抽屉里只读展示 links / absorbedFrom,
@@ -3969,6 +4043,17 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3969
4043
  // Which snapshot the painted settings belong to (task E). Refetched only when
3970
4044
  // the marker moves, so a write made in another window lands within one beat.
3971
4045
  const markerRef = React.useRef(null)
4046
+ // 整理 fork 的宿主模型目录(listForkModelOptions):切到 host/custom 时懒加载一次并
4047
+ // 缓存。失败只置 error 状态,相关行降级为手填输入——用户不被卡死。
4048
+ const [forkCatalog, setForkCatalog] = React.useState(null)
4049
+ const [forkCatalogState, setForkCatalogState] = React.useState('idle')
4050
+ // custom 模式的 key 草稿:密码框只养草稿,留空或删光都不覆盖已存的 key
4051
+ //(后端 updateSettings 对空串的语义是「清空」,所以 UI 只在有输入时才写)。
4052
+ const [forkKeyDraft, setForkKeyDraft] = React.useState('')
4053
+ const [forkDiscoverBusy, setForkDiscoverBusy] = React.useState(false)
4054
+ const [forkDiscoverNote, setForkDiscoverNote] = React.useState('')
4055
+ const [forkDiscoverModels, setForkDiscoverModels] = React.useState(null)
4056
+ const forkCatalogLoadingRef = React.useRef(false)
3972
4057
 
3973
4058
  const adoptState = (value) => {
3974
4059
  setState({ ...value, settings: { ...value?.settings, ...pendingSettings.current } })
@@ -4024,6 +4109,22 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4024
4109
  window.addEventListener?.('pagehide', flush)
4025
4110
  return () => { window.removeEventListener?.('pagehide', flush); clearTimeout(settingsTimer.current); flush() }
4026
4111
  }, [flushSettings])
4112
+ // 宿主模型目录懒加载:切到 host/custom 时拉一次,缓存在组件状态里,之后不再重复
4113
+ // 拉。失败不抛——目录拿不到只是降级成手填,设置页不该为一个目录炸掉。
4114
+ const loadForkCatalog = React.useCallback(async () => {
4115
+ if (forkCatalogLoadingRef.current) return
4116
+ forkCatalogLoadingRef.current = true
4117
+ setForkCatalogState('loading')
4118
+ try {
4119
+ setForkCatalog(await call('listForkModelOptions', {}))
4120
+ setForkCatalogState('loaded')
4121
+ } catch {
4122
+ setForkCatalog(null)
4123
+ setForkCatalogState('error')
4124
+ } finally {
4125
+ forkCatalogLoadingRef.current = false
4126
+ }
4127
+ }, [call])
4027
4128
  React.useEffect(() => {
4028
4129
  if (!standalone) return undefined
4029
4130
  const sync = () => {
@@ -4218,6 +4319,13 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4218
4319
  void loadReviews()
4219
4320
  }
4220
4321
  }, [page, foldersLoaded, promptsLoaded, globalLoaded, loadFolders, loadPrompts, loadGlobal, loadSessions, loadReviews])
4322
+ // host 需要 provider/model 枚举,custom 需要 customAvailable/discoveryAvailable
4323
+ // 能力位——三态不在 inherit 时目录才值得拉(一次,之后吃缓存)。
4324
+ React.useEffect(() => {
4325
+ const mode = state?.settings?.consolidationModelMode || 'inherit'
4326
+ if (mode !== 'host' && mode !== 'custom') return
4327
+ if (forkCatalogState === 'idle') void loadForkCatalog()
4328
+ }, [state?.settings?.consolidationModelMode, forkCatalogState, loadForkCatalog])
4221
4329
  React.useEffect(() => {
4222
4330
  if (page !== PAGE.browser || !browseLibId) return undefined
4223
4331
  let alive = true
@@ -4275,9 +4383,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4275
4383
  return () => { alive = false; clearInterval(id) }
4276
4384
  }, [page, expandedKey, loadFolderSessions])
4277
4385
 
4278
- const saveSettings = async () => {
4279
- await flushSettings()
4280
- }
4281
4386
  // Defaults live on the server (state.js DEFAULT_SETTINGS): the page asks for
4282
4387
  // them rather than carrying a second copy that would drift from the code.
4283
4388
  const resetSettingsNow = async () => {
@@ -4412,6 +4517,33 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4412
4517
  clearTimeout(settingsTimer.current)
4413
4518
  settingsTimer.current = setTimeout(() => { void flushSettings() }, 250)
4414
4519
  }
4520
+ // 「拉取模型列表」:把草稿端点转给 discoverForkModels。apiKey 是一次性草稿凭据——
4521
+ // 密码框里有输入就带草稿,留空就声明复用已存 key(useStoredKey),两者都不回显、
4522
+ // 不进日志。结果只填下拉,失败给一行自清状态。
4523
+ const discoverConsolidationModels = async () => {
4524
+ setForkDiscoverBusy(true)
4525
+ setForkDiscoverNote('')
4526
+ try {
4527
+ const res = await call('discoverForkModels', {
4528
+ baseURL: state?.settings?.consolidationCustomBaseURL || '',
4529
+ api: state?.settings?.consolidationCustomApi || 'openai-completions',
4530
+ apiKey: forkKeyDraft,
4531
+ useStoredKey: !forkKeyDraft,
4532
+ })
4533
+ if (res?.ok === true) {
4534
+ const models = Array.isArray(res.models) ? res.models : []
4535
+ setForkDiscoverModels(models)
4536
+ setForkDiscoverNote(t('consolidationDiscoverDone').replace('{n}', String(models.length)))
4537
+ } else {
4538
+ setForkDiscoverNote(res?.reason ? `${t('consolidationDiscoverFailed')} · ${res.reason}` : t('consolidationDiscoverFailed'))
4539
+ }
4540
+ } catch (e) {
4541
+ setForkDiscoverNote(`${t('consolidationDiscoverFailed')} · ${String(e?.message || e)}`)
4542
+ } finally {
4543
+ setForkDiscoverBusy(false)
4544
+ }
4545
+ setTimeout(() => setForkDiscoverNote(''), 2600)
4546
+ }
4415
4547
  const setBackend = async (backend) => {
4416
4548
  setSetting('memoryBackend', backend)
4417
4549
  setConfigNotice('')
@@ -5297,13 +5429,120 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5297
5429
 
5298
5430
  )
5299
5431
 
5432
+ // 每组一个 Section(title + desc 走 i18n),组内沿用同一个 dshm-settings-grid。
5433
+ // 这里只是重排 + 分组:行与取值逻辑(含 ?? 回落、反向语义开关)一行不增不减。
5434
+ const settingsGroup = (title, desc, ...rows) => h(Section, { title, desc },
5435
+ h('div', { className: 'dshm-settings-grid' }, rows))
5436
+
5437
+ // —— 整理 fork 的模型选择(三模式)行 ——————————————————————————————
5438
+ // 行随 consolidationModelMode 条件渲染:inherit 只露模式选择;host 露宿主目录的
5439
+ // provider/model 两行(目录拿不到就降级成 provider/model 手填,同样写
5440
+ // consolidationModel,用户不被卡死);custom 露接入点四件套(这台宿主确认挂不了
5441
+ // custom 时整组降级为一行说明)。curatorModel 是全局提炼的模型,与这里的私有
5442
+ // 整理模型是两条路,恒常显示。
5443
+ const consolidationMode = settings.consolidationModelMode || 'inherit'
5444
+ const consolidationModelValue = String(settings.consolidationModel || '')
5445
+ const consolidationSlash = consolidationModelValue.indexOf('/')
5446
+ const consolidationProvider = consolidationSlash > 0 ? consolidationModelValue.slice(0, consolidationSlash) : ''
5447
+ const consolidationModelId = consolidationSlash > 0 ? consolidationModelValue.slice(consolidationSlash + 1) : ''
5448
+ const forkProviders = Array.isArray(forkCatalog?.providers) ? forkCatalog.providers : []
5449
+ const forkCatalogReady = forkCatalogState === 'loaded' && forkProviders.length > 0
5450
+ const forkProviderIds = forkCatalogReady ? forkProviders.map((p) => String(p?.id || '')).filter(Boolean) : []
5451
+ const forkModelEntries = forkCatalogReady ? (forkProviders.find((p) => p?.id === consolidationProvider)?.models || []) : []
5452
+ const forkOptionLabel = (item) => (item?.name && item.name !== item.id ? `${item.name} (${item.id})` : String(item?.id || ''))
5453
+ // 下拉要能显示当前值:已有 consolidationModel 但不在目录里(宿主 route 下线)时
5454
+ // 把当前值补成一个选项,显示与状态不脱节。
5455
+ const providerChoices = []
5456
+ if (!consolidationProvider) providerChoices.push({ id: '', label: t('consolidationProviderPick') })
5457
+ if (consolidationProvider && !forkProviderIds.includes(consolidationProvider)) providerChoices.push({ id: consolidationProvider, label: consolidationProvider })
5458
+ for (const id of forkProviderIds) providerChoices.push({ id, label: forkOptionLabel(forkProviders.find((p) => p?.id === id)) })
5459
+ const modelChoices = []
5460
+ if (!consolidationModelId) modelChoices.push({ id: '', label: t('consolidationModelPick') })
5461
+ if (consolidationModelId && !forkModelEntries.some((m) => m?.id === consolidationModelId)) modelChoices.push({ id: consolidationModelId, label: consolidationModelId })
5462
+ for (const m of forkModelEntries) modelChoices.push({ id: m.id, label: forkOptionLabel(m) })
5463
+ const consolidationModelRows = []
5464
+ if (consolidationMode === 'host') {
5465
+ if (forkCatalogReady) {
5466
+ consolidationModelRows.push(
5467
+ h(Field, { label: t('consolidationHostProvider') },
5468
+ h('select', { style: S.input, value: consolidationProvider, onChange: (e) => {
5469
+ const provider = e.target.value
5470
+ if (!provider) { setSetting('consolidationModel', null); return }
5471
+ // 换 provider 顺手选它的第一个模型,避免留下 "<provider>/" 这种
5472
+ // 解析不过的中间态;该 provider 没目录时才留半截让用户接着选。
5473
+ const first = forkProviders.find((p) => p?.id === provider)?.models?.[0]?.id || ''
5474
+ setSetting('consolidationModel', first ? `${provider}/${first}` : `${provider}/`)
5475
+ } },
5476
+ providerChoices.map((choice) => h('option', { key: choice.id, value: choice.id }, choice.label)))),
5477
+ h(Field, { label: t('consolidationHostModel') },
5478
+ h('select', { style: S.input, value: consolidationModelId, onChange: (e) => {
5479
+ if (!e.target.value || !consolidationProvider) return
5480
+ setSetting('consolidationModel', `${consolidationProvider}/${e.target.value}`)
5481
+ } },
5482
+ modelChoices.map((choice) => h('option', { key: choice.id, value: choice.id }, choice.label)))),
5483
+ h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('consolidationHostHint')))
5484
+ } else {
5485
+ consolidationModelRows.push(
5486
+ h(Field, { label: t('consolidationHostModel') },
5487
+ h('input', { type: 'text', style: S.input, placeholder: 'provider/model', value: consolidationModelValue,
5488
+ onChange: (e) => setSetting('consolidationModel', e.target.value || null) })),
5489
+ h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } },
5490
+ forkCatalogState === 'loading' ? t('consolidationCatalogLoading') : t('consolidationCatalogDegraded')))
5491
+ }
5492
+ }
5493
+ if (consolidationMode === 'custom') {
5494
+ if (forkCatalog && forkCatalog.customAvailable === false) {
5495
+ consolidationModelRows.push(h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('consolidationCustomUnavailable')))
5496
+ } else {
5497
+ const customModelId = String(settings.consolidationCustomModel || '')
5498
+ // key 永不回显明文:占位只给「已配置」+ 服务端打码尾 4 位;草稿有输入才写
5499
+ // setSetting(留空/删光 = 保留原值,因为后端对空串的语义是清空)。
5500
+ const keyConfigured = settings.hasConsolidationCustomApiKey === true || Boolean(String(settings.consolidationCustomApiKey || ''))
5501
+ const keyTail = String(settings.consolidationCustomApiKeyTail || '')
5502
+ const keyPlaceholder = keyConfigured
5503
+ ? t('consolidationKeyKeep') + (keyTail && keyTail !== '****' ? ` ····${keyTail}` : '')
5504
+ : t('consolidationKeyEmpty')
5505
+ const discovered = Array.isArray(forkDiscoverModels) ? forkDiscoverModels : []
5506
+ const customModelChoices = []
5507
+ if (!customModelId) customModelChoices.push({ id: '', label: t('consolidationModelPick') })
5508
+ if (customModelId && !discovered.some((m) => m?.id === customModelId)) customModelChoices.push({ id: customModelId, label: customModelId })
5509
+ for (const m of discovered) customModelChoices.push({ id: m.id, label: forkOptionLabel(m) })
5510
+ consolidationModelRows.push(
5511
+ h(Field, { label: t('baseUrl') },
5512
+ h('input', { type: 'text', style: S.input, placeholder: 'http://127.0.0.1:8899', value: settings.consolidationCustomBaseURL || '',
5513
+ onChange: (e) => setSetting('consolidationCustomBaseURL', e.target.value) })),
5514
+ h(Field, { label: t('apiKey') },
5515
+ h('input', { type: 'password', style: S.input, autoComplete: 'new-password', placeholder: keyPlaceholder, value: forkKeyDraft,
5516
+ onChange: (e) => { const next = e.target.value; setForkKeyDraft(next); if (next) setSetting('consolidationCustomApiKey', next) } })),
5517
+ h(Field, { label: t('consolidationCustomModel') },
5518
+ discovered.length
5519
+ ? h('select', { style: S.input, value: customModelId, onChange: (e) => { if (e.target.value) setSetting('consolidationCustomModel', e.target.value) } },
5520
+ customModelChoices.map((choice) => h('option', { key: choice.id, value: choice.id }, choice.label)))
5521
+ : h('input', { type: 'text', style: S.input, placeholder: 'GLM-5.3-Flash', value: customModelId,
5522
+ onChange: (e) => setSetting('consolidationCustomModel', e.target.value) })),
5523
+ h(Field, { label: t('consolidationCustomApiLabel') },
5524
+ h('select', { style: S.input, value: settings.consolidationCustomApi || 'openai-completions', onChange: (e) => setSetting('consolidationCustomApi', e.target.value) },
5525
+ ['openai-completions', 'openai-responses', 'anthropic-messages'].map((v) => h('option', { key: v, value: v }, v)))),
5526
+ forkCatalog?.discoveryAvailable === true
5527
+ ? h('div', { style: S.row },
5528
+ h(Button, { onClick: discoverConsolidationModels, disabled: forkDiscoverBusy, title: t('consolidationDiscover') },
5529
+ forkDiscoverBusy ? t('loading') : t('consolidationDiscover')),
5530
+ forkDiscoverNote ? h('span', { style: S.muted, role: 'status' }, forkDiscoverNote) : null)
5531
+ : null,
5532
+ h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('consolidationCustomHint')))
5533
+ }
5534
+ }
5535
+
5536
+ // 页首精简头部:标题 + 一句话说明 + 恢复默认。保存机制保持原样:设置项即时保存
5537
+ //(250ms trailing debounce + pagehide flush),页首不放「保存」按钮——改动落盘
5538
+ // 由 debounce 兜底;「恢复默认」仍是两段确认后调 resetSettings RPC。
5300
5539
  const settingsBlock = h(React.Fragment, null, h(Section, {
5301
5540
  title: t('settingsTuning'),
5302
5541
  right: h('div', { style: { display: 'flex', gap: 6, flexShrink: 0 } },
5303
- h(Button, { onClick: resetSettingsNow, disabled: busy, style: S.ghost }, resetArmed ? t('settingsResetConfirm') : t('settingsReset')),
5304
- h(Button, { onClick: saveSettings, disabled: busy, primary: true }, t('save'))),
5542
+ h(Button, { onClick: resetSettingsNow, disabled: busy, style: S.ghost, title: resetArmed ? t('settingsResetConfirm') : t('settingsReset') }, resetArmed ? t('settingsResetConfirm') : t('settingsReset'))),
5305
5543
  },
5306
- h('div', { className: 'dshm-settings-grid' },
5544
+ h('div', { className: 'dshm-settings-note', style: { ...S.muted, lineHeight: 1.55 } }, t('settingsHeaderNote'))),
5545
+ settingsGroup(t('settingsGroupRecall'), t('settingsGroupRecallDesc'),
5307
5546
  h(Field, { label: t('autoInject') },
5308
5547
  h('select', { style: S.input, value: settings.autoInject || 'smart', onChange: (e) => setSetting('autoInject', e.target.value) },
5309
5548
  ['smart', 'anchor-only', 'per-turn', 'off'].map((v) => h('option', { key: v, value: v }, enumText(t, INJECT_LABELS, v))))),
@@ -5315,8 +5554,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5315
5554
  h(Field, { label: t('globalTopK') }, h('input', { type: 'number', style: S.input, value: settings.globalTopK ?? 5, onChange: (e) => setSetting('globalTopK', Number(e.target.value)) })),
5316
5555
  h(Field, { label: t('crossLibraryRecall') }, h(Toggle, { checked: settings.crossLibraryRecall === true, label: t('crossLibraryRecall'), onChange: value => setSetting('crossLibraryRecall', value) })),
5317
5556
  h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('crossLibraryRecallHint')),
5318
- h(Field, { label: t('mustRememberCap') }, h('input', { type: 'number', style: S.input, value: settings.mustRememberCap ?? 12, onChange: (e) => setSetting('mustRememberCap', Number(e.target.value)) })),
5319
- h(Field, { label: t('shortTermTtlHours') }, h('input', { type: 'number', min: 0, style: S.input, value: settings.shortTermTtlHours ?? 72, onChange: (e) => setSetting('shortTermTtlHours', Number(e.target.value)) })),
5320
5557
  h(Field, { label: t('anchorTokens') }, h('input', { type: 'number', style: S.input, value: settings.anchorTokens ?? 800, onChange: (e) => setSetting('anchorTokens', Number(e.target.value)) })),
5321
5558
  h(Field, { label: t('turnTokens') }, h('input', { type: 'number', style: S.input, value: settings.turnTokens ?? 800, onChange: (e) => setSetting('turnTokens', Number(e.target.value)) })),
5322
5559
  h(Field, { label: t('injectionTotalTokens') }, h('input', { type: 'number', style: S.input, value: settings.injectionTotalTokens ?? 2000, onChange: (e) => setSetting('injectionTotalTokens', Number(e.target.value)) })),
@@ -5325,35 +5562,50 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5325
5562
  h(Field, { label: t('minUserChars') }, h('input', { type: 'number', style: S.input, value: settings.minUserChars ?? 6, onChange: (e) => setSetting('minUserChars', Number(e.target.value)) })),
5326
5563
  h(Field, { label: t('relevanceThreshold') }, h('input', { type: 'number', step: '0.05', min: 0, max: 1, style: S.input, value: settings.relevanceThreshold ?? 0.4, onChange: (e) => setSetting('relevanceThreshold', Number(e.target.value)) })),
5327
5564
  h(Field, { label: t('randomCueChance') }, h('input', { type: 'number', step: '0.01', min: 0, max: 1, style: S.input, value: settings.randomCueChance ?? 0.02, onChange: (e) => setSetting('randomCueChance', Number(e.target.value)) })),
5328
- h(Field, { label: t('openLoopRemindDays') }, h('input', { type: 'number', min: 1, max: 365, style: S.input, value: settings.openLoopRemindDays ?? 7, onChange: (e) => setSetting('openLoopRemindDays', Number(e.target.value)) })),
5329
5565
  h(Field, { label: t('freshnessHint') }, h(Toggle, { checked: settings.freshnessHint !== false, label: t('freshnessHint'), onChange: value => setSetting('freshnessHint', value) })),
5330
5566
  h(Field, { label: t('freshnessDays') }, h('input', { type: 'number', min: 1, max: 3650, style: S.input, value: settings.freshnessDays ?? 30, onChange: (e) => setSetting('freshnessDays', Number(e.target.value)) })),
5331
5567
  h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('freshnessHintHint')),
5568
+ h(Field, { label: t('habitsInjection') }, h('input', { type: 'checkbox', checked: settings.habitsInjection !== false, onChange: (e) => setSetting('habitsInjection', e.target.checked) }))),
5569
+ settingsGroup(t('settingsGroupLifecycle'), t('settingsGroupLifecycleDesc'),
5570
+ h(Field, { label: t('mustRememberCap') }, h('input', { type: 'number', style: S.input, value: settings.mustRememberCap ?? 12, onChange: (e) => setSetting('mustRememberCap', Number(e.target.value)) })),
5571
+ h(Field, { label: t('shortTermTtlHours') }, h('input', { type: 'number', min: 0, style: S.input, value: settings.shortTermTtlHours ?? 72, onChange: (e) => setSetting('shortTermTtlHours', Number(e.target.value)) })),
5572
+ h(Field, { label: t('openLoopRemindDays') }, h('input', { type: 'number', min: 1, max: 365, style: S.input, value: settings.openLoopRemindDays ?? 7, onChange: (e) => setSetting('openLoopRemindDays', Number(e.target.value)) })),
5573
+ h(Field, { label: t('purgeArchivedAfterDays') }, h('input', { type: 'number', min: 0, style: S.input, value: settings.purgeArchivedAfterDays ?? 0, onChange: (e) => setSetting('purgeArchivedAfterDays', Number(e.target.value)) }))),
5574
+ settingsGroup(t('settingsGroupCuration'), t('settingsGroupCurationDesc'),
5575
+ h(Field, { label: t('sleepConsolidation') }, h('input', { type: 'checkbox', checked: settings.sleepConsolidation === true, onChange: (e) => setSetting('sleepConsolidation', e.target.checked) })),
5576
+ h(Field, { label: t('sleepAfterIdleMinutes') }, h('input', { type: 'number', min: 1, style: S.input, value: settings.sleepAfterIdleMinutes ?? 2, onChange: (e) => setSetting('sleepAfterIdleMinutes', Number(e.target.value)) })),
5577
+ h(Field, { label: t('autoCurateEveryHours') }, h('input', { type: 'number', min: 0, style: S.input, value: settings.autoCurateEveryHours ?? 0, onChange: (e) => setSetting('autoCurateEveryHours', Number(e.target.value)) })),
5578
+ h(Field, { label: t('autoCurateSessionLimit') }, h('input', { type: 'number', min: 1, max: 30, style: S.input, value: settings.autoCurateSessionLimit ?? 8, onChange: (e) => setSetting('autoCurateSessionLimit', Number(e.target.value)) })),
5579
+ h(Field, { label: t('consolidationModelMode') },
5580
+ h('select', { style: S.input, value: consolidationMode, onChange: (e) => setSetting('consolidationModelMode', e.target.value) },
5581
+ h('option', { value: 'inherit' }, t('consolidationModeInherit')),
5582
+ h('option', { value: 'host' }, t('consolidationModeHost')),
5583
+ h('option', { value: 'custom' }, t('consolidationModeCustom')))),
5584
+ ...consolidationModelRows,
5585
+ h(Field, { label: t('curatorModel') }, h('input', { type: 'text', style: S.input, placeholder: 'provider/model', value: settings.curatorModel || '', onChange: (e) => setSetting('curatorModel', e.target.value || null) })),
5586
+ h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('curatorModelHint')),
5332
5587
  h(Field, { label: t('salientWake') },
5333
5588
  h('select', { style: S.input, value: settings.salientWake || 'off', onChange: (e) => setSetting('salientWake', e.target.value) },
5334
5589
  h('option', { value: 'off' }, t('salientWakeOff')),
5335
5590
  h('option', { value: 'schedule' }, t('salientWakeSchedule')))),
5336
5591
  h(Field, { label: t('salientWakeHour') }, h('input', { type: 'time', style: S.input, value: settings.salientWakeHour || '09:00', onChange: (e) => setSetting('salientWakeHour', e.target.value) })),
5337
5592
  h(Field, { label: t('salientWakeTimeZone') }, h('input', { type: 'text', style: S.input, placeholder: 'Asia/Shanghai', value: settings.salientWakeTimeZone || '', onChange: (e) => setSetting('salientWakeTimeZone', e.target.value) })),
5338
- h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('salientWakeHint')),
5339
- h(Field, { label: t('autoInstall') }, h('input', { type: 'checkbox', checked: settings.autoInstallEngine !== false, onChange: (e) => setSetting('autoInstallEngine', e.target.checked) })),
5593
+ h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('salientWakeHint'))),
5594
+ settingsGroup(t('settingsGroupEngine'), t('settingsGroupEngineDesc'),
5595
+ h(Field, { label: t('memoryMode') },
5596
+ h('select', { style: S.input, value: settings.memoryMode || 'local', onChange: (e) => setSetting('memoryMode', e.target.value) },
5597
+ ['local', 'cloud'].map((v) => h('option', { key: v, value: v }, v)))),
5598
+ h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('memoryModeHint')),
5599
+ h(Field, { label: t('autoInstall') }, h('input', { type: 'checkbox', checked: settings.autoInstallEngine !== false, onChange: (e) => setSetting('autoInstallEngine', e.target.checked) }))),
5600
+ settingsGroup(t('settingsGroupSession'), t('settingsGroupSessionDesc'),
5340
5601
  h(Field, { label: t('newSessionPrompt') }, h('input', { type: 'checkbox', checked: settings.newSessionPromptDismissed !== true, onChange: (e) => setSetting('newSessionPromptDismissed', !e.target.checked) })),
5341
- h(Field, { label: t('habitsInjection') }, h('input', { type: 'checkbox', checked: settings.habitsInjection !== false, onChange: (e) => setSetting('habitsInjection', e.target.checked) })),
5342
5602
  h(Field, { label: t('sidebarSettings') }, h(Toggle, { checked: settings.sidebarSettings === true, label: t('sidebarSettings'), onChange: value => setSetting('sidebarSettings', value) })),
5343
- h(Field, { label: t('visionCaptionEnabled') }, h(Toggle, { checked: settings.visionCaptionEnabled === true, label: t('visionCaptionEnabled'), onChange: value => setSetting('visionCaptionEnabled', value) })),
5603
+ h(Field, { label: t('visionCaptionEnabled') }, h(Toggle, { checked: settings.visionCaptionEnabled === true, label: t('visionCaptionEnabled'), onChange: value => setSetting('visionCaptionEnabled', value) }))),
5604
+ settingsGroup(t('settingsGroupIntegration'), t('settingsGroupIntegrationDesc'),
5344
5605
  h(Field, { label: t('inboundToolNames') }, h(InboundToolsInput, {
5345
5606
  names: settings.inboundToolNames || [], onChange: values => setSetting('inboundToolNames', values),
5346
- })),
5347
- h(Field, { label: t('sleepConsolidation') }, h('input', { type: 'checkbox', checked: settings.sleepConsolidation === true, onChange: (e) => setSetting('sleepConsolidation', e.target.checked) })),
5348
- h(Field, { label: t('sleepAfterIdleMinutes') }, h('input', { type: 'number', min: 1, style: S.input, value: settings.sleepAfterIdleMinutes ?? 3, onChange: (e) => setSetting('sleepAfterIdleMinutes', Number(e.target.value)) })),
5349
- h(Field, { label: t('autoCurateEveryHours') }, h('input', { type: 'number', min: 0, style: S.input, value: settings.autoCurateEveryHours ?? 0, onChange: (e) => setSetting('autoCurateEveryHours', Number(e.target.value)) })),
5350
- h(Field, { label: t('autoCurateSessionLimit') }, h('input', { type: 'number', min: 1, max: 30, style: S.input, value: settings.autoCurateSessionLimit ?? 8, onChange: (e) => setSetting('autoCurateSessionLimit', Number(e.target.value)) })),
5351
- h(Field, { label: t('purgeArchivedAfterDays') }, h('input', { type: 'number', min: 0, style: S.input, value: settings.purgeArchivedAfterDays ?? 0, onChange: (e) => setSetting('purgeArchivedAfterDays', Number(e.target.value)) })),
5352
- h(Field, { label: t('memoryMode') },
5353
- h('select', { style: S.input, value: settings.memoryMode || 'local', onChange: (e) => setSetting('memoryMode', e.target.value) },
5354
- ['local', 'cloud'].map((v) => h('option', { key: v, value: v }, v)))),
5355
- h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('memoryModeHint')))),
5356
- h(Section, { title: t('visionService') }, h(VisionConfigPanel, { call, config: state.visionConfig, t })))
5607
+ }))),
5608
+ h(Section, { title: t('visionService') }, h(VisionConfigPanel, { call, config: state.visionConfig, t })))
5357
5609
 
5358
5610
  const renderLibraryItem = (lib) => h('div', { key: lib.id, style: S.item },
5359
5611
  h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8, alignItems: 'center' } },
@@ -5670,7 +5922,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5670
5922
  f.salientDate
5671
5923
  ? h(Tag, null, `${/^\d{4}-\d{2}-\d{2}$/.test(f.salientDate) ? t('dueDateTag') : t('anniversaryTag')} ${f.salientDate}`)
5672
5924
  : null,
5673
- moodText ? h(Tag, { title: emotionMetaText(f, t) || undefined }, `${t('moodTag')} ${moodText}`) : null,
5925
+ // 四轴构成放在 Tag 里;激活/掌控/来源直接可见,不再只藏在悬停提示里。
5926
+ moodText ? h(Tag, null, `${t('moodTag')} ${moodText}`) : null,
5927
+ emotionMetaText(f, t) ? h('span', { style: S.muted }, emotionMetaText(f, t)) : null,
5674
5928
  typeof f.accuracy === 'number' && typeof f.confidence === 'number' && f.accuracy <= 0.6 && f.accuracy < f.confidence - 0.1
5675
5929
  ? h(Tag, { tone: 'warn' }, `${t('accuracyTag')} ${f.accuracy}`) : null,
5676
5930
  h(Tag, null, enumText(t, STATUS_LABELS, f.status || 'active'))),