@melra/computer-runtime 0.3.0-alpha.3

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,39 @@
1
+ import type { ComputerOperation } from "@melra/protocol";
2
+ export interface ComputerCapabilities {
3
+ platform: NodeJS.Platform;
4
+ adapter: "macos-native" | "linux-xdotool" | "windows-powershell" | "unavailable";
5
+ available: boolean;
6
+ screenshot: boolean;
7
+ pointer: boolean;
8
+ keyboard: boolean;
9
+ scroll: boolean;
10
+ coordinateSpaces: Array<"normalized" | "pixel">;
11
+ limitations: string[];
12
+ }
13
+ export interface ComputerAdapter {
14
+ capabilities(): Promise<ComputerCapabilities>;
15
+ execute(operation: ComputerOperation, artifactDirectory: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
16
+ }
17
+ export interface ComputerRuntimeOptions {
18
+ artifactDirectory: string;
19
+ adapter?: ComputerAdapter;
20
+ }
21
+ /**
22
+ * `SendKeys` reads `+^%~(){}[]` as modifiers and grouping rather than as
23
+ * literal characters, so a password containing `+` types a Shift chord and a
24
+ * `(` opens a group that never closes. Each one is wrapped in braces, which is
25
+ * how `SendKeys` spells "the literal character".
26
+ *
27
+ * Exported because it is the part of the Windows adapter worth testing on any
28
+ * platform: the escaping is pure, and getting it wrong silently corrupts typed
29
+ * text rather than failing.
30
+ */
31
+ export declare function escapeSendKeys(text: string): string;
32
+ export declare function createSystemComputerAdapter(): ComputerAdapter;
33
+ export declare class ComputerRuntime {
34
+ private readonly options;
35
+ private readonly adapter;
36
+ constructor(options: ComputerRuntimeOptions);
37
+ execute(operation: ComputerOperation, signal?: AbortSignal): Promise<Record<string, unknown>>;
38
+ }
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","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index.js ADDED
@@ -0,0 +1,610 @@
1
+ // Copyright 2026 XAGI Labs Private Limited
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { execFile } from "node:child_process";
4
+ import { createHash, randomUUID } from "node:crypto";
5
+ import { constants } from "node:fs";
6
+ import { access, mkdir, readFile } from "node:fs/promises";
7
+ import { basename, join } from "node:path";
8
+ import { promisify } from "node:util";
9
+ const execFileAsync = promisify(execFile);
10
+ const ALLOWED_KEYS = {
11
+ ENTER: 36,
12
+ TAB: 48,
13
+ SPACE: 49,
14
+ BACKSPACE: 51,
15
+ ESCAPE: 53,
16
+ LEFT: 123,
17
+ RIGHT: 124,
18
+ DOWN: 125,
19
+ UP: 126,
20
+ HOME: 115,
21
+ END: 119,
22
+ PAGEUP: 116,
23
+ PAGEDOWN: 121,
24
+ DELETE: 117,
25
+ };
26
+ async function executable(path) {
27
+ try {
28
+ await access(path, constants.X_OK);
29
+ return true;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
35
+ async function run(file, args, timeoutMs, signal, env) {
36
+ try {
37
+ const result = await execFileAsync(file, args, {
38
+ timeout: timeoutMs,
39
+ maxBuffer: 1_000_000,
40
+ windowsHide: true,
41
+ ...(signal === undefined ? {} : { signal }),
42
+ ...(env === undefined ? {} : { env: { ...process.env, ...env } }),
43
+ });
44
+ return {
45
+ stdout: result.stdout,
46
+ stderr: result.stderr,
47
+ };
48
+ }
49
+ catch (cause) {
50
+ /**
51
+ * Node builds this rejection's message from the whole command line, which
52
+ * for an adapter means the entire script: a Windows screenshot failure
53
+ * arrived as fifteen lines of echoed PowerShell with the actual reason
54
+ * nowhere in it, and a timeout arrived as the same fifteen lines with an
55
+ * empty stderr, indistinguishable from a script that failed instantly.
56
+ *
57
+ * Report the interpreter's own words instead, and name a timeout as a
58
+ * timeout — a caller can act on "the helper was killed after 10000ms" and
59
+ * can act on a permission error, but not on a copy of the script it did
60
+ * not write.
61
+ */
62
+ const error = cause;
63
+ const program = basename(file);
64
+ if (error.killed === true || error.code === "ETIMEDOUT") {
65
+ throw new Error(`computer_helper_timeout:${program}:${timeoutMs}ms`);
66
+ }
67
+ if (signal?.aborted === true)
68
+ throw new Error("task_cancelled");
69
+ // First line only: interpreters follow the reason with a stack trace naming
70
+ // the script we generated, which is noise to whoever reads this.
71
+ const reason = (error.stderr ?? "").trim().split("\n")[0]?.trim();
72
+ throw new Error(reason === undefined || reason === ""
73
+ ? `computer_helper_failed:${program}`
74
+ : `computer_helper_failed:${program}: ${reason}`);
75
+ }
76
+ }
77
+ function coordinateScript(operation) {
78
+ const x = operation.x ?? 0;
79
+ const y = operation.y ?? 0;
80
+ const normalized = operation.coordinateSpace === "normalized";
81
+ return `
82
+ ObjC.import("AppKit");
83
+ ObjC.import("CoreGraphics");
84
+ const frame = $.NSScreen.mainScreen.frame;
85
+ const x = ${normalized ? `frame.size.width * ${x}` : x};
86
+ const y = ${normalized ? `frame.size.height * ${y}` : y};
87
+ const point = $.CGPointMake(x, y);
88
+ const move = $.CGEventCreateMouseEvent(null, $.kCGEventMouseMoved, point, $.kCGMouseButtonLeft);
89
+ $.CGEventPost($.kCGHIDEventTap, move);
90
+ ${operation.action === "click" ? `
91
+ const down = $.CGEventCreateMouseEvent(null, $.kCGEventLeftMouseDown, point, $.kCGMouseButtonLeft);
92
+ const up = $.CGEventCreateMouseEvent(null, $.kCGEventLeftMouseUp, point, $.kCGMouseButtonLeft);
93
+ $.CGEventPost($.kCGHIDEventTap, down);
94
+ $.CGEventPost($.kCGHIDEventTap, up);` : ""}
95
+ `;
96
+ }
97
+ class MacOsAdapter {
98
+ async capabilities() {
99
+ const osascript = await executable("/usr/bin/osascript");
100
+ const screencapture = await executable("/usr/sbin/screencapture");
101
+ return {
102
+ platform: "darwin",
103
+ adapter: "macos-native",
104
+ available: osascript || screencapture,
105
+ screenshot: screencapture,
106
+ pointer: osascript,
107
+ keyboard: osascript,
108
+ scroll: osascript,
109
+ coordinateSpaces: ["normalized", "pixel"],
110
+ limitations: [
111
+ "macOS Screen Recording permission is required for screenshots",
112
+ "macOS Accessibility permission is required for input actions",
113
+ "normalized coordinates currently target the main display",
114
+ ],
115
+ };
116
+ }
117
+ async execute(operation, artifactDirectory, signal) {
118
+ switch (operation.action) {
119
+ case "capabilities":
120
+ return { ...(await this.capabilities()) };
121
+ case "screenshot": {
122
+ await mkdir(artifactDirectory, { recursive: true });
123
+ const path = join(artifactDirectory, `computer-${randomUUID()}.png`);
124
+ await run("/usr/sbin/screencapture", ["-x", path], operation.timeoutMs, signal);
125
+ const bytes = await readFile(path);
126
+ return {
127
+ success: true,
128
+ captured: true,
129
+ path,
130
+ size: bytes.byteLength,
131
+ sha256: createHash("sha256").update(bytes).digest("hex"),
132
+ };
133
+ }
134
+ case "click":
135
+ case "move":
136
+ await run("/usr/bin/osascript", ["-l", "JavaScript", "-e", coordinateScript(operation)], operation.timeoutMs, signal);
137
+ return {
138
+ success: true,
139
+ action: operation.action,
140
+ coordinateSpace: operation.coordinateSpace,
141
+ x: operation.x,
142
+ y: operation.y,
143
+ };
144
+ case "type": {
145
+ if (operation.text === undefined) {
146
+ throw new Error("computer_type_requires_text");
147
+ }
148
+ await run("/usr/bin/osascript", [
149
+ "-e",
150
+ "on run argv",
151
+ "-e",
152
+ "tell application \"System Events\" to keystroke (item 1 of argv)",
153
+ "-e",
154
+ "end run",
155
+ "--",
156
+ operation.text,
157
+ ], operation.timeoutMs, signal);
158
+ return { success: true, action: "type", characters: operation.text.length };
159
+ }
160
+ case "key": {
161
+ const key = operation.key?.toLocaleUpperCase();
162
+ const keyCode = key === undefined ? undefined : ALLOWED_KEYS[key];
163
+ if (keyCode === undefined)
164
+ throw new Error("computer_key_not_allowed");
165
+ await run("/usr/bin/osascript", [
166
+ "-e",
167
+ `tell application "System Events" to key code ${keyCode}`,
168
+ ], operation.timeoutMs, signal);
169
+ return { success: true, action: "key", key };
170
+ }
171
+ case "scroll": {
172
+ const deltaY = Math.max(-2_000, Math.min(2_000, operation.deltaY ?? 0));
173
+ const script = `
174
+ ObjC.import("CoreGraphics");
175
+ const event = $.CGEventCreateScrollWheelEvent(null, $.kCGScrollEventUnitPixel, 1, ${Math.round(deltaY)});
176
+ $.CGEventPost($.kCGHIDEventTap, event);
177
+ `;
178
+ await run("/usr/bin/osascript", ["-l", "JavaScript", "-e", script], operation.timeoutMs, signal);
179
+ return { success: true, action: "scroll", deltaY };
180
+ }
181
+ }
182
+ }
183
+ }
184
+ class LinuxXdotoolAdapter {
185
+ async command(name) {
186
+ for (const prefix of ["/usr/bin", "/bin", "/usr/local/bin"]) {
187
+ const path = join(prefix, name);
188
+ if (await executable(path))
189
+ return path;
190
+ }
191
+ return undefined;
192
+ }
193
+ async capabilities() {
194
+ const xdotool = await this.command("xdotool");
195
+ const screenshot = (await this.command("gnome-screenshot")) ??
196
+ (await this.command("scrot"));
197
+ return {
198
+ platform: "linux",
199
+ adapter: "linux-xdotool",
200
+ available: xdotool !== undefined || screenshot !== undefined,
201
+ screenshot: screenshot !== undefined,
202
+ pointer: xdotool !== undefined,
203
+ keyboard: xdotool !== undefined,
204
+ scroll: xdotool !== undefined,
205
+ coordinateSpaces: ["normalized", "pixel"],
206
+ limitations: [
207
+ "input actions require xdotool and an X11 session",
208
+ "Wayland compositors may deny synthetic input",
209
+ "normalized coordinates target the current display size reported by xdotool",
210
+ ],
211
+ };
212
+ }
213
+ async xdotool(args, operation, signal) {
214
+ const executablePath = await this.command("xdotool");
215
+ if (executablePath === undefined)
216
+ throw new Error("computer_input_unavailable");
217
+ await run(executablePath, args, operation.timeoutMs, signal);
218
+ }
219
+ async coordinates(operation, signal) {
220
+ if (operation.x === undefined || operation.y === undefined) {
221
+ throw new Error(`computer_${operation.action}_requires_coordinates`);
222
+ }
223
+ if (operation.coordinateSpace === "pixel") {
224
+ return { x: Math.round(operation.x), y: Math.round(operation.y) };
225
+ }
226
+ const executablePath = await this.command("xdotool");
227
+ if (executablePath === undefined)
228
+ throw new Error("computer_input_unavailable");
229
+ const { stdout } = await run(executablePath, ["getdisplaygeometry"], operation.timeoutMs, signal);
230
+ const [width, height] = stdout.trim().split(/\s+/).map(Number);
231
+ if (!Number.isFinite(width) || !Number.isFinite(height)) {
232
+ throw new Error("computer_display_geometry_unavailable");
233
+ }
234
+ return {
235
+ x: Math.round(width * operation.x),
236
+ y: Math.round(height * operation.y),
237
+ };
238
+ }
239
+ async execute(operation, artifactDirectory, signal) {
240
+ switch (operation.action) {
241
+ case "capabilities":
242
+ return { ...(await this.capabilities()) };
243
+ case "screenshot": {
244
+ await mkdir(artifactDirectory, { recursive: true });
245
+ const path = join(artifactDirectory, `computer-${randomUUID()}.png`);
246
+ const gnome = await this.command("gnome-screenshot");
247
+ const scrot = await this.command("scrot");
248
+ if (gnome !== undefined) {
249
+ await run(gnome, ["-f", path], operation.timeoutMs, signal);
250
+ }
251
+ else if (scrot !== undefined) {
252
+ await run(scrot, [path], operation.timeoutMs, signal);
253
+ }
254
+ else {
255
+ throw new Error("computer_screenshot_unavailable");
256
+ }
257
+ const bytes = await readFile(path);
258
+ return {
259
+ success: true,
260
+ captured: true,
261
+ path,
262
+ size: bytes.byteLength,
263
+ sha256: createHash("sha256").update(bytes).digest("hex"),
264
+ };
265
+ }
266
+ case "click":
267
+ case "move": {
268
+ const point = await this.coordinates(operation, signal);
269
+ const args = ["mousemove", String(point.x), String(point.y)];
270
+ if (operation.action === "click")
271
+ args.push("click", "1");
272
+ await this.xdotool(args, operation, signal);
273
+ return { success: true, action: operation.action, ...point };
274
+ }
275
+ case "type":
276
+ if (operation.text === undefined)
277
+ throw new Error("computer_type_requires_text");
278
+ await this.xdotool(["type", "--", operation.text], operation, signal);
279
+ return { success: true, action: "type", characters: operation.text.length };
280
+ case "key": {
281
+ const key = operation.key?.toLocaleUpperCase();
282
+ const mapping = {
283
+ ENTER: "Return",
284
+ TAB: "Tab",
285
+ SPACE: "space",
286
+ BACKSPACE: "BackSpace",
287
+ ESCAPE: "Escape",
288
+ LEFT: "Left",
289
+ RIGHT: "Right",
290
+ DOWN: "Down",
291
+ UP: "Up",
292
+ HOME: "Home",
293
+ END: "End",
294
+ PAGEUP: "Page_Up",
295
+ PAGEDOWN: "Page_Down",
296
+ DELETE: "Delete",
297
+ };
298
+ if (key === undefined || mapping[key] === undefined) {
299
+ throw new Error("computer_key_not_allowed");
300
+ }
301
+ await this.xdotool(["key", mapping[key]], operation, signal);
302
+ return { success: true, action: "key", key };
303
+ }
304
+ case "scroll": {
305
+ const clicks = Math.max(-20, Math.min(20, Math.round((operation.deltaY ?? 0) / 100)));
306
+ const button = clicks < 0 ? "4" : "5";
307
+ for (let index = 0; index < Math.abs(clicks); index += 1) {
308
+ await this.xdotool(["click", button], operation, signal);
309
+ }
310
+ return { success: true, action: "scroll", deltaY: operation.deltaY ?? 0 };
311
+ }
312
+ }
313
+ }
314
+ }
315
+ /**
316
+ * `SendKeys` reads `+^%~(){}[]` as modifiers and grouping rather than as
317
+ * literal characters, so a password containing `+` types a Shift chord and a
318
+ * `(` opens a group that never closes. Each one is wrapped in braces, which is
319
+ * how `SendKeys` spells "the literal character".
320
+ *
321
+ * Exported because it is the part of the Windows adapter worth testing on any
322
+ * platform: the escaping is pure, and getting it wrong silently corrupts typed
323
+ * text rather than failing.
324
+ */
325
+ export function escapeSendKeys(text) {
326
+ return text.replace(/[+^%~(){}[\]]/g, (character) => `{${character}}`);
327
+ }
328
+ /** `SendKeys` names for the fixed key allowlist. */
329
+ const WINDOWS_KEYS = {
330
+ ENTER: "{ENTER}",
331
+ TAB: "{TAB}",
332
+ SPACE: " ",
333
+ BACKSPACE: "{BACKSPACE}",
334
+ ESCAPE: "{ESC}",
335
+ LEFT: "{LEFT}",
336
+ RIGHT: "{RIGHT}",
337
+ DOWN: "{DOWN}",
338
+ UP: "{UP}",
339
+ HOME: "{HOME}",
340
+ END: "{END}",
341
+ PAGEUP: "{PGUP}",
342
+ PAGEDOWN: "{PGDN}",
343
+ DELETE: "{DELETE}",
344
+ };
345
+ /**
346
+ * Pointer and wheel input, which .NET does not expose — `SetCursorPos` and
347
+ * `mouse_event` have to be reached through P/Invoke.
348
+ *
349
+ * Reads its inputs from the environment rather than being interpolated with
350
+ * them, so nothing a caller supplies is ever parsed as PowerShell.
351
+ */
352
+ const WINDOWS_POINTER_SCRIPT = `
353
+ $ErrorActionPreference = 'Stop'
354
+ Add-Type -AssemblyName System.Windows.Forms
355
+ Add-Type -TypeDefinition @'
356
+ using System;
357
+ using System.Runtime.InteropServices;
358
+ public static class MelraInput {
359
+ [DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y);
360
+ [DllImport("user32.dll")] public static extern void mouse_event(uint flags, uint dx, uint dy, uint data, IntPtr extra);
361
+ }
362
+ '@
363
+ $bounds = [System.Windows.Forms.SystemInformation]::VirtualScreen
364
+ if ($env:MELRA_NORMALIZED -eq '1') {
365
+ $x = [int][Math]::Round($bounds.X + $bounds.Width * [double]$env:MELRA_X)
366
+ $y = [int][Math]::Round($bounds.Y + $bounds.Height * [double]$env:MELRA_Y)
367
+ } else {
368
+ $x = [int][Math]::Round([double]$env:MELRA_X)
369
+ $y = [int][Math]::Round([double]$env:MELRA_Y)
370
+ }
371
+ if ($env:MELRA_MOVE -eq '1') { [void][MelraInput]::SetCursorPos($x, $y) }
372
+ if ($env:MELRA_CLICK -eq '1') {
373
+ [MelraInput]::mouse_event(0x0002, 0, 0, 0, [IntPtr]::Zero)
374
+ [MelraInput]::mouse_event(0x0004, 0, 0, 0, [IntPtr]::Zero)
375
+ }
376
+ if ($env:MELRA_WHEEL -ne $null -and $env:MELRA_WHEEL -ne '') {
377
+ [MelraInput]::mouse_event(0x0800, 0, 0, [uint32][int]$env:MELRA_WHEEL, [IntPtr]::Zero)
378
+ }
379
+ Write-Output "$x $y"
380
+ `;
381
+ const WINDOWS_SCREENSHOT_SCRIPT = `
382
+ $ErrorActionPreference = 'Stop'
383
+ Add-Type -AssemblyName System.Drawing
384
+ Add-Type -AssemblyName System.Windows.Forms
385
+ $bounds = [System.Windows.Forms.SystemInformation]::VirtualScreen
386
+ $bitmap = New-Object System.Drawing.Bitmap $bounds.Width, $bounds.Height
387
+ $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
388
+ try {
389
+ $graphics.CopyFromScreen($bounds.X, $bounds.Y, 0, 0, $bitmap.Size)
390
+ $bitmap.Save($env:MELRA_PATH, [System.Drawing.Imaging.ImageFormat]::Png)
391
+ } finally {
392
+ $graphics.Dispose()
393
+ $bitmap.Dispose()
394
+ }
395
+ `;
396
+ const WINDOWS_TYPE_SCRIPT = `
397
+ $ErrorActionPreference = 'Stop'
398
+ Add-Type -AssemblyName System.Windows.Forms
399
+ [System.Windows.Forms.SendKeys]::SendWait($env:MELRA_KEYS)
400
+ `;
401
+ /**
402
+ * Windows computer use through Windows PowerShell and .NET.
403
+ *
404
+ * `capabilities` used to report `unavailable` here and every input action threw
405
+ * a bare `computer_use_unavailable`, which is the whole of Windows computer use
406
+ * being missing rather than degraded.
407
+ *
408
+ * PowerShell is in the terminal runtime's unconditional deny list, and stays
409
+ * there: this is the trusted adapter invoking a fixed script it owns, the same
410
+ * arrangement under which the macOS adapter uses `osascript`. Nothing a caller
411
+ * supplies reaches the script as source — coordinates, wheel deltas, and text
412
+ * arrive in the environment.
413
+ */
414
+ class WindowsAdapter {
415
+ powershell = join(process.env["SystemRoot"] ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
416
+ async capabilities() {
417
+ // Windows PowerShell 5.1 ships with the OS, so this is present unless the
418
+ // install has been trimmed. `pwsh` is deliberately not consulted: it is an
419
+ // optional install and its absence is not the question being asked.
420
+ const available = await executable(this.powershell);
421
+ return {
422
+ platform: "win32",
423
+ adapter: "windows-powershell",
424
+ available,
425
+ screenshot: available,
426
+ pointer: available,
427
+ keyboard: available,
428
+ scroll: available,
429
+ coordinateSpaces: ["normalized", "pixel"],
430
+ limitations: [
431
+ ...(available
432
+ ? []
433
+ : ["Windows PowerShell was not found at the expected system path"]),
434
+ "input is delivered to whichever window holds focus; focus is not verified",
435
+ "SendKeys cannot type into a window running elevated unless this process is elevated too",
436
+ "normalized coordinates span the whole virtual desktop, not one display",
437
+ "per-monitor DPI scaling is not compensated for",
438
+ "every action pays PowerShell startup, and pointer/scroll additionally compile a P/Invoke shim, so raise timeoutMs above its 10s default on a slow or loaded machine",
439
+ ],
440
+ };
441
+ }
442
+ async powershellScript(script, operation, env, signal) {
443
+ if (!(await executable(this.powershell))) {
444
+ throw new Error("computer_input_unavailable");
445
+ }
446
+ const { stdout } = await run(this.powershell, [
447
+ "-NoProfile",
448
+ "-NonInteractive",
449
+ "-ExecutionPolicy",
450
+ "Bypass",
451
+ "-Command",
452
+ script,
453
+ ], operation.timeoutMs, signal, env);
454
+ return stdout;
455
+ }
456
+ async execute(operation, artifactDirectory, signal) {
457
+ switch (operation.action) {
458
+ case "capabilities":
459
+ return { ...(await this.capabilities()) };
460
+ case "screenshot": {
461
+ await mkdir(artifactDirectory, { recursive: true });
462
+ const path = join(artifactDirectory, `computer-${randomUUID()}.png`);
463
+ await this.powershellScript(WINDOWS_SCREENSHOT_SCRIPT, operation, { MELRA_PATH: path }, signal);
464
+ const bytes = await readFile(path);
465
+ return {
466
+ success: true,
467
+ captured: true,
468
+ path,
469
+ size: bytes.byteLength,
470
+ sha256: createHash("sha256").update(bytes).digest("hex"),
471
+ };
472
+ }
473
+ case "click":
474
+ case "move": {
475
+ if (operation.x === undefined || operation.y === undefined) {
476
+ throw new Error(`computer_${operation.action}_requires_coordinates`);
477
+ }
478
+ const stdout = await this.powershellScript(WINDOWS_POINTER_SCRIPT, operation, {
479
+ MELRA_X: String(operation.x),
480
+ MELRA_Y: String(operation.y),
481
+ MELRA_NORMALIZED: operation.coordinateSpace === "normalized" ? "1" : "0",
482
+ MELRA_MOVE: "1",
483
+ MELRA_CLICK: operation.action === "click" ? "1" : "0",
484
+ MELRA_WHEEL: "",
485
+ }, signal);
486
+ // The script resolves normalized coordinates against the virtual
487
+ // desktop, so the pixel point it actually used is reported back rather
488
+ // than recomputed here from a display size this process never saw.
489
+ const [x, y] = stdout.trim().split(/\s+/).map(Number);
490
+ if (!Number.isFinite(x) || !Number.isFinite(y)) {
491
+ throw new Error("computer_display_geometry_unavailable");
492
+ }
493
+ return {
494
+ success: true,
495
+ action: operation.action,
496
+ coordinateSpace: operation.coordinateSpace,
497
+ x,
498
+ y,
499
+ };
500
+ }
501
+ case "type": {
502
+ if (operation.text === undefined) {
503
+ throw new Error("computer_type_requires_text");
504
+ }
505
+ await this.powershellScript(WINDOWS_TYPE_SCRIPT, operation, { MELRA_KEYS: escapeSendKeys(operation.text) }, signal);
506
+ return { success: true, action: "type", characters: operation.text.length };
507
+ }
508
+ case "key": {
509
+ const key = operation.key?.toLocaleUpperCase();
510
+ const sequence = key === undefined ? undefined : WINDOWS_KEYS[key];
511
+ if (sequence === undefined)
512
+ throw new Error("computer_key_not_allowed");
513
+ await this.powershellScript(WINDOWS_TYPE_SCRIPT, operation, { MELRA_KEYS: sequence }, signal);
514
+ return { success: true, action: "key", key };
515
+ }
516
+ case "scroll": {
517
+ const deltaY = operation.deltaY ?? 0;
518
+ // One wheel notch is 120 units, and the sign is inverted against the
519
+ // web convention: a positive `deltaY` scrolls the page down, which is a
520
+ // negative wheel rotation.
521
+ const notches = Math.max(-20, Math.min(20, Math.round(deltaY / 100)));
522
+ // The wheel goes to the window under the cursor, so scroll positions it
523
+ // first when told where — and leaves it alone when not, rather than
524
+ // parking it at the origin and scrolling whatever happens to be there.
525
+ const positioned = operation.x !== undefined && operation.y !== undefined;
526
+ await this.powershellScript(WINDOWS_POINTER_SCRIPT, operation, {
527
+ MELRA_X: String(operation.x ?? 0),
528
+ MELRA_Y: String(operation.y ?? 0),
529
+ MELRA_NORMALIZED: operation.coordinateSpace === "normalized" ? "1" : "0",
530
+ MELRA_MOVE: positioned ? "1" : "0",
531
+ MELRA_CLICK: "0",
532
+ MELRA_WHEEL: String(-notches * 120),
533
+ }, signal);
534
+ return { success: true, action: "scroll", deltaY };
535
+ }
536
+ }
537
+ }
538
+ }
539
+ class UnavailableAdapter {
540
+ async capabilities() {
541
+ return {
542
+ platform: process.platform,
543
+ adapter: "unavailable",
544
+ available: false,
545
+ screenshot: false,
546
+ pointer: false,
547
+ keyboard: false,
548
+ scroll: false,
549
+ coordinateSpaces: ["normalized", "pixel"],
550
+ limitations: ["no supported local computer-use adapter was detected"],
551
+ };
552
+ }
553
+ async execute(operation) {
554
+ if (operation.action === "capabilities") {
555
+ return { ...(await this.capabilities()) };
556
+ }
557
+ throw new Error("computer_use_unavailable");
558
+ }
559
+ }
560
+ export function createSystemComputerAdapter() {
561
+ if (process.platform === "darwin")
562
+ return new MacOsAdapter();
563
+ if (process.platform === "linux")
564
+ return new LinuxXdotoolAdapter();
565
+ if (process.platform === "win32")
566
+ return new WindowsAdapter();
567
+ return new UnavailableAdapter();
568
+ }
569
+ export class ComputerRuntime {
570
+ options;
571
+ adapter;
572
+ constructor(options) {
573
+ this.options = options;
574
+ this.adapter = options.adapter ?? createSystemComputerAdapter();
575
+ }
576
+ async execute(operation, signal) {
577
+ if (signal?.aborted === true)
578
+ throw new Error("task_cancelled");
579
+ const capabilities = await this.adapter.capabilities();
580
+ if (operation.action === "capabilities") {
581
+ return { ...capabilities };
582
+ }
583
+ if (!capabilities.available) {
584
+ throw new Error("computer_use_unavailable");
585
+ }
586
+ const requiredCapability = operation.action === "screenshot"
587
+ ? "screenshot"
588
+ : operation.action === "click" || operation.action === "move"
589
+ ? "pointer"
590
+ : operation.action === "type" || operation.action === "key"
591
+ ? "keyboard"
592
+ : operation.action === "scroll"
593
+ ? "scroll"
594
+ : undefined;
595
+ if (requiredCapability !== undefined &&
596
+ !capabilities[requiredCapability]) {
597
+ throw new Error(`computer_${requiredCapability}_unavailable`);
598
+ }
599
+ if (["click", "move"].includes(operation.action) &&
600
+ (operation.x === undefined || operation.y === undefined)) {
601
+ throw new Error(`computer_${operation.action}_requires_coordinates`);
602
+ }
603
+ if (operation.coordinateSpace === "normalized" &&
604
+ ((operation.x ?? 0) > 1 || (operation.y ?? 0) > 1)) {
605
+ throw new Error("computer_normalized_coordinates_out_of_range");
606
+ }
607
+ return await this.adapter.execute(operation, this.options.artifactDirectory, signal);
608
+ }
609
+ }
610
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AA4B1C,MAAM,YAAY,GAA2B;IAC3C,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,EAAE;IACP,KAAK,EAAE,EAAE;IACT,SAAS,EAAE,EAAE;IACb,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,GAAG;IACT,EAAE,EAAE,GAAG;IACP,IAAI,EAAE,GAAG;IACT,GAAG,EAAE,GAAG;IACR,MAAM,EAAE,GAAG;IACX,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,GAAG;CACZ,CAAC;AAEF,KAAK,UAAU,UAAU,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAA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Y,CAAC,kBAAkB,CAAC,EACjC,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,YAAY,kBAAkB,cAAc,CAAC,CAAC;QAChE,CAAC;QACD,IACE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC;YAC5C,CAAC,SAAS,CAAC,CAAC,KAAK,SAAS,IAAI,SAAS,CAAC,CAAC,KAAK,SAAS,CAAC,EACxD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,YAAY,SAAS,CAAC,MAAM,uBAAuB,CAAC,CAAC;QACvE,CAAC;QACD,IACE,SAAS,CAAC,eAAe,KAAK,YAAY;YAC1C,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAClD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAC/B,SAAS,EACT,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAC9B,MAAM,CACP,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,85 @@
1
+ // Copyright 2026 XAGI Labs Private Limited
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { describe, expect, it } from "vitest";
4
+ import { ComputerOperationSchema } from "@melra/protocol";
5
+ import { ComputerRuntime, } from "./index.js";
6
+ class TestAdapter {
7
+ overrides;
8
+ calls = [];
9
+ constructor(overrides = {}) {
10
+ this.overrides = overrides;
11
+ }
12
+ async capabilities() {
13
+ return {
14
+ platform: "darwin",
15
+ adapter: "macos-native",
16
+ available: true,
17
+ screenshot: true,
18
+ pointer: true,
19
+ keyboard: true,
20
+ scroll: true,
21
+ coordinateSpaces: ["normalized", "pixel"],
22
+ limitations: [],
23
+ ...this.overrides,
24
+ };
25
+ }
26
+ async execute(operation) {
27
+ this.calls.push(operation.action);
28
+ return { success: true, action: operation.action };
29
+ }
30
+ }
31
+ describe("ComputerRuntime", () => {
32
+ it("reports adapter capabilities without a mutation", async () => {
33
+ const adapter = new TestAdapter();
34
+ const runtime = new ComputerRuntime({
35
+ artifactDirectory: "/tmp",
36
+ adapter,
37
+ });
38
+ const result = await runtime.execute(ComputerOperationSchema.parse({
39
+ kind: "computer",
40
+ action: "capabilities",
41
+ }));
42
+ expect(result.available).toBe(true);
43
+ expect(adapter.calls).toEqual([]);
44
+ });
45
+ it("requires explicit bounded coordinates for pointer actions", async () => {
46
+ const runtime = new ComputerRuntime({
47
+ artifactDirectory: "/tmp",
48
+ adapter: new TestAdapter(),
49
+ });
50
+ await expect(runtime.execute(ComputerOperationSchema.parse({
51
+ kind: "computer",
52
+ action: "click",
53
+ }))).rejects.toThrow("computer_click_requires_coordinates");
54
+ await expect(runtime.execute(ComputerOperationSchema.parse({
55
+ kind: "computer",
56
+ action: "click",
57
+ coordinateSpace: "normalized",
58
+ x: 2,
59
+ y: 0.5,
60
+ }))).rejects.toThrow("computer_normalized_coordinates_out_of_range");
61
+ });
62
+ it.each([
63
+ ["screenshot", "screenshot", "computer_screenshot_unavailable"],
64
+ ["click", "pointer", "computer_pointer_unavailable"],
65
+ ["type", "keyboard", "computer_keyboard_unavailable"],
66
+ ["scroll", "scroll", "computer_scroll_unavailable"],
67
+ ])("rejects %s when its adapter capability is unavailable", async (action, capability, error) => {
68
+ const adapter = new TestAdapter({ [capability]: false });
69
+ const runtime = new ComputerRuntime({
70
+ artifactDirectory: "/tmp",
71
+ adapter,
72
+ });
73
+ const operation = {
74
+ kind: "computer",
75
+ action,
76
+ ...(action === "click"
77
+ ? { coordinateSpace: "pixel", x: 10, y: 10 }
78
+ : {}),
79
+ ...(action === "type" ? { text: "safe" } : {}),
80
+ };
81
+ await expect(runtime.execute(ComputerOperationSchema.parse(operation))).rejects.toThrow(error);
82
+ expect(adapter.calls).toEqual([]);
83
+ });
84
+ });
85
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EACL,eAAe,GAGhB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW;IAII;IAHV,KAAK,GAAa,EAAE,CAAC;IAE9B,YACmB,YAA2C,EAAE;QAA7C,cAAS,GAAT,SAAS,CAAoC;IAC7D,CAAC;IAEJ,KAAK,CAAC,YAAY;QAChB,OAAO;YACL,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,cAAc;YACvB,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,IAAI;YAChB,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,IAAI;YACZ,gBAAgB,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC;YACzC,WAAW,EAAE,EAAE;YACf,GAAG,IAAI,CAAC,SAAS;SAClB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,SAA6B;QACzC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;IACrD,CAAC;CACF;AAED,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAC/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,SAAS,EAAE,8BAA8B,CAAC;QACpD,CAAC,MAAM,EAAE,UAAU,EAAE,+BAA+B,CAAC;QACrD,CAAC,QAAQ,EAAE,QAAQ,EAAE,6BAA6B,CAAC;KAC3C,CAAC,CACT,uDAAuD,EACvD,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;QAClC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACzD,MAAM,OAAO,GAAG,IAAI,eAAe,CAAC;YAClC,iBAAiB,EAAE,MAAM;YACzB,OAAO;SACR,CAAC,CAAC;QACH,MAAM,SAAS,GAAG;YAChB,IAAI,EAAE,UAAU;YAChB,MAAM;YACN,GAAG,CAAC,MAAM,KAAK,OAAO;gBACpB,CAAC,CAAC,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;gBAC5C,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/C,CAAC;QAEF,MAAM,MAAM,CACV,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAC1D,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACzB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=windows.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windows.test.d.ts","sourceRoot":"","sources":["../src/windows.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,129 @@
1
+ // Copyright 2026 XAGI Labs Private Limited
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { mkdtemp, rm, stat } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { ComputerOperationSchema } from "@melra/protocol";
7
+ import { afterEach, describe, expect, it } from "vitest";
8
+ import { ComputerRuntime, createSystemComputerAdapter, escapeSendKeys } from "./index.js";
9
+ /**
10
+ * Windows computer use was entirely absent: the factory had no `win32` branch,
11
+ * so `capabilities` reported `unavailable` and every input action threw a bare
12
+ * `computer_use_unavailable`. CI ran on `windows-latest` and stayed green
13
+ * because nothing exercised Windows behaviour — which is why the adapter tests
14
+ * below run for real on Windows rather than against a stub.
15
+ */
16
+ const onWindows = process.platform === "win32";
17
+ const roots = [];
18
+ /**
19
+ * Two clocks, and both have to clear the same wait: vitest's own default killed
20
+ * these tests at 5s, and once that was raised the operation's `timeoutMs` cap
21
+ * killed them at 30s — which is why the schema now allows 120s for a computer
22
+ * action like every other operation kind.
23
+ *
24
+ * The wait is real, not slack. A computer action spawns a whole interpreter:
25
+ * `powershell.exe` cold-starts in seconds, the pointer script's
26
+ * `Add-Type -TypeDefinition` runs the C# compiler to build the P/Invoke shim,
27
+ * and the first such spawn after boot pays for a cold disk on top. That cost is
28
+ * per-process, so it is paid on every action, and a caller who leaves
29
+ * `timeoutMs` at its 10s default is closer to the edge on a cold or loaded
30
+ * machine than the number suggests.
31
+ */
32
+ const POWERSHELL_TEST_TIMEOUT_MS = 120_000;
33
+ afterEach(async () => {
34
+ await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
35
+ });
36
+ async function workspace() {
37
+ const root = await mkdtemp(join(tmpdir(), "melra-computer-"));
38
+ roots.push(root);
39
+ return root;
40
+ }
41
+ describe("escapeSendKeys", () => {
42
+ it("neutralizes the characters SendKeys reads as modifiers", () => {
43
+ // Unescaped, `+` is Shift, `^` is Ctrl, `%` is Alt, `~` is Enter, and the
44
+ // brackets group — so this password would have typed a chord and pressed
45
+ // Enter instead of entering any of these characters.
46
+ expect(escapeSendKeys("a+b^c%d~e")).toBe("a{+}b{^}c{%}d{~}e");
47
+ expect(escapeSendKeys("({x})[y]")).toBe("{(}{{}x{}}{)}{[}y{]}");
48
+ });
49
+ it("leaves ordinary text alone", () => {
50
+ expect(escapeSendKeys("Hello, world 123")).toBe("Hello, world 123");
51
+ });
52
+ });
53
+ describe.runIf(onWindows)("Windows computer adapter", () => {
54
+ it("reports itself as available rather than unavailable", async () => {
55
+ const runtime = new ComputerRuntime({
56
+ artifactDirectory: await workspace(),
57
+ adapter: createSystemComputerAdapter(),
58
+ });
59
+ const observed = await runtime.execute(ComputerOperationSchema.parse({ kind: "computer", action: "capabilities" }));
60
+ expect(observed.platform).toBe("win32");
61
+ expect(observed.adapter).toBe("windows-powershell");
62
+ expect(observed.available).toBe(true);
63
+ expect(observed.screenshot).toBe(true);
64
+ expect(observed.pointer).toBe(true);
65
+ // The honest ceiling of SendKeys-based input, stated rather than implied.
66
+ expect(observed.limitations.join(" ")).toContain("focus");
67
+ });
68
+ it("captures a real screenshot to the artifact directory", async () => {
69
+ const artifactDirectory = join(await workspace(), "artifacts");
70
+ const runtime = new ComputerRuntime({
71
+ artifactDirectory,
72
+ adapter: createSystemComputerAdapter(),
73
+ });
74
+ const observed = await runtime.execute(ComputerOperationSchema.parse({
75
+ kind: "computer",
76
+ action: "screenshot",
77
+ timeoutMs: 90_000,
78
+ }));
79
+ expect(observed.captured).toBe(true);
80
+ expect(String(observed.path).startsWith(artifactDirectory)).toBe(true);
81
+ const written = await stat(String(observed.path));
82
+ expect(written.size).toBeGreaterThan(0);
83
+ expect(observed.size).toBe(written.size);
84
+ expect(String(observed.sha256)).toHaveLength(64);
85
+ }, POWERSHELL_TEST_TIMEOUT_MS);
86
+ it("resolves a normalized coordinate against the virtual desktop", async () => {
87
+ const runtime = new ComputerRuntime({
88
+ artifactDirectory: await workspace(),
89
+ adapter: createSystemComputerAdapter(),
90
+ });
91
+ // A pointer move is the P/Invoke path — the part most likely to be wrong —
92
+ // and moving the cursor on a headless runner has no side effect worth
93
+ // avoiding. Clicking would, so this does not click.
94
+ const observed = await runtime.execute(ComputerOperationSchema.parse({
95
+ kind: "computer",
96
+ action: "move",
97
+ x: 0.5,
98
+ y: 0.5,
99
+ coordinateSpace: "normalized",
100
+ timeoutMs: 90_000,
101
+ }));
102
+ expect(observed.success).toBe(true);
103
+ // The pixel point comes back from the script rather than being recomputed
104
+ // here, so a normalized centre must land somewhere other than the origin.
105
+ expect(observed.x).toBeGreaterThan(0);
106
+ expect(observed.y).toBeGreaterThan(0);
107
+ }, POWERSHELL_TEST_TIMEOUT_MS);
108
+ it("names a timeout as a timeout instead of echoing the script", async () => {
109
+ const runtime = new ComputerRuntime({
110
+ artifactDirectory: await workspace(),
111
+ adapter: createSystemComputerAdapter(),
112
+ });
113
+ /**
114
+ * This is how the screenshot failure first presented: Node builds the
115
+ * rejection message from the whole command line, so the caller received
116
+ * fifteen lines of echoed PowerShell with an empty stderr and no way to
117
+ * tell a killed helper from a script that failed instantly.
118
+ *
119
+ * 100ms is unreachable for a process that has to load the CLR, so this is a
120
+ * timeout by construction rather than by timing luck.
121
+ */
122
+ await expect(runtime.execute(ComputerOperationSchema.parse({
123
+ kind: "computer",
124
+ action: "screenshot",
125
+ timeoutMs: 100,
126
+ }))).rejects.toThrow(/^computer_helper_timeout:powershell\.exe:100ms$/);
127
+ }, POWERSHELL_TEST_TIMEOUT_MS);
128
+ });
129
+ //# sourceMappingURL=windows.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windows.test.js","sourceRoot":"","sources":["../src/windows.test.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAEtC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,E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EAAE,UAAU;YAChB,MAAM,EAAE,MAAM;YACd,CAAC,EAAE,GAAG;YACN,CAAC,EAAE,GAAG;YACN,eAAe,EAAE,YAAY;YAC7B,SAAS,EAAE,MAAM;SAClB,CAAC,CACH,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,0EAA0E;QAC1E,0EAA0E;QAC1E,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC,EAAE,0BAA0B,CAAC,CAAC;IAE/B,EAAE,CAAC,4DAA4D,EAAE,KAAK,IAAI,EAAE;QAC1E,MAAM,OAAO,GAAG,IAAI,eAAe,CAAC;YAClC,iBAAiB,EAAE,MAAM,SAAS,EAAE;YACpC,OAAO,EAAE,2BAA2B,EAAE;SACvC,CAAC,CAAC;QACH;;;;;;;;WAQG;QACH,MAAM,MAAM,CACV,OAAO,CAAC,OAAO,CACb,uBAAuB,CAAC,KAAK,CAAC;YAC5B,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,YAAY;YACpB,SAAS,EAAE,GAAG;SACf,CAAC,CACH,CACF,CAAC,OAAO,CAAC,OAAO,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC,EAAE,0BAA0B,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@melra/computer-runtime",
3
+ "version": "0.3.0-alpha.3",
4
+ "description": "Policy-governed local computer-use runtime for MELRA.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/XAGI-Lab/melra.git",
9
+ "directory": "packages/computer-runtime"
10
+ },
11
+ "homepage": "https://github.com/XAGI-Lab/melra#readme",
12
+ "bugs": "https://github.com/XAGI-Lab/melra/issues",
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "@melra/protocol": "0.3.0-alpha.3"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.json",
28
+ "clean": "rm -rf dist",
29
+ "test": "vitest run",
30
+ "typecheck": "tsc -p tsconfig.json --noEmit"
31
+ }
32
+ }