dsh-layered-memory 0.8.4 → 0.8.6

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 (52) hide show
  1. package/README.en.md +43 -13
  2. package/README.md +28 -13
  3. package/assets/img/ui-dark.jpg +0 -0
  4. package/assets/img/ui-light.jpg +0 -0
  5. package/assets/readme/bench-dialog.svg +49 -55
  6. package/dist/bench-control.d.ts +35 -0
  7. package/dist/bench-control.js +16 -0
  8. package/dist/client.js +173 -0
  9. package/dist/config.d.ts +12 -0
  10. package/dist/config.js +4 -0
  11. package/dist/embedding-worker.cjs +176 -0
  12. package/dist/hooks/recall.d.ts +28 -1
  13. package/dist/hooks/recall.js +72 -13
  14. package/dist/index.d.ts +6 -0
  15. package/dist/index.js +18 -3
  16. package/dist/llm-usage.d.ts +27 -0
  17. package/dist/llm-usage.js +39 -0
  18. package/dist/llm.d.ts +3 -0
  19. package/dist/llm.js +6 -0
  20. package/dist/pipeline/l1.js +4 -2
  21. package/dist/pipeline/l2.js +1 -0
  22. package/dist/pipeline/l3.js +1 -0
  23. package/dist/pipeline/runner.d.ts +21 -0
  24. package/dist/pipeline/runner.js +83 -4
  25. package/dist/pipeline/trigger.d.ts +2 -0
  26. package/dist/pipeline/trigger.js +11 -0
  27. package/dist/prompts/l1-extraction.d.ts +7 -1
  28. package/dist/prompts/l1-extraction.js +12 -3
  29. package/dist/stats.d.ts +27 -1
  30. package/dist/stats.js +37 -2
  31. package/dist/store/embedding-source.d.ts +2 -1
  32. package/dist/store/embedding-source.js +7 -2
  33. package/dist/store/embedding.d.ts +2 -1
  34. package/dist/store/l0.d.ts +2 -0
  35. package/dist/store/l0.js +14 -4
  36. package/dist/store/l1.d.ts +11 -1
  37. package/dist/store/l1.js +26 -6
  38. package/dist/store/local-embedding.d.ts +69 -46
  39. package/dist/store/local-embedding.js +179 -75
  40. package/dist/store/recall-dedupe.d.ts +26 -0
  41. package/dist/store/recall-dedupe.js +138 -0
  42. package/dist/store/runtime-installer.d.ts +0 -2
  43. package/dist/store/runtime-installer.js +0 -6
  44. package/dist/store/search-utils.d.ts +17 -0
  45. package/dist/store/search-utils.js +29 -0
  46. package/dist/store/sqlite.d.ts +2 -0
  47. package/dist/store/sqlite.js +37 -9
  48. package/dist/types.d.ts +8 -0
  49. package/dist/types.js +8 -0
  50. package/dist/util/recall-budget.d.ts +2 -2
  51. package/dist/util/recall-budget.js +2 -2
  52. package/package.json +1 -1
package/README.en.md CHANGED
@@ -21,7 +21,7 @@ Requires Node ≥ 22.16. Two invocation styles — the `npx` prefix can replace
21
21
  any command below:
22
22
 
