dsh-delete-session 0.1.2 → 0.1.4
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 +155 -50
- package/package.json +1 -2
- package/src/client.js +62 -20
- package/src/index.js +31 -17
- package/README.zh.md +0 -52
package/README.md
CHANGED
|
@@ -1,64 +1,169 @@
|
|
|
1
1
|
# dsh-delete-session
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
3
|
+
**DeepSeek Harness 会话删除插件 —— 在侧边栏会话菜单里直接删除会话。** 给 DeepSeek Harness (dsh) Web 侧边栏的会话 `...` 菜单(重命名 / 分叉 / 归档)补上「删除会话」:确认一次后可直接删除,真正删除会话日志、工作区记账与宿主内存中的会话状态。
|
|
4
|
+
|
|
5
|
+
[中文](#中文) · [English](#english)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 中文
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
<a href="https://raw.githubusercontent.com/DDDMUC/dsh-delete-session/main/assets/menu.jpg">
|
|
13
|
+
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-delete-session/main/assets/menu.jpg" alt="侧边栏会话菜单里的删除会话" width="820" />
|
|
14
|
+
</a>
|
|
15
|
+
<br>
|
|
16
|
+
<sub>▲ 侧边栏会话菜单里的「删除会话」(红色)</sub>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
### 为什么需要它
|
|
20
|
+
|
|
21
|
+
DSH 侧边栏的会话菜单只有**重命名 / 分叉 / 归档**——归档只是把会话藏起来,**不删数据**;而插件dsh-web里的全家桶里的「会话归档管理」在设置深处,删一个会话要跳好几个界面。
|
|
22
|
+
|
|
23
|
+
这个插件把「删除」放回你最常点的位置:会话行的 `...` 菜单。
|
|
24
|
+
|
|
25
|
+
### 特性
|
|
26
|
+
|
|
27
|
+
- **菜单内删除** —— 侧边栏会话 `...` 菜单直接多出「删除会话」;会话 ID 从菜单的 React fiber 读取,永远作用于你点的那一行,**不会切换当前会话**
|
|
28
|
+
- **风险确认** —— 首次删除弹出确认对话框:显示会话标题与 ID,勾选「我已了解,永久删除」后确认按钮才可用
|
|
29
|
+
- **确认一次后可跳过** —— 对话框里勾选「不再询问,以后直接删除」,之后点菜单项直接删除(左下角 toast 提示);**按住 Shift 点击**可临时恢复弹窗;清除 `localStorage['dsh-delete-session:skip-confirm']` 可永久恢复
|
|
30
|
+
- **真正的删除** —— 停止运行中的 agent(cancel + 等待空闲)→ flush / detach 活跃会话 → 删除磁盘会话目录(原始 ID 与 `session-` 前缀两种写法)→ 持久化服务复核 → 清理工作区记账,侧栏不会残留「未分组」孤儿
|
|
31
|
+
- **默认安全** —— 宿主路由仅限本机回环(回环 socket + 回环 Host 头 + 同源校验);被 DSH 打开占用的会话会被明确拒绝(409),绝不与活跃写者竞争
|
|
32
|
+
- **中英双语** —— 菜单项与对话框跟随 DSH 界面语言(zh / en)
|
|
33
|
+
- **零依赖** —— 不引入任何 DSH SDK,所有服务(`sessions` / `sessionPersistence` / `agents` / `workspaceRegistry` / `webServer`)都在调用时通过 cordis 上下文获取
|
|
34
|
+
|
|
35
|
+
### 安装
|
|
36
|
+
|
|
37
|
+
npm(推荐):
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
dsh plugin --profile web add dsh-delete-session
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
或从 GitHub 仓库直接安装:
|
|
32
44
|
|
|
33
45
|
```sh
|
|
34
46
|
dsh plugin --profile web add github:DDDMUC/dsh-delete-session
|
|
35
47
|
```
|
|
36
48
|
|
|
37
|
-
|
|
49
|
+
重启 `dsh web` 后生效。
|
|
50
|
+
|
|
51
|
+
### 使用
|
|
52
|
+
|
|
53
|
+
1. 把鼠标移到侧边栏的会话行,点 `...`(会话操作)
|
|
54
|
+
2. 选择底部的「删除会话」
|
|
55
|
+
3. 首次:勾选「我已了解,永久删除」(想省事可同时勾选「不再询问,以后直接删除」)→ 点「删除」
|
|
56
|
+
4. 之后:直接删除,左下角出现 toast 提示
|
|
57
|
+
|
|
58
|
+
<div align="center">
|
|
59
|
+
<a href="https://raw.githubusercontent.com/DDDMUC/dsh-delete-session/main/assets/dialog.jpg">
|
|
60
|
+
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-delete-session/main/assets/dialog.jpg" alt="删除确认对话框" width="560" />
|
|
61
|
+
</a>
|
|
62
|
+
<br>
|
|
63
|
+
<sub>▲ 删除确认对话框(首次删除)</sub>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
### 工作原理
|
|
67
|
+
|
|
68
|
+
- `src/index.js`(宿主):注册一条仅限回环的路由 `POST /dsh-delete-session/delete` `{ sessionId }`,执行删除链路
|
|
69
|
+
- `src/client.js`(浏览器):经典客户端 bundle——监听 portal 到 body 的会话菜单(`body > [role="menu"]`),沿 React fiber 链读取会话节点(`props.node.id`),克隆原生菜单行保持样式,弹出确认对话框
|
|
70
|
+
- 删除链路:停 agent → flush / detach 活跃会话 → 写所有权探测(被占用 → 409)→ 删除目录(两种 ID 写法 + 复核)→ 清理工作区记账
|
|
71
|
+
|
|
72
|
+
### 已知限制
|
|
73
|
+
|
|
74
|
+
- 被 DSH 当前打开占用的会话:删除会自动等待写所有权释放(通常几秒)后完成;极少数仍被占用的情况会提示稍后重试或重启 DSH
|
|
75
|
+
- 菜单注入是 DOM shim:核心 UI 若调整菜单结构或行 fiber 形状,可能不再注入菜单项(不影响其他功能)
|
|
76
|
+
- 删除不可恢复:没有回收站,也没有撤销
|
|
77
|
+
|
|
78
|
+
### 兼容性
|
|
79
|
+
|
|
80
|
+
- DSH `0.1.5-rc.1` 实测通过
|
|
81
|
+
- 宿主链路对缺少服务的旧版本会退化为纯文件系统清理
|
|
82
|
+
|
|
83
|
+
如果这个插件帮到了你,欢迎给仓库点个 ⭐([GitHub](https://github.com/DDDMUC/dsh-delete-session))——星标是开发者继续维护的最大动力,感谢支持!
|
|
84
|
+
|
|
85
|
+
### License
|
|
86
|
+
|
|
87
|
+
MIT
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## English
|
|
92
|
+
|
|
93
|
+
<div align="center">
|
|
94
|
+
<a href="https://raw.githubusercontent.com/DDDMUC/dsh-delete-session/main/assets/menu.jpg">
|
|
95
|
+
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-delete-session/main/assets/menu.jpg" alt="Delete session in the sidebar menu" width="820" />
|
|
96
|
+
</a>
|
|
97
|
+
<br>
|
|
98
|
+
<sub>▲ "Delete session" (red) in the sidebar session menu</sub>
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
### Why you need it
|
|
102
|
+
|
|
103
|
+
The DSH sidebar session menu only offers **Rename / Fork / Archive** — archive merely hides a session and keeps every byte on disk, while the session archive manager inside the dsh-web plugin suite lives deep in Settings and takes several screens to reach.
|
|
104
|
+
|
|
105
|
+
This plugin puts Delete back where you already click: the session row's `...` menu.
|
|
106
|
+
|
|
107
|
+
### Features
|
|
108
|
+
|
|
109
|
+
- **Delete from the menu** — a "Delete session" row appears in the sidebar session `...` menu; the session id is read from the menu's React fiber, so the action always targets the row you clicked and **never switches the active conversation**
|
|
110
|
+
- **Risk consent** — the first delete opens a confirmation dialog with the session title and id; the confirm button unlocks only after ticking "I understand"
|
|
111
|
+
- **Confirm once, then skip** — tick "Don't ask again" and later deletes run directly from the menu (a toast reports the result); **hold Shift while clicking** to force the dialog back, or clear `localStorage['dsh-delete-session:skip-confirm']` to restore it permanently
|
|
112
|
+
- **Real deletion** — stops a running agent (cancel + quiescence), flushes and detaches the live session, removes the on-disk session directories (both the raw and `session-` prefixed id), verifies through the persistence service, then cleans workspace accounting so no orphan shows up under "Ungrouped"
|
|
113
|
+
- **Safe by default** — the host route is loopback-only (loopback socket, loopback Host header, same-origin check); a session still held open by DSH is refused with 409 instead of racing the active writer
|
|
114
|
+
- **Bilingual** — the menu item and dialog follow the DSH interface language (zh / en)
|
|
115
|
+
- **Zero dependencies** — no DSH SDK imports; every service (`sessions`, `sessionPersistence`, `agents`, `workspaceRegistry`, `webServer`) is resolved through the cordis context at call time
|
|
116
|
+
|
|
117
|
+
### Install
|
|
118
|
+
|
|
119
|
+
From npm (recommended):
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
dsh plugin --profile web add dsh-delete-session
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Or straight from the GitHub repository:
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
dsh plugin --profile web add github:DDDMUC/dsh-delete-session
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Restart `dsh web` to apply.
|
|
132
|
+
|
|
133
|
+
### Usage
|
|
134
|
+
|
|
135
|
+
1. Hover a session row in the sidebar and click `...` (session actions)
|
|
136
|
+
2. Pick "Delete session" at the bottom
|
|
137
|
+
3. First time: tick "I understand - delete permanently" (tick "Don't ask again" too if you like) and confirm
|
|
138
|
+
4. Afterwards: the session is deleted directly, with a toast
|
|
139
|
+
|
|
140
|
+
<div align="center">
|
|
141
|
+
<a href="https://raw.githubusercontent.com/DDDMUC/dsh-delete-session/main/assets/dialog.jpg">
|
|
142
|
+
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-delete-session/main/assets/dialog.jpg" alt="Delete confirmation dialog" width="560" />
|
|
143
|
+
</a>
|
|
144
|
+
<br>
|
|
145
|
+
<sub>▲ The confirmation dialog (first delete)</sub>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
### How it works
|
|
149
|
+
|
|
150
|
+
- `src/index.js` (host): one loopback-only route `POST /dsh-delete-session/delete` `{ sessionId }` runs the deletion pipeline
|
|
151
|
+
- `src/client.js` (browser): a classic client bundle — watches for the portalled session menu (`body > [role="menu"]`), walks the React fiber chain to the session node (`props.node.id`), clones a native menu row for styling, and opens the confirmation dialog
|
|
152
|
+
- Pipeline: stop agent → flush / detach live session → write-lease probe (busy → 409) → remove directories (both id spellings + verification) → clean workspace accounting
|
|
153
|
+
|
|
154
|
+
### Known limitations
|
|
38
155
|
|
|
39
|
-
|
|
156
|
+
- A session DSH currently holds open: the delete waits for the write lease to be released (usually a few seconds) and then completes; in the rare case it stays busy, the dialog asks you to retry later or restart DSH
|
|
157
|
+
- The menu injection is a DOM shim: core UI changes to the menu markup or row fiber shape may stop the item from being injected (nothing else breaks)
|
|
158
|
+
- Deletion is permanent: there is no trash bin and no undo
|
|
40
159
|
|
|
41
|
-
|
|
42
|
-
`POST /dsh-delete-session/delete` `{ sessionId }`.
|
|
43
|
-
- `src/client.js` (browser) is a classic client bundle: it watches for the
|
|
44
|
-
portalled session menu (`body > [role="menu"]`), walks the React fiber chain
|
|
45
|
-
to the session node (`props.node.id`), clones a native menu row for styling,
|
|
46
|
-
and opens the confirmation dialog.
|
|
47
|
-
- No DSH SDK imports: every service (`sessions`, `sessionPersistence`,
|
|
48
|
-
`agents`, `workspaceRegistry`, `webServer`) is resolved through the cordis
|
|
49
|
-
context at call time, and the plugin degrades to filesystem cleanup when a
|
|
50
|
-
service is absent.
|
|
160
|
+
### Compatibility
|
|
51
161
|
|
|
52
|
-
|
|
162
|
+
- Tested on DSH `0.1.5-rc.1`
|
|
163
|
+
- On older versions without the services, the host pipeline degrades to filesystem cleanup
|
|
53
164
|
|
|
54
|
-
|
|
55
|
-
exposes no public way to release the write ownership, so the request is
|
|
56
|
-
refused with a message asking to restart DSH and retry.
|
|
57
|
-
- The sidebar menu injection is a DOM shim. Core UI changes to the menu markup
|
|
58
|
-
or the row fiber shape may require a plugin update; the menu item is simply
|
|
59
|
-
not injected when the contract changes, and nothing else breaks.
|
|
60
|
-
- Deletion is permanent. There is no trash bin and no undo.
|
|
165
|
+
If this plugin has been helpful, a ⭐ on [GitHub](https://github.com/DDDMUC/dsh-delete-session) would mean a lot — it is the biggest motivation for the developer to keep maintaining it. Thank you!
|
|
61
166
|
|
|
62
|
-
|
|
167
|
+
### License
|
|
63
168
|
|
|
64
169
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-delete-session",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Delete sessions from the DSH Web sidebar: adds a Delete action to the session row menu with a risk-consent dialog, then removes the session log, workspace accounting and live session state.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"src",
|
|
14
14
|
"cordis.patch.yml",
|
|
15
15
|
"README.md",
|
|
16
|
-
"README.zh.md",
|
|
17
16
|
"LICENSE"
|
|
18
17
|
],
|
|
19
18
|
"keywords": [
|
package/src/client.js
CHANGED
|
@@ -27,9 +27,10 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
confirm: '删除',
|
|
28
28
|
deleting: '删除中…',
|
|
29
29
|
ack: '我已了解,永久删除',
|
|
30
|
+
dontAsk: '不再询问,以后直接删除',
|
|
30
31
|
done: '已删除会话',
|
|
31
32
|
failed: '删除失败:',
|
|
32
|
-
busy: '该会话正被 DSH
|
|
33
|
+
busy: '该会话正被 DSH 打开,删除未能完成;请稍后重试(通常几秒后即可),或重启 DSH 后再试。',
|
|
33
34
|
notFound: '未找到该会话(可能已被删除)。',
|
|
34
35
|
untitled: '未命名会话',
|
|
35
36
|
}
|
|
@@ -42,9 +43,10 @@ window.__ModuleLoader__.load({
|
|
|
42
43
|
confirm: 'Delete',
|
|
43
44
|
deleting: 'Deleting...',
|
|
44
45
|
ack: 'I understand - delete permanently',
|
|
46
|
+
dontAsk: "Don't ask again",
|
|
45
47
|
done: 'Session deleted',
|
|
46
48
|
failed: 'Delete failed: ',
|
|
47
|
-
busy: 'This session is currently open in DSH
|
|
49
|
+
busy: 'This session is currently open in DSH; the delete did not complete. Try again in a moment (usually a few seconds), or restart DSH and retry.',
|
|
48
50
|
notFound: 'Session not found (it may already be deleted).',
|
|
49
51
|
untitled: 'Untitled session',
|
|
50
52
|
}
|
|
@@ -52,6 +54,49 @@ window.__ModuleLoader__.load({
|
|
|
52
54
|
let localeSvc = null
|
|
53
55
|
let sessionsSvc = null
|
|
54
56
|
|
|
57
|
+
// Once the user ticks "don't ask again" the confirmation dialog is
|
|
58
|
+
// skipped and the menu item deletes directly. Shift+click always opens
|
|
59
|
+
// the dialog again, and clearing the key in localStorage restores it.
|
|
60
|
+
const SKIP_KEY = 'dsh-delete-session:skip-confirm'
|
|
61
|
+
|
|
62
|
+
function skipConfirm() {
|
|
63
|
+
try { return localStorage.getItem(SKIP_KEY) === '1' } catch { return false }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function setSkipConfirm() {
|
|
67
|
+
try { localStorage.setItem(SKIP_KEY, '1') } catch { /* private mode: ignore */ }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function postDelete(sessionId) {
|
|
71
|
+
return fetch('/dsh-delete-session/delete', {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: { 'content-type': 'application/json' },
|
|
74
|
+
body: JSON.stringify({ sessionId }),
|
|
75
|
+
}).then(async (res) => {
|
|
76
|
+
let data = {}
|
|
77
|
+
try { data = await res.json() } catch { /* keep {} */ }
|
|
78
|
+
if (!res.ok || !data.ok) {
|
|
79
|
+
const code = data && data.code
|
|
80
|
+
const message = code === 'busy'
|
|
81
|
+
? t('busy')
|
|
82
|
+
: code === 'not-found'
|
|
83
|
+
? t('notFound')
|
|
84
|
+
: (data && data.error) || `HTTP ${res.status}`
|
|
85
|
+
throw new Error(message)
|
|
86
|
+
}
|
|
87
|
+
return data
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function deleteNow(info) {
|
|
92
|
+
postDelete(info.id)
|
|
93
|
+
.then(() => {
|
|
94
|
+
toast(t('done'))
|
|
95
|
+
refreshList()
|
|
96
|
+
})
|
|
97
|
+
.catch((reason) => toast(t('failed') + String((reason && reason.message) || reason), true))
|
|
98
|
+
}
|
|
99
|
+
|
|
55
100
|
function browserLang() {
|
|
56
101
|
if (typeof navigator === 'undefined') return 'zh'
|
|
57
102
|
for (const tag of (navigator.languages || []).concat([navigator.language])) {
|
|
@@ -188,6 +233,15 @@ window.__ModuleLoader__.load({
|
|
|
188
233
|
ack.appendChild(checkbox)
|
|
189
234
|
ack.appendChild(ackText)
|
|
190
235
|
|
|
236
|
+
const skip = document.createElement('label')
|
|
237
|
+
skip.className = 'dsdel-ack'
|
|
238
|
+
const skipBox = document.createElement('input')
|
|
239
|
+
skipBox.type = 'checkbox'
|
|
240
|
+
const skipText = document.createElement('span')
|
|
241
|
+
skipText.textContent = t('dontAsk')
|
|
242
|
+
skip.appendChild(skipBox)
|
|
243
|
+
skip.appendChild(skipText)
|
|
244
|
+
|
|
191
245
|
const error = document.createElement('p')
|
|
192
246
|
error.className = 'dsdel-error'
|
|
193
247
|
error.style.display = 'none'
|
|
@@ -210,6 +264,7 @@ window.__ModuleLoader__.load({
|
|
|
210
264
|
dialog.appendChild(meta)
|
|
211
265
|
dialog.appendChild(text)
|
|
212
266
|
dialog.appendChild(ack)
|
|
267
|
+
dialog.appendChild(skip)
|
|
213
268
|
dialog.appendChild(error)
|
|
214
269
|
dialog.appendChild(actions)
|
|
215
270
|
backdrop.appendChild(dialog)
|
|
@@ -232,23 +287,9 @@ window.__ModuleLoader__.load({
|
|
|
232
287
|
cancel.disabled = true
|
|
233
288
|
confirm.textContent = t('deleting')
|
|
234
289
|
error.style.display = 'none'
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
body: JSON.stringify({ sessionId: info.id }),
|
|
239
|
-
})
|
|
240
|
-
.then(async (res) => {
|
|
241
|
-
let data = {}
|
|
242
|
-
try { data = await res.json() } catch { /* keep {} */ }
|
|
243
|
-
if (!res.ok || !data.ok) {
|
|
244
|
-
const code = data && data.code
|
|
245
|
-
const message = code === 'busy'
|
|
246
|
-
? t('busy')
|
|
247
|
-
: code === 'not-found'
|
|
248
|
-
? t('notFound')
|
|
249
|
-
: (data && data.error) || `HTTP ${res.status}`
|
|
250
|
-
throw new Error(message)
|
|
251
|
-
}
|
|
290
|
+
if (skipBox.checked) setSkipConfirm()
|
|
291
|
+
postDelete(info.id)
|
|
292
|
+
.then(() => {
|
|
252
293
|
backdrop.remove()
|
|
253
294
|
toast(t('done'))
|
|
254
295
|
refreshList()
|
|
@@ -298,7 +339,8 @@ window.__ModuleLoader__.load({
|
|
|
298
339
|
e.stopPropagation()
|
|
299
340
|
e.preventDefault()
|
|
300
341
|
closeMenu()
|
|
301
|
-
|
|
342
|
+
if (skipConfirm() && !e.shiftKey) deleteNow(info)
|
|
343
|
+
else openDialog(info)
|
|
302
344
|
})
|
|
303
345
|
wrap.appendChild(button)
|
|
304
346
|
viewport.appendChild(wrap)
|
package/src/index.js
CHANGED
|
@@ -157,29 +157,43 @@ async function flushAndDetach(ctx, sessionId) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// Probe the persistence write lease. Holding it proves no active writer is
|
|
160
|
-
// around; it is released immediately.
|
|
161
|
-
//
|
|
162
|
-
//
|
|
160
|
+
// around; it is released immediately. Detaching a live session releases its
|
|
161
|
+
// lease asynchronously (session/disposed starts a persistence retirement), so
|
|
162
|
+
// the probe is retried with a short backoff before the request is refused -
|
|
163
|
+
// in practice the first click then succeeds without forcing anything.
|
|
164
|
+
const BUSY_RETRY_ATTEMPTS = 10
|
|
165
|
+
const BUSY_RETRY_DELAY_MS = 500
|
|
166
|
+
|
|
167
|
+
function sleep(ms) {
|
|
168
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
169
|
+
}
|
|
170
|
+
|
|
163
171
|
async function assertNoActiveWriter(ctx, sessionId) {
|
|
164
172
|
const sp = ctx.get('sessionPersistence')
|
|
165
173
|
if (!sp || typeof sp.open !== 'function') return false
|
|
166
|
-
let
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
} catch (error) {
|
|
170
|
-
const message = String((error && error.message) || error)
|
|
171
|
-
if (/own|busy|lock|hold|writer/i.test(message)) {
|
|
172
|
-
throw new HttpError(409, 'busy', 'session is currently open in DSH')
|
|
173
|
-
}
|
|
174
|
-
return false
|
|
175
|
-
} finally {
|
|
174
|
+
for (let attempt = 1; attempt <= BUSY_RETRY_ATTEMPTS; attempt += 1) {
|
|
175
|
+
let handle = null
|
|
176
|
+
let busy = false
|
|
176
177
|
try {
|
|
177
|
-
|
|
178
|
-
} catch {
|
|
179
|
-
|
|
178
|
+
handle = await sp.open(sessionId, 'write')
|
|
179
|
+
} catch (error) {
|
|
180
|
+
const message = String((error && error.message) || error)
|
|
181
|
+
if (/own|busy|lock|hold|writer/i.test(message)) {
|
|
182
|
+
busy = true
|
|
183
|
+
} else {
|
|
184
|
+
return false
|
|
185
|
+
}
|
|
186
|
+
} finally {
|
|
187
|
+
try {
|
|
188
|
+
if (handle && typeof handle.close === 'function') await handle.close()
|
|
189
|
+
} catch {
|
|
190
|
+
// lease release failure is harmless: the directory is removed next
|
|
191
|
+
}
|
|
180
192
|
}
|
|
193
|
+
if (!busy) return true
|
|
194
|
+
if (attempt < BUSY_RETRY_ATTEMPTS) await sleep(BUSY_RETRY_DELAY_MS)
|
|
181
195
|
}
|
|
182
|
-
|
|
196
|
+
throw new HttpError(409, 'busy', 'session is currently open in DSH')
|
|
183
197
|
}
|
|
184
198
|
|
|
185
199
|
async function detachFromWorkspace(ctx, sessionId) {
|
package/README.zh.md
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# dsh-delete-session
|
|
2
|
-
|
|
3
|
-
[English](README.md) | 中文
|
|
4
|
-
|
|
5
|
-
在 DSH Web 侧边栏直接删除会话:会话行的 `...` 菜单(重命名 / 分叉 / 归档)里会多出一项
|
|
6
|
-
**删除会话**。点击后弹出风险确认对话框(显示会话名称与 ID),确认后删除会话日志、
|
|
7
|
-
工作区记账与宿主内存中的会话状态。
|
|
8
|
-
|
|
9
|
-
为 DeepSeek Harness(DSH)Web 构建,已在 `0.1.5-rc.1` 上实测。
|
|
10
|
-
|
|
11
|
-
## 功能
|
|
12
|
-
|
|
13
|
-
- **侧边栏会话菜单里的「删除会话」**:无需切换会话(会话 ID 从菜单的 React fiber 读取,
|
|
14
|
-
永远作用于你点击的那一行)。
|
|
15
|
-
- **风险确认对话框**:显示会话标题与 ID;勾选「我已了解,永久删除」前确认按钮不可用。
|
|
16
|
-
- **真正的删除**:停止运行中的 agent(cancel + 等待空闲)、flush 并 detach 活跃会话、
|
|
17
|
-
删除磁盘上的全部会话目录(原始 ID 与 `session-` 前缀两种写法)、经持久化服务复核,
|
|
18
|
-
最后从工作区记账中移除,避免侧栏残留「未分组」孤儿。
|
|
19
|
-
- **默认安全**:宿主路由仅限本机回环(回环 socket + 回环 Host 头 + 同源校验);
|
|
20
|
-
被 DSH 打开占用中的会话会被明确拒绝,而不是与活跃写者竞争。
|
|
21
|
-
- **中英双语**:菜单项与对话框跟随 DSH 界面语言(存在 locale 服务时),否则按浏览器语言回退。
|
|
22
|
-
|
|
23
|
-
## 安装
|
|
24
|
-
|
|
25
|
-
```sh
|
|
26
|
-
dsh plugin --profile web add github:DDDMUC/dsh-delete-session
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
重启 `dsh web` 后,在侧边栏会话 `...` 菜单中即可看到「删除会话」。
|
|
30
|
-
|
|
31
|
-
## 工作原理
|
|
32
|
-
|
|
33
|
-
- `src/index.js`(宿主):注册一条仅限回环的路由
|
|
34
|
-
`POST /dsh-delete-session/delete` `{ sessionId }`。
|
|
35
|
-
- `src/client.js`(浏览器):经典客户端 bundle——监听 portal 到 body 的会话菜单
|
|
36
|
-
(`body > [role="menu"]`),沿 React fiber 链读取会话节点(`props.node.id`),
|
|
37
|
-
克隆原生菜单行保持样式一致,然后打开确认对话框。
|
|
38
|
-
- 不引入任何 DSH SDK:所有服务(`sessions`、`sessionPersistence`、`agents`、
|
|
39
|
-
`workspaceRegistry`、`webServer`)都在调用时通过 cordis 上下文获取;
|
|
40
|
-
服务缺失时退化为纯文件系统清理。
|
|
41
|
-
|
|
42
|
-
## 已知限制
|
|
43
|
-
|
|
44
|
-
- 被 DSH 当前打开占用的会话无法删除:运行时没有公开的写所有权释放入口,
|
|
45
|
-
因此会明确拒绝并提示「重启 DSH 后再试」。
|
|
46
|
-
- 侧边栏菜单注入是 DOM shim。核心 UI 若调整菜单结构或行 fiber 形状,可能需要插件跟进更新;
|
|
47
|
-
契约变化时插件只是不再注入菜单项,不会影响其他功能。
|
|
48
|
-
- 删除不可恢复:没有回收站,也没有撤销。
|
|
49
|
-
|
|
50
|
-
## License
|
|
51
|
-
|
|
52
|
-
MIT
|