dsh-workspace-curator 1.0.0 → 2.0.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 +112 -54
- package/client.js +407 -90
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +1 -1
- package/docs/demo-poster.png +0 -0
- package/docs/demo.gif +0 -0
- package/index.js +47 -15
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +8 -4
- package/pending-deletions.js +143 -0
- package/workspace-delete.js +189 -0
- package/docs/preview.svg +0 -44
package/client.js
CHANGED
|
@@ -12,6 +12,7 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
id: 'dsh-workspace-curator',
|
|
13
13
|
factory(require) {
|
|
14
14
|
const React = require('react')
|
|
15
|
+
const { createSnapshotStore } = require('@deepseek-ai/dsh-client-store')
|
|
15
16
|
const {
|
|
16
17
|
Button, Modal, Tooltip, relativeTime,
|
|
17
18
|
IconChevronUpOutlineRegular, IconChevronDownOutlineRegular,
|
|
@@ -65,18 +66,23 @@ window.__ModuleLoader__.load({
|
|
|
65
66
|
'badge.archived': '已归档',
|
|
66
67
|
'badge.pinned': '已置顶',
|
|
67
68
|
'badge.running': '运行中',
|
|
68
|
-
'confirm.workspace.title': '删除工作区?',
|
|
69
|
-
'confirm.workspace.body': '将把“{name}”从工作区列表中移除。文件夹与其会话都会保留,这些会话会显示在“未分组”下。',
|
|
70
|
-
'confirm.session.title': '永久删除此会话?',
|
|
71
|
-
'confirm.session.body': '“{name}”的会话日志会从磁盘移除,无法恢复。如果它包含子代理会话,这些子会话也会一并删除。只想隐藏请使用“归档”。',
|
|
72
69
|
'confirm.archive.title': '停止并归档此会话?',
|
|
73
70
|
'confirm.archive.body': '“{name}”仍在运行。归档会先停止它正在进行的工作,之后可在“全部对话(显示已归档)”中恢复;被停止的工作不会自动继续。',
|
|
74
71
|
'confirm.cancel': '取消',
|
|
75
|
-
'confirm.deleteWorkspace': '删除工作区',
|
|
76
|
-
'confirm.deleteSession': '永久删除',
|
|
77
72
|
'confirm.archiveAction': '停止并归档',
|
|
78
73
|
'confirm.deleting': '正在删除…',
|
|
79
74
|
'confirm.archiving': '正在停止并归档…',
|
|
75
|
+
'menu.deleteSession': '删除会话',
|
|
76
|
+
'menu.deleteWorkspace': '删除工作区',
|
|
77
|
+
'dialog.deleteSession.title': '删除会话?',
|
|
78
|
+
'dialog.deleteSession.body': '“{name}”的会话日志会从磁盘移除,无法恢复。如果它包含子代理会话,这些子会话也会一并删除。',
|
|
79
|
+
'dialog.deleteWorkspace.title': '删除工作区',
|
|
80
|
+
'dialog.deleteWorkspace.body': '将把“{name}”从工作区列表中删除,工作区下的会话将会被删除。',
|
|
81
|
+
'dialog.liveNote': '正在打开或运行的会话会先停止并从列表移除;磁盘日志将在重启 DSH 后清理。',
|
|
82
|
+
'dialog.workspaceCount': '共 {count} 个会话,将全部删除。',
|
|
83
|
+
'dialog.folderWarning': '工作区文件夹及其中的所有文件也会被永久删除,无法恢复。',
|
|
84
|
+
'dialog.deleteSession': '删除',
|
|
85
|
+
'dialog.deleteWorkspace': '确认删除',
|
|
80
86
|
'rename.title': '重命名工作区',
|
|
81
87
|
'rename.field': '工作区名称',
|
|
82
88
|
'rename.submit': '保存',
|
|
@@ -85,14 +91,16 @@ window.__ModuleLoader__.load({
|
|
|
85
91
|
'busy': '正在处理…',
|
|
86
92
|
'notice.workspaceAdded': '工作区已就绪。',
|
|
87
93
|
'notice.workspaceRenamed': '工作区已重命名。',
|
|
88
|
-
'notice.workspaceDeleted': '
|
|
94
|
+
'notice.workspaceDeleted': '工作区、文件夹及其会话已删除。',
|
|
89
95
|
'notice.sessionDeleted': '会话已从磁盘删除。',
|
|
90
96
|
'notice.sessionDeletedWarnings': '会话已删除,但部分引用未能清理:{message}',
|
|
91
97
|
'notice.sessionAlreadyGone': '该会话已不存在,列表已刷新。',
|
|
98
|
+
'notice.sessionQueued': '会话已删除;重启 DSH 后完成磁盘清理。',
|
|
99
|
+
'notice.workspaceQueued': '已删除 {total} 个会话并移除工作区;其中 {queued} 个打开中的会话将在重启 DSH 后完成磁盘清理。',
|
|
100
|
+
'notice.workspaceDeletedWarnings': '工作区已删除,但部分引用未能清理:{message}',
|
|
92
101
|
'notice.sessionArchived': '会话已归档。',
|
|
93
102
|
'notice.sessionUnarchived': '会话已取消归档。',
|
|
94
103
|
'err.generic': '操作失败:{message}',
|
|
95
|
-
'err.open': '该会话在当前 DSH 运行期间打开过,暂时无法安全删除。请重启 DSH 后再试,或改用“归档”。',
|
|
96
104
|
'err.active': '该会话仍有运行中的工作(回合、子代理、后台任务或定时提醒)。请先停止这些工作,或改用“归档”。',
|
|
97
105
|
'err.refresh': '登录状态可能已失效。请刷新页面或重新打开 DSH 链接后再试。',
|
|
98
106
|
'err.notFound': '该会话已不存在,列表已刷新。',
|
|
@@ -101,10 +109,14 @@ window.__ModuleLoader__.load({
|
|
|
101
109
|
'err.badId': '会话标识无效,未执行删除。',
|
|
102
110
|
'err.layout': '该会话的存储格式无法安全删除,已取消。',
|
|
103
111
|
'err.workspaceGone': '该工作区已不存在。',
|
|
112
|
+
'err.lastWorkspace': '这是最后一个工作区,无法删除。请先添加另一个工作区。',
|
|
104
113
|
'err.archiveActive': '会话仍在运行,无法归档。请先停止它的工作。',
|
|
105
114
|
'err.pickerUnavailable': '当前环境不支持系统目录选择器,请直接输入文件夹路径。',
|
|
106
115
|
'err.nameConflict': '已存在同名工作区,请换一个名称。',
|
|
107
116
|
'err.invalidPath': '该路径不是可用的文件夹。',
|
|
117
|
+
'err.protectedPath': '该文件夹受保护(当前工作目录、home、DSH 目录或安装目录),不能删除。',
|
|
118
|
+
'err.folderFailed': '会话已处理,但文件夹删除失败:{message}',
|
|
119
|
+
'err.workspaceDeleteFailed': '删除工作区失败:{message}',
|
|
108
120
|
'hint.archived': '已归档,取消归档后可打开',
|
|
109
121
|
'hint.checking': '正在检查删除服务…',
|
|
110
122
|
'hint.deleteUnavailable': '删除不可用:{reason}',
|
|
@@ -114,7 +126,7 @@ window.__ModuleLoader__.load({
|
|
|
114
126
|
'time.days': '{n} 天前',
|
|
115
127
|
'time.months': '{n} 个月前',
|
|
116
128
|
'time.years': '{n} 年前',
|
|
117
|
-
'footer.note': '
|
|
129
|
+
'footer.note': '删除会话只移除日志;删除工作区会同时删除其文件夹。打开中的会话会在重启 DSH 后完成磁盘清理。',
|
|
118
130
|
}
|
|
119
131
|
|
|
120
132
|
const en = {
|
|
@@ -148,18 +160,23 @@ window.__ModuleLoader__.load({
|
|
|
148
160
|
'badge.archived': 'Archived',
|
|
149
161
|
'badge.pinned': 'Pinned',
|
|
150
162
|
'badge.running': 'Running',
|
|
151
|
-
'confirm.workspace.title': 'Delete this workspace?',
|
|
152
|
-
'confirm.workspace.body': '“{name}” is removed from the workspace list. Its folder and sessions are kept; those sessions appear under “Ungrouped”.',
|
|
153
|
-
'confirm.session.title': 'Delete this session permanently?',
|
|
154
|
-
'confirm.session.body': 'The session log for “{name}” is removed from disk and cannot be recovered. Subagent sessions it contains are removed too. Use “Archive” to hide it instead.',
|
|
155
163
|
'confirm.archive.title': 'Stop and archive this session?',
|
|
156
164
|
'confirm.archive.body': '“{name}” is still running. Archiving first stops its work; you can restore it from “All conversations (including archived)”. Stopped work does not resume automatically.',
|
|
157
165
|
'confirm.cancel': 'Cancel',
|
|
158
|
-
'confirm.deleteWorkspace': 'Delete workspace',
|
|
159
|
-
'confirm.deleteSession': 'Delete permanently',
|
|
160
166
|
'confirm.archiveAction': 'Stop and archive',
|
|
161
167
|
'confirm.deleting': 'Deleting…',
|
|
162
168
|
'confirm.archiving': 'Stopping and archiving…',
|
|
169
|
+
'menu.deleteSession': 'Delete session',
|
|
170
|
+
'menu.deleteWorkspace': 'Delete workspace',
|
|
171
|
+
'dialog.deleteSession.title': 'Delete this session?',
|
|
172
|
+
'dialog.deleteSession.body': 'The session log for “{name}” is removed from disk and cannot be recovered. Subagent sessions it contains are removed too.',
|
|
173
|
+
'dialog.deleteWorkspace.title': 'Delete workspace',
|
|
174
|
+
'dialog.deleteWorkspace.body': '“{name}” will be removed from the workspace list, and its sessions will be deleted.',
|
|
175
|
+
'dialog.liveNote': 'Sessions that are open or running are stopped and removed from the list first; their logs are cleaned after DSH restarts.',
|
|
176
|
+
'dialog.workspaceCount': '{count} session(s) in total; all will be deleted.',
|
|
177
|
+
'dialog.folderWarning': 'The workspace folder and every file in it will also be permanently deleted and cannot be recovered.',
|
|
178
|
+
'dialog.deleteSession': 'Delete',
|
|
179
|
+
'dialog.deleteWorkspace': 'Confirm delete',
|
|
163
180
|
'rename.title': 'Rename workspace',
|
|
164
181
|
'rename.field': 'Workspace name',
|
|
165
182
|
'rename.submit': 'Save',
|
|
@@ -168,14 +185,16 @@ window.__ModuleLoader__.load({
|
|
|
168
185
|
'busy': 'Working…',
|
|
169
186
|
'notice.workspaceAdded': 'Workspace is ready.',
|
|
170
187
|
'notice.workspaceRenamed': 'Workspace renamed.',
|
|
171
|
-
'notice.workspaceDeleted': 'Workspace
|
|
188
|
+
'notice.workspaceDeleted': 'Workspace, its folder, and its sessions were deleted.',
|
|
172
189
|
'notice.sessionDeleted': 'Session removed from disk.',
|
|
173
190
|
'notice.sessionDeletedWarnings': 'Session removed, but some references could not be cleared: {message}',
|
|
174
191
|
'notice.sessionAlreadyGone': 'That session no longer exists; the list has been refreshed.',
|
|
192
|
+
'notice.sessionQueued': 'Session deleted; restart DSH to finish cleaning its disk log.',
|
|
193
|
+
'notice.workspaceQueued': 'Deleted {total} session(s) and removed the workspace; {queued} open session(s) are cleaned after DSH restarts.',
|
|
194
|
+
'notice.workspaceDeletedWarnings': 'Workspace removed, but some references could not be cleared: {message}',
|
|
175
195
|
'notice.sessionArchived': 'Session archived.',
|
|
176
196
|
'notice.sessionUnarchived': 'Session unarchived.',
|
|
177
197
|
'err.generic': 'Action failed: {message}',
|
|
178
|
-
'err.open': 'This session was opened during the current DSH run, so it cannot be deleted safely. Restart DSH and retry, or archive it instead.',
|
|
179
198
|
'err.active': 'This session still has running work (a turn, subagent, background job, or reminder). Stop that work first, or archive the session instead.',
|
|
180
199
|
'err.refresh': 'The browser session may have expired. Refresh the page or reopen the DSH link and try again.',
|
|
181
200
|
'err.notFound': 'That session no longer exists; the list has been refreshed.',
|
|
@@ -184,10 +203,14 @@ window.__ModuleLoader__.load({
|
|
|
184
203
|
'err.badId': 'Invalid session id; nothing was deleted.',
|
|
185
204
|
'err.layout': 'This session uses a storage format that cannot be removed safely; deletion was cancelled.',
|
|
186
205
|
'err.workspaceGone': 'That workspace no longer exists.',
|
|
206
|
+
'err.lastWorkspace': 'This is the only workspace and cannot be deleted. Add another workspace first.',
|
|
187
207
|
'err.archiveActive': 'The session is still running, so it cannot be archived. Stop its work first.',
|
|
188
208
|
'err.pickerUnavailable': 'This environment has no system folder picker; type the folder path instead.',
|
|
189
209
|
'err.nameConflict': 'A workspace with that name already exists.',
|
|
190
210
|
'err.invalidPath': 'That path is not a usable folder.',
|
|
211
|
+
'err.protectedPath': 'That folder is protected (a current working directory, home, or a DSH folder) and cannot be removed.',
|
|
212
|
+
'err.folderFailed': 'Sessions were handled, but the folder could not be removed: {message}',
|
|
213
|
+
'err.workspaceDeleteFailed': 'Deleting the workspace failed: {message}',
|
|
191
214
|
'hint.archived': 'Archived; unarchive to open',
|
|
192
215
|
'hint.checking': 'Checking the delete service…',
|
|
193
216
|
'hint.deleteUnavailable': 'Deletion is unavailable: {reason}',
|
|
@@ -197,7 +220,7 @@ window.__ModuleLoader__.load({
|
|
|
197
220
|
'time.days': '{n} days ago',
|
|
198
221
|
'time.months': '{n} months ago',
|
|
199
222
|
'time.years': '{n} years ago',
|
|
200
|
-
'footer.note': '
|
|
223
|
+
'footer.note': 'Deleting a session removes its log; deleting a workspace also removes its folder. Open sessions are cleaned after DSH restarts.',
|
|
201
224
|
}
|
|
202
225
|
|
|
203
226
|
/**
|
|
@@ -238,7 +261,6 @@ window.__ModuleLoader__.load({
|
|
|
238
261
|
/** Map one Host/Workspace failure to localized copy. */
|
|
239
262
|
function failureText(error, t) {
|
|
240
263
|
switch (errorCode(error)) {
|
|
241
|
-
case 'session/open': return t('err.open')
|
|
242
264
|
case 'session/active': return t('err.active')
|
|
243
265
|
case 'session/not-found': return t('err.notFound')
|
|
244
266
|
case 'session/bad-id': return t('err.badId')
|
|
@@ -249,6 +271,10 @@ window.__ModuleLoader__.load({
|
|
|
249
271
|
case 'workspace/name-conflict': return t('err.nameConflict')
|
|
250
272
|
case 'workspace/invalid-path': return t('err.invalidPath')
|
|
251
273
|
case 'workspace/session-active': return t('err.archiveActive')
|
|
274
|
+
case 'workspace/protected-path': return t('err.protectedPath')
|
|
275
|
+
case 'workspace/last-workspace': return t('err.lastWorkspace')
|
|
276
|
+
case 'workspace/folder-delete-failed': return t('err.folderFailed', { message: error?.message ?? String(error) })
|
|
277
|
+
case 'workspace/session-delete-failed': return t('err.workspaceDeleteFailed', { message: error?.message ?? String(error) })
|
|
252
278
|
case 'directory-picker/unavailable': return t('err.pickerUnavailable')
|
|
253
279
|
default: return t('err.generic', { message: error?.message ?? String(error) })
|
|
254
280
|
}
|
|
@@ -258,18 +284,18 @@ window.__ModuleLoader__.load({
|
|
|
258
284
|
* Call the Host delete endpoint. The connection layer authenticates the
|
|
259
285
|
* browser cookie before the handler runs.
|
|
260
286
|
* @param action - wire action.
|
|
261
|
-
* @param
|
|
287
|
+
* @param payload - action payload.
|
|
262
288
|
* @returns the parsed success payload.
|
|
263
289
|
* @throws an Error carrying the Host code.
|
|
264
290
|
*/
|
|
265
|
-
async function callAdmin(action,
|
|
291
|
+
async function callAdmin(action, requestPayload) {
|
|
266
292
|
const response = await fetch(ROUTE, {
|
|
267
293
|
method: 'POST',
|
|
268
294
|
headers: {
|
|
269
295
|
'content-type': 'application/json',
|
|
270
296
|
'x-workspace-curator': '1',
|
|
271
297
|
},
|
|
272
|
-
body: JSON.stringify({ action,
|
|
298
|
+
body: JSON.stringify({ action, ...requestPayload }),
|
|
273
299
|
})
|
|
274
300
|
const payload = await response.json().catch(() => null)
|
|
275
301
|
if (!response.ok || payload === null || payload.ok !== true) {
|
|
@@ -415,7 +441,7 @@ window.__ModuleLoader__.load({
|
|
|
415
441
|
}, t('rename')),
|
|
416
442
|
h(Button, {
|
|
417
443
|
size: 'sm', icon: h(IconTrashOutlineRegular, { size: 14 }),
|
|
418
|
-
disabled, style: { color: T.danger }, onClick: () => actions.remove(workspace),
|
|
444
|
+
disabled: disabled || deleteHint !== null, style: { color: T.danger }, onClick: () => actions.remove(workspace),
|
|
419
445
|
}, t('delete')))),
|
|
420
446
|
h('div', {
|
|
421
447
|
title: workspace.path,
|
|
@@ -446,7 +472,7 @@ window.__ModuleLoader__.load({
|
|
|
446
472
|
* Settings page body.
|
|
447
473
|
* @param props - shell close, injected services, and translator.
|
|
448
474
|
*/
|
|
449
|
-
function Page({ close, t, workspaces, sessions, uiWorkspace, subscribeLocale, localeRevision }) {
|
|
475
|
+
function Page({ close, t, workspaces, sessions, uiWorkspace, requestDeletion, subscribeLocale, localeRevision }) {
|
|
450
476
|
React.useSyncExternalStore(subscribeLocale, localeRevision)
|
|
451
477
|
const subscribeWorkspaces = React.useCallback(listener => workspaces.list.subscribe(listener), [workspaces])
|
|
452
478
|
const readWorkspaces = React.useCallback(() => workspaces.list.getSnapshot(), [workspaces])
|
|
@@ -582,14 +608,18 @@ window.__ModuleLoader__.load({
|
|
|
582
608
|
}, [busy, run, workspaceSnapshot, workspaces])
|
|
583
609
|
|
|
584
610
|
const requestRemove = React.useCallback((workspace) => {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
611
|
+
requestDeletion({
|
|
612
|
+
kind: 'workspace',
|
|
613
|
+
id: workspace.workspaceId,
|
|
614
|
+
title: workspace.title,
|
|
615
|
+
path: workspace.path,
|
|
616
|
+
count: workspace.sessionIds.length,
|
|
617
|
+
})
|
|
618
|
+
}, [requestDeletion])
|
|
588
619
|
|
|
589
620
|
const requestDelete = React.useCallback((session) => {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
}, [])
|
|
621
|
+
requestDeletion({ kind: 'session', id: session.id, title: session.displayTitle })
|
|
622
|
+
}, [requestDeletion])
|
|
593
623
|
|
|
594
624
|
const openSession = React.useCallback((sessionId) => {
|
|
595
625
|
uiWorkspace.openSession(sessionId)
|
|
@@ -615,45 +645,6 @@ window.__ModuleLoader__.load({
|
|
|
615
645
|
}, t('notice.sessionUnarchived'))
|
|
616
646
|
}, [busy, run, t, uiWorkspace])
|
|
617
647
|
|
|
618
|
-
const deleteSession = React.useCallback(async (sessionId) => {
|
|
619
|
-
setConfirmBusy(true)
|
|
620
|
-
setConfirmError(null)
|
|
621
|
-
try {
|
|
622
|
-
const result = await callAdmin('delete-session', sessionId)
|
|
623
|
-
await sessions.refresh().catch(() => {})
|
|
624
|
-
setConfirming(null)
|
|
625
|
-
if (Array.isArray(result.warnings) && result.warnings.length > 0) {
|
|
626
|
-
say(t('notice.sessionDeletedWarnings', { message: result.warnings.join('; ') }), 'error')
|
|
627
|
-
} else if (result.alreadyGone === true) {
|
|
628
|
-
say(t('notice.sessionAlreadyGone'))
|
|
629
|
-
} else {
|
|
630
|
-
say(t('notice.sessionDeleted'))
|
|
631
|
-
}
|
|
632
|
-
} catch (error) {
|
|
633
|
-
if (error instanceof TypeError) {
|
|
634
|
-
setConfirmError(t('err.unavailable', { message: error.message }))
|
|
635
|
-
} else {
|
|
636
|
-
setConfirmError(failureText(error, t))
|
|
637
|
-
}
|
|
638
|
-
} finally {
|
|
639
|
-
setConfirmBusy(false)
|
|
640
|
-
}
|
|
641
|
-
}, [say, sessions, t])
|
|
642
|
-
|
|
643
|
-
const deleteWorkspace = React.useCallback(async (workspaceId) => {
|
|
644
|
-
setConfirmBusy(true)
|
|
645
|
-
setConfirmError(null)
|
|
646
|
-
try {
|
|
647
|
-
await workspaces.delete(workspaceId)
|
|
648
|
-
setConfirming(null)
|
|
649
|
-
say(t('notice.workspaceDeleted'))
|
|
650
|
-
} catch (error) {
|
|
651
|
-
setConfirmError(failureText(error, t))
|
|
652
|
-
} finally {
|
|
653
|
-
setConfirmBusy(false)
|
|
654
|
-
}
|
|
655
|
-
}, [say, t, workspaces])
|
|
656
|
-
|
|
657
648
|
const stopAndArchive = React.useCallback(async (sessionId) => {
|
|
658
649
|
setConfirmBusy(true)
|
|
659
650
|
setConfirmError(null)
|
|
@@ -670,11 +661,9 @@ window.__ModuleLoader__.load({
|
|
|
670
661
|
|
|
671
662
|
const confirmAction = React.useCallback(() => {
|
|
672
663
|
const target = confirming
|
|
673
|
-
if (target === null || confirmBusy) return
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
else void stopAndArchive(target.id)
|
|
677
|
-
}, [confirmBusy, confirming, deleteSession, deleteWorkspace, stopAndArchive])
|
|
664
|
+
if (target === null || confirmBusy || target.kind !== 'archive') return
|
|
665
|
+
void stopAndArchive(target.id)
|
|
666
|
+
}, [confirmBusy, confirming, stopAndArchive])
|
|
678
667
|
|
|
679
668
|
const openRename = React.useCallback((workspace) => {
|
|
680
669
|
setRenaming(workspace)
|
|
@@ -711,21 +700,10 @@ window.__ModuleLoader__.load({
|
|
|
711
700
|
: deleteReady === false
|
|
712
701
|
? t('hint.deleteUnavailable', { reason: deleteReason })
|
|
713
702
|
: t('hint.checking')
|
|
714
|
-
const confirmTitle = confirming === null ? '' :
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
const
|
|
718
|
-
? t('confirm.workspace.body', { name: confirming.title })
|
|
719
|
-
: confirming.kind === 'session'
|
|
720
|
-
? t('confirm.session.body', { name: confirming.title })
|
|
721
|
-
: t('confirm.archive.body', { name: confirming.title })
|
|
722
|
-
const confirmLabel = confirming === null ? ''
|
|
723
|
-
: confirming.kind === 'workspace'
|
|
724
|
-
? t('confirm.deleteWorkspace')
|
|
725
|
-
: confirming.kind === 'session' ? t('confirm.deleteSession') : t('confirm.archiveAction')
|
|
726
|
-
const confirmProgress = confirmBusy
|
|
727
|
-
? (confirming?.kind === 'archive' ? t('confirm.archiving') : t('confirm.deleting'))
|
|
728
|
-
: confirmLabel
|
|
703
|
+
const confirmTitle = confirming === null ? '' : t('confirm.archive.title')
|
|
704
|
+
const confirmBody = confirming === null ? '' : t('confirm.archive.body', { name: confirming.title })
|
|
705
|
+
const confirmLabel = confirming === null ? '' : t('confirm.archiveAction')
|
|
706
|
+
const confirmProgress = confirmBusy ? t('confirm.archiving') : confirmLabel
|
|
729
707
|
|
|
730
708
|
const sessionList = (list) => list.map(session => h(SessionRow, {
|
|
731
709
|
key: session.id,
|
|
@@ -883,6 +861,150 @@ window.__ModuleLoader__.load({
|
|
|
883
861
|
renameError === null ? null : h('div', { role: 'alert', style: { fontSize: 12, lineHeight: '18px', color: T.danger } }, renameError)))
|
|
884
862
|
}
|
|
885
863
|
|
|
864
|
+
/**
|
|
865
|
+
* Global confirmation for Session/Workspace deletion, shared by the row
|
|
866
|
+
* menus and the Settings page. Rendered from `shell.overlay`.
|
|
867
|
+
*/
|
|
868
|
+
function DeleteDialog({ t, dialog, uiWorkspace, workspaces, sessions, callAdmin, notify }) {
|
|
869
|
+
const request = React.useSyncExternalStore(dialog.subscribe, dialog.getSnapshot)
|
|
870
|
+
const workspaceCount = React.useSyncExternalStore(
|
|
871
|
+
callback => workspaces.list.subscribe(callback),
|
|
872
|
+
() => workspaces.list.getSnapshot().items.length,
|
|
873
|
+
)
|
|
874
|
+
const [busy, setBusy] = React.useState(false)
|
|
875
|
+
const [error, setError] = React.useState(null)
|
|
876
|
+
|
|
877
|
+
React.useEffect(() => {
|
|
878
|
+
setBusy(false)
|
|
879
|
+
setError(null)
|
|
880
|
+
}, [request?.kind, request?.id])
|
|
881
|
+
|
|
882
|
+
if (request === null) return null
|
|
883
|
+
|
|
884
|
+
const isWorkspace = request.kind === 'workspace'
|
|
885
|
+
const onlyWorkspace = isWorkspace && workspaceCount <= 1
|
|
886
|
+
const close = () => {
|
|
887
|
+
if (busy) return
|
|
888
|
+
dialog.set(null)
|
|
889
|
+
setError(null)
|
|
890
|
+
}
|
|
891
|
+
const confirm = () => {
|
|
892
|
+
if (busy || onlyWorkspace) return
|
|
893
|
+
setBusy(true)
|
|
894
|
+
setError(null)
|
|
895
|
+
void (async () => {
|
|
896
|
+
try {
|
|
897
|
+
if (isWorkspace) {
|
|
898
|
+
const snapshot = workspaces.list.getSnapshot()
|
|
899
|
+
const workspace = snapshot.items.find(item => item.workspaceId === request.id)
|
|
900
|
+
const sessionSnapshot = sessions.list.getSnapshot()
|
|
901
|
+
const current = Object.values(sessionSnapshot.byId)
|
|
902
|
+
.find(row => (row.retainedBy?.mainView ?? 0) > 0)
|
|
903
|
+
// Move the selection out before the Host archives/deletes the
|
|
904
|
+
// workspace's sessions; clearing the selection is what makes DSH
|
|
905
|
+
// reveal or create a blank “新会话”.
|
|
906
|
+
if (workspace !== undefined && current !== undefined && workspace.sessionIds.includes(current.id)) {
|
|
907
|
+
const excluded = new Set(workspace.sessionIds)
|
|
908
|
+
const insideWorkspace = row => typeof row.cwd === 'string'
|
|
909
|
+
&& (row.cwd === workspace.path
|
|
910
|
+
|| row.cwd.startsWith(`${workspace.path}/`)
|
|
911
|
+
|| row.cwd.startsWith(`${workspace.path}\\`))
|
|
912
|
+
const alternative = sessionSnapshot.ids
|
|
913
|
+
.map(id => sessionSnapshot.byId[id])
|
|
914
|
+
.find(row => row !== undefined && !excluded.has(row.id) && !row.blank
|
|
915
|
+
&& row.origin !== 'subagent' && !snapshot.archivedSessionIds.includes(row.id)
|
|
916
|
+
&& !insideWorkspace(row))
|
|
917
|
+
if (alternative !== undefined) {
|
|
918
|
+
try { uiWorkspace.openSession(alternative.id) } catch (error) { console.warn('workspace-curator: could not select an alternative Session', error) }
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const result = await callAdmin('delete-workspace', { workspaceId: request.id, confirmFolder: true })
|
|
922
|
+
await sessions.refresh().catch(() => {})
|
|
923
|
+
dialog.set(null)
|
|
924
|
+
if (Array.isArray(result.warnings) && result.warnings.length > 0) {
|
|
925
|
+
notify(t('notice.workspaceDeletedWarnings', { message: result.warnings.join('; ') }), false)
|
|
926
|
+
} else if (result.queued > 0) {
|
|
927
|
+
notify(t('notice.workspaceQueued', { total: result.deleted + result.queued, queued: result.queued }), true)
|
|
928
|
+
} else {
|
|
929
|
+
notify(t('notice.workspaceDeleted'), true)
|
|
930
|
+
}
|
|
931
|
+
return
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
const sessionSnapshot = sessions.list.getSnapshot()
|
|
935
|
+
const workspaceSnapshot = workspaces.list.getSnapshot()
|
|
936
|
+
const current = Object.values(sessionSnapshot.byId)
|
|
937
|
+
.find(row => (row.retainedBy?.mainView ?? 0) > 0)
|
|
938
|
+
if (current?.id === request.id) {
|
|
939
|
+
const alternative = sessionSnapshot.ids
|
|
940
|
+
.map(id => sessionSnapshot.byId[id])
|
|
941
|
+
.find(row => row !== undefined && row.id !== request.id && !row.blank
|
|
942
|
+
&& row.origin !== 'subagent' && !workspaceSnapshot.archivedSessionIds.includes(row.id))
|
|
943
|
+
if (alternative !== undefined) {
|
|
944
|
+
try { uiWorkspace.openSession(alternative.id) } catch (error) { console.warn('workspace-curator: could not select an alternative Session', error) }
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
const result = await callAdmin('delete-session', { sessionId: request.id })
|
|
948
|
+
await sessions.refresh().catch(() => {})
|
|
949
|
+
dialog.set(null)
|
|
950
|
+
if (Array.isArray(result.warnings) && result.warnings.length > 0) {
|
|
951
|
+
notify(t('notice.sessionDeletedWarnings', { message: result.warnings.join('; ') }), false)
|
|
952
|
+
} else if (result.alreadyGone === true) {
|
|
953
|
+
notify(t('notice.sessionAlreadyGone'), true)
|
|
954
|
+
} else {
|
|
955
|
+
notify(result.queued === true ? t('notice.sessionQueued') : t('notice.sessionDeleted'), true)
|
|
956
|
+
}
|
|
957
|
+
} catch (failure) {
|
|
958
|
+
setError(failure instanceof TypeError
|
|
959
|
+
? t('err.unavailable', { message: failure.message })
|
|
960
|
+
: failureText(failure, t))
|
|
961
|
+
} finally {
|
|
962
|
+
setBusy(false)
|
|
963
|
+
}
|
|
964
|
+
})()
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const body = isWorkspace
|
|
968
|
+
? t('dialog.deleteWorkspace.body', { name: request.title, count: request.count, path: request.path })
|
|
969
|
+
: t('dialog.deleteSession.body', { name: request.title })
|
|
970
|
+
return h(Modal, {
|
|
971
|
+
open: true,
|
|
972
|
+
onClose: close,
|
|
973
|
+
closeLabel: t('close'),
|
|
974
|
+
title: isWorkspace ? t('dialog.deleteWorkspace.title') : t('dialog.deleteSession.title'),
|
|
975
|
+
description: body,
|
|
976
|
+
tone: 'warning',
|
|
977
|
+
footer: h(React.Fragment, null,
|
|
978
|
+
h(Button, { variant: 'outline', disabled: busy, onClick: close }, t('confirm.cancel')),
|
|
979
|
+
h(Button, {
|
|
980
|
+
variant: 'outline',
|
|
981
|
+
style: { color: T.danger },
|
|
982
|
+
disabled: busy || onlyWorkspace,
|
|
983
|
+
onClick: confirm,
|
|
984
|
+
}, busy ? t('confirm.deleting') : (isWorkspace ? t('dialog.deleteWorkspace') : t('dialog.deleteSession')))),
|
|
985
|
+
},
|
|
986
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
987
|
+
isWorkspace ? h('div', { style: { fontSize: 12, lineHeight: '18px', color: T.secondary } },
|
|
988
|
+
t('dialog.workspaceCount', { count: request.count })) : null,
|
|
989
|
+
isWorkspace ? h('div', {
|
|
990
|
+
style: {
|
|
991
|
+
fontSize: 12, lineHeight: '18px', color: T.tertiary,
|
|
992
|
+
fontFamily: 'var(--dsw-font-mono, monospace)', overflowWrap: 'anywhere',
|
|
993
|
+
},
|
|
994
|
+
}, request.path) : null,
|
|
995
|
+
onlyWorkspace ? h('div', { role: 'alert', style: { fontSize: 12, lineHeight: '18px', color: T.danger } },
|
|
996
|
+
t('err.lastWorkspace')) : null,
|
|
997
|
+
isWorkspace && !onlyWorkspace ? h('div', { style: { fontSize: 12, lineHeight: '18px', color: T.danger } },
|
|
998
|
+
t('dialog.folderWarning')) : null,
|
|
999
|
+
h('div', { style: { fontSize: 12, lineHeight: '18px', color: T.tertiary } }, t('dialog.liveNote')),
|
|
1000
|
+
error === null ? null : h('div', { role: 'alert', style: { fontSize: 12, lineHeight: '18px', color: T.danger } }, error)))
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/** Menu icon used by the delete contributions. */
|
|
1004
|
+
function TrashIcon({ size = 16 }) {
|
|
1005
|
+
return h(IconTrashOutlineRegular, { size })
|
|
1006
|
+
}
|
|
1007
|
+
|
|
886
1008
|
/** Navigation glyph: a folder with a removal cross, drawn in currentColor. */
|
|
887
1009
|
function AdminIcon({ size = 16 }) {
|
|
888
1010
|
return h('svg', {
|
|
@@ -896,17 +1018,212 @@ window.__ModuleLoader__.load({
|
|
|
896
1018
|
}
|
|
897
1019
|
|
|
898
1020
|
return {
|
|
899
|
-
inject: ['slots', 'locale', 'workspaces', 'sessions', 'uiWorkspace'],
|
|
1021
|
+
inject: ['slots', 'locale', 'contextMenus', 'remoteAccess', 'workspaces', 'sessions', 'uiWorkspace'],
|
|
900
1022
|
apply(ctx) {
|
|
901
1023
|
const t = ctx.locale.bind(NS)
|
|
902
1024
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'workspace-curator: dictionaries')
|
|
903
1025
|
const subscribeLocale = listener => ctx.locale.subscribe(listener)
|
|
904
1026
|
const localeRevision = () => ctx.locale.getSnapshot().revision
|
|
1027
|
+
const deletionRequest = createSnapshotStore(null)
|
|
1028
|
+
const requestDeletion = request => { deletionRequest.set(request) }
|
|
1029
|
+
const notify = (text, success) => { ctx.contextMenus.notify(text, success) }
|
|
1030
|
+
|
|
1031
|
+
// Compatibility shim: DSH's workspace UI owns a native "删除工作区"
|
|
1032
|
+
// action that only removes the registration. Hide that one action from
|
|
1033
|
+
// the menu so our cascade action is the single visible entry. Other
|
|
1034
|
+
// access checks are untouched.
|
|
1035
|
+
const remoteAccess = ctx.remoteAccess
|
|
1036
|
+
const originalSource = remoteAccess.source
|
|
1037
|
+
const readAccess = (kind, id, action) => originalSource.call(remoteAccess, kind, id, action)
|
|
1038
|
+
const hiddenAccess = { getSnapshot: () => false, subscribe: () => () => {} }
|
|
1039
|
+
let accessPatched = false
|
|
1040
|
+
try {
|
|
1041
|
+
remoteAccess.source = function patchedSource(kind, id, action) {
|
|
1042
|
+
if (kind === 'workspace' && action === 'workspace/delete') return hiddenAccess
|
|
1043
|
+
return readAccess(kind, id, action)
|
|
1044
|
+
}
|
|
1045
|
+
accessPatched = true
|
|
1046
|
+
} catch (error) {
|
|
1047
|
+
console.warn('workspace-curator: could not hide the native workspace delete action', error)
|
|
1048
|
+
}
|
|
1049
|
+
if (accessPatched) {
|
|
1050
|
+
ctx.effect(() => () => {
|
|
1051
|
+
if (remoteAccess.source !== originalSource) remoteAccess.source = originalSource
|
|
1052
|
+
}, 'workspace-curator: restore native workspace delete access')
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
ctx.effect(() => ctx.contextMenus.register({
|
|
1056
|
+
id: 'session.workspaceCurator.delete',
|
|
1057
|
+
target: 'session',
|
|
1058
|
+
order: 700,
|
|
1059
|
+
observe: ({ sessionId }) => [
|
|
1060
|
+
ctx.workspaces.list,
|
|
1061
|
+
ctx.locale,
|
|
1062
|
+
ctx.remoteAccess.source('session', sessionId, 'workspace/archiveSession'),
|
|
1063
|
+
ctx.remoteAccess.source('session', sessionId, 'workspace/unarchiveSession'),
|
|
1064
|
+
],
|
|
1065
|
+
resolve: (target) => {
|
|
1066
|
+
const archived = ctx.workspaces.list.getSnapshot().archivedSessionIds.includes(target.sessionId)
|
|
1067
|
+
const endpoint = archived ? 'workspace/unarchiveSession' : 'workspace/archiveSession'
|
|
1068
|
+
const allowed = ctx.remoteAccess.source('session', target.sessionId, endpoint).getSnapshot()
|
|
1069
|
+
if (!allowed) return []
|
|
1070
|
+
return [{
|
|
1071
|
+
id: 'delete',
|
|
1072
|
+
label: t('menu.deleteSession'),
|
|
1073
|
+
icon: { key: 'workspaceCurator.trash' },
|
|
1074
|
+
danger: true,
|
|
1075
|
+
separatorBefore: true,
|
|
1076
|
+
run: () => {
|
|
1077
|
+
requestDeletion({ kind: 'session', id: target.sessionId, title: target.displayTitle })
|
|
1078
|
+
},
|
|
1079
|
+
}]
|
|
1080
|
+
},
|
|
1081
|
+
}), 'workspace-curator: session delete menu')
|
|
1082
|
+
|
|
1083
|
+
if (accessPatched) {
|
|
1084
|
+
let disposeWorkspaceMenu
|
|
1085
|
+
let workspaceMenuChecked = false
|
|
1086
|
+
ctx.effect(() => {
|
|
1087
|
+
disposeWorkspaceMenu = ctx.contextMenus.register({
|
|
1088
|
+
id: 'workspace.workspaceCurator.deleteAll',
|
|
1089
|
+
target: 'workspace',
|
|
1090
|
+
order: 400,
|
|
1091
|
+
observe: ({ workspaceId }) => [
|
|
1092
|
+
ctx.workspaces.list,
|
|
1093
|
+
ctx.locale,
|
|
1094
|
+
readAccess('workspace', workspaceId, 'workspace/delete'),
|
|
1095
|
+
ctx.remoteAccess.source('workspace', workspaceId, 'workspace/delete'),
|
|
1096
|
+
],
|
|
1097
|
+
resolve: (target) => {
|
|
1098
|
+
// If the shim was removed (for example by a DSH reload), the
|
|
1099
|
+
// native action is visible again. Hide ours rather than ever
|
|
1100
|
+
// showing two workspace-delete entries.
|
|
1101
|
+
let nativeVisible = true
|
|
1102
|
+
try {
|
|
1103
|
+
nativeVisible = ctx.remoteAccess.source('workspace', target.workspaceId, 'workspace/delete').getSnapshot() === true
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
console.warn('workspace-curator: could not read native workspace delete visibility', error)
|
|
1106
|
+
}
|
|
1107
|
+
if (nativeVisible) return []
|
|
1108
|
+
const allowed = readAccess('workspace', target.workspaceId, 'workspace/delete').getSnapshot()
|
|
1109
|
+
if (!allowed) return []
|
|
1110
|
+
const workspace = ctx.workspaces.list.getSnapshot().items
|
|
1111
|
+
.find(item => item.workspaceId === target.workspaceId)
|
|
1112
|
+
if (workspace === undefined) return []
|
|
1113
|
+
return [{
|
|
1114
|
+
id: 'deleteAll',
|
|
1115
|
+
label: t('menu.deleteWorkspace'),
|
|
1116
|
+
icon: { key: 'workspaceCurator.trash' },
|
|
1117
|
+
danger: true,
|
|
1118
|
+
separatorBefore: true,
|
|
1119
|
+
run: () => {
|
|
1120
|
+
requestDeletion({
|
|
1121
|
+
kind: 'workspace',
|
|
1122
|
+
id: target.workspaceId,
|
|
1123
|
+
title: target.displayTitle,
|
|
1124
|
+
path: workspace.path,
|
|
1125
|
+
count: workspace.sessionIds.length,
|
|
1126
|
+
})
|
|
1127
|
+
},
|
|
1128
|
+
}]
|
|
1129
|
+
},
|
|
1130
|
+
})
|
|
1131
|
+
return disposeWorkspaceMenu
|
|
1132
|
+
}, 'workspace-curator: workspace delete menu')
|
|
1133
|
+
|
|
1134
|
+
const dropWorkspaceMenu = (reason) => {
|
|
1135
|
+
if (workspaceMenuChecked) return
|
|
1136
|
+
workspaceMenuChecked = true
|
|
1137
|
+
if (disposeWorkspaceMenu !== undefined) {
|
|
1138
|
+
disposeWorkspaceMenu()
|
|
1139
|
+
disposeWorkspaceMenu = undefined
|
|
1140
|
+
}
|
|
1141
|
+
console.warn(reason)
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// Verify against the real native provider before trusting the shim:
|
|
1145
|
+
// if a DSH update changes how `workspace/delete` is read, the probe
|
|
1146
|
+
// finds both actions and drops ours, so only one entry can be shown.
|
|
1147
|
+
const verifyNoNativeEntry = async () => {
|
|
1148
|
+
if (workspaceMenuChecked) return
|
|
1149
|
+
const workspace = ctx.workspaces.list.getSnapshot().items[0]
|
|
1150
|
+
if (workspace === undefined) return
|
|
1151
|
+
let resolution
|
|
1152
|
+
try {
|
|
1153
|
+
resolution = ctx.contextMenus.resolve({
|
|
1154
|
+
kind: 'workspace',
|
|
1155
|
+
value: {
|
|
1156
|
+
workspaceId: workspace.workspaceId,
|
|
1157
|
+
path: workspace.path,
|
|
1158
|
+
displayTitle: workspace.title ?? workspace.path,
|
|
1159
|
+
},
|
|
1160
|
+
})
|
|
1161
|
+
await resolution.ready
|
|
1162
|
+
let nativeLabel
|
|
1163
|
+
try { nativeLabel = ctx.locale.bind('workspace')('delete.workspace') } catch (_error) {}
|
|
1164
|
+
const nativeVisible = resolution.source.getSnapshot().some(action =>
|
|
1165
|
+
!action.id.startsWith('workspace.workspaceCurator.deleteAll/')
|
|
1166
|
+
&& (action.id === 'workspace.delete/delete'
|
|
1167
|
+
|| (nativeLabel !== undefined && action.id.startsWith('workspace.')
|
|
1168
|
+
&& action.label === nativeLabel)))
|
|
1169
|
+
if (nativeVisible) {
|
|
1170
|
+
dropWorkspaceMenu('workspace-curator: native workspace delete is still visible; cascade menu is hidden to avoid a duplicate')
|
|
1171
|
+
} else {
|
|
1172
|
+
workspaceMenuChecked = true
|
|
1173
|
+
}
|
|
1174
|
+
} catch (error) {
|
|
1175
|
+
dropWorkspaceMenu(`workspace-curator: workspace delete verification failed; cascade menu is hidden to avoid a duplicate (${String(error)})`)
|
|
1176
|
+
} finally {
|
|
1177
|
+
resolution?.dispose()
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
ctx.effect(() => {
|
|
1182
|
+
let stopped = false
|
|
1183
|
+
const check = () => {
|
|
1184
|
+
if (stopped || workspaceMenuChecked) return
|
|
1185
|
+
void verifyNoNativeEntry()
|
|
1186
|
+
}
|
|
1187
|
+
const detach = ctx.workspaces.list.subscribe(check)
|
|
1188
|
+
check()
|
|
1189
|
+
return () => {
|
|
1190
|
+
stopped = true
|
|
1191
|
+
detach()
|
|
1192
|
+
}
|
|
1193
|
+
}, 'workspace-curator: workspace delete duplicate guard')
|
|
1194
|
+
} else {
|
|
1195
|
+
// Never risk a second workspace-delete entry: when the native
|
|
1196
|
+
// action cannot be hidden, keep only the native one. The Settings
|
|
1197
|
+
// page still offers the cascade deletion.
|
|
1198
|
+
console.warn('workspace-curator: native workspace delete action remains visible; cascade menu is hidden to avoid a duplicate')
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
ctx.slots.inject('contextMenu.icon', () => ctx.slots.register({
|
|
1202
|
+
name: 'contextMenu.icon',
|
|
1203
|
+
key: 'workspaceCurator.trash',
|
|
1204
|
+
}, TrashIcon))
|
|
1205
|
+
|
|
1206
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
1207
|
+
name: 'shell.overlay',
|
|
1208
|
+
id: 'workspaceCurator.delete-dialog',
|
|
1209
|
+
locale: NS,
|
|
1210
|
+
inject: () => ({
|
|
1211
|
+
t,
|
|
1212
|
+
dialog: deletionRequest,
|
|
1213
|
+
uiWorkspace: ctx.uiWorkspace,
|
|
1214
|
+
workspaces: ctx.workspaces,
|
|
1215
|
+
sessions: ctx.sessions,
|
|
1216
|
+
callAdmin,
|
|
1217
|
+
notify,
|
|
1218
|
+
}),
|
|
1219
|
+
}, DeleteDialog))
|
|
1220
|
+
|
|
905
1221
|
const injected = () => ({
|
|
906
1222
|
t,
|
|
907
1223
|
workspaces: ctx.workspaces,
|
|
908
1224
|
sessions: ctx.sessions,
|
|
909
1225
|
uiWorkspace: ctx.uiWorkspace,
|
|
1226
|
+
requestDeletion,
|
|
910
1227
|
subscribeLocale,
|
|
911
1228
|
localeRevision,
|
|
912
1229
|
})
|