@parcha/agentrun-computer 0.1.0-beta.37 → 0.1.0-beta.38
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/README.md +259 -203
- package/box/Dockerfile +18 -1
- package/box/README.md +13 -0
- package/box/build-agent37.mjs +8 -27
- package/box/build-daytona.py +2 -2
- package/box/build-e2b.mjs +41 -18
- package/box/recipe.mjs +43 -0
- package/dist/agent37-ssh.d.ts +89 -0
- package/dist/agent37-ssh.js +445 -0
- package/dist/agent37.d.ts +2 -63
- package/dist/agent37.js +104 -461
- package/dist/browserbase.d.ts +0 -6
- package/dist/browserbase.js +1 -5
- package/dist/client.d.ts +12 -3
- package/dist/client.js +39 -4
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +4 -0
- package/dist/conformance/cases/apps.d.ts +6 -0
- package/dist/conformance/cases/apps.js +18 -5
- package/dist/conformance/cases/isolation.d.ts +7 -5
- package/dist/conformance/cases/isolation.js +44 -14
- package/dist/conformance/cases/mount.js +1 -1
- package/dist/conformance/cli.js +66 -6
- package/dist/conformance/daytona.d.ts +9 -20
- package/dist/conformance/daytona.js +12 -21
- package/dist/conformance/exec-stream.d.ts +45 -0
- package/dist/conformance/exec-stream.js +486 -0
- package/dist/conformance/sweep.js +8 -8
- package/dist/conformance/types.d.ts +2 -2
- package/dist/create-requests.d.ts +1 -1
- package/dist/daytona.d.ts +20 -131
- package/dist/daytona.js +405 -1450
- package/dist/descriptor.d.ts +6 -1
- package/dist/descriptor.js +7 -0
- package/dist/descriptors/agent37.d.ts +1 -1
- package/dist/descriptors/agent37.js +1 -1
- package/dist/descriptors/daytona.d.ts +6 -5
- package/dist/descriptors/daytona.js +9 -5
- package/dist/descriptors/index.d.ts +4 -5
- package/dist/descriptors/shared.d.ts +1 -1
- package/dist/descriptors/shared.js +2 -2
- package/dist/desktop.d.ts +18 -4
- package/dist/desktop.js +89 -9
- package/dist/docker.d.ts +0 -6
- package/dist/docker.js +1 -5
- package/dist/drift.js +4 -4
- package/dist/e2b.d.ts +10 -128
- package/dist/e2b.js +130 -233
- package/dist/host.d.ts +106 -87
- package/dist/host.js +8 -1
- package/dist/hosted/process.d.ts +22 -8
- package/dist/hosted/process.js +75 -44
- package/dist/hosted/provider.d.ts +35 -21
- package/dist/hosted/provider.js +312 -261
- package/dist/hosted/rest.d.ts +66 -0
- package/dist/hosted/rest.js +121 -0
- package/dist/hosted/scripts.d.ts +8 -2
- package/dist/hosted/scripts.js +27 -2
- package/dist/hosted/values.d.ts +5 -0
- package/dist/hosted/values.js +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/kernel.d.ts +0 -6
- package/dist/kernel.js +1 -5
- package/dist/kinds.d.ts +3 -1
- package/dist/local-chrome.d.ts +0 -6
- package/dist/local-chrome.js +1 -5
- package/dist/modal.d.ts +7 -84
- package/dist/modal.js +50 -174
- package/dist/mount-archil.d.ts +8 -4
- package/dist/mount-archil.js +22 -11
- package/dist/mount.d.ts +10 -4
- package/dist/mount.js +8 -4
- package/dist/orgo.d.ts +0 -9
- package/dist/orgo.js +2 -9
- package/dist/phone-harness.d.ts +0 -6
- package/dist/phone-harness.js +0 -4
- package/dist/protocol.d.ts +4 -1
- package/dist/protocol.js +1 -0
- package/dist/provider.d.ts +2 -2
- package/dist/providers.d.ts +11 -12
- package/dist/screen-watch.js +34 -6
- package/dist/surface/api.d.ts +14 -2
- package/dist/surface/core.d.ts +16 -3
- package/dist/surface/core.js +95 -13
- package/dist/surface/outline.d.ts +2 -0
- package/dist/surface/outline.js +2 -1
- package/dist/surface/script.js +2 -0
- package/dist/ui-engine.js +19 -3
- package/package.json +2 -3
- package/dist/conformance/daytona-sweep.d.ts +0 -18
- package/dist/conformance/daytona-sweep.js +0 -126
package/dist/protocol.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ export interface Features {
|
|
|
103
103
|
*/
|
|
104
104
|
export declare const FEATURES: {
|
|
105
105
|
readonly "screen.capture": "screen.shot and screen.watch capture the whole screen; a computer of the screen group that does not list it captures it, and one that lists it off refuses both with its reason (a Mac whose owner has not granted the server it is paired with the screen)";
|
|
106
|
+
readonly "screen.ahead": "screen.watch takes an after one past the newest frame, an ask ahead that waits for the frame after the one the ask before it answers: a caller keeps two asks in flight, and frames come at the computer's pace, not one each round trip";
|
|
106
107
|
readonly "apps.background": "apps.launch with background: true opens an app without bringing it to the front";
|
|
107
108
|
readonly "ui.tree": "ui.observe reads the window's elements; off, it answers the window's image with no nodes (ui.image on) or is refused";
|
|
108
109
|
readonly "ui.image": "ui.observe returns the window's image";
|
|
@@ -446,7 +447,9 @@ export interface ScreenReadResult {
|
|
|
446
447
|
}
|
|
447
448
|
/**
|
|
448
449
|
* The live view's frames (screen.watch): the next frame after the caller's ack, once the screen changed. `after` is
|
|
449
|
-
* the seq of the last frame the caller has whole, 0 for none; an older one gets the newest frame at once.
|
|
450
|
+
* the seq of the last frame the caller has whole, 0 for none; an older one gets the newest frame at once. On a computer
|
|
451
|
+
* that lists screen.ahead, `after` may be one past the newest frame: an ask ahead, which waits as an ask for the newest
|
|
452
|
+
* does.
|
|
450
453
|
*/
|
|
451
454
|
export interface ScreenWatchParams {
|
|
452
455
|
after: number;
|
package/dist/protocol.js
CHANGED
|
@@ -39,6 +39,7 @@ export const PROTOCOL_VERSION = "0.2";
|
|
|
39
39
|
*/
|
|
40
40
|
export const FEATURES = {
|
|
41
41
|
"screen.capture": "screen.shot and screen.watch capture the whole screen; a computer of the screen group that does not list it captures it, and one that lists it off refuses both with its reason (a Mac whose owner has not granted the server it is paired with the screen)",
|
|
42
|
+
"screen.ahead": "screen.watch takes an after one past the newest frame, an ask ahead that waits for the frame after the one the ask before it answers: a caller keeps two asks in flight, and frames come at the computer's pace, not one each round trip",
|
|
42
43
|
"apps.background": "apps.launch with background: true opens an app without bringing it to the front",
|
|
43
44
|
"ui.tree": "ui.observe reads the window's elements; off, it answers the window's image with no nodes (ui.image on) or is refused",
|
|
44
45
|
"ui.image": "ui.observe returns the window's image",
|
package/dist/provider.d.ts
CHANGED
|
@@ -179,8 +179,8 @@ export interface ComputerCapabilities {
|
|
|
179
179
|
isolation: "container" | "gvisor" | "microvm" | "vm" | "machine" | "host";
|
|
180
180
|
os: ComputerOs;
|
|
181
181
|
/**
|
|
182
|
-
* With release "stop": true when a stop ends in deletion
|
|
183
|
-
*
|
|
182
|
+
* With release "stop": true when a stop ends in deletion, so release(ref, "stop") leaves no computer, listed or
|
|
183
|
+
* attachable. Absent or false: a stopped computer is kept, listed stopped, until deleted.
|
|
184
184
|
*/
|
|
185
185
|
stopDeletes?: boolean;
|
|
186
186
|
daemon: DaemonMode;
|
package/dist/providers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RunFolder } from "./conformance/types.js";
|
|
2
2
|
import type { ProviderDescriptor } from "./descriptor.js";
|
|
3
3
|
import { DESCRIPTORS } from "./descriptors/index.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { MachineHost } from "./host.js";
|
|
5
5
|
import type { MountKind } from "./mount.js";
|
|
6
6
|
import type { ComputerProvider } from "./provider.js";
|
|
7
7
|
/** Where the conformance side reads its settings: process.env, or a record of the same shape. */
|
|
@@ -20,22 +20,21 @@ export interface ConformanceModule {
|
|
|
20
20
|
mountFor?(kind: MountKind, options?: object): RunFolder | undefined | Promise<RunFolder | undefined>;
|
|
21
21
|
conformanceImage?(options?: object): string | Promise<string>;
|
|
22
22
|
conformanceNotes?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* A provider on the shared adapter: its MachineHost from the same settings, with no live switch, since it makes
|
|
25
|
+
* nothing by itself. The live sweep lists and deletes through it, and the exec pre-check (--exec-stream) calls its
|
|
26
|
+
* exec alone.
|
|
27
|
+
*/
|
|
28
|
+
createHost?(options?: object): MachineHost | Promise<MachineHost>;
|
|
23
29
|
settingsFromEnv?(env?: ProviderEnv): object;
|
|
24
30
|
/** Every name settingsFromEnv (and the module) reads, by role: COMPUTER_<ID>_*, or its live switch. */
|
|
25
31
|
readonly ENV?: Readonly<Record<string, string>>;
|
|
26
32
|
}
|
|
27
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* What every registry line resolves to: the provider file's module. Its mount kinds and configurations are its
|
|
35
|
+
* descriptor's (mounts, capabilities), read without loading it.
|
|
36
|
+
*/
|
|
28
37
|
export interface ProviderModule {
|
|
29
|
-
/**
|
|
30
|
-
* The mount kinds its computers take, the same as its provider's capabilities().mount (none: []): a caller tells which
|
|
31
|
-
* provider binds a local folder from the registry alone, without building one.
|
|
32
|
-
*/
|
|
33
|
-
readonly MOUNT: readonly MountKind[];
|
|
34
|
-
/**
|
|
35
|
-
* The machine kind and groups of each configuration it offers, as its built providers' capabilities() declare them:
|
|
36
|
-
* the kind registry's entry for it (PROVIDERS in kinds.ts) holds the same, and derives its setting kinds from them.
|
|
37
|
-
*/
|
|
38
|
-
readonly CAPABILITIES: readonly KindCapabilities[];
|
|
39
38
|
/**
|
|
40
39
|
* The provider, built from its options alone, its key included; it reads no environment, and throws in words when an
|
|
41
40
|
* option is missing or wrong, never echoing a key. Each provider file types its own options.
|
package/dist/screen-watch.js
CHANGED
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
//
|
|
3
3
|
// watchScreen(connection, options) is the internal seam: the screen as pull-paced frames and an input sink on one
|
|
4
4
|
// connection. screen.watch asks for the frame after the last one given, and the next ask is made only when the caller
|
|
5
|
-
// calls next() again, so each next() is the ack of the frame before it.
|
|
5
|
+
// calls next() again, so each next() is the ack of the frame before it. A computer that lists screen.ahead (computerd
|
|
6
|
+
// on a desktop) is asked one frame ahead: two asks are kept in flight, the second for the frame after the first's, so
|
|
7
|
+
// its frames come at its own pace and not one each round trip; next() still gives one frame at a time, the newest
|
|
8
|
+
// answered, and a frame bettered before next() asked for it is dropped. act() sends input.actions on the same
|
|
6
9
|
// connection. close() and the caller's signal end both: the waiting ask is cancelled, the frames end, and act()
|
|
7
10
|
// refuses in words. A computer that fails makes next() reject with a ScreenWatchError.
|
|
8
11
|
//
|
|
9
12
|
// provider.watch(ref, handlers, options) is what the runner's viewer calls (tl-browser's handler shape, final), built
|
|
10
13
|
// once, by daemonWatch, as an adapter over watchScreen: each frame goes to handlers.frame(frame, ack), and the next is
|
|
11
|
-
//
|
|
14
|
+
// given only once ack() is called; a computer that goes ends it once with handlers.ended(error), its code gone,
|
|
12
15
|
// unreachable, refused or unsupported; close() and the signal end it with no ended(). Every computerd provider and the
|
|
13
16
|
// phone answer watch() through daemonWatch, on a connection of the watch's own: computerd gives JPEG frames, the phone
|
|
14
17
|
// client PNG ones. No error in either layer holds a URL or a secret.
|
|
@@ -84,18 +87,40 @@ export function watchScreen(connection, options = {}) {
|
|
|
84
87
|
...(options.maxWidth === undefined ? {} : { maxWidth: options.maxWidth }),
|
|
85
88
|
...(options.quality === undefined ? {} : { quality: options.quality }),
|
|
86
89
|
};
|
|
90
|
+
// A computer that lists screen.ahead takes a second ask while the first waits (after one past the newest frame): two
|
|
91
|
+
// are kept in flight, so its frames come at its own pace, not one each round trip. Else one, after each ack.
|
|
92
|
+
// Why it exists: with one ask in flight each frame waits a full round trip, about 7 fps (kit-10, 5-run medians:
|
|
93
|
+
// E2B 7.00 one ask vs 12.96 two, Agent37 6.15 vs 14.53).
|
|
94
|
+
const depth = connection.hello?.features?.["screen.ahead"] === true ? 2 : 1;
|
|
87
95
|
async function* frames() {
|
|
88
|
-
|
|
96
|
+
/** The seq of the newest frame given. */
|
|
97
|
+
let last = 0;
|
|
98
|
+
/** The asks in flight, oldest first. */
|
|
99
|
+
const asks = [];
|
|
100
|
+
const newer = (answer) => answer?.ok === true && answer.value.changed && answer.value.seq > last;
|
|
101
|
+
const ask = () => {
|
|
102
|
+
while (asks.length < depth) {
|
|
103
|
+
// The ask after one in flight is ahead by one: it waits for the frame after the one the first answers.
|
|
104
|
+
const asked = { promise: client.call("screen.watch", { after: last + asks.length, ...params }, { signal: stop.signal }) };
|
|
105
|
+
void asked.promise.then((answer) => (asked.answer = answer));
|
|
106
|
+
asks.push(asked);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
89
109
|
for (;;) {
|
|
90
110
|
if (ended)
|
|
91
111
|
return;
|
|
92
|
-
|
|
112
|
+
ask();
|
|
113
|
+
// A frame the ask after it has already bettered is dropped: the viewer wants the newest.
|
|
114
|
+
while (asks.length > 1 && asks[0].answer !== undefined && newer(asks[1].answer))
|
|
115
|
+
asks.shift();
|
|
116
|
+
const asked = await asks.shift().promise;
|
|
93
117
|
if (ended)
|
|
94
118
|
return;
|
|
95
119
|
if (!asked.ok)
|
|
96
120
|
throw new ScreenWatchError(asked.error.code, redactWords(asked.error.message));
|
|
97
121
|
const answer = asked.value;
|
|
98
|
-
if (!answer.changed) {
|
|
122
|
+
if (!answer.changed || answer.seq <= last) {
|
|
123
|
+
// No change within the wait, or a frame given already (two asks may answer the same newest frame).
|
|
99
124
|
// The computer waited its waitMs; one that answers at once must not spin: timers and the signal run first.
|
|
100
125
|
await new Promise((resolve) => setImmediate(resolve));
|
|
101
126
|
continue;
|
|
@@ -128,7 +153,10 @@ export function watchScreen(connection, options = {}) {
|
|
|
128
153
|
}
|
|
129
154
|
if (sized && size !== said)
|
|
130
155
|
throw new ScreenWatchError("invalid", `frame ${answer.seq} ended at ${size} bytes of the ${said} it said`);
|
|
131
|
-
|
|
156
|
+
last = answer.seq;
|
|
157
|
+
// Asked ahead, the next asks go out before this frame is drawn: the computer makes the next one meanwhile.
|
|
158
|
+
if (depth > 1)
|
|
159
|
+
ask();
|
|
132
160
|
yield {
|
|
133
161
|
seq: answer.seq,
|
|
134
162
|
format: answer.format ?? "jpeg",
|
package/dist/surface/api.d.ts
CHANGED
|
@@ -195,6 +195,18 @@ export interface Computer {
|
|
|
195
195
|
env?: Record<string, string>;
|
|
196
196
|
}): Promise<RunResult>;
|
|
197
197
|
};
|
|
198
|
+
/** @group processes */
|
|
199
|
+
readonly processes: {
|
|
200
|
+
/** Start a program that runs on after the call (an app on the desktop, a server), the way shell.run can't: it ends
|
|
201
|
+
* everything its command started. Answers once it started; it and what it starts run until they exit or the
|
|
202
|
+
* computer ends. A string runs in sh -c, a list is the program and its arguments. */
|
|
203
|
+
start(command: string | string[], options?: {
|
|
204
|
+
cwd?: string;
|
|
205
|
+
env?: Record<string, string>;
|
|
206
|
+
}): Promise<{
|
|
207
|
+
pid: number;
|
|
208
|
+
}>;
|
|
209
|
+
};
|
|
198
210
|
/** @group files */
|
|
199
211
|
readonly files: {
|
|
200
212
|
/** A file's text (UTF-8), or with base64 its bytes. */
|
|
@@ -210,7 +222,7 @@ export interface Computer {
|
|
|
210
222
|
}
|
|
211
223
|
/** computer_observe: observe an app's window (or, with no ui group, the screen). */
|
|
212
224
|
export interface ObserveArgs {
|
|
213
|
-
/** Default: the app in front. */
|
|
225
|
+
/** Default: the app in front. With no ui group, opened or brought in front first. */
|
|
214
226
|
app?: string;
|
|
215
227
|
/** Add the window's picture (always, with no ui group). */
|
|
216
228
|
image?: boolean;
|
|
@@ -219,7 +231,7 @@ export interface ObserveArgs {
|
|
|
219
231
|
}
|
|
220
232
|
/** computer_act: run steps on an app, and check a condition after them. */
|
|
221
233
|
export interface ActArgs {
|
|
222
|
-
/** Default: the state's app, else the app in front. */
|
|
234
|
+
/** Default: the state's app, else the app in front. With no ui group, opened or brought in front first. */
|
|
223
235
|
app?: string;
|
|
224
236
|
/** The state a step's point was read from. Default: the last observed. */
|
|
225
237
|
state?: string;
|
package/dist/surface/core.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComputerClient, HelloResult, UiStep } from "../protocol.js";
|
|
2
2
|
import type { ActResult, Card, Image } from "./api.js";
|
|
3
3
|
/** What a surface can be asked, by name: the members of Computer and the tools' calls. */
|
|
4
|
-
export type SurfaceOp = "observe" | "act" | "screenshot" | "input.act" | "apps.list" | "apps.open" | "shell.run" | "files.read" | "files.write" | "files.list" | "files.stat";
|
|
4
|
+
export type SurfaceOp = "observe" | "act" | "screenshot" | "input.act" | "apps.list" | "apps.open" | "shell.run" | "processes.start" | "files.read" | "files.write" | "files.list" | "files.stat";
|
|
5
5
|
export declare const SURFACE_OPS: readonly SurfaceOp[];
|
|
6
6
|
/** One call's answer: the value a script gets, the text a model reads, and the images that go with it. */
|
|
7
7
|
export interface SurfaceAnswer {
|
|
@@ -31,8 +31,20 @@ export declare function cardOf(hello: HelloResult): Card;
|
|
|
31
31
|
export declare function opsOf(groups: readonly string[]): SurfaceOp[];
|
|
32
32
|
/** The name of a step: its first key ("press", "click", ...). */
|
|
33
33
|
export declare const stepName: (step: UiStep) => string;
|
|
34
|
-
/** An
|
|
35
|
-
|
|
34
|
+
/** An element as a step's line names it: its ref, its role, its name, and `[secure]` for a secure field. */
|
|
35
|
+
type Named = {
|
|
36
|
+
role: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
secure: boolean;
|
|
39
|
+
};
|
|
40
|
+
/** A step as its line in an act's answer names it: its name, then the element it acted on as the outline names it
|
|
41
|
+
* (`press @e3 button "Save"`, `type into @e4 textbox "PIN" [secure]`), where that element was seen in an observation;
|
|
42
|
+
* `[secure]` is that element's own flag. A type with no element names none: where the focus is when it runs (which
|
|
43
|
+
* app, which field, after what the steps before it, a person, or the system did) is not known here, so no reader of
|
|
44
|
+
* its line can tell it went to an ordinary field, and none shows what was typed. */
|
|
45
|
+
export declare function stepWords(step: UiStep, named: (ref: string) => Named | undefined): string;
|
|
46
|
+
/** An act's answer as lines: one per step (named by `names`, stepWords), then the expect, then whether it changed and
|
|
47
|
+
* the new state, then the new observation's outline when there is one. */
|
|
36
48
|
export declare function actText(names: readonly string[], result: ActResult): string;
|
|
37
49
|
/** A chord's keys: "ctrl+shift+t" is ctrl, shift, t; a trailing "+" is the plus key ("ctrl++"). */
|
|
38
50
|
export declare const chordKeys: (chord: string) => string[];
|
|
@@ -40,3 +52,4 @@ export declare const chordKeys: (chord: string) => string[];
|
|
|
40
52
|
export declare function createSurface(client: ComputerClient, hello: HelloResult): Surface;
|
|
41
53
|
/** A value with its images' data left out: the structured half of an answer whose images travel beside it. */
|
|
42
54
|
export declare function withoutImageData(value: unknown): unknown;
|
|
55
|
+
export {};
|
package/dist/surface/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MAX_CHUNK_BYTES } from "../protocol.js";
|
|
2
|
-
import { outlineOf } from "./outline.js";
|
|
3
|
-
export const SURFACE_OPS = ["observe", "act", "screenshot", "input.act", "apps.list", "apps.open", "shell.run", "files.read", "files.write", "files.list", "files.stat"];
|
|
2
|
+
import { outlineOf, quoted } from "./outline.js";
|
|
3
|
+
export const SURFACE_OPS = ["observe", "act", "screenshot", "input.act", "apps.list", "apps.open", "shell.run", "processes.start", "files.read", "files.write", "files.list", "files.stat"];
|
|
4
4
|
/** A call the computer refused or failed: `kind` is the protocol's error kind (stale, unsupported, ...) or the
|
|
5
5
|
* connection's (gone, timeout). */
|
|
6
6
|
export class SurfaceError extends Error {
|
|
@@ -50,6 +50,7 @@ export function opsOf(groups) {
|
|
|
50
50
|
"apps.list": has("apps"),
|
|
51
51
|
"apps.open": has("apps"),
|
|
52
52
|
"shell.run": has("exec"),
|
|
53
|
+
"processes.start": has("processes"),
|
|
53
54
|
"files.read": has("files"),
|
|
54
55
|
"files.write": has("files"),
|
|
55
56
|
"files.list": has("files"),
|
|
@@ -65,8 +66,29 @@ function jsonText(value) {
|
|
|
65
66
|
}
|
|
66
67
|
/** The name of a step: its first key ("press", "click", ...). */
|
|
67
68
|
export const stepName = (step) => Object.keys(step)[0] ?? "step";
|
|
68
|
-
/**
|
|
69
|
-
*
|
|
69
|
+
/** The element a step acts on, by its ref: press's, set's, perform's, and click's or scroll's when they name one, or
|
|
70
|
+
* type's `into`. None for a step at a point or with no element. */
|
|
71
|
+
function stepRef(step) {
|
|
72
|
+
const at = "type" in step ? step.into : "press" in step ? step.press : "set" in step ? step.set : "perform" in step ? step.perform : "click" in step ? step.click : "scroll" in step ? step.scroll : undefined;
|
|
73
|
+
return typeof at === "string" ? at : undefined;
|
|
74
|
+
}
|
|
75
|
+
/** The most elements a surface remembers the names of, past which the oldest seen go first. */
|
|
76
|
+
const MAX_NAMED = 4000;
|
|
77
|
+
/** A step as its line in an act's answer names it: its name, then the element it acted on as the outline names it
|
|
78
|
+
* (`press @e3 button "Save"`, `type into @e4 textbox "PIN" [secure]`), where that element was seen in an observation;
|
|
79
|
+
* `[secure]` is that element's own flag. A type with no element names none: where the focus is when it runs (which
|
|
80
|
+
* app, which field, after what the steps before it, a person, or the system did) is not known here, so no reader of
|
|
81
|
+
* its line can tell it went to an ordinary field, and none shows what was typed. */
|
|
82
|
+
export function stepWords(step, named) {
|
|
83
|
+
const ref = stepRef(step);
|
|
84
|
+
const node = ref === undefined ? undefined : named(ref);
|
|
85
|
+
if (ref === undefined || node === undefined)
|
|
86
|
+
return stepName(step);
|
|
87
|
+
const target = [ref, node.role, ...(node.name ? [quoted(node.name)] : []), ...(node.secure ? ["[secure]"] : [])].join(" ");
|
|
88
|
+
return `${stepName(step)}${"type" in step ? " into" : ""} ${target}`;
|
|
89
|
+
}
|
|
90
|
+
/** An act's answer as lines: one per step (named by `names`, stepWords), then the expect, then whether it changed and
|
|
91
|
+
* the new state, then the new observation's outline when there is one. */
|
|
70
92
|
export function actText(names, result) {
|
|
71
93
|
const lines = result.steps.map((outcome, index) => {
|
|
72
94
|
const name = names[index] ?? "step";
|
|
@@ -102,6 +124,34 @@ export function createSurface(client, hello) {
|
|
|
102
124
|
let lastApp;
|
|
103
125
|
/** The app each observed state belongs to: an act that names a state and no app was run on that state's app. */
|
|
104
126
|
const appOfState = new Map();
|
|
127
|
+
/** Every element observed, by ref, as an act's step line names it (stepWords): a ref stays good across states. */
|
|
128
|
+
const named = new Map();
|
|
129
|
+
/** Remembers an observation's elements. One with no name of its own (an Android row, a container whose text is in
|
|
130
|
+
* its children) takes its first named element's within a few levels, as a person reading the row would say it. */
|
|
131
|
+
function remember(nodes) {
|
|
132
|
+
const parentOf = new Map();
|
|
133
|
+
for (const node of nodes) {
|
|
134
|
+
parentOf.set(node.ref, node.parent);
|
|
135
|
+
named.delete(node.ref);
|
|
136
|
+
named.set(node.ref, { role: node.role, ...(node.name ? { name: node.name } : {}), secure: node.flags?.includes("secure") === true });
|
|
137
|
+
}
|
|
138
|
+
for (const node of nodes) {
|
|
139
|
+
if (!node.name)
|
|
140
|
+
continue;
|
|
141
|
+
let up = node.parent;
|
|
142
|
+
for (let level = 0; up !== undefined && level < 3; level += 1, up = parentOf.get(up)) {
|
|
143
|
+
const above = named.get(up);
|
|
144
|
+
if (above === undefined || above.name !== undefined)
|
|
145
|
+
break;
|
|
146
|
+
above.name = node.name;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const ref of named.keys()) {
|
|
150
|
+
if (named.size <= MAX_NAMED)
|
|
151
|
+
break;
|
|
152
|
+
named.delete(ref);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
105
155
|
async function call(method, params, signal) {
|
|
106
156
|
const result = await client.call(method, params, { signal });
|
|
107
157
|
if (!result.ok)
|
|
@@ -131,6 +181,7 @@ export function createSurface(client, hello) {
|
|
|
131
181
|
lastState.set(result.app.id, result.state);
|
|
132
182
|
appOfState.set(result.state, result.app.id);
|
|
133
183
|
lastApp = result.app.id;
|
|
184
|
+
remember(result.nodes);
|
|
134
185
|
const outline = outlineOf(head, result.nodes, result.truncated, result.empty);
|
|
135
186
|
const imageNote = result.image ? `\nimage: ${result.image.width}×${result.image.height} px of the window's ${window.bounds[2]}×${window.bounds[3]} points` : "";
|
|
136
187
|
return {
|
|
@@ -143,16 +194,27 @@ export function createSurface(client, hello) {
|
|
|
143
194
|
...(result.image ? { image: imageOf(result.image) } : {}),
|
|
144
195
|
};
|
|
145
196
|
}
|
|
146
|
-
/**
|
|
197
|
+
/** On a computer with no ui group, input goes to what is in front: an app a look or an act names is opened, or brought
|
|
198
|
+
* in front, first (apps.launch), so the per-step tools open an app as a script's computer.apps.open does. */
|
|
199
|
+
async function inFront(app, signal) {
|
|
200
|
+
if (app && has("apps"))
|
|
201
|
+
await call("apps.launch", { id: app }, signal);
|
|
202
|
+
}
|
|
203
|
+
/** The screen as a state, for a computer with no ui group: its image, no elements. With nothing in front, the head
|
|
204
|
+
* lists the apps to name. */
|
|
147
205
|
async function screenState(signal) {
|
|
148
206
|
const image = await shot(undefined, signal);
|
|
149
|
-
const
|
|
150
|
-
const
|
|
207
|
+
const listed = has("apps") ? await call("apps.list", {}, signal) : undefined;
|
|
208
|
+
const app = listed?.foreground ?? "";
|
|
209
|
+
const front = app ? ` · ${app} in front` : listed ? ` · no app in front; name one as app to open it: ${listed.apps.map((one) => one.id).join(", ")}` : "";
|
|
210
|
+
const head = `screen ${image.width}×${image.height} px${front} · this computer has no ui group: no elements; act at points of this image`;
|
|
151
211
|
return { id: "screen", app: { id: app, name: "" }, window: { id: "screen", bounds: [0, 0, image.width, image.height] }, elements: [], truncated: false, outline: head, image };
|
|
152
212
|
}
|
|
153
213
|
async function observe(args, signal) {
|
|
154
|
-
if (!has("ui"))
|
|
214
|
+
if (!has("ui")) {
|
|
215
|
+
await inFront(args.app, signal);
|
|
155
216
|
return screenState(signal);
|
|
217
|
+
}
|
|
156
218
|
const imageInUi = args.image === true && card.features["ui.image"] === true;
|
|
157
219
|
const result = await call("ui.observe", { ...(args.app ? { target: { app: args.app } } : {}), ...(imageInUi ? { image: true } : {}), ...(args.full ? { full: true } : {}) }, signal);
|
|
158
220
|
const state = stateOf(result);
|
|
@@ -224,7 +286,9 @@ export function createSurface(client, hello) {
|
|
|
224
286
|
if (!has("ui")) {
|
|
225
287
|
if (args.expect)
|
|
226
288
|
throw new SurfaceError("unsupported", "this computer has no ui group, so it can't check an expect: take a screenshot to see the effect");
|
|
227
|
-
|
|
289
|
+
const actions = inputActionsOf(steps);
|
|
290
|
+
await inFront(args.app, signal);
|
|
291
|
+
return runInput(actions, Boolean(args.observe), signal);
|
|
228
292
|
}
|
|
229
293
|
const app = args.app;
|
|
230
294
|
const state = args.state ?? (hasPoint(steps) ? lastState.get(app ?? lastApp ?? "") : undefined);
|
|
@@ -284,13 +348,23 @@ export function createSurface(client, hello) {
|
|
|
284
348
|
}
|
|
285
349
|
return entries.map((entry) => infoOf(entry.path, entry));
|
|
286
350
|
}
|
|
287
|
-
|
|
288
|
-
|
|
351
|
+
/** A command's argv: a string in the shell (cmd on Windows), a list as given. */
|
|
352
|
+
function argvOf(command) {
|
|
289
353
|
const argv = typeof command === "string" ? (card.os === "windows" ? ["cmd.exe", "/d", "/s", "/c", command] : ["sh", "-c", command]) : Array.isArray(command) && command.every((part) => typeof part === "string") ? command : undefined;
|
|
290
354
|
if (!argv || argv.length === 0)
|
|
291
355
|
throw new SurfaceError("invalid", "command is a string (run by the shell) or a list: the program and its arguments");
|
|
356
|
+
return argv;
|
|
357
|
+
}
|
|
358
|
+
/** A program's env: on a desktop with an X display, its DISPLAY (the daemon gives its programs none: protocol.ts
|
|
359
|
+
* ExecRunParams), so an app opens where the screen is; the call's own variables over it. */
|
|
360
|
+
function envOf(given) {
|
|
361
|
+
const env = { ...(hello.display ? { DISPLAY: hello.display } : {}), ...(given ?? {}) };
|
|
362
|
+
return Object.keys(env).length > 0 ? { env } : {};
|
|
363
|
+
}
|
|
364
|
+
async function run(args, signal) {
|
|
365
|
+
const argv = argvOf(args.command);
|
|
292
366
|
const timeoutMs = Math.min(Math.max(1, args.timeoutMs ?? DEFAULT_RUN_MS), MAX_RUN_MS);
|
|
293
|
-
const result = await call("exec.run", { argv, timeoutMs, ...(args.cwd ? { cwd: args.cwd } : {}), ...(args.env
|
|
367
|
+
const result = await call("exec.run", { argv, timeoutMs, ...(args.cwd ? { cwd: args.cwd } : {}), ...envOf(args.env) }, signal);
|
|
294
368
|
return {
|
|
295
369
|
stdout: Buffer.from(result.stdout, "base64").toString("utf8"),
|
|
296
370
|
stderr: Buffer.from(result.stderr, "base64").toString("utf8"),
|
|
@@ -309,8 +383,10 @@ export function createSurface(client, hello) {
|
|
|
309
383
|
case "observe":
|
|
310
384
|
return observeAnswer(await observe(args, signal));
|
|
311
385
|
case "act": {
|
|
386
|
+
// Each step named as its element was before the act: what it pressed, not what the press made of it.
|
|
387
|
+
const given = args.steps;
|
|
388
|
+
const names = Array.isArray(given) ? given.map((step) => stepWords(step, (ref) => named.get(ref))) : [];
|
|
312
389
|
const result = await act(args, signal);
|
|
313
|
-
const names = (args.steps ?? []).map(stepName);
|
|
314
390
|
return { value: result, text: actText(names, result), images: result.after?.image ? [result.after.image] : [] };
|
|
315
391
|
}
|
|
316
392
|
case "input.act": {
|
|
@@ -340,6 +416,12 @@ export function createSurface(client, hello) {
|
|
|
340
416
|
const value = await run(args, signal);
|
|
341
417
|
return { value, text: jsonText(value), images: [] };
|
|
342
418
|
}
|
|
419
|
+
case "processes.start": {
|
|
420
|
+
const argv = argvOf(args.command);
|
|
421
|
+
// orphans "keep": what the program starts (a launcher that forks its app and exits) runs on too.
|
|
422
|
+
const started = await call("process.start", { argv, ...(typeof args.cwd === "string" && args.cwd ? { cwd: args.cwd } : {}), ...envOf(args.env), orphans: "keep" }, signal);
|
|
423
|
+
return { value: { pid: started.pid }, text: `started ${argv.join(" ")} (pid ${started.pid})`, images: [] };
|
|
424
|
+
}
|
|
343
425
|
case "files.read": {
|
|
344
426
|
const value = await readFile(pathOf(args), args.encoding, signal);
|
|
345
427
|
return { value, text: value.length > MAX_TEXT_CHARS ? `${value.slice(0, MAX_TEXT_CHARS)}… (${value.length - MAX_TEXT_CHARS} more characters)` : value, images: [] };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { UiNode } from "../protocol.js";
|
|
2
2
|
/** The most characters an outline takes: past it, the last line counts the elements left out. */
|
|
3
3
|
export declare const OUTLINE_MAX_CHARS = 12000;
|
|
4
|
+
/** A name or value as the outline shows it: on one line, cut, in JSON's quotes. */
|
|
5
|
+
export declare const quoted: (text: string) => string;
|
|
4
6
|
/** One element's line: `@e4 button "Save" = "value" ("what else it says") [focused]`. */
|
|
5
7
|
export declare function lineOf(node: UiNode): string;
|
|
6
8
|
/** The outline of an observation: `head`, then the elements within OUTLINE_MAX_CHARS, each indented under its parent,
|
package/dist/surface/outline.js
CHANGED
|
@@ -5,7 +5,8 @@ const TEXT_CHARS = 80;
|
|
|
5
5
|
/** The deepest indent, in levels: deeper elements line up at it. */
|
|
6
6
|
const MAX_INDENT = 8;
|
|
7
7
|
const clip = (text) => (text.length > TEXT_CHARS ? `${text.slice(0, TEXT_CHARS - 1)}…` : text);
|
|
8
|
-
|
|
8
|
+
/** A name or value as the outline shows it: on one line, cut, in JSON's quotes. */
|
|
9
|
+
export const quoted = (text) => JSON.stringify(clip(text.replace(/\s+/g, " ").trim()));
|
|
9
10
|
/** One element's line: `@e4 button "Save" = "value" ("what else it says") [focused]`. */
|
|
10
11
|
export function lineOf(node) {
|
|
11
12
|
const parts = [node.ref, node.role];
|
package/dist/surface/script.js
CHANGED
|
@@ -72,6 +72,8 @@ export function bindComputer(call, card) {
|
|
|
72
72
|
computer.input = freeze({ act: (actions) => call("input.act", { actions }) });
|
|
73
73
|
if (has("exec"))
|
|
74
74
|
computer.shell = freeze({ run: (command, options = {}) => call("shell.run", { ...options, command }) });
|
|
75
|
+
if (has("processes"))
|
|
76
|
+
computer.processes = freeze({ start: (command, options = {}) => call("processes.start", { ...options, command }) });
|
|
75
77
|
if (has("files"))
|
|
76
78
|
computer.files = freeze({
|
|
77
79
|
read: (path, options = {}) => call("files.read", { ...options, path }),
|
package/dist/ui-engine.js
CHANGED
|
@@ -286,9 +286,22 @@ const looksOf = (element) => JSON.stringify([element.role, element.name, valueOf
|
|
|
286
286
|
* What a person would see of a view, for the settle and an act's changed: the window, and its elements when it has
|
|
287
287
|
* any. The frame (a hash of its pixels) counts only with no elements (ui.tree off, or a window with none): a blinking
|
|
288
288
|
* caret or a spinner redraws the frame under the same tree, which held each settle to maxSettleMs (Notes on a Mac: 13.5 s
|
|
289
|
-
* against 1.9 s on the tree) and counted as a step's effect. A state keeps its frame, for a point with no element.
|
|
289
|
+
* against 1.9 s on the tree) and counted as a step's effect. A state keeps its frame, for a point with no element. Only
|
|
290
|
+
* what is on the window counts, with its bounds held inside it as ui.observe shows them: System Settings rebuilds its
|
|
291
|
+
* sidebar rows scrolled out of view each time its tree is read (so the list's content is a new height each time), and
|
|
292
|
+
* Finder's status bar below the window counts the free disk space, which held every settle there to maxSettleMs too.
|
|
293
|
+
* Nor which element each is (its key): a person sees none of that, and System Settings makes its sidebar's row at the
|
|
294
|
+
* window's edge anew on every read, the same words in the same place.
|
|
290
295
|
*/
|
|
291
|
-
const fingerprint = (view) => JSON.stringify([
|
|
296
|
+
const fingerprint = (view) => JSON.stringify([
|
|
297
|
+
view.window.id,
|
|
298
|
+
view.window.bounds,
|
|
299
|
+
view.elements.length > 0
|
|
300
|
+
? view.elements.filter((element) => onWindow(view, element.bounds)).map((element) => looksOf({ ...element, bounds: insideWindow(element.bounds, view.window.bounds[2], view.window.bounds[3]) }))
|
|
301
|
+
: view.frame,
|
|
302
|
+
]);
|
|
303
|
+
/** The bounds (window points) reach into the window. */
|
|
304
|
+
const onWindow = (view, [x, y, w, h]) => x < view.window.bounds[2] && 0 < x + w && y < view.window.bounds[3] && 0 < y + h;
|
|
292
305
|
/** Whether an element says text, in its name, value or desc. */
|
|
293
306
|
const holdsText = (element, text) => [element.name, valueOf(element), element.desc].some((said) => said?.includes(text) ?? false);
|
|
294
307
|
/** An element's key scoped to its window: what a ref stands for. */
|
|
@@ -638,7 +651,10 @@ export class UiEngine {
|
|
|
638
651
|
return "set" in step && result !== undefined && !("error" in result) && result.verified ? [index] : [];
|
|
639
652
|
});
|
|
640
653
|
if (sets.length > 0) {
|
|
641
|
-
|
|
654
|
+
// Waited out on the clock: a timer may fire a millisecond early, and the hold is a floor.
|
|
655
|
+
const heldUntil = Date.now() + SET_HOLD_MS;
|
|
656
|
+
for (let left = SET_HOLD_MS; left > 0 && !signal.aborted; left = heldUntil - Date.now())
|
|
657
|
+
await sleep(left, signal);
|
|
642
658
|
if (signal.aborted)
|
|
643
659
|
return aborted("ui.act");
|
|
644
660
|
read = await final();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-computer",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.38",
|
|
4
4
|
"description": "The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
@@ -101,8 +101,7 @@
|
|
|
101
101
|
"test:daytona": "node --test --test-timeout=1800000 test/daytona/*.test.mjs",
|
|
102
102
|
"test:modal": "node --test --test-timeout=1800000 test/modal/*.test.mjs",
|
|
103
103
|
"test:e2b": "node --test --test-timeout=1800000 test/e2b/*.test.mjs",
|
|
104
|
-
"conformance": "node dist/conformance/cli.js"
|
|
105
|
-
"daytona:sweep": "node dist/conformance/daytona-sweep.js"
|
|
104
|
+
"conformance": "node dist/conformance/cli.js"
|
|
106
105
|
},
|
|
107
106
|
"repository": {
|
|
108
107
|
"type": "git",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { DaytonaProviderOptions } from "../daytona.js";
|
|
2
|
-
/** A stream as main writes to it: done is called once the text is handed on. */
|
|
3
|
-
export interface Writer {
|
|
4
|
-
write(text: string, done?: (error?: Error | null) => void): unknown;
|
|
5
|
-
}
|
|
6
|
-
export interface SweepIo {
|
|
7
|
-
/** Where the settings are read; default process.env. */
|
|
8
|
-
env?: Record<string, string | undefined>;
|
|
9
|
-
fetch?: DaytonaProviderOptions["fetch"];
|
|
10
|
-
webSocket?: DaytonaProviderOptions["webSocket"];
|
|
11
|
-
stdout?: Writer;
|
|
12
|
-
stderr?: Writer;
|
|
13
|
-
/** How long --after reads one deleted sandbox back before it counts as still there; default 60 s. */
|
|
14
|
-
waitMs?: number;
|
|
15
|
-
/** The pause between two reads of one sandbox; default 2 s. */
|
|
16
|
-
pollMs?: number;
|
|
17
|
-
}
|
|
18
|
-
export declare function main(argv: string[], io?: SweepIo): Promise<number>;
|