@causyne/agent 1.20.127 → 1.20.128

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 (69) hide show
  1. package/docs/THIRD_PARTY_NOTICES.md +36 -2
  2. package/package.json +3 -1
  3. package/src/agentLoop.js +59 -26
  4. package/src/agentLoop.ts +59 -24
  5. package/src/browser/causyneBrowser.js +31 -0
  6. package/src/browser/causyneBrowser.ts +32 -0
  7. package/src/commands.js +177 -13
  8. package/src/commands.ts +194 -13
  9. package/src/memory/episodicStore.js +40 -0
  10. package/src/memory/episodicStore.ts +46 -0
  11. package/src/memory.js +67 -0
  12. package/src/memory.ts +65 -0
  13. package/src/personalization.js +365 -0
  14. package/src/personalization.ts +471 -0
  15. package/src/projectInstructions.js +30 -10
  16. package/src/projectInstructions.ts +31 -12
  17. package/src/providers/acp.js +3 -2
  18. package/src/providers/acp.ts +3 -2
  19. package/src/providers/antigravity.js +2 -0
  20. package/src/providers/antigravity.ts +2 -0
  21. package/src/tools/memoryWrite.js +15 -1
  22. package/src/tools/memoryWrite.ts +16 -1
  23. package/src/tools/osSandbox.js +1 -1
  24. package/src/tools/osSandbox.ts +1 -1
  25. package/src/tools/ptyTerminal.js +17 -5
  26. package/src/tools/ptyTerminal.ts +19 -5
  27. package/src/web/client/browserPanel.js +234 -31
  28. package/src/web/client/browserPanel.ts +240 -31
  29. package/src/web/client/chatStream.js +19 -7
  30. package/src/web/client/chatStream.ts +17 -9
  31. package/src/web/client/cliPanel.js +3 -3
  32. package/src/web/client/cliPanel.ts +3 -3
  33. package/src/web/client/dom.js +53 -2
  34. package/src/web/client/dom.ts +54 -3
  35. package/src/web/client/filesAndCanvas.js +3 -1
  36. package/src/web/client/filesAndCanvas.ts +3 -1
  37. package/src/web/client/main.js +28 -13
  38. package/src/web/client/main.ts +35 -12
  39. package/src/web/client/settingsModal.js +641 -8
  40. package/src/web/client/settingsModal.ts +791 -8
  41. package/src/web/client/state.js +31 -1
  42. package/src/web/client/state.ts +27 -1
  43. package/src/web/client/studioLayout.js +39 -4
  44. package/src/web/client/studioLayout.ts +47 -4
  45. package/src/web/client/studioShell.js +370 -37
  46. package/src/web/client/studioShell.ts +368 -36
  47. package/src/web/client/terminalPanel.js +378 -129
  48. package/src/web/client/terminalPanel.ts +394 -107
  49. package/src/web/client/terminalTheme.js +249 -0
  50. package/src/web/client/terminalTheme.ts +258 -0
  51. package/src/web/client/types.ts +3 -0
  52. package/src/web/client/validators.js +51 -10
  53. package/src/web/client/validators.ts +54 -10
  54. package/src/web/server/routesBrowser.js +64 -10
  55. package/src/web/server/routesBrowser.ts +62 -13
  56. package/src/web/server/routesSettings.js +344 -0
  57. package/src/web/server/routesSettings.ts +397 -0
  58. package/src/web/server/staticAssets.js +24 -0
  59. package/src/web/server/staticAssets.ts +25 -0
  60. package/src/web/skybridgeServer.js +3 -0
  61. package/src/web/skybridgeServer.ts +2 -0
  62. package/src/web/skybridgeUi.js +5 -1
  63. package/src/web/skybridgeUi.ts +8 -1
  64. package/src/web/styles/overlays.css +499 -0
  65. package/src/web/styles/studio.css +274 -46
  66. package/src/web/ui/modalsTemplate.js +320 -71
  67. package/src/web/ui/modalsTemplate.ts +320 -71
  68. package/src/web/ui/studioTemplate.js +19 -21
  69. package/src/web/ui/studioTemplate.ts +19 -21
