@parcha/agentrun-serve 0.0.0-bootstrap.0 → 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.
Files changed (229) hide show
  1. package/CHANGELOG.md +560 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +1724 -0
  5. package/dist/adapters.d.ts +205 -0
  6. package/dist/adapters.js +459 -0
  7. package/dist/agents.d.ts +124 -0
  8. package/dist/agents.js +302 -0
  9. package/dist/app.d.ts +7 -0
  10. package/dist/app.js +324 -0
  11. package/dist/bound-files.d.ts +4 -0
  12. package/dist/bound-files.js +164 -0
  13. package/dist/box/record.d.ts +6 -0
  14. package/dist/box/record.js +41 -0
  15. package/dist/box/sweep.d.ts +53 -0
  16. package/dist/box/sweep.js +193 -0
  17. package/dist/box-image.d.ts +98 -0
  18. package/dist/box-image.js +283 -0
  19. package/dist/box-relay.d.ts +42 -0
  20. package/dist/box-relay.js +222 -0
  21. package/dist/boxes.d.ts +54 -0
  22. package/dist/boxes.js +182 -0
  23. package/dist/cap.d.ts +224 -0
  24. package/dist/cap.js +721 -0
  25. package/dist/catalog.d.ts +20 -0
  26. package/dist/catalog.js +53 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +167 -0
  29. package/dist/coding-tools.d.ts +31 -0
  30. package/dist/coding-tools.js +81 -0
  31. package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
  32. package/dist/console/assets/index-BN7oVcO4.js +445 -0
  33. package/dist/console/assets/index-By-jkqki.css +1 -0
  34. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  35. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
  36. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
  37. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  38. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
  39. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
  40. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
  41. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
  42. package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  43. package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
  44. package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
  45. package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  46. package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
  47. package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  48. package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  49. package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
  50. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  51. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
  52. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  53. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
  54. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
  55. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
  56. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
  57. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
  58. package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
  59. package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
  60. package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
  61. package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
  62. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
  63. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
  64. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
  65. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
  66. package/dist/console/index.html +15 -0
  67. package/dist/daytona-api.d.ts +21 -0
  68. package/dist/daytona-api.js +101 -0
  69. package/dist/decision-rows.d.ts +11 -0
  70. package/dist/decision-rows.js +116 -0
  71. package/dist/decisions.d.ts +94 -0
  72. package/dist/decisions.js +184 -0
  73. package/dist/effort-guidance.d.ts +5 -0
  74. package/dist/effort-guidance.js +14 -0
  75. package/dist/environment.d.ts +5 -0
  76. package/dist/environment.js +11 -0
  77. package/dist/errors.d.ts +72 -0
  78. package/dist/errors.js +66 -0
  79. package/dist/exa-keyless.d.ts +35 -0
  80. package/dist/exa-keyless.js +202 -0
  81. package/dist/fetch-page.d.ts +114 -0
  82. package/dist/fetch-page.js +182 -0
  83. package/dist/files.d.ts +60 -0
  84. package/dist/files.js +153 -0
  85. package/dist/grade.d.ts +96 -0
  86. package/dist/grade.js +348 -0
  87. package/dist/graph-view.d.ts +100 -0
  88. package/dist/graph-view.js +212 -0
  89. package/dist/harness-app.d.ts +38 -0
  90. package/dist/harness-app.js +626 -0
  91. package/dist/harness.d.ts +53 -0
  92. package/dist/harness.js +74 -0
  93. package/dist/home-path.d.ts +27 -0
  94. package/dist/home-path.js +78 -0
  95. package/dist/host-tools.d.ts +20 -0
  96. package/dist/host-tools.js +140 -0
  97. package/dist/host.d.ts +39 -0
  98. package/dist/host.js +81 -0
  99. package/dist/hosted-search.d.ts +27 -0
  100. package/dist/hosted-search.js +129 -0
  101. package/dist/import-sources.d.ts +104 -0
  102. package/dist/import-sources.js +629 -0
  103. package/dist/import-summary.d.ts +25 -0
  104. package/dist/import-summary.js +75 -0
  105. package/dist/import-worker.d.ts +26 -0
  106. package/dist/import-worker.js +41 -0
  107. package/dist/import.d.ts +145 -0
  108. package/dist/import.js +1221 -0
  109. package/dist/index.d.ts +7 -0
  110. package/dist/index.js +6 -0
  111. package/dist/key-check.d.ts +36 -0
  112. package/dist/key-check.js +108 -0
  113. package/dist/key-refusal.d.ts +51 -0
  114. package/dist/key-refusal.js +187 -0
  115. package/dist/learn/check.d.ts +99 -0
  116. package/dist/learn/check.js +259 -0
  117. package/dist/learn/grade.d.ts +79 -0
  118. package/dist/learn/grade.js +433 -0
  119. package/dist/learn/index.d.ts +7 -0
  120. package/dist/learn/index.js +11 -0
  121. package/dist/learn/invisible.d.ts +5 -0
  122. package/dist/learn/invisible.js +42 -0
  123. package/dist/learn/notes.d.ts +59 -0
  124. package/dist/learn/notes.js +146 -0
  125. package/dist/learn/reflect.d.ts +49 -0
  126. package/dist/learn/reflect.js +167 -0
  127. package/dist/learn/secrets.d.ts +18 -0
  128. package/dist/learn/secrets.js +111 -0
  129. package/dist/learn/skills.d.ts +84 -0
  130. package/dist/learn/skills.js +198 -0
  131. package/dist/learning-routes.d.ts +196 -0
  132. package/dist/learning-routes.js +609 -0
  133. package/dist/learning-run.d.ts +304 -0
  134. package/dist/learning-run.js +797 -0
  135. package/dist/learning-words.d.ts +73 -0
  136. package/dist/learning-words.js +171 -0
  137. package/dist/learning.d.ts +377 -0
  138. package/dist/learning.js +801 -0
  139. package/dist/llm.d.ts +40 -0
  140. package/dist/llm.js +37 -0
  141. package/dist/llms.txt +37 -0
  142. package/dist/mcp-servers.d.ts +115 -0
  143. package/dist/mcp-servers.js +445 -0
  144. package/dist/mcp.d.ts +51 -0
  145. package/dist/mcp.js +392 -0
  146. package/dist/model.d.ts +184 -0
  147. package/dist/model.js +484 -0
  148. package/dist/monid.d.ts +74 -0
  149. package/dist/monid.js +277 -0
  150. package/dist/openapi/agentrun-v2.openapi.json +4805 -0
  151. package/dist/openapi.d.ts +10 -0
  152. package/dist/openapi.js +1417 -0
  153. package/dist/owner.d.ts +55 -0
  154. package/dist/owner.js +222 -0
  155. package/dist/packs.d.ts +71 -0
  156. package/dist/packs.js +180 -0
  157. package/dist/page.d.ts +32 -0
  158. package/dist/page.js +133 -0
  159. package/dist/paid-calls.d.ts +46 -0
  160. package/dist/paid-calls.js +110 -0
  161. package/dist/pause.d.ts +68 -0
  162. package/dist/pause.js +97 -0
  163. package/dist/pdf-pages.d.ts +44 -0
  164. package/dist/pdf-pages.js +147 -0
  165. package/dist/place.d.ts +46 -0
  166. package/dist/place.js +105 -0
  167. package/dist/print.d.ts +20 -0
  168. package/dist/print.js +29 -0
  169. package/dist/propose.d.ts +38 -0
  170. package/dist/propose.js +82 -0
  171. package/dist/quiet-sqlite-warning.d.ts +1 -0
  172. package/dist/quiet-sqlite-warning.js +14 -0
  173. package/dist/request-start.d.ts +14 -0
  174. package/dist/request-start.js +226 -0
  175. package/dist/result.d.ts +3 -0
  176. package/dist/result.js +5 -0
  177. package/dist/rows.d.ts +46 -0
  178. package/dist/rows.js +121 -0
  179. package/dist/run-box.d.ts +134 -0
  180. package/dist/run-box.js +440 -0
  181. package/dist/run-manifest.d.ts +27 -0
  182. package/dist/run-manifest.js +60 -0
  183. package/dist/runnable.d.ts +80 -0
  184. package/dist/runnable.js +162 -0
  185. package/dist/runs.d.ts +840 -0
  186. package/dist/runs.js +2279 -0
  187. package/dist/secret-cut.d.ts +27 -0
  188. package/dist/secret-cut.js +109 -0
  189. package/dist/secrets.d.ts +50 -0
  190. package/dist/secrets.js +140 -0
  191. package/dist/server-lock.d.ts +44 -0
  192. package/dist/server-lock.js +140 -0
  193. package/dist/server.d.ts +626 -0
  194. package/dist/server.js +1756 -0
  195. package/dist/sessions.d.ts +4 -0
  196. package/dist/sessions.js +105 -0
  197. package/dist/skills.d.ts +31 -0
  198. package/dist/skills.js +68 -0
  199. package/dist/stats.d.ts +101 -0
  200. package/dist/stats.js +82 -0
  201. package/dist/tool-keys.d.ts +151 -0
  202. package/dist/tool-keys.js +273 -0
  203. package/dist/tool-plane.d.ts +143 -0
  204. package/dist/tool-plane.js +242 -0
  205. package/dist/tools.d.ts +147 -0
  206. package/dist/tools.js +253 -0
  207. package/dist/turn-end.d.ts +23 -0
  208. package/dist/turn-end.js +14 -0
  209. package/dist/turns.d.ts +34 -0
  210. package/dist/turns.js +202 -0
  211. package/dist/uploads.d.ts +104 -0
  212. package/dist/uploads.js +474 -0
  213. package/dist/usage.d.ts +29 -0
  214. package/dist/usage.js +58 -0
  215. package/dist/validate.d.ts +55 -0
  216. package/dist/validate.js +175 -0
  217. package/dist/web-fetch.d.ts +64 -0
  218. package/dist/web-fetch.js +262 -0
  219. package/dist/web-search.d.ts +54 -0
  220. package/dist/web-search.js +136 -0
  221. package/dist/webhooks.d.ts +182 -0
  222. package/dist/webhooks.js +487 -0
  223. package/dist/workspace-paths.d.ts +33 -0
  224. package/dist/workspace-paths.js +104 -0
  225. package/dist/workspace.d.ts +88 -0
  226. package/dist/workspace.js +369 -0
  227. package/launcher/agentrun-serve +109 -0
  228. package/package.json +96 -1
  229. package/skills/agentrun-serve/SKILL.md +128 -0
