@kabmo-labs/kabmo 0.46.0 → 0.46.1

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.
Files changed (111) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +1 -1
  3. package/dist/client/static/js/{CsvGrid-br4j001k.js → CsvGrid-qdkmv8bj.js} +1 -1
  4. package/dist/client/static/js/{DocxView-kmtkbmmw.js → DocxView-k84ns803.js} +1 -1
  5. package/dist/client/static/js/{DrawioView-3df0g3jr.js → DrawioView-r1n717f7.js} +1 -1
  6. package/dist/client/static/js/{ImageView-2r8p5z3y.js → ImageView-jkrdrq8v.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-rq3d2a4e.js → LayoutWrapper-sh634350.js} +2 -2
  8. package/dist/client/static/js/{Modal-tmxhxd6q.js → Modal-xe6h99jn.js} +1 -1
  9. package/dist/client/static/js/{PdfView-p5z7c7eg.js → PdfView-ffg4mccg.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-t06h6zfx.js → SessionsView-cdcbsee9.js} +1 -1
  11. package/dist/client/static/js/{SheetView-agw459v2.js → SheetView-89sscpz6.js} +1 -1
  12. package/dist/client/static/js/{SvgPreview-b9rfy1h6.js → SvgPreview-68c0ccbv.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-wbnhzcnj.js → abnfDiagram-O67JEVCF-h3a5s259.js} +1 -1
  14. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-t2sgevea.js → architectureDiagram-NJMV4G6O-983p0jgn.js} +1 -1
  15. package/dist/client/static/js/{blockDiagram-BEXU5L5S-v2nzp54a.js → blockDiagram-BEXU5L5S-16pse5mh.js} +1 -1
  16. package/dist/client/static/js/{c4Diagram-YGBWAQC7-7h03146b.js → c4Diagram-YGBWAQC7-mvnb00zt.js} +1 -1
  17. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-m57e9kp1.js → classDiagram-v2-NBCMYWYE-kmpd91xb.js} +1 -1
  18. package/dist/client/static/js/{cose-bilkent-JH36ORCC-c4tnh4mg.js → cose-bilkent-JH36ORCC-3ek5r5se.js} +1 -1
  19. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-mjf6njey.js → cynefinDiagram-VND7K2PF-jkbh84zn.js} +1 -1
  20. package/dist/client/static/js/{dagre-6A5THRUB-6yma9ch3.js → dagre-6A5THRUB-4fdc0sgn.js} +1 -1
  21. package/dist/client/static/js/{diagram-22UHCM2B-1q4ce2gb.js → diagram-22UHCM2B-hbk61nq9.js} +1 -1
  22. package/dist/client/static/js/{diagram-3UASUU5V-0ttps29p.js → diagram-3UASUU5V-hfpbr9qh.js} +1 -1
  23. package/dist/client/static/js/{diagram-ATOU4E4O-1mzexgv1.js → diagram-ATOU4E4O-fn0nt71a.js} +1 -1
  24. package/dist/client/static/js/{diagram-CDSNMT55-4ae89t23.js → diagram-CDSNMT55-ssswxjeb.js} +1 -1
  25. package/dist/client/static/js/{diagram-MLGK6HIB-057jaqvh.js → diagram-MLGK6HIB-whnzxv6f.js} +1 -1
  26. package/dist/client/static/js/{diagram-MPIPVDR6-p6yyq5sx.js → diagram-MPIPVDR6-hk1chzxk.js} +1 -1
  27. package/dist/client/static/js/{dockerfile-00hqsk9c.js → dockerfile-zmsj8r4g.js} +1 -1
  28. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-bsk7dvm4.js → ebnfDiagram-ZINNZB2B-q1vkg5mr.js} +1 -1
  29. package/dist/client/static/js/{elk-276RUBZZ-dsq91er5.js → elk-276RUBZZ-kt98vg8j.js} +1 -1
  30. package/dist/client/static/js/{erDiagram-OPXOYQCR-p7p13mbh.js → erDiagram-OPXOYQCR-ey3avsn9.js} +1 -1
  31. package/dist/client/static/js/flowDiagram-KWPJA3E3-7gvtpn3d.js +1 -0
  32. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-bwgnttyk.js → ganttDiagram-FUAMR5RP-a9k1at43.js} +1 -1
  33. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-ca0gj5am.js → gitGraphDiagram-X574FWY7-gnekjfym.js} +1 -1
  34. package/dist/client/static/js/{index-jkay7aw7.js → index-1ax52p0q.js} +1 -1
  35. package/dist/client/static/js/{index-064vdkrs.js → index-2a6qp9y6.js} +1 -1
  36. package/dist/client/static/js/{index-j718pxb3.js → index-3x7h2eqj.js} +1 -1
  37. package/dist/client/static/js/{index-amys498v.js → index-4cag7w6k.js} +131 -131
  38. package/dist/client/static/js/{index-ta6gpcpw.js → index-5ka2tyf9.js} +2 -2
  39. package/dist/client/static/js/{index-x1fqhhpp.js → index-60v30k5h.js} +2 -2
  40. package/dist/client/static/js/{index-5gf52a6d.js → index-65afr75v.js} +1 -1
  41. package/dist/client/static/js/{index-4bqssvt6.js → index-83rkg916.js} +1 -1
  42. package/dist/client/static/js/{index-aagt3382.js → index-84fyq5a6.js} +1 -1
  43. package/dist/client/static/js/{index-dr5hca5b.js → index-8g7q8mz4.js} +1 -1
  44. package/dist/client/static/js/{index-bjv5ga2e.js → index-9vv7wr1n.js} +1 -1
  45. package/dist/client/static/js/{index-pwe6chtp.js → index-amsa0tfs.js} +1 -1
  46. package/dist/client/static/js/{index-red856x6.js → index-atq9q1s7.js} +1 -1
  47. package/dist/client/static/js/{index-f7te27n5.js → index-b2e5pwx7.js} +1 -1
  48. package/dist/client/static/js/{index-ex5dtdx2.js → index-b5dfvget.js} +1 -1
  49. package/dist/client/static/js/{index-zedt16w7.js → index-bsr7wmj2.js} +1 -1
  50. package/dist/client/static/js/{index-k5zfzgez.js → index-c9e417cs.js} +1 -1
  51. package/dist/client/static/js/{index-3bf7r7z4.js → index-dt6q3rws.js} +4 -4
  52. package/dist/client/static/js/{index-29npynva.js → index-e9cxje00.js} +1 -1
  53. package/dist/client/static/js/{index-zq0qxb17.js → index-fzngzhww.js} +1 -1
  54. package/dist/client/static/js/{index-16sd19f0.js → index-hgzntg2j.js} +1 -1
  55. package/dist/client/static/js/{index-bafe7hmd.js → index-kb14dhrx.js} +1 -1
  56. package/dist/client/static/js/{index-qn200x1b.js → index-kbhrvep8.js} +6 -6
  57. package/dist/client/static/js/{index-eqhjs1yv.js → index-m4k054wz.js} +3 -3
  58. package/dist/client/static/js/{index-8pksqzwq.js → index-pavvxrsz.js} +1 -1
  59. package/dist/client/static/js/{index-95kese1h.js → index-q9ytjey8.js} +1 -1
  60. package/dist/client/static/js/{index-3qnjdjg2.js → index-vkqb4dnt.js} +1 -1
  61. package/dist/client/static/js/{index-7055hdx1.js → index-wrcdc9vz.js} +1 -1
  62. package/dist/client/static/js/{index-ncpwteyt.js → index-x9r7zfp4.js} +1 -1
  63. package/dist/client/static/js/{index-y2z8nsvw.js → index-xq5f3nxa.js} +1 -1
  64. package/dist/client/static/js/{index-gq5w5w8x.js → index-xwjbq003.js} +1 -1
  65. package/dist/client/static/js/{index-twsbv1yn.js → index-yf93db65.js} +1 -1
  66. package/dist/client/static/js/{index-9d3n04vb.js → index-ykm7a3cp.js} +2 -2
  67. package/dist/client/static/js/{index-5h8y54t6.js → index-z25ss7xj.js} +1 -1
  68. package/dist/client/static/js/{infoDiagram-VRGFBTTK-7q58qdf1.js → infoDiagram-VRGFBTTK-r1p25738.js} +1 -1
  69. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-9jmeszag.js → ishikawaDiagram-OU5B5YK6-afgrqdrt.js} +1 -1
  70. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-0d7xe845.js → journeyDiagram-ZHPQQLJL-hepa4wk7.js} +1 -1
  71. package/dist/client/static/js/{kanban-definition-PNTS6WVX-7p83rwdn.js → kanban-definition-PNTS6WVX-jysft8ya.js} +1 -1
  72. package/dist/client/static/js/{mermaid.core-hwhzw0wv.js → mermaid.core-0m90b0s8.js} +2 -2
  73. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-hy0rtr7t.js → mindmap-definition-NLK3R4M7-x2rrzpvr.js} +1 -1
  74. package/dist/client/static/js/one-dark-pro-09d8p5vy.js +1 -0
  75. package/dist/client/static/js/one-light-g3ednt6p.js +1 -0
  76. package/dist/client/static/js/{pegDiagram-GJSIUBJH-kd8t53tx.js → pegDiagram-GJSIUBJH-z7vb7f1z.js} +1 -1
  77. package/dist/client/static/js/{pieDiagram-5QR66LMP-h3x03f80.js → pieDiagram-5QR66LMP-jqv6v4e6.js} +1 -1
  78. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-y2b1ncbg.js → quadrantDiagram-O4NWA36T-w2h8yxrv.js} +1 -1
  79. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-x188rcxf.js → railroadDiagram-XR7U4H2S-nd09yac3.js} +1 -1
  80. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-g5e9fk17.js → requirementDiagram-PLB6GJNP-t61zxh5v.js} +1 -1
  81. package/dist/client/static/js/{rust-1v8xbxn9.js → rust-avnkhh0p.js} +1 -1
  82. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-y9ht91gf.js → sankeyDiagram-IPEJSGJF-2f7h2cmw.js} +1 -1
  83. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-pp8s63rt.js → sequenceDiagram-PO4LG4MO-kfb5d7zd.js} +1 -1
  84. package/dist/client/static/js/{sizeCapture-INFHLROL-k6dhfxex.js → sizeCapture-INFHLROL-amfg19se.js} +1 -1
  85. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-y3akpsm4.js → stateDiagram-v2-GCMORJYK-k5hx7btx.js} +1 -1
  86. package/dist/client/static/js/{swimlanes-2SLR337P-89081dr3.js → swimlanes-2SLR337P-wv3rp8kk.js} +1 -1
  87. package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-3q2a15wc.js → swimlanesDiagram-TC7HE7FX-6y8zdbm4.js} +1 -1
  88. package/dist/client/static/js/{timeline-definition-EJHVYXUP-tz6r8g3q.js → timeline-definition-EJHVYXUP-0re95wtn.js} +1 -1
  89. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-yq2y1b09.js → usecaseDiagram-POWQR4AR-yrje14qp.js} +1 -1
  90. package/dist/client/static/js/{vennDiagram-UO4OBE2U-qdmjf6x3.js → vennDiagram-UO4OBE2U-jxkmrfy5.js} +1 -1
  91. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-3n2sm7rj.js → wardleyDiagram-VNRHLVJA-d3v2m9b1.js} +1 -1
  92. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-d7n2av2t.js → xychartDiagram-PMCCYNJV-9a1s1rjt.js} +1 -1
  93. package/package.json +1 -1
  94. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
  95. package/src/client/components/layout/desktop-layout/RightColumn.test.tsx +204 -0
  96. package/src/client/components/layout/desktop-layout/RightColumn.tsx +37 -16
  97. package/src/client/components/mobile/RightSidebar.tsx +10 -8
  98. package/src/client/components/mobile/mobile-session-sidebar/use-drawer-tabs.ts +2 -1
  99. package/src/client/components/workspace/chat-timeline/MessageList.test.ts +11 -0
  100. package/src/client/components/workspace/chat-timeline/MessageList.tsx +29 -21
  101. package/src/client/hooks/chat/timeline/row-measure.ts +75 -0
  102. package/src/client/hooks/chat/timeline/row-window.test.ts +41 -21
  103. package/src/client/hooks/chat/timeline/row-window.ts +6 -24
  104. package/src/client/hooks/workspace/panel-tabs-reveal.test.tsx +20 -17
  105. package/src/client/hooks/workspace/panel-tabs-reveal.ts +29 -17
  106. package/src/client/hooks/workspace/panel-tabs.ts +3 -2
  107. package/src/client/hooks/workspace/session-state/index.test.tsx +145 -0
  108. package/src/client/hooks/workspace/session-state/index.ts +28 -16
  109. package/dist/client/static/js/flowDiagram-KWPJA3E3-7b4w6phx.js +0 -1
  110. package/dist/client/static/js/one-dark-pro-4b8er03c.js +0 -1
  111. package/dist/client/static/js/one-light-e6r3vsz4.js +0 -1
