@kangyishuai/dsh-session-delete 0.1.0 → 0.3.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/README.md +9 -7
- package/README.zh-CN.md +9 -7
- package/lib/agent-tool.js +173 -0
- package/lib/capability.js +2 -0
- package/lib/client.js +345 -1
- package/lib/index.js +3 -2
- package/lib/operations.js +375 -7
- package/lib/receipts.js +65 -0
- package/lib/service.js +149 -1
- package/lib/trash.js +5 -1
- package/locale/en.json +17 -1
- package/locale/zh.json +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai). Not affiliated with DeepSeek.
|
|
8
8
|
|
|
9
|
-
> **Status: v0.
|
|
9
|
+
> **Status: v0.3, early.** Verified on DSH 0.2.1-rc.5 with `pnpm smoke:session-delete` (23 end-to-end assertions) plus a manual pass in the desktop GUI. Treat it as young software and keep backups of anything you cannot lose.
|
|
10
10
|
|
|
11
11
|
## What it does
|
|
12
12
|
|
|
@@ -38,6 +38,8 @@ Restart the DSH desktop app afterwards. A fresh install adds a host half, so rel
|
|
|
38
38
|
|
|
39
39
|
## Usage
|
|
40
40
|
|
|
41
|
+
**Agent tool**: models can call `session_delete`, but only in two steps — `action=plan` returns the impact summary plus a single-use token (2 minutes), and `action=delete` needs that token. It refuses to delete the calling session, and a changed session invalidates the token. Deleting from the UI never requires the tool.
|
|
42
|
+
|
|
41
43
|
**Keyboard**: Tab between controls, Enter/Space to activate, Esc to close a dialog. In the trash panel, ↑/↓/Home/End move focus between rows. `⌘/Ctrl + Alt + T` opens the trash. There is no one-key delete shortcut — deletion always goes through the menu and a confirmation dialog.
|
|
42
44
|
|
|
43
45
|
**Refresh**: the trash panel has no refresh button. It loads on open and re-syncs every 5 seconds, when the window becomes visible again, and after every restore or permanent delete.
|
|
@@ -49,7 +51,7 @@ Everything starts from a session row in the sidebar:
|
|
|
49
51
|
2. The confirmation dialog shows:
|
|
50
52
|
- how much disk space the session occupies;
|
|
51
53
|
- whether the session is live (running turn, subagents, background jobs) — a live session is stopped first, not refused;
|
|
52
|
-
- how many sub-sessions it has (
|
|
54
|
+
- how many sub-sessions it has, with a checkbox to delete them together (off by default; each child goes to trash separately);
|
|
53
55
|
- the references that will be cleaned: archived set, pinned set, workspace membership, projection cache.
|
|
54
56
|
3. Confirm. The session moves to the trash and disappears from the sidebar.
|
|
55
57
|
4. **回收站…** (Trash…) in the same menu opens the trash panel, where you can:
|
|
@@ -58,6 +60,8 @@ Everything starts from a session row in the sidebar:
|
|
|
58
60
|
- **purge** it permanently;
|
|
59
61
|
- read the audit log.
|
|
60
62
|
|
|
63
|
+
**Health check**: the trash panel has a third tab. It reconciles the session store against the workspace bookkeeping and reports dangling references (archived/pinned ghosts, workspace membership, orphan session dirs, broken trash entries, unfinished operations). Cleaning removes **bookkeeping only** — session files are never touched.
|
|
64
|
+
|
|
61
65
|
## Side effects & risks
|
|
62
66
|
|
|
63
67
|
Files and directories it touches:
|
|
@@ -93,7 +97,7 @@ v0.1 declares no `engines.dsh` range. Instead there are three layers of defense:
|
|
|
93
97
|
|
|
94
98
|
| Plugin | Verified on DSH | Notes |
|
|
95
99
|
| ------ | ------------------------ | ------------------------------------------------------------------------------------------- |
|
|
96
|
-
| 0.
|
|
100
|
+
| 0.3.0 | **0.2.1-rc.5** (desktop) | `pnpm smoke:session-delete`: 21 assertions green; manual GUI pass on the same host version. |
|
|
97
101
|
|
|
98
102
|
After a DSH upgrade: restart, then open the plugin status (settings → plugins). If it reports read-only mode, the host API changed — upgrade the plugin or report the version pair; don't force it.
|
|
99
103
|
|
|
@@ -108,13 +112,11 @@ After a DSH upgrade: restart, then open the plugin status (settings → plugins)
|
|
|
108
112
|
| Purge left something behind | Residue that the post-delete receipt lists | Read the receipt and the audit log, clean the listed path by hand, and open an issue with the receipt |
|
|
109
113
|
| The trash panel is empty after a delete | The plugin resolved a different data root than your DSH (`DSH_HOME` / config) | Look at `~/.dsh/session-trash/` on disk and check the plugin's `dataRoot` config |
|
|
110
114
|
|
|
111
|
-
## Roadmap (
|
|
115
|
+
## Roadmap (later releases)
|
|
112
116
|
|
|
113
|
-
The following are planned and
|
|
117
|
+
The following are planned and not implemented yet:
|
|
114
118
|
|
|
115
119
|
- batch deletion (multi-select);
|
|
116
|
-
- cascade deletion with a checkbox per sub-session;
|
|
117
|
-
- an agent tool (plan first, then delete);
|
|
118
120
|
- an undo toast after a delete.
|
|
119
121
|
|
|
120
122
|
## License
|
package/README.zh-CN.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
非官方 [DeepSeek Harness (DSH)](https://github.com/deepseek-ai) 插件,与 DeepSeek 无关。
|
|
8
8
|
|
|
9
|
-
> **状态:v0.
|
|
9
|
+
> **状态:v0.3,早期可用。** 已在 DSH 0.2.1-rc.5 上用 `pnpm smoke:session-delete`(23 项端到端断言)加一轮桌面版人工验收。仍是年轻软件,重要数据请自行备份。
|
|
10
10
|
|
|
11
11
|
## 做什么
|
|
12
12
|
|
|
@@ -38,6 +38,8 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
|
|
|
38
38
|
|
|
39
39
|
## 使用
|
|
40
40
|
|
|
41
|
+
**Agent 工具**:模型可以调用 `session_delete`,但必须两段式——`action=plan` 返回影响面摘要和一次性 token(2 分钟有效),`action=delete` 必须带这个 token。它拒绝删除调用者自己的会话,会话在此期间变化会让 token 失效。通过 UI 删除不需要这个工具。
|
|
42
|
+
|
|
41
43
|
**键盘**:Tab 在各按钮间移动,Enter/Space 触发,Esc 关闭对话框;回收站面板里可用 ↑/↓/Home/End 在条目间移动焦点;`⌘/Ctrl + Alt + T` 直接打开回收站。删除始终需要菜单 + 确认框,没有一键删除的快捷键。
|
|
42
44
|
|
|
43
45
|
**刷新**:回收站面板没有刷新按钮——打开时自动加载,之后每 5 秒、窗口重新可见、以及每次恢复/彻底删除后自动同步。
|
|
@@ -49,7 +51,7 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
|
|
|
49
51
|
2. 确认框会展示:
|
|
50
52
|
- 这条会话在磁盘上占多少体积;
|
|
51
53
|
- 会话是否 live(有没有在跑的轮次、子代理、后台任务)——live 会话会先被停下再删,而不是拒绝;
|
|
52
|
-
-
|
|
54
|
+
- 有几个子会话,并给一个勾选框决定是否一并删除(默认不勾;每个子会话单独进回收站);
|
|
53
55
|
- 将被清理的引用:归档集合、置顶集合、工作区归属、投影缓存。
|
|
54
56
|
3. 确认。会话进入回收站,侧栏里的那一行消失。
|
|
55
57
|
4. 同一个菜单里的「回收站…」打开回收站面板,可以:
|
|
@@ -58,6 +60,8 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
|
|
|
58
60
|
- **彻底删除**(不可恢复);
|
|
59
61
|
- 查看审计日志。
|
|
60
62
|
|
|
63
|
+
**体检**:回收站面板有第三个页签。它把会话存储与工作区记账对账,列出失效引用(归档/置顶幽灵、工作区记账、孤儿会话目录、损坏的回收站条目、未完成操作)。清理**只动登记表**,绝不删会话文件。
|
|
64
|
+
|
|
61
65
|
## 副作用与风险
|
|
62
66
|
|
|
63
67
|
会读写这些路径:
|
|
@@ -93,7 +97,7 @@ v0.1 没有声明 `engines.dsh` 版本范围,改用三层防线:
|
|
|
93
97
|
|
|
94
98
|
| 插件版本 | 已验证的 DSH 版本 | 说明 |
|
|
95
99
|
| -------- | ------------------------ | -------------------------------------------------------------------------------- |
|
|
96
|
-
| 0.
|
|
100
|
+
| 0.3.0 | **0.2.1-rc.5**(桌面版) | `pnpm smoke:session-delete` 21 项断言全绿,并在同一版本桌面版做过人工 GUI 验收。 |
|
|
97
101
|
|
|
98
102
|
DSH 升级之后:重启,然后看插件的状态条(设置 → 插件)。如果显示只读模式,说明宿主 API 变了——升级插件,或者把两个版本号一起报上来,别硬用。
|
|
99
103
|
|
|
@@ -108,13 +112,11 @@ DSH 升级之后:重启,然后看插件的状态条(设置 → 插件)
|
|
|
108
112
|
| 彻底删除后还残留东西 | 删除回执里列出的残留 | 对回执和审计日志,按回执里的路径手动清理,并把回执附在 issue 里 |
|
|
109
113
|
| 删完之后回收站是空的 | 插件解析到的数据根目录和你的 DSH 不是同一个(`DSH_HOME` / 配置) | 去磁盘上看 `~/.dsh/session-trash/`,再核对插件的 `dataRoot` 配置 |
|
|
110
114
|
|
|
111
|
-
##
|
|
115
|
+
## 计划中(后续版本)
|
|
112
116
|
|
|
113
|
-
|
|
117
|
+
下面这些是计划,尚未实现:
|
|
114
118
|
|
|
115
119
|
- 批量删除(多选);
|
|
116
|
-
- 子会话级联删除(逐个子会话勾选);
|
|
117
|
-
- agent 工具(先 plan 再删);
|
|
118
120
|
- 删除后的撤销 toast。
|
|
119
121
|
|
|
120
122
|
## License
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 模型工具的两段式控制器:先 plan 拿一次性 token,再 delete。
|
|
3
|
+
// 只做状态机与校验,不直接依赖 @deepseek-ai/*,方便单测。
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_TTL_MS = 120_000;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {object} options
|
|
10
|
+
* @param {{ plan: (sessionId: string) => Promise<any>, trash: (sessionId: string, request: any) => Promise<any> }} options.ops
|
|
11
|
+
* @param {() => number} [options.now]
|
|
12
|
+
* @param {number} [options.ttlMs]
|
|
13
|
+
*/
|
|
14
|
+
export function createAgentToolController({ ops, now = Date.now, ttlMs = DEFAULT_TTL_MS }) {
|
|
15
|
+
/** @type {Map<string, { sessionId: string, digest: string, cascade: boolean, expiresAt: number }>} */
|
|
16
|
+
const tokens = new Map();
|
|
17
|
+
|
|
18
|
+
/** @param {string} token */
|
|
19
|
+
function takeToken(token) {
|
|
20
|
+
const entry = tokens.get(token);
|
|
21
|
+
if (!entry) return { error: "invalid-token" };
|
|
22
|
+
tokens.delete(token);
|
|
23
|
+
if (entry.expiresAt < now()) return { error: "token-expired" };
|
|
24
|
+
return { entry };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 第一步:只读预览 + 发 token。
|
|
29
|
+
* @param {{ sessionId: string, cascade?: boolean }} args
|
|
30
|
+
*/
|
|
31
|
+
async function plan(args) {
|
|
32
|
+
const plan = await ops.plan(args.sessionId);
|
|
33
|
+
if (plan.blockers.length > 0) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
code: "blocked",
|
|
37
|
+
sessionId: plan.sessionId,
|
|
38
|
+
blockers: plan.blockers,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const token = randomUUID();
|
|
42
|
+
tokens.set(token, {
|
|
43
|
+
sessionId: plan.sessionId,
|
|
44
|
+
digest: plan.digest,
|
|
45
|
+
cascade: args.cascade === true,
|
|
46
|
+
expiresAt: now() + ttlMs,
|
|
47
|
+
});
|
|
48
|
+
// 简单上限,防止模型反复 plan 把内存撑大
|
|
49
|
+
while (tokens.size > 32) {
|
|
50
|
+
const oldest = tokens.keys().next().value;
|
|
51
|
+
if (oldest === undefined) break;
|
|
52
|
+
tokens.delete(oldest);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
ok: true,
|
|
56
|
+
sessionId: plan.sessionId,
|
|
57
|
+
title: plan.title,
|
|
58
|
+
sizeBytes: plan.sizeBytes,
|
|
59
|
+
live: plan.live,
|
|
60
|
+
children: plan.children.map((/** @type {any} */ child) => ({
|
|
61
|
+
id: child.id,
|
|
62
|
+
title: child.title,
|
|
63
|
+
})),
|
|
64
|
+
cascade: args.cascade === true,
|
|
65
|
+
digest: plan.digest,
|
|
66
|
+
token,
|
|
67
|
+
expiresAt: new Date(now() + ttlMs).toISOString(),
|
|
68
|
+
hint: "call this tool again with action=delete and the token to execute; the token is single-use and expires in 2 minutes",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 第二步:带 token 执行删除。
|
|
74
|
+
* @param {{ sessionId: string, token?: string, cascade?: boolean, callerSessionId?: string }} args
|
|
75
|
+
*/
|
|
76
|
+
async function remove(args) {
|
|
77
|
+
if (args.callerSessionId && args.callerSessionId === args.sessionId) {
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
code: "caller-session",
|
|
81
|
+
message: "refusing to delete the session that is calling this tool",
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (!args.token)
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
code: "token-required",
|
|
88
|
+
message: "call action=plan first to obtain a token",
|
|
89
|
+
};
|
|
90
|
+
const taken = takeToken(args.token);
|
|
91
|
+
if (taken.error)
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
code: taken.error,
|
|
95
|
+
message: "token is invalid or expired; run action=plan again",
|
|
96
|
+
};
|
|
97
|
+
const entry = /** @type {any} */ (taken.entry);
|
|
98
|
+
if (entry.sessionId !== args.sessionId) {
|
|
99
|
+
return { ok: false, code: "token-mismatch", message: "token was issued for another session" };
|
|
100
|
+
}
|
|
101
|
+
const plan = await ops.plan(args.sessionId);
|
|
102
|
+
if (plan.blockers.length > 0) {
|
|
103
|
+
return { ok: false, code: "blocked", blockers: plan.blockers };
|
|
104
|
+
}
|
|
105
|
+
if (plan.digest !== entry.digest) {
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
code: "stale-plan",
|
|
109
|
+
message: "session changed after the preview; run action=plan again",
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const result = await ops.trash(args.sessionId, {
|
|
113
|
+
digest: plan.digest,
|
|
114
|
+
cascade: args.cascade === true || entry.cascade === true,
|
|
115
|
+
operator: "agent",
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
ok: true,
|
|
119
|
+
sessionId: args.sessionId,
|
|
120
|
+
entryId: result.entryId,
|
|
121
|
+
receiptId: result.receiptId,
|
|
122
|
+
cascaded: result.cascaded,
|
|
123
|
+
removed: result.removed,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { plan, remove, size: () => tokens.size };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 生成给模型看的纯文本摘要。
|
|
132
|
+
* @param {any} planResult
|
|
133
|
+
* @returns {string}
|
|
134
|
+
*/
|
|
135
|
+
export function summarizePlanForModel(planResult) {
|
|
136
|
+
if (!planResult.ok) {
|
|
137
|
+
const blockers = (planResult.blockers ?? [])
|
|
138
|
+
.map((/** @type {any} */ item) => item.code)
|
|
139
|
+
.join(", ");
|
|
140
|
+
return (
|
|
141
|
+
"Delete preview failed: " +
|
|
142
|
+
(planResult.code || "blocked") +
|
|
143
|
+
(blockers ? " (" + blockers + ")" : "")
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
const parts = [
|
|
147
|
+
"Delete preview for " + (planResult.title || planResult.sessionId),
|
|
148
|
+
"size " +
|
|
149
|
+
(typeof planResult.sizeBytes === "number" ? planResult.sizeBytes + " bytes" : "unknown"),
|
|
150
|
+
];
|
|
151
|
+
if (planResult.live) parts.push("session is live");
|
|
152
|
+
if (planResult.children.length > 0) parts.push(planResult.children.length + " child session(s)");
|
|
153
|
+
parts.push("token " + planResult.token + " expires " + planResult.expiresAt);
|
|
154
|
+
return parts.join(" | ");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 把内部错误归一成模型能理解的返回:session/not-found → not-found。
|
|
159
|
+
* @param {unknown} error
|
|
160
|
+
* @returns {{ ok: false, code: string, message: string }}
|
|
161
|
+
*/
|
|
162
|
+
export function normalizeToolError(error) {
|
|
163
|
+
const raw = /** @type {any} */ (error);
|
|
164
|
+
const code =
|
|
165
|
+
typeof raw?.code === "string" && raw.code.startsWith("session/")
|
|
166
|
+
? raw.code.slice("session/".length)
|
|
167
|
+
: "error";
|
|
168
|
+
return {
|
|
169
|
+
ok: false,
|
|
170
|
+
code,
|
|
171
|
+
message: error instanceof Error ? error.message : String(error),
|
|
172
|
+
};
|
|
173
|
+
}
|
package/lib/capability.js
CHANGED
|
@@ -51,6 +51,7 @@ export function probeCapabilities(ctx) {
|
|
|
51
51
|
const checks = {
|
|
52
52
|
"persistence.stat": callable(persistence, "stat"),
|
|
53
53
|
"persistence.locate": callable(persistence, "locate"),
|
|
54
|
+
"persistence.list": callable(persistence, "list"),
|
|
54
55
|
"event.session-stop": typeof ctx?.parallel === "function",
|
|
55
56
|
"event.session-activity": typeof ctx?.waterfall === "function",
|
|
56
57
|
"sessions.get": callable(sessions, "get"),
|
|
@@ -76,6 +77,7 @@ export function probeCapabilities(ctx) {
|
|
|
76
77
|
let tier = "api";
|
|
77
78
|
const essential = ["persistence.stat", "workspace.archive", "workspace.unarchive"];
|
|
78
79
|
const convenient = [
|
|
80
|
+
"persistence.list",
|
|
79
81
|
"persistence.locate",
|
|
80
82
|
"storage.domain",
|
|
81
83
|
"sessions.detach",
|