@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
@@ -1,14 +1,28 @@
1
1
  import { dom } from './dom.js';
2
2
  import { DEFAULT_STUDIO_W, applyStudioWidth, state, syncExpandedStudioWidth } from './state.js';
3
- import { halvesFitWidth, isValidStudioTab, loadPersistedStudioLayout, persistStudioLayout, pickDistinctSecondaryTab } from './studioLayout.js';
3
+ import { clampSplitRatio, halvesFitWidth, isValidStudioTab, loadPersistedStudioLayout, normalizeOpenTabs, persistStudioLayout, pickDistinctSecondaryTab } from './studioLayout.js';
4
+ const DEFAULT_TAB_LABELS = {
5
+ start: 'Start',
6
+ files: 'Files',
7
+ canvas: 'Editor',
8
+ terminal: 'Terminal',
9
+ browser: 'Browser',
10
+ diff: 'Changes',
11
+ cli: 'Commands'
12
+ };
13
+ const dynamicTabTitles = new Map();
14
+ let lastActiveStudioTab = null;
4
15
  let tabHandlers = {
5
16
  onFilesTab: () => { },
6
17
  onDiffTab: () => { },
7
18
  onCliTab: () => { },
8
19
  onTerminalActivate: () => { },
9
20
  onTerminalDeactivate: () => { },
21
+ onTerminalClose: () => { },
10
22
  onBrowserActivate: () => { },
11
- onBrowserDeactivate: () => { }
23
+ onBrowserDeactivate: () => { },
24
+ onBrowserClose: () => { },
25
+ onLayoutResized: () => { }
12
26
  };