@@ -45,7 +45,7 @@ const nativeFetch = Bun.fetch;
45
45
  let container: HTMLElement;
46
46
 
47
47
  /** The column's props, driven from outside by the hook cases. */
48
- let column = { open: false, view: 'files', enabled: true, known: new Set(['files', 'git', 'todo']) };
48
+ let column = { open: false, storedView: 'files' as string | null, enabled: true, known: new Set(['files', 'git', 'todo']) };
49
49
  /** What the probe last rendered. */
50
50
  let seen: { tabs: readonly string[]; active: string | null; home: boolean; chosenHome: boolean } | null = null;
51
51
  /** The probe's writer, so a test can close a tab the way the strip does. */
@@ -56,7 +56,7 @@ function Probe() {
56
56
  useRevealPanelTab({
57
57
  enabled: column.enabled,
58
58
  revealed: useRevealEdge(column.open),
59
- view: column.view,
59
+ storedView: column.storedView,
60
60
  home: tabs.home,
61
61
  chosenHome: tabs.chosenHome,
62
62
  openTab: tabs.open,
@@ -114,7 +114,7 @@ afterAll(() => {
114
114
  beforeEach(() => {
115
115
  // The store is a module singleton: a tab left by one case would seed the next.
116
116
  resetSessionStateStore();
117
- column = { open: false, view: 'files', enabled: true, known: new Set(['files', 'git', 'todo']) };
117
+ column = { open: false, storedView: 'files', enabled: true, known: new Set(['files', 'git', 'todo']) };
118
118
  });
119
119
 
120
120
  afterEach(() => {
@@ -126,13 +126,13 @@ afterEach(() => {
126
126
  actions = null;
127
127
  });
128
128
 
129
- /** The rule, as data: only the reveal edge on a home page with a drawable view. */
129
+ /** The rule, as data: only the reveal edge on a home page with a view the session picked. */
130
130
  describe('revealTabId', () => {
131
131
  const base: RevealTabInput = {
132
132
  revealed: true,
133
133
  home: true,
134
134
  chosenHome: false,
135
- view: 'files',
135
+ storedView: 'files',
136
136
  known: new Set(['files', 'git']),
137
137
  enabled: true,
138
138
  };
@@ -165,8 +165,13 @@ describe('revealTabId', () => {
165
165
  test('a view this build cannot draw is not opened', () => {
166
166
  // Opening it would write an id `visiblePanelTabs` filters back out — a write
167
167
  // loop disguised as a sync.
168
- expect(revealTabId({ ...base, view: 'ghost' })).toBeNull();
169
- expect(revealTabId({ ...base, view: '' })).toBeNull();
168
+ expect(revealTabId({ ...base, storedView: 'ghost' })).toBeNull();
169
+ });
170
+
171
+ test('a session that never picked a view keeps its catalog', () => {
172
+ // The reported defect: a new chat's right drawer showed a `Files` tab on
173
+ // both layouts. The resolved fallback is not a pick.
174
+ expect(revealTabId({ ...base, storedView: null })).toBeNull();
170
175
  });
171
176
  });
172
177
 
@@ -212,23 +217,21 @@ describe('the column, mounted and toggled', () => {
212
217
  expect(seen).toEqual({ tabs: [], active: null, home: true, chosenHome: false });
213
218
  });
214
219
 
215
- test('putting the side away and bringing it back opens the stored view', async () => {
216
- // A session that has NEVER held a tab: the empty strip is the default home
217
- // page, not something the user chose, so the toggle brings its view back.
220
+ test('a session that never picked a view stays on its catalog', async () => {
221
+ // A fresh chat: the empty strip is its home page. Revealing the panel must
222
+ // not turn the `files` fallback into a tab — the reported defect on both
223
+ // layouts.
218
224
  currentSession = 'reveal-edge';
219
225
  hydrateSession(currentSession, {});
226
+ column.storedView = null;
220
227
  mount(currentSession);
221
228
  expect(seen).toEqual({ tabs: [], active: null, home: true, chosenHome: false });
222
229
 
223
230
  column.open = true;
224
231
  await rerender();
225
232
 
226
- expect(seen?.tabs).toEqual(['files']);
227
- expect(seen?.active).toBe('files');
228
- expect(seen?.home).toBe(false);
229
- // The write is the strip's own, so the persisted shape is a real tab.
230
- const stored = getSessionValue<{ tabs: string[]; active: string; home: boolean }>(currentSession, 'layout.rightPanelTabs');
231
- expect(stored).toEqual({ tabs: ['files'], active: 'files', home: false });
233
+ expect(seen).toEqual({ tabs: [], active: null, home: true, chosenHome: false });
234
+ expect(getSessionValue(currentSession, 'layout.rightPanelTabs')).toBeUndefined();
232
235
  });
233
236
 
234
237
  test('a tab closed by the user stays closed across a toggle', async () => {
@@ -257,7 +260,7 @@ describe('the column, mounted and toggled', () => {
257
260
  test('a column that already had a tab is only revealed, never re-opened', async () => {
258
261
  currentSession = 'reveal-existing';
259
262
  hydrateSession(currentSession, { 'layout.rightPanelTabs': { tabs: ['git'], active: 'git', home: false } });
260
- column.view = 'git';
263
+ column.storedView = 'git';
261
264
  mount(currentSession);
262
265
  expect(seen?.tabs).toEqual(['git']);
263
266
 
@@ -4,7 +4,8 @@
4
4
  */
5
5
 
6
6
  /**
7
- * A tab-style panel that is REVEALED shows a view, not its catalog.
7
+ * A tab-style panel that is REVEALED shows the view its session had, not its
8
+ * catalog — but a session that never picked a view keeps the catalog.
8
9
  *
9
10
  * A panel can be put away whole — the navbar's right-side toggle, the sidebar's
10
11
  * expand control, `⌥⌘J`, `⌘B`, and on a phone the same two header controls — and
@@ -17,8 +18,8 @@
17
18
  * opened `Resources` as a tab. Two clicks that both say "show me the panel" gave
18
19
  * two different answers, and the second one looked broken.
19
20
  *
20
- * So the rule is stated once, for every column and drawer, and it is a GESTURE,
21
- * not a state:
21
+ * So the rule is stated once, for every column and drawer, and it is a GESTURE
22
+ * over a STORED selection:
22
23
  *
23
24
  * - **Only a reveal counts.** Keying it on "the panel is open and on its home
24
25
  * page" would fight the `+` control: pressing it to browse the catalog would be
@@ -27,8 +28,12 @@
27
28
  * open — revealing it is enough.
28
29
  * - **A home page the user CHOSE is left alone.** Closing the last tab (or
29
30
  * pressing `+`) is an answer, not an absence: reopening the closed tab on the
30
- * next toggle is the defect this rule was extended for. Only a column that has
31
- * never held a tab is brought back on its view.
31
+ * next toggle is the defect this rule was extended for.
32
+ * - **A view the session never picked is not opened.** The resolved selection
33
+ * falls back to `files`, and that fallback is not a request: a fresh chat whose
34
+ * right drawer was opened from the header showed a `Files` tab on BOTH layouts
35
+ * — the reported defect — because the default was indistinguishable from the
36
+ * user's pick. With no stored view the catalog is the answer.
32
37
  * - **A view the panel cannot draw is not opened.** The stored selection can name
33
38
  * a panel that is switched off, uninstalled, or whose bundle has not loaded;
34
39
  * `open` would write an id `visiblePanelTabs` filters straight back out, which
@@ -53,12 +58,16 @@ export interface RevealTabInput {
53
58
  home: boolean;
54
59
  /**
55
60
  * The catalog is up because the user ASKED for it — `+`, or closing the last
56
- * tab. A reveal leaves that alone; only a column that never held a tab is
57
- * brought back on its view.
61
+ * tab. A reveal leaves that alone.
58
62
  */
59
63
  chosenHome: boolean;
60
- /** The view the panel would show — its stored selection. */
61
- view: string;
64
+ /**
65
+ * The view this SESSION stored, or `null` when it never picked one.
66
+ *
67
+ * The resolved fallback (`files`) is deliberately not accepted here: treating
68
+ * it as a pick is what opened the file explorer in every new chat.
69
+ */
70
+ storedView: string | null;
62
71
  /** Every id this panel could draw right now. */
63
72
  known: ReadonlySet<string>;
64
73
  /** Only the tab style has a home page to leave. */
@@ -66,14 +75,14 @@ export interface RevealTabInput {
66
75
  }
67
76
 
68
77
  /** The id a reveal must open, or `null` when there is nothing to do. */
69
- export function revealTabId({ revealed, home, chosenHome, view, known, enabled }: RevealTabInput): string | null {
78
+ export function revealTabId({ revealed, home, chosenHome, storedView, known, enabled }: RevealTabInput): string | null {
70
79
  if (!enabled || !revealed) return null;
71
80
  if (!home) return null;
72
81
  // Closing the last tab IS the answer. Reopening it on the next toggle is the
73
82
  // reported defect: the tab came back after the user had closed it.
74
83
  if (chosenHome) return null;
75
- if (!view || !known.has(view)) return null;
76
- return view;
84
+ if (!storedView || !known.has(storedView)) return null;
85
+ return storedView;
77
86
  }
78
87
 
79
88
  /**
@@ -127,8 +136,11 @@ export interface RevealPanelTabOptions {
127
136
  enabled: boolean;
128
137
  /** A reveal gesture landed on this render — see `useRevealEdge`. */
129
138
  revealed: boolean;
130
- /** The view to show when the strip has nothing on screen. */
131
- view: string;
139
+ /**
140
+ * The view THIS SESSION stored, or `null` when it never picked one. Not the
141
+ * resolved fallback: see `RevealTabInput.storedView`.
142
+ */
143
+ storedView: string | null;
132
144
  /** The panel's strip is showing its catalog. */
133
145
  home: boolean;
134
146
  /** The catalog was ASKED for (see `RevealTabInput.chosenHome`). */
@@ -153,10 +165,10 @@ export interface RevealPanelTabOptions {
153
165
  * `enabled` flag is what keeps rail panels out of it, where there is no home page
154
166
  * and the stored selection is already on screen.
155
167
  */
156
- export function useRevealPanelTab({ enabled, revealed, view, home, chosenHome, openTab, known }: RevealPanelTabOptions): void {
168
+ export function useRevealPanelTab({ enabled, revealed, storedView, home, chosenHome, openTab, known }: RevealPanelTabOptions): void {
157
169
  useEffect(() => {
158
170
  if (!openTab) return;
159
- const id = revealTabId({ revealed, home, chosenHome, view, known, enabled });
171
+ const id = revealTabId({ revealed, home, chosenHome, storedView, known, enabled });
160
172
  if (id !== null) openTab(id);
161
- }, [enabled, revealed, home, chosenHome, view, known, openTab]);
173
+ }, [enabled, revealed, home, chosenHome, storedView, known, openTab]);
162
174
  }
@@ -86,8 +86,9 @@ interface ColumnTabs {
86
86
  * differ from the rail's default (which opens `Files`). A rail has to show
87
87
  * something — a column with no view is a column of buttons over nothing — while
88
88
  * a strip's empty state is its catalog, which is a real answer. So the stored
89
- * `layout.activeRightPanel` (`files`) does NOT seed a tab; only an explicit
90
- * request does (`useRightOpenRequest`).
89
+ * `layout.activeRightPanel` (`files`) does NOT seed a tab by itself: only an
90
+ * explicit request (`useRightOpenRequest`), or a reveal of a session that had
91
+ * already picked a view (`panel-tabs-reveal`), opens one.
91
92
  */
92
93
  const EMPTY: ColumnTabs = { tabs: [], active: null, home: false };
93
94
 
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A per-session slot is never painted under another session's id.
8
+ *
9
+ * The reported defect: a fresh chat opened with the `Files` right-panel tab
10
+ * already in its strip, on both the phone and the desktop. The strip mirrors its
11
+ * selection into `layout.activeRightPanel`, and a switch renders once before the
12
+ * new session's blob lands — with the OLD session's local copy still in the
13
+ * hook. That commit wrote the old strip into the new session, where the (empty)
14
+ * blob then merged under it.
15
+ *
16
+ * So the claim is about the RENDER, not the store: after a switch, no commit may
17
+ * expose the previous session's value under the new id.
18
+ */
19
+
20
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
21
+ import { Window } from 'happy-dom';
22
+ import { h, render } from 'preact';
23
+ import { act } from 'preact/test-utils';
24
+ import { SessionStateProvider } from '@/client/components/common/session-state-provider/index';
25
+ import { useSessionState } from '@/client/hooks/workspace/session-state';
26
+ import { useSessionStateContext } from '@/client/hooks/workspace/session-state/context';
27
+ import {
28
+ getSessionState,
29
+ hydrateSession,
30
+ resetSessionStateStore,
31
+ } from '@/shared/lib/workspace/session-state/store';
32
+
33
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'Event', 'MouseEvent', 'KeyboardEvent'] as const;
34
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
35
+ const nativeFetch = Bun.fetch;
36
+
37
+ let container: HTMLElement;
38
+ /** Every commit's `(session, value)`, so a stale one cannot hide behind the last. */
39
+ let renders: Array<{ session: string; panel: string }> = [];
40
+
41
+ function Probe() {
42
+ const { sessionId } = useSessionStateContext();
43
+ const [panel] = useSessionState<string>('layout.activeRightPanel', 'files');
44
+ renders.push({ session: sessionId, panel });
45
+ return h('div', null, panel);
46
+ }
47
+
48
+ beforeAll(() => {
49
+ const win = new Window({ url: 'http://localhost' });
50
+ const target = globalThis as unknown as Record<string, unknown>;
51
+ for (const key of DOM_GLOBALS) {
52
+ if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
53
+ target[key] = (win as unknown as Record<string, unknown>)[key];
54
+ }
55
+ // Answer with the SESSION's own entry, so a load landing mid-test cannot
56
+ // adopt an empty blob over the value `hydrateSession` seeded.
57
+ target.fetch = async (input: unknown, init?: { method?: string }) => {
58
+ const method = init?.method ?? 'GET';
59
+ const sessionId = String(input).split('/sessions/')[1]?.split('/')[0] ?? 'x';
60
+ if (method === 'POST') return new Response(JSON.stringify({ success: true }), { status: 200 });
61
+ return new Response(
62
+ JSON.stringify({ sessionId, state: { ...(getSessionState(sessionId) ?? {}) } }),
63
+ { status: 200 },
64
+ );
65
+ };
66
+ });
67
+
68
+ afterAll(() => {
69
+ const target = globalThis as unknown as Record<string, unknown>;
70
+ for (const key of DOM_GLOBALS) {
71
+ if (nativeGlobals[key] === undefined) delete target[key];
72
+ else target[key] = nativeGlobals[key];
73
+ }
74
+ target.fetch = nativeFetch;
75
+ });
76
+
77
+ beforeEach(() => {
78
+ resetSessionStateStore();
79
+ renders = [];
80
+ container = document.createElement('div');
81
+ document.body.appendChild(container);
82
+ });
83
+
84
+ afterEach(() => {
85
+ render(null, container);
86
+ container.remove();
87
+ });
88
+
89
+ /** Render the provider on a session id and drain the load's promise chain. */
90
+ async function show(sessionId: string) {
91
+ await act(async () => {
92
+ render(h(SessionStateProvider, { sessionId, children: h(Probe, null) }), container);
93
+ });
94
+ for (let i = 0; i < 20; i += 1) await act(async () => {});
95
+ }
96
+
97
+ describe('useSessionState across a session switch', () => {
98
+ test('the previous session value is never rendered under the new id', async () => {
99
+ hydrateSession('s-prev', { 'layout.activeRightPanel': 'git' });
100
+ await show('s-prev');
101
+ expect(renders.at(-1)).toEqual({ session: 's-prev', panel: 'git' });
102
+
103
+ renders = [];
104
+ await show('s-fresh');
105
+
106
+ // The switch commit itself used to carry `git` — the old chat's pick — and
107
+ // every mirror-on-render then wrote it into the fresh session.
108
+ expect(renders.filter((r) => r.session === 's-fresh' && r.panel !== 'files')).toEqual([]);
109
+ expect(renders.at(-1)).toEqual({ session: 's-fresh', panel: 'files' });
110
+ });
111
+
112
+ test('a session with its own stored value shows that value, not the previous one', async () => {
113
+ hydrateSession('s-prev', { 'layout.activeRightPanel': 'git' });
114
+ hydrateSession('s-owns', { 'layout.activeRightPanel': 'todo' });
115
+ await show('s-prev');
116
+
117
+ renders = [];
118
+ await show('s-owns');
119
+ expect(renders.at(-1)).toEqual({ session: 's-owns', panel: 'todo' });
120
+ });
121
+
122
+ test('a write during the switch persists under the new id', async () => {
123
+ hydrateSession('s-prev', { 'layout.activeRightPanel': 'git' });
124
+ hydrateSession('s-write', {});
125
+ await show('s-prev');
126
+
127
+ function Writer() {
128
+ const [, setPanel] = useSessionState<string>('layout.activeRightPanel', 'files');
129
+ return h('button', { onClick: () => setPanel('terminal') }, 'pick');
130
+ }
131
+
132
+ await act(async () => {
133
+ render(
134
+ h(SessionStateProvider, { sessionId: 's-write', children: h(Writer, null) }),
135
+ container,
136
+ );
137
+ });
138
+ for (let i = 0; i < 20; i += 1) await act(async () => {});
139
+ (container.querySelector('button') as HTMLButtonElement).click();
140
+ await act(async () => {});
141
+
142
+ expect(getSessionState('s-write')?.['layout.activeRightPanel']).toBe('terminal');
143
+ expect(getSessionState('s-prev')?.['layout.activeRightPanel']).toBe('git');
144
+ });
145
+ });
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef, useState } from 'preact/hooks';
1
+ import { useEffect, useState } from 'preact/hooks';
2
2
  import { getSessionValue, hydrateSession, setSessionKey } from '@/shared/lib/workspace/session-state/store';
3
3
  import { subscribeSessionKey, subscribeSessionReplaced } from '@/shared/lib/workspace/session-state/listeners';
4
4
  import { useSessionStateContext } from '@/client/hooks/workspace/session-state/context';
@@ -23,21 +23,35 @@ type LoadedState = Record<string, unknown>;
23
23
  * move across an adoption (it was already true), so without the second
24
24
  * subscription a pending chat's opened panels and picked view were reset to
25
25
  * their defaults at the exact moment the spawn renamed the session.
26
+ *
27
+ * The local copy is KEYED by the session it was read for. A session switch
28
+ * happens one commit before the restore effect can run, and an unkeyed copy
29
+ * made that commit render the PREVIOUS chat's value under the NEW session id.
30
+ * Every reader that mirrors the value back into the store then persisted the
31
+ * old chat's state as the new one's — measured: opening a new chat while a
32
+ * right-panel tab strip was in `tabs` mode reopened `Files` in it, on both
33
+ * layouts, because the strip's selection was mirrored into the fresh session
34
+ * before its (empty) blob landed. A copy that belongs to another session is
35
+ * not a value this session may show; the store or the fallback is.
26
36
  */
27
37
  export function useSessionState<T>(key: string, fallback: T): [T, (value: T | ((prev: T) => T)) => void, boolean] {
28
38
  const { sessionId, ready } = useSessionStateContext();
29
39
  const stored = getSessionValue<T>(sessionId, key);
30
- const [local, setLocal] = useState<T>(stored === undefined ? fallback : stored);
31
- const sessionIdRef = useRef(sessionId);
40
+ const [local, setLocal] = useState<{ sessionId: string; value: T }>(() => ({
41
+ sessionId,
42
+ value: stored === undefined ? fallback : stored,
43
+ }));
44
+
45
+ // The copy belongs to another session: read this session's own value instead
46
+ // of carrying the previous chat's over. The restore effect below adopts it.
47
+ const current =
48
+ local.sessionId === sessionId ? local.value : stored === undefined ? fallback : stored;
32
49
 
33
50
  // Restore the stored value (or reset to fallback) on session change/load.
34
51
  useEffect(() => {
35
- if (sessionIdRef.current !== sessionId) {
36
- sessionIdRef.current = sessionId;
37
- }
38
52
  if (!ready) return;
39
53
  const next = getSessionValue<T>(sessionId, key);
40
- setLocal(next === undefined ? fallback : next);
54
+ setLocal({ sessionId, value: next === undefined ? fallback : next });
41
55
  // `key` and `fallback` are stable per call site; session/ready drive restore.
42
56
  // eslint-disable-next-line react-hooks/exhaustive-deps
43
57
  }, [sessionId, ready, key]);
@@ -48,7 +62,7 @@ export function useSessionState<T>(key: string, fallback: T): [T, (value: T | ((
48
62
  () =>
49
63
  subscribeSessionReplaced(sessionId, () => {
50
64
  const next = getSessionValue<T>(sessionId, key);
51
- setLocal(next === undefined ? fallback : next);
65
+ setLocal({ sessionId, value: next === undefined ? fallback : next });
52
66
  }),
53
67
  // `key` and `fallback` are stable per call site.
54
68
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -56,17 +70,15 @@ export function useSessionState<T>(key: string, fallback: T): [T, (value: T | ((
56
70
  );
57
71
 
58
72
  const setValue = (value: T | ((prev: T) => T)) => {
59
- const resolved = typeof value === 'function' ? (value as (prev: T) => T)(getSessionValue<T>(sessionId, key) ?? local) : value;
60
- setLocal(resolved);
73
+ const resolved =
74
+ typeof value === 'function'
75
+ ? (value as (prev: T) => T)(getSessionValue<T>(sessionId, key) ?? current)
76
+ : value;
77
+ setLocal({ sessionId, value: resolved });
61
78
  setSessionKey(sessionId, key, resolved);
62
79
  };
63
80
 
64
- // While the blob loads, surface the live in-memory value so a panel never
65
- // renders stale fallback over a fresher local write.
66
- if (!ready && stored !== undefined && stored !== local) {
67
- return [stored, setValue, ready];
68
- }
69
- return [local, setValue, ready];
81
+ return [current, setValue, ready];
70
82
  }
71
83
 
72
84
  export const useSessionUiState = useSessionState;
@@ -1 +0,0 @@
1
- import"./index-x1fqhhpp.js";import"./index-j718pxb3.js";import{r0}from"./index-29npynva.js";export{r0 as diagram};
@@ -1 +0,0 @@
1
- import{BA}from"./index-amys498v.js";export{BA as default};
@@ -1 +0,0 @@
1
- import{EA}from"./index-amys498v.js";export{EA as default};