@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,566 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isPhysicalPathAllowed } from '../../agent/workspaceBoundary.js';
|
|
4
|
+
import type { SessionMessage } from '../../sessionJournal.js';
|
|
5
|
+
import { SAFE_SESSION_ID_RE } from './security.js';
|
|
6
|
+
import { buildSynthesizedWriteHunk, resolveWorkspaceRelativePath } from './workspaceFiles.js';
|
|
7
|
+
import type {
|
|
8
|
+
SessionDisplayBlock,
|
|
9
|
+
SessionDisplayMessage,
|
|
10
|
+
SessionDisplayStep,
|
|
11
|
+
SessionFileEvidence
|
|
12
|
+
} from './types.js';
|
|
13
|
+
|
|
14
|
+
export const MUTATING_FILE_TOOLS = new Set([
|
|
15
|
+
'fs_write', 'fs_edit', 'multi_edit', 'apply_patch', 'fs_delete', 'fs_move',
|
|
16
|
+
'write_file', 'edit_file', 'write', 'edit', 'multiedit', 'replace_file_content',
|
|
17
|
+
'multi_replace_file_content', 'write_to_file', 'create_file', 'document_forge',
|
|
18
|
+
'ui_forge', 'screenshot', 'generate_media_via_api', 'code_verify_syntax'
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const SHELL_TOOLS = new Set(['sysrun', 'bash', 'shell', 'run_command', 'execute_command']);
|
|
22
|
+
|
|
23
|
+
export function normalizeWorkspaceRelCandidate(
|
|
24
|
+
workspaceRoot: string,
|
|
25
|
+
raw: unknown,
|
|
26
|
+
baseDir?: string
|
|
27
|
+
): string | null {
|
|
28
|
+
if (typeof raw !== 'string') return null;
|
|
29
|
+
let trimmed = raw.trim().replace(/^["'`]+|["'`]+$/g, '');
|
|
30
|
+
if (!trimmed || trimmed.includes('\0') || trimmed.length > 500) return null;
|
|
31
|
+
if (/^https?:\/\//i.test(trimmed)) return null;
|
|
32
|
+
if (trimmed.toLowerCase().startsWith('file://')) {
|
|
33
|
+
trimmed = trimmed.slice('file://'.length);
|
|
34
|
+
const hashIdx = trimmed.indexOf('#');
|
|
35
|
+
if (hashIdx >= 0) trimmed = trimmed.slice(0, hashIdx);
|
|
36
|
+
const queryIdx = trimmed.indexOf('?');
|
|
37
|
+
if (queryIdx >= 0) trimmed = trimmed.slice(0, queryIdx);
|
|
38
|
+
try {
|
|
39
|
+
trimmed = decodeURIComponent(trimmed);
|
|
40
|
+
} catch {
|
|
41
|
+
// Keep raw decoded string if percent encoding is malformed.
|
|
42
|
+
}
|
|
43
|
+
if (/^\/[A-Za-z]:[\\/]/.test(trimmed)) {
|
|
44
|
+
trimmed = trimmed.slice(1);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
const lineAnchor = trimmed.match(/^(.+?\.[a-zA-Z0-9]{1,8})#L\d+(?:-L?\d+)?$/);
|
|
48
|
+
if (lineAnchor?.[1]) trimmed = lineAnchor[1];
|
|
49
|
+
}
|
|
50
|
+
const escNl = trimmed.indexOf('\\n');
|
|
51
|
+
if (escNl >= 0) trimmed = trimmed.slice(0, escNl);
|
|
52
|
+
trimmed = trimmed.replace(/[),.;:]+$/g, '').trim();
|
|
53
|
+
if (!trimmed || trimmed === '.' || trimmed === '/') return null;
|
|
54
|
+
let rel = trimmed;
|
|
55
|
+
if (path.isAbsolute(trimmed)) {
|
|
56
|
+
const absNorm = path.resolve(trimmed);
|
|
57
|
+
if (!isPhysicalPathAllowed(absNorm, [workspaceRoot], false)) return null;
|
|
58
|
+
rel = path.relative(workspaceRoot, absNorm);
|
|
59
|
+
} else if (baseDir && path.isAbsolute(baseDir)) {
|
|
60
|
+
const absNorm = path.resolve(baseDir, trimmed);
|
|
61
|
+
if (!isPhysicalPathAllowed(absNorm, [workspaceRoot], false)) return null;
|
|
62
|
+
rel = path.relative(workspaceRoot, absNorm);
|
|
63
|
+
}
|
|
64
|
+
const abs = resolveWorkspaceRelativePath(workspaceRoot, rel);
|
|
65
|
+
if (!abs) return null;
|
|
66
|
+
const normalized = path.relative(workspaceRoot, abs).split(path.sep).join('/');
|
|
67
|
+
return normalized && !normalized.startsWith('..') ? normalized : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function tokenizeSimpleShell(command: string): string[] {
|
|
71
|
+
const tokens: string[] = [];
|
|
72
|
+
let current = '';
|
|
73
|
+
let quote: '"' | "'" | null = null;
|
|
74
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
75
|
+
const ch = command[i]!;
|
|
76
|
+
if (quote) {
|
|
77
|
+
if (ch === quote) quote = null;
|
|
78
|
+
else current += ch;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (ch === '"' || ch === "'") {
|
|
82
|
+
quote = ch;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
|
|
86
|
+
if (current) { tokens.push(current); current = ''; }
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (ch === ';' || ch === '|') {
|
|
90
|
+
if (current) { tokens.push(current); current = ''; }
|
|
91
|
+
tokens.push(ch);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (ch === '&' && command[i + 1] === '&') {
|
|
95
|
+
if (current) { tokens.push(current); current = ''; }
|
|
96
|
+
tokens.push('&&');
|
|
97
|
+
i += 1;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
current += ch;
|
|
101
|
+
}
|
|
102
|
+
if (current) tokens.push(current);
|
|
103
|
+
return tokens;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function extractShellWriteTargets(command: string, workspaceRoot: string, cwdArg?: unknown): string[] {
|
|
107
|
+
const found: string[] = [];
|
|
108
|
+
let curDir = workspaceRoot;
|
|
109
|
+
if (typeof cwdArg === 'string' && cwdArg.trim()) {
|
|
110
|
+
const resolvedCwd = path.isAbsolute(cwdArg.trim())
|
|
111
|
+
? path.resolve(cwdArg.trim())
|
|
112
|
+
: path.resolve(workspaceRoot, cwdArg.trim());
|
|
113
|
+
if (isPhysicalPathAllowed(resolvedCwd, [workspaceRoot], false)) curDir = resolvedCwd;
|
|
114
|
+
}
|
|
115
|
+
const tokens = tokenizeSimpleShell(command);
|
|
116
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
117
|
+
const tok = tokens[i]!;
|
|
118
|
+
if (tok === 'cd' && tokens[i + 1]) {
|
|
119
|
+
const nextDir = tokens[i + 1]!;
|
|
120
|
+
const resolved = path.isAbsolute(nextDir)
|
|
121
|
+
? path.resolve(nextDir)
|
|
122
|
+
: path.resolve(curDir, nextDir);
|
|
123
|
+
if (isPhysicalPathAllowed(resolved, [workspaceRoot], false)) curDir = resolved;
|
|
124
|
+
i += 1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if ((tok === '-o' || tok === '--output' || tok === '>' || tok === '>>' || tok === 'tee') && tokens[i + 1]) {
|
|
128
|
+
const target = tokens[i + 1]!;
|
|
129
|
+
if (target !== '/dev/null' && !target.startsWith('-')) {
|
|
130
|
+
const norm = normalizeWorkspaceRelCandidate(workspaceRoot, target, curDir);
|
|
131
|
+
if (norm) found.push(norm);
|
|
132
|
+
}
|
|
133
|
+
i += 1;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (tok === 'screencapture') {
|
|
137
|
+
let j = i + 1;
|
|
138
|
+
while (j < tokens.length && tokens[j] !== ';' && tokens[j] !== '&&' && tokens[j] !== '|') {
|
|
139
|
+
const arg = tokens[j]!;
|
|
140
|
+
if (!arg.startsWith('-')) {
|
|
141
|
+
const norm = normalizeWorkspaceRelCandidate(workspaceRoot, arg, curDir);
|
|
142
|
+
if (norm) found.push(norm);
|
|
143
|
+
}
|
|
144
|
+
j += 1;
|
|
145
|
+
}
|
|
146
|
+
i = j - 1;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return found;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function extractPatchPathsFromText(patchText: string): string[] {
|
|
153
|
+
const found: string[] = [];
|
|
154
|
+
for (const line of patchText.split(/\r?\n/)) {
|
|
155
|
+
const m = line.match(/^\*\*\*\s+(?:Add|Update|Delete)\s+File:\s+(.+)$/);
|
|
156
|
+
if (m?.[1]) found.push(m[1].trim());
|
|
157
|
+
const diffM = line.match(/^(?:\+\+\+|---)\s+[ab]\/(.+)$/);
|
|
158
|
+
if (diffM?.[1]) found.push(diffM[1].trim());
|
|
159
|
+
}
|
|
160
|
+
return found;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function buildSynthesizedEditHunk(oldStr: string, newStr: string): {
|
|
164
|
+
additions: number;
|
|
165
|
+
deletions: number;
|
|
166
|
+
hunks: Array<{ header: string; lines: string[] }>;
|
|
167
|
+
} {
|
|
168
|
+
const oldLines = oldStr ? oldStr.split(/\r?\n/) : [];
|
|
169
|
+
const newLines = newStr ? newStr.split(/\r?\n/) : [];
|
|
170
|
+
const diffLines: string[] = [];
|
|
171
|
+
for (const ln of oldLines.slice(0, 80)) diffLines.push(`-${ln}`);
|
|
172
|
+
for (const ln of newLines.slice(0, 80)) diffLines.push(`+${ln}`);
|
|
173
|
+
return {
|
|
174
|
+
additions: newLines.length,
|
|
175
|
+
deletions: oldLines.length,
|
|
176
|
+
hunks: diffLines.length > 0
|
|
177
|
+
? [{ header: `@@ -1,${oldLines.length} +1,${newLines.length} @@`, lines: diffLines }]
|
|
178
|
+
: []
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function hasFileExtension(relPath: string): boolean {
|
|
183
|
+
const base = path.posix.basename(relPath);
|
|
184
|
+
const dot = base.lastIndexOf('.');
|
|
185
|
+
return dot > 0 && dot < base.length - 1 && base.length - dot <= 10;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function extractSessionFileEvidence(
|
|
189
|
+
messages: readonly SessionMessage[],
|
|
190
|
+
workspaceRoot: string
|
|
191
|
+
): Map<string, SessionFileEvidence> {
|
|
192
|
+
const evidenceMap = new Map<string, SessionFileEvidence>();
|
|
193
|
+
const touchedDirs = new Set<string>();
|
|
194
|
+
|
|
195
|
+
const recordFile = (
|
|
196
|
+
raw: unknown,
|
|
197
|
+
opts: {
|
|
198
|
+
status?: 'added' | 'modified' | 'deleted' | undefined;
|
|
199
|
+
bytesWritten?: number | undefined;
|
|
200
|
+
additions?: number | undefined;
|
|
201
|
+
deletions?: number | undefined;
|
|
202
|
+
hunks?: Array<{ header: string; lines: string[] }> | undefined;
|
|
203
|
+
baseDir?: string | undefined;
|
|
204
|
+
} = {}
|
|
205
|
+
): void => {
|
|
206
|
+
const norm = normalizeWorkspaceRelCandidate(workspaceRoot, raw, opts.baseDir);
|
|
207
|
+
if (!norm) return;
|
|
208
|
+
const dir = path.posix.dirname(norm);
|
|
209
|
+
if (dir && dir !== '.') touchedDirs.add(dir);
|
|
210
|
+
const existing = evidenceMap.get(norm);
|
|
211
|
+
if (!existing) {
|
|
212
|
+
evidenceMap.set(norm, {
|
|
213
|
+
path: norm,
|
|
214
|
+
status: opts.status ?? 'added',
|
|
215
|
+
bytesWritten: opts.bytesWritten,
|
|
216
|
+
additions: opts.additions ?? 0,
|
|
217
|
+
deletions: opts.deletions ?? 0,
|
|
218
|
+
hunks: opts.hunks ?? []
|
|
219
|
+
});
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (opts.status === 'deleted') existing.status = 'deleted';
|
|
223
|
+
else if (opts.status === 'modified' && existing.status !== 'added') existing.status = 'modified';
|
|
224
|
+
if (typeof opts.bytesWritten === 'number' && opts.bytesWritten > 0) {
|
|
225
|
+
existing.bytesWritten = opts.bytesWritten;
|
|
226
|
+
}
|
|
227
|
+
if (opts.hunks && opts.hunks.length > 0) {
|
|
228
|
+
existing.hunks = opts.hunks;
|
|
229
|
+
existing.additions = opts.additions ?? existing.additions;
|
|
230
|
+
existing.deletions = opts.deletions ?? existing.deletions;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const assistantBacktickCandidates: string[] = [];
|
|
235
|
+
|
|
236
|
+
for (const msg of messages) {
|
|
237
|
+
const rec = msg as Record<string, unknown>;
|
|
238
|
+
const toolCalls = Array.isArray(rec.tool_calls)
|
|
239
|
+
? (rec.tool_calls as Array<Record<string, unknown>>)
|
|
240
|
+
: [];
|
|
241
|
+
for (const tc of toolCalls) {
|
|
242
|
+
const fn = (tc.function && typeof tc.function === 'object' ? tc.function : tc) as Record<string, unknown>;
|
|
243
|
+
const name = typeof fn.name === 'string' ? fn.name.trim().toLowerCase() : '';
|
|
244
|
+
if (!name) continue;
|
|
245
|
+
let args: Record<string, unknown> | null = null;
|
|
246
|
+
if (typeof fn.arguments === 'string') {
|
|
247
|
+
try {
|
|
248
|
+
const parsed = JSON.parse(fn.arguments);
|
|
249
|
+
if (parsed && typeof parsed === 'object') args = parsed as Record<string, unknown>;
|
|
250
|
+
} catch {
|
|
251
|
+
args = null;
|
|
252
|
+
}
|
|
253
|
+
} else if (fn.arguments && typeof fn.arguments === 'object') {
|
|
254
|
+
args = fn.arguments as Record<string, unknown>;
|
|
255
|
+
}
|
|
256
|
+
if (!args) continue;
|
|
257
|
+
|
|
258
|
+
if (MUTATING_FILE_TOOLS.has(name)) {
|
|
259
|
+
const status: 'added' | 'modified' | 'deleted' = name === 'fs_delete'
|
|
260
|
+
? 'deleted'
|
|
261
|
+
: name.includes('edit') || name.includes('patch') || name.includes('replace')
|
|
262
|
+
? 'modified'
|
|
263
|
+
: 'added';
|
|
264
|
+
const synthWrite = typeof args.content === 'string' && args.content.length > 0
|
|
265
|
+
? buildSynthesizedWriteHunk(args.content)
|
|
266
|
+
: null;
|
|
267
|
+
const synthEdit = (typeof args.old_string === 'string' || typeof args.new_string === 'string')
|
|
268
|
+
&& (Boolean(args.old_string) || Boolean(args.new_string))
|
|
269
|
+
? buildSynthesizedEditHunk(String(args.old_string || ''), String(args.new_string || ''))
|
|
270
|
+
: null;
|
|
271
|
+
const pathKeys = [
|
|
272
|
+
'path', 'filePath', 'file_path', 'targetFile', 'target_path',
|
|
273
|
+
'filename', 'file', 'destination', 'outputFile', 'output_path', 'outputPath'
|
|
274
|
+
];
|
|
275
|
+
for (const key of pathKeys) {
|
|
276
|
+
recordFile(args[key], {
|
|
277
|
+
status,
|
|
278
|
+
additions: synthWrite?.additions ?? synthEdit?.additions ?? 0,
|
|
279
|
+
deletions: synthEdit?.deletions ?? 0,
|
|
280
|
+
hunks: synthWrite?.hunks ?? synthEdit?.hunks ?? []
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
if (typeof args.patch === 'string') {
|
|
284
|
+
for (const p of extractPatchPathsFromText(args.patch)) {
|
|
285
|
+
recordFile(p, { status: 'modified' });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (Array.isArray(args.edits)) {
|
|
289
|
+
for (const ed of args.edits) {
|
|
290
|
+
if (ed && typeof ed === 'object') {
|
|
291
|
+
recordFile((ed as Record<string, unknown>).path, { status: 'modified' });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
} else if (name === 'browser_act' && Array.isArray(args.actions)) {
|
|
296
|
+
for (const a of args.actions) {
|
|
297
|
+
if (a && typeof a === 'object') {
|
|
298
|
+
const actObj = a as Record<string, unknown>;
|
|
299
|
+
if (actObj.filePath) recordFile(actObj.filePath, { status: 'modified' });
|
|
300
|
+
if (actObj.outputPath) recordFile(actObj.outputPath, { status: 'added' });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
} else if (SHELL_TOOLS.has(name) && typeof args.command === 'string') {
|
|
304
|
+
for (const p of extractShellWriteTargets(args.command, workspaceRoot, args.cwd)) {
|
|
305
|
+
recordFile(p, { status: 'added' });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const extActions = Array.isArray(rec.external_actions)
|
|
311
|
+
? (rec.external_actions as Array<Record<string, unknown>>)
|
|
312
|
+
: [];
|
|
313
|
+
for (const act of extActions) {
|
|
314
|
+
const name = typeof act.name === 'string' ? act.name.trim().toLowerCase() : '';
|
|
315
|
+
if (!name) continue;
|
|
316
|
+
if (MUTATING_FILE_TOOLS.has(name)) {
|
|
317
|
+
recordFile(act.detail, { status: name.includes('edit') ? 'modified' : 'added' });
|
|
318
|
+
const params = act.parameters && typeof act.parameters === 'object'
|
|
319
|
+
? (act.parameters as Record<string, unknown>)
|
|
320
|
+
: null;
|
|
321
|
+
if (params) {
|
|
322
|
+
for (const key of ['path', 'filePath', 'file_path', 'targetFile', 'filename', 'file', 'destination', 'outputPath']) {
|
|
323
|
+
recordFile(params[key], { status: name.includes('edit') ? 'modified' : 'added' });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} else if (SHELL_TOOLS.has(name) && typeof act.detail === 'string') {
|
|
327
|
+
for (const p of extractShellWriteTargets(act.detail, workspaceRoot)) {
|
|
328
|
+
recordFile(p, { status: 'added' });
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const rawText = typeof msg.content === 'string' ? msg.content : '';
|
|
334
|
+
if (msg.role === 'tool' && rawText) {
|
|
335
|
+
let toolText = rawText;
|
|
336
|
+
try {
|
|
337
|
+
const parsed = JSON.parse(rawText) as Record<string, unknown>;
|
|
338
|
+
if (parsed && typeof parsed === 'object' && typeof parsed.output === 'string') {
|
|
339
|
+
toolText = parsed.output;
|
|
340
|
+
}
|
|
341
|
+
} catch {
|
|
342
|
+
// Keep plain text tool output.
|
|
343
|
+
}
|
|
344
|
+
for (const m of toolText.matchAll(/Atomically wrote (\d+) bytes to ([^\r\n"'}]+)/g)) {
|
|
345
|
+
recordFile(m[2], { status: 'added', bytesWritten: Number(m[1]) || undefined });
|
|
346
|
+
}
|
|
347
|
+
for (const m of toolText.matchAll(/Saved (\d+)-byte screenshot to ([^\r\n"'}]+)/g)) {
|
|
348
|
+
recordFile(m[2], { status: 'added', bytesWritten: Number(m[1]) || undefined });
|
|
349
|
+
}
|
|
350
|
+
for (const m of toolText.matchAll(/(?:Successfully edited|Successfully wrote|Created file|Patched)\s+([^\r\n"'}]+)/g)) {
|
|
351
|
+
recordFile(m[1], { status: 'modified' });
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (msg.role === 'assistant' && rawText) {
|
|
356
|
+
for (const m of rawText.matchAll(/file:\/\/[^\s)\]"'<>]+/g)) {
|
|
357
|
+
recordFile(m[0], { status: 'added' });
|
|
358
|
+
}
|
|
359
|
+
for (const m of rawText.matchAll(/`([^`\r\n]{3,240})`/g)) {
|
|
360
|
+
const candidate = m[1]!;
|
|
361
|
+
if (candidate.includes('/') && hasFileExtension(candidate) && !candidate.includes(' ')) {
|
|
362
|
+
assistantBacktickCandidates.push(candidate);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
for (const cand of assistantBacktickCandidates) {
|
|
369
|
+
const norm = normalizeWorkspaceRelCandidate(workspaceRoot, cand);
|
|
370
|
+
if (!norm || evidenceMap.has(norm)) continue;
|
|
371
|
+
const dir = path.posix.dirname(norm);
|
|
372
|
+
const abs = resolveWorkspaceRelativePath(workspaceRoot, norm);
|
|
373
|
+
const inTouchedDir = Boolean(dir && dir !== '.' && touchedDirs.has(dir));
|
|
374
|
+
const existsUntrackedDotAsset = Boolean(abs && norm.startsWith('.') && fs.existsSync(abs));
|
|
375
|
+
if (inTouchedDir || existsUntrackedDotAsset) {
|
|
376
|
+
recordFile(norm, { status: 'added' });
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const allPaths = [...evidenceMap.keys()];
|
|
381
|
+
for (const p of allPaths) {
|
|
382
|
+
if (!hasFileExtension(p)) {
|
|
383
|
+
const prefix = `${p}/`;
|
|
384
|
+
if (allPaths.some((other) => other.startsWith(prefix))) {
|
|
385
|
+
evidenceMap.delete(p);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return evidenceMap;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export function extractSessionTouchedFiles(
|
|
394
|
+
messages: readonly SessionMessage[],
|
|
395
|
+
workspaceRoot: string
|
|
396
|
+
): string[] {
|
|
397
|
+
return [...extractSessionFileEvidence(messages, workspaceRoot).keys()].sort();
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function summarizeArgsTarget(args: Record<string, unknown> | null): string {
|
|
401
|
+
if (!args) return '';
|
|
402
|
+
for (const key of ['path', 'filePath', 'file_path', 'file', 'command', 'query', 'url', 'skill_id']) {
|
|
403
|
+
if (typeof args[key] === 'string' && String(args[key]).trim()) {
|
|
404
|
+
return String(args[key]).trim().slice(0, 100);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return '';
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function extractSessionDisplayMessages(
|
|
411
|
+
messages: readonly SessionMessage[]
|
|
412
|
+
): SessionDisplayMessage[] {
|
|
413
|
+
const toolOutputsById = new Map<string, { output: string; failed: boolean }>();
|
|
414
|
+
for (const msg of messages) {
|
|
415
|
+
if (msg.role !== 'tool') continue;
|
|
416
|
+
const rec = msg as Record<string, unknown>;
|
|
417
|
+
const id = typeof rec.tool_call_id === 'string' ? rec.tool_call_id : '';
|
|
418
|
+
if (!id) continue;
|
|
419
|
+
const raw = typeof msg.content === 'string' ? msg.content : '';
|
|
420
|
+
let failed = false;
|
|
421
|
+
let summary = raw.trim().slice(0, 360);
|
|
422
|
+
try {
|
|
423
|
+
const parsed = JSON.parse(raw) as Record<string, unknown>;
|
|
424
|
+
if (parsed && typeof parsed === 'object') {
|
|
425
|
+
if (parsed.success === false || typeof parsed.error === 'string') failed = true;
|
|
426
|
+
if (typeof parsed.error === 'string') summary = parsed.error.slice(0, 360);
|
|
427
|
+
else if (typeof parsed.output === 'string') summary = parsed.output.slice(0, 360);
|
|
428
|
+
}
|
|
429
|
+
} catch {
|
|
430
|
+
// plain text tool output
|
|
431
|
+
}
|
|
432
|
+
toolOutputsById.set(id, { output: summary, failed });
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const out: SessionDisplayMessage[] = [];
|
|
436
|
+
for (const msg of messages) {
|
|
437
|
+
if (msg.role !== 'user' && msg.role !== 'assistant') continue;
|
|
438
|
+
const rec = msg as Record<string, unknown>;
|
|
439
|
+
let text = '';
|
|
440
|
+
if (typeof msg.content === 'string') {
|
|
441
|
+
text = msg.content;
|
|
442
|
+
} else if (Array.isArray(msg.content)) {
|
|
443
|
+
const parts: string[] = [];
|
|
444
|
+
for (const block of msg.content) {
|
|
445
|
+
if (block && typeof block === 'object' && typeof (block as any).text === 'string') {
|
|
446
|
+
parts.push(String((block as any).text));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
text = parts.join('\n');
|
|
450
|
+
}
|
|
451
|
+
const trimmed = text.trim();
|
|
452
|
+
if (msg.role === 'user') {
|
|
453
|
+
if (!trimmed) continue;
|
|
454
|
+
out.push({ role: 'user', content: trimmed });
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const steps: SessionDisplayStep[] = [];
|
|
459
|
+
const extActions = Array.isArray(rec.external_actions)
|
|
460
|
+
? (rec.external_actions as Array<Record<string, unknown>>)
|
|
461
|
+
: [];
|
|
462
|
+
for (const act of extActions) {
|
|
463
|
+
const rawName = typeof act.name === 'string' ? act.name.trim() : '';
|
|
464
|
+
const rawDetail = typeof act.detail === 'string' ? act.detail.trim() : '';
|
|
465
|
+
if (!rawName || rawName === 'true' || rawName === ':' || rawDetail === 'true' || rawDetail === ':') continue;
|
|
466
|
+
steps.push({
|
|
467
|
+
tool: rawName.replace(/^causyne[-_]browser[_:]/i, ''),
|
|
468
|
+
target: rawDetail.slice(0, 100),
|
|
469
|
+
status: act.status === 'failed' ? 'failed' : 'done'
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
const toolCalls = Array.isArray(rec.tool_calls)
|
|
473
|
+
? (rec.tool_calls as Array<Record<string, unknown>>)
|
|
474
|
+
: [];
|
|
475
|
+
for (const tc of toolCalls) {
|
|
476
|
+
const fn = (tc.function && typeof tc.function === 'object' ? tc.function : tc) as Record<string, unknown>;
|
|
477
|
+
const name = typeof fn.name === 'string' ? fn.name.trim() : '';
|
|
478
|
+
if (!name || name === 'true' || name === ':') continue;
|
|
479
|
+
let args: Record<string, unknown> | null = null;
|
|
480
|
+
if (typeof fn.arguments === 'string') {
|
|
481
|
+
try {
|
|
482
|
+
const parsed = JSON.parse(fn.arguments);
|
|
483
|
+
if (parsed && typeof parsed === 'object') args = parsed as Record<string, unknown>;
|
|
484
|
+
} catch {
|
|
485
|
+
args = null;
|
|
486
|
+
}
|
|
487
|
+
} else if (fn.arguments && typeof fn.arguments === 'object') {
|
|
488
|
+
args = fn.arguments as Record<string, unknown>;
|
|
489
|
+
}
|
|
490
|
+
const tcId = typeof tc.id === 'string' ? tc.id : '';
|
|
491
|
+
const matchedOut = tcId ? toolOutputsById.get(tcId) : undefined;
|
|
492
|
+
steps.push({
|
|
493
|
+
tool: name,
|
|
494
|
+
target: summarizeArgsTarget(args),
|
|
495
|
+
status: matchedOut?.failed ? 'failed' : 'done',
|
|
496
|
+
...(matchedOut?.output ? { output: matchedOut.output } : {})
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
const rawReasoning = typeof rec.reasoning_content === 'string' ? rec.reasoning_content.trim() : '';
|
|
500
|
+
const reasoning = rawReasoning ? rawReasoning.slice(0, 8000) : undefined;
|
|
501
|
+
|
|
502
|
+
if (!trimmed && steps.length === 0 && !reasoning) continue;
|
|
503
|
+
const msgBlocks: SessionDisplayBlock[] = [];
|
|
504
|
+
if (reasoning) msgBlocks.push({ kind: 'reasoning', content: reasoning });
|
|
505
|
+
if (steps.length > 0) msgBlocks.push({ kind: 'steps', steps });
|
|
506
|
+
if (trimmed) msgBlocks.push({ kind: 'text', content: trimmed });
|
|
507
|
+
|
|
508
|
+
// Merge consecutive assistant messages between user turns while preserving chronological blocks.
|
|
509
|
+
const prev = out.length > 0 ? out[out.length - 1] : null;
|
|
510
|
+
if (prev && prev.role === 'assistant') {
|
|
511
|
+
const prevBlocks = prev.blocks ? [...prev.blocks] : [];
|
|
512
|
+
for (const blk of msgBlocks) {
|
|
513
|
+
const lastBlk = prevBlocks.length > 0 ? prevBlocks[prevBlocks.length - 1] : null;
|
|
514
|
+
if (blk.kind === 'steps' && lastBlk && lastBlk.kind === 'steps') {
|
|
515
|
+
lastBlk.steps = [...lastBlk.steps, ...blk.steps];
|
|
516
|
+
} else if (blk.kind === 'reasoning' && lastBlk && lastBlk.kind === 'reasoning') {
|
|
517
|
+
lastBlk.content = `${lastBlk.content}\n\n${blk.content}`.slice(0, 8000);
|
|
518
|
+
} else {
|
|
519
|
+
prevBlocks.push(blk);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
prev.blocks = prevBlocks;
|
|
523
|
+
if (steps.length > 0) prev.steps = [...(prev.steps || []), ...steps];
|
|
524
|
+
if (reasoning) prev.reasoning = prev.reasoning ? `${prev.reasoning}\n\n${reasoning}`.slice(0, 8000) : reasoning;
|
|
525
|
+
if (trimmed) prev.content = prev.content ? `${prev.content}\n\n${trimmed}` : trimmed;
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
out.push({
|
|
529
|
+
role: 'assistant',
|
|
530
|
+
content: trimmed,
|
|
531
|
+
...(reasoning ? { reasoning } : {}),
|
|
532
|
+
...(steps.length > 0 ? { steps } : {}),
|
|
533
|
+
blocks: msgBlocks
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
return out;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export function parseSessionIdRoute(pathname: string): string | null {
|
|
540
|
+
const prefix = '/api/sessions/';
|
|
541
|
+
if (!pathname.startsWith(prefix)) return null;
|
|
542
|
+
const raw = pathname.slice(prefix.length);
|
|
543
|
+
if (!raw || raw.includes('/')) return null;
|
|
544
|
+
let decoded = '';
|
|
545
|
+
try {
|
|
546
|
+
decoded = decodeURIComponent(raw);
|
|
547
|
+
} catch {
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
return SAFE_SESSION_ID_RE.test(decoded) ? decoded : null;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export function parseSessionStreamRoute(pathname: string): string | null {
|
|
554
|
+
const prefix = '/api/sessions/';
|
|
555
|
+
const suffix = '/stream';
|
|
556
|
+
if (!pathname.startsWith(prefix) || !pathname.endsWith(suffix)) return null;
|
|
557
|
+
const raw = pathname.slice(prefix.length, pathname.length - suffix.length);
|
|
558
|
+
if (!raw || raw.includes('/')) return null;
|
|
559
|
+
let decoded = '';
|
|
560
|
+
try {
|
|
561
|
+
decoded = decodeURIComponent(raw);
|
|
562
|
+
} catch {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
return SAFE_SESSION_ID_RE.test(decoded) ? decoded : null;
|
|
566
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
export const SKYBRIDGE_STYLESHEET_URLS = [
|
|
5
|
+
'/assets/vendor/xterm.css',
|
|
6
|
+
'/assets/styles/tokens.css',
|
|
7
|
+
'/assets/styles/shell.css',
|
|
8
|
+
'/assets/styles/thread.css',
|
|
9
|
+
'/assets/styles/agent.css',
|
|
10
|
+
'/assets/styles/composer.css',
|
|
11
|
+
'/assets/styles/studio.css',
|
|
12
|
+
'/assets/styles/overlays.css'
|
|
13
|
+
];
|
|
14
|
+
export const SKYBRIDGE_VENDOR_SCRIPT_URLS = [
|
|
15
|
+
'/assets/vendor/xterm.js',
|
|
16
|
+
'/assets/vendor/addon-fit.js'
|
|
17
|
+
];
|
|
18
|
+
export const SKYBRIDGE_CLIENT_MODULE_FILES = [
|
|
19
|
+
'types.js',
|
|
20
|
+
'dom.js',
|
|
21
|
+
'state.js',
|
|
22
|
+
'validators.js',
|
|
23
|
+
'markdown.js',
|
|
24
|
+
'streamSmoother.js',
|
|
25
|
+
'turnView.js',
|
|
26
|
+
'studioLayout.js',
|
|
27
|
+
'studioShell.js',
|
|
28
|
+
'studioStart.js',
|
|
29
|
+
'filesAndCanvas.js',
|
|
30
|
+
'diffPanel.js',
|
|
31
|
+
'browserPanel.js',
|
|
32
|
+
'terminalTheme.js',
|
|
33
|
+
'terminalPanel.js',
|
|
34
|
+
'cliPanel.js',
|
|
35
|
+
'gameLauncherUi.js',
|
|
36
|
+
'modelPicker.js',
|
|
37
|
+
'permissionPresetsUi.js',
|
|
38
|
+
'settingsModal.js',
|
|
39
|
+
'sessions.js',
|
|
40
|
+
'chatStream.js',
|
|
41
|
+
'composer.js',
|
|
42
|
+
'main.js'
|
|
43
|
+
];
|
|
44
|
+
const STATIC_ASSET_MAP = (() => {
|
|
45
|
+
const map = new Map();
|
|
46
|
+
const req = createRequire(import.meta.url);
|
|
47
|
+
const vendorEntries = [
|
|
48
|
+
['/assets/vendor/xterm.css', '@xterm/xterm/css/xterm.css', 'text/css; charset=utf-8'],
|
|
49
|
+
['/assets/vendor/xterm.js', '@xterm/xterm/lib/xterm.js', 'text/javascript; charset=utf-8'],
|
|
50
|
+
['/assets/vendor/addon-fit.js', '@xterm/addon-fit/lib/addon-fit.js', 'text/javascript; charset=utf-8']
|
|
51
|
+
];
|
|
52
|
+
for (const [route, pkgSpecifier, contentType] of vendorEntries) {
|
|
53
|
+
try {
|
|
54
|
+
map.set(route, {
|
|
55
|
+
filePath: req.resolve(pkgSpecifier),
|
|
56
|
+
contentType
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Vendor asset unavailable in minimal test install; handled cleanly with 404.
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const styleFiles = [
|
|
64
|
+
'tokens.css',
|
|
65
|
+
'shell.css',
|
|
66
|
+
'thread.css',
|
|
67
|
+
'agent.css',
|
|
68
|
+
'composer.css',
|
|
69
|
+
'studio.css',
|
|
70
|
+
'overlays.css'
|
|
71
|
+
];
|
|
72
|
+
for (const name of styleFiles) {
|
|
73
|
+
map.set(`/assets/styles/${name}`, {
|
|
74
|
+
filePath: fileURLToPath(new URL(`../styles/${name}`, import.meta.url)),
|
|
75
|
+
contentType: 'text/css; charset=utf-8'
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
for (const name of SKYBRIDGE_CLIENT_MODULE_FILES) {
|
|
79
|
+
map.set(`/assets/client/${name}`, {
|
|
80
|
+
filePath: fileURLToPath(new URL(`../client/${name}`, import.meta.url)),
|
|
81
|
+
contentType: 'text/javascript; charset=utf-8'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return map;
|
|
85
|
+
})();
|
|
86
|
+
export function serveStaticAsset(pathname, res) {
|
|
87
|
+
const entry = STATIC_ASSET_MAP.get(pathname);
|
|
88
|
+
if (!entry)
|
|
89
|
+
return false;
|
|
90
|
+
try {
|
|
91
|
+
const content = fs.readFileSync(entry.filePath);
|
|
92
|
+
res.statusCode = 200;
|
|
93
|
+
res.setHeader('Content-Type', entry.contentType);
|
|
94
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
95
|
+
res.end(content);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
res.statusCode = 404;
|
|
100
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
101
|
+
res.end(JSON.stringify({ error: 'Static asset unavailable.' }));
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|