dsh-memoir 0.8.0 → 0.8.2

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/README.en.md CHANGED
@@ -9,16 +9,16 @@
9
9
 
10
10
  **A local-first, cross-session project-memory plugin for DeepSeek Harness (DSH).** It persists an agent's confirmed work, lessons, and next actions, injects bounded cache-friendly Hot Memory into new sessions, and retrieves long-tail history through local BM25 ranking.
11
11
 
12
- No embeddings, vector database, or cloud memory service. The npm package has zero bundled runtime dependencies; DSH peers are supplied by the host.
12
+ No embeddings, vector database, or cloud memory service. The npm package has zero bundled runtime dependencies; DSH and Zod 4 peers are supplied by the host environment; Zod validates session projections and is not bundled.
13
13
 
14
14
  > [!IMPORTANT]
15
- > **0.8.0 requires DSH `>=0.1.7-rc.1 <0.1.8-0`**, tested against `0.1.7-rc.1` with Windows/WSL regressions and an isolated Windows host. Pin `dsh-memoir@0.7.1` on legacy DSH 0.1.5 instead of upgrading to latest. Real-browser interaction and paid-model end-to-end validation remain unverified.
15
+ > **0.8.2 requires DSH `>=0.1.7-rc.1 <0.1.8-0`**, with SDKs pinned to `0.1.7-rc.2`. It fixes auto-distillation hiding the original task answer, adds an optional native right-sidebar panel and offline About & help, and retains unskinned Desktop styling, actual-save diagnostics and public Session projections. Keep `dsh-memoir@0.7.1` on DSH 0.1.5.
16
16
  >
