@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.29
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 +560 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +1723 -2
- package/dist/adapters.d.ts +205 -0
- package/dist/adapters.js +459 -0
- package/dist/agents.d.ts +124 -0
- package/dist/agents.js +302 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +324 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +283 -0
- package/dist/box-relay.d.ts +42 -0
- package/dist/box-relay.js +222 -0
- package/dist/boxes.d.ts +54 -0
- package/dist/boxes.js +182 -0
- package/dist/cap.d.ts +224 -0
- package/dist/cap.js +721 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +31 -0
- package/dist/coding-tools.js +81 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
- package/dist/console/assets/index-BN7oVcO4.js +445 -0
- package/dist/console/assets/index-By-jkqki.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +11 -0
- package/dist/decision-rows.js +116 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +66 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +60 -0
- package/dist/files.js +153 -0
- package/dist/grade.d.ts +96 -0
- package/dist/grade.js +348 -0
- package/dist/graph-view.d.ts +100 -0
- package/dist/graph-view.js +212 -0
- package/dist/harness-app.d.ts +38 -0
- package/dist/harness-app.js +626 -0
- package/dist/harness.d.ts +53 -0
- package/dist/harness.js +74 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +20 -0
- package/dist/host-tools.js +140 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +81 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +129 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1221 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +36 -0
- package/dist/key-check.js +108 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +187 -0
- package/dist/learn/check.d.ts +99 -0
- package/dist/learn/check.js +259 -0
- package/dist/learn/grade.d.ts +79 -0
- package/dist/learn/grade.js +433 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +146 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +167 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +111 -0
- package/dist/learn/skills.d.ts +84 -0
- package/dist/learn/skills.js +198 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +304 -0
- package/dist/learning-run.js +797 -0
- package/dist/learning-words.d.ts +73 -0
- package/dist/learning-words.js +171 -0
- package/dist/learning.d.ts +377 -0
- package/dist/learning.js +801 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +115 -0
- package/dist/mcp-servers.js +445 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +184 -0
- package/dist/model.js +484 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4805 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1417 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +46 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +68 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +46 -0
- package/dist/place.js +105 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +38 -0
- package/dist/propose.js +82 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +14 -0
- package/dist/request-start.js +226 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +134 -0
- package/dist/run-box.js +440 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +80 -0
- package/dist/runnable.js +162 -0
- package/dist/runs.d.ts +840 -0
- package/dist/runs.js +2279 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +50 -0
- package/dist/secrets.js +140 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +626 -0
- package/dist/server.js +1756 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/skills.d.ts +31 -0
- package/dist/skills.js +68 -0
- package/dist/stats.d.ts +101 -0
- package/dist/stats.js +82 -0
- package/dist/tool-keys.d.ts +151 -0
- package/dist/tool-keys.js +273 -0
- package/dist/tool-plane.d.ts +143 -0
- package/dist/tool-plane.js +242 -0
- package/dist/tools.d.ts +147 -0
- package/dist/tools.js +253 -0
- package/dist/turn-end.d.ts +23 -0
- package/dist/turn-end.js +14 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +55 -0
- package/dist/validate.js +175 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +182 -0
- package/dist/webhooks.js +487 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +94 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// The file tools of a run whose box binds its work/ from this machine (Docker here): read, write and edit run on this
|
|
2
|
+
// machine, on the bind's source, and not as commands in the box, which cost one `docker exec` or more each (half a second
|
|
3
|
+
// and up on real Docker). bash stays in the box. This holds only where the confinement walks held directory handles
|
|
4
|
+
// (workspace.ts writesHeld: Linux's /proc/self/fd): a command in the box runs beside these tools and can plant a link, a
|
|
5
|
+
// hard link or a swapped directory at any moment, and only a walk on held handles refuses a swap between the check and
|
|
6
|
+
// the use. Elsewhere (macOS, a box that binds nothing, Daytona's) all four stay in the box (coding-tools.ts).
|
|
7
|
+
//
|
|
8
|
+
// Nothing a box's command makes in work/ is followed or taken. Every path is work/ joined with its own names, and a link
|
|
9
|
+
// anywhere on the way is refused, even one pointing inside work/. Only a regular file with one hard link is read or
|
|
10
|
+
// written. A write goes through a temporary file renamed over the old one, keeping its mode (workspace.ts
|
|
11
|
+
// writeWorkFile). work/ itself must be its own canonical path: the directory the box was given (run-box.ts
|
|
12
|
+
// mountSource). The model names the box's paths (BOX_WORK), mapped one for one onto the bind's source; every path and
|
|
13
|
+
// message it gets back names the box's, never this machine's.
|
|
14
|
+
import { realpathSync } from "node:fs";
|
|
15
|
+
import { posix } from "node:path";
|
|
16
|
+
import { err, ExecutionError, FileError, ok } from "@earendil-works/pi-durable/env";
|
|
17
|
+
import { NodeExecutionEnv } from "@earendil-works/pi-durable/env/node";
|
|
18
|
+
import { PathOutsideWorkError } from "@parcha/pi-durable-disk";
|
|
19
|
+
import { BOX_WORK } from "./place.js";
|
|
20
|
+
import { openWorkFile, WorkRefused, writeWorkFile } from "./workspace.js";
|
|
21
|
+
/** What a refusal tells the model, by the path it named: what is wrong, and that bash, in the box, can still reach it. */
|
|
22
|
+
const REFUSED = {
|
|
23
|
+
link: (path) => `${path}: refused: a link is on the way to it, or it is one, and read, write and edit follow no link in this run's work/ (bash, in the box, can)`,
|
|
24
|
+
hard_link: (path) => `${path}: refused: it has another hard link, and read, write and edit take only a file with one (bash, in the box, can)`,
|
|
25
|
+
not_regular: (path) => `${path}: refused: it is not a regular file`,
|
|
26
|
+
unreadable: (path) => `${path}: refused: this server may not read it (a command in the box made it private)`,
|
|
27
|
+
over_cap: (path) => `${path}: refused: it is too large`,
|
|
28
|
+
unheld: (path) => `${path}: refused: this host reaches the run's directories by path`,
|
|
29
|
+
};
|
|
30
|
+
const NODE_CODES = { ENOENT: "not_found", EACCES: "permission_denied", EPERM: "permission_denied", ENOTDIR: "not_directory", EISDIR: "is_directory", ELOOP: "invalid" };
|
|
31
|
+
/** A box run's read, write and edit environment on this machine's `hostWork` (canonical: the bind's source), naming the
|
|
32
|
+
* box's paths. Its shell runs nothing, and only the operations those tools make are offered. */
|
|
33
|
+
export function boundFiles(hostWork) {
|
|
34
|
+
// pi's own implementation, only ever handed a checked handle's /proc/self/fd entry, which names that inode and no path.
|
|
35
|
+
const node = new NodeExecutionEnv({ cwd: hostWork });
|
|
36
|
+
/** `text` with this machine's work/ named as the box names it. */
|
|
37
|
+
const boxed = (text) => text.split(`${hostWork}/`).join(`${BOX_WORK}/`).split(hostWork).join(BOX_WORK);
|
|
38
|
+
// The confinement's typed refusal, its message naming no path: the tools name it by the path the call gave
|
|
39
|
+
// (workspace-paths.ts asGivenRefusals). It crosses from pi-durable-disk's pi-durable as a value, typed on this side.
|
|
40
|
+
const outside = (path) => new PathOutsideWorkError(path, "outside_work", "outside the workspace");
|
|
41
|
+
/** `path` as an absolute path of the box, or the refusal of one outside its work/. */
|
|
42
|
+
const absolute = (path) => {
|
|
43
|
+
const abs = posix.resolve(BOX_WORK, path);
|
|
44
|
+
return abs === BOX_WORK || abs.startsWith(`${BOX_WORK}/`) ? ok(abs) : err(outside(path));
|
|
45
|
+
};
|
|
46
|
+
const failure = (error, path) => {
|
|
47
|
+
if (error instanceof WorkRefused) {
|
|
48
|
+
if (error.reason === "missing")
|
|
49
|
+
return new FileError("not_found", `ENOENT: no such file or directory, open '${path}'`, path);
|
|
50
|
+
return new FileError("permission_denied", REFUSED[error.reason](path), path);
|
|
51
|
+
}
|
|
52
|
+
if (error instanceof FileError)
|
|
53
|
+
return new FileError(error.code, boxed(error.message), path, error);
|
|
54
|
+
const code = error?.code;
|
|
55
|
+
return new FileError((code && NODE_CODES[code]) || "unknown", boxed(error?.message ?? String(error)), path);
|
|
56
|
+
};
|
|
57
|
+
/** The work/ the box was given: refused when it is no longer its own canonical path (swapped for a link). */
|
|
58
|
+
const root = () => {
|
|
59
|
+
if (realpathSync(hostWork) !== hostWork)
|
|
60
|
+
throw new WorkRefused(".", "link");
|
|
61
|
+
};
|
|
62
|
+
/** `use` on the file at `path`, opened held: a regular file with one link, reached through no link. */
|
|
63
|
+
async function opened(path, use) {
|
|
64
|
+
const abs = absolute(path);
|
|
65
|
+
if (!abs.ok)
|
|
66
|
+
return abs;
|
|
67
|
+
const rel = posix.relative(BOX_WORK, abs.value);
|
|
68
|
+
if (rel === "")
|
|
69
|
+
return err(new FileError("is_directory", `${abs.value}: is the run's work directory, not a file`, abs.value));
|
|
70
|
+
try {
|
|
71
|
+
root();
|
|
72
|
+
const { handle, stats } = await openWorkFile(hostWork, rel);
|
|
73
|
+
try {
|
|
74
|
+
return ok(await use(handle, stats, abs.value));
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await handle.close().catch(() => undefined);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return err(failure(error, abs.value));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** pi's reader of a checked handle, its info naming the box's path. */
|
|
85
|
+
const reader = async (handle, abs, context) => {
|
|
86
|
+
const made = await node.openBinaryReader(`/proc/self/fd/${handle.fd}`, undefined, context);
|
|
87
|
+
if (!made.ok)
|
|
88
|
+
throw made.error;
|
|
89
|
+
const inner = made.value;
|
|
90
|
+
return {
|
|
91
|
+
info: async (at) => {
|
|
92
|
+
const info = await inner.info(at);
|
|
93
|
+
return info.ok ? ok({ ...info.value, name: posix.basename(abs), path: abs }) : err(failure(info.error, abs));
|
|
94
|
+
},
|
|
95
|
+
read: (offset, length, at) => inner.read(offset, length, at),
|
|
96
|
+
scanLines: (options, at) => inner.scanLines(options, at),
|
|
97
|
+
close: (at) => inner.close(at),
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
/** An operation read, write and edit never make: refused, so nothing else of this machine is reached through it. */
|
|
101
|
+
const unoffered = (name) => async () => err(new FileError("not_supported", `${name} is not offered here: a box run's file tools on this machine read, write and edit, and bash runs in the box`));
|
|
102
|
+
return {
|
|
103
|
+
id: `bound-work:${hostWork}`,
|
|
104
|
+
cwd: BOX_WORK,
|
|
105
|
+
absolutePath: async (path) => absolute(path),
|
|
106
|
+
joinPath: async (parts) => ok(posix.join(...parts)),
|
|
107
|
+
// The mutation queue then keys a file by its absolute path: a link is never followed here, so that is the file.
|
|
108
|
+
canonicalPath: unoffered("canonicalPath"),
|
|
109
|
+
exists: async (path) => {
|
|
110
|
+
const abs = absolute(path);
|
|
111
|
+
if (!abs.ok)
|
|
112
|
+
return abs;
|
|
113
|
+
const found = await opened(abs.value, async () => true);
|
|
114
|
+
// A file refused is there: the operation that follows says why.
|
|
115
|
+
return found.ok || found.error.code !== "not_found" ? ok(true) : ok(false);
|
|
116
|
+
},
|
|
117
|
+
fileInfo: (path) => opened(path, async (_handle, info, abs) => ({ name: posix.basename(abs), path: abs, kind: "file", size: info.size, mtimeMs: info.mtimeMs })),
|
|
118
|
+
readTextFile: (path, context) => opened(path, (handle) => handle.readFile({ encoding: "utf8", ...(context.abortSignal ? { signal: context.abortSignal } : {}) })),
|
|
119
|
+
readBinaryFile: (path, context) => opened(path, async (handle) => new Uint8Array(await handle.readFile(context.abortSignal ? { signal: context.abortSignal } : {}))),
|
|
120
|
+
openBinaryReader: (path, _options, context) => opened(path, (handle, _info, abs) => reader(handle, abs, context)),
|
|
121
|
+
openTextLineReader: (path, context) => opened(path, async (handle, _info, abs) => {
|
|
122
|
+
const made = await node.openTextLineReader(`/proc/self/fd/${handle.fd}`, context);
|
|
123
|
+
if (!made.ok)
|
|
124
|
+
throw failure(made.error, abs);
|
|
125
|
+
return made.value;
|
|
126
|
+
}),
|
|
127
|
+
readTextLines: (path, options, context) => opened(path, async (handle, _info, abs) => {
|
|
128
|
+
const read = await node.readTextLines(`/proc/self/fd/${handle.fd}`, options, context);
|
|
129
|
+
if (!read.ok)
|
|
130
|
+
throw failure(read.error, abs);
|
|
131
|
+
return read.value;
|
|
132
|
+
}),
|
|
133
|
+
writeFile: async (path, content) => {
|
|
134
|
+
const abs = absolute(path);
|
|
135
|
+
if (!abs.ok)
|
|
136
|
+
return abs;
|
|
137
|
+
const rel = posix.relative(BOX_WORK, abs.value);
|
|
138
|
+
if (rel === "")
|
|
139
|
+
return err(new FileError("is_directory", `${abs.value}: is the run's work directory, not a file`, abs.value));
|
|
140
|
+
try {
|
|
141
|
+
root();
|
|
142
|
+
// A new file as a box's command would make it (0644); one already there keeps its mode.
|
|
143
|
+
await writeWorkFile(hostWork, rel, typeof content === "string" ? Buffer.from(content) : content, 0o644, true);
|
|
144
|
+
return ok(undefined);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
return err(failure(error, abs.value));
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
appendFile: unoffered("appendFile"),
|
|
151
|
+
truncateFile: unoffered("truncateFile"),
|
|
152
|
+
flushFile: unoffered("flushFile"),
|
|
153
|
+
renameFile: unoffered("renameFile"),
|
|
154
|
+
listDir: unoffered("listDir"),
|
|
155
|
+
openDirReader: unoffered("openDirReader"),
|
|
156
|
+
watch: unoffered("watch"),
|
|
157
|
+
createDir: unoffered("createDir"),
|
|
158
|
+
remove: unoffered("remove"),
|
|
159
|
+
createTempDir: unoffered("createTempDir"),
|
|
160
|
+
createTempFile: unoffered("createTempFile"),
|
|
161
|
+
exec: async () => err(new ExecutionError("shell_unavailable", "this environment runs no command: bash runs in the box")),
|
|
162
|
+
cleanup: async () => undefined,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BoxRecorder } from "@parcha/agentrun-kernel/host";
|
|
2
|
+
/** The run directory's box record. */
|
|
3
|
+
export declare const BOX_RECORD = "box.json";
|
|
4
|
+
/** The recorder a box start is given for the run in `runDir`: each call replaces the record. `ahead` returns only once
|
|
5
|
+
* the file and its directory are synced; `started` resolves then. */
|
|
6
|
+
export declare function boxRecorder(runDir: string): BoxRecorder;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// A run's box record, beside the run: written durably before anything runs in the box, so whatever crashes after (the
|
|
2
|
+
// run's process, the server, the machine) leaves a record a later start can find the box by. The box's first record
|
|
3
|
+
// (its id, its cgroup, its writer) is written synchronously before its spawn (`ahead`); its second (its first process's
|
|
4
|
+
// pid, start time and pid namespace) before that process is let go (`started`). The box's start names the writer, the
|
|
5
|
+
// run process: a record nothing could count is cleared only once that writer is gone, so a record without one is refused.
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { BoxError } from "@parcha/agentrun-kernel/host";
|
|
8
|
+
import { writeDurable, writeDurableSync } from "../files.js";
|
|
9
|
+
/** The run directory's box record. */
|
|
10
|
+
export const BOX_RECORD = "box.json";
|
|
11
|
+
function text(record) {
|
|
12
|
+
const writer = record.writer;
|
|
13
|
+
if (!writer || !Number.isSafeInteger(writer.pid) || typeof writer.startTime !== "string" || writer.startTime === "") {
|
|
14
|
+
throw new BoxError("box_record_failed", "box_record_failed: a box record names no writer (its run process's pid and start time), so it could never be cleared safely");
|
|
15
|
+
}
|
|
16
|
+
return `${JSON.stringify(record)}\n`;
|
|
17
|
+
}
|
|
18
|
+
/** The recorder a box start is given for the run in `runDir`: each call replaces the record. `ahead` returns only once
|
|
19
|
+
* the file and its directory are synced; `started` resolves then. */
|
|
20
|
+
export function boxRecorder(runDir) {
|
|
21
|
+
const path = join(runDir, BOX_RECORD);
|
|
22
|
+
const failed = (error) => (error instanceof BoxError ? error : new BoxError("box_record_failed", `box_record_failed: the box record could not be written whole: ${error.message}`, { cause: error }));
|
|
23
|
+
return {
|
|
24
|
+
ahead: (record) => {
|
|
25
|
+
try {
|
|
26
|
+
writeDurableSync(path, text(record));
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw failed(error);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
started: async (record) => {
|
|
33
|
+
try {
|
|
34
|
+
await writeDurable(path, text(record));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw failed(error);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { BoxRecord, Reaped } from "@parcha/agentrun-kernel/host";
|
|
2
|
+
/** The data directory's file of quarantined boxes. */
|
|
3
|
+
export declare const BOX_QUARANTINE = "box-quarantine.json";
|
|
4
|
+
/** What serve needs of the box: its reap, and on a shared server the run cgroups under its delegated subtree. */
|
|
5
|
+
export interface BoxHost {
|
|
6
|
+
reap(record: BoxRecord): Promise<Reaped>;
|
|
7
|
+
cgroups?: {
|
|
8
|
+
/** Every run cgroup under the subtree, by path. */
|
|
9
|
+
list(): Promise<string[]>;
|
|
10
|
+
/** Removes an empty cgroup. */
|
|
11
|
+
remove(path: string): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** A process's start time as /proc/<pid>/stat gives it (clock ticks since boot), or undefined when it is not running. */
|
|
15
|
+
export declare function startTimeOf(pid: number): string | undefined;
|
|
16
|
+
/** The record's writer is gone: no process has its pid, or the one that has it started at another time (a reused pid).
|
|
17
|
+
* box-image.ts asks the same of the server that wrote the image's record. */
|
|
18
|
+
export declare function writerGone(writer: BoxRecord["writer"] | undefined): boolean;
|
|
19
|
+
/** The boxes that a reap could not let go, kept across restarts: by run (or "" for a cgroup no record named). */
|
|
20
|
+
export declare class Quarantine {
|
|
21
|
+
private readonly file;
|
|
22
|
+
private readonly entries;
|
|
23
|
+
private constructor();
|
|
24
|
+
static open(file: string): Promise<Quarantine>;
|
|
25
|
+
has(key: string): boolean;
|
|
26
|
+
list(): Array<{
|
|
27
|
+
key: string;
|
|
28
|
+
record: BoxRecord;
|
|
29
|
+
why: string;
|
|
30
|
+
at: string;
|
|
31
|
+
}>;
|
|
32
|
+
add(key: string, record: BoxRecord, why: string): Promise<void>;
|
|
33
|
+
clear(key: string): Promise<void>;
|
|
34
|
+
private saving;
|
|
35
|
+
private save;
|
|
36
|
+
}
|
|
37
|
+
export type Settled = "none" | "owned" | "reaped" | "cleared" | "quarantined";
|
|
38
|
+
/** The quarantine key of a run's box: by the box, so a run whose box is quarantined and that opens a new one keeps the
|
|
39
|
+
* old one held, and the new one's reap never clears it. */
|
|
40
|
+
export declare const boxKey: (runId: string, record: Pick<BoxRecord, "id">) => string;
|
|
41
|
+
/**
|
|
42
|
+
* The box the run in `runDir` recorded, let go if nothing owns it: none recorded, or already let go (`none`); its writer,
|
|
43
|
+
* the run process, still alive, so the box is that process's (`owned`); else reaped. Empty: marked, its cgroup removed
|
|
44
|
+
* (`reaped`). Nothing to count, with its writer gone: marked (`cleared`). Anything else: quarantined, its record kept.
|
|
45
|
+
*/
|
|
46
|
+
export declare function settleBox(host: BoxHost, quarantine: Quarantine, runId: string, runDir: string): Promise<Settled>;
|
|
47
|
+
/** At start, before any run opens a box: every run's box let go that nothing owns; then every box the quarantine still
|
|
48
|
+
* holds that is no longer its run's current one (the run opened another since), tried again by its own record; then
|
|
49
|
+
* every run cgroup no record names, reaped by the cgroup and removed when empty. */
|
|
50
|
+
export declare function sweepBoxes(host: BoxHost, quarantine: Quarantine, runs: ReadonlyArray<{
|
|
51
|
+
id: string;
|
|
52
|
+
dir: string;
|
|
53
|
+
}>): Promise<Record<string, Settled>>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// What serve does with the boxes runs leave: the box a run's process recorded (its box.json), reaped once nothing owns
|
|
2
|
+
// it, and the cgroups no record names. A box is let go only on the reap's own count: empty, its record is marked reaped
|
|
3
|
+
// and its cgroup removed; anything else (left processes, a reap that throws) quarantines it, its record kept, and every
|
|
4
|
+
// later sweep tries again. A record nothing could count (no pid and no cgroup: a crash before the box's first process
|
|
5
|
+
// was known) is cleared only once the run process that wrote it is gone, by its pid and start time, so a box still
|
|
6
|
+
// starting is never written off.
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { readJson, writeDurable } from "../files.js";
|
|
10
|
+
import { BOX_RECORD } from "./record.js";
|
|
11
|
+
/** The data directory's file of quarantined boxes. */
|
|
12
|
+
export const BOX_QUARANTINE = "box-quarantine.json";
|
|
13
|
+
/** A run cgroup removed, or already gone: a reap that empties a cgroup may remove it itself (bwrapBox's does), so a
|
|
14
|
+
* missing one is the removal done. Any other failure is the caller's. */
|
|
15
|
+
async function removeCgroup(cgroups, path) {
|
|
16
|
+
try {
|
|
17
|
+
await cgroups.remove(path);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error?.code !== "ENOENT")
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** A process's start time as /proc/<pid>/stat gives it (clock ticks since boot), or undefined when it is not running. */
|
|
25
|
+
export function startTimeOf(pid) {
|
|
26
|
+
try {
|
|
27
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
28
|
+
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** The record's writer is gone: no process has its pid, or the one that has it started at another time (a reused pid).
|
|
35
|
+
* box-image.ts asks the same of the server that wrote the image's record. */
|
|
36
|
+
export function writerGone(writer) {
|
|
37
|
+
if (!writer || !Number.isSafeInteger(writer.pid) || writer.pid <= 0)
|
|
38
|
+
return true;
|
|
39
|
+
return startTimeOf(writer.pid) !== writer.startTime;
|
|
40
|
+
}
|
|
41
|
+
/** The boxes that a reap could not let go, kept across restarts: by run (or "" for a cgroup no record named). */
|
|
42
|
+
export class Quarantine {
|
|
43
|
+
file;
|
|
44
|
+
entries;
|
|
45
|
+
constructor(file, entries) {
|
|
46
|
+
this.file = file;
|
|
47
|
+
this.entries = entries;
|
|
48
|
+
}
|
|
49
|
+
static async open(file) {
|
|
50
|
+
const kept = await readJson(file);
|
|
51
|
+
const entries = new Map();
|
|
52
|
+
if (Array.isArray(kept))
|
|
53
|
+
for (const e of kept)
|
|
54
|
+
if (e && typeof e.key === "string")
|
|
55
|
+
entries.set(e.key, { record: e.record, why: e.why, at: e.at });
|
|
56
|
+
return new Quarantine(file, entries);
|
|
57
|
+
}
|
|
58
|
+
has(key) {
|
|
59
|
+
return this.entries.has(key);
|
|
60
|
+
}
|
|
61
|
+
list() {
|
|
62
|
+
return [...this.entries].map(([key, e]) => ({ key, ...e }));
|
|
63
|
+
}
|
|
64
|
+
async add(key, record, why) {
|
|
65
|
+
this.entries.set(key, { record, why, at: new Date().toISOString() });
|
|
66
|
+
await this.save();
|
|
67
|
+
}
|
|
68
|
+
async clear(key) {
|
|
69
|
+
if (this.entries.delete(key))
|
|
70
|
+
await this.save();
|
|
71
|
+
}
|
|
72
|
+
// One save at a time, each writing the whole set as it is then: concurrent writes of the same file would share its
|
|
73
|
+
// temporary file, and one could lose another's entries or fail its rename.
|
|
74
|
+
saving = Promise.resolve();
|
|
75
|
+
save() {
|
|
76
|
+
const next = this.saving.catch(() => { }).then(async () => void (await writeDurable(this.file, `${JSON.stringify(this.list())}\n`)));
|
|
77
|
+
this.saving = next;
|
|
78
|
+
return next;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** The quarantine key of a cgroup no record named. */
|
|
82
|
+
const leftoverKey = (path) => `cgroup:${path}`;
|
|
83
|
+
/** The quarantine key of a run's box: by the box, so a run whose box is quarantined and that opens a new one keeps the
|
|
84
|
+
* old one held, and the new one's reap never clears it. */
|
|
85
|
+
export const boxKey = (runId, record) => `${runId}/${record.id}`;
|
|
86
|
+
/** Whether a cgroup is still named by a box other than `key`'s that is not yet let go: a quarantined one, or (`current`)
|
|
87
|
+
* the run's current box. A run's boxes share its cgroup, so one box's empty count never removes another's. */
|
|
88
|
+
function namedElsewhere(quarantine, cgroup, key, current) {
|
|
89
|
+
if (current && !current.reaped && current.cgroup === cgroup && current.id !== key.slice(key.lastIndexOf("/") + 1))
|
|
90
|
+
return true;
|
|
91
|
+
return quarantine.list().some((entry) => entry.key !== key && entry.record.cgroup === cgroup);
|
|
92
|
+
}
|
|
93
|
+
const left = (verdict) => `its reap left ${verdict.left} process${verdict.left === 1 ? "" : "es"} (counted by ${verdict.by})`;
|
|
94
|
+
/**
|
|
95
|
+
* The box the run in `runDir` recorded, let go if nothing owns it: none recorded, or already let go (`none`); its writer,
|
|
96
|
+
* the run process, still alive, so the box is that process's (`owned`); else reaped. Empty: marked, its cgroup removed
|
|
97
|
+
* (`reaped`). Nothing to count, with its writer gone: marked (`cleared`). Anything else: quarantined, its record kept.
|
|
98
|
+
*/
|
|
99
|
+
export async function settleBox(host, quarantine, runId, runDir) {
|
|
100
|
+
const path = join(runDir, BOX_RECORD);
|
|
101
|
+
const stored = (await readJson(path));
|
|
102
|
+
if (!stored || typeof stored.id !== "string" || stored.reaped)
|
|
103
|
+
return "none";
|
|
104
|
+
if (!writerGone(stored.writer))
|
|
105
|
+
return "owned";
|
|
106
|
+
const { reaped: _, ...record } = stored;
|
|
107
|
+
let verdict;
|
|
108
|
+
try {
|
|
109
|
+
verdict = await host.reap(record);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
await quarantine.add(boxKey(runId, record), record, `its reap failed: ${error.message}`);
|
|
113
|
+
return "quarantined";
|
|
114
|
+
}
|
|
115
|
+
if (verdict.by === "none") {
|
|
116
|
+
// Nothing named the box to count, and its writer is gone: --die-with-parent ended whatever had started.
|
|
117
|
+
await writeDurable(path, `${JSON.stringify({ ...record, reaped: { at: new Date().toISOString(), by: "none" } })}\n`);
|
|
118
|
+
await quarantine.clear(boxKey(runId, record));
|
|
119
|
+
return "cleared";
|
|
120
|
+
}
|
|
121
|
+
if (!verdict.empty) {
|
|
122
|
+
await quarantine.add(boxKey(runId, record), record, left(verdict));
|
|
123
|
+
return "quarantined";
|
|
124
|
+
}
|
|
125
|
+
if (record.cgroup && host.cgroups && !namedElsewhere(quarantine, record.cgroup, boxKey(runId, record)))
|
|
126
|
+
await removeCgroup(host.cgroups, record.cgroup);
|
|
127
|
+
await writeDurable(path, `${JSON.stringify({ ...record, reaped: { at: new Date().toISOString(), by: verdict.by } })}\n`);
|
|
128
|
+
await quarantine.clear(boxKey(runId, record));
|
|
129
|
+
return "reaped";
|
|
130
|
+
}
|
|
131
|
+
/** At start, before any run opens a box: every run's box let go that nothing owns; then every box the quarantine still
|
|
132
|
+
* holds that is no longer its run's current one (the run opened another since), tried again by its own record; then
|
|
133
|
+
* every run cgroup no record names, reaped by the cgroup and removed when empty. */
|
|
134
|
+
export async function sweepBoxes(host, quarantine, runs) {
|
|
135
|
+
const settled = {};
|
|
136
|
+
const named = new Set();
|
|
137
|
+
for (const run of runs) {
|
|
138
|
+
settled[run.id] = await settleBox(host, quarantine, run.id, run.dir);
|
|
139
|
+
if (settled[run.id] === "owned" || settled[run.id] === "quarantined") {
|
|
140
|
+
const cgroup = (await readJson(join(run.dir, BOX_RECORD)))?.cgroup;
|
|
141
|
+
if (cgroup)
|
|
142
|
+
named.add(cgroup);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// A run's earlier box, still held: only its own reap's count lets it go. Its cgroup stays named while it is held.
|
|
146
|
+
const current = new Set(runs.map((run) => run.id));
|
|
147
|
+
for (const entry of quarantine.list()) {
|
|
148
|
+
if (entry.key.startsWith("cgroup:"))
|
|
149
|
+
continue;
|
|
150
|
+
const runId = entry.key.slice(0, entry.key.lastIndexOf("/"));
|
|
151
|
+
const now = current.has(runId) ? (await readJson(join(runs.find((r) => r.id === runId).dir, BOX_RECORD))) : null;
|
|
152
|
+
if (now?.id === entry.record.id) {
|
|
153
|
+
if (entry.record.cgroup && quarantine.has(entry.key))
|
|
154
|
+
named.add(entry.record.cgroup);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
let verdict;
|
|
158
|
+
if (!writerGone(entry.record.writer))
|
|
159
|
+
verdict = undefined;
|
|
160
|
+
else
|
|
161
|
+
verdict = await host.reap(entry.record).catch(() => undefined);
|
|
162
|
+
if (verdict && (verdict.empty || verdict.by === "none")) {
|
|
163
|
+
const cgroup = entry.record.cgroup;
|
|
164
|
+
if (verdict.empty && cgroup && host.cgroups && !namedElsewhere(quarantine, cgroup, entry.key, now))
|
|
165
|
+
await removeCgroup(host.cgroups, cgroup);
|
|
166
|
+
await quarantine.clear(entry.key);
|
|
167
|
+
}
|
|
168
|
+
else if (entry.record.cgroup)
|
|
169
|
+
named.add(entry.record.cgroup);
|
|
170
|
+
}
|
|
171
|
+
if (!host.cgroups)
|
|
172
|
+
return settled;
|
|
173
|
+
for (const cgroup of await host.cgroups.list()) {
|
|
174
|
+
if (named.has(cgroup))
|
|
175
|
+
continue;
|
|
176
|
+
const record = { id: leftoverKey(cgroup), cgroup, writer: { pid: 0, startTime: "" } };
|
|
177
|
+
let verdict;
|
|
178
|
+
try {
|
|
179
|
+
verdict = await host.reap(record);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
await quarantine.add(leftoverKey(cgroup), record, `its reap failed: ${error.message}`);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (verdict.empty) {
|
|
186
|
+
await removeCgroup(host.cgroups, cgroup);
|
|
187
|
+
await quarantine.clear(leftoverKey(cgroup));
|
|
188
|
+
}
|
|
189
|
+
else
|
|
190
|
+
await quarantine.add(leftoverKey(cgroup), record, left(verdict));
|
|
191
|
+
}
|
|
192
|
+
return settled;
|
|
193
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type BoxOffer } from "./boxes.js";
|
|
3
|
+
/** The setting that names another image for Docker boxes than this server's own. */
|
|
4
|
+
export declare const DOCKER_IMAGE_ENV = "AGENTRUN_DOCKER_IMAGE";
|
|
5
|
+
/** What the default image has, in words. */
|
|
6
|
+
export declare const RECIPE_HAS = "python, git, curl, node, rg";
|
|
7
|
+
/** The base the default image builds from: `python:3.12-slim`, pinned to the multi-arch index digest Docker Hub served
|
|
8
|
+
* for that tag on 2026-11-03, so a build gets the same base wherever it runs. To move it, read the tag's index digest
|
|
9
|
+
* again (an anonymous pull token from auth.docker.io for `repository:library/python:pull`, then a HEAD of
|
|
10
|
+
* registry-1.docker.io/v2/library/python/manifests/3.12-slim accepting an OCI index or a manifest list: its
|
|
11
|
+
* `docker-content-digest`), and put it here. The recipe's hash changes with it, and so does the image's tag
|
|
12
|
+
* (DEFAULT_DOCKER_IMAGE), so every server builds the new one at its next start. */
|
|
13
|
+
export declare const BOX_BASE = "python:3.12-slim@sha256:b18b261e1b4974b4f321451ad5251ded85abb22c2b8b262da527dda1d031ab30";
|
|
14
|
+
/** The default image's recipe: a Dockerfile that needs no other file, written alone into a private context directory for
|
|
15
|
+
* each build (buildContext). Its hash names the image. */
|
|
16
|
+
export declare const BOX_RECIPE: string;
|
|
17
|
+
/** The label the built image carries: its recipe's sha256. */
|
|
18
|
+
export declare const RECIPE_LABEL = "agentrun.box-image";
|
|
19
|
+
export declare const RECIPE_HASH: string;
|
|
20
|
+
/** The default image: this server's own, built from BOX_RECIPE, its tag the recipe's hash. */
|
|
21
|
+
export declare const DEFAULT_DOCKER_IMAGE: string;
|
|
22
|
+
/** The image a Docker box starts from on a server or a run with `env`. */
|
|
23
|
+
export declare const boxImageOf: (env: NodeJS.ProcessEnv) => string;
|
|
24
|
+
/** Where the image's state is kept for the run's processes, in the data directory. */
|
|
25
|
+
export declare const IMAGE_STATE_FILE = "box-image.json";
|
|
26
|
+
/** How long the start's pull, or build, may take; past it, it is stopped and docker is unavailable. */
|
|
27
|
+
export declare const PULL_TIMEOUT_MS: number;
|
|
28
|
+
export declare const BUILD_TIMEOUT_MS: number;
|
|
29
|
+
/** How long Docker may take to say whether it has the image. */
|
|
30
|
+
export declare const INSPECT_TIMEOUT_MS = 5000;
|
|
31
|
+
/** How long past the pull's deadline a run still waits on a file that says preparing: the server's own timer ends the
|
|
32
|
+
* pull at the deadline, so only a server that is gone leaves the file saying preparing after it. */
|
|
33
|
+
export declare const STALE_AFTER_MS = 30000;
|
|
34
|
+
/** How long after a failed build or pull it is tried once more. */
|
|
35
|
+
export declare const RETRY_AFTER_MS = 5000;
|
|
36
|
+
/** How long the server's close waits for the image's last record to be saved, so a docker that hangs cannot hold it. */
|
|
37
|
+
export declare const CLOSE_WAIT_MS = 5000;
|
|
38
|
+
/** The image's state: `ready`; `preparing` while the server pulls it; `unavailable`, with why. */
|
|
39
|
+
export type ImageState = {
|
|
40
|
+
state: "ready";
|
|
41
|
+
} | {
|
|
42
|
+
state: "preparing";
|
|
43
|
+
reason: string;
|
|
44
|
+
} | {
|
|
45
|
+
state: "unavailable";
|
|
46
|
+
reason: string;
|
|
47
|
+
};
|
|
48
|
+
/** The file's record: the image, its state, and while it is coming, the time it is stopped by (`until`, epoch ms) and
|
|
49
|
+
* the timeline row a run that waits for it writes (`row`). `writer`: the server that wrote it, its pid and start time,
|
|
50
|
+
* where /proc gives that. */
|
|
51
|
+
export type ImageRecord = {
|
|
52
|
+
image: string;
|
|
53
|
+
state: ImageState["state"];
|
|
54
|
+
reason?: string;
|
|
55
|
+
until?: number;
|
|
56
|
+
row?: string;
|
|
57
|
+
writer?: {
|
|
58
|
+
pid: number;
|
|
59
|
+
startTime: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export type DockerImage = {
|
|
63
|
+
readonly image: string;
|
|
64
|
+
/** The state now. */
|
|
65
|
+
state(): ImageState;
|
|
66
|
+
/** Settles with the state once it is ready or unavailable. */
|
|
67
|
+
readonly settled: Promise<ImageState>;
|
|
68
|
+
/** Stops a build or pull in progress and waits, at most CLOSE_WAIT_MS, for its last record to be saved: the server's
|
|
69
|
+
* close (and a start that failed) calls it before the data directory's lock goes, so no record of this server lands
|
|
70
|
+
* after the next one took the lock. */
|
|
71
|
+
close(): Promise<void>;
|
|
72
|
+
};
|
|
73
|
+
/** Removes the record: this server has no Docker box, so no run waits on its image. */
|
|
74
|
+
export declare const clearImage: (data: string) => Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* The image's readiness on this server: asked of Docker now (within INSPECT_TIMEOUT_MS), and when Docker has none (or,
|
|
77
|
+
* for the default, has one of another recipe), built from BOX_RECIPE or pulled, in the background, within its bound; a
|
|
78
|
+
* try that fails, but not for want of time, is made once more, `retryAfterMs` later. `onChange` is told each state after
|
|
79
|
+
* the first. The record in the data directory follows the state.
|
|
80
|
+
*/
|
|
81
|
+
export declare function dockerImage(env: NodeJS.ProcessEnv, data: string, image: string, options?: {
|
|
82
|
+
pullTimeoutMs?: number;
|
|
83
|
+
buildTimeoutMs?: number;
|
|
84
|
+
inspectTimeoutMs?: number;
|
|
85
|
+
retryAfterMs?: number;
|
|
86
|
+
onChange?: (state: ImageState, ms: number) => void;
|
|
87
|
+
warn?: (message: string) => void;
|
|
88
|
+
}): Promise<DockerImage>;
|
|
89
|
+
/** Docker's offer with the image's state on it: available while it is ready or preparing, else unavailable with why. */
|
|
90
|
+
export declare function withImage(offer: BoxOffer, image: ImageState): BoxOffer;
|
|
91
|
+
/**
|
|
92
|
+
* Before a run's box is made from `image`: returns once the server's record says the image is ready, or says nothing
|
|
93
|
+
* of it (no record, another image); waits while it says the image is being built or pulled, telling `note` once, as the
|
|
94
|
+
* run's timeline row; and throws, with the server's reason, when that failed, and saying to restart the server when the
|
|
95
|
+
* server that was making it is gone (its writer, or where that cannot be told, its deadline). A cancel of `context`
|
|
96
|
+
* ends the wait.
|
|
97
|
+
*/
|
|
98
|
+
export declare function awaitImage(data: string, image: string, context: Context, note: (summary: string) => Promise<void> | void): Promise<void>;
|