@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.31
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 +238 -0
- package/README.md +739 -116
- package/dist/adapters.d.ts +35 -6
- package/dist/adapters.js +152 -26
- package/dist/agents.d.ts +18 -7
- package/dist/agents.js +19 -10
- package/dist/app.js +101 -26
- package/dist/background.d.ts +29 -0
- package/dist/background.js +397 -0
- package/dist/box-egress-vm.d.ts +125 -0
- package/dist/box-egress-vm.js +350 -0
- package/dist/box-egress.d.ts +99 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +1 -1
- package/dist/box-image.js +9 -7
- package/dist/box-relay-vm.d.ts +84 -0
- package/dist/box-relay-vm.js +410 -0
- package/dist/box-relay.d.ts +8 -5
- package/dist/box-relay.js +14 -9
- package/dist/boxes.d.ts +28 -5
- package/dist/boxes.js +44 -18
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +130 -21
- package/dist/cap.js +339 -67
- package/dist/cli.js +30 -4
- package/dist/coding-tools.d.ts +7 -3
- package/dist/coding-tools.js +16 -10
- package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
- package/dist/console/assets/index-CnJBf7Lc.js +486 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-rows.d.ts +11 -3
- package/dist/decision-rows.js +18 -11
- package/dist/decisions.d.ts +3 -3
- package/dist/decisions.js +4 -3
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -2
- package/dist/files.d.ts +9 -1
- package/dist/files.js +10 -2
- package/dist/grade.d.ts +11 -11
- package/dist/grade.js +43 -55
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +7 -5
- package/dist/graph-view.js +10 -3
- package/dist/harness-app.d.ts +4 -2
- package/dist/harness-app.js +110 -19
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +4 -1
- package/dist/harness.js +5 -2
- package/dist/host-check.d.ts +12 -0
- package/dist/host-check.js +34 -0
- package/dist/host-tools.d.ts +12 -2
- package/dist/host-tools.js +26 -12
- package/dist/host.js +6 -2
- package/dist/hosted-search.js +5 -1
- package/dist/import.d.ts +2 -2
- package/dist/import.js +4 -3
- package/dist/key-check.d.ts +3 -2
- package/dist/key-check.js +7 -3
- package/dist/key-refusal.js +8 -4
- package/dist/key-words.d.ts +37 -0
- package/dist/key-words.js +40 -0
- package/dist/learn/check.d.ts +10 -1
- package/dist/learn/check.js +19 -1
- package/dist/learn/grade.d.ts +6 -2
- package/dist/learn/grade.js +28 -14
- package/dist/learn/index.d.ts +3 -3
- package/dist/learn/index.js +3 -3
- package/dist/learn/notes.js +2 -1
- package/dist/learn/reflect.d.ts +2 -2
- package/dist/learn/reflect.js +53 -5
- package/dist/learn/secrets.js +28 -8
- package/dist/learn/skills.d.ts +19 -4
- package/dist/learn/skills.js +95 -6
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +30 -1
- package/dist/learning-routes.js +173 -19
- package/dist/learning-run.d.ts +8 -6
- package/dist/learning-run.js +70 -27
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +34 -13
- package/dist/learning.d.ts +52 -3
- package/dist/learning.js +204 -4
- package/dist/mcp-gateway.d.ts +96 -0
- package/dist/mcp-gateway.js +408 -0
- package/dist/mcp-meta.d.ts +17 -0
- package/dist/mcp-meta.js +38 -0
- package/dist/mcp-servers.d.ts +33 -9
- package/dist/mcp-servers.js +58 -10
- package/dist/mcp.js +5 -5
- package/dist/model.d.ts +13 -11
- package/dist/model.js +11 -10
- package/dist/openapi/agentrun-v2.openapi.json +1 -0
- package/dist/openapi.js +407 -54
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -0
- package/dist/paid-calls.d.ts +5 -1
- package/dist/paid-calls.js +1 -1
- package/dist/pause.d.ts +2 -0
- package/dist/place.d.ts +29 -5
- package/dist/place.js +51 -11
- package/dist/print.d.ts +7 -0
- package/dist/print.js +13 -0
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +38 -8
- package/dist/request-start.d.ts +12 -4
- package/dist/request-start.js +139 -15
- package/dist/run-box.d.ts +56 -4
- package/dist/run-box.js +183 -23
- package/dist/runnable.d.ts +13 -3
- package/dist/runnable.js +63 -6
- package/dist/runs.d.ts +266 -37
- package/dist/runs.js +884 -90
- package/dist/secrets.d.ts +27 -0
- package/dist/secrets.js +38 -2
- package/dist/server.d.ts +141 -36
- package/dist/server.js +562 -118
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +16 -4
- package/dist/skills.js +35 -7
- package/dist/stats.d.ts +7 -2
- package/dist/stats.js +28 -7
- package/dist/tool-gate.d.ts +281 -0
- package/dist/tool-gate.js +585 -0
- package/dist/tool-keys.d.ts +48 -11
- package/dist/tool-keys.js +46 -8
- package/dist/tool-plane.d.ts +116 -27
- package/dist/tool-plane.js +232 -50
- package/dist/tools.d.ts +69 -14
- package/dist/tools.js +148 -26
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +3 -2
- package/dist/turn-end.js +3 -2
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +11 -2
- package/dist/web-fetch.js +3 -3
- package/dist/webhooks.d.ts +11 -4
- package/dist/webhooks.js +17 -1
- package/launcher/agentrun-serve +1 -1
- package/package.json +16 -14
- package/dist/console/assets/index-BN7oVcO4.js +0 -445
- package/dist/console/assets/index-By-jkqki.css +0 -1
package/dist/run-box.d.ts
CHANGED
|
@@ -2,9 +2,16 @@ import type { Context } from "@earendil-works/chord";
|
|
|
2
2
|
import type { ExecutionEnv } from "@earendil-works/pi-durable/env";
|
|
3
3
|
import type { BoxProvider, BoxSpec } from "@parcha/pi-transport";
|
|
4
4
|
import type { PullReceipt } from "@parcha/pi-transport/sync";
|
|
5
|
+
import { type BoxEgress, type DockerNetwork, egressBlockedBy } from "./box-egress.js";
|
|
5
6
|
import { type Place } from "./place.js";
|
|
6
7
|
/** The label a run's box carries: the run's id. */
|
|
7
8
|
export declare const RUN_LABEL = "agentrun.run";
|
|
9
|
+
/** And, on a box made with a network list, this one: the list's hash (netLabelOf). A box with none carries no such label,
|
|
10
|
+
* so its `docker run` is as it was. */
|
|
11
|
+
export declare const NET_LABEL = "agentrun.net";
|
|
12
|
+
/** The network label's value for a list: the same hosts give the same label, in whatever order and case the setting
|
|
13
|
+
* names them, each once. */
|
|
14
|
+
export declare const netLabelOf: (allow: readonly string[]) => string;
|
|
8
15
|
/** And this one, the same on every run's box, which the start's sweep lists them by. */
|
|
9
16
|
export declare const KIND_LABEL = "agentrun.box";
|
|
10
17
|
/** The whole environment of a box's programs: a constant, never this process's. */
|
|
@@ -36,6 +43,22 @@ export type BoxLimits = {
|
|
|
36
43
|
* that every create would fail on (less than a 1 ms quota, less memory than Docker gives, more processes than the kernel
|
|
37
44
|
* allows), throws, naming its setting: the start checks them (startServe), so no run meets one. */
|
|
38
45
|
export declare function boxLimitsOf(env: NodeJS.ProcessEnv): BoxLimits;
|
|
46
|
+
/** The setting that names the hosts a box may reach: a comma list of hosts, each a name or `*.` and a name, which
|
|
47
|
+
* replaces the default list; `none` for no network at all. Unset or empty, the default. */
|
|
48
|
+
export declare const BOX_ALLOW_ENV = "AGENTRUN_BOX_ALLOW";
|
|
49
|
+
/** The hosts a box reaches when the setting names none: the package registries pip and npm (and yarn) install from, and
|
|
50
|
+
* GitHub for a clone or an archive. */
|
|
51
|
+
export declare const DEFAULT_BOX_ALLOW: readonly string[];
|
|
52
|
+
/** The most hosts the list may hold: Daytona's own limit on a sandbox's domain list. */
|
|
53
|
+
export declare const MAX_BOX_ALLOW = 100;
|
|
54
|
+
/** The hosts a box may reach, from `env`'s AGENTRUN_BOX_ALLOW: its list, lower-cased, each host once; the default list when
|
|
55
|
+
* unset or empty; `none` for no network. `*`, an IP address, a CIDR, a port, a URL, or more than 100 hosts throws, saying
|
|
56
|
+
* what the setting takes: the start checks it (startServe), so no run meets one. */
|
|
57
|
+
export declare function boxAllowOf(env: NodeJS.ProcessEnv): readonly string[] | "none";
|
|
58
|
+
/** What a server's Docker boxes reach, resolved once at its start: the setting's list (boxAllowOf) where egressBlockedBy
|
|
59
|
+
* (box-egress.ts) finds the daemon is this Linux machine's own, else none with the reason; `none` from the setting, with
|
|
60
|
+
* it as the reason. */
|
|
61
|
+
export declare function boxNetworkOf(env: NodeJS.ProcessEnv, options?: Parameters<typeof egressBlockedBy>[1]): Promise<DockerNetwork>;
|
|
39
62
|
/** Under `--faux` only: a module whose default export, given the data root, is the provider runs' boxes come from in
|
|
40
63
|
* place of Docker (the tests' faux box). */
|
|
41
64
|
export declare const FAUX_BOX_ENV = "AGENTRUN_SERVE_FAUX_BOX";
|
|
@@ -54,9 +77,12 @@ export declare function mountSource(root: string, source: string): Promise<strin
|
|
|
54
77
|
/** Every mount a run's box gets, each through mountSource: its work/ only, read-write, at BOX_WORK. A run's home joins
|
|
55
78
|
* this list (read-only parts included) when it comes; nothing else of the data root does. */
|
|
56
79
|
export declare function boxMounts(root: string, runDir: string, place: Place): Promise<Mount[]>;
|
|
57
|
-
/** The provider runs' boxes come from,
|
|
80
|
+
/** The provider runs' boxes come from, what a create of its box waits on first (`ready`, run-box below), and, for a box
|
|
81
|
+
* that reaches the server's host list, where it finds its egress proxy (`egress`, box-egress.ts). */
|
|
58
82
|
export type RunBoxes = BoxProvider & {
|
|
59
83
|
ready?: BoxReady;
|
|
84
|
+
egress?: BoxEgress;
|
|
85
|
+
net?: string;
|
|
60
86
|
};
|
|
61
87
|
/** The provider runs' boxes come from: under `--faux` with a faux box, its module's; else Docker on this machine, run as
|
|
62
88
|
* this process's user (serve's: a run's process is its child), so what a box writes in work/ stays serve's, within the
|
|
@@ -94,13 +120,39 @@ export declare function runBox(given: BoxSource | (() => Promise<RunBoxes>), run
|
|
|
94
120
|
dir: string;
|
|
95
121
|
place: Place;
|
|
96
122
|
}): RunBox;
|
|
123
|
+
/** A remote box's limits, where its provider takes them (the VM box: CPUs and memory, from the same settings as a Docker
|
|
124
|
+
* box's, boxLimitsOf). */
|
|
125
|
+
export type RemoteLimits = {
|
|
126
|
+
cpus?: number;
|
|
127
|
+
memoryMb?: number;
|
|
128
|
+
};
|
|
129
|
+
/** A Docker size (boxLimitsOf's memory) in MiB, the fraction dropped. */
|
|
130
|
+
export declare const memoryMbOf: (memory: string) => number;
|
|
97
131
|
/** The server's side of a remote box: run `run`'s box, found by its label or made, with its work/ seeded once (its mark
|
|
98
|
-
* says so); its id, and whether it was made now. A
|
|
99
|
-
* a
|
|
132
|
+
* says so); its id, and whether it was made now. A box is made with the host list `allow` names, or with no network when
|
|
133
|
+
* it is `none`; a create the provider refuses for its list (NO_LIST) is said to `onNoList` at once, with its refusal's
|
|
134
|
+
* code and words (so a closed box or a seed that then fails leaves it said), and made again with no network, never open.
|
|
135
|
+
* A found box is kept when it has no network, or the list asked (the same hosts, in any order, as its provider reads
|
|
136
|
+
* them); any other (open, unknown, another list or one it does not say, or a list when `none` was asked) is copied back
|
|
137
|
+
* whole, then destroyed and made again, so a narrower list holds after a restart. One whose copy back fails or is not
|
|
138
|
+
* whole is kept, and the call fails. A box whose seed fails is destroyed, and the call fails. */
|
|
139
|
+
/** What ensureRemoteBox takes beyond the run: the wake of a box Daytona stopped, the hosts the box may reach (`none` for
|
|
140
|
+
* none), who hears a refused list, and the copy back a found box gets before it is replaced (pullRemoteBox). */
|
|
141
|
+
export type RemoteBoxOptions = {
|
|
142
|
+
wake?: () => Promise<number>;
|
|
143
|
+
allow?: readonly string[] | "none";
|
|
144
|
+
onNoList?: (code: string, message: string) => void;
|
|
145
|
+
pull?: (boxes: BoxProvider, run: {
|
|
146
|
+
id: string;
|
|
147
|
+
dir: string;
|
|
148
|
+
}, context: Context, wake?: () => Promise<number>) => Promise<unknown>;
|
|
149
|
+
/** The box's limits, where its provider takes them (remoteSpec). */
|
|
150
|
+
limits?: RemoteLimits;
|
|
151
|
+
};
|
|
100
152
|
export declare function ensureRemoteBox(boxes: BoxProvider, run: {
|
|
101
153
|
id: string;
|
|
102
154
|
dir: string;
|
|
103
|
-
}, context: Context,
|
|
155
|
+
}, context: Context, options?: RemoteBoxOptions): Promise<{
|
|
104
156
|
id: string;
|
|
105
157
|
made: boolean;
|
|
106
158
|
}>;
|
package/dist/run-box.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// is the record (a bound box's read, write and edit run on this machine: bound-files.ts). A run's process that starts
|
|
3
3
|
// again finds it by that label and first kills the commands the process before it left running. Serve destroys it at
|
|
4
4
|
// every settle (a cancel included) and at archive, and its start sweeps the boxes of runs that have ended. A box gets the
|
|
5
|
-
// run's work/ only, at BOX_WORK, a fixed environment (never this process's, so no key or token enters it), no network
|
|
5
|
+
// run's work/ only, at BOX_WORK, a fixed environment (never this process's, so no key or token enters it), no network
|
|
6
|
+
// (or, on Docker with the server's host list set, those hosts alone, through this process's egress proxy: box-egress.ts),
|
|
6
7
|
// and limits on its CPUs, memory and processes. pi-transport is an optional peer of this package: it is loaded only for a
|
|
7
8
|
// run whose place is a box.
|
|
8
9
|
//
|
|
@@ -10,19 +11,30 @@
|
|
|
10
11
|
// cannot bind work/, and its key is the server's alone. The server makes it (through the box relay, box-relay.ts), seeds
|
|
11
12
|
// it with work/, pulls work/ back at each turn's end and once more before the run's end is recorded, and destroys it
|
|
12
13
|
// after that pull; the run's process reaches it through the relay, which holds the key. What the run's own host tools
|
|
13
|
-
// file in work/ meanwhile (writeInWork) is copied into the box too, so its tools read it.
|
|
14
|
+
// file in work/ meanwhile (writeInWork) is copied into the box too, so its tools read it. The VM box is remote the same
|
|
15
|
+
// way: the server makes, seeds, pulls and ends it with its own client, and the run's process runs pi-transport's VM
|
|
16
|
+
// provider over the relay's VM half (box-relay-vm.ts), which holds the client and the token. It has no network.
|
|
14
17
|
import { createHash } from "node:crypto";
|
|
15
18
|
import { appendFile, lstat, readFile, realpath } from "node:fs/promises";
|
|
16
19
|
import { isAbsolute, join, posix, relative, sep } from "node:path";
|
|
17
20
|
import { pathToFileURL } from "node:url";
|
|
18
21
|
import { BACKGROUND_CONTEXT as BACKGROUND } from "@earendil-works/chord/context";
|
|
22
|
+
import { EGRESS_MOUNT, egressBlockedBy, forwarderStart, hostEgress, PROXY_ENV, relayFailed, runBoxAllowOf } from "./box-egress.js";
|
|
23
|
+
import { runBoxVolumeOf, vmDocker, vmEgress } from "./box-egress-vm.js";
|
|
19
24
|
import { awaitImage, boxImageOf } from "./box-image.js";
|
|
20
25
|
import { RELAYED_KEY, relayedBox, relayFetch } from "./box-relay.js";
|
|
26
|
+
import { VM_PROVIDER } from "./boxes.js";
|
|
21
27
|
import { readJson, writeDurable } from "./files.js";
|
|
22
28
|
import { FAUX_ENV } from "./model.js";
|
|
23
29
|
import { agentWorkDir, BOX_WORK } from "./place.js";
|
|
24
30
|
/** The label a run's box carries: the run's id. */
|
|
25
31
|
export const RUN_LABEL = "agentrun.run";
|
|
32
|
+
/** And, on a box made with a network list, this one: the list's hash (netLabelOf). A box with none carries no such label,
|
|
33
|
+
* so its `docker run` is as it was. */
|
|
34
|
+
export const NET_LABEL = "agentrun.net";
|
|
35
|
+
/** The network label's value for a list: the same hosts give the same label, in whatever order and case the setting
|
|
36
|
+
* names them, each once. */
|
|
37
|
+
export const netLabelOf = (allow) => createHash("sha256").update([...new Set(allow.map((host) => host.toLowerCase()))].sort().join(",")).digest("hex").slice(0, 16);
|
|
26
38
|
/** And this one, the same on every run's box, which the start's sweep lists them by. */
|
|
27
39
|
export const KIND_LABEL = "agentrun.box";
|
|
28
40
|
/** The whole environment of a box's programs: a constant, never this process's. */
|
|
@@ -76,6 +88,54 @@ export function boxLimitsOf(env) {
|
|
|
76
88
|
const pids = read(BOX_PIDS_ENV, "a whole number from 1 to 4194304, such as 1024", (value) => /^\d+$/.test(value) && Number(value) >= 1 && Number(value) <= MAX_BOX_PIDS);
|
|
77
89
|
return { cpus: cpus === undefined ? DEFAULT_BOX_CPUS : Number(cpus), memory: memory ?? DEFAULT_BOX_MEMORY, pidsLimit: pids === undefined ? DEFAULT_BOX_PIDS : Number(pids) };
|
|
78
90
|
}
|
|
91
|
+
/** The setting that names the hosts a box may reach: a comma list of hosts, each a name or `*.` and a name, which
|
|
92
|
+
* replaces the default list; `none` for no network at all. Unset or empty, the default. */
|
|
93
|
+
export const BOX_ALLOW_ENV = "AGENTRUN_BOX_ALLOW";
|
|
94
|
+
/** The hosts a box reaches when the setting names none: the package registries pip and npm (and yarn) install from, and
|
|
95
|
+
* GitHub for a clone or an archive. */
|
|
96
|
+
export const DEFAULT_BOX_ALLOW = Object.freeze(["pypi.org", "files.pythonhosted.org", "registry.npmjs.org", "registry.yarnpkg.com", "github.com", "codeload.github.com"]);
|
|
97
|
+
/** The most hosts the list may hold: Daytona's own limit on a sandbox's domain list. */
|
|
98
|
+
export const MAX_BOX_ALLOW = 100;
|
|
99
|
+
/** A host name, or `*.` and one: letters, digits and hyphens in dotted labels, the last one starting with a letter, so no
|
|
100
|
+
* IP address is one. */
|
|
101
|
+
const ALLOW_HOST = /^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
102
|
+
/** The hosts a box may reach, from `env`'s AGENTRUN_BOX_ALLOW: its list, lower-cased, each host once; the default list when
|
|
103
|
+
* unset or empty; `none` for no network. `*`, an IP address, a CIDR, a port, a URL, or more than 100 hosts throws, saying
|
|
104
|
+
* what the setting takes: the start checks it (startServe), so no run meets one. */
|
|
105
|
+
export function boxAllowOf(env) {
|
|
106
|
+
const value = (env[BOX_ALLOW_ENV] ?? "").trim();
|
|
107
|
+
if (!value)
|
|
108
|
+
return DEFAULT_BOX_ALLOW;
|
|
109
|
+
if (value.toLowerCase() === "none")
|
|
110
|
+
return "none";
|
|
111
|
+
const hosts = [...new Set(value.split(",").map((host) => host.trim().toLowerCase()).filter(Boolean))];
|
|
112
|
+
const takes = "a comma list of host names (such as pypi.org or *.pythonhosted.org), or none for no network";
|
|
113
|
+
const bad = hosts.find((host) => !ALLOW_HOST.test(host));
|
|
114
|
+
if (bad !== undefined)
|
|
115
|
+
throw new Error(`${BOX_ALLOW_ENV} is ${takes}: ${JSON.stringify(bad)} is not a host name${bad === "*" ? " (a box never reaches every host)" : ""}`);
|
|
116
|
+
if (hosts.length === 0)
|
|
117
|
+
throw new Error(`${BOX_ALLOW_ENV} is ${takes}; it is ${JSON.stringify(value)}`);
|
|
118
|
+
if (hosts.length > MAX_BOX_ALLOW)
|
|
119
|
+
throw new Error(`${BOX_ALLOW_ENV} names ${hosts.length} hosts; it takes at most ${MAX_BOX_ALLOW}`);
|
|
120
|
+
return Object.freeze(hosts);
|
|
121
|
+
}
|
|
122
|
+
/** What a server's Docker boxes reach, resolved once at its start: the setting's list (boxAllowOf) where egressBlockedBy
|
|
123
|
+
* (box-egress.ts) finds the daemon is this Linux machine's own, else none with the reason; `none` from the setting, with
|
|
124
|
+
* it as the reason. */
|
|
125
|
+
export async function boxNetworkOf(env, options = {}) {
|
|
126
|
+
const allow = boxAllowOf(env);
|
|
127
|
+
if (allow === "none")
|
|
128
|
+
return { allow: "none", reason: `${BOX_ALLOW_ENV} is none` };
|
|
129
|
+
const blocked = await egressBlockedBy(env, options);
|
|
130
|
+
if (!blocked)
|
|
131
|
+
return { allow };
|
|
132
|
+
// On a Mac only: a Docker that docker info names as a VM runtime this server knows gets the proxy container
|
|
133
|
+
// (box-egress-vm.ts); any other stays none, saying why.
|
|
134
|
+
if ((options.platform ?? process.platform) !== "darwin")
|
|
135
|
+
return { allow: "none", reason: blocked };
|
|
136
|
+
const vm = await vmDocker(env, { ...(options.platform ? { platform: options.platform } : {}), ...(options.kernel ? { kernel: options.kernel } : {}), ...(options.timeoutMs ? { timeoutMs: options.timeoutMs } : {}) });
|
|
137
|
+
return "runtime" in vm ? { allow, vm: vm.runtime } : { allow: "none", reason: vm.reason };
|
|
138
|
+
}
|
|
79
139
|
/** Under `--faux` only: a module whose default export, given the data root, is the provider runs' boxes come from in
|
|
80
140
|
* place of Docker (the tests' faux box). */
|
|
81
141
|
export const FAUX_BOX_ENV = "AGENTRUN_SERVE_FAUX_BOX";
|
|
@@ -123,7 +183,16 @@ export async function runBoxProvider(place, env, root) {
|
|
|
123
183
|
// With no capability and no way to gain one (no program in a run's box changes user): as root (serve run as uid 0) a
|
|
124
184
|
// box could otherwise make a device node in work/.
|
|
125
185
|
const image = boxImageOf(env);
|
|
126
|
-
|
|
186
|
+
// The list the server resolved for this run's box (box-egress.ts boxNetworkOf), or none.
|
|
187
|
+
const allow = runBoxAllowOf(env);
|
|
188
|
+
// On a Mac, the server's proxy container's volume (box-egress-vm.ts), which every box mounts read-only.
|
|
189
|
+
const volume = allow === "none" ? undefined : runBoxVolumeOf(env);
|
|
190
|
+
return {
|
|
191
|
+
...dockerBoxes({ image, ...(user ? { user } : {}), ...boxLimitsOf(env), dropCapabilities: true, ...(volume ? { volumes: [{ name: volume, target: EGRESS_MOUNT, readOnly: true }] } : {}) }),
|
|
192
|
+
ready: (context, note) => awaitImage(root, image, context, note),
|
|
193
|
+
// Where the proxy runs: the one line that picks it (box-egress.ts BoxEgress).
|
|
194
|
+
...(allow === "none" ? {} : { egress: volume ? vmEgress : hostEgress(allow, env, egressLog), net: netLabelOf(allow) }),
|
|
195
|
+
};
|
|
127
196
|
}
|
|
128
197
|
/** The tests' faux box provider, from its module. */
|
|
129
198
|
export const fauxBoxes = async (module, root) => (await import(pathToFileURL(module).href)).default(root);
|
|
@@ -135,7 +204,7 @@ export function runBox(given, run) {
|
|
|
135
204
|
const filed = new Map();
|
|
136
205
|
const open = async (context, note) => {
|
|
137
206
|
const { boxEnv, endLeftCommands } = await import("@parcha/pi-transport/hands");
|
|
138
|
-
const { box, made } = "relay" in source ? await relayedRunBox(source.relay, run
|
|
207
|
+
const { box, made } = "relay" in source ? await relayedRunBox(source.relay, run, context) : await localRunBox(await source.provider(), run, context, note);
|
|
139
208
|
if (!made) {
|
|
140
209
|
// A process before this one left it: what it still runs is killed first, since its calls were answered interrupted.
|
|
141
210
|
const ended = await endLeftCommands(box, context);
|
|
@@ -252,12 +321,33 @@ async function withMirrored(runDir, mark) {
|
|
|
252
321
|
function mirrorFailed(paths, error) {
|
|
253
322
|
process.stderr.write(`${JSON.stringify({ at: new Date().toISOString(), event: "box_mirror_failed", message: `${paths} filed in work/ but not copied into the run's box: ${error.message}` })}\n`);
|
|
254
323
|
}
|
|
324
|
+
/** Said in the run's process log: one of its egress proxy's decisions (the host, port, address and class). */
|
|
325
|
+
const egressLog = (line) => void process.stderr.write(`${JSON.stringify({ at: new Date().toISOString(), event: "box_egress", line })}\n`);
|
|
255
326
|
/** A box of this process's provider: the run's, by its label, or one made now with work/ bound, once its image is in
|
|
256
|
-
* (the provider's `ready`, `note` writing the one timeline row while it is built or pulled).
|
|
327
|
+
* (the provider's `ready`, `note` writing the one timeline row while it is built or pulled). A box that reaches the
|
|
328
|
+
* server's host list has the run's egress proxy started first, its directory bound read-only and the proxy variables
|
|
329
|
+
* in its environment, and, made or found, its relay started (startRelay). */
|
|
257
330
|
async function localRunBox(boxes, run, context, note) {
|
|
331
|
+
let egress;
|
|
332
|
+
try {
|
|
333
|
+
egress = boxes.egress ? await boxes.egress(run.id) : undefined;
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
throw new Error(`the run's box could not have its network: ${error.message}`);
|
|
337
|
+
}
|
|
338
|
+
// A box a process before this one made with another network (none, or another list: the server's setting changed
|
|
339
|
+
// since) is made again: its mounts and environment are fixed at its create. Its work/ is this machine's, bound.
|
|
340
|
+
await destroyListed(boxes, { [RUN_LABEL]: run.id }, (labels) => labels[NET_LABEL] !== boxes.net, context);
|
|
341
|
+
// And so is one bound to a proxy directory this process had to make again (the start's sweep took the old one once its
|
|
342
|
+
// proxy was gone): the box's bind holds the old directory, which no proxy listens in.
|
|
343
|
+
if (egress?.fresh)
|
|
344
|
+
await destroyListed(boxes, { [RUN_LABEL]: run.id }, () => true, context);
|
|
258
345
|
const found = await attachRunBox(boxes, run.id, context);
|
|
259
|
-
if (found)
|
|
346
|
+
if (found) {
|
|
347
|
+
if (egress)
|
|
348
|
+
await startRelay(found, egress.socket, context, note);
|
|
260
349
|
return { box: found, made: false };
|
|
350
|
+
}
|
|
261
351
|
// A box made while the server builds or pulls its image waits for the image, not for a `docker run` that pulls it.
|
|
262
352
|
if (boxes.ready) {
|
|
263
353
|
try {
|
|
@@ -269,9 +359,11 @@ async function localRunBox(boxes, run, context, note) {
|
|
|
269
359
|
throw new Error(`the run's box could not be made: ${error.message}`);
|
|
270
360
|
}
|
|
271
361
|
}
|
|
362
|
+
// Docker's network stays none either way: the box's only way out is the proxy's socket, which checks everything.
|
|
272
363
|
const spec = {
|
|
273
|
-
env: BOX_ENV,
|
|
274
|
-
|
|
364
|
+
env: egress ? { ...BOX_ENV, ...PROXY_ENV } : BOX_ENV, workspace: agentWorkDir(run.dir, run.place),
|
|
365
|
+
mounts: [...(await boxMounts(run.root, run.dir, run.place)), ...(egress?.mount ? [egress.mount] : [])],
|
|
366
|
+
labels: { [RUN_LABEL]: run.id, [KIND_LABEL]: "run", ...(boxes.net ? { [NET_LABEL]: boxes.net } : {}) }, network: "none", maxLifetimeMs: BOX_LIFETIME_MS,
|
|
275
367
|
};
|
|
276
368
|
const made = await boxes.create(spec, context);
|
|
277
369
|
if (!made.ok) {
|
|
@@ -279,14 +371,36 @@ async function localRunBox(boxes, run, context, note) {
|
|
|
279
371
|
await destroyRunBoxes(boxes, run.id, context).catch(() => undefined);
|
|
280
372
|
throw new Error(`the run's box could not be made: ${made.error.message}`);
|
|
281
373
|
}
|
|
374
|
+
if (egress)
|
|
375
|
+
await startRelay(made.value, egress.socket, context, note);
|
|
282
376
|
return { box: made.value, made: true };
|
|
283
377
|
}
|
|
378
|
+
/** The box's relay to its proxy's `socket` (box-egress.ts forwarder), started in the background and answered once it
|
|
379
|
+
* listens. One that cannot start (an image with no socat or setsid, or a relay not listening in time) leaves the box with
|
|
380
|
+
* no network, nothing listening on its proxy port, and the run's timeline says why (`note`). */
|
|
381
|
+
async function startRelay(box, socket, context, note) {
|
|
382
|
+
const started = await box.exec(forwarderStart(socket), undefined, context);
|
|
383
|
+
if (!started.ok)
|
|
384
|
+
throw new Error(`the run's box could not start its network relay: ${started.error.message}`);
|
|
385
|
+
let said = "";
|
|
386
|
+
const drain = async (stream, keep) => {
|
|
387
|
+
for await (const chunk of stream)
|
|
388
|
+
if (keep && said.length < 1000)
|
|
389
|
+
said += new TextDecoder().decode(chunk);
|
|
390
|
+
};
|
|
391
|
+
const [ended] = await Promise.all([started.value.wait(), drain(started.value.stdout, false), drain(started.value.stderr, true)]);
|
|
392
|
+
if (!ended.ok)
|
|
393
|
+
throw new Error(`the run's box could not start its network relay: ${ended.error.message}`);
|
|
394
|
+
if (ended.value !== 0)
|
|
395
|
+
await Promise.resolve(note(relayFailed(ended.value, said))).catch(() => undefined);
|
|
396
|
+
}
|
|
284
397
|
/** A remote box, which the server finds or makes and seeds (ensureRemoteBox), reached through its relay: this process's
|
|
285
|
-
*
|
|
286
|
-
|
|
398
|
+
* provider holds no key, and every call it makes goes to the relay, which sends it on with the server's (Daytona's key;
|
|
399
|
+
* the VM box's client, box-relay-vm.ts). */
|
|
400
|
+
async function relayedRunBox(root, run, context) {
|
|
401
|
+
const { id: runId, dir: runDir } = run;
|
|
287
402
|
const given = await relayedBox(root, runDir, runId, context.abortSignal);
|
|
288
|
-
const
|
|
289
|
-
const boxes = daytonaBoxes({ apiKey: RELAYED_KEY, apiUrl: given.apiUrl, fetch: relayFetch(root, runDir, runId) });
|
|
403
|
+
const boxes = run.place.mode === "sandbox" && run.place.box === VM_PROVIDER.id ? await relayedVmBoxes(root, runDir, runId) : await relayedDaytona(root, runDir, runId, given.apiUrl);
|
|
290
404
|
const attached = await boxes.attach(given.id, context);
|
|
291
405
|
if (!attached.ok)
|
|
292
406
|
throw new Error(`the run's box could not be reached: ${attached.error.message}`);
|
|
@@ -294,36 +408,82 @@ async function relayedRunBox(root, runDir, runId, context) {
|
|
|
294
408
|
throw new Error(`the run's box ${given.id} is not running`);
|
|
295
409
|
return { box: attached.value, made: given.made };
|
|
296
410
|
}
|
|
297
|
-
/** The
|
|
298
|
-
|
|
299
|
-
|
|
411
|
+
/** The run's process's Daytona provider: its calls go to the relay, which adds the key. */
|
|
412
|
+
async function relayedDaytona(root, runDir, runId, apiUrl) {
|
|
413
|
+
if (!apiUrl)
|
|
414
|
+
throw new Error("the server gave the run's Daytona box no API address");
|
|
415
|
+
const { daytonaBoxes } = await import("@parcha/pi-transport/box/daytona");
|
|
416
|
+
return daytonaBoxes({ apiKey: RELAYED_KEY, apiUrl, fetch: relayFetch(root, runDir, runId) });
|
|
417
|
+
}
|
|
418
|
+
/** The run's process's VM provider: pi-transport's, over the relay's client (box-relay-vm.ts). It only attaches. */
|
|
419
|
+
async function relayedVmBoxes(root, runDir, runId) {
|
|
420
|
+
const [{ relayedVmSdk }, transport] = await Promise.all([import("./box-relay-vm.js"), import(`@parcha/pi-transport/box/${VM_PROVIDER.id}`)]);
|
|
421
|
+
return transport.modalBoxes(relayedVmSdk(root, runDir, runId), { appName: "relayed" });
|
|
422
|
+
}
|
|
423
|
+
/** A Docker size (boxLimitsOf's memory) in MiB, the fraction dropped. */
|
|
424
|
+
export const memoryMbOf = (memory) => {
|
|
425
|
+
const size = /^(\d+(?:\.\d+)?)([bkmg])$/i.exec(memory);
|
|
426
|
+
return size ? Math.floor((Number(size[1]) * SIZE_UNITS[size[2].toLowerCase()]) / MIB) : 0;
|
|
427
|
+
};
|
|
428
|
+
/** The spec of a run's remote box: its work/ comes with its seed, never a mount; its network the hosts `allow` names, or
|
|
429
|
+
* none; its limits, where its provider takes them. */
|
|
430
|
+
const remoteSpec = (runId, allow, limits = {}) => ({
|
|
431
|
+
env: BOX_ENV, workspace: BOX_WORK, labels: { [RUN_LABEL]: runId, [KIND_LABEL]: "run" }, network: allow === "none" ? "none" : { allow }, maxLifetimeMs: BOX_LIFETIME_MS,
|
|
432
|
+
...(limits.cpus === undefined ? {} : { cpus: limits.cpus }), ...(limits.memoryMb ? { memoryMb: limits.memoryMb } : {}),
|
|
300
433
|
});
|
|
434
|
+
/** Whether a box's hosts, as its provider reads them (undefined: it does not say), are the hosts asked, as a set. */
|
|
435
|
+
const sameHosts = (hosts, asked) => {
|
|
436
|
+
if (!hosts)
|
|
437
|
+
return false;
|
|
438
|
+
const have = new Set(hosts.map((host) => host.toLowerCase()));
|
|
439
|
+
const want = new Set(asked.map((host) => host.toLowerCase()));
|
|
440
|
+
return have.size === want.size && [...want].every((host) => have.has(host));
|
|
441
|
+
};
|
|
442
|
+
/** The refusals of a create with a host list that say the provider cannot keep one here, so a box with no network is made
|
|
443
|
+
* in its place: Daytona did not keep the list (`unsupported`), or refused it (`invalid`, `unauthorized`: a tier that takes
|
|
444
|
+
* none). Never a refusal a closed box would meet too, such as a timeout. */
|
|
445
|
+
const NO_LIST = new Set(["unsupported", "invalid", "unauthorized"]);
|
|
301
446
|
const markOf = async (runDir) => {
|
|
302
447
|
const kept = (await readJson(join(runDir, BOX_SYNC_FILE)));
|
|
303
448
|
return typeof kept?.box === "string" && kept.mark && Array.isArray(kept.mark.entries) ? kept : undefined;
|
|
304
449
|
};
|
|
305
450
|
const keepMark = (runDir, mark) => writeDurable(join(runDir, BOX_SYNC_FILE), `${JSON.stringify(mark)}\n`);
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
export async function ensureRemoteBox(boxes, run, context, wake) {
|
|
451
|
+
export async function ensureRemoteBox(boxes, run, context, options = {}) {
|
|
452
|
+
const { wake, allow = "none", onNoList, pull = pullRemoteBox, limits } = options;
|
|
453
|
+
let asked = allow === "none" ? "none" : "allowlist";
|
|
310
454
|
let box = await runningRunBox(boxes, run.id, context, wake);
|
|
311
455
|
let made = false;
|
|
312
|
-
|
|
456
|
+
const facts = box?.facts();
|
|
457
|
+
const keep = facts?.network === "none" || (facts?.network === "allowlist" && allow !== "none" && sameHosts(facts.allow, allow));
|
|
458
|
+
if (box && !keep) {
|
|
459
|
+
// Its files first, whole: a box replaced here holds nothing only it had. One whose copy back fails, or is not whole,
|
|
460
|
+
// is kept for a later copy, and the call refused, so no tool runs in it.
|
|
461
|
+
try {
|
|
462
|
+
await pull(boxes, run, context, wake);
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
throw new Error(`the run's box has another host list than this server's now (or a network it does not ask for), and its files could not all be copied back, so it is kept and not used: ${error.message}`);
|
|
466
|
+
}
|
|
313
467
|
await destroyRunBoxes(boxes, run.id, context);
|
|
314
468
|
box = undefined;
|
|
315
469
|
}
|
|
316
470
|
if (!box) {
|
|
317
|
-
|
|
471
|
+
let created = await boxes.create(remoteSpec(run.id, allow, limits), context);
|
|
472
|
+
if (!created.ok && asked === "allowlist" && NO_LIST.has(created.error.code)) {
|
|
473
|
+
asked = "none";
|
|
474
|
+
onNoList?.(created.error.code, created.error.message);
|
|
475
|
+
await destroyRunBoxes(boxes, run.id, context).catch(() => undefined);
|
|
476
|
+
created = await boxes.create(remoteSpec(run.id, "none", limits), context);
|
|
477
|
+
}
|
|
318
478
|
if (!created.ok) {
|
|
319
479
|
await destroyRunBoxes(boxes, run.id, context).catch(() => undefined);
|
|
320
480
|
throw new Error(`the run's box could not be made: ${created.error.message}`);
|
|
321
481
|
}
|
|
322
482
|
box = created.value;
|
|
323
483
|
made = true;
|
|
324
|
-
if (box.facts().network !==
|
|
484
|
+
if (box.facts().network !== asked) {
|
|
325
485
|
await box.destroy(context);
|
|
326
|
-
throw new Error(
|
|
486
|
+
throw new Error(`the run's box was made with its network ${box.facts().network ?? "unknown"}, not ${asked === "none" ? "closed" : "its host list"}, so it is not used`);
|
|
327
487
|
}
|
|
328
488
|
}
|
|
329
489
|
// A box found without its seed's mark was made by a server that went down before it seeded it: seeded now.
|
package/dist/runnable.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { type HarnessCapability } from "./harness.js";
|
|
|
3
3
|
import { type ModelRef } from "./model.js";
|
|
4
4
|
import type { BoxOffer } from "./boxes.js";
|
|
5
5
|
import { type ToolSettingsMap } from "./tool-plane.js";
|
|
6
|
+
import { type McpTool } from "@parcha/agentrun-kernel";
|
|
7
|
+
/** The harnesses an agent's MCP tools run on here. */
|
|
8
|
+
export declare const MCP_HARNESSES: readonly string[];
|
|
6
9
|
/** A revision's body as it is saved or stored. */
|
|
7
10
|
export type RevisionShape = {
|
|
8
11
|
kind: "agentic";
|
|
@@ -28,8 +31,9 @@ export type RevisionShape = {
|
|
|
28
31
|
};
|
|
29
32
|
/** One thing that keeps a revision from running here. `host`: a setting of this host could fix it. `tool` (one it does
|
|
30
33
|
* not bind), `missing` (a bound tool's unset variables), `adapter`, `decision` (a decision provider's unset key), `codeNodes`
|
|
31
|
-
* (code nodes this server does not run), `shell` (a shell or executor call), `tier`, `harness
|
|
32
|
-
* which this server does not have)
|
|
34
|
+
* (code nodes this server does not run), `shell` (a shell or executor call), `tier`, `harness`, `box` (the place's,
|
|
35
|
+
* which this server does not have) and `denied` (a tool a workflow's call node calls that is set to deny) name it for a
|
|
36
|
+
* run's 409 details. */
|
|
33
37
|
export type Blocker = InputIssue & {
|
|
34
38
|
host: boolean;
|
|
35
39
|
tool?: string;
|
|
@@ -47,6 +51,8 @@ export type Blocker = InputIssue & {
|
|
|
47
51
|
tier?: string;
|
|
48
52
|
harness?: string;
|
|
49
53
|
box?: string;
|
|
54
|
+
denied?: string;
|
|
55
|
+
asks?: string;
|
|
50
56
|
};
|
|
51
57
|
/**
|
|
52
58
|
* The model `harness` runs an agentic revision on here: `ref`, its own `provider/model-id`, or with none this host's
|
|
@@ -71,10 +77,14 @@ export declare const CODE_NODES_ENV = "AGENTRUN_SERVE_CODE_NODES";
|
|
|
71
77
|
/** What keeps `revision` from running in `env` under the server's tool `settings` (tool-plane.ts). `boxes`: what this
|
|
72
78
|
* server's box registry set up at its start (boxes.ts); none, every box is unavailable. `offers`: the harnesses' offers
|
|
73
79
|
* the server already holds (its reading); none given, they are probed here. */
|
|
74
|
-
export declare function blockersOf(env: NodeJS.ProcessEnv, revision: RevisionShape, settings?: ToolSettingsMap, { capped, boxes, offers }?: {
|
|
80
|
+
export declare function blockersOf(env: NodeJS.ProcessEnv, revision: RevisionShape, settings?: ToolSettingsMap, { capped, boxes, offers, mcp }?: {
|
|
75
81
|
capped?: boolean;
|
|
76
82
|
boxes?: readonly BoxOffer[];
|
|
77
83
|
offers?: readonly HarnessCapability[];
|
|
84
|
+
mcp?: (server: string) => readonly (McpTool & {
|
|
85
|
+
grantable?: false;
|
|
86
|
+
reason?: string;
|
|
87
|
+
})[] | undefined;
|
|
78
88
|
}): Promise<Blocker[]>;
|
|
79
89
|
/** A blocker as a field issue, for a 422 or a warning. */
|
|
80
90
|
export declare const issueOf: ({ field, reason, message, fix }: Blocker) => InputIssue;
|
package/dist/runnable.js
CHANGED
|
@@ -10,8 +10,15 @@ import { DEFAULT_HARNESS, FAUX_HARNESS_ENV, harnessOffers } from "./harness.js";
|
|
|
10
10
|
import { chooseModel, llmTiers, nodeTiers, workflowNodes } from "./model.js";
|
|
11
11
|
import { boxAvailability, placeFix, RUN_BOXES } from "./place.js";
|
|
12
12
|
import { allows, BOUND_TOOLS, CALL_TOOLS, grantedTools, missingEnv, NODE_TOOLS, toolOf, workflowTools } from "./tools.js";
|
|
13
|
-
import { capabilityOf, isUnavailable, NO_PARALLEL_KEY, planeFor, whyUnavailable } from "./tool-plane.js";
|
|
13
|
+
import { capabilityOf, DENIED, isUnavailable, NO_PARALLEL_KEY, planeFor, whyUnavailable } from "./tool-plane.js";
|
|
14
|
+
import { permissionOf } from "./tool-gate.js";
|
|
14
15
|
import { PARALLEL_KEY_ENV } from "./decisions.js";
|
|
16
|
+
import { keyNeeded } from "./key-words.js";
|
|
17
|
+
import { wireName } from "./catalog.js";
|
|
18
|
+
import { mcpHeaderProblem, mcpNameOf } from "./mcp-gateway.js";
|
|
19
|
+
import { toolSchemaProblems } from "@parcha/agentrun-kernel";
|
|
20
|
+
/** The harnesses an agent's MCP tools run on here. */
|
|
21
|
+
export const MCP_HARNESSES = [DEFAULT_HARNESS, "claude-agent"];
|
|
15
22
|
/**
|
|
16
23
|
* The model `harness` runs an agentic revision on here: `ref`, its own `provider/model-id`, or with none this host's
|
|
17
24
|
* default for that harness. `why`: the model itself is the problem (`host`, a setting of this host could fix it);
|
|
@@ -26,7 +33,7 @@ export async function harnessModel(env, harness, ref, available) {
|
|
|
26
33
|
if (own && !available)
|
|
27
34
|
return undefined;
|
|
28
35
|
// codex's is the run's usual model, but an OpenAI model it reaches through OpenRouter alone is OpenRouter's (codexRef).
|
|
29
|
-
const chosen = own ? (await import("./adapters.js")).claudeModel(env, ref) : harness === "codex" ? await (await import("./adapters.js")).codexModel(env, ref) : await chooseModel(env, ref, "default", harness);
|
|
36
|
+
const chosen = own ? (await import("./adapters.js")).claudeModel(env, ref) : harness === "codex" || harness === "opencode" ? await (await import("./adapters.js")).codexModel(env, ref, harness) : await chooseModel(env, ref, "default", harness);
|
|
30
37
|
if ("why" in chosen)
|
|
31
38
|
return chosen;
|
|
32
39
|
// The harness runs here; whether it runs this model (the revision's, or the default) is checked on it.
|
|
@@ -46,20 +53,20 @@ export const CODE_NODES_ENV = "AGENTRUN_SERVE_CODE_NODES";
|
|
|
46
53
|
/** What keeps `revision` from running in `env` under the server's tool `settings` (tool-plane.ts). `boxes`: what this
|
|
47
54
|
* server's box registry set up at its start (boxes.ts); none, every box is unavailable. `offers`: the harnesses' offers
|
|
48
55
|
* the server already holds (its reading); none given, they are probed here. */
|
|
49
|
-
export async function blockersOf(env, revision, settings = {}, { capped = false, boxes = [], offers } = {}) {
|
|
56
|
+
export async function blockersOf(env, revision, settings = {}, { capped = false, boxes = [], offers, mcp } = {}) {
|
|
50
57
|
const out = [];
|
|
51
58
|
/** A web tool its run would resolve unavailable (tool-plane.ts): a warning at save, a 409 at a run, never another
|
|
52
|
-
* provider in its place. */
|
|
59
|
+
* provider in its place. One set to deny is not: its run starts, and the gate refuses each call. */
|
|
53
60
|
const unavailable = (field, tools, tool) => {
|
|
54
61
|
const resolved = planeFor(env, { tools, harness, ...(revision.kind === "workflow" ? { workflow: true } : {}), ...(revision.kind === "agentic" && revision.model ? { model: revision.model } : {}), ...(revision.toolSettings ? { overrides: revision.toolSettings } : {}) }, settings, { capped })[capabilityOf(tool)];
|
|
55
|
-
if (isUnavailable(resolved))
|
|
62
|
+
if (isUnavailable(resolved) && resolved !== DENIED)
|
|
56
63
|
out.push({ field, reason: NOT_SET_UP, message: `The tool ${tool} does not run here on ${harness}: ${whyUnavailable(resolved)}.`, host: true, ...(resolved === NO_PARALLEL_KEY ? { missing: { tool, vars: [PARALLEL_KEY_ENV] } } : {}) });
|
|
57
64
|
};
|
|
58
65
|
/** A bound tool whose variables this host does not set: a warning at save, a 409 at a run. */
|
|
59
66
|
const unset = (field, tool) => {
|
|
60
67
|
const vars = missingEnv(toolOf(tool), env);
|
|
61
68
|
if (vars.length)
|
|
62
|
-
out.push({ field, reason: NOT_SET_UP, message: `
|
|
69
|
+
out.push({ field, reason: NOT_SET_UP, message: `The tool ${tool} needs ${keyNeeded(vars)}.`, host: true, missing: { tool, vars } });
|
|
63
70
|
};
|
|
64
71
|
const harness = revision.harness ?? DEFAULT_HARNESS;
|
|
65
72
|
const offer = (offers ?? (await harnessOffers(env))).find((h) => h.id === harness);
|
|
@@ -80,6 +87,41 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
|
|
|
80
87
|
if (!revision.instructions.trim())
|
|
81
88
|
out.push({ field: "definition.instructions", reason: "too_short", message: "definition.instructions is empty: an agentic revision needs instructions.", host: false });
|
|
82
89
|
(revision.tools ?? []).forEach((tool, index) => {
|
|
90
|
+
// A remote MCP server's tool: one its saved snapshot lists, on a harness that binds them.
|
|
91
|
+
if (tool.startsWith("mcp:")) {
|
|
92
|
+
const field = `definition.tools[${index}]`;
|
|
93
|
+
const named = mcpNameOf(tool);
|
|
94
|
+
const saved = named && mcp?.(named.server);
|
|
95
|
+
const listed = saved && saved.map((t) => t.name);
|
|
96
|
+
const listedTool = saved && named ? saved.find((t) => t.name === named.tool) : undefined;
|
|
97
|
+
const schema = listedTool?.inputSchema;
|
|
98
|
+
const declared = schema ? mcpHeaderProblem(schema) : undefined;
|
|
99
|
+
// On claude-agent the CLI drops a tool whose schema fails the kernel's check, or whose root holds anyOf, allOf or
|
|
100
|
+
// oneOf (harness-claude's check, measured on the pinned CLI), without a word: refused here, not missing at the run.
|
|
101
|
+
const dropped = schema && named && harness === "claude-agent" ? [...toolSchemaProblems(`mcp__${named.server}__${named.tool}`, schema), ...["anyOf", "allOf", "oneOf"].filter((key) => key in schema).map((key) => `/${key}: the Claude Agent CLI drops a tool whose root has ${key}`)][0] : undefined;
|
|
102
|
+
if (!named)
|
|
103
|
+
out.push({ field, reason: "not_an_option", message: `${tool} is not an MCP tool's name: mcp:<server>/<tool>, the server's name in lowercase letters, digits and -.`, host: false, tool });
|
|
104
|
+
// claude-agent's own tools are its MCP server `hands`: a remote server of that name could never be called there.
|
|
105
|
+
else if (named.server === "hands")
|
|
106
|
+
out.push({ field, reason: "not_an_option", message: `${tool} names the MCP server hands, a name the harnesses keep for their own tools: save the server under another name.`, host: false, tool });
|
|
107
|
+
// A meta tool runs other actions by name: a grant of it could not name the action (mcp-meta.ts). Refused before
|
|
108
|
+
// the harness's check, since no host setup makes it grantable.
|
|
109
|
+
else if (listedTool?.grantable === false)
|
|
110
|
+
out.push({ field, reason: "not_an_option", message: `${tool} can't be granted: ${listedTool.reason}`, host: false, tool });
|
|
111
|
+
else if (!MCP_HARNESSES.includes(harness))
|
|
112
|
+
out.push({ field, reason: NOT_SET_UP, message: `${tool} runs on ${MCP_HARNESSES.join(" and ")} here; on ${harness} MCP tools are not bound yet.`, host: true, tool });
|
|
113
|
+
else if (!listed)
|
|
114
|
+
out.push({ field, reason: "not_an_option", message: `No MCP server ${named.server} is saved on this server: add it in Settings → MCP servers first.`, host: false, tool });
|
|
115
|
+
else if (!listed.includes(named.tool))
|
|
116
|
+
out.push({ field, reason: "not_an_option", message: `The MCP server ${named.server} has no tool ${named.tool}; its tools are ${listed.join(", ") || "none"}.`, host: false, tool });
|
|
117
|
+
else if (dropped)
|
|
118
|
+
out.push({ field, reason: "not_an_option", message: `The MCP server ${named.server}'s tool ${named.tool} cannot be offered on claude-agent: ${dropped.replace(/^mcp__\S+: /, "")}.`, host: false, tool });
|
|
119
|
+
else if (declared)
|
|
120
|
+
out.push({ field, reason: "not_an_option", message: `The MCP server ${named.server}'s tool ${named.tool} declares a header it cannot send: ${declared}.`, host: false, tool });
|
|
121
|
+
else if (wireName(tool) !== `mcp__${named.server}__${named.tool}`)
|
|
122
|
+
out.push({ field, reason: "not_an_option", message: `${tool} is too long: mcp__${named.server}__${named.tool} must be at most 52 characters, the budget every harness's tool names share.`, host: false, tool });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
83
125
|
if (!allows(BOUND_TOOLS, tool))
|
|
84
126
|
out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `agentrun-serve binds the tools ${BOUND_TOOLS.join(", ")}; ${tool} is not one of them.`, host: false, tool });
|
|
85
127
|
// A shell runs only in a box: no place, or the runner, has none.
|
|
@@ -107,6 +149,14 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
|
|
|
107
149
|
out.push({ field: revision.model ? "definition.model" : "definition.harness", reason: NOT_SET_UP, message: resolved.refused, host: true, harness });
|
|
108
150
|
return out;
|
|
109
151
|
}
|
|
152
|
+
// A workflow's own grants hold a known MCP meta tool to the same rule (mcp-meta.ts): refused at the save, never a
|
|
153
|
+
// workflow that cannot launch.
|
|
154
|
+
(revision.tools ?? []).forEach((tool, index) => {
|
|
155
|
+
const named = tool.startsWith("mcp:") ? mcpNameOf(tool) : undefined;
|
|
156
|
+
const listed = named ? mcp?.(named.server)?.find((t) => t.name === named.tool) : undefined;
|
|
157
|
+
if (listed?.grantable === false)
|
|
158
|
+
out.push({ field: `definition.tools[${index}]`, reason: "not_an_option", message: `${tool} can't be granted: ${listed.reason}`, host: false, tool });
|
|
159
|
+
});
|
|
110
160
|
// A workflow's model nodes run on pi here; on another harness they are not bound yet, and never run on pi instead.
|
|
111
161
|
if (harness !== DEFAULT_HARNESS)
|
|
112
162
|
out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: `A workflow runs on pi here; on ${harness} its model nodes are not bound yet.`, host: true, harness });
|
|
@@ -145,6 +195,13 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
|
|
|
145
195
|
for (const tool of named.calls) {
|
|
146
196
|
if (!allows(CALL_TOOLS, tool))
|
|
147
197
|
out.push({ field: "definition.workflow", reason: "not_an_option", message: `A workflow's call nodes run the tools ${CALL_TOOLS.join(", ")} here; this workflow also calls ${tool}.`, host: false, tool });
|
|
198
|
+
// A call node is the author's own step, and it cannot wait for an approval: one that calls a tool set to deny, or to
|
|
199
|
+
// ask (which it could never get), would be refused mid-run (app.ts runEffect), so the run never starts.
|
|
200
|
+
// Held to its settings key: a legacy name (fetch_page) takes its capability's permission (web_fetch's), as the gate does.
|
|
201
|
+
else if (permissionOf(capabilityOf(tool), settings, (revision.toolSettings ?? {})) === "ask")
|
|
202
|
+
out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: `This workflow's call node calls ${capabilityOf(tool) === tool ? tool : `${tool} (${capabilityOf(tool)})`}, which is set to ask, and a workflow's call node can't wait for an approval: set it to allow for this agent.`, host: true, asks: capabilityOf(tool) });
|
|
203
|
+
else if (permissionOf(capabilityOf(tool), settings, (revision.toolSettings ?? {})) === "deny")
|
|
204
|
+
out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: `This workflow's call node calls ${capabilityOf(tool) === tool ? tool : `${tool} (${capabilityOf(tool)})`}, which is set to deny on this server.`, host: true, denied: capabilityOf(tool) });
|
|
148
205
|
}
|
|
149
206
|
const granted = await grantedTools(revision);
|
|
150
207
|
for (const tool of new Set([...named.nodes.filter((name) => allows(NODE_TOOLS, name)), ...named.calls.filter((name) => allows(CALL_TOOLS, name))])) {
|