@foldrun/core 15.0.0 → 16.0.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 (63) hide show
  1. package/dist/src/a2a-publish.d.ts +7 -0
  2. package/dist/src/a2a-publish.js +15 -1
  3. package/dist/src/a2a-reach.d.ts +156 -0
  4. package/dist/src/a2a-reach.js +446 -0
  5. package/dist/src/browse-egress.d.ts +1 -1
  6. package/dist/src/browse-egress.js +7 -6
  7. package/dist/src/capture.js +2 -1
  8. package/dist/src/env-names.d.ts +12 -0
  9. package/dist/src/env-names.js +49 -0
  10. package/dist/src/failure.d.ts +92 -0
  11. package/dist/src/failure.js +294 -0
  12. package/dist/src/frontmatter-fields.js +1 -1
  13. package/dist/src/install-helper.js +10 -5
  14. package/dist/src/mail.js +2 -1
  15. package/dist/src/network.js +1 -1
  16. package/dist/src/notify.js +12 -7
  17. package/dist/src/ops-log.d.ts +55 -0
  18. package/dist/src/ops-log.js +393 -0
  19. package/dist/src/otel.d.ts +16 -1
  20. package/dist/src/otel.js +121 -5
  21. package/dist/src/run-container.d.ts +55 -3
  22. package/dist/src/run-container.js +109 -17
  23. package/dist/src/run-event.d.ts +179 -0
  24. package/dist/src/run-event.js +473 -0
  25. package/dist/src/runner.js +14 -5
  26. package/dist/src/runtime.d.ts +113 -16
  27. package/dist/src/runtime.js +528 -44
  28. package/dist/src/scan.js +80 -18
  29. package/dist/src/secrets.js +4 -3
  30. package/dist/src/starter.js +1 -1
  31. package/dist/src/step-exec.d.ts +4 -2
  32. package/dist/src/step-exec.js +10 -4
  33. package/dist/src/storage.js +2 -1
  34. package/dist/src/store.d.ts +25 -3
  35. package/dist/src/store.js +40 -10
  36. package/dist/src/triggers.js +6 -5
  37. package/dist/src/webhook.js +3 -2
  38. package/package.json +2 -1
  39. package/src/a2a-publish.ts +19 -1
  40. package/src/a2a-reach.ts +503 -0
  41. package/src/browse-egress.ts +8 -7
  42. package/src/capture.ts +2 -1
  43. package/src/env-names.ts +53 -0
  44. package/src/failure.ts +368 -0
  45. package/src/frontmatter-fields.ts +1 -1
  46. package/src/install-helper.ts +10 -5
  47. package/src/mail.ts +2 -1
  48. package/src/network.ts +1 -1
  49. package/src/notify.ts +12 -9
  50. package/src/ops-log.ts +403 -0
  51. package/src/otel.ts +122 -7
  52. package/src/run-container.ts +112 -21
  53. package/src/run-event.ts +563 -0
  54. package/src/runner.ts +14 -5
  55. package/src/runtime.ts +543 -45
  56. package/src/scan.ts +91 -20
  57. package/src/secrets.ts +4 -5
  58. package/src/starter.ts +1 -1
  59. package/src/step-exec.ts +10 -4
  60. package/src/storage.ts +2 -1
  61. package/src/store.ts +59 -11
  62. package/src/triggers.ts +6 -5
  63. package/src/webhook.ts +3 -2
@@ -121,30 +121,127 @@ export declare const SYSTEM_FROM_INPUT_SH = "FOLDRUN_SYSTEM_PACKAGES=\"$(node -e
121
121
  /** Where a run container's root start-up records the system install. */
122
122
  export declare const SYSTEM_STATUS_FILE = "/opt/runner/job/system-install.json";
123
123
  export declare const SYSTEM_LOG_FILE = "/opt/runner/job/system-install.log";
