@foldrun/core 0.3.0 → 0.5.0

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 (175) hide show
  1. package/README.md +27 -10
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +3 -0
  4. package/dist/src/account.d.ts +45 -0
  5. package/dist/src/account.js +130 -0
  6. package/dist/src/api-tools.d.ts +8 -0
  7. package/dist/src/api-tools.js +22 -4
  8. package/dist/src/approvals.d.ts +104 -1
  9. package/dist/src/approvals.js +192 -2
  10. package/dist/src/browser-pod.d.ts +129 -0
  11. package/dist/src/browser-pod.js +284 -0
  12. package/dist/src/budget.d.ts +32 -0
  13. package/dist/src/budget.js +177 -0
  14. package/dist/src/catalog.js +3 -1
  15. package/dist/src/clock.d.ts +49 -0
  16. package/dist/src/clock.js +121 -0
  17. package/dist/src/completions.js +17 -8
  18. package/dist/src/confine.d.ts +22 -0
  19. package/dist/src/confine.js +224 -4
  20. package/dist/src/deploy.d.ts +33 -0
  21. package/dist/src/deploy.js +145 -6
  22. package/dist/src/egress.d.ts +26 -2
  23. package/dist/src/egress.js +8 -1
  24. package/dist/src/eol.d.ts +2 -0
  25. package/dist/src/eol.js +7 -0
  26. package/dist/src/evals.d.ts +9 -0
  27. package/dist/src/evals.js +26 -13
  28. package/dist/src/flow-lint.d.ts +12 -0
  29. package/dist/src/flow-lint.js +331 -1
  30. package/dist/src/flow-patterns.d.ts +141 -0
  31. package/dist/src/flow-patterns.js +568 -0
  32. package/dist/src/gitrepo.d.ts +18 -0
  33. package/dist/src/gitrepo.js +49 -0
  34. package/dist/src/host-env.d.ts +8 -0
  35. package/dist/src/host-env.js +48 -0
  36. package/dist/src/json-schema.d.ts +12 -0
  37. package/dist/src/json-schema.js +202 -0
  38. package/dist/src/kinds.js +1 -1
  39. package/dist/src/language.d.ts +17 -0
  40. package/dist/src/language.js +55 -0
  41. package/dist/src/layout.d.ts +69 -0
  42. package/dist/src/layout.js +200 -0
  43. package/dist/src/library.d.ts +9 -0
  44. package/dist/src/library.js +43 -4
  45. package/dist/src/limits.d.ts +84 -0
  46. package/dist/src/limits.js +287 -0
  47. package/dist/src/locale.d.ts +47 -0
  48. package/dist/src/locale.js +177 -0
  49. package/dist/src/mail.d.ts +88 -0
  50. package/dist/src/mail.js +245 -0
  51. package/dist/src/model-probe.d.ts +3 -0
  52. package/dist/src/model-probe.js +1 -0
  53. package/dist/src/notify.d.ts +132 -8
  54. package/dist/src/notify.js +360 -58
  55. package/dist/src/openapi.js +5 -3
  56. package/dist/src/operator.d.ts +201 -0
  57. package/dist/src/operator.js +251 -0
  58. package/dist/src/paths.d.ts +33 -0
  59. package/dist/src/paths.js +87 -0
  60. package/dist/src/platform.d.ts +144 -4
  61. package/dist/src/platform.js +27 -3
  62. package/dist/src/provider-health.d.ts +55 -0
  63. package/dist/src/provider-health.js +233 -0
  64. package/dist/src/providers.d.ts +481 -0
  65. package/dist/src/providers.js +1105 -6
  66. package/dist/src/refusal.d.ts +83 -0
  67. package/dist/src/refusal.js +281 -0
  68. package/dist/src/run-container.d.ts +206 -17
  69. package/dist/src/run-container.js +547 -80
  70. package/dist/src/runner.d.ts +179 -10
  71. package/dist/src/runner.js +1423 -169
  72. package/dist/src/runtime.d.ts +52 -0
  73. package/dist/src/runtime.js +493 -58
  74. package/dist/src/script-tools.d.ts +15 -2
  75. package/dist/src/script-tools.js +44 -4
  76. package/dist/src/secret-files.d.ts +6 -5
  77. package/dist/src/secret-files.js +24 -11
  78. package/dist/src/secret-health.d.ts +83 -0
  79. package/dist/src/secret-health.js +177 -0
  80. package/dist/src/secrets.d.ts +38 -1
  81. package/dist/src/secrets.js +197 -96
  82. package/dist/src/starter.d.ts +9 -0
  83. package/dist/src/starter.js +95 -11
  84. package/dist/src/step-exec.d.ts +106 -1
  85. package/dist/src/step-exec.js +558 -85
  86. package/dist/src/step-removal.d.ts +15 -0
  87. package/dist/src/step-removal.js +49 -0
  88. package/dist/src/storage.d.ts +23 -4
  89. package/dist/src/storage.js +125 -23
  90. package/dist/src/store.d.ts +492 -38
  91. package/dist/src/store.js +882 -69
  92. package/dist/src/subagents.d.ts +75 -0
  93. package/dist/src/subagents.js +149 -0
  94. package/dist/src/tar.js +2 -1
  95. package/dist/src/test-mode.d.ts +111 -0
  96. package/dist/src/test-mode.js +285 -0
  97. package/dist/src/tool-names.d.ts +13 -1
  98. package/dist/src/tool-names.js +38 -11
  99. package/dist/src/tool-programs.d.ts +26 -0
  100. package/dist/src/tool-programs.js +172 -0
  101. package/dist/src/tool-test.js +152 -33
  102. package/dist/src/translator.d.ts +8 -2
  103. package/dist/src/translator.js +71 -24
  104. package/dist/src/trigger-log.d.ts +43 -0
  105. package/dist/src/trigger-log.js +122 -0
  106. package/dist/src/triggers.d.ts +23 -0
  107. package/dist/src/triggers.js +101 -12
  108. package/dist/src/untrusted-fetch.d.ts +11 -0
  109. package/dist/src/untrusted-fetch.js +77 -0
  110. package/dist/src/web-actions.d.ts +91 -0
  111. package/dist/src/web-actions.js +199 -0
  112. package/dist/src/webhook.d.ts +19 -3
  113. package/dist/src/webhook.js +50 -11
  114. package/index.ts +3 -0
  115. package/package.json +5 -5
  116. package/src/account.ts +149 -0
  117. package/src/api-tools.ts +32 -4
  118. package/src/approvals.ts +253 -2
  119. package/src/browser-pod.ts +313 -0
  120. package/src/budget.ts +178 -0
  121. package/src/catalog.ts +3 -1
  122. package/src/clock.ts +149 -0
  123. package/src/completions.ts +17 -8
  124. package/src/confine.ts +224 -4
  125. package/src/deploy.ts +137 -6
  126. package/src/egress.ts +32 -4
  127. package/src/eol.ts +7 -0
  128. package/src/evals.ts +36 -11
  129. package/src/flow-lint.ts +371 -1
  130. package/src/flow-patterns.ts +597 -0
  131. package/src/gitrepo.ts +48 -0
  132. package/src/host-env.ts +51 -0
  133. package/src/json-schema.ts +184 -0
  134. package/src/kinds.ts +1 -1
  135. package/src/language.ts +62 -0
  136. package/src/layout.ts +228 -0
  137. package/src/library.ts +50 -4
  138. package/src/limits.ts +290 -0
  139. package/src/locale.ts +217 -0
  140. package/src/mail.ts +316 -0
  141. package/src/model-probe.ts +4 -0
  142. package/src/notify.ts +391 -44
  143. package/src/openapi.ts +5 -3
  144. package/src/operator.ts +300 -0
  145. package/src/paths.ts +83 -0
  146. package/src/platform.ts +158 -5
  147. package/src/provider-health.ts +275 -0
  148. package/src/providers.ts +1368 -6
  149. package/src/refusal.ts +320 -0
  150. package/src/run-container.ts +611 -76
  151. package/src/runner.ts +1463 -165
  152. package/src/runtime.ts +487 -55
  153. package/src/script-tools.ts +55 -6
  154. package/src/secret-files.ts +22 -10
  155. package/src/secret-health.ts +230 -0
  156. package/src/secrets.ts +191 -95
  157. package/src/starter.ts +96 -11
  158. package/src/step-exec.ts +548 -41
  159. package/src/step-removal.ts +59 -0
  160. package/src/storage.ts +149 -24
  161. package/src/store.ts +1227 -74
  162. package/src/subagents.ts +189 -0
  163. package/src/tar.ts +2 -1
  164. package/src/test-mode.ts +311 -0
  165. package/src/tool-names.ts +40 -11
  166. package/src/tool-programs.ts +179 -0
  167. package/src/tool-test.ts +159 -32
  168. package/src/translator.ts +74 -23
  169. package/src/trigger-log.ts +160 -0
  170. package/src/triggers.ts +102 -12
  171. package/src/untrusted-fetch.ts +88 -0
  172. package/src/web-actions.ts +237 -0
  173. package/src/webhook.ts +58 -11
  174. package/templates/hello/agents/curator/agent.md +1 -1
  175. package/templates/hello/agents/notetaker/agent.md +1 -1
