@causyne/agent 1.20.30 → 1.20.32
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/package.json +1 -1
- package/src/agentLoop.js +8 -0
- package/src/agentLoop.ts +7 -0
- package/src/appChannel.js +52 -74
- package/src/appChannel.ts +106 -0
- package/src/creative/apps.js +206 -11
- package/src/creative/apps.ts +198 -6
- package/src/creative/liveBridge.js +1481 -0
- package/src/creative/liveBridge.ts +1829 -0
- package/src/creative/pipeline.js +31 -3
- package/src/creative/pipeline.ts +36 -7
- package/src/decideTools.js +3 -1
- package/src/decideTools.ts +3 -1
- package/src/decisionPolicy.js +5 -2
- package/src/decisionPolicy.ts +7 -1
- package/src/mcp/mcpRegistry.js +3 -1
- package/src/mcp/mcpRegistry.ts +3 -1
- package/src/sandbox.js +5 -1
- package/src/smartToolsUse.js +2 -1
- package/src/smartToolsUse.ts +2 -1
- package/src/tool-scripts/resolve_automator.py +167 -34
- package/src/toolPacks.js +5 -3
- package/src/toolPacks.ts +5 -3
- package/src/tools/creativeApps.js +226 -7
- package/src/tools/creativeApps.ts +233 -7
- package/src/tools/memoryWrite.js +71 -89
- package/src/tools/memoryWrite.ts +108 -0
- package/src/tools/resolveAutomator.js +356 -89
- package/src/tools/resolveAutomator.ts +403 -0
- package/src/toolsList.js +1 -1
- package/src/toolsList.ts +1 -1
- package/src/tui/consoleGuard.js +85 -0
- package/src/tui/consoleGuard.ts +102 -0
- package/src/tui/messageActionPlacement.js +8 -3
- package/src/tui/messageActionPlacement.ts +8 -3
- package/src/tui/messageInteraction.js +184 -27
- package/src/tui/messageInteraction.ts +221 -45
- package/src/tui/mouseHover.js +4 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/smartLinkClick.js +353 -0
- package/src/tui/smartLinkClick.ts +413 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { sidebarVisible, sessionMainWidth } from './sessionSidebar.js';
|
|
3
|
+
import { visibleWidth } from './text.js';
|
|
4
|
+
const KNOWN_WEB_TLDS = new Set([
|
|
5
|
+
'com', 'org', 'net', 'io', 'dev', 'app', 'ai', 'co', 'edu', 'gov',
|
|
6
|
+
'me', 'sh', 'xyz', 'tech', 'cloud', 'gg', 'tv', 'info', 'biz', 'page',
|
|
7
|
+
'site', 'online', 'link', 'live', 'studio', 'design', 'so', 'to', 'fm',
|
|
8
|
+
'id', 'uk', 'de', 'fr', 'jp', 'kr', 'au', 'ca', 'us', 'eu', 'in', 'sg'
|
|
9
|
+
]);
|
|
10
|
+
const CODE_FILE_EXTENSIONS = new Set([
|
|
11
|
+
'js', 'ts', 'jsx', 'tsx', 'mjs', 'cjs', 'py', 'rb', 'go', 'rs', 'java',
|
|
12
|
+
'c', 'cpp', 'h', 'hpp', 'cs', 'php', 'swift', 'kt', 'scala', 'lua',
|
|
13
|
+
'json', 'yaml', 'yml', 'toml', 'xml', 'ini', 'env', 'lock', 'md', 'txt',
|
|
14
|
+
'css', 'scss', 'less', 'vue', 'svelte', 'astro', 'sql', 'graphql', 'proto',
|
|
15
|
+
'wasm', 'map', 'png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'ico', 'mp4',
|
|
16
|
+
'mov', 'mp3', 'wav', 'ogg', 'pdf', 'zip', 'tar', 'gz', 'tgz'
|
|
17
|
+
]);
|
|
18
|
+
const KNOWN_HOST_SUFFIXES = [
|
|
19
|
+
'.vercel.app',
|
|
20
|
+
'.netlify.app',
|
|
21
|
+
'.pages.dev',
|
|
22
|
+
'.github.io',
|
|
23
|
+
'.fly.dev',
|
|
24
|
+
'.railway.app',
|
|
25
|
+
'.render.com',
|
|
26
|
+
'.onrender.com',
|
|
27
|
+
'.herokuapp.com',
|
|
28
|
+
'.workers.dev',
|
|
29
|
+
'.web.app',
|
|
30
|
+
'.firebaseapp.com',
|
|
31
|
+
'.supabase.co',
|
|
32
|
+
'.amazonaws.com',
|
|
33
|
+
'.cloudfront.net',
|
|
34
|
+
'vercel.com',
|
|
35
|
+
'github.com',
|
|
36
|
+
'gitlab.com',
|
|
37
|
+
'npmjs.com',
|
|
38
|
+
'pypi.org',
|
|
39
|
+
'crates.io',
|
|
40
|
+
'localhost'
|
|
41
|
+
];
|
|
42
|
+
function stripTrailingPunctuation(raw) {
|
|
43
|
+
let clean = raw;
|
|
44
|
+
let trimmedChars = 0;
|
|
45
|
+
while (clean.length > 0) {
|
|
46
|
+
const last = clean[clean.length - 1];
|
|
47
|
+
if (/[.,;:!?'"`\]>]/.test(last)) {
|
|
48
|
+
clean = clean.slice(0, -1);
|
|
49
|
+
trimmedChars++;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (last === ')') {
|
|
53
|
+
const opens = (clean.match(/\(/g) || []).length;
|
|
54
|
+
const closes = (clean.match(/\)/g) || []).length;
|
|
55
|
+
if (closes > opens) {
|
|
56
|
+
clean = clean.slice(0, -1);
|
|
57
|
+
trimmedChars++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
return { clean, trimmedChars };
|
|
64
|
+
}
|
|
65
|
+
function isLikelyBareWebDomain(token) {
|
|
66
|
+
const withoutEllipsis = token.replace(/(?:…|\.{2,})+$/, '');
|
|
67
|
+
const slashIdx = withoutEllipsis.indexOf('/');
|
|
68
|
+
const hostPort = (slashIdx >= 0 ? withoutEllipsis.slice(0, slashIdx) : withoutEllipsis).toLowerCase();
|
|
69
|
+
const pathPart = slashIdx >= 0 ? withoutEllipsis.slice(slashIdx) : '';
|
|
70
|
+
if (/^(?:localhost|127\.0\.0\.1|0\.0\.0\.0):\d{2,5}$/.test(hostPort)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const host = hostPort.replace(/:\d{2,5}$/, '');
|
|
74
|
+
if (!host.includes('.') || host.startsWith('.') || host.endsWith('.'))
|
|
75
|
+
return false;
|
|
76
|
+
for (const suffix of KNOWN_HOST_SUFFIXES) {
|
|
77
|
+
if (host === suffix || host.endsWith(suffix))
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const parts = host.split('.');
|
|
81
|
+
if (parts.length < 2)
|
|
82
|
+
return false;
|
|
83
|
+
const tld = parts[parts.length - 1];
|
|
84
|
+
if (!KNOWN_WEB_TLDS.has(tld))
|
|
85
|
+
return false;
|
|
86
|
+
if (!pathPart && CODE_FILE_EXTENSIONS.has(tld) && parts.length === 2) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (parts.some(p => !/^[a-z0-9-]+$/i.test(p) || p.startsWith('-') || p.endsWith('-'))) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
export function resolveFullUrlFromMessage(candidate, rawMessageText) {
|
|
95
|
+
const cleaned = candidate.trim();
|
|
96
|
+
const isTruncated = cleaned.endsWith('…') || cleaned.endsWith('...');
|
|
97
|
+
const prefix = cleaned
|
|
98
|
+
.replace(/(?:…|\.{2,})+$/, '')
|
|
99
|
+
.replace(/^https?:\/\//i, '')
|
|
100
|
+
.replace(/^www\./i, '');
|
|
101
|
+
if (rawMessageText && prefix.length >= 4) {
|
|
102
|
+
const urlRegex = /https?:\/\/[^\s<>"'`)\]]+/gi;
|
|
103
|
+
let match;
|
|
104
|
+
while ((match = urlRegex.exec(rawMessageText)) !== null) {
|
|
105
|
+
const fullUrl = stripTrailingPunctuation(match[0]).clean;
|
|
106
|
+
const normalizedFull = fullUrl.replace(/^https?:\/\//i, '').replace(/^www\./i, '');
|
|
107
|
+
if (isTruncated) {
|
|
108
|
+
if (normalizedFull.startsWith(prefix))
|
|
109
|
+
return fullUrl;
|
|
110
|
+
}
|
|
111
|
+
else if (normalizedFull === prefix) {
|
|
112
|
+
return fullUrl;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const withoutEllipsis = cleaned.replace(/(?:…|\.{2,})+$/, '');
|
|
117
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(withoutEllipsis)) {
|
|
118
|
+
return withoutEllipsis;
|
|
119
|
+
}
|
|
120
|
+
if (/^(?:localhost|127\.0\.0\.1|0\.0\.0\.0):\d{2,5}/i.test(withoutEllipsis)) {
|
|
121
|
+
return `http://${withoutEllipsis}`;
|
|
122
|
+
}
|
|
123
|
+
return `https://${withoutEllipsis}`;
|
|
124
|
+
}
|
|
125
|
+
function findUnclosedOsc8Url(rawRow) {
|
|
126
|
+
if (!rawRow || !rawRow.includes('\x1b]8;'))
|
|
127
|
+
return null;
|
|
128
|
+
let active = null;
|
|
129
|
+
const osc8Re = /\x1b\]8;[^;]*;([^\x07\x1b]*)(?:\x07|\x1b\\)/g;
|
|
130
|
+
let match;
|
|
131
|
+
while ((match = osc8Re.exec(rawRow)) !== null) {
|
|
132
|
+
const target = match[1] ?? '';
|
|
133
|
+
active = target.length > 0 ? target : null;
|
|
134
|
+
}
|
|
135
|
+
return active;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Extract all clickable links (both OSC 8 hyperlinks and visible URLs / bare domains)
|
|
139
|
+
* along with their exact visible column intervals `[startCol, endCol]` on a single row.
|
|
140
|
+
*/
|
|
141
|
+
export function extractRowLinks(rawRow, rowIndex = 0, rawMessageText, prevRawRow) {
|
|
142
|
+
if (!rawRow)
|
|
143
|
+
return [];
|
|
144
|
+
const links = [];
|
|
145
|
+
let col = 0;
|
|
146
|
+
let i = 0;
|
|
147
|
+
let activeOsc8Url = findUnclosedOsc8Url(prevRawRow);
|
|
148
|
+
let osc8StartCol = 0;
|
|
149
|
+
let osc8Label = '';
|
|
150
|
+
const charToColStart = [];
|
|
151
|
+
const charToColEnd = [];
|
|
152
|
+
let stripped = '';
|
|
153
|
+
while (i < rawRow.length) {
|
|
154
|
+
if (rawRow.startsWith('\x1b]8;', i)) {
|
|
155
|
+
const rest = rawRow.slice(i + 4);
|
|
156
|
+
const semi = rest.indexOf(';');
|
|
157
|
+
if (semi !== -1) {
|
|
158
|
+
const afterParams = rest.slice(semi + 1);
|
|
159
|
+
const belIdx = afterParams.indexOf('\x07');
|
|
160
|
+
const stIdx = afterParams.indexOf('\x1b\\');
|
|
161
|
+
let endOffset = -1;
|
|
162
|
+
let terminatorLen = 0;
|
|
163
|
+
if (belIdx !== -1 && (stIdx === -1 || belIdx < stIdx)) {
|
|
164
|
+
endOffset = belIdx;
|
|
165
|
+
terminatorLen = 1;
|
|
166
|
+
}
|
|
167
|
+
else if (stIdx !== -1) {
|
|
168
|
+
endOffset = stIdx;
|
|
169
|
+
terminatorLen = 2;
|
|
170
|
+
}
|
|
171
|
+
if (endOffset !== -1) {
|
|
172
|
+
const urlParam = afterParams.slice(0, endOffset);
|
|
173
|
+
if (urlParam.length > 0) {
|
|
174
|
+
activeOsc8Url = urlParam;
|
|
175
|
+
osc8StartCol = col;
|
|
176
|
+
osc8Label = '';
|
|
177
|
+
}
|
|
178
|
+
else if (activeOsc8Url) {
|
|
179
|
+
if (col > osc8StartCol) {
|
|
180
|
+
const resolved = resolveFullUrlFromMessage(activeOsc8Url.endsWith('…') ? osc8Label || activeOsc8Url : activeOsc8Url, rawMessageText);
|
|
181
|
+
links.push({
|
|
182
|
+
url: resolved,
|
|
183
|
+
label: osc8Label,
|
|
184
|
+
startCol: osc8StartCol,
|
|
185
|
+
endCol: col - 1,
|
|
186
|
+
row: rowIndex,
|
|
187
|
+
isOsc8: true
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
activeOsc8Url = null;
|
|
191
|
+
osc8Label = '';
|
|
192
|
+
}
|
|
193
|
+
i += 4 + semi + 1 + endOffset + terminatorLen;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (rawRow[i] === '\x1b') {
|
|
199
|
+
const csi = /^\x1b\[[0-?]*[ -/]*[@-~]/.exec(rawRow.slice(i));
|
|
200
|
+
if (csi) {
|
|
201
|
+
i += csi[0].length;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const osc = /^\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/.exec(rawRow.slice(i));
|
|
205
|
+
if (osc) {
|
|
206
|
+
i += osc[0].length;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
i++;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const code = rawRow.codePointAt(i);
|
|
213
|
+
const ch = String.fromCodePoint(code);
|
|
214
|
+
const w = Math.max(0, visibleWidth(ch));
|
|
215
|
+
charToColStart.push(col);
|
|
216
|
+
charToColEnd.push(w > 0 ? col + w - 1 : col);
|
|
217
|
+
stripped += ch;
|
|
218
|
+
if (activeOsc8Url)
|
|
219
|
+
osc8Label += ch;
|
|
220
|
+
col += w;
|
|
221
|
+
i += ch.length;
|
|
222
|
+
}
|
|
223
|
+
if (activeOsc8Url && col > osc8StartCol) {
|
|
224
|
+
const resolved = resolveFullUrlFromMessage(activeOsc8Url.endsWith('…') ? osc8Label || activeOsc8Url : activeOsc8Url, rawMessageText);
|
|
225
|
+
links.push({
|
|
226
|
+
url: resolved,
|
|
227
|
+
label: osc8Label,
|
|
228
|
+
startCol: osc8StartCol,
|
|
229
|
+
endCol: col - 1,
|
|
230
|
+
row: rowIndex,
|
|
231
|
+
isOsc8: true
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
const tokenRe = /(?:https?:\/\/|file:\/\/)[^\s<>"'`)\]]+|(?:localhost|127\.0\.0\.1|0\.0\.0\.0):\d{2,5}(?:\/[^\s<>"'`)\]]*)?|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,24}(?:\/[^\s<>"'`)\]]*)?/g;
|
|
235
|
+
let tokenMatch;
|
|
236
|
+
while ((tokenMatch = tokenRe.exec(stripped)) !== null) {
|
|
237
|
+
const rawToken = tokenMatch[0];
|
|
238
|
+
const { clean } = stripTrailingPunctuation(rawToken);
|
|
239
|
+
if (!clean)
|
|
240
|
+
continue;
|
|
241
|
+
const isExplicitScheme = /^(?:https?|file):\/\//i.test(clean);
|
|
242
|
+
if (!isExplicitScheme && !isLikelyBareWebDomain(clean))
|
|
243
|
+
continue;
|
|
244
|
+
const startCharIdx = Array.from(stripped.slice(0, tokenMatch.index)).length;
|
|
245
|
+
const cleanCodePoints = Array.from(clean).length;
|
|
246
|
+
const endCharIdx = startCharIdx + cleanCodePoints - 1;
|
|
247
|
+
const startCol = charToColStart[startCharIdx];
|
|
248
|
+
const endCol = charToColEnd[endCharIdx];
|
|
249
|
+
if (startCol === undefined || endCol === undefined)
|
|
250
|
+
continue;
|
|
251
|
+
const overlapsOsc8 = links.some(existing => existing.isOsc8 && startCol <= existing.endCol && endCol >= existing.startCol);
|
|
252
|
+
if (overlapsOsc8)
|
|
253
|
+
continue;
|
|
254
|
+
const resolvedUrl = resolveFullUrlFromMessage(clean, rawMessageText);
|
|
255
|
+
links.push({
|
|
256
|
+
url: resolvedUrl,
|
|
257
|
+
label: clean,
|
|
258
|
+
startCol,
|
|
259
|
+
endCol,
|
|
260
|
+
row: rowIndex,
|
|
261
|
+
isOsc8: false
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return links;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Check if a screen point `(point.x, point.y)` lands on a clickable URL/link in the transcript.
|
|
268
|
+
*/
|
|
269
|
+
export function detectLinkAtPoint(surface, point, marker) {
|
|
270
|
+
if (!surface?.stage.reserved || !Number.isFinite(point.x) || !Number.isFinite(point.y))
|
|
271
|
+
return null;
|
|
272
|
+
const mainWidth = sidebarVisible(surface.width) ? sessionMainWidth(surface.width) : surface.width;
|
|
273
|
+
const leftGutter = (surface.turnRailLayout?.turns?.length ?? 0) > 0 ? 3 : 0;
|
|
274
|
+
if (point.x < leftGutter || point.x >= Math.min(mainWidth, surface.viewport.width + leftGutter))
|
|
275
|
+
return null;
|
|
276
|
+
const top = Math.max(0, (surface.out.rows || surface.stage.height) - surface.stage.height);
|
|
277
|
+
const viewRow = point.y - top;
|
|
278
|
+
if (viewRow < 0 || viewRow >= surface.viewport.height)
|
|
279
|
+
return null;
|
|
280
|
+
const flat = surface.transcript.flatten(surface.viewport.width);
|
|
281
|
+
const visible = Math.max(0, Math.min(surface.viewport.height, flat.rows.length - surface.viewport.scrollTop));
|
|
282
|
+
const padding = surface.viewport.height - visible;
|
|
283
|
+
if (viewRow < padding)
|
|
284
|
+
return null;
|
|
285
|
+
const row = surface.viewport.scrollTop + viewRow - padding;
|
|
286
|
+
const rawRow = flat.rows[row];
|
|
287
|
+
if (!rawRow)
|
|
288
|
+
return null;
|
|
289
|
+
const prevRawRow = row > 0 ? flat.rows[row - 1] : undefined;
|
|
290
|
+
const rawMessageText = marker?.meta?.messageText;
|
|
291
|
+
const links = extractRowLinks(rawRow, row, rawMessageText, prevRawRow);
|
|
292
|
+
if (!links.length)
|
|
293
|
+
return null;
|
|
294
|
+
const col = point.x - leftGutter;
|
|
295
|
+
for (const link of links) {
|
|
296
|
+
if (col >= link.startCol && col <= link.endCol) {
|
|
297
|
+
return link;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
let lastOpenedUrl = '';
|
|
303
|
+
let lastOpenedAt = 0;
|
|
304
|
+
/**
|
|
305
|
+
* Open an HTTP/HTTPS/file URL in the system default browser or handler without blocking the TUI.
|
|
306
|
+
*/
|
|
307
|
+
export function openDetectedLink(url, options = {}) {
|
|
308
|
+
if (!url || !/^(?:https?|file):\/\//i.test(url))
|
|
309
|
+
return false;
|
|
310
|
+
const now = options.now ?? Date.now();
|
|
311
|
+
const debounceMs = options.debounceMs ?? 800;
|
|
312
|
+
if (url === lastOpenedUrl && now - lastOpenedAt < debounceMs) {
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
lastOpenedUrl = url;
|
|
316
|
+
lastOpenedAt = now;
|
|
317
|
+
const platform = options.platform ?? process.platform;
|
|
318
|
+
const spawnFn = options.spawnImpl ?? spawn;
|
|
319
|
+
let command;
|
|
320
|
+
let args;
|
|
321
|
+
if (platform === 'darwin') {
|
|
322
|
+
command = 'open';
|
|
323
|
+
args = [url];
|
|
324
|
+
}
|
|
325
|
+
else if (platform === 'win32') {
|
|
326
|
+
command = 'rundll32.exe';
|
|
327
|
+
args = ['url.dll,FileProtocolHandler', url];
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
command = 'xdg-open';
|
|
331
|
+
args = [url];
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
const child = spawnFn(command, args, {
|
|
335
|
+
detached: true,
|
|
336
|
+
stdio: 'ignore',
|
|
337
|
+
shell: false,
|
|
338
|
+
windowsHide: true
|
|
339
|
+
});
|
|
340
|
+
child.on?.('error', () => {
|
|
341
|
+
// Ignore missing browser opener errors on headless hosts.
|
|
342
|
+
});
|
|
343
|
+
child.unref?.();
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
export function resetLinkOpenDebounceForTests() {
|
|
351
|
+
lastOpenedUrl = '';
|
|
352
|
+
lastOpenedAt = 0;
|
|
353
|
+
}
|