124
+ /** Where the worker leaves the account's snapshot key for the root start-up
125
+ * (run-container.ts rootStartSh), which moves it somewhere only root can
126
+ * read and deletes this copy before any agent code runs. */
127
+ export declare const SNAPSHOT_KEY_FILE = "/opt/runner/job/snapshot.key";
128
+ /** The paths, relative to the root, a snapshot may write under: where Debian
129
+ * packages install. `var` reaches /var/run only through a link to /run, and
130
+ * /var/tmp is everyone's — the verifier refuses both on what is on disk. */
131
+ export declare const SNAPSHOT_ALLOWED = "etc usr var bin sbin lib lib32 lib64 libx32 opt";
132
+ /** The step's environment as the worker stages it in a run container: one
133
+ * `export NAME='value'` per line (stepEnvShell). Only the agent reads it —
134
+ * the drop's own shell, after runuser (agentStartSh, FOL-130). */
135
+ export declare const STEP_ENV_FILE = "/opt/runner/job/env.sh";
136
+ /** The part of the step's environment root's start-up may see: the proxy
137
+ * apt downloads through, and nothing else. The worker writes it beside
138
+ * STEP_ENV_FILE (rootEnvShell); rootStartSh's subshell reads it. */
139
+ export declare const ROOT_ENV_FILE = "/opt/runner/job/root-env.sh";
140
+ /** The names root's start-up takes from the step's environment (FOL-130). */
141
+ export declare const ROOT_ENV_NAMES: readonly string[];
142
+ /** An environment as a file a POSIX shell sources: `export NAME='value'`,
143
+ * single-quoted, so sourcing it assigns and never runs anything. Names a
144
+ * shell cannot hold are left out. The same shape as the k8s worker's
145
+ * envFileShell. */
146
+ export declare function stepEnvShell(env: Record<string, string>): string;
147
+ /** ROOT_ENV_FILE's content: the step's environment cut to ROOT_ENV_NAMES. */
148
+ export declare function rootEnvShell(env: Record<string, string>): string;
149
+ /**
150
+ * The first lines of root's start-up section (rootStartSh), run in a
151
+ * subshell: the step's environment is the account's — its secrets by
152
+ * whatever name the account chose, LD_PRELOAD and NODE_OPTIONS among the
153
+ * names it could choose — and none of it may steer what root runs. PATH and
154
+ * IFS are assigned before anything is executed, then `export -p` is read
155
+ * with builtins only and every exported name but the proxy's is unset. The
156
+ * test-only FOLDRUN_SYS_* / FOLDRUN_DPKG_DIR overrides go with the rest.
157
+ * Since FOL-130 the step's environment is not there to begin with — the
158
+ * subshell starts from the root shell's own and ROOT_ENV_FILE's proxy
159
+ * lines — and this stays as the lock behind that.
160
+ */
161
+ export declare const ROOT_ENV_RESET_SH: string;
162
+ /**
163
+ * The first lines of a run container's root shell (the k8s SHIM, the docker
164
+ * ENTRY), FOL-130: the loader's and the shells' variables (env-names.ts
165
+ * LOADER_ENV — LD_*, BASH_ENV, ENV, NODE_OPTIONS, PYTHONPATH…) unset and IFS
166
+ * made the shell's own. That shell's environment is the image's and the pod
167
+ * spec's, never the step's — the step's reaches the agent alone, after the
168
+ * drop (agentStartSh) — so this is the second lock: nothing the platform
169
+ * itself might one day set there can steer chown, runuser or date as root.
170
+ * PATH and NODE_PATH stay the image's: the agent's programs are found by them.
171
+ */
172
+ export declare const ROOT_SHELL_GUARD_SH: string;
124
173
  /**
125
174
  * The root start-up's half of `runtime: system:` — one shell snippet, used by
126
- * the k8s run pod, the docker entry and the deploy-time warm pod alike.
127
- * Reads the package names from $FOLDRUN_SYSTEM_PACKAGES (space-separated,
128
- * each re-checked against DEB_PACKAGE's shape here too, so nothing else can
129
- * ride in), installs them with apt as root BEFORE the drop to the agent user,
130
- * and writes SYSTEM_STATUS_FILE for prepareRuntime to read.
175
+ * the k8s run pod, the docker entry, the deploy-time warm pod and the install
176
+ * helper alike. Reads the package names from $FOLDRUN_SYSTEM_PACKAGES
177
+ * (space-separated, each re-checked against DEB_PACKAGE's shape here too, so
178
+ * nothing else can ride in), installs them with apt as root BEFORE the drop to
179
+ * the agent user, and writes SYSTEM_STATUS_FILE for prepareRuntime to read.
131
180
  *
132
- * The first step to need a package set installs it with apt (the .debs kept
133
- * in `<cache>/.apt/archives`) and then saves the files those packages added,
134
- * with their dpkg records, as a snapshot: `<cache>/.apt/snapshots/<key>.tar`.
181
+ * The first step to need a package set installs it with apt and then saves
182
+ * the files those packages added, with their dpkg records, as a snapshot.
135
183
  * Every later step restores the snapshot instead — measured 11 Oct 2026 in a
136
184
  * gVisor run pod on the NFS cache: build-essential, pkg-config, python3-dev,
137
185
  * libcairo2-dev and libpango1.0-dev (154 packages, 432 MB) took 23-30 s
138
186
  * through apt and 0.76 s from the snapshot, gcc and pkg-config working after.
139
- * The key is the package set AND a checksum of the image's own dpkg status,
140
- * so a new runner image never restores files built against the old one. A
141
- * snapshot is written under a temporary name and renamed, so two pods
142
- * building it at once cannot leave a torn one; a restore that fails falls
143
- * back to apt, and prepareRuntime verifies the result either way. Unused for
144
- * 30 days, one is pruned. Package lists stay per pod: two pods updating one
145
- * lists directory on a shared volume would corrupt it.
187
+ * Package lists stay per pod: two pods updating one lists directory on a
188
+ * shared volume would corrupt it.
189
+ *
190
+ * Who can write the snapshots (FOL-129, 5 Nov 2026). They live in the
191
+ * account's runtime cache, which the agent user owns and writes — and on EFS
192
+ * the access point makes every write uid 501 whoever asks, so no ownership
193
+ * can keep the agent out. Root extracts a snapshot onto `/`. Until v5 that
194
+ * meant an agent that rewrote snap.tar had its own files written as root
195
+ * anywhere at the next step's start (an /etc/ld.so.preload, say), in any
196
+ * later step of the account; and root's mkdir, mv and rm -rf in the agent's
197
+ * folder followed whatever links the agent left there. Now:
198
+ *
199
+ * - a snapshot is restored only under a SEAL: an HMAC, with a key the
200
+ * worker derives per account from the install key and hands to root in a
201
+ * file the agent never sees (SNAPSHOT_KEY_FILE), over the package set,
202
+ * the base, the time it was built and the tar's sha256. The tar is copied
203
+ * into a directory only root can read while it is hashed, and extracted
204
+ * from that copy, so a step running beside this one cannot swap it after
205
+ * the check. No key (a warm pod, an embedder): no snapshots, apt only;
206
+ * - under the seal, the verifier (SNAPSHOT_JS) audits every member, and
207
+ * extraction is --numeric-owner --no-overwrite-dir;
208
+ * - root reads, writes and deletes in the cache only as the agent user
209
+ * (runuser), so a link the agent planted there leads only where the agent
210
+ * could write itself;
211
+ * - only the start-up saves, before any agent code exists in the pod; the
212
+ * install helper (`save: false`), which runs beside the agent, restores
213
+ * but never seals what it found on disk;
214
+ * - the shared .deb cache is gone: apt downloads into the pod's own
215
+ * /var/cache/apt, so no root download is written through the agent's
216
+ * folder. Only a snapshot miss pays the download.
217
+ *
218
+ * Layout, format v5:
219
+ *
220
+ * <cache>/.system-snapshots/v5-<key>/<base>/snap.tar, seal, base
221
+ *
222
+ * The KEY is what the snapshot is of: the package set, the Debian release
223
+ * (os-release ID and VERSION_ID) and the machine (uname -m). Under it, one
224
+ * GENERATION per base, named by and holding the sha256 of the dpkg status
225
+ * file it was built on, and restored only onto a base whose status is
226
+ * byte-identical (FOL-50): the tar carries that status whole and files built
227
+ * against those exact packages, and a maintainer script reads the base as
228
+ * well as writing to it. What keeps a snapshot valid across releases is the
229
+ * image keeping its OS layers (run-container.ts, FOLDRUN_OS_REFRESH):
230
+ *
231
+ * - a base change is a new generation beside the old ones, counted in the
232
+ * status file as `stale` (the run log says "N snapshots did not fit this
233
+ * image"), and the four newest generations per key are kept;
234
+ * - a generation is restored for 14 days from the time sealed into it, then
235
+ * rebuilt — so the packages it added pick up Debian's fixes — and removed;
236
+ * - it is built in a staging directory and published with one rename, so
237
+ * a reader never sees half of one.
238
+ *
239
+ * A restore that is refused or fails falls back to apt, the status file says
240
+ * why (`refused`), and prepareRuntime verifies the result either way.
146
241
  */
147
- export declare function systemInstallSh(cacheDir: string, logDir?: string): string;
242
+ export declare function systemInstallSh(cacheDir: string, logDir?: string, opts?: {
243
+ save?: boolean;
244
+ }): string;
148
245
  /**
149
246
  * Are the declared system packages on this machine? The install happened in
150
247
  * the container's root start-up (systemInstallSh); this only reads the