dsh-delete-session 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # dsh-delete-session
2
+ - **拖到页脚删除** —— 把侧边栏里的对话直接拖到页脚那一条,整条变红并显示「松手删除「标题」」,松手即按「删除时询问」的设置走:开着就弹确认框,关着就直接删;多选模式下拖动仍是宿主的行排序,不会被接管
2
3
 
3
4
  **DeepSeek Harness 会话删除插件 —— 在侧边栏会话菜单里直接删除会话。**
4
5
 
@@ -24,7 +25,7 @@ DSH 侧边栏的会话菜单只有**重命名 / 分叉 / 归档**——归档只
24
25
  - **对话框文案跟随开关** —— 勾选时写「并放进系统回收站」,取消勾选时写「永久删除…不可恢复」。你看到的永远是你实际会得到的
25
26
  - **风险确认** —— 每次删除弹出确认对话框,显示会话标题与 ID。要不要弹这个框**只在设置页改**,弹窗里没有快捷勾选;**按住 Shift 点击**可以临时强制弹窗
26
27
  - **子会话一起删** —— 子代理是**独立会话**(独立目录、独立日志),父会话删掉后它们会变成孤儿留在磁盘上。现在删除对话时会处理它派生的子会话:设置里勾选「同时删除子会话」就一起删;不勾选则弹窗列出子会话,由你勾选要删哪些(默认全选)
27
- - **多选批量删除** —— 会话菜单「多选」进入选择模式:勾选多行后底部操作条显示「已选 N 个 / 取消 / 删除」;点删除立即批量执行,被选中的行乐观隐藏、操作条实时显示进度,客户端 6 路并发、工作区记账串行;失败的行恢复显示并保持选中,方便重试;Esc 退出
28
+ - **多选批量删除** —— 会话菜单「多选」进入选择模式:勾选多行后,侧边栏页脚那一行(官方 `sidebar.footer.action` 槽位)会出现操作条(「已选 N 个 / 取消 / 删除」),位置由宿主排列,退出选择模式即消失;点删除立即批量执行,被选中的行乐观隐藏、操作条实时显示进度,客户端 6 路并发、工作区记账串行;失败的行恢复显示并保持选中,方便重试;Esc 退出
28
29
  - **产出文件隔离(可选,默认关闭)** —— 打开后,删除会话时还能把这个对话在工作目录里产出的文件**移进隔离夹**,而不是直接删掉;范围可选「仅新建」或「新建的和改过的」,模式可选「全部直接隔离」或「先列清单由你勾选」
29
30
  - **跳过 git 仓库内的文件(默认开)** —— 在项目里干过活的对话,产出文件里往往就是项目源码。开启后仓库内的文件一律不碰,避免删一个对话把项目搬空
30
31
  - **删除后回到新会话** —— 若删除的正是当前打开的会话,自动切到一个全新会话,而不是落到已不可用的邻居页
@@ -71,6 +72,8 @@ dsh plugin --profile web add github:DDDMUC/dsh-delete-session
71
72
  | **同时删除子会话** | **关** | 开:删对话时把它派生的子代理会话一起删掉。关:弹窗列出子会话,由你勾选 |
72
73
  | 隔离夹保存位置 | 空(= `$DSH_HOME`) | 可手输、可点「选择文件夹…」调系统对话框、可点「打开」在资源管理器里定位 |
73
74
 
75
+ > 「选择文件夹…」用的是宿主自己的 `ctx.directoryPicker`:本地桌面弹系统对话框,远程/浏览式宿主自动退回页面内的目录列表。插件不再自带任何自绘或自编译的选择器。
76
+
74
77
  ### 删除之后文件在哪
75
78
 
76
79
  | 平台 | 去处 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-delete-session",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Delete sessions from the DSH Web sidebar: adds a Delete action to the session row menu with a risk-consent dialog, 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
