dsh-memoir 0.7.1 → 0.8.1
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 +16 -11
- package/README.md +16 -11
- package/cordis.patch.yml +2 -3
- package/lib/activity.d.ts +30 -0
- package/lib/activity.js +38 -0
- package/lib/autodistill.d.ts +25 -14
- package/lib/autodistill.js +23 -14
- package/lib/client.js +86 -46
- package/lib/client.js.map +3 -3
- package/lib/index.js +50 -3
- package/lib/tools.d.ts +12 -6
- package/lib/tools.js +26 -22
- package/package.json +25 -20
package/README.en.md
CHANGED
|
@@ -9,14 +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.1 requires DSH `>=0.1.7-rc.1 <0.1.8-0`**, with SDKs pinned to `0.1.7-rc.2`. It refines unskinned Desktop settings backgrounds, spacing and cards, adds actual-save diagnostics, and adopts public Session projections. Keep `dsh-memoir@0.7.1` on DSH 0.1.5.
|
|
16
|
+
>
|
|
15
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.
|
|
16
18
|
|
|
17
19
|
```bash
|
|
18
|
-
npm install --global @deepseek-ai/dsh@0.1.
|
|
19
|
-
dsh plugin --profile web add dsh-memoir@
|
|
20
|
+
npm install --global @deepseek-ai/dsh@0.1.7-rc.2
|
|
21
|
+
dsh plugin --profile web add dsh-memoir@0.8.1
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
Restart `dsh web`. Memory remains local and is not automatically deleted when the plugin is updated or removed.
|
|
@@ -86,9 +88,9 @@ Similar-memory governance starts with BM25 candidates, then combines title simil
|
|
|
86
88
|
|
|
87
89
|
## Automatic distillation
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
0.8.1 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.
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
0.8.1 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.
|
|
92
94
|
|
|
93
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.
|
|
94
96
|
|
|
@@ -150,20 +152,21 @@ Installing into a DSH-alpha `web` profile registers a native Memory Conversation
|
|
|
150
152
|
|
|
151
153
|
| Channel | DSH baseline | Installation | Status |
|
|
152
154
|
| --- | --- | --- | --- |
|
|
153
|
-
| npm `latest` (`0.
|
|
155
|
+
| npm `latest` (`0.8.1`) | `>=0.1.7-rc.1 <0.1.8-0` | `dsh plugin --profile web add dsh-memoir@0.8.1` | DSH 0.1.7 line |
|
|
156
|
+
| 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 |
|
|
154
157
|
| 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 |
|
|
155
158
|
| pinned npm `0.5.6` | `0.1.1-rc.2` | `dsh plugin --profile web add dsh-memoir@0.5.6` | rc2 compatibility line |
|
|
156
|
-
|
|
|
159
|
+
| Source `v0.8.1` | `>=0.1.7-rc.1 <0.1.8-0` | local build + `link:` | Development; not compatible with legacy 0.1.5 / 0.1.6 |
|
|
157
160
|
|
|
158
161
|
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.
|
|
159
162
|
|
|
160
163
|
<details>
|
|
161
164
|
<summary>Install from source</summary>
|
|
162
165
|
|
|
163
|
-
0.7.
|
|
166
|
+
Published 0.7.1 source (legacy DSH 0.1.5):
|
|
164
167
|
|
|
165
168
|
```bash
|
|
166
|
-
git clone https://github.com/Qinling-Melon-Farmers/dsh-memoir.git
|
|
169
|
+
git clone --branch v0.7.1 https://github.com/Qinling-Melon-Farmers/dsh-memoir.git
|
|
167
170
|
cd dsh-memoir
|
|
168
171
|
pnpm install --frozen-lockfile
|
|
169
172
|
pnpm run build
|
|
@@ -173,6 +176,8 @@ dsh plugin --profile web add "link:/absolute/path/dsh-memoir"
|
|
|
173
176
|
|
|
174
177
|
</details>
|
|
175
178
|
|
|
179
|
+
0.8.1 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.
|
|
180
|
+
|
|
176
181
|
## Storage, privacy, and security boundaries
|
|
177
182
|
|
|
178
183
|
```text
|
|
@@ -224,7 +229,7 @@ v0.5.6 benchmark (Node 24.19, 900/1200-token budget; full data in [`bench/report
|
|
|
224
229
|
|
|
225
230
|
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.
|
|
226
231
|
|
|
227
|
-
|
|
232
|
+
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.
|
|
228
233
|
|
|
229
234
|
## FAQ
|
|
230
235
|
|
|
@@ -253,6 +258,6 @@ pnpm test
|
|
|
253
258
|
npm run bench
|
|
254
259
|
```
|
|
255
260
|
|
|
256
|
-
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
|
|
261
|
+
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.1](https://github.com/Qinling-Melon-Farmers/dsh-memoir/releases/tag/v0.8.1), targeting DSH 0.1.7. Keep 0.7.1 on legacy DSH 0.1.5.
|
|
257
262
|
|
|
258
263
|
Apache-2.0
|
package/README.md
CHANGED
|
@@ -8,14 +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.1 要求 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
|
+
>
|
|
14
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`;这些旧版未包含本次修复。
|
|
15
17
|
|
|
16
18
|
```bash
|
|
17
|
-
npm install --global @deepseek-ai/dsh@0.1.
|
|
18
|
-
dsh plugin --profile web add dsh-memoir@
|
|
19
|
+
npm install --global @deepseek-ai/dsh@0.1.7-rc.2
|
|
20
|
+
dsh plugin --profile web add dsh-memoir@0.8.1
|
|
19
21
|
```
|
|
20
22
|
|
|
21
23
|
重启 `dsh web` 即可。记忆保存在本机,不会随插件升级或卸载自动删除。
|
|
@@ -85,9 +87,9 @@ memoir_record / memoir_update
|
|
|
85
87
|
|
|
86
88
|
## 自动蒸馏
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
0.8.1 诊断页区分提醒提交、实际保存、失败、取消、相似记忆待确认和回执降级。只有成功保存的 `memoir_record` / `memoir_update` 才抑制本回合提醒;失败或相似候选待确认不算写入。保存后宿主仍可能取消最终工具结果,因此计数可以重叠。提醒与后续保存的关联不证明因果或内容正确。GUI 手工写入不计入 Agent 工具计数。
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
0.8.1 使用公开 `sessionProjections` 从日志和 checkpoint 重建当前回合,不再读取弃用的 `snapshotEvents()`。每会话只保留当前回合最多 4096 个调用 ID,不保存参数或正文;超出保留范围时来源降级为 session-only。门控最多保留 1024 个 Agent,销毁时清理;旧版写入没有保存回执,不能仅从历史调用推断成功。BM25 是词项召回,不承诺跨语言语义匹配。
|
|
91
93
|
|
|
92
94
|
自动蒸馏是可观察的 Agent 收尾提醒,不是后台静默抓取聊天内容。默认 `1 / 0 / 1` 表示:每个有效 worked turn、无额外冷却、至少一次工具调用即可提醒。
|
|
93
95
|
|
|
@@ -149,20 +151,21 @@ v0.6.2 的诊断页显示最近触发或跳过原因及本次进程计数。已
|
|
|
149
151
|
|
|
150
152
|
| 渠道 | DSH 基线 | 安装方式 | 状态 |
|
|
151
153
|
| --- | --- | --- | --- |
|
|
152
|
-
| npm `latest`(`0.
|
|
154
|
+
| npm `latest`(`0.8.1`) | `>=0.1.7-rc.1 <0.1.8-0` | `dsh plugin --profile web add dsh-memoir@0.8.1` | 0.1.7 兼容线 |
|
|
155
|
+
| 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 维护线 |
|
|
153
156
|
| 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 兼容线 |
|
|
154
157
|
| npm 固定版 `0.5.6` | `0.1.1-rc.2` | `dsh plugin --profile web add dsh-memoir@0.5.6` | rc2 兼容线 |
|
|
155
|
-
|
|
|
158
|
+
| 源码 `v0.8.1` | `>=0.1.7-rc.1 <0.1.8-0` | 本地构建 + `link:` | 开发调试,不兼容旧 0.1.5 / 0.1.6 |
|
|
156
159
|
|
|
157
160
|
需要 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 本次不迁移或清空记忆,也不启用新动态提示词行为;既有会话快照语义保持不变。
|
|
158
161
|
|
|
159
162
|
<details>
|
|
160
163
|
<summary>从源码安装</summary>
|
|
161
164
|
|
|
162
|
-
0.7.
|
|
165
|
+
已发布 0.7.1 源码(旧 DSH 0.1.5):
|
|
163
166
|
|
|
164
167
|
```bash
|
|
165
|
-
git clone https://github.com/Qinling-Melon-Farmers/dsh-memoir.git
|
|
168
|
+
git clone --branch v0.7.1 https://github.com/Qinling-Melon-Farmers/dsh-memoir.git
|
|
166
169
|
cd dsh-memoir
|
|
167
170
|
pnpm install --frozen-lockfile
|
|
168
171
|
pnpm run build
|
|
@@ -172,6 +175,8 @@ dsh plugin --profile web add "link:/absolute/path/dsh-memoir"
|
|
|
172
175
|
|
|
173
176
|
</details>
|
|
174
177
|
|
|
178
|
+
0.8.1 使用原生 `uiWorkspace`、`conversation.view` / `settings.section` 与 Session V4 专属蒸馏来源。来源链接打开会话,回合编号可复制;不通过全局 DOM 自动滚到回合。设置页继承宿主背景、卡片使用主题层级色,保留皮肤覆盖与独立滚动。store v4 / settings v3 / snapshot v1 不变。升级 DSH 前备份 DSH_HOME,其会话迁移与插件记忆是两回事。
|
|
179
|
+
|
|
175
180
|
## 存储、隐私与安全边界
|
|
176
181
|
|
|
177
182
|
```text
|
|
@@ -223,7 +228,7 @@ v0.5.6 基准(Node 24.19,900/1200 token;完整数据见 [`bench/report.md`
|
|
|
223
228
|
|
|
224
229
|
基准值取决于机器和语料;它证明的重点是注入预算保持有界、缓存命中路径与记忆总量解耦。
|
|
225
230
|
|
|
226
|
-
|
|
231
|
+
自动化回归覆盖会话投影恢复、跨进程快照、写入与取消、生命周期清理、BM25 召回、Hot Memory 预算、缓存、纠错与跨项目隔离。固定词项样本的 Top-5 召回为 41/41;样本结果不代表真实模型的语义正确率,前缀一致性也不等同于实际账单节省保证。
|
|
227
232
|
|
|
228
233
|
## 常见问题
|
|
229
234
|
|
|
@@ -252,6 +257,6 @@ pnpm test
|
|
|
252
257
|
npm run bench
|
|
253
258
|
```
|
|
254
259
|
|
|
255
|
-
提交前请阅读 [CONTRIBUTING.md](./CONTRIBUTING.md)。版本变化见 [CHANGELOG.md](./CHANGELOG.md),正式包由 tag 工作流通过 npm OIDC
|
|
260
|
+
提交前请阅读 [CONTRIBUTING.md](./CONTRIBUTING.md)。版本变化见 [CHANGELOG.md](./CHANGELOG.md),正式包由 tag 工作流通过 npm OIDC 发布。当前版本是 [v0.8.1](https://github.com/Qinling-Melon-Farmers/dsh-memoir/releases/tag/v0.8.1),面向 DSH 0.1.7;旧 0.1.5 保留 0.7.1。
|
|
256
261
|
|
|
257
262
|
Apache-2.0
|
package/cordis.patch.yml
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
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.
|
|
4
|
-
# line >=0.1.
|
|
5
|
-
# dsh plugin --profile web add dsh-memoir@latest
|
|
3
|
+
# manifest field) over dsh-base. dsh-memoir v0.8.1 targets the DSH
|
|
4
|
+
# line >=0.1.7-rc.1 <0.1.8-0. Keep Memoir 0.7.1 on older DSH 0.1.5.
|
|
6
5
|
#
|
|
7
6
|
# The row is a bare plugin by package name: the node half (exports ".")
|
|
8
7
|
# registers the memoir_record / memoir_read tools, the /api/dsh-memoir panel
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}, z.core.$strip>;
|
|
13
|
+
export type MemoirActivity = z.infer<typeof schema>;
|
|
14
|
+
export declare const emptyActivity: () => MemoirActivity;
|
|
15
|
+
declare module '@deepseek-ai/dsh-session-projection/types' {
|
|
16
|
+
interface SessionProjectionStateMap {
|
|
17
|
+
'dsh-memoir/activity': MemoirActivity;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
declare module '@deepseek-ai/dsh-session/types' {
|
|
21
|
+
interface SessionEventMap {
|
|
22
|
+
/** Receipt after the Memoir store commit; no memory content is copied. */
|
|
23
|
+
'dsh-memoir/written': {
|
|
24
|
+
turn: number;
|
|
25
|
+
callId: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export declare const activityProjection: ProjectionDefinition<typeof ACTIVITY_KEY>;
|
|
30
|
+
export {};
|
package/lib/activity.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
});
|
|
12
|
+
export const emptyActivity = () => ({ turn: 0, toolCalls: 0, calls: [], recorded: false, reminded: false });
|
|
13
|
+
export const activityProjection = {
|
|
14
|
+
key: ACTIVITY_KEY,
|
|
15
|
+
stateVersion: 1,
|
|
16
|
+
stateSchema: schema,
|
|
17
|
+
init: emptyActivity,
|
|
18
|
+
apply(previous, event) {
|
|
19
|
+
if (event.type === 'turn/start' || event.type === 'tool/call' || event.type === 'dsh-memoir/written') {
|
|
20
|
+
const turn = event.data.turn;
|
|
21
|
+
if (turn < previous.turn)
|
|
22
|
+
return previous;
|
|
23
|
+
const state = turn > previous.turn ? { ...emptyActivity(), turn } : previous;
|
|
24
|
+
if (event.type === 'turn/start')
|
|
25
|
+
return state;
|
|
26
|
+
if (event.type === 'dsh-memoir/written')
|
|
27
|
+
return state.recorded ? state : { ...state, recorded: true };
|
|
28
|
+
if (state.calls.includes(event.data.callId))
|
|
29
|
+
return state;
|
|
30
|
+
return { ...state, toolCalls: state.toolCalls + 1, calls: [...state.calls, event.data.callId].slice(-CALL_LIMIT) };
|
|
31
|
+
}
|
|
32
|
+
if (event.type === 'agent/inbox/spliced' && event.data.target === 'next-step' &&
|
|
33
|
+
event.data.inserted.some(message => message.source.kind === 'dsh-memoir')) {
|
|
34
|
+
return previous.reminded ? previous : { ...previous, reminded: true };
|
|
35
|
+
}
|
|
36
|
+
return previous;
|
|
37
|
+
},
|
|
38
|
+
};
|
package/lib/autodistill.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
*
|
|
4
|
+
* persist memory is followed by one steering step asking the agent to distill
|
|
5
5
|
* the turn into memoir_record entries. Turns without tool activity are left
|
|
6
6
|
* alone (no extra model cost), subagent sessions are never steered, and each
|
|
7
7
|
* turn is steered at most once — the steering step runs inside the same turn,
|
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { UserMessage } from '@deepseek-ai/dsh-llm';
|
|
13
13
|
import type { MemoirLanguage } from './i18n.js';
|
|
14
|
+
import type { MemoirActivity } from './activity.js';
|
|
15
|
+
declare module '@deepseek-ai/dsh-llm/message' {
|
|
16
|
+
interface MessageSourceMap {
|
|
17
|
+
'dsh-memoir': {
|
|
18
|
+
kind: 'dsh-memoir';
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
/** The steering prompt injected at the end of an active turn. */
|
|
15
23
|
export declare function distillPrompt(language?: MemoirLanguage): string;
|
|
16
24
|
/** Backwards-compatible Chinese prompt constant. */
|
|
@@ -27,17 +35,7 @@ export interface TurnActivity {
|
|
|
27
35
|
recorded: boolean;
|
|
28
36
|
toolCalls: number;
|
|
29
37
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Session-log compatibility surface. DSH <= alpha.3 exposed `events` while
|
|
32
|
-
* alpha.4+ keeps the log private and exposes an immutable snapshot method.
|
|
33
|
-
*/
|
|
34
|
-
export interface SessionEventSource {
|
|
35
|
-
readonly events?: readonly TurnEventLike[];
|
|
36
|
-
snapshotEvents?: () => readonly TurnEventLike[];
|
|
37
|
-
}
|
|
38
|
-
/** Read a stable session event snapshot across the old and new DSH APIs. */
|
|
39
|
-
export declare function sessionEventSnapshot(session: SessionEventSource | undefined): readonly TurnEventLike[];
|
|
40
|
-
/** Scan the tail of a session log for one turn's tool activity. */
|
|
38
|
+
/** Pure event-fixture fold. Runtime activity comes from the host projection. */
|
|
41
39
|
export declare function turnActivity(events: readonly TurnEventLike[], turn: number): TurnActivity;
|
|
42
40
|
/** The agent surface the turn-stopping listener needs. */
|
|
43
41
|
export interface AutoDistillAgentLike {
|
|
@@ -76,16 +74,19 @@ export declare class AutoDistillGate {
|
|
|
76
74
|
/** Drop all state for one agent (disposal hygiene). */
|
|
77
75
|
forget(agentId: string): void;
|
|
78
76
|
}
|
|
79
|
-
export type DistillOutcome = 'disabled' | 'subagent' | 'aborted' | 'idle' | 'recorded' | 'duplicate' | 'interval' | 'tools' | 'cooldown' | 'steered' | 'failed';
|
|
77
|
+
export type DistillOutcome = 'disabled' | 'subagent' | 'aborted' | 'idle' | 'recorded' | 'duplicate' | 'interval' | 'tools' | 'cooldown' | 'steered' | 'failed' | 'unavailable';
|
|
80
78
|
/** Process-local counters only; never retains message content or credentials. */
|
|
81
79
|
export declare class DistillDiagnostics {
|
|
82
80
|
private counts;
|
|
83
81
|
private last;
|
|
84
82
|
private workedTurns;
|
|
85
83
|
private agents;
|
|
84
|
+
private writes;
|
|
85
|
+
write(outcome: keyof DistillDiagnostics['writes']): void;
|
|
86
86
|
record(outcome: DistillOutcome, at: number, turn: number, toolCalls: number, agents: number): void;
|
|
87
87
|
snapshot(): {
|
|
88
88
|
counts: {
|
|
89
|
+
recorded?: number | undefined;
|
|
89
90
|
subagent?: number | undefined;
|
|
90
91
|
duplicate?: number | undefined;
|
|
91
92
|
interval?: number | undefined;
|
|
@@ -94,9 +95,17 @@ export declare class DistillDiagnostics {
|
|
|
94
95
|
disabled?: number | undefined;
|
|
95
96
|
aborted?: number | undefined;
|
|
96
97
|
idle?: number | undefined;
|
|
97
|
-
recorded?: number | undefined;
|
|
98
98
|
steered?: number | undefined;
|
|
99
99
|
failed?: number | undefined;
|
|
100
|
+
unavailable?: number | undefined;
|
|
101
|
+
};
|
|
102
|
+
writes: {
|
|
103
|
+
persisted: number;
|
|
104
|
+
afterReminder: number;
|
|
105
|
+
failed: number;
|
|
106
|
+
canceled: number;
|
|
107
|
+
needsResolution: number;
|
|
108
|
+
receiptFailed: number;
|
|
100
109
|
};
|
|
101
110
|
workedTurns: number;
|
|
102
111
|
agents: number;
|
|
@@ -139,4 +148,6 @@ export declare function installAutoDistill(wire: AutoDistillWire, options: {
|
|
|
139
148
|
language?: () => MemoirLanguage;
|
|
140
149
|
now?: () => number;
|
|
141
150
|
diagnostics?: DistillDiagnostics;
|
|
151
|
+
/** Public host projection at the exact Session cursor; absent means skip safely. */
|
|
152
|
+
activity?: (agent: AutoDistillAgentLike) => MemoirActivity | undefined;
|
|
142
153
|
}): () => void;
|
package/lib/autodistill.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
*
|
|
4
|
+
* persist memory is followed by one steering step asking the agent to distill
|
|
5
5
|
* the turn into memoir_record entries. Turns without tool activity are left
|
|
6
6
|
* alone (no extra model cost), subagent sessions are never steered, and each
|
|
7
7
|
* turn is steered at most once — the steering step runs inside the same turn,
|
|
@@ -19,13 +19,7 @@ export function distillPrompt(language = DEFAULT_MEMOIR_LANGUAGE) {
|
|
|
19
19
|
export const DISTILL_PROMPT = distillPrompt();
|
|
20
20
|
/** Plugin identity stamped on the steering message source. */
|
|
21
21
|
export const AUTO_DISTILL_PLUGIN = 'dsh-memoir';
|
|
22
|
-
/**
|
|
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. */
|
|
22
|
+
/** Pure event-fixture fold. Runtime activity comes from the host projection. */
|
|
29
23
|
export function turnActivity(events, turn) {
|
|
30
24
|
let recorded = false;
|
|
31
25
|
let toolCalls = 0;
|
|
@@ -40,9 +34,9 @@ export function turnActivity(events, turn) {
|
|
|
40
34
|
continue;
|
|
41
35
|
if (event.type === 'tool/call') {
|
|
42
36
|
toolCalls += 1;
|
|
43
|
-
if (data.name === 'memoir_record' || data.name === 'memoir_update')
|
|
44
|
-
recorded = true;
|
|
45
37
|
}
|
|
38
|
+
if (event.type === 'dsh-memoir/written')
|
|
39
|
+
recorded = true;
|
|
46
40
|
}
|
|
47
41
|
return { worked: toolCalls > 0, recorded, toolCalls };
|
|
48
42
|
}
|
|
@@ -102,6 +96,8 @@ export class DistillDiagnostics {
|
|
|
102
96
|
last = null;
|
|
103
97
|
workedTurns = 0;
|
|
104
98
|
agents = 0;
|
|
99
|
+
writes = { persisted: 0, afterReminder: 0, failed: 0, canceled: 0, needsResolution: 0, receiptFailed: 0 };
|
|
100
|
+
write(outcome) { this.writes[outcome] += 1; }
|
|
105
101
|
record(outcome, at, turn, toolCalls, agents) {
|
|
106
102
|
this.counts[outcome] = (this.counts[outcome] ?? 0) + 1;
|
|
107
103
|
if (['interval', 'tools', 'cooldown', 'steered', 'failed'].includes(outcome))
|
|
@@ -109,7 +105,7 @@ export class DistillDiagnostics {
|
|
|
109
105
|
this.last = { outcome, at, turn, toolCalls };
|
|
110
106
|
this.agents = agents;
|
|
111
107
|
}
|
|
112
|
-
snapshot() { return { counts: { ...this.counts }, workedTurns: this.workedTurns, agents: this.agents, last: this.last === null ? null : { ...this.last } }; }
|
|
108
|
+
snapshot() { return { counts: { ...this.counts }, writes: { ...this.writes }, workedTurns: this.workedTurns, agents: this.agents, last: this.last === null ? null : { ...this.last } }; }
|
|
113
109
|
setAgents(agents) { this.agents = agents; }
|
|
114
110
|
}
|
|
115
111
|
/**
|
|
@@ -137,11 +133,24 @@ export function installAutoDistill(wire, options) {
|
|
|
137
133
|
report('aborted');
|
|
138
134
|
return;
|
|
139
135
|
}
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
136
|
+
const activity = options.activity?.(agent);
|
|
137
|
+
if (activity === undefined) {
|
|
138
|
+
report('unavailable');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (activity.turn > turn) {
|
|
142
|
+
report('duplicate');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const { recorded, toolCalls, reminded } = activity.turn === turn ? activity : { recorded: false, toolCalls: 0, reminded: false };
|
|
146
|
+
if (toolCalls === 0 || recorded) {
|
|
142
147
|
report(recorded ? 'recorded' : 'idle', toolCalls);
|
|
143
148
|
return;
|
|
144
149
|
}
|
|
150
|
+
if (reminded) {
|
|
151
|
+
report('duplicate', toolCalls);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
145
154
|
const live = options.policy?.();
|
|
146
155
|
const policy = {
|
|
147
156
|
every: integerAtLeast(live?.every ?? options.every, 1, 1),
|
|
@@ -155,7 +164,7 @@ export function installAutoDistill(wire, options) {
|
|
|
155
164
|
try {
|
|
156
165
|
agent.steer(createUserMessage({
|
|
157
166
|
content: [{ type: 'text', text: distillPrompt(options.language?.()) }],
|
|
158
|
-
source: { kind:
|
|
167
|
+
source: { kind: AUTO_DISTILL_PLUGIN },
|
|
159
168
|
}));
|
|
160
169
|
}
|
|
161
170
|
catch (error) {
|