@@ -6,9 +6,11 @@ import {
6
6
  syncExpandedStudioWidth
7
7
  } from './state.js';
8
8
  import {
9
+ clampSplitRatio,
9
10
  halvesFitWidth,
10
11
  isValidStudioTab,
11
12
  loadPersistedStudioLayout,
13
+ normalizeOpenTabs,
12
14
  persistStudioLayout,
13
15
  pickDistinctSecondaryTab
14
16
  } from './studioLayout.js';
@@ -19,18 +21,37 @@ export interface StudioTabHandlers {
19
21
  onCliTab(): void;
20
22
  onTerminalActivate(): void;
21
23
  onTerminalDeactivate(): void;
24
+ onTerminalClose(): void;
22
25
  onBrowserActivate(): void;
23
26
  onBrowserDeactivate(): void;
27
+ onBrowserClose(): void;
28
+ onLayoutResized(): void;
24
29
  }
25
30
 
31
+ const DEFAULT_TAB_LABELS: Record<string, string> = {
32
+ start: 'Start',
33
+ files: 'Files',
34
+ canvas: 'Editor',
35
+ terminal: 'Terminal',
36
+ browser: 'Browser',
37
+ diff: 'Changes',
38
+ cli: 'Commands'
39
+ };
40
+
41
+ const dynamicTabTitles = new Map<string, string>();
42
+ let lastActiveStudioTab: string | null = null;
43
+
26
44
  let tabHandlers: StudioTabHandlers = {
27
45
  onFilesTab: () => {},
28
46
  onDiffTab: () => {},
29
47
  onCliTab: () => {},
30
48
  onTerminalActivate: () => {},
31
49
  onTerminalDeactivate: () => {},
50
+ onTerminalClose: () => {},
32
51
  onBrowserActivate: () => {},
33
- onBrowserDeactivate: () => {}
52
+ onBrowserDeactivate: () => {},
53
+ onBrowserClose: () => {},
54
+ onLayoutResized: () => {}
34
55
  };
35
56
 
