antigravity-hands 0.0.0-stage → 0.6.2

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +21 -0
  3. package/README.md +135 -2
  4. package/README_ZH.md +100 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +121 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/driver/client.d.ts +19 -0
  9. package/dist/driver/client.js +169 -0
  10. package/dist/driver/client.js.map +1 -0
  11. package/dist/driver/downloader.d.ts +29 -0
  12. package/dist/driver/downloader.js +161 -0
  13. package/dist/driver/downloader.js.map +1 -0
  14. package/dist/driver/locator.d.ts +11 -0
  15. package/dist/driver/locator.js +108 -0
  16. package/dist/driver/locator.js.map +1 -0
  17. package/dist/engine/batch.d.ts +125 -0
  18. package/dist/engine/batch.js +910 -0
  19. package/dist/engine/batch.js.map +1 -0
  20. package/dist/engine/script.d.ts +47 -0
  21. package/dist/engine/script.js +403 -0
  22. package/dist/engine/script.js.map +1 -0
  23. package/dist/engine/snapshot.d.ts +23 -0
  24. package/dist/engine/snapshot.js +175 -0
  25. package/dist/engine/snapshot.js.map +1 -0
  26. package/dist/hooks/runner.d.ts +11 -0
  27. package/dist/hooks/runner.js +118 -0
  28. package/dist/hooks/runner.js.map +1 -0
  29. package/dist/installer/index.d.ts +21 -0
  30. package/dist/installer/index.js +170 -0
  31. package/dist/installer/index.js.map +1 -0
  32. package/dist/mcp/protocol.d.ts +38 -0
  33. package/dist/mcp/protocol.js +135 -0
  34. package/dist/mcp/protocol.js.map +1 -0
  35. package/dist/mcp/server.d.ts +19 -0
  36. package/dist/mcp/server.js +576 -0
  37. package/dist/mcp/server.js.map +1 -0
  38. package/dist/safety/policy.d.ts +26 -0
  39. package/dist/safety/policy.js +216 -0
  40. package/dist/safety/policy.js.map +1 -0
  41. package/dist/sidecar/server.d.ts +45 -0
  42. package/dist/sidecar/server.js +568 -0
  43. package/dist/sidecar/server.js.map +1 -0
  44. package/dist/sidecar/telemetry.d.ts +93 -0
  45. package/dist/sidecar/telemetry.js +257 -0
  46. package/dist/sidecar/telemetry.js.map +1 -0
  47. package/dist/sidecar/ui.html +1245 -0
  48. package/dist/types.d.ts +287 -0
  49. package/dist/types.js +21 -0
  50. package/dist/types.js.map +1 -0
  51. package/package.json +57 -4
  52. package/plugin/assets/logo.svg +15 -0
  53. package/plugin/hooks.json +11 -0
  54. package/plugin/mcp_config.json +8 -0
  55. package/plugin/plugin.json +18 -0
  56. package/plugin/rules/AGENTS.md +8 -0
  57. package/plugin/sidecars/hands_console/sidecar.json +21 -0
  58. package/plugin/skills/computer-use/SKILL.md +46 -0
