@kangyishuai/dsh-session-delete 0.4.9 → 0.5.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/lib/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // @ts-check
2
2
  // client 半:classic script,以 __ModuleLoader__.load 注册 factory,不能使用 import。
3
- // 注册:会话「…」菜单两项 + shell.overlay 里的确认框、回收站面板、toast(一次注册,三个浮层)。
3
+ // 注册面:会话「…」菜单项 + 侧栏页脚回收站入口 + shell.overlay(确认框 / 回收站面板 / toast)
4
+ // + 设置页「会话回收站」分节。
4
5
  // 宿主调用走 ctx.connection.rpc.call("/api", ...) —— 无构建插件没有 typert 生成的客户端产物,
5
6
  // 因此不能用 ctx.reflect.get("remote.xxx")(见 docs/runtime/0.2.1-rc.5.md §6.10)。
6
7
  window.__ModuleLoader__.load({
@@ -24,6 +25,8 @@ window.__ModuleLoader__.load({
24
25
  var MenuItemButton = primitives.MenuItemButton;
25
26
  var Modal = primitives.Modal;
26
27
  var IconTrash = primitives.IconTrashOutlineRegular;
28
+ var PrimitiveCheckbox = primitives.Checkbox;
29
+ var PrimitiveSwitch = primitives.Switch;
27
30
 
28
31
  /** 设计变量(宿主主题 token):深色/浅色自动跟随。 */
29
32
  var T = {
@@ -34,6 +37,7 @@ window.__ModuleLoader__.load({
34
37
  faint: "var(--dsw-alias-label-tertiary, GrayText)",
35
38
  border: "var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
36
39
  hover: "var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,0.12))",
40
+ hoverDanger: "var(--dsw-alias-interactive-bg-hover-danger, rgba(217,83,79,0.16))",
37
41
  danger: "var(--dsw-alias-state-error-primary, #d9534f)",
38
42
  // 与 danger 成对:反色实心填充必须配宿主的前景色 token,不能写死白。
39
43
  // 深色主题下宿主 error 是浅红 #f25a5a,白字只有 3.29:1;配 label-primary-foreground 是 5.75:1。
@@ -41,70 +45,100 @@ window.__ModuleLoader__.load({
41
45
  mask: "var(--dsw-alias-bg-mask-1, rgba(0,0,0,0.45))",
42
46
  toastBg: "var(--dsw-alias-toast-bg, Canvas)",
43
47
  toastText: "var(--dsw-alias-toast-label, CanvasText)",
48
+ brand: "var(--dsw-alias-brand-primary, #4f7cff)",
44
49
  radius: "10px",
45
50
  };
46
51
 
47
52
  /** locale 命名空间;必须与 locale/*.json 顶层键一致。 */
48
53
  var NS = "sessionDelete";
49
54
 
50
- /** 简体中文词典(键集的事实来源)。 */
55
+ /**
56
+ * 简体中文词典(键集的事实来源)。
57
+ * 精简原则:确认框正文只讲「删什么、多大、能不能恢复」,
58
+ * 技术细节(引用清单、回收站路径、子会话标题)一律进「详情」。
59
+ */
51
60
  var zh = {
52
61
  "menu.delete": "删除会话…",
53
62
  "menu.trash": "回收站…",
54
63
  "footer.trash": "回收站",
55
- "confirm.title": "删除这个会话?",
64
+ "confirm.title": "删除会话?",
65
+ "confirm.desc": "移入本机回收站,可以恢复。",
56
66
  "confirm.loading": "正在读取影响面…",
57
- "confirm.desc": "会话会被移入本机回收站,可以恢复。",
58
- "confirm.size": "会话日志约 {size}",
59
- "confirm.live": "该会话仍在本机打开,删除前会先停止它的工作。",
60
- "confirm.children": "会一并带上 {n} 个子代理会话",
61
- "confirm.cascade": "同时删除这 {n} 个子会话(各自进入回收站,需分别恢复)",
62
- "confirm.refs": "将清理:{list}",
63
- "confirm.trashPath": "回收站位置:{path}",
67
+ "confirm.size": "约 {size}",
68
+ "confirm.live": "正在运行,会先停止",
69
+ "confirm.children": "{n} 个子会话",
70
+ "confirm.cascade": "同时删除这 {n} 个子会话(各自进回收站,需分别恢复)",
71
+ "confirm.refs": "将清理 {n} 处引用",
72
+ "confirm.details": "详情",
73
+ "confirm.detail.refs": "引用:{list}",
74
+ "confirm.detail.children": "子会话:{list}",
75
+ "confirm.detail.trashPath": "回收站:{path}",
76
+ "confirm.detail.recoverable": "可恢复:删除后从回收站还原到原位置",
64
77
  "confirm.blocked": "暂时无法删除:{reason}",
65
78
  "confirm.cancel": "取消",
66
79
  "confirm.confirm": "移入回收站",
67
80
  "confirm.pending": "正在移入回收站…",
68
81
  "confirm.done": "已移入回收站",
69
82
  "confirm.undo": "撤销",
70
- "confirm.failed": "删除失败",
71
83
  "panel.title": "会话回收站",
72
- "panel.tabTrash": "回收站",
73
- "panel.tabAudit": "审计",
74
- "panel.tabHealth": "体检",
75
- "panel.tabReceipts": "回执",
76
- "trash.selectAll": "全选",
77
- "trash.clear": "清空",
78
- "trash.restoreMany": "批量恢复({n})",
79
- "trash.purgeMany": "批量彻底删除({n})",
80
- "trash.purgeManyConfirm": "确认彻底删除 {n} 个?不可恢复",
81
- "batch.done": "完成:{ok}/{total} 成功",
82
- "receipts.empty": "还没有操作回执。",
83
- "receipts.restored": "已移回原位置",
84
- "health.loading": "正在检查…",
85
- "health.inventory":
86
- "已存 {stored} · live {live} · 归档 {archived} · 回收站 {trash} · 待处理 {pending}",
87
- "health.ok": "未发现失效引用。",
88
- "health.items": "{n} 条",
89
- "health.agentTool": "模型工具 session_delete:{state}",
90
- "health.agentToolOn": "已注册",
91
- "health.agentToolOff": "未注册(宿主未提供 tools 运行时)",
92
- "health.unavailable": "无法体检:{reason}",
93
- "health.clean": "清理失效引用({n})",
94
- "health.cleanConfirm": "确认清理 {n} 条?只动登记表,不碰会话文件",
95
- "health.cleanDone": "已清理 {n} 条",
96
84
  "panel.empty": "回收站是空的。",
97
- "panel.auditEmpty": "还没有审计记录。",
98
85
  "panel.restore": "恢复",
99
86
  "panel.purge": "彻底删除",
100
- "panel.purgeConfirm": "彻底删除?不可恢复",
101
- "panel.size": "占用 {size}",
102
- "panel.trashedAt": "删除于 {time}",
87
+ "panel.purgeConfirm": "不可恢复,确认",
88
+ "panel.cancelConfirm": "取消",
89
+ "panel.size": "{size}",
90
+ "panel.trashedAt": "{time}",
103
91
  "panel.unknown": "{n} 个无法识别的目录已保留",
104
92
  "panel.pending": "{n} 个未完成的操作",
105
93
  "panel.readOnly": "只读模式:当前 DSH 版本缺少依赖接口,删除功能已禁用。",
106
94
  "panel.close": "关闭",
95
+ "trash.selectAll": "全选",
96
+ "trash.selectCount": "已选 {n}/{total}",
97
+ "trash.restoreMany": "恢复({n})",
98
+ "trash.purgeMany": "彻底删除({n})",
99
+ "trash.purgeManyConfirm": "彻底删除 {n} 个?不可恢复",
100
+ "batch.progress": "处理中 {done}/{total}",
101
+ "batch.stop": "停止",
102
+ "batch.done": "完成:{ok}/{total} 成功",
103
+ "batch.failed": "{n} 个失败,已保留选中",
107
104
  "toast.failed": "操作失败:{message}",
105
+ "settings.nav": "会话回收站",
106
+ "settings.group.delete": "删除偏好",
107
+ "settings.cascade.title": "记住「同时删除子会话」",
108
+ "settings.cascade.desc": "下次打开删除确认框时沿用上次的勾选状态。",
109
+ "settings.cascade.reset": "重置为默认(不勾选)",
110
+ "settings.cascade.resetDone": "已重置",
111
+ "settings.group.trash": "回收站",
112
+ "settings.trash.summary": "{n} 个会话 · 占用 {size}",
113
+ "settings.trash.open": "打开回收站",
114
+ "settings.group.maintenance": "维护",
115
+ "settings.health.title": "体检",
116
+ "settings.health.desc": "检查指向已不存在会话的登记条目(只读)。",
117
+ "settings.health.ok": "未发现失效引用。",
118
+ "settings.health.items": "{n} 条待清理",
119
+ "settings.health.unavailable": "无法体检:{reason}",
120
+ "settings.health.clean": "清理 {n} 条",
121
+ "settings.health.cleanConfirm": "确认清理 {n} 条?只动登记表,不碰会话文件",
122
+ "settings.health.cleaned": "已清理 {n} 条",
123
+ "settings.receipts.title": "操作回执",
124
+ "settings.receipts.empty": "还没有操作回执。",
125
+ "settings.audit.title": "审计日志",
126
+ "settings.audit.empty": "还没有审计记录。",
127
+ "settings.audit.path": "日志文件:{path}",
128
+ "settings.loading": "读取中…",
129
+ "confirm.workspace.title": "删除「{name}」里的全部会话?",
130
+ "confirm.workspace.summary": "{n} 个会话 · 约 {size}",
131
+ "confirm.workspace.live": "{n} 个正在运行,会先停止",
132
+ "confirm.workspace.blocked": "{n} 个暂时无法删除,会逐条报出来",
133
+ "confirm.workspace.missing": "{n} 个登记条目已失效,已忽略",
134
+ "confirm.workspace.confirm": "移入回收站({n})",
135
+ "confirm.detail.workspaceSessions": "会话:{list}",
136
+ "menu.workspaceTrash": "删除此工作区的全部会话…",
137
+ "toast.workspace.done": "已移入回收站 {ok}/{total} 个会话",
138
+ "shortcut.delete": "删除当前会话…",
139
+ "shortcut.workspace": "删除当前工作区的全部会话…",
140
+ "shortcut.noSession": "没有可以删除的当前会话",
141
+ "shortcut.busy": "删除确认框已经打开",
108
142
  };
109
143
 
110
144
  /** English dictionary(键集与 zh 完全一致)。 */
@@ -112,60 +146,87 @@ window.__ModuleLoader__.load({
112
146
  "menu.delete": "Delete session…",
113
147
  "menu.trash": "Trash…",
114
148
  "footer.trash": "Trash",
115
- "confirm.title": "Delete this session?",
149
+ "confirm.title": "Delete session?",
150
+ "confirm.desc": "Moves to the local trash and can be restored.",
116
151
  "confirm.loading": "Reading what will be removed…",
117
- "confirm.desc": "The session moves to the local trash and can be restored.",
118
- "confirm.size": "Session log is about {size}",
119
- "confirm.live": "This session is still open; its work is stopped first.",
120
- "confirm.children": "{n} subagent session(s) come along",
152
+ "confirm.size": "about {size}",
153
+ "confirm.live": "running; its work stops first",
154
+ "confirm.children": "{n} subagent session(s)",
121
155
  "confirm.cascade": "Also delete these {n} child session(s) (each goes to trash separately)",
122
- "confirm.refs": "Will clean: {list}",
123
- "confirm.trashPath": "Trash location: {path}",
156
+ "confirm.refs": "Cleans {n} reference(s)",
157
+ "confirm.details": "Details",
158
+ "confirm.detail.refs": "References: {list}",
159
+ "confirm.detail.children": "Child sessions: {list}",
160
+ "confirm.detail.trashPath": "Trash: {path}",
161
+ "confirm.detail.recoverable":
162
+ "Recoverable: restore from the trash back to its original place",
124
163
  "confirm.blocked": "Cannot delete right now: {reason}",
125
164
  "confirm.cancel": "Cancel",
126
165
  "confirm.confirm": "Move to trash",
127
166
  "confirm.pending": "Moving to trash…",
128
167
  "confirm.done": "Moved to trash",
129
168
  "confirm.undo": "Undo",
130
- "confirm.failed": "Deletion failed",
131
169
  "panel.title": "Session trash",
132
- "panel.tabTrash": "Trash",
133
- "panel.tabAudit": "Audit",
134
- "panel.tabHealth": "Health",
135
- "panel.tabReceipts": "Receipts",
136
- "trash.selectAll": "Select all",
137
- "trash.clear": "Clear",
138
- "trash.restoreMany": "Restore {n}",
139
- "trash.purgeMany": "Delete {n} permanently",
140
- "trash.purgeManyConfirm": "Permanently delete {n}? This cannot be undone",
141
- "batch.done": "Done: {ok}/{total} succeeded",
142
- "receipts.empty": "No operation receipts yet.",
143
- "receipts.restored": "restored",
144
- "health.loading": "Checking…",
145
- "health.inventory":
146
- "stored {stored} · live {live} · archived {archived} · trash {trash} · pending {pending}",
147
- "health.ok": "No dangling references found.",
148
- "health.items": "{n} item(s)",
149
- "health.agentTool": "Agent tool session_delete: {state}",
150
- "health.agentToolOn": "registered",
151
- "health.agentToolOff": "not registered (host has no tools runtime)",
152
- "health.unavailable": "Cannot run the check: {reason}",
153
- "health.clean": "Clean dangling references ({n})",
154
- "health.cleanConfirm": "Clean {n} dangling reference(s)? Bookkeeping only, no session files.",
155
- "health.cleanDone": "Cleaned {n}",
156
170
  "panel.empty": "The trash is empty.",
157
- "panel.auditEmpty": "No audit entries yet.",
158
171
  "panel.restore": "Restore",
159
172
  "panel.purge": "Delete for good",
160
- "panel.purgeConfirm": "Delete for good? This cannot be undone",
173
+ "panel.purgeConfirm": "Cannot be undone — confirm",
174
+ "panel.cancelConfirm": "Cancel",
161
175
  "panel.size": "{size}",
162
- "panel.trashedAt": "Trashed {time}",
176
+ "panel.trashedAt": "{time}",
163
177
  "panel.unknown": "{n} unrecognized director(ies) kept",
164
178
  "panel.pending": "{n} unfinished operation(s)",
165
179
  "panel.readOnly":
166
180
  "Read-only: this DSH version is missing required APIs; deletion is disabled.",
167
181
  "panel.close": "Close",
182
+ "trash.selectAll": "Select all",
183
+ "trash.selectCount": "{n}/{total} selected",
184
+ "trash.restoreMany": "Restore ({n})",
185
+ "trash.purgeMany": "Delete {n} permanently",
186
+ "trash.purgeManyConfirm": "Permanently delete {n}? This cannot be undone",
187
+ "batch.progress": "{done}/{total} done",
188
+ "batch.stop": "Stop",
189
+ "batch.done": "Done: {ok}/{total} succeeded",
190
+ "batch.failed": "{n} failed; kept selected",
168
191
  "toast.failed": "Operation failed: {message}",
192
+ "settings.nav": "Session trash",
193
+ "settings.group.delete": "Deletion preferences",
194
+ "settings.cascade.title": 'Remember "also delete child sessions"',
195
+ "settings.cascade.desc": "The next delete confirmation starts from your last choice.",
196
+ "settings.cascade.reset": "Reset to default (unchecked)",
197
+ "settings.cascade.resetDone": "Reset",
198
+ "settings.group.trash": "Trash",
199
+ "settings.trash.summary": "{n} session(s) · {size}",
200
+ "settings.trash.open": "Open trash",
201
+ "settings.group.maintenance": "Maintenance",
202
+ "settings.health.title": "Health",
203
+ "settings.health.desc":
204
+ "Checks bookkeeping that points at sessions that no longer exist (read-only).",
205
+ "settings.health.ok": "No dangling references found.",
206
+ "settings.health.items": "{n} to clean",
207
+ "settings.health.unavailable": "Cannot run the check: {reason}",
208
+ "settings.health.clean": "Clean {n}",
209
+ "settings.health.cleanConfirm": "Clean {n} dangling reference(s)? Bookkeeping only.",
210
+ "settings.health.cleaned": "Cleaned {n}",
211
+ "settings.receipts.title": "Receipts",
212
+ "settings.receipts.empty": "No operation receipts yet.",
213
+ "settings.audit.title": "Audit log",
214
+ "settings.audit.empty": "No audit entries yet.",
215
+ "settings.audit.path": "Log file: {path}",
216
+ "settings.loading": "Loading…",
217
+ "confirm.workspace.title": 'Delete every session in "{name}"?',
218
+ "confirm.workspace.summary": "{n} session(s) · about {size}",
219
+ "confirm.workspace.live": "{n} running; their work stops first",
220
+ "confirm.workspace.blocked": "{n} cannot be deleted right now and will be reported",
221
+ "confirm.workspace.missing": "{n} stale bookkeeping entr(ies) ignored",
222
+ "confirm.workspace.confirm": "Move {n} to trash",
223
+ "confirm.detail.workspaceSessions": "Sessions: {list}",
224
+ "menu.workspaceTrash": "Delete all sessions in this workspace…",
225
+ "toast.workspace.done": "Moved {ok}/{total} session(s) to the trash",
226
+ "shortcut.delete": "Delete current session…",
227
+ "shortcut.workspace": "Delete every session in the current workspace…",
228
+ "shortcut.noSession": "No current session to delete",
229
+ "shortcut.busy": "A delete confirmation is already open",
169
230
  };
170
231
 
171
232
  /** @param {any} initial @returns {any} */
@@ -193,21 +254,26 @@ window.__ModuleLoader__.load({
193
254
  return [React.useSyncExternalStore(store.subscribe, store.getSnapshot), store.set];
194
255
  }
195
256
 
196
- /** 主题化按钮:优先官方 Button,缺失时自绘。 */
257
+ /** 主题化按钮:hover / active / focus-visible 由注入的 CSS 类提供,不依赖合成事件。 */
197
258
  /** 主题化按钮:hover / active / focus-visible 由注入的 CSS 类提供,不依赖合成事件。 */
198
259
  function Btn(/** @type {any} */ props) {
260
+ var variant = props.variant === "danger" ? " dsh-sdel-btn--danger" : "";
261
+ var quiet = props.variant === "quiet" ? " dsh-sdel-btn--quiet" : "";
199
262
  return h(
200
263
  "button",
201
264
  {
202
265
  type: "button",
203
- autoFocus: props.autoFocus,
266
+ ref: props.innerRef,
204
267
  disabled: props.disabled,
268
+ title: props.title,
269
+ "aria-label": props.ariaLabel,
270
+ "data-modal-autofocus": props.modalAutofocus ? "" : undefined,
205
271
  onClick: props.onClick,
206
- className: `dsh-sdel-btn${props.danger ? " dsh-sdel-btn--danger" : ""}`,
272
+ className: `dsh-sdel-btn${variant}${quiet}${props.tight ? " dsh-sdel-btn--tight" : ""}`,
207
273
  style: {
208
- padding: "6px 14px",
274
+ padding: props.tight ? "2px 8px" : "6px 14px",
209
275
  borderRadius: "8px",
210
- fontSize: "13px",
276
+ fontSize: props.tight ? "12px" : "13px",
211
277
  cursor: props.disabled ? "not-allowed" : "pointer",
212
278
  opacity: props.disabled ? 0.45 : 1,
213
279
  },
@@ -216,6 +282,118 @@ window.__ModuleLoader__.load({
216
282
  );
217
283
  }
218
284
 
285
+ /** 复选框:优先宿主原语(尺寸/焦点环与设置页一致),缺失时回退到原生 input。 */
286
+ function Check(/** @type {any} */ props) {
287
+ if (typeof PrimitiveCheckbox === "function") {
288
+ return h(PrimitiveCheckbox, {
289
+ checked: props.checked === true,
290
+ disabled: props.disabled === true,
291
+ label: props.label,
292
+ onChange: props.onChange,
293
+ });
294
+ }
295
+ return h(
296
+ "label",
297
+ { style: { display: "inline-flex", alignItems: "center", gap: "6px", cursor: "pointer" } },
298
+ h("input", {
299
+ type: "checkbox",
300
+ checked: props.checked === true,
301
+ disabled: props.disabled === true,
302
+ onChange: (/** @type {any} */ event) => props.onChange?.(event.target.checked),
303
+ }),
304
+ props.label ? h("span", null, props.label) : null,
305
+ );
306
+ }
307
+
308
+ /** 开关:优先宿主原语,缺失时回退到复选框。 */
309
+ function Toggle(/** @type {any} */ props) {
310
+ if (typeof PrimitiveSwitch === "function") {
311
+ return h(PrimitiveSwitch, {
312
+ checked: props.checked === true,
313
+ disabled: props.disabled === true,
314
+ label: props.label,
315
+ onChange: props.onChange,
316
+ });
317
+ }
318
+ return h(Check, props);
319
+ }
320
+
321
+ /** 折叠三角:纯文本字形,避免依赖宿主图标名(缺失时不会变成空白)。 */
322
+ function Caret(/** @type {any} */ props) {
323
+ return h(
324
+ "span",
325
+ {
326
+ "aria-hidden": "true",
327
+ style: {
328
+ display: "inline-block",
329
+ width: "10px",
330
+ color: T.faint,
331
+ transform: props.open ? "rotate(90deg)" : "none",
332
+ transition: "transform 120ms ease",
333
+ fontSize: "10px",
334
+ },
335
+ },
336
+ "▶",
337
+ );
338
+ }
339
+
340
+ /** 一行可折叠的「标题 + 说明 + 右侧控件」。 */
341
+ function SettingRow(/** @type {any} */ props) {
342
+ return h(
343
+ "div",
344
+ { className: "dsh-sdel-setting-row" },
345
+ h(
346
+ "div",
347
+ { className: "dsh-sdel-setting-text" },
348
+ h("div", { className: "dsh-sdel-setting-title" }, props.title),
349
+ props.description
350
+ ? h("div", { className: "dsh-sdel-setting-desc" }, props.description)
351
+ : null,
352
+ props.children,
353
+ ),
354
+ props.action ? h("div", { className: "dsh-sdel-setting-action" }, props.action) : null,
355
+ );
356
+ }
357
+
358
+ /** 折叠区:默认关闭,展开后限高滚动 —— 长列表不会把弹窗/设置页撑长。 */
359
+ function Disclosure(/** @type {any} */ props) {
360
+ var state = React.useState(false);
361
+ var open = state[0];
362
+ var setOpen = state[1];
363
+ return h(
364
+ React.Fragment,
365
+ null,
366
+ h(
367
+ "button",
368
+ {
369
+ type: "button",
370
+ className: "dsh-sdel-disclosure",
371
+ "aria-expanded": open ? "true" : "false",
372
+ onClick: () => setOpen(!open),
373
+ },
374
+ h(Caret, { open: open }),
375
+ h("span", null, props.label),
376
+ props.meta ? h("span", { className: "dsh-sdel-disclosure-meta" }, props.meta) : null,
377
+ ),
378
+ open
379
+ ? h(
380
+ "div",
381
+ {
382
+ style: {
383
+ maxHeight: props.maxHeight || "220px",
384
+ overflowY: "auto",
385
+ padding: "2px 0 8px 16px",
386
+ color: T.dim,
387
+ fontSize: "12px",
388
+ lineHeight: 1.7,
389
+ },
390
+ },
391
+ props.children,
392
+ )
393
+ : null,
394
+ );
395
+ }
396
+
219
397
  /** 挂载时淡入的容器:官方 Modal 没有明确的入场过渡时,用它补齐。 */
220
398
  function Reveal(/** @type {any} */ props) {
221
399
  const state = React.useState(false);
@@ -258,11 +436,7 @@ window.__ModuleLoader__.load({
258
436
  description: props.description,
259
437
  footer: props.footer,
260
438
  },
261
- h(
262
- Reveal,
263
- { style: { maxHeight: "60vh", overflowY: "auto", paddingRight: "4px" } },
264
- props.children,
265
- ),
439
+ h(Reveal, null, props.children),
266
440
  );
267
441
  }
268
442
  return h(
@@ -283,7 +457,7 @@ window.__ModuleLoader__.load({
283
457
  },
284
458
  h(
285
459
  Reveal,
286
- { style: { width: "min(600px, 92vw)" } },
460
+ { style: { width: "min(480px, 92vw)" } },
287
461
  h(
288
462
  "div",
289
463
  {
@@ -334,6 +508,58 @@ window.__ModuleLoader__.load({
334
508
  );
335
509
  }
336
510
 
511
+ /**
512
+ * 中文/英文共用的列表连接符:把数组拼成一行,超过 max 条时补省略号。
513
+ * @param {any[]} items
514
+ * @param {number} [max]
515
+ * @returns {string}
516
+ */
517
+ function joinList(items, max = 6) {
518
+ var list = (Array.isArray(items) ? items : []).map((/** @type {any} */ item) =>
519
+ String(
520
+ item && typeof item === "object" ? (item.label ?? item.title ?? item.id ?? "") : item,
521
+ ),
522
+ );
523
+ var shown = list.slice(0, max);
524
+ return shown.join(" · ") + (list.length > max ? " …" : "");
525
+ }
526
+
527
+ /**
528
+ * 把数组切成固定大小的批次:回收站 80 条时一次 RPC 会被宿主上限拒绝,
529
+ * 界面必须分批并把进度显示出来(0.4.x 的 bug:整单被拒,看起来像没反应)。
530
+ * @param {any[]} items
531
+ * @param {number} size
532
+ * @returns {any[][]}
533
+ */
534
+ function chunk(items, size) {
535
+ var step = Math.max(1, Math.floor(size) || 1);
536
+ /** @type {any[][]} */
537
+ var out = [];
538
+ for (let index = 0; index < (items || []).length; index += step) {
539
+ out.push(items.slice(index, index + step));
540
+ }
541
+ return out;
542
+ }
543
+
544
+ /**
545
+ * 确认框正文的一行影响面:只拼成立的事实,用 `·` 分隔。
546
+ * 空值不进数组 —— 这是「不显示占位行」这条规则的单点实现。
547
+ * @param {{ sizeBytes?: number, live?: boolean, children?: any[] }} plan
548
+ * @param {(key: string, values?: any) => string} t
549
+ * @returns {string}
550
+ */
551
+ function impactLine(plan, t) {
552
+ /** @type {string[]} */
553
+ var facts = [];
554
+ if (plan && typeof plan.sizeBytes === "number") {
555
+ facts.push(t("confirm.size", { size: formatBytes(plan.sizeBytes) }));
556
+ }
557
+ var children = Array.isArray(plan?.children) ? plan.children.length : 0;
558
+ if (children > 0) facts.push(t("confirm.children", { n: children }));
559
+ if (plan?.live) facts.push(t("confirm.live"));
560
+ return facts.join(" · ");
561
+ }
562
+
337
563
  function formatBytes(/** @type {any} */ bytes) {
338
564
  if (typeof bytes !== "number" || bytes < 0) return "?";
339
565
  if (bytes < 1024) return `${Math.round(bytes)} B`;
@@ -392,19 +618,8 @@ window.__ModuleLoader__.load({
392
618
  {
393
619
  type: "button",
394
620
  onClick: onSelect,
395
- style: {
396
- display: "block",
397
- width: "100%",
398
- textAlign: "left",
399
- padding: "6px 12px",
400
- border: "none",
401
- borderRadius: "6px",
402
- background: "transparent",
403
- color: T.danger,
404
- cursor: "pointer",
405
- fontSize: "13px",
406
- transition: "background-color .15s ease",
407
- },
621
+ className: "dsh-sdel-btn dsh-sdel-btn--danger",
622
+ style: { display: "block", width: "100%", textAlign: "left", padding: "6px 12px" },
408
623
  },
409
624
  props.t("menu.delete"),
410
625
  );
@@ -423,7 +638,10 @@ window.__ModuleLoader__.load({
423
638
  .then((/** @type {any} */ value) => {
424
639
  setCount(value?.entries ? value.entries.length : 0);
425
640
  })
426
- .catch(() => setCount(null));
641
+ .catch(() => {
642
+ // 计数拿不到就退回不带数字的入口,但别让 rejection 无声无息。
643
+ setCount(null);
644
+ });
427
645
  };
428
646
  React.useEffect(() => {
429
647
  fetchCount();
@@ -482,6 +700,11 @@ window.__ModuleLoader__.load({
482
700
  );
483
701
  }
484
702
 
703
+ /**
704
+ * 删除确认框:会话与「整个工作区」共用一套。
705
+ * 正文三行(标题 / 影响面 / 需要留意的一行)+ 一行级联勾选 + 折叠详情;
706
+ * 默认焦点在「移入回收站」上(回车即生效),Esc 取消,不可删除时焦点回落到「取消」。
707
+ */
485
708
  function DeleteConfirm(/** @type {any} */ props) {
486
709
  var requestState = useStore(props.requestStore);
487
710
  var request = requestState[0];
@@ -494,24 +717,41 @@ window.__ModuleLoader__.load({
494
717
  var busyState = React.useState(false);
495
718
  var busy = busyState[0];
496
719
  var setBusy = busyState[1];
497
- var requestId = request ? request.sessionId : null;
498
720
  var cascadeState = React.useState(false);
499
721
  var cascade = cascadeState[0];
500
722
  var setCascade = cascadeState[1];
723
+ var confirmRef = React.useRef(null);
724
+ var cancelRef = React.useRef(null);
725
+ var workspaceId = request?.workspaceId ? String(request.workspaceId) : null;
726
+ var isWorkspace = workspaceId !== null;
727
+ var requestKey = request
728
+ ? isWorkspace
729
+ ? `workspace:${workspaceId}`
730
+ : `session:${request.sessionId}`
731
+ : null;
732
+
733
+ /** 偏好只决定「初值」:用户这次勾了什么,下次就带过来。 */
734
+ var rememberCascade = (/** @type {any} */ next) => {
735
+ setCascade(next);
736
+ props.prefsStore.set({ cascadeChildren: next });
737
+ props.call("setPrefs", { cascadeChildren: next }).catch(() => {});
738
+ };
501
739
 
502
740
  React.useEffect(() => {
503
- if (!requestId) {
741
+ if (!requestKey) {
504
742
  setPlan(null);
505
743
  setError(null);
506
744
  setBusy(false);
507
- setCascade(false);
508
745
  return undefined;
509
746
  }
510
747
  var alive = true;
511
748
  setPlan(null);
512
749
  setError(null);
513
- props
514
- .call("plan", { sessionId: requestId })
750
+ setCascade(props.prefsStore.getSnapshot()?.cascadeChildren === true);
751
+ var pending = workspaceId
752
+ ? props.call("planWorkspace", { workspaceId: workspaceId })
753
+ : props.call("plan", { sessionId: request.sessionId });
754
+ pending
515
755
  .then((/** @type {any} */ value) => {
516
756
  if (alive) setPlan(value);
517
757
  })
@@ -521,7 +761,24 @@ window.__ModuleLoader__.load({
521
761
  return () => {
522
762
  alive = false;
523
763
  };
524
- }, [requestId]);
764
+ }, [requestKey]);
765
+
766
+ // hooks 必须在任何 return 之前:确认框组件常驻挂载,提前 return 会让 hook 数量在
767
+ // 「有请求 / 无请求」两种渲染之间变化,React 会直接抛 rendered more hooks 错误。
768
+ var blocked = isWorkspace ? false : (plan?.blockers?.length ?? 0) > 0;
769
+ var children = isWorkspace || !plan ? [] : Array.isArray(plan.children) ? plan.children : [];
770
+ var removes = isWorkspace || !plan ? [] : Array.isArray(plan.removes) ? plan.removes : [];
771
+ // 工作区预览里的 children 是**汇总数字**,会话计划里是数组,这里统一成数量。
772
+ var childCount = isWorkspace ? Number(plan?.children ?? 0) : children.length;
773
+ var sessionTotal = isWorkspace ? Number(plan?.total ?? 0) : 0;
774
+ var canConfirm = !!plan && !blocked && !busy && (!isWorkspace || sessionTotal > 0);
775
+
776
+ /** 焦点策略:可确认时落在破坏性按钮(回车即删),否则落在「取消」。 */
777
+ React.useEffect(() => {
778
+ if (!request) return;
779
+ var target = canConfirm ? confirmRef.current : cancelRef.current;
780
+ if (target && typeof target.focus === "function") target.focus();
781
+ }, [canConfirm, plan, request]);
525
782
 
526
783
  if (!request) return null;
527
784
 
@@ -532,16 +789,23 @@ window.__ModuleLoader__.load({
532
789
  var confirm = () => {
533
790
  if (!plan || busy) return;
534
791
  setBusy(true);
535
- props
536
- .call("trash", {
537
- sessionId: request.sessionId,
538
- digest: plan.digest,
539
- title: request.title || null,
540
- cascade: cascade && plan.children.length > 0,
541
- })
792
+ var pending = isWorkspace
793
+ ? props.call("trashWorkspace", {
794
+ workspaceId: workspaceId,
795
+ digest: plan.digest,
796
+ cascade: cascade && childCount > 0,
797
+ })
798
+ : props.call("trash", {
799
+ sessionId: request.sessionId,
800
+ digest: plan.digest,
801
+ title: request.title || null,
802
+ cascade: cascade && children.length > 0,
803
+ });
804
+ pending
542
805
  .then((/** @type {any} */ result) => {
543
806
  props.requestStore.set(null);
544
- props.onTrashed(result);
807
+ if (isWorkspace) props.onTrashedMany?.(result);
808
+ else props.onTrashed?.(result);
545
809
  })
546
810
  .catch((/** @type {any} */ reason) => {
547
811
  setBusy(false);
@@ -549,72 +813,131 @@ window.__ModuleLoader__.load({
549
813
  });
550
814
  };
551
815
 
552
- var lines = [];
553
- if (plan) {
554
- if (typeof plan.sizeBytes === "number")
555
- lines.push(props.t("confirm.size", { size: formatBytes(plan.sizeBytes) }));
556
- if (plan.live) lines.push(props.t("confirm.live"));
557
- if (plan.children && plan.children.length > 0)
558
- lines.push(props.t("confirm.children", { n: plan.children.length }));
559
- if (plan.removes && plan.removes.length > 0) {
560
- lines.push(
561
- props.t("confirm.refs", {
562
- list: plan.removes.map((/** @type {any} */ item) => item.label).join(" · "),
563
- }),
564
- );
565
- }
566
- if (plan.blockers && plan.blockers.length > 0)
567
- lines.push(props.t("confirm.blocked", { reason: plan.blockers[0].message }));
568
- }
569
- var blocked = !!(plan?.blockers && plan.blockers.length > 0);
816
+ var impact = isWorkspace
817
+ ? plan
818
+ ? props.t("confirm.workspace.summary", {
819
+ n: sessionTotal,
820
+ size: formatBytes(plan.sizeBytes),
821
+ })
822
+ : props.t("confirm.loading")
823
+ : plan
824
+ ? impactLine(plan, props.t) || props.t("confirm.size", { size: "?" })
825
+ : props.t("confirm.loading");
570
826
 
571
827
  var body = h(
572
828
  React.Fragment,
573
829
  null,
574
- request.title
575
- ? h("div", { style: { fontWeight: 600, marginBottom: "10px" } }, request.title)
576
- : null,
577
- plan && plan.children.length > 0
830
+ !isWorkspace && request.title
578
831
  ? h(
579
- "label",
832
+ "div",
580
833
  {
581
- style: {
582
- display: "flex",
583
- alignItems: "flex-start",
584
- gap: "8px",
585
- margin: "8px 0 4px",
586
- cursor: "pointer",
587
- },
834
+ className: "dsh-sdel-truncate",
835
+ style: { fontWeight: 600, marginBottom: "4px" },
836
+ title: request.title,
588
837
  },
589
- h("input", {
590
- type: "checkbox",
838
+ request.title,
839
+ )
840
+ : null,
841
+ h("div", { style: { color: T.dim } }, impact),
842
+ !isWorkspace && removes.length > 0
843
+ ? h(
844
+ "div",
845
+ { style: { color: T.faint, fontSize: "12px", marginTop: "2px" } },
846
+ props.t("confirm.refs", { n: removes.length }),
847
+ )
848
+ : null,
849
+ isWorkspace && plan && plan.live > 0
850
+ ? h(
851
+ "div",
852
+ { style: { color: T.faint, fontSize: "12px", marginTop: "2px" } },
853
+ props.t("confirm.workspace.live", { n: plan.live }),
854
+ )
855
+ : null,
856
+ isWorkspace && plan && plan.blocked > 0
857
+ ? h(
858
+ "div",
859
+ { style: { color: T.danger, fontSize: "12px", marginTop: "2px" } },
860
+ props.t("confirm.workspace.blocked", { n: plan.blocked }),
861
+ )
862
+ : null,
863
+ childCount > 0
864
+ ? h(
865
+ "div",
866
+ { style: { marginTop: "10px" } },
867
+ h(Check, {
591
868
  checked: cascade,
592
869
  disabled: busy,
593
- onChange: (/** @type {any} */ event) => setCascade(Boolean(event.target.checked)),
594
- style: { marginTop: "2px" },
870
+ label: props.t("confirm.cascade", { n: childCount }),
871
+ onChange: rememberCascade,
595
872
  }),
873
+ )
874
+ : null,
875
+ blocked
876
+ ? h(
877
+ "div",
878
+ { style: { color: T.danger, marginTop: "10px" }, role: "alert" },
879
+ props.t("confirm.blocked", { reason: plan.blockers[0].message }),
880
+ )
881
+ : null,
882
+ error ? h("div", { style: { color: T.danger, marginTop: "8px" } }, error) : null,
883
+ plan
884
+ ? h(
885
+ "div",
886
+ { style: { marginTop: "10px" } },
596
887
  h(
597
- "span",
598
- null,
599
- props.t("confirm.cascade", { n: plan.children.length }),
600
- h(
601
- "span",
602
- {
603
- style: { display: "block", color: T.faint, fontSize: "12px", marginTop: "2px" },
604
- },
605
- plan.children
606
- .slice(0, 4)
607
- .map((/** @type {any} */ child) => child.title || child.id)
608
- .join(" · ") + (plan.children.length > 4 ? " …" : ""),
609
- ),
888
+ Disclosure,
889
+ { label: props.t("confirm.details"), meta: null, maxHeight: "180px" },
890
+ isWorkspace
891
+ ? h(
892
+ React.Fragment,
893
+ null,
894
+ sessionTotal > 0
895
+ ? h(
896
+ "div",
897
+ null,
898
+ props.t("confirm.detail.workspaceSessions", {
899
+ list: joinList(plan.sessions, 8),
900
+ }),
901
+ )
902
+ : null,
903
+ plan.missing && plan.missing.length > 0
904
+ ? h(
905
+ "div",
906
+ null,
907
+ props.t("confirm.workspace.missing", { n: plan.missing.length }),
908
+ )
909
+ : null,
910
+ h("div", null, props.t("confirm.detail.recoverable")),
911
+ )
912
+ : h(
913
+ React.Fragment,
914
+ null,
915
+ removes.length > 0
916
+ ? h(
917
+ "div",
918
+ null,
919
+ props.t("confirm.detail.refs", { list: joinList(removes) }),
920
+ )
921
+ : null,
922
+ children.length > 0
923
+ ? h(
924
+ "div",
925
+ null,
926
+ props.t("confirm.detail.children", { list: joinList(children) }),
927
+ )
928
+ : null,
929
+ plan.trashPath
930
+ ? h(
931
+ "div",
932
+ null,
933
+ props.t("confirm.detail.trashPath", { path: plan.trashPath }),
934
+ )
935
+ : null,
936
+ h("div", null, props.t("confirm.detail.recoverable")),
937
+ ),
610
938
  ),
611
939
  )
612
940
  : null,
613
- lines.map((/** @type {any} */ line, /** @type {any} */ index) =>
614
- h("div", { key: `line-${index}`, style: { marginBottom: "4px" } }, line),
615
- ),
616
- !plan && !error ? h("div", { style: { color: T.dim } }, props.t("confirm.loading")) : null,
617
- error ? h("div", { style: { color: T.danger, marginTop: "8px" } }, error) : null,
618
941
  );
619
942
 
620
943
  return h(
@@ -622,16 +945,34 @@ window.__ModuleLoader__.load({
622
945
  {
623
946
  onClose: close,
624
947
  closeLabel: props.t("confirm.cancel"),
625
- title: props.t("confirm.title"),
948
+ title: isWorkspace
949
+ ? props.t("confirm.workspace.title", {
950
+ name: request.title || plan?.title || workspaceId,
951
+ })
952
+ : props.t("confirm.title"),
626
953
  description: props.t("confirm.desc"),
627
954
  footer: h(
628
955
  React.Fragment,
629
956
  null,
630
- h(Btn, { autoFocus: true, onClick: close, disabled: busy }, props.t("confirm.cancel")),
631
957
  h(
632
958
  Btn,
633
- { onClick: confirm, danger: true, disabled: busy || blocked || !plan },
634
- busy ? props.t("confirm.pending") : props.t("confirm.confirm"),
959
+ { innerRef: cancelRef, onClick: close, disabled: busy },
960
+ props.t("confirm.cancel"),
961
+ ),
962
+ h(
963
+ Btn,
964
+ {
965
+ innerRef: confirmRef,
966
+ modalAutofocus: true,
967
+ onClick: confirm,
968
+ variant: "danger",
969
+ disabled: !canConfirm,
970
+ },
971
+ busy
972
+ ? props.t("confirm.pending")
973
+ : isWorkspace
974
+ ? props.t("confirm.workspace.confirm", { n: sessionTotal })
975
+ : props.t("confirm.confirm"),
635
976
  ),
636
977
  ),
637
978
  },
@@ -639,111 +980,57 @@ window.__ModuleLoader__.load({
639
980
  );
640
981
  }
641
982
 
983
+ /**
984
+ * 回收站面板:只有一件事 —— 看列表、选条目、恢复或彻底删除。
985
+ * 批量条固定在列表上方(不随内容滚动),80 条时也不会「找不到按钮」。
986
+ */
642
987
  function TrashPanel(/** @type {any} */ props) {
643
988
  var panelState = useStore(props.panelStore);
644
989
  var open = panelState[0];
645
- var tabState = React.useState("trash");
646
- var tab = tabState[0];
647
- var setTab = tabState[1];
648
990
  var dataState = React.useState(null);
649
991
  var data = dataState[0];
650
992
  var setData = dataState[1];
651
- var auditState = React.useState(null);
652
- var audit = auditState[0];
653
- var setAudit = auditState[1];
654
- var healthState = React.useState(null);
655
- var health = healthState[0];
656
- var setHealth = healthState[1];
657
993
  var errorState = React.useState(null);
658
994
  var error = errorState[0];
659
995
  var setError = errorState[1];
660
- var busyState = React.useState(null);
661
- var busyId = busyState[0];
662
- var setBusyId = busyState[1];
663
- var purgeState = React.useState(null);
664
- var confirmPurge = purgeState[0];
665
- var setConfirmPurge = purgeState[1];
666
- var selectedTrashState = React.useState({});
667
- var selectedTrash = selectedTrashState[0];
668
- var setSelectedTrash = selectedTrashState[1];
669
- var trashBusyState = React.useState(false);
670
- var trashBusy = trashBusyState[0];
671
- var setTrashBusy = trashBusyState[1];
672
- var trashMsgState = React.useState("");
673
- var trashMsg = trashMsgState[0];
674
- var setTrashMsg = trashMsgState[1];
675
- var scanState = React.useState(null);
676
- var scan = scanState[0];
677
- var setScan = scanState[1];
678
- var scanErrorState = React.useState(null);
679
- var scanError = scanErrorState[0];
680
- var setScanError = scanErrorState[1];
681
- var cleanState = React.useState(false);
682
- var cleaning = cleanState[0];
683
- var setCleaning = cleanState[1];
684
- var cleanMsgState = React.useState("");
685
- var cleanMsg = cleanMsgState[0];
686
- var setCleanMsg = cleanMsgState[1];
687
- var receiptsState = React.useState(null);
688
- var receipts = receiptsState[0];
689
- var setReceipts = receiptsState[1];
690
-
691
- const loadReceipts = React.useCallback(() => {
692
- props
693
- .call("receipts", { limit: 50 })
694
- .then((/** @type {any} */ value) => {
695
- setReceipts(value?.entries ? value.entries : []);
696
- })
697
- .catch(() => setReceipts([]));
698
- }, []);
699
-
700
- const loadHealth = React.useCallback(() => {
701
- setScan(null);
702
- setScanError(null);
703
- props
704
- .call("healthScan")
705
- .then((/** @type {any} */ value) => {
706
- setScan(value);
707
- })
708
- .catch((/** @type {any} */ reason) => {
709
- setScanError(errorText(reason));
710
- });
711
- }, []);
712
-
713
- const loadAudit = React.useCallback(() => {
714
- props
715
- .call("audit", { limit: 100 })
716
- .then((/** @type {any} */ value) => {
717
- setAudit(value?.entries ? value.entries : []);
718
- })
719
- .catch(() => {});
720
- }, []);
996
+ var busyIdState = React.useState(null);
997
+ var busyId = busyIdState[0];
998
+ var setBusyId = busyIdState[1];
999
+ var confirmPurgeState = React.useState(null);
1000
+ var confirmPurge = confirmPurgeState[0];
1001
+ var setConfirmPurge = confirmPurgeState[1];
1002
+ var selectedState = React.useState({});
1003
+ var selected = selectedState[0];
1004
+ var setSelected = selectedState[1];
1005
+ var batchState = React.useState(null);
1006
+ var batch = batchState[0];
1007
+ var setBatch = batchState[1];
1008
+ var readOnlyState = React.useState(false);
1009
+ var readOnly = readOnlyState[0];
1010
+ var setReadOnly = readOnlyState[1];
1011
+ var batchControl = React.useRef({ stop: false });
721
1012
 
1013
+ var loader = React.useMemo(
1014
+ () =>
1015
+ createPanelLoader(props.call, {
1016
+ setData: setData,
1017
+ setReadOnly: setReadOnly,
1018
+ setError: setError,
1019
+ }),
1020
+ [],
1021
+ );
722
1022
  var refresh = React.useCallback(() => {
723
- props
724
- .call("list")
725
- .then((/** @type {any} */ value) => {
726
- setData(value);
727
- })
728
- .catch((/** @type {any} */ reason) => {
729
- setError(errorText(reason));
730
- });
731
- }, []);
1023
+ void loader.load();
1024
+ }, [loader]);
732
1025
 
733
1026
  React.useEffect(() => {
734
1027
  if (!open) return undefined;
735
- refresh();
736
- props
737
- .call("health")
738
- .then((/** @type {any} */ value) => {
739
- setHealth(value);
740
- })
741
- .catch(() => {});
742
- loadAudit();
743
- // 面板打开期间自动同步,不需要手动刷新按钮。
1028
+ void loader.load();
1029
+ void loader.loadHealth();
1030
+ // 面板打开期间自动同步:agent 工具、另一个窗口都可能改动回收站。
744
1031
  const timer = setInterval(() => {
745
1032
  if (document.visibilityState === "visible") refresh();
746
- }, 5000);
1033
+ }, PANEL_POLL_MS);
747
1034
  const onVisible = () => {
748
1035
  if (document.visibilityState === "visible") refresh();
749
1036
  };
@@ -754,32 +1041,15 @@ window.__ModuleLoader__.load({
754
1041
  };
755
1042
  }, [open]);
756
1043
 
757
- const listRef = React.useRef(null);
758
- const onListKeyDown = (/** @type {any} */ event) => {
759
- if (event.key === "Escape") {
760
- event.preventDefault();
761
- props.panelStore.set(false);
762
- return;
763
- }
764
- const keys = ["ArrowDown", "ArrowUp", "Home", "End"];
765
- if (!keys.includes(event.key)) return;
766
- const root = listRef.current;
767
- if (!root) return;
768
- const items = [...root.querySelectorAll("button:not([disabled])")];
769
- if (items.length === 0) return;
770
- const current = items.indexOf(document.activeElement);
771
- let next = 0;
772
- if (event.key === "Home") next = 0;
773
- else if (event.key === "End") next = items.length - 1;
774
- else if (event.key === "ArrowDown")
775
- next = current < 0 ? 0 : Math.min(items.length - 1, current + 1);
776
- else next = current <= 0 ? 0 : current - 1;
777
- event.preventDefault();
778
- items[next].focus();
779
- };
780
-
781
1044
  if (!open) return null;
782
1045
 
1046
+ var entries = data?.entries || [];
1047
+ var selectedIds = Object.keys(selected).filter(
1048
+ (/** @type {string} */ entryId) => selected[entryId],
1049
+ );
1050
+ var allSelected = entries.length > 0 && selectedIds.length === entries.length;
1051
+ var batchRunning = batch?.running === true;
1052
+
783
1053
  var doRestore = (/** @type {any} */ entryId, /** @type {any} */ sessionId) => {
784
1054
  setBusyId(entryId);
785
1055
  props
@@ -812,513 +1082,266 @@ window.__ModuleLoader__.load({
812
1082
  });
813
1083
  };
814
1084
 
815
- var selectedEntryIds = Object.keys(selectedTrash).filter(
816
- (/** @type {string} */ entryId) => /** @type {any} */ (selectedTrash)[entryId],
817
- );
818
- var doBatchRestore = () => {
819
- if (selectedEntryIds.length === 0) return;
820
- setTrashBusy(true);
821
- setTrashMsg("");
822
- props
823
- .call("restoreMany", { entryIds: selectedEntryIds })
824
- .then((/** @type {any} */ result) => {
825
- setTrashBusy(false);
826
- setTrashMsg(props.t("batch.done", { ok: result.succeeded, total: result.total }));
827
- setSelectedTrash({});
828
- refresh();
829
- props.bump?.();
830
- for (const item of result.results) if (item.ok) props.onRestored?.(item.sessionId);
831
- })
832
- .catch((/** @type {any} */ reason) => {
833
- setTrashBusy(false);
834
- setTrashMsg(errorText(reason));
835
- });
836
- };
837
- var doBatchPurge = () => {
838
- if (selectedEntryIds.length === 0) return;
839
- setTrashBusy(true);
840
- setTrashMsg("");
841
- props
842
- .call("purgeMany", { entryIds: selectedEntryIds })
843
- .then((/** @type {any} */ result) => {
844
- setTrashBusy(false);
845
- setConfirmPurge(null);
846
- setTrashMsg(props.t("batch.done", { ok: result.succeeded, total: result.total }));
847
- setSelectedTrash({});
848
- refresh();
849
- props.bump?.();
850
- for (const item of result.results) if (item.ok) props.onPurged?.(undefined);
851
- })
852
- .catch((/** @type {any} */ reason) => {
853
- setTrashBusy(false);
854
- setTrashMsg(errorText(reason));
1085
+ /**
1086
+ * 分批执行批量动作。宿主单次上限是防御性的硬上限,界面按 BATCH_CHUNK 切块,
1087
+ * 每块之间让出一帧:进度可见、可中途停止、部分失败不中断其余批次。
1088
+ * @param {string[]} ids
1089
+ * @param {"purge" | "restore"} kind
1090
+ */
1091
+ var startBatch = (ids, kind) => {
1092
+ if (ids.length === 0 || batchRunning) return;
1093
+ batchControl.current = { stop: false };
1094
+ setBatch({ kind: kind, running: true, done: 0, total: ids.length, failures: [] });
1095
+ void runBatch({
1096
+ ids: ids,
1097
+ kind: kind,
1098
+ call: props.call,
1099
+ chunkSize: BATCH_CHUNK,
1100
+ onProgress: (/** @type {any} */ state) => {
1101
+ setBatch(state);
1102
+ },
1103
+ shouldStop: () => batchControl.current.stop === true,
1104
+ onRestored: (/** @type {any} */ sessionId) => props.onRestored?.(sessionId),
1105
+ }).then((/** @type {any} */ summary) => {
1106
+ setSelected((/** @type {any} */ current) => {
1107
+ /** @type {Record<string, boolean>} */
1108
+ var keep = {};
1109
+ for (let index = 0; index < summary.failures.length; index += 1) {
1110
+ if (current[summary.failures[index].entryId]) {
1111
+ keep[summary.failures[index].entryId] = true;
1112
+ }
1113
+ }
1114
+ return keep;
855
1115
  });
1116
+ setConfirmPurge(null);
1117
+ refresh();
1118
+ props.bump?.();
1119
+ if (kind === "purge") props.onPurged?.(undefined);
1120
+ });
856
1121
  };
857
1122
 
858
- var entries = data?.entries || [];
859
- var readOnly = !!health?.readOnly;
860
- var rowStyle = { borderTop: `1px solid ${T.border}`, padding: "10px 0" };
861
-
862
- var content = [];
863
- if (readOnly)
864
- content.push(
865
- h(
866
- "div",
867
- { key: "ro", style: { color: T.danger, marginBottom: "10px" } },
868
- props.t("panel.readOnly"),
869
- ),
870
- );
871
- if (error)
872
- content.push(
873
- h("div", { key: "err", style: { color: T.danger, marginBottom: "10px" } }, error),
874
- );
875
- content.push(
1123
+ var toolbar = h(
1124
+ "div",
1125
+ { className: "dsh-sdel-toolbar" },
1126
+ h(Check, {
1127
+ checked: allSelected,
1128
+ disabled: batchRunning || entries.length === 0,
1129
+ label:
1130
+ selectedIds.length > 0
1131
+ ? props.t("trash.selectCount", { n: selectedIds.length, total: entries.length })
1132
+ : props.t("trash.selectAll"),
1133
+ onChange: (/** @type {any} */ next) => {
1134
+ /** @type {Record<string, boolean>} */
1135
+ var map = {};
1136
+ if (next) {
1137
+ for (let index = 0; index < entries.length; index += 1) {
1138
+ map[entries[index].entryId] = true;
1139
+ }
1140
+ }
1141
+ setSelected(map);
1142
+ },
1143
+ }),
1144
+ h("span", { style: { flex: 1 } }),
876
1145
  h(
877
- "div",
878
- { key: "tabs", style: { display: "flex", gap: "8px", marginBottom: "12px" } },
879
- h(
880
- Btn,
881
- {
882
- onClick: () => {
883
- setTab("trash");
884
- },
885
- },
886
- props.t("panel.tabTrash") + (entries.length ? ` (${entries.length})` : ""),
887
- ),
888
- h(
889
- Btn,
890
- {
891
- onClick: () => {
892
- setTab("audit");
893
- loadAudit();
894
- },
895
- },
896
- props.t("panel.tabAudit"),
897
- ),
898
- h(
899
- Btn,
900
- {
901
- onClick: () => {
902
- setTab("health");
903
- loadHealth();
904
- },
905
- },
906
- props.t("panel.tabHealth"),
907
- ),
908
- h(
909
- Btn,
910
- {
911
- onClick: () => {
912
- setTab("receipts");
913
- loadReceipts();
914
- },
915
- },
916
- props.t("panel.tabReceipts"),
917
- ),
1146
+ Btn,
1147
+ {
1148
+ disabled: batchRunning || selectedIds.length === 0,
1149
+ onClick: () => startBatch(selectedIds, "restore"),
1150
+ },
1151
+ props.t("trash.restoreMany", { n: selectedIds.length }),
1152
+ ),
1153
+ h(
1154
+ Btn,
1155
+ {
1156
+ variant: "danger",
1157
+ disabled: batchRunning || selectedIds.length === 0,
1158
+ onClick: () => setConfirmPurge("__batch__"),
1159
+ },
1160
+ props.t("trash.purgeMany", { n: selectedIds.length }),
918
1161
  ),
919
1162
  );
920
1163
 
921
- if (tab === "receipts") {
922
- if (!receipts || receipts.length === 0) {
923
- content.push(
1164
+ var batchLine = batch
1165
+ ? h(
1166
+ "div",
1167
+ { className: "dsh-sdel-batch" },
924
1168
  h(
925
- "div",
926
- { key: "receipts-empty", style: { color: T.dim, padding: "8px 0" } },
927
- props.t("receipts.empty"),
1169
+ "span",
1170
+ { role: "status" },
1171
+ batch.running
1172
+ ? props.t("batch.progress", { done: batch.done, total: batch.total })
1173
+ : props.t("batch.done", {
1174
+ ok: batch.total - batch.failures.length,
1175
+ total: batch.total,
1176
+ }),
928
1177
  ),
929
- );
930
- } else {
931
- receipts.forEach((/** @type {any} */ receipt, /** @type {any} */ index) => {
932
- const removed = receipt.removed || [];
933
- const okCount = removed.filter(
934
- (/** @type {any} */ item) => item.status === "ok",
935
- ).length;
936
- const detail =
937
- receipt.action === "trash"
938
- ? `${formatBytes(receipt.sizeBytes || 0)} · ${okCount}/${removed.length}`
939
- : receipt.action === "restore"
940
- ? props.t("receipts.restored")
941
- : receipt.action === "purge"
942
- ? formatBytes(receipt.bytes || 0)
943
- : String(receipt.total || 0);
944
- content.push(
945
- h(
946
- "div",
947
- {
948
- key: `receipt-${index}`,
949
- title: String(receipt.sessionId || ""),
950
- style: {
951
- borderTop: `1px solid ${T.border}`,
952
- padding: "7px 0",
953
- fontSize: "12px",
954
- display: "flex",
955
- alignItems: "baseline",
956
- gap: "6px",
957
- },
958
- },
959
- h(
960
- "span",
961
- { style: { color: T.faint, whiteSpace: "nowrap" } },
962
- formatTime(receipt.at),
963
- ),
964
- h(
965
- "span",
966
- { style: { fontWeight: 600, whiteSpace: "nowrap" } },
967
- String(receipt.action || ""),
968
- ),
969
- h(
1178
+ batch.failures.length > 0
1179
+ ? h(
970
1180
  "span",
1181
+ { style: { color: T.danger } },
1182
+ props.t("batch.failed", { n: batch.failures.length }),
1183
+ )
1184
+ : null,
1185
+ batch.running
1186
+ ? h(
1187
+ Btn,
971
1188
  {
972
- style: {
973
- flex: 1,
974
- minWidth: 0,
975
- color: T.dim,
976
- overflow: "hidden",
977
- textOverflow: "ellipsis",
978
- whiteSpace: "nowrap",
1189
+ tight: true,
1190
+ onClick: () => {
1191
+ batchControl.current.stop = true;
979
1192
  },
980
1193
  },
981
- String(receipt.title || receipt.sessionId || "—"),
982
- ),
983
- h("span", { style: { color: T.faint, whiteSpace: "nowrap" } }, detail),
984
- ),
985
- );
986
- });
987
- }
988
- } else if (tab === "health") {
989
- if (scanError) {
990
- content.push(
991
- h("div", { key: "scan-err", style: { color: T.danger, padding: "8px 0" } }, scanError),
992
- );
993
- } else if (!scan) {
994
- content.push(
995
- h(
996
- "div",
997
- { key: "scan-loading", style: { color: T.dim, padding: "8px 0" } },
998
- props.t("health.loading"),
999
- ),
1000
- );
1001
- } else if (!scan.ok) {
1002
- content.push(
1003
- h(
1004
- "div",
1005
- { key: "scan-na", style: { color: T.dim, padding: "8px 0" } },
1006
- props.t("health.unavailable", { reason: scan.reason || "" }),
1007
- ),
1008
- );
1009
- } else {
1010
- content.push(
1011
- h(
1012
- "div",
1013
- { key: "scan-inventory", style: { color: T.dim, fontSize: "12px" } },
1014
- props.t("health.inventory", scan.inventory || {}),
1015
- ),
1016
- );
1017
- content.push(
1018
- h(
1194
+ props.t("batch.stop"),
1195
+ )
1196
+ : null,
1197
+ )
1198
+ : null;
1199
+
1200
+ var confirmLine =
1201
+ confirmPurge === "__batch__"
1202
+ ? h(
1019
1203
  "div",
1020
- { key: "scan-agent-tool", style: { color: T.dim, fontSize: "12px" } },
1021
- props.t("health.agentTool", {
1022
- state: scan.agentTool
1023
- ? props.t("health.agentToolOn")
1024
- : props.t("health.agentToolOff"),
1025
- }),
1026
- ),
1027
- );
1028
- if (scan.findings.length === 0) {
1029
- content.push(
1030
- h("div", { key: "scan-ok", style: { padding: "8px 0" } }, props.t("health.ok")),
1031
- );
1032
- }
1033
- scan.findings.forEach((/** @type {any} */ finding, /** @type {any} */ index) => {
1034
- content.push(
1204
+ { className: "dsh-sdel-confirm" },
1205
+ h("span", null, props.t("trash.purgeManyConfirm", { n: selectedIds.length })),
1035
1206
  h(
1036
- "div",
1037
- {
1038
- key: `finding-${index}`,
1039
- style: {
1040
- borderTop: `1px solid ${T.border}`,
1041
- padding: "8px 0",
1042
- color: finding.severity === "warn" ? T.text : T.dim,
1043
- },
1044
- },
1045
- h(
1046
- "div",
1047
- { style: { fontWeight: 600 } },
1048
- `${finding.label} · ${props.t("health.items", { n: finding.items.length })}`,
1049
- ),
1050
- h(
1051
- "div",
1052
- { style: { color: T.faint, fontSize: "12px", wordBreak: "break-all" } },
1053
- finding.items
1054
- .slice(0, 6)
1055
- .map((/** @type {any} */ item) =>
1056
- typeof item === "string" ? item : JSON.stringify(item),
1057
- )
1058
- .join(" · "),
1059
- ),
1060
- ),
1061
- );
1062
- });
1063
- if (scan.cleanable && scan.cleanable.total > 0) {
1064
- content.push(
1065
- h(
1066
- "div",
1207
+ Btn,
1067
1208
  {
1068
- key: "scan-clean",
1069
- style: { marginTop: "10px", display: "flex", gap: "8px", alignItems: "center" },
1209
+ tight: true,
1210
+ variant: "danger",
1211
+ onClick: () => startBatch(selectedIds, "purge"),
1070
1212
  },
1071
- confirmPurge === "__health__"
1072
- ? h(
1073
- Btn,
1074
- {
1075
- danger: true,
1076
- disabled: cleaning,
1077
- onClick: () => {
1078
- setCleaning(true);
1079
- setCleanMsg("");
1080
- props
1081
- .call("cleanHealth", { classes: ["archived", "pinned", "workspace"] })
1082
- .then((/** @type {any} */ result) => {
1083
- setCleaning(false);
1084
- setConfirmPurge(null);
1085
- setCleanMsg(props.t("health.cleanDone", { n: result.total }));
1086
- loadHealth();
1087
- props.bump?.();
1088
- })
1089
- .catch((/** @type {any} */ reason) => {
1090
- setCleaning(false);
1091
- setCleanMsg(errorText(reason));
1092
- });
1093
- },
1094
- },
1095
- props.t("health.cleanConfirm", { n: scan.cleanable.total }),
1096
- )
1097
- : h(
1098
- Btn,
1099
- { onClick: () => setConfirmPurge("__health__") },
1100
- props.t("health.clean", { n: scan.cleanable.total }),
1101
- ),
1213
+ props.t("panel.purge"),
1102
1214
  ),
1103
- );
1104
- }
1105
- if (cleanMsg) {
1106
- content.push(
1107
1215
  h(
1108
- "div",
1109
- { key: "scan-msg", style: { color: T.dim, marginTop: "8px", fontSize: "12px" } },
1110
- cleanMsg,
1216
+ Btn,
1217
+ { tight: true, onClick: () => setConfirmPurge(null) },
1218
+ props.t("panel.cancelConfirm"),
1111
1219
  ),
1112
- );
1113
- }
1114
- }
1115
- } else if (tab === "trash") {
1116
- if (entries.length === 0) {
1117
- content.push(
1118
- h(
1119
- "div",
1120
- { key: "empty", style: { color: T.dim, padding: "12px 0" } },
1121
- props.t("panel.empty"),
1122
- ),
1123
- );
1124
- } else {
1125
- content.push(
1220
+ )
1221
+ : null;
1222
+
1223
+ var rows = [];
1224
+ for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
1225
+ const entry = entries[entryIndex];
1226
+ const confirmThis = confirmPurge === entry.entryId;
1227
+ rows.push(
1228
+ h(
1229
+ "div",
1230
+ { key: entry.entryId, className: "dsh-sdel-row" },
1231
+ h(Check, {
1232
+ checked: Boolean(selected[entry.entryId]),
1233
+ disabled: batchRunning,
1234
+ onChange: () =>
1235
+ setSelected((/** @type {any} */ current) => ({
1236
+ ...current,
1237
+ [entry.entryId]: !current[entry.entryId],
1238
+ })),
1239
+ }),
1126
1240
  h(
1127
- "div",
1128
- {
1129
- key: "trash-tools",
1130
- style: {
1131
- display: "flex",
1132
- gap: "8px",
1133
- alignItems: "center",
1134
- marginBottom: "8px",
1135
- flexWrap: "wrap",
1136
- },
1137
- },
1241
+ "span",
1242
+ { className: "dsh-sdel-row-text" },
1138
1243
  h(
1139
- Btn,
1244
+ "span",
1140
1245
  {
1141
- onClick: () => {
1142
- /** @type {Record<string, boolean>} */
1143
- const all = {};
1144
- for (const item of entries) all[item.entryId] = true;
1145
- setSelectedTrash(all);
1146
- },
1147
- disabled: trashBusy,
1246
+ className: "dsh-sdel-row-title dsh-sdel-truncate",
1247
+ title: entry.title || entry.sessionId,
1148
1248
  },
1149
- props.t("trash.selectAll"),
1249
+ entry.title || entry.sessionId,
1150
1250
  ),
1151
1251
  h(
1152
- Btn,
1153
- { onClick: () => setSelectedTrash({}), disabled: trashBusy },
1154
- props.t("trash.clear"),
1155
- ),
1156
- h(
1157
- Btn,
1158
- {
1159
- disabled: trashBusy || selectedEntryIds.length === 0,
1160
- onClick: doBatchRestore,
1161
- },
1162
- props.t("trash.restoreMany", { n: selectedEntryIds.length }),
1252
+ "span",
1253
+ { className: "dsh-sdel-row-meta" },
1254
+ `${props.t("panel.size", { size: formatBytes(entry.bytes) })} · ${props.t("panel.trashedAt", { time: formatTime(entry.trashedAt) })}`,
1163
1255
  ),
1164
- confirmPurge === "__trashBatchPurge__"
1165
- ? h(
1256
+ ),
1257
+ confirmThis
1258
+ ? h(
1259
+ "span",
1260
+ { className: "dsh-sdel-row-actions dsh-sdel-row-actions--open" },
1261
+ h(
1166
1262
  Btn,
1167
1263
  {
1168
- danger: true,
1169
- disabled: trashBusy || selectedEntryIds.length === 0,
1170
- onClick: doBatchPurge,
1264
+ tight: true,
1265
+ variant: "danger",
1266
+ onClick: () => doPurge(entry.entryId, entry.sessionId),
1171
1267
  },
1172
- props.t("trash.purgeManyConfirm", { n: selectedEntryIds.length }),
1173
- )
1174
- : h(
1268
+ props.t("panel.purgeConfirm"),
1269
+ ),
1270
+ h(
1271
+ Btn,
1272
+ { tight: true, onClick: () => setConfirmPurge(null) },
1273
+ props.t("panel.cancelConfirm"),
1274
+ ),
1275
+ )
1276
+ : h(
1277
+ "span",
1278
+ { className: "dsh-sdel-row-actions" },
1279
+ h(
1175
1280
  Btn,
1176
1281
  {
1177
- danger: true,
1178
- disabled: trashBusy || selectedEntryIds.length === 0,
1179
- onClick: () => setConfirmPurge("__trashBatchPurge__"),
1282
+ tight: true,
1283
+ disabled: busyId === entry.entryId || batchRunning,
1284
+ onClick: () => doRestore(entry.entryId, entry.sessionId),
1180
1285
  },
1181
- props.t("trash.purgeMany", { n: selectedEntryIds.length }),
1286
+ props.t("panel.restore"),
1182
1287
  ),
1183
- ),
1184
- );
1185
- if (trashMsg) {
1186
- content.push(
1187
- h(
1188
- "div",
1189
- {
1190
- key: "trash-msg",
1191
- style: { color: T.dim, fontSize: "12px", marginBottom: "6px" },
1192
- },
1193
- trashMsg,
1194
- ),
1195
- );
1196
- }
1197
- entries.forEach((/** @type {any} */ entry) => {
1198
- content.push(
1199
- h(
1200
- "div",
1201
- { key: entry.entryId, style: rowStyle },
1202
- h(
1203
- "label",
1204
- { style: { display: "flex", alignItems: "baseline", gap: "8px" } },
1205
- h("input", {
1206
- type: "checkbox",
1207
- checked: Boolean(/** @type {any} */ (selectedTrash)[entry.entryId]),
1208
- disabled: trashBusy,
1209
- onChange: () =>
1210
- setSelectedTrash((/** @type {any} */ current) => ({
1211
- ...current,
1212
- [entry.entryId]: !current[entry.entryId],
1213
- })),
1214
- style: { marginTop: "2px" },
1215
- }),
1216
- h("span", { style: { fontWeight: 600 } }, entry.title || entry.sessionId),
1217
- ),
1218
- h(
1219
- "div",
1220
- { style: { color: T.dim, fontSize: "12px" } },
1221
- props.t("panel.size", { size: formatBytes(entry.bytes) }) +
1222
- " · " +
1223
- props.t("panel.trashedAt", { time: formatTime(entry.trashedAt) }),
1224
- ),
1225
- h(
1226
- "div",
1227
- { style: { display: "flex", gap: "8px", marginTop: "6px" } },
1228
1288
  h(
1229
1289
  Btn,
1230
1290
  {
1231
- onClick: () => {
1232
- doRestore(entry.entryId, entry.sessionId);
1233
- },
1234
- disabled: busyId === entry.entryId,
1291
+ tight: true,
1292
+ variant: "danger",
1293
+ disabled: busyId === entry.entryId || batchRunning,
1294
+ onClick: () => setConfirmPurge(entry.entryId),
1235
1295
  },
1236
- props.t("panel.restore"),
1296
+ props.t("panel.purge"),
1237
1297
  ),
1238
- confirmPurge === entry.entryId
1239
- ? h(
1240
- Btn,
1241
- {
1242
- onClick: () => {
1243
- doPurge(entry.entryId, entry.sessionId);
1244
- },
1245
- danger: true,
1246
- disabled: busyId === entry.entryId,
1247
- },
1248
- props.t("panel.purgeConfirm"),
1249
- )
1250
- : h(
1251
- Btn,
1252
- {
1253
- onClick: () => {
1254
- setConfirmPurge(entry.entryId);
1255
- },
1256
- danger: true,
1257
- },
1258
- props.t("panel.purge"),
1259
- ),
1260
1298
  ),
1261
- ),
1262
- );
1263
- });
1264
- }
1265
- } else if ((audit || []).length === 0) {
1266
- content.push(
1267
- h(
1268
- "div",
1269
- { key: "ae", style: { color: T.dim, padding: "12px 0" } },
1270
- props.t("panel.auditEmpty"),
1271
1299
  ),
1272
1300
  );
1273
- } else {
1274
- (audit || [])
1275
- .slice()
1276
- .reverse()
1277
- .forEach((/** @type {any} */ entry, /** @type {any} */ index) => {
1278
- content.push(
1279
- h(
1280
- "div",
1281
- {
1282
- key: `audit-${index}`,
1283
- style: { borderTop: `1px solid ${T.border}`, padding: "6px 0", fontSize: "12px" },
1284
- },
1285
- h("span", { style: { color: T.faint } }, `${formatTime(entry.ts)} `),
1286
- h("span", { style: { fontWeight: 600 } }, `${String(entry.action || "")} `),
1287
- h(
1288
- "span",
1289
- { title: entry.sessionId || "", style: { color: T.dim } },
1290
- String(entry.result || "") +
1291
- (entry.sessionId ? ` · ${String(entry.sessionId).slice(0, 13)}…` : "") +
1292
- (entry.detail ? ` · ${entry.detail}` : ""),
1293
- ),
1294
- ),
1295
- );
1296
- });
1297
1301
  }
1298
1302
 
1299
- if (data?.unknown && data.unknown.length > 0) {
1300
- content.push(
1301
- h(
1302
- "div",
1303
- { key: "unk", style: { color: T.faint, fontSize: "12px", marginTop: "10px" } },
1304
- props.t("panel.unknown", { n: data.unknown.length }),
1305
- ),
1306
- );
1307
- }
1308
- if (data?.pending && data.pending.length > 0) {
1309
- content.push(
1310
- h(
1311
- "div",
1312
- { key: "pend", style: { color: T.faint, fontSize: "12px", marginTop: "6px" } },
1313
- props.t("panel.pending", { n: data.pending.length }),
1314
- ),
1315
- );
1316
- }
1303
+ var body = h(
1304
+ React.Fragment,
1305
+ null,
1306
+ readOnly
1307
+ ? h(
1308
+ "div",
1309
+ { style: { color: T.danger, marginBottom: "10px" } },
1310
+ props.t("panel.readOnly"),
1311
+ )
1312
+ : null,
1313
+ error ? h("div", { style: { color: T.danger, marginBottom: "10px" } }, error) : null,
1314
+ entries.length === 0
1315
+ ? h("div", { style: { color: T.dim, padding: "12px 0" } }, props.t("panel.empty"))
1316
+ : h(
1317
+ "div",
1318
+ { className: "dsh-sdel-panel" },
1319
+ toolbar,
1320
+ confirmLine,
1321
+ batchLine,
1322
+ h("div", { className: "dsh-sdel-list" }, rows),
1323
+ ),
1324
+ (data?.unknown?.length ?? 0) > 0
1325
+ ? h(
1326
+ "div",
1327
+ { style: { color: T.faint, fontSize: "12px", marginTop: "8px" } },
1328
+ props.t("panel.unknown", { n: data.unknown.length }),
1329
+ )
1330
+ : null,
1331
+ (data?.pending?.length ?? 0) > 0
1332
+ ? h(
1333
+ "div",
1334
+ { style: { color: T.faint, fontSize: "12px", marginTop: "4px" } },
1335
+ props.t("panel.pending", { n: data.pending.length }),
1336
+ )
1337
+ : null,
1338
+ );
1317
1339
 
1318
1340
  return h(
1319
1341
  Dialog,
1320
1342
  {
1321
1343
  onClose: () => {
1344
+ if (batchRunning) return;
1322
1345
  props.panelStore.set(false);
1323
1346
  },
1324
1347
  closeLabel: props.t("panel.close"),
@@ -1326,19 +1349,281 @@ window.__ModuleLoader__.load({
1326
1349
  footer: h(
1327
1350
  Btn,
1328
1351
  {
1329
- autoFocus: true,
1330
1352
  onClick: () => {
1331
1353
  props.panelStore.set(false);
1332
1354
  },
1355
+ disabled: batchRunning,
1333
1356
  },
1334
1357
  props.t("panel.close"),
1335
1358
  ),
1336
1359
  },
1360
+ body,
1361
+ );
1362
+ }
1363
+
1364
+ /**
1365
+ * 设置页「会话回收站」:偏好 + 回收站概览 + 维护(体检/回执/审计)。
1366
+ * 原来这四块是回收站面板里的四个页签,搬到这里后主面板只剩一件事。
1367
+ */
1368
+ function SettingsSection(/** @type {any} */ props) {
1369
+ var prefsState = useStore(props.prefsStore);
1370
+ var prefs = prefsState[0];
1371
+ var infoState = React.useState(null);
1372
+ var info = infoState[0];
1373
+ var setInfo = infoState[1];
1374
+ var healthState = React.useState(null);
1375
+ var health = healthState[0];
1376
+ var setHealth = healthState[1];
1377
+ var healthErrorState = React.useState(null);
1378
+ var healthError = healthErrorState[0];
1379
+ var setHealthError = healthErrorState[1];
1380
+ var receiptsState = React.useState(null);
1381
+ var receipts = receiptsState[0];
1382
+ var setReceipts = receiptsState[1];
1383
+ var auditState = React.useState(null);
1384
+ var audit = auditState[0];
1385
+ var setAudit = auditState[1];
1386
+ var cleaningState = React.useState(false);
1387
+ var cleaning = cleaningState[0];
1388
+ var setCleaning = cleaningState[1];
1389
+ var confirmCleanState = React.useState(false);
1390
+ var confirmClean = confirmCleanState[0];
1391
+ var setConfirmClean = confirmCleanState[1];
1392
+ var msgState = React.useState("");
1393
+ var message = msgState[0];
1394
+ var setMessage = msgState[1];
1395
+
1396
+ React.useEffect(() => {
1397
+ var alive = true;
1398
+ props
1399
+ .call("list")
1400
+ .then((/** @type {any} */ value) => {
1401
+ if (alive) setInfo(value);
1402
+ })
1403
+ .catch(() => {});
1404
+ props
1405
+ .call("healthScan")
1406
+ .then((/** @type {any} */ value) => {
1407
+ if (alive) setHealth(value);
1408
+ })
1409
+ .catch((/** @type {any} */ reason) => {
1410
+ if (alive) setHealthError(errorText(reason));
1411
+ });
1412
+ props
1413
+ .call("receipts", { limit: 50 })
1414
+ .then((/** @type {any} */ value) => {
1415
+ if (alive) setReceipts(value?.entries || []);
1416
+ })
1417
+ .catch((/** @type {any} */ reason) => {
1418
+ // 空白 + 一声不响是最差的失败姿态:把原因写进页面里。
1419
+ if (alive) setMessage(errorText(reason));
1420
+ });
1421
+ props
1422
+ .call("audit", { limit: 100 })
1423
+ .then((/** @type {any} */ value) => {
1424
+ if (alive) setAudit(value?.entries || []);
1425
+ })
1426
+ .catch((/** @type {any} */ reason) => {
1427
+ if (alive) setMessage(errorText(reason));
1428
+ });
1429
+ return () => {
1430
+ alive = false;
1431
+ };
1432
+ }, []);
1433
+
1434
+ var entries = info?.entries || [];
1435
+ var totalBytes = 0;
1436
+ for (let index = 0; index < entries.length; index += 1) {
1437
+ totalBytes += Number(entries[index].bytes) || 0;
1438
+ }
1439
+ var cascade = prefs ? prefs.cascadeChildren === true : false;
1440
+
1441
+ var setCascade = (/** @type {any} */ next) => {
1442
+ props.prefsStore.set({ cascadeChildren: next });
1443
+ props.call("setPrefs", { cascadeChildren: next }).catch(() => {});
1444
+ };
1445
+
1446
+ var cleanable = health?.ok ? health.cleanable : null;
1447
+ var cleanRows = [];
1448
+ if (confirmClean && cleanable && cleanable.total > 0) {
1449
+ cleanRows.push(
1450
+ h(
1451
+ "div",
1452
+ { key: "confirm", style: { display: "flex", gap: "8px", alignItems: "center" } },
1453
+ h(
1454
+ "span",
1455
+ { style: { color: T.danger, fontSize: "12px" } },
1456
+ props.t("settings.health.cleanConfirm", { n: cleanable.total }),
1457
+ ),
1458
+ h(
1459
+ Btn,
1460
+ {
1461
+ tight: true,
1462
+ variant: "danger",
1463
+ disabled: cleaning,
1464
+ onClick: () => {
1465
+ setCleaning(true);
1466
+ props
1467
+ .call("cleanHealth", { classes: ["archived", "pinned", "workspace"] })
1468
+ .then((/** @type {any} */ result) => {
1469
+ setCleaning(false);
1470
+ setConfirmClean(false);
1471
+ setMessage(props.t("settings.health.cleaned", { n: result.total }));
1472
+ })
1473
+ .catch((/** @type {any} */ reason) => {
1474
+ setCleaning(false);
1475
+ setMessage(errorText(reason));
1476
+ });
1477
+ },
1478
+ },
1479
+ props.t("settings.health.clean", { n: cleanable.total }),
1480
+ ),
1481
+ h(
1482
+ Btn,
1483
+ { tight: true, onClick: () => setConfirmClean(false) },
1484
+ props.t("confirm.cancel"),
1485
+ ),
1486
+ ),
1487
+ );
1488
+ }
1489
+
1490
+ return h(
1491
+ "div",
1492
+ { className: "dsh-sdel-settings" },
1493
+ h("div", { className: "dsh-sdel-group" }, props.t("settings.group.delete")),
1494
+ h(SettingRow, {
1495
+ title: props.t("settings.cascade.title"),
1496
+ description: props.t("settings.cascade.desc"),
1497
+ action: h(Toggle, {
1498
+ checked: cascade,
1499
+ label: props.t("settings.cascade.title"),
1500
+ onChange: setCascade,
1501
+ }),
1502
+ }),
1503
+ h(SettingRow, {
1504
+ title: "",
1505
+ description: null,
1506
+ action: h(
1507
+ Btn,
1508
+ {
1509
+ tight: true,
1510
+ disabled: !cascade,
1511
+ onClick: () => {
1512
+ setCascade(false);
1513
+ setMessage(props.t("settings.cascade.resetDone"));
1514
+ },
1515
+ },
1516
+ props.t("settings.cascade.reset"),
1517
+ ),
1518
+ }),
1519
+ h("div", { className: "dsh-sdel-group" }, props.t("settings.group.trash")),
1520
+ h(SettingRow, {
1521
+ title: props.t("settings.trash.summary", {
1522
+ n: entries.length,
1523
+ size: formatBytes(totalBytes),
1524
+ }),
1525
+ description: info ? info.trashRoot : null,
1526
+ action: h(
1527
+ Btn,
1528
+ {
1529
+ tight: true,
1530
+ onClick: () => {
1531
+ props.close?.();
1532
+ props.panelStore.set(true);
1533
+ },
1534
+ },
1535
+ props.t("settings.trash.open"),
1536
+ ),
1537
+ }),
1538
+ h("div", { className: "dsh-sdel-group" }, props.t("settings.group.maintenance")),
1539
+ h(SettingRow, {
1540
+ title: props.t("settings.health.title"),
1541
+ description: props.t("settings.health.desc"),
1542
+ action:
1543
+ cleanable && cleanable.total > 0
1544
+ ? h(
1545
+ Btn,
1546
+ { tight: true, disabled: cleaning, onClick: () => setConfirmClean(true) },
1547
+ props.t("settings.health.items", { n: cleanable.total }),
1548
+ )
1549
+ : null,
1550
+ children: healthError
1551
+ ? h(
1552
+ "div",
1553
+ { style: { color: T.danger, fontSize: "12px" } },
1554
+ props.t("settings.health.unavailable", { reason: healthError }),
1555
+ )
1556
+ : !health
1557
+ ? h(
1558
+ "div",
1559
+ { style: { color: T.faint, fontSize: "12px" } },
1560
+ props.t("settings.loading"),
1561
+ )
1562
+ : !health.ok
1563
+ ? h(
1564
+ "div",
1565
+ { style: { color: T.dim, fontSize: "12px" } },
1566
+ props.t("settings.health.unavailable", { reason: health.reason || "" }),
1567
+ )
1568
+ : health.findings && health.findings.length === 0
1569
+ ? h(
1570
+ "div",
1571
+ { style: { color: T.dim, fontSize: "12px" } },
1572
+ props.t("settings.health.ok"),
1573
+ )
1574
+ : h(
1575
+ "div",
1576
+ { style: { color: T.dim, fontSize: "12px" } },
1577
+ joinList(
1578
+ (health.findings || []).map((/** @type {any} */ finding) => finding.label),
1579
+ 4,
1580
+ ),
1581
+ ),
1582
+ }),
1583
+ cleanRows.length > 0 ? h("div", { style: { padding: "0 0 12px" } }, cleanRows) : null,
1337
1584
  h(
1338
1585
  "div",
1339
- { ref: listRef, onKeyDown: onListKeyDown, tabIndex: -1, style: { outline: "none" } },
1340
- content,
1586
+ { className: "dsh-sdel-setting-row dsh-sdel-setting-row--stack" },
1587
+ h(
1588
+ Disclosure,
1589
+ {
1590
+ label: props.t("settings.receipts.title"),
1591
+ meta: receipts ? String(receipts.length) : "",
1592
+ },
1593
+ !receipts || receipts.length === 0
1594
+ ? h("div", null, props.t("settings.receipts.empty"))
1595
+ : receipts.map((/** @type {any} */ receipt, /** @type {any} */ receiptIndex) =>
1596
+ h(
1597
+ "div",
1598
+ { key: `receipt-${receiptIndex}`, className: "dsh-sdel-truncate" },
1599
+ `${formatTime(receipt.at)} · ${String(receipt.action || "")} · ${String(receipt.title || receipt.sessionId || "")}`,
1600
+ ),
1601
+ ),
1602
+ ),
1341
1603
  ),
1604
+ h(
1605
+ "div",
1606
+ { className: "dsh-sdel-setting-row dsh-sdel-setting-row--stack" },
1607
+ h(
1608
+ Disclosure,
1609
+ { label: props.t("settings.audit.title"), meta: audit ? String(audit.length) : "" },
1610
+ !audit || audit.length === 0
1611
+ ? h("div", null, props.t("settings.audit.empty"))
1612
+ : audit
1613
+ .slice()
1614
+ .reverse()
1615
+ .map((/** @type {any} */ entry, /** @type {any} */ auditIndex) =>
1616
+ h(
1617
+ "div",
1618
+ { key: `audit-${auditIndex}`, className: "dsh-sdel-truncate" },
1619
+ `${formatTime(entry.ts)} · ${String(entry.action || "")} · ${String(entry.result || "")}${entry.detail ? ` · ${entry.detail}` : ""}`,
1620
+ ),
1621
+ ),
1622
+ ),
1623
+ ),
1624
+ message
1625
+ ? h("div", { style: { color: T.dim, fontSize: "12px", paddingTop: "8px" } }, message)
1626
+ : null,
1342
1627
  );
1343
1628
  }
1344
1629
 
@@ -1346,6 +1631,7 @@ window.__ModuleLoader__.load({
1346
1631
  var toastState = useStore(props.toastStore);
1347
1632
  var toast = toastState[0];
1348
1633
  var entryId = toast ? toast.entryId : null;
1634
+ var text = toast ? toast.text : null;
1349
1635
  var shownState = React.useState(false);
1350
1636
  var shown = shownState[0];
1351
1637
  var setShown = shownState[1];
@@ -1354,7 +1640,7 @@ window.__ModuleLoader__.load({
1354
1640
  var setRestoring = restoreState[1];
1355
1641
 
1356
1642
  React.useEffect(() => {
1357
- if (!entryId) {
1643
+ if (!toast) {
1358
1644
  setShown(false);
1359
1645
  return undefined;
1360
1646
  }
@@ -1368,7 +1654,7 @@ window.__ModuleLoader__.load({
1368
1654
  clearTimeout(raise);
1369
1655
  clearTimeout(timer);
1370
1656
  };
1371
- }, [entryId]);
1657
+ }, [toast]);
1372
1658
 
1373
1659
  if (!toast) return null;
1374
1660
  return h(
@@ -1394,29 +1680,148 @@ window.__ModuleLoader__.load({
1394
1680
  transition: "opacity .18s ease, transform .18s ease",
1395
1681
  },
1396
1682
  },
1397
- h("span", null, props.t("confirm.done")),
1398
- h(
1399
- Btn,
1400
- {
1401
- disabled: restoring,
1402
- onClick: () => {
1403
- setRestoring(true);
1404
- props
1405
- .call("restore", { entryId: toast.entryId })
1406
- .then(() => {
1407
- setRestoring(false);
1408
- props.toastStore.set(null);
1409
- })
1410
- .catch(() => {
1411
- setRestoring(false);
1412
- });
1413
- },
1414
- },
1415
- props.t("confirm.undo"),
1416
- ),
1683
+ h("span", null, text ? text : props.t("confirm.done")),
1684
+ entryId
1685
+ ? h(
1686
+ Btn,
1687
+ {
1688
+ disabled: restoring,
1689
+ onClick: () => {
1690
+ setRestoring(true);
1691
+ props
1692
+ .call("restore", { entryId: toast.entryId })
1693
+ .then(() => {
1694
+ setRestoring(false);
1695
+ props.toastStore.set(null);
1696
+ })
1697
+ .catch(() => {
1698
+ setRestoring(false);
1699
+ });
1700
+ },
1701
+ },
1702
+ props.t("confirm.undo"),
1703
+ )
1704
+ : null,
1417
1705
  );
1418
1706
  }
1419
1707
 
1708
+ /** 面板打开后的轮询间隔:外部(agent 工具 / 另一个窗口)改了回收站也要跟上。 */
1709
+ var PANEL_POLL_MS = 5000;
1710
+
1711
+ /**
1712
+ * 加载回收站面板的数据。抽出来是为了单测能直接驱动它 —— 面板的加载失败
1713
+ * 不许把整个浮层(确认框、toast)一起拖死,这个行为必须在没有浏览器的地方也能验证。
1714
+ * @param {(method: string, request?: any) => Promise<any>} call
1715
+ * @param {{ setData?: (value: any) => void, setReadOnly?: (value: boolean) => void,
1716
+ * setError?: (value: string | null) => void }} sinks
1717
+ * @returns {{ load: () => Promise<any>, loadHealth: () => Promise<void> }}
1718
+ */
1719
+ function createPanelLoader(call, sinks) {
1720
+ var report = (/** @type {any} */ reason) => {
1721
+ try {
1722
+ sinks.setError?.(errorText(reason));
1723
+ } catch (_error) {
1724
+ /* 渲染层挂了也不该让 RPC 的 rejection 逃逸成未捕获异常 */
1725
+ }
1726
+ };
1727
+ var load = () =>
1728
+ Promise.resolve()
1729
+ .then(() => call("list"))
1730
+ .then(
1731
+ (/** @type {any} */ value) => {
1732
+ try {
1733
+ sinks.setData?.(value);
1734
+ } catch (_error) {}
1735
+ return value;
1736
+ },
1737
+ (/** @type {any} */ reason) => {
1738
+ report(reason);
1739
+ return null;
1740
+ },
1741
+ );
1742
+ var loadHealth = () =>
1743
+ Promise.resolve()
1744
+ .then(() => call("health"))
1745
+ .then(
1746
+ (/** @type {any} */ value) => {
1747
+ try {
1748
+ sinks.setReadOnly?.(value?.readOnly === true);
1749
+ } catch (_error) {}
1750
+ },
1751
+ () => {
1752
+ /* 能力快照拿不到只影响只读横幅,不报错 */
1753
+ },
1754
+ );
1755
+ return { load: load, loadHealth: loadHealth };
1756
+ }
1757
+
1758
+ /**
1759
+ * 分批执行批量动作。宿主单次上限是防御性硬上限,界面按 chunkSize 切块;
1760
+ * 每块之间让出一帧:进度可见、可中途停止、部分失败不中断其余批次。
1761
+ * 抽成纯函数是为了在单测里用假 call 直接验证「>50 条不会被整单拒绝」与
1762
+ * 「部分失败被汇总、成功的也不再算失败」。
1763
+ * @param {{ ids: string[], kind: "purge" | "restore", call: (method: string, request?: any) => Promise<any>,
1764
+ * chunkSize?: number, onProgress?: (state: any) => void, shouldStop?: () => boolean,
1765
+ * onRestored?: (sessionId: string) => void }} options
1766
+ * @returns {Promise<{ kind: string, total: number, done: number, ok: number, failures: any[], stopped: boolean }>}
1767
+ */
1768
+ async function runBatch(options) {
1769
+ var ids = options.ids || [];
1770
+ var kind = options.kind === "restore" ? "restore" : "purge";
1771
+ var chunkSize = options.chunkSize || BATCH_CHUNK;
1772
+ var groups = chunk(ids, chunkSize);
1773
+ /** @type {any[]} */
1774
+ var failures = [];
1775
+ var done = 0;
1776
+ var stopped = false;
1777
+ const emit = (/** @type {boolean} */ running) => {
1778
+ try {
1779
+ options.onProgress?.({
1780
+ kind: kind,
1781
+ running: running,
1782
+ done: done,
1783
+ total: ids.length,
1784
+ failures: failures.slice(),
1785
+ });
1786
+ } catch (_error) {}
1787
+ };
1788
+ for (let index = 0; index < groups.length; index += 1) {
1789
+ if (options.shouldStop?.()) {
1790
+ stopped = true;
1791
+ break;
1792
+ }
1793
+ const group = groups[index];
1794
+ try {
1795
+ const result = await options.call(kind === "purge" ? "purgeMany" : "restoreMany", {
1796
+ entryIds: group,
1797
+ });
1798
+ const results = result?.results || [];
1799
+ for (let itemIndex = 0; itemIndex < results.length; itemIndex += 1) {
1800
+ const item = results[itemIndex];
1801
+ if (!item.ok) failures.push(item);
1802
+ else if (kind === "restore" && item.sessionId) options.onRestored?.(item.sessionId);
1803
+ }
1804
+ } catch (reason) {
1805
+ for (let groupIndex = 0; groupIndex < group.length; groupIndex += 1) {
1806
+ failures.push({ entryId: group[groupIndex], ok: false, error: errorText(reason) });
1807
+ }
1808
+ }
1809
+ done += group.length;
1810
+ emit(true);
1811
+ // 让出一帧:让「处理中 n/total」和「停止」真的可见、可点。
1812
+ await new Promise((resolve) => setTimeout(resolve, 0));
1813
+ }
1814
+ emit(false);
1815
+ return {
1816
+ kind: kind,
1817
+ total: ids.length,
1818
+ done: done,
1819
+ ok: done - failures.length,
1820
+ failures: failures,
1821
+ stopped: stopped,
1822
+ };
1823
+ }
1824
+
1420
1825
  /** 一个浮层里渲染确认框 + 面板 + toast,因为 shell.overlay 是单实例 slot。 */
1421
1826
  function SessionDeleteOverlay(/** @type {any} */ props) {
1422
1827
  return h(
@@ -1426,8 +1831,10 @@ window.__ModuleLoader__.load({
1426
1831
  DeleteConfirm,
1427
1832
  Object.assign({}, props, {
1428
1833
  requestStore: props.requestStore,
1834
+ prefsStore: props.prefsStore,
1429
1835
  call: props.call,
1430
1836
  onTrashed: props.onTrashed,
1837
+ onTrashedMany: props.onTrashedMany,
1431
1838
  }),
1432
1839
  ),
1433
1840
  h(
@@ -1445,25 +1852,83 @@ window.__ModuleLoader__.load({
1445
1852
  );
1446
1853
  }
1447
1854
 
1855
+ /** 单批条目数:既让「处理中 n/total」有节奏,也避免一次 RPC 太久没有反馈。 */
1856
+ var BATCH_CHUNK = 20;
1857
+
1858
+ /**
1859
+ * 等 contextMenus 服务就绪的宽限期(毫秒)。Cordis 的 inject 只有「必须」语义,
1860
+ * 没有可选依赖:老宿主永远不会提供这个服务,等下去就等于「会话菜单里没有删除项」。
1861
+ * 所以超时就认为没有该服务,退回到旧的 slot 渲染。
1862
+ */
1863
+ var MENU_FALLBACK = { ms: 1200 };
1864
+
1865
+ /** 菜单图标键:注册到宿主的 contextMenu.icon keyed slot 上。 */
1866
+ var TRASH_ICON = "session-delete.trash";
1867
+
1868
+ /** 快捷键命令 id:菜单行的 commandId 必须与它一致,键位提示才会显示。 */
1869
+ var COMMAND_DELETE = "session.delete";
1870
+ var COMMAND_DELETE_WORKSPACE = "session.deleteWorkspace";
1871
+
1448
1872
  exports.inject = ["slots", "locale", "connection"];
1449
1873
  exports.apply = function apply(/** @type {any} */ ctx) {
1450
1874
  ctx.effect(() => ctx.locale.register(NS, { zh: zh, en: en }), "session-delete: dictionaries");
1451
1875
 
1876
+ /** @type {(key: string, values?: any) => string} */
1877
+ var translate;
1878
+ var fallbackTranslate = (/** @type {string} */ key) =>
1879
+ /** @type {Record<string, string>} */ (zh)[key] || key;
1880
+ try {
1881
+ translate =
1882
+ ctx.locale && typeof ctx.locale.bind === "function"
1883
+ ? ctx.locale.bind(NS)
1884
+ : fallbackTranslate;
1885
+ } catch (_error) {
1886
+ translate = fallbackTranslate;
1887
+ }
1888
+
1452
1889
  // 用真实的 :hover / :focus-visible 伪类,避免依赖 React 合成事件与内联样式。
1890
+ // 原则:控件外观只调宿主 token;行高与间距对齐设置页(16px 竖向留白、.5px 分隔线)。
1453
1891
  ctx.effect(() => {
1454
1892
  const style = document.createElement("style");
1455
1893
  // 标注归属:便于在 DevTools 里认出这段样式、也方便测试断言插件确实加载了。
1456
1894
  style.setAttribute("data-plugin", "@kangyishuai/dsh-session-delete");
1457
1895
  style.textContent = [
1458
- ".dsh-sdel-btn{background:transparent;color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));transition:background-color 150ms ease,border-color 150ms ease,transform 80ms ease,color 150ms ease;}",
1459
- ".dsh-sdel-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));}",
1460
- ".dsh-sdel-btn:active{transform:scale(.98);}",
1896
+ ".dsh-sdel-btn{background:transparent;color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));transition:background-color 150ms ease,border-color 150ms ease,transform 80ms ease,color 150ms ease;white-space:nowrap;}",
1897
+ ".dsh-sdel-btn:hover:enabled{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));}",
1898
+ ".dsh-sdel-btn:active:enabled{transform:scale(.98);}",
1461
1899
  ".dsh-sdel-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:1px;}",
1462
1900
  ".dsh-sdel-btn--danger{color:var(--dsw-alias-state-error-primary,#d9534f);}",
1463
- ".dsh-sdel-btn--danger:hover{background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.16));}",
1901
+ ".dsh-sdel-btn--danger:hover:enabled{background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.16));}",
1902
+ ".dsh-sdel-btn--quiet{border-color:transparent;}",
1903
+ ".dsh-sdel-btn--tight{padding:2px 8px;border-radius:6px;font-size:12px;}",
1464
1904
  ".dsh-sdel-footer{background:transparent;color:var(--dsw-alias-label-secondary,GrayText);border:1px solid transparent;border-radius:8px;transition:background-color 150ms ease,color 150ms ease;}",
1465
1905
  ".dsh-sdel-footer:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));color:var(--dsw-alias-label-primary,inherit);}",
1466
1906
  ".dsh-sdel-footer:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:1px;}",
1907
+ ".dsh-sdel-truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;}",
1908
+ ".dsh-sdel-panel{display:flex;flex-direction:column;gap:8px;min-height:0;}",
1909
+ ".dsh-sdel-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}",
1910
+ ".dsh-sdel-list{max-height:min(56vh,520px);overflow-y:auto;border-top:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));}",
1911
+ ".dsh-sdel-row{display:flex;align-items:center;gap:10px;padding:7px 0;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));min-width:0;}",
1912
+ ".dsh-sdel-row:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.08));}",
1913
+ ".dsh-sdel-row-text{display:flex;flex-direction:column;gap:1px;flex:1 1 auto;min-width:0;}",
1914
+ ".dsh-sdel-row-title{font-size:13px;line-height:18px;min-width:0;}",
1915
+ ".dsh-sdel-row-meta{color:var(--dsw-alias-label-tertiary,GrayText);font-size:11px;line-height:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}",
1916
+ ".dsh-sdel-row-actions{display:flex;gap:6px;flex:none;opacity:0;transition:opacity 120ms ease;}",
1917
+ ".dsh-sdel-row:hover .dsh-sdel-row-actions,.dsh-sdel-row:focus-within .dsh-sdel-row-actions,.dsh-sdel-row-actions--open{opacity:1;}",
1918
+ ".dsh-sdel-batch{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--dsw-alias-label-secondary,GrayText);}",
1919
+ ".dsh-sdel-confirm{display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:8px;background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.12));font-size:12px;color:var(--dsw-alias-state-error-primary,#d9534f);}",
1920
+ ".dsh-sdel-disclosure{display:flex;align-items:center;gap:6px;background:transparent;border:none;padding:2px 0;cursor:pointer;color:var(--dsw-alias-label-secondary,GrayText);font-size:12px;font-family:inherit;}",
1921
+ ".dsh-sdel-disclosure:hover{color:var(--dsw-alias-label-primary,inherit);}",
1922
+ ".dsh-sdel-disclosure:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:2px;border-radius:4px;}",
1923
+ ".dsh-sdel-disclosure-meta{margin-left:auto;color:var(--dsw-alias-label-tertiary,GrayText);}",
1924
+ ".dsh-sdel-settings{display:flex;flex-direction:column;width:100%;}",
1925
+ ".dsh-sdel-group{color:var(--dsw-alias-label-secondary,GrayText);font-size:12px;font-weight:600;padding:20px 0 4px;}",
1926
+ ".dsh-sdel-setting-row{display:flex;align-items:center;justify-content:space-between;gap:24px;padding:16px 0;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));}",
1927
+ ".dsh-sdel-setting-row--stack{display:block;}",
1928
+ ".dsh-sdel-setting-text{min-width:0;flex:1;}",
1929
+ ".dsh-sdel-setting-title{color:var(--dsw-alias-label-primary,inherit);font-size:14px;line-height:22px;}",
1930
+ ".dsh-sdel-setting-desc{color:var(--dsw-alias-label-tertiary,GrayText);font-size:12px;line-height:18px;margin-top:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}",
1931
+ ".dsh-sdel-setting-action{display:flex;align-items:center;gap:8px;flex:none;}",
1467
1932
  ].join("\n");
1468
1933
  document.head.appendChild(style);
1469
1934
  return () => style.remove();
@@ -1473,12 +1938,13 @@ window.__ModuleLoader__.load({
1473
1938
  var panelStore = createStore(false);
1474
1939
  var toastStore = createStore(null);
1475
1940
  var tickStore = createStore(0);
1941
+ var prefsStore = createStore(null);
1476
1942
 
1477
1943
  /**
1478
1944
  * 调宿主 sessionDelete 的 Remote 方法。走 /api 的普通 RPC 通道:
1479
1945
  * 无构建插件没有 typert 生成的客户端产物,不能用 ctx.reflect.get。
1480
1946
  * @param {string} method
1481
- * @param {any} request
1947
+ * @param {any} [request]
1482
1948
  * @returns {Promise<any>}
1483
1949
  */
1484
1950
  function call(method, request) {
@@ -1502,6 +1968,18 @@ window.__ModuleLoader__.load({
1502
1968
  );
1503
1969
  }
1504
1970
 
1971
+ /** 偏好只加载一次:确认框与设置页共享同一份快照。 */
1972
+ var loadPrefs = () => {
1973
+ call("getPrefs")
1974
+ .then((/** @type {any} */ value) => {
1975
+ prefsStore.set(value || { cascadeChildren: false });
1976
+ })
1977
+ .catch(() => {
1978
+ prefsStore.set({ cascadeChildren: false });
1979
+ });
1980
+ };
1981
+ loadPrefs();
1982
+
1505
1983
  // 宿主列表 = persistence ∪ live:刷新会把宿主内存里还没释放的会话折回来。
1506
1984
  // 所以删掉的 id 要记住,并在每次 refresh 后重放移除事件(参考实现同款做法)。
1507
1985
  const retired = new Set();
@@ -1547,6 +2025,66 @@ window.__ModuleLoader__.load({
1547
2025
  void refreshRows(result?.sessionId ? result.sessionId : undefined);
1548
2026
  tickStore.set(tickStore.getSnapshot() + 1);
1549
2027
  };
2028
+ /**
2029
+ * 工作区批量的收尾:逐条结果汇总成一句 toast,并把删掉的 id 记进 retired,
2030
+ * 让下一次 refreshRows 重放移除事件(否则刷新会把 live 会话折回来)。
2031
+ * @param {any} result
2032
+ */
2033
+ const onTrashedMany = (result) => {
2034
+ var ok = 0;
2035
+ var total = 0;
2036
+ if (result && Array.isArray(result.results)) {
2037
+ total = result.results.length;
2038
+ for (let index = 0; index < total; index += 1) {
2039
+ const item = result.results[index];
2040
+ if (!item.ok) continue;
2041
+ ok += 1;
2042
+ if (item.sessionId) retired.add(String(item.sessionId));
2043
+ }
2044
+ }
2045
+ toastStore.set({ text: translate("toast.workspace.done", { ok: ok, total: total }) });
2046
+ void refreshRows(undefined);
2047
+ tickStore.set(tickStore.getSnapshot() + 1);
2048
+ };
2049
+
2050
+ /** 当前会话(主视图持有的那一条)。快捷键的语义就是「这个会话」。 */
2051
+ const currentSession = () => {
2052
+ try {
2053
+ const sessions = ctx.get ? ctx.get("sessions") : undefined;
2054
+ const list = sessions?.list?.getSnapshot?.();
2055
+ if (!list?.byId) return undefined;
2056
+ const ids = Array.isArray(list.ids) ? list.ids : Object.keys(list.byId);
2057
+ for (let index = 0; index < ids.length; index += 1) {
2058
+ const row = list.byId[ids[index]];
2059
+ if ((row?.retainedBy?.mainView ?? 0) > 0) return row;
2060
+ }
2061
+ } catch (_error) {
2062
+ return undefined;
2063
+ }
2064
+ return undefined;
2065
+ };
2066
+
2067
+ /** 当前会话所属的工作区(工作区记账里包含它,或路径与它的 cwd 相同)。 */
2068
+ const currentWorkspace = () => {
2069
+ var row = currentSession();
2070
+ if (!row) return undefined;
2071
+ try {
2072
+ const workspaces = ctx.get ? ctx.get("workspaces") : undefined;
2073
+ const snapshot = workspaces?.list?.getSnapshot?.();
2074
+ const items = snapshot?.items || [];
2075
+ for (let index = 0; index < items.length; index += 1) {
2076
+ const item = items[index];
2077
+ if (Array.isArray(item.sessionIds) && item.sessionIds.includes(row.id)) return item;
2078
+ }
2079
+ for (let cursor = 0; cursor < items.length; cursor += 1) {
2080
+ if (typeof row.cwd === "string" && items[cursor].path === row.cwd) return items[cursor];
2081
+ }
2082
+ } catch (_error) {
2083
+ return undefined;
2084
+ }
2085
+ return undefined;
2086
+ };
2087
+
1550
2088
  // 外部变更(agent 工具、另一个窗口、CLI)不会通知本页面,
1551
2089
  // 定期拉一次会话列表;页面重新可见时也立刻拉一次。
1552
2090
  ctx.effect(() => {
@@ -1573,26 +2111,223 @@ window.__ModuleLoader__.load({
1573
2111
  void refreshRows(undefined);
1574
2112
  };
1575
2113
 
1576
- ctx.effect(
1577
- () =>
1578
- ctx.slots.inject("sidebar.workspaces.session.menu.item", () =>
1579
- ctx.slots.register(
1580
- {
1581
- name: "sidebar.workspaces.session.menu.item",
1582
- id: "session-delete",
1583
- order: 420,
1584
- locale: NS,
1585
- inject: () => ({
1586
- requestDelete: (/** @type {any} */ request) => {
1587
- requestStore.set(request);
2114
+ /**
2115
+ * 菜单:优先走官方的 contextMenus 贡献。
2116
+ * 好处有三点:能参与官方排序(不再是「兼容位置」的附加行)、能显示快捷键、
2117
+ * 工作区「…」菜单也有正式入口。拿不到服务(老宿主)时退回旧 slot,功能不减。
2118
+ */
2119
+ const openSessionConfirm = (/** @type {any} */ sessionId, /** @type {any} */ title) => {
2120
+ requestStore.set({ sessionId: sessionId, title: title || null });
2121
+ };
2122
+ const openWorkspaceConfirm = (/** @type {any} */ workspaceId, /** @type {any} */ title) => {
2123
+ requestStore.set({ workspaceId: String(workspaceId), title: title || null });
2124
+ };
2125
+
2126
+ /** @param {any} contextMenus */
2127
+ const installMenuContributions = (contextMenus) => {
2128
+ if (!contextMenus || typeof contextMenus.register !== "function") return false;
2129
+ try {
2130
+ ctx.effect(
2131
+ () =>
2132
+ contextMenus.register({
2133
+ id: COMMAND_DELETE,
2134
+ target: "session",
2135
+ order: 560,
2136
+ resolve: (/** @type {any} */ target) => [
2137
+ {
2138
+ id: "delete",
2139
+ label: translate("menu.delete"),
2140
+ danger: true,
2141
+ separatorBefore: true,
2142
+ ...(typeof IconTrash === "function" ? { icon: { key: TRASH_ICON } } : {}),
2143
+ commandId: COMMAND_DELETE,
2144
+ run: () => openSessionConfirm(target.sessionId, target.displayTitle),
1588
2145
  },
1589
- }),
1590
- },
1591
- DeleteSessionMenuItem,
2146
+ ],
2147
+ }),
2148
+ "session-delete: session menu action",
2149
+ );
2150
+ ctx.effect(
2151
+ () =>
2152
+ contextMenus.register({
2153
+ id: COMMAND_DELETE_WORKSPACE,
2154
+ target: "workspace",
2155
+ order: 250,
2156
+ resolve: (/** @type {any} */ target) => [
2157
+ {
2158
+ id: "delete-workspace-sessions",
2159
+ label: translate("menu.workspaceTrash"),
2160
+ danger: true,
2161
+ separatorBefore: true,
2162
+ ...(typeof IconTrash === "function" ? { icon: { key: TRASH_ICON } } : {}),
2163
+ commandId: COMMAND_DELETE_WORKSPACE,
2164
+ run: () => openWorkspaceConfirm(target.workspaceId, target.displayTitle),
2165
+ },
2166
+ ],
2167
+ }),
2168
+ "session-delete: workspace menu action",
2169
+ );
2170
+ if (typeof IconTrash === "function") {
2171
+ try {
2172
+ ctx.effect(
2173
+ () =>
2174
+ ctx.slots.inject("contextMenu.icon", () =>
2175
+ ctx.slots.register(
2176
+ { name: "contextMenu.icon", key: TRASH_ICON },
2177
+ function TrashMenuIcon() {
2178
+ return h(IconTrash, { size: 14 });
2179
+ },
2180
+ ),
2181
+ ),
2182
+ "session-delete: menu icon",
2183
+ );
2184
+ } catch (_error) {
2185
+ /* 图标 slot 不存在时菜单仍然可用(宿主的 icon key 匹配不到就不画) */
2186
+ }
2187
+ }
2188
+ return true;
2189
+ } catch (error) {
2190
+ ctx.logger?.warn?.(
2191
+ `session-delete: cannot register menu contributions: ${errorText(error)}`,
2192
+ );
2193
+ return false;
2194
+ }
2195
+ };
2196
+
2197
+ /** @returns {any} ctx.effect 的释放函数(contextMenus 迟到时用它撤掉旧 slot,避免两行)。 */
2198
+ const registerLegacyMenuItem = () =>
2199
+ ctx.effect(
2200
+ () =>
2201
+ ctx.slots.inject("sidebar.workspaces.session.menu.item", () =>
2202
+ ctx.slots.register(
2203
+ {
2204
+ name: "sidebar.workspaces.session.menu.item",
2205
+ id: "session-delete",
2206
+ order: 420,
2207
+ locale: NS,
2208
+ inject: () => ({
2209
+ requestDelete: (/** @type {any} */ request) => {
2210
+ requestStore.set(request);
2211
+ },
2212
+ }),
2213
+ },
2214
+ DeleteSessionMenuItem,
2215
+ ),
1592
2216
  ),
1593
- ),
1594
- "session-delete: session menu item",
1595
- );
2217
+ "session-delete: session menu item (legacy slot)",
2218
+ );
2219
+
2220
+ /**
2221
+ * 快捷键:删除「当前会话」与「当前工作区的全部会话」。
2222
+ * 注册整体包 try/catch —— 与本机已有的自定义键位冲突时宿主会抛错,
2223
+ * 那种情况下只失去快捷键,菜单与确认框照常工作。
2224
+ */
2225
+ /** @param {any} shortcuts */
2226
+ const installShortcuts = (shortcuts) => {
2227
+ if (!shortcuts || typeof shortcuts.register !== "function") return;
2228
+ const register = (/** @type {any} */ command) => {
2229
+ try {
2230
+ ctx.effect(() => shortcuts.register(command), `session-delete: shortcut ${command.id}`);
2231
+ } catch (error) {
2232
+ ctx.logger?.warn?.(
2233
+ `session-delete: shortcut ${command.id} unavailable: ${errorText(error)}`,
2234
+ );
2235
+ }
2236
+ };
2237
+ const busy = () =>
2238
+ requestStore.getSnapshot()
2239
+ ? { status: "blocked", reason: translate("shortcut.busy") }
2240
+ : null;
2241
+ register({
2242
+ id: COMMAND_DELETE,
2243
+ label: () => translate("shortcut.delete"),
2244
+ aliases: ["delete session", "remove session", "删除会话"],
2245
+ // Linux(桌面与 Web)都不声明默认值:宿主把「修饰键 + Backspace」列为保留组合,
2246
+ // 声明了 register() 会抛错,整条快捷键就没了。用户在设置里可以自己绑。
2247
+ defaults: {
2248
+ "desktop:macos": { code: "Backspace", modifiers: ["primary", "alt"] },
2249
+ "desktop:windows": { code: "Backspace", modifiers: ["primary", "alt"] },
2250
+ "web:macos": { code: "Backspace", modifiers: ["primary", "alt"] },
2251
+ "web:windows": { code: "Backspace", modifiers: ["primary", "alt"] },
2252
+ },
2253
+ // 编辑区也放行:⌘⌥⌫ 不是 macOS/Windows 的文本编辑键(那些是 ⌘⌫ / ⌥⌫ / ⌘⌃⌫),
2254
+ // 而 composer 几乎总是持有焦点,只允许 page 会让快捷键实际上按不出来。
2255
+ // 终端排除在外:那里的删除键有更强的本地语义。
2256
+ regions: ["page", "editable"],
2257
+ modals: [],
2258
+ resolve: () => {
2259
+ const blockedNow = busy();
2260
+ if (blockedNow) return blockedNow;
2261
+ const row = currentSession();
2262
+ if (!row) return { status: "blocked", reason: translate("shortcut.noSession") };
2263
+ return {
2264
+ status: "handled",
2265
+ run: () => openSessionConfirm(row.id, row.displayTitle),
2266
+ };
2267
+ },
2268
+ });
2269
+ // 工作区级清空没有默认键位:误触代价太大,键位留给用户在设置里自己绑。
2270
+ register({
2271
+ id: COMMAND_DELETE_WORKSPACE,
2272
+ label: () => translate("shortcut.workspace"),
2273
+ aliases: ["delete workspace sessions", "清空工作区会话"],
2274
+ defaults: {},
2275
+ regions: ["page"],
2276
+ modals: [],
2277
+ resolve: () => {
2278
+ const blockedNow = busy();
2279
+ if (blockedNow) return blockedNow;
2280
+ const workspace = currentWorkspace();
2281
+ if (!workspace) return { status: "blocked", reason: translate("shortcut.noSession") };
2282
+ return {
2283
+ status: "handled",
2284
+ run: () => openWorkspaceConfirm(workspace.workspaceId, workspace.title),
2285
+ };
2286
+ },
2287
+ });
2288
+ };
2289
+
2290
+ // 两个服务都可能比插件晚就绪:用 ctx.inject 延迟,缺任何一个都不影响插件本身加载。
2291
+ // ctx.inject 只有「必须」语义,所以再加一个宽限期兜底:超时就认定宿主没有
2292
+ // contextMenus,直接上旧的会话菜单 slot(否则老宿主上「删除会话」入口会整个消失)。
2293
+ let menusInstalled = false;
2294
+ /** @type {any} */
2295
+ let legacyDispose = null;
2296
+ const ensureLegacyMenu = () => {
2297
+ if (menusInstalled || legacyDispose) return;
2298
+ legacyDispose = registerLegacyMenuItem();
2299
+ };
2300
+ try {
2301
+ if (typeof ctx.inject === "function") {
2302
+ ctx.inject(["contextMenus"], (/** @type {any} */ scoped) => {
2303
+ const service = scoped?.contextMenus ?? (ctx.get ? ctx.get("contextMenus") : undefined);
2304
+ if (installMenuContributions(service)) {
2305
+ menusInstalled = true;
2306
+ if (legacyDispose) {
2307
+ legacyDispose();
2308
+ legacyDispose = null;
2309
+ }
2310
+ } else {
2311
+ ensureLegacyMenu();
2312
+ }
2313
+ });
2314
+ ctx.inject(["shortcuts"], (/** @type {any} */ scoped) => {
2315
+ installShortcuts(scoped?.shortcuts ?? (ctx.get ? ctx.get("shortcuts") : undefined));
2316
+ });
2317
+ const timer = setTimeout(ensureLegacyMenu, MENU_FALLBACK.ms);
2318
+ ctx.effect(() => () => clearTimeout(timer), "session-delete: menu fallback timer");
2319
+ } else {
2320
+ const menus = ctx.get ? ctx.get("contextMenus") : undefined;
2321
+ if (installMenuContributions(menus)) menusInstalled = true;
2322
+ else ensureLegacyMenu();
2323
+ installShortcuts(ctx.get ? ctx.get("shortcuts") : undefined);
2324
+ }
2325
+ } catch (error) {
2326
+ ctx.logger?.warn?.(
2327
+ `session-delete: menu/shortcut setup failed, falling back: ${errorText(error)}`,
2328
+ );
2329
+ ensureLegacyMenu();
2330
+ }
1596
2331
 
1597
2332
  // 回收站入口固定在侧栏页脚,不出现在每个会话的「…」菜单里。
1598
2333
  ctx.effect(
@@ -1619,6 +2354,34 @@ window.__ModuleLoader__.load({
1619
2354
  "session-delete: sidebar footer trash entry",
1620
2355
  );
1621
2356
 
2357
+ // 设置页分节:偏好 + 回收站概览 + 维护(体检/回执/审计)。
2358
+ // 宿主没有 settings.section 的版本会静默跳过,不影响主流程。
2359
+ try {
2360
+ ctx.effect(
2361
+ () =>
2362
+ ctx.slots.inject("settings.section", () =>
2363
+ ctx.slots.register(
2364
+ {
2365
+ name: "settings.section",
2366
+ id: "session-delete",
2367
+ order: 90,
2368
+ label: () => translate("settings.nav"),
2369
+ locale: NS,
2370
+ inject: () => ({
2371
+ prefsStore: prefsStore,
2372
+ panelStore: panelStore,
2373
+ call: call,
2374
+ }),
2375
+ },
2376
+ SettingsSection,
2377
+ ),
2378
+ ),
2379
+ "session-delete: settings section",
2380
+ );
2381
+ } catch (error) {
2382
+ ctx.logger?.warn?.(`session-delete: settings section unavailable: ${errorText(error)}`);
2383
+ }
2384
+
1622
2385
  ctx.effect(
1623
2386
  () =>
1624
2387
  ctx.slots.inject("shell.overlay", () =>
@@ -1630,9 +2393,11 @@ window.__ModuleLoader__.load({
1630
2393
  Object.assign({}, props, {
1631
2394
  requestStore: requestStore,
1632
2395
  panelStore: panelStore,
2396
+ prefsStore: prefsStore,
1633
2397
  toastStore: toastStore,
1634
2398
  call: call,
1635
2399
  onTrashed: onTrashed,
2400
+ onTrashedMany: onTrashedMany,
1636
2401
  onPurged: onPurged,
1637
2402
  onRestored: onRestored,
1638
2403
  tickStore: tickStore,
@@ -1650,6 +2415,17 @@ window.__ModuleLoader__.load({
1650
2415
  Object.defineProperty(exports, "__test", {
1651
2416
  value: Object.freeze({
1652
2417
  tokens: T,
2418
+ chunk: chunk,
2419
+ joinList: joinList,
2420
+ impactLine: impactLine,
2421
+ batchChunk: BATCH_CHUNK,
2422
+ menuFallback: MENU_FALLBACK,
2423
+ createPanelLoader: createPanelLoader,
2424
+ runBatch: runBatch,
2425
+ panelPollMs: PANEL_POLL_MS,
2426
+ // 词典也暴露出来:单测要比对「内联词典 / locale/*.json」的键集,防止两处漂移。
2427
+ zh: zh,
2428
+ en: en,
1653
2429
  }),
1654
2430
  });
1655
2431