23
23
  ```bash
24
- # Option 1: run the official CLI directly via npx (no pre-installed dsh; version can be pinned, e.g. dsh-layered-memory@0.8.2)
24
+ # Option 1: run the official CLI directly via npx (no pre-installed dsh; version can be pinned, e.g. dsh-layered-memory@0.8.4)
25
25
  npx -y @deepseek-ai/dsh plugin --profile web add dsh-layered-memory
26
26
 
27
27
  # Option 2: with the dsh CLI installed (dsh is a pnpm forwarder; npm i -g pnpm first if missing)
@@ -90,7 +90,16 @@ synthetic message placed right before the user's new message, rendered as a
90
90
  **"Context injection · memory"** row in the chat flow (expand to see the hits) — so you
91
91
  can see "memory at work" directly. Injected content is bounded by length and
92
92
  time budgets — oversized lines are truncated (pointing the model at the memory tools for
93
- the full text) and a timed-out recall silently skips that turn, never slowing the chat. It
93
+ the full text) and a timed-out recall silently skips that turn, never slowing the chat.
94
+ **Per-session dedupe**: a memory already injected in this session is not injected again
95
+ (the model's context already holds it — follow-up questions on the same topic save
96
+ tokens); the record resets when the context is compacted or cleared, so memories can
97
+ flow back in, and an updated memory (new id after a content change) is never held back
98
+ by the old suppression. **Freshness weighting**: recall ranking applies a soft weight
99
+ `relevance × max(0.5, 0.5^(days since last update / 30))` — among candidates of similar
100
+ relevance the fresh one wins (slots rotate naturally), while a strongly relevant old
101
+ memory still recalls fine (the floor caps its loss at half a ranking score, so
102
+ long-lived facts never sink); tune via `recall.decayHalfLifeDays`, `0` disables. It
94
103
  also registers three model-callable memory tools: `memory_search` /
95
104
  `conversation_search` / `memory_read_scene`.
96
105
 
@@ -129,6 +138,15 @@ trajectory view):
129
138
  - **Control**: the pill next to the mode selector in the input bar (`Memory · Auto`);
130
139
  clicking opens a macOS-style sliding picker above — release to snap to the nearest
131
140
  mode; adapts to light/dark themes;
141
+ - The lower half of the popover is a **per-session info area**: recall hits
142
+ (hit/searched turns plus cumulative items), batching progress (this session's
143
+ slice x/effective threshold; the off mode shows parked slices instead), memories
144
+ produced for this session, and session message count — plus status lines for
145
+ anomalies (storage degraded / vector search unavailable) and a global summary
146
+ (pending distill count, last distill time). Data comes from the
147
+ `dsh-memory/session-stats` endpoint (in-memory registries + an indexed COUNT,
148
+ zero file I/O), adaptively polled while open (2s busy / 5s idle) and stopped on
149
+ close;
132
150
  - Each session's choice is persisted by sessionId to `session-modes.json`, surviving
133
151
  restarts/session restore; stacks with the global switches (global is the master gate);
134
152
  L2/L3 are fully family-isolated — content never leaks across families.
@@ -144,20 +162,24 @@ trajectory view):
144
162
 
145
163
  ## Measured Comparison (DSH-MemBench: Automated Benchmark)
146
164
 
147
- Screenshots show what the plugin looks like — this section answers "**what does enabling it actually buy you?**" with measured numbers from an **automated benchmark** ([`bench/`](./bench/), one command to reproduce). Method: the same scenario bank with verbatim-identical inputs runs in **Group A (memory on)** with 3 merged repetitions and **Group B (memory off)** with 1 repetition (a memory-off long task burns multiples of the tokens per scenario — a cost guardrail); the dialog track now runs Group A only (memory-off probes in independent sessions cannot succeed, so the control carries no information — retired). Workflow-track environment: DeepSeek official `deepseek-v4-flash` (reasoning effort high), judge `glm-5.3`, plugin 0.8.3, Windows; taxonomy adapted from [LongMemEval](https://github.com/xiaowu0162/longmemeval) / [LoCoMo](https://snap-research.github.io/locomo/) / [AMB](https://github.com/vectorize-io/agent-memory-benchmark).
165
+ Screenshots show what the plugin looks like — this section answers "**what does enabling it actually buy you?**" with measured numbers from an **automated benchmark** ([`bench/`](./bench/), one command to reproduce). Method: the same scenario bank with verbatim-identical inputs runs in **Group A (memory on)** with 3 merged repetitions and **Group B (memory off)** with 1 repetition (a memory-off long task burns multiples of the tokens per scenario — a cost guardrail); the dialog track now runs Group A only (memory-off probes in independent sessions cannot succeed, so the control carries no information — retired). Dialog-track environment: DeepSeek official `deepseek-v4-flash`, plugin 0.8.5 (judge same-source as tested; every answer archived for manual audit), Windows; taxonomy adapted from [LongMemEval](https://github.com/xiaowu0162/longmemeval) / [LoCoMo](https://snap-research.github.io/locomo/) / [AMB](https://github.com/vectorize-io/agent-memory-benchmark), with the extended probe types and lifecycle track informed by [MemoryAgentBench](https://arxiv.org/abs/2507.05257) / [GoodAI LTM](https://github.com/GoodAI/goodai-ltm-benchmark) / BEAM.
148
166
 
149
- ### Dialog track (15 scenarios × 6 probe types × 3 reps = 270 questions): does it remember correctly
167
+ > The dialog track below is the **fresh 0.8.5 baseline** (fixed plugin + corrected judging criteria); the workflow-track numbers remain the archived 0.8.3 run (the bank has since grown to 8 scenarios with a prospective-memory addition — re-run pending).
150
168
 
151
- > Archived 0.8.0 baseline (Group A data; the dialog-track B arm has since been retired Group A only).
169
+ ### Dialog track (20 scenarios × 10 probe types × 3 reps = 420 questions): does it remember correctly
170
+
171
+ > 0.8.5 baseline (Group A data; the dialog-track B arm is retired — Group A only).
152
172
 
153
173
  <p align="center">
154
174
  <img src="./assets/readme/bench-dialog.svg" width="100%"
155
- alt="DSH-MemBench dialog track accuracy chart (Group A, memory on): overall accuracy 92.6% (250/270); per probe type, 45 each — extraction 45/45, multi-hop 45/45, temporal 43/45, knowledge updates 31/45, scene recall 41/45, abstention 45/45 with 0 fabricated; the dialog-track B arm is retired (memory-off probes in independent sessions cannot succeed)">
175
+ alt="DSH-MemBench dialog track accuracy chart (Group A, memory on): overall accuracy 95.2% (400/420); six core probe types, 60 questions each — extraction 58/60, multi-hop 60/60, temporal 56/60, updates 55/60, scene recall 52/60, abstention 60/60 with 0 fabricated; four extended probe types, 15 each accretive completion 15/15, update chains 15/15, event ordering 14/15, paraphrase 15/15">
156
176
  </p>
157
177
 
158
- **Dual-channel recall** (Group A): passive injection hit rate **75.1%** (the answer's key points appear in the recall injection, 169/225); most of the rest the model recovered by **actively calling the memory tools** — 84 questions with active queries, **60 rescued by tools**. The end-to-end 92.6% is the composite of both channels plus model utilization. With the memory store accumulating across scenarios for the whole run, 144 probe injections carried other scenarios' memories (honestly counted) — yet overall accuracy held at 92.6%: interference resistance under a growing store, measured.
178
+ **Dual-channel recall** (Group A): passive injection hit rate **78.1%** (the answer's key points appear in the recall injection, 281/360); most of the rest the model recovered by **actively calling the memory tools** — 106 questions with active queries, **75 rescued by tools**. The end-to-end 95.2% is the composite of both channels plus model utilization. With the memory store accumulating across scenarios for the whole run, 295 probe injections carried other scenarios' memories (honestly counted) — yet accuracy actually *rose* from 92.8% (early, small store) to 97.7% (late, largest store), and offline flooding with 600 extra synthetic records moved retrieval recall@5 by only −2.8pp: interference resistance under a growing store, measured.
179
+
180
+ **Layered weaknesses**: offline retrieval metrics (recall@5, controlled replay) total 73.3%, with event ordering at 0% and scene recall at 50% — end-to-end still 93%+ thanks to model robustness over adjacent injected memories. **Efficiency triangle** (the cost of memory): injections add no latency (injected turns respond 210ms *faster* on average), recall text is ~10.3% of per-turn input, and the whole distillation pipeline costs ≈2727 input / 240 output tokens per captured message (1172 calls, 0 failures).
159
181
 
160
- ### Workflow track (7 scenarios · Group A ×3 / Group B ×1, real tool sandbox): does it do it right, and cheaper
182
+ ### Workflow track (archived 0.8.3 · 7-scenario edition · Group A ×3 / Group B ×1, real tool sandbox): does it do it right, and cheaper
161
183
 
162
184
  <p align="center">
163
185
  <img src="./assets/readme/bench-workflow.svg" width="100%"
@@ -173,14 +195,17 @@ Screenshots show what the plugin looks like — this section answers "**what doe
173
195
  ```bash
174
196
  node bench/harness/run.mjs --arm A --repeats 3 --provider deepseek-official --model deepseek-v4-flash # dialog track (Group A only)
175
197
  node bench/harness/run.mjs --track workflow --arm AB --repeats 3 ... # workflow track (A/B arms in parallel)
198
+ node bench/harness/run.mjs --track lifecycle --arm A ... # lifecycle track (gating/off/rebuild/forget)
176
199
  node bench/harness/report.mjs --latest [dialog|workflow] # aggregate report
