@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.
- package/docs/THIRD_PARTY_NOTICES.md +36 -2
- package/package.json +3 -1
- package/src/agentLoop.js +59 -26
- package/src/agentLoop.ts +59 -24
- package/src/browser/causyneBrowser.js +31 -0
- package/src/browser/causyneBrowser.ts +32 -0
- package/src/commands.js +177 -13
- package/src/commands.ts +194 -13
- 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/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 +2 -0
- package/src/providers/antigravity.ts +2 -0
- package/src/tools/memoryWrite.js +15 -1
- package/src/tools/memoryWrite.ts +16 -1
- package/src/tools/osSandbox.js +1 -1
- package/src/tools/osSandbox.ts +1 -1
- package/src/tools/ptyTerminal.js +17 -5
- package/src/tools/ptyTerminal.ts +19 -5
- package/src/web/client/browserPanel.js +234 -31
- package/src/web/client/browserPanel.ts +240 -31
- package/src/web/client/chatStream.js +19 -7
- package/src/web/client/chatStream.ts +17 -9
- package/src/web/client/cliPanel.js +3 -3
- package/src/web/client/cliPanel.ts +3 -3
- package/src/web/client/dom.js +53 -2
- package/src/web/client/dom.ts +54 -3
- package/src/web/client/filesAndCanvas.js +3 -1
- package/src/web/client/filesAndCanvas.ts +3 -1
- package/src/web/client/main.js +28 -13
- package/src/web/client/main.ts +35 -12
- package/src/web/client/settingsModal.js +641 -8
- package/src/web/client/settingsModal.ts +791 -8
- package/src/web/client/state.js +31 -1
- package/src/web/client/state.ts +27 -1
- package/src/web/client/studioLayout.js +39 -4
- package/src/web/client/studioLayout.ts +47 -4
- package/src/web/client/studioShell.js +370 -37
- package/src/web/client/studioShell.ts +368 -36
- package/src/web/client/terminalPanel.js +378 -129
- package/src/web/client/terminalPanel.ts +394 -107
- package/src/web/client/terminalTheme.js +249 -0
- package/src/web/client/terminalTheme.ts +258 -0
- package/src/web/client/types.ts +3 -0
- package/src/web/client/validators.js +51 -10
- package/src/web/client/validators.ts +54 -10
- package/src/web/server/routesBrowser.js +64 -10
- package/src/web/server/routesBrowser.ts +62 -13
- package/src/web/server/routesSettings.js +344 -0
- package/src/web/server/routesSettings.ts +397 -0
- package/src/web/server/staticAssets.js +24 -0
- package/src/web/server/staticAssets.ts +25 -0
- package/src/web/skybridgeServer.js +3 -0
- package/src/web/skybridgeServer.ts +2 -0
- package/src/web/skybridgeUi.js +5 -1
- package/src/web/skybridgeUi.ts +8 -1
- package/src/web/styles/overlays.css +499 -0
- package/src/web/styles/studio.css +274 -46
- package/src/web/ui/modalsTemplate.js +320 -71
- package/src/web/ui/modalsTemplate.ts +320 -71
- package/src/web/ui/studioTemplate.js +19 -21
- package/src/web/ui/studioTemplate.ts +19 -21
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
const ANSI_KEYS = [
|
|
2
|
+
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white',
|
|
3
|
+
'brightBlack', 'brightRed', 'brightGreen', 'brightYellow', 'brightBlue', 'brightMagenta', 'brightCyan', 'brightWhite'
|
|
4
|
+
];
|
|
5
|
+
const SPECIAL_KEYS = ['foreground', 'background', 'cursor'];
|
|
6
|
+
const DARK_ANSI_PALETTE = {
|
|
7
|
+
black: '#1c201c',
|
|
8
|
+
red: '#f87171',
|
|
9
|
+
green: '#4ade80',
|
|
10
|
+
yellow: '#facc15',
|
|
11
|
+
blue: '#60a5fa',
|
|
12
|
+
magenta: '#c084fc',
|
|
13
|
+
cyan: '#22d3ee',
|
|
14
|
+
white: '#e6ece4',
|
|
15
|
+
brightBlack: '#6b736a',
|
|
16
|
+
brightRed: '#fca5a5',
|
|
17
|
+
brightGreen: '#86efac',
|
|
18
|
+
brightYellow: '#fde047',
|
|
19
|
+
brightBlue: '#93c5fd',
|
|
20
|
+
brightMagenta: '#d8b4fe',
|
|
21
|
+
brightCyan: '#67e8f9',
|
|
22
|
+
brightWhite: '#ffffff'
|
|
23
|
+
};
|
|
24
|
+
const LIGHT_ANSI_PALETTE = {
|
|
25
|
+
black: '#1f2328',
|
|
26
|
+
red: '#cf222e',
|
|
27
|
+
green: '#116329',
|
|
28
|
+
yellow: '#9a6700',
|
|
29
|
+
blue: '#0969da',
|
|
30
|
+
magenta: '#8250df',
|
|
31
|
+
cyan: '#1b7c83',
|
|
32
|
+
white: '#6e7781',
|
|
33
|
+
brightBlack: '#57606a',
|
|
34
|
+
brightRed: '#a40e26',
|
|
35
|
+
brightGreen: '#1a7f37',
|
|
36
|
+
brightYellow: '#bf8700',
|
|
37
|
+
brightBlue: '#218bff',
|
|
38
|
+
brightMagenta: '#a475f9',
|
|
39
|
+
brightCyan: '#3192aa',
|
|
40
|
+
brightWhite: '#8c959f'
|
|
41
|
+
};
|
|
42
|
+
function colorIndex(value) {
|
|
43
|
+
if (!/^\d{1,3}$/.test(value))
|
|
44
|
+
return undefined;
|
|
45
|
+
const parsed = Number(value);
|
|
46
|
+
return parsed >= 0 && parsed < 256 ? parsed : undefined;
|
|
47
|
+
}
|
|
48
|
+
function oscColor(value) {
|
|
49
|
+
const rgb = /^rgb:([\da-f]{1,4})\/([\da-f]{1,4})\/([\da-f]{1,4})$/i.exec(value);
|
|
50
|
+
let channels;
|
|
51
|
+
if (rgb !== null) {
|
|
52
|
+
const r = rgb[1];
|
|
53
|
+
const g = rgb[2];
|
|
54
|
+
const b = rgb[3];
|
|
55
|
+
if (!r || !g || !b)
|
|
56
|
+
return undefined;
|
|
57
|
+
channels = [r, g, b];
|
|
58
|
+
if (!channels.every((c) => c.length === r.length))
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (!/^#(?:[\da-f]{3}|[\da-f]{6}|[\da-f]{9}|[\da-f]{12})$/i.test(value))
|
|
63
|
+
return undefined;
|
|
64
|
+
const width = (value.length - 1) / 3;
|
|
65
|
+
channels = [
|
|
66
|
+
value.slice(1, width + 1),
|
|
67
|
+
value.slice(width + 1, 2 * width + 1),
|
|
68
|
+
value.slice(2 * width + 1)
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
const hex = channels.map((channel) => {
|
|
72
|
+
const n = rgb === null
|
|
73
|
+
? Number.parseInt(channel.padEnd(2, '0').slice(0, 2), 16)
|
|
74
|
+
: Math.round((Number.parseInt(channel, 16) * 255) / (16 ** channel.length - 1));
|
|
75
|
+
return n.toString(16).padStart(2, '0');
|
|
76
|
+
}).join('');
|
|
77
|
+
return `#${hex}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Tracks application OSC color overrides (OSC 4/10/11/12/104/110-112) separately from
|
|
81
|
+
* Causyne Studio theme defaults so light/dark theme switches preserve program palettes.
|
|
82
|
+
*/
|
|
83
|
+
export class TerminalTheme {
|
|
84
|
+
terminal;
|
|
85
|
+
defaults = {};
|
|
86
|
+
indexed = new Map();
|
|
87
|
+
special = new Map();
|
|
88
|
+
subscriptions;
|
|
89
|
+
constructor(terminal) {
|
|
90
|
+
this.terminal = terminal;
|
|
91
|
+
const observe = (code, change) => terminal.parser.registerOscHandler(code, (data) => {
|
|
92
|
+
change(data);
|
|
93
|
+
return false;
|
|
94
|
+
});
|
|
95
|
+
this.subscriptions = [
|
|
96
|
+
observe(4, (data) => {
|
|
97
|
+
const parts = data.split(';');
|
|
98
|
+
for (let i = 0; i + 1 < parts.length; i += 2) {
|
|
99
|
+
const idxRaw = parts[i];
|
|
100
|
+
const colRaw = parts[i + 1];
|
|
101
|
+
if (idxRaw === undefined || colRaw === undefined)
|
|
102
|
+
continue;
|
|
103
|
+
const index = colorIndex(idxRaw);
|
|
104
|
+
const color = oscColor(colRaw);
|
|
105
|
+
if (index !== undefined && color !== undefined)
|
|
106
|
+
this.indexed.set(index, color);
|
|
107
|
+
}
|
|
108
|
+
}),
|
|
109
|
+
observe(104, (data) => {
|
|
110
|
+
if (data === '') {
|
|
111
|
+
this.indexed.clear();
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
for (const part of data.split(';')) {
|
|
115
|
+
const index = colorIndex(part);
|
|
116
|
+
if (index !== undefined)
|
|
117
|
+
this.indexed.delete(index);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.apply();
|
|
121
|
+
}),
|
|
122
|
+
...SPECIAL_KEYS.flatMap((key, offset) => [
|
|
123
|
+
observe(10 + offset, (data) => {
|
|
124
|
+
const parts = data.split(';');
|
|
125
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
126
|
+
const target = SPECIAL_KEYS[offset + i];
|
|
127
|
+
const part = parts[i];
|
|
128
|
+
if (target === undefined || part === undefined)
|
|
129
|
+
continue;
|
|
130
|
+
const color = oscColor(part);
|
|
131
|
+
if (color !== undefined)
|
|
132
|
+
this.special.set(target, color);
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
observe(110 + offset, () => {
|
|
136
|
+
this.special.delete(key);
|
|
137
|
+
this.apply();
|
|
138
|
+
})
|
|
139
|
+
])
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
update(background, foreground, isLight) {
|
|
143
|
+
const basePalette = isLight ? LIGHT_ANSI_PALETTE : DARK_ANSI_PALETTE;
|
|
144
|
+
if (this.defaults.background === background
|
|
145
|
+
&& this.defaults.foreground === foreground
|
|
146
|
+
&& this.defaults.blue === basePalette.blue) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.defaults = {
|
|
150
|
+
...basePalette,
|
|
151
|
+
background,
|
|
152
|
+
foreground,
|
|
153
|
+
cursor: foreground,
|
|
154
|
+
cursorAccent: background,
|
|
155
|
+
selectionBackground: isLight ? 'rgba(9, 105, 218, 0.24)' : 'rgba(147, 197, 253, 0.28)',
|
|
156
|
+
selectionInactiveBackground: isLight ? 'rgba(9, 105, 218, 0.14)' : 'rgba(147, 197, 253, 0.16)'
|
|
157
|
+
};
|
|
158
|
+
this.apply();
|
|
159
|
+
}
|
|
160
|
+
get cursor() {
|
|
161
|
+
return this.special.get('cursor') ?? this.defaults.cursor ?? '#e6ece4';
|
|
162
|
+
}
|
|
163
|
+
dispose() {
|
|
164
|
+
for (const sub of this.subscriptions)
|
|
165
|
+
sub.dispose();
|
|
166
|
+
}
|
|
167
|
+
apply() {
|
|
168
|
+
const theme = { ...this.defaults };
|
|
169
|
+
for (const [k, v] of this.special) {
|
|
170
|
+
theme[k] = v;
|
|
171
|
+
}
|
|
172
|
+
for (const [index, color] of this.indexed) {
|
|
173
|
+
const key = ANSI_KEYS[index];
|
|
174
|
+
if (key !== undefined) {
|
|
175
|
+
theme[key] = color;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const ext = theme.extendedAnsi ?? [];
|
|
179
|
+
ext[index - ANSI_KEYS.length] = color;
|
|
180
|
+
theme.extendedAnsi = ext;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
this.terminal.options.theme = theme;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function colorChannels(color) {
|
|
187
|
+
if (color.startsWith('#') && color.length >= 7) {
|
|
188
|
+
return [
|
|
189
|
+
Number.parseInt(color.slice(1, 3), 16),
|
|
190
|
+
Number.parseInt(color.slice(3, 5), 16),
|
|
191
|
+
Number.parseInt(color.slice(5, 7), 16)
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
const matches = color.match(/\d+(?:\.\d+)?/g);
|
|
195
|
+
return matches ? matches.map(Number) : [0, 0, 0];
|
|
196
|
+
}
|
|
197
|
+
function luminance(color) {
|
|
198
|
+
const channels = colorChannels(color);
|
|
199
|
+
const r = (channels[0] ?? 0) / 255;
|
|
200
|
+
const g = (channels[1] ?? 0) / 255;
|
|
201
|
+
const b = (channels[2] ?? 0) / 255;
|
|
202
|
+
const lin = (v) => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
|
|
203
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
204
|
+
}
|
|
205
|
+
function opaqueColor(color, background) {
|
|
206
|
+
const channels = colorChannels(color);
|
|
207
|
+
const alpha = channels[3] ?? 1;
|
|
208
|
+
if (alpha >= 1)
|
|
209
|
+
return color;
|
|
210
|
+
const surface = colorChannels(background());
|
|
211
|
+
const rgb = [0, 1, 2].map((i) => Math.round((channels[i] ?? 0) * alpha + (surface[i] ?? 0) * (1 - alpha)));
|
|
212
|
+
return `rgb(${rgb.join(', ')})`;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Keeps the xterm DOM cursor legible against default, ANSI, true-color, and inverse cells.
|
|
216
|
+
*/
|
|
217
|
+
export function observeTerminalCursor(terminal, node, preferredCursor) {
|
|
218
|
+
return terminal.onRender(() => {
|
|
219
|
+
const cursor = node.querySelector('.xterm-cursor');
|
|
220
|
+
if (!cursor)
|
|
221
|
+
return;
|
|
222
|
+
cursor.classList.remove('xterm-cursor');
|
|
223
|
+
let background = '#0d100d';
|
|
224
|
+
let foreground = '#e6ece4';
|
|
225
|
+
try {
|
|
226
|
+
const style = window.getComputedStyle(cursor);
|
|
227
|
+
foreground = style.color || foreground;
|
|
228
|
+
const fallbackSurface = () => {
|
|
229
|
+
const scrollEl = node.querySelector('.xterm-scrollable-element');
|
|
230
|
+
return scrollEl
|
|
231
|
+
? window.getComputedStyle(scrollEl).backgroundColor
|
|
232
|
+
: window.getComputedStyle(node).backgroundColor;
|
|
233
|
+
};
|
|
234
|
+
background = opaqueColor(style.backgroundColor, fallbackSurface);
|
|
235
|
+
}
|
|
236
|
+
finally {
|
|
237
|
+
cursor.classList.add('xterm-cursor');
|
|
238
|
+
}
|
|
239
|
+
const preferred = opaqueColor(preferredCursor(), () => background);
|
|
240
|
+
const bgLum = luminance(background);
|
|
241
|
+
const prefLum = luminance(preferred);
|
|
242
|
+
const contrast = (Math.max(bgLum, prefLum) + 0.05) / (Math.min(bgLum, prefLum) + 0.05);
|
|
243
|
+
const fill = contrast >= 3 ? preferred : (bgLum > 0.179 ? '#000000' : '#ffffff');
|
|
244
|
+
node.style.setProperty('--terminal-cursor', fill);
|
|
245
|
+
node.style.setProperty('--terminal-cursor-accent', luminance(fill) > 0.179 ? '#000000' : '#ffffff');
|
|
246
|
+
node.style.setProperty('--terminal-cursor-cell-background', background);
|
|
247
|
+
node.style.setProperty('--terminal-cursor-cell-foreground', foreground);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { IDisposable, ITheme, Terminal } from '@xterm/xterm';
|
|
2
|
+
|
|
3
|
+
const ANSI_KEYS = [
|
|
4
|
+
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white',
|
|
5
|
+
'brightBlack', 'brightRed', 'brightGreen', 'brightYellow', 'brightBlue', 'brightMagenta', 'brightCyan', 'brightWhite'
|
|
6
|
+
] as const;
|
|
7
|
+
|
|
8
|
+
const SPECIAL_KEYS = ['foreground', 'background', 'cursor'] as const;
|
|
9
|
+
type SpecialKey = (typeof SPECIAL_KEYS)[number];
|
|
10
|
+
|
|
11
|
+
const DARK_ANSI_PALETTE: ITheme = {
|
|
12
|
+
black: '#1c201c',
|
|
13
|
+
red: '#f87171',
|
|
14
|
+
green: '#4ade80',
|
|
15
|
+
yellow: '#facc15',
|
|
16
|
+
blue: '#60a5fa',
|
|
17
|
+
magenta: '#c084fc',
|
|
18
|
+
cyan: '#22d3ee',
|
|
19
|
+
white: '#e6ece4',
|
|
20
|
+
brightBlack: '#6b736a',
|
|
21
|
+
brightRed: '#fca5a5',
|
|
22
|
+
brightGreen: '#86efac',
|
|
23
|
+
brightYellow: '#fde047',
|
|
24
|
+
brightBlue: '#93c5fd',
|
|
25
|
+
brightMagenta: '#d8b4fe',
|
|
26
|
+
brightCyan: '#67e8f9',
|
|
27
|
+
brightWhite: '#ffffff'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const LIGHT_ANSI_PALETTE: ITheme = {
|
|
31
|
+
black: '#1f2328',
|
|
32
|
+
red: '#cf222e',
|
|
33
|
+
green: '#116329',
|
|
34
|
+
yellow: '#9a6700',
|
|
35
|
+
blue: '#0969da',
|
|
36
|
+
magenta: '#8250df',
|
|
37
|
+
cyan: '#1b7c83',
|
|
38
|
+
white: '#6e7781',
|
|
39
|
+
brightBlack: '#57606a',
|
|
40
|
+
brightRed: '#a40e26',
|
|
41
|
+
brightGreen: '#1a7f37',
|
|
42
|
+
brightYellow: '#bf8700',
|
|
43
|
+
brightBlue: '#218bff',
|
|
44
|
+
brightMagenta: '#a475f9',
|
|
45
|
+
brightCyan: '#3192aa',
|
|
46
|
+
brightWhite: '#8c959f'
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function colorIndex(value: string): number | undefined {
|
|
50
|
+
if (!/^\d{1,3}$/.test(value)) return undefined;
|
|
51
|
+
const parsed = Number(value);
|
|
52
|
+
return parsed >= 0 && parsed < 256 ? parsed : undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function oscColor(value: string): string | undefined {
|
|
56
|
+
const rgb = /^rgb:([\da-f]{1,4})\/([\da-f]{1,4})\/([\da-f]{1,4})$/i.exec(value);
|
|
57
|
+
let channels: string[];
|
|
58
|
+
if (rgb !== null) {
|
|
59
|
+
const r = rgb[1];
|
|
60
|
+
const g = rgb[2];
|
|
61
|
+
const b = rgb[3];
|
|
62
|
+
if (!r || !g || !b) return undefined;
|
|
63
|
+
channels = [r, g, b];
|
|
64
|
+
if (!channels.every((c) => c.length === r.length)) return undefined;
|
|
65
|
+
} else {
|
|
66
|
+
if (!/^#(?:[\da-f]{3}|[\da-f]{6}|[\da-f]{9}|[\da-f]{12})$/i.test(value)) return undefined;
|
|
67
|
+
const width = (value.length - 1) / 3;
|
|
68
|
+
channels = [
|
|
69
|
+
value.slice(1, width + 1),
|
|
70
|
+
value.slice(width + 1, 2 * width + 1),
|
|
71
|
+
value.slice(2 * width + 1)
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
const hex = channels.map((channel) => {
|
|
75
|
+
const n = rgb === null
|
|
76
|
+
? Number.parseInt(channel.padEnd(2, '0').slice(0, 2), 16)
|
|
77
|
+
: Math.round((Number.parseInt(channel, 16) * 255) / (16 ** channel.length - 1));
|
|
78
|
+
return n.toString(16).padStart(2, '0');
|
|
79
|
+
}).join('');
|
|
80
|
+
return `#${hex}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Tracks application OSC color overrides (OSC 4/10/11/12/104/110-112) separately from
|
|
85
|
+
* Causyne Studio theme defaults so light/dark theme switches preserve program palettes.
|
|
86
|
+
*/
|
|
87
|
+
export class TerminalTheme implements IDisposable {
|
|
88
|
+
private readonly terminal: Terminal;
|
|
89
|
+
private defaults: ITheme = {};
|
|
90
|
+
private readonly indexed = new Map<number, string>();
|
|
91
|
+
private readonly special = new Map<SpecialKey, string>();
|
|
92
|
+
private readonly subscriptions: IDisposable[];
|
|
93
|
+
|
|
94
|
+
constructor(terminal: Terminal) {
|
|
95
|
+
this.terminal = terminal;
|
|
96
|
+
const observe = (code: number, change: (data: string) => void): IDisposable =>
|
|
97
|
+
terminal.parser.registerOscHandler(code, (data) => {
|
|
98
|
+
change(data);
|
|
99
|
+
return false;
|
|
100
|
+
});
|
|
101
|
+
this.subscriptions = [
|
|
102
|
+
observe(4, (data) => {
|
|
103
|
+
const parts = data.split(';');
|
|
104
|
+
for (let i = 0; i + 1 < parts.length; i += 2) {
|
|
105
|
+
const idxRaw = parts[i];
|
|
106
|
+
const colRaw = parts[i + 1];
|
|
107
|
+
if (idxRaw === undefined || colRaw === undefined) continue;
|
|
108
|
+
const index = colorIndex(idxRaw);
|
|
109
|
+
const color = oscColor(colRaw);
|
|
110
|
+
if (index !== undefined && color !== undefined) this.indexed.set(index, color);
|
|
111
|
+
}
|
|
112
|
+
}),
|
|
113
|
+
observe(104, (data) => {
|
|
114
|
+
if (data === '') {
|
|
115
|
+
this.indexed.clear();
|
|
116
|
+
} else {
|
|
117
|
+
for (const part of data.split(';')) {
|
|
118
|
+
const index = colorIndex(part);
|
|
119
|
+
if (index !== undefined) this.indexed.delete(index);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
this.apply();
|
|
123
|
+
}),
|
|
124
|
+
...SPECIAL_KEYS.flatMap((key, offset) => [
|
|
125
|
+
observe(10 + offset, (data) => {
|
|
126
|
+
const parts = data.split(';');
|
|
127
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
128
|
+
const target = SPECIAL_KEYS[offset + i];
|
|
129
|
+
const part = parts[i];
|
|
130
|
+
if (target === undefined || part === undefined) continue;
|
|
131
|
+
const color = oscColor(part);
|
|
132
|
+
if (color !== undefined) this.special.set(target, color);
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
observe(110 + offset, () => {
|
|
136
|
+
this.special.delete(key);
|
|
137
|
+
this.apply();
|
|
138
|
+
})
|
|
139
|
+
])
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
update(background: string, foreground: string, isLight: boolean): void {
|
|
144
|
+
const basePalette = isLight ? LIGHT_ANSI_PALETTE : DARK_ANSI_PALETTE;
|
|
145
|
+
if (
|
|
146
|
+
this.defaults.background === background
|
|
147
|
+
&& this.defaults.foreground === foreground
|
|
148
|
+
&& this.defaults.blue === basePalette.blue
|
|
149
|
+
) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
this.defaults = {
|
|
153
|
+
...basePalette,
|
|
154
|
+
background,
|
|
155
|
+
foreground,
|
|
156
|
+
cursor: foreground,
|
|
157
|
+
cursorAccent: background,
|
|
158
|
+
selectionBackground: isLight ? 'rgba(9, 105, 218, 0.24)' : 'rgba(147, 197, 253, 0.28)',
|
|
159
|
+
selectionInactiveBackground: isLight ? 'rgba(9, 105, 218, 0.14)' : 'rgba(147, 197, 253, 0.16)'
|
|
160
|
+
};
|
|
161
|
+
this.apply();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
get cursor(): string {
|
|
165
|
+
return this.special.get('cursor') ?? this.defaults.cursor ?? '#e6ece4';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
dispose(): void {
|
|
169
|
+
for (const sub of this.subscriptions) sub.dispose();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private apply(): void {
|
|
173
|
+
const theme: ITheme = { ...this.defaults };
|
|
174
|
+
for (const [k, v] of this.special) {
|
|
175
|
+
theme[k] = v;
|
|
176
|
+
}
|
|
177
|
+
for (const [index, color] of this.indexed) {
|
|
178
|
+
const key = ANSI_KEYS[index];
|
|
179
|
+
if (key !== undefined) {
|
|
180
|
+
theme[key] = color;
|
|
181
|
+
} else {
|
|
182
|
+
const ext = theme.extendedAnsi ?? [];
|
|
183
|
+
ext[index - ANSI_KEYS.length] = color;
|
|
184
|
+
theme.extendedAnsi = ext;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this.terminal.options.theme = theme;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function colorChannels(color: string): number[] {
|
|
192
|
+
if (color.startsWith('#') && color.length >= 7) {
|
|
193
|
+
return [
|
|
194
|
+
Number.parseInt(color.slice(1, 3), 16),
|
|
195
|
+
Number.parseInt(color.slice(3, 5), 16),
|
|
196
|
+
Number.parseInt(color.slice(5, 7), 16)
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
const matches = color.match(/\d+(?:\.\d+)?/g);
|
|
200
|
+
return matches ? matches.map(Number) : [0, 0, 0];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function luminance(color: string): number {
|
|
204
|
+
const channels = colorChannels(color);
|
|
205
|
+
const r = (channels[0] ?? 0) / 255;
|
|
206
|
+
const g = (channels[1] ?? 0) / 255;
|
|
207
|
+
const b = (channels[2] ?? 0) / 255;
|
|
208
|
+
const lin = (v: number): number => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
|
|
209
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function opaqueColor(color: string, background: () => string): string {
|
|
213
|
+
const channels = colorChannels(color);
|
|
214
|
+
const alpha = channels[3] ?? 1;
|
|
215
|
+
if (alpha >= 1) return color;
|
|
216
|
+
const surface = colorChannels(background());
|
|
217
|
+
const rgb = [0, 1, 2].map((i) => Math.round((channels[i] ?? 0) * alpha + (surface[i] ?? 0) * (1 - alpha)));
|
|
218
|
+
return `rgb(${rgb.join(', ')})`;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Keeps the xterm DOM cursor legible against default, ANSI, true-color, and inverse cells.
|
|
223
|
+
*/
|
|
224
|
+
export function observeTerminalCursor(
|
|
225
|
+
terminal: Terminal,
|
|
226
|
+
node: HTMLElement,
|
|
227
|
+
preferredCursor: () => string
|
|
228
|
+
): IDisposable {
|
|
229
|
+
return terminal.onRender(() => {
|
|
230
|
+
const cursor = node.querySelector<HTMLElement>('.xterm-cursor');
|
|
231
|
+
if (!cursor) return;
|
|
232
|
+
cursor.classList.remove('xterm-cursor');
|
|
233
|
+
let background = '#0d100d';
|
|
234
|
+
let foreground = '#e6ece4';
|
|
235
|
+
try {
|
|
236
|
+
const style = window.getComputedStyle(cursor);
|
|
237
|
+
foreground = style.color || foreground;
|
|
238
|
+
const fallbackSurface = (): string => {
|
|
239
|
+
const scrollEl = node.querySelector<HTMLElement>('.xterm-scrollable-element');
|
|
240
|
+
return scrollEl
|
|
241
|
+
? window.getComputedStyle(scrollEl).backgroundColor
|
|
242
|
+
: window.getComputedStyle(node).backgroundColor;
|
|
243
|
+
};
|
|
244
|
+
background = opaqueColor(style.backgroundColor, fallbackSurface);
|
|
245
|
+
} finally {
|
|
246
|
+
cursor.classList.add('xterm-cursor');
|
|
247
|
+
}
|
|
248
|
+
const preferred = opaqueColor(preferredCursor(), () => background);
|
|
249
|
+
const bgLum = luminance(background);
|
|
250
|
+
const prefLum = luminance(preferred);
|
|
251
|
+
const contrast = (Math.max(bgLum, prefLum) + 0.05) / (Math.min(bgLum, prefLum) + 0.05);
|
|
252
|
+
const fill = contrast >= 3 ? preferred : (bgLum > 0.179 ? '#000000' : '#ffffff');
|
|
253
|
+
node.style.setProperty('--terminal-cursor', fill);
|
|
254
|
+
node.style.setProperty('--terminal-cursor-accent', luminance(fill) > 0.179 ? '#000000' : '#ffffff');
|
|
255
|
+
node.style.setProperty('--terminal-cursor-cell-background', background);
|
|
256
|
+
node.style.setProperty('--terminal-cursor-cell-foreground', foreground);
|
|
257
|
+
});
|
|
258
|
+
}
|
package/src/web/client/types.ts
CHANGED
|
@@ -272,8 +272,10 @@ export interface AppState {
|
|
|
272
272
|
currentDir: string;
|
|
273
273
|
parentDir: string;
|
|
274
274
|
studioTab: string;
|
|
275
|
+
studioOpenTabs: string[];
|
|
275
276
|
studioSplit: boolean;
|
|
276
277
|
studioSecondaryTab: string;
|
|
278
|
+
studioSplitRatio: number;
|
|
277
279
|
studioExpanded: boolean;
|
|
278
280
|
studioWidth: number;
|
|
279
281
|
terminalSessions: TerminalSessionPayload[];
|
|
@@ -291,6 +293,7 @@ export interface AppState {
|
|
|
291
293
|
browserUrl: string;
|
|
292
294
|
browserSrcdoc: string;
|
|
293
295
|
browserViewport: string;
|
|
296
|
+
browserFrameStrictSandbox: boolean;
|
|
294
297
|
liveBrowserActive: boolean;
|
|
295
298
|
liveBrowserVisible: boolean;
|
|
296
299
|
liveBrowserRuntime: string | null;
|
|
@@ -36,11 +36,23 @@ export function extractLoopbackUrls(text) {
|
|
|
36
36
|
}
|
|
37
37
|
return found.slice(0, 3);
|
|
38
38
|
}
|
|
39
|
+
function normalizePathSlashes(raw) {
|
|
40
|
+
return raw.replace(/\\/g, '/');
|
|
41
|
+
}
|
|
42
|
+
function normalizeDrivePrefix(raw) {
|
|
43
|
+
// file:///C:/foo -> C:/foo (Windows compatibility alongside POSIX /Users/...)
|
|
44
|
+
const winFile = /^\/([a-zA-Z]:\/.*)$/.exec(raw);
|
|
45
|
+
return winFile?.[1] ? winFile[1] : raw;
|
|
46
|
+
}
|
|
39
47
|
export function parseWorkspaceFileHref(rawHref, workspaceRoot) {
|
|
40
48
|
const trimmed = String(rawHref || '').trim();
|
|
41
|
-
if (!trimmed.
|
|
49
|
+
if (!trimmed || trimmed.startsWith('#'))
|
|
50
|
+
return null;
|
|
51
|
+
const isFileScheme = trimmed.toLowerCase().startsWith('file://');
|
|
52
|
+
// Reject every non-file URI scheme (javascript:, data:, vbscript:, mailto:, http:, etc.)
|
|
53
|
+
if (!isFileScheme && /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed))
|
|
42
54
|
return null;
|
|
43
|
-
let body = trimmed.slice(7);
|
|
55
|
+
let body = isFileScheme ? trimmed.slice(7) : trimmed;
|
|
44
56
|
let lineBadge = '';
|
|
45
57
|
const hashIdx = body.indexOf('#');
|
|
46
58
|
if (hashIdx >= 0) {
|
|
@@ -57,16 +69,45 @@ export function parseWorkspaceFileHref(rawHref, workspaceRoot) {
|
|
|
57
69
|
body = decodeURIComponent(body);
|
|
58
70
|
}
|
|
59
71
|
catch { /* keep raw */ }
|
|
60
|
-
|
|
72
|
+
// Reject control characters or NUL bytes
|
|
73
|
+
for (let i = 0; i < body.length; i += 1) {
|
|
74
|
+
const code = body.charCodeAt(i);
|
|
75
|
+
if (code < 0x20 || code === 0x7f)
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const wsRoot = normalizePathSlashes(String(workspaceRoot || '')).replace(/\/+$/, '');
|
|
61
79
|
const normPrivate = (p) => p.replace(/^\/private(?=\/(?:var|tmp)(?:\/|$))/, '');
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
relPath =
|
|
80
|
+
if (isFileScheme) {
|
|
81
|
+
const bodyClean = normalizeDrivePrefix(normalizePathSlashes(body));
|
|
82
|
+
const bodyNorm = normPrivate(bodyClean);
|
|
83
|
+
const wsNorm = normPrivate(wsRoot);
|
|
84
|
+
let relPath = null;
|
|
85
|
+
if (wsNorm) {
|
|
86
|
+
const isWin = /^[a-zA-Z]:\//.test(wsNorm);
|
|
87
|
+
const cmpBody = isWin ? bodyNorm.toLowerCase() : bodyNorm;
|
|
88
|
+
const cmpWs = isWin ? wsNorm.toLowerCase() : wsNorm;
|
|
89
|
+
if (cmpBody.startsWith(`${cmpWs}/`)) {
|
|
90
|
+
relPath = bodyNorm.slice(wsNorm.length + 1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const display = relPath || bodyClean.split('/').slice(-2).join('/') || bodyClean;
|
|
94
|
+
return { fullPath: bodyClean, relPath, display, lineBadge };
|
|
67
95
|
}
|
|
68
|
-
|
|
69
|
-
|
|
96
|
+
// Safe relative workspace file link (e.g. "package.json", "./src/index.ts", "docs/guide.md#L12")
|
|
97
|
+
const relClean = normalizePathSlashes(body).replace(/^\.\//, '');
|
|
98
|
+
if (!relClean || relClean.startsWith('/') || relClean.endsWith('/'))
|
|
99
|
+
return null;
|
|
100
|
+
if (/^[a-zA-Z]:/.test(relClean))
|
|
101
|
+
return null;
|
|
102
|
+
const segments = relClean.split('/');
|
|
103
|
+
if (segments.some((seg) => !seg || seg === '.' || seg === '..'))
|
|
104
|
+
return null;
|
|
105
|
+
// Require a recognizable file name (has extension or dotfile/Makefile-style relative path)
|
|
106
|
+
const leaf = segments[segments.length - 1] || '';
|
|
107
|
+
if (!leaf.includes('.') && segments.length < 2)
|
|
108
|
+
return null;
|
|
109
|
+
const fullPath = wsRoot ? `${wsRoot}/${relClean}` : relClean;
|
|
110
|
+
return { fullPath, relPath: relClean, display: relClean, lineBadge };
|
|
70
111
|
}
|
|
71
112
|
export function isHtmlOrSvgPath(relPath) {
|
|
72
113
|
const p = String(relPath || '').toLowerCase();
|
|
@@ -35,10 +35,25 @@ export function extractLoopbackUrls(text: string): string[] {
|
|
|
35
35
|
return found.slice(0, 3);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
function normalizePathSlashes(raw: string): string {
|
|
39
|
+
return raw.replace(/\\/g, '/');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeDrivePrefix(raw: string): string {
|
|
43
|
+
// file:///C:/foo -> C:/foo (Windows compatibility alongside POSIX /Users/...)
|
|
44
|
+
const winFile = /^\/([a-zA-Z]:\/.*)$/.exec(raw);
|
|
45
|
+
return winFile?.[1] ? winFile[1] : raw;
|
|
46
|
+
}
|
|
47
|
+
|
|
38
48
|
export function parseWorkspaceFileHref(rawHref: string, workspaceRoot: string): WorkspaceFileHrefInfo | null {
|
|
39
49
|
const trimmed = String(rawHref || '').trim();
|
|
40
|
-
if (!trimmed.
|
|
41
|
-
|
|
50
|
+
if (!trimmed || trimmed.startsWith('#')) return null;
|
|
51
|
+
|
|
52
|
+
const isFileScheme = trimmed.toLowerCase().startsWith('file://');
|
|
53
|
+
// Reject every non-file URI scheme (javascript:, data:, vbscript:, mailto:, http:, etc.)
|
|
54
|
+
if (!isFileScheme && /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed)) return null;
|
|
55
|
+
|
|
56
|
+
let body = isFileScheme ? trimmed.slice(7) : trimmed;
|
|
42
57
|
let lineBadge = '';
|
|
43
58
|
const hashIdx = body.indexOf('#');
|
|
44
59
|
if (hashIdx >= 0) {
|
|
@@ -50,16 +65,45 @@ export function parseWorkspaceFileHref(rawHref: string, workspaceRoot: string):
|
|
|
50
65
|
const qIdx = body.indexOf('?');
|
|
51
66
|
if (qIdx >= 0) body = body.slice(0, qIdx);
|
|
52
67
|
try { body = decodeURIComponent(body); } catch { /* keep raw */ }
|
|
53
|
-
|
|
68
|
+
|
|
69
|
+
// Reject control characters or NUL bytes
|
|
70
|
+
for (let i = 0; i < body.length; i += 1) {
|
|
71
|
+
const code = body.charCodeAt(i);
|
|
72
|
+
if (code < 0x20 || code === 0x7f) return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const wsRoot = normalizePathSlashes(String(workspaceRoot || '')).replace(/\/+$/, '');
|
|
54
76
|
const normPrivate = (p: string): string => p.replace(/^\/private(?=\/(?:var|tmp)(?:\/|$))/, '');
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
77
|
+
|
|
78
|
+
if (isFileScheme) {
|
|
79
|
+
const bodyClean = normalizeDrivePrefix(normalizePathSlashes(body));
|
|
80
|
+
const bodyNorm = normPrivate(bodyClean);
|
|
81
|
+
const wsNorm = normPrivate(wsRoot);
|
|
82
|
+
let relPath: string | null = null;
|
|
83
|
+
if (wsNorm) {
|
|
84
|
+
const isWin = /^[a-zA-Z]:\//.test(wsNorm);
|
|
85
|
+
const cmpBody = isWin ? bodyNorm.toLowerCase() : bodyNorm;
|
|
86
|
+
const cmpWs = isWin ? wsNorm.toLowerCase() : wsNorm;
|
|
87
|
+
if (cmpBody.startsWith(`${cmpWs}/`)) {
|
|
88
|
+
relPath = bodyNorm.slice(wsNorm.length + 1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const display = relPath || bodyClean.split('/').slice(-2).join('/') || bodyClean;
|
|
92
|
+
return { fullPath: bodyClean, relPath, display, lineBadge };
|
|
60
93
|
}
|
|
61
|
-
|
|
62
|
-
|
|
94
|
+
|
|
95
|
+
// Safe relative workspace file link (e.g. "package.json", "./src/index.ts", "docs/guide.md#L12")
|
|
96
|
+
const relClean = normalizePathSlashes(body).replace(/^\.\//, '');
|
|
97
|
+
if (!relClean || relClean.startsWith('/') || relClean.endsWith('/')) return null;
|
|
98
|
+
if (/^[a-zA-Z]:/.test(relClean)) return null;
|
|
99
|
+
const segments = relClean.split('/');
|
|
100
|
+
if (segments.some((seg) => !seg || seg === '.' || seg === '..')) return null;
|
|
101
|
+
// Require a recognizable file name (has extension or dotfile/Makefile-style relative path)
|
|
102
|
+
const leaf = segments[segments.length - 1] || '';
|
|
103
|
+
if (!leaf.includes('.') && segments.length < 2) return null;
|
|
104
|
+
|
|
105
|
+
const fullPath = wsRoot ? `${wsRoot}/${relClean}` : relClean;
|
|
106
|
+
return { fullPath, relPath: relClean, display: relClean, lineBadge };
|
|
63
107
|
}
|
|
64
108
|
|
|
65
109
|
export function isHtmlOrSvgPath(relPath: string): boolean {
|