@causyne/agent 1.20.111 → 1.20.116
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/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +72 -37
- package/src/agentLoop.ts +70 -38
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +7 -2
- package/src/browser/causyneBrowser.ts +8 -2
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +135 -83
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +57 -26
- package/src/tui/codeProgress.ts +57 -25
- package/src/tui/codeStreamRenderer.js +59 -14
- package/src/tui/codeStreamRenderer.ts +58 -14
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +33 -17
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +162 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +120 -49
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +156 -67
- package/src/tui/turnRail.ts +155 -58
- package/src/tui/usageCard.js +80 -45
- package/src/tui/usageCard.ts +81 -46
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
package/src/browser/urlPolicy.js
CHANGED
|
@@ -23,18 +23,27 @@ function isPrivateIpv4(address) {
|
|
|
23
23
|
}
|
|
24
24
|
function isPrivateIpv6(address) {
|
|
25
25
|
const normalized = address.toLowerCase().split('%')[0] ?? '';
|
|
26
|
-
|
|
26
|
+
let canonical = normalized;
|
|
27
|
+
try {
|
|
28
|
+
canonical = new URL(`http://[${normalized}]/`).hostname.slice(1, -1);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
27
31
|
return true;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
||
|
|
32
|
+
}
|
|
33
|
+
if (canonical === '::' || canonical === '::1')
|
|
34
|
+
return true;
|
|
35
|
+
if (canonical.startsWith('fc') || canonical.startsWith('fd') || canonical.startsWith('fe8')
|
|
36
|
+
|| canonical.startsWith('fe9') || canonical.startsWith('fea') || canonical.startsWith('feb')
|
|
37
|
+
|| canonical.startsWith('fec') || canonical.startsWith('fed') || canonical.startsWith('fee')
|
|
38
|
+
|| canonical.startsWith('fef') || canonical.startsWith('ff') || canonical.startsWith('2001:db8:')
|
|
39
|
+
|| canonical === '2001:db8::' || canonical.startsWith('64:ff9b:'))
|
|
33
40
|
return true;
|
|
34
41
|
if (normalized.startsWith('::ffff:')) {
|
|
35
42
|
const mapped = normalized.slice('::ffff:'.length);
|
|
36
43
|
return isIP(mapped) === 4 ? isPrivateIpv4(mapped) : true;
|
|
37
44
|
}
|
|
45
|
+
if (canonical.startsWith('::ffff:'))
|
|
46
|
+
return true;
|
|
38
47
|
return false;
|
|
39
48
|
}
|
|
40
49
|
export function isPrivateAddress(address) {
|
|
@@ -87,8 +96,9 @@ export async function assertPublicWebUrl(value) {
|
|
|
87
96
|
throw new Error('URLs containing credentials are not allowed');
|
|
88
97
|
if (blockedHostname(url.hostname))
|
|
89
98
|
throw new Error('Local and internal hostnames are not allowed');
|
|
90
|
-
const
|
|
91
|
-
const
|
|
99
|
+
const literalHost = url.hostname.replace(/^\[|\]$/g, '');
|
|
100
|
+
const literalVersion = isIP(literalHost);
|
|
101
|
+
const addresses = literalVersion ? [literalHost] : await resolvedAddresses(url.hostname);
|
|
92
102
|
if (addresses.length === 0 || addresses.some(isPrivateAddress)) {
|
|
93
103
|
throw new Error('Local, private, link-local, multicast, and reserved network addresses are not allowed');
|
|
94
104
|
}
|
|
@@ -112,8 +122,9 @@ export async function assertBrowserNavigableUrl(value) {
|
|
|
112
122
|
}
|
|
113
123
|
if (blockedHostname(url.hostname))
|
|
114
124
|
throw new Error('Local and internal hostnames are not allowed');
|
|
115
|
-
const
|
|
116
|
-
const
|
|
125
|
+
const literalHost = url.hostname.replace(/^\[|\]$/g, '');
|
|
126
|
+
const literalVersion = isIP(literalHost);
|
|
127
|
+
const addresses = literalVersion ? [literalHost] : await resolvedAddresses(url.hostname);
|
|
117
128
|
if (addresses.length === 0 || addresses.some(isPrivateAddress)) {
|
|
118
129
|
throw new Error('Local, private, link-local, multicast, and reserved network addresses are not allowed');
|
|
119
130
|
}
|
package/src/browser/urlPolicy.ts
CHANGED
|
@@ -25,16 +25,23 @@ function isPrivateIpv4(address: string): boolean {
|
|
|
25
25
|
|
|
26
26
|
function isPrivateIpv6(address: string): boolean {
|
|
27
27
|
const normalized = address.toLowerCase().split('%')[0] ?? '';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
let canonical = normalized;
|
|
29
|
+
try {
|
|
30
|
+
canonical = new URL(`http://[${normalized}]/`).hostname.slice(1, -1);
|
|
31
|
+
} catch {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (canonical === '::' || canonical === '::1') return true;
|
|
35
|
+
if (canonical.startsWith('fc') || canonical.startsWith('fd') || canonical.startsWith('fe8')
|
|
36
|
+
|| canonical.startsWith('fe9') || canonical.startsWith('fea') || canonical.startsWith('feb')
|
|
37
|
+
|| canonical.startsWith('fec') || canonical.startsWith('fed') || canonical.startsWith('fee')
|
|
38
|
+
|| canonical.startsWith('fef') || canonical.startsWith('ff') || canonical.startsWith('2001:db8:')
|
|
39
|
+
|| canonical === '2001:db8::' || canonical.startsWith('64:ff9b:')) return true;
|
|
34
40
|
if (normalized.startsWith('::ffff:')) {
|
|
35
41
|
const mapped = normalized.slice('::ffff:'.length);
|
|
36
42
|
return isIP(mapped) === 4 ? isPrivateIpv4(mapped) : true;
|
|
37
43
|
}
|
|
44
|
+
if (canonical.startsWith('::ffff:')) return true;
|
|
38
45
|
return false;
|
|
39
46
|
}
|
|
40
47
|
|
|
@@ -84,8 +91,9 @@ export async function assertPublicWebUrl(value: string): Promise<URL> {
|
|
|
84
91
|
if (url.username || url.password) throw new Error('URLs containing credentials are not allowed');
|
|
85
92
|
if (blockedHostname(url.hostname)) throw new Error('Local and internal hostnames are not allowed');
|
|
86
93
|
|
|
87
|
-
const
|
|
88
|
-
const
|
|
94
|
+
const literalHost = url.hostname.replace(/^\[|\]$/g, '');
|
|
95
|
+
const literalVersion = isIP(literalHost);
|
|
96
|
+
const addresses = literalVersion ? [literalHost] : await resolvedAddresses(url.hostname);
|
|
89
97
|
if (addresses.length === 0 || addresses.some(isPrivateAddress)) {
|
|
90
98
|
throw new Error('Local, private, link-local, multicast, and reserved network addresses are not allowed');
|
|
91
99
|
}
|
|
@@ -110,8 +118,9 @@ export async function assertBrowserNavigableUrl(value: string): Promise<URL> {
|
|
|
110
118
|
|
|
111
119
|
if (blockedHostname(url.hostname)) throw new Error('Local and internal hostnames are not allowed');
|
|
112
120
|
|
|
113
|
-
const
|
|
114
|
-
const
|
|
121
|
+
const literalHost = url.hostname.replace(/^\[|\]$/g, '');
|
|
122
|
+
const literalVersion = isIP(literalHost);
|
|
123
|
+
const addresses = literalVersion ? [literalHost] : await resolvedAddresses(url.hostname);
|
|
115
124
|
if (addresses.length === 0 || addresses.some(isPrivateAddress)) {
|
|
116
125
|
throw new Error('Local, private, link-local, multicast, and reserved network addresses are not allowed');
|
|
117
126
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
|
+
const MAX_ACTIVE_PREVIEWS = 128;
|
|
4
5
|
const MIME = {
|
|
5
6
|
'.html': 'text/html', '.htm': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript',
|
|
6
7
|
'.css': 'text/css', '.json': 'application/json', '.svg': 'image/svg+xml', '.png': 'image/png',
|
|
@@ -24,10 +25,21 @@ export class WorkspacePreview {
|
|
|
24
25
|
throw new Error('Preview requires an HTML file inside the selected workspace');
|
|
25
26
|
const origin = `https://${randomUUID()}.causyne-preview.invalid`;
|
|
26
27
|
this.roots.set(origin, path.dirname(target));
|
|
28
|
+
if (this.roots.size > MAX_ACTIVE_PREVIEWS) {
|
|
29
|
+
const oldest = this.roots.keys().next().value;
|
|
30
|
+
if (oldest)
|
|
31
|
+
this.roots.delete(oldest);
|
|
32
|
+
}
|
|
27
33
|
return `${origin}/${encodeURIComponent(path.basename(target))}`;
|
|
28
34
|
}
|
|
29
35
|
async response(rawUrl) {
|
|
30
|
-
|
|
36
|
+
let url;
|
|
37
|
+
try {
|
|
38
|
+
url = new URL(rawUrl);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
31
43
|
const root = this.roots.get(url.origin);
|
|
32
44
|
if (!root)
|
|
33
45
|
return null;
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
|
|
5
|
+
const MAX_ACTIVE_PREVIEWS = 128;
|
|
5
6
|
const MIME: Record<string, string> = {
|
|
6
7
|
'.html': 'text/html', '.htm': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript',
|
|
7
8
|
'.css': 'text/css', '.json': 'application/json', '.svg': 'image/svg+xml', '.png': 'image/png',
|
|
@@ -27,11 +28,20 @@ export class WorkspacePreview {
|
|
|
27
28
|
if (!within(root, target) || !/\.html?$/i.test(target)) throw new Error('Preview requires an HTML file inside the selected workspace');
|
|
28
29
|
const origin = `https://${randomUUID()}.causyne-preview.invalid`;
|
|
29
30
|
this.roots.set(origin, path.dirname(target));
|
|
31
|
+
if (this.roots.size > MAX_ACTIVE_PREVIEWS) {
|
|
32
|
+
const oldest = this.roots.keys().next().value;
|
|
33
|
+
if (oldest) this.roots.delete(oldest);
|
|
34
|
+
}
|
|
30
35
|
return `${origin}/${encodeURIComponent(path.basename(target))}`;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
async response(rawUrl: string): Promise<{ status: number; contentType: string; body: Buffer } | null> {
|
|
34
|
-
|
|
39
|
+
let url: URL;
|
|
40
|
+
try {
|
|
41
|
+
url = new URL(rawUrl);
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
35
45
|
const root = this.roots.get(url.origin);
|
|
36
46
|
if (!root) return null;
|
|
37
47
|
const deny = { status: 403, contentType: 'text/plain', body: Buffer.from('Preview asset is outside the allowed scope') };
|
|
@@ -12,22 +12,26 @@ export function extractCoordinateNumbers(raw) {
|
|
|
12
12
|
const clean = String(raw || '').replace(/[()[\]]/g, ' ').trim();
|
|
13
13
|
if (!clean)
|
|
14
14
|
return [];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.map((s) => Number.parseFloat(s))
|
|
18
|
-
.filter((n) => Number.isFinite(n));
|
|
15
|
+
const values = clean.split(/[\s,]+/).map((part) => Number(part));
|
|
16
|
+
return values.every(Number.isFinite) ? values : [];
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
19
|
* Ground normalized coordinates (0-1000) to actual screen units.
|
|
22
20
|
* Defaults to OS logical points on macOS/modern desktop actuators to prevent double-scaling.
|
|
23
21
|
*/
|
|
24
22
|
export function groundPoint(nums, screen = { width: 1920, height: 1080, scaleFactor: 1 }, factor = DEFAULT_FACTOR) {
|
|
25
|
-
if (nums.length
|
|
23
|
+
if (!Array.isArray(nums) || nums.length !== 2 || !nums.every(Number.isFinite))
|
|
24
|
+
return null;
|
|
25
|
+
if (!Number.isFinite(screen.width) || screen.width <= 0 || !Number.isFinite(screen.height) || screen.height <= 0)
|
|
26
|
+
return null;
|
|
27
|
+
if (!factor.every(value => Number.isFinite(value) && value > 0))
|
|
26
28
|
return null;
|
|
27
29
|
const rawX = nums[0] ?? 0;
|
|
28
30
|
const rawY = nums[1] ?? 0;
|
|
29
31
|
const targetSpace = screen.targetSpace ?? 'logical';
|
|
30
|
-
const scale = targetSpace === 'physical' ? (screen.scaleFactor
|
|
32
|
+
const scale = targetSpace === 'physical' ? (screen.scaleFactor ?? 1) : 1;
|
|
33
|
+
if (!Number.isFinite(scale) || scale <= 0)
|
|
34
|
+
return null;
|
|
31
35
|
const normX = Math.max(0, Math.min(1, rawX / factor[0]));
|
|
32
36
|
const normY = Math.max(0, Math.min(1, rawY / factor[1]));
|
|
33
37
|
return {
|
|
@@ -39,7 +43,7 @@ export function groundPoint(nums, screen = { width: 1920, height: 1080, scaleFac
|
|
|
39
43
|
* Ground a bounding box (x1, y1, x2, y2) into its midpoint (center click).
|
|
40
44
|
*/
|
|
41
45
|
export function groundBoxCenter(nums, screen = { width: 1920, height: 1080, scaleFactor: 1 }, factor = DEFAULT_FACTOR) {
|
|
42
|
-
if (nums.length
|
|
46
|
+
if (!Array.isArray(nums) || (nums.length !== 2 && nums.length !== 4) || !nums.every(Number.isFinite))
|
|
43
47
|
return null;
|
|
44
48
|
if (nums.length === 2) {
|
|
45
49
|
return groundPoint(nums, screen, factor);
|
|
@@ -64,7 +68,7 @@ export function parseSingleAction(rawAction, screenContext = { width: 1920, heig
|
|
|
64
68
|
line = line.replace(/^(?:Action(?:_Summary)?[::]\s*)/i, '').trim();
|
|
65
69
|
const callMatch = line.match(/^([a-zA-Z_0-9]+)\s*\((.*)\)$/);
|
|
66
70
|
if (!callMatch) {
|
|
67
|
-
if (
|
|
71
|
+
if (/^finished$/i.test(line)) {
|
|
68
72
|
return { action: 'finished', rawStr: line };
|
|
69
73
|
}
|
|
70
74
|
return null;
|
|
@@ -72,11 +76,11 @@ export function parseSingleAction(rawAction, screenContext = { width: 1920, heig
|
|
|
72
76
|
const funcName = callMatch[1]?.toLowerCase();
|
|
73
77
|
const argsRaw = callMatch[2] || '';
|
|
74
78
|
const argsMap = {};
|
|
75
|
-
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:[
|
|
79
|
+
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|([^,\s'")]+))/g;
|
|
76
80
|
let match;
|
|
77
81
|
while ((match = kvRegex.exec(argsRaw)) !== null) {
|
|
78
82
|
const key = match[1];
|
|
79
|
-
const val = match[2] ?? match[3];
|
|
83
|
+
const val = (match[2] ?? match[3] ?? match[4])?.replace(/\\(['"\\])/g, '$1');
|
|
80
84
|
if (key && val !== undefined) {
|
|
81
85
|
argsMap[key] = val;
|
|
82
86
|
}
|
|
@@ -222,13 +226,13 @@ export function visionGroundingToDesktopAct(actions) {
|
|
|
222
226
|
case 'triple_click': {
|
|
223
227
|
const point = act.coordinates;
|
|
224
228
|
if (point) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
const clicks = act.action === 'triple_click' ? 3 : act.action === 'double_click' ? 2 : 1;
|
|
230
|
+
for (let i = 0; i < clicks; i++) {
|
|
231
|
+
result.push({
|
|
232
|
+
verb: 'clickxy',
|
|
233
|
+
x: point.x,
|
|
234
|
+
y: point.y
|
|
235
|
+
});
|
|
232
236
|
}
|
|
233
237
|
}
|
|
234
238
|
break;
|
|
@@ -283,18 +287,18 @@ export function visionGroundingToDesktopAct(actions) {
|
|
|
283
287
|
break;
|
|
284
288
|
}
|
|
285
289
|
case 'drag': {
|
|
286
|
-
const
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
+
const start = act.startCoordinates ?? act.coordinates;
|
|
291
|
+
const end = act.endCoordinates;
|
|
292
|
+
if (!start || !end)
|
|
293
|
+
break;
|
|
290
294
|
result.push({
|
|
291
295
|
verb: 'drag',
|
|
292
|
-
fromX,
|
|
293
|
-
fromY,
|
|
294
|
-
toX,
|
|
295
|
-
toY,
|
|
296
|
-
x:
|
|
297
|
-
y:
|
|
296
|
+
fromX: start.x,
|
|
297
|
+
fromY: start.y,
|
|
298
|
+
toX: end.x,
|
|
299
|
+
toY: end.y,
|
|
300
|
+
x: end.x,
|
|
301
|
+
y: end.y
|
|
298
302
|
});
|
|
299
303
|
break;
|
|
300
304
|
}
|
|
@@ -71,10 +71,8 @@ const DEFAULT_FACTOR: [number, number] = [1000, 1000];
|
|
|
71
71
|
export function extractCoordinateNumbers(raw: string): number[] {
|
|
72
72
|
const clean = String(raw || '').replace(/[()[\]]/g, ' ').trim();
|
|
73
73
|
if (!clean) return [];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.map((s) => Number.parseFloat(s))
|
|
77
|
-
.filter((n) => Number.isFinite(n));
|
|
74
|
+
const values = clean.split(/[\s,]+/).map((part) => Number(part));
|
|
75
|
+
return values.every(Number.isFinite) ? values : [];
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
/**
|
|
@@ -86,11 +84,14 @@ export function groundPoint(
|
|
|
86
84
|
screen: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 },
|
|
87
85
|
factor: [number, number] = DEFAULT_FACTOR
|
|
88
86
|
): { x: number; y: number } | null {
|
|
89
|
-
if (nums.length
|
|
87
|
+
if (!Array.isArray(nums) || nums.length !== 2 || !nums.every(Number.isFinite)) return null;
|
|
88
|
+
if (!Number.isFinite(screen.width) || screen.width <= 0 || !Number.isFinite(screen.height) || screen.height <= 0) return null;
|
|
89
|
+
if (!factor.every(value => Number.isFinite(value) && value > 0)) return null;
|
|
90
90
|
const rawX = nums[0] ?? 0;
|
|
91
91
|
const rawY = nums[1] ?? 0;
|
|
92
92
|
const targetSpace = screen.targetSpace ?? 'logical';
|
|
93
|
-
const scale = targetSpace === 'physical' ? (screen.scaleFactor
|
|
93
|
+
const scale = targetSpace === 'physical' ? (screen.scaleFactor ?? 1) : 1;
|
|
94
|
+
if (!Number.isFinite(scale) || scale <= 0) return null;
|
|
94
95
|
|
|
95
96
|
const normX = Math.max(0, Math.min(1, rawX / factor[0]));
|
|
96
97
|
const normY = Math.max(0, Math.min(1, rawY / factor[1]));
|
|
@@ -109,7 +110,7 @@ export function groundBoxCenter(
|
|
|
109
110
|
screen: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 },
|
|
110
111
|
factor: [number, number] = DEFAULT_FACTOR
|
|
111
112
|
): { x: number; y: number } | null {
|
|
112
|
-
if (nums.length
|
|
113
|
+
if (!Array.isArray(nums) || (nums.length !== 2 && nums.length !== 4) || !nums.every(Number.isFinite)) return null;
|
|
113
114
|
if (nums.length === 2) {
|
|
114
115
|
return groundPoint(nums, screen, factor);
|
|
115
116
|
}
|
|
@@ -139,7 +140,7 @@ export function parseSingleAction(
|
|
|
139
140
|
|
|
140
141
|
const callMatch = line.match(/^([a-zA-Z_0-9]+)\s*\((.*)\)$/);
|
|
141
142
|
if (!callMatch) {
|
|
142
|
-
if (
|
|
143
|
+
if (/^finished$/i.test(line)) {
|
|
143
144
|
return { action: 'finished', rawStr: line };
|
|
144
145
|
}
|
|
145
146
|
return null;
|
|
@@ -149,11 +150,11 @@ export function parseSingleAction(
|
|
|
149
150
|
const argsRaw = callMatch[2] || '';
|
|
150
151
|
|
|
151
152
|
const argsMap: Record<string, string> = {};
|
|
152
|
-
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:[
|
|
153
|
+
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|([^,\s'")]+))/g;
|
|
153
154
|
let match: RegExpExecArray | null;
|
|
154
155
|
while ((match = kvRegex.exec(argsRaw)) !== null) {
|
|
155
156
|
const key = match[1];
|
|
156
|
-
const val = match[2] ?? match[3];
|
|
157
|
+
const val = (match[2] ?? match[3] ?? match[4])?.replace(/\\(['"\\])/g, '$1');
|
|
157
158
|
if (key && val !== undefined) {
|
|
158
159
|
argsMap[key] = val;
|
|
159
160
|
}
|
|
@@ -319,13 +320,13 @@ export function visionGroundingToDesktopAct(actions: VisionAction[]): DesktopAct
|
|
|
319
320
|
case 'triple_click': {
|
|
320
321
|
const point = act.coordinates;
|
|
321
322
|
if (point) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
323
|
+
const clicks = act.action === 'triple_click' ? 3 : act.action === 'double_click' ? 2 : 1;
|
|
324
|
+
for (let i = 0; i < clicks; i++) {
|
|
325
|
+
result.push({
|
|
326
|
+
verb: 'clickxy',
|
|
327
|
+
x: point.x,
|
|
328
|
+
y: point.y
|
|
329
|
+
});
|
|
329
330
|
}
|
|
330
331
|
}
|
|
331
332
|
break;
|
|
@@ -378,18 +379,17 @@ export function visionGroundingToDesktopAct(actions: VisionAction[]): DesktopAct
|
|
|
378
379
|
break;
|
|
379
380
|
}
|
|
380
381
|
case 'drag': {
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
const toY = act.endCoordinates?.y ?? fromY;
|
|
382
|
+
const start = act.startCoordinates ?? act.coordinates;
|
|
383
|
+
const end = act.endCoordinates;
|
|
384
|
+
if (!start || !end) break;
|
|
385
385
|
result.push({
|
|
386
386
|
verb: 'drag',
|
|
387
|
-
fromX,
|
|
388
|
-
fromY,
|
|
389
|
-
toX,
|
|
390
|
-
toY,
|
|
391
|
-
x:
|
|
392
|
-
y:
|
|
387
|
+
fromX: start.x,
|
|
388
|
+
fromY: start.y,
|
|
389
|
+
toX: end.x,
|
|
390
|
+
toY: end.y,
|
|
391
|
+
x: end.x,
|
|
392
|
+
y: end.y
|
|
393
393
|
});
|
|
394
394
|
break;
|
|
395
395
|
}
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
import { TextLayer } from '../../tui/dialogs.js';
|
|
5
5
|
// @ts-expect-error untyped local TUI theme
|
|
6
6
|
import { GLYPHS } from '../../tui/theme.js';
|
|
7
|
+
import { safeDisplay } from '../../tui/text.js';
|
|
7
8
|
import { ContinuumPickerLayer } from './continuumPickerView.js';
|
|
8
9
|
import { ContinuumScanner } from '../scanner.js';
|
|
9
10
|
import { adoptContinuumSession } from '../ingest.js';
|
|
10
11
|
function formatTimeAgo(timestamp) {
|
|
11
|
-
|
|
12
|
+
if (!Number.isFinite(timestamp) || timestamp <= 0)
|
|
13
|
+
return 'unknown';
|
|
14
|
+
const diffMs = Math.max(0, Date.now() - timestamp);
|
|
12
15
|
const minutes = Math.floor(diffMs / (60 * 1000));
|
|
13
16
|
if (minutes < 60)
|
|
14
17
|
return `${Math.max(1, minutes)}m ago`;
|
|
@@ -21,8 +24,10 @@ function formatTimeAgo(timestamp) {
|
|
|
21
24
|
export function buildContinuumItems(sessions) {
|
|
22
25
|
return sessions.map(s => {
|
|
23
26
|
const timeAgo = formatTimeAgo(s.updatedAt);
|
|
24
|
-
const
|
|
25
|
-
const
|
|
27
|
+
const trimmedWs = s.workspacePath ? s.workspacePath.replace(/[/\\]+$/, '') : '';
|
|
28
|
+
const ws = trimmedWs ? trimmedWs.split(/[/\\]/).filter(Boolean).pop() || trimmedWs : '';
|
|
29
|
+
const safeMessageCount = Number.isFinite(s.messageCount) ? Math.max(0, Math.floor(s.messageCount)) : 0;
|
|
30
|
+
const desc = `${safeMessageCount} msg${safeMessageCount === 1 ? '' : 's'} ${GLYPHS.dot} ${timeAgo}${ws ? ` ${GLYPHS.dot} ${ws}` : ''}`;
|
|
26
31
|
return {
|
|
27
32
|
label: s.title,
|
|
28
33
|
description: desc,
|
|
@@ -115,21 +120,24 @@ export async function openContinuumPreview(sessionId, prompt, scanner) {
|
|
|
115
120
|
if (!detail || !detail.messages) {
|
|
116
121
|
return false;
|
|
117
122
|
}
|
|
123
|
+
const safeSource = safeDisplay(String(detail.sourceLabel ?? '')).replace(/\s+/g, ' ').trim();
|
|
124
|
+
const safeWorkspace = safeDisplay(String(detail.workspacePath || '(default)')).replace(/\s+/g, ' ').trim();
|
|
125
|
+
const safeTitle = safeDisplay(String(detail.title ?? '')).replace(/\s+/g, ' ').trim();
|
|
118
126
|
const lines = [
|
|
119
|
-
`Source: ${
|
|
127
|
+
`Source: ${safeSource} · Messages: ${detail.messages.length} · Workspace: ${safeWorkspace}`,
|
|
120
128
|
'─'.repeat(70),
|
|
121
129
|
''
|
|
122
130
|
];
|
|
123
131
|
for (const msg of detail.messages) {
|
|
124
132
|
const rolePrefix = msg.role === 'user' ? 'USER' : 'ASSISTANT';
|
|
125
133
|
lines.push(`${rolePrefix}:`);
|
|
126
|
-
for (const textLine of msg.content.split('\n')) {
|
|
134
|
+
for (const textLine of safeDisplay(String(msg.content ?? '')).split('\n')) {
|
|
127
135
|
lines.push(` ${textLine}`);
|
|
128
136
|
}
|
|
129
137
|
lines.push('');
|
|
130
138
|
}
|
|
131
139
|
const layer = new TextLayer({
|
|
132
|
-
title: `Preview: ${
|
|
140
|
+
title: `Preview: ${safeTitle}`,
|
|
133
141
|
lines,
|
|
134
142
|
width: 76,
|
|
135
143
|
height: 22
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
import { TextLayer } from '../../tui/dialogs.js';
|
|
6
6
|
// @ts-expect-error untyped local TUI theme
|
|
7
7
|
import { GLYPHS } from '../../tui/theme.js';
|
|
8
|
+
import { safeDisplay } from '../../tui/text.js';
|
|
8
9
|
import { ContinuumPickerLayer } from './continuumPickerView.js';
|
|
9
10
|
import type { ContinuumSessionSummary } from '../types.js';
|
|
10
11
|
import { ContinuumScanner } from '../scanner.js';
|
|
11
12
|
import { adoptContinuumSession } from '../ingest.js';
|
|
12
13
|
|
|
13
14
|
function formatTimeAgo(timestamp: number): string {
|
|
14
|
-
|
|
15
|
+
if (!Number.isFinite(timestamp) || timestamp <= 0) return 'unknown';
|
|
16
|
+
const diffMs = Math.max(0, Date.now() - timestamp);
|
|
15
17
|
const minutes = Math.floor(diffMs / (60 * 1000));
|
|
16
18
|
if (minutes < 60) return `${Math.max(1, minutes)}m ago`;
|
|
17
19
|
const hours = Math.floor(minutes / 60);
|
|
@@ -23,8 +25,10 @@ function formatTimeAgo(timestamp: number): string {
|
|
|
23
25
|
export function buildContinuumItems(sessions: ContinuumSessionSummary[]) {
|
|
24
26
|
return sessions.map(s => {
|
|
25
27
|
const timeAgo = formatTimeAgo(s.updatedAt);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
+
const trimmedWs = s.workspacePath ? s.workspacePath.replace(/[/\\]+$/, '') : '';
|
|
29
|
+
const ws = trimmedWs ? trimmedWs.split(/[/\\]/).filter(Boolean).pop() || trimmedWs : '';
|
|
30
|
+
const safeMessageCount = Number.isFinite(s.messageCount) ? Math.max(0, Math.floor(s.messageCount)) : 0;
|
|
31
|
+
const desc = `${safeMessageCount} msg${safeMessageCount === 1 ? '' : 's'} ${GLYPHS.dot} ${timeAgo}${ws ? ` ${GLYPHS.dot} ${ws}` : ''}`;
|
|
28
32
|
|
|
29
33
|
return {
|
|
30
34
|
label: s.title,
|
|
@@ -146,8 +150,11 @@ export async function openContinuumPreview(
|
|
|
146
150
|
return false;
|
|
147
151
|
}
|
|
148
152
|
|
|
153
|
+
const safeSource = safeDisplay(String(detail.sourceLabel ?? '')).replace(/\s+/g, ' ').trim();
|
|
154
|
+
const safeWorkspace = safeDisplay(String(detail.workspacePath || '(default)')).replace(/\s+/g, ' ').trim();
|
|
155
|
+
const safeTitle = safeDisplay(String(detail.title ?? '')).replace(/\s+/g, ' ').trim();
|
|
149
156
|
const lines: string[] = [
|
|
150
|
-
`Source: ${
|
|
157
|
+
`Source: ${safeSource} · Messages: ${detail.messages.length} · Workspace: ${safeWorkspace}`,
|
|
151
158
|
'─'.repeat(70),
|
|
152
159
|
''
|
|
153
160
|
];
|
|
@@ -155,14 +162,14 @@ export async function openContinuumPreview(
|
|
|
155
162
|
for (const msg of detail.messages) {
|
|
156
163
|
const rolePrefix = msg.role === 'user' ? 'USER' : 'ASSISTANT';
|
|
157
164
|
lines.push(`${rolePrefix}:`);
|
|
158
|
-
for (const textLine of msg.content.split('\n')) {
|
|
165
|
+
for (const textLine of safeDisplay(String(msg.content ?? '')).split('\n')) {
|
|
159
166
|
lines.push(` ${textLine}`);
|
|
160
167
|
}
|
|
161
168
|
lines.push('');
|
|
162
169
|
}
|
|
163
170
|
|
|
164
171
|
const layer = new TextLayer({
|
|
165
|
-
title: `Preview: ${
|
|
172
|
+
title: `Preview: ${safeTitle}`,
|
|
166
173
|
lines,
|
|
167
174
|
width: 76,
|
|
168
175
|
height: 22
|
|
@@ -49,11 +49,12 @@ function relativeTime(timestamp, now) {
|
|
|
49
49
|
function countLabel(count) {
|
|
50
50
|
if (!Number.isFinite(count) || count < 0)
|
|
51
51
|
return '0 msgs';
|
|
52
|
-
|
|
52
|
+
const safeCount = Math.floor(count);
|
|
53
|
+
return `${safeCount.toLocaleString('en-US')} ${safeCount === 1 ? 'msg' : 'msgs'}`;
|
|
53
54
|
}
|
|
54
55
|
/** Fit two pieces of styled text in one terminal row, retaining the left title. */
|
|
55
56
|
function pairedRow(left, right, columns) {
|
|
56
|
-
const width = Math.max(1, Math.floor(columns));
|
|
57
|
+
const width = Number.isFinite(columns) ? Math.max(1, Math.min(512, Math.floor(columns))) : 80;
|
|
57
58
|
const rightWidth = visibleWidth(right);
|
|
58
59
|
if (!right || width < 45 || rightWidth > width - 20)
|
|
59
60
|
return truncate(left, width, '…');
|
|
@@ -72,9 +73,11 @@ export function sortContinuumItems(items) {
|
|
|
72
73
|
return [...items].sort((a, b) => {
|
|
73
74
|
const groupA = order.get(a.value.sourcePlatform) ?? SOURCE_ORDER.length;
|
|
74
75
|
const groupB = order.get(b.value.sourcePlatform) ?? SOURCE_ORDER.length;
|
|
76
|
+
const timeA = Number.isFinite(Number(a.value.updatedAt)) ? Number(a.value.updatedAt) : 0;
|
|
77
|
+
const timeB = Number.isFinite(Number(b.value.updatedAt)) ? Number(b.value.updatedAt) : 0;
|
|
75
78
|
return groupA - groupB
|
|
76
|
-
||
|
|
77
|
-
|| a.value.id.localeCompare(b.value.id);
|
|
79
|
+
|| timeB - timeA
|
|
80
|
+
|| String(a.value.id ?? '').localeCompare(String(b.value.id ?? ''));
|
|
78
81
|
});
|
|
79
82
|
}
|
|
80
83
|
function renderedItem(item, selected, width, now) {
|
|
@@ -92,12 +95,14 @@ function renderedItem(item, selected, width, now) {
|
|
|
92
95
|
*/
|
|
93
96
|
export function renderContinuumWindow(entries, start, selected, width, budget, now = Date.now()) {
|
|
94
97
|
const rows = [];
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
+
const safeStart = Number.isFinite(start) ? Math.max(0, Math.floor(start)) : 0;
|
|
99
|
+
const safeSelected = Number.isFinite(selected) ? Math.max(0, Math.floor(selected)) : 0;
|
|
100
|
+
const safeWidth = Number.isFinite(width) ? Math.max(1, Math.min(512, Math.floor(width))) : 80;
|
|
101
|
+
const allowed = Number.isFinite(budget) ? Math.max(0, Math.min(200, Math.floor(budget))) : 0;
|
|
102
|
+
let lastIndex = safeStart - 1;
|
|
98
103
|
let itemCount = 0;
|
|
99
104
|
let previousGroup = null;
|
|
100
|
-
for (let index =
|
|
105
|
+
for (let index = safeStart; index < entries.length; index++) {
|
|
101
106
|
const item = entries[index]?.item;
|
|
102
107
|
if (!item)
|
|
103
108
|
continue;
|
|
@@ -112,12 +117,12 @@ export function renderContinuumWindow(entries, start, selected, width, budget, n
|
|
|
112
117
|
else if (needHeader) {
|
|
113
118
|
rows.push(dim(` ${truncate(group.toUpperCase(), Math.max(1, safeWidth - 5), '…')}`));
|
|
114
119
|
}
|
|
115
|
-
rows.push(...renderedItem(item, index ===
|
|
120
|
+
rows.push(...renderedItem(item, index === safeSelected, safeWidth, now));
|
|
116
121
|
lastIndex = index;
|
|
117
122
|
itemCount++;
|
|
118
123
|
previousGroup = group;
|
|
119
124
|
}
|
|
120
|
-
return { rows, firstIndex:
|
|
125
|
+
return { rows, firstIndex: safeStart, lastIndex, itemCount };
|
|
121
126
|
}
|
|
122
127
|
export class ContinuumPickerLayer extends SelectLayer {
|
|
123
128
|
items;
|
|
@@ -178,7 +183,9 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
178
183
|
}
|
|
179
184
|
if (event.name === 'pageup' || event.name === 'pagedown') {
|
|
180
185
|
const direction = event.name === 'pageup' ? -1 : 1;
|
|
181
|
-
|
|
186
|
+
const curSelected = Number.isFinite(this.list.selected) ? Math.max(0, Math.floor(this.list.selected)) : 0;
|
|
187
|
+
const safeVisible = Number.isFinite(this.visibleItems) ? Math.max(1, Math.floor(this.visibleItems)) : 5;
|
|
188
|
+
this.list.moveTo(curSelected + direction * Math.max(1, safeVisible - 1), safeVisible);
|
|
182
189
|
return 'handled';
|
|
183
190
|
}
|
|
184
191
|
const query = this.list.query;
|
|
@@ -190,8 +197,8 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
190
197
|
return result;
|
|
191
198
|
}
|
|
192
199
|
body(width, height) {
|
|
193
|
-
const w = Math.max(8, Math.floor(width));
|
|
194
|
-
const h = Math.max(1, Math.floor(height));
|
|
200
|
+
const w = Number.isFinite(width) ? Math.max(8, Math.min(512, Math.floor(width))) : 80;
|
|
201
|
+
const h = Number.isFinite(height) ? Math.max(1, Math.min(200, Math.floor(height))) : 1;
|
|
195
202
|
const rows = [];
|
|
196
203
|
const scope = this.scope;
|
|
197
204
|
const label = scope === 'all' ? 'ALL SOURCES' : PLATFORM_NAMES[scope];
|
|
@@ -222,8 +229,10 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
222
229
|
rows.push(dim(' Tab changes source. Ctrl+U clears search.'));
|
|
223
230
|
}
|
|
224
231
|
else if (budget > 0) {
|
|
225
|
-
const
|
|
226
|
-
|
|
232
|
+
const rawSelected = Number.isFinite(this.list.selected) ? Math.floor(this.list.selected) : 0;
|
|
233
|
+
const rawOffset = Number.isFinite(this.list.offset) ? Math.floor(this.list.offset) : 0;
|
|
234
|
+
const selected = Math.min(Math.max(0, rawSelected), count - 1);
|
|
235
|
+
let from = Math.min(Math.max(0, rawOffset), selected);
|
|
227
236
|
let output = renderContinuumWindow(filtered, from, selected, w, budget);
|
|
228
237
|
while (output.lastIndex < selected && from < selected) {
|
|
229
238
|
from++;
|