dsh-delete-session 0.3.2 → 0.4.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,19 @@ MIT
162
162
 
163
163
  ## 修复记录
164
164
 
165
+ **(v0.4.0)** —— 「删完开一个新会话」变成可选,默认开,并改走宿主的 `startSession()`。
166
+
167
+ - **为什么会新建**:删掉当前打开的会话,主视图会停在一个已经不存在的会话上(合成器禁用,看着像删除失败)。v0.1.7 起,插件为此**去点侧栏的「新建会话」按钮** —— 那是用户入口,任何拦截新建的插件(命名、模板选择、预设工作区)都会被误伤。
168
+ - **改走宿主方法**:模拟点击靠猜 DOM(`button[class*="newSession"]`、`aria-label` 中英文各列一遍),宿主一改样式就静默失效。现在调 `uiWorkspace.startSession()`,语义明确、不依赖 UI 形状。
169
+ - **变成可选**:插件页多一个「删完打开一个新会话」,**默认勾选**。勾着 → 删完开一个新的(`startSession()`);取消 → 主视图留空(`clearMain()`)。两种都走宿主自己的方法,谁也不猜按钮。
170
+ - **旧宿主兜底不变**:两个方法都拿不到时,才退回原来的按钮点击 + 重置指针 + reload,视图不会停在已删的会话上。
171
+ - **关于第三方插件**:勾选时 `startSession()` 仍会经过 dsh-session-namer 之类的包装 —— 那是**预期行为**,用户就是要新建,问名字是对的。不想看到就取消勾选([#5](https://github.com/DDDMUC/dsh-delete-session/issues/5))。
172
+ **(v0.3.3)** —— 删除当前会话不再顺手新建一个会话。
173
+
174
+ - **问题**:删掉正在看的那个会话之后,`leaveIfCurrent()` 会去侧边栏点「新建会话」按钮,好让主视图别停在那个禁用的合成器上。可那个按钮是**用户**新建会话的入口,凡是拦截「新建会话」的插件(命名弹窗、模板选择、预设工作区)都会跟着触发 —— 结果是「删了一个会话」被做成了「新建一个会话」([#5](https://github.com/DDDMUC/dsh-delete-session/issues/5))。
175
+ - **改用宿主的 `uiWorkspace.clearMain()`**:放掉主引用、释放 retain、把持久化的 `dsh.sessions.current` 一并复位、清空面板。宿主自己就用它表达「没有当前会话」—— 归档当前会话走它,`startSession` 拿不到工作区也走它。
176
+ - **顺带去掉两个副作用**:不再需要 `localStorage.removeItem('dsh.sessions.current')`(`clearMain` 已经复位),也不再需要 `location.reload()`。
177
+ - **旧宿主仍有兜底**:`uiWorkspace` 拿不到(或没有 `clearMain`)时才退回原来的按钮点击 + 重置指针 + reload,保证视图不会停在已删的会话上。服务本身经 `ctx.get` 查一次、拿不到再 `ctx.inject` 补挂。
165
178
  **(v0.3.2)** —— 语言跟随 DSH 的界面语言,而不是操作系统。
166
179
 
167
180
  - **问题**:插件的语言只认 `navigator.language`。OS 是英文、DSH 设成中文的用户,看到的是全英文界面,而且没有任何办法改([#3](https://github.com/DDDMUC/dsh-delete-session/issues/3))。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-delete-session",
3
- "version": "0.3.2",
3
+ "version": "0.4.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
@@ -73,6 +73,9 @@ window.__ModuleLoader__.load({
73
73
  starCta: '行,给你一颗 Star',
74
74
  pageSyncChildrenOn: '删除对话时,把它派生的子代理会话一起删掉。',
75
75
  pageSyncChildrenOff: '不勾选时,删除前会列出子会话,由你勾选要删哪些。',
76
+ pageReplaceCurrent: '删完打开一个新会话',
77
+ pageReplaceCurrentOn: '删掉的如果正是当前打开的那个,顺手开一个新的,主视图不会空着。',
78
+ pageReplaceCurrentOff: '删掉的如果正是当前打开的那个,主视图留空,什么都不新建。',
76
79
  childrenHint: '这个对话有 {n} 个子会话(子代理),勾选的会一起删除。',
77
80
  pageRecycleOn: '删除后放进系统回收站,可以还原。',
78
81
  pageRecycleOff: '删除后直接从硬盘移除,不可恢复。',
@@ -182,6 +185,9 @@ window.__ModuleLoader__.load({
182
185
  starCta: 'Fine — have one',
183
186
  pageSyncChildrenOn: 'A delete also removes the subagent sessions it spawned.',
184
187
  pageSyncChildrenOff: 'When off, the dialog lists the child sessions and you tick the ones to delete.',
188
+ pageReplaceCurrent: 'Open a new conversation after deleting',
189
+ pageReplaceCurrentOn: 'If the conversation you are viewing is the one deleted, a fresh one opens instead of leaving the view blank.',
190
+ pageReplaceCurrentOff: 'If the conversation you are viewing is the one deleted, the view stays blank and nothing is created.',
185
191
  childrenHint: 'This conversation has {n} child sessions (subagents). Ticked ones are deleted too.',
186
192
  pageRecycleOn: 'The session goes to the system trash and can be restored.',
187
193
  pageRecycleOff: 'The session is removed from the disk right away and cannot be restored.',
@@ -288,6 +294,9 @@ window.__ModuleLoader__.load({
288
294
  starCta: 'Ладно, держи звезду',
289
295
  pageSyncChildrenOn: 'Удаление сессии удаляет и порождённые ею сессии субагентов.',
290
296
  pageSyncChildrenOff: 'Если выключено, перед удалением появится список дочерних сессий и вы отметите, какие удалить.',
297
+ pageReplaceCurrent: 'Открывать новый диалог после удаления',
298
+ pageReplaceCurrentOn: 'Если удалён тот диалог, который открыт, вместо пустого экрана откроется новый.',
299
+ pageReplaceCurrentOff: 'Если удалён тот диалог, который открыт, экран останется пустым, ничего не создаётся.',
291
300
  childrenHint: 'У этого диалога {n} дочерних сессий (субагентов). Отмеченные удалятся вместе с ним.',
292
301
  pageRecycleOn: 'Сессия попадёт в системную корзину, её можно восстановить.',
293
302
  pageRecycleOff: 'Сессия сразу удаляется с диска, восстановить её нельзя.',
@@ -358,6 +367,10 @@ window.__ModuleLoader__.load({
358
367
 
359
368
  let sessionsSvc = null
360
369
  let localeSvc = null
370
+ /** `uiWorkspace`: the host's own "this conversation is closed" face. */
371
+ let navigationSvc = null
372
+ /** Kept so the navigation service can be looked up lazily, outside apply(). */
373
+ let hostCtx = null
361
374
 
362
375
  /** Languages this plugin ships dictionaries for. */
363
376
  const SHIPPED = ['zh', 'en', 'ru']
@@ -619,6 +632,8 @@ window.__ModuleLoader__.load({
619
632
  const RECYCLE_KEY = 'dsh-delete-session:recycle'
620
633
  /** Whether a delete takes the subagent sessions with it, without asking. */
621
634
  const SYNC_CHILDREN_KEY = 'dsh-delete-session:sync-children'
635
+ /** Whether deleting the open conversation opens a fresh one afterwards. */
636
+ const REPLACE_KEY = 'dsh-delete-session:replace-current'
622
637
  /** How many artifact rows the dialog lists before collapsing the rest. */
623
638
  const ARTIFACT_ROWS_SHOWN = 40
624
639
  const prefListeners = new Set()
@@ -724,6 +739,23 @@ window.__ModuleLoader__.load({
724
739
  return readPref(SYNC_CHILDREN_KEY, '1') !== '0'
725
740
  }
726
741
 
742
+ /**
743
+ * Whether a delete of the OPEN conversation is followed by a new one.
744
+ *
745
+ * On by default: a DSH sitting on a deleted conversation is a dead end, and
746
+ * most people would rather keep working than stare at an empty screen. It is
747
+ * a choice, though - "leave me on a blank view" has to be reachable.
748
+ */
749
+ function replaceCurrent() {
750
+ return readPref(REPLACE_KEY, '1') !== '0'
751
+ }
752
+
753
+ function setReplaceCurrent(on) {
754
+ // Written as '0' rather than cleared, like the child-session switch: the
755
+ // default is on, so a removed key would read back as on again.
756
+ writePref(REPLACE_KEY, on ? '1' : '0')
757
+ }
758
+
727
759
  function setSyncChildren(on) {
728
760
  // "Off" is written as '0' rather than cleared: the default is now on, so a
729
761
  // removed key would read back as on again.
@@ -920,13 +952,34 @@ window.__ModuleLoader__.load({
920
952
  try { window.location.reload() } catch { /* ignore */ }
921
953
  }
922
954
 
923
- // Deleting the session the main view is showing leaves the app to restore a
924
- // stale neighbour (an unavailable Agent Team row with a disabled composer),
925
- // which reads as "the delete did not work". Open a fresh session instead.
955
+ // Deleting the session the main view is showing has to leave the app with no
956
+ // current conversation. It used to click the sidebar's "new session" button,
957
+ // which is wrong twice over: that button is the USER entry point, so every
958
+ // plugin that intercepts a new session (a naming dialog, a template picker,
959
+ // a preset workspace) fires on a delete; and the visible result of a delete
960
+ // became "a new conversation was created".
961
+ //
962
+ // The host has a way to express exactly this: `uiWorkspace.clearMain()`
963
+ // drops the main reference, releases its retain, resets the persisted
964
+ // `dsh.sessions.current` pointer and clears the panel. Archiving the current
965
+ // conversation and a failed `startSession` both go through it, so it is the
966
+ // sanctioned "nothing is open" state rather than a side effect of ours.
926
967
  function deletedVariants(id) {
927
968
  return id.startsWith('session-') ? [id, id.slice('session-'.length)] : [id, `session-${id}`]
928
969
  }
929
970
 
971
+ /** The navigation service, looked up lazily so a late one is still found. */
972
+ function navigationApi() {
973
+ if (navigationSvc !== null) return navigationSvc
974
+ const holder = hostCtx
975
+ if (holder === null || typeof holder.get !== 'function') return navigationSvc
976
+ try {
977
+ const svc = holder.get('uiWorkspace')
978
+ if (svc !== null && svc !== undefined) navigationSvc = svc
979
+ } catch { /* optional service */ }
980
+ return navigationSvc
981
+ }
982
+
930
983
  function leaveIfCurrent(id) {
931
984
  let current = null
932
985
  try {
@@ -936,6 +989,28 @@ window.__ModuleLoader__.load({
936
989
  return
937
990
  }
938
991
  if (!current || !deletedVariants(id).includes(current)) return
992
+
993
+ const api = navigationApi()
994
+
995
+ // The switch is a real choice: open a fresh conversation, or leave the view
996
+ // blank. Both go through the host - neither guesses at a button.
997
+ if (replaceCurrent() && api !== null && typeof api.startSession === 'function') {
998
+ try {
999
+ api.startSession()
1000
+ return
1001
+ } catch { /* older build: fall through to clearing */ }
1002
+ }
1003
+
1004
+ // Tell the host, which owns the pointer and the retain.
1005
+ if (api !== null && typeof api.clearMain === 'function') {
1006
+ try {
1007
+ api.clearMain()
1008
+ return
1009
+ } catch { /* older build: fall through */ }
1010
+ }
1011
+
1012
+ // No such service (a host that predates it): the old route, kept so the
1013
+ // view is never left pointing at a conversation that no longer exists.
939
1014
  const btn = document.querySelector(
940
1015
  'button[class*="newSession"], button[aria-label*="New session" i], button[aria-label*="新会话"]',
941
1016
  )
@@ -2522,6 +2597,7 @@ window.__ModuleLoader__.load({
2522
2597
  const [ask, setAsk] = react.useState(!skipConfirm())
2523
2598
  const [recycle, setRecycle] = react.useState(recycleSession())
2524
2599
  const [syncChildrenState, setSyncChildrenState] = react.useState(syncChildren())
2600
+ const [replaceState, setReplaceState] = react.useState(replaceCurrent())
2525
2601
  const [off, setOff] = react.useState(artifactsOff())
2526
2602
  const [auto, setAuto] = react.useState(artifactsAuto())
2527
2603
  const [scope, setScope] = react.useState(artifactScope())
@@ -2530,6 +2606,7 @@ window.__ModuleLoader__.load({
2530
2606
  react.useEffect(() => subscribeSkip(() => setAsk(!skipConfirm())), [])
2531
2607
  react.useEffect(() => { loadDefaultRoot() }, [])
2532
2608
  react.useEffect(() => subscribePrefs(() => {
2609
+ setReplaceState(replaceCurrent())
2533
2610
  setOff(artifactsOff())
2534
2611
  setAuto(artifactsAuto())
2535
2612
  setScope(artifactScope())
@@ -2580,6 +2657,18 @@ window.__ModuleLoader__.load({
2580
2657
  h('p', { key: 'syncChildrenHint', className: 'dsdel-page-hint' },
2581
2658
  translate(syncChildrenState ? 'pageSyncChildrenOn' : 'pageSyncChildrenOff')),
2582
2659
 
2660
+ h(primitives.Checkbox, {
2661
+ key: 'replaceCurrent',
2662
+ checked: replaceState,
2663
+ label: translate('pageReplaceCurrent'),
2664
+ onChange: (checked) => {
2665
+ setReplaceState(checked === true)
2666
+ setReplaceCurrent(checked === true)
2667
+ },
2668
+ }),
2669
+ h('p', { key: 'replaceCurrentHint', className: 'dsdel-page-hint' },
2670
+ translate(replaceState ? 'pageReplaceCurrentOn' : 'pageReplaceCurrentOff')),
2671
+
2583
2672
  h(primitives.Checkbox, {
2584
2673
  key: 'off',
2585
2674
  checked: off,
@@ -2723,7 +2812,7 @@ window.__ModuleLoader__.load({
2723
2812
  // Each control owns the nodes that explain it. Grouping them here keeps the
2724
2813
  // markup above flat (a switch and its hint are still two pushes) while the
2725
2814
  // page draws them as one block.
2726
- const FIELD_KEYS = new Set(['ask', 'recycle', 'syncChildren', 'off', 'auto', 'scope', 'skipGit', 'root'])
2815
+ const FIELD_KEYS = new Set(['ask', 'recycle', 'syncChildren', 'replaceCurrent', 'off', 'auto', 'scope', 'skipGit', 'root'])
2727
2816
  function groupFields(nodes) {
2728
2817
  const groups = []
2729
2818
  let current = null
@@ -2770,11 +2859,23 @@ window.__ModuleLoader__.load({
2770
2859
  }
2771
2860
  }
2772
2861
 
2862
+ hostCtx = ctx
2773
2863
  sessionsSvc = ctx.get('sessions') || null
2774
2864
  if (!sessionsSvc) {
2775
2865
  try { ctx.inject(['sessions'], (sub) => { sessionsSvc = sub.sessions }) } catch { /* optional */ }
2776
2866
  }
2777
2867
  localeSvc = ctx.get('locale') || null
2868
+ // `uiWorkspace` is a service, not a module: `ctx.get` is an optional lookup,
2869
+ // and a host that provides it later is covered by the inject below.
2870
+ try {
2871
+ const nav = ctx.get('uiWorkspace')
2872
+ if (nav !== null && nav !== undefined) navigationSvc = nav
2873
+ } catch { /* optional service */ }
2874
+ if (navigationSvc === null) {
2875
+ try {
2876
+ ctx.inject(['uiWorkspace'], (sub) => { navigationSvc = sub.uiWorkspace || null })
2877
+ } catch { /* optional service */ }
2878
+ }
2778
2879
 
2779
2880
  // Slot components are handed a `t` bound to this namespace, so the
2780
2881
  // dictionaries must reach the host - on BOTH arrival paths. If `locale`
@@ -188,6 +188,12 @@ function walk(root) {
188
188
  }
189
189
 
190
190
  function matches(node, selector) {
191
+ // A comma list is an OR in the DOM, and the plugin uses one to find the
192
+ // "new session" button. Without this the stub silently answered "no match"
193
+ // for every alternative, which hid the fallback path entirely.
194
+ if (selector.includes(',')) {
195
+ return selector.split(',').some((part) => matches(node, part.trim()))
196
+ }
191
197
  // `:scope > .dsdel-check` - a DIRECT child. The plugin uses this to tell its
192
198
  // own row checkbox apart from anything nested, so depth has to be respected.
193
199
  const scoped = /^:scope > \.([\w-]+)$/.exec(selector)
@@ -201,6 +207,23 @@ function matches(node, selector) {
201
207
  return node._classes.has(selector.slice(1))
202
208
  }
203
209
 
210
+ // `button[class*="newSession"]` - tag-qualified, used by the fallback that
211
+ // finds the host's "new session" button after a delete.
212
+ const tagClassContains = /^([A-Za-z][\w-]*)\[class\*="([^"]*)"\]$/.exec(selector)
213
+ if (tagClassContains !== null) {
214
+ if (String(node.tagName || '').toLowerCase() !== tagClassContains[1].toLowerCase()) return false
215
+ return String(node.className ?? '').includes(tagClassContains[2])
216
+ }
217
+
218
+ // `button[aria-label*="New session" i]` - a case-insensitive attribute match.
219
+ const tagAttrContains = /^([A-Za-z][\w-]*)\[([\w-]+)\*="([^"]*)"(?: i)?\]$/.exec(selector)
220
+ if (tagAttrContains !== null) {
221
+ if (String(node.tagName || '').toLowerCase() !== tagAttrContains[1].toLowerCase()) return false
222
+ const value = node.attributes[tagAttrContains[2]]
223
+ if (typeof value !== 'string') return false
224
+ return value.toLowerCase().includes(tagAttrContains[3].toLowerCase())
225
+ }
226
+
204
227
  // `[class*="_footArea"]` - how the bar finds the host's sidebar footer.
205
228
  const classContains = /^\[class\*="([^"]*)"\]$/.exec(selector)
206
229
  if (classContains !== null) return node.className.includes(classContains[1])
@@ -457,12 +480,16 @@ async function loadPlugin(options = {}) {
457
480
  // `lateLocale` models a host where the locale service is only reachable
458
481
  // through ctx.inject, which is the path that used to skip registration.
459
482
  if (name === 'locale') return (options.lateLocale || options.noLocale) ? null : localeStub
483
+ if (name === 'uiWorkspace') return options.noNavigation ? null : (options.navigation || null)
460
484
  return null
461
485
  },
462
486
  inject: (names, cb) => {
463
487
  if (typeof cb === 'function') {
464
488
  const late = options.lateLocale && !options.noLocale
465
- cb(late ? { slots: slotsStub, locale: localeStub } : { slots: slotsStub })
489
+ const bag = { slots: slotsStub }
490
+ if (late) bag.locale = localeStub
491
+ if (options.navigation && !options.noNavigation) bag.uiWorkspace = options.navigation
492
+ cb(bag)
466
493
  }
467
494
  },
468
495
  effect: (fn) => { const dispose = fn(); return () => { if (typeof dispose === 'function') dispose() } },
@@ -874,6 +901,134 @@ test('shift-click forces the dialog even after asking was turned off', async ()
874
901
 
875
902
  // --- the regression ---------------------------------------------------------
876
903
 
904
+ test('deleting the current session clears the main view instead of opening a new one (issue #5)', async () => {
905
+ let cleared = 0
906
+ const harness = await loadPlugin({
907
+ navigation: { clearMain: () => { cleared += 1 } },
908
+ })
909
+ mountRow(harness, SESSION_A)
910
+ localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
911
+
912
+ // The host's own session menu row drives the delete; asking is off so it goes
913
+ // straight through, like the reporter did.
914
+ localStorage.setItem(SKIP_KEY, '1')
915
+ const { element } = deleteRow(harness)
916
+ element.props.onSelect({ shiftKey: false })
917
+ await tick()
918
+ await flush()
919
+
920
+ // Issue #5: this used to click the sidebar's "new session" button, which every
921
+ // plugin that intercepts session creation shares (a naming dialog, a template
922
+ // picker). Deleting a conversation must not create one.
923
+ assert.equal(cleared, 1, 'the host was told to drop the main reference')
924
+ assert.equal(harness.requests.filter((c) => c.url === '/dsh-delete-session/delete').length, 1, 'the delete still went out')
925
+ })
926
+
927
+ test('a delete that is not the current session leaves navigation alone', async () => {
928
+ let cleared = 0
929
+ const harness = await loadPlugin({
930
+ navigation: { clearMain: () => { cleared += 1 } },
931
+ })
932
+ mountRow(harness, SESSION_A)
933
+ localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_B.id }))
934
+ localStorage.setItem(SKIP_KEY, '1')
935
+
936
+ const { element } = deleteRow(harness)
937
+ element.props.onSelect({ shiftKey: false })
938
+ await tick()
939
+ await flush()
940
+
941
+ assert.equal(cleared, 0, 'nothing to clear: the deleted one was not on screen')
942
+ })
943
+
944
+ test('with no navigation service the sidebar button is the last resort', async () => {
945
+ const harness = await loadPlugin({ noNavigation: true })
946
+ mountRow(harness, SESSION_A)
947
+ localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
948
+ localStorage.setItem(SKIP_KEY, '1')
949
+
950
+ // A host that predates `clearMain` still has to end up with no current
951
+ // conversation, so the old fallback stays. It is only reached when the service
952
+ // is genuinely absent.
953
+ let clicked = 0
954
+ const btn = harness.document.createElement('button')
955
+ btn.className = 'newSession'
956
+ btn.click = () => { clicked += 1 }
957
+ harness.document.body.appendChild(btn)
958
+
959
+ const { element } = deleteRow(harness)
960
+ element.props.onSelect({ shiftKey: false })
961
+ await tick()
962
+ await flush()
963
+
964
+ assert.equal(clicked, 1, 'the fallback still runs without the service')
965
+ })
966
+ test('by default a delete of the open conversation opens a fresh one', async () => {
967
+ const calls = []
968
+ const harness = await loadPlugin({
969
+ navigation: {
970
+ startSession: () => { calls.push('startSession') },
971
+ clearMain: () => { calls.push('clearMain') },
972
+ },
973
+ })
974
+ mountRow(harness, SESSION_A)
975
+ localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
976
+ localStorage.setItem(SKIP_KEY, '1')
977
+
978
+ const { element } = deleteRow(harness)
979
+ element.props.onSelect({ shiftKey: false })
980
+ await tick()
981
+ await flush()
982
+
983
+ assert.deepEqual(calls, ['startSession'], 'one fresh conversation, nothing cleared')
984
+ })
985
+
986
+ test('turning the switch off leaves the view blank instead', async () => {
987
+ const calls = []
988
+ const harness = await loadPlugin({
989
+ navigation: {
990
+ startSession: () => { calls.push('startSession') },
991
+ clearMain: () => { calls.push('clearMain') },
992
+ },
993
+ })
994
+ localStorage.setItem('dsh-delete-session:replace-current', '0')
995
+ mountRow(harness, SESSION_A)
996
+ localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
997
+ localStorage.setItem(SKIP_KEY, '1')
998
+
999
+ const { element } = deleteRow(harness)
1000
+ element.props.onSelect({ shiftKey: false })
1001
+ await tick()
1002
+ await flush()
1003
+
1004
+ assert.deepEqual(calls, ['clearMain'], 'the switch is a real choice')
1005
+ })
1006
+
1007
+ test('a host without startSession still ends up with a blank view', async () => {
1008
+ const calls = []
1009
+ const harness = await loadPlugin({
1010
+ navigation: { clearMain: () => { calls.push('clearMain') } },
1011
+ })
1012
+ mountRow(harness, SESSION_A)
1013
+ localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
1014
+ localStorage.setItem(SKIP_KEY, '1')
1015
+
1016
+ const { element } = deleteRow(harness)
1017
+ element.props.onSelect({ shiftKey: false })
1018
+ await tick()
1019
+ await flush()
1020
+
1021
+ assert.deepEqual(calls, ['clearMain'], 'no fresh session available, so clear')
1022
+ })
1023
+
1024
+ test('the replace-current switch renders on the plugin page', async () => {
1025
+ const harness = await loadPlugin()
1026
+ const card = pageCard(harness)
1027
+ const fields = (card.props.children ?? []).filter((node) => node && node.props && node.props.className === 'dsdel-field')
1028
+
1029
+ // Five switches: ask / recycle / syncChildren / replaceCurrent / artifacts.
1030
+ assert.ok(fields.length >= 5, 'the new switch became its own block, saw ' + fields.length)
1031
+ })
877
1032
  test('a single delete plants no checkbox on any row (the v0.1.8 regression)', async () => {
878
1033
  const harness = await loadPlugin()
879
1034
  mountRow(harness, SESSION_A)
@@ -1267,7 +1422,7 @@ test('the produced-files feature ships off: no scan, no section, no quarantine f
1267
1422
 
1268
1423
  test('the page hides the artifact sub-controls while the master switch is on', async () => {
1269
1424
  const harness = await loadPlugin()
1270
- assert.equal(pageChecks(harness).length, 4, 'ask, recycle, subagents and the master switch render')
1425
+ assert.equal(pageChecks(harness).length, 5, 'ask, recycle, subagents, replace-current and the master switch render')
1271
1426
  assert.equal(offCheckbox(harness).props.checked, true, 'the master switch starts ticked')
1272
1427
  })
1273
1428
 
@@ -1276,7 +1431,7 @@ test('clearing the master switch reveals the auto and scope controls', async ()
1276
1431
  offCheckbox(harness).props.onChange(false)
1277
1432
 
1278
1433
  assert.equal(localStorage.getItem(OFF_KEY), '0', 'the opt-in was stored')
1279
- assert.equal(pageChecks(harness).length, 8, 'the sub-controls render once enabled')
1434
+ assert.equal(pageChecks(harness).length, 9, 'the sub-controls render once enabled')
1280
1435
  assert.equal(autoCheckbox(harness).props.checked, false, 'asking is the default once enabled')
1281
1436
  assert.equal(scopeCreatedCheckbox(harness).props.checked, true, 'created-only is the default scope')
1282
1437
  assert.equal(scopeAllCheckbox(harness).props.checked, false)