@@ -0,0 +1,440 @@
1
+ // A sandbox run's box: one per run, made on the first call that runs in it and labelled with the run's id, so the label
2
+ // is the record (a bound box's read, write and edit run on this machine: bound-files.ts). A run's process that starts
3
+ // again finds it by that label and first kills the commands the process before it left running. Serve destroys it at
4
+ // every settle (a cancel included) and at archive, and its start sweeps the boxes of runs that have ended. A box gets the
5
+ // run's work/ only, at BOX_WORK, a fixed environment (never this process's, so no key or token enters it), no network,
6
+ // and limits on its CPUs, memory and processes. pi-transport is an optional peer of this package: it is loaded only for a
7
+ // run whose place is a box.
8
+ //
9
+ // Docker's box is made here, in the run's process, as this server's user, with work/ bound. A Daytona box is remote: it
10
+ // cannot bind work/, and its key is the server's alone. The server makes it (through the box relay, box-relay.ts), seeds
11
+ // it with work/, pulls work/ back at each turn's end and once more before the run's end is recorded, and destroys it
12
+ // after that pull; the run's process reaches it through the relay, which holds the key. What the run's own host tools
13
+ // file in work/ meanwhile (writeInWork) is copied into the box too, so its tools read it.
14
+ import { createHash } from "node:crypto";
15
+ import { appendFile, lstat, readFile, realpath } from "node:fs/promises";
16
+ import { isAbsolute, join, posix, relative, sep } from "node:path";
17
+ import { pathToFileURL } from "node:url";
18
+ import { BACKGROUND_CONTEXT as BACKGROUND } from "@earendil-works/chord/context";
19
+ import { awaitImage, boxImageOf } from "./box-image.js";
20
+ import { RELAYED_KEY, relayedBox, relayFetch } from "./box-relay.js";
21
+ import { readJson, writeDurable } from "./files.js";
22
+ import { FAUX_ENV } from "./model.js";
23
+ import { agentWorkDir, BOX_WORK } from "./place.js";
24
+ /** The label a run's box carries: the run's id. */
25
+ export const RUN_LABEL = "agentrun.run";
26
+ /** And this one, the same on every run's box, which the start's sweep lists them by. */
27
+ export const KIND_LABEL = "agentrun.box";
28
+ /** The whole environment of a box's programs: a constant, never this process's. */
29
+ export const BOX_ENV = Object.freeze({ LANG: "C.UTF-8", HOME: "/tmp" });
30
+ /** How long a box lives whatever happens to the server: a bound on a leaked box, never its clean end. */
31
+ export const BOX_LIFETIME_MS = 24 * 60 * 60_000;
32
+ /** A bash command's timeout when the model names none. */
33
+ export const BASH_TIMEOUT_MS = 300_000;
34
+ /** The image a Docker box starts from (box-image.ts, where the server makes it ready). */
35
+ export { DEFAULT_DOCKER_IMAGE, DOCKER_IMAGE_ENV } from "./box-image.js";
36
+ /** The settings that bound a Docker box; unset, their defaults: enough for a build, and safe on a laptop, where one run's
37
+ * runaway build or fork bomb would otherwise starve everything else. */
38
+ export const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
39
+ export const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
40
+ export const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
41
+ /** 2 CPUs' time: a CFS quota (pi-transport's Docker provider), which holds whatever CPU count Docker's VM has. */
42
+ export const DEFAULT_BOX_CPUS = 2;
43
+ /** 4 GiB, swap included (--memory-swap the same). */
44
+ export const DEFAULT_BOX_MEMORY = "4g";
45
+ /** Processes and threads at once. */
46
+ export const DEFAULT_BOX_PIDS = 1024;
47
+ /** The fewest CPUs a quota gives: the kernel's least quota is 1 ms of each 100 ms period. A quota is also a whole number of
48
+ * µs, so a count too large for one (or a long string of digits, which reads as Infinity) is refused too. */
49
+ const MIN_BOX_CPUS = 0.01;
50
+ const MIB = 1024 * 1024;
51
+ /** A size's units as Docker reads them, each 1024 of the one before. */
52
+ const SIZE_UNITS = { b: 1, k: 1024, m: MIB, g: 1024 * MIB };
53
+ /** The least memory Docker gives a container. */
54
+ const MIN_BOX_MEMORY = 6 * MIB;
55
+ /** The most processes a cgroup may be given (the kernel's PID_MAX_LIMIT); above it, every create fails. */
56
+ const MAX_BOX_PIDS = 4_194_304;
57
+ /** A Docker box's limits from `env`: each setting's value, or its default when unset or empty. A value that is not one, or
58
+ * that every create would fail on (less than a 1 ms quota, less memory than Docker gives, more processes than the kernel
59
+ * allows), throws, naming its setting: the start checks them (startServe), so no run meets one. */
60
+ export function boxLimitsOf(env) {
61
+ const read = (name, what, takes) => {
62
+ const value = env[name];
63
+ if (!value)
64
+ return undefined;
65
+ if (!takes(value))
66
+ throw new Error(`${name} is ${what}; it is ${JSON.stringify(value)}`);
67
+ return value;
68
+ };
69
+ const cpus = read(BOX_CPUS_ENV, "a number of CPUs of at least 0.01, such as 2 or 1.5", (value) => /^\d+(\.\d+)?$/.test(value) && Number(value) >= MIN_BOX_CPUS && Number.isSafeInteger(Math.round(Number(value) * 100_000)));
70
+ const memory = read(BOX_MEMORY_ENV, "a size of at least 6m with its unit (b, k, m or g), such as 512m or 4g", (value) => {
71
+ const size = /^(\d+(?:\.\d+)?)([bkmg])$/i.exec(value);
72
+ // Its bytes as Docker reads them, and pi-transport's Docker provider: the number times the unit, the fraction dropped.
73
+ const bytes = size ? Math.floor(Number(size[1]) * SIZE_UNITS[size[2].toLowerCase()]) : 0;
74
+ return Number.isSafeInteger(bytes) && bytes >= MIN_BOX_MEMORY;
75
+ });
76
+ const pids = read(BOX_PIDS_ENV, "a whole number from 1 to 4194304, such as 1024", (value) => /^\d+$/.test(value) && Number(value) >= 1 && Number(value) <= MAX_BOX_PIDS);
77
+ return { cpus: cpus === undefined ? DEFAULT_BOX_CPUS : Number(cpus), memory: memory ?? DEFAULT_BOX_MEMORY, pidsLimit: pids === undefined ? DEFAULT_BOX_PIDS : Number(pids) };
78
+ }
79
+ /** Under `--faux` only: a module whose default export, given the data root, is the provider runs' boxes come from in
80
+ * place of Docker (the tests' faux box). */
81
+ export const FAUX_BOX_ENV = "AGENTRUN_SERVE_FAUX_BOX";
82
+ /** A remote box's sync mark in its run's directory: the box's id and the listing its seed or last pull left. The
83
+ * server alone writes it. */
84
+ export const BOX_SYNC_FILE = "box-sync.json";
85
+ /** What the run's process copied into its remote box after the seed (a file its host tools filed in work/): one JSON line
86
+ * per file, `{path, sha256, bytes}`, appended by that process alone. The mark has one writer, the server, so the
87
+ * process never writes it; a pull folds these lines into the mark it compares against, for paths the mark lacks, so
88
+ * the box's later edit of such a file comes back instead of reading as a change the server made. */
89
+ export const BOX_MIRRORED_FILE = "box-mirrored.jsonl";
90
+ /** `source`, when it is below `root` through no link and is its own canonical path; else a refusal naming the link.
91
+ * `root`, the data root, is canonical already (startServe), so a link above it is the operator's choice. */
92
+ export async function mountSource(root, source) {
93
+ const below = relative(root, source);
94
+ if (!below || below.startsWith("..") || isAbsolute(below))
95
+ throw new Error(`the mount source ${source} is not below the data root ${root}`);
96
+ let at = root;
97
+ for (const part of below.split(sep)) {
98
+ at = join(at, part);
99
+ if ((await lstat(at)).isSymbolicLink())
100
+ throw new Error(`the mount source ${source} is refused: ${at} is a link`);
101
+ }
102
+ if ((await realpath(source)) !== source)
103
+ throw new Error(`the mount source ${source} is refused: it is not its own canonical path`);
104
+ return source;
105
+ }
106
+ /** Every mount a run's box gets, each through mountSource: its work/ only, read-write, at BOX_WORK. A run's home joins
107
+ * this list (read-only parts included) when it comes; nothing else of the data root does. */
108
+ export async function boxMounts(root, runDir, place) {
109
+ return [{ source: await mountSource(root, join(runDir, "work")), target: agentWorkDir(runDir, place) }];
110
+ }
111
+ /** The provider runs' boxes come from: under `--faux` with a faux box, its module's; else Docker on this machine, run as
112
+ * this process's user (serve's: a run's process is its child), so what a box writes in work/ stays serve's, within the
113
+ * box limits the server's settings give (boxLimitsOf), and whose create first waits while the server pulls its image
114
+ * (box-image.ts). */
115
+ export async function runBoxProvider(place, env, root) {
116
+ const faux = env[FAUX_ENV] ? env[FAUX_BOX_ENV] : undefined;
117
+ if (faux)
118
+ return fauxBoxes(faux, root);
119
+ if (place.mode !== "sandbox" || place.box !== "docker")
120
+ throw new Error(`runs in the ${place.mode === "sandbox" ? place.box : "runner"} place have no box`);
121
+ const { dockerBoxes } = await import("@parcha/pi-transport/box/docker");
122
+ const user = process.getuid && process.getgid ? `${process.getuid()}:${process.getgid()}` : undefined;
123
+ // With no capability and no way to gain one (no program in a run's box changes user): as root (serve run as uid 0) a
124
+ // box could otherwise make a device node in work/.
125
+ const image = boxImageOf(env);
126
+ return { ...dockerBoxes({ image, ...(user ? { user } : {}), ...boxLimitsOf(env), dropCapabilities: true }), ready: (context, note) => awaitImage(root, image, context, note) };
127
+ }
128
+ /** The tests' faux box provider, from its module. */
129
+ export const fauxBoxes = async (module, root) => (await import(pathToFileURL(module).href)).default(root);
130
+ export function runBox(given, run) {
131
+ const source = typeof given === "function" ? { provider: given } : given;
132
+ let held;
133
+ // What the host tools filed while no box was open in this process: a box a process before it made has no seed now, so
134
+ // these go in when it opens (and to a new box, whose seed carries them anyway, again: the same bytes).
135
+ const filed = new Map();
136
+ const open = async (context, note) => {
137
+ const { boxEnv, endLeftCommands } = await import("@parcha/pi-transport/hands");
138
+ const { box, made } = "relay" in source ? await relayedRunBox(source.relay, run.dir, run.id, context) : await localRunBox(await source.provider(), run, context, note);
139
+ if (!made) {
140
+ // A process before this one left it: what it still runs is killed first, since its calls were answered interrupted.
141
+ const ended = await endLeftCommands(box, context);
142
+ if (!ended.ok)
143
+ throw new Error(`the run's box could not be taken over: ${ended.error.message}`);
144
+ }
145
+ if (filed.size) {
146
+ const queued = [...filed];
147
+ filed.clear();
148
+ const sent = await box.upload(queued.map(([path, bytes]) => ({ path: posix.join(BOX_WORK, path), bytes })), context);
149
+ if (!sent.ok)
150
+ mirrorFailed(queued.map(([path]) => path).join(", "), sent.error);
151
+ else
152
+ for (const [path, bytes] of queued)
153
+ await mirrored(run.dir, path, bytes);
154
+ }
155
+ return { box, env: boxEnv(box, { maxExecMs: BASH_TIMEOUT_MS, onLost: () => void (held = undefined) }) };
156
+ };
157
+ const opened = (context, note = () => undefined) => {
158
+ held ??= open(context, note).catch((error) => {
159
+ held = undefined;
160
+ throw error;
161
+ });
162
+ return held;
163
+ };
164
+ let binds;
165
+ let checked;
166
+ const env = async (context, note) => (await opened(context, note)).env;
167
+ return {
168
+ // The bind's source, or what a remote box is seeded from: a path another harness names under it is the same file in
169
+ // the box (coding-tools.ts boxPath).
170
+ hostWork: join(run.dir, "work"),
171
+ env,
172
+ // Whether the provider binds it (BoxProvider.mounts): then the file tools may work on it here (bound-files.ts). A
173
+ // remote box binds nothing.
174
+ bound() {
175
+ if ("relay" in source)
176
+ return Promise.resolve(false);
177
+ const provider = source.provider;
178
+ binds ??= provider().then((boxes) => boxes.mounts === true, (error) => {
179
+ binds = undefined;
180
+ throw error;
181
+ });
182
+ return binds;
183
+ },
184
+ // Before a file tool works on work/ here, once a process: a box an earlier process of the run left may still run a
185
+ // command that changes work/, so that box is taken over (env: its left commands killed first). None, none is made.
186
+ // A remote box's file tools never work here.
187
+ leftEnded(context) {
188
+ if ("relay" in source)
189
+ return Promise.resolve();
190
+ const provider = source.provider;
191
+ checked ??= (async () => {
192
+ if (held)
193
+ return void (await held);
194
+ const listed = await (await provider()).list({ [RUN_LABEL]: run.id }, context);
195
+ if (!listed.ok)
196
+ throw listed.error;
197
+ if (listed.value.length)
198
+ await env(context);
199
+ })().catch((error) => {
200
+ checked = undefined;
201
+ throw error;
202
+ });
203
+ return checked;
204
+ },
205
+ ...("relay" in source
206
+ ? {
207
+ // An open (or opening) box is written now; with none, the file waits for the box's open.
208
+ mirror: async (path, data) => {
209
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
210
+ const box = held && (await held.catch(() => undefined))?.box;
211
+ if (!box)
212
+ return void filed.set(path, bytes);
213
+ const sent = await box.upload([{ path: posix.join(BOX_WORK, path), bytes }], BACKGROUND);
214
+ if (!sent.ok)
215
+ throw sent.error;
216
+ await mirrored(run.dir, path, bytes);
217
+ },
218
+ }
219
+ : {}),
220
+ };
221
+ }
222
+ /** Notes in BOX_MIRRORED_FILE that `bytes` at `path` (below work/) went into the run's box: one appended line. */
223
+ async function mirrored(runDir, path, bytes) {
224
+ const line = { path, sha256: createHash("sha256").update(bytes).digest("hex"), bytes: bytes.length };
225
+ await appendFile(join(runDir, BOX_MIRRORED_FILE), `${JSON.stringify(line)}\n`, { mode: 0o600 });
226
+ }
227
+ /** `mark` with each file the run's process mirrored into the box since (BOX_MIRRORED_FILE) that it lacks: as the bytes
228
+ * both sides held, so the box's edit of it is a change to fetch and this machine's copy is not a change of its own. */
229
+ async function withMirrored(runDir, mark) {
230
+ const text = await readFile(join(runDir, BOX_MIRRORED_FILE), "utf8").catch(() => "");
231
+ const held = new Set(mark.entries.map((entry) => entry.path));
232
+ const added = new Map();
233
+ for (const line of text.split("\n")) {
234
+ let entry;
235
+ try {
236
+ entry = JSON.parse(line);
237
+ }
238
+ catch {
239
+ continue;
240
+ }
241
+ if (typeof entry.path !== "string" || typeof entry.sha256 !== "string" || typeof entry.bytes !== "number" || held.has(entry.path))
242
+ continue;
243
+ // The newest line for a path wins; its listed fields never match the box's, so the pull lists it as changed.
244
+ added.set(entry.path, { path: entry.path, kind: "file", bytes: entry.bytes, sha256: entry.sha256, mode: 0o644, mtime: "0" });
245
+ }
246
+ if (!added.size)
247
+ return mark;
248
+ const entries = [...mark.entries, ...added.values()].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
249
+ return { entries, bytes: entries.reduce((sum, entry) => sum + entry.bytes, 0) };
250
+ }
251
+ /** Said in the run's process log: a file the host tools filed in work/ that its remote box did not get. */
252
+ function mirrorFailed(paths, error) {
253
+ process.stderr.write(`${JSON.stringify({ at: new Date().toISOString(), event: "box_mirror_failed", message: `${paths} filed in work/ but not copied into the run's box: ${error.message}` })}\n`);
254
+ }
255
+ /** A box of this process's provider: the run's, by its label, or one made now with work/ bound, once its image is in
256
+ * (the provider's `ready`, `note` writing the one timeline row while it is built or pulled). */
257
+ async function localRunBox(boxes, run, context, note) {
258
+ const found = await attachRunBox(boxes, run.id, context);
259
+ if (found)
260
+ return { box: found, made: false };
261
+ // A box made while the server builds or pulls its image waits for the image, not for a `docker run` that pulls it.
262
+ if (boxes.ready) {
263
+ try {
264
+ await boxes.ready(context, note);
265
+ }
266
+ catch (error) {
267
+ if (context.abortSignal?.aborted)
268
+ throw error;
269
+ throw new Error(`the run's box could not be made: ${error.message}`);
270
+ }
271
+ }
272
+ const spec = {
273
+ env: BOX_ENV, workspace: agentWorkDir(run.dir, run.place), mounts: await boxMounts(run.root, run.dir, run.place),
274
+ labels: { [RUN_LABEL]: run.id, [KIND_LABEL]: "run" }, network: "none", maxLifetimeMs: BOX_LIFETIME_MS,
275
+ };
276
+ const made = await boxes.create(spec, context);
277
+ if (!made.ok) {
278
+ // A create that failed may still have left a box (a client cut off while the daemon made it): it carries the label.
279
+ await destroyRunBoxes(boxes, run.id, context).catch(() => undefined);
280
+ throw new Error(`the run's box could not be made: ${made.error.message}`);
281
+ }
282
+ return { box: made.value, made: true };
283
+ }
284
+ /** A remote box, which the server finds or makes and seeds (ensureRemoteBox), reached through its relay: this process's
285
+ * Daytona provider holds no key, and every call it makes goes to the relay, which sends it on with the server's. */
286
+ async function relayedRunBox(root, runDir, runId, context) {
287
+ const given = await relayedBox(root, runDir, runId, context.abortSignal);
288
+ const { daytonaBoxes } = await import("@parcha/pi-transport/box/daytona");
289
+ const boxes = daytonaBoxes({ apiKey: RELAYED_KEY, apiUrl: given.apiUrl, fetch: relayFetch(root, runDir, runId) });
290
+ const attached = await boxes.attach(given.id, context);
291
+ if (!attached.ok)
292
+ throw new Error(`the run's box could not be reached: ${attached.error.message}`);
293
+ if (!attached.value)
294
+ throw new Error(`the run's box ${given.id} is not running`);
295
+ return { box: attached.value, made: given.made };
296
+ }
297
+ /** The spec of a run's remote box: its work/ comes with its seed, never a mount. */
298
+ const remoteSpec = (runId) => ({
299
+ env: BOX_ENV, workspace: BOX_WORK, labels: { [RUN_LABEL]: runId, [KIND_LABEL]: "run" }, network: "none", maxLifetimeMs: BOX_LIFETIME_MS,
300
+ });
301
+ const markOf = async (runDir) => {
302
+ const kept = (await readJson(join(runDir, BOX_SYNC_FILE)));
303
+ return typeof kept?.box === "string" && kept.mark && Array.isArray(kept.mark.entries) ? kept : undefined;
304
+ };
305
+ const keepMark = (runDir, mark) => writeDurable(join(runDir, BOX_SYNC_FILE), `${JSON.stringify(mark)}\n`);
306
+ /** The server's side of a remote box: run `run`'s box, found by its label or made, with its work/ seeded once (its mark
307
+ * says so); its id, and whether it was made now. A found box whose network is not closed is destroyed and made again;
308
+ * a box whose seed fails is destroyed, and the call fails. */
309
+ export async function ensureRemoteBox(boxes, run, context, wake) {
310
+ let box = await runningRunBox(boxes, run.id, context, wake);
311
+ let made = false;
312
+ if (box && box.facts().network !== "none") {
313
+ await destroyRunBoxes(boxes, run.id, context);
314
+ box = undefined;
315
+ }
316
+ if (!box) {
317
+ const created = await boxes.create(remoteSpec(run.id), context);
318
+ if (!created.ok) {
319
+ await destroyRunBoxes(boxes, run.id, context).catch(() => undefined);
320
+ throw new Error(`the run's box could not be made: ${created.error.message}`);
321
+ }
322
+ box = created.value;
323
+ made = true;
324
+ if (box.facts().network !== "none") {
325
+ await box.destroy(context);
326
+ throw new Error("the run's box was made with its network open, so it is not used");
327
+ }
328
+ }
329
+ // A box found without its seed's mark was made by a server that went down before it seeded it: seeded now.
330
+ if ((await markOf(run.dir))?.box !== box.id) {
331
+ const { seedDir } = await import("@parcha/pi-transport/sync");
332
+ const seeded = await seedDir(box, { from: join(run.dir, "work"), to: BOX_WORK }, context);
333
+ if (!seeded.ok) {
334
+ await box.destroy(context).catch(() => undefined);
335
+ throw new Error(`the run's files could not be copied into its box: ${seeded.error.message}`);
336
+ }
337
+ await keepMark(run.dir, { box: box.id, mark: seeded.value.mark });
338
+ }
339
+ return { id: box.id, made };
340
+ }
341
+ /** A pull that did not bring the box's work/ back whole: what it wrote is kept, with its mark, and the box must stay.
342
+ * `lasting`: a stop another pull will meet again (an archive the extractor cannot read, or a limit a pull that wrote
343
+ * nothing reached); else the copy failed, and a later pull may land. */
344
+ export class PullIncomplete extends Error {
345
+ lasting;
346
+ /** The box that keeps what did not come back. */
347
+ box;
348
+ constructor(message, lasting, box) {
349
+ super(message);
350
+ this.lasting = lasting;
351
+ this.box = box;
352
+ }
353
+ }
354
+ /** How many pulls one copy back takes at most: each pull past a limit brings the next part, up to the limit again. */
355
+ const PULL_ROUNDS = 8;
356
+ /** The server's side of a remote box: what changed in the box's work/ since its mark, pulled into the run's work/ by the
357
+ * safe extractor (nothing outside work/, no link, safe names only). A file this machine changed since the mark stays
358
+ * (`if_unchanged`), and what the box removed is removed here too. A pull a limit stopped after it wrote something is
359
+ * followed by another, which asks only for the rest. Throws when the copy fails (the mark kept), and PullIncomplete when
360
+ * it is not whole: a caller then keeps the box. */
361
+ export async function pullRemoteBox(boxes, run, context, wake) {
362
+ const box = await runningRunBox(boxes, run.id, context, wake);
363
+ if (!box)
364
+ return undefined;
365
+ const { pullDir } = await import("@parcha/pi-transport/sync");
366
+ const total = { changed: 0, files: 0, bytes: 0, removed: 0 };
367
+ for (let round = 1;; round++) {
368
+ const kept = await markOf(run.dir);
369
+ const since = kept?.box === box.id ? await withMirrored(run.dir, kept.mark) : undefined;
370
+ const pulled = await pullDir(box, { from: BOX_WORK, to: join(run.dir, "work"), ...(since ? { since } : {}), mirrorDeletes: true, overwrite: "if_unchanged" }, context);
371
+ if (!pulled.ok)
372
+ throw new Error(`the run's files could not be copied back from its box: ${pulled.error.message}`);
373
+ // What it wrote is whole and in the mark, a stopped pull's too: the next pull asks only for the rest.
374
+ await keepMark(run.dir, { box: box.id, mark: pulled.value.mark });
375
+ const { changed, files, directories, bytes, removed, stopped } = pulled.value;
376
+ if (round === 1)
377
+ total.changed = changed;
378
+ total.files += files;
379
+ total.bytes += bytes;
380
+ total.removed += removed;
381
+ if (!stopped)
382
+ return total;
383
+ const wrote = files + directories + removed > 0;
384
+ if (stopped.reason === "copy_failed")
385
+ throw new PullIncomplete(`the copy back from the run's box stopped: ${stopped.message}`, false, box.id);
386
+ if (stopped.reason === "malformed" || !wrote || round >= PULL_ROUNDS)
387
+ throw new PullIncomplete(`the copy back from the run's box stopped (${stopped.reason}): ${stopped.message}`, true, box.id);
388
+ }
389
+ }
390
+ /** The running box labelled with run `runId`; with none running, one `wake` started (Daytona stopped or paused it), else none. */
391
+ async function runningRunBox(boxes, runId, context, wake) {
392
+ const box = await attachRunBox(boxes, runId, context);
393
+ if (box || !wake || (await wake()) === 0)
394
+ return box;
395
+ return attachRunBox(boxes, runId, context);
396
+ }
397
+ /** The running box labelled with run `runId`, if any. */
398
+ async function attachRunBox(boxes, runId, context) {
399
+ const listed = await boxes.list({ [RUN_LABEL]: runId }, context);
400
+ if (!listed.ok)
401
+ throw listed.error;
402
+ for (const ref of listed.value) {
403
+ const attached = await boxes.attach(ref.id, context);
404
+ if (!attached.ok)
405
+ throw attached.error;
406
+ if (attached.value)
407
+ return attached.value;
408
+ }
409
+ return undefined;
410
+ }
411
+ /** Destroys every box labelled with run `runId`; how many it destroyed. */
412
+ export async function destroyRunBoxes(boxes, runId, context) {
413
+ return destroyListed(boxes, { [RUN_LABEL]: runId }, () => true, context);
414
+ }
415
+ /** The start's sweep: destroys every run's box whose run `ended` says is over, once `before` (a remote box's pull) for its
416
+ * run says it may go. A box of a run this server does not know is left to its lifetime: another server's, or one being
417
+ * made. */
418
+ export async function sweepRunBoxes(boxes, ended, context, before) {
419
+ return destroyListed(boxes, { [KIND_LABEL]: "run" }, (labels) => typeof labels[RUN_LABEL] === "string" && ended(labels[RUN_LABEL]), context, before);
420
+ }
421
+ async function destroyListed(boxes, labels, pick, context, before) {
422
+ const listed = await boxes.list(labels, context);
423
+ if (!listed.ok)
424
+ throw listed.error;
425
+ let destroyed = 0;
426
+ for (const ref of listed.value.filter((r) => pick(r.labels))) {
427
+ const box = await boxes.attach(ref.id, context);
428
+ if (!box.ok)
429
+ throw box.error;
430
+ if (!box.value)
431
+ continue;
432
+ if (before && !(await before(ref.labels[RUN_LABEL], ref.id)))
433
+ continue;
434
+ const gone = await box.value.destroy(context);
435
+ if (!gone.ok)
436
+ throw gone.error;
437
+ destroyed++;
438
+ }
439
+ return destroyed;
440
+ }
@@ -0,0 +1,27 @@
1
+ /** The most files the line names; the rest are counted. */
2
+ export declare const MANIFEST_ENTRIES = 20;
3
+ /** The most the first message may take, as the JSON string the run's door is sent: pi-durable-disk's door takes a body of
4
+ * at most 1 MiB (serve.ts), and this leaves room for the request's other fields. */
5
+ export declare const FIRST_MESSAGE_BYTES: number;
6
+ /** `bytes` as a person reads a size: `32 B`, `1.5 KB`, `2.0 MB`. */
7
+ export declare const sizeOf: (bytes: number) => string;
8
+ /** A file the line names: its path as the run's tools take it, and its size. */
9
+ export type ManifestFile = {
10
+ path: string;
11
+ size: number;
12
+ };
13
+ /** `name` as a JSON string, each character UNSEEN names as its `\uXXXX` escape: so a quote or a comma in it cannot end
14
+ * it and forge another entry, and nothing in it can break the line or reorder what is read. */
15
+ export declare const quoted: (name: string) => string;
16
+ /** `label: "a" (1 B), "b" (2 B).`, at most `entries` (MANIFEST_ENTRIES) of `files`, each name `quoted`, and then `and N
17
+ * more`, or with none named `label: N files.`; undefined for no file. */
18
+ export declare function filesLine(label: string, files: readonly ManifestFile[], entries?: number): string | undefined;
19
+ /** The regular files under the run's work/inputs/, by their path from work/, in order, as deep as an upload's path
20
+ * goes: walked from work/ as the run's file list is (workspace.ts walkWork), entering inputs/ alone, so a link at
21
+ * inputs/ or anywhere below it is never followed; a dot-name left out. None when there is no inputs/ or it cannot be
22
+ * read. */
23
+ export declare function inputFiles(work: string): Promise<ManifestFile[]>;
24
+ /** The run's first message: `content`, then, after a blank line, the files given to it, when it has any: as many named
25
+ * as keep the message within `budget` (FIRST_MESSAGE_BYTES), else only how many, else no line at all, so the line never
26
+ * turns a message the run took into one its door refuses. */
27
+ export declare function firstMessage(content: string, work: string, budget?: number): Promise<string>;
@@ -0,0 +1,60 @@
1
+ // What a run is told of its workspace: one line after its first message naming the files given to it (`file_ids`,
2
+ // copied into its work/inputs/, uploads.ts), so a model asked about "the attached file" knows where it is. On every
3
+ // harness: it rides in the first message itself, which runs.ts sends to the run's door. Bounded: at most
4
+ // MANIFEST_ENTRIES files, then how many more, and never past what the door takes in one message (FIRST_MESSAGE_BYTES):
5
+ // a message that fits at the run's creation still fits with its line.
6
+ import { INPUTS_DIR } from "./uploads.js";
7
+ import { walkWork } from "./workspace.js";
8
+ /** The most files the line names; the rest are counted. */
9
+ export const MANIFEST_ENTRIES = 20;
10
+ /** The most the first message may take, as the JSON string the run's door is sent: pi-durable-disk's door takes a body of
11
+ * at most 1 MiB (serve.ts), and this leaves room for the request's other fields. */
12
+ export const FIRST_MESSAGE_BYTES = (1 << 20) - 4096;
13
+ /** `bytes` as a person reads a size: `32 B`, `1.5 KB`, `2.0 MB`. */
14
+ export const sizeOf = (bytes) => bytes < 1024 ? `${bytes} B` : bytes < 1024 * 1024 ? `${(bytes / 1024).toFixed(1)} KB` : `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
15
+ /** What a quoted name never holds as itself: a control character, a format character (an RTL override, a zero-width
16
+ * space) or a line or paragraph separator, which JSON leaves as they are where it escapes no more than it must. */
17
+ const UNSEEN = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu;
18
+ /** `name` as a JSON string, each character UNSEEN names as its `\uXXXX` escape: so a quote or a comma in it cannot end
19
+ * it and forge another entry, and nothing in it can break the line or reorder what is read. */
20
+ export const quoted = (name) => JSON.stringify(name).replace(UNSEEN, (found) => Array.from({ length: found.length }, (_, i) => `\\u${found.charCodeAt(i).toString(16).padStart(4, "0")}`).join(""));
21
+ /** `label: "a" (1 B), "b" (2 B).`, at most `entries` (MANIFEST_ENTRIES) of `files`, each name `quoted`, and then `and N
22
+ * more`, or with none named `label: N files.`; undefined for no file. */
23
+ export function filesLine(label, files, entries = MANIFEST_ENTRIES) {
24
+ if (files.length === 0)
25
+ return undefined;
26
+ const named = files.slice(0, Math.min(entries, MANIFEST_ENTRIES)).map((file) => `${quoted(file.path)} (${sizeOf(file.size)})`);
27
+ const more = files.length - named.length;
28
+ if (named.length === 0)
29
+ return `${label}: ${files.length} ${files.length === 1 ? "file" : "files"}.`;
30
+ return `${label}: ${named.join(", ")}${more > 0 ? `, and ${more} more` : ""}.`;
31
+ }
32
+ /** The size of `text` as the door is sent it: a JSON string, in UTF-8 bytes. */
33
+ const sentBytes = (text) => Buffer.byteLength(JSON.stringify(text));
34
+ /** How deep the walk of work/inputs/ goes: an upload's path is at most 1024 characters, so at most 512 folders deep,
35
+ * and inputs/ is one more. */
36
+ const INPUTS_DEPTH = 513;
37
+ /** The regular files under the run's work/inputs/, by their path from work/, in order, as deep as an upload's path
38
+ * goes: walked from work/ as the run's file list is (workspace.ts walkWork), entering inputs/ alone, so a link at
39
+ * inputs/ or anywhere below it is never followed; a dot-name left out. None when there is no inputs/ or it cannot be
40
+ * read. */
41
+ export async function inputFiles(work) {
42
+ const files = [];
43
+ await walkWork(work, (path, stats) => void (stats.isFile() && files.push({ path, size: stats.size })), {
44
+ skip: (name, path) => name.startsWith(".") || (path === name && name !== INPUTS_DIR),
45
+ depth: INPUTS_DEPTH,
46
+ }).catch(() => undefined);
47
+ return files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
48
+ }
49
+ /** The run's first message: `content`, then, after a blank line, the files given to it, when it has any: as many named
50
+ * as keep the message within `budget` (FIRST_MESSAGE_BYTES), else only how many, else no line at all, so the line never
51
+ * turns a message the run took into one its door refuses. */
52
+ export async function firstMessage(content, work, budget = FIRST_MESSAGE_BYTES) {
53
+ const files = await inputFiles(work);
54
+ for (let entries = Math.min(files.length, MANIFEST_ENTRIES); entries >= 0 && files.length > 0; entries--) {
55
+ const message = `${content}\n\n${filesLine("Files for this run", files, entries)}`;
56
+ if (sentBytes(message) <= budget)
57
+ return message;
58
+ }
59
+ return content;
60
+ }
@@ -0,0 +1,80 @@
1
+ import { type InputIssue } from "./errors.js";
2
+ import { type HarnessCapability } from "./harness.js";
3
+ import { type ModelRef } from "./model.js";
4
+ import type { BoxOffer } from "./boxes.js";
5
+ import { type ToolSettingsMap } from "./tool-plane.js";
6
+ /** A revision's body as it is saved or stored. */
7
+ export type RevisionShape = {
8
+ kind: "agentic";
9
+ instructions: string;
10
+ tools?: readonly string[];
11
+ model?: string;
12
+ harness?: string;
13
+ place?: {
14
+ mode: string;
15
+ box?: string;
16
+ };
17
+ toolSettings?: ToolSettingsMap;
18
+ } | {
19
+ kind: "workflow";
20
+ workflow: unknown;
21
+ tools?: readonly string[];
22
+ harness?: string;
23
+ place?: {
24
+ mode: string;
25
+ box?: string;
26
+ };
27
+ toolSettings?: ToolSettingsMap;
28
+ };
29
+ /** One thing that keeps a revision from running here. `host`: a setting of this host could fix it. `tool` (one it does
30
+ * not bind), `missing` (a bound tool's unset variables), `adapter`, `decision` (a decision provider's unset key), `codeNodes`
31
+ * (code nodes this server does not run), `shell` (a shell or executor call), `tier`, `harness` and `box` (the place's,
32
+ * which this server does not have) name it for a run's 409 details. */
33
+ export type Blocker = InputIssue & {
34
+ host: boolean;
35
+ tool?: string;
36
+ missing?: {
37
+ tool: string;
38
+ vars: string[];
39
+ };
40
+ adapter?: string;
41
+ decision?: {
42
+ provider: string;
43
+ needs: string[];
44
+ };
45
+ codeNodes?: true;
46
+ shell?: true;
47
+ tier?: string;
48
+ harness?: string;
49
+ box?: string;
50
+ };
51
+ /**
52
+ * The model `harness` runs an agentic revision on here: `ref`, its own `provider/model-id`, or with none this host's
53
+ * default for that harness. `why`: the model itself is the problem (`host`, a setting of this host could fix it);
54
+ * `refused`: the harness runs here but refuses that model. Undefined when claude-agent does not run here: its model is
55
+ * its own, and the harness says why. A save, a run and capabilities' `harnesses[].default_model` all ask this, so they
56
+ * cannot drift.
57
+ */
58
+ export declare function harnessModel(env: NodeJS.ProcessEnv, harness: string, ref: string | undefined, available: boolean): Promise<{
59
+ model: ModelRef;
60
+ } | {
61
+ why: string;
62
+ host: boolean;
63
+ } | {
64
+ refused: string;
65
+ } | undefined>;
66
+ /** The reason a warning gives: the revision runs once this host has what it names. */
67
+ export declare const NOT_SET_UP = "not_set_up_here";
68
+ /** Set to 1 (`--allow-code-nodes`), this server runs workflows' `code` nodes: in the run's process, through the DSL's
69
+ * `new Function` transform, which is no sandbox. Off by default. */
70
+ export declare const CODE_NODES_ENV = "AGENTRUN_SERVE_CODE_NODES";
71
+ /** What keeps `revision` from running in `env` under the server's tool `settings` (tool-plane.ts). `boxes`: what this
72
+ * server's box registry set up at its start (boxes.ts); none, every box is unavailable. `offers`: the harnesses' offers
73
+ * the server already holds (its reading); none given, they are probed here. */
74
+ export declare function blockersOf(env: NodeJS.ProcessEnv, revision: RevisionShape, settings?: ToolSettingsMap, { capped, boxes, offers }?: {
75
+ capped?: boolean;
76
+ boxes?: readonly BoxOffer[];
77
+ offers?: readonly HarnessCapability[];
78
+ }): Promise<Blocker[]>;
79
+ /** A blocker as a field issue, for a 422 or a warning. */
80
+ export declare const issueOf: ({ field, reason, message, fix }: Blocker) => InputIssue;