@causyne/agent 1.20.124 → 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.
- package/bin/causyne.js +1 -1
- package/docs/THIRD_PARTY_NOTICES.md +36 -2
- package/package.json +6 -4
- package/src/acp/protocol.ts +19 -1
- package/src/acp/server.js +282 -8
- package/src/acp/server.ts +284 -8
- package/src/agent/abortableDelay.js +2 -2
- package/src/agent/abortableDelay.ts +2 -2
- package/src/agent/errorClassifier.js +9 -1
- package/src/agent/errorClassifier.ts +8 -1
- package/src/agentLoop.js +142 -53
- package/src/agentLoop.ts +151 -50
- package/src/approvalPolicy.js +34 -10
- package/src/approvalPolicy.ts +42 -11
- package/src/browser/causyneBrowser.js +61 -3
- package/src/browser/causyneBrowser.ts +65 -3
- package/src/browser/urlPolicy.js +14 -1
- package/src/browser/urlPolicy.ts +12 -1
- package/src/cliMode.js +21 -9
- package/src/cliMode.ts +20 -8
- package/src/commands.js +365 -45
- package/src/commands.ts +403 -45
- package/src/config.js +19 -4
- package/src/config.ts +18 -4
- package/src/core/contextCompactor.js +54 -7
- package/src/core/contextCompactor.ts +63 -7
- package/src/core/goalLoop.js +257 -0
- package/src/core/goalLoop.ts +310 -0
- package/src/entrypoint.js +135 -3
- package/src/entrypoint.ts +136 -3
- package/src/game/causyneCoreBridge.js +686 -0
- package/src/game/causyneCoreBridge.ts +702 -0
- package/src/game/gameLauncher.js +287 -0
- package/src/game/gameLauncher.ts +352 -0
- package/src/game/gameProvisioner.js +425 -0
- package/src/game/gameProvisioner.ts +488 -0
- package/src/headlessCli.js +19 -12
- package/src/headlessCli.ts +22 -8
- package/src/infra/atomicWriter.js +40 -4
- package/src/infra/atomicWriter.ts +36 -4
- package/src/launchIntent.js +73 -3
- package/src/launchIntent.ts +76 -3
- package/src/lsp/lspClient.js +83 -12
- package/src/lsp/lspClient.ts +75 -12
- package/src/mcp/mcpRegistry.js +75 -8
- package/src/mcp/mcpRegistry.ts +70 -7
- package/src/memory/contextBudget.js +2 -0
- package/src/memory/contextBudget.ts +1 -0
- package/src/memory/episodicStore.js +40 -0
- package/src/memory/episodicStore.ts +46 -0
- package/src/memory.js +67 -0
- package/src/memory.ts +65 -0
- package/src/modelVariants.js +45 -0
- package/src/modelVariants.ts +54 -0
- package/src/outputRecovery.js +3 -2
- package/src/outputRecovery.ts +4 -2
- package/src/permissionPresets.js +327 -0
- package/src/permissionPresets.ts +361 -0
- package/src/personalization.js +365 -0
- package/src/personalization.ts +471 -0
- package/src/projectInstructions.js +30 -10
- package/src/projectInstructions.ts +31 -12
- package/src/providers/acp.js +3 -2
- package/src/providers/acp.ts +3 -2
- package/src/providers/antigravity.js +64 -9
- package/src/providers/antigravity.ts +75 -9
- package/src/providers/byokHttp.js +7 -1
- package/src/providers/byokHttp.ts +6 -1
- package/src/providers/byokStream.js +21 -8
- package/src/providers/byokStream.ts +17 -7
- package/src/providers/dashscope-byok.js +21 -5
- package/src/providers/dashscope-byok.ts +29 -11
- package/src/providers/moonshot.js +26 -7
- package/src/providers/moonshot.ts +34 -13
- package/src/providers/muse.js +6 -0
- package/src/providers/muse.ts +8 -0
- package/src/providers/ollama.js +39 -7
- package/src/providers/ollama.ts +36 -7
- package/src/providers/openai-compatible.js +16 -3
- package/src/providers/openai-compatible.ts +13 -3
- package/src/providers/openai.js +62 -4
- package/src/providers/openai.ts +50 -4
- package/src/providers/openrouter.js +19 -4
- package/src/providers/openrouter.ts +21 -4
- package/src/providers/qwen-byok.js +21 -5
- package/src/providers/qwen-byok.ts +29 -11
- package/src/providers/xai.js +26 -10
- package/src/providers/xai.ts +34 -16
- package/src/reporting.js +4 -2
- package/src/reporting.ts +4 -2
- package/src/sandbox.js +34 -0
- package/src/sandbox.ts +43 -0
- package/src/scheduler/scheduler.js +372 -0
- package/src/scheduler/scheduler.ts +433 -0
- package/src/sessionSearchIndex.js +267 -0
- package/src/sessionSearchIndex.ts +311 -0
- package/src/skillsManager.js +2 -3
- package/src/skillsManager.ts +2 -3
- package/src/toolPacks.js +6 -0
- package/src/toolPacks.ts +6 -0
- package/src/tools/applyPatch.js +1 -1
- package/src/tools/applyPatch.ts +1 -1
- package/src/tools/generateMediaViaApi.js +4 -3
- package/src/tools/generateMediaViaApi.ts +4 -3
- package/src/tools/memoryWrite.js +15 -1
- package/src/tools/memoryWrite.ts +16 -1
- package/src/tools/nativeEngine.js +2 -2
- package/src/tools/nativeEngine.ts +2 -2
- package/src/tools/openSourceToolProvisioner.js +2 -2
- package/src/tools/openSourceToolProvisioner.ts +2 -2
- package/src/tools/osSandbox.js +1 -1
- package/src/tools/osSandbox.ts +1 -1
- package/src/tools/payloadSanitizer.js +0 -1
- package/src/tools/payloadSanitizer.ts +0 -1
- package/src/tools/pdfReader.js +122 -20
- package/src/tools/pdfReader.ts +111 -20
- package/src/tools/presentDeliverable.js +103 -0
- package/src/tools/presentDeliverable.ts +127 -0
- package/src/tools/ptcRuntime.js +444 -0
- package/src/tools/ptcRuntime.ts +490 -0
- package/src/tools/ptyTerminal.js +1108 -0
- package/src/tools/ptyTerminal.ts +1245 -0
- package/src/tools/registry.js +21 -12
- package/src/tools/registry.ts +21 -12
- package/src/tools/toolOutputStore.js +26 -4
- package/src/tools/toolOutputStore.ts +22 -4
- package/src/tools/webFetch.js +158 -11
- package/src/tools/webFetch.ts +145 -11
- package/src/tools/webSearch.js +123 -36
- package/src/tools/webSearch.ts +124 -33
- package/src/tui/banner.js +5 -1
- package/src/tui/banner.ts +6 -1
- package/src/tui/chatRenderer.js +1 -2
- package/src/tui/chatRenderer.ts +1 -2
- package/src/tui/completion.js +1 -0
- package/src/tui/completion.ts +1 -0
- package/src/tui/composerControls.js +111 -27
- package/src/tui/composerControls.ts +124 -28
- package/src/tui/dialogs.js +3 -16
- package/src/tui/dialogs.ts +3 -16
- package/src/tui/home.js +1 -0
- package/src/tui/home.ts +1 -0
- package/src/tui/invocation.js +1 -2
- package/src/tui/invocation.ts +1 -2
- package/src/tui/modelPicker.js +22 -12
- package/src/tui/modelPicker.ts +22 -12
- package/src/tui/overlay.js +2 -5
- package/src/tui/overlay.ts +2 -5
- package/src/tui/prompt.js +6 -4
- package/src/tui/prompt.ts +6 -4
- package/src/tui/selectList.js +4 -12
- package/src/tui/selectList.ts +4 -12
- package/src/tui/setup.js +22 -9
- package/src/tui/setup.ts +26 -9
- package/src/tui/statusLine.ts +2 -0
- package/src/web/client/browserPanel.js +905 -0
- package/src/web/client/browserPanel.ts +872 -0
- package/src/web/client/chatStream.js +321 -0
- package/src/web/client/chatStream.ts +297 -0
- package/src/web/client/cliPanel.js +165 -0
- package/src/web/client/cliPanel.ts +171 -0
- package/src/web/client/composer.js +204 -0
- package/src/web/client/composer.ts +209 -0
- package/src/web/client/diffPanel.js +176 -0
- package/src/web/client/diffPanel.ts +203 -0
- package/src/web/client/dom.js +271 -0
- package/src/web/client/dom.ts +272 -0
- package/src/web/client/filesAndCanvas.js +233 -0
- package/src/web/client/filesAndCanvas.ts +240 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +316 -0
- package/src/web/client/main.ts +391 -0
- package/src/web/client/markdown.js +364 -0
- package/src/web/client/markdown.ts +373 -0
- package/src/web/client/modelPicker.js +455 -0
- package/src/web/client/modelPicker.ts +451 -0
- package/src/web/client/permissionPresetsUi.js +307 -0
- package/src/web/client/permissionPresetsUi.ts +333 -0
- package/src/web/client/sessions.js +353 -0
- package/src/web/client/sessions.ts +372 -0
- package/src/web/client/settingsModal.js +824 -0
- package/src/web/client/settingsModal.ts +959 -0
- package/src/web/client/state.js +280 -0
- package/src/web/client/state.ts +259 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +89 -0
- package/src/web/client/studioLayout.ts +103 -0
- package/src/web/client/studioShell.js +660 -0
- package/src/web/client/studioShell.ts +672 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +606 -0
- package/src/web/client/terminalPanel.ts +632 -0
- package/src/web/client/terminalTheme.js +249 -0
- package/src/web/client/terminalTheme.ts +258 -0
- package/src/web/client/turnView.js +934 -0
- package/src/web/client/turnView.ts +981 -0
- package/src/web/client/types.js +1 -0
- package/src/web/client/types.ts +322 -0
- package/src/web/client/validators.js +147 -0
- package/src/web/client/validators.ts +140 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +409 -0
- package/src/web/server/routesBrowser.ts +435 -0
- package/src/web/server/routesChat.js +304 -0
- package/src/web/server/routesChat.ts +347 -0
- package/src/web/server/routesCore.js +472 -0
- package/src/web/server/routesCore.ts +522 -0
- package/src/web/server/routesSettings.js +344 -0
- package/src/web/server/routesSettings.ts +397 -0
- package/src/web/server/routesTerminal.js +162 -0
- package/src/web/server/routesTerminal.ts +182 -0
- package/src/web/server/routesWorkspace.js +510 -0
- package/src/web/server/routesWorkspace.ts +546 -0
- package/src/web/server/security.js +98 -0
- package/src/web/server/security.ts +108 -0
- package/src/web/server/sessionTranscript.js +586 -0
- package/src/web/server/sessionTranscript.ts +566 -0
- package/src/web/server/staticAssets.js +104 -0
- package/src/web/server/staticAssets.ts +116 -0
- package/src/web/server/types.js +1 -0
- package/src/web/server/types.ts +135 -0
- package/src/web/server/workspaceFiles.js +368 -0
- package/src/web/server/workspaceFiles.ts +363 -0
- package/src/web/skybridgeServer.js +78 -2448
- package/src/web/skybridgeServer.ts +120 -2600
- package/src/web/skybridgeUi.js +20 -450
- package/src/web/skybridgeUi.ts +24 -455
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +935 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +951 -0
- package/src/web/styles/thread.css +221 -0
- package/src/web/styles/tokens.css +94 -0
- package/src/web/ui/brandMark.js +73 -0
- package/src/web/ui/brandMark.ts +82 -0
- package/src/web/ui/modalsTemplate.js +388 -0
- package/src/web/ui/modalsTemplate.ts +388 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +256 -0
- package/src/web/ui/studioTemplate.ts +256 -0
- package/src/web/ui/workspaceTemplate.js +72 -0
- package/src/web/ui/workspaceTemplate.ts +73 -0
- package/src/worktreeManager.js +16 -1
- package/src/worktreeManager.ts +22 -1
- package/src/web/skybridgeClientScript.js +0 -3951
- package/src/web/skybridgeClientScript.ts +0 -3952
- package/src/web/skybridgeStyles.js +0 -827
- package/src/web/skybridgeStyles.ts +0 -828
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export interface StreamSmoother {
|
|
2
|
+
push(delta: string): void;
|
|
3
|
+
setFull(text: string, streaming: boolean): void;
|
|
4
|
+
flush(): void;
|
|
5
|
+
getText(): string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function solveBarrierBisect(fn: (x: number) => number, lo: number, hi: number): number {
|
|
9
|
+
if (lo >= hi) return hi;
|
|
10
|
+
let a = lo;
|
|
11
|
+
let b = hi;
|
|
12
|
+
if (fn(a) >= 0) return a;
|
|
13
|
+
if (fn(b) <= 0) return b;
|
|
14
|
+
for (let k = 0; k < 22 && (b - a) > 0.05; k += 1) {
|
|
15
|
+
const mid = (a + b) * 0.5;
|
|
16
|
+
if (fn(mid) <= 0) a = mid;
|
|
17
|
+
else b = mid;
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createStreamSmoother(
|
|
23
|
+
onRender: (visibleText: string, isStreaming: boolean, shownLen: number) => void
|
|
24
|
+
): StreamSmoother {
|
|
25
|
+
let fullText = '';
|
|
26
|
+
let shownLen = 0;
|
|
27
|
+
let vel = 120;
|
|
28
|
+
let lastT = 0;
|
|
29
|
+
let startMs = 0;
|
|
30
|
+
const arrivals: Array<[number, number]> = [[-9999, 0]];
|
|
31
|
+
let done = false;
|
|
32
|
+
let rafId = 0;
|
|
33
|
+
const alpha = 0.99;
|
|
34
|
+
const gamma = 1e-5;
|
|
35
|
+
const reducedMotion = Boolean(
|
|
36
|
+
window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
function step(): void {
|
|
40
|
+
rafId = 0;
|
|
41
|
+
const total = fullText.length;
|
|
42
|
+
if (reducedMotion || total === 0) {
|
|
43
|
+
shownLen = total;
|
|
44
|
+
onRender(fullText, !done, shownLen);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (shownLen >= total) {
|
|
48
|
+
if (done) onRender(fullText, false, total);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const nowSec = (performance.now() - startMs) / 1000;
|
|
52
|
+
const dt = Math.max(nowSec - lastT, 1e-4);
|
|
53
|
+
const upper = total + (done ? 120 : 0);
|
|
54
|
+
const lagTarget = 0.9 * nowSec - 0.25;
|
|
55
|
+
let minChars = 0;
|
|
56
|
+
for (let idx = arrivals.length - 1; idx >= 0; idx -= 1) {
|
|
57
|
+
const pair = arrivals[idx]!;
|
|
58
|
+
if (pair[0] < lagTarget) {
|
|
59
|
+
minChars = pair[1];
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const lo = Math.max(shownLen, Math.min(total, done ? total : minChars));
|
|
64
|
+
const nextX = done && (total - shownLen) <= 18
|
|
65
|
+
? total
|
|
66
|
+
: solveBarrierBisect((x) => {
|
|
67
|
+
const d = (x - shownLen) / dt;
|
|
68
|
+
return 2 * (done ? gamma * 0.01 : gamma) * (1 / dt) * (d - vel)
|
|
69
|
+
- 1 / Math.max(1e-4, x - lo)
|
|
70
|
+
+ 1 / Math.max(1e-4, upper - x);
|
|
71
|
+
}, lo, upper);
|
|
72
|
+
const clamped = Math.min(total, Math.max(shownLen + 1, Math.round(nextX)));
|
|
73
|
+
const instV = (clamped - shownLen) / dt;
|
|
74
|
+
vel = Math.max(45, Math.min(2400, alpha * vel + (1 - alpha) * instV));
|
|
75
|
+
shownLen = clamped;
|
|
76
|
+
lastT = nowSec;
|
|
77
|
+
onRender(fullText.slice(0, shownLen), !done || shownLen < total, shownLen);
|
|
78
|
+
if (shownLen < total) rafId = window.requestAnimationFrame(step);
|
|
79
|
+
else if (done) onRender(fullText, false, total);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function schedule(): void {
|
|
83
|
+
if (!rafId) rafId = window.requestAnimationFrame(step);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
push(delta: string): void {
|
|
88
|
+
if (!delta) return;
|
|
89
|
+
if (!startMs) { startMs = performance.now(); lastT = 0; }
|
|
90
|
+
fullText += delta;
|
|
91
|
+
const tSec = (performance.now() - startMs) / 1000;
|
|
92
|
+
arrivals.push([tSec, fullText.length]);
|
|
93
|
+
if (arrivals.length > 120) arrivals.shift();
|
|
94
|
+
schedule();
|
|
95
|
+
},
|
|
96
|
+
setFull(text: string, streaming: boolean): void {
|
|
97
|
+
fullText = String(text || '');
|
|
98
|
+
if (!streaming) {
|
|
99
|
+
if (rafId) { window.cancelAnimationFrame(rafId); rafId = 0; }
|
|
100
|
+
done = true;
|
|
101
|
+
shownLen = fullText.length;
|
|
102
|
+
onRender(fullText, false, shownLen);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!startMs) { startMs = performance.now(); lastT = 0; }
|
|
106
|
+
arrivals.push([(performance.now() - startMs) / 1000, fullText.length]);
|
|
107
|
+
schedule();
|
|
108
|
+
},
|
|
109
|
+
flush(): void {
|
|
110
|
+
done = true;
|
|
111
|
+
if (rafId) { window.cancelAnimationFrame(rafId); rafId = 0; }
|
|
112
|
+
shownLen = fullText.length;
|
|
113
|
+
onRender(fullText, false, shownLen);
|
|
114
|
+
},
|
|
115
|
+
getText(): string {
|
|
116
|
+
return fullText;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export const STUDIO_LAYOUT_KEY = 'causyne/web/studioLayout/v1';
|
|
2
|
+
export const VALID_STUDIO_TABS = new Set(['start', 'files', 'canvas', 'terminal', 'browser', 'diff', 'cli']);
|
|
3
|
+
const MIN_SPLIT_PANE_WIDTH_PX = 280;
|
|
4
|
+
export function isValidStudioTab(tab) {
|
|
5
|
+
return typeof tab === 'string' && VALID_STUDIO_TABS.has(tab);
|
|
6
|
+
}
|
|
7
|
+
export function clampSplitRatio(raw) {
|
|
8
|
+
const n = Number(raw);
|
|
9
|
+
if (!Number.isFinite(n))
|
|
10
|
+
return 0.5;
|
|
11
|
+
return Math.max(0.25, Math.min(0.75, n));
|
|
12
|
+
}
|
|
13
|
+
export function pickDistinctSecondaryTab(primaryTab, preferred) {
|
|
14
|
+
if (preferred && isValidStudioTab(preferred) && preferred !== primaryTab)
|
|
15
|
+
return preferred;
|
|
16
|
+
const fallbacks = ['terminal', 'browser', 'files', 'canvas', 'diff', 'cli', 'start'];
|
|
17
|
+
for (const candidate of fallbacks) {
|
|
18
|
+
if (candidate !== primaryTab)
|
|
19
|
+
return candidate;
|
|
20
|
+
}
|
|
21
|
+
return 'terminal';
|
|
22
|
+
}
|
|
23
|
+
export function halvesFitWidth(containerWidthPx) {
|
|
24
|
+
return Number.isFinite(containerWidthPx) && containerWidthPx >= MIN_SPLIT_PANE_WIDTH_PX * 2;
|
|
25
|
+
}
|
|
26
|
+
export function normalizeOpenTabs(rawTabs, primaryTab, splitActive, secondaryTab) {
|
|
27
|
+
const out = [];
|
|
28
|
+
const seen = new Set();
|
|
29
|
+
if (Array.isArray(rawTabs)) {
|
|
30
|
+
for (const item of rawTabs) {
|
|
31
|
+
if (isValidStudioTab(item) && !seen.has(item)) {
|
|
32
|
+
seen.add(item);
|
|
33
|
+
out.push(item);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!seen.has(primaryTab)) {
|
|
38
|
+
seen.add(primaryTab);
|
|
39
|
+
out.push(primaryTab);
|
|
40
|
+
}
|
|
41
|
+
if (splitActive && isValidStudioTab(secondaryTab) && !seen.has(secondaryTab)) {
|
|
42
|
+
seen.add(secondaryTab);
|
|
43
|
+
out.push(secondaryTab);
|
|
44
|
+
}
|
|
45
|
+
return out.length > 0 ? out : ['start'];
|
|
46
|
+
}
|
|
47
|
+
export function loadPersistedStudioLayout() {
|
|
48
|
+
const defaults = {
|
|
49
|
+
openTabs: ['start'],
|
|
50
|
+
primaryTab: 'start',
|
|
51
|
+
splitActive: false,
|
|
52
|
+
secondaryTab: 'terminal',
|
|
53
|
+
splitRatio: 0.5
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
const raw = window.localStorage.getItem(STUDIO_LAYOUT_KEY);
|
|
57
|
+
if (!raw)
|
|
58
|
+
return defaults;
|
|
59
|
+
const parsed = JSON.parse(raw);
|
|
60
|
+
const primaryTab = isValidStudioTab(parsed.primaryTab) ? parsed.primaryTab : defaults.primaryTab;
|
|
61
|
+
const splitActive = Boolean(parsed.splitActive);
|
|
62
|
+
const secondaryTab = pickDistinctSecondaryTab(primaryTab, parsed.secondaryTab);
|
|
63
|
+
const openTabs = normalizeOpenTabs(parsed.openTabs, primaryTab, splitActive, secondaryTab);
|
|
64
|
+
return {
|
|
65
|
+
openTabs,
|
|
66
|
+
primaryTab,
|
|
67
|
+
splitActive,
|
|
68
|
+
secondaryTab,
|
|
69
|
+
splitRatio: clampSplitRatio(parsed.splitRatio)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return defaults;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function persistStudioLayout(layout) {
|
|
77
|
+
try {
|
|
78
|
+
window.localStorage.setItem(STUDIO_LAYOUT_KEY, JSON.stringify({
|
|
79
|
+
openTabs: layout.openTabs,
|
|
80
|
+
primaryTab: layout.primaryTab,
|
|
81
|
+
splitActive: layout.splitActive,
|
|
82
|
+
secondaryTab: layout.secondaryTab,
|
|
83
|
+
splitRatio: clampSplitRatio(layout.splitRatio)
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Ignore storage unavailability
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export const STUDIO_LAYOUT_KEY = 'causyne/web/studioLayout/v1';
|
|
2
|
+
export const VALID_STUDIO_TABS = new Set(['start', 'files', 'canvas', 'terminal', 'browser', 'diff', 'cli']);
|
|
3
|
+
const MIN_SPLIT_PANE_WIDTH_PX = 280;
|
|
4
|
+
|
|
5
|
+
export interface StudioLayoutState {
|
|
6
|
+
openTabs: string[];
|
|
7
|
+
primaryTab: string;
|
|
8
|
+
splitActive: boolean;
|
|
9
|
+
secondaryTab: string;
|
|
10
|
+
splitRatio: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isValidStudioTab(tab: unknown): tab is string {
|
|
14
|
+
return typeof tab === 'string' && VALID_STUDIO_TABS.has(tab);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function clampSplitRatio(raw: unknown): number {
|
|
18
|
+
const n = Number(raw);
|
|
19
|
+
if (!Number.isFinite(n)) return 0.5;
|
|
20
|
+
return Math.max(0.25, Math.min(0.75, n));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function pickDistinctSecondaryTab(primaryTab: string, preferred?: string): string {
|
|
24
|
+
if (preferred && isValidStudioTab(preferred) && preferred !== primaryTab) return preferred;
|
|
25
|
+
const fallbacks = ['terminal', 'browser', 'files', 'canvas', 'diff', 'cli', 'start'];
|
|
26
|
+
for (const candidate of fallbacks) {
|
|
27
|
+
if (candidate !== primaryTab) return candidate;
|
|
28
|
+
}
|
|
29
|
+
return 'terminal';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function halvesFitWidth(containerWidthPx: number): boolean {
|
|
33
|
+
return Number.isFinite(containerWidthPx) && containerWidthPx >= MIN_SPLIT_PANE_WIDTH_PX * 2;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function normalizeOpenTabs(
|
|
37
|
+
rawTabs: unknown,
|
|
38
|
+
primaryTab: string,
|
|
39
|
+
splitActive: boolean,
|
|
40
|
+
secondaryTab: string
|
|
41
|
+
): string[] {
|
|
42
|
+
const out: string[] = [];
|
|
43
|
+
const seen = new Set<string>();
|
|
44
|
+
if (Array.isArray(rawTabs)) {
|
|
45
|
+
for (const item of rawTabs) {
|
|
46
|
+
if (isValidStudioTab(item) && !seen.has(item)) {
|
|
47
|
+
seen.add(item);
|
|
48
|
+
out.push(item);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!seen.has(primaryTab)) {
|
|
53
|
+
seen.add(primaryTab);
|
|
54
|
+
out.push(primaryTab);
|
|
55
|
+
}
|
|
56
|
+
if (splitActive && isValidStudioTab(secondaryTab) && !seen.has(secondaryTab)) {
|
|
57
|
+
seen.add(secondaryTab);
|
|
58
|
+
out.push(secondaryTab);
|
|
59
|
+
}
|
|
60
|
+
return out.length > 0 ? out : ['start'];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function loadPersistedStudioLayout(): StudioLayoutState {
|
|
64
|
+
const defaults: StudioLayoutState = {
|
|
65
|
+
openTabs: ['start'],
|
|
66
|
+
primaryTab: 'start',
|
|
67
|
+
splitActive: false,
|
|
68
|
+
secondaryTab: 'terminal',
|
|
69
|
+
splitRatio: 0.5
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const raw = window.localStorage.getItem(STUDIO_LAYOUT_KEY);
|
|
73
|
+
if (!raw) return defaults;
|
|
74
|
+
const parsed = JSON.parse(raw) as Partial<StudioLayoutState>;
|
|
75
|
+
const primaryTab = isValidStudioTab(parsed.primaryTab) ? parsed.primaryTab : defaults.primaryTab;
|
|
76
|
+
const splitActive = Boolean(parsed.splitActive);
|
|
77
|
+
const secondaryTab = pickDistinctSecondaryTab(primaryTab, parsed.secondaryTab);
|
|
78
|
+
const openTabs = normalizeOpenTabs(parsed.openTabs, primaryTab, splitActive, secondaryTab);
|
|
79
|
+
return {
|
|
80
|
+
openTabs,
|
|
81
|
+
primaryTab,
|
|
82
|
+
splitActive,
|
|
83
|
+
secondaryTab,
|
|
84
|
+
splitRatio: clampSplitRatio(parsed.splitRatio)
|
|
85
|
+
};
|
|
86
|
+
} catch {
|
|
87
|
+
return defaults;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function persistStudioLayout(layout: StudioLayoutState): void {
|
|
92
|
+
try {
|
|
93
|
+
window.localStorage.setItem(STUDIO_LAYOUT_KEY, JSON.stringify({
|
|
94
|
+
openTabs: layout.openTabs,
|
|
95
|
+
primaryTab: layout.primaryTab,
|
|
96
|
+
splitActive: layout.splitActive,
|
|
97
|
+
secondaryTab: layout.secondaryTab,
|
|
98
|
+
splitRatio: clampSplitRatio(layout.splitRatio)
|
|
99
|
+
}));
|
|
100
|
+
} catch {
|
|
101
|
+
// Ignore storage unavailability
|
|
102
|
+
}
|
|
103
|
+
}
|