17
17
  > `dsh-memoir@0.7.1` fixes lost session snapshots after restart or RAM eviction (#10), supporting DSH **0.1.5-rc.1 / rc.2**. It requires `>=0.1.5-rc.1 <0.1.6-0`; check your host first. Keep `0.6.2` on DSH 0.1.2, or `0.5.6` on DSH 0.1.1-rc.2; those older lines do not include this fix.
18
18
 
19
19
  ```bash
20
- npm install --global @deepseek-ai/dsh@0.1.7-rc.1
21
- dsh plugin --profile web add dsh-memoir@0.8.0
20
+ npm install --global @deepseek-ai/dsh@0.1.7-rc.2
21
+ dsh plugin --profile web add dsh-memoir@0.8.2
22
22
  ```
23
23
 
24
24
  Restart `dsh web`. Memory remains local and is not automatically deleted when the plugin is updated or removed.
@@ -88,12 +88,16 @@ Similar-memory governance starts with BM25 candidates, then combines title simil
88
88
 
89
89
  ## Automatic distillation
90
90
 
91
- v0.6.2 diagnostics show the latest decision and process-local counters. Turns calling `memoir_record` or `memoir_update` skip reminders; submitting a reminder does not confirm persistence. Agent disposal clears gate state, with a fallback cap of 1024 recently active agents (eviction also forgets their turn watermark and cooldown). Manual recording remains available when automatic distillation is disabled.
91
+ 0.8.2 diagnostics distinguish reminders, persistence, failures, cancellation, unresolved similarity, and unavailable receipts. Only persisted `memoir_record` / `memoir_update` operations suppress reminders; failed calls or unresolved candidates do not count as saves. Host cancellation may follow persistence, so counters can overlap. Correlation with a reminder proves neither causation nor semantic correctness. GUI writes are excluded from Agent-tool counters.
92
92
 
93
- 0.8.0 targets DSH `0.1.7-rc.1`; 0.7.1 was validated on `0.1.5-rc.1 / rc.2`. BM25 is lexical retrieval and does not guarantee cross-language semantic matches without shared terms. Distillation guidance does not replace fact checking.
93
+ 0.8.2 uses public `sessionProjections` to reconstruct current-turn activity from logs and checkpoints without deprecated `snapshotEvents()` reads. Each session retains at most 4096 current-turn call IDs, without arguments or content; evicted IDs degrade to session-only provenance. Gate state is capped at 1024 agents and cleared on disposal. Legacy writes have no receipts: a historical call alone cannot prove persistence. BM25 remains lexical retrieval, not guaranteed cross-language semantic matching.
94
94
 
95
95
  Automatic distillation is an observable agent turn-end reminder, not silent background scraping of every chat. The default `1 / 0 / 1` means every eligible worked turn, no extra cooldown, and at least one tool call.
96
96
 
97
+ > **0.8.2 fixes distillation-induced answer folding for new turns ([#13](https://github.com/Qinling-Melon-Farmers/dsh-memoir/issues/13)):** The public `followup` API queues a separate memory wrap-up turn instead of using same-turn `steer`. A short receipt, empty output or failed wrap-up tool cannot change the original task answer’s turn boundary. Memory provenance still points to the source work turn. Wrap-up turns neither advance the worked-turn cadence nor recursively trigger distillation. This is still visible, cancelable model work—not a free background task—and may increase the displayed turn count.
98
+ >
99
+ > Upgrading does not rewrite history. For same-turn folding already recorded by 0.8.0 / 0.8.1, expand the process disclosure or use Normal (`normal`) transcript mode. This fix does not change DSH’s answer selection for arbitrary same-turn continuations from other producers, and does not rely on a “remain silent” prompt.
100
+
97
101
  `autoDistillEvery`, `autoDistillCooldownMin`, and `autoDistillMinTools` are AND conditions isolated per agent. Idle, aborted, subagent, and already-recorded turns do not trigger. Cooldown advances only after a successful reminder. All cadence parameters are live-editable in the GUI.
98
102
 
99
103
  `language` independently controls agent-visible tool descriptions and parameters, the distillation prompt, tool results, Hot Memory / `PROJECT_MEMORY.md` headings, and validation or governance errors. It defaults to `zh` for backward compatibility and can be switched to `en` in the GUI. Tool schemas and subsequent prompts update live without restarting DSH.
@@ -152,11 +156,11 @@ Installing into a DSH-alpha `web` profile registers a native Memory Conversation
152
156
 
153
157
  | Channel | DSH baseline | Installation | Status |
154
158
  | --- | --- | --- | --- |
155
- | npm `latest` (`0.8.0`) | `>=0.1.7-rc.1 <0.1.8-0` | `dsh plugin --profile web add dsh-memoir@0.8.0` | DSH 0.1.7 line |
159
+ | npm `latest` (`0.8.2`) | `>=0.1.7-rc.1 <0.1.8-0` | `dsh plugin --profile web add dsh-memoir@0.8.2` | DSH 0.1.7 line |
156
160
  | pinned npm `0.7.1` | `>=0.1.5-rc.1 <0.1.6-0` | `dsh plugin --profile web add dsh-memoir@0.7.1` | Legacy 0.1.5 line |
157
161
  | pinned npm `0.6.2` | `>=0.1.2-alpha.2 <0.1.3` | `dsh plugin --profile web add dsh-memoir@0.6.2` | Legacy 0.1.2 line |
158
162
  | pinned npm `0.5.6` | `0.1.1-rc.2` | `dsh plugin --profile web add dsh-memoir@0.5.6` | rc2 compatibility line |
159
- | Source `v0.8.0` | `>=0.1.7-rc.1 <0.1.8-0` | local build + `link:` | Development; not compatible with legacy 0.1.5 / 0.1.6 |
163
+ | Source `v0.8.2` | `>=0.1.7-rc.1 <0.1.8-0` | local build + `link:` | Development; not compatible with legacy 0.1.5 / 0.1.6 |
160
164
 
161
165
  Node.js `^22.19.0 || >=24.0.0` is required. 0.7.1 keeps the native `conversation.view` / `settings.section` slots and `snapshotEvents()`. DSH 0.1.5 uses Session log V3, independent of Memoir store v4 / settings v3. Back up DSH_HOME before upgrading DSH; migrated sessions are not guaranteed readable by older hosts. This Memoir release neither migrates nor resets memory and retains frozen session snapshots without enabling new dynamic-prompt behavior.
162
166
 
@@ -176,7 +180,14 @@ dsh plugin --profile web add "link:/absolute/path/dsh-memoir"
176
180
 
177
181
  </details>
178
182
 
179
- 0.8.0 uses native `uiWorkspace` navigation, `conversation.view` / `settings.section`, and a producer-owned Session V4 distillation source. Source links open the session and turn IDs remain copyable; global DOM turn scrolling is removed to avoid targeting another conversation. `snapshotEvents()` remains in use (deprecated but still available); migration to public asynchronous projections is planned. Memoir data formats are unchanged. Back up DSH_HOME before upgrading: DSH Session V4 migration is separate from plugin memory storage.
183
+ 0.8.2 uses native `uiWorkspace`, `conversation.view` / `settings.section`, and the Session V4 producer-owned distillation source. Links open sessions and turn IDs remain copyable; no global DOM turn scrolling is used. Settings inherit the host background and cards use theme layers while preserving skins and independent scrolling. Store v4 / settings v3 / snapshot v1 are unchanged. Back up DSH_HOME before upgrading: host session migration is separate from plugin memory storage.
184
+
185
+ ## Native sidebar and help
186
+
187
+ - Existing Conversation and Settings entries stay unchanged. The right-sidebar guide now offers Memory for browsing project memory, Hot Memory and diagnostics alongside chat; it never opens automatically or replaces another panel.
188
+ - Each sidebar instance follows its own session workspace and reuses the same data layer, with independent active surfaces and scroll state. Conversation and Settings remain available when the optional sidebar service is absent.
189
+ - Under Memory settings, the collapsed About & help card shows the plugin version, host range, SDK baseline, maintainer, repository, bilingual documentation, releases and issue links. The plugin repository is explicitly distinct from the current workspace.
190
+ - No background update requests, workspace Git-remote inspection or path/memory uploads. Use the host plugin manager to update, after checking the target package’s DSH requirements and prerelease channel. The panel does not auto-upgrade.
180
191
 
181
192
  ## Storage, privacy, and security boundaries
182
193
 
@@ -229,9 +240,7 @@ v0.5.6 benchmark (Node 24.19, 900/1200-token budget; full data in [`bench/report
229
240
 
230
241
  Numbers vary by machine and corpus. The important properties are that injection remains bounded and the cache-hit path is independent of total memory size.
231
242
 
232
- 0.8.0: Windows passes 206 of 207 tests with one skip; WSL passes all 207. Typecheck/build pass on both. Three Cordis lifecycle cycles and client slot/style/language-observer cleanup pass, as do the isolated Windows page, official client combo and Memoir APIs. Real-browser interaction and paid-model end-to-end validation remain unverified; historical screenshots are not visual evidence for this version.
233
-
234
- Historical 0.7.1 has 202 tests: 201 pass on Windows with one POSIX permission test skipped; all pass on Linux. Coverage includes actual process restart, same-session concurrent creation, LRU, empty baselines, forks, language isolation, corruption and permission errors, plus existing BM25/Hot Memory/tool regressions. DSH rc.1 and the newest rc.2 are validated. Prefix equality in tests is not a guarantee of actual billing savings.
243
+ Automated regressions cover session projection recovery, cross-process snapshots, writes and cancellation, lifecycle cleanup, BM25 recall, Hot Memory budgets, caching, corrections and project isolation. Curated lexical Top-5 recall is 41/41; fixture results do not measure real-model semantic accuracy, and prefix equality does not guarantee actual billing savings.
235
244
 
236
245
  ## FAQ
237
246
 
@@ -260,6 +269,6 @@ pnpm test
260
269
  npm run bench
261
270
  ```
262
271
 
263
- Read [CONTRIBUTING.md](./CONTRIBUTING.md) before submitting changes. See [CHANGELOG.md](./CHANGELOG.md) for version history. Formal packages are published by the tag workflow through npm OIDC. The current version is [v0.8.0](https://github.com/Qinling-Melon-Farmers/dsh-memoir/releases/tag/v0.8.0), targeting DSH 0.1.7. Keep 0.7.1 on legacy DSH 0.1.5.
272
+ Read [CONTRIBUTING.md](./CONTRIBUTING.md) before submitting changes. See [CHANGELOG.md](./CHANGELOG.md) for version history. Formal packages are published by the tag workflow through npm OIDC. The current version is [v0.8.2](https://github.com/Qinling-Melon-Farmers/dsh-memoir/releases/tag/v0.8.2), targeting DSH 0.1.7. Keep 0.7.1 on legacy DSH 0.1.5.
264
273
 
265
274
  Apache-2.0
package/README.md CHANGED
@@ -8,16 +8,16 @@
8
8
 
9
9
  **DeepSeek Harness(DSH)的本地优先、跨会话项目记忆插件。** 它把 Agent 已确认的工作结论、经验教训和后续行动持久化,在新会话中注入有界且缓存友好的 Hot Memory,并通过本地 BM25 排序召回长尾历史。
10
10
 
11
- 无需 embedding、向量数据库或云端记忆服务;npm 包零捆绑运行时依赖,DSH peer 由宿主提供。
11
+ 无需 embedding、向量数据库或云端记忆服务;npm 包零捆绑运行时依赖,DSH 与 Zod 4 peer 由宿主环境提供;Zod 用于验证宿主会话投影,不捆绑进插件。
12
12
 
13
13
  > [!IMPORTANT]
14
- > **0.8.0 要求 DSH `>=0.1.7-rc.1 <0.1.8-0`**,已针对 `0.1.7-rc.1` 完成 Windows/WSL 自动化回归与 Windows 隔离宿主验证。旧 DSH 0.1.5 请固定安装 `dsh-memoir@0.7.1`,不要直接升级 latest。真实浏览器交互与付费模型端到端验证尚未完成。
14
+ > **0.8.2 要求 DSH `>=0.1.7-rc.1 <0.1.8-0`**,开发 SDK 为 `0.1.7-rc.2`。修复自动蒸馏遮住原任务答复的问题;新增可选原生右侧记忆面板和离线“关于与帮助”。保留无皮肤桌面适配、实际保存诊断和公开 Session projection。旧 DSH 0.1.5 请固定安装 `dsh-memoir@0.7.1`。
15
15
  >
16
16
  > `dsh-memoir@0.7.1` 修复重启和内存淘汰后旧会话快照丢失(#10),支持 DSH **0.1.5-rc.1 / rc.2**。要求 `>=0.1.5-rc.1 <0.1.6-0`;请先核对宿主版本。旧 DSH 0.1.2 用户固定使用 `0.6.2`,0.1.1-rc.2 用户固定使用 `0.5.6`;这些旧版未包含本次修复。
17
17
 
18
18
  ```bash
19
- npm install --global @deepseek-ai/dsh@0.1.7-rc.1
20
- dsh plugin --profile web add dsh-memoir@0.8.0
19
+ npm install --global @deepseek-ai/dsh@0.1.7-rc.2
20
+ dsh plugin --profile web add dsh-memoir@0.8.2
21
21
  ```
22
22
 
23
23
  重启 `dsh web` 即可。记忆保存在本机,不会随插件升级或卸载自动删除。
@@ -87,13 +87,17 @@ memoir_record / memoir_update
87
87
 
88
88
  ## 自动蒸馏
89
89
 
90
- v0.6.2 的诊断页显示最近触发或跳过原因及本次进程计数。已经调用 `memoir_record` 或 `memoir_update` 的回合不再提醒;提交提醒不代表写入已完成。Agent 销毁会清理门控状态,最多保留 1024 个最近活动 Agent(淘汰后不再保留其回合水位和冷却)。关闭自动蒸馏后仍可手动记录。
90
+ 0.8.2 诊断页区分提醒提交、实际保存、失败、取消、相似记忆待确认和回执降级。只有成功保存的 `memoir_record` / `memoir_update` 才抑制本回合提醒;失败或相似候选待确认不算写入。保存后宿主仍可能取消最终工具结果,因此计数可以重叠。提醒与后续保存的关联不证明因果或内容正确。GUI 手工写入不计入 Agent 工具计数。
91
91
 
92
- 0.8.0面向 DSH `0.1.7-rc.1`;0.7.1 的历史验证范围为 `0.1.5-rc.1 / rc.2`。BM25 是词项召回,不能保证无共同词项的跨语言语义匹配;提炼质量提示也不能替代事实核验。
92
+ 0.8.2 使用公开 `sessionProjections` 从日志和 checkpoint 重建当前回合,不再读取弃用的 `snapshotEvents()`。每会话只保留当前回合最多 4096 个调用 ID,不保存参数或正文;超出保留范围时来源降级为 session-only。门控最多保留 1024 个 Agent,销毁时清理;旧版写入没有保存回执,不能仅从历史调用推断成功。BM25 是词项召回,不承诺跨语言语义匹配。
93
93
 
94
94
  自动蒸馏是可观察的 Agent 收尾提醒,不是后台静默抓取聊天内容。默认 `1 / 0 / 1` 表示:每个有效 worked turn、无额外冷却、至少一次工具调用即可提醒。
95
95
 
96
- `autoDistillEvery`、`autoDistillCooldownMin`、`autoDistillMinTools` 三个条件按 AND 判定并按 Agent 隔离。idle、aborted、subagent 和已调用 `memoir_record` 的回合不会触发;冷却只在提醒成功后更新。所有频率参数都可在 GUI 中即时修改。
96
+ > **0.8.2 修复了新回合的蒸馏答案折叠问题([#13](https://github.com/Qinling-Melon-Farmers/dsh-memoir/issues/13))**:通过公开 `followup` 排入独立记忆收尾回合,不再用同回合 `steer` 抢占原任务回合的最后一步。短回执、空输出或收尾工具失败都不会改变原任务答复的回合边界;记忆来源仍指向原工作回合。收尾回合不计入 worked-turn 频率,也不会递归触发蒸馏。它仍是可见、可取消的模型收尾,不是无成本后台任务,可能增加会话显示的回合数。
97
+ >
98
+ > 升级不会改写旧会话:0.8.0 / 0.8.1 产生的同回合折叠历史仍需展开“用时 / 过程”或切到标准(`normal`)模式查看。本修复不改变 DSH 对任意其他同回合追加步骤的答案选择,也不靠“禁止输出”的提示词掩盖问题。
99
+
100
+ `autoDistillEvery`、`autoDistillCooldownMin`、`autoDistillMinTools` 三个条件按 AND 判定并按 Agent 隔离。idle、aborted、subagent 和已成功保存记忆的回合不会触发;冷却只在提醒成功后更新。所有频率参数都可在 GUI 中即时修改。
97
101
 
98
102
  `language` 独立控制 Agent 可见的工具描述、参数说明、蒸馏提示、工具结果、Hot Memory / `PROJECT_MEMORY.md` 标题以及校验与治理错误。默认 `zh` 保持向后兼容,也可在 GUI 中切换为 `en`;切换后工具 schema 与后续提示即时更新,不要求重启 DSH。
99
103
 
@@ -151,11 +155,11 @@ v0.6.2 的诊断页显示最近触发或跳过原因及本次进程计数。已
151
155
 
152
156
  | 渠道 | DSH 基线 | 安装方式 | 状态 |
153
157
  | --- | --- | --- | --- |
154
- | npm `latest`(`0.8.0`) | `>=0.1.7-rc.1 <0.1.8-0` | `dsh plugin --profile web add dsh-memoir@0.8.0` | 0.1.7 兼容线 |
158
+ | npm `latest`(`0.8.2`) | `>=0.1.7-rc.1 <0.1.8-0` | `dsh plugin --profile web add dsh-memoir@0.8.2` | 0.1.7 兼容线 |
155
159
  | npm 固定版 `0.7.1` | `>=0.1.5-rc.1 <0.1.6-0` | `dsh plugin --profile web add dsh-memoir@0.7.1` | 旧 0.1.5 维护线 |
156
160
  | npm 固定版 `0.6.2` | `>=0.1.2-alpha.2 <0.1.3` | `dsh plugin --profile web add dsh-memoir@0.6.2` | 旧 0.1.2 兼容线 |
157
161
  | npm 固定版 `0.5.6` | `0.1.1-rc.2` | `dsh plugin --profile web add dsh-memoir@0.5.6` | rc2 兼容线 |
158
- | 源码 `v0.8.0` | `>=0.1.7-rc.1 <0.1.8-0` | 本地构建 + `link:` | 开发调试,不兼容旧 0.1.5 / 0.1.6 |
162
+ | 源码 `v0.8.2` | `>=0.1.7-rc.1 <0.1.8-0` | 本地构建 + `link:` | 开发调试,不兼容旧 0.1.5 / 0.1.6 |
159
163
 
160
164
  需要 Node.js `^22.19.0 || >=24.0.0`。0.7.1 继续使用原生 `conversation.view` / `settings.section` 与 `snapshotEvents()`。DSH 0.1.5 的会话日志升级至 V3;其迁移与 Memoir 的 store v4 / settings v3 是独立格式。升级 DSH 前备份 DSH_HOME,迁移后的 DSH 会话不能承诺被旧宿主读取。Memoir 本次不迁移或清空记忆,也不启用新动态提示词行为;既有会话快照语义保持不变。
161
165
 
@@ -175,7 +179,14 @@ dsh plugin --profile web add "link:/absolute/path/dsh-memoir"
175
179
 
176
180
  </details>
177
181
 
178
- 0.8.0使用原生 `uiWorkspace` 导航、`conversation.view` / `settings.section` 和 Session V4 专属蒸馏来源。来源链接打开会话,回合编号可复制;不再通过全局 DOM 自动滚到回合,避免多会话串扰。`snapshotEvents()` 仍在使用(宿主已标记弃用但尚未移除),公开异步 projection 迁移列入后续版本。Memoir 数据格式不变;升级 DSH 前备份 DSH_HOME,其 Session V4 迁移与插件记忆迁移是两回事。
182
+ 0.8.2 使用原生 `uiWorkspace`、`conversation.view` / `settings.section` 与 Session V4 专属蒸馏来源。来源链接打开会话,回合编号可复制;不通过全局 DOM 自动滚到回合。设置页继承宿主背景、卡片使用主题层级色,保留皮肤覆盖与独立滚动。store v4 / settings v3 / snapshot v1 不变。升级 DSH 前备份 DSH_HOME,其会话迁移与插件记忆是两回事。
183
+
184
+ ## 原生侧栏与帮助入口
185
+
186
+ - 会话“记忆”和设置页入口保持不变;右侧栏引导页新增“记忆”,可边对话边看项目记忆、Hot Memory 和诊断,不会自动打开或抢占其它面板。
187
+ - 侧栏读取所属会话的工作区,复用同一数据层;每个实例独立保存当前功能区和滚动状态。缺少侧栏服务时,会话页和设置页仍可用。
188
+ - 任一记忆面板的“记忆设置”底部提供默认折叠的“关于与帮助”:显示插件版本、宿主范围、SDK 基线、维护者,以及仓库、双语文档、Release、反馈链接。插件仓库与当前工作区明确区分。
189
+ - 关于区不后台联网、不探测工作区 Git remote、不上传路径或记忆内容。更新通过宿主插件管理器操作,先核对目标包要求的 DSH 版本和预发布通道;本面板不自动升级。
179
190
 
180
191
  ## 存储、隐私与安全边界
181
192
 
@@ -228,9 +239,7 @@ v0.5.6 基准(Node 24.19,900/1200 token;完整数据见 [`bench/report.md`
228
239
 
229
240
  基准值取决于机器和语料;它证明的重点是注入预算保持有界、缓存命中路径与记忆总量解耦。
230
241
 
231
- 0.8.0:Windows 207 项测试中 206 通过、1 项跳过,WSL 207 项全部通过;双端类型检查/构建通过。三轮 Cordis 生命周期与客户端 slots/样式/语言 observer 清理测试通过,Windows 隔离宿主页、官方客户端组合资源及 Memoir API 通过。未完成真实浏览器交互和付费模型端到端验收;历史截图不是本版实机证据。
232
-
233
- 历史 0.7.1 含 202 项测试:Windows 201 项通过、1 项 POSIX 权限测试跳过;Linux 全部通过。覆盖实际跨进程快照恢复、同会话并发写入、LRU、空基线、fork、语言隔离、损坏与权限失败,以及原有 BM25/Hot Memory/工具回归。已核验 DSH rc.1 和最新 rc.2;没有把测试前缀一致性等同于实际账单节省保证。
242
+ 自动化回归覆盖会话投影恢复、跨进程快照、写入与取消、生命周期清理、BM25 召回、Hot Memory 预算、缓存、纠错与跨项目隔离。固定词项样本的 Top-5 召回为 41/41;样本结果不代表真实模型的语义正确率,前缀一致性也不等同于实际账单节省保证。
234
243
 
235
244
  ## 常见问题
236
245
 
@@ -259,6 +268,6 @@ pnpm test
259
268
  npm run bench
260
269
  ```
261
270
 
262
- 提交前请阅读 [CONTRIBUTING.md](./CONTRIBUTING.md)。版本变化见 [CHANGELOG.md](./CHANGELOG.md),正式包由 tag 工作流通过 npm OIDC 发布。当前版本是 [v0.8.0](https://github.com/Qinling-Melon-Farmers/dsh-memoir/releases/tag/v0.8.0),面向 DSH 0.1.7;旧 0.1.5 保留 0.7.1。
271
+ 提交前请阅读 [CONTRIBUTING.md](./CONTRIBUTING.md)。版本变化见 [CHANGELOG.md](./CHANGELOG.md),正式包由 tag 工作流通过 npm OIDC 发布。当前版本是 [v0.8.2](https://github.com/Qinling-Melon-Farmers/dsh-memoir/releases/tag/v0.8.2),面向 DSH 0.1.7;旧 0.1.5 保留 0.7.1。
263
272
 
264
273
  Apache-2.0
package/cordis.patch.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-memoir bundle patch: inserts the host-half plugin row into the web
2
2
  # profile roster. Applied as a profile bundle layer (the `dsh.bundle.patch`
3
- # manifest field) over dsh-base. dsh-memoir v0.8.0 targets the DSH
3
+ # manifest field) over dsh-base. dsh-memoir v0.8.1 targets the DSH
4
4
  # line >=0.1.7-rc.1 <0.1.8-0. Keep Memoir 0.7.1 on older DSH 0.1.5.
5
5
  #
6
6
  # The row is a bare plugin by package name: the node half (exports ".")
@@ -0,0 +1,32 @@
1
+ /** Bounded, replayable activity projection. No synchronous Session log reads. */
2
+ import { z } from 'zod';
3
+ import type { ProjectionDefinition } from '@deepseek-ai/dsh-session-projection';
4
+ export declare const ACTIVITY_KEY = "dsh-memoir/activity";
5
+ export declare const CALL_LIMIT = 4096;
6
+ declare const schema: z.ZodObject<{
7
+ turn: z.ZodNumber;
8
+ toolCalls: z.ZodNumber;
9
+ calls: z.ZodArray<z.ZodString>;
10
+ recorded: z.ZodBoolean;
11
+ reminded: z.ZodBoolean;
12
+ distilling: z.ZodBoolean;
13
+ originTurn: z.ZodNullable<z.ZodNumber>;
14
+ }, z.core.$strip>;
15
+ export type MemoirActivity = z.infer<typeof schema>;
16
+ export declare const emptyActivity: () => MemoirActivity;
17
+ declare module '@deepseek-ai/dsh-session-projection/types' {
18
+ interface SessionProjectionStateMap {
19
+ 'dsh-memoir/activity': MemoirActivity;
20
+ }
21
+ }
22
+ declare module '@deepseek-ai/dsh-session/types' {
23
+ interface SessionEventMap {
24
+ /** Receipt after the Memoir store commit; no memory content is copied. */
25
+ 'dsh-memoir/written': {
26
+ turn: number;
27
+ callId: string;
28
+ };
29
+ }
30
+ }
31
+ export declare const activityProjection: ProjectionDefinition<typeof ACTIVITY_KEY>;
32
+ export {};
@@ -0,0 +1,49 @@
1
+ /** Bounded, replayable activity projection. No synchronous Session log reads. */
2
+ import { z } from 'zod';
3
+ export const ACTIVITY_KEY = 'dsh-memoir/activity';
4
+ export const CALL_LIMIT = 4096;
5
+ const schema = z.object({
6
+ turn: z.number().int().nonnegative(),
7
+ toolCalls: z.number().int().nonnegative(),
8
+ calls: z.array(z.string()).max(CALL_LIMIT),
9
+ recorded: z.boolean(),
10
+ reminded: z.boolean(),
11
+ distilling: z.boolean(),
12
+ originTurn: z.number().int().positive().nullable(),
13
+ });
14
+ export const emptyActivity = () => ({ turn: 0, toolCalls: 0, calls: [], recorded: false, reminded: false, distilling: false, originTurn: null });
15
+ export const activityProjection = {
16
+ key: ACTIVITY_KEY,
17
+ stateVersion: 2,
18
+ stateSchema: schema,
19
+ init: emptyActivity,
20
+ apply(previous, event) {
21
+ if (event.type === 'turn/start' || event.type === 'tool/call' || event.type === 'dsh-memoir/written') {
22
+ const turn = event.data.turn;
23
+ if (turn < previous.turn)
24
+ return previous;
25
+ const state = turn > previous.turn ? { ...emptyActivity(), turn } : previous;
26
+ if (event.type === 'turn/start')
27
+ return state;
28
+ if (event.type === 'dsh-memoir/written')
29
+ return state.recorded ? state : { ...state, recorded: true };
30
+ if (state.calls.includes(event.data.callId))
31
+ return state;
32
+ return { ...state, toolCalls: state.toolCalls + 1, calls: [...state.calls, event.data.callId].slice(-CALL_LIMIT) };
33
+ }
34
+ // next-step is retained for replay of pre-0.8.2 sessions. New reminders
35
+ // use next-turn, protecting the original turn's compact answer boundary.
36
+ if (event.type === 'agent/inbox/spliced' &&
37
+ event.data.inserted.some(message => message.source.kind === 'dsh-memoir')) {
38
+ return previous.reminded ? previous : { ...previous, reminded: true };
39
+ }
40
+ // Persisted source identity survives reloads/remounts. Do not rely on a
41
+ // process-local flag: a failed or empty distillation must not recurse.
42
+ if (event.type === 'user/message' && event.data.source.kind === 'dsh-memoir') {
43
+ const origin = event.data.source.originTurn;
44
+ const originTurn = typeof origin === 'number' && Number.isInteger(origin) && origin > 0 && origin < previous.turn ? origin : null;
45
+ return { ...previous, reminded: true, distilling: true, originTurn };
46
+ }
47
+ return previous;
48
+ },
49
+ };
@@ -1,28 +1,31 @@
1
1
  /**
2
2
  * Automatic turn-end distillation: when the plugin is enabled, each turn of a
3
3
  * top-level agent that did real work (made tool calls) and did not already
4
- * record memory is followed by one steering step asking the agent to distill
4
+ * persist memory is followed by a separate turn asking the agent to distill
5
5
  * the turn into memoir_record entries. Turns without tool activity are left
6
- * alone (no extra model cost), subagent sessions are never steered, and each
7
- * turn is steered at most once — the steering step runs inside the same turn,
8
- * so the per-turn gate is what lets the turn close afterwards.
6
+ * alone (no extra model cost), subagent sessions are excluded, and each work
7
+ * turn queues at most one reminder. Never steer inside the completed work
8
+ * turn: compact chat selects its last step as the answer. The replayable
9
+ * activity projection excludes reminder turns, including failed/no-op ones.
9
10
  *
10
11
  * Pure decision helpers are exported for unit tests.
11
12
  */
12
13
  import type { UserMessage } from '@deepseek-ai/dsh-llm';
13
14
  import type { MemoirLanguage } from './i18n.js';
15
+ import type { MemoirActivity } from './activity.js';
14
16
  declare module '@deepseek-ai/dsh-llm/message' {
15
17
  interface MessageSourceMap {
16
18
  'dsh-memoir': {
17
19
  kind: 'dsh-memoir';
20
+ originTurn?: number;
18
21
  };
19
22
  }
20
23
  }
21
- /** The steering prompt injected at the end of an active turn. */
22
- export declare function distillPrompt(language?: MemoirLanguage): string;
24
+ /** The follow-up instruction; the originating work turn is not rewritten. */
25
+ export declare function distillPrompt(language?: MemoirLanguage, originTurn?: number): string;
23
26
  /** Backwards-compatible Chinese prompt constant. */
24
27
  export declare const DISTILL_PROMPT: string;
25
- /** Plugin identity stamped on the steering message source. */
28
+ /** Plugin identity stamped on the follow-up message source. */
26
29
  export declare const AUTO_DISTILL_PLUGIN = "dsh-memoir";
27
30
  /** A minimal event view for the turn-activity scan (data is narrowed inside). */
28
31
  export interface TurnEventLike {
@@ -34,17 +37,7 @@ export interface TurnActivity {
34
37
  recorded: boolean;
35
38
  toolCalls: number;
36
39
  }
37
- /**
38
- * Session-log compatibility surface. DSH <= alpha.3 exposed `events` while
39
- * alpha.4+ keeps the log private and exposes an immutable snapshot method.
40
- */
41
- export interface SessionEventSource {
42
- readonly events?: readonly TurnEventLike[];
43
- snapshotEvents?: () => readonly TurnEventLike[];
44
- }
45
- /** Read a stable session event snapshot across the old and new DSH APIs. */
46
- export declare function sessionEventSnapshot(session: SessionEventSource | undefined): readonly TurnEventLike[];
47
- /** Scan the tail of a session log for one turn's tool activity. */
40
+ /** Pure event-fixture fold. Runtime activity comes from the host projection. */
48
41
  export declare function turnActivity(events: readonly TurnEventLike[], turn: number): TurnActivity;
49
42
  /** The agent surface the turn-stopping listener needs. */
50
43
  export interface AutoDistillAgentLike {
@@ -57,7 +50,7 @@ export interface AutoDistillAgentLike {
57
50
  readonly events?: readonly TurnEventLike[];
58
51
  snapshotEvents?: () => readonly TurnEventLike[];
59
52
  };
60
- steer(message: UserMessage): void;
53
+ followup(message: UserMessage): void;
61
54
  }
62
55
  /** Subagent sessions (and any nested delegation) never get distilled. */
63
56
  export declare function isSubagentSession(agent: AutoDistillAgentLike): boolean;
@@ -78,21 +71,24 @@ export declare class AutoDistillGate {
78
71
  * are ready. Duplicate events never advance the worked-turn counter.
79
72
  */
80
73
  consume(agentId: string, turn: number, toolCalls: number, policy: AutoDistillPolicy, now: number): boolean;
81
- /** Record a successful steer; failed steer attempts do not start cooldown. */
82
- recordSteer(agentId: string, now: number): void;
74
+ /** Record a successful followup; failed followup attempts do not start cooldown. */
75
+ recordReminder(agentId: string, now: number): void;
83
76
  /** Drop all state for one agent (disposal hygiene). */
84
77
  forget(agentId: string): void;
85
78
  }
86
- export type DistillOutcome = 'disabled' | 'subagent' | 'aborted' | 'idle' | 'recorded' | 'duplicate' | 'interval' | 'tools' | 'cooldown' | 'steered' | 'failed';
79
+ export type DistillOutcome = 'disabled' | 'subagent' | 'aborted' | 'idle' | 'recorded' | 'duplicate' | 'interval' | 'tools' | 'cooldown' | 'queued' | 'distillation' | 'failed' | 'unavailable';
87
80
  /** Process-local counters only; never retains message content or credentials. */
88
81
  export declare class DistillDiagnostics {
89
82
  private counts;
90
83
  private last;
91
84
  private workedTurns;
92
85
  private agents;
86
+ private writes;
87
+ write(outcome: keyof DistillDiagnostics['writes']): void;
93
88
  record(outcome: DistillOutcome, at: number, turn: number, toolCalls: number, agents: number): void;
94
89
  snapshot(): {
95
90
  counts: {
91
+ recorded?: number | undefined;
96
92
  subagent?: number | undefined;
97
93
  duplicate?: number | undefined;
98
94
  interval?: number | undefined;
@@ -101,9 +97,18 @@ export declare class DistillDiagnostics {
101
97
  disabled?: number | undefined;
102
98
  aborted?: number | undefined;
103
99
  idle?: number | undefined;
104
- recorded?: number | undefined;
105
- steered?: number | undefined;
100
+ queued?: number | undefined;
101
+ distillation?: number | undefined;
106
102
  failed?: number | undefined;
103
+ unavailable?: number | undefined;
104
+ };
105
+ writes: {
106
+ persisted: number;
107
+ afterReminder: number;
108
+ failed: number;
109
+ canceled: number;
110
+ needsResolution: number;
111
+ receiptFailed: number;
107
112
  };
108
113
  workedTurns: number;
109
114
  agents: number;
@@ -142,8 +147,10 @@ export declare function installAutoDistill(wire: AutoDistillWire, options: {
142
147
  cooldownMin?: number;
143
148
  minTools?: number;
144
149
  };
145
- /** Optional live language source for the steering instruction. */
150
+ /** Optional live language source for the follow-up instruction. */
146
151
  language?: () => MemoirLanguage;
147
152
  now?: () => number;
148
153
  diagnostics?: DistillDiagnostics;
154
+ /** Public host projection at the exact Session cursor; absent means skip safely. */
155
+ activity?: (agent: AutoDistillAgentLike) => MemoirActivity | undefined;
149
156
  }): () => void;
@@ -1,31 +1,29 @@
1
1
  /**
2
2
  * Automatic turn-end distillation: when the plugin is enabled, each turn of a
3
3
  * top-level agent that did real work (made tool calls) and did not already
4
- * record memory is followed by one steering step asking the agent to distill
4
+ * persist memory is followed by a separate turn asking the agent to distill
5
5
  * the turn into memoir_record entries. Turns without tool activity are left
6
- * alone (no extra model cost), subagent sessions are never steered, and each
7
- * turn is steered at most once — the steering step runs inside the same turn,
8
- * so the per-turn gate is what lets the turn close afterwards.
6
+ * alone (no extra model cost), subagent sessions are excluded, and each work
7
+ * turn queues at most one reminder. Never steer inside the completed work
8
+ * turn: compact chat selects its last step as the answer. The replayable
9
+ * activity projection excludes reminder turns, including failed/no-op ones.
9
10
  *
10
11
  * Pure decision helpers are exported for unit tests.
11
12
  */
12
13
  import { createUserMessage } from '@deepseek-ai/dsh-llm';
13
14
  import { DEFAULT_MEMOIR_LANGUAGE, hostCopy } from './i18n.js';
14
- /** The steering prompt injected at the end of an active turn. */
15
- export function distillPrompt(language = DEFAULT_MEMOIR_LANGUAGE) {
16
- return hostCopy(language).distillPrompt;
15
+ /** The follow-up instruction; the originating work turn is not rewritten. */
16
+ export function distillPrompt(language = DEFAULT_MEMOIR_LANGUAGE, originTurn) {
17
+ const origin = originTurn === undefined ? '' : language === 'en'
18
+ ? `Source work turn: ${originTurn}. This is a separate memory-only follow-up, not a new user task.\n`
19
+ : `来源工作回合:${originTurn}。这是独立的记忆收尾回合,不是新的用户任务。\n`;
20
+ return origin + hostCopy(language).distillPrompt;
17
21
  }
18
22
  /** Backwards-compatible Chinese prompt constant. */
19
23
  export const DISTILL_PROMPT = distillPrompt();
20
- /** Plugin identity stamped on the steering message source. */
24
+ /** Plugin identity stamped on the follow-up message source. */
21
25
  export const AUTO_DISTILL_PLUGIN = 'dsh-memoir';
22
- /** Read a stable session event snapshot across the old and new DSH APIs. */
23
- export function sessionEventSnapshot(session) {
24
- if (typeof session?.snapshotEvents === 'function')
25
- return session.snapshotEvents();
26
- return session?.events ?? [];
27
- }
28
- /** Scan the tail of a session log for one turn's tool activity. */
26
+ /** Pure event-fixture fold. Runtime activity comes from the host projection. */
29
27
  export function turnActivity(events, turn) {
30
28
  let recorded = false;
31
29
  let toolCalls = 0;
@@ -40,9 +38,9 @@ export function turnActivity(events, turn) {
40
38
  continue;
41
39
  if (event.type === 'tool/call') {
42
40
  toolCalls += 1;
43
- if (data.name === 'memoir_record' || data.name === 'memoir_update')
44
- recorded = true;
45
41
  }
42
+ if (event.type === 'dsh-memoir/written')
43
+ recorded = true;
46
44
  }
47
45
  return { worked: toolCalls > 0, recorded, toolCalls };
48
46
  }
@@ -64,7 +62,7 @@ export class AutoDistillGate {
64
62
  consume(agentId, turn, toolCalls, policy, now) {
65
63
  let state = this.states.get(agentId);
66
64
  if (state === undefined) {
67
- state = { lastTurn: -Infinity, workedSinceSteer: 0 };
65
+ state = { lastTurn: -Infinity, workedSinceReminder: 0 };
68
66
  this.states.set(agentId, state);
69
67
  if (this.states.size > this.capacity)
70
68
  this.states.delete(this.states.keys().next().value);
@@ -76,20 +74,20 @@ export class AutoDistillGate {
76
74
  state.lastTurn = turn;
77
75
  this.states.delete(agentId);
78
76
  this.states.set(agentId, state);
79
- state.workedSinceSteer += 1;
80
- const intervalReady = state.workedSinceSteer >= policy.every;
77
+ state.workedSinceReminder += 1;
78
+ const intervalReady = state.workedSinceReminder >= policy.every;
81
79
  const activityReady = toolCalls >= policy.minTools;
82
- const cooldownReady = state.lastSteeredAt === undefined || now - state.lastSteeredAt >= policy.cooldownMs;
80
+ const cooldownReady = state.lastRemindedAt === undefined || now - state.lastRemindedAt >= policy.cooldownMs;
83
81
  this.reason = !intervalReady ? 'interval' : !activityReady ? 'tools' : !cooldownReady ? 'cooldown' : 'ready';
84
82
  return this.reason === 'ready';
85
83
  }
86
- /** Record a successful steer; failed steer attempts do not start cooldown. */
87
- recordSteer(agentId, now) {
84
+ /** Record a successful followup; failed followup attempts do not start cooldown. */
85
+ recordReminder(agentId, now) {
88
86
  const state = this.states.get(agentId);
89
87
  if (state === undefined)
90
88
  return;
91
- state.workedSinceSteer = 0;
92
- state.lastSteeredAt = now;
89
+ state.workedSinceReminder = 0;
90
+ state.lastRemindedAt = now;
93
91
  }
94
92
  /** Drop all state for one agent (disposal hygiene). */
95
93
  forget(agentId) {
@@ -102,14 +100,16 @@ export class DistillDiagnostics {
102
100
  last = null;
103
101
  workedTurns = 0;
104
102
  agents = 0;
103
+ writes = { persisted: 0, afterReminder: 0, failed: 0, canceled: 0, needsResolution: 0, receiptFailed: 0 };
104
+ write(outcome) { this.writes[outcome] += 1; }
105
105
  record(outcome, at, turn, toolCalls, agents) {
106
106
  this.counts[outcome] = (this.counts[outcome] ?? 0) + 1;
107
- if (['interval', 'tools', 'cooldown', 'steered', 'failed'].includes(outcome))
107
+ if (['interval', 'tools', 'cooldown', 'queued', 'failed'].includes(outcome))
108
108
  this.workedTurns += 1;
109
109
  this.last = { outcome, at, turn, toolCalls };
110
110
  this.agents = agents;
111
111
  }
112
- snapshot() { return { counts: { ...this.counts }, workedTurns: this.workedTurns, agents: this.agents, last: this.last === null ? null : { ...this.last } }; }
112
+ snapshot() { return { counts: { ...this.counts }, writes: { ...this.writes }, workedTurns: this.workedTurns, agents: this.agents, last: this.last === null ? null : { ...this.last } }; }
113
113
  setAgents(agents) { this.agents = agents; }
114
114
  }
115
115
  /**
@@ -137,11 +137,28 @@ export function installAutoDistill(wire, options) {
137
137
  report('aborted');
138
138
  return;
139
139
  }
140
- const { worked, recorded, toolCalls } = turnActivity(sessionEventSnapshot(agent.session), turn);
141
- if (!worked || recorded) {
140
+ const activity = options.activity?.(agent);
141
+ if (activity === undefined) {
142
+ report('unavailable');
143
+ return;
144
+ }
145
+ if (activity.turn > turn) {
146
+ report('duplicate');
147
+ return;
148
+ }
149
+ if (activity.turn === turn && activity.distilling) {
150
+ report('distillation', activity.toolCalls);
151
+ return;
152
+ }
153
+ const { recorded, toolCalls, reminded } = activity.turn === turn ? activity : { recorded: false, toolCalls: 0, reminded: false };
154
+ if (toolCalls === 0 || recorded) {
142
155
  report(recorded ? 'recorded' : 'idle', toolCalls);
143
156
  return;
144
157
  }
158
+ if (reminded) {
159
+ report('duplicate', toolCalls);
160
+ return;
161
+ }
145
162
  const live = options.policy?.();
146
163
  const policy = {
147
164
  every: integerAtLeast(live?.every ?? options.every, 1, 1),
@@ -153,17 +170,17 @@ export function installAutoDistill(wire, options) {
153
170
  return;
154
171
  }
155
172
  try {
156
- agent.steer(createUserMessage({
157
- content: [{ type: 'text', text: distillPrompt(options.language?.()) }],
158
- source: { kind: AUTO_DISTILL_PLUGIN },
173
+ agent.followup(createUserMessage({
174
+ content: [{ type: 'text', text: distillPrompt(options.language?.(), turn) }],
175
+ source: { kind: AUTO_DISTILL_PLUGIN, originTurn: turn },
159
176
  }));
160
177
  }
161
178
  catch (error) {
162
179
  report('failed', toolCalls);
163
180
  throw error;
164
181
  }
165
- gate.recordSteer(agent.id, now);
166
- report('steered', toolCalls);
182
+ gate.recordReminder(agent.id, now);
183
+ report('queued', toolCalls);
167
184
  });
168
185
  const disposeAgent = wire.onDisposed?.((agentId) => { gate.forget(agentId); options.diagnostics?.setAgents(gate.size); });
169
186
  return () => { dispose(); disposeAgent?.(); gate.clear(); options.diagnostics?.setAgents(0); };