@@ -0,0 +1,576 @@
1
+ import { HandsError, } from "../types.js";
2
+ import { HandsEngine, formatBatchCompact, formatScreenshotMetaCompact, formatWindowsCompact, } from "../engine/batch.js";
3
+ import { HandsScriptRunner, formatScriptResultCompact } from "../engine/script.js";
4
+ import { SnapshotStore } from "../engine/snapshot.js";
5
+ import { SafetyPolicyEngine, loadSafetyConfig } from "../safety/policy.js";
6
+ import { TelemetryStore } from "../sidecar/telemetry.js";
7
+ export const SERVER_NAME = "antigravity-hands";
8
+ export const SERVER_VERSION = "0.6.2";
9
+ export const MCP_PROTOCOL_VERSION = "2024-11-05";
10
+ /**
11
+ * High-cohesion 13-tool MCP surface including Codex `cua_repl`-inspired `hands_script`.
12
+ * Legacy v0.1/v0.2 names remain routed silently as aliases.
13
+ */
14
+ const TOOL_DEFINITIONS = [
15
+ {
16
+ name: "hands_status",
17
+ description: "Check native driver health, OS permissions (Accessibility/Screen Recording), capabilities, and Esc emergency-stop state.",
18
+ inputSchema: {
19
+ type: "object",
20
+ properties: {
21
+ reset_emergency_stop: {
22
+ type: "boolean",
23
+ description: "Clear latched Esc emergency stop ONLY after explicit user approval.",
24
+ },
25
+ },
26
+ },
27
+ },
28
+ {
29
+ name: "hands_list_windows",
30
+ description: "List desktop windows in compact single-line format grouped into [VISIBLE] and [MINIMIZED / OTHER SPACE] in one call.",
31
+ inputSchema: {
32
+ type: "object",
33
+ properties: {
34
+ app: { type: "string", description: "Optional filter by application name." },
35
+ include_minimized: {
36
+ type: "boolean",
37
+ description: "Include minimized/other-Space windows (default true).",
38
+ },
39
+ json: { type: "boolean", description: "Return raw JSON instead of compact text (default false)." },
40
+ },
41
+ },
42
+ },
43
+ {
44
+ name: "hands_focus_app",
45
+ description: "Reliably bring an app/window on-screen: unhides, activates, un-minimizes Dock windows, reopens windowless apps (like WPS/Finder), or launches if not running, and returns fresh window_id & bounds.",
46
+ inputSchema: {
47
+ type: "object",
48
+ properties: {
49
+ app: { type: "string", description: "Application name (e.g. 'WPS Office', 'Notes', '微信')." },
50
+ pid: { type: "number" },
51
+ window_id: { type: "number" },
52
+ launch: { type: "boolean", description: "Launch/reopen app if not running or windowless (default true)." },
53
+ },
54
+ },
55
+ },
56
+ {
57
+ name: "hands_observe",
58
+ description: "Primary desktop observer: mode='auto' reads background accessibility tree (@e1..@eN) and auto-augments with offline Chinese/English OCR (@m1..@mN) if AX nodes are sparse; also supports mode='ax' | 'ocr' | 'both'.",
59
+ inputSchema: {
60
+ type: "object",
61
+ properties: {
62
+ app: { type: "string", description: "Application name." },
63
+ window_id: { type: "number", description: "Specific window_id." },
64
+ mode: {
65
+ type: "string",
66
+ enum: ["auto", "ax", "ocr", "both"],
67
+ description: "Observation strategy (default 'auto').",
68
+ },
69
+ min_ax_nodes: { type: "number", description: "Auto-trigger OCR fallback if AX has fewer nodes (default 5)." },
70
+ max_depth: { type: "number" },
71
+ max_nodes: { type: "number" },
72
+ languages: { type: "array", items: { type: "string" } },
73
+ },
74
+ },
75
+ },
76
+ {
77
+ name: "hands_screenshot",
78
+ description: "Capture a silent window-scoped screenshot (fast compact JPEG by default). Set annotate=true for Set-of-Marks numbered badges (#1..#N) paired with clickable @m1..@mN refs. Automatically rejects blank/minimized frames.",
79
+ inputSchema: {
80
+ type: "object",
81
+ properties: {
82
+ app: { type: "string" },
83
+ window_id: { type: "number" },
84
+ max_width: { type: "number", description: "Width cap in px (default 1024)." },
85
+ format: { type: "string", enum: ["jpeg", "png"], description: "Image format (default 'jpeg')." },
86
+ annotate: {
87
+ type: "boolean",
88
+ description: "Overlay numbered Set-of-Marks badges (#1..#N) and return clickable @m1..@mN refs.",
89
+ },
90
+ languages: { type: "array", items: { type: "string" } },
91
+ },
92
+ },
93
+ },
94
+ {
95
+ name: "hands_click",
96
+ description: "Click, double-click (click_count=2), or right-click (button='right') by @ref (@e1/@m1), semantic (app+label/role), direct ocr_text, or logical (x,y). Uses background AXPress first when possible.",
97
+ inputSchema: {
98
+ type: "object",
99
+ properties: {
100
+ ref: { type: "string", description: "Element ref like '@e3' or '@m5'." },
101
+ snapshot_id: { type: "string" },
102
+ app: { type: "string" },
103
+ window_id: { type: "number" },
104
+ label: { type: "string" },
105
+ role: { type: "string" },
106
+ ocr_text: { type: "string", description: "Find & click visible text via native OCR." },
107
+ x: { type: "number" },
108
+ y: { type: "number" },
109
+ button: { type: "string", enum: ["left", "right"], description: "Mouse button (default 'left')." },
110
+ click_count: { type: "number", description: "1=click (default), 2=double-click." },
111
+ prefer_background: { type: "boolean", description: "Try background AXPress first (default true)." },
112
+ allow_destructive: {
113
+ type: "boolean",
114
+ description: "Set true ONLY after explicit user confirmation for Send/Delete/Pay actions.",
115
+ },
116
+ restore_cursor: { type: "boolean" },
117
+ },
118
+ },
119
+ },
120
+ {
121
+ name: "hands_type_text",
122
+ description: "Enter UTF-8 text with full Chinese/CJK/Emoji support (background AXSetValue or lossless clipboard save->paste->restore). Blocks password fields.",
123
+ inputSchema: {
124
+ type: "object",
125
+ required: ["text"],
126
+ properties: {
127
+ text: { type: "string" },
128
+ ref: { type: "string" },
129
+ snapshot_id: { type: "string" },
130
+ app: { type: "string" },
131
+ window_id: { type: "number" },
132
+ label: { type: "string" },
133
+ role: { type: "string" },
134
+ clear_first: { type: "boolean" },
135
+ method: { type: "string", enum: ["auto", "clipboard", "keystrokes"] },
136
+ prefer_background: { type: "boolean" },
137
+ },
138
+ },
139
+ },
140
+ {
141
+ name: "hands_key",
142
+ description: "Press a single key (key='pagedown', optional repeat=29, delay_ms=35) OR a keyboard shortcut chord (keys=['cmd', 's']). Native driver executes repeats at high speed with Esc check per press.",
143
+ inputSchema: {
144
+ type: "object",
145
+ properties: {
146
+ key: { type: "string", description: "Key name: enter, tab, pagedown, pageup, escape, backspace, up, down, left, right, space..." },
147
+ modifiers: { type: "array", items: { type: "string" }, description: "Modifiers: cmd, ctrl, alt, option, shift." },
148
+ keys: { type: "array", items: { type: "string" }, description: "Shortcut chord, e.g. ['cmd', 'k']." },
149
+ repeat: { type: "number", description: "Repeat count 1..100 (default 1)." },
150
+ delay_ms: { type: "number", description: "Delay between repeats in ms (default 35)." },
151
+ },
152
+ },
153
+ },
154
+ {
155
+ name: "hands_scroll",
156
+ description: "Scroll vertically/horizontally at logical coordinates (x, y) with optional native repeat.",
157
+ inputSchema: {
158
+ type: "object",
159
+ required: ["x", "y"],
160
+ properties: {
161
+ x: { type: "number" },
162
+ y: { type: "number" },
163
+ delta_x: { type: "number" },
164
+ delta_y: { type: "number", description: "Negative scrolls down (default -120)." },
165
+ repeat: { type: "number", description: "Repeat count 1..100 (default 1)." },
166
+ delay_ms: { type: "number", description: "Delay between repeats in ms (default 35)." },
167
+ },
168
+ },
169
+ },
170
+ {
171
+ name: "hands_drag",
172
+ description: "Drag mouse from (x1, y1) to (x2, y2).",
173
+ inputSchema: {
174
+ type: "object",
175
+ required: ["x1", "y1", "x2", "y2"],
176
+ properties: {
177
+ x1: { type: "number" },
178
+ y1: { type: "number" },
179
+ x2: { type: "number" },
180
+ y2: { type: "number" },
181
+ duration_ms: { type: "number" },
182
+ },
183
+ },
184
+ },
185
+ {
186
+ name: "hands_wait_for",
187
+ description: "Poll live AX tree or native OCR until a target element/text appears or timeout.",
188
+ inputSchema: {
189
+ type: "object",
190
+ properties: {
191
+ app: { type: "string" },
192
+ window_id: { type: "number" },
193
+ label: { type: "string" },
194
+ role: { type: "string" },
195
+ ocr_text: { type: "string" },
196
+ timeout_ms: { type: "number", description: "Timeout in ms (default 8000)." },
197
+ poll_ms: { type: "number", description: "Polling interval in ms (default 350)." },
198
+ },
199
+ },
200
+ },
201
+ {
202
+ name: "hands_batch",
203
+ description: "Execute a linear multi-step sequence in one turn with automatic glow HUD, Esc abort safety, native repeat on key/scroll, and optional final_observe=true.",
204
+ inputSchema: {
205
+ type: "object",
206
+ required: ["steps"],
207
+ properties: {
208
+ steps: {
209
+ type: "array",
210
+ description: "Actions: focus_app, observe, click, double_click, right_click, type_text, key/press_key/hotkey, scroll, drag, wait, wait_for.",
211
+ items: {
212
+ type: "object",
213
+ required: ["action"],
214
+ properties: {
215
+ action: { type: "string" },
216
+ },
217
+ additionalProperties: true,
218
+ },
219
+ },
220
+ restore_focus: { type: "boolean" },
221
+ restore_cursor: { type: "boolean" },
222
+ show_hud: { type: "boolean" },
223
+ hud_bounds: {
224
+ type: "object",
225
+ properties: {
226
+ x: { type: "number" },
227
+ y: { type: "number" },
228
+ width: { type: "number" },
229
+ height: { type: "number" },
230
+ },
231
+ },
232
+ final_observe: { type: "boolean" },
233
+ final_observe_mode: { type: "string", enum: ["auto", "ax", "ocr", "both"] },
234
+ final_observe_delay_ms: { type: "number" },
235
+ reset_emergency_stop: { type: "boolean" },
236
+ },
237
+ },
238
+ },
239
+ {
240
+ name: "hands_script",
241
+ description: "Codex-style persistent async JavaScript sandbox for fast multi-step desktop workflows with loops & conditionals (if/for/while). Exposes `hands` (windows, focus, observe, screenshot, click, doubleClick, rightClick, type, key, scroll, drag, wait, waitFor), persistent `state` object across calls, and `log(...)`. Enforces all safety policies, HUD glow, and Esc emergency stop.",
242
+ inputSchema: {
243
+ type: "object",
244
+ required: ["code"],
245
+ properties: {
246
+ code: {
247
+ type: "string",
248
+ description: "Async JavaScript body (supports await & return). Example: `await hands.focus('WPS Office'); await hands.key('pagedown', { repeat: 29 }); return await hands.observe('WPS Office');`",
249
+ },
250
+ reset: { type: "boolean", description: "Clear persistent `state` before running (default false)." },
251
+ timeout_ms: { type: "number", description: "Execution timeout in ms (default 30000, max 120000)." },
252
+ max_ops: { type: "number", description: "Max hands.* calls allowed in this run (default 80)." },
253
+ show_hud: { type: "boolean", description: "Show screenshot-invisible HUD glow (default true)." },
254
+ restore_focus: { type: "boolean" },
255
+ restore_cursor: { type: "boolean" },
256
+ reset_emergency_stop: { type: "boolean" },
257
+ },
258
+ },
259
+ },
260
+ ];
261
+ export class HandsMcpServer {
262
+ driver;
263
+ snapshots = new SnapshotStore();
264
+ safety;
265
+ telemetry;
266
+ engine;
267
+ scriptRunner;
268
+ constructor(driver, safety, telemetry) {
269
+ this.driver = driver;
270
+ this.safety = safety ?? new SafetyPolicyEngine(loadSafetyConfig());
271
+ this.telemetry = telemetry ?? new TelemetryStore();
272
+ this.engine = new HandsEngine(this.driver, this.snapshots, this.safety, this.telemetry);
273
+ this.scriptRunner = new HandsScriptRunner(this.driver, this.engine, this.safety, this.telemetry);
274
+ }
275
+ async handleRequest(req) {
276
+ switch (req.method) {
277
+ case "initialize":
278
+ return {
279
+ protocolVersion: MCP_PROTOCOL_VERSION,
280
+ capabilities: {
281
+ tools: {},
282
+ },
283
+ serverInfo: {
284
+ name: SERVER_NAME,
285
+ version: SERVER_VERSION,
286
+ },
287
+ };
288
+ case "notifications/initialized":
289
+ case "notifications/cancelled":
290
+ if (req.method === "notifications/cancelled") {
291
+ await this.driver.call("release_keys").catch(() => undefined);
292
+ }
293
+ return undefined;
294
+ case "ping":
295
+ return {};
296
+ case "tools/list":
297
+ return { tools: TOOL_DEFINITIONS };
298
+ case "tools/call":
299
+ return this.handleToolCall(req.params ?? {});
300
+ default: {
301
+ const err = new Error(`Method not found: ${req.method}`);
302
+ err.rpcCode = -32601;
303
+ throw err;
304
+ }
305
+ }
306
+ }
307
+ async handleToolCall(params) {
308
+ const name = String(params.name ?? "");
309
+ const args = (params.arguments ?? {});
310
+ try {
311
+ switch (name) {
312
+ case "hands_status": {
313
+ if (args.reset_emergency_stop) {
314
+ await this.driver.call("reset_stop");
315
+ this.telemetry.setEmergencyStop(false, "Reset via hands_status");
316
+ }
317
+ const h = await this.driver.call("health");
318
+ this.telemetry.updateDriverInfo(h);
319
+ const summary = [
320
+ `driver: ${h.driver} v${h.version} (${h.os}/${h.arch} ${h.os_version})`,
321
+ `permissions: accessibility=${h.permissions.accessibility} screen_recording=${h.permissions.screen_recording}`,
322
+ `emergency_stopped: ${h.emergency_stopped || this.telemetry.isEmergencyStopRequested()}`,
323
+ `capabilities: ${h.capabilities.join(", ")}`,
324
+ ].join("\n");
325
+ return this.textResult(summary);
326
+ }
327
+ case "hands_list_windows": {
328
+ const includeMinimized = typeof args.include_minimized === "boolean"
329
+ ? args.include_minimized
330
+ : true;
331
+ const res = await this.driver.call("list_windows", {
332
+ app: args.app,
333
+ include_minimized: includeMinimized,
334
+ });
335
+ if (args.json) {
336
+ return this.textResult(JSON.stringify(res));
337
+ }
338
+ return this.textResult(formatWindowsCompact(res));
339
+ }
340
+ case "hands_focus_app": {
341
+ const start = Date.now();
342
+ this.safety.assertAppAllowed(args.app);
343
+ const res = await this.driver.call("focus_app", {
344
+ app: args.app,
345
+ pid: args.pid,
346
+ window_id: args.window_id,
347
+ launch: args.launch ?? true,
348
+ });
349
+ this.telemetry.recordEvent({
350
+ tool: "hands_focus_app",
351
+ mode: "foreground",
352
+ app: res.app ?? args.app,
353
+ window_id: res.window_id,
354
+ summary: `Focused ${res.app ?? String(args.app ?? "window")}${res.unminimized ? " (un-minimized)" : ""}`,
355
+ duration_ms: Date.now() - start,
356
+ ok: true,
357
+ });
358
+ return this.textResult(JSON.stringify(res));
359
+ }
360
+ case "hands_observe": {
361
+ const res = await this.engine.observe({
362
+ app: args.app,
363
+ window_id: args.window_id,
364
+ mode: args.mode,
365
+ include_ocr: args.include_ocr,
366
+ min_ax_nodes: args.min_ax_nodes,
367
+ max_depth: args.max_depth,
368
+ max_nodes: args.max_nodes,
369
+ languages: args.languages,
370
+ });
371
+ return this.textResult(`strategy: ${res.strategy} (ax=${res.ax_count}, ocr=${res.ocr_count})\n${res.compact}`);
372
+ }
373
+ case "hands_ax_snapshot": {
374
+ const snap = await this.engine.takeSnapshot({
375
+ app: args.app,
376
+ window_id: args.window_id,
377
+ max_depth: args.max_depth,
378
+ max_nodes: args.max_nodes,
379
+ include_menubar: args.include_menubar,
380
+ });
381
+ return this.textResult(SnapshotStore.formatCompact(snap));
382
+ }
383
+ case "hands_ocr": {
384
+ this.safety.assertAppAllowed(args.app);
385
+ const ocr = await this.driver.call("ocr", {
386
+ app: args.app,
387
+ window_id: args.window_id,
388
+ languages: args.languages ?? ["zh-Hans", "zh-Hant", "en-US"],
389
+ });
390
+ const compact = ocr.lines
391
+ .map((l) => `${JSON.stringify(l.text)} @(${Math.round(l.center.x)},${Math.round(l.center.y)})`)
392
+ .join("\n");
393
+ return this.textResult(`ocr lines: ${ocr.lines.length}\n${compact}`);
394
+ }
395
+ case "hands_screenshot": {
396
+ const { shot, snapshot_id } = await this.engine.takeScreenshot({
397
+ app: args.app,
398
+ window_id: args.window_id,
399
+ max_width: args.max_width,
400
+ format: args.format,
401
+ annotate: args.annotate,
402
+ languages: args.languages,
403
+ });
404
+ return {
405
+ content: [
406
+ { type: "text", text: formatScreenshotMetaCompact(shot, snapshot_id) },
407
+ {
408
+ type: "image",
409
+ data: shot.data_base64,
410
+ mimeType: shot.mime_type,
411
+ },
412
+ ],
413
+ };
414
+ }
415
+ case "hands_click":
416
+ case "hands_double_click":
417
+ case "hands_right_click": {
418
+ const res = await this.engine.clickTarget({
419
+ ref: args.ref,
420
+ snapshot_id: args.snapshot_id,
421
+ app: args.app,
422
+ window_id: args.window_id,
423
+ label: args.label,
424
+ role: args.role,
425
+ ocr_text: args.ocr_text,
426
+ x: args.x,
427
+ y: args.y,
428
+ button: name === "hands_right_click"
429
+ ? "right"
430
+ : (args.button ?? "left"),
431
+ click_count: name === "hands_double_click"
432
+ ? 2
433
+ : (args.click_count ?? 1),
434
+ prefer_background: args.prefer_background,
435
+ allow_destructive: args.allow_destructive,
436
+ restore_cursor: args.restore_cursor,
437
+ });
438
+ return this.textResult(JSON.stringify(res));
439
+ }
440
+ case "hands_type_text": {
441
+ const res = await this.engine.typeText({
442
+ text: String(args.text ?? ""),
443
+ ref: args.ref,
444
+ snapshot_id: args.snapshot_id,
445
+ app: args.app,
446
+ window_id: args.window_id,
447
+ label: args.label,
448
+ role: args.role,
449
+ clear_first: args.clear_first,
450
+ method: args.method,
451
+ prefer_background: args.prefer_background,
452
+ });
453
+ return this.textResult(JSON.stringify(res));
454
+ }
455
+ case "hands_key":
456
+ case "hands_press_key":
457
+ case "hands_hotkey": {
458
+ const res = await this.engine.pressKeyOrChord({
459
+ key: args.key,
460
+ keys: args.keys,
461
+ modifiers: args.modifiers,
462
+ repeat: args.repeat,
463
+ delay_ms: args.delay_ms,
464
+ });
465
+ return this.textResult(JSON.stringify(res));
466
+ }
467
+ case "hands_scroll": {
468
+ const res = await this.driver.call("scroll", {
469
+ x: args.x,
470
+ y: args.y,
471
+ delta_x: args.delta_x ?? 0,
472
+ delta_y: args.delta_y ?? -120,
473
+ repeat: args.repeat ?? 1,
474
+ delay_ms: args.delay_ms ?? 35,
475
+ });
476
+ return this.textResult(JSON.stringify(res));
477
+ }
478
+ case "hands_drag": {
479
+ const res = await this.driver.call("drag", {
480
+ x1: args.x1,
481
+ y1: args.y1,
482
+ x2: args.x2,
483
+ y2: args.y2,
484
+ duration_ms: args.duration_ms ?? 250,
485
+ });
486
+ return this.textResult(JSON.stringify(res));
487
+ }
488
+ case "hands_wait_for": {
489
+ const res = await this.engine.waitFor({
490
+ app: args.app,
491
+ window_id: args.window_id,
492
+ label: args.label,
493
+ role: args.role,
494
+ ocr_text: args.ocr_text,
495
+ timeout_ms: args.timeout_ms,
496
+ poll_ms: args.poll_ms,
497
+ });
498
+ return this.textResult(JSON.stringify(res));
499
+ }
500
+ case "hands_batch": {
501
+ const res = await this.engine.runBatch({
502
+ steps: (args.steps ?? []),
503
+ restore_focus: args.restore_focus,
504
+ restore_cursor: args.restore_cursor,
505
+ show_hud: args.show_hud,
506
+ hud_bounds: args.hud_bounds,
507
+ reset_emergency_stop: args.reset_emergency_stop,
508
+ final_observe: args.final_observe,
509
+ final_observe_mode: args.final_observe_mode,
510
+ final_observe_delay_ms: args.final_observe_delay_ms,
511
+ });
512
+ return {
513
+ content: [{ type: "text", text: formatBatchCompact(res) }],
514
+ isError: !res.ok,
515
+ };
516
+ }
517
+ case "hands_script": {
518
+ const res = await this.scriptRunner.run({
519
+ code: String(args.code ?? ""),
520
+ reset: args.reset,
521
+ timeout_ms: args.timeout_ms,
522
+ max_ops: args.max_ops,
523
+ show_hud: args.show_hud,
524
+ restore_focus: args.restore_focus,
525
+ restore_cursor: args.restore_cursor,
526
+ reset_emergency_stop: args.reset_emergency_stop,
527
+ });
528
+ const content = [{ type: "text", text: formatScriptResultCompact(res) }];
529
+ if (res.screenshot) {
530
+ content.push({
531
+ type: "image",
532
+ data: res.screenshot.data_base64,
533
+ mimeType: res.screenshot.mime_type,
534
+ });
535
+ }
536
+ return { content, isError: !res.ok };
537
+ }
538
+ default:
539
+ return {
540
+ content: [{ type: "text", text: `Unknown tool: ${name}` }],
541
+ isError: true,
542
+ };
543
+ }
544
+ }
545
+ catch (err) {
546
+ const payload = err instanceof HandsError
547
+ ? err.toJSON()
548
+ : {
549
+ code: "internal_error",
550
+ message: err instanceof Error ? err.message : String(err),
551
+ };
552
+ if (payload.code === "policy_blocked" ||
553
+ payload.code === "secure_field_refused" ||
554
+ payload.code === "emergency_stop") {
555
+ this.telemetry.recordEvent({
556
+ tool: name,
557
+ mode: payload.code === "emergency_stop" ? "system" : "blocked",
558
+ app: typeof args.app === "string" ? args.app : undefined,
559
+ summary: `${payload.code}: ${payload.message.slice(0, 140)}`,
560
+ ok: false,
561
+ error_code: payload.code,
562
+ });
563
+ }
564
+ return {
565
+ content: [{ type: "text", text: JSON.stringify({ error: payload }) }],
566
+ isError: true,
567
+ };
568
+ }
569
+ }
570
+ textResult(text) {
571
+ return {
572
+ content: [{ type: "text", text }],
573
+ };
574
+ }
575
+ }
576
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GASX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AACtC,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAQjD;;;GAGG;AACH,MAAM,gBAAgB,GAAc;IAClC;QACE,IAAI,EAAE,cAAc;QACpB,WAAW,EACT,0HAA0H;QAC5H,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,oBAAoB,EAAE;oBACpB,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE,qEAAqE;iBACnF;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EACT,sHAAsH;QACxH,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,sCAAsC,EAAE;gBAC5E,iBAAi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AAE,OAAO,EAAE,CAAC,EAAE,CAAC;gBACrE,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,UAAU,CAAC,IAAY;QAC7B,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC;SAC3C,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import { type AxNode, type AxSnapshotResult, type SafetyConfig, type SafetyVerdict } from "../types.js";
2
+ export declare const DEFAULT_SAFETY_CONFIG: SafetyConfig;
3
+ export declare function loadSafetyConfig(configPath?: string): SafetyConfig;
4
+ export declare class SafetyPolicyEngine {
5
+ private readonly config;
6
+ constructor(config?: Partial<SafetyConfig>);
7
+ getConfig(): SafetyConfig;
8
+ checkApp(appName?: string): SafetyVerdict;
9
+ assertAppAllowed(appName?: string): void;
10
+ checkElement(node: AxNode, options?: {
11
+ allowDestructive?: boolean;
12
+ isWrite?: boolean;
13
+ }): SafetyVerdict;
14
+ assertElementAllowed(node: AxNode, options?: {
15
+ allowDestructive?: boolean;
16
+ isWrite?: boolean;
17
+ }): void;
18
+ checkTextTarget(text: string, options?: {
19
+ allowDestructive?: boolean;
20
+ }): SafetyVerdict;
21
+ assertTextTargetAllowed(text: string, options?: {
22
+ allowDestructive?: boolean;
23
+ }): void;
24
+ sanitizeSnapshot(snapshot: AxSnapshotResult): AxSnapshotResult;
25
+ private matchDestructiveKeyword;
26
+ }