dsh-delete-session 0.3.3 → 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,13 @@ 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))。
165
172
  **(v0.3.3)** —— 删除当前会话不再顺手新建一个会话。
166
173
 
167
174
  - **问题**:删掉正在看的那个会话之后,`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.3",
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: 'Сессия сразу удаляется с диска, восстановить её нельзя.',
@@ -623,6 +632,8 @@ window.__ModuleLoader__.load({
623
632
  const RECYCLE_KEY = 'dsh-delete-session:recycle'
624
633
  /** Whether a delete takes the subagent sessions with it, without asking. */
625
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'
626
637
  /** How many artifact rows the dialog lists before collapsing the rest. */
627
638
  const ARTIFACT_ROWS_SHOWN = 40
628
639
  const prefListeners = new Set()
@@ -728,6 +739,23 @@ window.__ModuleLoader__.load({
728
739
  return readPref(SYNC_CHILDREN_KEY, '1') !== '0'
729
740
  }
730
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
+
731
759
  function setSyncChildren(on) {
732
760
  // "Off" is written as '0' rather than cleared: the default is now on, so a
733
761
  // removed key would read back as on again.
@@ -962,8 +990,18 @@ window.__ModuleLoader__.load({
962
990
  }
963
991
  if (!current || !deletedVariants(id).includes(current)) return
964
992
 
965
- // Preferred: tell the host, which owns the pointer and the retain.
966
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.
967
1005
  if (api !== null && typeof api.clearMain === 'function') {
968
1006
  try {
969
1007
  api.clearMain()
@@ -2559,6 +2597,7 @@ window.__ModuleLoader__.load({
2559
2597
  const [ask, setAsk] = react.useState(!skipConfirm())
2560
2598
  const [recycle, setRecycle] = react.useState(recycleSession())
2561
2599
  const [syncChildrenState, setSyncChildrenState] = react.useState(syncChildren())
2600
+ const [replaceState, setReplaceState] = react.useState(replaceCurrent())
2562
2601
  const [off, setOff] = react.useState(artifactsOff())
2563
2602
  const [auto, setAuto] = react.useState(artifactsAuto())
2564
2603
  const [scope, setScope] = react.useState(artifactScope())
@@ -2567,6 +2606,7 @@ window.__ModuleLoader__.load({
2567
2606
  react.useEffect(() => subscribeSkip(() => setAsk(!skipConfirm())), [])
2568
2607
  react.useEffect(() => { loadDefaultRoot() }, [])
2569
2608
  react.useEffect(() => subscribePrefs(() => {
2609
+ setReplaceState(replaceCurrent())
2570
2610
  setOff(artifactsOff())
2571
2611
  setAuto(artifactsAuto())
2572
2612
  setScope(artifactScope())
@@ -2617,6 +2657,18 @@ window.__ModuleLoader__.load({
2617
2657
  h('p', { key: 'syncChildrenHint', className: 'dsdel-page-hint' },
2618
2658
  translate(syncChildrenState ? 'pageSyncChildrenOn' : 'pageSyncChildrenOff')),
2619
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
+
2620
2672
  h(primitives.Checkbox, {
2621
2673
  key: 'off',
2622
2674
  checked: off,
@@ -2760,7 +2812,7 @@ window.__ModuleLoader__.load({
2760
2812
  // Each control owns the nodes that explain it. Grouping them here keeps the
2761
2813
  // markup above flat (a switch and its hint are still two pushes) while the
2762
2814
  // page draws them as one block.
2763
- 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'])
2764
2816
  function groupFields(nodes) {
2765
2817
  const groups = []
2766
2818
  let current = null
@@ -963,6 +963,72 @@ test('with no navigation service the sidebar button is the last resort', async (
963
963
 
964
964
  assert.equal(clicked, 1, 'the fallback still runs without the service')
965
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
+ })
966
1032
  test('a single delete plants no checkbox on any row (the v0.1.8 regression)', async () => {
967
1033
  const harness = await loadPlugin()
968
1034
  mountRow(harness, SESSION_A)
@@ -1356,7 +1422,7 @@ test('the produced-files feature ships off: no scan, no section, no quarantine f
1356
1422
 
1357
1423
  test('the page hides the artifact sub-controls while the master switch is on', async () => {
1358
1424
  const harness = await loadPlugin()
1359
- 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')
1360
1426
  assert.equal(offCheckbox(harness).props.checked, true, 'the master switch starts ticked')
1361
1427
  })
1362
1428
 
@@ -1365,7 +1431,7 @@ test('clearing the master switch reveals the auto and scope controls', async ()
1365
1431
  offCheckbox(harness).props.onChange(false)
1366
1432
 
1367
1433
  assert.equal(localStorage.getItem(OFF_KEY), '0', 'the opt-in was stored')
1368
- 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')
1369
1435
  assert.equal(autoCheckbox(harness).props.checked, false, 'asking is the default once enabled')
1370
1436
  assert.equal(scopeCreatedCheckbox(harness).props.checked, true, 'created-only is the default scope')
1371
1437
  assert.equal(scopeAllCheckbox(harness).props.checked, false)