dsh-delete-session 0.3.3 → 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 +14 -0
- package/package.json +1 -1
- package/src/client.js +415 -10
- package/test/checkbox.dom.test.js +244 -8
package/README.md
CHANGED
|
@@ -162,6 +162,20 @@ 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
|
+
- **两个模式不变**:功能关闭、或设成「全部自动进隔离夹」时仍然直接删,跟以前一样。
|
|
172
|
+
**(v0.4.0)** —— 「删完开一个新会话」变成可选,默认开,并改走宿主的 `startSession()`。
|
|
173
|
+
|
|
174
|
+
- **为什么会新建**:删掉当前打开的会话,主视图会停在一个已经不存在的会话上(合成器禁用,看着像删除失败)。v0.1.7 起,插件为此**去点侧栏的「新建会话」按钮** —— 那是用户入口,任何拦截新建的插件(命名、模板选择、预设工作区)都会被误伤。
|
|
175
|
+
- **改走宿主方法**:模拟点击靠猜 DOM(`button[class*="newSession"]`、`aria-label` 中英文各列一遍),宿主一改样式就静默失效。现在调 `uiWorkspace.startSession()`,语义明确、不依赖 UI 形状。
|
|
176
|
+
- **变成可选**:插件页多一个「删完打开一个新会话」,**默认勾选**。勾着 → 删完开一个新的(`startSession()`);取消 → 主视图留空(`clearMain()`)。两种都走宿主自己的方法,谁也不猜按钮。
|
|
177
|
+
- **旧宿主兜底不变**:两个方法都拿不到时,才退回原来的按钮点击 + 重置指针 + reload,视图不会停在已删的会话上。
|
|
178
|
+
- **关于第三方插件**:勾选时 `startSession()` 仍会经过 dsh-session-namer 之类的包装 —— 那是**预期行为**,用户就是要新建,问名字是对的。不想看到就取消勾选([#5](https://github.com/DDDMUC/dsh-delete-session/issues/5))。
|
|
165
179
|
**(v0.3.3)** —— 删除当前会话不再顺手新建一个会话。
|
|
166
180
|
|
|
167
181
|
- **问题**:删掉正在看的那个会话之后,`leaveIfCurrent()` 会去侧边栏点「新建会话」按钮,好让主视图别停在那个禁用的合成器上。可那个按钮是**用户**新建会话的入口,凡是拦截「新建会话」的插件(命名弹窗、模板选择、预设工作区)都会跟着触发 —— 结果是「删了一个会话」被做成了「新建一个会话」([#5](https://github.com/DDDMUC/dsh-delete-session/issues/5))。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-delete-session",
|
|
3
|
-
"version": "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: '删除时询问',
|
|
@@ -73,6 +79,9 @@ window.__ModuleLoader__.load({
|
|
|
73
79
|
starCta: '行,给你一颗 Star',
|
|
74
80
|
pageSyncChildrenOn: '删除对话时,把它派生的子代理会话一起删掉。',
|
|
75
81
|
pageSyncChildrenOff: '不勾选时,删除前会列出子会话,由你勾选要删哪些。',
|
|
82
|
+
pageReplaceCurrent: '删完打开一个新会话',
|
|
83
|
+
pageReplaceCurrentOn: '删掉的如果正是当前打开的那个,顺手开一个新的,主视图不会空着。',
|
|
84
|
+
pageReplaceCurrentOff: '删掉的如果正是当前打开的那个,主视图留空,什么都不新建。',
|
|
76
85
|
childrenHint: '这个对话有 {n} 个子会话(子代理),勾选的会一起删除。',
|
|
77
86
|
pageRecycleOn: '删除后放进系统回收站,可以还原。',
|
|
78
87
|
pageRecycleOff: '删除后直接从硬盘移除,不可恢复。',
|
|
@@ -170,6 +179,12 @@ window.__ModuleLoader__.load({
|
|
|
170
179
|
batchPartial: (ok, fail) => `Deleted ${ok}, ${fail} failed`,
|
|
171
180
|
batchDoneQuarantine: (n, m) => `Deleted ${n} session(s), ${m} file(s) moved to quarantine`,
|
|
172
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.',
|
|
173
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".',
|
|
174
189
|
batchFailed: 'Batch delete failed: ',
|
|
175
190
|
pageAsk: 'Ask before deleting',
|
|
@@ -182,6 +197,9 @@ window.__ModuleLoader__.load({
|
|
|
182
197
|
starCta: 'Fine — have one',
|
|
183
198
|
pageSyncChildrenOn: 'A delete also removes the subagent sessions it spawned.',
|
|
184
199
|
pageSyncChildrenOff: 'When off, the dialog lists the child sessions and you tick the ones to delete.',
|
|
200
|
+
pageReplaceCurrent: 'Open a new conversation after deleting',
|
|
201
|
+
pageReplaceCurrentOn: 'If the conversation you are viewing is the one deleted, a fresh one opens instead of leaving the view blank.',
|
|
202
|
+
pageReplaceCurrentOff: 'If the conversation you are viewing is the one deleted, the view stays blank and nothing is created.',
|
|
185
203
|
childrenHint: 'This conversation has {n} child sessions (subagents). Ticked ones are deleted too.',
|
|
186
204
|
pageRecycleOn: 'The session goes to the system trash and can be restored.',
|
|
187
205
|
pageRecycleOff: 'The session is removed from the disk right away and cannot be restored.',
|
|
@@ -276,6 +294,12 @@ window.__ModuleLoader__.load({
|
|
|
276
294
|
batchPartial: (ok, fail) => `Удалено ${ok}, не удалось ${fail}`,
|
|
277
295
|
batchDoneQuarantine: (n, m) => `Удалено сессий: ${n}, файлов в карантине: ${m}`,
|
|
278
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: 'Ни одна из этих сессий не создавала файлов; удаление очистит только журналы диалогов.',
|
|
279
303
|
batchAskArtifacts: 'Файлы этих сессий не обработаны: пакетное удаление не показывает список файлов. Удаляйте по одному или переключите страницу плагина на «все созданные файлы в карантин». ',
|
|
280
304
|
batchFailed: 'Массовое удаление не удалось: ',
|
|
281
305
|
pageAsk: 'Спрашивать перед удалением',
|
|
@@ -288,6 +312,9 @@ window.__ModuleLoader__.load({
|
|
|
288
312
|
starCta: 'Ладно, держи звезду',
|
|
289
313
|
pageSyncChildrenOn: 'Удаление сессии удаляет и порождённые ею сессии субагентов.',
|
|
290
314
|
pageSyncChildrenOff: 'Если выключено, перед удалением появится список дочерних сессий и вы отметите, какие удалить.',
|
|
315
|
+
pageReplaceCurrent: 'Открывать новый диалог после удаления',
|
|
316
|
+
pageReplaceCurrentOn: 'Если удалён тот диалог, который открыт, вместо пустого экрана откроется новый.',
|
|
317
|
+
pageReplaceCurrentOff: 'Если удалён тот диалог, который открыт, экран останется пустым, ничего не создаётся.',
|
|
291
318
|
childrenHint: 'У этого диалога {n} дочерних сессий (субагентов). Отмеченные удалятся вместе с ним.',
|
|
292
319
|
pageRecycleOn: 'Сессия попадёт в системную корзину, её можно восстановить.',
|
|
293
320
|
pageRecycleOff: 'Сессия сразу удаляется с диска, восстановить её нельзя.',
|
|
@@ -518,6 +545,13 @@ window.__ModuleLoader__.load({
|
|
|
518
545
|
pending: new Set(),
|
|
519
546
|
/** { total, done, failed } while a batch delete runs, else null. */
|
|
520
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,
|
|
521
555
|
/** Folder-picker state while it is open, else null. */
|
|
522
556
|
picker: null,
|
|
523
557
|
/** The host's default quarantine root, fetched once so the card can name it. */
|
|
@@ -538,6 +572,7 @@ window.__ModuleLoader__.load({
|
|
|
538
572
|
selected: state.selected,
|
|
539
573
|
pending: state.pending,
|
|
540
574
|
batch: state.batch,
|
|
575
|
+
batchPlan: state.batchPlan,
|
|
541
576
|
picker: state.picker,
|
|
542
577
|
defaultRoot: state.defaultRoot,
|
|
543
578
|
drag: state.drag,
|
|
@@ -623,6 +658,8 @@ window.__ModuleLoader__.load({
|
|
|
623
658
|
const RECYCLE_KEY = 'dsh-delete-session:recycle'
|
|
624
659
|
/** Whether a delete takes the subagent sessions with it, without asking. */
|
|
625
660
|
const SYNC_CHILDREN_KEY = 'dsh-delete-session:sync-children'
|
|
661
|
+
/** Whether deleting the open conversation opens a fresh one afterwards. */
|
|
662
|
+
const REPLACE_KEY = 'dsh-delete-session:replace-current'
|
|
626
663
|
/** How many artifact rows the dialog lists before collapsing the rest. */
|
|
627
664
|
const ARTIFACT_ROWS_SHOWN = 40
|
|
628
665
|
const prefListeners = new Set()
|
|
@@ -728,6 +765,23 @@ window.__ModuleLoader__.load({
|
|
|
728
765
|
return readPref(SYNC_CHILDREN_KEY, '1') !== '0'
|
|
729
766
|
}
|
|
730
767
|
|
|
768
|
+
/**
|
|
769
|
+
* Whether a delete of the OPEN conversation is followed by a new one.
|
|
770
|
+
*
|
|
771
|
+
* On by default: a DSH sitting on a deleted conversation is a dead end, and
|
|
772
|
+
* most people would rather keep working than stare at an empty screen. It is
|
|
773
|
+
* a choice, though - "leave me on a blank view" has to be reachable.
|
|
774
|
+
*/
|
|
775
|
+
function replaceCurrent() {
|
|
776
|
+
return readPref(REPLACE_KEY, '1') !== '0'
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
function setReplaceCurrent(on) {
|
|
780
|
+
// Written as '0' rather than cleared, like the child-session switch: the
|
|
781
|
+
// default is on, so a removed key would read back as on again.
|
|
782
|
+
writePref(REPLACE_KEY, on ? '1' : '0')
|
|
783
|
+
}
|
|
784
|
+
|
|
731
785
|
function setSyncChildren(on) {
|
|
732
786
|
// "Off" is written as '0' rather than cleared: the default is now on, so a
|
|
733
787
|
// removed key would read back as on again.
|
|
@@ -962,8 +1016,18 @@ window.__ModuleLoader__.load({
|
|
|
962
1016
|
}
|
|
963
1017
|
if (!current || !deletedVariants(id).includes(current)) return
|
|
964
1018
|
|
|
965
|
-
// Preferred: tell the host, which owns the pointer and the retain.
|
|
966
1019
|
const api = navigationApi()
|
|
1020
|
+
|
|
1021
|
+
// The switch is a real choice: open a fresh conversation, or leave the view
|
|
1022
|
+
// blank. Both go through the host - neither guesses at a button.
|
|
1023
|
+
if (replaceCurrent() && api !== null && typeof api.startSession === 'function') {
|
|
1024
|
+
try {
|
|
1025
|
+
api.startSession()
|
|
1026
|
+
return
|
|
1027
|
+
} catch { /* older build: fall through to clearing */ }
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// Tell the host, which owns the pointer and the retain.
|
|
967
1031
|
if (api !== null && typeof api.clearMain === 'function') {
|
|
968
1032
|
try {
|
|
969
1033
|
api.clearMain()
|
|
@@ -1090,6 +1154,7 @@ window.__ModuleLoader__.load({
|
|
|
1090
1154
|
'.dsdel-dialog-wide > :first-child{flex:1 1 auto;min-height:0;overflow:auto}',
|
|
1091
1155
|
'.dsdel-dialog-wide > :last-child{flex:0 0 auto;margin-top:auto}',
|
|
1092
1156
|
'.dsdel-artifacts{overflow:auto;overscroll-behavior:contain;padding-right:2px}',
|
|
1157
|
+
'.dsdel-batch-row{padding-left:22px}',
|
|
1093
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}',
|
|
1094
1159
|
'.dsdel-picker-list{display:flex;flex-direction:column;gap:2px;max-height:280px;overflow:auto;margin:0 0 8px}',
|
|
1095
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}',
|
|
@@ -1633,7 +1698,7 @@ window.__ModuleLoader__.load({
|
|
|
1633
1698
|
disabled: busy || empty,
|
|
1634
1699
|
onClick: (event) => {
|
|
1635
1700
|
if (event && event.stopPropagation) event.stopPropagation()
|
|
1636
|
-
|
|
1701
|
+
beginBatchDelete()
|
|
1637
1702
|
},
|
|
1638
1703
|
}, translate('deleteSelected')),
|
|
1639
1704
|
)
|
|
@@ -1712,6 +1777,7 @@ window.__ModuleLoader__.load({
|
|
|
1712
1777
|
state.selecting = false
|
|
1713
1778
|
state.selected.clear()
|
|
1714
1779
|
state.batch = null
|
|
1780
|
+
state.batchPlan = null
|
|
1715
1781
|
const keepPending = !!(options && options.keepPending)
|
|
1716
1782
|
if (!keepPending) {
|
|
1717
1783
|
state.pending.clear()
|
|
@@ -1747,7 +1813,169 @@ window.__ModuleLoader__.load({
|
|
|
1747
1813
|
// (I/O 并行度约在 8 饱和),6 路比 4 路快约 1/3 且仍在饱和点以下。
|
|
1748
1814
|
const BATCH_CONCURRENCY = 6
|
|
1749
1815
|
|
|
1750
|
-
|
|
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) {
|
|
1751
1979
|
if (state.batch !== null) return
|
|
1752
1980
|
const ids = [...state.selected]
|
|
1753
1981
|
if (ids.length === 0) return
|
|
@@ -1758,11 +1986,23 @@ window.__ModuleLoader__.load({
|
|
|
1758
1986
|
|
|
1759
1987
|
// The same switch the single path honours; without this every request went
|
|
1760
1988
|
// out with no `quarantine` field and the files stayed where they were.
|
|
1761
|
-
|
|
1762
|
-
//
|
|
1763
|
-
//
|
|
1764
|
-
//
|
|
1765
|
-
const
|
|
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()
|
|
1766
2006
|
let movedFiles = 0
|
|
1767
2007
|
let failedFiles = 0
|
|
1768
2008
|
const failedIds = []
|
|
@@ -1774,7 +2014,7 @@ window.__ModuleLoader__.load({
|
|
|
1774
2014
|
if (index >= ids.length) return
|
|
1775
2015
|
const id = ids[index]
|
|
1776
2016
|
try {
|
|
1777
|
-
const result = await postDelete(id,
|
|
2017
|
+
const result = await postDelete(id, quarantineFor(id))
|
|
1778
2018
|
const outcome = result && result.quarantine ? result.quarantine : null
|
|
1779
2019
|
if (outcome !== null) {
|
|
1780
2020
|
movedFiles += outcome.moved.length
|
|
@@ -2391,6 +2631,151 @@ window.__ModuleLoader__.load({
|
|
|
2391
2631
|
return h('div', { key: 'artifacts', className: 'dsdel-artifacts' }, elements)
|
|
2392
2632
|
}
|
|
2393
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
|
+
|
|
2394
2779
|
/** Folder picker overlay: walk directories, then commit one. */
|
|
2395
2780
|
function QuarantinePicker({ t: injected }) {
|
|
2396
2781
|
const translate = localizedTranslator(injected)
|
|
@@ -2559,6 +2944,7 @@ window.__ModuleLoader__.load({
|
|
|
2559
2944
|
const [ask, setAsk] = react.useState(!skipConfirm())
|
|
2560
2945
|
const [recycle, setRecycle] = react.useState(recycleSession())
|
|
2561
2946
|
const [syncChildrenState, setSyncChildrenState] = react.useState(syncChildren())
|
|
2947
|
+
const [replaceState, setReplaceState] = react.useState(replaceCurrent())
|
|
2562
2948
|
const [off, setOff] = react.useState(artifactsOff())
|
|
2563
2949
|
const [auto, setAuto] = react.useState(artifactsAuto())
|
|
2564
2950
|
const [scope, setScope] = react.useState(artifactScope())
|
|
@@ -2567,6 +2953,7 @@ window.__ModuleLoader__.load({
|
|
|
2567
2953
|
react.useEffect(() => subscribeSkip(() => setAsk(!skipConfirm())), [])
|
|
2568
2954
|
react.useEffect(() => { loadDefaultRoot() }, [])
|
|
2569
2955
|
react.useEffect(() => subscribePrefs(() => {
|
|
2956
|
+
setReplaceState(replaceCurrent())
|
|
2570
2957
|
setOff(artifactsOff())
|
|
2571
2958
|
setAuto(artifactsAuto())
|
|
2572
2959
|
setScope(artifactScope())
|
|
@@ -2617,6 +3004,18 @@ window.__ModuleLoader__.load({
|
|
|
2617
3004
|
h('p', { key: 'syncChildrenHint', className: 'dsdel-page-hint' },
|
|
2618
3005
|
translate(syncChildrenState ? 'pageSyncChildrenOn' : 'pageSyncChildrenOff')),
|
|
2619
3006
|
|
|
3007
|
+
h(primitives.Checkbox, {
|
|
3008
|
+
key: 'replaceCurrent',
|
|
3009
|
+
checked: replaceState,
|
|
3010
|
+
label: translate('pageReplaceCurrent'),
|
|
3011
|
+
onChange: (checked) => {
|
|
3012
|
+
setReplaceState(checked === true)
|
|
3013
|
+
setReplaceCurrent(checked === true)
|
|
3014
|
+
},
|
|
3015
|
+
}),
|
|
3016
|
+
h('p', { key: 'replaceCurrentHint', className: 'dsdel-page-hint' },
|
|
3017
|
+
translate(replaceState ? 'pageReplaceCurrentOn' : 'pageReplaceCurrentOff')),
|
|
3018
|
+
|
|
2620
3019
|
h(primitives.Checkbox, {
|
|
2621
3020
|
key: 'off',
|
|
2622
3021
|
checked: off,
|
|
@@ -2760,7 +3159,7 @@ window.__ModuleLoader__.load({
|
|
|
2760
3159
|
// Each control owns the nodes that explain it. Grouping them here keeps the
|
|
2761
3160
|
// markup above flat (a switch and its hint are still two pushes) while the
|
|
2762
3161
|
// page draws them as one block.
|
|
2763
|
-
const FIELD_KEYS = new Set(['ask', 'recycle', 'syncChildren', 'off', 'auto', 'scope', 'skipGit', 'root'])
|
|
3162
|
+
const FIELD_KEYS = new Set(['ask', 'recycle', 'syncChildren', 'replaceCurrent', 'off', 'auto', 'scope', 'skipGit', 'root'])
|
|
2764
3163
|
function groupFields(nodes) {
|
|
2765
3164
|
const groups = []
|
|
2766
3165
|
let current = null
|
|
@@ -2887,6 +3286,12 @@ window.__ModuleLoader__.load({
|
|
|
2887
3286
|
{ name: 'shell.overlay', id: `${NS}-picker`, order: 1, locale: NS },
|
|
2888
3287
|
QuarantinePicker,
|
|
2889
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
|
+
))
|
|
2890
3295
|
// The plugin page card, on BOTH seats the manager offers.
|
|
2891
3296
|
//
|
|
2892
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
|
|
|
@@ -963,6 +1008,72 @@ test('with no navigation service the sidebar button is the last resort', async (
|
|
|
963
1008
|
|
|
964
1009
|
assert.equal(clicked, 1, 'the fallback still runs without the service')
|
|
965
1010
|
})
|
|
1011
|
+
test('by default a delete of the open conversation opens a fresh one', async () => {
|
|
1012
|
+
const calls = []
|
|
1013
|
+
const harness = await loadPlugin({
|
|
1014
|
+
navigation: {
|
|
1015
|
+
startSession: () => { calls.push('startSession') },
|
|
1016
|
+
clearMain: () => { calls.push('clearMain') },
|
|
1017
|
+
},
|
|
1018
|
+
})
|
|
1019
|
+
mountRow(harness, SESSION_A)
|
|
1020
|
+
localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
|
|
1021
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
1022
|
+
|
|
1023
|
+
const { element } = deleteRow(harness)
|
|
1024
|
+
element.props.onSelect({ shiftKey: false })
|
|
1025
|
+
await tick()
|
|
1026
|
+
await flush()
|
|
1027
|
+
|
|
1028
|
+
assert.deepEqual(calls, ['startSession'], 'one fresh conversation, nothing cleared')
|
|
1029
|
+
})
|
|
1030
|
+
|
|
1031
|
+
test('turning the switch off leaves the view blank instead', async () => {
|
|
1032
|
+
const calls = []
|
|
1033
|
+
const harness = await loadPlugin({
|
|
1034
|
+
navigation: {
|
|
1035
|
+
startSession: () => { calls.push('startSession') },
|
|
1036
|
+
clearMain: () => { calls.push('clearMain') },
|
|
1037
|
+
},
|
|
1038
|
+
})
|
|
1039
|
+
localStorage.setItem('dsh-delete-session:replace-current', '0')
|
|
1040
|
+
mountRow(harness, SESSION_A)
|
|
1041
|
+
localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
|
|
1042
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
1043
|
+
|
|
1044
|
+
const { element } = deleteRow(harness)
|
|
1045
|
+
element.props.onSelect({ shiftKey: false })
|
|
1046
|
+
await tick()
|
|
1047
|
+
await flush()
|
|
1048
|
+
|
|
1049
|
+
assert.deepEqual(calls, ['clearMain'], 'the switch is a real choice')
|
|
1050
|
+
})
|
|
1051
|
+
|
|
1052
|
+
test('a host without startSession still ends up with a blank view', async () => {
|
|
1053
|
+
const calls = []
|
|
1054
|
+
const harness = await loadPlugin({
|
|
1055
|
+
navigation: { clearMain: () => { calls.push('clearMain') } },
|
|
1056
|
+
})
|
|
1057
|
+
mountRow(harness, SESSION_A)
|
|
1058
|
+
localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
|
|
1059
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
1060
|
+
|
|
1061
|
+
const { element } = deleteRow(harness)
|
|
1062
|
+
element.props.onSelect({ shiftKey: false })
|
|
1063
|
+
await tick()
|
|
1064
|
+
await flush()
|
|
1065
|
+
|
|
1066
|
+
assert.deepEqual(calls, ['clearMain'], 'no fresh session available, so clear')
|
|
1067
|
+
})
|
|
1068
|
+
|
|
1069
|
+
test('the replace-current switch renders on the plugin page', async () => {
|
|
1070
|
+
const harness = await loadPlugin()
|
|
1071
|
+
const card = pageCard(harness)
|
|
1072
|
+
const fields = (card.props.children ?? []).filter((node) => node && node.props && node.props.className === 'dsdel-field')
|
|
1073
|
+
|
|
1074
|
+
// Five switches: ask / recycle / syncChildren / replaceCurrent / artifacts.
|
|
1075
|
+
assert.ok(fields.length >= 5, 'the new switch became its own block, saw ' + fields.length)
|
|
1076
|
+
})
|
|
966
1077
|
test('a single delete plants no checkbox on any row (the v0.1.8 regression)', async () => {
|
|
967
1078
|
const harness = await loadPlugin()
|
|
968
1079
|
mountRow(harness, SESSION_A)
|
|
@@ -1356,7 +1467,7 @@ test('the produced-files feature ships off: no scan, no section, no quarantine f
|
|
|
1356
1467
|
|
|
1357
1468
|
test('the page hides the artifact sub-controls while the master switch is on', async () => {
|
|
1358
1469
|
const harness = await loadPlugin()
|
|
1359
|
-
assert.equal(pageChecks(harness).length,
|
|
1470
|
+
assert.equal(pageChecks(harness).length, 5, 'ask, recycle, subagents, replace-current and the master switch render')
|
|
1360
1471
|
assert.equal(offCheckbox(harness).props.checked, true, 'the master switch starts ticked')
|
|
1361
1472
|
})
|
|
1362
1473
|
|
|
@@ -1365,7 +1476,7 @@ test('clearing the master switch reveals the auto and scope controls', async ()
|
|
|
1365
1476
|
offCheckbox(harness).props.onChange(false)
|
|
1366
1477
|
|
|
1367
1478
|
assert.equal(localStorage.getItem(OFF_KEY), '0', 'the opt-in was stored')
|
|
1368
|
-
assert.equal(pageChecks(harness).length,
|
|
1479
|
+
assert.equal(pageChecks(harness).length, 9, 'the sub-controls render once enabled')
|
|
1369
1480
|
assert.equal(autoCheckbox(harness).props.checked, false, 'asking is the default once enabled')
|
|
1370
1481
|
assert.equal(scopeCreatedCheckbox(harness).props.checked, true, 'created-only is the default scope')
|
|
1371
1482
|
assert.equal(scopeAllCheckbox(harness).props.checked, false)
|
|
@@ -3809,7 +3920,99 @@ test('multi-select delete leaves the files alone when the switch is off', async
|
|
|
3809
3920
|
assert.equal('quarantine' in bodies[0], false, 'and does not move any file')
|
|
3810
3921
|
})
|
|
3811
3922
|
|
|
3812
|
-
test('a batch in asking mode
|
|
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 () => {
|
|
3963
|
+
const harness = await loadPlugin()
|
|
3964
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
3965
|
+
localStorage.setItem(AUTO_KEY, '0')
|
|
3966
|
+
const first = mountRow(harness, SESSION_A)
|
|
3967
|
+
await enterMulti(harness)
|
|
3968
|
+
clickRowIn(harness, first)
|
|
3969
|
+
await flush()
|
|
3970
|
+
clickBar(barDelete(harness))
|
|
3971
|
+
await settle()
|
|
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 () => {
|
|
3813
4016
|
const harness = await loadPlugin()
|
|
3814
4017
|
localStorage.setItem(OFF_KEY, '0')
|
|
3815
4018
|
localStorage.setItem(AUTO_KEY, '0')
|
|
@@ -3817,14 +4020,47 @@ test('a batch in asking mode says the files were left alone', async () => {
|
|
|
3817
4020
|
await enterMulti(harness)
|
|
3818
4021
|
clickRowIn(harness, first)
|
|
3819
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()
|
|
3820
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()
|
|
3821
4059
|
clickBar(barDelete(harness))
|
|
3822
4060
|
await settle()
|
|
3823
4061
|
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3824
4062
|
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
assert.equal(said.includes('产出文件没有处理'), true, 'the user is told: ' + said)
|
|
3829
|
-
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')
|
|
3830
4066
|
})
|