dsh-delete-session 0.2.9 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -162,6 +162,21 @@ MIT
162
162
 
163
163
  ## 修复记录
164
164
 
165
+ **(v0.3.1)** —— 批量删除也会处理产出文件了。
166
+
167
+ - **批量删除原来完全不碰产出文件**:单删会带上 `quarantine`,批量那条却调 `postDelete(id)` 什么都不传,宿主按缺省当「不动文件」。于是用户明明开着「产出文件默认全部进隔离夹」,批量删时文件**原地留着**,而且没有任何提示——看起来像做了,其实没做。现在两条路径共用 `quarantinePlan()`。
168
+ - **批量也会报文件数**:「已删除 N 个会话,M 个文件已移入隔离夹」;有失败则分开报成功与失败数。原来是干巴巴一句「已删除 N 个会话」,看不出文件去哪了。
169
+ - **询问模式下批量会明说**:勾着「产出文件先询问」时批量删不了清单(100 个会话挨个弹窗不现实),所以文件确实没处理。现在补一句提示,告诉用户要么单个删、要么在插件页改成自动隔离——而不是让它静默过去。
170
+ - 顺带修了测试夹具跨用例串扰:批量成功后排的 2.5 秒 `settlePendingSoon` 定时器会活到下一个用例,用**旧插件的闭包**去装饰**新用例的 DOM**,导致三条毫不相关的用例随机变红。现在每条用例开始前清掉遗留定时器,连跑 5 次稳定。
171
+ **(v0.3.0)** —— 多选支持按工作区全选,也能一次选中全部会话。
172
+
173
+ - **两个全选框**:`工作区 N` 那一行多一个框,选中**所有**会话;每个工作区标题行(含「未分组」)各多一个框,只选中**该组**。点一下全选,再点一下清空。
174
+ - **分组归属从 DOM 读,不向宿主索取**:会话行与工作区标题行同属一个 `groupSection`,从标题行向上找容器再取子行即可。宿主给工作区行的外面还套了一层 `HoverCard` 的 `<span>`,所以不能只看 `parentElement`,要逐层向上,并在「这一层已经装着几个工作区」时停手——否则会把别组的会话一起卷进来。嵌套的 `div[role="group"]` 直接跳过。
175
+ - **半选状态**:组里只勾了几个时,组框显示 `−`(`aria-checked="mixed"`),而不是谎报全选或全不选。
176
+ - **位置在标签文字右边**:宿主把行尾操作区用 `margin-left:auto` 推到最右,直接 `appendChild` 会落到行的另一头;框插在 `[class*="_rowActions"]` 之前。工作区名是 `flex:1`,会把剩余宽度全部吃掉,所以框后面还要跟一条 `flex:1` 的间隔条,把数值/菜单/新建重新顶回行尾。
177
+ - **修饰过的元素不参与行点击**:多选的点击走 document 的 capture 阶段,框会长在工作区行里面,不加标记就会被当成「点了一行」而被吞掉。所有自建元素都带 `data-dsh-delete-session`,capture 监听先跳过它们。
178
+ - **不再自己触发自己**:装饰只在位置不对时碰 DOM,变更观察器也忽略自己插入的节点。原来每帧重插会把框从指针底下反复摘走,表现为「狂点十几次才中一次」。
179
+ - **不假设 `children` 是数组**:浏览器里它是 `HTMLCollection`,没有 `indexOf`,一次误用就让整趟装饰抛异常、框一个都不出现。
165
180
  **(v0.2.9)** —— 俄语界面 + 修掉拖拽标签里的 `{name}`。
166
181
 
