@causyne/agent 1.20.8 → 1.20.9
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 +167 -34
- package/src/agentLoop.ts +188 -37
- package/src/compiledSkills.js +7330 -319
- package/src/computerUse/types.js +8 -0
- package/src/computerUse/types.ts +121 -0
- package/src/computerUse/visionGrounding.js +87 -29
- package/src/computerUse/visionGrounding.ts +108 -36
- package/src/decisionPolicy.js +7 -9
- package/src/decisionPolicy.ts +7 -9
- package/src/documentEngine/antiSlopAuditor.js +13 -43
- package/src/documentEngine/antiSlopAuditor.ts +15 -47
- package/src/documentEngine/documentForge.js +3 -3
- package/src/documentEngine/documentForge.ts +3 -3
- package/src/launchIntent.js +3 -3
- package/src/launchIntent.ts +3 -3
- package/src/planCache.js +4 -14
- package/src/planCache.ts +4 -14
- package/src/providers/acp.js +4 -2
- package/src/providers/acp.ts +4 -2
- package/src/providers/antigravity.js +122 -22
- package/src/providers/antigravity.ts +121 -21
- package/src/providers/base.d.ts +2 -0
- package/src/providers/pi.js +3 -1
- package/src/providers/pi.ts +4 -2
- package/src/sandbox.js +7 -10
- package/src/smartToolsUse.js +203 -0
- package/src/smartToolsUse.ts +263 -0
- package/src/taskShape.js +7 -7
- package/src/taskShape.ts +7 -7
- package/src/toolPacks.js +5 -5
- package/src/tools/blenderAutomator.js +198 -11
- package/src/tools/documentForge.js +1 -1
- package/src/tools/documentForge.ts +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/computerUse/types.ts
|
|
3
|
+
* Core data contracts for Causyne Universal Hybrid Computer-Use Grounding & Set-of-Marks Engine.
|
|
4
|
+
*
|
|
5
|
+
* Implements ratified Engineering Plan v2 specifications.
|
|
6
|
+
* Strict TypeScript (Causyne Agent).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Geometric rectangle representation. Native input units unless explicitly stated. */
|
|
10
|
+
export interface Rect {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
w: number;
|
|
14
|
+
h: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Display monitor topology and DPI scaling context. */
|
|
18
|
+
export interface Display {
|
|
19
|
+
id: string;
|
|
20
|
+
origin: { x: number; y: number }; // Native units
|
|
21
|
+
size: { w: number; h: number }; // Native units
|
|
22
|
+
physical: { w: number; h: number }; // Captured physical pixels
|
|
23
|
+
pxPerUnit: number; // macOS: backing scale factor (e.g. 2.0); Windows/Linux: 1.0
|
|
24
|
+
rotation: 0 | 90 | 180 | 270;
|
|
25
|
+
primary: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Window reference with hierarchy and z-ordering. */
|
|
29
|
+
export interface WindowRef {
|
|
30
|
+
id: string;
|
|
31
|
+
pid: number;
|
|
32
|
+
app: string;
|
|
33
|
+
title?: string;
|
|
34
|
+
bounds: Rect;
|
|
35
|
+
z: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Point coordinates in various coordinate spaces. */
|
|
39
|
+
export type ModelPoint = {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
space: 'norm1000' | 'norm1' | 'image-px';
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Interactive UI Element perceived from accessibility tree, DOM, or visual grounding. */
|
|
46
|
+
export interface UiElement {
|
|
47
|
+
/** Unique numerical identifier within the snapshot (referenced as snapshotId#tag). */
|
|
48
|
+
tag: number;
|
|
49
|
+
role: string;
|
|
50
|
+
name?: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
/** Never populated for secret/password fields. */
|
|
53
|
+
value?: string;
|
|
54
|
+
state: {
|
|
55
|
+
enabled: boolean;
|
|
56
|
+
checked?: boolean;
|
|
57
|
+
selected?: boolean;
|
|
58
|
+
focused?: boolean;
|
|
59
|
+
expanded?: boolean;
|
|
60
|
+
readOnly?: boolean;
|
|
61
|
+
};
|
|
62
|
+
frame: Rect;
|
|
63
|
+
visibleFrame: Rect;
|
|
64
|
+
clickPoint?: { x: number; y: number };
|
|
65
|
+
actions: ('press' | 'focus' | 'setValue' | 'scroll' | 'expand')[];
|
|
66
|
+
/** Deterministic element fingerprint: SHA-256(role, name, ancestorPath, relativeFrame). */
|
|
67
|
+
fingerprint: string;
|
|
68
|
+
window: string;
|
|
69
|
+
provenance: 'a11y' | 'dom' | 'vision';
|
|
70
|
+
confidence: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Immutable, versioned screen perception snapshot. */
|
|
74
|
+
export interface Snapshot {
|
|
75
|
+
id: string;
|
|
76
|
+
epoch: number;
|
|
77
|
+
takenAtMs: number;
|
|
78
|
+
skewMs: number; // Time difference between visual capture and tree capture
|
|
79
|
+
displays: Display[];
|
|
80
|
+
frontmost: WindowRef;
|
|
81
|
+
windows: WindowRef[];
|
|
82
|
+
elements: UiElement[];
|
|
83
|
+
image: {
|
|
84
|
+
displayId: string;
|
|
85
|
+
sha256: string;
|
|
86
|
+
w: number;
|
|
87
|
+
h: number;
|
|
88
|
+
resize: { scale: number; padX: number; padY: number };
|
|
89
|
+
};
|
|
90
|
+
channel: 'cdp' | 'a11y' | 'vision' | 'fused';
|
|
91
|
+
truncated?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Target reference for actions: either an immutable tag or a model-space point. */
|
|
95
|
+
export type Target =
|
|
96
|
+
| { snapshotId: string; tag: number }
|
|
97
|
+
| { snapshotId: string; point: ModelPoint };
|
|
98
|
+
|
|
99
|
+
/** Executable computer-use action types. */
|
|
100
|
+
export type Action =
|
|
101
|
+
| { type: 'click'; target: Target; button?: 'left' | 'right' | 'middle'; count?: 1 | 2 | 3 }
|
|
102
|
+
| { type: 'drag'; from: Target; to: Target; steps?: number }
|
|
103
|
+
| { type: 'scroll'; at: Target; dx: number; dy: number; unit: 'line' | 'pixel' }
|
|
104
|
+
| { type: 'type'; text: string; strategy?: 'unicode' | 'paste' }
|
|
105
|
+
| { type: 'secret'; ref: string }
|
|
106
|
+
| { type: 'key'; chord: string }
|
|
107
|
+
| { type: 'focusWindow'; windowId: string }
|
|
108
|
+
| { type: 'wait'; ms: number }
|
|
109
|
+
| { type: 'screenshot' };
|
|
110
|
+
|
|
111
|
+
/** Action risk tiers for policy gate enforcement. */
|
|
112
|
+
export type ActionRiskTier = 'R0' | 'R1' | 'R2' | 'R3' | 'R4';
|
|
113
|
+
|
|
114
|
+
/** Target-bound cryptographic approval token for high-risk actions. */
|
|
115
|
+
export interface TargetBoundApprovalToken {
|
|
116
|
+
token: string;
|
|
117
|
+
snapshotId: string;
|
|
118
|
+
elementFingerprint: string;
|
|
119
|
+
actionType: string;
|
|
120
|
+
expiresAtMs: number;
|
|
121
|
+
}
|
|
@@ -18,14 +18,16 @@ export function extractCoordinateNumbers(raw) {
|
|
|
18
18
|
.filter((n) => Number.isFinite(n));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Ground normalized coordinates (0-1000) to actual screen
|
|
21
|
+
* Ground normalized coordinates (0-1000) to actual screen units.
|
|
22
|
+
* Defaults to OS logical points on macOS/modern desktop actuators to prevent double-scaling.
|
|
22
23
|
*/
|
|
23
24
|
export function groundPoint(nums, screen = { width: 1920, height: 1080, scaleFactor: 1 }, factor = DEFAULT_FACTOR) {
|
|
24
25
|
if (nums.length < 2)
|
|
25
26
|
return null;
|
|
26
27
|
const rawX = nums[0] ?? 0;
|
|
27
28
|
const rawY = nums[1] ?? 0;
|
|
28
|
-
const
|
|
29
|
+
const targetSpace = screen.targetSpace ?? 'logical';
|
|
30
|
+
const scale = targetSpace === 'physical' ? (screen.scaleFactor || 1) : 1;
|
|
29
31
|
const normX = Math.max(0, Math.min(1, rawX / factor[0]));
|
|
30
32
|
const normY = Math.max(0, Math.min(1, rawY / factor[1]));
|
|
31
33
|
return {
|
|
@@ -55,9 +57,11 @@ export function groundBoxCenter(nums, screen = { width: 1920, height: 1080, scal
|
|
|
55
57
|
* E.g. Action: click(start_box='(240, 500)')
|
|
56
58
|
*/
|
|
57
59
|
export function parseSingleAction(rawAction, screenContext = { width: 1920, height: 1080, scaleFactor: 1 }) {
|
|
58
|
-
|
|
60
|
+
let line = (rawAction || '').trim();
|
|
59
61
|
if (!line)
|
|
60
62
|
return null;
|
|
63
|
+
// Strip leading Action: or Action_Summary: prefixes
|
|
64
|
+
line = line.replace(/^(?:Action(?:_Summary)?[::]\s*)/i, '').trim();
|
|
61
65
|
const callMatch = line.match(/^([a-zA-Z_0-9]+)\s*\((.*)\)$/);
|
|
62
66
|
if (!callMatch) {
|
|
63
67
|
if (/finished/i.test(line)) {
|
|
@@ -68,12 +72,12 @@ export function parseSingleAction(rawAction, screenContext = { width: 1920, heig
|
|
|
68
72
|
const funcName = callMatch[1]?.toLowerCase();
|
|
69
73
|
const argsRaw = callMatch[2] || '';
|
|
70
74
|
const argsMap = {};
|
|
71
|
-
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*['"]([^'"]+)['"]/g;
|
|
75
|
+
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:['"]([^'"]+)['"]|([^,\s'")]+))/g;
|
|
72
76
|
let match;
|
|
73
77
|
while ((match = kvRegex.exec(argsRaw)) !== null) {
|
|
74
78
|
const key = match[1];
|
|
75
|
-
const val = match[2];
|
|
76
|
-
if (key && val) {
|
|
79
|
+
const val = match[2] ?? match[3];
|
|
80
|
+
if (key && val !== undefined) {
|
|
77
81
|
argsMap[key] = val;
|
|
78
82
|
}
|
|
79
83
|
}
|
|
@@ -170,18 +174,41 @@ export function parseVisionGroundingPrediction(predictionText, screenContext = {
|
|
|
170
174
|
return { thought, reflection, actions };
|
|
171
175
|
}
|
|
172
176
|
const MAC_KEY_CODES = {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
esc: 53,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
left: 123,
|
|
183
|
-
right: 124
|
|
177
|
+
a: 0, s: 1, d: 2, f: 3, h: 4, g: 5, z: 6, x: 7, c: 8, v: 9,
|
|
178
|
+
b: 11, q: 12, w: 13, e: 14, r: 15, y: 16, t: 17,
|
|
179
|
+
1: 18, 2: 19, 3: 20, 4: 21, 6: 22, 5: 23, 9: 25, 7: 26, 8: 28, 0: 29,
|
|
180
|
+
o: 31, u: 32, i: 34, p: 35, l: 37, j: 38, k: 40,
|
|
181
|
+
n: 45, m: 46,
|
|
182
|
+
return: 36, enter: 36, tab: 48, space: 49,
|
|
183
|
+
backspace: 51, delete: 51, escape: 53, esc: 53,
|
|
184
|
+
command: 55, cmd: 55, shift: 56,
|
|
185
|
+
option: 58, alt: 58, control: 59, ctrl: 59,
|
|
186
|
+
up: 126, down: 125, left: 123, right: 124
|
|
184
187
|
};
|
|
188
|
+
function parseCompoundKeyChord(raw) {
|
|
189
|
+
const parts = raw.toLowerCase().split(/[+\-_ ]+/).map((p) => p.trim()).filter(Boolean);
|
|
190
|
+
const modifiers = [];
|
|
191
|
+
let baseKey;
|
|
192
|
+
for (const p of parts) {
|
|
193
|
+
if (p === 'cmd' || p === 'command' || p === 'meta' || p === 'super') {
|
|
194
|
+
modifiers.push('cmd');
|
|
195
|
+
}
|
|
196
|
+
else if (p === 'ctrl' || p === 'control') {
|
|
197
|
+
modifiers.push('ctrl');
|
|
198
|
+
}
|
|
199
|
+
else if (p === 'alt' || p === 'option') {
|
|
200
|
+
modifiers.push('alt');
|
|
201
|
+
}
|
|
202
|
+
else if (p === 'shift') {
|
|
203
|
+
modifiers.push('shift');
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
baseKey = p;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const keyCode = baseKey ? MAC_KEY_CODES[baseKey] : undefined;
|
|
210
|
+
return { chord: raw, modifiers, baseKey, keyCode };
|
|
211
|
+
}
|
|
185
212
|
/**
|
|
186
213
|
* Convert parsed vision grounding actions into Causyne desktop_act equivalent instructions.
|
|
187
214
|
*/
|
|
@@ -217,27 +244,58 @@ export function visionGroundingToDesktopAct(actions) {
|
|
|
217
244
|
}
|
|
218
245
|
case 'press_key':
|
|
219
246
|
case 'hotkey': {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
247
|
+
const rawKey = (act.key || '').trim();
|
|
248
|
+
if (!rawKey)
|
|
249
|
+
break;
|
|
250
|
+
if (rawKey.includes('+') || rawKey.includes('-')) {
|
|
251
|
+
const chordInfo = parseCompoundKeyChord(rawKey);
|
|
252
|
+
result.push({
|
|
253
|
+
verb: 'key',
|
|
254
|
+
chord: chordInfo.chord,
|
|
255
|
+
modifiers: chordInfo.modifiers,
|
|
256
|
+
key: chordInfo.baseKey,
|
|
257
|
+
keyCode: chordInfo.keyCode
|
|
258
|
+
});
|
|
224
259
|
}
|
|
225
|
-
else
|
|
226
|
-
|
|
260
|
+
else {
|
|
261
|
+
const keyName = rawKey.toLowerCase();
|
|
262
|
+
const code = MAC_KEY_CODES[keyName];
|
|
263
|
+
if (code !== undefined) {
|
|
264
|
+
result.push({ verb: 'key', keyCode: code, key: keyName });
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
result.push({ verb: 'type', text: rawKey });
|
|
268
|
+
}
|
|
227
269
|
}
|
|
228
270
|
break;
|
|
229
271
|
}
|
|
272
|
+
case 'scroll': {
|
|
273
|
+
result.push({
|
|
274
|
+
verb: 'scroll',
|
|
275
|
+
direction: act.direction || 'down',
|
|
276
|
+
seconds: act.seconds || 1,
|
|
277
|
+
...(act.coordinates ? { x: act.coordinates.x, y: act.coordinates.y } : {})
|
|
278
|
+
});
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
230
281
|
case 'wait': {
|
|
231
282
|
result.push({ verb: 'wait', seconds: act.seconds || 1 });
|
|
232
283
|
break;
|
|
233
284
|
}
|
|
234
285
|
case 'drag': {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
286
|
+
const fromX = act.startCoordinates?.x ?? act.coordinates?.x ?? 0;
|
|
287
|
+
const fromY = act.startCoordinates?.y ?? act.coordinates?.y ?? 0;
|
|
288
|
+
const toX = act.endCoordinates?.x ?? fromX;
|
|
289
|
+
const toY = act.endCoordinates?.y ?? fromY;
|
|
290
|
+
result.push({
|
|
291
|
+
verb: 'drag',
|
|
292
|
+
fromX,
|
|
293
|
+
fromY,
|
|
294
|
+
toX,
|
|
295
|
+
toY,
|
|
296
|
+
x: toX,
|
|
297
|
+
y: toY
|
|
298
|
+
});
|
|
241
299
|
break;
|
|
242
300
|
}
|
|
243
301
|
case 'finished':
|
|
@@ -9,6 +9,7 @@ export interface ScreenContext {
|
|
|
9
9
|
width: number;
|
|
10
10
|
height: number;
|
|
11
11
|
scaleFactor?: number;
|
|
12
|
+
targetSpace?: 'logical' | 'physical';
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export type ActionVerb =
|
|
@@ -44,13 +45,22 @@ export interface VisionAction {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export interface DesktopActEquivalent {
|
|
47
|
-
verb: 'press' | 'clickxy' | 'type' | 'key' | 'wait';
|
|
48
|
-
x?: number;
|
|
49
|
-
y?: number;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
verb: 'press' | 'clickxy' | 'type' | 'key' | 'wait' | 'scroll' | 'drag';
|
|
49
|
+
x?: number | undefined;
|
|
50
|
+
y?: number | undefined;
|
|
51
|
+
fromX?: number | undefined;
|
|
52
|
+
fromY?: number | undefined;
|
|
53
|
+
toX?: number | undefined;
|
|
54
|
+
toY?: number | undefined;
|
|
55
|
+
text?: string | undefined;
|
|
56
|
+
keyCode?: number | undefined;
|
|
57
|
+
chord?: string | undefined;
|
|
58
|
+
modifiers?: ('cmd' | 'ctrl' | 'alt' | 'shift')[] | undefined;
|
|
59
|
+
key?: string | undefined;
|
|
60
|
+
target?: string | undefined;
|
|
61
|
+
seconds?: number | undefined;
|
|
62
|
+
direction?: ('up' | 'down' | 'left' | 'right') | undefined;
|
|
63
|
+
steps?: number | undefined;
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
const DEFAULT_FACTOR: [number, number] = [1000, 1000];
|
|
@@ -68,7 +78,8 @@ export function extractCoordinateNumbers(raw: string): number[] {
|
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
/**
|
|
71
|
-
* Ground normalized coordinates (0-1000) to actual screen
|
|
81
|
+
* Ground normalized coordinates (0-1000) to actual screen units.
|
|
82
|
+
* Defaults to OS logical points on macOS/modern desktop actuators to prevent double-scaling.
|
|
72
83
|
*/
|
|
73
84
|
export function groundPoint(
|
|
74
85
|
nums: number[],
|
|
@@ -78,7 +89,8 @@ export function groundPoint(
|
|
|
78
89
|
if (nums.length < 2) return null;
|
|
79
90
|
const rawX = nums[0] ?? 0;
|
|
80
91
|
const rawY = nums[1] ?? 0;
|
|
81
|
-
const
|
|
92
|
+
const targetSpace = screen.targetSpace ?? 'logical';
|
|
93
|
+
const scale = targetSpace === 'physical' ? (screen.scaleFactor || 1) : 1;
|
|
82
94
|
|
|
83
95
|
const normX = Math.max(0, Math.min(1, rawX / factor[0]));
|
|
84
96
|
const normY = Math.max(0, Math.min(1, rawY / factor[1]));
|
|
@@ -119,9 +131,12 @@ export function parseSingleAction(
|
|
|
119
131
|
rawAction: string,
|
|
120
132
|
screenContext: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 }
|
|
121
133
|
): VisionAction | null {
|
|
122
|
-
|
|
134
|
+
let line = (rawAction || '').trim();
|
|
123
135
|
if (!line) return null;
|
|
124
136
|
|
|
137
|
+
// Strip leading Action: or Action_Summary: prefixes
|
|
138
|
+
line = line.replace(/^(?:Action(?:_Summary)?[::]\s*)/i, '').trim();
|
|
139
|
+
|
|
125
140
|
const callMatch = line.match(/^([a-zA-Z_0-9]+)\s*\((.*)\)$/);
|
|
126
141
|
if (!callMatch) {
|
|
127
142
|
if (/finished/i.test(line)) {
|
|
@@ -134,12 +149,12 @@ export function parseSingleAction(
|
|
|
134
149
|
const argsRaw = callMatch[2] || '';
|
|
135
150
|
|
|
136
151
|
const argsMap: Record<string, string> = {};
|
|
137
|
-
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*['"]([^'"]+)['"]/g;
|
|
152
|
+
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:['"]([^'"]+)['"]|([^,\s'")]+))/g;
|
|
138
153
|
let match: RegExpExecArray | null;
|
|
139
154
|
while ((match = kvRegex.exec(argsRaw)) !== null) {
|
|
140
155
|
const key = match[1];
|
|
141
|
-
const val = match[2];
|
|
142
|
-
if (key && val) {
|
|
156
|
+
const val = match[2] ?? match[3];
|
|
157
|
+
if (key && val !== undefined) {
|
|
143
158
|
argsMap[key] = val;
|
|
144
159
|
}
|
|
145
160
|
}
|
|
@@ -250,19 +265,46 @@ export function parseVisionGroundingPrediction(
|
|
|
250
265
|
}
|
|
251
266
|
|
|
252
267
|
const MAC_KEY_CODES: Record<string, number> = {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
esc: 53,
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
left: 123,
|
|
263
|
-
right: 124
|
|
268
|
+
a: 0, s: 1, d: 2, f: 3, h: 4, g: 5, z: 6, x: 7, c: 8, v: 9,
|
|
269
|
+
b: 11, q: 12, w: 13, e: 14, r: 15, y: 16, t: 17,
|
|
270
|
+
1: 18, 2: 19, 3: 20, 4: 21, 6: 22, 5: 23, 9: 25, 7: 26, 8: 28, 0: 29,
|
|
271
|
+
o: 31, u: 32, i: 34, p: 35, l: 37, j: 38, k: 40,
|
|
272
|
+
n: 45, m: 46,
|
|
273
|
+
return: 36, enter: 36, tab: 48, space: 49,
|
|
274
|
+
backspace: 51, delete: 51, escape: 53, esc: 53,
|
|
275
|
+
command: 55, cmd: 55, shift: 56,
|
|
276
|
+
option: 58, alt: 58, control: 59, ctrl: 59,
|
|
277
|
+
up: 126, down: 125, left: 123, right: 124
|
|
264
278
|
};
|
|
265
279
|
|
|
280
|
+
function parseCompoundKeyChord(raw: string): {
|
|
281
|
+
chord: string;
|
|
282
|
+
modifiers: ('cmd' | 'ctrl' | 'alt' | 'shift')[];
|
|
283
|
+
baseKey?: string | undefined;
|
|
284
|
+
keyCode?: number | undefined;
|
|
285
|
+
} {
|
|
286
|
+
const parts = raw.toLowerCase().split(/[+\-_ ]+/).map((p) => p.trim()).filter(Boolean);
|
|
287
|
+
const modifiers: ('cmd' | 'ctrl' | 'alt' | 'shift')[] = [];
|
|
288
|
+
let baseKey: string | undefined;
|
|
289
|
+
|
|
290
|
+
for (const p of parts) {
|
|
291
|
+
if (p === 'cmd' || p === 'command' || p === 'meta' || p === 'super') {
|
|
292
|
+
modifiers.push('cmd');
|
|
293
|
+
} else if (p === 'ctrl' || p === 'control') {
|
|
294
|
+
modifiers.push('ctrl');
|
|
295
|
+
} else if (p === 'alt' || p === 'option') {
|
|
296
|
+
modifiers.push('alt');
|
|
297
|
+
} else if (p === 'shift') {
|
|
298
|
+
modifiers.push('shift');
|
|
299
|
+
} else {
|
|
300
|
+
baseKey = p;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const keyCode = baseKey ? MAC_KEY_CODES[baseKey] : undefined;
|
|
305
|
+
return { chord: raw, modifiers, baseKey, keyCode };
|
|
306
|
+
}
|
|
307
|
+
|
|
266
308
|
/**
|
|
267
309
|
* Convert parsed vision grounding actions into Causyne desktop_act equivalent instructions.
|
|
268
310
|
*/
|
|
@@ -299,26 +341,56 @@ export function visionGroundingToDesktopAct(actions: VisionAction[]): DesktopAct
|
|
|
299
341
|
}
|
|
300
342
|
case 'press_key':
|
|
301
343
|
case 'hotkey': {
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
result.push({
|
|
344
|
+
const rawKey = (act.key || '').trim();
|
|
345
|
+
if (!rawKey) break;
|
|
346
|
+
|
|
347
|
+
if (rawKey.includes('+') || rawKey.includes('-')) {
|
|
348
|
+
const chordInfo = parseCompoundKeyChord(rawKey);
|
|
349
|
+
result.push({
|
|
350
|
+
verb: 'key',
|
|
351
|
+
chord: chordInfo.chord,
|
|
352
|
+
modifiers: chordInfo.modifiers,
|
|
353
|
+
key: chordInfo.baseKey,
|
|
354
|
+
keyCode: chordInfo.keyCode
|
|
355
|
+
});
|
|
356
|
+
} else {
|
|
357
|
+
const keyName = rawKey.toLowerCase();
|
|
358
|
+
const code = MAC_KEY_CODES[keyName];
|
|
359
|
+
if (code !== undefined) {
|
|
360
|
+
result.push({ verb: 'key', keyCode: code, key: keyName });
|
|
361
|
+
} else {
|
|
362
|
+
result.push({ verb: 'type', text: rawKey });
|
|
363
|
+
}
|
|
308
364
|
}
|
|
309
365
|
break;
|
|
310
366
|
}
|
|
367
|
+
case 'scroll': {
|
|
368
|
+
result.push({
|
|
369
|
+
verb: 'scroll',
|
|
370
|
+
direction: act.direction || 'down',
|
|
371
|
+
seconds: act.seconds || 1,
|
|
372
|
+
...(act.coordinates ? { x: act.coordinates.x, y: act.coordinates.y } : {})
|
|
373
|
+
});
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
311
376
|
case 'wait': {
|
|
312
377
|
result.push({ verb: 'wait', seconds: act.seconds || 1 });
|
|
313
378
|
break;
|
|
314
379
|
}
|
|
315
380
|
case 'drag': {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
381
|
+
const fromX = act.startCoordinates?.x ?? act.coordinates?.x ?? 0;
|
|
382
|
+
const fromY = act.startCoordinates?.y ?? act.coordinates?.y ?? 0;
|
|
383
|
+
const toX = act.endCoordinates?.x ?? fromX;
|
|
384
|
+
const toY = act.endCoordinates?.y ?? fromY;
|
|
385
|
+
result.push({
|
|
386
|
+
verb: 'drag',
|
|
387
|
+
fromX,
|
|
388
|
+
fromY,
|
|
389
|
+
toX,
|
|
390
|
+
toY,
|
|
391
|
+
x: toX,
|
|
392
|
+
y: toY
|
|
393
|
+
});
|
|
322
394
|
break;
|
|
323
395
|
}
|
|
324
396
|
case 'finished':
|
package/src/decisionPolicy.js
CHANGED
|
@@ -6,15 +6,13 @@ const ARCHITECTURE_TERMS = [
|
|
|
6
6
|
];
|
|
7
7
|
const CHANGE_TERMS = [
|
|
8
8
|
'change', 'replace', 'switch', 'choose', 'decide', 'redesign', 'restructure',
|
|
9
|
-
'rewrite', 'rebuild', 'migration', 'migrate'
|
|
10
|
-
'ubah', 'ganti', 'pilih', 'tentukan', 'rombak', 'beralih', 'migrasi'
|
|
9
|
+
'rewrite', 'rebuild', 'migration', 'migrate'
|
|
11
10
|
];
|
|
12
11
|
const EXPLICIT_CHOICE_PATTERNS = [
|
|
13
12
|
/\b(?:i|we)\s+(?:choose|chose|selected?|decided? (?:on|to use))\s+[a-z0-9@._+-]+/i,
|
|
14
13
|
/\b(?:must use|will use|switch to|rewrite (?:to|in)|migrate to)\s+[a-z0-9@._+-]+/i,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/\b(?:do not|don't|jangan)\s+(?:use|gunakan|pakai)\s+[a-z0-9@._+-]+/i
|
|
14
|
+
/^(?:please\s+)?(?:use|choose)\s+[a-z0-9@._+-]+/i,
|
|
15
|
+
/\b(?:do not|don't)\s+use\s+[a-z0-9@._+-]+/i
|
|
18
16
|
];
|
|
19
17
|
const MUTATING_TOOLS = new Set([
|
|
20
18
|
'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move', 'sysRun', 'sysRunBg',
|
|
@@ -28,9 +26,9 @@ export function assessDecisionRequirement(prompt) {
|
|
|
28
26
|
const text = raw.toLowerCase();
|
|
29
27
|
const architectural = containsAny(text, ARCHITECTURE_TERMS);
|
|
30
28
|
const change = containsAny(text, CHANGE_TERMS);
|
|
31
|
-
const alternatives = /\b(?:or|versus|vs
|
|
32
|
-
const asksForChoice = /\b(?:which|what should|should we
|
|
33
|
-
const delegatesBroadRedesign = /\b(?:redesign|restructure
|
|
29
|
+
const alternatives = /\b(?:or|versus|vs\.?)\b/i.test(raw);
|
|
30
|
+
const asksForChoice = /\b(?:which|what should|should we)\b/i.test(raw);
|
|
31
|
+
const delegatesBroadRedesign = /\b(?:redesign|restructure)\s+(?:the\s+)?(?:architecture|system|runtime|database)\b/i.test(raw);
|
|
34
32
|
const explicit = EXPLICIT_CHOICE_PATTERNS.some(pattern => pattern.test(raw));
|
|
35
33
|
if (!architectural || explicit || (!alternatives && !asksForChoice && !(change && delegatesBroadRedesign))) {
|
|
36
34
|
return { required: false, kind: 'architecture', reason: '' };
|
|
@@ -45,7 +43,7 @@ export function requiresImplementationPlan(prompt, archetype = '', confidence =
|
|
|
45
43
|
const text = String(prompt ?? '').toLowerCase();
|
|
46
44
|
if (archetype === 'build_app' || archetype === 'integrate')
|
|
47
45
|
return true;
|
|
48
|
-
if (confidence === 'high' && /\b(?:implement|build|create|migrate|rewrite|refactor|integrate
|
|
46
|
+
if (confidence === 'high' && /\b(?:implement|build|create|migrate|rewrite|refactor|integrate)\b/i.test(text)) {
|
|
49
47
|
return true;
|
|
50
48
|
}
|
|
51
49
|
return containsAny(text, ARCHITECTURE_TERMS) && containsAny(text, CHANGE_TERMS);
|
package/src/decisionPolicy.ts
CHANGED
|
@@ -38,16 +38,14 @@ const ARCHITECTURE_TERMS = [
|
|
|
38
38
|
|
|
39
39
|
const CHANGE_TERMS = [
|
|
40
40
|
'change', 'replace', 'switch', 'choose', 'decide', 'redesign', 'restructure',
|
|
41
|
-
'rewrite', 'rebuild', 'migration', 'migrate'
|
|
42
|
-
'ubah', 'ganti', 'pilih', 'tentukan', 'rombak', 'beralih', 'migrasi'
|
|
41
|
+
'rewrite', 'rebuild', 'migration', 'migrate'
|
|
43
42
|
];
|
|
44
43
|
|
|
45
44
|
const EXPLICIT_CHOICE_PATTERNS = [
|
|
46
45
|
/\b(?:i|we)\s+(?:choose|chose|selected?|decided? (?:on|to use))\s+[a-z0-9@._+-]+/i,
|
|
47
46
|
/\b(?:must use|will use|switch to|rewrite (?:to|in)|migrate to)\s+[a-z0-9@._+-]+/i,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
/\b(?:do not|don't|jangan)\s+(?:use|gunakan|pakai)\s+[a-z0-9@._+-]+/i
|
|
47
|
+
/^(?:please\s+)?(?:use|choose)\s+[a-z0-9@._+-]+/i,
|
|
48
|
+
/\b(?:do not|don't)\s+use\s+[a-z0-9@._+-]+/i
|
|
51
49
|
];
|
|
52
50
|
|
|
53
51
|
const MUTATING_TOOLS = new Set([
|
|
@@ -64,9 +62,9 @@ export function assessDecisionRequirement(prompt: string): DecisionRequirement {
|
|
|
64
62
|
const text = raw.toLowerCase();
|
|
65
63
|
const architectural = containsAny(text, ARCHITECTURE_TERMS);
|
|
66
64
|
const change = containsAny(text, CHANGE_TERMS);
|
|
67
|
-
const alternatives = /\b(?:or|versus|vs
|
|
68
|
-
const asksForChoice = /\b(?:which|what should|should we
|
|
69
|
-
const delegatesBroadRedesign = /\b(?:redesign|restructure
|
|
65
|
+
const alternatives = /\b(?:or|versus|vs\.?)\b/i.test(raw);
|
|
66
|
+
const asksForChoice = /\b(?:which|what should|should we)\b/i.test(raw);
|
|
67
|
+
const delegatesBroadRedesign = /\b(?:redesign|restructure)\s+(?:the\s+)?(?:architecture|system|runtime|database)\b/i.test(raw);
|
|
70
68
|
const explicit = EXPLICIT_CHOICE_PATTERNS.some(pattern => pattern.test(raw));
|
|
71
69
|
|
|
72
70
|
if (!architectural || explicit || (!alternatives && !asksForChoice && !(change && delegatesBroadRedesign))) {
|
|
@@ -83,7 +81,7 @@ export function assessDecisionRequirement(prompt: string): DecisionRequirement {
|
|
|
83
81
|
export function requiresImplementationPlan(prompt: string, archetype = '', confidence = ''): boolean {
|
|
84
82
|
const text = String(prompt ?? '').toLowerCase();
|
|
85
83
|
if (archetype === 'build_app' || archetype === 'integrate') return true;
|
|
86
|
-
if (confidence === 'high' && /\b(?:implement|build|create|migrate|rewrite|refactor|integrate
|
|
84
|
+
if (confidence === 'high' && /\b(?:implement|build|create|migrate|rewrite|refactor|integrate)\b/i.test(text)) {
|
|
87
85
|
return true;
|
|
88
86
|
}
|
|
89
87
|
return containsAny(text, ARCHITECTURE_TERMS) && containsAny(text, CHANGE_TERMS);
|