200
+ node bench/harness/retrieval-metrics.mjs <runDir> --flood 200,600 # retrieval metrics + flooding curve
177
201
  ```
178
202
 
179
- - Scoring: programmatic `contains-all` plus an LLM judge against key points (every answer and verdict is preserved in `result.json` for human audit); workflow completion is verified programmatically from produced files and their contents (four check kinds: positive / forbidden-word / must-not-exist / exists);
203
+ - Scoring: programmatic `contains-all` plus an LLM judge against key points (every answer and verdict is preserved in `result.json` for human audit); for stale-bearing probes (updates/update-chains/forget) an old value only fails when stated *as the current answer*, and abstention probes allow citing real adjacent facts while denying the asked point; workflow completion is verified programmatically from produced files and their contents (four check kinds: positive / forbidden-word / must-not-exist / exists);
204
+ - Metric surface: beyond the per-type accuracy table (6 core + 4 extended types), reports automatically include **offline retrieval metrics** (recall@5 / injection precision / stale leakage), the **efficiency triangle** (injection latency differential / injection share / distillation accounting per captured message), **scale-position analysis** (accuracy & contamination vs store growth), and the lifecycle-track section (family-gating matrix / off-mode dual assertions / rebuild fidelity / forget requests);
180
205
  - Live progress: running the benchmark auto-starts a local progress panel and opens the browser (`--no-panel` to disable) — per-arm scenario/phase/message-level progress, heartbeat & activity freshness (distinguishes "stuck" from "process died"), and cumulative cost as it accrues;
181
- - Metrics come from provider-reported usage (input with cache-hit split) and session-event folding; the steady-state cache rate excludes each session's first request (archived 0.8.0 baseline: A 88.7% vs B 85.4% — memory injection does not hurt caching);
182
- - Regression use: run before/after a plugin change and diff with `compare.mjs` (environment header check including git SHA + Group-B control-drift warning);
183
- - Limitations (stated honestly): single machine; Group A ×3 merged, Group B ×1 (cost guardrail — noisier); judge vs tested model: same model in the archived dialog baseline, heterogeneous in the new workflow run (glm-5.3 judging v4-flash); the scenario bank is author-built (biased toward memory-advantage scenarios — reproduce it yourself); sandbox-file affordances partially leak procedures (Group B can reverse-engineer by reading scripts — discrimination limits honestly noted); dual-tier tool audit (strict violation voids the scenario / loose heuristic flags only), with 0 violations measured on both sides.
206
+ - Metrics come from provider-reported usage (input with cache-hit split) and session-event folding; the steady-state cache rate excludes each session's first request (0.8.5 baseline: 89.1% — memory injection does not hurt caching);
207
+ - Regression use: run before/after a plugin change and diff with `compare.mjs` (environment header check including git SHA + Group-B control-drift warning + retrieval-metric comparison);
208
+ - Limitations (stated honestly): single machine; Group A ×3 merged, Group B ×1 (cost guardrail — noisier); judge vs tested model: same model in the 0.8.5 dialog baseline, heterogeneous in the archived workflow run (glm-5.3 judging v4-flash); the scenario bank is author-built (biased toward memory-advantage scenarios — reproduce it yourself); sandbox-file affordances partially leak procedures (Group B can reverse-engineer by reading scripts — discrimination limits honestly noted); dual-tier tool audit (strict violation voids the scenario / loose heuristic flags only), with 0 violations measured on both sides.
184
209
 
185
210
  Full reports and per-question data: [`bench/baseline/`](./bench/baseline/).
186
211
 
@@ -227,6 +252,7 @@ the bundle layer appends and causes `duplicate loader entry id` startup failure)
227
252
  | `recall.includeSceneNav` | `true` | Inject scene navigation into the system prompt (`<scene-navigation>`, stable zone) |
228
253
  | `recall.strategy` | `hybrid` | Retrieval strategy: `keyword` / `embedding` / `hybrid` |
229
254
  | `recall.scoreThreshold` | `0.3` | Recall score threshold (below is not injected; applies to keyword/embedding only, not pre-fusion hybrid; tool path unfiltered) |
255
+ | `recall.decayHalfLifeDays` | `30` | Freshness-decay half-life for recall ranking (days, 0=off): ranking applies `relevance × max(0.5, 0.5^(days since last update / half-life))` — among similarly relevant candidates the fresh one wins (slots rotate), and an old memory loses at most half its ranking score (floor keeps long-lived facts afloat) |
230
256
  | `embedding.enabled` | `false` | Vector retrieval switch; off = pure FTS |
231
257
  | `embedding.baseUrl` | empty | OpenAI-compatible /embeddings endpoint (e.g. `https://api.siliconflow.cn/v1`) |
232
258
  | `embedding.apiKey` | empty | API key |
@@ -244,6 +270,7 @@ the bundle layer appends and causes `duplicate loader entry id` startup failure)
244
270
  | `llm.maxInputChars` | `700000` | Input character budget per distillation call (over-budget L1 inputs are chunked automatically); runtime-adjustable in Settings → distillation parameters → input budget (empty/0 = follow this value) |
245
271
  | `llm.timeoutMs` | `120000` | Per-call distillation timeout (ms) |
246
272
  | `tools` | `true` | Whether to register model-callable memory tools |
273
+ | `benchControl` | `false` | Register the in-process bench control service (rebuild trigger / session-mode setting / distillation usage snapshot — used by the benchmark's lifecycle track). Off by default — zero surface in production deployments; do not enable casually |
247
274
 
248
275
  ## Storage Layout
249
276
 
@@ -282,7 +309,10 @@ with per-file sha256; arbitrary repos cannot be downloaded).
282
309
  under `models/<id>/` in the data directory, deletable from the settings page at any time;
283
310
  - **On-demand runtime**: the inference runtime (transformers.js, ~100–200MB) is
284
311
  installed only on first switch to the local tier, into `runtime/` in the data
285
- directory — never in the plugin's dependency tree or install directory;
312
+ directory — never in the plugin's dependency tree or install directory; model
313
+ loading and inference run on a **dedicated worker thread**, so the host event
314
+ loop is never frozen (conversations and page interactions stay responsive while
315
+ text is being embedded);
286
316
  - **Live switching**: one click to swap sources — everything is re-embedded in the
