dsh-context-manager 0.0.0-stage → 1.6.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 ADDED
@@ -0,0 +1,56 @@
1
+ # Changelog
2
+
3
+ ## 1.6.0
4
+
5
+ - 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.
6
+ - Renamed the command `/msgmgr` to `/ctxmgr` (same subcommands: `list` / `turns` / `delete` / `deleteturn` / `restore`) and the model tool `message_manager` to `context_manager` (same actions: `list` / `list-turns` / `delete` / `delete-turns` / `restore`). The bundle patch id is now `context-manager`.
7
+ - Renamed the header entry and dialog from 消息管理 to 上下文管理 (Context manager in English); the plugin title in the Plugin Manager follows the same name.
8
+ - README: added a 使用场景 section with concrete workflows — rolling back to the start of a turn and asking again, dropping error logs and trial instructions entry by entry, forgetting superseded conclusions, converging over-long sessions, and the honest limits of removing leaked content — and updated every install source to 1.6.0 with migration steps from the old package.
9
+ - Backward compatible with session logs written by 1.5.0: tombstones whose source kind is `message-manager` and queued records `plugin:message-manager/pending` / `plugin:message-manager/ack` are still recognized, restored and applied, so no manual log cleanup is needed.
10
+ - Plugin market submission moved to `data/plugins/xian-yu-zhao__dsh-context-manager.yml` (category `session`).
11
+
12
+ ## 1.5.0
13
+
14
+ - Publishable package: renamed from `@local/dsh-message-manager` to `dsh-message-manager`, dropped `private`, added keywords, `author`, `publishConfig` (public, `registry.npmjs.org`), `homepage`/`bugs`, and a `files` whitelist that covers runtime files, locales, icon and `docs/`.
15
+ - The bundle patch row now names `dsh-message-manager`, so the installed bundle resolves from the npm package, a GitHub spec, a tarball or a linked directory alike.
16
+ - Plugin detail page: `docs/DETAIL.md` / `docs/DETAIL.zh.md` with a single text-free `preview.svg`, declared through `meta.detail`; `meta.description` now carries the full capability, entry points and limitations for the Plugin Manager and market listing.
17
+ - README rewritten: install sources (npm / GitHub / tgz / local directory), the header dialog walkthrough, command and tool reference, queued-apply rules, restore boundaries, limitations, and a maintainer publish procedure.
18
+ - Published to npm as `dsh-message-manager@1.5.0`, and verified end to end by installing that spec through `plugin_manager` (pnpm resolved the registry tarball, the bundle activated, `message_manager` answered).
19
+ - Plugin market: added the community index submission at `market/awesome-dsh-plugin.yml` (category `session`) and documented how the market indexes work, since DSH ships no official index. Repository gained the `dsh-plugin` topic.
20
+
21
+ ## 1.4.1
22
+
23
+ - The message list section starts collapsed in the header dialog, keeping the turns view in focus; click its header (chevron) to expand. The section keeps its select-all and batch-delete actions usable while collapsed.
24
+
25
+ ## 1.4.0
26
+
27
+ - Delete a whole conversation turn in one action: the user prompt, the assistant work and reply, and that turn's injected context. `core.turnsFromSurface` groups the surface by turn (a node's own `data.turn`; tombstones stay invisible, so a fully deleted turn disappears).
28
+ - `deleteTurnNow` reuses the single-message planner per remaining node, so every tombstone keeps its own restore semantics: user messages restore in place, assistant groups and text restore at the tail. Tombstones already on the surface are left untouched.
29
+ - `/msgmgr turns` / `list-turns` lists turns with numbers and previews (`T3 · … · 12 条`), marking the turn that is still in progress.
30
+ - `/msgmgr deleteturn <轮号,...>` and the `message_manager` tool actions `list-turns` / `delete-turns` delete turns now when safe or queue them durably (`delete-turn` pending records) — including turns that are still in progress, which apply at the next request.
31
+ - The header dialog gains a turns section above the message list: per-turn row with selection, preview, message count, in-progress note, and a delete button, plus batch select-all and a turns-specific confirm bar.
32
+
33
+ ## 1.3.0
34
+
35
+ - Durable queue: idle deletions and restores are recorded as `plugin:message-manager/pending` records in the session log itself, so queued operations survive Host restarts instead of living only in memory. Applied records are acknowledged (`plugin:message-manager/ack`) and never replay twice; replayed operations whose target vanished are acknowledged as skipped.
36
+ - `/msgmgr list` and the `message_manager` tool now also list deleted records (with the tombstone seqs `restore` needs) and queued operations, giving the model the same view as the header dialog.
37
+ - The confirm bar in the header dialog now shows the total removal count and the tool-group hint when a selection expands (deleting an assistant tool-call message or a tool result takes its whole group along).
38
+ - `openStepOf` scans the log backward, so finding the open step no longer walks the whole history.
39
+
40
+ ## 1.2.0
41
+
42
+ - Batch selection: delete multiple messages in one action.
43
+ - Deleted records list with per-item and batch restore.
44
+ - Restore user/context messages at their original surface position.
45
+ - Restore assistant text and assistant tool-call groups by appending them at the tail with a valid tool lifecycle.
46
+ - Queue delete/restore operations until the next `agent/request`, so no event is appended outside an open turn/step.
47
+
48
+ ## 1.1.0
49
+
50
+ - Fix false "operation failed" after a successful command by unwrapping `RemoteResult`.
51
+ - Queue idle deletions and apply them inside the next request instead of appending outside an open step.
52
+ - Prevent corrupt session logs caused by `developer/message` tombstones outside an open turn/step.
53
+
54
+ ## 1.0.0
55
+
56
+ - Initial release: header message manager, per-message deletion, `/msgmgr` command, and `message_manager` tool.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Session Message Manager contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,227 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # 会话上下文管理 · dsh-context-manager
2
+
3
+ 一个 DSH(DeepSeek Harness)插件:在会话标题栏增加「上下文管理」入口,管理会话的**模型上下文**——按条删、按整轮删,之后还能恢复。原始会话日志、聊天记录与审计数据始终保留。
4
+
5
+ - 包名:`dsh-context-manager`
6
+ - 版本:`1.6.0`
7
+ - 类型:Cordis bundle(Host 半 + Web Client 半),纯 JavaScript,**无构建、无第三方依赖**
8
+ - 适用:DSH `0.2.1-rc.2` 及以上(`0.2.2-rc.5` 实测)
9
+
10
+ ---
11
+
12
+ ## 安装
13
+
14
+ 插件管理页里选择任一来源即可,也可以直接用 `plugin_manager` 工具的 `install_bundle`:
15
+
16
+ | 来源 | target 写法 | 说明 |
17
+ |---|---|---|
18
+ | npm | `dsh-context-manager@1.6.0` | 已发布到 [npm](https://www.npmjs.com/package/dsh-context-manager) |
19
+ | GitHub | `github:xian-yu-zhao/dsh-context-manager` | 免 npm,直接从仓库取 |
20
+ | 本地 tgz | `file:C:\path\to\dsh-context-manager-1.6.0.tgz` | Release 资产或 `npm pack` 产物 |
21
+ | 本地目录 | `link:C:\path\to\dsh-context-manager` | 开发调试用,改源码即生效 |
22
+
23
+ 安装后刷新 Web 页面(F5)或重启应用,会话标题栏右侧会出现列表图标。
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.6.0`——新版本仍能识别旧版写入会话日志的删除记录与排队记录。
26
+
27
+ > 无 npm CLI 也能装:GitHub / tgz / 本地目录三种来源都不经过 npm 发布。
28
+ >
29
+ > 若 npm 上暂时只能看到 `0.0.0-stage` 占位版本,说明 npm 的暂存审核尚未通过,此时请先用 GitHub 源安装。
30
+
31
+ ---
32
+
33
+ ## 使用场景
34
+
35
+ ### 回退到某一轮的开始,重新提问
36
+
37
+ 模型在某一轮改坏了文件,或者方向跑偏了。先用 `/ctxmgr turns` 看清轮号与预览,再用 `/ctxmgr deleteturn 5` 把第 5 轮(你的提问 + 它的全部工作与回答)整体移出上下文——上下文就回到第 5 轮开始前的状态,然后重新描述需求。想回到第 5 轮之前但保留第 5 轮之前的成果,就删掉它之后的所有轮次。
38
+
39
+ `/ctxmgr turns` → `/ctxmgr deleteturn 5`
40
+
41
+ ### 清除废物信息,省下上下文
42
+
43
+ 几屏报错日志、一大段粘贴的代码、试错过程中的无效指令、啰嗦的工具输出,都会持续占用上下文预算。用 `/ctxmgr list` 找到序号,再按条清掉,后续请求不再携带这些内容。
44
+
45
+ `/ctxmgr list` → `/ctxmgr delete 12,13,14`
46
+
47
+ ### 让模型忘掉过时的中间结论
48
+
49
+ 探索阶段达成的方案与结论,后来被推翻或替换了,留在上下文里容易被模型反复引用。删掉对应的轮次,只保留最终结论所在的轮。
50
+
51
+ `/ctxmgr turns` → `/ctxmgr deleteturn 3,4`(工具等价:`context_manager` + `delete-turns`)
52
+
53
+ ### 收敛超长会话
54
+
55
+ 上下文快满,但又不想新开一个会话丢掉历史。把早期纯探索的轮次整轮删掉,保留关键决策轮次,后续请求就能继续在同一个会话里推进。
56
+
57
+ `/ctxmgr turns` → `/ctxmgr deleteturn 2,3,4`
58
+
59
+ ### 误发内容的止损(如实说明边界)
60
+
61
+ 把密钥、隐私片段或发错的内容从**模型上下文**里移除,后续请求不再看到它们。但必须清楚:**原始会话日志与聊天记录仍在本地会话文件里**,这个插件不是擦除工具,真要抹掉请自行处理会话文件。
62
+
63
+ `/ctxmgr delete 9`(工具等价:`context_manager` + `delete`)
64
+
65
+ ---
66
+
67
+ ## 插件市场收录
68
+
69
+ 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`。
70
+
71
+ 使用市场:
72
+
73
+ 1. 侧栏 **Plugins** → **Experimental plugins** 打开 **Custom plugin indexes**,页面出现 **Installed / Discover** 两个标签。
74
+ 2. **Discover** → **Add index source**,填入索引地址(已配置过就跳过)。
75
+ 3. 搜索 `context manager`,安装按钮把索引里的 `name@version` 交给同一套 `installBundle`。
76
+
77
+ 投稿收录:向 awesome-dsh-plugin 仓库提一个 PR,**只新增一个文件** `data/plugins/xian-yu-zhao__dsh-context-manager.yml`,内容即本仓库的 [`market/awesome-dsh-plugin.yml`](market/awesome-dsh-plugin.yml):
78
+
79
+ ```yaml
80
+ url: https://github.com/xian-yu-zhao/dsh-context-manager
81
+ name: xian-yu-zhao/dsh-context-manager
82
+ category: session
83
+ description:
84
+ en: 'Manages the model context of a DSH session: removes single messages or whole conversation turns (roll back to the start of a turn) and can restore them later.'
85
+ zh: '管理 DSH 会话的模型上下文:按条或按整轮移除消息(可回退到某一轮的开始),之后还能恢复。'
86
+ ```
87
+
88
+ 合并后站点重建索引,即可被搜到并一键安装(安装来源为 npm 上的 `dsh-context-manager`)。门槛核对:`dsh.bundle` 已声明 ✅、有真实可用代码 ✅、仓库建满 1 天 ✅、`dsh-plugin` topic 已添加 ✅。
89
+
90
+ ### 自己托管一份索引
91
+
92
+ 任何静态 https 地址都可托管一份 format 1 索引(**不能有重定向**),让别人「Add index source」即可:
93
+
94
+ ```json
95
+ {
96
+ "format": 1,
97
+ "title": { "en": "xian-yu-zhao plugins", "zh": "xian-yu-zhao 插件" },
98
+ "plugins": [
99
+ {
100
+ "id": "context-manager",
101
+ "name": "dsh-context-manager",
102
+ "title": { "en": "Context manager", "zh": "会话上下文管理" },
103
+ "versions": [
104
+ { "version": "1.6.0", "publishTimestamp": 1795534865, "source": { "type": "npm" } }
105
+ ]
106
+ }
107
+ ]
108
+ }
109
+ ```
110
+
111
+ `versions[].source` 只有两种形态:`{"type":"npm"}`(可带 `registry`)或 `{"type":"git","url":"https://github.com/owner/repo","commit":"<40 位小写 commit>","path?":"子目录"}`。字段细节、图标限制(`data:` ≤32 KiB)与校验规则见 DSH 内置包 `@deepseek-ai/dsh-plugin-market-index`。
112
+
113
+ ---
114
+
115
+ ## 使用
116
+
117
+ ### 弹窗
118
+
119
+ 1. 打开任意会话,点标题栏右侧的列表图标,打开「上下文管理」。
120
+ 2. **对话轮(整轮删除)**:一行一轮,显示轮号、预览与消息条数;勾选后点「删除选中」,或点行尾「删除本轮」。这一轮里的用户提问、助手的工作与回答、该轮注入的上下文会一起移出,不必逐条删工具调用。
121
+ 3. **当前消息**(默认折叠,点标题或 ▸ 展开):按条勾选,点「删除选中」;也可点行尾垃圾桶单独删。折叠状态下全选与批量删除按钮仍可用。
122
+ 4. **已删除**:保留本插件产生的删除记录(`删除记录 #seq`),可勾选后「恢复选中」,或逐条「恢复」。
123
+ 5. 删除只影响**后续模型请求**;恢复后重新进入后续请求。
124
+
125
+ 确认条会提示连带移除的总条数(`共移除 N 条消息`),因为删助手消息会带走它发起的工具结果,删工具结果会带走所属助手消息与同组结果。
126
+
127
+ ### 命令
128
+
129
+ ```text
130
+ /ctxmgr list # 当前消息 + 已删除记录 + 排队中的操作
131
+ /ctxmgr turns # 对话轮列表(轮号、预览、条数、进行中标记)
132
+ /ctxmgr delete <序号,...> # 按条删除
133
+ /ctxmgr deleteturn <轮号,...> # 按轮删除
134
+ /ctxmgr restore <删除记录序号,...> # 恢复
135
+ ```
136
+
137
+ ### 工具
138
+
139
+ 模型可调用 `context_manager`,参数 `action` ∈ `list` / `list-turns` / `delete` / `delete-turns` / `restore`,`seqs` 按 action 解释为消息序号、轮号或删除记录序号。工具描述里明确要求「仅在用户明确要求时使用」。
140
+
141
+ ---
142
+
143
+ ## 删除与恢复何时生效
144
+
145
+ DSH 的会话格式要求 `developer/message` 必须位于一个已打开的 turn/step 中,且 Session 不能在 `session/event` 派发过程中重入追加。插件据此选路:
146
+
147
+ - **目标属于更早的步骤,且当前有步骤打开**:立即从模型上下文移除。
148
+ - **会话空闲,或目标包含当前正在进行的步骤**:进入**持久化队列**——一条 `plugin:context-manager/pending` 记录直接写进会话日志(plugin 记录不要求打开的 turn/step),在下一个 `agent/request` 时、模型请求组装之前同步应用。也就是「你下次发消息时它就不在上下文里了」。
149
+ - **恢复**:总是进队列,在下一个 `agent/request` 时应用。
150
+ - 队列存在会话日志里,重启不丢;应用完的操作追加 `plugin:context-manager/ack` 记录,**绝不重放两次**;重放时目标已消失则以 skipped 收尾,不反复报错。
151
+ - **兼容旧数据**:旧版 `dsh-message-manager` 写入会话日志的删除记录(tombstone 来源 kind `message-manager`)与排队记录(旧名 `plugin:message-manager/pending` / `plugin:message-manager/ack`)仍会被识别、恢复与应用,升级无需手工清理日志。
152
+ - 整轮删除拆成逐个节点(或工具调用组)的独立删除记录,每条仍保有自己的恢复语义;表面上已有的删除记录不会被覆盖。
153
+
154
+ ---
155
+
156
+ ## 恢复的能力边界
157
+
158
+ | 目标 | 恢复行为 |
159
+ |---|---|
160
+ | 用户消息、普通上下文消息 | 恢复到原来的表面位置 |
161
+ | 助手纯文本消息 | 追加到会话末尾(DSH 不允许 assistant 消息作为带 source 引用的表面替换) |
162
+ | 助手工具调用组(助手消息 + 工具调用 + 工具结果) | 整组追加到末尾,保持合法工具生命周期 |
163
+ | 单独的工具结果、带工具变更的上下文消息、系统提示词 | 不支持恢复 |
164
+
165
+ 恢复助手消息会在聊天记录末尾新增一份内容副本;原删除记录仍留在日志里。
166
+
167
+ ---
168
+
169
+ ## 行为与限制
170
+
171
+ - 删除的实现是追加一条「空 developer 消息」做表面替换,符合会话日志只追加、可重放的约定。
172
+ - 聊天视图展示历史记录,因此被删的消息**仍会出现在聊天记录里**;弹窗与后续模型请求使用当前表面。
173
+ - 系统提示词、尚未落盘的消息(例如正在流式生成的消息)不在可删除范围内。
174
+ - 需要会话处于运行状态。
175
+ - 纯本地运行:不联网、不外发任何数据。
176
+ - 关闭插件后标题栏入口、`/ctxmgr` 命令与 `context_manager` 工具都会消失;已写入日志的删除记录仍然保留。
177
+
178
+ ---
179
+
180
+ ## 结构
181
+
182
+ | 文件 | 作用 |
183
+ |---|---|
184
+ | `index.js` | Host 半:`/ctxmgr` 命令、`context_manager` 工具、删除/恢复计划、持久化队列与 `agent/request` 应用器 |
185
+ | `core.js` | 纯函数:表面折叠、删除计划、墓碑消息、列表与对话轮格式化 |
186
+ | `client.js` | Client 半:标题栏按钮、「上下文管理」弹窗(对话轮 / 当前消息 / 已删除) |
187
+ | `cordis.patch.yml` | 向 profile patch 插入一行插件 |
188
+ | `locale/*.json` | 插件管理页与详情页的标题、描述、详情文档路径 |
189
+ | `docs/DETAIL*.md`、`docs/preview.svg` | 插件详情页的单图说明 |
190
+ | `CHANGELOG.md` | 版本记录 |
191
+
192
+ ### 关于 `@deepseek-ai/*` 引用
193
+
194
+ Host 半需要 `@deepseek-ai/dsh-session` 的内部工具函数。以 `link:` 方式安装时,真实路径在 profile 之外,裸导入会报 `ERR_MODULE_NOT_FOUND`;插件因此先试裸导入,失败则用 `process.argv[2]`(Host 运行目录)拼出 asar 内的绝对 URL 再导入——同一 URL 得到同一模块实例,Session 的私有 brand 校验才能通过。
195
+
196
+ ---
197
+
198
+ ## 开发
199
+
200
+ ```bash
201
+ # 语法检查(无构建步骤)
202
+ node --check index.js
203
+ node --check client.js
204
+ node --check core.js
205
+ ```
206
+
207
+ 改 Client 半后需要刷新页面(F5)或重启应用;改 Host 半需重新安装 bundle:
208
+
209
+ ```text
210
+ plugin_manager remove_bundle target=dsh-context-manager
211
+ plugin_manager install_bundle target=link:<插件目录>
212
+ ```
213
+
214
+ ## 发布(维护者)
215
+
216
+ `publishConfig` 已锁定 `registry.npmjs.org` 与 `access: public`,`files` 已覆盖运行文件、locale、图标与 `docs/`:
217
+
218
+ ```bash
219
+ npm publish # 发布 dsh-context-manager@<version>
220
+ git push origin main
221
+ ```
222
+
223
+ 发版顺序:改 `package.json` 版本 → 补 `CHANGELOG.md` → 语法检查 → `npm publish` → 打 tag / 上传 tgz 到 Release → 推 GitHub。
224
+
225
+ ## 许可
226
+
227
+ MIT