dsh-conversation-float 0.3.1 → 0.3.3

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/client.js CHANGED
@@ -10,13 +10,20 @@
10
10
  * the panel (same document, same React root, so events and reconciliation keep
11
11
  * working) and moved back to its seat when the panel closes.
12
12
  *
13
- * While the window is on screen it can be dragged onto three drop bands:
13
+ * While the window is on screen it can be dragged onto three drop bands — the
14
+ * right one only while the Conversation fills the main column:
14
15
  *
15
16
  * left the window minimises — still mounted, hidden — and its taskbar row
16
17
  * in the left sidebar brings it back; the centre column stays empty,
17
18
  * exactly as it is while the window is on screen
18
- * center the window closes and the Conversation returns to its column
19
- * right the tab is handed to the right sidebar, where DSH docks it
19
+ * center the window closes and the Conversation returns to its column
20
+ *
21
+ * The right band exists only while the Conversation fills the main column.
22
+ * Open Plugins, Automations, Settings or any other left-sidebar page and the
23
+ * right column is not drawn at all — DSH suppresses it while a global panel is
24
+ * active — so a right band there would promise a column that cannot appear.
25
+ * On those pages the drag has two bands only: everything right of the left band
26
+ * is centre, and the outline says so.
20
27
  *
21
28
  * The bands are measured once per drag. Holding the press for {@link DWELL_MS}
22
29
  * switches the drag into judging: from that moment the outline follows the band
@@ -47,6 +54,12 @@ window.__ModuleLoader__.load({
47
54
  }
48
55
  })()
49
56
  const MenuItemButton = primitives?.MenuItemButton ?? null
57
+ /**
58
+ * DSH's own right-sidebar glyph. Its expand and collapse controls use the
59
+ * panel-left outline mirrored, so a rescue row wearing the same icon reads
60
+ * as "this Conversation is behind the right bar", not as a second window.
61
+ */
62
+ const PanelLeftIcon = primitives?.IconPanelLeftOutlineRegular ?? null
50
63
 
51
64
  /**
52
65
  * Copy for every locale DSH ships. The word for the Conversation is read
@@ -196,6 +209,10 @@ window.__ModuleLoader__.load({
196
209
  const ANCHOR_ATTR = 'data-dsh-conversation-float-anchor'
197
210
  /** Set on a taskbar row's button, with the Session its window shows. */
198
211
  const ROW_MARK_ATTR = 'data-dsh-conversation-float-row'
212
+ /** Set on a rescue row's button: the Session docked in a railed right bar. */
213
+ const RESCUE_ATTR = 'data-dsh-conversation-float-rescue'
214
+ /** The left row a docked Conversation gets while the right bar is collapsed. */
215
+ const RESCUE_ID = 'conversation-rescue:'
199
216
  const CHAT_ID = 'conversation-float-panel'
200
217
  const CHAT_KIND = 'conversation-float-panel'
201
218
  /** A resource address our own tab type claims; the panel is opened by it. */