287
317
  background (visible progress, cancellable; retrieval silently degrades to keywords
288
318
  in the meantime, conversations unaffected; a dimension change rebuilds the vector
package/README.md CHANGED
@@ -20,7 +20,7 @@
20
20
  需要 Node ≥ 22.16。两种调用方式任选(`npx` 前缀可替换下面任何 `dsh` 命令):
21
21
 
22
22
  ```bash
23
- # 方式一:npx 直接跑官方 CLI(无需预装 dsh;可 pin 版本,如 dsh-layered-memory@0.8.2
23
+ # 方式一:npx 直接跑官方 CLI(无需预装 dsh;可 pin 版本,如 dsh-layered-memory@0.8.4
24
24
  npx -y @deepseek-ai/dsh plugin --profile web add dsh-layered-memory
25
25
 
26
26
  # 方式二:已装 dsh CLI(dsh 是 pnpm 转发器,未装 pnpm 时先 npm i -g pnpm)
@@ -74,7 +74,7 @@ npx tsc src/smoke.ts --outDir dist-smoke --module nodenext --moduleResolution no
74
74
  alt="dsh-layered-memory 运行时数据流:左侧 User 与 Assistant 的会话事件流入插件(L0 捕获、L1–L3 蒸馏、检索召回、记忆工具),插件经 agent/pre-step 把相关记忆注入右侧 DSH 核心;蒸馏复用核心的 ctx.llm,数据双写 ~/.dsh/memory/">
75
75
  </p>
76
76
 
77
- 插件挂在 dsh 原生事件上(`session/event` 捕获、`agent/pre-step` 注入),蒸馏调用复用宿主 `ctx.llm`。召回以**消息侧注入**呈现:相关记忆作为一条合成消息排在用户新消息之前,会话流里显示为**"上下文注入 · memory"**行(点开看命中内容)——用户能直接看到"记忆生效了";注入内容有长度预算与时间预算,超限截断/超时跳过,绝不拖慢对话。
77
+ 插件挂在 dsh 原生事件上(`session/event` 捕获、`agent/pre-step` 注入),蒸馏调用复用宿主 `ctx.llm`。召回以**消息侧注入**呈现:相关记忆作为一条合成消息排在用户新消息之前,会话流里显示为**"上下文注入 · memory"**行(点开看命中内容)——用户能直接看到"记忆生效了";注入内容有长度预算与时间预算,超限截断/超时跳过,绝不拖慢对话。**同会话去重**:已注入过的记忆不再重复注入(模型上下文里已经有了,追问同类问题时省 token);上下文被 `/compact` 压缩或清空时自动重置,记忆可重新注入;被更新的记忆(内容变化换新 id)不受旧压制。**时效加权**:召回排序按 `相关度 × max(0.5, 0.5^(距上次更新天数/30))` 软加权——相关度相近的候选之间新鲜记忆优先(名额自然轮转),相关度足够高的老记忆照常召回(地板保证最多损失一半排序分,长期事实不沉底);`recall.decayHalfLifeDays` 可调,0=关闭。
78
78
 
79
79
  **记忆工具(3):**
80
80
  - memory_search
@@ -110,6 +110,11 @@ npx tsc src/smoke.ts --outDir dist-smoke --module nodenext --moduleResolution no
110
110
  </p>
111
111
 
112
112
  - **控件**:输入栏内、模式选择器右侧的 pill(`记忆·自动`),点击在上方浮出档位滑块深浅主题自适应;
113
+ - 悬浮板下半部是**会话信息区**:召回命中(命中/检索轮次与累计条数)、攒批进度
114
+ (本会话切片 x/生效阈值;关闭档显示挂起切片数)、本会话产出记忆条数、会话消息数,
115
+ 外加异常状态行(存储降级 / 向量检索不可用)与全局摘要(待蒸馏条数、上次蒸馏时间);
116
+ 数据走 `dsh-memory/session-stats` 端点(纯内存注册表 + 索引 COUNT,零文件 I/O),
117
+ 打开期间自适应轮询(忙 2s / 静 5s),关闭即停;
113
118
  - 每会话的选择按 sessionId 持久化到 `session-modes.json`,重启/恢复会话不丢;
114
119
  与全局开关叠加(全局是总闸);L2/L3 完全分类,分类内容不渗透。
115
120
 
@@ -124,20 +129,24 @@ npx tsc src/smoke.ts --outDir dist-smoke --module nodenext --moduleResolution no
124
129
 
125
130
  ## 实测对比(DSH-MemBench:自动化基准)
126
131
 
127
- 图文回答"长什么样",这一节用**自动化基准**的实测数字回答"**开了到底有什么用**"([`bench/`](./bench/),一条命令可复现)。方法:同场景库、逐字相同输入,**A 组(记忆开)跑 3 次取合并值,B 组(记忆关)跑 1 次**(无记忆的长任务每场景要吞数倍 token,成本护栏);对话赛道只跑 A 组(B 组会话独立无记忆必然失败,对照无信息量,已下线)。工作流赛道环境:DeepSeek 官方 `deepseek-v4-flash`(思考档 high)、判卷 `glm-5.3`、插件 0.8.3、Windows;题型设计借鉴 [LongMemEval](https://github.com/xiaowu0162/longmemeval) / [LoCoMo](https://snap-research.github.io/locomo/) / [AMB](https://github.com/vectorize-io/agent-memory-benchmark)。
132
+ 图文回答"长什么样",这一节用**自动化基准**的实测数字回答"**开了到底有什么用**"([`bench/`](./bench/),一条命令可复现)。方法:同场景库、逐字相同输入,**A 组(记忆开)跑 3 次取合并值,B 组(记忆关)跑 1 次**(无记忆的长任务每场景要吞数倍 token,成本护栏);对话赛道只跑 A 组(B 组会话独立无记忆必然失败,对照无信息量,已下线)。对话赛道环境:DeepSeek 官方 `deepseek-v4-flash`、插件 0.8.5(判卷与被测同源,答案原文全部留痕可人工复核)、Windows;题型设计借鉴 [LongMemEval](https://github.com/xiaowu0162/longmemeval) / [LoCoMo](https://snap-research.github.io/locomo/) / [AMB](https://github.com/vectorize-io/agent-memory-benchmark),扩展题型与生命周期赛道参照 [MemoryAgentBench](https://arxiv.org/abs/2507.05257) / [GoodAI LTM](https://github.com/GoodAI/goodai-ltm-benchmark) / BEAM
128
133
 
129
- ### 对话赛道(15 场景 × 6 题型 × 3 = 270 题):答得准吗
134
+ > 对话赛道为 **0.8.5 新基线**(修复版插件 + 修正后的判卷口径);工作流赛道数字仍为 0.8.3 存档(0.8.5 起场景库扩至 8 个,新增前瞻记忆场景,重跑待做)。
130
135
 
131
- > 0.8.0 留档基线(A 组数据;此后对话赛道 B 组下线,只跑 A 组)。
136
+ ### 对话赛道(20 场景 × 10 题型 × 3 次 = 420 题):答得准吗
137
+
138
+ > 0.8.5 基线(A 组数据;对话赛道 B 组已下线,只跑 A 组)。
132
139
 
133
140
  <p align="center">
134
141
  <img src="./assets/readme/bench-dialog.svg" width="100%"
135
- alt="DSH-MemBench 对话赛道准确率图(A 组·记忆开):总准确率 92.6%(250/270);分题型各 45 题——抽取 45/45、多跳 45/45、时序 43/45、知识更新 31/45、场景回忆 41/45、拒答 45/45 且 0 编造;对话赛道 B 组已下线(会话独立无记忆必然失败)">
142
+ alt="DSH-MemBench 对话赛道准确率图(A 组·记忆开):总准确率 95.2%(400/420);核心六题型各 60 题——抽取 58/60、多跳 60/60、时序 56/60、更新 55/60、场景回忆 52/60、拒答 60/60 且 0 编造;扩展四题型各 15 题——增量积累 15/15、连锁更新 15/15、事件排序 14/15、同义改写 15/15">
136
143
  </p>
137
144
 
138
- **召回双通道**(A 组):被动注入召回率 **75.1%**(该题要点出现在召回注入中,169/225),其余多数由模型**主动调用记忆工具**查回——84 题主动查询、**60 题靠工具兜底答对**;端到端 92.6% 是两通道 + 模型利用的合成结果。记忆库跨场景全程累积下,探针召回注入混入其他场景记忆 144 次(已如实计数),总准确率仍稳在 92.6%——抗干扰能力经受住了膨胀记忆库的考验。
145
+ **召回双通道**(A 组):被动注入召回率 **78.1%**(该题要点出现在召回注入中,281/360),其余多数由模型**主动调用记忆工具**查回——106 题主动查询、**75 题靠工具兜底答对**;端到端 95.2% 是两通道 + 模型利用的合成结果。记忆库跨场景全程累积下,探针召回注入混入其他场景记忆 295 次(已如实计数),总准确率反而前段 92.8% → 后段 97.7%——抗干扰能力经受住了膨胀记忆库的考验(离线灌水再灌 600 条合成噪声,检索层 recall@5 也只降 2.8pp)。
146
+
147
+ **分层看短板**:检索层离线指标(recall@5 受控复现)总 73.3%,其中事件排序 0%、场景回忆 50%——端到端仍 93%+ 靠的是注入邻近记忆后模型的鲁棒性;**效率三角**(记忆的开销):注入非但不加延迟(注入轮响应比无注入轮平均快 210ms)、注入占每轮输入约 10.3%,蒸馏全链路摊到每条捕获消息 ≈2727 输入 / 240 输出 token(1172 次调用 0 失败)。
139
148
 
140
- ### 工作流赛道(7 场景 · A 组 3 次 / B 组 1 次,真实工具沙箱):做得对、做得省吗
149
+ ### 工作流赛道(0.8.3 存档 · 7 场景版 · A 组 3 次 / B 组 1 次,真实工具沙箱):做得对、做得省吗
141
150
 
142
151
  <p align="center">
143
152
  <img src="./assets/readme/bench-workflow.svg" width="100%"
@@ -153,14 +162,17 @@ npx tsc src/smoke.ts --outDir dist-smoke --module nodenext --moduleResolution no
153
162
  ```bash
154
163
  node bench/harness/run.mjs --arm A --repeats 3 --provider deepseek-official --model deepseek-v4-flash # 对话赛道(只跑 A 组)
155
164
  node bench/harness/run.mjs --track workflow --arm AB --repeats 3 ... # 工作流赛道(A/B 双组并行)
165
+ node bench/harness/run.mjs --track lifecycle --arm A ... # 生命周期赛道(门控/off/rebuild/遗忘)
156
166
  node bench/harness/report.mjs --latest [dialog|workflow] # 汇总报告
167
+ node bench/harness/retrieval-metrics.mjs <runDir> --flood 200,600 # 检索层指标 + 灌水曲线
157
168
  ```
158
169
 
159
- - 判分:`contains-all` 程序判 + 判卷模型按要点判(答案原文与判分理由全部留痕 `result.json` 可人工复核);工作流完成度为产物文件 + 关键内容程序化校验(四型判据:正检查/禁词/产物缺席/存在性);
170
+ - 判分:`contains-all` 程序判 + 判卷模型按要点判(答案原文与判分理由全部留痕 `result.json` 可人工复核);带 stale 的题(更新/连锁/遗忘)"旧值当作现状陈述"才判负、拒答题允许引用真实背景解释"不知道被问点";工作流完成度为产物文件 + 关键内容程序化校验(四型判据:正检查/禁词/产物缺席/存在性);
171
+ - 指标面:准确率总表(6 核心 + 4 扩展题型)之外,自动产出**检索层离线指标**(recall@5 / 注入精度 / 作废泄漏)、**效率三角**(注入开销差分 / 注入占比 / 蒸馏记账摊到每消息)、**规模位置分析**(库容膨胀下的准确率/污染)与生命周期赛道专属节(分族门控矩阵 / off 双断言 / rebuild 保真 / 遗忘);
160
172
  - 实时进度:跑基准时自动拉起本地进度面板并打开浏览器(`--no-panel` 关闭)——A/B 双臂场景/阶段/消息粒度进度、心跳与活动新鲜度(直判"卡住 vs 进程挂了")、累计成本随跑随涨;
161
- - 指标全部来自供应商上报 usage(输入含缓存命中拆分)与会话事件折叠;稳态缓存率剔除每会话首请求(0.8.0 留档基线:A 88.7% vs B 85.4%——记忆注入不伤缓存);
162
- - 回归用途:改插件前后各跑一遍,`compare.mjs` 出对比表(环境头校验含 gitSha + B 组对照组漂移告警);
163
- - 局限(诚实声明):单机;A 组 ×3 合并、B 组 ×1(成本护栏,噪声更大);判卷与被测模型:对话留档基线同源、工作流新跑为异构(glm-5.3 判 v4-flash);作者自建场景库(倾向记忆优势场景,欢迎自行复现);沙箱文件的可供性会部分泄露流程(B 组可读脚本逆向,判别力受限处已如实标注);工具审计双档(严格违规判负/宽松提示),实测双方 0 违规。
173
+ - 指标全部来自供应商上报 usage(输入含缓存命中拆分)与会话事件折叠;稳态缓存率剔除每会话首请求(0.8.5 基线:89.1%——记忆注入不伤缓存);
174
+ - 回归用途:改插件前后各跑一遍,`compare.mjs` 出对比表(环境头校验含 gitSha + B 组对照组漂移告警 + 检索层指标对比);
175
+ - 局限(诚实声明):单机;A 组 ×3 合并、B 组 ×1(成本护栏,噪声更大);判卷与被测模型:对话 0.8.5 基线同源、工作流存档跑为异构(glm-5.3 判 v4-flash);作者自建场景库(倾向记忆优势场景,欢迎自行复现);沙箱文件的可供性会部分泄露流程(B 组可读脚本逆向,判别力受限处已如实标注);工具审计双档(严格违规判负/宽松提示),实测双方 0 违规。
164
176
 
165
177
  完整报告与逐题数据:[`bench/baseline/`](./bench/baseline/)。
166
178
 
@@ -194,7 +206,8 @@ ONNX 量化 **CPU 推理**——无需 API Key,数据不出本机)。本地
194
206
  绕开镜像 CDN 偶发的坏缓存对象),校验失配从零重下、网络错误保留断点续传;
195
207
  落盘数据目录 `models/<id>/`,不用了随时在设置页删除;
196
208
  - **按需运行时**:首次切换本地档才安装推理运行时(transformers.js,约 100~200MB,
197
- 装进数据目录 `runtime/`——不进插件依赖树,不碰插件安装目录);
209
+ 装进数据目录 `runtime/`——不进插件依赖树,不碰插件安装目录);模型加载与推理在
210
+ **独立 worker 线程**执行,不冻结宿主事件循环(嵌入计算期间对话与页面交互照常);
198
211
  - **活切换**:一键换源——自动后台全量重嵌(进度可见、可取消,期间检索自动降级
199
212
  关键词,不影响对话;维度变化时向量表按新维度重建);切换失败保持旧源,重启仍按原源运行;
200
213
  - **生效规则 = 部署上限 AND 运行时选择**:`embedding.allowLocalModels=false` 可整体
@@ -244,6 +257,7 @@ ONNX 量化 **CPU 推理**——无需 API Key,数据不出本机)。本地
244
257
  | `recall.includeSceneNav` | `true` | 系统提示注入场景导航(`<scene-navigation>`,稳定区) |
245
258
  | `recall.strategy` | `hybrid` | 检索策略:`keyword` / `embedding` / `hybrid` |
246
259
  | `recall.scoreThreshold` | `0.3` | 召回分数阈值(低于不注入;仅 keyword/embedding 策略生效,hybrid 融合前不过滤;工具路径不过滤) |
260
+ | `recall.decayHalfLifeDays` | `30` | 召回时效衰减半衰期(天,0=关):排序按 `相关度 × max(0.5, 0.5^(距更新天数/半衰期))` 软加权——相关度相近的候选间新鲜记忆优先(名额轮转),老记忆最多损失一半排序分(地板兜底,长期事实不沉底) |
247
261
  | `embedding.enabled` | `false` | 向量检索开关;关闭即纯 FTS 运行 |
248
262
  | `embedding.baseUrl` | 空 | OpenAI 兼容 /embeddings 地址(如 `https://api.siliconflow.cn/v1`) |
249
263
  | `embedding.apiKey` | 空 | API Key |
@@ -261,6 +275,7 @@ ONNX 量化 **CPU 推理**——无需 API Key,数据不出本机)。本地
261
275
  | `llm.maxInputChars` | `700000` | 单次蒸馏输入字符预算(超限的 L1 输入自动分块抽取);运行时可在设置页 → 蒸馏参数 → 输入预算调整(留空/0 = 跟随本值) |
