@causyne/agent 1.20.124 → 1.20.127
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/package.json +4 -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 +83 -27
- package/src/agentLoop.ts +92 -26
- package/src/approvalPolicy.js +34 -10
- package/src/approvalPolicy.ts +42 -11
- package/src/browser/causyneBrowser.js +30 -3
- package/src/browser/causyneBrowser.ts +33 -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 +188 -32
- package/src/commands.ts +209 -32
- 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/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/providers/antigravity.js +62 -9
- package/src/providers/antigravity.ts +73 -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/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/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 +1096 -0
- package/src/tools/ptyTerminal.ts +1231 -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 +702 -0
- package/src/web/client/browserPanel.ts +663 -0
- package/src/web/client/chatStream.js +309 -0
- package/src/web/client/chatStream.ts +289 -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 +220 -0
- package/src/web/client/dom.ts +221 -0
- package/src/web/client/filesAndCanvas.js +231 -0
- package/src/web/client/filesAndCanvas.ts +238 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +301 -0
- package/src/web/client/main.ts +368 -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 +191 -0
- package/src/web/client/settingsModal.ts +176 -0
- package/src/web/client/state.js +250 -0
- package/src/web/client/state.ts +233 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +54 -0
- package/src/web/client/studioLayout.ts +60 -0
- package/src/web/client/studioShell.js +327 -0
- package/src/web/client/studioShell.ts +340 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +357 -0
- package/src/web/client/terminalPanel.ts +345 -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 +319 -0
- package/src/web/client/validators.js +106 -0
- package/src/web/client/validators.ts +96 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +355 -0
- package/src/web/server/routesBrowser.ts +386 -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/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 +80 -0
- package/src/web/server/staticAssets.ts +91 -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 +76 -2449
- package/src/web/skybridgeServer.ts +118 -2600
- package/src/web/skybridgeUi.js +16 -450
- package/src/web/skybridgeUi.ts +16 -454
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +436 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +723 -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 +139 -0
- package/src/web/ui/modalsTemplate.ts +139 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +258 -0
- package/src/web/ui/studioTemplate.ts +258 -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,353 @@
|
|
|
1
|
+
import { dom } from './dom.js';
|
|
2
|
+
import { apiUrl, authHeaders, scrollToBottom, setLiveness, setStageMode, state, syncUsagePill, updateComposerMetrics } from './state.js';
|
|
3
|
+
import { renderAttachmentChips } from './composer.js';
|
|
4
|
+
import { loadFiles, setCanvasPreviewMode, syncArtifactVersionSelect } from './filesAndCanvas.js';
|
|
5
|
+
import { loadDiff, syncDiffControlsUi } from './diffPanel.js';
|
|
6
|
+
import { refreshLiveBrowserState, setBrowserEngine, startLiveBrowserStream } from './browserPanel.js';
|
|
7
|
+
import { loadCliOverview } from './cliPanel.js';
|
|
8
|
+
import { appendUserTurn, createAssistantTurn, resetThreadSpacer } from './turnView.js';
|
|
9
|
+
import { loadPermissionPresets, syncPermissionPresetLock } from './permissionPresetsUi.js';
|
|
10
|
+
let callbacks = {
|
|
11
|
+
attachToActiveSessionStream: async () => { }
|
|
12
|
+
};
|
|
13
|
+
export function configureSessionsCallbacks(cbs) {
|
|
14
|
+
callbacks = cbs;
|
|
15
|
+
}
|
|
16
|
+
function sessionKey(id) {
|
|
17
|
+
return id || '__draft__';
|
|
18
|
+
}
|
|
19
|
+
function bucketLabel(ts) {
|
|
20
|
+
const now = new Date();
|
|
21
|
+
const startToday = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
|
|
22
|
+
const dayMs = 86400000;
|
|
23
|
+
if (ts >= startToday)
|
|
24
|
+
return 'Today';
|
|
25
|
+
if (ts >= startToday - dayMs)
|
|
26
|
+
return 'Yesterday';
|
|
27
|
+
if (ts >= startToday - 7 * dayMs)
|
|
28
|
+
return 'Previous 7 days';
|
|
29
|
+
return 'Older';
|
|
30
|
+
}
|
|
31
|
+
function updateActiveSessionRow(activeId) {
|
|
32
|
+
dom.sessionListEl.querySelectorAll('.session-item').forEach((elItem) => {
|
|
33
|
+
elItem.classList.toggle('active', Boolean(activeId && elItem.dataset.sessionId === activeId));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export function startInlineSessionRename(item, titleBtn, s) {
|
|
37
|
+
const input = document.createElement('input');
|
|
38
|
+
input.type = 'text';
|
|
39
|
+
input.className = 'session-rename-input';
|
|
40
|
+
input.value = s.title || '';
|
|
41
|
+
input.maxLength = 80;
|
|
42
|
+
titleBtn.style.display = 'none';
|
|
43
|
+
item.insertBefore(input, titleBtn);
|
|
44
|
+
input.focus();
|
|
45
|
+
input.select();
|
|
46
|
+
let finished = false;
|
|
47
|
+
const finish = async (save) => {
|
|
48
|
+
if (finished)
|
|
49
|
+
return;
|
|
50
|
+
finished = true;
|
|
51
|
+
const next = (input.value || '').trim();
|
|
52
|
+
input.remove();
|
|
53
|
+
titleBtn.style.display = '';
|
|
54
|
+
if (!save || !next || next === s.title)
|
|
55
|
+
return;
|
|
56
|
+
s.title = next;
|
|
57
|
+
titleBtn.textContent = next;
|
|
58
|
+
await fetch(apiUrl(`/api/sessions/${encodeURIComponent(s.id)}`), {
|
|
59
|
+
method: 'PATCH',
|
|
60
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
61
|
+
body: JSON.stringify({ title: next })
|
|
62
|
+
}).catch(() => { });
|
|
63
|
+
};
|
|
64
|
+
input.addEventListener('click', (ev) => ev.stopPropagation());
|
|
65
|
+
input.addEventListener('keydown', (ev) => {
|
|
66
|
+
if (ev.key === 'Enter') {
|
|
67
|
+
ev.preventDefault();
|
|
68
|
+
ev.stopPropagation();
|
|
69
|
+
void finish(true);
|
|
70
|
+
}
|
|
71
|
+
else if (ev.key === 'Escape') {
|
|
72
|
+
ev.preventDefault();
|
|
73
|
+
ev.stopPropagation();
|
|
74
|
+
void finish(false);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
input.addEventListener('blur', () => { void finish(true); });
|
|
78
|
+
}
|
|
79
|
+
export function renderSessionList() {
|
|
80
|
+
const prevScroll = dom.sessionListEl.scrollTop;
|
|
81
|
+
const q = (dom.sessionSearchEl.value || '').trim().toLowerCase();
|
|
82
|
+
const filtered = state.sessions.filter((s) => !q || String(s.title || '').toLowerCase().includes(q));
|
|
83
|
+
dom.sessionListEl.textContent = '';
|
|
84
|
+
if (filtered.length === 0) {
|
|
85
|
+
const empty = document.createElement('div');
|
|
86
|
+
empty.className = 'session-empty';
|
|
87
|
+
empty.textContent = q ? 'No matching chats.' : 'No saved workspace chats yet.';
|
|
88
|
+
dom.sessionListEl.appendChild(empty);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let currentGroup = '';
|
|
92
|
+
for (const s of filtered) {
|
|
93
|
+
const grp = bucketLabel(s.updatedAt || s.createdAt || 0);
|
|
94
|
+
if (grp !== currentGroup) {
|
|
95
|
+
currentGroup = grp;
|
|
96
|
+
const gl = document.createElement('div');
|
|
97
|
+
gl.className = 'session-group-label';
|
|
98
|
+
gl.textContent = grp;
|
|
99
|
+
dom.sessionListEl.appendChild(gl);
|
|
100
|
+
}
|
|
101
|
+
const item = document.createElement('div');
|
|
102
|
+
item.dataset.sessionId = s.id;
|
|
103
|
+
item.className = `session-item${s.id === state.sessionId ? ' active' : ''}`;
|
|
104
|
+
item.addEventListener('click', () => { void loadSessionTranscript(s.id); });
|
|
105
|
+
if (s.running) {
|
|
106
|
+
const dot = document.createElement('span');
|
|
107
|
+
dot.className = `session-run-dot${s.awaitingClient ? ' awaiting' : ''}`;
|
|
108
|
+
dot.title = s.awaitingClient ? 'Waiting for your input' : 'Running in background';
|
|
109
|
+
item.appendChild(dot);
|
|
110
|
+
}
|
|
111
|
+
const titleBtn = document.createElement('button');
|
|
112
|
+
titleBtn.type = 'button';
|
|
113
|
+
titleBtn.className = 'session-title';
|
|
114
|
+
titleBtn.textContent = s.title || 'Untitled';
|
|
115
|
+
titleBtn.title = s.title || 'Untitled';
|
|
116
|
+
const actions = document.createElement('div');
|
|
117
|
+
actions.className = 'session-actions';
|
|
118
|
+
const renBtn = document.createElement('button');
|
|
119
|
+
renBtn.type = 'button';
|
|
120
|
+
renBtn.className = 'mini-icon-btn';
|
|
121
|
+
renBtn.textContent = 'R';
|
|
122
|
+
renBtn.title = 'Rename';
|
|
123
|
+
renBtn.addEventListener('click', (e) => {
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
startInlineSessionRename(item, titleBtn, s);
|
|
126
|
+
});
|
|
127
|
+
const delBtn = document.createElement('button');
|
|
128
|
+
delBtn.type = 'button';
|
|
129
|
+
delBtn.className = 'mini-icon-btn';
|
|
130
|
+
delBtn.textContent = 'x';
|
|
131
|
+
delBtn.title = 'Delete';
|
|
132
|
+
delBtn.addEventListener('click', async (e) => {
|
|
133
|
+
e.stopPropagation();
|
|
134
|
+
await fetch(apiUrl(`/api/sessions/${encodeURIComponent(s.id)}`), {
|
|
135
|
+
method: 'DELETE',
|
|
136
|
+
headers: authHeaders()
|
|
137
|
+
}).catch(() => { });
|
|
138
|
+
state.sessionWorkspaces.delete(s.id);
|
|
139
|
+
if (state.sessionId === s.id)
|
|
140
|
+
void startFreshChat();
|
|
141
|
+
void loadSessions();
|
|
142
|
+
});
|
|
143
|
+
actions.appendChild(renBtn);
|
|
144
|
+
actions.appendChild(delBtn);
|
|
145
|
+
item.appendChild(titleBtn);
|
|
146
|
+
item.appendChild(actions);
|
|
147
|
+
dom.sessionListEl.appendChild(item);
|
|
148
|
+
}
|
|
149
|
+
dom.sessionListEl.scrollTop = prevScroll;
|
|
150
|
+
}
|
|
151
|
+
export async function loadSessions() {
|
|
152
|
+
const res = await fetch(apiUrl('/api/sessions'), { headers: authHeaders() });
|
|
153
|
+
if (!res.ok)
|
|
154
|
+
return;
|
|
155
|
+
const data = await res.json();
|
|
156
|
+
state.sessions = data.sessions || [];
|
|
157
|
+
renderSessionList();
|
|
158
|
+
}
|
|
159
|
+
export function saveCurrentSessionWorkspace() {
|
|
160
|
+
const key = sessionKey(state.sessionId);
|
|
161
|
+
state.sessionWorkspaces.set(key, {
|
|
162
|
+
studioOpen: dom.appEl.classList.contains('studio-open'),
|
|
163
|
+
studioTab: state.studioTab,
|
|
164
|
+
canvasPath: dom.filePathInput.value || '',
|
|
165
|
+
canvasContent: dom.fileContentInput.value || '',
|
|
166
|
+
canvasPreviewMode: Boolean(state.canvasPreviewMode),
|
|
167
|
+
canvasStatus: dom.fileStatusEl.textContent || 'Ready',
|
|
168
|
+
canvasDirty: Boolean(state.canvasDirty),
|
|
169
|
+
diffScope: state.diffScope,
|
|
170
|
+
diffStaged: Boolean(state.diffStaged),
|
|
171
|
+
attachments: state.attachments.slice(),
|
|
172
|
+
draftPrompt: dom.promptInput.value || '',
|
|
173
|
+
usageTokens: state.usageTokens,
|
|
174
|
+
browserEngine: state.browserEngine,
|
|
175
|
+
browserMode: state.browserMode,
|
|
176
|
+
browserUrl: state.browserUrl,
|
|
177
|
+
browserSrcdoc: state.browserSrcdoc,
|
|
178
|
+
cliConsoleText: dom.cliConsoleEl.textContent || 'Select a command above or type /help.',
|
|
179
|
+
cliStatusText: dom.cliStatusEl.textContent || 'Ready'
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
export function applySessionWorkspace(nextSessionId) {
|
|
183
|
+
const key = sessionKey(nextSessionId);
|
|
184
|
+
const saved = state.sessionWorkspaces.get(key) || null;
|
|
185
|
+
state.attachments = saved ? saved.attachments.slice() : [];
|
|
186
|
+
renderAttachmentChips();
|
|
187
|
+
dom.promptInput.value = saved ? saved.draftPrompt : '';
|
|
188
|
+
updateComposerMetrics();
|
|
189
|
+
syncUsagePill(saved ? saved.usageTokens : 0);
|
|
190
|
+
dom.filePathInput.value = saved ? saved.canvasPath : '';
|
|
191
|
+
dom.fileContentInput.value = saved ? saved.canvasContent : '';
|
|
192
|
+
state.canvasDirty = saved ? Boolean(saved.canvasDirty) : false;
|
|
193
|
+
dom.fileStatusEl.textContent = saved ? saved.canvasStatus : 'Ready';
|
|
194
|
+
dom.canvasHtmlFrame.removeAttribute('srcdoc');
|
|
195
|
+
dom.canvasPreviewEl.textContent = '';
|
|
196
|
+
syncArtifactVersionSelect(dom.filePathInput.value.trim());
|
|
197
|
+
setCanvasPreviewMode(saved ? Boolean(saved.canvasPreviewMode) : false);
|
|
198
|
+
state.diffScope = saved ? saved.diffScope : (nextSessionId ? 'session' : 'workspace');
|
|
199
|
+
state.diffStaged = saved ? Boolean(saved.diffStaged) : false;
|
|
200
|
+
syncDiffControlsUi();
|
|
201
|
+
dom.diffListEl.textContent = '';
|
|
202
|
+
dom.diffSummaryEl.textContent = 'Loading...';
|
|
203
|
+
dom.cliConsoleEl.textContent = saved ? saved.cliConsoleText : 'Select a command above or type /help.';
|
|
204
|
+
dom.cliStatusEl.textContent = saved ? saved.cliStatusText : 'Ready';
|
|
205
|
+
if (saved && saved.browserEngine === 'frame') {
|
|
206
|
+
state.browserMode = saved.browserMode || 'empty';
|
|
207
|
+
state.browserUrl = saved.browserUrl || '';
|
|
208
|
+
state.browserSrcdoc = saved.browserSrcdoc || '';
|
|
209
|
+
if (state.browserMode === 'srcdoc' && state.browserSrcdoc) {
|
|
210
|
+
dom.browserFrame.removeAttribute('src');
|
|
211
|
+
dom.browserFrame.srcdoc = state.browserSrcdoc;
|
|
212
|
+
}
|
|
213
|
+
else if (state.browserMode === 'url' && state.browserUrl) {
|
|
214
|
+
dom.browserFrame.removeAttribute('srcdoc');
|
|
215
|
+
dom.browserFrame.src = state.browserUrl;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
dom.browserFrame.removeAttribute('srcdoc');
|
|
219
|
+
dom.browserFrame.removeAttribute('src');
|
|
220
|
+
}
|
|
221
|
+
setBrowserEngine('frame');
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
state.browserMode = 'empty';
|
|
225
|
+
state.browserUrl = '';
|
|
226
|
+
state.browserSrcdoc = '';
|
|
227
|
+
dom.browserFrame.removeAttribute('srcdoc');
|
|
228
|
+
dom.browserFrame.removeAttribute('src');
|
|
229
|
+
if (state.browserEngine === 'frame')
|
|
230
|
+
setBrowserEngine('agent');
|
|
231
|
+
}
|
|
232
|
+
if (dom.appEl.classList.contains('studio-open')) {
|
|
233
|
+
if (state.studioTab === 'diff')
|
|
234
|
+
void loadDiff();
|
|
235
|
+
else if (state.studioTab === 'files')
|
|
236
|
+
void loadFiles(state.currentDir, dom.fileFilterEl.value || '');
|
|
237
|
+
else if (state.studioTab === 'cli')
|
|
238
|
+
void loadCliOverview();
|
|
239
|
+
else if (state.studioTab === 'browser' && state.browserEngine === 'agent') {
|
|
240
|
+
void refreshLiveBrowserState(false);
|
|
241
|
+
startLiveBrowserStream();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
export function detachLocalStreamReader() {
|
|
246
|
+
if (state.activeController) {
|
|
247
|
+
try {
|
|
248
|
+
state.activeController.abort();
|
|
249
|
+
}
|
|
250
|
+
catch { /* ignore */ }
|
|
251
|
+
state.activeController = null;
|
|
252
|
+
}
|
|
253
|
+
state.activeTurn = null;
|
|
254
|
+
state.activePrompt = '';
|
|
255
|
+
setLiveness(false, '');
|
|
256
|
+
syncPermissionPresetLock(false);
|
|
257
|
+
updateComposerMetrics();
|
|
258
|
+
}
|
|
259
|
+
export async function loadSessionTranscript(id) {
|
|
260
|
+
if (!id)
|
|
261
|
+
return;
|
|
262
|
+
detachLocalStreamReader();
|
|
263
|
+
saveCurrentSessionWorkspace();
|
|
264
|
+
const seq = ++state.sessionSwitchSeq;
|
|
265
|
+
state.sessionId = id;
|
|
266
|
+
updateActiveSessionRow(id);
|
|
267
|
+
applySessionWorkspace(id);
|
|
268
|
+
void loadPermissionPresets(id);
|
|
269
|
+
if (window.innerWidth <= 960)
|
|
270
|
+
dom.appEl.classList.add('sidebar-collapsed');
|
|
271
|
+
const res = await fetch(apiUrl(`/api/sessions/${encodeURIComponent(id)}`), { headers: authHeaders() }).catch(() => null);
|
|
272
|
+
if (seq !== state.sessionSwitchSeq)
|
|
273
|
+
return;
|
|
274
|
+
if (!res || !res.ok) {
|
|
275
|
+
dom.threadEl.textContent = '';
|
|
276
|
+
resetThreadSpacer();
|
|
277
|
+
setStageMode(true);
|
|
278
|
+
const errTurn = createAssistantTurn('');
|
|
279
|
+
errTurn.addError(res && res.status === 401
|
|
280
|
+
? 'Session authentication expired. Reopen the URL printed by `causyne web`.'
|
|
281
|
+
: `Could not load conversation (HTTP ${res ? res.status : 'network error'}).`);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const data = await res.json().catch(() => null);
|
|
285
|
+
const sess = data?.session;
|
|
286
|
+
if (!sess || seq !== state.sessionSwitchSeq)
|
|
287
|
+
return;
|
|
288
|
+
dom.threadEl.textContent = '';
|
|
289
|
+
resetThreadSpacer();
|
|
290
|
+
dom.threadEl.classList.remove('chat-fade-in');
|
|
291
|
+
void dom.threadEl.offsetWidth;
|
|
292
|
+
dom.threadEl.classList.add('chat-fade-in');
|
|
293
|
+
const msgs = sess.messages || [];
|
|
294
|
+
setStageMode(msgs.length > 0 || Boolean(sess.running));
|
|
295
|
+
let lastUserPrompt = '';
|
|
296
|
+
for (const m of msgs) {
|
|
297
|
+
if (m.role === 'user') {
|
|
298
|
+
lastUserPrompt = m.content || '';
|
|
299
|
+
appendUserTurn(lastUserPrompt, [], false);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
const t = createAssistantTurn(lastUserPrompt, { restored: true });
|
|
303
|
+
if (Array.isArray(m.blocks) && m.blocks.length > 0) {
|
|
304
|
+
t.renderRestoredBlocks(m.blocks);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
if (m.reasoning)
|
|
308
|
+
t.updateReasoning({ content: m.reasoning, streaming: false });
|
|
309
|
+
if (Array.isArray(m.steps)) {
|
|
310
|
+
for (const st of m.steps) {
|
|
311
|
+
t.addNativeStep({ actionName: st.tool || '', detail: st.target || st.output || '', message: st.tool || '' }, st.status === 'failed');
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (m.content)
|
|
315
|
+
t.setText(m.content, false);
|
|
316
|
+
}
|
|
317
|
+
t.finish();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (sess.running && sess.activeRun) {
|
|
321
|
+
const runPrompt = sess.activeRun.prompt || lastUserPrompt;
|
|
322
|
+
const lastMsg = msgs[msgs.length - 1];
|
|
323
|
+
if (runPrompt && (!lastMsg || lastMsg.role !== 'user' || lastMsg.content !== runPrompt)) {
|
|
324
|
+
appendUserTurn(runPrompt, [], false);
|
|
325
|
+
}
|
|
326
|
+
scrollToBottom(true);
|
|
327
|
+
void callbacks.attachToActiveSessionStream(id, runPrompt, seq);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const tailMsg = msgs[msgs.length - 1];
|
|
331
|
+
if (tailMsg && tailMsg.role === 'user') {
|
|
332
|
+
const interruptedTurn = createAssistantTurn(lastUserPrompt, { restored: true });
|
|
333
|
+
interruptedTurn.addInterrupted('Causyne\u2019s response was interrupted.', lastUserPrompt);
|
|
334
|
+
interruptedTurn.finish();
|
|
335
|
+
}
|
|
336
|
+
scrollToBottom(true);
|
|
337
|
+
}
|
|
338
|
+
export async function startFreshChat() {
|
|
339
|
+
detachLocalStreamReader();
|
|
340
|
+
saveCurrentSessionWorkspace();
|
|
341
|
+
state.sessionSwitchSeq += 1;
|
|
342
|
+
state.sessionWorkspaces.delete('__draft__');
|
|
343
|
+
state.sessionId = null;
|
|
344
|
+
dom.threadEl.textContent = '';
|
|
345
|
+
resetThreadSpacer();
|
|
346
|
+
setStageMode(false);
|
|
347
|
+
applySessionWorkspace(null);
|
|
348
|
+
updateActiveSessionRow(null);
|
|
349
|
+
void loadPermissionPresets(null);
|
|
350
|
+
dom.promptInput.focus();
|
|
351
|
+
if (window.innerWidth <= 960)
|
|
352
|
+
dom.appEl.classList.add('sidebar-collapsed');
|
|
353
|
+
}
|