dsh-session-delete
Manifest validAdds a "Delete session" action after "Archive session" that permanently removes one session: its log directory, rewind snapshots and projection-cache entry, its workspace/archive/pin registrations, sc
dsh-session-delete
DeepSeek Harness 插件:在会话右键菜单的 归档会话 之后追加 删除会话,永久删除该会话的日志、回退快照、投影缓存、工作区登记、定时任务与索引行。
Adds a permanent Delete session action right after Archive session in the session context menu, and removes every artifact the Host keeps for that Session. MIT licensed.
- 版本:1.3.0
- 分发:GitHub 仓库 + Release 里的 zip/tgz(未发布到 npm:npm 上
dsh-session-delete已被他人占用,且发布需要账号 2FA) - 宿主侧提供同名 Agent 工具
session_delete({ sessionId, dryRun })与 HTTP 接口,浏览器里点右键菜单和 Agent 调用走同一套删除实现。 - 删除后宿主广播
api-session/removed,侧栏那一行立即消失,无需刷新;宿主还会把该 id 记进自己的墓碑文件,浏览器半读取它并在目录每次刷新后重新剔除该行 —— 宿主内存里仍存活的会话因此不会以“未分组”身份复活(见下)。 - 共享附件(
attachments/v1/objects/<sha>)按内容寻址、多会话共用,刻意不删。
删除范围
| 类别 | 位置 |
|---|---|
| 会话日志 | $DSH_HOME/sessions/<projectKey>/<id> 与历史命名 session-<id>(两种命名都会扫) |
| 回退快照 | $DSH_HOME/rewind-snapshots/{<id>,session-<id>} |
| 投影缓存 | $DSH_HOME/storages/session_projcache/sessions/{<id>,session-<id>}.json(含 .json.tmp、.tmp 残留) |
| 注册表 | storages/workspace.json 中的 sessionIds(工作区成员)、pinnedSessionIds(置顶);archivedSessionIds 里若残留 1.2.3 时代写入的墓碑会被一次性回收(unarchive)并改记到插件自己的墓碑文件 |
| 定时任务 | target.kind 为 session(投递进该会话)或 new_once(预留了该会话身份、会话没了就永远无法投递)的任务,经 schedule.edit({ id, action: 'delete' }) 正式删除(不改文件) |
| 聊天索引 | $DSH_HOME/bot/chat-index.sqlite 的 lines(FTS5) 与 marks 表,session = <id> 与 session = session-<id> 两种键 |
| 用量账本 | $DSH_HOME/bot/usage.sqlite 的 calls / marks / owners / kinds 表,同样两种键 |
| 运行状态 | 先 sessionController.cancel + workspace/session-stop 停掉正在跑的回合,等 120 ms 释放句柄再删文件 |
刻意不动的东西:
attachments/v1/objects/<sha>—— 内容寻址、多会话共享,按会话删会误伤别的会话。storages/workspace.json里其它会话、schedule.json里其它任务、两个 sqlite 里其它会话的行 —— 测试里有对照组断言。integrations/dsh-im/group-history.sqlite—— IM 群历史,与会话无关。
使用
- 侧栏会话行右键 → 删除会话(危险色,位于“归档会话”之后)→ 确认弹窗显示会话标题,执行后列出删除的路径与字节数、被删的定时任务、被清理的索引行数、失败项、备注。
- 删除成功后宿主广播
api-session/removed,侧栏那一行立即消失,不需要刷新页面(客户端先sessions.handleSessionRemoved()移除,再sessions.refresh()重拉基线,最后再移除一次兜底)。 - Agent 工具
session_delete({ sessionId, dryRun }):同一套逻辑,dryRun=true只列出将被删除的路径、任务与索引行数。 - HTTP(客户端走这条通道,带
connection.requestRejection请求栅栏;Host 没有该服务时退化为Sec-Fetch-Site+Origin/Host同源校验):GET /session-delete/api/health—— 宿主半的加载状态(见下)GET /session-delete/api/preview?sessionId=...POST /session-delete/api/delete{ "sessionId": "...", "dryRun": false }
会话 ID 只接受 ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$,../、绝对路径、空串一律拒绝。
为什么需要墓碑文件(1.3.0)
DSH 没有“销毁会话”的公开 API:ctx.sessions 只提供 create/prepare/enter/announce/get/list/fork,唯一能把会话从内存里移除的路径是 enter() 返回的 detach 闭包(由 agent-loop 的 teardown 持有,而 API 会话控制器 resumeObserved 拿到的 AgentHandle.dispose 被丢掉了)。因此任何在 GUI 里打开过、提问过的会话都会常驻宿主进程直到进程退出,session.list 每次都把它报回来。
只要它在列表里、又不属于任何工作区,侧栏就会按“未分组”渲染(dsh-client-ui-workspace 的 owningGroupKey() 找不到工作区就回落到 UNGROUPED_KEY)。
1.2.2 的做法是先 detach 再删磁盘,客户端 handleSessionRemoved() 之后紧接着 refresh();而 ClientSessions.refreshList() 开头就把 mutation 日志重置(this.listMutations = mutations),刚记下的 remove 被丢掉,基线又把它加回来 → 幽灵行出现在“未分组”。
1.2.3 改用 archiveSession 当墓碑:默认视图确实不显示,但归档集合同时也是“显示已归档”视图的数据源 —— 用户一切到那个筛选(archivedFilter 会持久化在 dsh.workspace.view.v5),被删的会话就变成一条永久灰行,而且 archivedSessionIds 会一直积垃圾。
1.3.0 因此把墓碑搬到插件自己名下:
- 宿主删除时只做干净的注册表清理:unpin →(若已被 1.2.3 归档则 unarchive)→ 逐工作区 detach,不再调用
archiveSession; - 同时把 id 写进
$DSH_HOME/dsh-session-delete/tombstones.json(临时文件 + rename 原子写),并通过GET /session-delete/api/tombstones交给浏览器; - 浏览器半订阅
sessions.list,目录每次变化(refresh、重连、宿主推送)后把墓碑 id 用handleSessionRemoved()再剔除一遍 —— 行不再回来,也不依赖任何视图筛选; - 首次访问该接口时,把
archivedSessionIds中“仍存活 + 磁盘日志已不在”的 id 视为 1.2.3 遗留:unarchiveSession+ 转入墓碑文件(legacyArchiveSwept只做一次),用户不会在“显示已归档”里看到旧灰行; - 墓碑随宿主重启自然失效:重启后该 id 既不在内存也不在磁盘,
tombstonesForClient()会把它剔除,文件不会无限增长。
安装
需要 DeepSeek Harness,Node.js ≥ 22.5(用到 node:sqlite;DSH 自带 Node 24)。
git clone https://github.com/LIQiang-IT/dsh-session-delete.git
然后在 DSH 里用 插件管理 / plugin_manager 的 install_bundle 指向克隆下来的目录安装(不要手改 profile 的 package.json)。首次安装后需要重启一次 DSH 进程(restartReason: package-moved),再刷新一次 Web UI 让 client.js 生效。
手动兜底(仅在插件管理不可用时):在 profile 的 package.json 里加依赖 "dsh-session-delete": "file:<克隆目录的绝对路径>",并把 "dsh-session-delete" 加进 dsh.profile.bundles,重新安装依赖后重启 DSH。
卸载:从 profile 的 dsh.profile.bundles 与 dependencies 移除该条目,重装依赖并重启;插件不在磁盘上留私货。
宿主侧改动即时生效(dev loop)
宿主进程只在启动时 import 一次插件模块,而 DSH 的 HMR 监视器忽略 node_modules,所以正常改完 index.js 必须重启。本插件自己解决这个问题:
apply()里启动了源文件监视器(node:fs的watch,只看同目录的index.js,300 ms 防抖)。- 文件变化后以
import(路径 + '?v=<时间戳>')重新导入自己,把新的deleteSession()换进status.impl,HTTP 路由与session_delete工具都通过status.impl间接调用,因此行为立即跟着源码走。 - 重新导入失败(语法错误等)时不替换旧实现,把错误记在
status.lastReloadError,仍用旧代码继续服务。 GET /session-delete/api/health返回:version、generation(重载次数)、loadedAt/reloadedAt、loadedModuleMtimeMs/diskModuleMtimeMs、stale、lastReloadError。- 客户端在确认弹窗打开时读一次 health;若
stale === true或有lastReloadError,弹窗顶部用危险色提示“宿主插件仍在跑旧代码”,避免在不知情的情况下以为改的东西已经生效。 - 只有首次安装(bundle 尚未进入进程)需要重启一次;此后改
index.js不用重启。
客户端 client.js 属于浏览器侧模块:宿主会 stat 轮询客户端包入口文件并通过 /plugins/events 推送 rebuilt 帧,正常情况下开着的页面会自动热替换;若没换过来,刷新一次 Web UI(Ctrl+R)即可。
测试
node tests/delete-session.test.mjs # 54 项断言(scratch DSH_HOME,不碰真实数据)
node tests/reload.test.mjs # 7 项断言
npm test
tests/delete-session.test.mjs:非法 id 拒绝、dryRun不落盘且只列出待删任务、5 类磁盘目标删除、注册表清理(unpin → 必要时 unarchive → detach,且断言从不 archive)、墓碑文件写入、1.2.3 归档墓碑的一次性回收(含“只扫一次”)、定时任务真删、两个 sqlite 的按 id 清理、对照组(keep 会话)全部保留、重复删除幂等。tests/reload.test.mjs:挂载路由、health 初始状态、改文件后自动换模块(generation变 1、version变新值)、无重载错误、卸载释放路由。
测试全部在 mkdtemp 出来的临时 DSH_HOME 里跑,不读写真机数据。
结构
index.js— 宿主:HTTP 路由(/health、/preview、/delete、/tombstones)、session_delete工具、删除编排(deleteSession()是唯一实现)、自热重载与健康检查。client.js— 客户端:会话右键菜单项 + 确认弹窗(shell.overlay,零 Harness 依赖,只用react)。locale/{zh,en}.json— 插件显示元数据;界面文案在client.js内注册到 locale 服务(ctx.locale.register)。
安全
- 会话 ID 先过
^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$,显式拒绝.与..,用户输入不参与路径拼接。 - 所有目标路径都由
join(DSH_HOME, …)构造,只落在这五类位置;存在性检查用lstat(不跟随符号链接)。 - 不删除
attachments(内容寻址共享),不猜测未知目录。 dryRun完全只读:只列出目标,不写磁盘、不发事件。
License
MIT © 2026 LIQiang-IT
Versions
| Latest version | Published | Size |
|---|---|---|
| 1.2.2 | — | — |
Comments
Loading…
Similar plugins
Session management for DSH: archive or delete one session, archive/delete all sessions in a workspace, and restore archived sessions from the settings page — archiving backs up workspace metadata and
★ 0
↓ 283/wk
dsh plugin --profile web add dsh-session-deleteAdds a Delete session item to the sidebar session row menu that permanently removes the session log directory, projection cache and archive/pin membership and drops its row from the sidebar, plus an a
★ 0
dsh plugin --profile web add dsh-archive-workbenchManage and delete archived DSH conversations: a Settings page lists every archived session with per-row and bulk delete, and the sidebar session menu gains a Delete row next to Unarchive. Deletion is
★ 0
dsh plugin --profile web add dsh-archived-sessionsby Linusteller
DeepSeek Harness 插件:侧栏会话菜单「删除会话」(永久删除,非归档)
★ 6
↓ 417/wk
MIT
JavaScript
Oct 22, 2026
dsh plugin --profile web add dsh-delete-sessionsby rhl88
Deletes a session from the sidebar session menu after a confirmation dialog, removing its log directory, projection-cache record and workspace/pin/archive accounting; registry calls are timeout-guarde
★ 0
MIT
JavaScript
Oct 13, 2026
dsh plugin --profile web add dsh-session-removeby mcf171
Permanently delete a session from the session row menu — archives the id, removes the log directory and drops the row at once, with a Delete shortcut; built only on shipped extension points, and a ses
★ 0
MIT
JavaScript
Oct 16, 2026
dsh plugin --profile web add @mcf171/dsh-session-delete