262
276
  | `llm.timeoutMs` | `120000` | 单次蒸馏调用超时(ms) |
263
277
  | `tools` | `true` | 是否注册模型可调用的记忆工具 |
278
+ | `benchControl` | `false` | 注册 bench 控制服务(进程内 rebuild 触发/会话档位设置/蒸馏用量快照,供基准 lifecycle 赛道)。默认关——生产部署零表面积,勿随意开启 |
264
279
 
265
280
  ## 日志与故障排查
266
281
 
Binary file
Binary file
@@ -2,75 +2,69 @@
2
2
  width="1200" height="630" viewBox="0 0 1200 630"
3
3
  role="img" aria-labelledby="benchDialogTitle benchDialogDesc">
4
4
  <title id="benchDialogTitle">DSH-MemBench 对话赛道:A 组(记忆开)准确率</title>
5
- <desc id="benchDialogDesc">A 组(记忆开)总准确率 92.6%(250/27015 场景 × 6 题型 × 3 次)。分题型(每题型 45 题):抽取 45/45;多跳 45/45;时序 43/45;知识更新 31/45;场景回忆 41/45;拒答 45/45、0 编造。对话赛道 B 组已下线(会话独立、无记忆必然失败,对照无信息量)。</desc>
5
+ <desc id="benchDialogDesc">A 组(记忆开)总准确率 95.2%(400/42020 场景 × 10 题型 × 3 次)。核心六题型各 60 题:抽取 58/60、多跳 60/60、时序 56/60、更新 55/60、场景回忆 52/60、拒答 60/60 且 0 编造;扩展四题型各 15 题:增量积累 15/15、连锁更新 15/15、事件排序 14/15、同义改写 15/15。对话赛道 B 组已下线(会话独立、无记忆必然失败,对照无信息量)。</desc>
6
6
 