@@ -4,8 +4,11 @@ import type { EventExtra } from "./step-exec.ts";
4
4
  import { type RuntimeSpec } from "./runtime.ts";
5
5
  import type { ScriptSpec } from "./script-tools.ts";
6
6
  import type { ConsultSpec } from "./agent-tools.ts";
7
+ import type { SubagentSpec } from "./subagents.ts";
8
+ import { type OperatorEvent } from "./operator.ts";
7
9
  import type { SearchRoot, RunDigest } from "./context-tools.ts";
8
10
  import type { TranslatorSpec } from "./translator.ts";
11
+ import { type BrowserPodOutcome } from "./browser-pod.ts";
9
12
  /** What crosses the boundary. Everything in here is values — pre-resolved
10
13
  * secrets in headers, assembled prompt, serializable MCP configs. */
11
14
  export interface ContainerStepInput {
@@ -29,10 +32,13 @@ export interface ContainerStepInput {
29
32
  * their agent.md files host-side. The driver rebuilds the consult tools
30
33
  * in here; the callees run toolless, so nothing else need cross. */
31
34
  consults: ConsultSpec[];
35
+ /** `subagents:` — built host-side (runner.ts), plain JSON. */
36
+ subagents?: SubagentSpec[];
32
37
  timeoutSec?: number;
33
38
  /** The step's spend ceiling and the model's per-token price — see
34
39
  * step-exec.ts. Values, so the driver can enforce them in the pod. */
35
40
  budgetUsd?: number | null;
41
+ budgetNote?: string;
36
42
  price?: {
37
43
  input: number;
38
44
  output: number;
@@ -40,6 +46,13 @@ export interface ContainerStepInput {
40
46
  verify?: string;
41
47
  /** `output: json` — checked inside, where the reply is. */
42
48
  output?: "json";
49
+ /** `schema:` and `max_turns:`, resolved host-side — see ExecOptions. */
50
+ schema?: Record<string, unknown> | boolean;
51
+ maxTurns?: number;
52
+ /** `limits:` resolved host-side, and the SDK-name → foldrun-name map the
53
+ * count reads (limits.ts) — enforced in the pod by the same hook. */
54
+ limits?: Record<string, number>;
55
+ toolOwners?: Record<string, string>;
43
56
  /** tools: [search] — the directories to search, as paths INSIDE the
44
57
  * container (/workspace/…, /library/…). */
45
58
  search?: SearchRoot[];
@@ -47,10 +60,21 @@ export interface ContainerStepInput {
47
60
  history?: RunDigest[];
48
61
  /** tools: [desks] — the account's other workspaces' runs, gathered host-side. */
49
62
  desks?: RunDigest[];
63
+ /** tools: [ask] — ask_person, and how long it may wait for an answer. */
64
+ ask?: {
65
+ timeoutSec: number;
66
+ };
50
67
  /** A Chat-Completions provider: the driver starts the runtime's translator
51
68
  * on loopback and points the SDK at it. Null or absent: the env's
52
69
  * ANTHROPIC_BASE_URL is spoken to directly. */
53
70
  translator?: TranslatorSpec | null;
71
+ /** A granted tool acts outward (`outward: true`): an executor that could
72
+ * put a browsing step on the slim image keeps this one on the full image,
73
+ * where a browser in the step is always there (browser-pod.ts). */
74
+ outward?: boolean;
75
+ /** "full" — this attempt must have the full image: the re-run after the
76
+ * browser pod was lost. Absent lets the executor choose. */
77
+ image?: "full";
54
78
  }
55
79
  /**
56
80
  * How long the sandbox actually existed, measured host-side — the driver
@@ -92,11 +116,25 @@ export interface ContainerStepOutcome {
92
116
  inputTokens: number;
93
117
  outputTokens: number;
94
118
  } | null;
119
+ /** Every turn priced at its own model, when sub-agents ran on others —
120
+ * see ExecOutcome.turnsCostUsd. */
121
+ turnsCostUsd?: number;
95
122
  /** What the sandbox actually touched — see the driver's readActuals. */
96
123
  res?: StepActuals | null;
97
124
  /** Set by the isolated executors only — an in-process step rents no
98
125
  * sandbox, so it has no compute seconds to bill. */
99
126
  timing?: StepTiming | null;
127
+ /** Which runner image the sandbox ran, as the executor chose it: `pod`
128
+ * when a browsing step ran on slim and browsed through the account's
129
+ * browser pod. Absent from an executor with one image. */
130
+ image?: {
131
+ variant: "full" | "slim";
132
+ why?: string;
133
+ pod?: boolean;
134
+ } | null;
135
+ /** The pod's reconnects and, when it was lost, what the step had written —
136
+ * see ExecOutcome.browserPod. */
137
+ browserPod?: BrowserPodOutcome;
100
138
  }
101
139
  /**
102
140
  * The one place the timing line is worded, so the docker and k8s traces
@@ -131,7 +169,27 @@ export declare function allowedBack(rel: string): boolean;
131
169
  * step changed without the staging copy the first driver held in /tmp.
132
170
  */
133
171
  export declare function hashTree(dir: string): Record<string, string>;
134
- export declare function applyContainerChanges(hostWs: string, containerWs: string, baseline?: string | Record<string, string>): string[];
172
+ /**
173
+ * Every file's mtime under `dir`, relative path to milliseconds — so a copy
174
+ * that cannot carry times can have them put back. `kubectl cp` unpacks with
175
+ * `tar -m`, which stamps every file with the moment it landed; on 2026-09-24
176
+ * gbp-desk's reply-sheet check ("pending-replies.json written in the last
177
+ * hour") passed on a file last written on 2026-09-13, and the poster sent
178
+ * nothing. Every freshness check in every flow was answering "yes".
179
+ */
180
+ export declare function mtimeManifest(dir: string): Record<string, number>;
181
+ /** The in-pod half of mtimeManifest: a node one-liner, run as root before `go`. */
182
+ export declare const APPLY_MTIMES_JS: string;
183
+ /**
184
+ * Both sides changed a file the step was handed. When each is the handed-in
185
+ * content with lines added on the end — a ledger, history.md, a .jsonl — the
186
+ * answer is the base, then the host's additions, then the step's. Only the
187
+ * base's hash may be known, so the base is found as the longest shared
188
+ * leading run of whole lines whose hash matches. Anything else is null: a
189
+ * real conflict, which the caller must not settle by dropping one side.
190
+ */
191
+ export declare function mergeAppends(was: Buffer | string | null, host: Buffer, next: Buffer): Buffer | null;
192
+ export declare function applyContainerChanges(hostWs: string, containerWs: string, baseline?: string | Record<string, string>, note?: (message: string) => void, divert?: WriteDivert): string[];
135
193
  /**
136
194
  * Where the driver builds venvs and npm prefixes, as an absolute path *inside*
137
195
  * the runner. Fixed, and it has to be: a venv bakes its own absolute path into
@@ -144,31 +202,129 @@ export declare function applyContainerChanges(hostWs: string, containerWs: strin
144
202
  */
145
203
  export declare const RUNTIME_CACHE = "/home/agent/.foldrun/runner/.runtimes";
146
204
  /**
147
- * The per-tenant directory backing that mount, or null when there is none.
205
+ * Where the platform's shared runtime layer is mounted, read-only, in a run
206
+ * pod — and read-write, one entry at a time, in the pod that builds an entry
207
+ * for it (foldrun-platform runtime-warm.ts). A fixed path for the same reason
208
+ * as RUNTIME_CACHE: a venv hard-codes its own location. Laid out as
209
+ * <FOLDRUN_DATA>/shared/.runtimes so the builder's prepareRuntime("shared", …)
210
+ * lands exactly here with FOLDRUN_DATA=/opt/foldrun-runtimes.
211
+ */
212
+ export declare const SHARED_RUNTIMES = "/opt/foldrun-runtimes/shared/.runtimes";
213
+ /**
214
+ * The per-tenant runtime cache mount — a Docker NAMED volume and the fixed
215
+ * path it mounts at — or null when there is none.
216
+ *
217
+ * A named volume, not a host path. The run's `docker create` is issued to the
218
+ * host daemon over the mounted socket, and that daemon cannot resolve a path
219
+ * under the platform's own FOLDRUN_DATA — which under compose is itself a named
220
+ * volume, or a directory Docker Desktop has not shared — so `-v <hostpath>:…`
221
+ * failed with "mounts denied". A named volume is resolved by the daemon, needs
222
+ * no host sharing, and on first use is seeded from the image's mount point,
223
+ * which the runner image creates owned by the agent user (the DOCKERFILE below,
224
+ * `${RUNTIME_CACHE}`) — so the fresh cache is writable without a host-side chown.
148
225
  *
149
- * Per-tenant, not shared. A shared cache would store one copy of pandas
150
- * instead of one per account, but it would also be mutable state that one
151
- * tenant's step writes and another tenant's step then *executes* — a poisoned
152
- * venv arriving as a trusted local file, which is precisely the path gVisor,
153
- * the capability drop and the egress policy all exist to close. Disk is the
154
- * cheaper thing to spend. If the duplication ever stops being cheap, the fix
155
- * is a read-only mount filled by a trusted builder, not a writable shared one.
226
+ * Per-tenant, not shared. A shared cache would store one copy of pandas instead
227
+ * of one per account, but it would also be mutable state that one tenant's step
228
+ * writes and another tenant's step then *executes* — a poisoned venv arriving
229
+ * as a trusted local file, which is precisely the path gVisor, the capability
230
+ * drop and the egress policy all exist to close. Disk is the cheaper thing to
231
+ * spend. One volume per tenant keeps that boundary; each carries a
232
+ * `foldrun.io/tenant` label so it can be found and pruned (self-hosting/README.md).
156
233
  *
157
- * Deliberately NOT under `<tenant>/.runtimes`, which is the *host* cache: the
158
- * venvs there carry host absolute paths and would be unusable inside a runner.
159
- * Two roots, so a hit is always a real hit.
234
+ * The venvs inside carry the runner's own absolute paths, distinct from the
235
+ * host's `<tenant>/.runtimes` cache — two roots, so a hit is always a real hit.
160
236
  */
161
- export declare function runtimeCacheDir(tenant: string | undefined): string | null;
162
- export declare function runnerImageTag(): string;
237
+ export declare function runtimeCacheMount(tenant: string | undefined): {
238
+ source: string;
239
+ target: string;
240
+ } | null;
241
+ /** The uv release copied into the image. Pinned: a floating uv is a floating
242
+ * resolver, and the runtime cache is keyed on the declaration, not on it. */
243
+ export declare const UV_VERSION = "0.11.25";
244
+ /** How many times a best-effort engine download is tried before the build
245
+ * gives up on it, and the wait before the second and third (15s, then 30s).
246
+ * A GitHub release or Google's apt mirror that blinks for a minute used to
247
+ * cost the engine outright; on x86_64 that now fails the build, so a
248
+ * transient blip would fail a deploy. */
249
+ export declare const ENGINE_DOWNLOAD_ATTEMPTS = 3;
250
+ /** `retry <engine> <command…>`: one shell function, defined at the top of each
251
+ * RUN that downloads an engine (a RUN is its own shell). Its lines start
252
+ * "runner image:" like every engine line, and go to stderr so a quiet
253
+ * install (>/dev/null) still shows them — the deploy greps them into the
254
+ * step summary (buildFailureSummary). */
255
+ export declare const RETRY_SH = "retry() { what=$1; shift; n=1; until \"$@\"; do if [ \"$n\" -ge 3 ]; then echo \"runner image: $what - download failed $n times, giving up\" >&2; return 1; fi; echo \"runner image: $what - download failed (attempt $n of 3), retrying in $((n * 15))s\" >&2; sleep $((n * 15)); n=$((n + 1)); done; }";
256
+ /** The base both targets start from, pinned by digest. The tag alone floats:
257
+ * `node:22-slim` is re-pushed for every Node patch and Debian point release,
258
+ * and will change Debian release when the Node image decides to, so the
259
+ * same runner tag — a hash of this text — could hold different bytes on two
260
+ * rebuilds. With the digest in the text, new base bytes mean a new tag.
261
+ *
262
+ * Debian 13 (trixie), not the 12 that `node:22-slim` still names: its glibc
263
+ * (2.41) runs Lightpanda past 0.3.6, which wants 2.38; Debian 12 has 2.36.
264
+ * Python is 3.13 here (3.11 on 12): runtime.ts checkEntry rebuilds a cached
265
+ * venv whose interpreter moved, once per declaration.
266
+ *
267
+ * Raise it on purpose (foldrun-infra/README.md, "Runner images"): read the
268
+ * current digest of the tag, put it here, build both targets on both arches
269
+ * and make one browse call per engine on the full image:
270
+ * docker buildx imagetools inspect node:22-trixie-slim --format '{{json .Manifest}}' | jq -r .digest
271
+ * The digest names the multi-arch index, so the one pin serves amd64 and
272
+ * arm64 alike. */
273
+ export declare const NODE_BASE = "node:22-trixie-slim@sha256:b26b04c123d9ff8ab646ceb18b9d75a1173acf64b9a401094b906d27b29338d4";
274
+ export declare const DOCKERFILE = "FROM node:22-trixie-slim@sha256:b26b04c123d9ff8ab646ceb18b9d75a1173acf64b9a401094b906d27b29338d4 AS base\nRUN apt-get update \\\n && apt-get install -y --no-install-recommends python3 python3-venv ca-certificates bash util-linux tar openssh-client sshpass git curl \\\n && rm -rf /var/lib/apt/lists/* \\\n && useradd -m -u 10001 agent\n# uv builds the declared python environments (runtime.ts): a fraction of\n# pip's time, and it can fetch a pinned python the image does not carry.\nCOPY --from=ghcr.io/astral-sh/uv:0.11.25 /uv /uvx /usr/local/bin/\nENV PLAYWRIGHT_BROWSERS_PATH=/opt/browser NODE_PATH=/usr/local/lib/node_modules\n\nFROM base AS slim\n# Fonts, because a step that draws text without a browser still needs them:\n# the full image gets 51 from Playwright's --with-deps, slim had none, so from\n# 2026-09-29 (when non-browsing steps moved to slim) every resvg/sharp diagram\n# rendered its labels as empty boxes \u2014 expert-witness-desk's validator failed\n# four passes on a post image that was \"three empty boxes\". DejaVu covers\n# Latin, Greek and Cyrillic in a few MB; fontconfig is how renderers find it.\n# DejaVu alone still drew emoji, Chinese, Japanese, Korean, Devanagari and\n# Thai as empty boxes (reproduced 2026-10-01 with resvg-js 2.6 and sharp\n# 0.34), so four more, the smallest set that drew all of them \u2014 8 MB:\n# Symbola emoji and symbols, as outlines. NOT Noto Color Emoji (10 MB):\n# resvg draws nothing from its bitmap glyphs, so a resvg\n# diagram kept its empty boxes.\n# WenQuanYi Micro Hei Chinese, Japanese kana and Korean Hangul, one file.\n# Lohit Devanagari, Loma Hindi and Thai.\n# Here, not in base, so the full image's browser layers stay cached.\nRUN apt-get update \\\n && apt-get install -y --no-install-recommends fonts-dejavu-core fontconfig fonts-symbola fonts-wqy-microhei fonts-lohit-deva fonts-tlwg-loma-otf \\\n && rm -rf /var/lib/apt/lists/* \\\n && fc-cache -f >/dev/null\n# The Playwright client only, the same pinned version as the browser pod's\n# server (the wire protocol is version-locked), so a tool that imports it\n# still loads; there is nothing here for it to launch.\n# npm's download cache is dropped in the same layer: it was 190 MB of every\n# image, read by nothing after the build.\nRUN npm install -g playwright@1.63.0 axe-core@4.13.0 >/dev/null && npm cache clean --force >/dev/null 2>&1\nWORKDIR /opt/runner\nCOPY foldrun-core.tgz driver.mjs entry.sh ./\nRUN npm init -y >/dev/null && npm install ./foldrun-core.tgz --omit=dev \\\n && npm cache clean --force >/dev/null 2>&1 \\\n && mkdir -p /workspace /library /opt/runner/job /home/agent/.foldrun/runner/.runtimes /opt/foldrun-runtimes/shared/.runtimes \\\n && chown -R agent:agent /workspace /library /opt/runner /home/agent/.foldrun /opt/foldrun-runtimes \\\n && chmod +x /opt/runner/entry.sh\nENTRYPOINT [\"/opt/runner/entry.sh\"]\n\nFROM base AS browsers\n# Real browsers, because directories and portals increasingly render with\n# JavaScript and a plain fetch sees only the empty shell. Chromium is the one the\n# browser tool drives by default; Firefox and WebKit (Safari's engine) are\n# there for an agent asked to see a page the way those render it. Installed\n# to a fixed path the agent user can read (the default cache would be\n# root's HOME). The browsers' own sandboxes are disabled at launch time \u2014 in\n# this platform the container/gVisor IS the sandbox, and the two fight.\n# Pinned exactly, not @1: web browse's numbered elements use ariaSnapshot's\n# \"ai\" mode (1.59+), and the per-account browser pod runs this same image, so\n# a floating version would move both under a working tool on any rebuild.\n# Raise it on purpose, with the gallery tests and one real call.\n# axe-core beside it is web browse's mode=a11y: one file the tool injects\n# into the page; without it the mode falls back to its own shorter checks.\n# Xvfb by name: the browser pod starts it at boot and web browse starts one\n# per call for headless: false. It used to arrive only as one of Playwright's\n# --with-deps packages, so a Playwright bump that dropped it would have\n# broken every windowed browser without a word. No xauth: nothing here runs\n# xvfb-run, and Xvfb started without -auth takes the local client as it is.\nRUN apt-get update \\\n && apt-get install -y --no-install-recommends xvfb \\\n && rm -rf /var/lib/apt/lists/*\n# Google Chrome and Chrome beta come from Google's apt repository, which\n# Playwright adds; each is tried ENGINE_DOWNLOAD_ATTEMPTS times. Only on\n# x86_64: Google ships no Linux Chrome for arm64, so there it is not tried.\nRUN npm install -g playwright@1.63.0 axe-core@4.13.0 >/dev/null \\\n && playwright install --with-deps chromium firefox webkit >/dev/null \\\n && retry() { what=$1; shift; n=1; until \"$@\"; do if [ \"$n\" -ge 3 ]; then echo \"runner image: $what - download failed $n times, giving up\" >&2; return 1; fi; echo \"runner image: $what - download failed (attempt $n of 3), retrying in $((n * 15))s\" >&2; sleep $((n * 15)); n=$((n + 1)); done; } \\\n && if [ \"$(uname -m)\" = x86_64 ]; then \\\n retry chrome playwright install --with-deps chrome >/dev/null || echo \"runner image: chrome not installed - engine: chrome would fall back to chromium\" >&2; \\\n retry chrome-beta playwright install --with-deps chrome-beta >/dev/null || echo \"runner image: chrome-beta not installed\" >&2; \\\n else echo \"runner image: no Google Chrome for $(uname -m) - engine: chrome falls back to chromium\"; fi \\\n && chmod -R a+rX /opt/browser \\\n && npm cache clean --force >/dev/null 2>&1\n# Lightpanda (engine: lightpanda): a browser that runs the JavaScript and\n# never draws \u2014 a fraction of Chromium's memory for reading and filling\n# pages. Its own program, which web browse starts beside a call and drives\n# over the DevTools protocol; shipped unmodified (AGPL-3.0). Pinned by\n# checksum (GitHub's own asset digests, checked again here). 0.4.1 since the\n# move to Debian 13: 0.3.7 on wants glibc 2.38, and Debian 12's 2.36 held it\n# at 0.3.6. An arch without a build leaves the engine out, and the tool says\n# so when asked for it. Each download (with its checksum) is tried\n# ENGINE_DOWNLOAD_ATTEMPTS times before the engine is left out.\n# Raise it on purpose: the new release's two sha256s, then one\n# engine=lightpanda call on each arch.\nRUN arch=$(uname -m) \\\n && case \"$arch\" in \\\n x86_64) sum=1d40801e72c0bc61b2cbd3f3562bcfc46de7b79e0568f33f686b64f2e587610a ;; \\\n aarch64) sum=664775c7f5ab69cc3189954c7f9345e25c167cb4dace016173e629f9a5e82c42 ;; \\\n *) sum= ;; \\\n esac \\\n && mkdir -p /opt/browser/lightpanda \\\n && retry() { what=$1; shift; n=1; until \"$@\"; do if [ \"$n\" -ge 3 ]; then echo \"runner image: $what - download failed $n times, giving up\" >&2; return 1; fi; echo \"runner image: $what - download failed (attempt $n of 3), retrying in $((n * 15))s\" >&2; sleep $((n * 15)); n=$((n + 1)); done; } \\\n && fetch() { curl -fsSL -o /opt/browser/lightpanda/lightpanda \"https://github.com/lightpanda-io/browser/releases/download/0.4.1/lightpanda-$arch-linux\" \\\n && echo \"$sum /opt/browser/lightpanda/lightpanda\" | sha256sum -c - >/dev/null; } \\\n && if [ -n \"$sum\" ] && retry lightpanda fetch; then \\\n chmod a+rx /opt/browser/lightpanda/lightpanda && /opt/browser/lightpanda/lightpanda version; \\\n else rm -f /opt/browser/lightpanda/lightpanda; echo \"runner image: lightpanda not installed for $arch - engine: lightpanda says so when asked\" >&2; fi\n# Obscura (engine: obscura): a headless browser in Rust around V8 that does\n# draw \u2014 screenshots, a raster PDF, a screencast \u2014 light like Lightpanda.\n# Apache-2.0. The plain build, not -stealth: this platform does not help a\n# page not see automation. Two binaries, obscura and obscura-worker, which\n# must sit side by side. Pinned by checksum; glibc 2.35 is its floor, so\n# Debian 13 (2.41) runs it. As above, a download is tried\n# ENGINE_DOWNLOAD_ATTEMPTS times, then a failed one leaves the engine out.\nRUN arch=$(uname -m) \\\n && case \"$arch\" in \\\n x86_64) sum=1534d1e6ddaf3d080ec4091eb41d0a4d8cc042a48b607d3c410fc13b482a9eec ;; \\\n aarch64) sum=5ecf980bca3060236a7a86ec7ed83d943e6598ee87caa46d20325d90bc75f979 ;; \\\n *) sum= ;; \\\n esac \\\n && mkdir -p /opt/browser/obscura \\\n && retry() { what=$1; shift; n=1; until \"$@\"; do if [ \"$n\" -ge 3 ]; then echo \"runner image: $what - download failed $n times, giving up\" >&2; return 1; fi; echo \"runner image: $what - download failed (attempt $n of 3), retrying in $((n * 15))s\" >&2; sleep $((n * 15)); n=$((n + 1)); done; } \\\n && fetch() { curl -fsSL -o /tmp/obscura.tgz \"https://github.com/h4ckf0r0day/obscura/releases/download/v0.2.3/obscura-$arch-linux.tar.gz\" \\\n && echo \"$sum /tmp/obscura.tgz\" | sha256sum -c - >/dev/null; } \\\n && if [ -n \"$sum\" ] && retry obscura fetch \\\n && tar -xzf /tmp/obscura.tgz -C /opt/browser/obscura obscura obscura-worker; then \\\n chmod a+rx /opt/browser/obscura/obscura /opt/browser/obscura/obscura-worker && /opt/browser/obscura/obscura --version; \\\n else rm -rf /opt/browser/obscura/*; echo \"runner image: obscura not installed for $arch - engine: obscura says so when asked\" >&2; fi \\\n && rm -f /tmp/obscura.tgz\n# What this image actually has, written down: /opt/browser/engines.json, one\n# entry per engine (its path and version, or null when the install above\n# left it out) plus Xvfb. Chromium's version is its own --version (dotted,\n# so FOLDRUN_RUNNER_ENGINES carries it: a pinned user_agent on engine\n# chromium is compared with it, not with Google Chrome's) then the build.\n# web browse reads it for its \"built without\" answer, and the deploy reads\n# it to report the engines beside the version.\n# On x86_64 a missing engine FAILS the build: every engine ships for that\n# arch, so a gap there is a failed download, and an image that quietly lacks\n# the Chrome or Lightpanda a desk names would fail those runs instead. A\n# failed build leaves the previous image running and says why. Elsewhere\n# (arm64 has no Google Chrome) the gap is recorded and the image ships.\nRUN node -e ' \\\n const fs = require(\"fs\"), cp = require(\"child_process\"), pw = require(\"playwright\"); \\\n const at = (p) => (p && fs.existsSync(p) ? p : null); \\\n const ver = (bin, args) => { try { return cp.execFileSync(bin, args, { timeout: 30000, stdio: [\"ignore\", \"pipe\", \"ignore\"] }).toString().trim().split(\"\\n\")[0] || null; } catch { return null; } }; \\\n const one = (p, v) => (p ? { path: p, version: v } : null); \\\n const pwBuild = (p) => (p ? (p.match(/(chromium|firefox|webkit)-(\\d+)/) || [])[0] || null : null); \\\n const lp = at(\"/opt/browser/lightpanda/lightpanda\"); \\\n const cr = at(pw.chromium.executablePath()); \\\n const ob = at(\"/opt/browser/obscura/obscura-worker\") && at(\"/opt/browser/obscura/obscura\"); \\\n const engines = { \\\n chromium: one(cr, cr && [ver(cr, [\"--version\"]), pwBuild(cr)].filter(Boolean).join(\" \")), \\\n chrome: one(at(\"/opt/google/chrome/chrome\"), ver(\"/opt/google/chrome/chrome\", [\"--version\"])), \\\n \"chrome-beta\": one(at(\"/opt/google/chrome-beta/chrome\"), ver(\"/opt/google/chrome-beta/chrome\", [\"--version\"])), \\\n firefox: one(at(pw.firefox.executablePath()), pwBuild(pw.firefox.executablePath())), \\\n webkit: one(at(pw.webkit.executablePath()), pwBuild(pw.webkit.executablePath())), \\\n lightpanda: one(lp, lp && ver(lp, [\"version\"])), \\\n obscura: one(ob, ob && ver(ob, [\"--version\"])), \\\n }; \\\n const xvfb = ver(\"sh\", [\"-c\", \"command -v Xvfb\"]); \\\n const arch = cp.execFileSync(\"uname\", [\"-m\"]).toString().trim(); \\\n const manifest = { arch, playwright: require(\"playwright/package.json\").version, engines, xvfb }; \\\n fs.writeFileSync(\"/opt/browser/engines.json\", JSON.stringify(manifest, null, 2) + \"\\n\"); \\\n console.log(JSON.stringify(manifest)); \\\n const missing = [\"chromium\", \"chrome\", \"firefox\", \"webkit\", \"lightpanda\", \"obscura\"].filter((e) => !engines[e]).concat(xvfb ? [] : [\"Xvfb\"]); \\\n if (missing.length && arch === \"x86_64\") { \\\n console.error(\"runner image: MISSING ENGINES on x86_64: \" + missing.join(\", \")); \\\n console.error(\"runner image: every engine ships for x86_64, so a missing one is a failed download (the retry lines above say which) - failing the build\"); \\\n process.exit(1); \\\n } \\\n if (missing.length) console.error(\"runner image: built without \" + missing.join(\", \") + \" on \" + arch); \\\n ' \\\n && chmod a+r /opt/browser/engines.json\n\nFROM browsers AS full\nWORKDIR /opt/runner\nCOPY foldrun-core.tgz driver.mjs entry.sh ./\nRUN npm init -y >/dev/null && npm install ./foldrun-core.tgz --omit=dev \\\n && npm cache clean --force >/dev/null 2>&1 \\\n && mkdir -p /workspace /library /opt/runner/job /home/agent/.foldrun/runner/.runtimes /opt/foldrun-runtimes/shared/.runtimes \\\n && chown -R agent:agent /workspace /library /opt/runner /home/agent/.foldrun /opt/foldrun-runtimes \\\n && chmod +x /opt/runner/entry.sh\nENTRYPOINT [\"/opt/runner/entry.sh\"]\n";
275
+ /** Which build target of the runner image (see DOCKERFILE). */
276
+ export type RunnerVariant = "full" | "slim";
277
+ export declare function runnerImageTag(variant?: RunnerVariant): string;
163
278
  /**
164
279
  * Build the runner image if this exact (core version, driver, dockerfile)
165
280
  * has not been built before. `npm pack` of the installed core, so the image
166
281
  * runs the same bytes the server does.
167
282
  */
168
- export declare function ensureRunnerImage(): {
283
+ /**
284
+ * `platform`: build for another architecture — "linux/arm64" on the amd64
285
+ * box, through QEMU — and name the result with the arch appended so it never
286
+ * shadows the native image in the daemon. Only the publisher asks for this;
287
+ * a step always runs the native image. Needs binfmt registered on the host
288
+ * (tonistiigi/binfmt); the publisher does that itself, every time, because
289
+ * the registration does not survive a reboot.
290
+ */
291
+ /**
292
+ * Which image a step runs in: an explicit FOLDRUN_RUNNER_IMAGE when one is
293
+ * set, otherwise the content-hash tag core builds itself. `explicit` is what
294
+ * ensureRunnerImage checks to skip the build — an empty string is *not* an
295
+ * image name (it is `docker build -t ""` → "repository name must have at
296
+ * least one component"), so it falls through to the content-hash tag exactly
297
+ * as an unset value does. Pure, so the resolution is testable without docker.
298
+ */
299
+ export declare function runnerImageRef(opts?: {
300
+ platform?: string;
301
+ variant?: RunnerVariant;
302
+ }): {
303
+ tag: string;
304
+ explicit: boolean;
305
+ };
306
+ export declare function ensureRunnerImage(opts?: {
307
+ platform?: string;
308
+ variant?: RunnerVariant;
309
+ }): {
169
310
  tag: string;
170
311
  log: string[];
171
312
  };
313
+ /**
314
+ * What a failed runner build's error says: the lines that name the failure,
315
+ * then the end of the log. Only the last 2000 characters used to survive,
316
+ * and BuildKit ends a failed RUN by echoing the instruction — the engines
317
+ * probe is a long one — so "chrome missing" scrolled out of the very error
318
+ * that existed to say it. Every engine line the DOCKERFILE prints starts
319
+ * "runner image:" (the retries, the giving up, the MISSING ENGINES line);
320
+ * those are kept, from anywhere in the log, with BuildKit's "#12 3.456 "
321
+ * prefix taken off, and so are BuildKit's own ERROR lines (each cut short:
322
+ * they quote the whole instruction). Pure, so it is tested on fixtures.
323
+ */
324
+ export declare function buildFailureSummary(log: string, opts?: {
325
+ tail?: number;
326
+ maxLines?: number;
327
+ }): string;
172
328
  export declare function parseDriverLine(line: string): {
173
329
  e: "event";
174
330
  type: "text" | "tool" | "info" | "error";
@@ -176,12 +332,17 @@ export declare function parseDriverLine(line: string): {
176
332
  call?: string;
177
333
  ms?: number;
178
334
  err?: boolean;
179
- } | {
335
+ operator?: OperatorEvent;
336
+ subagent?: string;
337
+ check?: boolean;
338
+ } | ({
180
339
  e: "done";
181
- } & ContainerStepOutcome | null;
340
+ } & ContainerStepOutcome) | null;
182
341
  export interface RunInContainerArgs {
183
342
  workspaceRoot: string;
184
343
  libraryRoot: string;
344
+ /** The platform's gallery, staged under /library BEFORE the account library so the account's copies win. */
345
+ galleryRoot?: string;
185
346
  /** The account this step belongs to — the key for its dependency cache.
186
347
  * Optional so an embedder that has no tenancy simply gets no cache. */
187
348
  tenant?: string;
@@ -208,7 +369,35 @@ export interface RunInContainerArgs {
208
369
  * (consumed 0), and before each output line it applies. The runner
209
370
  * records these on the step, so the next driver knows where to attach. */
210
371
  checkpoint?: (ref: string, consumed: number) => void;
372
+ /** A test run: where state/ and storage/ changes go instead of the
373
+ * workspace, and who to tell about each. See test-mode.ts. */
374
+ divert?: WriteDivert;
375
+ /** The run is a test run. An isolated executor labels the sandbox so the
376
+ * cluster can cut its network down to the egress proxy: a script tool
377
+ * calls the network directly, not through the proxy where the test-mode
378
+ * policy lives, so without this a test run's script could still send. */
379
+ test?: boolean;
380
+ }
381
+ /** What a test run does with a write it must not apply. */
382
+ export interface WriteDivert {
383
+ /** The directory the diverted files are written under, by their
384
+ * workspace-relative path: runs/<id>/test-writes/. */
385
+ to: string;
386
+ note: (rel: string, summary: string) => void;
211
387
  }
388
+ /**
389
+ * What crosses into the container as its environment, and how.
390
+ *
391
+ * A docker --env-file is one `KEY=value` per line and cannot carry a
392
+ * newline. @file secrets are multi-line by nature (a PEM key, a cert), so
393
+ * they are staged as files NOW, into the copied-in workspace, and the env
394
+ * carries the container path — the one place a path is stable across the
395
+ * boundary. A plain secret whose value happens to hold a newline gets the
396
+ * same treatment, and the trace says so: it used to be dropped from the
397
+ * env file without a word, and the step failed later, elsewhere, on a
398
+ * variable that read as unset. Everything else goes through the env file.
399
+ */
400
+ export declare function stageContainerEnv(env: Record<string, string>, wsIn: string, agentRel: string, emit: (type: "info" | "error", text: string) => void): Record<string, string>;
212
401
  /** The limits a size class reserves. Large is the install's configured
213
402
  * limits unchanged, so existing installs bill and behave identically;
214
403
  * small defaults to a quarter-ish slice and is env-tunable. */