dsh-context-manager 1.6.0 → 1.7.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/CHANGELOG.md +24 -0
- package/README.md +151 -10
- package/client.js +231 -10
- package/core.js +273 -13
- package/docs/DETAIL.md +17 -0
- package/docs/DETAIL.zh.md +17 -0
- package/index.js +523 -43
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.7.1
|
|
4
|
+
|
|
5
|
+
- 修复:操作台账(`/ctxmgr batches`)在个别时刻读成空台账。根因是把日志事件序号当成「已消费事件数」传给 `snapshotEvents(n)`,窗口可能落到日志末尾之外;台账现在每次全量扫描会话日志(只由用户命令触发,成本可忽略)。
|
|
6
|
+
- 修复:持久队列(删除/恢复的排队重放)使用同一错误游标,改为按「已消费事件数」推进——与 agent-loop 的 `storedCount` 写法一致,不再有跳过记录的窗口。
|
|
7
|
+
- 修复:`/ctxmgr undo-batch` 可能重复选中「已经撤销过」的批次(撤销是排队到下个请求才落地,连调工具时墓碑仍在表面上)。现在同时看台账信号:某批次已被一条 `op=undo` 记录点名即视为已撤销,再撤销会明确报「还没有可撤销的批次记录」。
|
|
8
|
+
## 1.7.0
|
|
9
|
+
|
|
10
|
+
- Token metering: `core.js` gains `estimateMessageTokens`, a heuristic priced like DSH's own `dsh-token-meter` (4 characters ≈ 1 token, +4 per content block, +4 role overhead per message). The message list shows `≈N tok` per message and the current total context occupation; delete, whole-turn delete and clean results report the estimated tokens released. These are estimates only — Chinese text and JSON are markedly underestimated.
|
|
11
|
+
- Budget clean-up: new `/ctxmgr clean <target tokens>` command and `context_manager` action `clean` (optional `targetTokens`, `minCandidateTokens`, `protectRecent`). Candidates are only `tool` / `assistant` messages, sorted by estimated tokens descending; user and context messages are never eligible, the most recent 3 messages are protected by default, candidates below 100 tokens are skipped by default, and the clean stops once the budget is met. Deletion reuses the existing delete pipeline (`planDeletion` + tombstones + durable queue), not a second deletion path.
|
|
12
|
+
- The header dialog gains a budget row at the top: a target-token field plus a clean button.
|
|
13
|
+
- The Host prefers node pricing from `ctx.tokenMeter.measure()` and falls back to the local heuristic when no token meter is injected.
|
|
14
|
+
- Batch ids: every delete, whole-turn delete and budget clean now mints a `batchId`, recorded in the tombstone `source` as `{ kind: 'context-manager', batchId: '<uuid>' }`. `kind` stays the only marker, so tombstones written before batch ids keep working unchanged.
|
|
15
|
+
- Audit ledger: every operation appends one `plugin:context-manager/batch` record to the session log — `batchId`, `op` (`delete` / `delete-turn` / `clean` / `undo`), target `seqs`, written `tombstoneSeqs`, `estimatedFreedTokens`, outcome (`applied` / `queued` / `skipped` / `failed`) and `reason`. The ledger is append-only, persists with the session log, survives restarts and writes no external files.
|
|
16
|
+
- `/ctxmgr batches` (aliases `ledger` / `audit`) lists the ledger, and the `context_manager` tool gains `action=batches`.
|
|
17
|
+
- `/ctxmgr undo-batch` undoes the latest batch, `/ctxmgr undo-batch <batchId prefix>` a specific one (alias `undo-last`); the tool exposes `action=undo-batch` with an optional `batchId`. Undo reuses the existing restore path (durable queue + idempotent ack) instead of a second restore mechanism, and leaves its own `op=undo` ledger entry.
|
|
18
|
+
- Header dialog: each deleted-record row shows the first 8 characters of its batch id, and a "undo last operation" button at the bottom undoes the most recent batch.
|
|
19
|
+
- README: added a 与同类插件的边界 (boundaries against similar plugins) section covering `dsh-context`, `dsh-compact-manager` / `dsh-compression-improved`, `dsh-context-redline`, the same-named `@sulytwelve/dsh-context-manager` and memory plugins, plus the audit ledger section and the new commands and tool actions.
|
|
20
|
+
- Recall pointers: every tombstone `source` is now `{ kind: 'context-manager', batchId, recall }`, where `recall` holds at most 8 `{ seq, role, preview }` entries (`RECALL_MAX_ENTRIES = 8`) with previews truncated to 80 characters (`RECALL_PREVIEW_LIMIT = 80`). It stores the original seq, the role and a one-line preview — never the full message text — and the tombstone `content` stays an empty array, because a tombstone must project as an empty message. Older tombstones without `batchId` / `recall` keep working unchanged. The dialog's deleted rows fall back to 可召回 #seq · 摘要 when the original text is no longer on the surface.
|
|
21
|
+
- Retrieving deleted originals: the recalled `seq` is the session seq of the original event, so the read-only tools of `@deepseek-ai/dsh-tool-session-query` (`session_search`, `session_event_search`, `session_trace`, `session_event_trace`, `session_event_read`) can locate it — search it by keyword with `session_event_search`, or read the complete unredacted event as JSON with `session_event_read`. Searches exclude the caller's own session and are authorized by the workspace `cwd`. Deleting is therefore redefined as unloading the range from the main context into a searchable archive: the main context no longer carries it, while the raw event stays in the append-only session log and can be fetched back by seq or keyword.
|
|
22
|
+
- Local compaction: new `/ctxmgr compact <start> <end>` command and `context_manager` action `compact` (parameters `start` / `end`). It calls the official `ctx.compaction.compactRegion(start, end, agentCtx, signal)`; `start` / `end` are surface position seqs (not numeric order) and both edges must be tool-pair balanced, otherwise the engine reports an unbalanced region. This is the only place the plugin leans on official compaction, and it is strictly limited to the user selection — no global threshold compaction (that is `dsh-compact-manager` / the compaction backend). A loaded compaction backend (e.g. `dsh-compaction-basic`) is required: without one the plugin shows a clear Chinese hint and records the failure in the ledger, and the plugin does not hard-depend on the service (it gets `compaction` optionally via `ctx.get('compaction')`). Success and failure both append one `op: 'compact'` ledger entry with the shadowed node count and tokens. Unlike delete / clean, which unload restorably with no summary, compact replaces the range with one official summary.
|
|
23
|
+
- Header dialog: a new filter dropdown (全部 / 用户 / 助手 / 工具 / 上下文) that only affects display — selection, token totals and the Host planner are untouched — with a 显示 X/Y counter; user message rows carry a 受保护 (protected) marker, matching that clean never selects user messages.
|
|
24
|
+
- Tests: three zero-dependency `node:test` files under `test/` with 49 cases in total (`core.test.mjs` 9, `batch.test.mjs` 14, `surface.test.mjs` 26), covering `planDeletion` tool-group linkage, `deletedFromSurface`, `foldSurface`, `turnsFromSurface`, `planClean` protection and ordering, `undo-batch` selection (including ambiguous-prefix rejection), and recall pointers with tombstone projection.
|
|
25
|
+
- Boundary fixes: a tombstone can no longer be deleted as if it were a message (the plugin answers 该序号是一条删除记录(墓碑)…请用 restore), and `foldSurface` ignores malformed surface objects that lack a `seq`.
|
|
26
|
+
|
|
3
27
|
## 1.6.0
|
|
4
28
|
|
|
5
29
|
- Renamed the package and bundle from `dsh-message-manager` to `dsh-context-manager` (1.5.0 → 1.6.0): a new npm package plus a renamed GitHub repository. The old package is deprecated on npm in favour of the new one, and the old repository URL redirects to the new one.
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
一个 DSH(DeepSeek Harness)插件:在会话标题栏增加「上下文管理」入口,管理会话的**模型上下文**——按条删、按整轮删,之后还能恢复。原始会话日志、聊天记录与审计数据始终保留。
|
|
4
4
|
|
|
5
5
|
- 包名:`dsh-context-manager`
|
|
6
|
-
- 版本:`1.
|
|
6
|
+
- 版本:`1.7.1`
|
|
7
7
|
- 类型:Cordis bundle(Host 半 + Web Client 半),纯 JavaScript,**无构建、无第三方依赖**
|
|
8
8
|
- 适用:DSH `0.2.1-rc.2` 及以上(`0.2.2-rc.5` 实测)
|
|
9
9
|
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
|
|
16
16
|
| 来源 | target 写法 | 说明 |
|
|
17
17
|
|---|---|---|
|
|
18
|
-
| npm | `dsh-context-manager@1.
|
|
18
|
+
| npm | `dsh-context-manager@1.7.1` | 已发布到 [npm](https://www.npmjs.com/package/dsh-context-manager) |
|
|
19
19
|
| GitHub | `github:xian-yu-zhao/dsh-context-manager` | 免 npm,直接从仓库取 |
|
|
20
|
-
| 本地 tgz | `file:C:\path\to\dsh-context-manager-1.
|
|
20
|
+
| 本地 tgz | `file:C:\path\to\dsh-context-manager-1.7.1.tgz` | Release 资产或 `npm pack` 产物 |
|
|
21
21
|
| 本地目录 | `link:C:\path\to\dsh-context-manager` | 开发调试用,改源码即生效 |
|
|
22
22
|
|
|
23
23
|
安装后刷新 Web 页面(F5)或重启应用,会话标题栏右侧会出现列表图标。
|
|
24
24
|
|
|
25
|
-
> **旧包已弃用**:`dsh-message-manager`(1.5.0)已在 npm 上标记 deprecated 并指向本包,GitHub 旧仓库 `xian-yu-zhao/dsh-message-manager` 自动重定向到 [`xian-yu-zhao/dsh-context-manager`](https://github.com/xian-yu-zhao/dsh-context-manager)。迁移只需两步:`plugin_manager remove_bundle target=dsh-message-manager`,再 `plugin_manager install_bundle target=dsh-context-manager@1.
|
|
25
|
+
> **旧包已弃用**:`dsh-message-manager`(1.5.0)已在 npm 上标记 deprecated 并指向本包,GitHub 旧仓库 `xian-yu-zhao/dsh-message-manager` 自动重定向到 [`xian-yu-zhao/dsh-context-manager`](https://github.com/xian-yu-zhao/dsh-context-manager)。迁移只需两步:`plugin_manager remove_bundle target=dsh-message-manager`,再 `plugin_manager install_bundle target=dsh-context-manager@1.7.1`——新版本仍能识别旧版写入会话日志的删除记录与排队记录。
|
|
26
26
|
|
|
27
27
|
> 无 npm CLI 也能装:GitHub / tgz / 本地目录三种来源都不经过 npm 发布。
|
|
28
28
|
>
|
|
@@ -56,6 +56,12 @@
|
|
|
56
56
|
|
|
57
57
|
`/ctxmgr turns` → `/ctxmgr deleteturn 2,3,4`
|
|
58
58
|
|
|
59
|
+
### 按预算快速瘦身
|
|
60
|
+
|
|
61
|
+
不想逐条挑,就直接给一个 token 预算:`/ctxmgr clean 60000` 会按估算占用从大到小清掉工具输出与助手消息,直到降到目标附近。用户消息与上下文消息永不入选,默认保护最近 3 条,小于 100 tokens 的候选默认跳过;删除复用按条删除的同一套墓碑与持久队列,因此仍可恢复。
|
|
62
|
+
|
|
63
|
+
`/ctxmgr clean 60000`(工具等价:`context_manager` + `clean`,可带 `targetTokens` / `minCandidateTokens` / `protectRecent`)
|
|
64
|
+
|
|
59
65
|
### 误发内容的止损(如实说明边界)
|
|
60
66
|
|
|
61
67
|
把密钥、隐私片段或发错的内容从**模型上下文**里移除,后续请求不再看到它们。但必须清楚:**原始会话日志与聊天记录仍在本地会话文件里**,这个插件不是擦除工具,真要抹掉请自行处理会话文件。
|
|
@@ -64,6 +70,25 @@
|
|
|
64
70
|
|
|
65
71
|
---
|
|
66
72
|
|
|
73
|
+
## 与同类插件的边界
|
|
74
|
+
|
|
75
|
+
上下文赛道很挤,同名或近名的插件尤其多。先划清边界,避免装错东西,也避免预期错位:
|
|
76
|
+
|
|
77
|
+
| 插件 / 类别 | 它做什么 | 我们的关系 |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `dsh-context`(周下载很高、官方推荐) | 仪表板、成本图表、上下文占用可视化 | 不做仪表板与成本图表;我们只做就地裁剪 |
|
|
80
|
+
| `dsh-compact-manager` / `dsh-compression-improved` | 全局阈值压缩、工具结果压缩引擎 | 不做全局压缩引擎;我们只在用户选区上删除或局部压缩 |
|
|
81
|
+
| `dsh-context-redline` | 迁移到零历史的新会话 + 交接摘要 | 不做交接与迁移;我们不改消息内容,只把选中的内容从主上下文卸载到可检索存档(按 seq 可取回)或恢复 |
|
|
82
|
+
| `@sulytwelve/dsh-context-manager`(同名)与各类 `dsh-memory` | 跨会话记忆 | 不做跨会话记忆 |
|
|
83
|
+
|
|
84
|
+
与它们最本质的区别是**可逆性 + 原日志只增不改 + 按 seq 审计**:我们不重写任何消息内容,只追加空 developer 消息做表面替换;每一次删除、整轮删除与撤销都留在会话日志的台账里,可按批次追溯与撤回。
|
|
85
|
+
|
|
86
|
+
同名插件不是我们,认包名 `dsh-context-manager`(GitHub [`xian-yu-zhao/dsh-context-manager`](https://github.com/xian-yu-zhao/dsh-context-manager))。
|
|
87
|
+
|
|
88
|
+
> **手术刀,不是压缩机,也不是记忆库。**
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
67
92
|
## 插件市场收录
|
|
68
93
|
|
|
69
94
|
DSH 的插件市场(**Plugins → Discover**)**没有官方索引**:它只读用户自己添加的索引 URL,索引是一份 format 1 的 JSON。社区事实标准索引是 [awesome-dsh-plugin](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin),站点索引地址 `https://awesome-dsh-plugin.com/index.json`。
|
|
@@ -117,12 +142,13 @@ description:
|
|
|
117
142
|
### 弹窗
|
|
118
143
|
|
|
119
144
|
1. 打开任意会话,点标题栏右侧的列表图标,打开「上下文管理」。
|
|
120
|
-
2.
|
|
121
|
-
3.
|
|
122
|
-
4.
|
|
123
|
-
5.
|
|
145
|
+
2. **预算 + 按 token 清理**(弹窗顶部一行):填入目标 tokens 点清理,不用手挑也会优先清掉最占地方的工具与助手消息;规则见下。当前消息每行显示 `≈N tok`,列表标题显示当前上下文总占用——都是启发式估算,不是精确用量。
|
|
146
|
+
3. **对话轮(整轮删除)**:一行一轮,显示轮号、预览与消息条数;勾选后点「删除选中」,或点行尾「删除本轮」。这一轮里的用户提问、助手的工作与回答、该轮注入的上下文会一起移出,不必逐条删工具调用。
|
|
147
|
+
4. **当前消息**(默认折叠,点标题或 ▸ 展开):按条勾选,点「删除选中」;也可点行尾垃圾桶单独删。折叠状态下全选与批量删除按钮仍可用。**过滤**下拉可切到 全部 / 用户 / 助手 / 工具 / 上下文:只影响显示,选择、token 总计与 Host 计划器都不受影响,过滤时显示「显示 X/Y」。用户消息行带「受保护」标记——`clean` 永不选择用户消息。
|
|
148
|
+
5. **已删除**:保留本插件产生的删除记录(`删除记录 #seq`),每行还显示所属批次号前 8 位;可勾选后「恢复选中」,或逐条「恢复」。原文已不在当前表面时,行内改用召回指针显示「可召回 #seq · 摘要」,可凭该 seq 用 `session_event_read` 取回完整原始事件。弹窗底部另有「撤销上次操作」按钮,一次撤销最近一个批次。
|
|
149
|
+
6. 删除只影响**后续模型请求**;恢复后重新进入后续请求。
|
|
124
150
|
|
|
125
|
-
确认条会提示连带移除的总条数(`共移除 N
|
|
151
|
+
确认条会提示连带移除的总条数(`共移除 N 条消息`)与估算释放的 tokens(`估算释放约 X tokens`),因为删助手消息会带走它发起的工具结果,删工具结果会带走所属助手消息与同组结果。
|
|
126
152
|
|
|
127
153
|
### 命令
|
|
128
154
|
|
|
@@ -132,11 +158,108 @@ description:
|
|
|
132
158
|
/ctxmgr delete <序号,...> # 按条删除
|
|
133
159
|
/ctxmgr deleteturn <轮号,...> # 按轮删除
|
|
134
160
|
/ctxmgr restore <删除记录序号,...> # 恢复
|
|
161
|
+
/ctxmgr clean <目标tokens> # 按预算清理:只看 tool / assistant,默认保护最近 3 条、候选 ≥100 tokens
|
|
162
|
+
/ctxmgr compact <起序号> <止序号> # 局部压缩:把用户选区交给官方 ctx.compaction.compactRegion
|
|
163
|
+
/ctxmgr batches # 操作台账(审计):列出批次号、操作、目标序号与结果
|
|
164
|
+
/ctxmgr undo-batch [batchId] # 撤销最近一次操作;带 batchId 前几位时撤销指定批次(别名 undo-last)
|
|
135
165
|
```
|
|
136
166
|
|
|
137
167
|
### 工具
|
|
138
168
|
|
|
139
|
-
模型可调用 `context_manager`,参数 `action` ∈ `list` / `list-turns` / `delete` / `delete-turns` / `restore`,`seqs` 按 action
|
|
169
|
+
模型可调用 `context_manager`,参数 `action` ∈ `list` / `list-turns` / `delete` / `delete-turns` / `restore` / `clean` / `compact` / `batches` / `undo-batch`,`seqs` 按 action 解释为消息序号、轮号或删除记录序号(`clean` 与 `compact` 不用 `seqs`;`compact` 改用 `start` / `end`,二者都是表面位置序号)。工具描述里明确要求「仅在用户明确要求时使用」。
|
|
170
|
+
|
|
171
|
+
`clean` 按 token 预算清理,可选参数:
|
|
172
|
+
|
|
173
|
+
| 参数 | 默认值 | 含义 |
|
|
174
|
+
|---|---|---|
|
|
175
|
+
| `targetTokens` | — | 目标估算 tokens,按此预算判断何时停止 |
|
|
176
|
+
| `minCandidateTokens` | `100` | 只考虑估算 ≥ 该值的候选 |
|
|
177
|
+
| `protectRecent` | `3` | 最近 N 条消息不参与清理 |
|
|
178
|
+
|
|
179
|
+
候选只取 `tool` / `assistant` 消息,按估算 token 降序排列;用户消息与上下文消息永不入选;达到预算即停止。删除完全复用既有 `delete` 管线(`planDeletion` + 墓碑 + 持久队列),不是另一套删除逻辑,所以恢复语义与按条删除完全一致。
|
|
180
|
+
|
|
181
|
+
`action=batches` 列出操作台账;`action=undo-batch` 撤销最近一次操作,可选参数 `batchId`(前缀匹配)撤销指定批次。撤销复用既有 restore 路径(持久队列 + ack 幂等),并在台账里追加一条 `op=undo` 记录。
|
|
182
|
+
|
|
183
|
+
`action=compact` 需要 `start` 与 `end` 两个参数:它们是**表面位置序号**,两端必须落在工具配对平衡的边界上;插件把这一段交给官方 `ctx.compaction.compactRegion` 换成一条摘要。调用契约、前提与和 delete / clean 的区别见下文「局部压缩」。
|
|
184
|
+
|
|
185
|
+
### 审计台账
|
|
186
|
+
|
|
187
|
+
每次删除、整轮删除、按预算清理、局部压缩与撤销都会在会话日志里追加一条 `plugin:context-manager/batch` 审计记录,只增不改,随会话日志持久化——重启后仍可查,不写任何外部文件。
|
|
188
|
+
|
|
189
|
+
| 字段 | 含义 |
|
|
190
|
+
|---|---|
|
|
191
|
+
| `batchId` | 批次号;每次操作生成一个,撤销记录同样带 `batchId` |
|
|
192
|
+
| `op` | 操作类型:`delete` / `delete-turn` / `clean` / `compact` / `undo` |
|
|
193
|
+
| `seqs` | 本次操作的目标序号(消息序号或轮号) |
|
|
194
|
+
| `tombstoneSeqs` | 实际写入的墓碑序号 |
|
|
195
|
+
| `estimatedFreedTokens` | 估算释放的 tokens(启发式,非精确值) |
|
|
196
|
+
| `result` | `applied` 成功 / `queued` 排队中 / `skipped` 跳过 / `failed` 失败 |
|
|
197
|
+
| `reason` | 结果的原因说明 |
|
|
198
|
+
|
|
199
|
+
批次号同时写进墓碑消息的 `source`:`source = { kind: 'context-manager', batchId: '<uuid>', recall: [...] }`。`kind` 仍是唯一标记,`batchId` 与 `recall` 只是附加信息——旧墓碑没有这两个字段也照常工作(`recall` 见下节「召回」)。
|
|
200
|
+
|
|
201
|
+
查看与撤销:
|
|
202
|
+
|
|
203
|
+
- `/ctxmgr batches`(别名 `ledger` / `audit`;工具 `context_manager` + `action=batches`):列出台账。
|
|
204
|
+
- `/ctxmgr undo-batch`:撤销最近一次操作(别名 `undo-last`)。
|
|
205
|
+
- `/ctxmgr undo-batch <batchId 前几位>`:撤销指定批次;工具等价 `action=undo-batch` + 可选 `batchId`。
|
|
206
|
+
|
|
207
|
+
撤销**复用既有的 restore 路径**(持久队列 + ack 幂等),不是另起一套恢复机制;撤销本身也会在台账里留一条 `op=undo` 记录。
|
|
208
|
+
|
|
209
|
+
### 局部压缩(与官方 compaction 分工)
|
|
210
|
+
|
|
211
|
+
`/ctxmgr compact <起序号> <止序号>`(工具等价:`context_manager` + `action=compact`,参数 `start` / `end`)把用户选中的一段交给官方压缩引擎,换回一条官方摘要。
|
|
212
|
+
|
|
213
|
+
**调用契约**:插件内部调用 `ctx.compaction.compactRegion(start, end, agentCtx, signal)`——这是本插件唯一借力官方压缩的地方,摘要逻辑本身不自己实现。
|
|
214
|
+
|
|
215
|
+
- `start` / `end` 是**表面位置序号**,不是数值大小顺序;两端必须落在工具配对平衡的边界上(不能切在「助手工具调用」与「工具结果」之间),否则引擎报 unbalanced,操作失败并写进台账。
|
|
216
|
+
- **需要压缩后端**:环境里必须加载了压缩后端(如 `dsh-compaction-basic`)。没加载时插件给明确的中文提示,并把失败记进台账;插件自身不硬依赖该服务,用 `ctx.get('compaction')` 可选获取。
|
|
217
|
+
- **只作用于用户选区**:不做全局阈值压缩——那是 `dsh-compact-manager` 与压缩后端的事。你指哪一段,它压哪一段。
|
|
218
|
+
- 成功与失败都会在台账留一条 `op: 'compact'` 记录(含被遮蔽的节点数与 tokens)。
|
|
219
|
+
|
|
220
|
+
与 delete / clean 的区别:
|
|
221
|
+
|
|
222
|
+
| 操作 | 结果 | 能否按消息恢复 |
|
|
223
|
+
|---|---|---|
|
|
224
|
+
| `delete` / `delete-turn` / `clean` | 目标从主上下文移出(墓碑投影成空消息) | 能,走 `restore` / `undo-batch` |
|
|
225
|
+
| `compact` | 选区换成一条官方摘要 | 不能按消息恢复;原始事件仍留在只增不改的会话日志里 |
|
|
226
|
+
|
|
227
|
+
一句话:delete / clean 是「卸载」,compact 是「摘要掉」,两者都不删除原始日志。
|
|
228
|
+
|
|
229
|
+
### 召回:删掉的还能取回
|
|
230
|
+
|
|
231
|
+
每条墓碑的 `source` 里现在带一个极短的**召回指针**:
|
|
232
|
+
|
|
233
|
+
```js
|
|
234
|
+
source = {
|
|
235
|
+
kind: 'context-manager',
|
|
236
|
+
batchId: '<uuid>',
|
|
237
|
+
recall: [{ seq: 42, role: 'assistant', preview: '……一行摘要……' }],
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
- 最多 `RECALL_MAX_ENTRIES = 8` 条,`preview` 截断到 `RECALL_PREVIEW_LIMIT = 80` 字符。
|
|
242
|
+
- 只存原始 `seq`、角色与一行摘要,**不写消息全文**;墓碑的 `content` 仍是空数组——墓碑必须投影成空消息,这是硬约束。
|
|
243
|
+
- 与 `batchId` 并存;老墓碑没有这两个字段也照常工作。
|
|
244
|
+
- 弹窗「已删除」行在拿不到原文时,用召回指针显示「可召回 #seq · 摘要」。
|
|
245
|
+
|
|
246
|
+
**怎么取回原文**:`recall` 里的 `seq` 就是原始事件的会话序号。启用 `@deepseek-ai/dsh-tool-session-query` 那套只读工具后:
|
|
247
|
+
|
|
248
|
+
| 工具 | 用途 |
|
|
249
|
+
|---|---|
|
|
250
|
+
| `session_event_search` | 在该会话内按关键字检索事件,定位被删的那一段 |
|
|
251
|
+
| `session_event_read` | 按事件定位读取完整未删节事件(JSON) |
|
|
252
|
+
| `session_search` / `session_event_trace` / `session_trace` | 找到会话、看事件轨迹与调用链 |
|
|
253
|
+
|
|
254
|
+
搜索会排除调用方自己的会话、按工作区 `cwd` 授权。于是「删除」的准确定位是:**从主上下文卸载到可检索存档**——主上下文不再携带它(不再花 token,模型也看不见),但原始事件仍在 append-only 会话日志里,可按 seq / 关键字取回。
|
|
255
|
+
|
|
256
|
+
与隔壁的区分:`dsh-context-redline` 把内容「迁移走」到新会话,压缩插件把内容「摘要掉」,我们只是把选中的内容「卸载」出主上下文,原会话与原文都还在原地。
|
|
257
|
+
|
|
258
|
+
### token 估算(启发式)
|
|
259
|
+
|
|
260
|
+
消息列表里的 `≈N tok`、标题处的上下文总占用,以及删除 / 整轮删除 / 清理结果里的「估算释放约 X tokens」,都来自 `core.js` 的 `estimateMessageTokens`:与 DSH 官方 `dsh-token-meter` 同源的启发式定价——**4 字符 ≈ 1 token,每个内容块 +4,每条消息角色开销 +4**。Host 会优先用 `ctx.tokenMeter.measure()` 的节点定价;插件没注入 token-meter 时回退本地启发式。
|
|
261
|
+
|
|
262
|
+
**这只是估算,不是精确用量**:中文与 JSON 明显被低估。按预算清理也用同一套估算做排序与停止判断,所以实际省下的 token 通常多于显示值。
|
|
140
263
|
|
|
141
264
|
---
|
|
142
265
|
|
|
@@ -171,6 +294,7 @@ DSH 的会话格式要求 `developer/message` 必须位于一个已打开的 tur
|
|
|
171
294
|
- 删除的实现是追加一条「空 developer 消息」做表面替换,符合会话日志只追加、可重放的约定。
|
|
172
295
|
- 聊天视图展示历史记录,因此被删的消息**仍会出现在聊天记录里**;弹窗与后续模型请求使用当前表面。
|
|
173
296
|
- 系统提示词、尚未落盘的消息(例如正在流式生成的消息)不在可删除范围内。
|
|
297
|
+
- 删除记录(墓碑)本身不能再被当作消息删除:会提示该序号是一条删除记录、请改用 `restore`;`foldSurface` 会忽略缺 `seq` 的畸形表面对象。
|
|
174
298
|
- 需要会话处于运行状态。
|
|
175
299
|
- 纯本地运行:不联网、不外发任何数据。
|
|
176
300
|
- 关闭插件后标题栏入口、`/ctxmgr` 命令与 `context_manager` 工具都会消失;已写入日志的删除记录仍然保留。
|
|
@@ -188,6 +312,7 @@ DSH 的会话格式要求 `developer/message` 必须位于一个已打开的 tur
|
|
|
188
312
|
| `locale/*.json` | 插件管理页与详情页的标题、描述、详情文档路径 |
|
|
189
313
|
| `docs/DETAIL*.md`、`docs/preview.svg` | 插件详情页的单图说明 |
|
|
190
314
|
| `CHANGELOG.md` | 版本记录 |
|
|
315
|
+
| `test/*.test.mjs` | 零依赖 `node:test` 用例,共 49 个(`node --test "test/*.test.mjs"`) |
|
|
191
316
|
|
|
192
317
|
### 关于 `@deepseek-ai/*` 引用
|
|
193
318
|
|
|
@@ -211,6 +336,22 @@ plugin_manager remove_bundle target=dsh-context-manager
|
|
|
211
336
|
plugin_manager install_bundle target=link:<插件目录>
|
|
212
337
|
```
|
|
213
338
|
|
|
339
|
+
### 测试
|
|
340
|
+
|
|
341
|
+
`test/` 下三个零依赖 `node:test` 文件,共 49 个用例,只用内置模块,不需要安装任何依赖:
|
|
342
|
+
|
|
343
|
+
| 文件 | 用例数 |
|
|
344
|
+
|---|---|
|
|
345
|
+
| `test/core.test.mjs` | 9 |
|
|
346
|
+
| `test/batch.test.mjs` | 14 |
|
|
347
|
+
| `test/surface.test.mjs` | 26 |
|
|
348
|
+
|
|
349
|
+
覆盖 `planDeletion` 的工具组联动、`deletedFromSurface`、`foldSurface`(含缺 `seq` 的畸形对象)、`turnsFromSurface`、`planClean` 的保护与排序、`undo-batch` 的批次选择(含歧义前缀拒绝),以及召回指针与墓碑投影。
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
node --test "test/*.test.mjs"
|
|
353
|
+
```
|
|
354
|
+
|
|
214
355
|
## 发布(维护者)
|
|
215
356
|
|
|
216
357
|
`publishConfig` 已锁定 `registry.npmjs.org` 与 `access: public`,`files` 已覆盖运行文件、locale、图标与 `docs/`:
|
package/client.js
CHANGED
|
@@ -75,11 +75,33 @@ window.__ModuleLoader__.load({
|
|
|
75
75
|
deleteTurn: '删除本轮',
|
|
76
76
|
confirmBatchTurns: '确认删除选中的 {count} 轮对话?',
|
|
77
77
|
turnsDeleted: '已提交删除 {count} 轮对话。',
|
|
78
|
-
inProgressNote: '
|
|
78
|
+
inProgressNote: '进行中,下一次请求生效',
|
|
79
79
|
noUserMessage: '(无用户提问)',
|
|
80
80
|
turnMeta: '{count} 条',
|
|
81
81
|
expandSection: '展开',
|
|
82
82
|
collapseSection: '折叠',
|
|
83
|
+
cleanSelected: '按 token 优化 ({count})',
|
|
84
|
+
tokens: 'tokens(估算)',
|
|
85
|
+
estimated: '估算值:4 字符 ≈ 1 token,中文与 JSON 会明显低估',
|
|
86
|
+
totalTokens: '当前总占用 ≈{tokens} tokens(估算)',
|
|
87
|
+
cleanHint: '清理仅选取大体积工具/助手消息,按估算 token 降序,用户消息与最近 3 条受保护',
|
|
88
|
+
protectedUser: '用户消息受保护',
|
|
89
|
+
filterLabel: '过滤',
|
|
90
|
+
filterAll: '全部',
|
|
91
|
+
filterRole: '只看 {role}',
|
|
92
|
+
filterEmpty: '没有符合过滤条件的消息。',
|
|
93
|
+
filterCount: '显示 {shown}/{total}',
|
|
94
|
+
protectedChip: '受保护',
|
|
95
|
+
recallChip: '可召回 #{seq}',
|
|
96
|
+
userTokens: '用户 tokens(保护):{tokens}',
|
|
97
|
+
tokenSuffix: '≈{tokens} tok',
|
|
98
|
+
cleanNote: '清理使用启发式估算,实际释放可能略有偏差',
|
|
99
|
+
cleaned: '已按预算清理,目标释放 {tokens} tokens(估算)',
|
|
100
|
+
undoLast: '撤销上次操作',
|
|
101
|
+
undoDone: '已提交撤销,下一回合恢复。',
|
|
102
|
+
batchLabel: '批次 {id}',
|
|
103
|
+
cleanBudget: '预算',
|
|
104
|
+
cleanInvalid: '请输入正整数 token 预算。',
|
|
83
105
|
}
|
|
84
106
|
|
|
85
107
|
const en = {
|
|
@@ -134,6 +156,28 @@ window.__ModuleLoader__.load({
|
|
|
134
156
|
turnMeta: '{count} messages',
|
|
135
157
|
expandSection: 'Expand',
|
|
136
158
|
collapseSection: 'Collapse',
|
|
159
|
+
cleanSelected: 'Optimize by tokens ({count})',
|
|
160
|
+
tokens: 'tokens (estimated)',
|
|
161
|
+
estimated: 'Estimate: 4 characters ≈ 1 token; CJK text and JSON are notably underpriced',
|
|
162
|
+
totalTokens: 'Current usage ≈{tokens} tokens (estimated)',
|
|
163
|
+
cleanHint: 'Cleaning picks only large tool/assistant messages ranked by estimated tokens; user messages and the most recent 3 messages are protected',
|
|
164
|
+
protectedUser: 'User messages protected',
|
|
165
|
+
filterLabel: 'Filter',
|
|
166
|
+
filterAll: 'All',
|
|
167
|
+
filterRole: '{role} only',
|
|
168
|
+
filterEmpty: 'No messages match the filter.',
|
|
169
|
+
filterCount: 'showing {shown}/{total}',
|
|
170
|
+
protectedChip: 'protected',
|
|
171
|
+
recallChip: 'recall #{seq}',
|
|
172
|
+
userTokens: 'User tokens (protected): {tokens}',
|
|
173
|
+
tokenSuffix: '≈{tokens} tok',
|
|
174
|
+
cleanNote: 'Cleaning uses heuristic estimates; actual relief may differ',
|
|
175
|
+
cleaned: 'Cleaned toward {tokens} tokens (estimated)',
|
|
176
|
+
undoLast: 'Undo last batch',
|
|
177
|
+
undoDone: 'Undo queued; restores on the next turn.',
|
|
178
|
+
batchLabel: 'batch {id}',
|
|
179
|
+
cleanBudget: 'Budget',
|
|
180
|
+
cleanInvalid: 'Enter a positive integer token budget.',
|
|
137
181
|
}
|
|
138
182
|
|
|
139
183
|
const CSS = `
|
|
@@ -202,6 +246,17 @@ window.__ModuleLoader__.load({
|
|
|
202
246
|
.dshmm-confirmBar{display:flex;align-items:center;gap:10px;margin:10px 20px 0;padding:8px 10px;border-radius:8px;background:color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent);color:var(--dsw-alias-label-primary);font-size:12px;line-height:18px;flex:none}
|
|
203
247
|
.dshmm-confirmBar .dshmm-confirmActions{margin-left:auto}
|
|
204
248
|
.dshmm-subtle{font-size:11px;color:var(--dsw-alias-label-secondary)}
|
|
249
|
+
.dshmm-cleanbar{display:flex;align-items:center;gap:8px;margin:8px 20px 0;padding:8px 10px;border-radius:8px;background:color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent);flex:none;flex-wrap:wrap}
|
|
250
|
+
.dshmm-cleanlabel{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);flex:auto;min-width:0}
|
|
251
|
+
.dshmm-cleaninput{appearance:none;border:0.5px solid var(--dsw-alias-border-l2);border-radius:6px;padding:4px 8px;font:inherit;font-size:11px;line-height:16px;width:96px;background:var(--dsw-alias-bg-overlay);color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums}
|
|
252
|
+
.dshmm-cleaninput:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
253
|
+
.dshmm-chip{flex:none;font-size:10px;line-height:15px;padding:0 6px;margin-top:2px;border-radius:5px;white-space:nowrap}
|
|
254
|
+
.dshmm-chipProtect{color:var(--dsw-alias-brand-primary);background:color-mix(in srgb, var(--dsw-alias-brand-primary) 12%, transparent)}
|
|
255
|
+
.dshmm-filterbar{display:flex;align-items:center;gap:8px;margin:8px 20px 0;flex:none;flex-wrap:wrap}
|
|
256
|
+
.dshmm-filterLabel{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary)}
|
|
257
|
+
.dshmm-select{appearance:none;border:0.5px solid var(--dsw-alias-border-l2);border-radius:6px;padding:4px 8px;font:inherit;font-size:11px;line-height:16px;background:var(--dsw-alias-bg-overlay);color:var(--dsw-alias-label-primary);cursor:pointer}
|
|
258
|
+
.dshmm-select:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
259
|
+
.dshmm-filterCount{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
|
|
205
260
|
@media (max-width:520px){.dshmm-backdrop{padding:10px}.dshmm-panel{max-height:90vh}.dshmm-footHint{display:none}.dshmm-reason{display:none}}
|
|
206
261
|
`
|
|
207
262
|
|
|
@@ -336,6 +391,26 @@ window.__ModuleLoader__.load({
|
|
|
336
391
|
&& content.some((block) => block?.type === 'tool-addition' || block?.type === 'tool-removal')
|
|
337
392
|
}
|
|
338
393
|
|
|
394
|
+
/** Heuristic token estimate (4 chars ≈ 1 token), mirrors the Host estimate; CJK/JSON underpriced. */
|
|
395
|
+
function estimateTokens(message, isSystem) {
|
|
396
|
+
if (message === undefined || message === null) return 0
|
|
397
|
+
const content = Array.isArray(message.content) ? message.content : []
|
|
398
|
+
if (content.length === 0) return 0
|
|
399
|
+
if (isSystem) {
|
|
400
|
+
let chars = 0
|
|
401
|
+
for (const block of content) chars += block?.type === 'text' ? (block.text?.length ?? 0) : JSON.stringify(block).length
|
|
402
|
+
return Math.ceil(chars / 4) + 4
|
|
403
|
+
}
|
|
404
|
+
let tokens = 0
|
|
405
|
+
for (const block of content) {
|
|
406
|
+
if (block === null || typeof block !== 'object') continue
|
|
407
|
+
if (block.type === 'text' || block.type === 'reasoning') tokens += Math.ceil((block.text?.length ?? 0) / 4) + 4
|
|
408
|
+
else if (block.type === 'tool-call') tokens += Math.ceil((block.name?.length ?? 0) / 4) + Math.ceil((block.arguments?.length ?? 0) / 4) + 4
|
|
409
|
+
else tokens += 4 + Math.ceil(JSON.stringify(block).length / 4)
|
|
410
|
+
}
|
|
411
|
+
return tokens + 4
|
|
412
|
+
}
|
|
413
|
+
|
|
339
414
|
/** Source kinds this plugin writes for tombstones: current, then older releases. */
|
|
340
415
|
const TOMBSTONE_KINDS = ['context-manager', 'message-manager']
|
|
341
416
|
|
|
@@ -385,7 +460,18 @@ window.__ModuleLoader__.load({
|
|
|
385
460
|
const end = seqs.indexOf(op.endSeq)
|
|
386
461
|
if (start < 0 || end < start) continue
|
|
387
462
|
const removed = seqs.slice(start, end + 1)
|
|
388
|
-
if (isTombstoneEvent(event))
|
|
463
|
+
if (isTombstoneEvent(event)) {
|
|
464
|
+
groups.push({
|
|
465
|
+
tombstoneSeq: event.seq,
|
|
466
|
+
targetSeqs: removed,
|
|
467
|
+
batchId: typeof event.data?.message?.source?.batchId === 'string'
|
|
468
|
+
? event.data.message.source.batchId
|
|
469
|
+
: undefined,
|
|
470
|
+
recall: Array.isArray(event.data?.message?.source?.recall)
|
|
471
|
+
? event.data.message.source.recall
|
|
472
|
+
: [],
|
|
473
|
+
})
|
|
474
|
+
}
|
|
389
475
|
seqs.splice(start, end - start + 1, event.seq)
|
|
390
476
|
}
|
|
391
477
|
}
|
|
@@ -428,6 +514,7 @@ window.__ModuleLoader__.load({
|
|
|
428
514
|
blocks: content.length,
|
|
429
515
|
callIds: toolCallIdsOf(event),
|
|
430
516
|
toolCallId: event.type === 'tool/result' && typeof message.toolCallId === 'string' ? message.toolCallId : undefined,
|
|
517
|
+
tokens: content.length === 0 ? 0 : estimateTokens(message, event.type === 'system/message'),
|
|
431
518
|
})
|
|
432
519
|
}
|
|
433
520
|
|
|
@@ -571,6 +658,8 @@ window.__ModuleLoader__.load({
|
|
|
571
658
|
const panelRef = useRef(null)
|
|
572
659
|
// The per-message list is secondary to the turns view; start collapsed.
|
|
573
660
|
const [currentCollapsed, setCurrentCollapsed] = useState(true)
|
|
661
|
+
const [cleanBudget, setCleanBudget] = useState('20000')
|
|
662
|
+
const [roleFilter, setRoleFilter] = useState('all')
|
|
574
663
|
|
|
575
664
|
useEffect(() => {
|
|
576
665
|
const panel = panelRef.current
|
|
@@ -590,6 +679,10 @@ window.__ModuleLoader__.load({
|
|
|
590
679
|
return () => { document.removeEventListener('keydown', onKeyDown, true) }
|
|
591
680
|
}, [manager, busy])
|
|
592
681
|
|
|
682
|
+
const totalTokens = items.reduce((sum, item) => sum + (item.tokens ?? 0), 0)
|
|
683
|
+
// Filtering is a view concern only: selection, token totals and the Host
|
|
684
|
+
// planner still see the complete list.
|
|
685
|
+
const visibleItems = roleFilter === 'all' ? items : items.filter((item) => item.role === roleFilter)
|
|
593
686
|
const currentSelectedSeqs = items.filter((item) => selectedItems.has(item.seq)).map((item) => item.seq)
|
|
594
687
|
const restorableDeleted = deleted.filter((group) => group.restorable)
|
|
595
688
|
const deletedSelectedSeqs = restorableDeleted
|
|
@@ -603,8 +696,9 @@ window.__ModuleLoader__.load({
|
|
|
603
696
|
const turnGroups = useMemo(() => {
|
|
604
697
|
const byTurn = new Map()
|
|
605
698
|
for (const item of items) {
|
|
606
|
-
const group = byTurn.get(item.turn) ?? { turn: item.turn, items: [] }
|
|
699
|
+
const group = byTurn.get(item.turn) ?? { turn: item.turn, items: [], tokens: 0 }
|
|
607
700
|
group.items.push(item)
|
|
701
|
+
group.tokens = (group.tokens ?? 0) + (item.tokens ?? 0)
|
|
608
702
|
byTurn.set(item.turn, group)
|
|
609
703
|
}
|
|
610
704
|
return [...byTurn.values()].sort((a, b) => a.turn - b.turn)
|
|
@@ -678,6 +772,50 @@ window.__ModuleLoader__.load({
|
|
|
678
772
|
}
|
|
679
773
|
}
|
|
680
774
|
|
|
775
|
+
const runClean = async (targetTokens) => {
|
|
776
|
+
if (busy || !Number.isSafeInteger(targetTokens) || targetTokens <= 0) return
|
|
777
|
+
setBusy(true)
|
|
778
|
+
setStatus(undefined)
|
|
779
|
+
setPending(undefined)
|
|
780
|
+
try {
|
|
781
|
+
const execution = await manager.executeCommand(sessionId, `/ctxmgr clean ${targetTokens}`)
|
|
782
|
+
const result = execution?.result !== undefined ? execution.result : execution
|
|
783
|
+
if (result !== undefined && result !== null && result.kind === 'error') {
|
|
784
|
+
setStatus({ kind: 'error', text: result.text || t('failed') })
|
|
785
|
+
return
|
|
786
|
+
}
|
|
787
|
+
const text = result !== undefined && result !== null && result.kind === 'success' ? result.text : undefined
|
|
788
|
+
setStatus({ kind: 'success', text: text || t('cleaned', { tokens: targetTokens.toLocaleString('en-US') }) })
|
|
789
|
+
setSelectedItems(new Set())
|
|
790
|
+
} catch (error) {
|
|
791
|
+
setStatus({ kind: 'error', text: error instanceof Error ? error.message : String(error) })
|
|
792
|
+
} finally {
|
|
793
|
+
setBusy(false)
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const runUndo = async () => {
|
|
798
|
+
if (busy) return
|
|
799
|
+
setBusy(true)
|
|
800
|
+
setStatus(undefined)
|
|
801
|
+
setPending(undefined)
|
|
802
|
+
try {
|
|
803
|
+
const execution = await manager.executeCommand(sessionId, '/ctxmgr undo-batch')
|
|
804
|
+
const result = execution?.result !== undefined ? execution.result : execution
|
|
805
|
+
if (result !== undefined && result !== null && result.kind === 'error') {
|
|
806
|
+
setStatus({ kind: 'error', text: result.text || t('failed') })
|
|
807
|
+
return
|
|
808
|
+
}
|
|
809
|
+
const text = result !== undefined && result !== null && result.kind === 'success' ? result.text : undefined
|
|
810
|
+
setStatus({ kind: 'success', text: text || t('undoDone') })
|
|
811
|
+
setSelectedDeleted(new Set())
|
|
812
|
+
} catch (error) {
|
|
813
|
+
setStatus({ kind: 'error', text: error instanceof Error ? error.message : String(error) })
|
|
814
|
+
} finally {
|
|
815
|
+
setBusy(false)
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
681
819
|
const confirmPending = () => {
|
|
682
820
|
if (pending === undefined) return
|
|
683
821
|
run(pending.kind === 'turns' ? 'deleteturn' : 'delete', pending.seqs)
|
|
@@ -699,6 +837,9 @@ window.__ModuleLoader__.load({
|
|
|
699
837
|
}),
|
|
700
838
|
),
|
|
701
839
|
h('span', { className: 'dshmm-role' }, t(item.role)),
|
|
840
|
+
item.role === 'user'
|
|
841
|
+
? h('span', { className: 'dshmm-chip dshmm-chipProtect', title: t('protectedUser') }, t('protectedChip'))
|
|
842
|
+
: null,
|
|
702
843
|
h(
|
|
703
844
|
'div',
|
|
704
845
|
{ className: 'dshmm-main' },
|
|
@@ -714,6 +855,9 @@ window.__ModuleLoader__.load({
|
|
|
714
855
|
' · ',
|
|
715
856
|
formatTime(item.time, locale),
|
|
716
857
|
item.turn > 0 ? ` · T${item.turn}S${item.step}` : '',
|
|
858
|
+
item.tokens !== undefined && Number.isFinite(item.tokens)
|
|
859
|
+
? ` · ${t('tokenSuffix', { tokens: Math.round(item.tokens).toLocaleString('en-US') })}`
|
|
860
|
+
: '',
|
|
717
861
|
),
|
|
718
862
|
),
|
|
719
863
|
h(
|
|
@@ -769,6 +913,7 @@ window.__ModuleLoader__.load({
|
|
|
769
913
|
'div',
|
|
770
914
|
{ className: 'dshmm-meta' },
|
|
771
915
|
t('turnMeta', { count: group.items.length }),
|
|
916
|
+
` · ${t('tokenSuffix', { tokens: group.tokens.toLocaleString('en-US') })}`,
|
|
772
917
|
inProgress ? ` · ${t('inProgressNote')}` : '',
|
|
773
918
|
),
|
|
774
919
|
),
|
|
@@ -796,11 +941,14 @@ window.__ModuleLoader__.load({
|
|
|
796
941
|
|
|
797
942
|
const renderDeleted = (group) => {
|
|
798
943
|
const first = group.items[0]
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
944
|
+
const recalled = Array.isArray(group.recall) ? group.recall : []
|
|
945
|
+
const summary = first === undefined && recalled.length > 0
|
|
946
|
+
? `${t('recallChip', { seq: recalled[0].seq })} · ${recalled[0].preview || t('emptyMessage')}`
|
|
947
|
+
: group.count === 1
|
|
948
|
+
? first === undefined
|
|
949
|
+
? `#${group.targetSeqs[0]} · ${t('contentNotLoaded')}`
|
|
950
|
+
: `${t(first.role)} · ${first.preview || t('emptyMessage')}`
|
|
951
|
+
: `${t('deletedGroup')} · ${group.count}${first !== undefined && first.preview ? ` · ${first.preview}` : ''}`
|
|
804
952
|
const reasonKey = group.reason === 'appended'
|
|
805
953
|
? 'restoreAppended'
|
|
806
954
|
: group.reason === 'tool'
|
|
@@ -838,6 +986,7 @@ window.__ModuleLoader__.load({
|
|
|
838
986
|
'div',
|
|
839
987
|
{ className: 'dshmm-meta' },
|
|
840
988
|
t('deletedRecord', { seq: group.tombstoneSeq }),
|
|
989
|
+
typeof group.batchId === 'string' ? ` · ${t('batchLabel', { id: group.batchId.slice(0, 8) })}` : '',
|
|
841
990
|
reasonKey === undefined ? '' : ` · ${t(reasonKey)}`,
|
|
842
991
|
),
|
|
843
992
|
),
|
|
@@ -935,6 +1084,63 @@ window.__ModuleLoader__.load({
|
|
|
935
1084
|
),
|
|
936
1085
|
),
|
|
937
1086
|
h('p', { className: 'dshmm-subtitle' }, t('subtitle')),
|
|
1087
|
+
h(
|
|
1088
|
+
'div',
|
|
1089
|
+
{ className: 'dshmm-filterbar' },
|
|
1090
|
+
h('span', { className: 'dshmm-filterLabel' }, t('filterLabel')),
|
|
1091
|
+
h(
|
|
1092
|
+
'select',
|
|
1093
|
+
{
|
|
1094
|
+
className: 'dshmm-select',
|
|
1095
|
+
value: roleFilter,
|
|
1096
|
+
disabled: busy,
|
|
1097
|
+
'aria-label': t('filterLabel'),
|
|
1098
|
+
onChange: (event) => setRoleFilter(event.target.value),
|
|
1099
|
+
},
|
|
1100
|
+
h('option', { value: 'all' }, t('filterAll')),
|
|
1101
|
+
['user', 'assistant', 'tool', 'context'].map((role) => h(
|
|
1102
|
+
'option',
|
|
1103
|
+
{ key: role, value: role },
|
|
1104
|
+
t('filterRole', { role: t(role) }),
|
|
1105
|
+
)),
|
|
1106
|
+
),
|
|
1107
|
+
roleFilter === 'all'
|
|
1108
|
+
? null
|
|
1109
|
+
: h('span', { className: 'dshmm-filterCount' }, t('filterCount', { shown: visibleItems.length, total: items.length })),
|
|
1110
|
+
),
|
|
1111
|
+
h(
|
|
1112
|
+
'div',
|
|
1113
|
+
{ className: 'dshmm-cleanbar' },
|
|
1114
|
+
h('span', { className: 'dshmm-cleanlabel' }, t('cleanHint')),
|
|
1115
|
+
h('input', {
|
|
1116
|
+
type: 'number',
|
|
1117
|
+
min: 1,
|
|
1118
|
+
step: 1000,
|
|
1119
|
+
className: 'dshmm-cleaninput',
|
|
1120
|
+
value: cleanBudget,
|
|
1121
|
+
disabled: busy,
|
|
1122
|
+
'aria-label': t('cleanBudget'),
|
|
1123
|
+
placeholder: t('cleanBudget'),
|
|
1124
|
+
onChange: (event) => setCleanBudget(event.target.value),
|
|
1125
|
+
}),
|
|
1126
|
+
h(
|
|
1127
|
+
'button',
|
|
1128
|
+
{
|
|
1129
|
+
type: 'button',
|
|
1130
|
+
className: 'dshmm-small',
|
|
1131
|
+
disabled: busy,
|
|
1132
|
+
onClick: () => {
|
|
1133
|
+
const budget = Number.parseInt(cleanBudget, 10)
|
|
1134
|
+
if (!Number.isSafeInteger(budget) || budget <= 0) {
|
|
1135
|
+
setStatus({ kind: 'error', text: t('cleanInvalid') })
|
|
1136
|
+
return
|
|
1137
|
+
}
|
|
1138
|
+
runClean(budget)
|
|
1139
|
+
},
|
|
1140
|
+
},
|
|
1141
|
+
t('cleanSelected', { count: cleanBudget }),
|
|
1142
|
+
),
|
|
1143
|
+
),
|
|
938
1144
|
),
|
|
939
1145
|
status === undefined
|
|
940
1146
|
? null
|
|
@@ -1045,7 +1251,10 @@ window.__ModuleLoader__.load({
|
|
|
1045
1251
|
? h('div', { className: 'dshmm-empty' }, t('empty'))
|
|
1046
1252
|
: currentCollapsed
|
|
1047
1253
|
? null
|
|
1048
|
-
:
|
|
1254
|
+
: visibleItems.length === 0
|
|
1255
|
+
? h('div', { className: 'dshmm-empty' }, t('filterEmpty'))
|
|
1256
|
+
: visibleItems.map(renderCurrent),
|
|
1257
|
+
|
|
1049
1258
|
deleted.length === 0
|
|
1050
1259
|
? null
|
|
1051
1260
|
: h(
|
|
@@ -1080,8 +1289,20 @@ window.__ModuleLoader__.load({
|
|
|
1080
1289
|
{ className: 'dshmm-footCount' },
|
|
1081
1290
|
busy
|
|
1082
1291
|
? t('busy')
|
|
1083
|
-
: `${t('count', { count: items.length })}${deleted.length > 0 ? ` · ${t('deletedSection')} ${deleted.length}` : ''}`,
|
|
1292
|
+
: `${t('count', { count: items.length })} · ${t('totalTokens', { tokens: totalTokens.toLocaleString('en-US') })}${deleted.length > 0 ? ` · ${t('deletedSection')} ${deleted.length}` : ''}`,
|
|
1084
1293
|
),
|
|
1294
|
+
deleted.length === 0
|
|
1295
|
+
? null
|
|
1296
|
+
: h(
|
|
1297
|
+
'button',
|
|
1298
|
+
{
|
|
1299
|
+
type: 'button',
|
|
1300
|
+
className: 'dshmm-small',
|
|
1301
|
+
disabled: busy,
|
|
1302
|
+
onClick: runUndo,
|
|
1303
|
+
},
|
|
1304
|
+
t('undoLast'),
|
|
1305
|
+
),
|
|
1085
1306
|
h(
|
|
1086
1307
|
'span',
|
|
1087
1308
|
{ className: 'dshmm-footHint' },
|