7
7
  <rect width="1200" height="630" rx="26" fill="#0D1526"/>
8
8
 
9
9
  <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif">
10
10
 
11
- <!-- ── 标题与图例 ── -->
12
11
  <text x="64" y="66" font-size="26" font-weight="700" fill="#EFF3FA">对话赛道:记忆开 · 准确率</text>
13
- <text x="64" y="94" font-size="18" fill="#8296B3">15 场景 × 6 题型 × 3 次 = 270 题(每题型 45 题)· 条长 = 答对率,数值 = 答对题数</text>
12
+ <text x="64" y="94" font-size="18" fill="#8296B3">20 场景 × 10 题型 × 3 次 = 420 题(核心六题型各 60 题、扩展四题型各 15 题)· 条长 = 答对率,数值 = 答对题数</text>
14
13
 
15
14
  <rect x="842" y="50" width="18" height="18" rx="5" fill="#FFD15D"/>
16
- <text x="868" y="65" font-size="18" fill="#C2CDDE">A 组 · 记忆开</text>
15
+ <text x="868" y="65" font-size="17" fill="#C2CDDE">核心六题型</text>
16
+ <rect x="966" y="50" width="18" height="18" rx="5" fill="#6FB1FF"/>
17
+ <text x="992" y="65" font-size="17" fill="#C2CDDE">扩展四题型</text>
17
18
 