167
182
  - **俄语(`ru`)**:来自社区贡献([#1](https://github.com/DDDMUC/dsh-delete-session/pull/1),作者 [@aleXela17](https://github.com/aleXela17))。98 条词条与中英完全对齐,函数型条目仍然返回数字。DSH 自身没有 ru 语言包,所以俄语浏览器下插件字典优先于宿主翻译;中英路径不变,宿主仍是权威。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-delete-session",
3
- "version": "0.2.9",
3
+ "version": "0.3.1",
4
4
  "description": "Delete sessions from the DSH Web sidebar: adds a Delete action to the session row menu with a risk-consent dialog, sends the session log, workspace accounting and live session state to the system trash (or removes them outright), and, when opted in, quarantines the files the conversation produced.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/client.js CHANGED
@@ -36,6 +36,8 @@ window.__ModuleLoader__.load({
36
36
  const zh = {
37
37
  menu: '删除会话',
38
38
  multiSelect: '多选',
39
+ selectAllGroup: '全选这个工作区',
40
+ selectAllWorkspaces: '全选所有工作区',
39
41
  title: '删除会话',
40
42
  descRecycle: '将把该会话及其全部对话记录(会话日志、工作区记账与统计)从列表中移除,并放进系统回收站。',
41
43
  descPermanent: '将永久删除该会话及其全部对话记录(会话日志、工作区记账与统计),此操作不可恢复。',
@@ -57,6 +59,9 @@ window.__ModuleLoader__.load({
57
59
  deleteSelected: '删除',
58
60
  batchDone: (n) => `已删除 ${n} 个会话`,
59
61
  batchPartial: (ok, fail) => `已删除 ${ok} 个,${fail} 个失败`,
62
+ batchDoneQuarantine: (n, m) => `已删除 ${n} 个会话,${m} 个文件已移入隔离夹`,
63
+ batchDoneQuarantineFailed: (n, ok, fail) => `已删除 ${n} 个会话,隔离 ${ok} 个、${fail} 个失败`,
64
+ batchAskArtifacts: '这批会话的产出文件没有处理:批量删除不列逐文件清单。要处理它们,请单个删除,或在插件页改成「产出文件默认全部进隔离夹」。',
60
65
  batchFailed: '批量删除失败:',
61
66
  pageAsk: '删除时询问',
62
67
  pageRecycle: '删除至回收站',
@@ -140,6 +145,8 @@ window.__ModuleLoader__.load({
140
145
  const en = {
141
146
  menu: 'Delete session',
142
147
  multiSelect: 'Select multiple',
148
+ selectAllGroup: 'Select every session in this workspace',
149
+ selectAllWorkspaces: 'Select every session in every workspace',
143
150
  title: 'Delete session',
144
151
  descRecycle: 'This removes the session and all of its conversation records (log, workspace accounting and statistics) from the list and puts them in the system trash.',
145
152
  descPermanent: 'This permanently deletes the session and all of its conversation records (log, workspace accounting and statistics). This cannot be undone.',
@@ -161,6 +168,9 @@ window.__ModuleLoader__.load({
161
168
  deleteSelected: 'Delete',
162
169
  batchDone: (n) => `Deleted ${n} session(s)`,
163
170
  batchPartial: (ok, fail) => `Deleted ${ok}, ${fail} failed`,
171
+ batchDoneQuarantine: (n, m) => `Deleted ${n} session(s), ${m} file(s) moved to quarantine`,
172
+ batchDoneQuarantineFailed: (n, ok, fail) => `Deleted ${n} session(s), ${ok} quarantined and ${fail} failed`,
173
+ batchAskArtifacts: 'The produced files of these sessions were left alone: a batch has no per-file checklist. Delete them one by one, or switch the plugin page to "move every produced file to quarantine".',
164
174
  batchFailed: 'Batch delete failed: ',
165
175
  pageAsk: 'Ask before deleting',
166
176
  pageRecycle: 'Delete to the Recycle Bin',
@@ -241,6 +251,8 @@ window.__ModuleLoader__.load({
241
251
  const ru = {
242
252
  menu: 'Удалить сессию',
243
253
  multiSelect: 'Выбрать несколько',
254
+ selectAllGroup: 'Выбрать все сессии этой рабочей папки',
255
+ selectAllWorkspaces: 'Выбрать все сессии во всех рабочих папках',
244
256
  title: 'Удалить сессию',
245
257
  descRecycle: 'Сессия и все её записи (журнал, учёт рабочей папки и статистика) будут убраны из списка и перемещены в системную корзину.',
246
258
  descPermanent: 'Сессия и все её записи (журнал, учёт рабочей папки и статистика) будут удалены безвозвратно. Отменить это нельзя.',
@@ -262,6 +274,9 @@ window.__ModuleLoader__.load({
262
274
  deleteSelected: 'Удалить',
263
275
  batchDone: (n) => `Удалено сессий: ${n}`,
264
276
  batchPartial: (ok, fail) => `Удалено ${ok}, не удалось ${fail}`,
277
+ batchDoneQuarantine: (n, m) => `Удалено сессий: ${n}, файлов в карантине: ${m}`,
278
+ batchDoneQuarantineFailed: (n, ok, fail) => `Удалено сессий: ${n}, в карантине ${ok}, не удалось ${fail}`,
279
+ batchAskArtifacts: 'Файлы этих сессий не обработаны: пакетное удаление не показывает список файлов. Удаляйте по одному или переключите страницу плагина на «все созданные файлы в карантин». ',
265
280
  batchFailed: 'Массовое удаление не удалось: ',
266
281
  pageAsk: 'Спрашивать перед удалением',
267
282
  pageRecycle: 'Удалять в корзину',
@@ -592,6 +607,20 @@ window.__ModuleLoader__.load({
592
607
  return () => { prefListeners.delete(listener) }
593
608
  }
594
609
 
610
+ /**
611
+ * The `quarantine` payload a delete should carry, or undefined for "do not
612
+ * touch any file".
613
+ *
614
+ * Only `auto` mode can answer this without a dialog: asking means handing the
615
+ * user a per-file checklist, which a batch of sessions has nowhere to put.
616
+ * The batch path used to skip this entirely, so a user who had switched the
617
+ * feature on got a silent no-op instead of a quarantine.
618
+ */
619
+ function quarantinePlan() {
620
+ if (artifactsOff() || !artifactsAuto()) return undefined
621
+ return { scope: artifactScope() }
622
+ }
623
+
595
624
  /** Whether the produced-files feature is off. Off unless explicitly enabled. */
596
625
  function artifactsOff() {
597
626
  return readPref(OFF_KEY, '1') !== '0'
@@ -893,6 +922,27 @@ window.__ModuleLoader__.load({
893
922
  '@keyframes dsdel-toast-in{from{opacity:0;transform:translate(-50%,6px)}to{opacity:1;transform:translate(-50%,0)}}',
894
923
  '@media (prefers-reduced-motion:reduce){.dsdel-toast{animation:none}.dsdel-field{transition:none}}',
895
924
  '.dsdel-check{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;border-radius:50%;border:1.5px solid var(--dsw-alias-border-l3,rgba(128,128,128,.5));background:transparent;flex:none;margin-right:8px;box-sizing:border-box;cursor:pointer}',
925
+ // The two select-all boxes sit where the host puts them: inside each
926
+ // workspace header row, and inside the `工作区 N` heading above all of them.
927
+ //
928
+ // They live in the SIDEBAR, outside the `.dsdel-page` / `.dsdel-modal` /
929
+ // `.dsdel-bar` token scope, so every rule here reads a host alias with its
930
+ // own fallback. Reaching for `var(--dsdel-border)` was the bug: an unknown
931
+ // custom property voids the whole declaration, which left the box with no
932
+ // border, no content and nothing to click on.
933
+
934
+ // The spacer is the only child that grows, so the right-hand cluster keeps
935
+ // its place at the row's end while the box stays beside the name.
936
+ '.dsdel-flex-spacer{flex:1 1 auto;min-width:0;align-self:center;height:1px}',
937
+ '.dsdel-select-all,.dsdel-select-all-workspaces{flex:0 0 auto;box-sizing:border-box;width:15px;height:15px;min-width:15px;margin:0 0 0 6px;padding:0;display:inline-flex;align-items:center;justify-content:center;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.45));border-radius:4px;background:transparent;color:var(--dsw-alias-label-secondary,#666);font-size:10px;line-height:1;cursor:pointer;opacity:1;visibility:visible;align-self:center}',
938
+ '.dsdel-select-all:hover,.dsdel-select-all-workspaces:hover{border-color:var(--dsw-alias-brand-primary,#4c8dff);color:var(--dsw-alias-brand-primary,#4c8dff)}',
939
+ '.dsdel-select-all[aria-checked="true"],.dsdel-select-all-workspaces[aria-checked="true"]{background:var(--dsw-alias-brand-primary,#4c8dff);border-color:var(--dsw-alias-brand-primary,#4c8dff);color:#fff}',
940
+ '.dsdel-select-all[aria-checked="mixed"],.dsdel-select-all-workspaces[aria-checked="mixed"]{border-color:var(--dsw-alias-brand-primary,#4c8dff);color:var(--dsw-alias-brand-primary,#4c8dff)}',
941
+ '.dsdel-select-all:focus-visible,.dsdel-select-all-workspaces:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4c8dff);outline-offset:1px}',
942
+ // While the mode runs, let the workspace name size to its own text. With
943
+ // `flex:1` it fills the row, so the select-all box inserted after it was
944
+ // pushed to the far edge even though it sits early in the child list.
945
+ 'body.dsdel-selecting [class*="_projectText"]{flex:0 1 auto;min-width:0}',
896
946
  '.dsdel-check-on{background:var(--dsw-alias-state-business-primary,#4c6ef5);border-color:var(--dsw-alias-state-business-primary,#4c6ef5)}',
897
947
  '.dsdel-check-on::after{content:"";width:9px;height:5px;border-left:2px solid #fff;border-bottom:2px solid #fff;transform:rotate(-45deg) translateY(-1px)}',
898
948
  // 乐观删除:行先隐藏,失败时随 decorate 恢复
@@ -1084,6 +1134,244 @@ window.__ModuleLoader__.load({
1084
1134
  else openDeleteDialog(drag.sessionId, drag.title)
1085
1135
  }
1086
1136
 
1137
+ // --- select a whole workspace ----------------------------------------------
1138
+ //
1139
+ // The sidebar groups sessions under `[data-row-key="workspace:<key>"]` headers,
1140
+ // and the host renders the `工作区 N` heading above all of them as
1141
+ // `[data-sidebar-workspace-header]`. Both get a checkbox of their own while the
1142
+ // mode runs: one per group, one for every group together.
1143
+ //
1144
+ // Group membership is read off the DOM rather than asked from the host: a
1145
+ // session row and its workspace row are siblings inside the same section
1146
+ // element, so a subtree query from the header finds exactly that group.
1147
+
1148
+ const GROUP_BUTTON = 'dsdel-select-all'
1149
+ const SPACER = 'dsdel-flex-spacer'
1150
+ const ALL_BUTTON = 'dsdel-select-all-workspaces'
1151
+ const WORKSPACE_ROWS_HEADER = '[data-sidebar-workspace-header]'
1152
+
1153
+ /**
1154
+ * Position of `node` among `parent`'s element children, or -1.
1155
+ *
1156
+ * `children` is an HTMLCollection in a browser and a plain array in the test
1157
+ * stub. HTMLCollection has no `indexOf`, so the call has to be spelled out.
1158
+ */
1159
+ function childIndex(parent, node) {
1160
+ if (parent === null || parent === undefined) return -1
1161
+ const kids = parent.children
1162
+ if (kids === null || kids === undefined) return -1
1163
+ for (let i = 0; i < kids.length; i += 1) {
1164
+ if (kids[i] === node) return i
1165
+ }
1166
+ return -1
1167
+ }
1168
+
1169
+ /** `data-row-key` of a sidebar row, or null. */
1170
+ function rowKeyOf(node) {
1171
+ if (node === null || node === undefined || typeof node.getAttribute !== 'function') return null
1172
+ return node.getAttribute('data-row-key')
1173
+ }
1174
+
1175
+ /**
1176
+ * The session ids under one workspace header row.
1177
+ *
1178
+ * The row is not always a direct child of its section: the host may wrap it
1179
+ * (a hover card, a drag shell), and a subtree query from that wrapper finds
1180
+ * no sessions at all. So the ancestors are climbed until one of them owns
1181
+ * session rows — that ancestor is the section.
1182
+ */
1183
+ /**
1184
+ * Rows that sit directly in `node`, looking one level into a wrapper.
1185
+ *
1186
+ * The host wraps the workspace row in `HoverCard`'s <span>, so the row's
1187
+ * `parentElement` is that span and not the group section. Whatever contains
1188
+ * the rows also has to be read through it.
1189
+ *
1190
+ * A `div[role="group"]` child is a NESTED workspace: it is skipped, or a
1191
+ * parent's select-all would sweep in its children's sessions.
1192
+ */
1193
+ function ownRows(node) {
1194
+ const rows = []
1195
+ const visit = (parent, depth) => {
1196
+ if (parent === null || parent === undefined || parent.children === undefined) return
1197
+ for (const child of parent.children) {
1198
+ const key = typeof child.getAttribute === 'function' ? child.getAttribute('data-row-key') : null
1199
+ if (key !== null) { rows.push(child); continue }
1200
+ if (depth >= 2) continue
1201
+ if (typeof child.getAttribute === 'function' && child.getAttribute('role') === 'group') continue
1202
+ visit(child, depth + 1)
1203
+ }
1204
+ }
1205
+ visit(node, 0)
1206
+ return rows
1207
+ }
1208
+
1209
+ /**
1210
+ * The session ids under one workspace header row.
1211
+ *
1212
+ * Climbed rather than assumed: a wrapper span put every id out of reach, so
1213
+ * the box ended up with an empty list and `toggleGroup` returned without
1214
+ * doing anything. The climb stops as soon as it reaches a container holding
1215
+ * more than one workspace, which is the shared list — grabbing there would
1216
+ * hand this group every other group's sessions.
1217
+ */
1218
+ function sessionsUnderWorkspace(headRow) {
1219
+ let node = headRow.parentElement
1220
+ for (let depth = 0; depth < 6; depth += 1) {
1221
+ if (node === null || node === undefined) return []
1222
+ const rows = ownRows(node)
1223
+ let workspaces = 0
1224
+ const ids = []
1225
+ for (const row of rows) {
1226
+ const key = rowKeyOf(row)
1227
+ if (typeof key !== 'string') continue
1228
+ if (key.startsWith('workspace:')) workspaces += 1
1229
+ else if (key.startsWith('session:')) ids.push(key.slice('session:'.length))
1230
+ }
1231
+ if (workspaces > 1) return []
1232
+ if (ids.length > 0) return ids
1233
+ node = node.parentElement
1234
+ }
1235
+ return []
1236
+ }
1237
+
1238
+
1239
+ /**
1240
+ * The tri-state a select-all box shows: every id in, none in, or something
1241
+ * between. `mixed` is what tells a user their group is partly ticked.
1242
+ */
1243
+ function groupState(ids) {
1244
+ if (ids.length === 0) return 'false'
1245
+ let picked = 0
1246
+ for (const id of ids) if (state.selected.has(id)) picked += 1
1247
+ if (picked === 0) return 'false'
1248
+ return picked === ids.length ? 'true' : 'mixed'
1249
+ }
1250
+
1251
+ /** Ticking a full or partly ticked box clears the group; an empty one fills it. */
1252
+ function toggleGroup(ids) {
1253
+ if (ids.length === 0) return
1254
+ const fill = groupState(ids) !== 'true'
1255
+ for (const id of ids) {
1256
+ if (fill) state.selected.add(id)
1257
+ else state.selected.delete(id)
1258
+ }
1259
+ publish()
1260
+ }
1261
+
1262
+ /**
1263
+ * Place (or refresh) one of the two boxes. `host` gets nothing appended twice:
1264
+ * the element is looked up by class first, so a decorate pass after a host
1265
+ * re-render reuses the box it already owns.
1266
+ */
1267
+ /**
1268
+ * Place (or refresh) one of the two boxes.
1269
+ *
1270
+ * `anchor` is the class of the element the box should sit IN FRONT OF: the
1271
+ * host pushes its right-hand actions out with an auto margin, so appending at
1272
+ * the end drops the box at the row's far edge. Inserting before those actions
1273
+ * puts it right after the label, which is where it reads as part of the
1274
+ * heading.
1275
+ */
1276
+ function placeGroupBox(host, className, label, ids, anchor) {
1277
+ if (host === null || host === undefined) return
1278
+ let box = typeof host.querySelector === 'function' ? host.querySelector('.' + className) : null
1279
+ const created = box === null
1280
+ if (created) {
1281
+ box = document.createElement('button')
1282
+ box.setAttribute('type', 'button')
1283
+ box.className = className
1284
+ box.setAttribute('role', 'checkbox')
1285
+ box.addEventListener('click', (event) => {
1286
+ // The workspace header toggles its group on click; this box must not.
1287
+ if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
1288
+ toggleGroup(box.__dsdelIds || [])
1289
+ })
1290
+ }
1291
+
1292
+ // The anchor is a comma list, tried one at a time: a document-order match
1293
+ // could otherwise pick a later sibling than the caller meant.
1294
+ let before = null
1295
+ if (anchor !== undefined && anchor !== null) {
1296
+ for (const selector of String(anchor).split(',')) {
1297
+ const found = host.querySelector(selector.trim())
1298
+ if (found !== null && found !== undefined) { before = found; break }
1299
+ }
1300
+ }
1301
+
1302
+ // ALWAYS insert, not only on creation. A box placed by an earlier decorate
1303
+ // pass (or an earlier build) kept its old seat forever, because the insert
1304
+ // sat inside the `created` branch: the header box moved on the next pass and
1305
+ // the workspace box did not. `insertBefore` on an existing child just moves
1306
+ // it, so this is idempotent.
1307
+ // One flex child has to absorb the free space, or the whole right-hand
1308
+ // cluster (count, menu, new-session) slides left with the box. The spacer
1309
+ // takes that job so the name can stay at its natural width.
1310
+ let spacer = host.querySelector('.' + SPACER)
1311
+ if (before !== null && before !== undefined) {
1312
+ if (spacer === null) {
1313
+ spacer = document.createElement('span')
1314
+ spacer.className = SPACER
1315
+ spacer.setAttribute('aria-hidden', 'true')
1316
+ spacer.setAttribute('data-dsh-delete-session', 'spacer')
1317
+ }
1318
+ // Only touch the DOM when something is actually out of place. Every
1319
+ // `insertBefore` is a real mutation, and the list observer counted it as
1320
+ // a change: moving the box on every pass fed the observer its own work,
1321
+ // so a new pass was scheduled for the next frame, forever. A click that
1322
+ // landed while the box was detached and re-attached never completed,
1323
+ // which is why it took a dozen taps to hit it once.
1324
+ const boxAt = childIndex(host, box)
1325
+ const spacerAt = childIndex(host, spacer)
1326
+ const beforeAt = childIndex(host, before)
1327
+ if (boxAt === -1 || spacerAt === -1 || beforeAt === -1
1328
+ || boxAt !== spacerAt - 1 || beforeAt !== spacerAt + 1) {
1329
+ host.insertBefore(spacer, before)
1330
+ host.insertBefore(box, spacer)
1331
+ }
1332
+ } else if (created) {
1333
+ host.appendChild(box)
1334
+ }
1335
+
1336
+ box.setAttribute('aria-label', label)
1337
+ box.setAttribute('data-dsh-delete-session', 'select-all')
1338
+ const state_ = groupState(ids)
1339
+ box.setAttribute('aria-checked', state_)
1340
+ box.textContent = state_ === 'true' ? '✓' : (state_ === 'mixed' ? '−' : '')
1341
+ box.__dsdelIds = ids
1342
+ }
1343
+ function decorateSelectAll(rows) {
1344
+ if (!state.selecting) {
1345
+ for (const el of document.querySelectorAll('.' + GROUP_BUTTON)) el.remove()
1346
+ for (const el of document.querySelectorAll('.' + ALL_BUTTON)) el.remove()
1347
+ for (const el of document.querySelectorAll('.' + SPACER)) el.remove()
1348
+ return
1349
+ }
1350
+ const headings = document.querySelectorAll(WORKSPACE_ROWS_HEADER)
1351
+ if (headings.length > 0) {
1352
+ const every = []
1353
+ for (const row of rows) {
1354
+ const key = rowKeyOf(row)
1355
+ if (typeof key === 'string' && key.startsWith('session:')) every.push(key.slice('session:'.length))
1356
+ }
1357
+ // In the heading the label is followed by the search slot; inserting before
1358
+ // it keeps the box beside the words instead of inside the action cluster.
1359
+ // The heading row is: label, search slot, options, add. The box goes after
1360
+ // the label, before the first action it can find.
1361
+ placeGroupBox(headings[0], ALL_BUTTON, t('selectAllWorkspaces'), every,
1362
+ '[class*="_searchSlot"], [class*="_headerActions"]')
1363
+ }
1364
+ for (const row of rows) {
1365
+ const key = rowKeyOf(row)
1366
+ if (typeof key !== 'string' || !key.startsWith('workspace:')) continue
1367
+ // The workspace row is: folder, chevron, label block, then the actions. The
1368
+ // actions carry `margin-left:auto`, so anything appended after them lands at
1369
+ // the far edge; inserting before them keeps the box beside the name.
1370
+ placeGroupBox(row, GROUP_BUTTON, t('selectAllGroup'), sessionsUnderWorkspace(row),
1371
+ '[class*="_rowActions"]')
1372
+ }
1373
+ }
1374
+
1087
1375
  function decorateRows() {
1088
1376
  if (typeof document === 'undefined') return
1089
1377
  const rows = document.querySelectorAll('[role="treeitem"]')
@@ -1115,6 +1403,7 @@ window.__ModuleLoader__.load({
1115
1403
  }
1116
1404
  row.classList.toggle('dsdel-row-pending', state.pending.has(id))
1117
1405
  })
1406
+ decorateSelectAll(rows)
1118
1407
  if (!state.selecting) {
1119
1408
  document.querySelectorAll('.dsdel-check').forEach((el) => el.remove())
1120
1409
  }
@@ -1124,16 +1413,32 @@ window.__ModuleLoader__.load({
1124
1413
  * inside the transcript produces characterData records forever; scheduling a
1125
1414
  * full row scan for those would burn a frame's budget on every token.
1126
1415
  */
1416
+ /** True for the nodes this plugin itself inserts into the sidebar. */
1417
+ function isOwnNode(node) {
1418
+ if (node === null || node === undefined || typeof node.getAttribute !== 'function') return false
1419
+ return node.getAttribute('data-dsh-delete-session') !== null
1420
+ }
1421
+
1422
+ function allOwnNodes(list) {
1423
+ if (list === null || list === undefined || list.length === 0) return true
1424
+ for (const node of list) if (!isOwnNode(node)) return false
1425
+ return true
1426
+ }
1427
+
1127
1428
  function onRowMutations(records) {
1128
1429
  if (records === undefined || records === null) return scheduleDecorate()
1129
1430
  for (const record of records) {
1130
1431
  const added = record === null || record === undefined ? null : record.addedNodes
1131
1432
  const removed = record === null || record === undefined ? null : record.removedNodes
1132
- if ((added !== null && added !== undefined && added.length > 0)
1133
- || (removed !== null && removed !== undefined && removed.length > 0)) {
1134
- scheduleDecorate()
1135
- return
1136
- }
1433
+ const hasAdded = added !== null && added !== undefined && added.length > 0
1434
+ const hasRemoved = removed !== null && removed !== undefined && removed.length > 0
1435
+ if (!hasAdded && !hasRemoved) continue
1436
+ // Its own boxes and spacers are not a reason to scan again. Counting
1437
+ // them made every pass schedule the next one: a loop that kept moving
1438
+ // the box out from under the cursor.
1439
+ if (allOwnNodes(added) && allOwnNodes(removed)) continue
1440
+ scheduleDecorate()
1441
+ return
1137
1442
  }
1138
1443
  }
1139
1444
 
@@ -1262,7 +1567,12 @@ window.__ModuleLoader__.load({
1262
1567
 
1263
1568
  function onSelectClickCapture(e) {
1264
1569
  if (!state.selecting) return
1265
- const row = e.target && e.target.closest ? e.target.closest('[role="treeitem"]') : null
1570
+ const target = e.target && typeof e.target.closest === 'function' ? e.target : null
1571
+ // Anything this plugin drew handles its own click. Its document listener
1572
+ // runs first (capture), so without this guard a click on a select-all box
1573
+ // inside a workspace treeitem is swallowed as if the row itself was clicked.
1574
+ if (target !== null && target.closest('[data-dsh-delete-session]') !== null) return
1575
+ const row = target === null ? null : target.closest('[role="treeitem"]')
1266
1576
  if (!row) return
1267
1577
  const id = sessionIdFromRow(row)
1268
1578
  if (!id) return
@@ -1333,6 +1643,12 @@ window.__ModuleLoader__.load({
1333
1643
  document.removeEventListener('keydown', onSelectKeydown, true)
1334
1644
  if (rowObserver) { rowObserver.disconnect(); rowObserver = null }
1335
1645
  document.querySelectorAll('.dsdel-check').forEach((el) => el.remove())
1646
+ // Take the select-all boxes and their spacer with the mode, now rather than
1647
+ // on the next decorate pass: the spacer grows, so a frame of it left behind
1648
+ // would visibly shove the row's right-hand cluster to the left.
1649
+ for (const cls of [GROUP_BUTTON, ALL_BUTTON, SPACER]) {
1650
+ document.querySelectorAll('.' + cls).forEach((el) => el.remove())
1651
+ }
1336
1652
  publish()
1337
1653
  }
1338
1654
 
@@ -1361,6 +1677,15 @@ window.__ModuleLoader__.load({
1361
1677
  for (const id of ids) state.pending.add(id)
1362
1678
  publish()
1363
1679
 
1680
+ // The same switch the single path honours; without this every request went
1681
+ // out with no `quarantine` field and the files stayed where they were.
1682
+ const quarantine = quarantinePlan()
1683
+ // The feature is on but `auto` is off: the user expects files to be handled
1684
+ // and a batch cannot show the per-file checklist. Say so afterwards rather
1685
+ // than pretending the files were dealt with.
1686
+ const askOnly = !artifactsOff() && !artifactsAuto()
1687
+ let movedFiles = 0
1688
+ let failedFiles = 0
1364
1689
  const failedIds = []
1365
1690
  let cursor = 0
1366
1691
  const worker = async () => {
@@ -1370,7 +1695,12 @@ window.__ModuleLoader__.load({
1370
1695
  if (index >= ids.length) return
1371
1696
  const id = ids[index]
1372
1697
  try {
1373
- await postDelete(id)
1698
+ const result = await postDelete(id, quarantine)
1699
+ const outcome = result && result.quarantine ? result.quarantine : null
1700
+ if (outcome !== null) {
1701
+ movedFiles += outcome.moved.length
1702
+ failedFiles += outcome.failed.length
1703
+ }
1374
1704
  state.batch.done += 1
1375
1705
  } catch {
1376
1706
  state.batch.failed += 1
@@ -1388,12 +1718,22 @@ window.__ModuleLoader__.load({
1388
1718
  const ok = state.batch ? state.batch.done : 0
1389
1719
  state.batch = null
1390
1720
  if (failed === 0) {
1391
- toast(t('batchDone', ok))
1721
+ // The files are reported with the count, so a user who moved a hundred
1722
+ // of them sees that number instead of a bare "deleted".
1723
+ if (failedFiles > 0) {
1724
+ toast(t('batchDoneQuarantineFailed', ok, movedFiles, failedFiles), true)
1725
+ } else if (movedFiles > 0) {
1726
+ toast(t('batchDoneQuarantine', ok, movedFiles))
1727
+ } else {
1728
+ toast(t('batchDone', ok))
1729
+ }
1730
+ if (askOnly) toast(t('batchAskArtifacts'), true)
1392
1731
  exitSelection({ keepPending: true })
1393
1732
  settlePendingSoon()
1394
1733
  } else {
1395
1734
  for (const id of failedIds) state.selected.add(id)
1396
1735
  toast(t('batchPartial', ok, failed), true)
1736
+ if (askOnly) toast(t('batchAskArtifacts'), true)
1397
1737
  publish()
1398
1738
  }
1399
1739
  refreshList()
@@ -1472,7 +1812,7 @@ window.__ModuleLoader__.load({
1472
1812
  // and the menu row forces the dialog in that case. With the feature off no
1473
1813
  // quarantine field is sent at all, keeping the request identical to the
1474
1814
  // version that predates the feature.
1475
- const quarantine = !artifactsOff() && artifactsAuto() ? { scope: artifactScope() } : undefined
1815
+ const quarantine = quarantinePlan()
1476
1816
  postDelete(info.sessionId, quarantine)
1477
1817
  .then((result) => {
1478
1818
  const outcome = result && result.quarantine ? result.quarantine : null