@@ -260,6 +277,14 @@ window.__ModuleLoader__.load({
260
277
  let inLayout = false
261
278
  /** Whether the main slot carried a page during the last pass. */
262
279
  let lastPageOpen = false
280
+ /**
281
+ * The Session DSH last said was current.
282
+ *
283
+ * A pass has to run when this moves even while a page owns the main slot:
284
+ * the float's own switch chip trades the live Conversation and keeps the
285
+ * page open, so "a page is up, nothing can have changed" stopped being true.
286
+ */
287
+ let lastSelected = null
263
288
  /**
264
289
  * What one layout pass has already worked out.
265
290
  *
@@ -297,10 +322,16 @@ window.__ModuleLoader__.load({
297
322
  const pageChanged = pageOpen !== lastPageOpen
298
323
  lastPageOpen = pageOpen
299
324
  // A page owns the main slot: the Conversation is not on screen, the column
300
- // is home and every body already shows its own transcript. Nothing a pass
301
- // could decide is different until the page closes — and that transition is
302
- // what the flag above catches.
303
- if (pageOpen && !pageChanged) return
325
+ // is home and every body shows its own transcript. Nothing a pass could
326
+ // decide is different until the page closes — except WHICH Session is the
327
+ // current one, which the float's switch chip changes without closing the
328
+ // page. That switch is the one thing this early exit must not swallow: the
329
+ // new Session's window has to turn into the full Conversation and the old
330
+ // one back into a transcript.
331
+ const selectedNow = selectedSession()
332
+ const selectedChanged = selectedNow !== lastSelected
333
+ lastSelected = selectedNow
334
+ if (pageOpen && !pageChanged && !selectedChanged) return
304
335
  inLayout = true
305
336
  beginPass()
306
337
  try {
@@ -331,6 +362,9 @@ window.__ModuleLoader__.load({
331
362
  }
332
363
  }
333
364
  refreshSwitchChips()
365
+ // A pass may have moved the Conversation into or out of a railed right
366
+ // bar: the left rescue row follows the column, not a timer.
367
+ scheduleRescueSync()
334
368
  // The transcript's height is a layout fact: refresh the float's own
335
369
  // scroll lane here, where the composer has already settled.
336
370
  for (const win of windows.values()) syncScrollbar(win)
@@ -343,8 +377,6 @@ window.__ModuleLoader__.load({
343
377
  let pendingChromeless = false
344
378
  /** The last sane band geometry, kept for when the columns are hidden. */
345
379
  let lastBand = null
346
- /** Sidebar state captured when the float opened; restored when it closes. */
347
- let savedChrome = null
348
380
  /**
349
381
  * A retry of the sidebar arrangement, cancelable by the user's own hand.
350
382
  *
@@ -353,14 +385,10 @@ window.__ModuleLoader__.load({
353
385
  * never kept. A hand on the sidebars now ends the retry directly.
354
386
  */
355
387
  let chromeApplyStop = null
356
- /** Set while docking to the right sidebar: the column is not going home. */
357
- let dockingRight = false
358
388
  /** Set when a minimise is waiting for the float that carries the column. */
359
389
  let pendingMinimise = false
360
390
  /** The Session list projection, when the Client exposes it. */
361
391
  let sessions = null
362
- /** Set while the float is being reopened from the drawer. */
363
- let suspendRestore = false
364
392
  /** The drop preview overlay, created on demand. */
365
393
  let preview = null
366
394
 
@@ -527,96 +555,6 @@ window.__ModuleLoader__.load({
527
555
  return null
528
556
  }
529
557
 
530
- /** DSH's layout grid: every panel edge lands on a multiple of it. */
531
- const GRID = 8
532
- /**
533
- * The float's size: 450 x 720 by request, never larger than the room the
534
- * window actually has. Asking for more makes the dock kit clamp on its own
535
- * and hands back a half-sized panel with no room left for the messages.
536
- */
537
- function floatSize() {
538
- return {
539
- width: Math.max(320, Math.min(450, window.innerWidth - 80)),
540
- height: Math.max(320, Math.min(720, window.innerHeight - 80)),
541
- }
542
- }
543
-
544
- /** The room the sidebars leave in the middle: their two inner edges. */
545
- function middleRoom() {
546
- const width = window.innerWidth
547
- const overlay = document.querySelector('[data-shell-overlay]')
548
- const frame = overlay === null ? null : overlay.parentElement
549
- let left = 0
550
- let right = width
551
- if (frame !== null) {
552
- const sidebar = frame.firstElementChild
553
- if (sidebar !== null) {
554
- const box = sidebar.getBoundingClientRect()
555
- if (box.width > 80) left = Math.round(box.right)
556
- }
557
- const rightColumn = frame.querySelector('[data-rightbar-col]')
558
- if (rightColumn !== null) {
559
- const box = rightColumn.getBoundingClientRect()
560
- if (box.width > 80) right = Math.round(box.left)
561
- }
562
- }
563
- return { left, right: Math.max(left, right) }
564
- }
565
-
566
- /**
567
- * Upper-left corner of that seat: centred in the room the sidebars leave,
568
- * snapped, clear of the frame. With the window showing nothing but the
569
- * float those columns measure zero and the seat falls back to the window.
570
- */
571
- function floatSeat(size) {
572
- const snap = (value) => Math.max(0, Math.round(value / GRID) * GRID)
573
- const room = middleRoom()
574
- const free = room.right - room.left
575
- return {
576
- x: free > size.width ? snap(room.left + (free - size.width) / 2) : snap(room.left),
577
- y: Math.max(48, snap((window.innerHeight - size.height) / 2)),
578
- }
579
- }
580
-
581
- /**
582
- * Give the float a readable size on open. DSH's dock kit builds a fresh
583
- * float at a small default; the plugin cannot write the panel's inline box,
584
- * but the kit exposes the very intent its own resize drag dispatches:
585
- * `sidebarRight.require()` -> `actions.resizeFloat(sessionId, paneId, rect)`.
586
- * The pane id is the float element's own `data-dockkit-float` value.
587
- */
588
- function sizeFloat() {
589
- const panel = floatPanel()
590
- if (panel === null) return
591
- const paneId = panel.getAttribute(FLOAT_ATTR) ?? document.querySelector(`[${FLOAT_ATTR}]`)?.getAttribute(FLOAT_ATTR)
592
- if (paneId === null || paneId === undefined) return
593
- let seat = null
594
- try {
595
- seat = sidebarRight?.require?.() ?? null
596
- } catch {
597
- seat = null
598
- }
599
- if (seat === null) {
600
- // The mounted-session shortcut can be missing right after a docked tab
601
- // is floated again; fall back to the per-session action face.
602
- try {
603
- const sessionId = sidebarRight?.mounted?.getSnapshot?.()
604
- const actions = sessionId === undefined ? undefined : sidebarRight?.actionsFor?.(sessionId)
605
- if (actions !== undefined && actions !== null) seat = { sessionId, actions }
606
- } catch {
607
- seat = null
608
- }
609
- }
610
- if (seat === null || typeof seat.actions?.resizeFloat !== 'function') return
611
- const size = floatSize()
612
- const corner = floatSeat(size)
613
- const rect = { ...corner, width: size.width, height: size.height }
614
- try {
615
- seat.actions.resizeFloat(seat.sessionId, paneId, rect)
616
- } catch (error) {
617
- report('[conversation-float] could not size the floating panel:', error)
618
- }
619
- }
620
558
  function attachColumn(container, keepHome = false) {
621
559
  const column = findColumn()
622
560
  if (column === null || container === null) return null
@@ -650,13 +588,6 @@ window.__ModuleLoader__.load({
650
588
  noteColumnMoved()
651
589
  const ownPanel = floatPanel()
652
590
  if (ownPanel !== null) ownPanel.setAttribute(OWN_FLOAT_ATTR, '')
653
- // The dock kit gives a new float its own seat; ask it — through the same
654
- // intent its own resize drag uses — for the configured one.
655
- sizeFloat()
656
-
657
- // A host has taken the column, so a docking that was waiting for its tab
658
- // has arrived: the restore guard must not outlive it.
659
- dockingRight = false
660
591
 
661
592
  // The left-hand action asked for the conversation while no float existed.
662
593
  // The body is mounted in a layout effect — before paint — so minimising
@@ -953,27 +884,16 @@ window.__ModuleLoader__.load({
953
884
  } catch { /* no window yet */ }
954
885
  }
955
886
 
956
- function detachColumn(keepChrome = false) {
887
+ function detachColumn() {
957
888
  const column = movedColumn
958
889
  const home = movedFrom
959
890
  if (column !== null) column.removeAttribute(COLUMN_ATTR)
960
891
  movedColumn = null
961
892
  movedFrom = null
962
893
  notifyState()
963
- // Closing is the plugin's doing, even when a click on the panel's own
964
- // close button started it. Nothing has to be suppressed for that: the
965
- // restore below compares against a snapshot taken before the float
966
- // opened, so a re-rail cannot be mistaken for the user's arrangement.
967
894
  for (const el of document.querySelectorAll(`[${OWN_FLOAT_ATTR}]`)) el.removeAttribute(OWN_FLOAT_ATTR)
968
895
  // The float is leaving the screen: the rest of DSH has to come back.
969
896
  if (chromeless) setChromeless(false)
970
- // A float that goes home hands the sidebars back as they were — but only
971
- // when it really goes home. Moving the live column between hosts (back
972
- // out of the left drawer, a remounted float body) also detaches it for
973
- // a frame; restoring there would collapse the sidebars under a float
974
- // that is still on screen.
975
- if (!keepChrome && !dockingRight && !suspendRestore) scheduleRestoreChrome()
976
- dockingRight = false
977
897
  if (column === null) return
978
898
  noteColumnMoved()
979
899
  column.style.width = ''
@@ -1106,7 +1026,13 @@ window.__ModuleLoader__.load({
1106
1026
  // A docked page can be the Conversation's only home; its Session is the
1107
1027
  // one on screen and the entry must still find it.
1108
1028
  const docked = dockedBodySession()
1109
- answer = docked !== null ? docked : lastSession
1029
+ // On a page that is not a Conversation there is no column to read and no
1030
+ // docked body to read either: DSH's own selection store is the only
1031
+ // answer, and it is the right one there — the page never renders the
1032
+ // Conversation at all, so nothing on screen can disagree with it. That is
1033
+ // how a switch made from a page finds the Session it just made live.
1034
+ const selected = docked === null && mainPanelOpen() ? selectedSession() : null
1035
+ answer = docked !== null ? docked : (selected ?? lastSession)
1110
1036
  }
1111
1037
  if (answer !== null) lastSession = answer
1112
1038
  if (passMemo !== null) {
@@ -1423,39 +1349,18 @@ window.__ModuleLoader__.load({
1423
1349
  }
1424
1350
 
1425
1351
  /**
1426
- * Bring the rest of DSH back. Hiding the columns lets DSH re-rail the left
1427
- * sidebar, so the window used to come back as "only the right column": a
1428
- * reveal opens the drawer again, the same way opening the float does.
1352
+ * Bring the rest of DSH back after the float hid it. The sidebars are left
1353
+ * exactly as the user last had them: this plugin no longer puts a captured
1354
+ * arrangement back.
1429
1355
  */
1430
- function revealChrome(forceDrawer = false) {
1356
+ function revealChrome() {
1431
1357
  setChromeless(false)
1432
- // The columns are opened by the plugin, and a hand on them ends any retry
1433
- // this pass started (see the pointerdown tracker in apply()), so the
1434
- // user's own first click is never swallowed by a settle window.
1435
- // Back to the arrangement the window had: whatever the user last left the
1436
- // sidebars in, or the pair the float found. Never a blanket "both open" —
1437
- // that would undo a sidebar the user closed on purpose.
1438
- const base = restoreTarget()
1439
- // Stowing the float needs its drawer row on screen, whatever the target.
1440
- // The forced drawer is folded into the target itself: a separate toggle
1441
- // would be undone by the retry pass that follows it.
1442
- const target = base === null ? null : forceDrawer ? { ...base, leftCollapsed: false } : base
1443
- if (target !== null) {
1444
- applyChromeTarget(target)
1445
- return
1446
- }
1447
- if (!forceDrawer) return
1448
- try {
1449
- if (leftCollapsed()) layout?.toggleSidebar?.()
1450
- } catch (error) {
1451
- report('[conversation-float] could not expand the left sidebar:', error)
1452
- }
1453
1358
  }
1454
1359
 
1455
1360
  /**
1456
- * Match the sidebars to the snapshot, and report whether they already do.
1361
+ * Match the sidebars to a target, and report whether they already do.
1457
1362
  * Right goes first because opening the left drawer rails the right column
1458
- * on a narrow window; doing the left last leaves the pair the snapshot
1363
+ * on a narrow window; doing the left last leaves the pair the target
1459
1364
  * asked for.
1460
1365
  */
1461
1366
  function applyChromeSnapshot(saved) {
@@ -1516,42 +1421,6 @@ window.__ModuleLoader__.load({
1516
1421
  return { leftCollapsed: leftCollapsed(), rightExpanded: rightExpanded() }
1517
1422
  }
1518
1423
 
1519
- /**
1520
- * Remember the sidebars as they were before the float forced them open.
1521
- * The capture happens once, before the plugin touches anything, and is
1522
- * never refreshed while the float is up: a later sample would record the
1523
- * forced state instead, and then every close would look like the user's
1524
- * choice and nothing would ever be restored.
1525
- */
1526
- function saveChromeState() {
1527
- if (savedChrome !== null) return
1528
- savedChrome = chromeNow()
1529
- }
1530
-
1531
- /**
1532
- * A detach is not a close until the float is really gone. The drawer row
1533
- * re-hosts the live column and a remounted body re-attaches it, and both
1534
- * detach it for a frame; the chrome is restored only when nothing took the
1535
- * column back and no panel is left to finish tearing down.
1536
- */
1537
- function scheduleRestoreChrome(depth = 0) {
1538
- window.requestAnimationFrame(() => {
1539
- // A host took the column back: the float is still open, not closed.
1540
- if (movedColumn !== null) return
1541
- // The panel is still on its way out; give it a few frames.
1542
- if (floatPanel() !== null) {
1543
- if (depth < 12) scheduleRestoreChrome(depth + 1)
1544
- return
1545
- }
1546
- restoreChrome()
1547
- })
1548
- }
1549
-
1550
- /** The pair a reveal or a close puts back: the snapshot taken on open. */
1551
- function restoreTarget() {
1552
- return savedChrome
1553
- }
1554
-
1555
1424
  /** Match the sidebars to a target, retrying while the dock kit settles. */
1556
1425
  function applyChromeTarget(target) {
1557
1426
  // A toggle the dock kit queued needs a commit to land, so a retry fired
@@ -1590,13 +1459,6 @@ window.__ModuleLoader__.load({
1590
1459
  return rightOk && leftOk
1591
1460
  }
1592
1461
 
1593
- function restoreChrome() {
1594
- const target = restoreTarget()
1595
- savedChrome = null
1596
- if (target === null) return
1597
- applyChromeTarget(target)
1598
- }
1599
-
1600
1462
  /** Open (or focus) the float at the dock kit's own default seat. */
1601
1463
  /**
1602
1464
  * Give this Conversation a window.
@@ -1609,7 +1471,7 @@ window.__ModuleLoader__.load({
1609
1471
  function openFloatAtDefault() {
1610
1472
  const sessionId = liveSession()
1611
1473
  if (sessionId === null) return
1612
- saveChromeState()
1474
+ invokedThisRun.add(sessionId)
1613
1475
  if (tabIdFor(sessionId) !== null) {
1614
1476
  // The tab exists. Floating it is the SAME tab moving, never a second
1615
1477
  // one: a docked page is floated through the dock kit's own intent, and
@@ -1679,49 +1541,74 @@ window.__ModuleLoader__.load({
1679
1541
  /* ---------------------------------------------------------------- bands */
1680
1542
 
1681
1543
  /**
1682
- * The three drop bands, taken from the frame's own columns: the left
1683
- * sidebar is the frame's first child, the right sidebar carries
1684
- * `data-rightbar-col`, and the middle column is whatever lies between them.
1685
- * The preview therefore covers the same area the drop lands in.
1544
+ * The drop bands a drag may judge against, taken from the frame's own
1545
+ * columns: the left sidebar is the frame's first child, the right sidebar
1546
+ * carries `data-rightbar-col`, and the middle column is whatever lies
1547
+ * between them. The preview therefore covers the same area the drop lands
1548
+ * in.
1549
+ *
1550
+ * The right band is CONDITIONAL. DSH draws the right column only while the
1551
+ * Conversation fills the main column; a plugin, automation or settings page
1552
+ * suppresses it, so docking there would open a tab into a column nothing is
1553
+ * drawing. On those pages `right` is null: there are two bands, and every
1554
+ * point past the left band is centre.
1686
1555
  */
1687
1556
  function bands() {
1688
1557
  const width = window.innerWidth
1689
1558
  const height = window.innerHeight
1559
+ const dockable = !mainPanelOpen()
1690
1560
  // With the window showing nothing but the float, the columns are hidden:
1691
1561
  // their rects read as a zero-width left band, which is exactly why "放进
1692
1562
  // 左栏" could never be chosen. Judge by thirds of the window there.
1693
- if (chromeless) return thirds(width, height)
1563
+ if (chromeless) return thirds(width, height, dockable)
1694
1564
  const overlay = document.querySelector('[data-shell-overlay]')
1695
1565
  const frame = overlay === null ? null : overlay.parentElement
1696
1566
  let left = 0
1697
- let right = 0
1567
+ let right = dockable ? 0 : null
1698
1568
  if (frame !== null) {
1699
1569
  const sidebar = frame.firstElementChild
1700
1570
  if (sidebar !== null) left = Math.round(sidebar.getBoundingClientRect().right)
1701
- const rightCol = frame.querySelector('[data-rightbar-col]')
1702
- if (rightCol !== null) right = Math.round(rightCol.getBoundingClientRect().left)
1571
+ if (right !== null) {
1572
+ const rightCol = frame.querySelector('[data-rightbar-col]')
1573
+ if (rightCol !== null) right = Math.round(rightCol.getBoundingClientRect().left)
1574
+ }
1703
1575
  }
1704
1576
  // A collapsed right column measures at the window's edge, which would leave
1705
1577
  // the "dock right" band zero wide and unreachable; keep a third of the
1706
1578
  // window aimable there, and the docking itself opens the column.
1707
- if (right >= width - 1) right = Math.round((width * 2) / 3)
1579
+ if (right !== null && right >= width - 1) right = Math.round((width * 2) / 3)
1708
1580
  // While the columns are hidden the measurements collapse; keep the last
1709
- // geometry that made sense so a drag does not land in nonsense bands.
1710
- const sane = left >= 0 && right > left + 80 && right <= width + 1
1711
- if (!sane) return lastBand !== null ? { ...lastBand, width, height } : thirds(width, height)
1581
+ // geometry that made sense so a drag does not land in nonsense bands. A
1582
+ // remembered geometry only serves a frame of the same kind: a band read on
1583
+ // the Conversation page kept its right edge across a page switch.
1584
+ const edge = right === null ? width : right
1585
+ const sane = left >= 0 && edge > left + 80 && edge <= width + 1
1586
+ if (!sane) {
1587
+ if (lastBand !== null && (lastBand.right === null) === (right === null)) return { ...lastBand, width, height }
1588
+ return thirds(width, height, dockable)
1589
+ }
1712
1590
  // A railed drawer is too thin to aim at: widen its band to something a
1713
1591
  // hand can actually hit.
1714
1592
  lastBand = { left: Math.max(left, 96), right, width, height }
1715
1593
  return lastBand
1716
1594
  }
1717
1595
 
1718
- /** The window in thirds: the bands used while the float is alone. */
1719
- function thirds(width, height) {
1720
- return { left: Math.round(width / 3), right: Math.round((width * 2) / 3), width, height }
1596
+ /**
1597
+ * The window in thirds: the bands used while the float is alone.
1598
+ * `right` is null on a page that suppresses the right column, which leaves
1599
+ * this function returning the same two bands the measured frame would.
1600
+ */
1601
+ function thirds(width, height, dockable) {
1602
+ return {
1603
+ left: Math.round(width / 3),
1604
+ right: dockable ? Math.round((width * 2) / 3) : null,
1605
+ width,
1606
+ height,
1607
+ }
1721
1608
  }
1722
1609
  function zoneAt(x, band) {
1723
1610
  if (x <= band.left) return 'left'
1724
- if (x >= band.right) return 'right'
1611
+ if (band.right !== null && x >= band.right) return 'right'
1725
1612
  return 'center'
1726
1613
  }
1727
1614
 
@@ -1753,8 +1640,11 @@ window.__ModuleLoader__.load({
1753
1640
 
1754
1641
  function previewRect(zone, band) {
1755
1642
  if (zone === 'left') return [0, 0, band.left, band.height]
1756
- if (zone === 'right') return [band.right, 0, band.width - band.right, band.height]
1757
- return [band.left, 0, band.right - band.left, band.height]
1643
+ // Without a right edge — a page that suppresses the right column — the
1644
+ // centre band runs to the frame's own edge.
1645
+ const edge = band.right === null ? band.width : band.right
1646
+ if (zone === 'right') return [edge, 0, band.width - edge, band.height]
1647
+ return [band.left, 0, edge - band.left, band.height]
1758
1648
  }
1759
1649
 
1760
1650
  /**
@@ -1904,17 +1794,17 @@ window.__ModuleLoader__.load({
1904
1794
  }
1905
1795
 
1906
1796
  function drop(zone) {
1797
+ // Dock right only where DSH draws the right column: a page suppresses it,
1798
+ // and a tab opened into a column nobody draws is a tab nobody can see. A
1799
+ // dock asked for from a page lands in the centre instead.
1800
+ if (zone === 'right' && mainPanelOpen()) zone = 'centre'
1907
1801
  if (zone === 'right') {
1908
- dockingRight = true
1909
- // The float leaves as an ordinary right-sidebar tab. The sidebar
1910
- // snapshot belonged to the float: keeping it would let a close of that
1911
- // tab — possibly hours later — move the sidebars back in time.
1912
- savedChrome = null
1913
1802
  // Our window and the right-sidebar page are the same tab: the window
1914
1803
  // goes first, or it would outlive the page it was showing and sit there
1915
1804
  // blank while the tab moves underneath it.
1916
1805
  const shown = liveSession()
1917
1806
  if (shown !== null) {
1807
+ invokedThisRun.add(shown)
1918
1808
  // A re-hosted body keeps its React tree and loses the column's
1919
1809
  // bookkeeping with it; closing the tab first gives the page a fresh
1920
1810
  // body that attaches the column again.
@@ -2239,7 +2129,22 @@ window.__ModuleLoader__.load({
2239
2129
  const WINDOW_SCROLLBAR_THUMB_ATTR = 'data-dsh-conversation-float-window-scrollbar-thumb'
2240
2130
  const WINDOW_TITLE_ATTR = 'data-dsh-conversation-float-window-title'
2241
2131
  const WINDOW_HIDE_PANE_ATTR = 'data-dsh-conversation-float-hide-pane'
2132
+ /**
2133
+ * The key an older build used for a stored window rectangle.
2134
+ *
2135
+ * Nothing writes it any more: a float effect lives for the run that made it
2136
+ * and is not restored from a previous one. The prefix is kept only so the
2137
+ * startup pass can clear what earlier builds left behind.
2138
+ */
2242
2139
  const WINDOW_KEY = 'dsh-conversation-float.window.'
2140
+ /**
2141
+ * sessionId -> the rectangle the user dragged out in THIS run.
2142
+ *
2143
+ * Kept in memory on purpose. A window position is part of the float, and a
2144
+ * float is a temporary arrangement: opening DSH again starts with none, so
2145
+ * nothing from the last run may come back — not the window, not its place.
2146
+ */
2147
+ const windowRects = new Map()
2243
2148
  /**
2244
2149
  * One per-Session content epoch.
2245
2150
  *
@@ -2271,6 +2176,16 @@ window.__ModuleLoader__.load({
2271
2176
 
2272
2177
  /** sessionId -> { el, body, title, header, resizer, rect } */
2273
2178
  const windows = new Map()
2179
+ /**
2180
+ * Sessions whose float the user asked for in THIS run.
2181
+ *
2182
+ * DSH persists each Session's right sidebar to localStorage and restores it
2183
+ * on start. Our docked tab travels with that snapshot, so it can mount again
2184
+ * in a run that never opened it. Such a body is not a float the user asked
2185
+ * for: it closes its own tab before it can move the Conversation into a
2186
+ * hidden page, which is how "the last float came back on click" is fixed.
2187
+ */
2188
+ const invokedThisRun = new Set()
2274
2189
  /**
2275
2190
  * The band the float windows live in.
2276
2191
  *
@@ -2288,22 +2203,30 @@ window.__ModuleLoader__.load({
2288
2203
  const WINDOW_Z_TOP = 900
2289
2204
 
2290
2205
  function readWindowRect(sessionId) {
2291
- try {
2292
- const raw = window.localStorage.getItem(WINDOW_KEY + sessionId)
2293
- if (raw === null) return null
2294
- const r = JSON.parse(raw)
2295
- if (!r || typeof r.x !== 'number' || typeof r.y !== 'number' || typeof r.width !== 'number' || typeof r.height !== 'number') return null
2296
- return r
2297
- } catch {
2298
- return null
2299
- }
2206
+ const rect = windowRects.get(sessionId)
2207
+ if (rect === undefined) return null
2208
+ return { ...rect }
2300
2209
  }
2301
2210
 
2302
2211
  function writeWindowRect(sessionId, rect) {
2212
+ windowRects.set(sessionId, { ...rect })
2213
+ capSessionMap(windowRects, 64)
2214
+ }
2215
+
2216
+ /**
2217
+ * Drop every rectangle an earlier build stored before rectangles became
2218
+ * per-run. Left in place, those records would be the only float state that
2219
+ * outlived a restart; the startup pass removes them once.
2220
+ */
2221
+ function clearStoredWindowRects() {
2303
2222
  try {
2304
- window.localStorage.setItem(WINDOW_KEY + sessionId, JSON.stringify(rect))
2223
+ const store = window.localStorage
2224
+ for (let index = store.length - 1; index >= 0; index -= 1) {
2225
+ const key = store.key(index)
2226
+ if (key !== null && key.startsWith(WINDOW_KEY)) store.removeItem(key)
2227
+ }
2305
2228
  } catch {
2306
- /* a full quota must not break the float */
2229
+ /* storage may be unavailable; nothing to clear then */
2307
2230
  }
2308
2231
  }
2309
2232
 
@@ -2351,8 +2274,11 @@ window.__ModuleLoader__.load({
2351
2274
 
2352
2275
  function defaultWindowRect() {
2353
2276
  const top = windowTopInset()
2354
- const width = Math.min(920, Math.round(window.innerWidth * 0.62))
2355
- const height = Math.min(720, Math.round((window.innerHeight - top) * 0.86))
2277
+ // The float's long-standing size, now the default for the window of our
2278
+ // own: 450 x 720 by request, never wider or taller than the room the
2279
+ // application window leaves around it.
2280
+ const width = Math.max(320, Math.min(450, window.innerWidth - 80))
2281
+ const height = Math.max(320, Math.min(720, window.innerHeight - 80))
2356
2282
  return clampRect({
2357
2283
  x: Math.round((window.innerWidth - width) / 2),
2358
2284
  y: Math.round(top + (window.innerHeight - top - height) / 2),
@@ -2651,7 +2577,7 @@ window.__ModuleLoader__.load({
2651
2577
  // which travels with the column, is the only copy of that switch.
2652
2578
  const chip = switchChip(() => switchToWindow(sessionId))
2653
2579
  header.appendChild(chip)
2654
- header.appendChild(windowButton(t('minimize'), '—', () => hideWindow(sessionId)))
2580
+ header.appendChild(windowButton(t('minimize'), '—', () => minimiseWindow(sessionId)))
2655
2581
  header.appendChild(windowButton(t('close'), '✕', () => closeWindow(sessionId)))
2656
2582
  const scrollbar = document.createElement('div')
2657
2583
  scrollbar.setAttribute(WINDOW_SCROLLBAR_ATTR, '')
@@ -2736,6 +2662,15 @@ window.__ModuleLoader__.load({
2736
2662
  win.resizer.addEventListener('pointercancel', settled)
2737
2663
  }
2738
2664
 
2665
+ /** The page filling the main column, or null while the Conversation has it. */
2666
+ function currentPanel() {
2667
+ try {
2668
+ return layout?.panelInfo?.getSnapshot?.()?.activePanelId ?? null
2669
+ } catch {
2670
+ return null
2671
+ }
2672
+ }
2673
+
2739
2674
  /**
2740
2675
  * Make another Conversation the one on screen.
2741
2676
  *
@@ -2743,9 +2678,23 @@ window.__ModuleLoader__.load({
2743
2678
  * and both columns move together — the same call the sidebar's session rows
2744
2679
  * make. The window then re-decides its own mode on the next layout pass, and
2745
2680
  * the real column, header and composer follow it in.
2681
+ *
2682
+ * From a page, DSH's switch is half wrong: `openSession` selects the Session
2683
+ * AND reveals the Conversation, which closes the page the user is working in.
2684
+ * A switch made here must trade the live Conversation and leave the page
2685
+ * where it is — the same thing the user gets by opening the page while this
2686
+ * Session is already the current one. So the page is read first and put back
2687
+ * in the same tick: `openSession` runs its `selectPanel(null)` synchronously,
2688
+ * and no React render can happen between two writes of one JavaScript task,
2689
+ * so the slot never actually empties and the page never unmounts.
2690
+ *
2691
+ * A rescue row is the exception: its whole promise is "take me back to that
2692
+ * Conversation", so it passes `keepPage = false` and lets the page close.
2746
2693
  */
2747
- function switchToWindow(sessionId) {
2694
+ function switchToWindow(sessionId, keepPage = true) {
2695
+ const page = keepPage && mainPanelOpen() ? currentPanel() : null
2748
2696
  let switched = false
2697
+ let threw = false
2749
2698
  try {
2750
2699
  const workspace = typeof ctxRef?.get === 'function' ? ctxRef.get('uiWorkspace') : null
2751
2700
  if (workspace !== null && workspace !== undefined && typeof workspace.openSession === 'function') {
@@ -2753,10 +2702,22 @@ window.__ModuleLoader__.load({
2753
2702
  switched = true
2754
2703
  }
2755
2704
  } catch (error) {
2705
+ threw = true
2756
2706
  report('[conversation-float] could not switch the conversation:', error)
2757
2707
  }
2708
+ if (page !== null) {
2709
+ // Same tick as the switch, and never skipped on the failure path: a
2710
+ // switch that threw may still have closed the panel.
2711
+ try {
2712
+ layout?.selectPanel?.(page)
2713
+ } catch (error) {
2714
+ report('[conversation-float] could not put the page back:', error)
2715
+ }
2716
+ }
2758
2717
  if (!switched) {
2759
- report('[conversation-float] no uiWorkspace service to switch the Session')
2718
+ // A throw already said what went wrong; the missing-service line is for
2719
+ // the other way this fails, so the two never stack into noise.
2720
+ if (!threw) report('[conversation-float] no uiWorkspace service to switch the Session')
2760
2721
  return
2761
2722
  }
2762
2723
  raiseWindow(sessionId)
@@ -2767,6 +2728,12 @@ window.__ModuleLoader__.load({
2767
2728
  // delays could all fire before the column moved, or long after.
2768
2729
  notifyLayout()
2769
2730
  refreshSwitchChips()
2731
+ // The wait below is "until the column shows the Session we switched to".
2732
+ // A page keeps the column home and leaves it showing nothing, so there is
2733
+ // no such change to wait for: the pass above already moved the window to
2734
+ // the full local Conversation, and a frame loop here would only burn
2735
+ // frames for two and a half seconds.
2736
+ if (page !== null) return
2770
2737
  let lastSeen = '__start__'
2771
2738
  untilFrame(() => {
2772
2739
  const column = findColumn()
@@ -2796,10 +2763,47 @@ window.__ModuleLoader__.load({
2796
2763
  bumpContentEpoch(sessionId)
2797
2764
  // The body mounts with the window: one frame later is when it can report
2798
2765
  // how tall the transcript really is.
2799
- requestAnimationFrame(() => syncScrollbar(win))
2766
+ requestAnimationFrame(() => {
2767
+ syncScrollbar(win)
2768
+ scheduleRescueSync()
2769
+ })
2800
2770
  return win
2801
2771
  }
2802
2772
 
2773
+ /**
2774
+ * The title bar's dash: put this window away.
2775
+ *
2776
+ * A window that had hidden the rest of DSH left the screen behind nothing
2777
+ * when it went away — a blank page with no key but Escape. So the dash also
2778
+ * ends the hidden arrangement: the interface comes back and both bars are
2779
+ * put away, which leaves the left taskbar row as the way to the window.
2780
+ */
2781
+ function minimiseWindow(sessionId) {
2782
+ // "Alone" is the state the blank screen comes from: the interface is
2783
+ // hidden AND this was the last window on it. With another window still up
2784
+ // there is something to see, and revealing DSH would undo a choice the
2785
+ // hand did not make.
2786
+ let another = false
2787
+ for (const [id, win] of windows) {
2788
+ if (id === sessionId || win.el.hidden) continue
2789
+ another = true
2790
+ break
2791
+ }
2792
+ const wasAlone = chromeless && !another
2793
+ hideWindow(sessionId)
2794
+ if (!wasAlone) {
2795
+ notifyState()
2796
+ return
2797
+ }
2798
+ setChromeless(false)
2799
+ // A window that was the only thing on screen leaves nothing behind: the
2800
+ // interface is back and both bars are put away, so the taskbar row is the
2801
+ // way in. This is a fixed arrangement the hand asked for, not a captured
2802
+ // one.
2803
+ applyChromeTarget({ leftCollapsed: true, rightExpanded: false })
2804
+ notifyState()
2805
+ }
2806
+
2803
2807
  function hideWindow(sessionId) {
2804
2808
  const win = windows.get(sessionId)
2805
2809
  if (win === undefined) return
@@ -2842,6 +2846,7 @@ window.__ModuleLoader__.load({
2842
2846
  win.el.remove()
2843
2847
  queueMicrotask(syncTaskbar)
2844
2848
  refreshSwitchChips()
2849
+ scheduleRescueSync()
2845
2850
  }
2846
2851
 
2847
2852
  /**
@@ -2930,6 +2935,211 @@ window.__ModuleLoader__.load({
2930
2935
  }
2931
2936
  }
2932
2937
 
2938
+ /* ------------------------------------- the collapsed right bar's way back */
2939
+
2940
+ /**
2941
+ * DSH stores each Session's right-sidebar surface under this prefix.
2942
+ *
2943
+ * A Session's panel is drawn only while that Session is on screen, so from
2944
+ * another Session the DOM cannot answer "is that Session's bar railed?".
2945
+ * The stored surface carries exactly that: the tabs with their kind, which
2946
+ * pane hosts them (dock or float), and that Session's own `expanded` flag.
2947
+ */
2948
+ const SIDEBAR_SURFACE_KEY = 'dsh.sidebar-right.v1.'
2949
+
2950
+ /** sessionId -> the left row that recalls a docked page while its right bar is railed. */
2951
+ const rescueRows = new Map()
2952
+ /** Sessions whose restored tab this run has already asked to close. */
2953
+ const restoredCleared = new Set()
2954
+ /** Set while a rescue-row sync is already waiting for the next frame. */
2955
+ let rescueSyncQueued = false
2956
+ /** Set once this plugin instance is gone: a queued sync must not register anew. */
2957
+ let rescueSyncOff = false
2958
+
2959
+ function scheduleRescueSync() {
2960
+ if (rescueSyncQueued || rescueSyncOff) return
2961
+ rescueSyncQueued = true
2962
+ window.requestAnimationFrame(() => {
2963
+ rescueSyncQueued = false
2964
+ if (rescueSyncOff) return
2965
+ try { syncRescueRows() } catch (error) { report('[conversation-float] rescue rows failed:', error) }
2966
+ })
2967
+ }
2968
+
2969
+ /** One Session's stored right-sidebar layout, or null when it has none. */
2970
+ function storedSidebarLayout(sessionId) {
2971
+ try {
2972
+ const raw = window.localStorage.getItem(SIDEBAR_SURFACE_KEY + sessionId)
2973
+ if (raw === null) return null
2974
+ const saved = JSON.parse(raw)?.bySession?.[sessionId]
2975
+ if (saved === null || saved === undefined) return null
2976
+ return typeof saved.layout === 'object' && saved.layout !== null ? saved.layout : null
2977
+ } catch (error) {
2978
+ return null
2979
+ }
2980
+ }
2981
+
2982
+ /** Whether a stored surface holds OUR tab as a docked page. */
2983
+ function storedDockHoldsOurs(layout) {
2984
+ if (layout === null || typeof layout !== 'object') return false
2985
+ const tabs = layout.tabs
2986
+ if (tabs === null || tabs === undefined || typeof tabs !== 'object') return false
2987
+ let ours = null
2988
+ for (const tabId of Object.keys(tabs)) {
2989
+ if (tabs[tabId]?.kind === CHAT_KIND) { ours = tabId; break }
2990
+ }
2991
+ if (ours === null) return false
2992
+ const nodes = layout.nodes
2993
+ if (nodes === null || nodes === undefined || typeof nodes !== 'object') return false
2994
+ for (const nodeId of Object.keys(nodes)) {
2995
+ const node = nodes[nodeId]
2996
+ if (node === null || node === undefined || node.kind !== 'pane') continue
2997
+ if (node.host !== 'dock') continue
2998
+ if (!Array.isArray(node.tabs)) continue
2999
+ if (node.tabs.includes(ours)) return true
3000
+ }
3001
+ return false
3002
+ }
3003
+
3004
+ /**
3005
+ * Sessions whose docked Conversation this run put in a railed right bar.
3006
+ *
3007
+ * The run gate is the whole of "no float outlives a restart": a dock carried
3008
+ * in DSH's own snapshot from an earlier run is not this run's arrangement,
3009
+ * even though it is still stored.
3010
+ *
3011
+ * A page owns the main slot without touching any Session's stored right
3012
+ * bar, so a railed dock behind a page is still a railed dock: the row stays
3013
+ * on screen there, or the page would hide the only way back to it.
3014
+ */
3015
+ function storedRaisedDocks() {
3016
+ const out = []
3017
+ try {
3018
+ const store = window.localStorage
3019
+ for (let index = 0; index < store.length; index += 1) {
3020
+ const key = store.key(index)
3021
+ if (key === null || !key.startsWith(SIDEBAR_SURFACE_KEY)) continue
3022
+ const sessionId = key.slice(SIDEBAR_SURFACE_KEY.length)
3023
+ if (sessionId === '' || windows.has(sessionId)) continue
3024
+ if (!invokedThisRun.has(sessionId)) continue
3025
+ const layout = storedSidebarLayout(sessionId)
3026
+ if (layout === null || layout.expanded === true) continue
3027
+ if (!storedDockHoldsOurs(layout)) continue
3028
+ out.push(sessionId)
3029
+ }
3030
+ } catch (error) {
3031
+ report('[conversation-float] could not read the stored right sidebar:', error)
3032
+ }
3033
+ return out
3034
+ }
3035
+
3036
+ /**
3037
+ * Close a tab DSH restored from a previous run, before its page can take the
3038
+ * Conversation. Only the Session on screen has a mounted surface to close in.
3039
+ */
3040
+ function clearRestoredDock(sessionId) {
3041
+ if (sessionId === null || invokedThisRun.has(sessionId)) return
3042
+ if (restoredCleared.has(sessionId)) return
3043
+ if (tabIdFor(sessionId) === null) return
3044
+ restoredCleared.add(sessionId)
3045
+ queueMicrotask(() => {
3046
+ try {
3047
+ closeTabFor(sessionId)
3048
+ } catch (error) {
3049
+ report('[conversation-float] could not clear a restored tab:', error)
3050
+ }
3051
+ })
3052
+ }
3053
+
3054
+ /**
3055
+ * Keep one left-sidebar row per docked Conversation whose own right bar is
3056
+ * railed. The row is the only key such a page has: collapsing the bar hides
3057
+ * the tab strip, the page and the Conversation with it — and the panel is
3058
+ * not even drawn once another Session takes the screen, or once a page
3059
+ * outside the conversation suppresses the right column. The row stays.
3060
+ */
3061
+ function syncRescueRows() {
3062
+ if (ctxRef === null) return
3063
+ clearRestoredDock(liveSession())
3064
+ const wanted = new Map()
3065
+ for (const sessionId of storedRaisedDocks()) {
3066
+ wanted.set(sessionId, sessionTitle(sessionId) ?? t('floatTitle'))
3067
+ }
3068
+ for (const [sessionId, entry] of [...rescueRows]) {
3069
+ if (wanted.get(sessionId) === entry.label) continue
3070
+ rescueRows.delete(sessionId)
3071
+ try { entry.dispose() } catch { /* the slot may be gone */ }
3072
+ }
3073
+ for (const [sessionId, label] of wanted) {
3074
+ if (rescueRows.has(sessionId)) continue
3075
+ try {
3076
+ const dispose = ctxRef.slots.register(
3077
+ { name: 'sidebar.panellist', id: RESCUE_ID + sessionId, order: 21, label: () => label },
3078
+ makeRescueIcon(sessionId),
3079
+ )
3080
+ rescueRows.set(sessionId, { label, dispose })
3081
+ } catch (error) {
3082
+ report('[conversation-float] could not register the rescue row:', error)
3083
+ }
3084
+ }
3085
+ }
3086
+
3087
+ /**
3088
+ * Bring one Session's railed right bar back onto the screen, EXPANDING it.
3089
+ *
3090
+ * The row's promise is "switch to this Conversation and show it", not "flip
3091
+ * the bar": a bar that is already expanded must not collapse under a press
3092
+ * that was meant to reveal the Conversation.
3093
+ */
3094
+ function expandBarFor(sessionId) {
3095
+ const layout = storedSidebarLayout(sessionId)
3096
+ if (layout !== null && layout.expanded === true) return
3097
+ // The expand control rides the Conversation header of the Session on
3098
+ // screen; after the switch it belongs to this Session.
3099
+ const expand = document.querySelector('[data-sidebar-right-expand]')
3100
+ if (expand instanceof HTMLElement) {
3101
+ try { expand.click(); return } catch { /* the button may be mid-swap */ }
3102
+ }
3103
+ // No header control (the Conversation header is not drawn): only this
3104
+ // Session's own railed panel may open, never a bar that is already open.
3105
+ const panel = document.querySelector(`[data-sidebar-right-session="${sessionId}"][data-sidebar-right-panel]`)
3106
+ if (panel === null || panel.getAttribute('data-sidebar-right-open') !== null) return
3107
+ try {
3108
+ sidebarRight?.toggleExpanded?.()
3109
+ } catch (error) {
3110
+ report('[conversation-float] could not expand the right sidebar:', error)
3111
+ }
3112
+ }
3113
+
3114
+ /**
3115
+ * The left rescue row's press: that Session on screen, its right bar open.
3116
+ *
3117
+ * The expand control belongs to whichever Conversation header is on screen,
3118
+ * so it has to wait for the switch to land — firing it before the commit
3119
+ * would expand the previous Session's bar, or skip this one.
3120
+ */
3121
+ function rescueDocked(sessionId) {
3122
+ // Pressed from a page, the row means "take me back to that Conversation":
3123
+ // the page has to give way for the dock to be shown. The ordinary switch
3124
+ // keeps the page; this is the one exception.
3125
+ switchToWindow(sessionId, false)
3126
+ untilFrame(
3127
+ () => {
3128
+ const column = findColumn()
3129
+ return column !== null && columnSession(column) === sessionId
3130
+ },
3131
+ () => {
3132
+ expandBarFor(sessionId)
3133
+ scheduleRescueSync()
3134
+ },
3135
+ 2000,
3136
+ () => {
3137
+ expandBarFor(sessionId)
3138
+ scheduleRescueSync()
3139
+ },
3140
+ )
3141
+ }
3142
+
2933
3143
  /**
2934
3144
  * A taskbar row is DSH's own main-panel button: selecting it replaces the
2935
3145
  * central entry, which would take a plugin or automation page away. When a
@@ -2937,10 +3147,20 @@ window.__ModuleLoader__.load({
2937
3147
  * the page must stay where it is.
2938
3148
  */
2939
3149
  function taskbarRowPress(event) {
3150
+ // Any press may have railed or unrailed the right bar: a cheap check that
3151
+ // follows the click is what keeps the rescue row in step with the bar.
3152
+ scheduleRescueSync()
2940
3153
  const target = event.target
2941
3154
  if (!(target instanceof Element)) return
2942
- const row = target.closest(`button[${ROW_MARK_ATTR}]`)
3155
+ const row = target.closest(`button[${ROW_MARK_ATTR}], button[${RESCUE_ATTR}]`)
2943
3156
  if (row === null) return
3157
+ const rescueId = row.getAttribute(RESCUE_ATTR)
3158
+ if (rescueId !== null && rescueId !== '') {
3159
+ event.preventDefault()
3160
+ event.stopPropagation()
3161
+ rescueDocked(rescueId)
3162
+ return
3163
+ }
2944
3164
  const sessionId = row.getAttribute(ROW_MARK_ATTR)
2945
3165
  if (sessionId === null || sessionId === '') return
2946
3166
  event.preventDefault()
@@ -3003,6 +3223,11 @@ window.__ModuleLoader__.load({
3003
3223
  .dsw-menu-row:hover { background: var(--dsw-alias-bg-layer-2); }
3004
3224
  .dsw-menu-row:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }
3005
3225
  .dsw-icon:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
3226
+ /* The rescue row wears DSH's right-panel glyph, mirrored exactly like the
3227
+ right sidebar's own expand/collapse controls. */
3228
+ [data-dsh-conversation-float-rescue][data-dsh-conversation-float-rescue-icon="panel"] svg {
3229
+ transform: scaleX(-1);
3230
+ }
3006
3231
  .dsw-host {
3007
3232
  position: relative;
3008
3233
  display: flex; flex-direction: column;
@@ -3188,6 +3413,32 @@ window.__ModuleLoader__.load({
3188
3413
  }
3189
3414
  }
3190
3415
 
3416
+ /**
3417
+ * The glyph of a rescue row.
3418
+ *
3419
+ * DSH's own right-sidebar glyph, not our window: the header's expand
3420
+ * control uses the panel-left outline mirrored, so the row matches the
3421
+ * control it stands in for. A host without primitives falls back to the
3422
+ * window glyph, and the stylesheet mirrors only the real one.
3423
+ */
3424
+ function makeRescueIcon(sessionId) {
3425
+ return function RescueIcon({ size = 16 }) {
3426
+ const ref = React.useRef(null)
3427
+ React.useLayoutEffect(() => {
3428
+ const icon = ref.current
3429
+ const row = icon === null ? null : icon.closest('button')
3430
+ if (row !== null) {
3431
+ row.setAttribute(RESCUE_ATTR, sessionId)
3432
+ // Lets a probe — and the mirror rule below — tell DSH's glyph
3433
+ // apart from the fallback a host without primitives gets.
3434
+ row.setAttribute('data-dsh-conversation-float-rescue-icon', PanelLeftIcon === null ? 'window' : 'panel')
3435
+ }
3436
+ })
3437
+ const glyph = PanelLeftIcon === null ? h(Icon, { name: 'window', size }) : h(PanelLeftIcon, { size })
3438
+ return h('span', { ref, style: { display: 'contents' } }, glyph)
3439
+ }
3440
+ }
3441
+
3191
3442
  /**
3192
3443
  * The floating tab's body.
3193
3444
  *
@@ -3244,6 +3495,8 @@ window.__ModuleLoader__.load({
3244
3495
  sessionRef.current = sessionId
3245
3496
  let disposed = false
3246
3497
  let seenPane = null
3498
+ /** Set once this body has asked for its own tab to be closed. */
3499
+ let closing = false
3247
3500
  const onEpoch = (id) => {
3248
3501
  if (id === sessionRef.current) setEpoch((value) => value + 1)
3249
3502
  }
@@ -3257,6 +3510,23 @@ window.__ModuleLoader__.load({
3257
3510
  if (disposed) return
3258
3511
  const el = host.current
3259
3512
  if (el === null) return
3513
+ // DSH restores a Session's right sidebar from localStorage, and our
3514
+ // docked tab is part of that snapshot. A body mounting in a run that
3515
+ // never asked for this float is the previous run's arrangement coming
3516
+ // back; closing the tab is what keeps it from outliving a restart.
3517
+ if (!closing && sessionId !== null && !invokedThisRun.has(sessionId) && tabIdFor(sessionId) !== null) {
3518
+ closing = true
3519
+ // Deferred out of the commit that is mounting this body: a store
3520
+ // write here would unmount the tab from inside its own layout pass.
3521
+ queueMicrotask(() => {
3522
+ try {
3523
+ closeTabFor(sessionId)
3524
+ } catch (error) {
3525
+ report('[conversation-float] could not clear a restored tab:', error)
3526
+ }
3527
+ })
3528
+ return
3529
+ }
3260
3530
  const pane = el.closest('[' + FLOAT_ATTR + ']')
3261
3531
  const paneChanged = pane !== seenPane
3262
3532
  seenPane = pane
@@ -3335,7 +3605,7 @@ window.__ModuleLoader__.load({
3335
3605
  const page = mainPanelOpen() && (columnNow === null || columnSession(columnNow) === null)
3336
3606
  if (page && movedColumn !== null && win !== undefined && win.body.contains(movedColumn)) {
3337
3607
  try {
3338
- detachColumn(true)
3608
+ detachColumn()
3339
3609
  } catch (error) {
3340
3610
  report('[conversation-float] could not hand the page its column:', error)
3341
3611
  }
@@ -3485,7 +3755,7 @@ window.__ModuleLoader__.load({
3485
3755
  ctxRef = ctx
3486
3756
  // Build marker: lets a probe tell a re-imported client.js from the copy
3487
3757
  // the host still holds in memory (a page refresh does NOT reload it).
3488
- try { window.__dshFloatBuild = 'rowguard-0.2.7' } catch { /* no window yet */ }
3758
+ try { window.__dshFloatBuild = 'nosnapshot-0.3.3-r2' } catch { /* no window yet */ }
3489
3759
  ctx.effect(() => {
3490
3760
  try {
3491
3761
  return ctx.locale.register(NS, Object.fromEntries(LOCALES.map((id) => [id, { title: COPY[id].floatTitle, description: COPY[id].description }])))
@@ -3528,18 +3798,22 @@ window.__ModuleLoader__.load({
3528
3798
  if (typeof chromeApplyStop === 'function') chromeApplyStop()
3529
3799
  }
3530
3800
  window.addEventListener('pointerdown', onHand, true)
3801
+ // The right bar's own keyboard shortcut (primary+Backslash) is not a
3802
+ // click: a rescue row must still follow a bar collapsed that way.
3803
+ const onBarKey = (event) => {
3804
+ if (event.code !== 'Backslash' && event.key !== '\\') return
3805
+ if (!event.ctrlKey && !event.metaKey) return
3806
+ scheduleRescueSync()
3807
+ }
3808
+ window.addEventListener('keydown', onBarKey, true)
3531
3809
  return () => {
3532
3810
  window.removeEventListener('keydown', escapeOnKey, true)
3811
+ window.removeEventListener('keydown', onBarKey, true)
3533
3812
  document.removeEventListener('click', taskbarRowPress, true)
3534
3813
  window.removeEventListener('pointerdown', onHand, true)
3535
3814
  }
3536
3815
  })
3537
3816
 
3538
- // One frame after load, give any float already on screen its size.
3539
- ctx.effect(() => {
3540
- const id = window.requestAnimationFrame(() => sizeFloat())
3541
- return () => window.cancelAnimationFrame(id)
3542
- })
3543
3817
  // A reload can leave the last run's hidden columns behind.
3544
3818
  // An earlier build parked the View tab strip in the main window; put it
3545
3819
  // back inside the Conversation column and drop the parked container.
@@ -3554,6 +3828,24 @@ window.__ModuleLoader__.load({
3554
3828
  // A previous build hid the two shipped View buttons; put them back.
3555
3829
  for (const el of document.querySelectorAll('[data-dsh-conversation-float-core-tab]')) el.removeAttribute('data-dsh-conversation-float-core-tab')
3556
3830
  setChromeless(false)
3831
+ // No float effect outlives the run that made it: a rectangle an older
3832
+ // build stored is the only piece that could, and it goes now.
3833
+ clearStoredWindowRects()
3834
+ // A tab the previous run left in the current Session's stored surface is
3835
+ // closed as soon as that surface exists; untilFrame ends the moment it
3836
+ // does, so a normal boot pays one store read per frame for nothing.
3837
+ untilFrame(
3838
+ () => {
3839
+ const live = liveSession()
3840
+ return live !== null && tabIdFor(live) !== null
3841
+ },
3842
+ () => {
3843
+ clearRestoredDock(liveSession())
3844
+ scheduleRescueSync()
3845
+ },
3846
+ 3000,
3847
+ )
3848
+ scheduleRescueSync()
3557
3849
 
3558
3850
 
3559
3851
  ctx.effect(() => {
@@ -3675,6 +3967,12 @@ window.__ModuleLoader__.load({
3675
3967
  scanned: scanned === null ? null : columnSession(scanned),
3676
3968
  columns: document.querySelectorAll('[data-conversation-session]').length,
3677
3969
  windows: windows.size,
3970
+ rescue: {
3971
+ rows: rescueRows.size,
3972
+ sessions: [...rescueRows.keys()],
3973
+ cleared: [...restoredCleared],
3974
+ },
3975
+ invoked: [...invokedThisRun],
3678
3976
  compat: compatReport(),
3679
3977
  lastError: window.__dshFloatLastError ?? null,
3680
3978
  waits: pendingWaits.size,
@@ -3695,9 +3993,9 @@ window.__ModuleLoader__.load({
3695
3993
  get moved() {
3696
3994
  return movedColumn !== null
3697
3995
  },
3698
- /** What the sidebars restore is working from, for the test harness. */
3996
+ /** What the sidebar retry is working from, for the test harness. */
3699
3997
  get chrome() {
3700
- return { saved: savedChrome, chromeless, retrying: typeof chromeApplyStop === 'function' }
3998
+ return { chromeless, retrying: typeof chromeApplyStop === 'function' }
3701
3999
  },
3702
4000
  }
3703
4001
  // The probe is READ-ONLY unless a page asked for the harness. The
@@ -3711,7 +4009,11 @@ window.__ModuleLoader__.load({
3711
4009
  }
3712
4010
  ctx.effect(() => {
3713
4011
  window.addEventListener('resize', reclampWindows)
3714
- return () => window.removeEventListener('resize', reclampWindows)
4012
+ window.addEventListener('resize', scheduleRescueSync)
4013
+ return () => {
4014
+ window.removeEventListener('resize', reclampWindows)
4015
+ window.removeEventListener('resize', scheduleRescueSync)
4016
+ }
3715
4017
  })
3716
4018
 
3717
4019
  // The Session on screen is DSH's own state, and DSH publishes it: one
@@ -3776,10 +4078,13 @@ window.__ModuleLoader__.load({
3776
4078
  ctx.effect(() => () => {
3777
4079
  // Nothing this instance scheduled may outlive it: every wait is a
3778
4080
  // frame loop, and a frame loop left running holds a dead closure.
4081
+ rescueSyncOff = true
3779
4082
  cancelWaits()
3780
4083
  hidePreview()
3781
- // Unloading is not a user close: leave the sidebars alone.
3782
- suspendRestore = true
4084
+ for (const dispose of rescueRows.values()) {
4085
+ try { dispose() } catch { /* the slot may be gone */ }
4086
+ }
4087
+ rescueRows.clear()
3783
4088
  detachColumn()
3784
4089
  delete window.__dshSessionWindow
3785
4090
  })