18
- <!-- ── 网格线(0/25/50/75/100%)── -->
19
19
  <g stroke="#1C2A47" stroke-width="1">
20
- <line x1="260" y1="122" x2="260" y2="530"/>
21
- <line x1="435" y1="122" x2="435" y2="530"/>
22
- <line x1="610" y1="122" x2="610" y2="530"/>
23
- <line x1="785" y1="122" x2="785" y2="530"/>
24
- <line x1="960" y1="122" x2="960" y2="530"/>
20
+ <line x1="260" y1="120" x2="260" y2="525"/>
21
+ <line x1="435" y1="120" x2="435" y2="525"/>
22
+ <line x1="610" y1="120" x2="610" y2="525"/>
23
+ <line x1="785" y1="120" x2="785" y2="525"/>
24
+ <line x1="960" y1="120" x2="960" y2="525"/>
25
25
  </g>
26
26
  <g font-size="17" fill="#8296B3" text-anchor="middle">
27
- <text x="260" y="558">0%</text>
28
- <text x="435" y="558">25%</text>
29
- <text x="610" y="558">50%</text>
30
- <text x="785" y="558">75%</text>
31
- <text x="960" y="558">100%</text>
27
+ <text x="260" y="552">0%</text>
28
+ <text x="435" y="552">25%</text>
29
+ <text x="610" y="552">50%</text>
30
+ <text x="785" y="552">75%</text>
31
+ <text x="960" y="552">100%</text>
32
32
  </g>
33
33
 
34
- <!-- ── 总准确率(强调行)── -->
35
- <text x="240" y="169" font-size="21" font-weight="700" fill="#EFF3FA" text-anchor="end">总准确率</text>
36
- <rect x="260" y="148" width="648" height="26" rx="6" fill="#FFD15D"/>
37
- <text x="922" y="169" font-size="22" font-weight="700" fill="#FFD15D">92.6%(250/270)</text>
34
+ <text x="240" y="149" font-size="18" font-weight="700" fill="#EFF3FA" text-anchor="end">总准确率</text>
35
+ <rect x="260" y="130" width="667" height="25" rx="6" fill="#FFD15D"/>
36
+ <text x="939" y="149" font-size="17" font-weight="600" fill="#FFD15D">400/420(95.2%)</text>
37
+ <text x="240" y="184" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">抽取</text>
38
+ <rect x="260" y="165" width="677" height="25" rx="6" fill="#FFD15D"/>
39
+ <text x="949" y="184" font-size="17" font-weight="600" fill="#FFD15D">58/60(96.7%)</text>
40
+ <text x="240" y="219" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">多跳</text>
41
+ <rect x="260" y="200" width="700" height="25" rx="6" fill="#FFD15D"/>
42
+ <text x="972" y="219" font-size="17" font-weight="600" fill="#FFD15D">60/60(100.0%)</text>
43
+ <text x="240" y="254" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">时序</text>
44
+ <rect x="260" y="235" width="653" height="25" rx="6" fill="#FFD15D"/>
45
+ <text x="925" y="254" font-size="17" font-weight="600" fill="#FFD15D">56/60(93.3%)</text>
46
+ <text x="240" y="289" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">更新</text>
47
+ <rect x="260" y="270" width="642" height="25" rx="6" fill="#FFD15D"/>
48
+ <text x="914" y="289" font-size="17" font-weight="600" fill="#FFD15D">55/60(91.7%)</text>
49
+ <text x="240" y="324" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">场景回忆</text>
50
+ <rect x="260" y="305" width="607" height="25" rx="6" fill="#FFD15D"/>
51
+ <text x="879" y="324" font-size="17" font-weight="600" fill="#FFD15D">52/60(86.7%)</text>
52
+ <text x="240" y="359" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">拒答(0 编造)</text>
53
+ <rect x="260" y="340" width="700" height="25" rx="6" fill="#FFD15D"/>
54
+ <text x="972" y="359" font-size="17" font-weight="600" fill="#FFD15D">60/60(100.0%)</text>
55
+ <text x="240" y="394" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">增量积累</text>
56
+ <rect x="260" y="375" width="700" height="25" rx="6" fill="#6FB1FF"/>
57
+ <text x="972" y="394" font-size="17" font-weight="600" fill="#6FB1FF">15/15(100.0%)</text>
58
+ <text x="240" y="429" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">连锁更新</text>
59
+ <rect x="260" y="410" width="700" height="25" rx="6" fill="#6FB1FF"/>
60
+ <text x="972" y="429" font-size="17" font-weight="600" fill="#6FB1FF">15/15(100.0%)</text>
61
+ <text x="240" y="464" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">事件排序</text>
62
+ <rect x="260" y="445" width="653" height="25" rx="6" fill="#6FB1FF"/>
63
+ <text x="925" y="464" font-size="17" font-weight="600" fill="#6FB1FF">14/15(93.3%)</text>
64
+ <text x="240" y="499" font-size="18" font-weight="400" fill="#C2CDDE" text-anchor="end">同义改写</text>
65
+ <rect x="260" y="480" width="700" height="25" rx="6" fill="#6FB1FF"/>
66
+ <text x="972" y="499" font-size="17" font-weight="600" fill="#6FB1FF">15/15(100.0%)</text>
38
67
 