36
57
  export function configureStudioTabHandlers(handlers: StudioTabHandlers): void {
@@ -65,13 +86,208 @@ export function positionPopover(pop: HTMLElement, anchor: HTMLElement, preferUp:
65
86
  pop.style.top = `${top}px`;
66
87
  }
67
88
 
68
- function isTabVisible(tab: string): boolean {
89
+ export function isStudioTabVisible(tab: string): boolean {
69
90
  return state.studioTab === tab || (state.studioSplit && state.studioSecondaryTab === tab);
70
91
  }
71
92
 
93
+ function createSvgElement(tag: string, attrs: Record<string, string>): SVGElement {
94
+ const el = document.createElementNS('http://www.w3.org/2000/svg', tag);
95
+ for (const [k, v] of Object.entries(attrs)) {
96
+ el.setAttribute(k, v);
97
+ }
98
+ return el;
99
+ }
100
+
101
+ function createTabIconSvg(tab: string): SVGElement {
102
+ const svg = createSvgElement('svg', {
103
+ class: 'studio-tab-icon',
104
+ viewBox: '0 0 24 24',
105
+ 'aria-hidden': 'true'
106
+ });
107
+ if (tab === 'start') {
108
+ svg.appendChild(createSvgElement('circle', { cx: '12', cy: '12', r: '9' }));
109
+ svg.appendChild(createSvgElement('polygon', { points: '16.24 7.76 14.12 14.12 7.76 16.24 9.88 9.88 16.24 7.76' }));
110
+ } else if (tab === 'files') {
111
+ svg.appendChild(createSvgElement('path', { d: 'M3 7a2 2 0 0 1 2-2h5l2 2h7a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z' }));
112
+ } else if (tab === 'canvas') {
113
+ svg.appendChild(createSvgElement('path', { d: 'M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z' }));
114
+ svg.appendChild(createSvgElement('polyline', { points: '14 2 14 8 20 8' }));
115
+ } else if (tab === 'terminal') {
116
+ svg.appendChild(createSvgElement('polyline', { points: '4 17 10 11 4 5' }));
117
+ svg.appendChild(createSvgElement('line', { x1: '12', y1: '19', x2: '20', y2: '19' }));
118
+ } else if (tab === 'browser') {
119
+ svg.appendChild(createSvgElement('circle', { cx: '12', cy: '12', r: '9' }));
120
+ svg.appendChild(createSvgElement('line', { x1: '3', y1: '12', x2: '21', y2: '12' }));
121
+ svg.appendChild(createSvgElement('path', { d: 'M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18' }));
122
+ } else if (tab === 'diff') {
123
+ svg.appendChild(createSvgElement('circle', { cx: '18', cy: '18', r: '3' }));
124
+ svg.appendChild(createSvgElement('circle', { cx: '6', cy: '6', r: '3' }));
125
+ svg.appendChild(createSvgElement('path', { d: 'M6 9v6a3 3 0 0 0 3 3h6' }));
126
+ } else {
127
+ svg.appendChild(createSvgElement('polyline', { points: '9 18 15 12 9 6' }));
128
+ }
129
+ return svg;
130
+ }
131
+
132
+ function createCloseIconSvg(): SVGElement {
133
+ const svg = createSvgElement('svg', {
134
+ viewBox: '0 0 24 24',
135
+ 'aria-hidden': 'true'
136
+ });
137
+ svg.appendChild(createSvgElement('line', { x1: '18', y1: '6', x2: '6', y2: '18' }));
138
+ svg.appendChild(createSvgElement('line', { x1: '6', y1: '6', x2: '18', y2: '18' }));
139
+ return svg;
140
+ }
141
+
142
+ function tabDisplayTitle(tab: string): string {
143
+ const dynamic = dynamicTabTitles.get(tab);
144
+ if (dynamic && dynamic.trim()) return dynamic.trim();
145
+ return DEFAULT_TAB_LABELS[tab] || tab;
146
+ }
147
+
148
+ function persistCurrentLayout(): void {
149
+ persistStudioLayout({
150
+ openTabs: state.studioOpenTabs,
151
+ primaryTab: state.studioTab,
152
+ splitActive: state.studioSplit,
153
+ secondaryTab: state.studioSecondaryTab,
154
+ splitRatio: state.studioSplitRatio
155
+ });
156
+ }
157
+
158
+ function applySplitRatioVar(): void {
159
+ const ratio = clampSplitRatio(state.studioSplitRatio);
160
+ state.studioSplitRatio = ratio;
161
+ const leftPct = `${(ratio * 100).toFixed(2)}%`;
162
+ const rightPct = `${((1 - ratio) * 100).toFixed(2)}%`;
163
+ if (dom.studioPanesGrid) {
164
+ dom.studioPanesGrid.style.setProperty('--studio-split-left', leftPct);
165
+ dom.studioPanesGrid.style.setProperty('--studio-split-right', rightPct);
166
+ }
167
+ }
168
+
169
+ export function setStudioTabDynamicTitle(tab: string, title: string | null): void {
170
+ if (!isValidStudioTab(tab)) return;
171
+ const clean = typeof title === 'string' ? title.trim().slice(0, 40) : '';
172
+ const prev = dynamicTabTitles.get(tab) || '';
173
+ if (clean === prev) return;
174
+ if (clean) dynamicTabTitles.set(tab, clean);
175
+ else dynamicTabTitles.delete(tab);
176
+ const labelEl = dom.studioTabs?.querySelector<HTMLElement>(`.studio-tab[data-tab="${tab}"] .studio-tab-label`);
177
+ if (labelEl) {
178
+ const nextText = tabDisplayTitle(tab);
179
+ labelEl.textContent = nextText;
180
+ const chipEl = labelEl.closest<HTMLElement>('.studio-tab');
181
+ if (chipEl) chipEl.title = nextText;
182
+ }
183
+ }
184
+
185
+ function scrollActiveTabIntoView(): void {
186
+ const strip = dom.studioTabs;
187
+ if (!strip) return;
188
+ const activeChip = strip.querySelector<HTMLElement>('.studio-tab.active');
189
+ if (!activeChip) return;
190
+ const stripRect = strip.getBoundingClientRect();
191
+ if (stripRect.width <= 0) return;
192
+ const chipRect = activeChip.getBoundingClientRect();
193
+ if (chipRect.left < stripRect.left) {
194
+ strip.scrollLeft = Math.max(0, strip.scrollLeft - (stripRect.left - chipRect.left) - 6);
195
+ } else if (chipRect.right > stripRect.right) {
196
+ strip.scrollLeft = strip.scrollLeft + (chipRect.right - stripRect.right) + 6;
197
+ }
198
+ }
199
+
200
+ export function renderStudioTabs(): void {
201
+ const strip = dom.studioTabs;
202
+ if (!strip) return;
203
+ const effectiveSplit = state.studioSplit && state.studioSecondaryTab !== state.studioTab;
204
+ const openTabs = normalizeOpenTabs(
205
+ state.studioOpenTabs,
206
+ state.studioTab,
207
+ effectiveSplit,
208
+ state.studioSecondaryTab
209
+ );
210
+ state.studioOpenTabs = openTabs;
211
+
212
+ const isQuietLoneStart = openTabs.length === 1 && openTabs[0] === 'start' && !effectiveSplit;
213
+ strip.textContent = '';
214
+
215
+ openTabs.forEach((tab, index) => {
216
+ if (index > 0) {
217
+ const slot = document.createElement('span');
218
+ slot.className = 'studio-tab-slot';
219
+ slot.setAttribute('aria-hidden', 'true');
220
+ strip.appendChild(slot);
221
+ }
222
+
223
+ const isPrimary = tab === state.studioTab;
224
+ const isSecondary = effectiveSplit && tab === state.studioSecondaryTab;
225
+ const closable = !isQuietLoneStart;
226
+ const labelText = tabDisplayTitle(tab);
227
+
228
+ const chip = document.createElement('div');
229
+ chip.className = 'studio-tab';
230
+ if (isPrimary) chip.classList.add('active');
231
+ if (isSecondary) chip.classList.add('split-secondary');
232
+ if (isQuietLoneStart) chip.classList.add('quiet');
233
+ chip.setAttribute('data-tab', tab);
234
+ chip.setAttribute('role', 'tab');
235
+ chip.setAttribute('aria-selected', isPrimary ? 'true' : 'false');
236
+ chip.tabIndex = isPrimary ? 0 : -1;
237
+ chip.title = labelText;
238
+
239
+ const titleWrap = document.createElement('span');
240
+ titleWrap.className = 'studio-tab-title';
241
+ titleWrap.appendChild(createTabIconSvg(tab));
242
+ const label = document.createElement('span');
243
+ label.className = 'studio-tab-label';
244
+ label.textContent = labelText;
245
+ titleWrap.appendChild(label);
246
+ chip.appendChild(titleWrap);
247
+
248
+ chip.addEventListener('click', (e) => {
249
+ const target = e.target as HTMLElement | null;
250
+ if (target && target.closest('.studio-tab-close')) return;
251
+ setStudioTab(tab);
252
+ });
253
+ chip.addEventListener('keydown', (e) => {
254
+ if (e.key === 'Enter' || e.key === ' ') {
255
+ e.preventDefault();
256
+ setStudioTab(tab);
257
+ }
258
+ });
259
+ if (closable) {
260
+ chip.addEventListener('auxclick', (e) => {
261
+ if (e.button === 1) {
262
+ e.preventDefault();
263
+ closeStudioTab(tab);
264
+ }
265
+ });
266
+
267
+ const closeBtn = document.createElement('button');
268
+ closeBtn.type = 'button';
269
+ closeBtn.className = 'studio-tab-close';
270
+ closeBtn.setAttribute('aria-label', `Close ${labelText}`);
271
+ closeBtn.title = `Close ${labelText}`;
272
+ closeBtn.appendChild(createCloseIconSvg());
273
+ closeBtn.addEventListener('click', (e) => {
274
+ e.stopPropagation();
275
+ closeStudioTab(tab);
276
+ });
277
+ chip.appendChild(closeBtn);
278
+ }
279
+
280
+ strip.appendChild(chip);
281
+ });
282
+
283
+ scrollActiveTabIntoView();
284
+ window.requestAnimationFrame(scrollActiveTabIntoView);
285
+ }
286
+
72
287
  function syncStudioPanes(): void {
73
288
  const effectiveSplit = state.studioSplit && state.studioSecondaryTab !== state.studioTab;
74
289
  dom.appEl.classList.toggle('studio-split', effectiveSplit);
290
+ applySplitRatioVar();
75
291
  if (dom.studioSplitBar) dom.studioSplitBar.classList.toggle('open', effectiveSplit);
76
292
  if (dom.studioSplitBtn) {
77
293
  dom.studioSplitBtn.classList.toggle('active', effectiveSplit);
@@ -81,11 +297,7 @@ function syncStudioPanes(): void {
81
297
  dom.studioSecondarySelect.value = state.studioSecondaryTab;
82
298
  }
83
299
 
84
- document.querySelectorAll('.studio-tab').forEach((b) => {
85
- const t = b.getAttribute('data-tab') || '';
86
- b.classList.toggle('active', t === state.studioTab);
87
- b.classList.toggle('split-secondary', effectiveSplit && t === state.studioSecondaryTab);
88
- });
300
+ renderStudioTabs();
89
301
 
90
302
  document.querySelectorAll('.studio-pane').forEach((p) => {
91
303
  const t = p.getAttribute('data-pane') || '';
@@ -99,17 +311,18 @@ function syncStudioPanes(): void {
99
311
 
100
312
  function notifyVisibleTabs(): void {
101
313
  if (!dom.appEl.classList.contains('studio-open')) return;
102
- if (isTabVisible('files')) tabHandlers.onFilesTab();
103
- if (isTabVisible('diff')) tabHandlers.onDiffTab();
104
- if (isTabVisible('cli')) tabHandlers.onCliTab();
105
- if (isTabVisible('terminal')) tabHandlers.onTerminalActivate();
314
+ if (isStudioTabVisible('files')) tabHandlers.onFilesTab();
315
+ if (isStudioTabVisible('diff')) tabHandlers.onDiffTab();
316
+ if (isStudioTabVisible('cli')) tabHandlers.onCliTab();
317
+ if (isStudioTabVisible('terminal')) tabHandlers.onTerminalActivate();
106
318
  else tabHandlers.onTerminalDeactivate();
107
319
 
108
- if (isTabVisible('browser') && state.browserEngine === 'agent') {
320
+ if (isStudioTabVisible('browser') && state.browserEngine === 'agent') {
109
321
  tabHandlers.onBrowserActivate();
110
322
  } else {
111
323
  tabHandlers.onBrowserDeactivate();
112
324
  }
325
+ tabHandlers.onLayoutResized();
113
326
  }
114
327
 
115
328
  export function syncPanelChromeState(): void {
@@ -130,29 +343,89 @@ export function syncPanelChromeState(): void {
130
343
  ];
131
344
  for (const [btn, tab] of navPairs) {
132
345
  if (!btn) continue;
133
- btn.classList.toggle('active', isOpen && isTabVisible(tab));
346
+ btn.classList.toggle('active', isOpen && isStudioTabVisible(tab));
134
347
  }
135
348
  }
136
349
 
137
350
  export function restoreStudioLayoutPreference(): void {
138
351
  const saved = loadPersistedStudioLayout();
352
+ state.studioOpenTabs = saved.openTabs;
139
353
  state.studioTab = saved.primaryTab;
140
354
  state.studioSplit = saved.splitActive;
141
355
  state.studioSecondaryTab = saved.secondaryTab;
356
+ state.studioSplitRatio = saved.splitRatio;
142
357
  syncStudioPanes();
143
358
  }
144
359
 
145
360
  export function setStudioTab(tab: string): void {
146
361
  const nextTab = isValidStudioTab(tab) ? tab : 'start';
362
+ if (state.studioTab && state.studioTab !== nextTab && state.studioTab !== 'start') {
363
+ lastActiveStudioTab = state.studioTab;
364
+ }
365
+ if (!state.studioOpenTabs.includes(nextTab)) {
366
+ // Opening a concrete tool from a lone Start tab replaces Start smoothly,
367
+ // while opening Start via "+" appends it as a launch tab.
368
+ if (
369
+ nextTab !== 'start'
370
+ && state.studioOpenTabs.length === 1
371
+ && state.studioOpenTabs[0] === 'start'
372
+ && !state.studioSplit
373
+ ) {
374
+ state.studioOpenTabs = [nextTab];
375
+ } else {
376
+ state.studioOpenTabs = [...state.studioOpenTabs, nextTab];
377
+ }
378
+ }
147
379
  if (state.studioSplit && nextTab === state.studioSecondaryTab) {
148
380
  state.studioSecondaryTab = pickDistinctSecondaryTab(nextTab, state.studioTab);
149
381
  }
150
382
  state.studioTab = nextTab;
151
- persistStudioLayout({
152
- primaryTab: state.studioTab,
153
- splitActive: state.studioSplit,
154
- secondaryTab: state.studioSecondaryTab
155
- });
383
+ persistCurrentLayout();
384
+ syncStudioPanes();
385
+ syncPanelChromeState();
386
+ notifyVisibleTabs();
387
+ }
388
+
389
+ export function closeStudioTab(tab: string): void {
390
+ if (!isValidStudioTab(tab)) return;
391
+ const idx = state.studioOpenTabs.indexOf(tab);
392
+ if (idx === -1) return;
393
+
394
+ if (tab === 'browser') {
395
+ dynamicTabTitles.delete('browser');
396
+ tabHandlers.onBrowserClose();
397
+ } else if (tab === 'terminal') {
398
+ dynamicTabTitles.delete('terminal');
399
+ tabHandlers.onTerminalClose();
400
+ } else if (tab === 'canvas') {
401
+ dynamicTabTitles.delete('canvas');
402
+ }
403
+
404
+ const remaining = state.studioOpenTabs.filter((t) => t !== tab);
405
+ if (remaining.length === 0) {
406
+ state.studioOpenTabs = ['start'];
407
+ state.studioTab = 'start';
408
+ state.studioSplit = false;
409
+ } else {
410
+ state.studioOpenTabs = remaining;
411
+ if (state.studioSplit) {
412
+ if (remaining.length < 2) {
413
+ state.studioSplit = false;
414
+ state.studioTab = remaining[0] || 'start';
415
+ } else if (tab === state.studioTab) {
416
+ const nextPrimary = remaining.find((t) => t !== state.studioSecondaryTab) || remaining[0] || 'start';
417
+ state.studioTab = nextPrimary;
418
+ } else if (tab === state.studioSecondaryTab) {
419
+ const nextSecondary = remaining.find((t) => t !== state.studioTab) || pickDistinctSecondaryTab(state.studioTab);
420
+ state.studioSecondaryTab = nextSecondary;
421
+ }
422
+ } else if (tab === state.studioTab) {
423
+ const nextIdx = Math.min(idx, remaining.length - 1);
424
+ state.studioTab = remaining[nextIdx] || 'start';
425
+ }
426
+ }
427
+
428
+ persistCurrentLayout();
156
429
  syncStudioPanes();
157
430
  syncPanelChromeState();
158
431
  notifyVisibleTabs();
@@ -160,6 +433,9 @@ export function setStudioTab(tab: string): void {
160
433
 
161
434
  export function setSecondaryStudioTab(tab: string): void {
162
435
  if (!isValidStudioTab(tab)) return;
436
+ if (!state.studioOpenTabs.includes(tab)) {
437
+ state.studioOpenTabs = [...state.studioOpenTabs, tab];
438
+ }
163
439
  if (tab === state.studioTab) {
164
440
  const prevPrimary = state.studioTab;
165
441
  state.studioTab = state.studioSecondaryTab;
@@ -167,11 +443,7 @@ export function setSecondaryStudioTab(tab: string): void {
167
443
  } else {
168
444
  state.studioSecondaryTab = tab;
169
445
  }
170
- persistStudioLayout({
171
- primaryTab: state.studioTab,
172
- splitActive: state.studioSplit,
173
- secondaryTab: state.studioSecondaryTab
174
- });
446
+ persistCurrentLayout();
175
447
  syncStudioPanes();
176
448
  syncPanelChromeState();
177
449
  notifyVisibleTabs();
@@ -192,14 +464,21 @@ export function toggleStudioSplit(force?: boolean): void {
192
464
  syncExpandedStudioWidth();
193
465
  dom.appEl.classList.toggle('studio-expanded', true);
194
466
  }
195
- state.studioSecondaryTab = pickDistinctSecondaryTab(state.studioTab, state.studioSecondaryTab);
467
+ const recentCandidate = lastActiveStudioTab
468
+ && lastActiveStudioTab !== state.studioTab
469
+ && state.studioOpenTabs.includes(lastActiveStudioTab)
470
+ ? lastActiveStudioTab
471
+ : undefined;
472
+ const otherOpen = recentCandidate
473
+ || state.studioOpenTabs.find((t) => t !== state.studioTab && t !== 'start')
474
+ || state.studioOpenTabs.find((t) => t !== state.studioTab);
475
+ state.studioSecondaryTab = pickDistinctSecondaryTab(state.studioTab, otherOpen || state.studioSecondaryTab);
476
+ if (!state.studioOpenTabs.includes(state.studioSecondaryTab)) {
477
+ state.studioOpenTabs = [...state.studioOpenTabs, state.studioSecondaryTab];
478
+ }
196
479
  }
197
480
  state.studioSplit = nextSplit;
198
- persistStudioLayout({
199
- primaryTab: state.studioTab,
200
- splitActive: state.studioSplit,
201
- secondaryTab: state.studioSecondaryTab
202
- });
481
+ persistCurrentLayout();
203
482
  syncStudioPanes();
204
483
  syncPanelChromeState();
205
484
  notifyVisibleTabs();
@@ -210,11 +489,7 @@ export function swapStudioSplitPanes(): void {
210
489
  const prevPrimary = state.studioTab;
211
490
  state.studioTab = state.studioSecondaryTab;
212
491
  state.studioSecondaryTab = prevPrimary;
213
- persistStudioLayout({
214
- primaryTab: state.studioTab,
215
- splitActive: state.studioSplit,
216
- secondaryTab: state.studioSecondaryTab
217
- });
492
+ persistCurrentLayout();
218
493
  syncStudioPanes();
219
494
  syncPanelChromeState();
220
495
  notifyVisibleTabs();
@@ -237,6 +512,7 @@ export function openStudio(tab?: string): void {
237
512
  syncPanelChromeState();
238
513
  notifyVisibleTabs();
239
514
  }
515
+ setTimeout(scrollActiveTabIntoView, 220);
240
516
  }
241
517
 
242
518
  export function closeStudio(): void {
@@ -253,8 +529,11 @@ export function closeStudio(): void {
253
529
  }
254
530
 
255
531
  export function toggleStudioNav(tab: string): void {
256
- if (dom.appEl.classList.contains('studio-open') && state.studioTab === tab && !state.studioSplit) closeStudio();
257
- else openStudio(tab);
532
+ if (dom.appEl.classList.contains('studio-open') && state.studioTab === tab && !state.studioSplit) {
533
+ closeStudio();
534
+ } else {
535
+ openStudio(tab);
536
+ }
258
537
  }
259
538
 
260
539
  export function toggleStudioMaximize(): void {
@@ -266,6 +545,7 @@ export function toggleStudioMaximize(): void {
266
545
  syncExpandedStudioWidth();
267
546
  dom.appEl.classList.toggle('studio-expanded', state.studioExpanded);
268
547
  syncPanelChromeState();
548
+ tabHandlers.onLayoutResized();
269
549
  }
270
550
 
271
551
  let resizing = false;
@@ -293,8 +573,10 @@ export function endStudioResize(cancelled: boolean): void {
293
573
  closeStudio();
294
574
  } else if (cancelled) {
295
575
  applyStudioWidth(resizeStartWidth, false);
576
+ tabHandlers.onLayoutResized();
296
577
  } else {
297
578
  applyStudioWidth(state.studioWidth, true);
579
+ tabHandlers.onLayoutResized();
298
580
  }
299
581
  }
300
582
 
@@ -330,11 +612,61 @@ export function bindStudioResizer(): void {
330
612
  dom.appEl.classList.remove('studio-expanded');
331
613
  applyStudioWidth(DEFAULT_STUDIO_W, true);
332
614
  syncPanelChromeState();
615
+ tabHandlers.onLayoutResized();
333
616
  });
334
617
  window.addEventListener('resize', () => {
335
618
  closeAllPopovers();
336
619
  if (dom.appEl.classList.contains('studio-open') && window.innerWidth > 960) {
337
620
  applyStudioWidth(state.studioWidth, false);
621
+ tabHandlers.onLayoutResized();
622
+ }
623
+ });
624
+ }
625
+
626
+ export function bindStudioSplitDivider(): void {
627
+ const divider = dom.studioSplitDivider;
628
+ const grid = dom.studioPanesGrid;
629
+ if (!divider || !grid) return;
630
+
631
+ let splitDragging = false;
632
+ let splitPointerId: number | null = null;
633
+
634
+ const stopSplitDrag = (persist: boolean): void => {
635
+ if (!splitDragging) return;
636
+ splitDragging = false;
637
+ dom.appEl.classList.remove('studio-resizing');
638
+ divider.classList.remove('dragging');
639
+ if (splitPointerId !== null) {
640
+ try { divider.releasePointerCapture(splitPointerId); } catch { /* ignore */ }
641
+ splitPointerId = null;
338
642
  }
643
+ if (persist) persistCurrentLayout();
644
+ tabHandlers.onLayoutResized();
645
+ };
646
+
647
+ divider.addEventListener('pointerdown', (e) => {
648
+ if (!state.studioSplit) return;
649
+ e.preventDefault();
650
+ splitDragging = true;
651
+ splitPointerId = e.pointerId;
652
+ dom.appEl.classList.add('studio-resizing');
653
+ divider.classList.add('dragging');
654
+ try { divider.setPointerCapture(e.pointerId); } catch { /* ignore */ }
655
+ });
656
+ divider.addEventListener('pointermove', (e) => {
657
+ if (!splitDragging) return;
658
+ const rect = grid.getBoundingClientRect();
659
+ if (rect.width <= 0) return;
660
+ const rawRatio = (e.clientX - rect.left) / rect.width;
661
+ state.studioSplitRatio = clampSplitRatio(rawRatio);
662
+ applySplitRatioVar();
663
+ });
664
+ divider.addEventListener('pointerup', () => stopSplitDrag(true));
665
+ divider.addEventListener('pointercancel', () => stopSplitDrag(false));
666
+ divider.addEventListener('dblclick', () => {
667
+ state.studioSplitRatio = 0.5;
668
+ applySplitRatioVar();
669
+ persistCurrentLayout();
670
+ tabHandlers.onLayoutResized();
339
671
  });
340
672
  }