@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37
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/CHANGELOG.md +170 -0
- package/README.md +158 -52
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/cap.d.ts +0 -17
- package/dist/cap.js +0 -91
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +13 -4
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-view.d.ts +13 -0
- package/dist/computer-view.js +50 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +33 -7
- package/dist/computers.js +50 -8
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +53 -25
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/graph-view.d.ts +1 -1
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +35 -1
- package/dist/host-tools.d.ts +1 -1
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/learn/check.d.ts +4 -1
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +4 -2
- package/dist/learn/commit.js +5 -5
- package/dist/learn/folder.d.ts +6 -0
- package/dist/learn/folder.js +4 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +22 -1
- package/dist/learn/reflect.d.ts +10 -1
- package/dist/learn/reflect.js +14 -4
- package/dist/learn/skills.d.ts +33 -5
- package/dist/learn/skills.js +53 -7
- package/dist/learned-workflow.d.ts +24 -0
- package/dist/learned-workflow.js +66 -3
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +25 -2
- package/dist/learning-routes.js +39 -6
- package/dist/learning-words.d.ts +6 -0
- package/dist/learning-words.js +6 -0
- package/dist/learning.d.ts +28 -15
- package/dist/learning.js +84 -44
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +19 -2
- package/dist/mcp-probe.js +44 -9
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +112 -20
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.js +23 -10
- package/dist/openapi.js +386 -21
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/place-offers.d.ts +2 -3
- package/dist/place-offers.js +3 -7
- package/dist/place.js +1 -2
- package/dist/print.d.ts +15 -1
- package/dist/print.js +14 -3
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +13 -5
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-launch.d.ts +14 -2
- package/dist/run-launch.js +9 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-view.d.ts +3 -3
- package/dist/run-view.js +14 -7
- package/dist/runner/adapter-loop.d.ts +23 -7
- package/dist/runner/adapter-loop.js +648 -62
- package/dist/runner/adapter-run-spec.d.ts +11 -3
- package/dist/runner/adapter-run-spec.js +77 -22
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +9 -4
- package/dist/runner/adapters/pi.js +76 -14
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +21 -11
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +20 -3
- package/dist/runner/cli-run-spec.js +113 -43
- package/dist/runner/commands.d.ts +3 -1
- package/dist/runner/commands.js +28 -3
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.js +80 -14
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +4 -2
- package/dist/runner/harness-loops.js +15 -1
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +20 -1
- package/dist/runner/journal-kinds.js +14 -0
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +22 -1
- package/dist/runner/learning-end.js +92 -12
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +11 -5
- package/dist/runner/learning-loop.d.ts +67 -7
- package/dist/runner/learning-loop.js +173 -21
- package/dist/runner/learning-seed.d.ts +7 -0
- package/dist/runner/learning-seed.js +13 -0
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +2 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +27 -5
- package/dist/runner/mcp-claim.d.ts +10 -7
- package/dist/runner/mcp-claim.js +113 -24
- package/dist/runner/mcp-github.js +1 -1
- package/dist/runner/mcp-run.d.ts +5 -5
- package/dist/runner/mcp-run.js +15 -3
- package/dist/runner/metrics.d.ts +11 -2
- package/dist/runner/metrics.js +12 -2
- package/dist/runner/pr-checkout.d.ts +1 -0
- package/dist/runner/pr-checkout.js +1 -1
- package/dist/runner/reflect-hook.d.ts +18 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +184 -15
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/store-port.d.ts +4 -2
- package/dist/runner/store-secrets.js +4 -3
- package/dist/runner/subagent.js +3 -1
- package/dist/runner/workflow-host.d.ts +6 -1
- package/dist/runner/workflow-host.js +1 -1
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-spec.d.ts +14 -2
- package/dist/runner/workflow-spec.js +56 -20
- package/dist/runs-over-store.d.ts +6 -1
- package/dist/runs-over-store.js +38 -9
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +43 -14
- package/dist/server.js +472 -126
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +13 -5
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +1 -1
- package/dist/store/schema.js +77 -8
- package/dist/store/sqlite/run-patch.d.ts +7 -5
- package/dist/store/sqlite/run-patch.js +28 -13
- package/dist/store/sqlite/store.js +272 -54
- package/dist/store/store.d.ts +268 -9
- package/dist/store/store.js +12 -1
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +8 -1
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +1 -1
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +73 -15
- package/dist/store-reads/learning.d.ts +20 -4
- package/dist/store-reads/learning.js +74 -18
- package/dist/store-reads/runs.d.ts +1 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +26 -11
- package/dist/template-eval.js +6 -4
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/timeline/timeline.d.ts +27 -0
- package/dist/timeline/timeline.js +10 -9
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-budget.d.ts +19 -7
- package/dist/tool-budget.js +14 -8
- package/dist/tool-gate.d.ts +16 -9
- package/dist/tool-gate.js +53 -42
- package/dist/tool-plane.d.ts +16 -12
- package/dist/tool-plane.js +9 -4
- package/dist/tools.d.ts +13 -4
- package/dist/tools.js +13 -4
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +25 -6
- package/dist/trigger-signatures.js +41 -7
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +35 -5
- package/dist/turns.js +16 -1
- package/dist/validate.js +11 -1
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +145 -102
- package/dist/webhooks.js +559 -322
- package/dist/workflow/decisions.d.ts +1 -1
- package/dist/workflow/node-runner.d.ts +2 -1
- package/dist/workflow/node.d.ts +2 -1
- package/dist/workflow/node.js +3 -1
- package/dist/workflow/pi-versions.d.ts +23 -0
- package/dist/workflow/pi-versions.js +57 -0
- package/dist/workflow/record-tool.d.ts +2 -1
- package/dist/workflow/store.d.ts +1 -1
- package/dist/workflow/task.js +3 -2
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +16 -9
- package/dist/workspace/computer-deps.js +19 -7
- package/dist/workspace/computer-for-claim.d.ts +17 -8
- package/dist/workspace/computer-for-claim.js +62 -21
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +4 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +4 -2
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +3 -0
- package/dist/workspace/resolve-computer.js +8 -2
- package/dist/workspace/run-tools.d.ts +32 -15
- package/dist/workspace/run-tools.js +23 -30
- package/package.json +19 -16
- package/templates/market-monitor/agent.md +1 -1
- package/dist/console/assets/index-BI4Byidu.js +0 -550
- package/dist/console/assets/index-C19gUF2n.css +0 -1
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/dist/workflow/readers.d.ts +0 -36
- package/dist/workflow/readers.js +0 -145
- package/dist/workflow/wal.d.ts +0 -11
- package/dist/workflow/wal.js +0 -106
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// computer_script's run: the model's JavaScript in a QuickJS isolate here in serve (pi-codemode's CodemodeSandbox, a
|
|
2
|
+
// worker thread per script), whose only binding is the claim's computer. The script sees `computer` (the surface's
|
|
3
|
+
// script prelude builds it inside the isolate over one host function, __computerCall) and pi-codemode's output helpers
|
|
4
|
+
// (text, image, console); no network, no keys, no timers, no modules, no file of this machine. Each call of the computer
|
|
5
|
+
// goes through the run's hands (Hands.computer), so a person's hold parks and refuses it as it does a per-step tool's.
|
|
6
|
+
//
|
|
7
|
+
// The answer: the script's text and images in the order it made them, then its returned value as JSON (its images'
|
|
8
|
+
// data left out: they are the answer's images); `structured` is the value. A script that threw answers its words, with
|
|
9
|
+
// what it showed before.
|
|
10
|
+
import { CodemodeSandbox } from "@earendil-works/pi-codemode";
|
|
11
|
+
import { COMPUTER_CALL_GLOBAL, scriptPrelude, withoutImageData } from "@parcha/agentrun-computer/surface";
|
|
12
|
+
/** A script's longest run by default, and at most, in ms. */
|
|
13
|
+
export const SCRIPT_DEFAULT_MS = 120_000;
|
|
14
|
+
export const SCRIPT_MAX_MS = 600_000;
|
|
15
|
+
/** The isolate's memory. */
|
|
16
|
+
const SCRIPT_MEMORY_BYTES = 256 * 1024 * 1024;
|
|
17
|
+
/** The settings key a script's computer call is held to, as the run's own tool of that name is: the shell is bash's, a
|
|
18
|
+
* file's write is write's, a file's read, listing or stat is read's. The other ops (looking, acting) are the computer
|
|
19
|
+
* kind's, which the call of computer_script or codemode was already held to. */
|
|
20
|
+
const HELD_AS = Object.freeze({ "shell.run": "bash", "files.write": "write", "files.read": "read", "files.list": "read", "files.stat": "read" });
|
|
21
|
+
/** What a script's `computer.shell` and `computer.files` are held to: the run's gate, which a person's settings (a denied
|
|
22
|
+
* bash, a read-only bash policy, a denied write) reach through the one decision the run's own tools get. A script can't
|
|
23
|
+
* stop to ask, so a call the gate would ask about is refused in words that send the model to the tool itself. Until a
|
|
24
|
+
* gate is installed (the spec installs it once built) every one of those calls is refused. */
|
|
25
|
+
export class ScriptGuard {
|
|
26
|
+
shell;
|
|
27
|
+
#decide;
|
|
28
|
+
/** `shell`: what the run's bash adds under its bash policy (bash-read-only.ts policyEnv, policyPrelude): the environment
|
|
29
|
+
* that locks git's config down, set over any a script gives, and the line that runs git only at the floor version. */
|
|
30
|
+
constructor(shell = { env: {}, prelude: "" }) {
|
|
31
|
+
this.shell = shell;
|
|
32
|
+
}
|
|
33
|
+
/** `op`'s arguments as the computer is sent them: a script's shell command with the policy's safeguards, as the bash
|
|
34
|
+
* tool's own command has them, which no option of the script's overrides. */
|
|
35
|
+
shaped(op, args) {
|
|
36
|
+
if (op !== "shell.run")
|
|
37
|
+
return args;
|
|
38
|
+
const given = (args ?? {});
|
|
39
|
+
const env = { ...(given.env ?? {}), ...this.shell.env };
|
|
40
|
+
return { ...given, ...(Object.keys(env).length > 0 ? { env } : {}), ...(this.shell.prelude !== "" && typeof given.command === "string" ? { command: `${this.shell.prelude}${given.command}` } : {}) };
|
|
41
|
+
}
|
|
42
|
+
install(decide) {
|
|
43
|
+
this.#decide = decide;
|
|
44
|
+
}
|
|
45
|
+
/** Why `op` with `args` may not run now, or undefined when the gate lets it. */
|
|
46
|
+
async refusal(op, args) {
|
|
47
|
+
const tool = HELD_AS[op];
|
|
48
|
+
if (tool === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
if (!this.#decide)
|
|
51
|
+
return `computer call ${op} was not run: this run's tool settings are not attached to its scripts yet`;
|
|
52
|
+
const given = (args ?? {});
|
|
53
|
+
const decision = await this.#decide(tool, tool === "bash" ? { command: given.command, ...(given.cwd !== undefined ? { cwd: given.cwd } : {}) } : { path: given.path });
|
|
54
|
+
if (decision === "allow")
|
|
55
|
+
return undefined;
|
|
56
|
+
if (decision === "ask")
|
|
57
|
+
return `computer call ${op} was not run: this agent's ${tool} setting asks a person first, and a script can't wait for one. Call the ${tool} tool itself, or ask for the setting to be allow.`;
|
|
58
|
+
return `computer call ${op} was not run: ${decision.deny}`;
|
|
59
|
+
}
|
|
60
|
+
/** `call` of the computer's port with a script's computer call held to the gate first: the refusal throws in the
|
|
61
|
+
* script, where its `await` is. */
|
|
62
|
+
async call(op, args, send) {
|
|
63
|
+
const refused = await this.refusal(op, args);
|
|
64
|
+
if (refused !== undefined)
|
|
65
|
+
throw new Error(refused);
|
|
66
|
+
return (await send(this.shaped(op, args ?? {}))).value ?? null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Every image in `value` (`{ type: "image", data }`), in the order withImageData puts data back into them. */
|
|
70
|
+
function imagesIn(value) {
|
|
71
|
+
if (Array.isArray(value))
|
|
72
|
+
return value.flatMap(imagesIn);
|
|
73
|
+
if (value === null || typeof value !== "object")
|
|
74
|
+
return [];
|
|
75
|
+
const record = value;
|
|
76
|
+
if (record.type === "image" && typeof record.data === "string")
|
|
77
|
+
return [{ data: record.data, mimeType: typeof record.mimeType === "string" ? record.mimeType : "image/png" }];
|
|
78
|
+
return Object.values(record).flatMap(imagesIn);
|
|
79
|
+
}
|
|
80
|
+
/** The script's own output and its value, as the model reads them. The images come as the structured value wants them
|
|
81
|
+
* back (withImageData fills its data-less image objects in order): the returned value's own first, then the ones the
|
|
82
|
+
* script showed with image(...), so a returned image keeps its own pixels whatever was shown. */
|
|
83
|
+
function answerOf(output, value) {
|
|
84
|
+
const words = [];
|
|
85
|
+
const shown = [];
|
|
86
|
+
for (const item of output) {
|
|
87
|
+
if (item.type === "text")
|
|
88
|
+
words.push(item.text);
|
|
89
|
+
else
|
|
90
|
+
shown.push({ data: item.data, mimeType: item.mimeType });
|
|
91
|
+
}
|
|
92
|
+
if (value !== undefined)
|
|
93
|
+
words.push(typeof value === "string" ? value : JSON.stringify(withoutImageData(value)));
|
|
94
|
+
return { text: words.join("\n") || "(the script returned nothing and showed nothing)", images: [...imagesIn(value), ...shown] };
|
|
95
|
+
}
|
|
96
|
+
/** computer_script's executor for a computer that is `card`: each script in its own isolate, its computer calls through
|
|
97
|
+
* the call's hands, the shell's and the files' held to `guard`. */
|
|
98
|
+
export function computerScriptExecutor(card, guard) {
|
|
99
|
+
const prelude = scriptPrelude(card);
|
|
100
|
+
return async (args, call) => {
|
|
101
|
+
const { code, timeoutMs } = (args ?? {});
|
|
102
|
+
if (typeof code !== "string" || code.trim() === "")
|
|
103
|
+
return { text: "", error: "computer_script needs code: the body of an async function, with `computer` bound" };
|
|
104
|
+
const port = call.hands.computer;
|
|
105
|
+
if (!port)
|
|
106
|
+
return { text: "", error: "computer_script needs a desktop or a phone computer: this run has none" };
|
|
107
|
+
const limit = typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? Math.min(timeoutMs, SCRIPT_MAX_MS) : SCRIPT_DEFAULT_MS;
|
|
108
|
+
const sandbox = new CodemodeSandbox({
|
|
109
|
+
timeoutMs: limit,
|
|
110
|
+
memoryLimitBytes: SCRIPT_MEMORY_BYTES,
|
|
111
|
+
globals: [{
|
|
112
|
+
name: COMPUTER_CALL_GLOBAL,
|
|
113
|
+
spread: true,
|
|
114
|
+
// The value whole, images and all: a script shows one with image(...). The JSON round trip is the isolate's.
|
|
115
|
+
execute: async (given, context) => {
|
|
116
|
+
const [op, opArgs] = given;
|
|
117
|
+
return (await guard.call(String(op), opArgs, (sent) => port.call(String(op), sent ?? {}, AbortSignal.any([context.signal, ...(call.signal ? [call.signal] : [])]))));
|
|
118
|
+
},
|
|
119
|
+
}],
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
// The prelude is one line, so the script's own line numbers hold.
|
|
123
|
+
const result = await sandbox.execute(`${prelude}\n${code}`, call.signal ? { signal: call.signal } : {});
|
|
124
|
+
if (!result.ok) {
|
|
125
|
+
if (result.error.kind === "aborted" && call.signal?.aborted)
|
|
126
|
+
throw call.signal.reason ?? new Error(result.error.message);
|
|
127
|
+
const shown = answerOf(result.output, undefined);
|
|
128
|
+
const why = result.error.kind === "timeout" ? `the script ran past its ${limit} ms: ${result.error.message}` : result.error.message;
|
|
129
|
+
return { text: result.output.length > 0 ? shown.text : "", error: why, ...(shown.images.length > 0 ? { images: shown.images } : {}) };
|
|
130
|
+
}
|
|
131
|
+
const shown = answerOf(result.output, result.value);
|
|
132
|
+
return { text: shown.text, ...(shown.images.length > 0 ? { images: shown.images } : {}), ...(result.value === undefined ? {} : { structured: withoutImageData(result.value) }) };
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
await sandbox.close();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import type { ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
3
|
import type { ExecutionEnv } from "@earendil-works/pi-durable/env";
|
|
4
4
|
import type { ToolAnswer, ToolCall } from "@parcha/agentrun-kernel/kernel";
|
|
@@ -13,8 +13,10 @@ export { readOnlyWorkspace, SERVER_READS_ONLY, serverRunWorkspace, type ServerRu
|
|
|
13
13
|
export { type LedgerEntry, type ProviderLedger, storeLedger } from "./computer-ledger.js";
|
|
14
14
|
export { type LearningPlace, type LearningWorkspace, learningWorkspace, type LearningWorkspaceOptions } from "./learning-workspace.js";
|
|
15
15
|
export { ARCHIL_MAX_EXEC_S, handsOf, MAX_EXEC_S, processesOf, shellEnv } from "./hands.js";
|
|
16
|
-
export { type RunComputer, type RunHold, runTools, type RunTools, withKindTools } from "./run-tools.js";
|
|
17
|
-
export {
|
|
16
|
+
export { type RunComputer, type RunHold, runTools, type RunTools, type ScriptComputer, withKindTools } from "./run-tools.js";
|
|
17
|
+
export { portOf } from "./computer-ports.js";
|
|
18
|
+
export { computerScriptExecutor, SCRIPT_DEFAULT_MS, SCRIPT_MAX_MS, ScriptGuard, type ScriptDecide } from "./computer-script.js";
|
|
19
|
+
export { COMPUTER_MCP_NAME, computerMcp, type ComputerMcpAnswer, mcpAnswerOf } from "./computer-mcp.js";
|
|
18
20
|
export { type ClaimSide, computerReadiness, type ComputerSetting, type KindRegistry, type LaunchedComputer, type Port, resolveComputer, type ResolvedComputer, runShellOf, type ShellPlace, shellPlaceOf, type StartedComputer, } from "./resolve-computer.js";
|
|
19
21
|
export { computerProviderFactories, computerProviderMakers, type ProviderLoad } from "./computer-providers.js";
|
|
20
22
|
export { claimComputer, claimKinds, type ComputerDeps, computerDepsFrom, type ComputerDepsOptions, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, type DockerComputerOptions, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
|
package/dist/workspace/index.js
CHANGED
|
@@ -15,7 +15,9 @@ export { storeLedger } from "./computer-ledger.js";
|
|
|
15
15
|
export { learningWorkspace } from "./learning-workspace.js";
|
|
16
16
|
export { ARCHIL_MAX_EXEC_S, handsOf, MAX_EXEC_S, processesOf, shellEnv } from "./hands.js";
|
|
17
17
|
export { runTools, withKindTools } from "./run-tools.js";
|
|
18
|
-
export {
|
|
18
|
+
export { portOf } from "./computer-ports.js";
|
|
19
|
+
export { computerScriptExecutor, SCRIPT_DEFAULT_MS, SCRIPT_MAX_MS, ScriptGuard } from "./computer-script.js";
|
|
20
|
+
export { COMPUTER_MCP_NAME, computerMcp, mcpAnswerOf } from "./computer-mcp.js";
|
|
19
21
|
export { computerReadiness, resolveComputer, runShellOf, shellPlaceOf, } from "./resolve-computer.js";
|
|
20
22
|
export { computerProviderFactories, computerProviderMakers } from "./computer-providers.js";
|
|
21
23
|
export { claimComputer, claimKinds, computerDepsFrom, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
|
|
@@ -1,106 +1,141 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: desktop-computer
|
|
3
|
-
description: Use a desktop computer through
|
|
3
|
+
description: Use a desktop computer (a Mac, or a Linux desktop) through computer_observe, computer_act, computer_screenshot and computer_script. It covers reading an app's elements, acting on them by ref, running known steps as one script, checking what happened, recovering, and reading the computer's refusals. Use when a run has a desktop and the task needs its apps or its windows.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Using a desktop
|
|
7
7
|
|
|
8
|
-
The run has a desktop
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
The run has a desktop, rented while the run lives. You read an app's window as a list of its elements and act on
|
|
9
|
+
them by their refs, the way an accessibility tool does. Where the desktop can't list elements (no `ui` group), you see
|
|
10
|
+
it through screenshots and act at their pixels. The tools say which one you have.
|
|
11
11
|
|
|
12
12
|
## The tools
|
|
13
13
|
|
|
14
|
-
**`
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
14
|
+
**`computer_observe` `{app?, image?, full?}`** shows an app's window (the one in front when you name none) as compact
|
|
15
|
+
lines, one per element:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
state s3 · com.apple.Notes "Notes" · window "Groceries" 900×700 pt
|
|
19
|
+
@e1 window "Groceries"
|
|
20
|
+
@e4 textbox "Title" = "Groceries" [focused]
|
|
21
|
+
@e7 button "Save"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Each line is a ref (`@e7`), a role, a name, a value after `=`, what else the element says in parentheses (a help tag)
|
|
25
|
+
and flags in brackets. A child is indented under its parent. When an app draws its own window, the computer can't
|
|
26
|
+
list its elements: the outline says so, the window's picture comes with it, and you act at points in that picture. The head line names the **state** (`s3`). `image: true` adds the window's picture, which you need only for
|
|
27
|
+
what elements can't tell you: layout, colours, images. `full: true` lists every element, not only the named or
|
|
28
|
+
actionable ones.
|
|
29
|
+
|
|
30
|
+
**`computer_act` `{app?, steps, state?, expect?, observe?}`** runs steps in order:
|
|
31
|
+
|
|
32
|
+
| Step | What it does |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `{press: "@e7"}` | The element's own action (a button's press, a menu item's pick). The surest step. |
|
|
35
|
+
| `{set: "@e4", value: "Milk"}` | Sets a field's text, a slider's value, a switch's `"on"` or `"off"`. |
|
|
36
|
+
| `{click: "@e7"}` or `{click: [x, y]}` | A click on the element, or at a point; `button: "right"`, `count: 2`. |
|
|
37
|
+
| `{type: "text", into?: "@e4"}` | Types, into the element when named, else where the focus is. |
|
|
38
|
+
| `{key: "super+s"}` | A key or a chord: names or one character, joined by `+` (`enter`, `ctrl+shift+t`). |
|
|
39
|
+
| `{scroll: "@e9", dy: 300}` | Scrolls by points: `dy` above 0 shows what is below. |
|
|
40
|
+
| `{drag: [[x1, y1], [x2, y2]]}` | Presses at the first point, lets go at the last. |
|
|
41
|
+
| `{perform: "@e7", action: "AXShowMenu"}` | One of the element's own platform actions. |
|
|
42
|
+
|
|
43
|
+
Each step answers its **route** (`semantic`: through the element; `page`: through the page; `background`: an event to
|
|
44
|
+
the app; `foreground`: the real pointer and keys) and whether a readback **verified** it. The answer ends with whether
|
|
45
|
+
the window changed and its new state. `expect: {text: "Saved"}` waits after the steps until that text shows (`gone:
|
|
46
|
+
true`: until it is gone); no steps and an expect is a wait. `observe: true` adds the new outline: one call instead of
|
|
47
|
+
two. The first refused step stops the rest.
|
|
48
|
+
|
|
49
|
+
Prefer refs. A step at a point (`[x, y]`, in the window's points) is read against a state, the last one you observed
|
|
50
|
+
unless you name another, and is refused as **stale** once the window moved or redrew under it: observe again and use
|
|
51
|
+
the new state.
|
|
52
|
+
|
|
53
|
+
**`computer_screenshot` `{region?}`** is the whole screen, or `region: [x, y, w, h]` of it, in screen pixels.
|
|
54
|
+
|
|
55
|
+
**`computer_script` `{code}`** runs JavaScript in an isolate whose only binding is `computer`. Its tool description
|
|
56
|
+
gives the `computer` object's types for this desktop. The body is an async function: `await` the calls and `return`
|
|
57
|
+
what you need; `text(...)` and `image(...)` show words and pictures beside the value.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const notes = computer.app("com.apple.Notes");
|
|
61
|
+
await notes.observe();
|
|
62
|
+
const title = notes.find({ role: "textbox", text: "Title" })[0];
|
|
63
|
+
await notes.set(title.ref, "Groceries");
|
|
64
|
+
const saved = await notes.key("super+s", { expect: { text: "Saved" } });
|
|
65
|
+
return { saved: saved.expect, state: saved.state };
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Your harness's own code mode.** pi's `codemode` binds `computer` as computer_script does. Codex's `exec` does not:
|
|
69
|
+
there, call the tools, each answering its value as JSON text, or call `tools.computer_script` with the code above.
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
const notes = JSON.parse(await tools.computer_observe({ app: "com.apple.Notes" }));
|
|
73
|
+
const title = notes.elements.find((node) => node.role === "textbox" && node.name === "Title");
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**The screen itself.** Prefer an app's steps. A script's `computer.input.act([...])` is the screen-level way out, at
|
|
77
|
+
screenshot pixels (`computer.screen.shot()`), for what one app's window can't reach: a drag from one app to another (a
|
|
78
|
+
file from Finder into a Mail message), or anything outside every window.
|
|
79
|
+
|
|
80
|
+
## How to work: observe, then act by ref, then check
|
|
81
|
+
|
|
82
|
+
1. **Observe** the app first. Find your target by its name and role, and note its ref.
|
|
83
|
+
2. **Act** by ref. Several steps you are sure of go in one `computer_act`: set a field, press a button. End the call
|
|
84
|
+
where you need to see the result.
|
|
85
|
+
3. **Check** what the answer says: each step's route and verified, `changed`, and the expect's `met` or `unmet`. A
|
|
86
|
+
step that ran is not proof the app did what you meant. When the answer doesn't settle it, observe again.
|
|
87
|
+
4. **Recover.** A refused step says why. `stale`: observe again, then act on the new refs or state. Nothing changed:
|
|
88
|
+
a dialog may be in front, or the element may be disabled (`[disabled]`). Try once more another way (`press`
|
|
89
|
+
instead of `click`, the keyboard instead of the pointer, a menu instead of a button), then change approach.
|
|
90
|
+
|
|
91
|
+
## When to write a script
|
|
92
|
+
|
|
93
|
+
A script is one call where tools would be many. Use one when:
|
|
94
|
+
|
|
95
|
+
- **You know the steps.** A form you have seen, a menu path you know, a sequence you have done once: run it as one
|
|
96
|
+
script with an `expect` at the end, instead of one act per step.
|
|
97
|
+
- **You need a few facts out of a big window.** Observe and `find()` inside the script, and return only what the next
|
|
98
|
+
decision needs: a ref, a value, a count, three rows. Never return whole observations: their elements are long, and
|
|
99
|
+
you pay for every line you read. `find({ role, text, id })`: a role is the same name on every OS, a text matches
|
|
100
|
+
the name, the value or what the parentheses say, and an id is the app's own for the element.
|
|
101
|
+
- **You loop.** Scroll a list until a row shows, or read each row of a table.
|
|
102
|
+
|
|
103
|
+
Don't script steps you have not seen yet. When you are unsure what is on the screen, observe before you act, by tool
|
|
104
|
+
or inside the script, and decide from what it shows.
|
|
105
|
+
|
|
106
|
+
## Without the ui group (a Linux desktop)
|
|
107
|
+
|
|
108
|
+
The desktop lists no elements. `computer_observe` answers a screenshot of the whole screen, and `computer_act`'s steps
|
|
109
|
+
are raw input at its pixels: `click`, `type`, `key`, `scroll` and `drag` at points, with no refs, no states and no
|
|
110
|
+
expect. `press`, `set` and `perform` are refused. Take the points from the latest screenshot, aim at the middle of a
|
|
111
|
+
target, and take another screenshot to see what your steps did. Click a field before typing into it.
|
|
53
112
|
|
|
54
113
|
## Habits that work
|
|
55
114
|
|
|
56
|
-
- **
|
|
57
|
-
|
|
58
|
-
- **
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- `alt` + `f4` closes a window.
|
|
63
|
-
- `enter` confirms.
|
|
64
|
-
Shortcuts don't depend on where things are drawn.
|
|
65
|
-
- **Scroll where the content is.** A scroll goes to what is under its point. Put `at` on the list or the page you mean,
|
|
66
|
-
not on a sidebar.
|
|
67
|
-
- **Wait by looking.** If a page or an app is loading, take another screenshot before you act. Don't repeat a click
|
|
68
|
-
while the screen is still changing: the second click may land on the new screen.
|
|
69
|
-
- **Windows.** If the window you need is behind another one, click its visible part or its taskbar entry, or use
|
|
70
|
-
`alt` + `tab`. Then look again to check that it is in front.
|
|
71
|
-
- **Dialogs first.** A dialog, a notice or a cookie banner blocks what is under it. Read it, answer it or close it,
|
|
72
|
-
then go on.
|
|
115
|
+
- **The keyboard is exact.** `super+a` (Mac) or `ctrl+a` selects all, `escape` closes a menu or a dialog, `enter`
|
|
116
|
+
confirms. A chord doesn't depend on where things are drawn.
|
|
117
|
+
- **Dialogs first.** A sheet, an alert or a permission prompt blocks the window under it: answer it, then go on.
|
|
118
|
+
- **Wait by expecting.** Put an `expect` on the step that starts something slow, rather than observing in a loop.
|
|
119
|
+
- **The right app.** Name the app (`app: "com.apple.Notes"`) when more than one is open. In a script,
|
|
120
|
+
`computer.apps.open(id)` opens one, and `computer.app(id)` binds it.
|
|
73
121
|
|
|
74
122
|
## When a tool answers an error
|
|
75
123
|
|
|
76
|
-
Errors come in words, and they say what was wrong. Read them,
|
|
124
|
+
Errors come in words, and they say what was wrong. Read them, act on what they say, and don't repeat the same call.
|
|
77
125
|
|
|
78
|
-
- **
|
|
79
|
-
|
|
80
|
-
- **A
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- **"The person had this desktop"**: a person took the desktop over and has handed it back, and your input was not
|
|
84
|
-
done. The screen may have changed, so take a screenshot before you act again.
|
|
85
|
-
- **The computer is gone or unreachable**: the run's desktop ended (its time ran out, or it was released). Don't keep
|
|
86
|
-
calling. Say what you finished and what you could not.
|
|
87
|
-
|
|
88
|
-
## What not to do
|
|
89
|
-
|
|
90
|
-
- Don't guess coordinates from memory of another screen or another resolution. Use this screenshot's pixels.
|
|
91
|
-
- Don't send a long batch blind across screens you have not seen. One wrong click early sends the rest astray.
|
|
92
|
-
- Don't take screenshots in a loop just to wait. Each one takes time, and the desktop's time is limited and may be
|
|
93
|
-
billed.
|
|
94
|
-
- Don't type secrets you were not given for this task, and don't change the computer's settings beyond what the task
|
|
95
|
-
needs.
|
|
126
|
+
- **"The person had this computer"**: a person took the desktop over and has handed it back, and your act was not
|
|
127
|
+
done. The screen may have changed: observe again before you act.
|
|
128
|
+
- **A step refused as `unsupported`** names what this desktop can't do. Use another step.
|
|
129
|
+
- **The computer is gone or unreachable**: the run's desktop ended. Don't keep calling. Say what you finished and what
|
|
130
|
+
you could not.
|
|
96
131
|
|
|
97
132
|
## Time and cost
|
|
98
133
|
|
|
99
|
-
The desktop lives only for the run's lifetime
|
|
100
|
-
|
|
101
|
-
|
|
134
|
+
The desktop lives only for the run's lifetime and may be billed while it runs. Make a short plan first: which app,
|
|
135
|
+
which steps, what will show success. Script what is certain, observe what is not, and stop once the task is done or
|
|
136
|
+
can't be done. Don't type secrets you were not given for this task.
|
|
102
137
|
|
|
103
138
|
## Finishing
|
|
104
139
|
|
|
105
|
-
Before you call the task done,
|
|
106
|
-
and name anything you could not finish or check.
|
|
140
|
+
Before you call the task done, check the result: an observe that shows it, or a screenshot when it is visual. Say what
|
|
141
|
+
it shows in your answer, and name anything you could not finish or check.
|