39
- <line x1="64" y1="200" x2="1136" y2="200" stroke="#263A5C" stroke-width="1.5"/>
40
-
41
- <!-- ── 分题型行 ── -->
42
- <!-- 抽取 -->
43
- <text x="240" y="249" font-size="19" fill="#C2CDDE" text-anchor="end">抽取</text>
44
- <rect x="260" y="234" width="700" height="18" rx="5" fill="#FFD15D"/>
45
- <text x="974" y="249" font-size="18" font-weight="700" fill="#FFD15D" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace">45/45</text>
46
-
47
- <!-- 多跳 -->
48
- <text x="240" y="303" font-size="19" fill="#C2CDDE" text-anchor="end">多跳</text>
49
- <rect x="260" y="288" width="700" height="18" rx="5" fill="#FFD15D"/>
50
- <text x="974" y="303" font-size="18" font-weight="700" fill="#FFD15D" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace">45/45</text>
51
-
52
- <!-- 时序 -->
53
- <text x="240" y="357" font-size="19" fill="#C2CDDE" text-anchor="end">时序</text>
54
- <rect x="260" y="342" width="669" height="18" rx="5" fill="#FFD15D"/>
55
- <text x="943" y="357" font-size="18" font-weight="700" fill="#FFD15D" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace">43/45</text>
56
-
57
- <!-- 知识更新 -->
58
- <text x="240" y="411" font-size="19" fill="#C2CDDE" text-anchor="end">知识更新 *</text>
59
- <rect x="260" y="396" width="482" height="18" rx="5" fill="#FFD15D"/>
60
- <text x="756" y="411" font-size="18" font-weight="700" fill="#FFD15D" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace">31/45</text>
61
-
62
- <!-- 场景回忆 -->
63
- <text x="240" y="465" font-size="19" fill="#C2CDDE" text-anchor="end">场景回忆</text>
64
- <rect x="260" y="450" width="638" height="18" rx="5" fill="#FFD15D"/>
65
- <text x="912" y="465" font-size="18" font-weight="700" fill="#FFD15D" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace">41/45</text>
66
-
67
- <!-- 拒答 -->
68
- <text x="240" y="519" font-size="19" fill="#C2CDDE" text-anchor="end">拒答 *</text>
69
- <rect x="260" y="504" width="700" height="18" rx="5" fill="#FFD15D"/>
70
- <text x="974" y="519" font-size="18" font-weight="700" fill="#FFD15D" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace">45/45</text>
71
-
72
- <!-- ── 脚注 ── -->
73
- <text x="64" y="600" font-size="16" fill="#8296B3">* 知识更新:改口后仍答旧值记 0 分(直接考核 L1 去重更新);拒答:没发生过的事编造即 0 分(0 编造)。</text>
74
- <text x="64" y="622" font-size="16" fill="#8296B3">对话赛道 B 组已下线:Harness 会话彼此独立,无记忆的探针必然失败,对照无信息量。</text>
68
+ <text x="64" y="600" font-size="16" fill="#8296B3">DSH-MemBench 0.8.5 基线 · DeepSeek v4-flash · 3 次重复合并 · 场景库跨场景累积(越靠后的场景记忆干扰越大)</text>
75
69
  </g>
76
70
  </svg>
@@ -0,0 +1,35 @@
1
+ /**
2
+ * bench 控制服务(config `benchControl` 门控,默认关):为同进程的基准驱动插件
3
+ * (dsh-bench-runner 的 lifecycle 赛道)提供进程内控制面。
4
+ *
5
+ * 为什么不走 RPC:宿主侧 connection.rpc 只有 handle/intercept、没有 call(),
6
+ * 基准驱动包在 dsh 宿主进程内无法调用插件的 loopback RPC 端点;cordis 服务
7
+ * (ctx.provide / ctx.get)是唯一干净的进程内通道。生产部署不开启该配置,
8
+ * 服务不注册、零表面积;即便开启,暴露的也只是既有公开 API 的薄包装,
9
+ * 不引入新逻辑:
10
+ * - RebuildController.start()/getStatus()(重建触发与状态轮询);
11
+ * - SessionModeStore.set()/get()(会话档位——capture/recall 每轮读 Map,
12
+ * agent 建好后、首条消息前设档即可生效,且走 onModeChange 回调的
13
+ * pending 落袋/挂起语义,不是裸改 Map)。
14
+ */
15
+ import type { Context } from '@deepseek-ai/cordis';
16
+ import type { MemoryLogger, MemoryMode } from './types.js';
17
+ import type { RebuildController, RebuildStatus } from './pipeline/rebuild.js';
18
+ import type { SessionModeStore } from './store/session-modes.js';
19
+ import type { DistillUsageSnapshot } from './llm-usage.js';
20
+ /** 服务名(消费方:bench/harness/dsh-bench-runner 的 lifecycle 赛道)。 */
21
+ export declare const BENCH_CONTROL_SERVICE = "dsh-memory-bench";
22
+ export interface BenchControlSurface {
23
+ /** 触发全量重建(从 L0 重导派生层);前置条件不满足时抛错(调用方捕获)。 */
24
+ rebuildStart(): RebuildStatus;
25
+ /** 重建状态快照(phase/running/recordsBuilt/…,轮询至 done/failed/cancelled)。 */
26
+ rebuildStatus(): RebuildStatus;
27
+ /** 设置会话档位(chat/work/off/auto);对全新会话应在首条消息前设置。 */
28
+ setSessionMode(sessionId: string, mode: MemoryMode): void;
29
+ /** 查询会话档位(未设过的会话返回部署默认档)。 */
30
+ getSessionMode(sessionId: string): MemoryMode;
31
+ /** 蒸馏用量快照(按层累计的调用数/输入字符/输出 token——「记忆开销」记账)。 */
32
+ getDistillUsage(): DistillUsageSnapshot;
33
+ }
34
+ /** 注册控制服务,返回注销函数(调用方在插件 dispose 时执行)。 */
35
+ export declare function registerBenchControl(ctx: Context, rebuild: RebuildController, modes: SessionModeStore, logger: MemoryLogger): () => void;
@@ -0,0 +1,16 @@
1
+ import { snapshotDistillUsage } from './llm-usage.js';
2
+ /** 服务名(消费方:bench/harness/dsh-bench-runner 的 lifecycle 赛道)。 */
3
+ export const BENCH_CONTROL_SERVICE = 'dsh-memory-bench';
4
+ /** 注册控制服务,返回注销函数(调用方在插件 dispose 时执行)。 */
5
+ export function registerBenchControl(ctx, rebuild, modes, logger) {
6
+ const surface = {
7
+ rebuildStart: () => rebuild.start(),
8
+ rebuildStatus: () => rebuild.getStatus(),
9
+ setSessionMode: (sessionId, mode) => modes.set(sessionId, mode),
10
+ getSessionMode: (sessionId) => modes.get(sessionId),
11
+ getDistillUsage: () => snapshotDistillUsage(),
12
+ };
13
+ const dispose = ctx.provide(BENCH_CONTROL_SERVICE, surface);
14
+ logger.info('[memory] bench 控制服务已提供(dsh-memory-bench,仅基准/调试部署)');
15
+ return dispose;
16
+ }