13
27
  export function configureStudioTabHandlers(handlers) {
14
28
  tabHandlers = handlers;
@@ -42,12 +56,205 @@ export function positionPopover(pop, anchor, preferUp) {
42
56
  pop.style.left = `${left}px`;
43
57
  pop.style.top = `${top}px`;
44
58
  }
45
- function isTabVisible(tab) {
59
+ export function isStudioTabVisible(tab) {
46
60
  return state.studioTab === tab || (state.studioSplit && state.studioSecondaryTab === tab);
47
61
  }
62
+ function createSvgElement(tag, attrs) {
63
+ const el = document.createElementNS('http://www.w3.org/2000/svg', tag);
64
+ for (const [k, v] of Object.entries(attrs)) {
65
+ el.setAttribute(k, v);
66
+ }
67
+ return el;
68
+ }
69
+ function createTabIconSvg(tab) {
70
+ const svg = createSvgElement('svg', {
71
+ class: 'studio-tab-icon',
72
+ viewBox: '0 0 24 24',
73
+ 'aria-hidden': 'true'
74
+ });
75
+ if (tab === 'start') {
76
+ svg.appendChild(createSvgElement('circle', { cx: '12', cy: '12', r: '9' }));
77
+ 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' }));
78
+ }
79
+ else if (tab === 'files') {
80
+ 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' }));
81
+ }
82
+ else if (tab === 'canvas') {
83
+ 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' }));
84
+ svg.appendChild(createSvgElement('polyline', { points: '14 2 14 8 20 8' }));
85
+ }
86
+ else if (tab === 'terminal') {
87
+ svg.appendChild(createSvgElement('polyline', { points: '4 17 10 11 4 5' }));
88
+ svg.appendChild(createSvgElement('line', { x1: '12', y1: '19', x2: '20', y2: '19' }));
89
+ }
90
+ else if (tab === 'browser') {
91
+ svg.appendChild(createSvgElement('circle', { cx: '12', cy: '12', r: '9' }));
92
+ svg.appendChild(createSvgElement('line', { x1: '3', y1: '12', x2: '21', y2: '12' }));
93
+ svg.appendChild(createSvgElement('path', { d: 'M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18' }));
94
+ }
95
+ else if (tab === 'diff') {
96
+ svg.appendChild(createSvgElement('circle', { cx: '18', cy: '18', r: '3' }));
97
+ svg.appendChild(createSvgElement('circle', { cx: '6', cy: '6', r: '3' }));
98
+ svg.appendChild(createSvgElement('path', { d: 'M6 9v6a3 3 0 0 0 3 3h6' }));
99
+ }
100
+ else {
101
+ svg.appendChild(createSvgElement('polyline', { points: '9 18 15 12 9 6' }));
102
+ }
103
+ return svg;
104
+ }
105
+ function createCloseIconSvg() {
106
+ const svg = createSvgElement('svg', {
107
+ viewBox: '0 0 24 24',
108
+ 'aria-hidden': 'true'
109
+ });
110
+ svg.appendChild(createSvgElement('line', { x1: '18', y1: '6', x2: '6', y2: '18' }));
111
+ svg.appendChild(createSvgElement('line', { x1: '6', y1: '6', x2: '18', y2: '18' }));
112
+ return svg;
113
+ }
114
+ function tabDisplayTitle(tab) {
115
+ const dynamic = dynamicTabTitles.get(tab);
116
+ if (dynamic && dynamic.trim())
117
+ return dynamic.trim();
118
+ return DEFAULT_TAB_LABELS[tab] || tab;
119
+ }
120
+ function persistCurrentLayout() {
121
+ persistStudioLayout({
122
+ openTabs: state.studioOpenTabs,
123
+ primaryTab: state.studioTab,
124
+ splitActive: state.studioSplit,
125
+ secondaryTab: state.studioSecondaryTab,
126
+ splitRatio: state.studioSplitRatio
127
+ });
128
+ }
129
+ function applySplitRatioVar() {
130
+ const ratio = clampSplitRatio(state.studioSplitRatio);
131
+ state.studioSplitRatio = ratio;
132
+ const leftPct = `${(ratio * 100).toFixed(2)}%`;
133
+ const rightPct = `${((1 - ratio) * 100).toFixed(2)}%`;
134
+ if (dom.studioPanesGrid) {
135
+ dom.studioPanesGrid.style.setProperty('--studio-split-left', leftPct);
136
+ dom.studioPanesGrid.style.setProperty('--studio-split-right', rightPct);
137
+ }
138
+ }
139
+ export function setStudioTabDynamicTitle(tab, title) {
140
+ if (!isValidStudioTab(tab))
141
+ return;
142
+ const clean = typeof title === 'string' ? title.trim().slice(0, 40) : '';
143
+ const prev = dynamicTabTitles.get(tab) || '';
144
+ if (clean === prev)
145
+ return;
146
+ if (clean)
147
+ dynamicTabTitles.set(tab, clean);
148
+ else
149
+ dynamicTabTitles.delete(tab);
150
+ const labelEl = dom.studioTabs?.querySelector(`.studio-tab[data-tab="${tab}"] .studio-tab-label`);
151
+ if (labelEl) {
152
+ const nextText = tabDisplayTitle(tab);
153
+ labelEl.textContent = nextText;
154
+ const chipEl = labelEl.closest('.studio-tab');
155
+ if (chipEl)
156
+ chipEl.title = nextText;
157
+ }
158
+ }
159
+ function scrollActiveTabIntoView() {
160
+ const strip = dom.studioTabs;
161
+ if (!strip)
162
+ return;
163
+ const activeChip = strip.querySelector('.studio-tab.active');
164
+ if (!activeChip)
165
+ return;
166
+ const stripRect = strip.getBoundingClientRect();
167
+ if (stripRect.width <= 0)
168
+ return;
169
+ const chipRect = activeChip.getBoundingClientRect();
170
+ if (chipRect.left < stripRect.left) {
171
+ strip.scrollLeft = Math.max(0, strip.scrollLeft - (stripRect.left - chipRect.left) - 6);
172
+ }
173
+ else if (chipRect.right > stripRect.right) {
174
+ strip.scrollLeft = strip.scrollLeft + (chipRect.right - stripRect.right) + 6;
175
+ }
176
+ }
177
+ export function renderStudioTabs() {
178
+ const strip = dom.studioTabs;
179
+ if (!strip)
180
+ return;
181
+ const effectiveSplit = state.studioSplit && state.studioSecondaryTab !== state.studioTab;
182
+ const openTabs = normalizeOpenTabs(state.studioOpenTabs, state.studioTab, effectiveSplit, state.studioSecondaryTab);
183
+ state.studioOpenTabs = openTabs;
184
+ const isQuietLoneStart = openTabs.length === 1 && openTabs[0] === 'start' && !effectiveSplit;
185
+ strip.textContent = '';
186
+ openTabs.forEach((tab, index) => {
187
+ if (index > 0) {
188
+ const slot = document.createElement('span');
189
+ slot.className = 'studio-tab-slot';
190
+ slot.setAttribute('aria-hidden', 'true');
191
+ strip.appendChild(slot);
192
+ }
193
+ const isPrimary = tab === state.studioTab;
194
+ const isSecondary = effectiveSplit && tab === state.studioSecondaryTab;
195
+ const closable = !isQuietLoneStart;
196
+ const labelText = tabDisplayTitle(tab);
197
+ const chip = document.createElement('div');
198
+ chip.className = 'studio-tab';
199
+ if (isPrimary)
200
+ chip.classList.add('active');
201
+ if (isSecondary)
202
+ chip.classList.add('split-secondary');
203
+ if (isQuietLoneStart)
204
+ chip.classList.add('quiet');
205
+ chip.setAttribute('data-tab', tab);
206
+ chip.setAttribute('role', 'tab');
207
+ chip.setAttribute('aria-selected', isPrimary ? 'true' : 'false');
208
+ chip.tabIndex = isPrimary ? 0 : -1;
209
+ chip.title = labelText;
210
+ const titleWrap = document.createElement('span');
211
+ titleWrap.className = 'studio-tab-title';
212
+ titleWrap.appendChild(createTabIconSvg(tab));
213
+ const label = document.createElement('span');
214
+ label.className = 'studio-tab-label';
215
+ label.textContent = labelText;
216
+ titleWrap.appendChild(label);
217
+ chip.appendChild(titleWrap);
218
+ chip.addEventListener('click', (e) => {
219
+ const target = e.target;
220
+ if (target && target.closest('.studio-tab-close'))
221
+ return;
222
+ setStudioTab(tab);
223
+ });
224
+ chip.addEventListener('keydown', (e) => {
225
+ if (e.key === 'Enter' || e.key === ' ') {
226
+ e.preventDefault();
227
+ setStudioTab(tab);
228
+ }
229
+ });
230
+ if (closable) {
231
+ chip.addEventListener('auxclick', (e) => {
232
+ if (e.button === 1) {
233
+ e.preventDefault();
234
+ closeStudioTab(tab);
235
+ }
236
+ });
237
+ const closeBtn = document.createElement('button');
238
+ closeBtn.type = 'button';
239
+ closeBtn.className = 'studio-tab-close';
240
+ closeBtn.setAttribute('aria-label', `Close ${labelText}`);
241
+ closeBtn.title = `Close ${labelText}`;
242
+ closeBtn.appendChild(createCloseIconSvg());
243
+ closeBtn.addEventListener('click', (e) => {
244
+ e.stopPropagation();
245
+ closeStudioTab(tab);
246
+ });
247
+ chip.appendChild(closeBtn);
248
+ }
249
+ strip.appendChild(chip);
250
+ });
251
+ scrollActiveTabIntoView();
252
+ window.requestAnimationFrame(scrollActiveTabIntoView);
253
+ }
48
254
  function syncStudioPanes() {
49
255
  const effectiveSplit = state.studioSplit && state.studioSecondaryTab !== state.studioTab;
50
256
  dom.appEl.classList.toggle('studio-split', effectiveSplit);
257
+ applySplitRatioVar();
51
258
  if (dom.studioSplitBar)
52
259
  dom.studioSplitBar.classList.toggle('open', effectiveSplit);
53
260
  if (dom.studioSplitBtn) {
@@ -57,11 +264,7 @@ function syncStudioPanes() {
57
264
  if (dom.studioSecondarySelect && dom.studioSecondarySelect.value !== state.studioSecondaryTab) {
58
265
  dom.studioSecondarySelect.value = state.studioSecondaryTab;
59
266
  }
60
- document.querySelectorAll('.studio-tab').forEach((b) => {
61
- const t = b.getAttribute('data-tab') || '';
62
- b.classList.toggle('active', t === state.studioTab);
63
- b.classList.toggle('split-secondary', effectiveSplit && t === state.studioSecondaryTab);
64
- });
267
+ renderStudioTabs();
65
268
  document.querySelectorAll('.studio-pane').forEach((p) => {
66
269
  const t = p.getAttribute('data-pane') || '';
67
270
  const isPrimary = t === state.studioTab;
@@ -74,22 +277,23 @@ function syncStudioPanes() {
74
277
  function notifyVisibleTabs() {
75
278
  if (!dom.appEl.classList.contains('studio-open'))
76
279
  return;
77
- if (isTabVisible('files'))
280
+ if (isStudioTabVisible('files'))
78
281
  tabHandlers.onFilesTab();
79
- if (isTabVisible('diff'))
282
+ if (isStudioTabVisible('diff'))
80
283
  tabHandlers.onDiffTab();
81
- if (isTabVisible('cli'))
284
+ if (isStudioTabVisible('cli'))
82
285
  tabHandlers.onCliTab();
83
- if (isTabVisible('terminal'))
286
+ if (isStudioTabVisible('terminal'))
84
287
  tabHandlers.onTerminalActivate();
85
288
  else
86
289
  tabHandlers.onTerminalDeactivate();
87
- if (isTabVisible('browser') && state.browserEngine === 'agent') {
290
+ if (isStudioTabVisible('browser') && state.browserEngine === 'agent') {
88
291
  tabHandlers.onBrowserActivate();
89
292
  }
90
293
  else {
91
294
  tabHandlers.onBrowserDeactivate();
92
295
  }
296
+ tabHandlers.onLayoutResized();
93
297
  }
94
298
  export function syncPanelChromeState() {
95
299
  const isOpen = dom.appEl.classList.contains('studio-open');
@@ -110,27 +314,90 @@ export function syncPanelChromeState() {
110
314
  for (const [btn, tab] of navPairs) {
111
315
  if (!btn)
112
316
  continue;
113
- btn.classList.toggle('active', isOpen && isTabVisible(tab));
317
+ btn.classList.toggle('active', isOpen && isStudioTabVisible(tab));
114
318
  }
115
319
  }
116
320
  export function restoreStudioLayoutPreference() {
117
321
  const saved = loadPersistedStudioLayout();
322
+ state.studioOpenTabs = saved.openTabs;
118
323
  state.studioTab = saved.primaryTab;
119
324
  state.studioSplit = saved.splitActive;
120
325
  state.studioSecondaryTab = saved.secondaryTab;
326
+ state.studioSplitRatio = saved.splitRatio;
121
327
  syncStudioPanes();
122
328
  }
123
329
  export function setStudioTab(tab) {
124
330
  const nextTab = isValidStudioTab(tab) ? tab : 'start';
331
+ if (state.studioTab && state.studioTab !== nextTab && state.studioTab !== 'start') {
332
+ lastActiveStudioTab = state.studioTab;
333
+ }
334
+ if (!state.studioOpenTabs.includes(nextTab)) {
335
+ // Opening a concrete tool from a lone Start tab replaces Start smoothly,
336
+ // while opening Start via "+" appends it as a launch tab.
337
+ if (nextTab !== 'start'
338
+ && state.studioOpenTabs.length === 1
339
+ && state.studioOpenTabs[0] === 'start'
340
+ && !state.studioSplit) {
341
+ state.studioOpenTabs = [nextTab];
342
+ }
343
+ else {
344
+ state.studioOpenTabs = [...state.studioOpenTabs, nextTab];
345
+ }
346
+ }
125
347
  if (state.studioSplit && nextTab === state.studioSecondaryTab) {
126
348
  state.studioSecondaryTab = pickDistinctSecondaryTab(nextTab, state.studioTab);
127
349
  }
128
350
  state.studioTab = nextTab;
129
- persistStudioLayout({
130
- primaryTab: state.studioTab,
131
- splitActive: state.studioSplit,
132
- secondaryTab: state.studioSecondaryTab
133
- });
351
+ persistCurrentLayout();
352
+ syncStudioPanes();
353
+ syncPanelChromeState();
354
+ notifyVisibleTabs();
355
+ }
356
+ export function closeStudioTab(tab) {
357
+ if (!isValidStudioTab(tab))
358
+ return;
359
+ const idx = state.studioOpenTabs.indexOf(tab);
360
+ if (idx === -1)
361
+ return;
362
+ if (tab === 'browser') {
363
+ dynamicTabTitles.delete('browser');
364
+ tabHandlers.onBrowserClose();
365
+ }
366
+ else if (tab === 'terminal') {
367
+ dynamicTabTitles.delete('terminal');
368
+ tabHandlers.onTerminalClose();
369
+ }
370
+ else if (tab === 'canvas') {
371
+ dynamicTabTitles.delete('canvas');
372
+ }
373
+ const remaining = state.studioOpenTabs.filter((t) => t !== tab);
374
+ if (remaining.length === 0) {
375
+ state.studioOpenTabs = ['start'];
376
+ state.studioTab = 'start';
377
+ state.studioSplit = false;
378
+ }
379
+ else {
380
+ state.studioOpenTabs = remaining;
381
+ if (state.studioSplit) {
382
+ if (remaining.length < 2) {
383
+ state.studioSplit = false;
384
+ state.studioTab = remaining[0] || 'start';
385
+ }
386
+ else if (tab === state.studioTab) {
387
+ const nextPrimary = remaining.find((t) => t !== state.studioSecondaryTab) || remaining[0] || 'start';
388
+ state.studioTab = nextPrimary;
389
+ }
390
+ else if (tab === state.studioSecondaryTab) {
391
+ const nextSecondary = remaining.find((t) => t !== state.studioTab) || pickDistinctSecondaryTab(state.studioTab);
392
+ state.studioSecondaryTab = nextSecondary;
393
+ }
394
+ }
395
+ else if (tab === state.studioTab) {
396
+ const nextIdx = Math.min(idx, remaining.length - 1);
397
+ state.studioTab = remaining[nextIdx] || 'start';
398
+ }
399
+ }
400
+ persistCurrentLayout();
134
401
  syncStudioPanes();
135
402
  syncPanelChromeState();
136
403
  notifyVisibleTabs();
@@ -138,6 +405,9 @@ export function setStudioTab(tab) {
138
405
  export function setSecondaryStudioTab(tab) {
139
406
  if (!isValidStudioTab(tab))
140
407
  return;
408
+ if (!state.studioOpenTabs.includes(tab)) {
409
+ state.studioOpenTabs = [...state.studioOpenTabs, tab];
410
+ }
141
411
  if (tab === state.studioTab) {
142
412
  const prevPrimary = state.studioTab;
143
413
  state.studioTab = state.studioSecondaryTab;
@@ -146,11 +416,7 @@ export function setSecondaryStudioTab(tab) {
146
416
  else {
147
417
  state.studioSecondaryTab = tab;
148
418
  }
149
- persistStudioLayout({
150
- primaryTab: state.studioTab,
151
- splitActive: state.studioSplit,
152
- secondaryTab: state.studioSecondaryTab
153
- });
419
+ persistCurrentLayout();
154
420
  syncStudioPanes();
155
421
  syncPanelChromeState();
156
422
  notifyVisibleTabs();
@@ -170,14 +436,21 @@ export function toggleStudioSplit(force) {
170
436
  syncExpandedStudioWidth();
171
437
  dom.appEl.classList.toggle('studio-expanded', true);
172
438
  }
173
- state.studioSecondaryTab = pickDistinctSecondaryTab(state.studioTab, state.studioSecondaryTab);
439
+ const recentCandidate = lastActiveStudioTab
440
+ && lastActiveStudioTab !== state.studioTab
441
+ && state.studioOpenTabs.includes(lastActiveStudioTab)
442
+ ? lastActiveStudioTab
443
+ : undefined;
444
+ const otherOpen = recentCandidate
445
+ || state.studioOpenTabs.find((t) => t !== state.studioTab && t !== 'start')
446
+ || state.studioOpenTabs.find((t) => t !== state.studioTab);
447
+ state.studioSecondaryTab = pickDistinctSecondaryTab(state.studioTab, otherOpen || state.studioSecondaryTab);
448
+ if (!state.studioOpenTabs.includes(state.studioSecondaryTab)) {
449
+ state.studioOpenTabs = [...state.studioOpenTabs, state.studioSecondaryTab];
450
+ }
174
451
  }
175
452
  state.studioSplit = nextSplit;
176
- persistStudioLayout({
177
- primaryTab: state.studioTab,
178
- splitActive: state.studioSplit,
179
- secondaryTab: state.studioSecondaryTab
180
- });
453
+ persistCurrentLayout();
181
454
  syncStudioPanes();
182
455
  syncPanelChromeState();
183
456
  notifyVisibleTabs();
@@ -188,11 +461,7 @@ export function swapStudioSplitPanes() {
188
461
  const prevPrimary = state.studioTab;
189
462
  state.studioTab = state.studioSecondaryTab;
190
463
  state.studioSecondaryTab = prevPrimary;
191
- persistStudioLayout({
192
- primaryTab: state.studioTab,
193
- splitActive: state.studioSplit,
194
- secondaryTab: state.studioSecondaryTab
195
- });
464
+ persistCurrentLayout();
196
465
  syncStudioPanes();
197
466
  syncPanelChromeState();
198
467
  notifyVisibleTabs();
@@ -216,6 +485,7 @@ export function openStudio(tab) {
216
485
  syncPanelChromeState();
217
486
  notifyVisibleTabs();
218
487
  }
488
+ setTimeout(scrollActiveTabIntoView, 220);
219
489
  }
220
490
  export function closeStudio() {
221
491
  state.studioExpanded = false;
@@ -230,10 +500,12 @@ export function closeStudio() {
230
500
  syncPanelChromeState();
231
501
  }
232
502
  export function toggleStudioNav(tab) {
233
- if (dom.appEl.classList.contains('studio-open') && state.studioTab === tab && !state.studioSplit)
503
+ if (dom.appEl.classList.contains('studio-open') && state.studioTab === tab && !state.studioSplit) {
234
504
  closeStudio();
235
- else
505
+ }
506
+ else {
236
507
  openStudio(tab);
508
+ }
237
509
  }
238
510
  export function toggleStudioMaximize() {
239
511
  if (!dom.appEl.classList.contains('studio-open'))
@@ -245,6 +517,7 @@ export function toggleStudioMaximize() {
245
517
  syncExpandedStudioWidth();
246
518
  dom.appEl.classList.toggle('studio-expanded', state.studioExpanded);
247
519
  syncPanelChromeState();
520
+ tabHandlers.onLayoutResized();
248
521
  }
249
522
  let resizing = false;
250
523
  let snapClosePending = false;
@@ -274,9 +547,11 @@ export function endStudioResize(cancelled) {
274
547
  }
275
548
  else if (cancelled) {
276
549
  applyStudioWidth(resizeStartWidth, false);
550
+ tabHandlers.onLayoutResized();
277
551
  }
278
552
  else {
279
553
  applyStudioWidth(state.studioWidth, true);
554
+ tabHandlers.onLayoutResized();
280
555
  }
281
556
  }
282
557
  export function bindStudioResizer() {
@@ -317,11 +592,69 @@ export function bindStudioResizer() {
317
592
  dom.appEl.classList.remove('studio-expanded');
318
593
  applyStudioWidth(DEFAULT_STUDIO_W, true);
319
594
  syncPanelChromeState();
595
+ tabHandlers.onLayoutResized();
320
596
  });
321
597
  window.addEventListener('resize', () => {
322
598
  closeAllPopovers();
323
599
  if (dom.appEl.classList.contains('studio-open') && window.innerWidth > 960) {
324
600
  applyStudioWidth(state.studioWidth, false);
601
+ tabHandlers.onLayoutResized();
325
602
  }
326
603
  });
327
604
  }
605
+ export function bindStudioSplitDivider() {
606
+ const divider = dom.studioSplitDivider;
607
+ const grid = dom.studioPanesGrid;
608
+ if (!divider || !grid)
609
+ return;
610
+ let splitDragging = false;
611
+ let splitPointerId = null;
612
+ const stopSplitDrag = (persist) => {
613
+ if (!splitDragging)
614
+ return;
615
+ splitDragging = false;
616
+ dom.appEl.classList.remove('studio-resizing');
617
+ divider.classList.remove('dragging');
618
+ if (splitPointerId !== null) {
619
+ try {
620
+ divider.releasePointerCapture(splitPointerId);
621
+ }
622
+ catch { /* ignore */ }
623
+ splitPointerId = null;
624
+ }
625
+ if (persist)
626
+ persistCurrentLayout();
627
+ tabHandlers.onLayoutResized();
628
+ };
629
+ divider.addEventListener('pointerdown', (e) => {
630
+ if (!state.studioSplit)
631
+ return;
632
+ e.preventDefault();
633
+ splitDragging = true;
634
+ splitPointerId = e.pointerId;
635
+ dom.appEl.classList.add('studio-resizing');
636
+ divider.classList.add('dragging');
637
+ try {
638
+ divider.setPointerCapture(e.pointerId);
639
+ }
640
+ catch { /* ignore */ }
641
+ });
642
+ divider.addEventListener('pointermove', (e) => {
643
+ if (!splitDragging)
644
+ return;
645
+ const rect = grid.getBoundingClientRect();
646
+ if (rect.width <= 0)
647
+ return;
648
+ const rawRatio = (e.clientX - rect.left) / rect.width;
649
+ state.studioSplitRatio = clampSplitRatio(rawRatio);
650
+ applySplitRatioVar();
651
+ });
652
+ divider.addEventListener('pointerup', () => stopSplitDrag(true));
653
+ divider.addEventListener('pointercancel', () => stopSplitDrag(false));
654
+ divider.addEventListener('dblclick', () => {
655
+ state.studioSplitRatio = 0.5;
656
+ applySplitRatioVar();
657
+ persistCurrentLayout();
658
+ tabHandlers.onLayoutResized();
659
+ });
660
+ }