dsh-context-manager 0.0.0-stage → 1.7.0
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 +75 -0
- package/LICENSE +21 -0
- package/README.md +368 -3
- package/client.js +1371 -0
- package/cordis.patch.yml +3 -0
- package/core.js +730 -0
- package/docs/DETAIL.md +23 -0
- package/docs/DETAIL.zh.md +23 -0
- package/docs/preview.svg +56 -0
- package/icon.svg +19 -0
- package/index.js +1330 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +70 -6
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
- Roll back to the start of a turn: `/ctxmgr turns` to read the turn numbers, `/ctxmgr deleteturn 5` to remove that whole turn from the context, then ask again.
|
|
4
|
+
- Drop noise: `/ctxmgr list` to find the indexes, `/ctxmgr delete 12,13,14` to clear error logs and trial-and-error instructions entry by entry.
|
|
5
|
+
- Forget superseded conclusions: delete the turns that hold plans which were later overturned, so the model stops citing them.
|
|
6
|
+
- Honest limit: this only removes content from the model context; the raw session log and chat transcript stay in the local session file, and this plugin is not an eraser.
|
|
7
|
+
|
|
8
|
+
- Token estimates: the `≈N tok` values and the total occupation come from `estimateMessageTokens` in `core.js`, a heuristic priced like DSH's `dsh-token-meter` (4 characters ≈ 1 token, +4 per content block, +4 role overhead per message). The Host prefers `ctx.tokenMeter.measure()` node pricing and falls back to the local heuristic when no token meter is injected.
|
|
9
|
+
- These are estimates, not exact usage: Chinese text and JSON are markedly underestimated, so the real saving is usually larger than the reported figure.
|
|
10
|
+
- Budget clean-up: `/ctxmgr clean 60000` (tool: `context_manager` action `clean`) sorts `tool` / `assistant` candidates by estimated tokens descending and deletes until the budget is met. User and context messages are never eligible, the most recent 3 messages are protected by default, candidates below 100 tokens are skipped, and deletion reuses the same tombstone + durable queue pipeline, so it stays restorable.
|
|
11
|
+
|
|
12
|
+
- Batch audit: every delete, whole-turn delete and clean mints a `batchId`, stored in the tombstone `source` as `{ kind: 'context-manager', batchId: '<uuid>' }`.
|
|
13
|
+
- `kind` stays the only marker, so tombstones written before batch ids are still recognized and restored.
|
|
14
|
+
- Ledger: each operation appends one `plugin:context-manager/batch` record to the session log — `batchId`, `op` (`delete` / `delete-turn` / `clean` / `undo`), `seqs`, `tombstoneSeqs`, `estimatedFreedTokens`, outcome (`applied` / `queued` / `skipped` / `failed`) and `reason`.
|
|
15
|
+
- The ledger is append-only, persists with the session log, survives restarts and writes no external files.
|
|
16
|
+
- Undo: `/ctxmgr batches` lists the ledger; `/ctxmgr undo-batch [batchId]` undoes the latest batch or a specific one by id prefix (tool: `action=batches` / `action=undo-batch`).
|
|
17
|
+
- Undo reuses the existing restore path (durable queue + idempotent ack) rather than a second mechanism, and leaves its own `op=undo` ledger entry.
|
|
18
|
+
|
|
19
|
+
- Recall pointers: each tombstone `source` is `{ 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 seq, 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.
|
|
20
|
+
- Retrieving the original: the recalled `seq` is the session seq of the original event. 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 search that session by keyword or read the complete unredacted event as JSON; searches exclude the caller's own session and are authorized by the workspace `cwd`. Deletion is therefore unloading from the main context into a searchable archive, not erasure — versus `dsh-context-redline` (migrates away) and compaction plugins (summarize away).
|
|
21
|
+
- Local compaction: `/ctxmgr compact <start> <end>` (tool: `context_manager` action `compact` with `start` / `end`) 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 or the engine reports an unbalanced region.
|
|
22
|
+
- It only compacts the user selection — no global threshold compaction — and requires a loaded compaction backend (e.g. `dsh-compaction-basic`); without one the plugin answers with a clear Chinese hint and records the failure in the ledger. The service is obtained optionally via `ctx.get('compaction')`, so the plugin does not hard-depend on it, and both success and failure append an `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 that cannot be restored per message, while the raw session log is still append-only.
|
|
23
|
+
- Tombstones written before `batchId` / `recall` keep working unchanged, and the dialog's deleted rows fall back to 可召回 #seq · 摘要 when the original text is no longer on the surface.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
- 回退到某一轮的开始:`/ctxmgr turns` 查看轮号,`/ctxmgr deleteturn 5` 把该轮整体移出上下文,然后重新提问。
|
|
4
|
+
- 清除废物信息:`/ctxmgr list` 找到序号,`/ctxmgr delete 12,13,14` 按条清掉报错日志与试错指令。
|
|
5
|
+
- 让模型忘掉过时的中间结论:删掉被推翻的方案所在的轮次,避免它反复引用旧结论。
|
|
6
|
+
- 止损边界:只移出模型上下文,原始会话日志与聊天记录仍留在本地会话文件里,本插件不是擦除工具。
|
|
7
|
+
|
|
8
|
+
- token 估算:列表里的 `≈N tok` 与总占用来自 `core.js` 的 `estimateMessageTokens`,定价与 DSH 官方 `dsh-token-meter` 同源——4 字符 ≈ 1 token、每个内容块 +4、每条消息角色开销 +4。Host 有 token-meter 时优先用 `ctx.tokenMeter.measure()` 的节点定价,否则回退本地启发式。
|
|
9
|
+
- 这只是估算:中文与 JSON 明显被低估,实际省下的 token 通常多于显示值。
|
|
10
|
+
- 按预算清理:`/ctxmgr clean 60000`(工具等价 `context_manager` + `clean`)把 `tool` / `assistant` 候选按估算 token 降序删除,达到预算即停止。用户消息与上下文消息永不入选,默认保护最近 3 条,候选默认 ≥100 tokens;删除复用同一套墓碑与持久队列,仍可恢复。
|
|
11
|
+
|
|
12
|
+
- 批次审计:每次删除、整轮删除与按预算清理都会生成 `batchId`,写进墓碑消息的 `source`:`{ kind: 'context-manager', batchId: '<uuid>' }`。
|
|
13
|
+
- `kind` 仍是唯一标记,因此旧墓碑没有 `batchId` 也照常识别与恢复。
|
|
14
|
+
- 台账:每次操作在会话日志追加一条 `plugin:context-manager/batch` 记录——`batchId`、`op`(`delete` / `delete-turn` / `clean` / `undo`)、`seqs`、`tombstoneSeqs`、`estimatedFreedTokens`、结果(`applied` / `queued` / `skipped` / `failed`)与 `reason`。
|
|
15
|
+
- 台账只增不改,随会话日志持久化,重启后仍可查,不写外部文件。
|
|
16
|
+
- 撤销:`/ctxmgr batches` 查看台账;`/ctxmgr undo-batch [batchId]` 撤销最近一次或按 batchId 前几位撤销指定批次(工具 `action=batches` / `action=undo-batch`)。
|
|
17
|
+
- 撤销复用既有 restore 路径(持久队列 + ack 幂等),不是新的恢复机制,并会留下自己的 `op=undo` 台账记录。
|
|
18
|
+
|
|
19
|
+
- 召回指针:每条墓碑的 `source` 是 `{ kind: 'context-manager', batchId, recall }`,其中 `recall` 最多 8 条 `{ seq, role, preview }`(`RECALL_MAX_ENTRIES = 8`),`preview` 截断到 80 字符(`RECALL_PREVIEW_LIMIT = 80`)。只存 seq、角色与一行摘要,不写消息全文;墓碑的 content 仍为空数组——墓碑必须投影成空消息。老墓碑没有这两个字段也照常工作。
|
|
20
|
+
- 取回原文:`recall` 里的 `seq` 就是原始事件的会话序号,可用 `@deepseek-ai/dsh-tool-session-query` 的只读工具 `session_search` / `session_event_search` / `session_trace` / `session_event_trace` / `session_event_read` 按关键字检索或读取完整未删节事件(JSON);搜索会排除调用方会话、按工作区 `cwd` 授权。所以「删除」是从主上下文卸载到可检索存档,不是擦除——与 `dsh-context-redline`(迁移走)和压缩插件(摘要掉)区分开。
|
|
21
|
+
- 局部压缩:`/ctxmgr compact <起序号> <止序号>`(工具 `context_manager` + `action=compact`,参数 `start` / `end`)调用官方 `ctx.compaction.compactRegion(start, end, agentCtx, signal)`。start / end 是表面位置序号,不是数值大小顺序,两端必须工具配对平衡,否则引擎报 unbalanced。
|
|
22
|
+
- 它只作用于用户选区,不做全局阈值压缩;需要环境加载压缩后端(如 `dsh-compaction-basic`),没加载时给明确中文提示并把失败写进台账。服务通过 `ctx.get('compaction')` 可选获取,插件不硬依赖;成功与失败都会在台账留一条 `op: 'compact'` 记录(含被遮蔽的节点数与 tokens)。与 delete / clean 的区别:delete / clean 是移出上下文、可恢复且无摘要,compact 是把一段换成一条官方摘要、不能按消息恢复,但原始会话日志仍只增不改。
|
|
23
|
+
- 旧墓碑没有 `batchId` / `recall` 也照常工作;弹窗「已删除」行在拿不到原文时,用召回指针显示「可召回 #seq · 摘要」。
|
package/docs/preview.svg
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="300" viewBox="0 0 640 300" role="img" aria-label="A conversation turn selected in the manager dialog and removed from the model context">
|
|
2
|
+
<g fill="none" stroke-linecap="round" stroke-linejoin="round">
|
|
3
|
+
<g stroke="#8b94a7" stroke-width="1.5">
|
|
4
|
+
<rect x="40" y="82" width="190" height="52" rx="11" fill="#8b94a7" fill-opacity="0.08"/>
|
|
5
|
+
<rect x="40" y="214" width="190" height="52" rx="11" fill="#8b94a7" fill-opacity="0.08"/>
|
|
6
|
+
</g>
|
|
7
|
+
<g stroke="#8b94a7" stroke-width="1.5">
|
|
8
|
+
<circle cx="62" cy="108" r="9" fill="#8b94a7" fill-opacity="0.16"/>
|
|
9
|
+
<rect x="82" y="98" width="112" height="8" rx="4" fill="#8b94a7" fill-opacity="0.22" stroke="none"/>
|
|
10
|
+
<rect x="82" y="114" width="74" height="8" rx="4" fill="#8b94a7" fill-opacity="0.16" stroke="none"/>
|
|
11
|
+
<circle cx="62" cy="240" r="9" fill="#8b94a7" fill-opacity="0.16"/>
|
|
12
|
+
<rect x="82" y="230" width="96" height="8" rx="4" fill="#8b94a7" fill-opacity="0.22" stroke="none"/>
|
|
13
|
+
<rect x="82" y="246" width="58" height="8" rx="4" fill="#8b94a7" fill-opacity="0.16" stroke="none"/>
|
|
14
|
+
</g>
|
|
15
|
+
<g stroke="#4c8dff" stroke-width="1.8">
|
|
16
|
+
<rect x="40" y="148" width="190" height="52" rx="11" fill="#4c8dff" fill-opacity="0.14"/>
|
|
17
|
+
<circle cx="62" cy="174" r="9" fill="#4c8dff" fill-opacity="0.2"/>
|
|
18
|
+
<rect x="82" y="164" width="104" height="8" rx="4" fill="#4c8dff" fill-opacity="0.55" stroke="none"/>
|
|
19
|
+
<rect x="82" y="180" width="66" height="8" rx="4" fill="#4c8dff" fill-opacity="0.35" stroke="none"/>
|
|
20
|
+
<polyline points="196,170 202,177 214,161" stroke-width="2.4"/>
|
|
21
|
+
</g>
|
|
22
|
+
<g stroke="#8b94a7" stroke-width="1.8">
|
|
23
|
+
<path d="M236 174 H286"/>
|
|
24
|
+
<polyline points="278,166 288,174 278,182"/>
|
|
25
|
+
</g>
|
|
26
|
+
<g stroke="#8b94a7" stroke-width="1.5">
|
|
27
|
+
<rect x="306" y="52" width="298" height="196" rx="14" fill="#8b94a7" fill-opacity="0.08"/>
|
|
28
|
+
<path d="M306 88 H604" stroke-opacity="0.8"/>
|
|
29
|
+
</g>
|
|
30
|
+
<g stroke="#4c8dff" stroke-width="2">
|
|
31
|
+
<polyline points="324,66 331,73 324,80"/>
|
|
32
|
+
</g>
|
|
33
|
+
<g stroke="#8b94a7" stroke-width="1.4">
|
|
34
|
+
<rect x="344" y="66" width="92" height="8" rx="4" fill="#8b94a7" fill-opacity="0.28" stroke="none"/>
|
|
35
|
+
<circle cx="566" cy="72" r="10" fill="#8b94a7" fill-opacity="0.12"/>
|
|
36
|
+
<path d="M562 68 H570 M563 72 H569 M564 70 V76 A2 2 0 0 1 562 78 H570 A2 2 0 0 1 568 76 V70"/>
|
|
37
|
+
</g>
|
|
38
|
+
<g stroke="#8b94a7" stroke-width="1.4">
|
|
39
|
+
<circle cx="336" cy="106" r="4" fill="#8b94a7" fill-opacity="0.4" stroke="none"/>
|
|
40
|
+
<rect x="352" y="101" width="150" height="8" rx="4" fill="#8b94a7" fill-opacity="0.2" stroke="none"/>
|
|
41
|
+
<rect x="352" y="116" width="96" height="7" rx="3.5" fill="#8b94a7" fill-opacity="0.13" stroke="none"/>
|
|
42
|
+
<circle cx="336" cy="140" r="4" fill="#8b94a7" fill-opacity="0.4" stroke="none"/>
|
|
43
|
+
<rect x="352" y="135" width="186" height="8" rx="4" fill="#8b94a7" fill-opacity="0.2" stroke="none"/>
|
|
44
|
+
<rect x="352" y="150" width="122" height="7" rx="3.5" fill="#8b94a7" fill-opacity="0.13" stroke="none"/>
|
|
45
|
+
<circle cx="336" cy="174" r="4" fill="#8b94a7" fill-opacity="0.4" stroke="none"/>
|
|
46
|
+
<rect x="352" y="169" width="132" height="8" rx="4" fill="#8b94a7" fill-opacity="0.2" stroke="none"/>
|
|
47
|
+
</g>
|
|
48
|
+
<g stroke="#f0806b" stroke-width="1.6" stroke-dasharray="7 6">
|
|
49
|
+
<rect x="324" y="196" width="262" height="34" rx="9" fill="#f0806b" fill-opacity="0.08"/>
|
|
50
|
+
</g>
|
|
51
|
+
<g stroke="#f0806b" stroke-width="1.8" stroke-opacity="0.75">
|
|
52
|
+
<path d="M468 205 L494 221"/>
|
|
53
|
+
<path d="M494 205 L468 221"/>
|
|
54
|
+
</g>
|
|
55
|
+
</g>
|
|
56
|
+
</svg>
|
package/icon.svg
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Session Message Manager">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="dshmm-bg" x1="8" y1="6" x2="56" y2="58" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop offset="0" stop-color="#3b82f6"/>
|
|
5
|
+
<stop offset="1" stop-color="#1d4ed8"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect x="2" y="2" width="60" height="60" rx="14" fill="url(#dshmm-bg)"/>
|
|
9
|
+
<g fill="#ffffff">
|
|
10
|
+
<rect x="13" y="16" width="30" height="5" rx="2.5" opacity="0.96"/>
|
|
11
|
+
<rect x="13" y="26" width="24" height="5" rx="2.5" opacity="0.9"/>
|
|
12
|
+
<rect x="13" y="36" width="17" height="5" rx="2.5" opacity="0.82"/>
|
|
13
|
+
</g>
|
|
14
|
+
<g transform="translate(36 34)">
|
|
15
|
+
<rect x="0" y="2" width="19" height="20" rx="4.5" fill="#ef4444" stroke="#ffffff" stroke-width="1.6"/>
|
|
16
|
+
<path d="M5.5 2V0.8h8V2" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round"/>
|
|
17
|
+
<path d="M6.2 7v9.5M9.5 7v9.5M12.8 7v9.5" fill="none" stroke="#ffffff" stroke-width="1.8" stroke-linecap="round" opacity="0.92"/>
|
|
18
|
+
</g>
|
|
19
|
+
</svg>
|