@@ -61,6 +61,9 @@ window.__ModuleLoader__.load({
61
61
  pageAsk: '删除时询问',
62
62
  pageRecycle: '删除至回收站',
63
63
  pageSyncChildren: '同时删除子会话',
64
+ dropHint: '拖到这里删除',
65
+ dropRelease: '松手删除「{name}」',
66
+ dropFallback: '这个对话',
64
67
  starAsk: '⭐ 顺手留颗 Star,作者能高兴一整天',
65
68
  starCta: '行,给你一颗 Star',
66
69
  pageSyncChildrenOn: '删除对话时,把它派生的子代理会话一起删掉。',
@@ -98,6 +101,7 @@ window.__ModuleLoader__.load({
98
101
  rootOpened: '已在文件管理器中打开',
99
102
  rootOpenFailed: '打开失败:',
100
103
  pickerOpening: '已打开系统文件夹对话框,请在弹出的窗口里选择',
104
+ pickerFailed: '选择文件夹失败:',
101
105
  pageRootReset: '用默认',
102
106
  pageRootDefaultHint: (path) => `当前使用默认路径:${path}`,
103
107
  pageRootCustomHint: '隔离夹会建在这个目录下,每次删除生成一个带时间戳的子目录',
@@ -155,6 +159,9 @@ window.__ModuleLoader__.load({
155
159
  pageAsk: 'Ask before deleting',
156
160
  pageRecycle: 'Delete to the Recycle Bin',
157
161
  pageSyncChildren: 'Delete child sessions too',
162
+ dropHint: 'Drop here to delete',
163
+ dropRelease: 'Release to delete \'{name}\'',
164
+ dropFallback: 'this conversation',
158
165
  starAsk: '⭐ A star would make the author\'s day',
159
166
  starCta: 'Fine — have one',
160
167
  pageSyncChildrenOn: 'A delete also removes the subagent sessions it spawned.',
@@ -190,6 +197,7 @@ window.__ModuleLoader__.load({
190
197
  rootOpened: 'Opened in the file manager',
191
198
  rootOpenFailed: 'Could not open: ',
192
199
  pickerOpening: 'The system folder dialog is open; pick a folder in that window',
200
+ pickerFailed: 'Could not open the folder picker: ',
193
201
  pageRootReset: 'Use default',
194
202
  pageRootDefaultHint: (path) => `Using the default path: ${path}`,
195
203
  pageRootCustomHint: 'The quarantine folder is created here, one timestamped subfolder per delete',
@@ -259,8 +267,32 @@ window.__ModuleLoader__.load({
259
267
  const raw = typeof injected === 'function' ? injected : t
260
268
  if (raw.__dsdelLocalized === true) return raw
261
269
  const wrapped = (key, a, b) => {
262
- const value = raw(key, a, b)
263
- return typeof value === 'function' ? value(a, b) : value
270
+ // Our own dictionary answers first, and it is resolved HERE rather than
271
+ // through the host. `dsh-client-locale` interpolates whatever it finds as
272
+ // soon as params are present - it calls `template.replace(...)` - while
273
+ // most of these entries are functions. Handing it params made the host
274
+ // throw "template.replace is not a function", and the slot boundary turned
275
+ // that into an empty `data-slot-error` anchor: the bar vanished, Cancel
276
+ // and all. Calling it without params is no better: the host (and this
277
+ // module's own `t`) invoke function entries with no arguments, which
278
+ // produces "已选 undefined 个".
279
+ const dictionary = browserLang() === 'en' ? en : zh
280
+ const local = dictionary[key]
281
+ if (local !== undefined) {
282
+ if (typeof local === 'function') return local(a, b)
283
+ if (typeof local === 'string' && local.includes('{') && a !== undefined) {
284
+ const params = a !== null && typeof a === 'object'
285
+ ? a
286
+ : { n: a, done: a, total: b, ok: a, fail: b, path: a }
287
+ return local.replace(/\{(\w+)\}/g, (match, name) => (
288
+ params[name] === undefined ? match : String(params[name])
289
+ ))
290
+ }
291
+ return local
292
+ }
293
+ // A key this plugin does not ship: let the host answer.
294
+ const value = raw(key)
295
+ return typeof value === 'function' ? value(a, b) : (value === undefined || value === null ? key : value)
264
296
  }
265
297
  wrapped.__dsdelLocalized = true
266
298
  return wrapped
@@ -285,6 +317,11 @@ window.__ModuleLoader__.load({
285
317
  picker: null,
286
318
  /** The host's default quarantine root, fetched once so the card can name it. */
287
319
  defaultRoot: null,
320
+ /**
321
+ * The session being dragged over the footer, or null. `over` arms the drop:
322
+ * the bar only says "松手删除" once the pointer is actually on it.
323
+ */
324
+ drag: null,
288
325
  }
289
326
 
290
327
  const listeners = new Set()
@@ -298,6 +335,7 @@ window.__ModuleLoader__.load({
298
335
  batch: state.batch,
299
336
  picker: state.picker,
300
337
  defaultRoot: state.defaultRoot,
338
+ drag: state.drag,
301
339
  selectedCount: state.selected.size,
302
340
  }
303
341
  }
@@ -468,11 +506,13 @@ window.__ModuleLoader__.load({
468
506
  * a conversation of its own, so it is offered rather than swept up.
469
507
  */
470
508
  function syncChildren() {
471
- return readPref(SYNC_CHILDREN_KEY, '0') === '1'
509
+ return readPref(SYNC_CHILDREN_KEY, '1') !== '0'
472
510
  }
473
511
 
474
512
  function setSyncChildren(on) {
475
- writePref(SYNC_CHILDREN_KEY, on ? '1' : null)
513
+ // "Off" is written as '0' rather than cleared: the default is now on, so a
514
+ // removed key would read back as on again.
515
+ writePref(SYNC_CHILDREN_KEY, on ? '1' : '0')
476
516
  }
477
517
 
478
518
  /** The chosen quarantine root, or '' for "use the host default". */
@@ -652,9 +692,23 @@ window.__ModuleLoader__.load({
652
692
  '.dsdel-check-on::after{content:"";width:9px;height:5px;border-left:2px solid #fff;border-bottom:2px solid #fff;transform:rotate(-45deg) translateY(-1px)}',
653
693
  // 乐观删除:行先隐藏,失败时随 decorate 恢复
654
694
  '.dsdel-row-pending{display:none!important}',
655
- '.dsdel-bar{position:fixed;left:12px;bottom:12px;z-index:2147483600;display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:12px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.3));box-shadow:0 12px 32px rgba(0,0,0,.28);color:var(--dsw-alias-label-primary,inherit);font-size:13px;background:linear-gradient(var(--dsw-alias-bg-layer-2,#fff),var(--dsw-alias-bg-layer-2,#fff)),linear-gradient(var(--dsw-alias-bg-layer-2,#fff),var(--dsw-alias-bg-layer-2,#fff)),linear-gradient(var(--dsw-alias-bg-layer-2,#fff),var(--dsw-alias-bg-layer-2,#fff)),var(--dsw-alias-bg-base,#fff)}',
656
- '.dsdel-bar-count{white-space:nowrap}',
657
- '.dsdel-bar-btn{appearance:none;min-height:30px;padding:0 12px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.4));background:var(--dsw-alias-fill-elevated,rgba(128,128,128,.08));color:var(--dsw-alias-label-primary,inherit);border-radius:8px;font-size:13px;cursor:pointer}',
695
+ '.dsdel-bar{display:flex;align-items:center;gap:8px;width:100%;min-width:0;padding:6px 8px;box-sizing:border-box;font-size:13px}',
696
+ // The sidebar foot stacks three things: the footer-action row, the usage
697
+ // card and the account row. While a selection runs only the action row
698
+ // stays, so the bar sits where the account row used to end the sidebar.
699
+ 'body.dsdel-selecting [class*="_footArea"] > *:not([class*="_footerActions"]){display:none}',
700
+ // The other footer buttons are named POSITIVELY, by the attributes their
701
+ // plugins put on them, and never by "everything except the bar": the bar
702
+ // turned out not to be a direct child of the slot container, so an
703
+ // exclusion rule silently hid the bar together with its Cancel button.
704
+ 'body.dsdel-selecting [data-slot="sidebar.footer.action"] > [data-dsh-plugin]{display:none}',
705
+ 'body.dsdel-selecting [data-slot="sidebar.footer.action"] > [class*="_entryRow"]{display:none}',
706
+ '.dsdel-drop{border:1px dashed var(--dsw-alias-border-l2,rgba(128,128,128,.4));border-radius:8px;color:var(--dsw-alias-label-secondary,inherit)}',
707
+ '.dsdel-drop-over{border-color:var(--dsw-alias-state-error-primary,#e5484d);border-style:solid;background:rgba(229,72,77,.10);color:var(--dsw-alias-state-error-primary,#e5484d)}',
708
+ '.dsdel-drop-icon{display:inline-flex;flex:0 0 auto;align-items:center}',
709
+ '.dsdel-drop-text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
710
+ '.dsdel-bar-count{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--dsw-alias-label-secondary,inherit)}',
711
+ '.dsdel-bar-btn{flex:0 0 auto;white-space:nowrap;appearance:none;min-height:30px;padding:0 12px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.4));background:var(--dsw-alias-fill-elevated,rgba(128,128,128,.08));color:var(--dsw-alias-label-primary,inherit);border-radius:8px;font-size:13px;cursor:pointer}',
658
712
  '.dsdel-bar-btn:disabled{opacity:.5;cursor:default}',
659
713
  '.dsdel-bar-danger{border-color:var(--dsw-alias-state-error-primary,#e5484d);background:var(--dsw-alias-state-error-primary,#e5484d);color:#fff}',
660
714
  '.dsdel-page{display:flex;flex-direction:column;gap:8px}',
@@ -722,7 +776,8 @@ window.__ModuleLoader__.load({
722
776
  // per-row disabling: every row is selectable and the batch deletes
723
777
  // immediately (the single-session flow keeps its own consent dialog).
724
778
 
725
- let bar = null
779
+ // The bar lives in the sidebar footer slot: the host owns where that row sits,
780
+ // so there is no element here to create, dock or hide.
726
781
  let decorateRaf = null
727
782
  let rowObserver = null
728
783
 
@@ -739,6 +794,56 @@ window.__ModuleLoader__.load({
739
794
  return id === '' ? null : id
740
795
  }
741
796
 
797
+ // --- drag a session onto the footer to delete it ---------------------------
798
+ //
799
+ // The id comes from the host's own `data-row-key`, never from `dataTransfer`:
800
+ // the official drag only reorders, and a dragover payload is unreadable anyway.
801
+ // The gesture ends in the same place as the menu row - the confirmation dialog
802
+ // unless the user turned asking off - so there is exactly one delete policy.
803
+
804
+ /** The row under the pointer, with the title the drop target can name. */
805
+ function draggedSession(event) {
806
+ const target = event === null || event === undefined ? null : event.target
807
+ const row = target && typeof target.closest === 'function'
808
+ ? target.closest('[role="treeitem"]')
809
+ : null
810
+ const sessionId = sessionIdFromRow(row)
811
+ if (sessionId === null) return null
812
+ const text = row !== null && typeof row.textContent === 'string' ? row.textContent.trim() : ''
813
+ const title = text === '' ? null : text.slice(0, 40)
814
+ return { sessionId, title }
815
+ }
816
+
817
+ function onDragStartCapture(event) {
818
+ // Inside multi-select a drag is the host reordering rows; deleting on drop
819
+ // would make the mode quietly destructive.
820
+ if (state.selecting) return
821
+ const info = draggedSession(event)
822
+ if (info === null) return
823
+ state.drag = { sessionId: info.sessionId, title: info.title, over: false }
824
+ syncFooterMode()
825
+ publish()
826
+ }
827
+
828
+ function onDragEndCapture() {
829
+ if (state.drag === null) return
830
+ state.drag = null
831
+ syncFooterMode()
832
+ publish()
833
+ }
834
+
835
+ /** Drop on the bar: same policy as the menu row. */
836
+ function dropToDelete() {
837
+ const drag = state.drag
838
+ if (drag === null) return
839
+ state.drag = null
840
+ syncFooterMode()
841
+ publish()
842
+ const needsDialog = !artifactsOff() && !artifactsAuto()
843
+ if (skipConfirm() && !needsDialog) deleteNow({ sessionId: drag.sessionId })
844
+ else openDeleteDialog(drag.sessionId, drag.title)
845
+ }
846
+
742
847
  function decorateRows() {
743
848
  if (typeof document === 'undefined') return
744
849
  const rows = document.querySelectorAll('[role="treeitem"]')
@@ -747,14 +852,22 @@ window.__ModuleLoader__.load({
747
852
  if (!id) return
748
853
  // Checkboxes belong to multi-select only: a single delete (or any other
749
854
  // decorate pass outside the mode) must not plant them on every row.
855
+ // The checkbox is always the row's first element child, so it is read
856
+ // through the pointer. `querySelector` here ran twice per row per frame,
857
+ // which is the pass's dominant cost once the list is long.
858
+ const first = row.firstElementChild
859
+ const existing = first !== null && first !== undefined
860
+ && first.classList
861
+ && first.classList.contains(DEL_CHECK)
862
+ ? first
863
+ : null
750
864
  if (!state.selecting) {
751
- const stray = row.querySelector(':scope > .dsdel-check')
752
- if (stray) stray.remove()
865
+ if (existing !== null) existing.remove()
753
866
  } else {
754
- let check = row.querySelector(':scope > .dsdel-check')
867
+ let check = existing
755
868
  if (!check) {
756
869
  check = document.createElement('span')
757
- check.className = 'dsdel-check'
870
+ check.className = DEL_CHECK
758
871
  check.setAttribute('data-dsh-delete-session', 'check')
759
872
  row.insertBefore(check, row.firstChild)
760
873
  }
@@ -766,6 +879,23 @@ window.__ModuleLoader__.load({
766
879
  document.querySelectorAll('.dsdel-check').forEach((el) => el.remove())
767
880
  }
768
881
  }
882
+ /**
883
+ * A mutation batch only matters when a node came or went. Text streaming
884
+ * inside the transcript produces characterData records forever; scheduling a
885
+ * full row scan for those would burn a frame's budget on every token.
886
+ */
887
+ function onRowMutations(records) {
888
+ if (records === undefined || records === null) return scheduleDecorate()
889
+ for (const record of records) {
890
+ const added = record === null || record === undefined ? null : record.addedNodes
891
+ const removed = record === null || record === undefined ? null : record.removedNodes
892
+ if ((added !== null && added !== undefined && added.length > 0)
893
+ || (removed !== null && removed !== undefined && removed.length > 0)) {
894
+ scheduleDecorate()
895
+ return
896
+ }
897
+ }
898
+ }
769
899
 
770
900
  function scheduleDecorate() {
771
901
  if (typeof requestAnimationFrame !== 'function') return
@@ -789,74 +919,105 @@ window.__ModuleLoader__.load({
789
919
  return api
790
920
  }
791
921
 
792
- function updateBar() {
793
- if (!bar) return
794
- const count = bar.querySelector('.dsdel-bar-count')
795
- if (count) {
796
- if (state.batch === null) {
797
- count.textContent = t('selectedCount', state.selected.size)
798
- } else {
799
- // A move reports processed-so-far (success + failure + skip) in one
800
- // number; a delete counts its own two buckets.
801
- const done = state.batch.kind === 'move'
802
- ? state.batch.done
803
- : state.batch.done + state.batch.failed
804
- count.textContent = state.batch.kind === 'move'
805
- ? t('batchMoving', done, state.batch.total)
806
- : t('batchRunning', done, state.batch.total)
807
- }
808
- }
809
- const busy = state.batch !== null
810
- const empty = state.selected.size === 0
811
- const cancel = bar.querySelector('.dsdel-bar-cancel')
812
- const move = bar.querySelector('.dsdel-bar-move')
813
- const del = bar.querySelector('.dsdel-bar-danger')
814
- if (cancel) cancel.disabled = busy
815
- // Move and delete both need something selected, and both are inert while a
816
- // batch is already running.
817
- if (move) move.disabled = busy || empty
818
- if (del) del.disabled = busy || empty
819
- }
820
-
821
- function buildBar() {
822
- const el = document.createElement('div')
823
- el.className = 'dsdel-bar'
824
- el.setAttribute('role', 'toolbar')
825
- const count = document.createElement('span')
826
- count.className = 'dsdel-bar-count'
827
- const cancel = document.createElement('button')
828
- cancel.type = 'button'
829
- // Named so the bar never has to guess which plain button is Cancel.
830
- cancel.className = 'dsdel-bar-btn dsdel-bar-cancel'
831
- cancel.textContent = t('cancelSelect')
832
- cancel.addEventListener('click', (e) => { e.stopPropagation(); exitSelection() })
833
- const del = document.createElement('button')
834
- del.type = 'button'
835
- del.className = 'dsdel-bar-btn dsdel-bar-danger'
836
- del.textContent = t('deleteSelected')
837
- del.addEventListener('click', (e) => { e.stopPropagation(); runBatchDelete() })
838
- el.appendChild(count)
839
- el.appendChild(cancel)
840
- // One more button when dsh-session-relocate is installed; otherwise the bar
841
- // is exactly what it was before.
842
- if (relocateApi() !== null) {
843
- const move = document.createElement('button')
844
- move.type = 'button'
845
- move.className = 'dsdel-bar-btn dsdel-bar-move'
846
- move.textContent = t('moveSelected')
847
- move.addEventListener('click', (e) => { e.stopPropagation(); runBatchMove() })
848
- el.appendChild(move)
922
+ /**
923
+ * The batch bar, rendered into the host's `sidebar.footer.action` seat.
924
+ *
925
+ * The host decides where that row sits, how wide it is and whether the account
926
+ * chip shares it. Occupying the slot means this plugin never measures, docks,
927
+ * hides or restores host DOM: the row gains our controls while a selection is
928
+ * running, and loses them the moment it ends.
929
+ */
930
+ function BulkBar({ t: injected }) {
931
+ const translate = localizedTranslator(injected)
932
+ const view = useSnapshot()
933
+ // A session dragged over the sidebar turns the footer into a drop target.
934
+ if (view.drag !== null && view.drag !== undefined) {
935
+ const armed = view.drag.over === true
936
+ const name = view.drag.title === null || view.drag.title === undefined
937
+ ? translate('dropFallback')
938
+ : view.drag.title
939
+ return h('div', {
940
+ className: armed ? 'dsdel-bar dsdel-drop dsdel-drop-over' : 'dsdel-bar dsdel-drop',
941
+ role: 'toolbar',
942
+ onDragOver: (event) => {
943
+ if (event && typeof event.preventDefault === 'function') event.preventDefault()
944
+ if (event && event.dataTransfer) {
945
+ try { event.dataTransfer.dropEffect = 'move' } catch { /* read-only */ }
946
+ }
947
+ if (state.drag !== null && state.drag.over !== true) {
948
+ state.drag.over = true
949
+ publish()
950
+ }
951
+ },
952
+ onDragLeave: () => {
953
+ if (state.drag !== null && state.drag.over !== false) {
954
+ state.drag.over = false
955
+ publish()
956
+ }
957
+ },
958
+ onDrop: (event) => {
959
+ if (event && typeof event.preventDefault === 'function') event.preventDefault()
960
+ if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
961
+ dropToDelete()
962
+ },
963
+ },
964
+ h('span', { key: 'icon', className: 'dsdel-drop-icon' }, glyph(TRASH_PATHS)),
965
+ h('span', { key: 'text', className: 'dsdel-drop-text' },
966
+ armed ? translate('dropRelease', name) : translate('dropHint', name)),
967
+ )
849
968
  }
850
- el.appendChild(del)
851
- document.body.appendChild(el)
852
- return el
969
+ // Outside selection mode the footer keeps its normal face.
970
+ if (!view.selecting) return null
971
+ const busy = view.batch !== null
972
+ const empty = view.selectedCount === 0
973
+ // A move reports processed-so-far (success + failure + skip) in one number;
974
+ // a delete counts its own two buckets.
975
+ const done = view.batch === null ? 0 : view.batch.kind === 'move' ? view.batch.done : view.batch.done + view.batch.failed
976
+ const label = view.batch === null
977
+ ? translate('selectedCount', view.selectedCount)
978
+ : view.batch.kind === 'move'
979
+ ? translate('batchMoving', done, view.batch.total)
980
+ : translate('batchRunning', done, view.batch.total)
981
+ return h('div', { className: 'dsdel-bar', role: 'toolbar' },
982
+ h('span', { key: 'count', className: 'dsdel-bar-count' }, label),
983
+ h('button', {
984
+ key: 'cancel',
985
+ type: 'button',
986
+ className: 'dsdel-bar-btn dsdel-bar-cancel',
987
+ disabled: busy,
988
+ onClick: (event) => {
989
+ if (event && event.stopPropagation) event.stopPropagation()
990
+ exitSelection()
991
+ },
992
+ }, translate('cancelSelect')),
993
+ // One more button when dsh-session-relocate is installed; otherwise the bar
994
+ // is exactly what it was before.
995
+ relocateApi() === null ? null : h('button', {
996
+ key: 'move',
997
+ type: 'button',
998
+ className: 'dsdel-bar-btn dsdel-bar-move',
999
+ disabled: busy || empty,
1000
+ onClick: (event) => {
1001
+ if (event && event.stopPropagation) event.stopPropagation()
1002
+ runBatchMove()
1003
+ },
1004
+ }, translate('moveSelected')),
1005
+ h('button', {
1006
+ key: 'delete',
1007
+ type: 'button',
1008
+ className: 'dsdel-bar-btn dsdel-bar-danger',
1009
+ disabled: busy || empty,
1010
+ onClick: (event) => {
1011
+ if (event && event.stopPropagation) event.stopPropagation()
1012
+ runBatchDelete()
1013
+ },
1014
+ }, translate('deleteSelected')),
1015
+ )
853
1016
  }
854
-
855
1017
  function toggleSelect(id) {
856
1018
  if (state.selected.has(id)) state.selected.delete(id)
857
1019
  else state.selected.add(id)
858
1020
  publish()
859
- updateBar()
860
1021
  }
861
1022
 
862
1023
  function onSelectClickCapture(e) {
@@ -877,21 +1038,44 @@ window.__ModuleLoader__.load({
877
1038
  exitSelection()
878
1039
  }
879
1040
 
1041
+ /**
1042
+ * Mark the page while the mode runs. The marker is the only hook the
1043
+ * stylesheet needs to let the account row step aside for the bar.
1044
+ */
1045
+ function markSelecting(on) {
1046
+ if (typeof document === 'undefined' || !document.body) return
1047
+ const classes = document.body.classList
1048
+ if (!classes) return
1049
+ if (on) classes.add('dsdel-selecting')
1050
+ else classes.remove('dsdel-selecting')
1051
+ }
1052
+
1053
+ /** The footer is ours while selecting or while a session is dragged over it. */
1054
+ function syncFooterMode() {
1055
+ markSelecting(state.selecting || state.drag !== null)
1056
+ }
1057
+
880
1058
  function enterSelection() {
881
1059
  if (state.selecting) return
882
1060
  state.selecting = true
883
1061
  state.selected.clear()
884
1062
  ensureStyle()
885
- if (!bar) bar = buildBar()
886
- bar.style.display = 'flex'
1063
+ syncFooterMode()
887
1064
  document.addEventListener('click', onSelectClickCapture, true)
888
1065
  document.addEventListener('keydown', onSelectKeydown, true)
889
1066
  if (typeof MutationObserver === 'function') {
890
- rowObserver = new MutationObserver(scheduleDecorate)
891
- rowObserver.observe(document.body, { childList: true, subtree: true })
1067
+ rowObserver = new MutationObserver(onRowMutations)
1068
+ // Observation root is the list, not the document: the transcript below
1069
+ // streams tokens continuously and would otherwise wake this on every one.
1070
+ const list = typeof document.querySelector === 'function'
1071
+ ? document.querySelector(LIST_SELECTOR)
1072
+ : null
1073
+ rowObserver.observe(list !== null && list !== undefined ? list : document.body, {
1074
+ childList: true,
1075
+ subtree: true,
1076
+ })
892
1077
  }
893
1078
  publish()
894
- updateBar()
895
1079
  }
896
1080
 
897
1081
  function exitSelection(options) {
@@ -904,7 +1088,7 @@ window.__ModuleLoader__.load({
904
1088
  state.pending.clear()
905
1089
  document.querySelectorAll('.dsdel-row-pending').forEach((el) => el.classList.remove('dsdel-row-pending'))
906
1090
  }
907
- if (bar) bar.style.display = 'none'
1091
+ syncFooterMode()
908
1092
  document.removeEventListener('click', onSelectClickCapture, true)
909
1093
  document.removeEventListener('keydown', onSelectKeydown, true)
910
1094
  if (rowObserver) { rowObserver.disconnect(); rowObserver = null }
@@ -936,7 +1120,6 @@ window.__ModuleLoader__.load({
936
1120
  state.selected.clear()
937
1121
  for (const id of ids) state.pending.add(id)
938
1122
  publish()
939
- updateBar()
940
1123
 
941
1124
  const failedIds = []
942
1125
  let cursor = 0
@@ -955,7 +1138,6 @@ window.__ModuleLoader__.load({
955
1138
  state.pending.delete(id)
956
1139
  }
957
1140
  publish()
958
- updateBar()
959
1141
  }
960
1142
  }
961
1143
  const workers = []
@@ -973,7 +1155,6 @@ window.__ModuleLoader__.load({
973
1155
  for (const id of failedIds) state.selected.add(id)
974
1156
  toast(t('batchPartial', ok, failed), true)
975
1157
  publish()
976
- updateBar()
977
1158
  }
978
1159
  refreshList()
979
1160
  for (const id of ids) {
@@ -997,7 +1178,6 @@ window.__ModuleLoader__.load({
997
1178
 
998
1179
  state.batch = { kind: 'move', total: ids.length, done: 0, failed: 0 }
999
1180
  publish()
1000
- updateBar()
1001
1181
 
1002
1182
  let result
1003
1183
  try {
@@ -1006,13 +1186,11 @@ window.__ModuleLoader__.load({
1006
1186
  if (state.batch === null || state.batch.kind !== 'move') return
1007
1187
  if (typeof done === 'number' && Number.isFinite(done)) state.batch.done = Math.max(0, done)
1008
1188
  if (typeof total === 'number' && Number.isFinite(total)) state.batch.total = Math.max(1, total)
1009
- updateBar()
1010
1189
  },
1011
1190
  })
1012
1191
  } catch (reason) {
1013
1192
  state.batch = null
1014
1193
  publish()
1015
- updateBar()
1016
1194
  toast(t('failed') + String((reason && reason.message) || reason), true)
1017
1195
  return
1018
1196
  }
@@ -1024,7 +1202,6 @@ window.__ModuleLoader__.load({
1024
1202
  if (result && (result.canceled === true || result.cancelled === true)) {
1025
1203
  // The user backed out of the target picker; keep the selection for a retry.
1026
1204
  publish()
1027
- updateBar()
1028
1205
  return
1029
1206
  }
1030
1207
 
@@ -1261,11 +1438,16 @@ window.__ModuleLoader__.load({
1261
1438
  toast(t('rootSet'))
1262
1439
  })
1263
1440
  .catch((reason) => {
1264
- if (reason && reason.code === 'unsupported') {
1441
+ // Two host answers mean "use the page picker instead": `unsupported`
1442
+ // (no directoryPicker service at all) and `browse` (the service exists
1443
+ // but serves listings, which is what a remote client gets). Neither is
1444
+ // a failure, so neither may surface as a toast.
1445
+ if (reason && (reason.code === 'unsupported' || reason.code === 'browse')) {
1265
1446
  openPicker()
1266
1447
  return
1267
1448
  }
1268
- toast(t('failed') + String((reason && reason.message) || reason), true)
1449
+ // Nothing was deleted here, so the delete wording would mislead.
1450
+ toast(t('pickerFailed') + String((reason && reason.message) || reason), true)
1269
1451
  })
1270
1452
  .finally(() => {
1271
1453
  folderDialogOpen = false
@@ -1339,6 +1521,11 @@ window.__ModuleLoader__.load({
1339
1521
 
1340
1522
  // --- menu rows (slot: sidebar.workspaces.session.menu.item) ----------------
1341
1523
 
1524
+ /** The sidebar list container; hashed class name, matched by its suffix. */
1525
+ const LIST_SELECTOR = '[class*="_regionArea"]'
1526
+ /** Marks a row checkbox this plugin planted. */
1527
+ const DEL_CHECK = 'dsdel-check'
1528
+
1342
1529
  /** Inline glyphs for the two rows; the host exposes no matching pair. */
1343
1530
  const TRASH_PATHS = ['M4 7h16', 'M10 11v6', 'M14 11v6', 'M6 7l1 13a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1l1-13', 'M9 7V4h6v3']
1344
1531
  const SELECT_PATHS = ['M5 7m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0', 'M5 17m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0', 'M11 7h9', 'M11 17h9']
@@ -1904,6 +2091,12 @@ window.__ModuleLoader__.load({
1904
2091
  }
1905
2092
 
1906
2093
  const install = (slots) => {
2094
+ // The drag gesture is document-wide (the row is not ours), so these are
2095
+ // plain capture listeners rather than slot handlers.
2096
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
2097
+ document.addEventListener('dragstart', onDragStartCapture, true)
2098
+ document.addEventListener('dragend', onDragEndCapture, true)
2099
+ }
1907
2100
  // Session menu rows. A package-namespaced id keeps them beside the
1908
2101
  // shipped pin(100)/rename(200)/fork(300)/archive(400)/session-id(450).
1909
2102
  slots.inject('sidebar.workspaces.session.menu.item', () => slots.register(
@@ -1930,12 +2123,22 @@ window.__ModuleLoader__.load({
1930
2123
  { name: 'plugins.row.config', key: `${NS}#${NS}` },
1931
2124
  AskBeforeDeleteOption,
1932
2125
  ))
2126
+ // The batch bar rides the official footer seat, so the host owns its
2127
+ // position and the row it shares with the account chip.
2128
+ slots.inject('sidebar.footer.action', () => slots.register(
2129
+ { name: 'sidebar.footer.action', id: `${NS}-bulkbar`, order: 30, locale: NS },
2130
+ BulkBar,
2131
+ ))
1933
2132
 
1934
- // The batch bar and its row observer are the only long-lived DOM state;
1935
- // drop them when the plugin unloads.
2133
+ // Leaving the mode disconnects the row observer and strips the checkboxes.
1936
2134
  return () => {
2135
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
2136
+ document.removeEventListener('dragstart', onDragStartCapture, true)
2137
+ document.removeEventListener('dragend', onDragEndCapture, true)
2138
+ }
2139
+ state.drag = null
2140
+ syncFooterMode()
1937
2141
  exitSelection()
1938
- if (bar) { bar.remove(); bar = null }
1939
2142
  }
1940
2143
  }
1941
2144