@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.35
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 +135 -0
- package/README.md +84 -16
- package/dist/adapters.d.ts +3 -0
- package/dist/adapters.js +7 -0
- package/dist/agent-rows.d.ts +1 -0
- package/dist/agents-store.js +17 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +6 -3
- package/dist/cap.js +7 -4
- package/dist/cli.js +32 -5
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-setting.d.ts +6 -5
- package/dist/computer-setting.js +54 -26
- package/dist/computers.d.ts +9 -4
- package/dist/computers.js +4 -2
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -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-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/explain.js +3 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.js +5 -2
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +3 -3
- package/dist/learn/folder.d.ts +6 -3
- package/dist/learn/folder.js +7 -16
- package/dist/learn/grade.d.ts +4 -1
- package/dist/learn/grade.js +43 -5
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.js +5 -3
- package/dist/learn/skills.d.ts +48 -5
- package/dist/learn/skills.js +97 -21
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +9 -5
- package/dist/learned-workflow.js +53 -9
- package/dist/learning-routes.d.ts +41 -0
- package/dist/learning-routes.js +94 -26
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning.d.ts +0 -22
- package/dist/learning.js +0 -16
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +3 -0
- package/dist/model.js +8 -0
- package/dist/openapi.js +37 -13
- package/dist/paid-calls.js +1 -1
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +1 -10
- package/dist/run-launch.d.ts +5 -3
- package/dist/run-launch.js +6 -5
- package/dist/run-learning-served.d.ts +11 -0
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-timeline-served.js +12 -2
- package/dist/run-view.d.ts +30 -14
- package/dist/run-view.js +60 -32
- package/dist/runnable.d.ts +4 -1
- package/dist/runnable.js +14 -2
- package/dist/runner/adapter-loop.d.ts +30 -4
- package/dist/runner/adapter-loop.js +253 -29
- package/dist/runner/adapter-run-spec.d.ts +21 -0
- package/dist/runner/adapter-run-spec.js +104 -28
- package/dist/runner/adapters/pi.d.ts +29 -1
- package/dist/runner/adapters/pi.js +95 -23
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +18 -0
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +3 -0
- package/dist/runner/cli-run-spec.js +123 -34
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +5 -5
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +23 -0
- package/dist/runner/journal-kinds.d.ts +38 -2
- package/dist/runner/journal-kinds.js +23 -0
- package/dist/runner/learning-end.js +88 -16
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +13 -5
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +26 -11
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +6 -1
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.js +1 -0
- package/dist/runner/metrics.d.ts +14 -1
- package/dist/runner/metrics.js +72 -1
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/runner.js +90 -8
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +4 -1
- package/dist/runner/workflow-loop.js +8 -2
- package/dist/runner/workflow-spec.d.ts +3 -0
- package/dist/runner/workflow-spec.js +156 -78
- package/dist/runs-over-store.d.ts +7 -1
- package/dist/runs-over-store.js +42 -11
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +21 -18
- package/dist/server.js +183 -34
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +5 -1
- package/dist/store/agent-body.js +11 -5
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +55 -9
- package/dist/store/sqlite/connection.js +3 -38
- package/dist/store-reads/journal.js +39 -4
- package/dist/store-reads/learning.d.ts +58 -2
- package/dist/store-reads/learning.js +172 -7
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +45 -12
- package/dist/templates.d.ts +9 -4
- package/dist/templates.js +14 -9
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +6 -2
- package/dist/tool-gate.js +8 -5
- package/dist/tool-plane.d.ts +9 -10
- package/dist/tools.d.ts +37 -7
- package/dist/tools.js +73 -12
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +11 -1
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/computer-deps.d.ts +9 -10
- package/dist/workspace/computer-deps.js +53 -40
- package/dist/workspace/computer-for-claim.d.ts +5 -3
- package/dist/workspace/computer-for-claim.js +28 -16
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +3 -3
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +8 -3
- package/dist/workspace/resolve-computer.js +28 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +9 -3
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +1 -14
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +2 -2
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/release-notes/agent.md +11 -0
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
package/dist/usage.js
CHANGED
|
@@ -1,90 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// /usage's `learning` meter reads from it what learning spent outside any run, so neither opens a run's files. A line
|
|
4
|
-
// holds the run, its agent, how its learning ended and when, how many notes it started from, when its answer was final
|
|
5
|
-
// and what its job and its look-back cost (GET /v2/agents/{id}/learning's `impact` reads these), and what its grade
|
|
6
|
-
// spent on the host after the run (the
|
|
7
|
-
// grader on the agent's model, and the injection screen when Jev is its judge), which is in no run's journal and no
|
|
8
|
-
// run's total: `cost` in dollars and `tokens`, each null when unknown, never 0, and 0 when nothing was graded. A run's
|
|
9
|
-
// learning ends once and never moves again, so a line is read once per run: one written again (a restart that found
|
|
10
|
-
// its run's end saved and its line maybe missing) is not counted twice. The notes a run was given and read are the one
|
|
11
|
-
// part that moves after (a follow-up reads another note): a `notes` line, the run's and its files only, says them anew,
|
|
12
|
-
// and the latest one wins; it never counts the run or its costs.
|
|
13
|
-
import { appendFile, readFile } from "node:fs/promises";
|
|
14
|
-
import { join } from "node:path";
|
|
15
|
-
import { LEARNING_REASONS, NO_TOKENS } from "./learning.js";
|
|
1
|
+
// A learning's notes as files: the notes a run was given and read (learning.ts Learning), each by its file, as the store's
|
|
2
|
+
// learning reads (store-reads/learning.ts) and a learning run (learning-run.ts) count them.
|
|
16
3
|
import { isObject } from "./validate.js";
|
|
17
|
-
const ledger = (data) => join(data, "learning-usage.jsonl");
|
|
18
|
-
/** Whether a run's learning has ended: merged or dropped, which never moves again. */
|
|
19
|
-
export const ended = (learning) => learning?.state === "merged" || learning?.state === "dropped";
|
|
20
4
|
const filesOf = (source, fileOf) => {
|
|
21
5
|
const files = (list) => (Array.isArray(list) ? list.flatMap((entry) => { const file = fileOf(entry); return typeof file === "string" ? [file] : []; }) : []);
|
|
22
6
|
const [given, read] = [files(source.given), files(source.read)];
|
|
23
7
|
return { ...(given.length ? { given } : {}), ...(read.length ? { read } : {}) };
|
|
24
8
|
};
|
|
25
9
|
/** A learning's notes ({file, name}) as files: an entry without a string `file` is skipped, so a learning saved out of
|
|
26
|
-
* shape never stops a reader
|
|
10
|
+
* shape never stops a reader. */
|
|
27
11
|
export const notesOf = (learning) => filesOf(learning, (entry) => (isObject(entry) ? entry.file : undefined));
|
|
28
|
-
/** A ledger line's notes (files): an entry that is not a string is skipped. */
|
|
29
|
-
export const lineNotesOf = (line) => filesOf(line, (entry) => entry);
|
|
30
|
-
/** The line of run `run` of agent `agent`, whose learning ended as `learning` says. */
|
|
31
|
-
export const outcomeOf = (run, agent, learning) => ({
|
|
32
|
-
run, agent, state: learning.state, reason: learning.reason, at: learning.at,
|
|
33
|
-
...(learning.cost_usd ? { cost: learning.cost_usd.grade, tokens: learning.tokens?.grade ?? null } : { cost: 0, tokens: { ...NO_TOKENS } }),
|
|
34
|
-
...(isCount(learning.seed_notes) ? { seed_notes: learning.seed_notes } : {}),
|
|
35
|
-
// The files of the notes it was given and read (learning.ts Learning), so an agent's notes count their runs after it ends.
|
|
36
|
-
...notesOf(learning),
|
|
37
|
-
...(learning.answered_at === undefined ? { look_back_usd: 0 } : { answered_at: learning.answered_at, job_cost_usd: learning.job_cost_usd ?? null, look_back_usd: learning.look_back_usd ?? null }),
|
|
38
|
-
});
|
|
39
|
-
const isUsd = (value) => value === null || (typeof value === "number" && Number.isFinite(value) && value >= 0);
|
|
40
|
-
const isCount = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
41
|
-
/** Every run's line, by run (its first), its files as its latest `notes` line says them: a line cut short by a crash,
|
|
42
|
-
* or out of shape, is skipped. */
|
|
43
|
-
export async function outcomes(data) {
|
|
44
|
-
const text = await readFile(ledger(data), "utf8").catch((error) => (error.code === "ENOENT" ? "" : Promise.reject(error)));
|
|
45
|
-
const out = new Map();
|
|
46
|
-
const latest = new Map();
|
|
47
|
-
for (const line of text.split("\n")) {
|
|
48
|
-
let entry;
|
|
49
|
-
try {
|
|
50
|
-
entry = JSON.parse(line);
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (isObject(entry) && entry.notes === true && typeof entry.run === "string") {
|
|
56
|
-
latest.set(entry.run, lineNotesOf(entry));
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (!isObject(entry) || typeof entry.run !== "string" || typeof entry.agent !== "string" || typeof entry.at !== "string")
|
|
60
|
-
continue;
|
|
61
|
-
if ((entry.state !== "merged" && entry.state !== "dropped") || !(entry.reason === null || LEARNING_REASONS.includes(entry.reason)))
|
|
62
|
-
continue;
|
|
63
|
-
if (!(entry.cost === null || typeof entry.cost === "number"))
|
|
64
|
-
continue;
|
|
65
|
-
if (entry.seed_notes !== undefined && !isCount(entry.seed_notes))
|
|
66
|
-
delete entry.seed_notes;
|
|
67
|
-
for (const key of ["given", "read"])
|
|
68
|
-
if (entry[key] !== undefined && !(Array.isArray(entry[key]) && entry[key].every((file) => typeof file === "string")))
|
|
69
|
-
delete entry[key];
|
|
70
|
-
if (entry.answered_at !== undefined && (typeof entry.answered_at !== "string" || !Date.parse(entry.answered_at)))
|
|
71
|
-
delete entry.answered_at;
|
|
72
|
-
for (const key of ["job_cost_usd", "look_back_usd"])
|
|
73
|
-
if (entry[key] !== undefined && !isUsd(entry[key]))
|
|
74
|
-
delete entry[key];
|
|
75
|
-
if (!out.has(entry.run))
|
|
76
|
-
out.set(entry.run, entry);
|
|
77
|
-
}
|
|
78
|
-
for (const [run, files] of latest) {
|
|
79
|
-
const outcome = out.get(run);
|
|
80
|
-
if (!outcome)
|
|
81
|
-
continue;
|
|
82
|
-
delete outcome.given;
|
|
83
|
-
delete outcome.read;
|
|
84
|
-
Object.assign(outcome, files);
|
|
85
|
-
}
|
|
86
|
-
return out;
|
|
87
|
-
}
|
|
88
|
-
/** Writes one run's line, or its `notes` line. A line starts on a line of its own, so one a crash cut short spoils
|
|
89
|
-
* nothing after it. */
|
|
90
|
-
export const record = (data, line) => appendFile(ledger(data), `\n${JSON.stringify(line)}\n`, { mode: 0o600 });
|
package/dist/validate.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare const stable: (value: unknown) => string;
|
|
|
11
11
|
export declare const DEFINITION_FIELDS: string[];
|
|
12
12
|
/** Why a field a definition may have elsewhere has no place in an agent store's revision. */
|
|
13
13
|
export declare const NOT_KEPT: Record<string, string>;
|
|
14
|
+
/** The most tool calls an agent's budget (max_tool_calls, tool-budget.ts) may name. */
|
|
15
|
+
export declare const MAX_TOOL_CALLS = 1000;
|
|
14
16
|
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
15
17
|
export declare const MAX_OUTPUT_SCHEMA_BYTES: number;
|
|
16
18
|
/** `provider/model-id`. */
|
package/dist/validate.js
CHANGED
|
@@ -17,11 +17,13 @@ export const isObject = (value) => typeof value === "object" && value !== null &
|
|
|
17
17
|
/** How long an Idempotency-Key answers with its first answer (capabilities' limits.idempotency_ttl_s). */
|
|
18
18
|
export const IDEMPOTENCY_TTL_S = 86_400;
|
|
19
19
|
export const stable = (value) => Array.isArray(value) ? `[${value.map(stable).join(",")}]` : isObject(value) ? `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stable(value[k])}`).join(",")}}` : JSON.stringify(value);
|
|
20
|
-
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema"];
|
|
20
|
+
export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema", "max_tool_calls"];
|
|
21
21
|
/** Why a field a definition may have elsewhere has no place in an agent store's revision. */
|
|
22
22
|
export const NOT_KEPT = {
|
|
23
23
|
input_schema: "The agent store keeps no input_schema: an agentic run takes {content}, and a workflow checks its input against its own schema.",
|
|
24
24
|
};
|
|
25
|
+
/** The most tool calls an agent's budget (max_tool_calls, tool-budget.ts) may name. */
|
|
26
|
+
export const MAX_TOOL_CALLS = 1_000;
|
|
25
27
|
/** The most bytes an agent's output_schema takes, as JSON. */
|
|
26
28
|
export const MAX_OUTPUT_SCHEMA_BYTES = 64 * 1024;
|
|
27
29
|
/** `provider/model-id`. */
|
|
@@ -130,6 +132,14 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
130
132
|
if (!(typeof d.max_cost_usd === "number" && Number.isFinite(d.max_cost_usd) && d.max_cost_usd >= 0))
|
|
131
133
|
out.push(issue(`${at}.max_cost_usd`, "wrong_type", `${at}.max_cost_usd is a number of at least 0, in US dollars: above 0 sets the agent's default cap, 0 clears it`));
|
|
132
134
|
}
|
|
135
|
+
// The tool calls each conversation of an agentic run may make (tool-budget.ts): above 0 sets the budget, 0 clears it, and
|
|
136
|
+
// an edit that leaves it out keeps the agent's, as the default cap is kept.
|
|
137
|
+
if (d.max_tool_calls !== undefined) {
|
|
138
|
+
if (d.workflow !== undefined)
|
|
139
|
+
out.push(issue(`${at}.max_tool_calls`, "not_allowed", "A workflow revision keeps no tool-call budget: its nodes are its steps.", `Remove ${at}.max_tool_calls.`));
|
|
140
|
+
else if (!(Number.isSafeInteger(d.max_tool_calls) && d.max_tool_calls >= 0 && d.max_tool_calls <= MAX_TOOL_CALLS))
|
|
141
|
+
out.push(issue(`${at}.max_tool_calls`, "wrong_type", `${at}.max_tool_calls is a whole number from 0 to ${MAX_TOOL_CALLS}: above 0, the tool calls each conversation of a run may make before every further call is refused with words that say to answer now; 0 clears it`));
|
|
142
|
+
}
|
|
133
143
|
// How a run's cap prices its requests (cap.ts CapMode): kept, as the default cap is, by an edit that leaves it out.
|
|
134
144
|
if (d.cap_mode !== undefined) {
|
|
135
145
|
if (!CAP_MODES.includes(d.cap_mode))
|
|
@@ -41,8 +41,8 @@ export interface ArchilClaim {
|
|
|
41
41
|
readonly disk: ArchilDisk;
|
|
42
42
|
/** The disk's region (a computer's mount names it). */
|
|
43
43
|
readonly region: string;
|
|
44
|
-
/** The exec image, pinned by digest
|
|
45
|
-
readonly image: ArchilImage
|
|
44
|
+
/** The exec image, pinned by digest: the saved one, else DEFAULT_ARCHIL_EXEC_IMAGE. */
|
|
45
|
+
readonly image: ArchilImage;
|
|
46
46
|
/** The run's mount credential's token, minted the first time a mount asks (once per claim), held in memory only. */
|
|
47
47
|
token(): Promise<string>;
|
|
48
48
|
/** Removes the run's mount credential at Archil by its identifier (the computer's release, the run's end). Idempotent:
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The Archil claim step: once per claim in Mode 2, before the run's loop starts, the claim's Archil disk is made from the
|
|
2
2
|
// server's Archil settings (archil-settings.ts, the store's one settings row) and its keys come from the store's
|
|
3
3
|
// sealed_keys rows under archil-settings.ts's names, opened with the runner's seal key. A saved exec image must be pinned
|
|
4
|
-
// by digest (`<name>@sha256:<64 hex>`): any other refuses the claim before a key is read.
|
|
4
|
+
// by digest (`<name>@sha256:<64 hex>`): any other refuses the claim before a key is read. With none saved, the exec runs
|
|
5
|
+
// in DEFAULT_ARCHIL_EXEC_IMAGE, never Archil's own default (its git is older than a bash policy's floor).
|
|
5
6
|
//
|
|
6
7
|
// One row: "archil.api_key", the account API key the disk's file API and serverless exec take (archil-disk.ts asks for
|
|
7
8
|
// it on every call, and gets it from this step's memory). The disk token a computer's mount takes
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
// refused. A row that is missing, or that does not open under the seal key (sealed under another key, or for another
|
|
15
16
|
// row), refuses in words that name the row and never hold a value. Nothing here reads the environment: the settings,
|
|
16
17
|
// the store's sealed keys and the seal key are handed in.
|
|
17
|
-
import { ARCHIL_API_KEY_ROW } from "../archil-settings.js";
|
|
18
|
+
import { ARCHIL_API_KEY_ROW, DEFAULT_ARCHIL_EXEC_IMAGE } from "../archil-settings.js";
|
|
18
19
|
import { archilApiKey } from "./archil-key.js";
|
|
19
20
|
import { archilDisk, pinnedImage } from "./archil-disk.js";
|
|
20
21
|
import { mintMountToken, nicknameOf, removeMountToken, removeOlderMountTokens, removeRunMountTokens } from "./archil-mount-credential.js";
|
|
@@ -39,7 +40,7 @@ export async function archilClaim(options) {
|
|
|
39
40
|
}
|
|
40
41
|
let image;
|
|
41
42
|
try {
|
|
42
|
-
image =
|
|
43
|
+
image = pinnedImage({ baseImage: settings.image ?? DEFAULT_ARCHIL_EXEC_IMAGE });
|
|
43
44
|
}
|
|
44
45
|
catch (error) {
|
|
45
46
|
throw new ArchilClaimRefused(`This server's Archil exec image ${JSON.stringify(settings.image)} can't be used: ${error.message}`, { cause: error });
|
|
@@ -37,14 +37,23 @@ export type ArchilImage = {
|
|
|
37
37
|
};
|
|
38
38
|
/** `image` checked as an ArchilImage pinned by digest, and copied: only its own fields, nothing else it carries. */
|
|
39
39
|
export declare function pinnedImage(image: unknown): ArchilImage;
|
|
40
|
+
/** An exec's network: its egress denied, so the container reaches nothing but the disk's own mounts. */
|
|
41
|
+
export type ArchilExecNetwork = {
|
|
42
|
+
readonly egress: {
|
|
43
|
+
readonly default: "deny";
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/** The one network an exec is given: no egress. */
|
|
47
|
+
export declare const DENY_EGRESS: ArchilExecNetwork;
|
|
40
48
|
/** One exec: `command` runs with each folder of `mounts` (mount name → folder of the disk), and nothing else of the
|
|
41
49
|
* disk, at /mnt/archil/<name>, each held for the line (waiting up to queueMs for another client's hold), in `image` or
|
|
42
|
-
* Archil's default. */
|
|
50
|
+
* Archil's default, with `network` (absent: Archil's default, egress open). */
|
|
43
51
|
export type ArchilExecRequest = {
|
|
44
52
|
readonly mounts: Readonly<Record<string, string>>;
|
|
45
53
|
readonly queueMs: number;
|
|
46
54
|
readonly command: string;
|
|
47
55
|
readonly image?: ArchilImage;
|
|
56
|
+
readonly network?: ArchilExecNetwork;
|
|
48
57
|
};
|
|
49
58
|
export type ArchilExecAnswer = {
|
|
50
59
|
readonly exitCode: number;
|
|
@@ -14,6 +14,8 @@ export function pinnedImage(image) {
|
|
|
14
14
|
return refuse();
|
|
15
15
|
return { imageId, digest };
|
|
16
16
|
}
|
|
17
|
+
/** The one network an exec is given: no egress. */
|
|
18
|
+
export const DENY_EGRESS = Object.freeze({ egress: Object.freeze({ default: "deny" }) });
|
|
17
19
|
const LOOPBACK = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule names loopback hosts to allow plain http only to them, in tests
|
|
18
20
|
/** The S3 endpoint, checked: https on an Archil host whose name carries the region ("aws-us-east-1" → "….us-east-1.aws.
|
|
19
21
|
* …archil.com"), or, when the control plane is a loopback one too (a test), http(s) to this machine's loopback. */
|
|
@@ -244,6 +246,8 @@ class SdkArchilDisk {
|
|
|
244
246
|
}
|
|
245
247
|
const answer = await client.exec({
|
|
246
248
|
...(image === undefined ? {} : "baseImage" in image ? { baseImage: image.baseImage } : { imageId: image.imageId }),
|
|
249
|
+
// The network's one field, picked by name, as the image's are.
|
|
250
|
+
...(request.network === undefined ? {} : { network: { egress: { default: request.network.egress.default } } }),
|
|
247
251
|
command: request.command,
|
|
248
252
|
disks: Object.fromEntries(Object.entries(request.mounts).map(([name, subdirectory]) => [name, { disk: this.id, subdirectory, queueMs: request.queueMs }])),
|
|
249
253
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ArchilDisk, ArchilImage } from "./archil-disk.js";
|
|
2
|
-
import { type ExecResult } from "./workspace.js";
|
|
1
|
+
import type { ArchilDisk, ArchilExecNetwork, ArchilImage } from "./archil-disk.js";
|
|
2
|
+
import { type ExecResult, WorkspaceError } from "./workspace.js";
|
|
3
3
|
/** Archil cuts an exec call at 300 s. */
|
|
4
4
|
export declare const MAX_EXEC_MS = 300000;
|
|
5
5
|
/** The longest deadline a command may ask for: 5 s of the 300 are the line's own (its walk, its drains, its answer).
|
|
@@ -38,7 +38,17 @@ export type ExecJob = {
|
|
|
38
38
|
readonly maxOutput: number;
|
|
39
39
|
readonly queueMs: number;
|
|
40
40
|
readonly image?: ArchilImage;
|
|
41
|
+
/** The container's network (DENY_EGRESS); absent, Archil's default, egress open. */
|
|
42
|
+
readonly network?: ArchilExecNetwork;
|
|
41
43
|
};
|
|
44
|
+
/** Archil refused an exec's network policy (a plan without network policies): nothing ran. The words are Archil's. */
|
|
45
|
+
export declare class ArchilEgressRefused extends WorkspaceError {
|
|
46
|
+
name: string;
|
|
47
|
+
}
|
|
48
|
+
/** Whether `error`, from an exec that asked for a network policy, is Archil refusing the policy itself: a 402 or a 403
|
|
49
|
+
* whose code or words name the network (`network_plan_required`). Archil's exact answer is not measured; a 403 that
|
|
50
|
+
* names no network (a refused key, the exec allowance spent) stays what it is. */
|
|
51
|
+
export declare function refusesNetwork(error: unknown): boolean;
|
|
42
52
|
/** The shell line one exec call runs (POSIX sh; GNU timeout, perl, mkfifo, head and mktemp in the image). `mark` is
|
|
43
53
|
* this call's marker: the line's answer is found by it, whatever else the call's stdout holds. */
|
|
44
54
|
export declare function execLine(job: ExecJob, mark: string): string;
|
|
@@ -55,6 +55,17 @@ export const quote = (text) => `'${text.replace(/'/g, `'\\''`)}'`;
|
|
|
55
55
|
export const spillName = () => `x${randomBytes(8).toString("hex")}`;
|
|
56
56
|
/** The keys of one exec's files, in spill folder `folder`. */
|
|
57
57
|
export const spillKeys = (folder, name) => ({ in: `${folder}/${name}.in`, out: `${folder}/${name}.out`, err: `${folder}/${name}.err` });
|
|
58
|
+
/** Archil refused an exec's network policy (a plan without network policies): nothing ran. The words are Archil's. */
|
|
59
|
+
export class ArchilEgressRefused extends WorkspaceError {
|
|
60
|
+
name = "ArchilEgressRefused";
|
|
61
|
+
}
|
|
62
|
+
/** Whether `error`, from an exec that asked for a network policy, is Archil refusing the policy itself: a 402 or a 403
|
|
63
|
+
* whose code or words name the network (`network_plan_required`). Archil's exact answer is not measured; a 403 that
|
|
64
|
+
* names no network (a refused key, the exec allowance spent) stays what it is. */
|
|
65
|
+
export function refusesNetwork(error) {
|
|
66
|
+
const { status, code, message } = (error ?? {});
|
|
67
|
+
return (status === 402 || status === 403) && /network|egress/i.test(`${typeof code === "string" ? code : ""} ${typeof message === "string" ? message : ""}`);
|
|
68
|
+
}
|
|
58
69
|
/** The program's runner: stderr to the file in its first argument, the program run, its raw wait status written to the
|
|
59
70
|
* file in its second, and the same exit a shell would give. No single quote in it: it rides in one. */
|
|
60
71
|
const RUNNER = [
|
|
@@ -158,6 +169,7 @@ export async function archilExec(disk, job) {
|
|
|
158
169
|
const request = {
|
|
159
170
|
mounts: { [EXEC_MOUNT]: job.root, [SPILL_MOUNT]: job.spill }, queueMs: job.queueMs, command: execLine(job, mark),
|
|
160
171
|
...(job.image === undefined ? {} : { image: job.image }),
|
|
172
|
+
...(job.network === undefined ? {} : { network: job.network }),
|
|
161
173
|
};
|
|
162
174
|
answer = await Promise.race([disk.exec(request), gaveUp]);
|
|
163
175
|
}
|
|
@@ -165,6 +177,10 @@ export async function archilExec(disk, job) {
|
|
|
165
177
|
if (error instanceof WorkspaceError)
|
|
166
178
|
throw error;
|
|
167
179
|
const status = error?.status;
|
|
180
|
+
if (job.network !== undefined && refusesNetwork(error)) {
|
|
181
|
+
const code = error.code;
|
|
182
|
+
throw new ArchilEgressRefused("REFUSED", `Archil refused the exec's network policy (${status}${typeof code === "string" ? ` ${code}` : ""}): ${describe(error)}`, { path, cause: error });
|
|
183
|
+
}
|
|
168
184
|
// A 400 is a mount Archil refused (a folder missing, or held by another client past the queue's wait): its own
|
|
169
185
|
// words say which.
|
|
170
186
|
const why = status === 400 ? "Archil refused to mount the exec's folders"
|
|
@@ -9,8 +9,8 @@ export type ArchilWorkspaceOptions = {
|
|
|
9
9
|
readonly queueMs?: number;
|
|
10
10
|
/** The image every exec runs in, the same for every workspace serve makes (a run's or a learning folder's), pinned by
|
|
11
11
|
* digest (an image given without one is refused): a public image `<name>@sha256:…`, or one built through Archil's
|
|
12
|
-
* images API with its digest. With none, Archil's default exec image, whose git (2.34.1, measured) is older than
|
|
13
|
-
*
|
|
12
|
+
* images API with its digest. With none, Archil's default exec image, whose git (2.34.1, measured) is older than a
|
|
13
|
+
* bash policy's floor; serve's claim always names one (archil-settings.ts DEFAULT_ARCHIL_EXEC_IMAGE). */
|
|
14
14
|
readonly image?: ArchilImage;
|
|
15
15
|
/** Told when an exec's cleanup leaves spill files behind (a failed delete, tried twice), with the keys and why; the
|
|
16
16
|
* exec's own result stands. Default: a process warning. */
|
package/dist/workspace/archil.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { pinnedImage } from "./archil-disk.js";
|
|
2
|
-
import { archilExec, COMMAND_MAX_MS, DEFAULT_QUEUE_MS, MAX_EXEC_MS, spillKeys, spillName } from "./archil-exec.js";
|
|
1
|
+
import { DENY_EGRESS, pinnedImage } from "./archil-disk.js";
|
|
2
|
+
import { ArchilEgressRefused, archilExec, COMMAND_MAX_MS, DEFAULT_QUEUE_MS, MAX_EXEC_MS, spillKeys, spillName } from "./archil-exec.js";
|
|
3
3
|
import { attachedWorkspace, checkReadBack, noProcesses } from "./attach.js";
|
|
4
4
|
import { globRegex } from "./glob.js";
|
|
5
5
|
import { relativeSegments } from "./paths.js";
|
|
@@ -64,6 +64,8 @@ class ArchilWorkspace {
|
|
|
64
64
|
#mountToken;
|
|
65
65
|
/** The last exec asked for, settled either way: the next exec, and every write, starts after it. */
|
|
66
66
|
#execs = Promise.resolve();
|
|
67
|
+
/** Why Archil refused an exec's network policy, once it has: an exec asking for no network then runs with it open. */
|
|
68
|
+
#egressOpen;
|
|
67
69
|
#rooted = false;
|
|
68
70
|
constructor(disk, root, options = {}) {
|
|
69
71
|
if (relativeSegments(root).length === 0)
|
|
@@ -551,13 +553,31 @@ class ArchilWorkspace {
|
|
|
551
553
|
const stdin = options.stdin;
|
|
552
554
|
await this.#settle("", () => this.#disk.putObject(files.in, stdin)).catch((error) => { throw failed(error, "", "exec's stdin"); });
|
|
553
555
|
}
|
|
554
|
-
const
|
|
556
|
+
const job = {
|
|
555
557
|
root: this.#root, spill: this.#spill, name, cwd, argv, env, timeoutMs, maxOutput: readBack, queueMs: this.#queueMs,
|
|
556
558
|
stdin: options.stdin !== undefined, ...(this.#image === undefined ? {} : { image: this.#image }),
|
|
557
|
-
}
|
|
559
|
+
};
|
|
560
|
+
const deny = options.network === "deny";
|
|
561
|
+
let read;
|
|
562
|
+
if (deny && this.#egressOpen === undefined) {
|
|
563
|
+
try {
|
|
564
|
+
read = await archilExec(this.#disk, { ...job, network: DENY_EGRESS });
|
|
565
|
+
}
|
|
566
|
+
catch (error) {
|
|
567
|
+
// Archil's plan takes no network policy: nothing ran, so the command runs again with the network open.
|
|
568
|
+
if (!(error instanceof ArchilEgressRefused))
|
|
569
|
+
throw error;
|
|
570
|
+
this.#egressOpen = error.message;
|
|
571
|
+
// The caller gave up while Archil answered: the command it no longer waits for is not started now.
|
|
572
|
+
if (signal?.aborted)
|
|
573
|
+
throw abortError(signal);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
read ??= await archilExec(this.#disk, job);
|
|
558
577
|
// Archil answers once the command has ended: each stream once, whole. An error the caller's callback throws is
|
|
559
578
|
// not the call's.
|
|
560
|
-
const
|
|
579
|
+
const warning = deny && this.#egressOpen !== undefined ? `agentrun: this command ran with the network open. ${this.#egressOpen}\n` : "";
|
|
580
|
+
const stderr = Buffer.from(`${warning}${read.stderr}`, "utf8");
|
|
561
581
|
for (const chunk of [{ stream: "stdout", data: read.stdout }, { stream: "stderr", data: stderr }]) {
|
|
562
582
|
try {
|
|
563
583
|
options.onOutput?.(chunk);
|
package/dist/workspace/attach.js
CHANGED
|
@@ -339,6 +339,8 @@ export function attachedWorkspace(base, computer, options = {}) {
|
|
|
339
339
|
async exec(argv, options) {
|
|
340
340
|
if (options.stdin !== undefined)
|
|
341
341
|
throw new WorkspaceError("REFUSED", "exec with stdin runs on the run's folder, not in a computer: a computer's exec takes no stdin");
|
|
342
|
+
if (options.network !== undefined)
|
|
343
|
+
throw new WorkspaceError("REFUSED", "a command in a computer has the computer's own network: its exec takes no network of its own, and nothing ran");
|
|
342
344
|
const { timeoutMs, signal } = options;
|
|
343
345
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
344
346
|
throw new WorkspaceError("REFUSED", "exec's timeoutMs is a number above 0");
|
|
@@ -27,9 +27,6 @@ export declare function dockerLimitsOf(env: KeyEnv): DockerLimits;
|
|
|
27
27
|
* container): a comma list of IP addresses. The Docker provider's egress proxy refuses them as the host's, so a
|
|
28
28
|
* computer's allow-list never reaches the host itself; without them it refuses any allow-list there. */
|
|
29
29
|
export declare const DOCKER_HOST_ADDRESSES_ENV = "AGENTRUN_DOCKER_HOST_ADDRESSES";
|
|
30
|
-
/** The variables the local browser's provider finds its Chrome by (the computer package's findChrome): the server's own
|
|
31
|
-
* values are handed to it, and no other variable of the server's. */
|
|
32
|
-
export declare const CHROME_LOOKUP: readonly ["CHROME_PATH", "PI_BROWSER_CHROME", "PATH"];
|
|
33
30
|
/** `env`'s AGENTRUN_DOCKER_HOST_ADDRESSES: its addresses, each once; undefined when unset or empty, never one made up.
|
|
34
31
|
* An entry that is not an IP address throws, naming it: the server's start checks the setting, so no run meets one. */
|
|
35
32
|
export declare function dockerHostAddressesOf(env: KeyEnv): string[] | undefined;
|
|
@@ -77,13 +74,15 @@ export interface ComputerDepsOptions {
|
|
|
77
74
|
* and factories. */
|
|
78
75
|
readonly faux?: FauxComputers;
|
|
79
76
|
}
|
|
80
|
-
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (
|
|
81
|
-
* owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
77
|
+
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (a provider that
|
|
78
|
+
* prepares its own image, its descriptor's prepareImage: the owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox
|
|
79
|
+
* the package's recipe, which its prepareImage() builds; any other provider's: its descriptor's defaultImage for the
|
|
80
|
+
* kind, the computer package's PROVIDERS[].defaultImage; a kind with none refused in words, a prepared desktop's saying
|
|
81
|
+
* it needs an image with an X server, which the recipe lacks), the leak bound for its lifetime (its clean end is the
|
|
82
|
+
* run's release), and its network (networkOf): the run's box_allow, or this server's own (AGENTRUN_BOX_ALLOW, read
|
|
83
|
+
* from `env`) for a launch that names none; and the size of a computer on this machine's container engine (its
|
|
84
|
+
* descriptor's `local`), AGENTRUN_BOX_CPUS, _MEMORY and _PIDS (dockerLimitsOf, read once here): a vendor's computer
|
|
85
|
+
* sizes itself. No key and no environment. */
|
|
87
86
|
export declare function computerSpecOf(env: KeyEnv): ComputerForClaimDeps["spec"];
|
|
88
87
|
/** The run's timeline phase while its claim waits on its computer's image (computerForClaim's onImageWait): main's box
|
|
89
88
|
* image row, the computer's noun for the box's. */
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
// with names no key, no account key and no database or Redis credential, and carries no environment at all.
|
|
17
17
|
import { isIP } from "node:net";
|
|
18
18
|
import { posix } from "node:path";
|
|
19
|
-
import { DEFAULT_DOCKER_IMAGE, DOCKER_RECIPE, DOCKER_RECIPE_HAS,
|
|
19
|
+
import { DEFAULT_DOCKER_IMAGE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, PROVIDERS, providerFor, readBackOf, servingRefusals, SETTING_KINDS } from "@parcha/agentrun-computer";
|
|
20
|
+
// The local container engine's provider, for its check() of the operator's size settings at the start (dockerLimitsOf).
|
|
21
|
+
import { DockerProvider } from "@parcha/agentrun-computer/docker";
|
|
20
22
|
import { DOCKER_IMAGE_ENV } from "../box-image.js";
|
|
21
23
|
import { dockerDaemonCheck } from "../docker-daemon.js";
|
|
22
24
|
import { unionOf } from "../docker-host-addresses.js";
|
|
@@ -83,9 +85,6 @@ export function dockerLimitsOf(env) {
|
|
|
83
85
|
* container): a comma list of IP addresses. The Docker provider's egress proxy refuses them as the host's, so a
|
|
84
86
|
* computer's allow-list never reaches the host itself; without them it refuses any allow-list there. */
|
|
85
87
|
export const DOCKER_HOST_ADDRESSES_ENV = "AGENTRUN_DOCKER_HOST_ADDRESSES";
|
|
86
|
-
/** The variables the local browser's provider finds its Chrome by (the computer package's findChrome): the server's own
|
|
87
|
-
* values are handed to it, and no other variable of the server's. */
|
|
88
|
-
export const CHROME_LOOKUP = ["CHROME_PATH", "PI_BROWSER_CHROME", "PATH"];
|
|
89
88
|
/** `env`'s AGENTRUN_DOCKER_HOST_ADDRESSES: its addresses, each once; undefined when unset or empty, never one made up.
|
|
90
89
|
* An entry that is not an IP address throws, naming it: the server's start checks the setting, so no run meets one. */
|
|
91
90
|
export function dockerHostAddressesOf(env) {
|
|
@@ -107,39 +106,43 @@ export function dockerVolumeOf(paths) {
|
|
|
107
106
|
const root = paths.paths.at;
|
|
108
107
|
return { volume: { name: paths.paths.volume, root }, daemonCache: posix.join(root, DAEMON_CACHE_IN_VOLUME) };
|
|
109
108
|
}
|
|
110
|
-
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (
|
|
111
|
-
* owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
109
|
+
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (a provider that
|
|
110
|
+
* prepares its own image, its descriptor's prepareImage: the owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox
|
|
111
|
+
* the package's recipe, which its prepareImage() builds; any other provider's: its descriptor's defaultImage for the
|
|
112
|
+
* kind, the computer package's PROVIDERS[].defaultImage; a kind with none refused in words, a prepared desktop's saying
|
|
113
|
+
* it needs an image with an X server, which the recipe lacks), the leak bound for its lifetime (its clean end is the
|
|
114
|
+
* run's release), and its network (networkOf): the run's box_allow, or this server's own (AGENTRUN_BOX_ALLOW, read
|
|
115
|
+
* from `env`) for a launch that names none; and the size of a computer on this machine's container engine (its
|
|
116
|
+
* descriptor's `local`), AGENTRUN_BOX_CPUS, _MEMORY and _PIDS (dockerLimitsOf, read once here): a vendor's computer
|
|
117
|
+
* sizes itself. No key and no environment. */
|
|
117
118
|
export function computerSpecOf(env) {
|
|
118
119
|
const named = envValue(env, DOCKER_IMAGE_ENV);
|
|
119
120
|
// This server's allow setting, as a launch is stamped with it (box-settings.ts boxAllowOf; its start checks the setting).
|
|
120
121
|
const current = () => boxAllowOf(env);
|
|
121
122
|
const currentSet = () => boxAllowSetIn(env);
|
|
122
123
|
const imageOf = (entry, kind) => {
|
|
123
|
-
if (entry.
|
|
124
|
+
if (entry.prepareImage && named !== undefined)
|
|
124
125
|
return named;
|
|
125
|
-
//
|
|
126
|
-
|
|
126
|
+
// A sandbox whose provider prepares its image: the package's own recipe, which its prepareImage() builds (the
|
|
127
|
+
// descriptor gives it no default).
|
|
128
|
+
if (entry.prepareImage && kind === "sandbox")
|
|
127
129
|
return DEFAULT_DOCKER_IMAGE;
|
|
128
130
|
const image = entry.defaultImage?.[kind];
|
|
129
131
|
if (image !== undefined)
|
|
130
132
|
return image;
|
|
131
|
-
if (entry.
|
|
132
|
-
throw refused(
|
|
133
|
+
if (entry.prepareImage && kind === "desktop")
|
|
134
|
+
throw refused(`A ${entry.label} desktop needs an image with an X server; set one for desktops.`);
|
|
133
135
|
throw refused(`${entry.label} has no image for a ${kind} computer here: pick another provider for this agent's computer in Settings → Computers.`);
|
|
134
136
|
};
|
|
135
137
|
const limits = dockerLimitsOf(env);
|
|
136
|
-
return (entry, kind, run) => ({
|
|
137
|
-
image
|
|
138
|
+
return (entry, kind, run, image) => ({
|
|
139
|
+
// The setting's configuration's image (Orgo's `windows`), else the kind's.
|
|
140
|
+
image: image ?? imageOf(entry, kind),
|
|
138
141
|
// The leak bound, within the longest the provider makes (E2B's is an hour): a longer one it refuses at create.
|
|
139
142
|
lifetimeMs: Math.min(COMPUTER_LIFETIME_MS, run.maxLifetimeMs ?? COMPUTER_LIFETIME_MS),
|
|
140
143
|
network: networkOf(entry, kind, run, current, currentSet),
|
|
141
|
-
//
|
|
142
|
-
...(entry.
|
|
144
|
+
// The size of a computer on this machine's container engine, the operator's (dockerLimitsOf); a vendor's sizes itself.
|
|
145
|
+
...(entry.local ? limits : {}),
|
|
143
146
|
});
|
|
144
147
|
}
|
|
145
148
|
/** The network a computer of `kind` on `entry` asks for: what the run allows (its box_allow), narrowed to "none" when its
|
|
@@ -197,24 +200,25 @@ const dockerDaemonOf = (env) => {
|
|
|
197
200
|
export function computerDepsFrom(options) {
|
|
198
201
|
const { env, store, sealKey, faux } = options;
|
|
199
202
|
const kinds = claimKinds(options);
|
|
200
|
-
//
|
|
201
|
-
// when
|
|
202
|
-
// recipe's bare tag, which no registry has.
|
|
203
|
+
// A provider that prepares its own image (its descriptor's prepareImage) is given that image's source, which its
|
|
204
|
+
// prepareImage() makes ready (built from the recipe when the engine lacks it, or pulled by name): the owner's
|
|
205
|
+
// AGENTRUN_DOCKER_IMAGE, else the package's recipe. Never the recipe's bare tag, which no registry has.
|
|
203
206
|
const named = envValue(env, DOCKER_IMAGE_ENV);
|
|
204
|
-
const
|
|
207
|
+
const preparedImage = named !== undefined ? { image: named } : { recipe: DOCKER_RECIPE };
|
|
205
208
|
// The operator's Docker host addresses (AGENTRUN_DOCKER_HOST_ADDRESSES), checked once here.
|
|
206
209
|
const namedAddresses = dockerHostAddressesOf(env);
|
|
207
210
|
// Where this process's Docker has the data, read once, when a Docker provider is first built.
|
|
208
211
|
let paths;
|
|
209
|
-
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* allow-list where it isn't on the
|
|
214
|
-
* has an allow-list (`boxAllow`, the claim's own
|
|
215
|
-
*
|
|
216
|
-
* The read itself is once per process
|
|
217
|
-
|
|
212
|
+
/** A local provider's host options (its descriptor's `local`: its computers run on this machine's container engine):
|
|
213
|
+
* for a server in a container of that engine's, the named volume that holds its data and the daemon copy's place
|
|
214
|
+
* under it (dockerVolumeOf), and the host's own addresses for its egress proxy, the union of the read through the
|
|
215
|
+
* socket (`hostAddresses`) and the operator's; on a host, the operator's alone (the provider reads its own
|
|
216
|
+
* interfaces). With none, none are given, and the provider refuses an allow-list where it isn't on the host, in its
|
|
217
|
+
* words. The read is made only for a claim whose run's computer has an allow-list (`boxAllow`, the claim's own
|
|
218
|
+
* launch's box_allow, a list): a run launched under a list keeps it across a restart, whatever this process's
|
|
219
|
+
* AGENTRUN_BOX_ALLOW says now; one with none, or no claim, reads nothing. The read itself is once per process
|
|
220
|
+
* (`hostAddresses`). */
|
|
221
|
+
const localHostOptions = async (boxAllow) => {
|
|
218
222
|
const where = options.dockerPaths ? await (paths ??= options.dockerPaths()) : { here: true };
|
|
219
223
|
const volume = dockerVolumeOf(where);
|
|
220
224
|
// A launch that names no box_allow (a row from before every launch was stamped) allows what this server allows now,
|
|
@@ -222,15 +226,24 @@ export function computerDepsFrom(options) {
|
|
|
222
226
|
const allow = boxAllow ?? boxAllowOf(env);
|
|
223
227
|
const read = volume && Array.isArray(allow) && options.hostAddresses ? await options.hostAddresses() : undefined;
|
|
224
228
|
const addresses = read ? unionOf(read, namedAddresses).addresses : (namedAddresses ?? []);
|
|
225
|
-
return {
|
|
229
|
+
return { ...(volume ?? {}), ...(addresses.length > 0 ? { egress: { hostAddresses: addresses } } : {}) };
|
|
230
|
+
};
|
|
231
|
+
/** The server's own values of the environment variables a provider declares it reads on this machine (hostEnv: Local
|
|
232
|
+
* Chrome's, where it finds Chrome), and no other variable of the server's. */
|
|
233
|
+
const hostEnvOf = (names) => Object.fromEntries(names.flatMap((name) => (env[name] === undefined ? [] : [[name, String(env[name])]])));
|
|
234
|
+
/** The options a provider takes beside its keys, by what its descriptor declares, never by its id: the image source
|
|
235
|
+
* for one that prepares its image, the host options for a local one, the host environment it reads. */
|
|
236
|
+
const declaredOptions = async (id, boxAllow) => {
|
|
237
|
+
const entry = kinds.PROVIDERS.find((one) => one.id === id);
|
|
238
|
+
return {
|
|
239
|
+
...(entry?.prepareImage ? { image: preparedImage } : {}),
|
|
240
|
+
...(entry?.local ? await localHostOptions(boxAllow) : {}),
|
|
241
|
+
...(entry?.hostEnv ? { env: hostEnvOf(entry.hostEnv) } : {}),
|
|
242
|
+
};
|
|
226
243
|
};
|
|
227
244
|
const load = options.load ?? providerFor;
|
|
228
|
-
// The
|
|
229
|
-
|
|
230
|
-
const chromeEnv = { env: Object.fromEntries(CHROME_LOOKUP.flatMap((name) => (env[name] === undefined ? [] : [[name, env[name]]]))) };
|
|
231
|
-
const providers = computerProviderMakers({
|
|
232
|
-
load: async (id, given, claim) => load(id, id === "docker" ? { ...given, ...(await dockerOptions(claim?.boxAllow)) } : id === "local" ? { ...given, ...chromeEnv } : given),
|
|
233
|
-
});
|
|
245
|
+
// The claim and Settings → Computers' test alike.
|
|
246
|
+
const providers = computerProviderMakers({ load: async (id, given, claim) => load(id, { ...given, ...(await declaredOptions(id, claim?.boxAllow)) }) });
|
|
234
247
|
const computerDeps = {
|
|
235
248
|
kinds,
|
|
236
249
|
providers,
|
|
@@ -35,7 +35,7 @@ export interface ComputerRun {
|
|
|
35
35
|
/** A provider module's create(), by provider id: its options from the saved keys, and the store's ledger for a provider
|
|
36
36
|
* that keeps one (the phone's `ledger` option); for a claim, what its run's computer may reach (`boxAllow`, the
|
|
37
37
|
* launch's box_allow), which no provider option carries. The computer package's providers, or a test's stand-in. */
|
|
38
|
-
export type ProviderMakers = Readonly<Partial<Record<string, (options: Record<string,
|
|
38
|
+
export type ProviderMakers = Readonly<Partial<Record<string, (options: Readonly<Record<string, unknown>>, extras: ProviderExtras) => ComputerProvider | Promise<ComputerProvider>>>>;
|
|
39
39
|
/** What a provider is made with beside its options: the store's ledger, and the claim's box_allow when a claim makes it. */
|
|
40
40
|
export type ProviderExtras = {
|
|
41
41
|
readonly ledger: ProviderLedger;
|
|
@@ -74,8 +74,9 @@ export interface ComputerForClaimDeps {
|
|
|
74
74
|
/** The server's seal key: absent, no key is opened, so a provider that needs one is refused in words. */
|
|
75
75
|
readonly sealKey: Buffer | undefined;
|
|
76
76
|
readonly providers: ProviderMakers;
|
|
77
|
-
/** What a computer of `kind` is made with, besides its labels and its mount: image, lifetime, network (from `run`).
|
|
78
|
-
|
|
77
|
+
/** What a computer of `kind` is made with, besides its labels and its mount: image, lifetime, network (from `run`).
|
|
78
|
+
* `image`: the one the setting's configuration names, over the kind's default. */
|
|
79
|
+
readonly spec: (entry: ProviderEntry, kind: Exclude<ComputerSettingKind, "none">, run: ComputerRun, image?: string) => Omit<ComputerSpec, "labels" | "mount">;
|
|
79
80
|
/** A provider key's value by its name, as the server reads it (key-meta.ts keyReader: the environment's, else the
|
|
80
81
|
* saved one). Absent: the saved one alone, opened with `sealKey`. */
|
|
81
82
|
readonly keyOf?: (name: string) => Promise<string | undefined>;
|
|
@@ -113,6 +114,7 @@ export interface ClaimComputer {
|
|
|
113
114
|
readonly hold?: RunHold;
|
|
114
115
|
release(why?: ViewEnd): Promise<void>;
|
|
115
116
|
}
|
|
117
|
+
/** The provider's watch of a computer's screen (ComputerProvider.watch), where it has one. */
|
|
116
118
|
/** Told once, before the claim waits on its computer's image being built or pulled; never when the host has it. */
|
|
117
119
|
export type ImageWait = (making: "build" | "pull", tag: string) => void;
|
|
118
120
|
/** The run's computer for this claim, started and registered; `{ computer: undefined }` for none. Throws with code
|