dsh-delete-session 0.4.0 → 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/README.md CHANGED
@@ -162,6 +162,13 @@ MIT
162
162
 
163
163
  ## 修复记录
164
164
 
165
+ **(v0.5.0)** —— 批量删除也会列出产出文件清单,交给你勾。
166
+
167
+ - **问题**:产出文件功能开着、默认的「先询问」模式下,批量删一个文件都不处理 —— 删完才弹一句「这批会话的产出文件没有处理」([#4](https://github.com/DDDMUC/dsh-delete-session/issues/4))。v0.3.1 只修了「全部自动进隔离夹」那一半。
168
+ - **现在**:点「删除」先扫一遍选中会话,弹一个汇总清单 —— 按会话分组、可逐文件勾选、每个会话一行「已选 X/Y」、顶上还有「全选」。确认后每个会话带**自己的** `paths` 发请求,宿主把它跟自己派生的候选集取交集,**只能收窄不能放宽**。取消则什么都不删。
169
+ - **扫描是只读的**:4 路并发读会话日志,进度条照实显示 N/M。不给「超过 N 个就不问」的降级 —— 那会回到「不问就动文件」。
170
+ - **没有产出文件的会话照样列出**,写明「没有产出文件」,不隐藏。
171
+ - **两个模式不变**:功能关闭、或设成「全部自动进隔离夹」时仍然直接删,跟以前一样。
165
172
  **(v0.4.0)** —— 「删完开一个新会话」变成可选,默认开,并改走宿主的 `startSession()`。
166
173
 
167
174
  - **为什么会新建**:删掉当前打开的会话,主视图会停在一个已经不存在的会话上(合成器禁用,看着像删除失败)。v0.1.7 起,插件为此**去点侧栏的「新建会话」按钮** —— 那是用户入口,任何拦截新建的插件(命名、模板选择、预设工作区)都会被误伤。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-delete-session",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
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,12 @@ window.__ModuleLoader__.load({
61
61
  batchPartial: (ok, fail) => `已删除 ${ok} 个,${fail} 个失败`,
62
62
  batchDoneQuarantine: (n, m) => `已删除 ${n} 个会话,${m} 个文件已移入隔离夹`,
63
63
  batchDoneQuarantineFailed: (n, ok, fail) => `已删除 ${n} 个会话,隔离 ${ok} 个、${fail} 个失败`,
64
+ batchPlanTitle: '这批会话的产出文件',
65
+ batchPlanScanning: (done, total) => `正在读取会话记录… ${done}/${total}`,
66
+ batchPlanSummary: (sessions, files) => `${sessions} 个会话,共 ${files} 个文件`,
67
+ batchPlanAll: (picked, total) => `全选(已选 ${picked}/${total})`,
68
+ batchPlanSession: (picked, total) => `这个小节已选 ${picked}/${total}`,
69
+ batchPlanEmpty: '这些会话都没有产出文件,删除只清理对话记录。',
64
70
  batchAskArtifacts: '这批会话的产出文件没有处理:批量删除不列逐文件清单。要处理它们,请单个删除,或在插件页改成「产出文件默认全部进隔离夹」。',
65
71
  batchFailed: '批量删除失败:',
66
72
  pageAsk: '删除时询问',
@@ -173,6 +179,12 @@ window.__ModuleLoader__.load({
173
179
  batchPartial: (ok, fail) => `Deleted ${ok}, ${fail} failed`,
174
180
  batchDoneQuarantine: (n, m) => `Deleted ${n} session(s), ${m} file(s) moved to quarantine`,
175
181
  batchDoneQuarantineFailed: (n, ok, fail) => `Deleted ${n} session(s), ${ok} quarantined and ${fail} failed`,
182
+ batchPlanTitle: 'Produced files in these sessions',
183
+ batchPlanScanning: (done, total) => `Reading the session logs… ${done}/${total}`,
184
+ batchPlanSummary: (sessions, files) => `${sessions} sessions, ${files} files`,
185
+ batchPlanAll: (picked, total) => `Select all (${picked}/${total} ticked)`,
186
+ batchPlanSession: (picked, total) => `${picked}/${total} ticked in this session`,
187
+ batchPlanEmpty: 'None of these sessions produced files; deleting them only clears the conversation logs.',
176
188
  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".',
177
189
  batchFailed: 'Batch delete failed: ',
178
190
  pageAsk: 'Ask before deleting',
@@ -282,6 +294,12 @@ window.__ModuleLoader__.load({
282
294
  batchPartial: (ok, fail) => `Удалено ${ok}, не удалось ${fail}`,
283
295
  batchDoneQuarantine: (n, m) => `Удалено сессий: ${n}, файлов в карантине: ${m}`,
284
296
  batchDoneQuarantineFailed: (n, ok, fail) => `Удалено сессий: ${n}, в карантине ${ok}, не удалось ${fail}`,
297
+ batchPlanTitle: 'Файлы этих сессий',
298
+ batchPlanScanning: (done, total) => `Читаю журналы сессий… ${done}/${total}`,
299
+ batchPlanSummary: (sessions, files) => `${sessions} сессий, ${files} файлов`,
300
+ batchPlanAll: (picked, total) => `Выбрать все (${picked}/${total})`,
301
+ batchPlanSession: (picked, total) => `В этой сессии отмечено ${picked}/${total}`,
302
+ batchPlanEmpty: 'Ни одна из этих сессий не создавала файлов; удаление очистит только журналы диалогов.',
285
303
  batchAskArtifacts: 'Файлы этих сессий не обработаны: пакетное удаление не показывает список файлов. Удаляйте по одному или переключите страницу плагина на «все созданные файлы в карантин». ',
286
304
  batchFailed: 'Массовое удаление не удалось: ',
287
305
  pageAsk: 'Спрашивать перед удалением',
@@ -527,6 +545,13 @@ window.__ModuleLoader__.load({
527
545
  pending: new Set(),
528
546
  /** { total, done, failed } while a batch delete runs, else null. */
529
547
  batch: null,
548
+ /**
549
+ * The aggregated file checklist a batch in asking mode shows before it
550
+ * deletes anything: { scanning, scanned, total, error, sessions[] }.
551
+ * Asking means the user picks the files, and a batch of sessions has no
552
+ * per-session dialog to pick them in - so the choice is made here, once.
553
+ */
554
+ batchPlan: null,
530
555
  /** Folder-picker state while it is open, else null. */
531
556
  picker: null,
532
557
  /** The host's default quarantine root, fetched once so the card can name it. */
@@ -547,6 +572,7 @@ window.__ModuleLoader__.load({
547
572
  selected: state.selected,
548
573
  pending: state.pending,
549
574
  batch: state.batch,
575
+ batchPlan: state.batchPlan,
550
576
  picker: state.picker,
551
577
  defaultRoot: state.defaultRoot,
552
578
  drag: state.drag,
@@ -1128,6 +1154,7 @@ window.__ModuleLoader__.load({
1128
1154
  '.dsdel-dialog-wide > :first-child{flex:1 1 auto;min-height:0;overflow:auto}',
1129
1155
  '.dsdel-dialog-wide > :last-child{flex:0 0 auto;margin-top:auto}',
1130
1156
  '.dsdel-artifacts{overflow:auto;overscroll-behavior:contain;padding-right:2px}',
1157
+ '.dsdel-batch-row{padding-left:22px}',
1131
1158
  '[role="dialog"]:has(.dsdel-file-row),[aria-modal="true"]:has(.dsdel-file-row){width:min(46vw,860px);max-width:min(46vw,860px);min-height:min(240px,88vh);max-height:88vh}',
1132
1159
  '.dsdel-picker-list{display:flex;flex-direction:column;gap:2px;max-height:280px;overflow:auto;margin:0 0 8px}',
1133
1160
  '.dsdel-picker-row{appearance:none;text-align:left;padding:6px 8px;border:0;border-radius:6px;background:transparent;color:inherit;font:inherit;font-size:13px;cursor:pointer}',
@@ -1671,7 +1698,7 @@ window.__ModuleLoader__.load({
1671
1698
  disabled: busy || empty,
1672
1699
  onClick: (event) => {
1673
1700
  if (event && event.stopPropagation) event.stopPropagation()
1674
- runBatchDelete()
1701
+ beginBatchDelete()
1675
1702
  },
1676
1703
  }, translate('deleteSelected')),
1677
1704
  )
@@ -1750,6 +1777,7 @@ window.__ModuleLoader__.load({
1750
1777
  state.selecting = false
1751
1778
  state.selected.clear()
1752
1779
  state.batch = null
1780
+ state.batchPlan = null
1753
1781
  const keepPending = !!(options && options.keepPending)
1754
1782
  if (!keepPending) {
1755
1783
  state.pending.clear()
@@ -1785,7 +1813,169 @@ window.__ModuleLoader__.load({
1785
1813
  // (I/O 并行度约在 8 饱和),6 路比 4 路快约 1/3 且仍在饱和点以下。
1786
1814
  const BATCH_CONCURRENCY = 6
1787
1815
 
1788
- function runBatchDelete() {
1816
+ /** How many sessions one checklist scan reads at a time. */
1817
+ const SCAN_CONCURRENCY = 4
1818
+
1819
+ /**
1820
+ * The bar's Delete: straight through in auto/off mode, a checklist in asking
1821
+ * mode.
1822
+ *
1823
+ * Asking means the user chooses the files, and the single path honours that by
1824
+ * showing a list inside the confirmation dialog. A batch has no such dialog -
1825
+ * it deletes several sessions at once - so leaving it out was the whole of
1826
+ * issue #4: the feature was on, the files stayed put, and the only signal was
1827
+ * a toast afterwards. Here the choice is made once, over every session in the
1828
+ * selection, before anything is deleted.
1829
+ */
1830
+ function beginBatchDelete() {
1831
+ if (state.batch !== null || state.batchPlan !== null) return
1832
+ if (state.selected.size === 0) return
1833
+ if (artifactsOff() || artifactsAuto()) {
1834
+ runBatchDelete()
1835
+ return
1836
+ }
1837
+ startBatchScan()
1838
+ }
1839
+
1840
+ /** The title the sidebar row shows, for naming a session in the checklist. */
1841
+ function titleForSession(id) {
1842
+ if (typeof document === 'undefined') return null
1843
+ const key = `session:${id}`
1844
+ let row = null
1845
+ try {
1846
+ for (const candidate of document.querySelectorAll('[role="treeitem"]')) {
1847
+ if (rowKeyOf(candidate) === key) { row = candidate; break }
1848
+ }
1849
+ } catch { /* no DOM: fall back to the id */ }
1850
+ const text = row !== null && typeof row.textContent === 'string' ? row.textContent.trim() : ''
1851
+ return text === '' ? null : text.slice(0, 60)
1852
+ }
1853
+
1854
+ /**
1855
+ * Read every selected session's plan, then show the checklist.
1856
+ *
1857
+ * The scan is read-only and per-session, so it runs concurrently with a small
1858
+ * pool: one long-lived conversation can name hundreds of paths, and a batch of
1859
+ * twenty would otherwise serialize twenty of those scans in front of the
1860
+ * dialog.
1861
+ */
1862
+ function startBatchScan() {
1863
+ const ids = [...state.selected]
1864
+ const scope = artifactScope()
1865
+ const skipGit = skipGitRepos()
1866
+ state.batchPlan = {
1867
+ scanning: true,
1868
+ scanned: 0,
1869
+ error: null,
1870
+ scope,
1871
+ skipGit,
1872
+ sessions: ids.map((id) => ({
1873
+ id,
1874
+ title: titleForSession(id),
1875
+ loading: true,
1876
+ error: null,
1877
+ plan: null,
1878
+ selected: new Set(),
1879
+ })),
1880
+ }
1881
+ publish()
1882
+
1883
+ let cursor = 0
1884
+ const worker = async () => {
1885
+ while (true) {
1886
+ const index = cursor
1887
+ cursor += 1
1888
+ const plan = state.batchPlan
1889
+ if (plan === null || index >= plan.sessions.length) return
1890
+ const entry = plan.sessions[index]
1891
+ try {
1892
+ const artifacts = await postArtifacts(entry.id)
1893
+ // The dialog may have been closed while this was in flight.
1894
+ const current = state.batchPlan
1895
+ if (current === null) return
1896
+ entry.plan = artifacts
1897
+ entry.selected = new Set(candidatePaths(artifacts, scope))
1898
+ } catch (reason) {
1899
+ const current = state.batchPlan
1900
+ if (current === null) return
1901
+ entry.error = String((reason && reason.message) || reason)
1902
+ }
1903
+ entry.loading = false
1904
+ if (state.batchPlan !== null) state.batchPlan.scanned += 1
1905
+ publish()
1906
+ }
1907
+ }
1908
+ const workers = []
1909
+ for (let i = 0; i < Math.min(SCAN_CONCURRENCY, ids.length); i += 1) workers.push(worker())
1910
+ Promise.all(workers).then(() => {
1911
+ if (state.batchPlan !== null) {
1912
+ state.batchPlan.scanning = false
1913
+ publish()
1914
+ }
1915
+ })
1916
+ }
1917
+
1918
+ function closeBatchPlan() {
1919
+ if (state.batchPlan === null) return
1920
+ state.batchPlan = null
1921
+ publish()
1922
+ }
1923
+
1924
+ /** Files offered across the whole checklist. */
1925
+ function batchPlanFiles(plan) {
1926
+ const rows = []
1927
+ for (const session of plan.sessions) {
1928
+ if (session.plan === null) continue
1929
+ for (const row of batchRows(session.plan, plan.scope)) rows.push({ session, row })
1930
+ }
1931
+ return rows
1932
+ }
1933
+
1934
+ /** The rows one session offers at the current scope. */
1935
+ function batchRows(plan, scope) {
1936
+ if (plan === null || plan === undefined) return []
1937
+ return scope === 'all' ? [...plan.created, ...plan.modified] : [...plan.created]
1938
+ }
1939
+
1940
+ function toggleBatchSession(session) {
1941
+ const rows = batchRows(session.plan, state.batchPlan === null ? 'created' : state.batchPlan.scope)
1942
+ const all = rows.every((row) => session.selected.has(row.path))
1943
+ for (const row of rows) {
1944
+ if (all) session.selected.delete(row.path)
1945
+ else session.selected.add(row.path)
1946
+ }
1947
+ publish()
1948
+ }
1949
+
1950
+ function toggleBatchAll() {
1951
+ const plan = state.batchPlan
1952
+ if (plan === null) return
1953
+ const files = batchPlanFiles(plan)
1954
+ const all = files.every(({ session, row }) => session.selected.has(row.path))
1955
+ for (const { session, row } of files) {
1956
+ if (all) session.selected.delete(row.path)
1957
+ else session.selected.add(row.path)
1958
+ }
1959
+ publish()
1960
+ }
1961
+
1962
+ /** Confirm the checklist: run the delete with each session's own file list. */
1963
+ function confirmBatchPlan() {
1964
+ const plan = state.batchPlan
1965
+ if (plan === null || plan.scanning) return
1966
+ const paths = {}
1967
+ for (const session of plan.sessions) {
1968
+ // A session whose scan failed carries no list, and an empty array means
1969
+ // "move nothing" - so it is left out entirely and its files stay put.
1970
+ if (session.error !== null) continue
1971
+ paths[session.id] = [...session.selected]
1972
+ }
1973
+ state.batchPlan = null
1974
+ publish()
1975
+ runBatchDelete(paths)
1976
+ }
1977
+
1978
+ function runBatchDelete(pathsById) {
1789
1979
  if (state.batch !== null) return
1790
1980
  const ids = [...state.selected]
1791
1981
  if (ids.length === 0) return
@@ -1796,11 +1986,23 @@ window.__ModuleLoader__.load({
1796
1986
 
1797
1987
  // The same switch the single path honours; without this every request went
1798
1988
  // out with no `quarantine` field and the files stayed where they were.
1799
- const quarantine = quarantinePlan()
1800
- // The feature is on but `auto` is off: the user expects files to be handled
1801
- // and a batch cannot show the per-file checklist. Say so afterwards rather
1802
- // than pretending the files were dealt with.
1803
- const askOnly = !artifactsOff() && !artifactsAuto()
1989
+ //
1990
+ // In asking mode the checklist already produced an explicit list per session
1991
+ // (issue #4): sending `{ scope }` there would move the whole derived set and
1992
+ // quietly ignore what the user ticked.
1993
+ const derived = quarantinePlan()
1994
+ const listed = pathsById !== undefined && pathsById !== null
1995
+ const scope = artifactScope()
1996
+ const skipGit = skipGitRepos()
1997
+ const quarantineFor = (id) => {
1998
+ if (!listed) return derived
1999
+ const paths = pathsById[id]
2000
+ if (!Array.isArray(paths)) return undefined
2001
+ return { scope, paths, skipGit }
2002
+ }
2003
+ // Asking mode with no checklist (the caller skipped it) still has to be
2004
+ // honest about the files it is not moving.
2005
+ const askOnly = !listed && !artifactsOff() && !artifactsAuto()
1804
2006
  let movedFiles = 0
1805
2007
  let failedFiles = 0
1806
2008
  const failedIds = []
@@ -1812,7 +2014,7 @@ window.__ModuleLoader__.load({
1812
2014
  if (index >= ids.length) return
1813
2015
  const id = ids[index]
1814
2016
  try {
1815
- const result = await postDelete(id, quarantine)
2017
+ const result = await postDelete(id, quarantineFor(id))
1816
2018
  const outcome = result && result.quarantine ? result.quarantine : null
1817
2019
  if (outcome !== null) {
1818
2020
  movedFiles += outcome.moved.length
@@ -2429,6 +2631,151 @@ window.__ModuleLoader__.load({
2429
2631
  return h('div', { key: 'artifacts', className: 'dsdel-artifacts' }, elements)
2430
2632
  }
2431
2633
 
2634
+ /**
2635
+ * The batch file checklist (issue #4).
2636
+ *
2637
+ * Asking mode gives the single delete a per-file list inside its confirmation
2638
+ * dialog. A batch has no such dialog, so the equivalent is one aggregated list
2639
+ * over every selected session, shown before anything is deleted. Sessions are
2640
+ * grouped so the user can tell whose files are whose, and a session with
2641
+ * nothing to move is listed rather than hidden - "this one has no produced
2642
+ * files" is information, not noise.
2643
+ */
2644
+ function BatchPlanDialog({ t: injected }) {
2645
+ const translate = localizedTranslator(injected)
2646
+ const view = useSnapshot()
2647
+ const plan = view.batchPlan
2648
+ if (plan === null) return null
2649
+
2650
+ const files = batchPlanFiles(plan)
2651
+ const picked = files.filter(({ session, row }) => session.selected.has(row.path)).length
2652
+ const children = []
2653
+
2654
+ if (plan.error !== null) {
2655
+ children.push(h('p', { key: 'error', className: 'dsdel-modal-error', role: 'alert' }, plan.error))
2656
+ }
2657
+
2658
+ // The overall progress line. Scanning every session is a real wait on a
2659
+ // long selection, and a dialog that appears frozen reads as a hang.
2660
+ if (plan.scanning) {
2661
+ children.push(h('p', { key: 'scanning', className: 'dsdel-modal-meta' },
2662
+ translate('batchPlanScanning', plan.scanned, plan.sessions.length)))
2663
+ } else {
2664
+ children.push(h('p', { key: 'summary', className: 'dsdel-modal-meta' },
2665
+ translate('batchPlanSummary', plan.sessions.length, files.length)))
2666
+ }
2667
+
2668
+ // One line for the whole list: ticking them one by one across twenty
2669
+ // sessions is the thing that made the single dialog worth having.
2670
+ if (files.length > 0) {
2671
+ children.push(h('div', { key: 'all', className: 'dsdel-file-row' },
2672
+ h('label', { key: 'label', className: 'dsdel-file-label' },
2673
+ h('input', {
2674
+ type: 'checkbox',
2675
+ className: 'dsdel-batch-all',
2676
+ checked: picked === files.length,
2677
+ onChange: () => toggleBatchAll(),
2678
+ }),
2679
+ h('span', { key: 'text', className: 'dsdel-file-path' },
2680
+ translate('batchPlanAll', picked, files.length)),
2681
+ ),
2682
+ ))
2683
+ }
2684
+
2685
+ for (const session of plan.sessions) {
2686
+ const rows = batchRows(session.plan, plan.scope)
2687
+ const label = session.title === null || session.title === undefined
2688
+ ? session.id
2689
+ : `${session.title} · ${session.id}`
2690
+ children.push(h('p', {
2691
+ key: `head:${session.id}`,
2692
+ className: 'dsdel-modal-text',
2693
+ style: { marginTop: '10px', fontWeight: 600 },
2694
+ }, label))
2695
+
2696
+ if (session.loading) {
2697
+ children.push(h('p', { key: `load:${session.id}`, className: 'dsdel-modal-meta' },
2698
+ translate('artifactLoading')))
2699
+ continue
2700
+ }
2701
+ if (session.error !== null) {
2702
+ children.push(h('p', { key: `err:${session.id}`, className: 'dsdel-modal-error', role: 'alert' },
2703
+ translate('artifactFailed') + session.error))
2704
+ continue
2705
+ }
2706
+ if (rows.length === 0) {
2707
+ children.push(h('p', { key: `none:${session.id}`, className: 'dsdel-modal-meta' },
2708
+ translate('artifactNone')))
2709
+ continue
2710
+ }
2711
+
2712
+ const all = rows.every((row) => session.selected.has(row.path))
2713
+ children.push(h('div', { key: `all:${session.id}`, className: 'dsdel-file-row' },
2714
+ h('label', { key: 'label', className: 'dsdel-file-label' },
2715
+ h('input', {
2716
+ type: 'checkbox',
2717
+ checked: all,
2718
+ onChange: () => toggleBatchSession(session),
2719
+ }),
2720
+ h('span', { key: 'text', className: 'dsdel-file-path' },
2721
+ translate('batchPlanSession', session.selected.size, rows.length)),
2722
+ ),
2723
+ ))
2724
+ for (const row of rows.slice(0, ARTIFACT_ROWS_SHOWN)) {
2725
+ children.push(h('div', {
2726
+ key: `row:${session.id}:${row.path}`,
2727
+ 'data-file-row': row.path,
2728
+ className: 'dsdel-file-row dsdel-batch-row',
2729
+ },
2730
+ h('label', { key: 'label', className: 'dsdel-file-label' },
2731
+ h('input', {
2732
+ type: 'checkbox',
2733
+ checked: session.selected.has(row.path),
2734
+ onChange: (e) => {
2735
+ if (e && e.target && e.target.checked) session.selected.add(row.path)
2736
+ else session.selected.delete(row.path)
2737
+ publish()
2738
+ },
2739
+ }),
2740
+ h('span', { key: 'path', className: 'dsdel-file-path' }, row.displayPath || row.path),
2741
+ ),
2742
+ ))
2743
+ }
2744
+ if (rows.length > ARTIFACT_ROWS_SHOWN) {
2745
+ children.push(h('p', { key: `more:${session.id}`, className: 'dsdel-modal-meta' },
2746
+ translate('artifactMore', rows.length - ARTIFACT_ROWS_SHOWN)))
2747
+ }
2748
+ if (session.plan.refused !== undefined && session.plan.refused.length > 0) {
2749
+ children.push(h('p', { key: `ref:${session.id}`, className: 'dsdel-modal-meta' },
2750
+ translate('artifactRefused', session.plan.refused.length)))
2751
+ }
2752
+ }
2753
+
2754
+ return h(primitives.Modal, {
2755
+ open: true,
2756
+ onClose: () => closeBatchPlan(),
2757
+ closeLabel: translate('cancel'),
2758
+ title: translate('batchPlanTitle'),
2759
+ footer: [
2760
+ h(primitives.Button, {
2761
+ key: 'cancel',
2762
+ variant: 'outline',
2763
+ onClick: () => closeBatchPlan(),
2764
+ children: translate('cancel'),
2765
+ }),
2766
+ h(primitives.Button, {
2767
+ key: 'confirm',
2768
+ variant: 'outline',
2769
+ className: 'dsdel-danger-btn',
2770
+ disabled: plan.scanning,
2771
+ onClick: () => confirmBatchPlan(),
2772
+ children: translate('confirm'),
2773
+ }),
2774
+ ],
2775
+ children,
2776
+ })
2777
+ }
2778
+
2432
2779
  /** Folder picker overlay: walk directories, then commit one. */
2433
2780
  function QuarantinePicker({ t: injected }) {
2434
2781
  const translate = localizedTranslator(injected)
@@ -2939,6 +3286,12 @@ window.__ModuleLoader__.load({
2939
3286
  { name: 'shell.overlay', id: `${NS}-picker`, order: 1, locale: NS },
2940
3287
  QuarantinePicker,
2941
3288
  ))
3289
+ // The batch file checklist: the aggregated list asking mode shows before
3290
+ // it deletes several sessions (issue #4).
3291
+ slots.inject('shell.overlay', () => slots.register(
3292
+ { name: 'shell.overlay', id: `${NS}-batchplan`, order: 2, locale: NS },
3293
+ BatchPlanDialog,
3294
+ ))
2942
3295
  // The plugin page card, on BOTH seats the manager offers.
2943
3296
  //
2944
3297
  // `plugins.bundle.config` renders on the package page, whose address is
@@ -549,6 +549,51 @@ function mountRow(harness, session = SESSION_A, parent = null) {
549
549
  const menuEntry = (harness, id) =>
550
550
  harness.slotRegistrations.find((entry) => entry.spec.name === MENU_SLOT && entry.spec.id === id) ?? null
551
551
 
552
+ /** The batch checklist overlay, rendered the way the host renders it. */
553
+ const batchPlanEntry = (harness) =>
554
+ harness.slotRegistrations.find((entry) => entry.spec.name === 'shell.overlay'
555
+ && entry.spec.id === NS + '-batchplan') ?? null
556
+
557
+ const batchPlan = (harness) => {
558
+ const entry = batchPlanEntry(harness)
559
+ if (entry === null) return null
560
+ return entry.Component({ t: harness.t })
561
+ }
562
+
563
+ const childList = (node) => {
564
+ if (node === null || node === undefined || node.props === undefined) return []
565
+ const children = node.props.children
566
+ if (children === null || children === undefined) return []
567
+ return Array.isArray(children) ? children.filter(Boolean) : [children]
568
+ }
569
+
570
+ /** Every file row the checklist renders, as `{ path, input }`. */
571
+ function batchFileRows(harness) {
572
+ const modal = batchPlan(harness)
573
+ if (modal === null) return []
574
+ const rows = []
575
+ for (const node of childList(modal)) {
576
+ if (node.props === undefined || node.props['data-file-row'] === undefined) continue
577
+ const label = childList(node).find((child) => child.type === 'label')
578
+ const input = label === undefined
579
+ ? null
580
+ : childList(label).find((child) => child.props && child.props.type === 'checkbox')
581
+ rows.push({ path: node.props['data-file-row'], input: input ?? null })
582
+ }
583
+ return rows
584
+ }
585
+
586
+ /** Invoke one footer button of the checklist. */
587
+ function clickBatchPlan(harness, key) {
588
+ const modal = batchPlan(harness)
589
+ if (modal === null) return false
590
+ const footer = (modal.props.footer ?? []).filter(Boolean)
591
+ const button = footer.find((node) => node.props && node.props.key === key)
592
+ if (button === undefined) return false
593
+ button.props.onClick()
594
+ return true
595
+ }
596
+
552
597
  const overlayEntry = (harness) =>
553
598
  harness.slotRegistrations.find((entry) => entry.spec.name === 'shell.overlay') ?? null
554
599
 
@@ -3875,7 +3920,46 @@ test('multi-select delete leaves the files alone when the switch is off', async
3875
3920
  assert.equal('quarantine' in bodies[0], false, 'and does not move any file')
3876
3921
  })
3877
3922
 
3878
- test('a batch in asking mode says the files were left alone', async () => {
3923
+ test('a batch in asking mode opens a checklist instead of deleting straight away', async () => {
3924
+ const harness = await loadPlugin()
3925
+ localStorage.setItem(OFF_KEY, '0')
3926
+ localStorage.setItem(AUTO_KEY, '0')
3927
+ const first = mountRow(harness, SESSION_A)
3928
+ await enterMulti(harness)
3929
+ clickRowIn(harness, first)
3930
+ await flush()
3931
+
3932
+ clickBar(barDelete(harness))
3933
+ await settle()
3934
+
3935
+ // Issue #4: asking mode must show a list. It used to delete first and only say
3936
+ // afterwards that the files had been left alone.
3937
+ assert.equal(deleteCalls(harness), 0, 'nothing deleted before the user confirmed')
3938
+ assert.ok(batchPlan(harness) !== null, 'the checklist opened')
3939
+ })
3940
+
3941
+ test('the batch checklist lists every selected session and its files', async () => {
3942
+ const harness = await loadPlugin({ plan: PLAN })
3943
+ localStorage.setItem(OFF_KEY, '0')
3944
+ localStorage.setItem(AUTO_KEY, '0')
3945
+ const first = mountRow(harness, SESSION_A)
3946
+ const second = mountRow(harness, SESSION_B)
3947
+ await enterMulti(harness)
3948
+ clickRowIn(harness, first)
3949
+ clickRowIn(harness, second)
3950
+ await flush()
3951
+
3952
+ clickBar(barDelete(harness))
3953
+ await settle()
3954
+
3955
+ // The checklist covers the whole selection, not just whichever session happened
3956
+ // to be first: the stub answers every scan with the same PLAN, so two sessions
3957
+ // with two created files each make four rows.
3958
+ const rows = batchFileRows(harness)
3959
+ assert.equal(rows.length, 4, 'two sessions, two files each, saw ' + rows.length)
3960
+ })
3961
+
3962
+ test('confirming the checklist sends each session its own file list', async () => {
3879
3963
  const harness = await loadPlugin()
3880
3964
  localStorage.setItem(OFF_KEY, '0')
3881
3965
  localStorage.setItem(AUTO_KEY, '0')
@@ -3883,14 +3967,100 @@ test('a batch in asking mode says the files were left alone', async () => {
3883
3967
  await enterMulti(harness)
3884
3968
  clickRowIn(harness, first)
3885
3969
  await flush()
3970
+ clickBar(barDelete(harness))
3971
+ await settle()
3886
3972
 
3973
+ assert.equal(clickBatchPlan(harness, 'confirm'), true, 'the checklist has a confirm')
3974
+ await settle()
3975
+ for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
3976
+
3977
+ // `paths` is the whole point: the host intersects it with its own derived set,
3978
+ // so sending it can only narrow the move, never widen it.
3979
+ const body = deleteBody(harness)
3980
+ assert.ok(body, 'a delete went out')
3981
+ assert.ok(body.quarantine, 'the delete carries a quarantine plan')
3982
+ assert.ok(Array.isArray(body.quarantine.paths), 'and an explicit file list')
3983
+ })
3984
+
3985
+ test('unticking a file keeps it out of the request', async () => {
3986
+ const harness = await loadPlugin({ plan: PLAN })
3987
+ localStorage.setItem(OFF_KEY, '0')
3988
+ localStorage.setItem(AUTO_KEY, '0')
3989
+ const first = mountRow(harness, SESSION_A)
3990
+ await enterMulti(harness)
3991
+ clickRowIn(harness, first)
3992
+ await flush()
3993
+ clickBar(barDelete(harness))
3994
+ await settle()
3995
+
3996
+ const rows = batchFileRows(harness)
3997
+ assert.ok(rows.length >= 1, 'the fixture has at least one file')
3998
+ // Untick through the input the user would click, not through store internals.
3999
+ rows[0].input.props.onChange({ target: { checked: false } })
4000
+ await flush()
4001
+
4002
+ // The box itself has to show the new state: a checkbox that stays ticked while
4003
+ // the file is no longer in the request is a lie about what will happen.
4004
+ const after = batchFileRows(harness)
4005
+ assert.equal(after[0].input.props.checked, false, 'the unticked row renders unticked')
4006
+
4007
+ assert.equal(clickBatchPlan(harness, 'confirm'), true)
4008
+ await settle()
4009
+ for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
4010
+
4011
+ const body = deleteBody(harness)
4012
+ assert.equal(body.quarantine.paths.includes(rows[0].path), false, 'the unticked file stays put')
4013
+ })
4014
+
4015
+ test('cancelling the checklist deletes nothing', async () => {
4016
+ const harness = await loadPlugin()
4017
+ localStorage.setItem(OFF_KEY, '0')
4018
+ localStorage.setItem(AUTO_KEY, '0')
4019
+ const first = mountRow(harness, SESSION_A)
4020
+ await enterMulti(harness)
4021
+ clickRowIn(harness, first)
4022
+ await flush()
4023
+ clickBar(barDelete(harness))
4024
+ await settle()
4025
+
4026
+ assert.equal(clickBatchPlan(harness, 'cancel'), true, 'the checklist has a cancel')
4027
+ await flush()
4028
+
4029
+ assert.equal(deleteCalls(harness), 0, 'no delete went out')
4030
+ assert.equal(batchPlan(harness), null, 'and the dialog closed')
4031
+ })
4032
+
4033
+ test('auto mode still deletes straight through, with no checklist', async () => {
4034
+ const harness = await loadPlugin()
4035
+ localStorage.setItem(OFF_KEY, '0')
4036
+ localStorage.setItem(AUTO_KEY, '1')
4037
+ localStorage.setItem(SKIP_KEY, '1')
4038
+ const first = mountRow(harness, SESSION_A)
4039
+ await enterMulti(harness)
4040
+ clickRowIn(harness, first)
4041
+ await flush()
4042
+ clickBar(barDelete(harness))
4043
+ await settle()
4044
+ for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
4045
+
4046
+ assert.equal(batchPlan(harness), null, 'no checklist in auto mode')
4047
+ assert.equal(deleteCalls(harness), 1, 'the delete ran')
4048
+ assert.deepEqual(deleteBody(harness).quarantine, { scope: 'created' }, 'the derived set, not a list')
4049
+ })
4050
+
4051
+ test('the feature off deletes straight through too', async () => {
4052
+ const harness = await loadPlugin()
4053
+ localStorage.setItem(OFF_KEY, '1')
4054
+ localStorage.setItem(SKIP_KEY, '1')
4055
+ const first = mountRow(harness, SESSION_A)
4056
+ await enterMulti(harness)
4057
+ clickRowIn(harness, first)
4058
+ await flush()
3887
4059
  clickBar(barDelete(harness))
3888
4060
  await settle()
3889
4061
  for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
3890
4062
 
3891
- // Asking means a per-file checklist, which a batch has nowhere to show. Silence
3892
- // would look like the files had been handled.
3893
- const said = toasts(harness).join(' | ')
3894
- assert.equal(said.includes('产出文件没有处理'), true, 'the user is told: ' + said)
3895
- assert.equal('quarantine' in deleteBody(harness), false, 'and nothing was moved')
4063
+ assert.equal(batchPlan(harness), null, 'the dialog never opened')
4064
+ assert.equal(deleteCalls(harness), 1, 'the delete ran')
4065
+ assert.equal('quarantine' in deleteBody(harness), false, 'and touched no file')
3896
4066
  })