@cnc-tools/storm 0.16.0 → 0.17.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 (281) hide show
  1. package/dist/application.d.ts +22 -13
  2. package/dist/application.js +21 -10
  3. package/dist/bin/run.d.ts +18 -0
  4. package/dist/bin/run.js +31 -0
  5. package/dist/bin/storm.js +42 -26
  6. package/dist/build-info.js +1 -1
  7. package/dist/chunks/{chunk-5CCP36QQ.js → chunk-2RNDPDTJ.js} +2 -2
  8. package/dist/chunks/chunk-2VP4GRJM.js +1219 -0
  9. package/dist/chunks/{chunk-P357TZAY.js → chunk-4O5C2XGJ.js} +18 -15
  10. package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-4WAMTUWZ.js} +419 -340
  11. package/dist/chunks/{chunk-OIY3DMF2.js → chunk-6UHIJXZG.js} +3 -3
  12. package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
  13. package/dist/chunks/{chunk-CK2GZEPK.js → chunk-7DZE67QM.js} +2 -2
  14. package/dist/chunks/{chunk-VUPZH7J2.js → chunk-BCBKYOHW.js} +1 -1
  15. package/dist/chunks/{chunk-2MAD5NKK.js → chunk-CKGZA25H.js} +1 -18
  16. package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-D27KILIA.js} +1 -1
  17. package/dist/chunks/{chunk-V4IKA3WI.js → chunk-DADEYJDW.js} +24 -17
  18. package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
  19. package/dist/chunks/chunk-F4MOYHRY.js +198 -0
  20. package/dist/chunks/{chunk-HVNK3I45.js → chunk-FNBB6V4R.js} +1 -1
  21. package/dist/chunks/{chunk-G3PHMXH5.js → chunk-GRT3UIBV.js} +18 -1
  22. package/dist/chunks/chunk-HP3CURSZ.js +88 -0
  23. package/dist/chunks/{chunk-DWEAHX4T.js → chunk-HWIQ2S7K.js} +5 -5
  24. package/dist/chunks/chunk-JN3YY6ZH.js +2166 -0
  25. package/dist/chunks/{chunk-TJNFVNKR.js → chunk-LKTZ5OXS.js} +1 -1
  26. package/dist/chunks/{chunk-3L52KNQA.js → chunk-M7EKRGVD.js} +8 -8
  27. package/dist/chunks/chunk-MR77L2GK.js +340 -0
  28. package/dist/chunks/{chunk-DC2CDHNK.js → chunk-RNAS7JHE.js} +1438 -445
  29. package/dist/chunks/{chunk-FCQUJDA4.js → chunk-RWIXDDCK.js} +4 -189
  30. package/dist/chunks/{chunk-5VXBKPW6.js → chunk-WV3DP6NR.js} +1 -1
  31. package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
  32. package/dist/chunks/{chunk-FOZWA52V.js → chunk-YEPFSLQR.js} +480 -375
  33. package/dist/chunks/{live-app-WECQOQ4C.js → live-app-R76JQXZL.js} +15 -13
  34. package/dist/commands/exec/across-sandboxes-outcomes.d.ts +1 -1
  35. package/dist/commands/exec/across-sandboxes-outcomes.js +2 -2
  36. package/dist/commands/exec/before-run.d.ts +123 -0
  37. package/dist/commands/exec/before-run.js +105 -0
  38. package/dist/commands/exec/command.d.ts +31 -2
  39. package/dist/commands/exec/command.js +31 -95
  40. package/dist/commands/exec/driver-plan.d.ts +9 -4
  41. package/dist/commands/exec/driver-plan.js +8 -8
  42. package/dist/commands/exec/exec-words.js +1 -1
  43. package/dist/commands/exec/execute-run.d.ts +39 -0
  44. package/dist/commands/exec/execute-run.js +325 -0
  45. package/dist/commands/exec/live-view.d.ts +3 -3
  46. package/dist/commands/exec/live-view.js +16 -15
  47. package/dist/commands/exec/metadata.js +1 -1
  48. package/dist/commands/exec/mint-failed.d.ts +38 -0
  49. package/dist/commands/exec/mint-failed.js +27 -4
  50. package/dist/commands/exec/outcomes.d.ts +34 -8
  51. package/dist/commands/exec/outcomes.js +30 -23
  52. package/dist/commands/exec/plan-run.d.ts +58 -150
  53. package/dist/commands/exec/plan-run.js +232 -88
  54. package/dist/commands/exec/progress.d.ts +10 -6
  55. package/dist/commands/exec/progress.js +38 -25
  56. package/dist/commands/exec/run-bin.d.ts +11 -11
  57. package/dist/commands/exec/run-bin.js +9 -9
  58. package/dist/commands/exec/run-flags.d.ts +69 -0
  59. package/dist/commands/exec/run-flags.js +58 -0
  60. package/dist/commands/exec/run-metadata.js +4 -4
  61. package/dist/commands/exec/run-summary.d.ts +58 -0
  62. package/dist/commands/exec/run-summary.js +205 -0
  63. package/dist/commands/exec/runner-refusals.d.ts +82 -0
  64. package/dist/commands/exec/runner-refusals.js +71 -0
  65. package/dist/commands/exec/sandbox-progress.js +3 -0
  66. package/dist/commands/exec/stopped-outcome.d.ts +12 -0
  67. package/dist/commands/exec/stopped-outcome.js +77 -0
  68. package/dist/commands/exec/view.d.ts +20 -11
  69. package/dist/commands/exec/view.js +103 -47
  70. package/dist/commands/runs/facts.d.ts +7 -3
  71. package/dist/commands/runs/facts.js +17 -8
  72. package/dist/commands/runs/list/command.d.ts +14 -6
  73. package/dist/commands/runs/list/command.js +10 -10
  74. package/dist/commands/runs/list/outcomes.d.ts +7 -3
  75. package/dist/commands/runs/logs/command.js +10 -10
  76. package/dist/commands/runs/show/command.d.ts +14 -6
  77. package/dist/commands/runs/show/command.js +30 -28
  78. package/dist/commands/runs/show/outcomes.d.ts +7 -3
  79. package/dist/commands/runs/show/outcomes.js +7 -5
  80. package/dist/commands/snapshots/access.d.ts +111 -0
  81. package/dist/commands/snapshots/access.js +96 -0
  82. package/dist/commands/snapshots/build/command.d.ts +360 -93
  83. package/dist/commands/snapshots/build/command.js +446 -150
  84. package/dist/commands/snapshots/build/metadata.d.ts +10 -0
  85. package/dist/commands/snapshots/build/metadata.js +31 -11
  86. package/dist/commands/snapshots/build/outcomes.d.ts +234 -43
  87. package/dist/commands/snapshots/build/outcomes.js +200 -36
  88. package/dist/commands/snapshots/list/command.d.ts +366 -25
  89. package/dist/commands/snapshots/list/command.js +296 -66
  90. package/dist/commands/snapshots/list/metadata.d.ts +16 -0
  91. package/dist/commands/snapshots/list/metadata.js +29 -6
  92. package/dist/commands/snapshots/list/outcomes.d.ts +245 -13
  93. package/dist/commands/snapshots/list/outcomes.js +221 -50
  94. package/dist/commands/snapshots/metadata.js +1 -1
  95. package/dist/commands/snapshots/prune/command.d.ts +430 -0
  96. package/dist/commands/snapshots/prune/command.js +161 -0
  97. package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
  98. package/dist/commands/snapshots/prune/metadata.js +39 -0
  99. package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
  100. package/dist/commands/snapshots/prune/outcomes.js +78 -0
  101. package/dist/commands/suites/list/command.js +17 -17
  102. package/dist/commands/suites/list/outcomes.js +2 -2
  103. package/dist/commands/test/command.d.ts +31 -2
  104. package/dist/commands/test/command.js +49 -252
  105. package/dist/commands/test/outcomes.d.ts +15 -1
  106. package/dist/config/check-runner.d.ts +3 -3
  107. package/dist/config/check-runner.js +8 -7
  108. package/dist/config/credential-resolver.d.ts +50 -5
  109. package/dist/config/credential-resolver.js +51 -19
  110. package/dist/config/credential-settle.d.ts +6 -2
  111. package/dist/config/credential-settle.js +11 -5
  112. package/dist/config/index.d.ts +2 -2
  113. package/dist/config/index.js +1 -1
  114. package/dist/config/runner.d.ts +5 -5
  115. package/dist/config/runner.js +1 -1
  116. package/dist/config/schema.d.ts +2 -2
  117. package/dist/config/schema.js +1 -1
  118. package/dist/config-file/define.d.ts +1 -1
  119. package/dist/config-file/define.js +1 -1
  120. package/dist/config-file/runner.d.ts +5 -5
  121. package/dist/config-file/toolchain.d.ts +1 -1
  122. package/dist/config-file/toolchain.js +2 -2
  123. package/dist/context.d.ts +8 -6
  124. package/dist/context.js +7 -6
  125. package/dist/core/across-sandboxes.d.ts +7 -6
  126. package/dist/core/across-sandboxes.js +123 -152
  127. package/dist/core/coordinator.d.ts +166 -0
  128. package/dist/core/coordinator.js +233 -0
  129. package/dist/core/events.d.ts +2 -2
  130. package/dist/core/index.d.ts +4 -2
  131. package/dist/core/index.js +1 -1
  132. package/dist/core/outcomes.d.ts +148 -0
  133. package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
  134. package/dist/core/resources.d.ts +31 -53
  135. package/dist/core/resources.js +32 -70
  136. package/dist/core/run-state.d.ts +7 -1
  137. package/dist/core/run-state.js +2 -0
  138. package/dist/core/run.d.ts +32 -236
  139. package/dist/core/run.js +106 -266
  140. package/dist/core/state-directory.d.ts +1 -1
  141. package/dist/core/state-directory.js +2 -2
  142. package/dist/credential/gateways.d.ts +15 -1
  143. package/dist/credential/index.d.ts +4 -3
  144. package/dist/credential/index.js +3 -2
  145. package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
  146. package/dist/credential/live/vercel-cli-gateway.js +1 -1
  147. package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
  148. package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
  149. package/dist/credential/source.d.ts +73 -6
  150. package/dist/credential/source.js +55 -2
  151. package/dist/extension-commands.d.ts +6 -1
  152. package/dist/extension-commands.js +15 -1
  153. package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
  154. package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
  155. package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
  156. package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
  157. package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
  158. package/dist/extensions/testserver/credential-facts.d.ts +6 -2
  159. package/dist/extensions/testserver/credential-facts.js +29 -11
  160. package/dist/extensions/testserver/lifecycle.js +7 -1
  161. package/dist/extensions/testserver/limit.d.ts +3 -0
  162. package/dist/extensions/testserver/limit.js +3 -0
  163. package/dist/extensions/testserver/provision.d.ts +8 -1
  164. package/dist/extensions/testserver/provision.js +8 -3
  165. package/dist/extensions/testserver/refusals.d.ts +6 -1
  166. package/dist/extensions/testserver/refusals.js +16 -1
  167. package/dist/extensions/testserver/resource.d.ts +1 -1
  168. package/dist/extensions/testserver/resource.js +1 -1
  169. package/dist/extensions/testserver/result.d.ts +1 -1
  170. package/dist/extensions/testserver/result.js +9 -4
  171. package/dist/planning/driver-file-lists.d.ts +0 -15
  172. package/dist/planning/driver-file-lists.js +2 -21
  173. package/dist/planning/plan-only.d.ts +3 -14
  174. package/dist/planning/plan-only.js +11 -20
  175. package/dist/planning/run-kind-flags.js +2 -2
  176. package/dist/planning/run-plan.d.ts +45 -12
  177. package/dist/planning/run-plan.js +4 -3
  178. package/dist/planning/suites.d.ts +1 -1
  179. package/dist/planning/suites.js +2 -2
  180. package/dist/planning/test-plan.d.ts +9 -0
  181. package/dist/planning/test-plan.js +9 -0
  182. package/dist/run-directory/recording.js +2 -2
  183. package/dist/run-directory/run-record.d.ts +21 -6
  184. package/dist/run-directory/run-record.js +12 -9
  185. package/dist/runner/base.js +1 -1
  186. package/dist/runner/build-snapshots.d.ts +55 -29
  187. package/dist/runner/build-snapshots.js +130 -29
  188. package/dist/runner/context.d.ts +15 -7
  189. package/dist/runner/context.js +19 -6
  190. package/dist/runner/events.d.ts +16 -10
  191. package/dist/runner/gateways.d.ts +87 -21
  192. package/dist/runner/gateways.js +1 -1
  193. package/dist/runner/index.d.ts +11 -7
  194. package/dist/runner/index.js +9 -4
  195. package/dist/runner/live/sandbox-errors.d.ts +2 -0
  196. package/dist/runner/live/sandbox-errors.js +4 -0
  197. package/dist/runner/live/sandbox-gateway.js +129 -3
  198. package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
  199. package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
  200. package/dist/runner/live/snapshot-records.js +6 -7
  201. package/dist/runner/local-snapshot-index.d.ts +199 -0
  202. package/dist/runner/local-snapshot-index.js +211 -0
  203. package/dist/runner/network-policy.d.ts +6 -6
  204. package/dist/runner/network-policy.js +7 -7
  205. package/dist/runner/policy-writes.d.ts +1 -1
  206. package/dist/runner/policy-writes.js +1 -1
  207. package/dist/runner/prepare.d.ts +14 -14
  208. package/dist/runner/prepare.js +20 -11
  209. package/dist/runner/ready.d.ts +18 -10
  210. package/dist/runner/ready.js +104 -33
  211. package/dist/runner/sandboxed-command.d.ts +3 -3
  212. package/dist/runner/sandboxed-command.js +3 -3
  213. package/dist/runner/scope.d.ts +10 -6
  214. package/dist/runner/scope.js +10 -3
  215. package/dist/runner/secrets.d.ts +13 -13
  216. package/dist/runner/secrets.js +18 -15
  217. package/dist/runner/session.d.ts +8 -8
  218. package/dist/runner/session.js +3 -3
  219. package/dist/runner/shared-snapshot-entry.d.ts +92 -0
  220. package/dist/runner/shared-snapshot-entry.js +168 -0
  221. package/dist/runner/shared-snapshot-list.d.ts +81 -0
  222. package/dist/runner/shared-snapshot-list.js +155 -0
  223. package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
  224. package/dist/runner/shared-snapshot-lookup.js +118 -0
  225. package/dist/runner/shared-snapshot-prune.d.ts +58 -0
  226. package/dist/runner/shared-snapshot-prune.js +133 -0
  227. package/dist/runner/snapshot-build.d.ts +42 -14
  228. package/dist/runner/snapshot-build.js +32 -29
  229. package/dist/runner/snapshot-choice.js +1 -1
  230. package/dist/runner/snapshot-inspect.d.ts +39 -40
  231. package/dist/runner/snapshot-inspect.js +55 -35
  232. package/dist/runner/snapshot-key.d.ts +13 -12
  233. package/dist/runner/snapshot-key.js +13 -12
  234. package/dist/runner/steps.d.ts +1 -1
  235. package/dist/runner/steps.js +1 -1
  236. package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +2 -2
  237. package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +3 -2
  238. package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +24 -23
  239. package/dist/runner/{recipe.js → vercel-sandbox-options.js} +70 -69
  240. package/dist/runner/{recipe-secrets.d.ts → vercel-sandbox-secrets.d.ts} +6 -6
  241. package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +20 -20
  242. package/dist/sdk/extension/commands.d.ts +8 -3
  243. package/dist/sdk/extension/commands.js +3 -1
  244. package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
  245. package/dist/sdk/extension/credential-diagnosis.js +25 -5
  246. package/dist/sdk/extension/credential-source.d.ts +20 -3
  247. package/dist/sdk/extension/credential-source.js +4 -4
  248. package/dist/sdk/extension/index.d.ts +3 -2
  249. package/dist/sdk/extension/index.js +2 -1
  250. package/dist/sdk/extension/resource-definition.d.ts +1 -1
  251. package/dist/sdk/extension/secret-source.d.ts +1 -1
  252. package/dist/sdk/extension/secret-source.js +1 -1
  253. package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
  254. package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
  255. package/dist/shared/cleanup.d.ts +3 -3
  256. package/dist/shared/cleanup.js +15 -5
  257. package/dist/shared/snapshot-text.d.ts +4 -4
  258. package/dist/shared/snapshot-text.js +11 -11
  259. package/dist/time/duration.js +1 -1
  260. package/package.json +3 -2
  261. package/skills/overview.md +4 -4
  262. package/skills/plan-runs.md +1 -1
  263. package/skills/read-run-output.md +6 -6
  264. package/dist/chunks/chunk-7EENF73W.js +0 -782
  265. package/dist/chunks/chunk-Z5PBVG3Y.js +0 -2599
  266. package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
  267. package/dist/commands/exec/across-sandboxes-run.js +0 -339
  268. package/dist/commands/exec/plan-only.d.ts +0 -10
  269. package/dist/commands/exec/plan-only.js +0 -45
  270. package/dist/commands/exec/run-command.d.ts +0 -475
  271. package/dist/commands/exec/run-command.js +0 -603
  272. package/dist/commands/exec/run-planned.d.ts +0 -20
  273. package/dist/commands/exec/run-planned.js +0 -22
  274. package/dist/commands/exec/sandbox-view.d.ts +0 -19
  275. package/dist/commands/exec/sandbox-view.js +0 -72
  276. package/dist/commands/test/plan.d.ts +0 -92
  277. package/dist/commands/test/plan.js +0 -125
  278. package/dist/core/sandbox-end.d.ts +0 -64
  279. package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
  280. package/dist/runner/snapshot-cache.d.ts +0 -148
  281. package/dist/runner/snapshot-cache.js +0 -126
@@ -15,52 +15,14 @@ import {
15
15
  resourceCall,
16
16
  secretSourceId,
17
17
  tokenRequestFailureFacts,
18
- tokenRequestFailureShape
19
- } from "./chunk-AWBSONHB.js";
18
+ tokenRequestFailureShape,
19
+ vercelOidcTokenFailureFacts,
20
+ vercelOidcTokenFailureShape
21
+ } from "./chunk-XBDRVFEV.js";
20
22
  import {
21
23
  defineErrors,
22
24
  refused
23
- } from "./chunk-VL7WFTVQ.js";
24
-
25
- // src/config/credential-settle.ts
26
- import { z } from "zod";
27
- var credentialErrors = defineErrors({
28
- missingTarget: {
29
- exitCode: 2,
30
- description: "The command may mint a credential, and neither a flag nor storm.config.ts names the control plane team or project.",
31
- schema: z.object({
32
- /** The settings no flag or config file gave. */
33
- missing: z.array(z.enum(["scope", "project"]))
34
- }),
35
- render: ({ missing }) => ({
36
- message: `No control plane ${missing.map((key) => key === "scope" ? "team" : "project").join(" or ")} to mint a credential for.`,
37
- next: [
38
- {
39
- type: "text",
40
- text: `Give ${missing.map((key) => `--${key}`).join(" and ")}, or set ${missing.join(" and ")} in storm.config.ts.`
41
- }
42
- ]
43
- })
44
- }
45
- });
46
- function requireTarget(scope, project) {
47
- if (scope === void 0 || project === void 0)
48
- return refused(
49
- credentialErrors.missingTarget({
50
- missing: [
51
- ...scope === void 0 ? ["scope"] : [],
52
- ...project === void 0 ? ["project"] : []
53
- ]
54
- })
55
- );
56
- return { ok: true, target: { team: scope.value, project: project.value } };
57
- }
58
- function settleCredential(source, scope, project) {
59
- if (source === "github-actions") return { ok: true, credential: { source } };
60
- const required = requireTarget(scope, project);
61
- if (!required.ok) return required;
62
- return { ok: true, credential: { source, target: required.target } };
63
- }
25
+ } from "./chunk-4WAMTUWZ.js";
64
26
 
65
27
  // src/runner/base.ts
66
28
  async function resolveBase(checkout, request2) {
@@ -90,6 +52,173 @@ async function resolveBase(checkout, request2) {
90
52
  return best === void 0 ? { kind: "no-base-ref", refs: refused2 } : { kind: "resolved", ...best };
91
53
  }
92
54
 
55
+ // src/runner/context.ts
56
+ function runnerPurpose(runnerName) {
57
+ return `storm-runner-${runnerName}`;
58
+ }
59
+ function runnerTags(runnerName, role, user) {
60
+ return { purpose: runnerPurpose(runnerName), user, role };
61
+ }
62
+ function snapshotIndexTags(runnerName, user, base, expiresAt) {
63
+ return {
64
+ purpose: runnerPurpose(runnerName),
65
+ user,
66
+ role: "snapshot-index",
67
+ base,
68
+ "expires-at": expiresAt
69
+ };
70
+ }
71
+
72
+ // src/runner/local-snapshot-index.ts
73
+ import { createHash } from "node:crypto";
74
+ var RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
75
+ var SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1e3;
76
+ var SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1e3;
77
+ function snapshotEntryIdentity(entry) {
78
+ return createHash("sha256").update(
79
+ [
80
+ entry.teamId,
81
+ entry.projectId,
82
+ entry.region,
83
+ entry.runtime,
84
+ entry.runnerName,
85
+ entry.snapshotKey,
86
+ entry.base
87
+ ].join("\0")
88
+ ).digest("hex").slice(0, 32);
89
+ }
90
+ function snapshotEntryFileName(entry) {
91
+ return `${snapshotEntryIdentity(entry)}.json`;
92
+ }
93
+ function isExpiredEntry(entry, now) {
94
+ return Date.parse(entry.expiresAt) <= now.getTime();
95
+ }
96
+ function hasTimeLeft(entry, now) {
97
+ return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
98
+ }
99
+ async function removeExpiredEntries(context) {
100
+ const { runnerSnapshots } = context;
101
+ const listed = await runnerSnapshots.listEntries();
102
+ if (!listed.ok) return { entries: [], notes: [{ kind: "local-index-unreadable", failure: listed.failure }] };
103
+ const now = context.clock.now();
104
+ const entries = [];
105
+ const notes = [];
106
+ for (const entry of listed.value.entries) {
107
+ if (!isExpiredEntry(entry, now)) {
108
+ entries.push(entry);
109
+ continue;
110
+ }
111
+ const removed = await runnerSnapshots.removeEntry(entry);
112
+ if (!removed.ok) notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
113
+ }
114
+ return { entries, notes };
115
+ }
116
+ async function resolveAncestorDistances(context, request2) {
117
+ const { checkout, clock } = context;
118
+ const { repoRoot, entries, options, mergeBase } = request2;
119
+ const now = clock.now();
120
+ const seen = /* @__PURE__ */ new Set([mergeBase]);
121
+ const distances = {};
122
+ for (const entry of entries) {
123
+ if (entry.region !== options.region || entry.runtime !== options.runtime || entry.runnerName !== options.name) {
124
+ continue;
125
+ }
126
+ if (isExpiredEntry(entry, now) || !hasTimeLeft(entry, now)) continue;
127
+ if (seen.has(entry.base)) continue;
128
+ seen.add(entry.base);
129
+ const contained = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
130
+ if (!contained.ok) return contained;
131
+ if (!contained.value) continue;
132
+ const behindMergeBase = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
133
+ if (!behindMergeBase.ok) return behindMergeBase;
134
+ distances[entry.base] = behindMergeBase.value;
135
+ }
136
+ return { ok: true, value: distances };
137
+ }
138
+ function classifySnapshotEntries(context, request2) {
139
+ const { entries, options, base, snapshotKey: snapshotKey2, commitsAfterBase, ancestorDistances } = request2;
140
+ const now = context.clock.now();
141
+ const candidates = [];
142
+ const rejected = [];
143
+ const verdicts = [];
144
+ const reject = (entry, reason) => {
145
+ const rejection = { entry, reason };
146
+ rejected.push(rejection);
147
+ verdicts.push({ kind: "rejected", entry, rejection });
148
+ };
149
+ for (const entry of entries) {
150
+ if (entry.region !== options.region || entry.runtime !== options.runtime || entry.runnerName !== options.name) {
151
+ verdicts.push({ kind: "other-runner", entry });
152
+ continue;
153
+ }
154
+ if (isExpiredEntry(entry, now)) {
155
+ reject(entry, "expired");
156
+ continue;
157
+ }
158
+ if (!hasTimeLeft(entry, now)) {
159
+ reject(entry, "expires-soon");
160
+ continue;
161
+ }
162
+ const commitsBehindMergeBase = entry.base === base ? 0 : ancestorDistances !== void 0 && Object.hasOwn(ancestorDistances, entry.base) ? ancestorDistances[entry.base] : void 0;
163
+ if (commitsBehindMergeBase === void 0) {
164
+ reject(entry, "other-base");
165
+ continue;
166
+ }
167
+ if (entry.snapshotKey !== snapshotKey2) {
168
+ reject(entry, "steps-changed");
169
+ continue;
170
+ }
171
+ const candidate = {
172
+ entry,
173
+ builtBehind: commitsAfterBase + commitsBehindMergeBase,
174
+ commitsBehindMergeBase
175
+ };
176
+ candidates.push(candidate);
177
+ verdicts.push({ kind: "candidate", entry, candidate });
178
+ }
179
+ candidates.sort(
180
+ (a, b) => compareSnapshotCandidates(
181
+ {
182
+ commitsBehindMergeBase: a.commitsBehindMergeBase,
183
+ createdAt: a.entry.createdAt,
184
+ tieBreaker: a.entry.snapshotId
185
+ },
186
+ {
187
+ commitsBehindMergeBase: b.commitsBehindMergeBase,
188
+ createdAt: b.entry.createdAt,
189
+ tieBreaker: b.entry.snapshotId
190
+ }
191
+ )
192
+ );
193
+ return { candidates, rejected, verdicts };
194
+ }
195
+ function parseTimestampMs(iso) {
196
+ const ms = Date.parse(iso);
197
+ return Number.isNaN(ms) ? Number.NEGATIVE_INFINITY : ms;
198
+ }
199
+ function compareSnapshotCandidates(a, b) {
200
+ if (a.commitsBehindMergeBase !== b.commitsBehindMergeBase) {
201
+ return a.commitsBehindMergeBase - b.commitsBehindMergeBase;
202
+ }
203
+ const aCreated = parseTimestampMs(a.createdAt);
204
+ const bCreated = parseTimestampMs(b.createdAt);
205
+ if (aCreated !== bCreated) return bCreated - aCreated;
206
+ return a.tieBreaker < b.tieBreaker ? -1 : a.tieBreaker > b.tieBreaker ? 1 : 0;
207
+ }
208
+ function sharedBeatsLocal(sharedCommitsBehindMergeBase, localCommitsBehindMergeBase) {
209
+ return localCommitsBehindMergeBase === void 0 || sharedCommitsBehindMergeBase < localCommitsBehindMergeBase;
210
+ }
211
+ function snapshotRejections(read, owner) {
212
+ const owned = (entry) => entry.teamId === owner.teamId && entry.projectId === owner.projectId;
213
+ return [
214
+ ...read.candidates.map(({ entry }) => ({ entry, reason: "other-owner" })),
215
+ ...read.rejected.map(({ entry, reason }) => ({ entry, reason: owned(entry) ? reason : "other-owner" }))
216
+ ];
217
+ }
218
+ function pickSnapshot(candidates, owner) {
219
+ return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
220
+ }
221
+
93
222
  // src/runner/time-limit.ts
94
223
  function callWithin(timer, ms, call) {
95
224
  const abort = new AbortController();
@@ -133,9 +262,9 @@ function untilAborted(promise, signal) {
133
262
 
134
263
  // src/runner/network-policy.ts
135
264
  var NETWORK_POLICY_WRITE_LIMIT_MS = 1e4;
136
- function runnerNetworkPolicy(recipe) {
137
- if (recipe.allowedDomains === void 0) return { kind: "allow-all", credentials: [] };
138
- return { kind: "custom", allowedDomains: [...recipe.allowedDomains], credentials: [] };
265
+ function runnerNetworkPolicy(options) {
266
+ if (options.allowedDomains === void 0) return { kind: "allow-all", credentials: [] };
267
+ return { kind: "custom", allowedDomains: [...options.allowedDomains], credentials: [] };
139
268
  }
140
269
  function withCredentials(base, credentials2) {
141
270
  return { ...base, credentials: credentials2 };
@@ -452,9 +581,15 @@ function runnerSandboxScope(context, progress, settings) {
452
581
  if (!removed.ok)
453
582
  return { ok: false, failure: { kind: "credential-not-revoked", failure: removed.failure } };
454
583
  }
455
- const saved = await sandboxes.saveSnapshot(sandbox, request2);
584
+ const saved = await sandboxes.saveSnapshot(sandbox, { expirationMs: request2.expirationMs });
456
585
  const now = currentPhase();
457
- if (saved.ok && now.kind !== "closing" && now.sandboxes.delete(sandbox)) await deleteSandbox(sandbox);
586
+ if (saved.ok) {
587
+ if (request2.keepStopped === true) {
588
+ if (now.kind === "open") now.sandboxes.delete(sandbox);
589
+ } else if (now.kind !== "closing" && now.sandboxes.delete(sandbox)) {
590
+ await deleteSandbox(sandbox);
591
+ }
592
+ }
458
593
  return saved;
459
594
  })()
460
595
  ),
@@ -488,97 +623,6 @@ function callFailureMessage(answer, limitMs) {
488
623
  return answer === null ? `no answer within ${limitMs / 1e3} seconds` : failureMessage(answer.failure);
489
624
  }
490
625
 
491
- // src/runner/context.ts
492
- function runnerPurpose(recipeName) {
493
- return `storm-runner-${recipeName}`;
494
- }
495
- function runnerTags(recipeName, role, user) {
496
- return { purpose: runnerPurpose(recipeName), user, role };
497
- }
498
-
499
- // src/runner/snapshot-cache.ts
500
- import { createHash } from "node:crypto";
501
- var RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
502
- var SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1e3;
503
- var SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1e3;
504
- function snapshotEntryIdentity(entry) {
505
- return createHash("sha256").update(
506
- [
507
- entry.teamId,
508
- entry.projectId,
509
- entry.region,
510
- entry.runtime,
511
- entry.recipeName,
512
- entry.snapshotKey,
513
- entry.base
514
- ].join("\0")
515
- ).digest("hex").slice(0, 32);
516
- }
517
- function snapshotEntryFileName(entry) {
518
- return `${snapshotEntryIdentity(entry)}.json`;
519
- }
520
- function isExpiredEntry(entry, now) {
521
- return Date.parse(entry.expiresAt) <= now.getTime();
522
- }
523
- function hasTimeLeft(entry, now) {
524
- return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
525
- }
526
- async function removeExpiredEntries(context) {
527
- const { runnerSnapshots } = context;
528
- const listed = await runnerSnapshots.listEntries();
529
- if (!listed.ok) return { entries: [], notes: [{ kind: "cache-unreadable", failure: listed.failure }] };
530
- const now = context.clock.now();
531
- const entries = [];
532
- const notes = [];
533
- for (const entry of listed.value.entries) {
534
- if (!isExpiredEntry(entry, now)) {
535
- entries.push(entry);
536
- continue;
537
- }
538
- const removed = await runnerSnapshots.removeEntry(entry);
539
- if (!removed.ok) notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
540
- }
541
- return { entries, notes };
542
- }
543
- function classifySnapshotEntries(context, request2) {
544
- const { entries, recipe, base, snapshotKey: snapshotKey2, commitsAfterBase } = request2;
545
- const now = context.clock.now();
546
- const candidates = [];
547
- const rejected = [];
548
- const verdicts = [];
549
- const reject = (entry, reason) => {
550
- const rejection = { entry, reason };
551
- rejected.push(rejection);
552
- verdicts.push({ kind: "rejected", entry, rejection });
553
- };
554
- for (const entry of entries) {
555
- if (entry.region !== recipe.region || entry.runtime !== recipe.runtime || entry.recipeName !== recipe.name) {
556
- verdicts.push({ kind: "other-recipe", entry });
557
- continue;
558
- }
559
- if (isExpiredEntry(entry, now)) reject(entry, "expired");
560
- else if (!hasTimeLeft(entry, now)) reject(entry, "expires-soon");
561
- else if (entry.base !== base) reject(entry, "other-base");
562
- else if (entry.snapshotKey !== snapshotKey2) reject(entry, "steps-changed");
563
- else {
564
- const candidate = { entry, builtBehind: commitsAfterBase };
565
- candidates.push(candidate);
566
- verdicts.push({ kind: "candidate", entry, candidate });
567
- }
568
- }
569
- return { candidates, rejected, verdicts };
570
- }
571
- function snapshotRejections(read, owner) {
572
- const owned = (entry) => entry.teamId === owner.teamId && entry.projectId === owner.projectId;
573
- return [
574
- ...read.candidates.map(({ entry }) => ({ entry, reason: "other-owner" })),
575
- ...read.rejected.map(({ entry, reason }) => ({ entry, reason: owned(entry) ? reason : "other-owner" }))
576
- ];
577
- }
578
- function pickSnapshot(candidates, owner) {
579
- return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
580
- }
581
-
582
626
  // src/runner/snapshot-key.ts
583
627
  import { createHash as createHash2 } from "node:crypto";
584
628
 
@@ -623,67 +667,67 @@ var systemClock = {
623
667
  };
624
668
 
625
669
  // src/sdk/run/payload.ts
626
- import { z as z2 } from "zod";
670
+ import { z } from "zod";
627
671
  var RUN_PAYLOAD_VARIABLE = "STORM_RUN";
628
672
  var RUN_PAYLOAD_VERSION = 3;
629
- var runPayloadSandboxSchema = z2.object({
630
- index: z2.number().int().nonnegative(),
631
- count: z2.number().int().positive(),
632
- files: z2.array(z2.string().min(1)).optional()
673
+ var runPayloadSandboxSchema = z.object({
674
+ index: z.number().int().nonnegative(),
675
+ count: z.number().int().positive(),
676
+ files: z.array(z.string().min(1)).optional()
633
677
  });
634
- var runPayloadSchema = z2.object({
635
- version: z2.literal(RUN_PAYLOAD_VERSION),
636
- resources: z2.record(z2.string(), z2.object({ definition: z2.string().min(1), payload: z2.unknown() })),
637
- testEvents: z2.string().min(1).optional(),
638
- verbose: z2.literal(true).optional(),
678
+ var runPayloadSchema = z.object({
679
+ version: z.literal(RUN_PAYLOAD_VERSION),
680
+ resources: z.record(z.string(), z.object({ definition: z.string().min(1), payload: z.unknown() })),
681
+ testEvents: z.string().min(1).optional(),
682
+ verbose: z.literal(true).optional(),
639
683
  sandbox: runPayloadSandboxSchema.optional()
640
684
  });
641
685
 
642
686
  // src/sdk/run/test-events.ts
643
- import { z as z3 } from "zod";
644
- var where = { file: z3.string(), worker: z3.number().int().nonnegative(), at: z3.number() };
645
- var fileWhere = { file: z3.string(), worker: z3.number().int().nonnegative().exactOptional(), at: z3.number() };
646
- var attempt = { id: z3.string().min(1), test: z3.string() };
647
- var setup = { label: z3.string().min(1), resource: z3.string().min(1) };
648
- var state = z3.enum(["pass", "fail", "skip"]);
649
- var testEventSchema = z3.discriminatedUnion("kind", [
650
- z3.object({ kind: z3.literal("file-started"), ...fileWhere }),
651
- z3.object({ kind: z3.literal("file-finished"), ...fileWhere }),
652
- z3.object({ kind: z3.literal("test-started"), ...where, ...attempt, fileTests: z3.number().int().nonnegative() }),
653
- z3.object({
654
- kind: z3.literal("test-attempt-finished"),
687
+ import { z as z2 } from "zod";
688
+ var where = { file: z2.string(), worker: z2.number().int().nonnegative(), at: z2.number() };
689
+ var fileWhere = { file: z2.string(), worker: z2.number().int().nonnegative().exactOptional(), at: z2.number() };
690
+ var attempt = { id: z2.string().min(1), test: z2.string() };
691
+ var setup = { label: z2.string().min(1), resource: z2.string().min(1) };
692
+ var state = z2.enum(["pass", "fail", "skip"]);
693
+ var testEventSchema = z2.discriminatedUnion("kind", [
694
+ z2.object({ kind: z2.literal("file-started"), ...fileWhere }),
695
+ z2.object({ kind: z2.literal("file-finished"), ...fileWhere }),
696
+ z2.object({ kind: z2.literal("test-started"), ...where, ...attempt, fileTests: z2.number().int().nonnegative() }),
697
+ z2.object({
698
+ kind: z2.literal("test-attempt-finished"),
655
699
  ...where,
656
700
  ...attempt,
657
701
  state,
658
- ms: z3.number().nonnegative()
702
+ ms: z2.number().nonnegative()
659
703
  }),
660
- z3.object({ kind: z3.literal("setup-started"), ...where, ...setup }),
661
- z3.object({
662
- kind: z3.literal("setup-finished"),
704
+ z2.object({ kind: z2.literal("setup-started"), ...where, ...setup }),
705
+ z2.object({
706
+ kind: z2.literal("setup-finished"),
663
707
  ...where,
664
708
  ...setup,
665
- ms: z3.number().nonnegative(),
666
- ok: z3.boolean(),
667
- warmupMs: z3.number().nonnegative().exactOptional()
709
+ ms: z2.number().nonnegative(),
710
+ ok: z2.boolean(),
711
+ warmupMs: z2.number().nonnegative().exactOptional()
668
712
  }),
669
- z3.object({
670
- kind: z3.literal("test-result"),
671
- id: z3.string().min(1),
672
- file: z3.string(),
673
- test: z3.string(),
713
+ z2.object({
714
+ kind: z2.literal("test-result"),
715
+ id: z2.string().min(1),
716
+ file: z2.string(),
717
+ test: z2.string(),
674
718
  state,
675
- retryCount: z3.number().int().nonnegative(),
676
- flaky: z3.boolean(),
677
- at: z3.number(),
678
- errors: z3.array(
679
- z3.object({
680
- name: z3.string(),
681
- message: z3.string(),
682
- stack: z3.string().exactOptional(),
683
- diff: z3.string().exactOptional()
719
+ retryCount: z2.number().int().nonnegative(),
720
+ flaky: z2.boolean(),
721
+ at: z2.number(),
722
+ errors: z2.array(
723
+ z2.object({
724
+ name: z2.string(),
725
+ message: z2.string(),
726
+ stack: z2.string().exactOptional(),
727
+ diff: z2.string().exactOptional()
684
728
  })
685
729
  ).exactOptional(),
686
- output: z3.object({ text: z3.string(), droppedChars: z3.number().int().nonnegative() }).exactOptional()
730
+ output: z2.object({ text: z2.string(), droppedChars: z2.number().int().nonnegative() }).exactOptional()
687
731
  })
688
732
  ]);
689
733
  function testEventLine(event) {
@@ -707,7 +751,7 @@ function redactSecrets(text, secrets) {
707
751
  return ordered.reduce((redacted, secret) => redacted.split(secret).join(REDACTED), text);
708
752
  }
709
753
 
710
- // src/runner/recipe-check.ts
754
+ // src/runner/vercel-sandbox-check.ts
711
755
  function reportUnknownKeys(value, known, path, what, report) {
712
756
  let ok = true;
713
757
  for (const key of Object.keys(value))
@@ -717,7 +761,7 @@ function reportUnknownKeys(value, known, path, what, report) {
717
761
  }
718
762
  return ok;
719
763
  }
720
- function describeRecipeValue(value) {
764
+ function describeOptionValue(value) {
721
765
  if (typeof value === "string") return JSON.stringify(value);
722
766
  if (typeof value === "number" || typeof value === "boolean") return String(value);
723
767
  if (value === null) return "null";
@@ -728,7 +772,7 @@ function describeRecipeValue(value) {
728
772
  return `a ${typeof value}`;
729
773
  }
730
774
 
731
- // src/runner/recipe-secrets.ts
775
+ // src/runner/vercel-sandbox-secrets.ts
732
776
  var CREDENTIAL_KEYS = /* @__PURE__ */ new Set(["domain", "header", "source", "requests"]);
733
777
  var UNSAFE_SECRET_ENV_VAR_KEYS = /* @__PURE__ */ new Set(["name", "source"]);
734
778
  var ENV_SOURCE_KEYS = /* @__PURE__ */ new Set(["kind", "name"]);
@@ -753,15 +797,15 @@ var RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES = /* @__PURE__ */ new Set([
753
797
  "NO_COLOR"
754
798
  ]);
755
799
  var RESERVED_UNSAFE_SECRET_ENV_VAR_PREFIXES = ["LD_", "DYLD_"];
756
- function credentialSourceIds(recipe) {
757
- return [...new Set(recipe.credentials.map(({ source }) => secretSourceId(source)))].toSorted();
800
+ function credentialSourceIds(options) {
801
+ return [...new Set(options.credentials.map(({ source }) => secretSourceId(source)))].toSorted();
758
802
  }
759
803
  function checkCredentials(value, report) {
760
804
  if (value === void 0) return [];
761
805
  if (!Array.isArray(value)) {
762
806
  report(
763
807
  ["credentials"],
764
- `must be a list of credentials, each { domain, header?, source, requests? }, not ${describeRecipeValue(value)}`
808
+ `must be a list of credentials, each { domain, header?, source, requests? }, not ${describeOptionValue(value)}`
765
809
  );
766
810
  return void 0;
767
811
  }
@@ -800,7 +844,7 @@ function checkCredentials(value, report) {
800
844
  }
801
845
  function checkCredential(value, path, report) {
802
846
  if (!isPlainObject(value)) {
803
- report(path, `must be { domain, header?, source, requests? }, not ${describeRecipeValue(value)}`);
847
+ report(path, `must be { domain, header?, source, requests? }, not ${describeOptionValue(value)}`);
804
848
  return void 0;
805
849
  }
806
850
  let ok = reportUnknownKeys(value, CREDENTIAL_KEYS, path, "a credential key", report);
@@ -808,7 +852,7 @@ function checkCredential(value, path, report) {
808
852
  if (typeof domain !== "string" || !HOST_PATTERN.test(domain)) {
809
853
  report(
810
854
  [...path, "domain"],
811
- `must be a bare hostname, such as registry.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, path, or wildcard, not ${describeRecipeValue(domain)}`
855
+ `must be a bare hostname, such as registry.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, path, or wildcard, not ${describeOptionValue(domain)}`
812
856
  );
813
857
  ok = false;
814
858
  }
@@ -816,7 +860,7 @@ function checkCredential(value, path, report) {
816
860
  if (typeof header !== "string" || !HEADER_PATTERN.test(header)) {
817
861
  report(
818
862
  [...path, "header"],
819
- `must be an HTTP header name, such as authorization, not ${describeRecipeValue(header)}`
863
+ `must be an HTTP header name, such as authorization, not ${describeOptionValue(header)}`
820
864
  );
821
865
  ok = false;
822
866
  } else if (REFUSED_HEADERS.has(header.toLowerCase())) {
@@ -827,7 +871,7 @@ function checkCredential(value, path, report) {
827
871
  if (source === void 0) ok = false;
828
872
  const requests = value["requests"] === void 0 ? "read" : value["requests"];
829
873
  if (requests !== "read" && requests !== "all") {
830
- report([...path, "requests"], `must be "read" or "all", not ${describeRecipeValue(requests)}`);
874
+ report([...path, "requests"], `must be "read" or "all", not ${describeOptionValue(requests)}`);
831
875
  ok = false;
832
876
  }
833
877
  return ok && source !== void 0 ? {
@@ -839,19 +883,19 @@ function checkCredential(value, path, report) {
839
883
  }
840
884
  function checkSecretSource(value, path, report) {
841
885
  if (!isPlainObject(value)) {
842
- report(path, `must be a secret source, { kind: "env", name }, not ${describeRecipeValue(value)}`);
886
+ report(path, `must be a secret source, { kind: "env", name }, not ${describeOptionValue(value)}`);
843
887
  return void 0;
844
888
  }
845
889
  const kind2 = value["kind"];
846
890
  if (kind2 !== "env") {
847
- report([...path, "kind"], `must be "env", not ${describeRecipeValue(kind2)}`);
891
+ report([...path, "kind"], `must be "env", not ${describeOptionValue(kind2)}`);
848
892
  if (kind2 !== void 0) return void 0;
849
893
  }
850
894
  let ok = kind2 === "env";
851
895
  if (!reportUnknownKeys(value, ENV_SOURCE_KEYS, path, "a secret source key", report)) ok = false;
852
896
  const name = value["name"];
853
897
  if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
854
- report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${describeRecipeValue(name)}`);
898
+ report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(name)}`);
855
899
  ok = false;
856
900
  }
857
901
  return ok ? { kind: "env", name } : void 0;
@@ -861,7 +905,7 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
861
905
  if (!Array.isArray(value)) {
862
906
  report(
863
907
  ["unsafeSecretEnvVars"],
864
- `must be a list of unsafe secret environment variables, each { name, source }, not ${describeRecipeValue(value)}`
908
+ `must be a list of unsafe secret environment variables, each { name, source }, not ${describeOptionValue(value)}`
865
909
  );
866
910
  return void 0;
867
911
  }
@@ -872,7 +916,7 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
872
916
  value.forEach((entry, index) => {
873
917
  const path = ["unsafeSecretEnvVars", String(index)];
874
918
  if (!isPlainObject(entry)) {
875
- report(path, `must be { name, source }, not ${describeRecipeValue(entry)}`);
919
+ report(path, `must be { name, source }, not ${describeOptionValue(entry)}`);
876
920
  ok = false;
877
921
  return;
878
922
  }
@@ -886,7 +930,7 @@ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
886
930
  const name = entry["name"];
887
931
  const namePath = [...path, "name"];
888
932
  if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
889
- report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${describeRecipeValue(name)}`);
933
+ report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${describeOptionValue(name)}`);
890
934
  entryOk = false;
891
935
  } else if (name === RUN_PAYLOAD_VARIABLE) {
892
936
  report(namePath, `can't be ${name}: storm sets it for the command`);
@@ -929,16 +973,16 @@ function isPlainObject(value) {
929
973
  return proto === Object.prototype || proto === null;
930
974
  }
931
975
 
932
- // src/runner/recipe.ts
976
+ // src/runner/vercel-sandbox-options.ts
933
977
  var MAX_RUNNER_SANDBOXES = 32;
934
- var RECIPE_DEFAULTS = {
978
+ var VERCEL_SANDBOX_DEFAULTS = {
935
979
  cwd: ".",
936
980
  timeout: "60m",
937
981
  baseRefs: ["main", "origin/main"],
938
982
  region: "iad1",
939
983
  runtime: "node22"
940
984
  };
941
- var RECIPE_KEYS = /* @__PURE__ */ new Set([
985
+ var VERCEL_SANDBOX_OPTION_KEYS = /* @__PURE__ */ new Set([
942
986
  "name",
943
987
  "snapshot",
944
988
  "run",
@@ -964,43 +1008,43 @@ var STEP_KEYS = /* @__PURE__ */ new Set(["label", "script"]);
964
1008
  var TOOLCHAIN_STEP_KEYS = /* @__PURE__ */ new Set(["label", "script", "baseFiles"]);
965
1009
  var NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
966
1010
  var ALLOWED_DOMAIN_PATTERN = /^(?:\*\.)?(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
967
- function checkRecipe(value) {
1011
+ function checkVercelSandboxOptions(value) {
968
1012
  const problems = [];
969
1013
  const report = (path, problem) => problems.push({ path, problem });
970
1014
  if (!isRecord(value)) {
971
- report([], `must be an object, not ${describeRecipeValue(value)}`);
1015
+ report([], `must be an object, not ${describeOptionValue(value)}`);
972
1016
  return { ok: false, problems };
973
1017
  }
974
- reportUnknownKeys(value, RECIPE_KEYS, [], "a runner recipe key", report);
1018
+ reportUnknownKeys(value, VERCEL_SANDBOX_OPTION_KEYS, [], "a vercelSandbox option key", report);
975
1019
  const name = value["name"];
976
1020
  if (typeof name !== "string" || !NAME_PATTERN.test(name))
977
1021
  report(
978
1022
  ["name"],
979
- `must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeRecipeValue(name)}`
1023
+ `must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeOptionValue(name)}`
980
1024
  );
981
1025
  const snapshot = checkSnapshot(value["snapshot"], report);
982
1026
  const run = checkRun(value["run"], report);
983
- const cwd = orDefault(value["cwd"], RECIPE_DEFAULTS.cwd);
1027
+ const cwd = orDefault(value["cwd"], VERCEL_SANDBOX_DEFAULTS.cwd);
984
1028
  if (!isRelativePath(cwd))
985
- report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeRecipeValue(cwd)}`);
1029
+ report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeOptionValue(cwd)}`);
986
1030
  const vcpus = checkVcpus(value["vcpus"], report);
987
1031
  const env = checkEnv(value["env"], report);
988
1032
  const credentials2 = checkCredentials(value["credentials"], report);
989
1033
  const unsafeSecretEnvVars = checkUnsafeSecretEnvVars(value["unsafeSecretEnvVars"], env, credentials2, report);
990
1034
  const allowedDomains = checkAllowedDomains(value["allowedDomains"], report);
991
- const timeout = orDefault(value["timeout"], RECIPE_DEFAULTS.timeout);
1035
+ const timeout = orDefault(value["timeout"], VERCEL_SANDBOX_DEFAULTS.timeout);
992
1036
  const timeoutMinutes = typeof timeout === "string" ? parseTtl(timeout) : void 0;
993
1037
  if (timeoutMinutes === void 0)
994
1038
  report(
995
1039
  ["timeout"],
996
- `must be a whole number of minutes or hours from 10m to 5h, not ${describeRecipeValue(timeout)}`
1040
+ `must be a whole number of minutes or hours from 10m to 5h, not ${describeOptionValue(timeout)}`
997
1041
  );
998
1042
  const keepSandbox = value["keepSandbox"];
999
1043
  const keepSandboxMinutes = typeof keepSandbox === "string" ? parseKeepTime(keepSandbox) : void 0;
1000
1044
  if (keepSandbox !== void 0 && keepSandboxMinutes === void 0)
1001
1045
  report(
1002
1046
  ["keepSandbox"],
1003
- `must be 0, or a whole number of minutes or hours up to 5h, not ${describeRecipeValue(keepSandbox)}`
1047
+ `must be 0, or a whole number of minutes or hours up to 5h, not ${describeOptionValue(keepSandbox)}`
1004
1048
  );
1005
1049
  else if (unsafeSecretEnvVars !== void 0 && unsafeSecretEnvVars.length > 0 && keepSandboxMinutes !== void 0 && keepSandboxMinutes > 0)
1006
1050
  report(
@@ -1008,11 +1052,11 @@ function checkRecipe(value) {
1008
1052
  "can't be above 0 when runner.unsafeSecretEnvVars is set: a run that passes secrets into the runner sandbox's environment never keeps its runner sandbox"
1009
1053
  );
1010
1054
  const baseRefs = checkBaseRefs(value["baseRefs"], report);
1011
- const region = orDefault(value["region"], RECIPE_DEFAULTS.region);
1012
- if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${describeRecipeValue(region)}`);
1013
- const runtime = orDefault(value["runtime"], RECIPE_DEFAULTS.runtime);
1055
+ const region = orDefault(value["region"], VERCEL_SANDBOX_DEFAULTS.region);
1056
+ if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${describeOptionValue(region)}`);
1057
+ const runtime = orDefault(value["runtime"], VERCEL_SANDBOX_DEFAULTS.runtime);
1014
1058
  if (!isNonEmptyString(runtime))
1015
- report(["runtime"], `must be a non-empty string, not ${describeRecipeValue(runtime)}`);
1059
+ report(["runtime"], `must be a non-empty string, not ${describeOptionValue(runtime)}`);
1016
1060
  const sandboxes = checkSandboxes(value["sandboxes"], report);
1017
1061
  if (problems.length > 0 || snapshot === void 0 || run === void 0 || vcpus === void 0 || env === void 0 || credentials2 === void 0 || unsafeSecretEnvVars === void 0 || allowedDomains === null || baseRefs === void 0 || timeoutMinutes === void 0 || sandboxes === false)
1018
1062
  return { ok: false, problems };
@@ -1047,34 +1091,34 @@ function checkVcpus(value, report) {
1047
1091
  if (!isRecord(value)) {
1048
1092
  report(
1049
1093
  ["vcpus"],
1050
- `must be a positive whole number, or { resource, option, per, min, max }, not ${describeRecipeValue(value)}`
1094
+ `must be a positive whole number, or { resource, option, per, min, max }, not ${describeOptionValue(value)}`
1051
1095
  );
1052
1096
  return void 0;
1053
1097
  }
1054
- let ok = reportUnknownKeys(value, VCPUS_RULE_KEYS, ["vcpus"], "a runner recipe vcpus rule key", report);
1098
+ let ok = reportUnknownKeys(value, VCPUS_RULE_KEYS, ["vcpus"], "a vercelSandbox vcpus rule key", report);
1055
1099
  const resource = value["resource"];
1056
1100
  if (!isNonEmptyString(resource)) {
1057
- report(["vcpus", "resource"], `must be a non-empty string, not ${describeRecipeValue(resource)}`);
1101
+ report(["vcpus", "resource"], `must be a non-empty string, not ${describeOptionValue(resource)}`);
1058
1102
  ok = false;
1059
1103
  }
1060
1104
  const option = value["option"];
1061
1105
  if (!isNonEmptyString(option)) {
1062
- report(["vcpus", "option"], `must be a non-empty string, not ${describeRecipeValue(option)}`);
1106
+ report(["vcpus", "option"], `must be a non-empty string, not ${describeOptionValue(option)}`);
1063
1107
  ok = false;
1064
1108
  }
1065
1109
  const per = value["per"];
1066
1110
  if (!isPositiveInteger(per)) {
1067
- report(["vcpus", "per"], `must be a positive whole number, not ${describeRecipeValue(per)}`);
1111
+ report(["vcpus", "per"], `must be a positive whole number, not ${describeOptionValue(per)}`);
1068
1112
  ok = false;
1069
1113
  }
1070
1114
  const min = value["min"];
1071
1115
  if (!isPositiveInteger(min)) {
1072
- report(["vcpus", "min"], `must be a positive whole number, not ${describeRecipeValue(min)}`);
1116
+ report(["vcpus", "min"], `must be a positive whole number, not ${describeOptionValue(min)}`);
1073
1117
  ok = false;
1074
1118
  }
1075
1119
  const max = value["max"];
1076
1120
  if (!isPositiveInteger(max)) {
1077
- report(["vcpus", "max"], `must be a positive whole number, not ${describeRecipeValue(max)}`);
1121
+ report(["vcpus", "max"], `must be a positive whole number, not ${describeOptionValue(max)}`);
1078
1122
  ok = false;
1079
1123
  } else if (isPositiveInteger(min) && max < min) {
1080
1124
  report(["vcpus", "max"], `must be at least vcpus.min (${min}), not ${max}`);
@@ -1091,15 +1135,15 @@ function checkVcpus(value, report) {
1091
1135
  function checkSandboxes(value, report) {
1092
1136
  if (value === void 0) return void 0;
1093
1137
  if (!isRecord(value)) {
1094
- report(["sandboxes"], `must be an object with max, not ${describeRecipeValue(value)}`);
1138
+ report(["sandboxes"], `must be an object with max, not ${describeOptionValue(value)}`);
1095
1139
  return false;
1096
1140
  }
1097
- let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a runner recipe sandboxes key", report);
1141
+ let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a vercelSandbox sandboxes key", report);
1098
1142
  const max = value["max"];
1099
1143
  if (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES) {
1100
1144
  report(
1101
1145
  ["sandboxes", "max"],
1102
- `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeRecipeValue(max)}`
1146
+ `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeOptionValue(max)}`
1103
1147
  );
1104
1148
  ok = false;
1105
1149
  }
@@ -1128,7 +1172,7 @@ function checkSandboxesDefault(value, report) {
1128
1172
  if (!isRecord(value)) {
1129
1173
  report(
1130
1174
  ["sandboxes", "default"],
1131
- `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }, not ${describeRecipeValue(value)}`
1175
+ `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or { filesPerSandbox, max? }, not ${describeOptionValue(value)}`
1132
1176
  );
1133
1177
  return void 0;
1134
1178
  }
@@ -1136,14 +1180,14 @@ function checkSandboxesDefault(value, report) {
1136
1180
  value,
1137
1181
  SANDBOXES_DEFAULT_RULE_KEYS,
1138
1182
  ["sandboxes", "default"],
1139
- "a runner recipe sandboxes default rule key",
1183
+ "a vercelSandbox sandboxes default rule key",
1140
1184
  report
1141
1185
  );
1142
1186
  const filesPerSandbox = value["filesPerSandbox"];
1143
1187
  if (!isPositiveInteger(filesPerSandbox)) {
1144
1188
  report(
1145
1189
  ["sandboxes", "default", "filesPerSandbox"],
1146
- `must be a positive whole number, not ${describeRecipeValue(filesPerSandbox)}`
1190
+ `must be a positive whole number, not ${describeOptionValue(filesPerSandbox)}`
1147
1191
  );
1148
1192
  ok = false;
1149
1193
  }
@@ -1151,7 +1195,7 @@ function checkSandboxesDefault(value, report) {
1151
1195
  if (max !== void 0 && (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES)) {
1152
1196
  report(
1153
1197
  ["sandboxes", "default", "max"],
1154
- `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeRecipeValue(max)}`
1198
+ `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeOptionValue(max)}`
1155
1199
  );
1156
1200
  ok = false;
1157
1201
  }
@@ -1165,19 +1209,19 @@ function checkSnapshot(value, report) {
1165
1209
  if (!isRecord(value)) {
1166
1210
  report(
1167
1211
  ["snapshot"],
1168
- `must be an object of vcpus, toolchains, prebuild, and an optional summary, not ${describeRecipeValue(value)}`
1212
+ `must be an object of vcpus, toolchains, prebuild, and an optional summary, not ${describeOptionValue(value)}`
1169
1213
  );
1170
1214
  return void 0;
1171
1215
  }
1172
- let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a runner recipe snapshot key", report);
1216
+ let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a vercelSandbox snapshot key", report);
1173
1217
  const vcpus = value["vcpus"];
1174
1218
  if (!isPositiveInteger(vcpus)) {
1175
- report(["snapshot", "vcpus"], `must be a positive whole number, not ${describeRecipeValue(vcpus)}`);
1219
+ report(["snapshot", "vcpus"], `must be a positive whole number, not ${describeOptionValue(vcpus)}`);
1176
1220
  ok = false;
1177
1221
  }
1178
1222
  const summary = value["summary"];
1179
1223
  if (summary !== void 0 && !isNonEmptyString(summary)) {
1180
- report(["snapshot", "summary"], `must be a non-empty string, not ${describeRecipeValue(summary)}`);
1224
+ report(["snapshot", "summary"], `must be a non-empty string, not ${describeOptionValue(summary)}`);
1181
1225
  ok = false;
1182
1226
  }
1183
1227
  const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], true, report);
@@ -1192,10 +1236,10 @@ function checkSnapshot(value, report) {
1192
1236
  }
1193
1237
  function checkRun(value, report) {
1194
1238
  if (!isRecord(value)) {
1195
- report(["run"], `must be an object of install and build steps, not ${describeRecipeValue(value)}`);
1239
+ report(["run"], `must be an object of install and build steps, not ${describeOptionValue(value)}`);
1196
1240
  return void 0;
1197
1241
  }
1198
- const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a runner recipe run key", report);
1242
+ const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a vercelSandbox run key", report);
1199
1243
  const install = checkStep(value["install"], ["run", "install"], false, report);
1200
1244
  const build = checkStep(value["build"], ["run", "build"], false, report);
1201
1245
  return ok && install !== void 0 && build !== void 0 ? { install, build } : void 0;
@@ -1209,7 +1253,7 @@ function checkSteps(value, path, allowBaseFiles, report) {
1209
1253
  return void 0;
1210
1254
  }
1211
1255
  if (!Array.isArray(value)) {
1212
- report(path, `must be a list of steps, not ${describeRecipeValue(value)}`);
1256
+ report(path, `must be a list of steps, not ${describeOptionValue(value)}`);
1213
1257
  return void 0;
1214
1258
  }
1215
1259
  const steps = value.map(
@@ -1220,7 +1264,7 @@ function checkSteps(value, path, allowBaseFiles, report) {
1220
1264
  function checkStep(value, path, allowBaseFiles, report) {
1221
1265
  if (!isRecord(value)) {
1222
1266
  const shape = allowBaseFiles ? "{ label, script, baseFiles? }" : "{ label, script }";
1223
- report(path, `must be a step, ${shape}, not ${describeRecipeValue(value)}`);
1267
+ report(path, `must be a step, ${shape}, not ${describeOptionValue(value)}`);
1224
1268
  return void 0;
1225
1269
  }
1226
1270
  const allowedKeys = allowBaseFiles ? TOOLCHAIN_STEP_KEYS : STEP_KEYS;
@@ -1229,18 +1273,18 @@ function checkStep(value, path, allowBaseFiles, report) {
1229
1273
  if (allowedKeys.has(key)) continue;
1230
1274
  report(
1231
1275
  [...path, key],
1232
- key === "secrets" ? "is not a step key: every recipe step gets every credential runner.credentials declares" : key === "baseFiles" ? "is only allowed on snapshot.toolchains steps: this step already sees the base's files" : "is not a step key"
1276
+ key === "secrets" ? "is not a step key: every step of the runner gets every credential runner.credentials declares" : key === "baseFiles" ? "is only allowed on snapshot.toolchains steps: this step already sees the base's files" : "is not a step key"
1233
1277
  );
1234
1278
  ok = false;
1235
1279
  }
1236
1280
  const label = value["label"];
1237
1281
  const script = value["script"];
1238
1282
  if (!isNonEmptyString(label)) {
1239
- report([...path, "label"], `must be a non-empty string, not ${describeRecipeValue(label)}`);
1283
+ report([...path, "label"], `must be a non-empty string, not ${describeOptionValue(label)}`);
1240
1284
  ok = false;
1241
1285
  }
1242
1286
  if (!isNonEmptyString(script)) {
1243
- report([...path, "script"], `must be a non-empty string, not ${describeRecipeValue(script)}`);
1287
+ report([...path, "script"], `must be a non-empty string, not ${describeOptionValue(script)}`);
1244
1288
  ok = false;
1245
1289
  }
1246
1290
  if (!allowBaseFiles) return ok ? { label, script } : void 0;
@@ -1256,7 +1300,7 @@ function checkStep(value, path, allowBaseFiles, report) {
1256
1300
  function checkBaseFiles(value, path, report) {
1257
1301
  if (value === void 0) return void 0;
1258
1302
  if (!Array.isArray(value)) {
1259
- report(path, `must be a list of relative file paths, not ${describeRecipeValue(value)}`);
1303
+ report(path, `must be a list of relative file paths, not ${describeOptionValue(value)}`);
1260
1304
  return null;
1261
1305
  }
1262
1306
  let ok = true;
@@ -1267,7 +1311,7 @@ function checkBaseFiles(value, path, report) {
1267
1311
  if (!isRelativeFilePath(entry)) {
1268
1312
  report(
1269
1313
  at,
1270
- `must be a relative file path without leading "/", "./", "..", or trailing "/", not ${describeRecipeValue(entry)}`
1314
+ `must be a relative file path without leading "/", "./", "..", or trailing "/", not ${describeOptionValue(entry)}`
1271
1315
  );
1272
1316
  ok = false;
1273
1317
  } else if (seen.has(entry)) {
@@ -1283,7 +1327,7 @@ function checkBaseFiles(value, path, report) {
1283
1327
  function checkEnv(value, report) {
1284
1328
  if (value === void 0) return {};
1285
1329
  if (!isRecord(value)) {
1286
- report(["env"], `must be an object of strings, not ${describeRecipeValue(value)}`);
1330
+ report(["env"], `must be an object of strings, not ${describeOptionValue(value)}`);
1287
1331
  return void 0;
1288
1332
  }
1289
1333
  let ok = true;
@@ -1293,7 +1337,7 @@ function checkEnv(value, report) {
1293
1337
  report(["env", key], "can't be set: storm sets it for the command");
1294
1338
  ok = false;
1295
1339
  } else if (typeof variable !== "string") {
1296
- report(["env", key], `must be a string, not ${describeRecipeValue(variable)}`);
1340
+ report(["env", key], `must be a string, not ${describeOptionValue(variable)}`);
1297
1341
  ok = false;
1298
1342
  } else env[key] = variable;
1299
1343
  }
@@ -1304,7 +1348,7 @@ function checkAllowedDomains(value, report) {
1304
1348
  if (!Array.isArray(value)) {
1305
1349
  report(
1306
1350
  ["allowedDomains"],
1307
- `must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${describeRecipeValue(value)}`
1351
+ `must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${describeOptionValue(value)}`
1308
1352
  );
1309
1353
  return null;
1310
1354
  }
@@ -1322,7 +1366,7 @@ function checkAllowedDomains(value, report) {
1322
1366
  } else if (typeof domain !== "string" || !ALLOWED_DOMAIN_PATTERN.test(domain)) {
1323
1367
  report(
1324
1368
  at,
1325
- `must be a hostname, such as example.com, or a wildcard with one leading *., such as *.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, or path, not ${describeRecipeValue(domain)}`
1369
+ `must be a hostname, such as example.com, or a wildcard with one leading *., such as *.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, or path, not ${describeOptionValue(domain)}`
1326
1370
  );
1327
1371
  ok = false;
1328
1372
  } else if (seen.has(domain)) {
@@ -1334,15 +1378,15 @@ function checkAllowedDomains(value, report) {
1334
1378
  return ok ? [...value] : null;
1335
1379
  }
1336
1380
  function checkBaseRefs(value, report) {
1337
- if (value === void 0) return [...RECIPE_DEFAULTS.baseRefs];
1381
+ if (value === void 0) return [...VERCEL_SANDBOX_DEFAULTS.baseRefs];
1338
1382
  if (!Array.isArray(value) || value.length === 0) {
1339
- report(["baseRefs"], `must be a non-empty list of refs, not ${describeRecipeValue(value)}`);
1383
+ report(["baseRefs"], `must be a non-empty list of refs, not ${describeOptionValue(value)}`);
1340
1384
  return void 0;
1341
1385
  }
1342
1386
  let ok = true;
1343
1387
  value.forEach((ref, index) => {
1344
1388
  if (!isNonEmptyString(ref)) {
1345
- report(["baseRefs", String(index)], `must be a non-empty string, not ${describeRecipeValue(ref)}`);
1389
+ report(["baseRefs", String(index)], `must be a non-empty string, not ${describeOptionValue(ref)}`);
1346
1390
  ok = false;
1347
1391
  }
1348
1392
  });
@@ -1356,16 +1400,16 @@ function declaredBaseFilePaths(toolchains) {
1356
1400
  }
1357
1401
  return [...paths].toSorted((a, b) => a < b ? -1 : a > b ? 1 : 0);
1358
1402
  }
1359
- function resolveVcpus(recipe, run) {
1360
- if (typeof recipe.vcpus === "number") return { ok: true, vcpus: recipe.vcpus };
1361
- const { resource, option, per, min, max } = recipe.vcpus;
1362
- const options = Object.hasOwn(run.resources, resource) ? run.resources[resource] : void 0;
1363
- if (options === void 0) return { ok: true, vcpus: min };
1364
- const raw = Object.hasOwn(options, option) ? options[option] : void 0;
1403
+ function resolveVcpus(options, run) {
1404
+ if (typeof options.vcpus === "number") return { ok: true, vcpus: options.vcpus };
1405
+ const { resource, option, per, min, max } = options.vcpus;
1406
+ const resourceOptions = Object.hasOwn(run.resources, resource) ? run.resources[resource] : void 0;
1407
+ if (resourceOptions === void 0) return { ok: true, vcpus: min };
1408
+ const raw = Object.hasOwn(resourceOptions, option) ? resourceOptions[option] : void 0;
1365
1409
  if (typeof raw !== "number" || !Number.isFinite(raw) || raw < 0) {
1366
1410
  return {
1367
1411
  ok: false,
1368
- problem: `resource "${resource}" option "${option}" must be a non-negative number, not ${describeRecipeValue(raw)}`
1412
+ problem: `resource "${resource}" option "${option}" must be a non-negative number, not ${describeOptionValue(raw)}`
1369
1413
  };
1370
1414
  }
1371
1415
  const perSandbox = Math.ceil(raw / Math.max(1, run.sandboxes));
@@ -1463,8 +1507,8 @@ function snapshotKey(steps) {
1463
1507
  ).digest("hex");
1464
1508
  }
1465
1509
  async function snapshotInputsAt(checkout, request2) {
1466
- const { repoRoot, base, recipe } = request2;
1467
- const { snapshot } = recipe;
1510
+ const { repoRoot, base, options } = request2;
1511
+ const { snapshot } = options;
1468
1512
  const baseFiles = [];
1469
1513
  for (const path of declaredBaseFilePaths(snapshot.toolchains)) {
1470
1514
  const file = await checkout.readFileAt({ repoRoot, commit: base, path });
@@ -1488,7 +1532,7 @@ async function snapshotInputsAt(checkout, request2) {
1488
1532
  ok: true,
1489
1533
  baseFiles,
1490
1534
  key: snapshotKey({
1491
- credentials: credentialSourceIds(recipe),
1535
+ credentials: credentialSourceIds(options),
1492
1536
  baseFiles,
1493
1537
  toolchains: snapshot.toolchains,
1494
1538
  prebuild: snapshot.prebuild
@@ -1621,34 +1665,36 @@ var BUILD_SANDBOX_TIMEOUT_MS = 30 * 6e4;
1621
1665
  var BASE_INDEX_LABEL = "Committing the base's files";
1622
1666
  async function buildSnapshot(context, request2, control, progress) {
1623
1667
  const { prepared, access } = request2;
1624
- const { recipe, repoRoot, base } = prepared;
1668
+ const { options, repoRoot, base } = prepared;
1625
1669
  const { scope, signal } = control;
1670
+ const { publish } = request2;
1626
1671
  const now = () => context.clock.now().getTime();
1627
1672
  const startedAt = now();
1628
1673
  await progress.emit({
1629
1674
  kind: "snapshot-build-started",
1630
1675
  base,
1631
1676
  why: request2.why,
1632
- summary: recipe.snapshot.summary ?? [...recipe.snapshot.toolchains, ...recipe.snapshot.prebuild].map(({ label }) => label).join(", ")
1677
+ summary: options.snapshot.summary ?? [...options.snapshot.toolchains, ...options.snapshot.prebuild].map(({ label }) => label).join(", ")
1633
1678
  });
1634
1679
  const [started, archive] = await Promise.all([
1635
1680
  scope.startBuildSandbox(access, {
1636
- region: recipe.region,
1637
- runtime: recipe.runtime,
1638
- vcpus: recipe.snapshot.vcpus,
1681
+ region: options.region,
1682
+ runtime: options.runtime,
1683
+ vcpus: options.snapshot.vcpus,
1639
1684
  timeoutMs: BUILD_SANDBOX_TIMEOUT_MS,
1640
- tags: runnerTags(recipe.name, "snapshot-build", request2.user)
1685
+ ...publish === void 0 ? { tags: runnerTags(options.name, "snapshot-build", request2.user) } : { name: publish.name, tags: publish.tags }
1641
1686
  }),
1642
1687
  context.checkout.baseArchive({ repoRoot, base })
1643
1688
  ]);
1644
- if (!started.ok) return sandboxStop("start-build-sandbox", started.failure);
1689
+ if (!started.ok)
1690
+ return started.failure.kind === "name-taken" ? { kind: "name-taken", name: started.failure.name, message: started.failure.message } : sandboxStop("start-build-sandbox", started.failure);
1645
1691
  const sandbox = started.value;
1646
1692
  await progress.emit({
1647
1693
  kind: "sandbox-started",
1648
1694
  role: "snapshot-build",
1649
1695
  name: sandbox.name,
1650
- region: recipe.region,
1651
- vcpus: recipe.snapshot.vcpus,
1696
+ region: options.region,
1697
+ vcpus: options.snapshot.vcpus,
1652
1698
  ms: now() - startedAt
1653
1699
  });
1654
1700
  if (!archive.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: archive.failure } };
@@ -1671,11 +1717,11 @@ async function buildSnapshot(context, request2, control, progress) {
1671
1717
  if (!placed.ok) return sandboxStop("upload", placed.failure);
1672
1718
  }
1673
1719
  const steps = [
1674
- ...recipe.snapshot.toolchains,
1720
+ ...options.snapshot.toolchains,
1675
1721
  { label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
1676
- ...recipe.snapshot.prebuild
1722
+ ...options.snapshot.prebuild
1677
1723
  ];
1678
- await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: recipe.region });
1724
+ await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: options.region });
1679
1725
  let stop;
1680
1726
  if (request2.credentials.length > 0) {
1681
1727
  const granted = await scope.grantCredentials(sandbox, request2.credentials, signal);
@@ -1709,16 +1755,19 @@ async function buildSnapshot(context, request2, control, progress) {
1709
1755
  if (stop !== void 0) return stop;
1710
1756
  if (signal.aborted) return { kind: "aborted" };
1711
1757
  await progress.emit({ kind: "snapshot-saving" });
1712
- const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
1758
+ const saved = await scope.saveSnapshot(sandbox, {
1759
+ expirationMs: SNAPSHOT_EXPIRATION_MS,
1760
+ ...publish === void 0 ? {} : { keepStopped: true }
1761
+ });
1713
1762
  if (!saved.ok)
1714
1763
  return saved.failure.kind === "credential-not-revoked" ? networkPolicyStop("remove", "snapshot-save", saved.failure.failure) : sandboxStop("save-snapshot", saved.failure);
1715
1764
  const savedAt = context.clock.now();
1716
1765
  const entry = {
1717
1766
  teamId: access.teamId,
1718
1767
  projectId: access.projectId,
1719
- region: recipe.region,
1720
- runtime: recipe.runtime,
1721
- recipeName: recipe.name,
1768
+ region: options.region,
1769
+ runtime: options.runtime,
1770
+ runnerName: options.name,
1722
1771
  snapshotKey: prepared.snapshotKey,
1723
1772
  base,
1724
1773
  snapshotId: saved.value.snapshotId,
@@ -1738,20 +1787,146 @@ async function buildSnapshot(context, request2, control, progress) {
1738
1787
  });
1739
1788
  return {
1740
1789
  kind: "ok",
1741
- value: { entry, ms, sizeBytes: saved.value.sizeBytes, cacheFailure: written.ok ? null : written.failure }
1790
+ value: { entry, ms, sizeBytes: saved.value.sizeBytes, localIndexFailure: written.ok ? null : written.failure }
1742
1791
  };
1743
1792
  }
1744
1793
 
1794
+ // src/runner/shared-snapshot-entry.ts
1795
+ import { createHash as createHash3 } from "node:crypto";
1796
+ var SHARED_SNAPSHOT_SANDBOX_PREFIX = "storm-snap-";
1797
+ var SHARED_SNAPSHOT_NAME_PATTERN = /^storm-snap-([0-9a-f]{16})-([0-9a-f]{40})$/;
1798
+ var INDEX_CONCURRENCY = 8;
1799
+ function isBuildingSandboxStatus(status) {
1800
+ switch (status) {
1801
+ case "pending":
1802
+ case "running":
1803
+ case "snapshotting":
1804
+ case "stopping":
1805
+ return true;
1806
+ case "stopped":
1807
+ case "failed":
1808
+ case "aborted":
1809
+ return false;
1810
+ }
1811
+ }
1812
+ function hasSnapshotId(row) {
1813
+ return row.currentSnapshotId !== void 0 && row.currentSnapshotId !== "";
1814
+ }
1815
+ function sharedSnapshotBucket(input) {
1816
+ return createHash3("sha256").update(
1817
+ [input.teamId, input.projectId, input.region, input.runtime, input.runnerName, input.snapshotKey].join("\0")
1818
+ ).digest("hex").slice(0, 16);
1819
+ }
1820
+ function sharedSnapshotSandboxPrefix(bucket) {
1821
+ return `${SHARED_SNAPSHOT_SANDBOX_PREFIX}${bucket}-`;
1822
+ }
1823
+ function sharedSnapshotSandboxName(bucket, base) {
1824
+ return `${SHARED_SNAPSHOT_SANDBOX_PREFIX}${bucket}-${base}`;
1825
+ }
1826
+ function parseSharedSnapshotSandboxName(name) {
1827
+ const match = SHARED_SNAPSHOT_NAME_PATTERN.exec(name);
1828
+ if (match === null) return null;
1829
+ const [, bucket, base] = match;
1830
+ if (bucket === void 0 || base === void 0) return null;
1831
+ return { bucket, base };
1832
+ }
1833
+ function classifyUnverifiedSharedSandbox(row) {
1834
+ if (isBuildingSandboxStatus(row.status)) return { kind: "settled", status: "building" };
1835
+ if (row.status === "failed" || row.status === "aborted") return { kind: "settled", status: "failed" };
1836
+ if (!hasSnapshotId(row)) return { kind: "settled", status: "no-snapshot" };
1837
+ return { kind: "needs-snapshot", snapshotId: row.currentSnapshotId };
1838
+ }
1839
+ function classifyVerifiedSharedSnapshot(row, lookup, now) {
1840
+ if (lookup.kind === "not-found") {
1841
+ return {
1842
+ status: "missing",
1843
+ snapshotId: row.currentSnapshotId,
1844
+ snapshotStatus: void 0,
1845
+ createdAt: row.createdAt,
1846
+ expiresAt: row.tags["expires-at"]
1847
+ };
1848
+ }
1849
+ const { snapshot } = lookup;
1850
+ const expiresAt = snapshot.expiresAt ?? row.tags["expires-at"];
1851
+ if (snapshot.status !== "created") {
1852
+ return {
1853
+ status: "missing",
1854
+ snapshotId: snapshot.snapshotId,
1855
+ snapshotStatus: snapshot.status,
1856
+ createdAt: snapshot.createdAt,
1857
+ expiresAt
1858
+ };
1859
+ }
1860
+ const expiresAtMs = expiresAt === void 0 ? Number.NaN : Date.parse(expiresAt);
1861
+ if (Number.isNaN(expiresAtMs)) {
1862
+ return {
1863
+ status: "unknown-expiry",
1864
+ snapshotId: snapshot.snapshotId,
1865
+ snapshotStatus: snapshot.status,
1866
+ createdAt: snapshot.createdAt,
1867
+ expiresAt
1868
+ };
1869
+ }
1870
+ const nowMs = now.getTime();
1871
+ const status = expiresAtMs <= nowMs ? "expired" : expiresAtMs - nowMs > SNAPSHOT_MIN_REMAINING_MS ? "ready" : "expires-soon";
1872
+ return {
1873
+ status,
1874
+ snapshotId: snapshot.snapshotId,
1875
+ snapshotStatus: snapshot.status,
1876
+ createdAt: snapshot.createdAt,
1877
+ expiresAt
1878
+ };
1879
+ }
1880
+ function usableSharedEntry(access, runner, snapshotKey2, base, sandbox, snapshot, now) {
1881
+ const verified = classifyVerifiedSharedSnapshot(
1882
+ { ...sandbox, currentSnapshotId: snapshot.snapshotId },
1883
+ { kind: "found", snapshot },
1884
+ now
1885
+ );
1886
+ if (verified.status !== "ready" || verified.expiresAt === void 0) return null;
1887
+ return {
1888
+ teamId: access.teamId,
1889
+ projectId: access.projectId,
1890
+ region: runner.region,
1891
+ runtime: runner.runtime,
1892
+ runnerName: runner.name,
1893
+ snapshotKey: snapshotKey2,
1894
+ base,
1895
+ snapshotId: verified.snapshotId,
1896
+ createdAt: verified.createdAt,
1897
+ expiresAt: verified.expiresAt
1898
+ };
1899
+ }
1900
+ async function runLimited(count, limit, proceed, task) {
1901
+ const results = Array.from({ length: count }, () => void 0);
1902
+ let failure;
1903
+ let next = 0;
1904
+ const worker = async () => {
1905
+ while (failure === void 0 && next < count && proceed()) {
1906
+ const index = next;
1907
+ next += 1;
1908
+ try {
1909
+ results[index] = await task(index);
1910
+ } catch (error) {
1911
+ failure ??= { error };
1912
+ }
1913
+ }
1914
+ };
1915
+ await Promise.all(Array.from({ length: Math.min(limit, count) }, worker));
1916
+ if (failure !== void 0) throw failure.error;
1917
+ return results;
1918
+ }
1919
+
1745
1920
  // src/runner/build-snapshots.ts
1746
1921
  async function prepareSnapshotBuild(context, request2) {
1747
1922
  const { checkout } = context;
1748
- const { recipe, ref } = request2;
1923
+ const { options, ref } = request2;
1749
1924
  const root = await checkout.repositoryRoot({ cwd: request2.cwd });
1750
1925
  if (!root.ok) return { kind: "checkout-failed", failure: root.failure };
1751
1926
  const repoRoot = root.value;
1752
1927
  const head2 = await checkout.head({ repoRoot });
1753
1928
  if (!head2.ok) return { kind: "checkout-failed", failure: head2.failure };
1754
- const resolved = await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
1929
+ const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
1755
1930
  if (resolved.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
1756
1931
  const mergeBase = resolved.kind === "resolved" ? { commit: resolved.base, ref: resolved.ref } : null;
1757
1932
  const submodules2 = await checkout.submodules({ repoRoot });
@@ -1767,12 +1942,12 @@ async function prepareSnapshotBuild(context, request2) {
1767
1942
  if (commit.value === null) return { kind: "ref-not-found", ref };
1768
1943
  base = commit.value;
1769
1944
  }
1770
- const inputs = await snapshotInputsAt(checkout, { repoRoot, base, recipe });
1771
- if (!inputs.ok) return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
1945
+ const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
1946
+ if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
1772
1947
  const listed = await context.runnerSnapshots.listEntries();
1773
1948
  const now = context.clock.now();
1774
- const cached = (listed.ok ? listed.value.entries : []).filter(
1775
- (entry) => entry.base === base && entry.recipeName === recipe.name && entry.region === recipe.region && entry.runtime === recipe.runtime && entry.snapshotKey === inputs.key && hasTimeLeft(entry, now)
1949
+ const indexed = (listed.ok ? listed.value.entries : []).filter(
1950
+ (entry) => entry.base === base && entry.runnerName === options.name && entry.region === options.region && entry.runtime === options.runtime && entry.snapshotKey === inputs.key && hasTimeLeft(entry, now)
1776
1951
  );
1777
1952
  const atMergeBase = base === mergeBase?.commit;
1778
1953
  let commitsAfterBase = null;
@@ -1781,11 +1956,17 @@ async function prepareSnapshotBuild(context, request2) {
1781
1956
  if (!counted.ok) return { kind: "checkout-failed", failure: counted.failure };
1782
1957
  commitsAfterBase = counted.value;
1783
1958
  }
1959
+ let ancestorOfMergeBase = false;
1960
+ if (!atMergeBase && mergeBase !== null) {
1961
+ const contained = await checkout.contains({ repoRoot, ancestor: base, descendant: mergeBase.commit });
1962
+ if (!contained.ok) return { kind: "checkout-failed", failure: contained.failure };
1963
+ ancestorOfMergeBase = contained.value;
1964
+ }
1784
1965
  return {
1785
1966
  kind: "ok",
1786
1967
  build: {
1787
1968
  plan: {
1788
- recipe,
1969
+ options,
1789
1970
  repoRoot,
1790
1971
  base,
1791
1972
  baseFiles: inputs.baseFiles,
@@ -1796,7 +1977,8 @@ async function prepareSnapshotBuild(context, request2) {
1796
1977
  ref: ref ?? null,
1797
1978
  mergeBase,
1798
1979
  atMergeBase,
1799
- cached,
1980
+ ancestorOfMergeBase,
1981
+ indexed,
1800
1982
  full: request2.full
1801
1983
  }
1802
1984
  };
@@ -1805,7 +1987,7 @@ async function buildSnapshots(context, request2, control, progress) {
1805
1987
  const { signal } = control;
1806
1988
  const scope = runnerSandboxScope(context, progress, {
1807
1989
  keepMs: 0,
1808
- basePolicy: runnerNetworkPolicy(request2.build.plan.recipe),
1990
+ basePolicy: runnerNetworkPolicy(request2.build.plan.options),
1809
1991
  signal
1810
1992
  });
1811
1993
  try {
@@ -1820,26 +2002,99 @@ async function buildIn(context, request2, control, progress) {
1820
2002
  const { build, access, user, credentials: credentials2 } = request2;
1821
2003
  const { signal } = control;
1822
2004
  if (signal.aborted) return { kind: "aborted", snapshot: null };
1823
- const cached = build.cached.find((entry2) => entry2.teamId === access.teamId && entry2.projectId === access.projectId);
1824
- if (!build.full && cached !== void 0) return { kind: "up-to-date", snapshot: cached };
2005
+ if (request2.publish === true) return await publishIn(context, request2, control, progress);
2006
+ const indexed = build.indexed.find((entry2) => entry2.teamId === access.teamId && entry2.projectId === access.projectId);
2007
+ if (!build.full && indexed !== void 0) return { kind: "up-to-date", snapshot: indexed };
2008
+ const built = await buildSnapshot(
2009
+ context,
2010
+ { prepared: build.plan, access, user, credentials: credentials2, why: buildReason(build) },
2011
+ control,
2012
+ progress
2013
+ );
2014
+ if (built.kind === "aborted") return { kind: "aborted", snapshot: null };
2015
+ if (built.kind !== "ok") return built;
2016
+ const { entry, localIndexFailure, ms, sizeBytes } = built.value;
2017
+ if (signal.aborted) return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
2018
+ return localIndexFailure === null ? { kind: "built", snapshot: entry, ms, sizeBytes } : { kind: "not-indexed", snapshot: entry, failure: localIndexFailure };
2019
+ }
2020
+ function buildReason(build) {
1825
2021
  const why = build.full ? "full" : build.ref === null ? "no-snapshot" : "base";
2022
+ return why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why };
2023
+ }
2024
+ async function publishIn(context, request2, control, progress) {
2025
+ const { build, access, user, credentials: credentials2 } = request2;
2026
+ const { plan } = build;
2027
+ const { options } = plan;
2028
+ const { signal } = control;
2029
+ const { runnerSandboxes } = context;
2030
+ const bucket = sharedSnapshotBucket({
2031
+ teamId: access.teamId,
2032
+ projectId: access.projectId,
2033
+ region: options.region,
2034
+ runtime: options.runtime,
2035
+ runnerName: options.name,
2036
+ snapshotKey: plan.snapshotKey
2037
+ });
2038
+ const name = sharedSnapshotSandboxName(bucket, plan.base);
2039
+ const found = await runnerSandboxes.getNamedSandbox(access, { name }, signal);
2040
+ if (!found.ok) return callStop("get-named-sandbox", found.failure);
2041
+ if (found.value.kind === "found") {
2042
+ const { sandbox } = found.value;
2043
+ const unverified = classifyUnverifiedSharedSandbox(sandbox);
2044
+ if (unverified.kind === "settled" && unverified.status === "building")
2045
+ return { kind: "already-building", sandboxName: name, status: sandbox.status };
2046
+ if (!build.full && unverified.kind === "needs-snapshot") {
2047
+ const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
2048
+ if (!verified.ok) return callStop("get-snapshot", verified.failure);
2049
+ const entry2 = verified.value.kind === "found" ? usableSharedEntry(
2050
+ access,
2051
+ options,
2052
+ plan.snapshotKey,
2053
+ plan.base,
2054
+ sandbox,
2055
+ verified.value.snapshot,
2056
+ context.clock.now()
2057
+ ) : null;
2058
+ if (entry2 !== null) {
2059
+ const written = await context.runnerSnapshots.writeEntry(entry2);
2060
+ if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
2061
+ return { kind: "up-to-date", snapshot: entry2, sandboxName: name };
2062
+ }
2063
+ }
2064
+ const removed = await runnerSandboxes.deleteNamedSandbox(access, { name }, signal);
2065
+ if (!removed.ok) return callStop("delete-named-sandbox", removed.failure);
2066
+ }
2067
+ if (signal.aborted) return { kind: "aborted", snapshot: null };
2068
+ const expiresAt = new Date(context.clock.now().getTime() + SNAPSHOT_EXPIRATION_MS).toISOString();
1826
2069
  const built = await buildSnapshot(
1827
2070
  context,
1828
2071
  {
1829
- prepared: build.plan,
2072
+ prepared: plan,
1830
2073
  access,
1831
2074
  user,
1832
2075
  credentials: credentials2,
1833
- why: why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why }
2076
+ why: buildReason(build),
2077
+ publish: { name, tags: snapshotIndexTags(options.name, user, plan.base, expiresAt) }
1834
2078
  },
1835
2079
  control,
1836
2080
  progress
1837
2081
  );
2082
+ if (built.kind === "name-taken") return { kind: "already-building", sandboxName: name, status: null };
1838
2083
  if (built.kind === "aborted") return { kind: "aborted", snapshot: null };
1839
2084
  if (built.kind !== "ok") return built;
1840
- const { entry, cacheFailure, ms, sizeBytes } = built.value;
1841
- if (signal.aborted) return { kind: "aborted", snapshot: { entry, cached: cacheFailure === null } };
1842
- return cacheFailure === null ? { kind: "built", snapshot: entry, ms, sizeBytes } : { kind: "not-cached", snapshot: entry, failure: cacheFailure };
2085
+ const { entry, localIndexFailure, ms, sizeBytes } = built.value;
2086
+ if (signal.aborted) return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
2087
+ return {
2088
+ kind: "built",
2089
+ snapshot: entry,
2090
+ ms,
2091
+ sizeBytes,
2092
+ sandboxName: name,
2093
+ ...localIndexFailure === null ? {} : { localIndexFailure }
2094
+ };
2095
+ }
2096
+ function callStop(operation, failure) {
2097
+ return failure.kind === "aborted" ? { kind: "aborted", snapshot: null } : { kind: "failed", failure: sandboxApiFailure(operation, failure) };
1843
2098
  }
1844
2099
 
1845
2100
  // src/runner/live/user.ts
@@ -1853,11 +2108,11 @@ function localUserName() {
1853
2108
  }
1854
2109
 
1855
2110
  // src/runner/secrets.ts
1856
- function declaredSecretValues(recipe, env) {
1857
- if (recipe === void 0) return [];
2111
+ function declaredSecretValues(options, env) {
2112
+ if (options === void 0) return [];
1858
2113
  const seen = /* @__PURE__ */ new Set();
1859
2114
  const values = [];
1860
- for (const { source } of [...recipe.credentials, ...recipe.unsafeSecretEnvVars]) {
2115
+ for (const { source } of [...options.credentials, ...options.unsafeSecretEnvVars]) {
1861
2116
  const id = secretSourceId(source);
1862
2117
  if (seen.has(id)) continue;
1863
2118
  seen.add(id);
@@ -1866,8 +2121,8 @@ function declaredSecretValues(recipe, env) {
1866
2121
  }
1867
2122
  return values;
1868
2123
  }
1869
- function readCredentials(recipe, env) {
1870
- const read = readUniqueSources(recipe.credentials, env, ({ domain, header, requests }, value) => ({
2124
+ function readCredentials(options, env) {
2125
+ const read = readUniqueSources(options.credentials, env, ({ domain, header, requests }, value) => ({
1871
2126
  domain,
1872
2127
  header,
1873
2128
  value,
@@ -1875,8 +2130,11 @@ function readCredentials(recipe, env) {
1875
2130
  }));
1876
2131
  return read.ok ? { ok: true, credentials: read.items } : read;
1877
2132
  }
1878
- function readUnsafeSecretEnvVars(recipe, env) {
1879
- const read = readUniqueSources(recipe.unsafeSecretEnvVars, env, ({ name }, value) => [name, value]);
2133
+ function readUnsafeSecretEnvVars(options, env) {
2134
+ const read = readUniqueSources(options.unsafeSecretEnvVars, env, ({ name }, value) => [
2135
+ name,
2136
+ value
2137
+ ]);
1880
2138
  return read.ok ? { ok: true, values: Object.fromEntries(read.items) } : read;
1881
2139
  }
1882
2140
  function readUniqueSources(entries, env, map) {
@@ -1897,15 +2155,15 @@ function readUniqueSources(entries, env, map) {
1897
2155
  }
1898
2156
 
1899
2157
  // src/runner/snapshot-inspect.ts
1900
- async function inspectSnapshotCache(context, request2) {
2158
+ async function inspectLocalSnapshotIndex(context, request2) {
1901
2159
  const { checkout, runnerSnapshots } = context;
1902
- const { recipe } = request2;
2160
+ const { options } = request2;
1903
2161
  const listed = await runnerSnapshots.listEntries();
1904
- if (!listed.ok) return { kind: "cache-unreadable", ...listed.failure };
2162
+ if (!listed.ok) return { kind: "local-index-unreadable", ...listed.failure };
1905
2163
  const { directory, entries, unreadable } = listed.value;
1906
2164
  const now = context.clock.now();
1907
- const ofRecipe = (entry) => recipe !== void 0 && entry.recipeName === recipe.name && entry.region === recipe.region && entry.runtime === recipe.runtime;
1908
- const shows = (entry) => request2.all || recipe === void 0 || ofRecipe(entry);
2165
+ const ofRunner = (entry) => options !== void 0 && entry.runnerName === options.name && entry.region === options.region && entry.runtime === options.runtime;
2166
+ const shows = (entry) => request2.all || options === void 0 || ofRunner(entry);
1909
2167
  const shown = entries.filter(shows);
1910
2168
  const root = await checkout.repositoryRoot({ cwd: request2.cwd });
1911
2169
  const head2 = root.ok ? await checkout.head({ repoRoot: root.value }) : void 0;
@@ -1916,37 +2174,47 @@ async function inspectSnapshotCache(context, request2) {
1916
2174
  directory,
1917
2175
  checkout: null,
1918
2176
  picking: { kind: "none", why: "no-checkout" },
2177
+ snapshotKey: null,
1919
2178
  snapshots: shown.map((entry) => unchecked(entry, now)),
1920
2179
  unreadable
1921
2180
  }
1922
2181
  };
1923
2182
  }
1924
2183
  const repoRoot = root.value;
1925
- const resolved = recipe === void 0 ? void 0 : await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
2184
+ const resolved = options === void 0 ? void 0 : await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
1926
2185
  if (resolved?.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
1927
- if (recipe === void 0 || resolved === void 0 || resolved.kind !== "resolved") {
2186
+ if (options === void 0 || resolved === void 0 || resolved.kind !== "resolved") {
1928
2187
  return {
1929
2188
  kind: "ok",
1930
2189
  inspection: {
1931
2190
  directory,
1932
2191
  checkout: { repoRoot, head: head2.value, mergeBase: null },
1933
- picking: { kind: "none", why: recipe === void 0 ? "no-recipe" : "no-base" },
2192
+ picking: { kind: "none", why: options === void 0 ? "no-runner" : "no-base" },
2193
+ snapshotKey: null,
1934
2194
  snapshots: shown.map((entry) => unchecked(entry, now)),
1935
2195
  unreadable
1936
2196
  }
1937
2197
  };
1938
2198
  }
1939
2199
  const mergeBase = resolved.base;
1940
- const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase, recipe });
1941
- if (!inputs.ok) return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
2200
+ const inputs = await snapshotInputsAt(checkout, { repoRoot, base: mergeBase, options });
2201
+ if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
1942
2202
  const afterBase = await checkout.commitCount({ repoRoot, from: mergeBase, to: "HEAD" });
1943
2203
  if (!afterBase.ok) return { kind: "checkout-failed", failure: afterBase.failure };
2204
+ const ancestorDistances = await resolveAncestorDistances(context, {
2205
+ repoRoot,
2206
+ entries,
2207
+ options,
2208
+ mergeBase
2209
+ });
2210
+ if (!ancestorDistances.ok) return { kind: "checkout-failed", failure: ancestorDistances.failure };
1944
2211
  const read = classifySnapshotEntries(context, {
1945
2212
  entries,
1946
- recipe,
2213
+ options,
1947
2214
  base: mergeBase,
1948
2215
  snapshotKey: inputs.key,
1949
- commitsAfterBase: afterBase.value
2216
+ commitsAfterBase: afterBase.value,
2217
+ ancestorDistances: ancestorDistances.value
1950
2218
  });
1951
2219
  const owners = new Map(read.candidates.map(({ entry }) => [`${entry.teamId}\0${entry.projectId}`, entry]));
1952
2220
  const picked = /* @__PURE__ */ new Set();
@@ -1954,7 +2222,12 @@ async function inspectSnapshotCache(context, request2) {
1954
2222
  const pick = pickSnapshot(read.candidates, owner);
1955
2223
  if (pick !== void 0) picked.add(pick);
1956
2224
  }
1957
- const place = historyPlacer(context, { repoRoot, mergeBase, commitsAfterBase: afterBase.value });
2225
+ const place = historyPlacer(context, {
2226
+ repoRoot,
2227
+ mergeBase,
2228
+ commitsAfterBase: afterBase.value,
2229
+ ancestorDistances: ancestorDistances.value
2230
+ });
1958
2231
  const snapshots = [];
1959
2232
  for (const verdict of read.verdicts) {
1960
2233
  const { entry } = verdict;
@@ -1966,62 +2239,347 @@ async function inspectSnapshotCache(context, request2) {
1966
2239
  entry,
1967
2240
  inHistory: true,
1968
2241
  builtBehind: candidate.builtBehind,
2242
+ commitsBehindMergeBase: candidate.commitsBehindMergeBase,
1969
2243
  expired,
1970
2244
  picked: picked.has(candidate),
1971
2245
  reason: null
1972
2246
  });
1973
2247
  continue;
1974
2248
  }
1975
- const placed = await place(entry.base);
1976
- if (!placed.ok) return { kind: "checkout-failed", failure: placed.failure };
1977
- snapshots.push({
1978
- entry,
1979
- ...placed.value,
1980
- expired,
1981
- picked: false,
1982
- reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-recipe"
1983
- });
2249
+ const placed = await place(entry.base);
2250
+ if (!placed.ok) return { kind: "checkout-failed", failure: placed.failure };
2251
+ snapshots.push({
2252
+ entry,
2253
+ ...placed.value,
2254
+ commitsBehindMergeBase: null,
2255
+ expired,
2256
+ picked: false,
2257
+ reason: verdict.kind === "rejected" ? verdict.rejection.reason : "other-runner"
2258
+ });
2259
+ }
2260
+ return {
2261
+ kind: "ok",
2262
+ inspection: {
2263
+ directory,
2264
+ checkout: {
2265
+ repoRoot,
2266
+ head: head2.value,
2267
+ mergeBase: { commit: mergeBase, ref: resolved.ref, commitsAfterBase: afterBase.value }
2268
+ },
2269
+ picking: { kind: "runner", runner: options.name },
2270
+ snapshotKey: inputs.key,
2271
+ snapshots,
2272
+ unreadable
2273
+ }
2274
+ };
2275
+ }
2276
+ function unchecked(entry, now) {
2277
+ return {
2278
+ entry,
2279
+ inHistory: null,
2280
+ builtBehind: null,
2281
+ commitsBehindMergeBase: null,
2282
+ expired: isExpiredEntry(entry, now),
2283
+ picked: false,
2284
+ reason: null
2285
+ };
2286
+ }
2287
+ function historyPlacer(context, request2) {
2288
+ const { repoRoot } = request2;
2289
+ const known = new Map([
2290
+ [request2.mergeBase, { inHistory: true, builtBehind: request2.commitsAfterBase }],
2291
+ ...Object.entries(request2.ancestorDistances).map(
2292
+ ([base, commitsBehindMergeBase]) => [
2293
+ base,
2294
+ { inHistory: true, builtBehind: request2.commitsAfterBase + commitsBehindMergeBase }
2295
+ ]
2296
+ )
2297
+ ]);
2298
+ return async (base) => {
2299
+ const answer = known.get(base);
2300
+ if (answer !== void 0) return { ok: true, value: answer };
2301
+ const contained = await context.checkout.contains({ repoRoot, ancestor: base, descendant: "HEAD" });
2302
+ if (!contained.ok) return contained;
2303
+ let placed = { inHistory: false, builtBehind: null };
2304
+ if (contained.value) {
2305
+ const counted = await context.checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
2306
+ if (!counted.ok) return counted;
2307
+ placed = { inHistory: true, builtBehind: counted.value };
2308
+ }
2309
+ known.set(base, placed);
2310
+ return { ok: true, value: placed };
2311
+ };
2312
+ }
2313
+
2314
+ // src/runner/shared-snapshot-list.ts
2315
+ async function listSharedSnapshots(context, request2, signal) {
2316
+ const { runnerSandboxes, clock } = context;
2317
+ const { access, runner, snapshotKey: snapshotKey2 } = request2;
2318
+ const bucket = sharedSnapshotBucket({
2319
+ teamId: access.teamId,
2320
+ projectId: access.projectId,
2321
+ region: runner.region,
2322
+ runtime: runner.runtime,
2323
+ runnerName: runner.name,
2324
+ snapshotKey: snapshotKey2
2325
+ });
2326
+ const listed = await runnerSandboxes.listNamedSandboxes(
2327
+ access,
2328
+ { namePrefix: sharedSnapshotSandboxPrefix(bucket) },
2329
+ signal
2330
+ );
2331
+ if (!listed.ok) {
2332
+ return listed.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: listed.failure.message };
2333
+ }
2334
+ const now = clock.now();
2335
+ const matched = [];
2336
+ for (const row of listed.value) {
2337
+ const parsed = parseSharedSnapshotSandboxName(row.name);
2338
+ if (parsed === null || parsed.bucket !== bucket) continue;
2339
+ matched.push({ row, base: parsed.base });
2340
+ }
2341
+ let stop = false;
2342
+ const outcomes = await runLimited(
2343
+ matched.length,
2344
+ INDEX_CONCURRENCY,
2345
+ () => !stop && signal?.aborted !== true,
2346
+ async (index) => {
2347
+ const { row, base } = matched[index];
2348
+ const unverified = classifyUnverifiedSharedSandbox(row);
2349
+ if (unverified.kind === "settled") {
2350
+ return {
2351
+ kind: "entry",
2352
+ entry: indexEntryOf(row, base, {
2353
+ status: unverified.status,
2354
+ snapshotId: unverified.status === "no-snapshot" ? void 0 : row.currentSnapshotId,
2355
+ snapshotStatus: void 0,
2356
+ createdAt: row.createdAt,
2357
+ expiresAt: row.tags["expires-at"],
2358
+ expired: false
2359
+ })
2360
+ };
2361
+ }
2362
+ const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
2363
+ if (!verified.ok) {
2364
+ stop = true;
2365
+ return verified.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: verified.failure.message };
2366
+ }
2367
+ const classified = classifyVerifiedSharedSnapshot(
2368
+ { ...row, currentSnapshotId: unverified.snapshotId },
2369
+ verified.value,
2370
+ now
2371
+ );
2372
+ return {
2373
+ kind: "entry",
2374
+ entry: indexEntryOf(row, base, {
2375
+ status: classified.status,
2376
+ snapshotId: classified.snapshotId,
2377
+ snapshotStatus: classified.snapshotStatus,
2378
+ createdAt: classified.createdAt,
2379
+ expiresAt: classified.expiresAt,
2380
+ expired: classified.status === "expired"
2381
+ })
2382
+ };
2383
+ }
2384
+ );
2385
+ if (signal?.aborted === true) return { kind: "aborted" };
2386
+ const entries = [];
2387
+ for (const outcome of outcomes) {
2388
+ if (outcome === void 0) continue;
2389
+ if (outcome.kind === "aborted") return { kind: "aborted" };
2390
+ if (outcome.kind === "failed") return outcome;
2391
+ entries.push(outcome.entry);
2392
+ }
2393
+ return { kind: "ok", bucket, entries };
2394
+ }
2395
+ function indexEntryOf(row, base, fields) {
2396
+ return {
2397
+ sandboxName: row.name,
2398
+ base,
2399
+ sandboxStatus: row.status,
2400
+ sandboxCreatedAt: row.createdAt,
2401
+ ...fields
2402
+ };
2403
+ }
2404
+ async function pickSnapshotAcrossIndexes(context, request2) {
2405
+ const { checkout } = context;
2406
+ const { repoRoot, mergeBase, commitsAfterBase, owner, local, entries } = request2;
2407
+ const owned = (snapshot) => snapshot.entry.teamId === owner.teamId && snapshot.entry.projectId === owner.projectId;
2408
+ const localPick = local.find((snapshot) => snapshot.picked && owned(snapshot));
2409
+ const behindMergeBaseByBase = /* @__PURE__ */ new Map([[mergeBase, 0]]);
2410
+ const qualifying = [];
2411
+ for (const entry of entries) {
2412
+ if (entry.status !== "ready") continue;
2413
+ let commitsBehindMergeBase = behindMergeBaseByBase.get(entry.base);
2414
+ if (commitsBehindMergeBase === void 0) {
2415
+ const ancestor = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
2416
+ if (!ancestor.ok) return { kind: "checkout-failed", failure: ancestor.failure };
2417
+ commitsBehindMergeBase = null;
2418
+ if (ancestor.value) {
2419
+ const counted = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
2420
+ if (!counted.ok) return { kind: "checkout-failed", failure: counted.failure };
2421
+ commitsBehindMergeBase = counted.value;
2422
+ }
2423
+ behindMergeBaseByBase.set(entry.base, commitsBehindMergeBase);
2424
+ }
2425
+ if (commitsBehindMergeBase !== null) qualifying.push({ entry, commitsBehindMergeBase });
2426
+ }
2427
+ const best = qualifying.toSorted(
2428
+ (a, b) => compareSnapshotCandidates(
2429
+ {
2430
+ commitsBehindMergeBase: a.commitsBehindMergeBase,
2431
+ createdAt: a.entry.sandboxCreatedAt,
2432
+ tieBreaker: a.entry.sandboxName
2433
+ },
2434
+ {
2435
+ commitsBehindMergeBase: b.commitsBehindMergeBase,
2436
+ createdAt: b.entry.sandboxCreatedAt,
2437
+ tieBreaker: b.entry.sandboxName
2438
+ }
2439
+ )
2440
+ )[0];
2441
+ const sharedPick = best !== void 0 && sharedBeatsLocal(best.commitsBehindMergeBase, localPick?.commitsBehindMergeBase ?? void 0) ? best.entry : void 0;
2442
+ const readyBehind = new Map(qualifying.map(({ entry, commitsBehindMergeBase }) => [entry, commitsBehindMergeBase]));
2443
+ return {
2444
+ kind: "ok",
2445
+ local: sharedPick === void 0 || localPick === void 0 ? local : local.map((snapshot) => snapshot === localPick ? { ...snapshot, picked: false } : snapshot),
2446
+ shared: entries.map((entry) => {
2447
+ const commitsBehindMergeBase = readyBehind.get(entry);
2448
+ return {
2449
+ entry,
2450
+ picked: entry === sharedPick,
2451
+ builtBehind: commitsBehindMergeBase === void 0 ? null : commitsAfterBase + commitsBehindMergeBase
2452
+ };
2453
+ })
2454
+ };
2455
+ }
2456
+
2457
+ // src/runner/shared-snapshot-prune.ts
2458
+ async function pruneSharedSnapshots(context, request2, signal) {
2459
+ const { runnerSandboxes, clock } = context;
2460
+ const { access, dryRun } = request2;
2461
+ const listed = await runnerSandboxes.listNamedSandboxes(
2462
+ access,
2463
+ { namePrefix: SHARED_SNAPSHOT_SANDBOX_PREFIX },
2464
+ signal
2465
+ );
2466
+ if (!listed.ok) {
2467
+ return listed.failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", message: listed.failure.message };
2468
+ }
2469
+ const validRows = listed.value.filter((row) => parseSharedSnapshotSandboxName(row.name) !== null);
2470
+ const now = clock.now();
2471
+ const nowMs = now.getTime();
2472
+ let aborted = false;
2473
+ const checked = await runLimited(
2474
+ validRows.length,
2475
+ INDEX_CONCURRENCY,
2476
+ () => !aborted && !isAborted(signal),
2477
+ async (index) => {
2478
+ const row = validRows[index];
2479
+ const unverified = classifyUnverifiedSharedSandbox(row);
2480
+ if (unverified.kind === "settled") {
2481
+ switch (unverified.status) {
2482
+ case "building":
2483
+ return { kind: "skip" };
2484
+ case "failed":
2485
+ return { kind: "mark", entry: { name: row.name, reason: "failed" } };
2486
+ case "no-snapshot":
2487
+ return { kind: "mark", entry: { name: row.name, reason: "no-snapshot" } };
2488
+ }
2489
+ }
2490
+ const tagExpiresAt = row.tags["expires-at"];
2491
+ if (tagExpiresAt !== void 0) {
2492
+ const tagMs = Date.parse(tagExpiresAt);
2493
+ if (!Number.isNaN(tagMs) && tagMs > nowMs) return { kind: "skip" };
2494
+ }
2495
+ const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
2496
+ if (!verified.ok) {
2497
+ if (verified.failure.kind === "aborted") {
2498
+ aborted = true;
2499
+ return void 0;
2500
+ }
2501
+ return { kind: "failed", failure: { name: row.name, message: verified.failure.message } };
2502
+ }
2503
+ const classified = classifyVerifiedSharedSnapshot(
2504
+ { ...row, currentSnapshotId: unverified.snapshotId },
2505
+ verified.value,
2506
+ now
2507
+ );
2508
+ switch (classified.status) {
2509
+ case "missing":
2510
+ return { kind: "mark", entry: { name: row.name, reason: "missing", snapshotId: unverified.snapshotId } };
2511
+ case "expired":
2512
+ return { kind: "mark", entry: { name: row.name, reason: "expired", snapshotId: unverified.snapshotId } };
2513
+ case "ready":
2514
+ case "expires-soon":
2515
+ case "unknown-expiry":
2516
+ return { kind: "skip" };
2517
+ }
2518
+ }
2519
+ );
2520
+ if (aborted || isAborted(signal)) return { kind: "aborted" };
2521
+ const marked = [];
2522
+ const failed = [];
2523
+ let skipped = 0;
2524
+ for (const outcome of checked) {
2525
+ if (outcome === void 0) continue;
2526
+ switch (outcome.kind) {
2527
+ case "skip":
2528
+ skipped += 1;
2529
+ break;
2530
+ case "mark":
2531
+ marked.push(outcome.entry);
2532
+ break;
2533
+ case "failed":
2534
+ failed.push(outcome.failure);
2535
+ break;
2536
+ }
2537
+ }
2538
+ const deleted = [];
2539
+ if (dryRun) {
2540
+ deleted.push(...marked);
2541
+ } else {
2542
+ const deleteResults = await runLimited(
2543
+ marked.length,
2544
+ INDEX_CONCURRENCY,
2545
+ () => !aborted && !isAborted(signal),
2546
+ async (index) => {
2547
+ const entry = marked[index];
2548
+ const removed = await runnerSandboxes.deleteNamedSandbox(access, { name: entry.name }, signal);
2549
+ if (removed.ok) return { kind: "deleted", entry };
2550
+ if (removed.failure.kind === "aborted") {
2551
+ aborted = true;
2552
+ return void 0;
2553
+ }
2554
+ return { kind: "failed", failure: { name: entry.name, message: removed.failure.message } };
2555
+ }
2556
+ );
2557
+ if (aborted || isAborted(signal)) return { kind: "aborted" };
2558
+ for (const outcome of deleteResults) {
2559
+ if (outcome === void 0) continue;
2560
+ switch (outcome.kind) {
2561
+ case "deleted":
2562
+ deleted.push(outcome.entry);
2563
+ break;
2564
+ case "failed":
2565
+ failed.push(outcome.failure);
2566
+ break;
2567
+ }
2568
+ }
1984
2569
  }
1985
2570
  return {
1986
2571
  kind: "ok",
1987
- inspection: {
1988
- directory,
1989
- checkout: { repoRoot, head: head2.value, mergeBase: { commit: mergeBase, ref: resolved.ref } },
1990
- picking: { kind: "recipe", recipe: recipe.name },
1991
- snapshots,
1992
- unreadable
2572
+ summary: {
2573
+ scanned: validRows.length,
2574
+ deleted,
2575
+ skipped,
2576
+ failed,
2577
+ dryRun
1993
2578
  }
1994
2579
  };
1995
2580
  }
1996
- function unchecked(entry, now) {
1997
- return {
1998
- entry,
1999
- inHistory: null,
2000
- builtBehind: null,
2001
- expired: isExpiredEntry(entry, now),
2002
- picked: false,
2003
- reason: null
2004
- };
2005
- }
2006
- function historyPlacer(context, request2) {
2007
- const { repoRoot } = request2;
2008
- const known = /* @__PURE__ */ new Map([
2009
- [request2.mergeBase, { inHistory: true, builtBehind: request2.commitsAfterBase }]
2010
- ]);
2011
- return async (base) => {
2012
- const answer = known.get(base);
2013
- if (answer !== void 0) return { ok: true, value: answer };
2014
- const contained = await context.checkout.contains({ repoRoot, ancestor: base, descendant: "HEAD" });
2015
- if (!contained.ok) return contained;
2016
- let placed = { inHistory: false, builtBehind: null };
2017
- if (contained.value) {
2018
- const counted = await context.checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
2019
- if (!counted.ok) return counted;
2020
- placed = { inHistory: true, builtBehind: counted.value };
2021
- }
2022
- known.set(base, placed);
2023
- return { ok: true, value: placed };
2024
- };
2581
+ function isAborted(signal) {
2582
+ return signal?.aborted === true;
2025
2583
  }
2026
2584
 
2027
2585
  // src/runner/live/checkout-gateway.ts
@@ -2247,6 +2805,9 @@ function apiStatus(error) {
2247
2805
  function isAbortError(error) {
2248
2806
  return typeof error === "object" && error !== null && error.name === "AbortError";
2249
2807
  }
2808
+ function isNameTakenError(error, message) {
2809
+ return apiStatus(error) === 400 && /already exists/i.test(message);
2810
+ }
2250
2811
  function sandboxFailure(error, signal) {
2251
2812
  if (signal?.aborted === true || isAbortError(error)) return { kind: "aborted" };
2252
2813
  return { kind: "api", status: apiStatus(error), message: error instanceof Error ? error.message : String(error) };
@@ -2256,7 +2817,9 @@ function sandboxFailure(error, signal) {
2256
2817
  var TERMINATE_GRACE_MS = 1e4;
2257
2818
  var KILL_GRACE_MS = 5e3;
2258
2819
  var STDERR_MESSAGE_CHARS = 1e3;
2820
+ var NOT_FOUND_STATUS = 404;
2259
2821
  var SNAPSHOT_GONE_STATUS = 410;
2822
+ var LIST_SANDBOXES_PAGE_LIMIT = 50;
2260
2823
  var DROP_CAPABILITIES_ARGS = [
2261
2824
  "--inh-caps=-all",
2262
2825
  "--ambient-caps=-all",
@@ -2284,14 +2847,18 @@ function liveRunnerSandboxGateway() {
2284
2847
  const { Sandbox } = await sdk();
2285
2848
  const sandbox = await Sandbox.create({
2286
2849
  ...credentials(access),
2287
- // oxlint-disable-next-line typescript/no-deprecated -- the recipe names a runtime; moving to `image` changes the recipe format.
2850
+ // oxlint-disable-next-line typescript/no-deprecated -- the runner options name a runtime; moving to `image` changes the config file's format.
2288
2851
  runtime: request2.runtime,
2852
+ ...request2.name === void 0 ? {} : { name: request2.name },
2289
2853
  ...placement(request2),
2290
2854
  ...signal === void 0 ? {} : { signal }
2291
2855
  });
2292
2856
  return { ok: true, value: adopt(sandbox, "snapshot-build", request2.timeoutMs) };
2293
2857
  } catch (error) {
2294
- return { ok: false, failure: sandboxFailure(error, signal) };
2858
+ const failure = sandboxFailure(error, signal);
2859
+ if (request2.name !== void 0 && failure.kind === "api" && isNameTakenError(error, failure.message))
2860
+ return { ok: false, failure: { kind: "name-taken", name: request2.name, message: failure.message } };
2861
+ return { ok: false, failure };
2295
2862
  }
2296
2863
  },
2297
2864
  async startRunnerSandbox(access, request2, signal) {
@@ -2311,6 +2878,112 @@ function liveRunnerSandboxGateway() {
2311
2878
  return { ok: false, failure };
2312
2879
  }
2313
2880
  },
2881
+ async getNamedSandbox(access, request2, signal) {
2882
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2883
+ try {
2884
+ const { Sandbox } = await sdk();
2885
+ const sandbox = await Sandbox.get({
2886
+ ...credentials(access),
2887
+ name: request2.name,
2888
+ ...signal === void 0 ? {} : { signal }
2889
+ });
2890
+ return {
2891
+ ok: true,
2892
+ value: {
2893
+ kind: "found",
2894
+ sandbox: {
2895
+ name: sandbox.name,
2896
+ status: sandbox.status,
2897
+ currentSnapshotId: sandbox.currentSnapshotId,
2898
+ createdAt: sandbox.createdAt.toISOString(),
2899
+ tags: { ...sandbox.tags }
2900
+ }
2901
+ }
2902
+ };
2903
+ } catch (error) {
2904
+ const failure = sandboxFailure(error, signal);
2905
+ if (failure.kind === "api" && apiStatus(error) === NOT_FOUND_STATUS)
2906
+ return { ok: true, value: { kind: "not-found" } };
2907
+ return { ok: false, failure };
2908
+ }
2909
+ },
2910
+ async listNamedSandboxes(access, request2, signal) {
2911
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2912
+ try {
2913
+ const { Sandbox } = await sdk();
2914
+ const paginator = await Sandbox.list({
2915
+ ...credentials(access),
2916
+ namePrefix: request2.namePrefix,
2917
+ sortBy: "name",
2918
+ limit: LIST_SANDBOXES_PAGE_LIMIT,
2919
+ ...signal === void 0 ? {} : { signal }
2920
+ });
2921
+ const listed = [];
2922
+ for await (const page of paginator.pages()) {
2923
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2924
+ for (const item of page.sandboxes) {
2925
+ listed.push({
2926
+ name: item.name,
2927
+ status: item.status,
2928
+ currentSnapshotId: item.currentSnapshotId,
2929
+ createdAt: new Date(item.createdAt).toISOString(),
2930
+ tags: { ...item.tags }
2931
+ });
2932
+ }
2933
+ }
2934
+ return { ok: true, value: listed };
2935
+ } catch (error) {
2936
+ return { ok: false, failure: sandboxFailure(error, signal) };
2937
+ }
2938
+ },
2939
+ async getSnapshot(access, request2, signal) {
2940
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2941
+ try {
2942
+ const { Snapshot } = await sdk();
2943
+ const snapshot = await Snapshot.get({
2944
+ ...credentials(access),
2945
+ snapshotId: request2.snapshotId,
2946
+ ...signal === void 0 ? {} : { signal }
2947
+ });
2948
+ return {
2949
+ ok: true,
2950
+ value: {
2951
+ kind: "found",
2952
+ snapshot: {
2953
+ snapshotId: snapshot.snapshotId,
2954
+ status: snapshot.status,
2955
+ createdAt: snapshot.createdAt.toISOString(),
2956
+ expiresAt: snapshot.expiresAt?.toISOString(),
2957
+ sizeBytes: snapshot.sizeBytes
2958
+ }
2959
+ }
2960
+ };
2961
+ } catch (error) {
2962
+ const failure = sandboxFailure(error, signal);
2963
+ const status = apiStatus(error);
2964
+ if (failure.kind === "api" && (status === NOT_FOUND_STATUS || status === SNAPSHOT_GONE_STATUS))
2965
+ return { ok: true, value: { kind: "not-found" } };
2966
+ return { ok: false, failure };
2967
+ }
2968
+ },
2969
+ async deleteNamedSandbox(access, request2, signal) {
2970
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2971
+ try {
2972
+ const { Sandbox } = await sdk();
2973
+ const sandbox = await Sandbox.get({
2974
+ ...credentials(access),
2975
+ name: request2.name,
2976
+ ...signal === void 0 ? {} : { signal }
2977
+ });
2978
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2979
+ await sandbox.delete({ deleteOrphanSnapshots: false, ...signal === void 0 ? {} : { signal } });
2980
+ return { ok: true };
2981
+ } catch (error) {
2982
+ const failure = sandboxFailure(error, signal);
2983
+ if (failure.kind === "api" && apiStatus(error) === NOT_FOUND_STATUS) return { ok: true };
2984
+ return { ok: false, failure };
2985
+ }
2986
+ },
2314
2987
  async upload(sandbox, files, signal) {
2315
2988
  const holder = holding(sandbox);
2316
2989
  try {
@@ -2450,7 +3123,7 @@ function liveRunnerSandboxGateway() {
2450
3123
  command.kill("SIGTERM").catch(() => {
2451
3124
  });
2452
3125
  };
2453
- if (isAborted(signal)) end();
3126
+ if (isAborted2(signal)) end();
2454
3127
  else signal?.addEventListener("abort", end, { once: true });
2455
3128
  let stderr = "";
2456
3129
  try {
@@ -2524,7 +3197,7 @@ function liveRunnerSandboxGateway() {
2524
3197
  holder.keeping = true;
2525
3198
  if (!await settledUnlessAborted(holder.starting, signal)) return { ok: false, failure: { kind: "aborted" } };
2526
3199
  const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command, signal)))).filter((ended) => !ended).length;
2527
- if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
3200
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2528
3201
  if (stillRunning > 0)
2529
3202
  return {
2530
3203
  ok: false,
@@ -2546,7 +3219,7 @@ function liveRunnerSandboxGateway() {
2546
3219
  },
2547
3220
  async stop(sandbox, signal) {
2548
3221
  const holder = holding(sandbox);
2549
- if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
3222
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2550
3223
  try {
2551
3224
  if (signal === void 0) await holder.sandbox.stop();
2552
3225
  else await holder.sandbox.stop({ signal });
@@ -2557,7 +3230,7 @@ function liveRunnerSandboxGateway() {
2557
3230
  },
2558
3231
  async delete(sandbox, signal) {
2559
3232
  const holder = holding(sandbox);
2560
- if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
3233
+ if (isAborted2(signal)) return { ok: false, failure: { kind: "aborted" } };
2561
3234
  try {
2562
3235
  await holder.sandbox.delete({ deleteOrphanSnapshots: false, ...signal === void 0 ? {} : { signal } });
2563
3236
  return { ok: true };
@@ -2668,7 +3341,7 @@ async function endProcess(holder, command, signal) {
2668
3341
  ["SIGTERM", TERMINATE_GRACE_MS],
2669
3342
  ["SIGKILL", KILL_GRACE_MS]
2670
3343
  ]) {
2671
- if (isAborted(signal)) return false;
3344
+ if (isAborted2(signal)) return false;
2672
3345
  await withinLimit(graceMs, signal, (limit) => command.kill(kill, { abortSignal: limit })).catch(() => void 0);
2673
3346
  if (await endsWithin(command, graceMs, signal)) {
2674
3347
  holder.running.delete(command);
@@ -2686,7 +3359,7 @@ async function endsWithin(command, ms, signal) {
2686
3359
  }
2687
3360
  }
2688
3361
  async function withinLimit(ms, signal, call) {
2689
- if (isAborted(signal)) throw new DOMException("This operation was aborted", "AbortError");
3362
+ if (isAborted2(signal)) throw new DOMException("This operation was aborted", "AbortError");
2690
3363
  const limit = new AbortController();
2691
3364
  const timer = setTimeout(() => limit.abort(), ms);
2692
3365
  const onAbort = () => limit.abort();
@@ -2704,14 +3377,14 @@ async function withinLimit(ms, signal, call) {
2704
3377
  }
2705
3378
  }
2706
3379
  async function settledUnlessAborted(tasks, signal) {
2707
- if (isAborted(signal)) return false;
3380
+ if (isAborted2(signal)) return false;
2708
3381
  if (signal === void 0 || tasks.size === 0) {
2709
3382
  await Promise.allSettled(tasks);
2710
3383
  return true;
2711
3384
  }
2712
3385
  return await untilAborted(Promise.allSettled(tasks), signal) !== ABORTED;
2713
3386
  }
2714
- function isAborted(signal) {
3387
+ function isAborted2(signal) {
2715
3388
  return signal?.aborted === true;
2716
3389
  }
2717
3390
 
@@ -2758,22 +3431,22 @@ function liveRunnerTerminal(options) {
2758
3431
  };
2759
3432
  }
2760
3433
 
2761
- // src/runner/live/snapshot-cache-gateway.ts
3434
+ // src/runner/live/snapshot-index-gateway.ts
2762
3435
  import { randomBytes } from "node:crypto";
2763
3436
  import { mkdir, readdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
2764
3437
  import { join } from "node:path";
2765
3438
 
2766
3439
  // src/runner/live/snapshot-records.ts
2767
- import { z as z4 } from "zod";
2768
- var isoTime = z4.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
2769
- var nonEmpty = z4.string().min(1);
2770
- var entrySchema = z4.object({
2771
- version: z4.literal(1),
3440
+ import { z as z3 } from "zod";
3441
+ var isoTime = z3.string().refine((value) => !Number.isNaN(Date.parse(value)), { message: "not a time" });
3442
+ var nonEmpty = z3.string().min(1);
3443
+ var entrySchema = z3.object({
3444
+ version: z3.literal(1),
2772
3445
  teamId: nonEmpty,
2773
3446
  projectId: nonEmpty,
2774
3447
  region: nonEmpty,
2775
3448
  runtime: nonEmpty,
2776
- recipeName: nonEmpty,
3449
+ runnerName: nonEmpty,
2777
3450
  snapshotKey: nonEmpty,
2778
3451
  base: nonEmpty,
2779
3452
  snapshotId: nonEmpty,
@@ -2799,7 +3472,7 @@ function parseSnapshotEntry(text) {
2799
3472
  return { ok: true, value: entry };
2800
3473
  }
2801
3474
  function snapshotEntryText(entry) {
2802
- const { teamId, projectId, region, runtime, recipeName, snapshotKey: snapshotKey2, base } = entry;
3475
+ const { teamId, projectId, region, runtime, runnerName, snapshotKey: snapshotKey2, base } = entry;
2803
3476
  const { snapshotId, createdAt, expiresAt } = entry;
2804
3477
  const record = {
2805
3478
  version: 1,
@@ -2807,7 +3480,7 @@ function snapshotEntryText(entry) {
2807
3480
  projectId,
2808
3481
  region,
2809
3482
  runtime,
2810
- recipeName,
3483
+ runnerName,
2811
3484
  snapshotKey: snapshotKey2,
2812
3485
  base,
2813
3486
  snapshotId,
@@ -2818,11 +3491,11 @@ function snapshotEntryText(entry) {
2818
3491
  `;
2819
3492
  }
2820
3493
 
2821
- // src/runner/live/snapshot-cache-gateway.ts
3494
+ // src/runner/live/snapshot-index-gateway.ts
2822
3495
  var DIRECTORY_MODE = 448;
2823
3496
  var FILE_MODE = 384;
2824
3497
  var ENTRY_FILE_NAME = /^[0-9a-f]{32}\.json$/;
2825
- function liveRunnerSnapshotCacheGateway(options) {
3498
+ function liveRunnerSnapshotIndexGateway(options) {
2826
3499
  const { directory } = options;
2827
3500
  return {
2828
3501
  listEntries: () => listEntries(directory),
@@ -2830,7 +3503,7 @@ function liveRunnerSnapshotCacheGateway(options) {
2830
3503
  removeEntry: (entry) => removeEntry(directory, entry)
2831
3504
  };
2832
3505
  }
2833
- function unavailableRunnerSnapshotCacheGateway(location, reason) {
3506
+ function unavailableRunnerSnapshotIndexGateway(location, reason) {
2834
3507
  const failure = { path: location, message: reason };
2835
3508
  const fail = async () => ({ ok: false, failure });
2836
3509
  return { listEntries: fail, writeEntry: fail, removeEntry: fail };
@@ -2903,37 +3576,45 @@ function failureAt(path, error) {
2903
3576
  // src/runner/prepare.ts
2904
3577
  async function prepareRunner(context, request2) {
2905
3578
  const { checkout } = context;
2906
- const { recipe } = request2;
3579
+ const { options } = request2;
2907
3580
  const root = await checkout.repositoryRoot({ cwd: request2.cwd });
2908
3581
  if (!root.ok) return { kind: "checkout-failed", failure: root.failure };
2909
3582
  const repoRoot = root.value;
2910
- const resolved = await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
3583
+ const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
2911
3584
  if (resolved.kind === "failed") return { kind: "checkout-failed", failure: resolved.failure };
2912
3585
  if (resolved.kind === "no-base-ref") return resolved;
2913
3586
  const { base } = resolved;
2914
3587
  const submodules2 = await checkout.submodules({ repoRoot });
2915
3588
  if (!submodules2.ok) return { kind: "checkout-failed", failure: submodules2.failure };
2916
3589
  if (submodules2.value.length > 0) return { kind: "submodules", paths: [...submodules2.value] };
2917
- const inputs = await snapshotInputsAt(checkout, { repoRoot, base, recipe });
2918
- if (!inputs.ok) return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
2919
- const vcpus = resolveVcpus(recipe, request2.vcpuRun);
2920
- if (!vcpus.ok) return { kind: "invalid-recipe", path: ["vcpus"], problem: vcpus.problem };
3590
+ const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
3591
+ if (!inputs.ok) return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
3592
+ const vcpus = resolveVcpus(options, request2.vcpuRun);
3593
+ if (!vcpus.ok) return { kind: "invalid-runner", path: ["vcpus"], problem: vcpus.problem };
2921
3594
  const upload = await checkout.assembleUpload({ repoRoot, base });
2922
3595
  if (!upload.ok) return { kind: "checkout-failed", failure: upload.failure };
2923
3596
  const afterBase = await checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
2924
3597
  if (!afterBase.ok) return { kind: "checkout-failed", failure: afterBase.failure };
2925
3598
  const listing = await removeExpiredEntries(context);
3599
+ const ancestorDistances = await resolveAncestorDistances(context, {
3600
+ repoRoot,
3601
+ entries: listing.entries,
3602
+ options,
3603
+ mergeBase: base
3604
+ });
3605
+ if (!ancestorDistances.ok) return { kind: "checkout-failed", failure: ancestorDistances.failure };
2926
3606
  const cache = classifySnapshotEntries(context, {
2927
3607
  entries: listing.entries,
2928
- recipe,
3608
+ options,
2929
3609
  base,
2930
3610
  snapshotKey: inputs.key,
2931
- commitsAfterBase: afterBase.value
3611
+ commitsAfterBase: afterBase.value,
3612
+ ancestorDistances: ancestorDistances.value
2932
3613
  });
2933
3614
  return {
2934
3615
  kind: "ok",
2935
3616
  prepared: {
2936
- recipe,
3617
+ options,
2937
3618
  repoRoot,
2938
3619
  base,
2939
3620
  baseRef: resolved.ref,
@@ -2951,6 +3632,133 @@ async function prepareRunner(context, request2) {
2951
3632
 
2952
3633
  // src/runner/ready.ts
2953
3634
  import { posix } from "node:path";
3635
+
3636
+ // src/runner/shared-snapshot-lookup.ts
3637
+ async function lookupSharedSnapshot(context, request2, signal) {
3638
+ const { runnerSandboxes, checkout, clock } = context;
3639
+ const { access, repoRoot, runner, snapshotKey: snapshotKey2, mergeBase, maxCommitsBehindMergeBase } = request2;
3640
+ if (!sharedBeatsLocal(0, maxCommitsBehindMergeBase)) return { kind: "miss" };
3641
+ const bucket = sharedSnapshotBucket({
3642
+ teamId: access.teamId,
3643
+ projectId: access.projectId,
3644
+ region: runner.region,
3645
+ runtime: runner.runtime,
3646
+ runnerName: runner.name,
3647
+ snapshotKey: snapshotKey2
3648
+ });
3649
+ const exactName = sharedSnapshotSandboxName(bucket, mergeBase);
3650
+ const exact = await runnerSandboxes.getNamedSandbox(access, { name: exactName }, signal);
3651
+ if (!exact.ok) {
3652
+ return unavailable(exact.failure);
3653
+ }
3654
+ if (exact.value.kind === "found") {
3655
+ const { sandbox } = exact.value;
3656
+ const unverified = classifyUnverifiedSharedSandbox(sandbox);
3657
+ if (unverified.kind === "needs-snapshot") {
3658
+ const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
3659
+ if (!verified.ok) {
3660
+ return unavailable(verified.failure);
3661
+ }
3662
+ if (verified.value.kind === "found") {
3663
+ const entry = usableSharedEntry(
3664
+ access,
3665
+ runner,
3666
+ snapshotKey2,
3667
+ mergeBase,
3668
+ sandbox,
3669
+ verified.value.snapshot,
3670
+ clock.now()
3671
+ );
3672
+ if (entry !== null) {
3673
+ return { kind: "hit", entry, commitsBehindMergeBase: 0, sandboxName: sandbox.name };
3674
+ }
3675
+ }
3676
+ }
3677
+ }
3678
+ if (!sharedBeatsLocal(1, maxCommitsBehindMergeBase)) return { kind: "miss" };
3679
+ const listed = await runnerSandboxes.listNamedSandboxes(
3680
+ access,
3681
+ { namePrefix: sharedSnapshotSandboxPrefix(bucket) },
3682
+ signal
3683
+ );
3684
+ if (!listed.ok) {
3685
+ return unavailable(listed.failure);
3686
+ }
3687
+ const stoppedRows = [];
3688
+ for (const row of listed.value) {
3689
+ const unverified = classifyUnverifiedSharedSandbox(row);
3690
+ if (unverified.kind !== "needs-snapshot") continue;
3691
+ const parsed = parseSharedSnapshotSandboxName(row.name);
3692
+ if (parsed === null || parsed.bucket !== bucket || parsed.base === mergeBase) continue;
3693
+ stoppedRows.push({ row, base: parsed.base, snapshotId: unverified.snapshotId });
3694
+ }
3695
+ const checked = await runLimited(
3696
+ stoppedRows.length,
3697
+ INDEX_CONCURRENCY,
3698
+ () => signal?.aborted !== true,
3699
+ async (index) => {
3700
+ const item = stoppedRows[index];
3701
+ const ancestor = await checkout.contains({ repoRoot, ancestor: item.base, descendant: mergeBase });
3702
+ if (!ancestor.ok || !ancestor.value) return null;
3703
+ if (signal?.aborted === true) return null;
3704
+ const counted = await checkout.commitCount({ repoRoot, from: item.base, to: mergeBase });
3705
+ if (!counted.ok) return null;
3706
+ if (!sharedBeatsLocal(counted.value, maxCommitsBehindMergeBase)) return null;
3707
+ return {
3708
+ row: item.row,
3709
+ base: item.base,
3710
+ snapshotId: item.snapshotId,
3711
+ commitsBehindMergeBase: counted.value
3712
+ };
3713
+ }
3714
+ );
3715
+ if (signal?.aborted === true) return { kind: "aborted" };
3716
+ const candidates = checked.filter((candidate) => candidate != null);
3717
+ candidates.sort(
3718
+ (a, b) => compareSnapshotCandidates(
3719
+ {
3720
+ commitsBehindMergeBase: a.commitsBehindMergeBase,
3721
+ createdAt: a.row.createdAt,
3722
+ tieBreaker: a.row.name
3723
+ },
3724
+ {
3725
+ commitsBehindMergeBase: b.commitsBehindMergeBase,
3726
+ createdAt: b.row.createdAt,
3727
+ tieBreaker: b.row.name
3728
+ }
3729
+ )
3730
+ );
3731
+ for (const candidate of candidates) {
3732
+ const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: candidate.snapshotId }, signal);
3733
+ if (!verified.ok) {
3734
+ return unavailable(verified.failure);
3735
+ }
3736
+ if (verified.value.kind !== "found") continue;
3737
+ const entry = usableSharedEntry(
3738
+ access,
3739
+ runner,
3740
+ snapshotKey2,
3741
+ candidate.base,
3742
+ candidate.row,
3743
+ verified.value.snapshot,
3744
+ clock.now()
3745
+ );
3746
+ if (entry !== null) {
3747
+ return {
3748
+ kind: "hit",
3749
+ entry,
3750
+ commitsBehindMergeBase: candidate.commitsBehindMergeBase,
3751
+ sandboxName: candidate.row.name
3752
+ };
3753
+ }
3754
+ }
3755
+ return { kind: "miss" };
3756
+ }
3757
+ function unavailable(failure) {
3758
+ return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "unavailable", message: failure.message };
3759
+ }
3760
+
3761
+ // src/runner/ready.ts
2954
3762
  var APPLY_LABEL = "Applying your changes";
2955
3763
  async function readyRunner(context, request2, control, progress) {
2956
3764
  const chosen = await chooseSnapshot(context, request2, control, progress);
@@ -2959,17 +3767,62 @@ async function readyRunner(context, request2, control, progress) {
2959
3767
  }
2960
3768
  async function chooseSnapshot(context, request2, control, progress) {
2961
3769
  const { prepared, access } = request2;
2962
- if (control.signal.aborted) return { kind: "aborted" };
2963
- const pick = pickSnapshot(prepared.candidates, access);
2964
- if (pick !== void 0) {
2965
- const { entry } = pick;
3770
+ const { signal } = control;
3771
+ if (signal.aborted) return { kind: "aborted" };
3772
+ const localCandidate = pickSnapshot(prepared.candidates, access);
3773
+ if (localCandidate !== void 0 && localCandidate.commitsBehindMergeBase === 0) {
3774
+ const { entry, builtBehind } = localCandidate;
3775
+ await progress.emit({
3776
+ kind: "snapshot-reused",
3777
+ snapshotId: entry.snapshotId,
3778
+ base: entry.base,
3779
+ builtBehind,
3780
+ source: "local"
3781
+ });
3782
+ return { kind: "ok", value: { entry, built: false, builtBehind, upload: prepared.upload } };
3783
+ }
3784
+ const shared = await lookupSharedSnapshot(
3785
+ context,
3786
+ {
3787
+ access,
3788
+ repoRoot: prepared.repoRoot,
3789
+ runner: prepared.options,
3790
+ snapshotKey: prepared.snapshotKey,
3791
+ mergeBase: prepared.base,
3792
+ ...localCandidate === void 0 ? {} : { maxCommitsBehindMergeBase: localCandidate.commitsBehindMergeBase }
3793
+ },
3794
+ signal
3795
+ );
3796
+ if (shared.kind === "aborted") return { kind: "aborted" };
3797
+ if (shared.kind === "unavailable") {
3798
+ await progress.emit({ kind: "shared-snapshot-lookup-failed", message: shared.message });
3799
+ }
3800
+ const sharedHit = shared.kind === "hit" ? shared : void 0;
3801
+ const useShared = sharedHit !== void 0 && sharedBeatsLocal(sharedHit.commitsBehindMergeBase, localCandidate?.commitsBehindMergeBase);
3802
+ const winner = useShared ? { source: "shared", hit: sharedHit } : localCandidate !== void 0 ? { source: "local", candidate: localCandidate } : void 0;
3803
+ if (winner !== void 0) {
3804
+ let entry;
3805
+ let builtBehind;
3806
+ if (winner.source === "shared") {
3807
+ entry = winner.hit.entry;
3808
+ const written = await context.runnerSnapshots.writeEntry(entry);
3809
+ if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
3810
+ builtBehind = prepared.commitsAfterBase + winner.hit.commitsBehindMergeBase;
3811
+ } else {
3812
+ entry = winner.candidate.entry;
3813
+ builtBehind = winner.candidate.builtBehind;
3814
+ }
3815
+ const upload = await uploadForBase(context, prepared, entry.base);
3816
+ if (!upload.ok) return { kind: "failed", failure: { kind: "checkout-failed", failure: upload.failure } };
3817
+ if (signal.aborted) return { kind: "aborted" };
2966
3818
  await progress.emit({
2967
3819
  kind: "snapshot-reused",
2968
3820
  snapshotId: entry.snapshotId,
2969
3821
  base: entry.base,
2970
- builtBehind: pick.builtBehind
3822
+ builtBehind,
3823
+ source: winner.source
2971
3824
  });
2972
- return { kind: "ok", value: { entry, built: false } };
3825
+ return { kind: "ok", value: { entry, built: false, builtBehind, upload: upload.value } };
2973
3826
  }
2974
3827
  const why = { kind: "no-snapshot", rejected: snapshotRejections(prepared, access) };
2975
3828
  const building = await buildSnapshot(
@@ -2979,12 +3832,24 @@ async function chooseSnapshot(context, request2, control, progress) {
2979
3832
  progress
2980
3833
  );
2981
3834
  if (building.kind !== "ok") return building;
2982
- return { kind: "ok", value: { entry: building.value.entry, built: true } };
3835
+ return {
3836
+ kind: "ok",
3837
+ value: {
3838
+ entry: building.value.entry,
3839
+ built: true,
3840
+ builtBehind: prepared.commitsAfterBase,
3841
+ upload: prepared.upload
3842
+ }
3843
+ };
3844
+ }
3845
+ async function uploadForBase(context, prepared, base) {
3846
+ if (base === prepared.base) return { ok: true, value: prepared.upload };
3847
+ return await context.checkout.assembleUpload({ repoRoot: prepared.repoRoot, base });
2983
3848
  }
2984
3849
  async function readyFromSnapshot(context, request2, control, progress) {
2985
3850
  const { prepared, access } = request2;
2986
- const { entry, built } = request2.snapshot;
2987
- const { recipe, repoRoot } = prepared;
3851
+ const { entry, built, builtBehind, upload } = request2.snapshot;
3852
+ const { options, repoRoot } = prepared;
2988
3853
  const { scope, signal } = control;
2989
3854
  const now = () => context.clock.now().getTime();
2990
3855
  if (signal.aborted) return { kind: "aborted" };
@@ -2992,10 +3857,10 @@ async function readyFromSnapshot(context, request2, control, progress) {
2992
3857
  const startedAt = now();
2993
3858
  const started = await scope.startRunnerSandbox(access, {
2994
3859
  snapshotId: entry.snapshotId,
2995
- region: recipe.region,
3860
+ region: options.region,
2996
3861
  vcpus: prepared.vcpus,
2997
- timeoutMs: recipe.timeoutMinutes * 6e4,
2998
- tags: runnerTags(recipe.name, "runner", request2.user)
3862
+ timeoutMs: options.timeoutMinutes * 6e4,
3863
+ tags: runnerTags(options.name, "runner", request2.user)
2999
3864
  });
3000
3865
  if (!started.ok) {
3001
3866
  if (started.failure.kind === "snapshot-gone") {
@@ -3009,11 +3874,11 @@ async function readyFromSnapshot(context, request2, control, progress) {
3009
3874
  kind: "sandbox-started",
3010
3875
  role: "runner",
3011
3876
  name: sandbox.name,
3012
- region: recipe.region,
3877
+ region: options.region,
3013
3878
  vcpus: prepared.vcpus,
3014
3879
  ms: now() - startedAt
3015
3880
  });
3016
- const changes = await uploadChanges(context, { prepared, sandbox }, signal, progress);
3881
+ const changes = await uploadChanges(context, { upload, sandbox }, signal, progress);
3017
3882
  if (changes.kind !== "ok") return changes;
3018
3883
  const applied = await stage(
3019
3884
  context,
@@ -3021,7 +3886,7 @@ async function readyFromSnapshot(context, request2, control, progress) {
3021
3886
  sandbox,
3022
3887
  phase: "apply",
3023
3888
  step: { label: APPLY_LABEL, script: applyScript(changes.value.directory) },
3024
- region: recipe.region
3889
+ region: options.region
3025
3890
  },
3026
3891
  signal,
3027
3892
  progress
@@ -3035,14 +3900,14 @@ async function readyFromSnapshot(context, request2, control, progress) {
3035
3900
  }
3036
3901
  const installed = await stage(
3037
3902
  context,
3038
- { sandbox, phase: "install", step: recipe.run.install, region: recipe.region },
3903
+ { sandbox, phase: "install", step: options.run.install, region: options.region },
3039
3904
  signal,
3040
3905
  progress
3041
3906
  );
3042
3907
  if (installed.kind !== "ok") return installed;
3043
3908
  const builtOutputs = await stage(
3044
3909
  context,
3045
- { sandbox, phase: "build", step: recipe.run.build, region: recipe.region },
3910
+ { sandbox, phase: "build", step: options.run.build, region: options.region },
3046
3911
  signal,
3047
3912
  progress
3048
3913
  );
@@ -3054,15 +3919,15 @@ async function readyFromSnapshot(context, request2, control, progress) {
3054
3919
  snapshotId: entry.snapshotId,
3055
3920
  base: entry.base,
3056
3921
  built,
3057
- builtBehind: prepared.commitsAfterBase,
3922
+ builtBehind,
3058
3923
  uploadBytes: changes.value.bytes,
3059
3924
  buildMs: builtOutputs.value,
3060
3925
  vcpus: prepared.vcpus,
3061
- region: recipe.region,
3062
- runtime: recipe.runtime,
3926
+ region: options.region,
3927
+ runtime: options.runtime,
3063
3928
  repoRoot,
3064
- cwd: posix.join(SANDBOX_ROOT, recipe.cwd),
3065
- env: recipe.env,
3929
+ cwd: posix.join(SANDBOX_ROOT, options.cwd),
3930
+ env: options.env,
3066
3931
  loginPath: loginPath.value
3067
3932
  }
3068
3933
  };
@@ -3070,7 +3935,7 @@ async function readyFromSnapshot(context, request2, control, progress) {
3070
3935
  async function uploadChanges(context, request2, signal, progress) {
3071
3936
  await progress.emit({ kind: "uploading" });
3072
3937
  const startedAt = context.clock.now().getTime();
3073
- const files = stagedChanges(request2.prepared.upload);
3938
+ const files = stagedChanges(request2.upload);
3074
3939
  const staged = await context.runnerSandboxes.upload(request2.sandbox, files, signal);
3075
3940
  if (!staged.ok) return sandboxStop("upload", staged.failure);
3076
3941
  const bytes = files.reduce((sum, file) => sum + file.content.byteLength, 0);
@@ -3114,7 +3979,7 @@ async function chooseSnapshotForRun(context, request2, control, progress) {
3114
3979
  const stageSignal = stop === void 0 ? signal : AbortSignal.any([signal, stop]);
3115
3980
  const scope = runnerSandboxScope(context, progress, {
3116
3981
  keepMs: 0,
3117
- basePolicy: runnerNetworkPolicy(request2.prepared.recipe),
3982
+ basePolicy: runnerNetworkPolicy(request2.prepared.options),
3118
3983
  signal
3119
3984
  });
3120
3985
  try {
@@ -3260,7 +4125,7 @@ function openRunnerSession(context, request2, control, progress) {
3260
4125
  let commandRunning = false;
3261
4126
  const scope = runnerSandboxScope(context, progress, {
3262
4127
  keepMs: request2.keepMs,
3263
- basePolicy: runnerNetworkPolicy(request2.prepared.recipe),
4128
+ basePolicy: runnerNetworkPolicy(request2.prepared.options),
3264
4129
  signal,
3265
4130
  commandRunning: () => commandRunning
3266
4131
  });
@@ -3366,11 +4231,11 @@ function checkRunner(value, inherited, definitions = []) {
3366
4231
  ...inherited,
3367
4232
  ...Object.fromEntries(Object.entries(options).filter(([, entry]) => entry !== void 0))
3368
4233
  };
3369
- const checked = checkRecipe(rawOptions);
4234
+ const checked = checkVercelSandboxOptions(rawOptions);
3370
4235
  if (!checked.ok) return checked;
3371
4236
  const vcpusProblems = checkVcpusRuleDefinitions(checked.value.vcpus, definitions);
3372
4237
  if (vcpusProblems.length > 0) return { ok: false, problems: vcpusProblems };
3373
- return { ok: true, value: { kind: "vercel-sandbox", recipe: checked.value } };
4238
+ return { ok: true, value: { kind: "vercel-sandbox", options: checked.value } };
3374
4239
  }
3375
4240
  return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not ${describeValue(value)}` }] };
3376
4241
  }
@@ -3797,14 +4662,14 @@ function fileProblem(problem) {
3797
4662
  }
3798
4663
 
3799
4664
  // src/config/errors.ts
3800
- import { z as z5 } from "zod";
3801
- var problemSchema = z5.object({
4665
+ import { z as z4 } from "zod";
4666
+ var problemSchema = z4.object({
3802
4667
  /** The key the problem is about; null when it is about the whole file. */
3803
- key: z5.string().nullable(),
4668
+ key: z4.string().nullable(),
3804
4669
  /** Where Node said the import failed; null otherwise. */
3805
- location: z5.object({ line: z5.number(), column: z5.number().nullable() }).nullable(),
4670
+ location: z4.object({ line: z4.number(), column: z4.number().nullable() }).nullable(),
3806
4671
  /** What is wrong, worded to follow the key, or the file name when there is no key. */
3807
- problem: z5.string()
4672
+ problem: z4.string()
3808
4673
  });
3809
4674
  function configProblemLine(file, { key, location, problem }) {
3810
4675
  const sentence = `${problem.replace(/\.$/, "")}.`;
@@ -3813,21 +4678,21 @@ function configProblemLine(file, { key, location, problem }) {
3813
4678
  return `${file}:${location.line}${location.column === null ? "" : `:${location.column}`} ${sentence}`;
3814
4679
  return `${file}: ${sentence}`;
3815
4680
  }
3816
- var optionValueSchema = z5.object({
4681
+ var optionValueSchema = z4.object({
3817
4682
  /** The option's key path, such as resources.<key>.ttl. */
3818
- key: z5.string(),
4683
+ key: z4.string(),
3819
4684
  /** Its value, as text. */
3820
- value: z5.string(),
4685
+ value: z4.string(),
3821
4686
  /** Where it came from: the command's own flag for the option, the config file or the default. */
3822
- source: z5.enum(["flag", "file", "default"])
4687
+ source: z4.enum(["flag", "file", "default"])
3823
4688
  });
3824
- var optionProblemSchema = z5.object({
4689
+ var optionProblemSchema = z4.object({
3825
4690
  /** The key path of the option the problem is about, such as resources.<key>.ttl. */
3826
- key: z5.string(),
4691
+ key: z4.string(),
3827
4692
  /** What is wrong, worded to follow the key path, as the resource's rule words it. */
3828
- problem: z5.string(),
4693
+ problem: z4.string(),
3829
4694
  /** Each value the problem is about, with its source; empty for a required option nothing gave. */
3830
- values: z5.array(optionValueSchema)
4695
+ values: z4.array(optionValueSchema)
3831
4696
  });
3832
4697
  function optionValueText({ key, value, source }, configFile) {
3833
4698
  switch (source) {
@@ -3848,10 +4713,10 @@ var configErrors = defineErrors({
3848
4713
  invalidConfig: {
3849
4714
  exitCode: 2,
3850
4715
  description: "storm.config.ts can't be used: it can't be imported, doesn't default-export an object, has an unknown key, or a value in it is invalid. storm checks the whole file whenever a command loads it.",
3851
- schema: z5.object({
4716
+ schema: z4.object({
3852
4717
  /** The config file's absolute path. */
3853
- file: z5.string(),
3854
- problems: z5.array(problemSchema)
4718
+ file: z4.string(),
4719
+ problems: z4.array(problemSchema)
3855
4720
  }),
3856
4721
  render: ({ file, problems }) => {
3857
4722
  const [first, ...rest] = problems;
@@ -3865,10 +4730,10 @@ var configErrors = defineErrors({
3865
4730
  invalidResourceOptions: {
3866
4731
  exitCode: 2,
3867
4732
  description: "A resource's options, once its defaults, storm.config.ts and the flags are merged, don't fit together, as the resource's own checks say, or one it requires is missing: such as resources.<key>.ttl not longer than its minTimeLeft. Each problem names the values it is about and where each came from.",
3868
- schema: z5.object({
4733
+ schema: z4.object({
3869
4734
  /** The config file that applied; null when none did. */
3870
- configFile: z5.string().nullable(),
3871
- problems: z5.array(optionProblemSchema)
4735
+ configFile: z4.string().nullable(),
4736
+ problems: z4.array(optionProblemSchema)
3872
4737
  }),
3873
4738
  render: ({ configFile, problems }) => {
3874
4739
  const [first, ...rest] = problems;
@@ -4323,6 +5188,17 @@ function failedRun(error, stdout, stderr) {
4323
5188
  return { ok: false, reason: "exit", stdout: out, stderr: err };
4324
5189
  }
4325
5190
 
5191
+ // src/credential/live/vercel-oidc-token-gateway.ts
5192
+ function liveVercelOidcTokenGateway(options) {
5193
+ return {
5194
+ async read() {
5195
+ const token = Object.hasOwn(options.env, "VERCEL_OIDC_TOKEN") ? options.env["VERCEL_OIDC_TOKEN"] : void 0;
5196
+ if (token === void 0 || token === "") return { ok: false, failure: { kind: "missing-token" } };
5197
+ return { ok: true, credential: new Credential(token) };
5198
+ }
5199
+ };
5200
+ }
5201
+
4326
5202
  // src/credential/source.ts
4327
5203
  var REQUESTING_TOKEN_LINE = "Requesting a GitHub Actions OIDC token\u2026";
4328
5204
  function credentialSourceFor(choice, context, progress) {
@@ -4333,6 +5209,7 @@ function credentialSourceFor(choice, context, progress) {
4333
5209
  timer: context.timer,
4334
5210
  progress
4335
5211
  });
5212
+ if (choice.source === "vercel-oidc") return vercelOidcSource(context.vercelOidcTokens);
4336
5213
  const { target } = choice;
4337
5214
  return mintSource(target, async () => {
4338
5215
  await progress.emit({ kind: "minting", target });
@@ -4413,12 +5290,90 @@ function isRetryable(failure) {
4413
5290
  return false;
4414
5291
  }
4415
5292
  }
5293
+ function vercelOidcSource(gateway) {
5294
+ let outcome;
5295
+ return {
5296
+ obtain() {
5297
+ outcome ??= (async () => {
5298
+ const read = await gateway.read();
5299
+ if (!read.ok) return { ok: false, failure: { source: "vercel-oidc", failure: read.failure } };
5300
+ const project = read.credential.vercelProject();
5301
+ if (project === void 0)
5302
+ return { ok: false, failure: { source: "vercel-oidc", failure: { kind: "invalid-token" } } };
5303
+ return { ok: true, credential: read.credential, project };
5304
+ })();
5305
+ return outcome;
5306
+ },
5307
+ origin() {
5308
+ return { source: "vercel-oidc" };
5309
+ }
5310
+ };
5311
+ }
5312
+ function vercelProjectSource(choice, context, progress) {
5313
+ if (choice.source === "vercel-oidc") {
5314
+ const source2 = credentialSourceFor(choice, context, progress);
5315
+ return { source: source2, obtain: () => source2.obtain() };
5316
+ }
5317
+ const source = credentialSourceFor(choice, context, progress);
5318
+ return {
5319
+ source,
5320
+ obtain: async () => {
5321
+ const got = await source.obtain();
5322
+ if (!got.ok) return got;
5323
+ const project = got.credential.vercelProject();
5324
+ return project === void 0 ? { ok: false, failure: { source: "claims-missing", target: choice.target } } : { ok: true, credential: got.credential, project };
5325
+ }
5326
+ };
5327
+ }
4416
5328
 
4417
5329
  // src/credential/target.ts
4418
5330
  function mintTargetText(target) {
4419
5331
  return `Vercel project ${target.project} on team ${target.team}`;
4420
5332
  }
4421
5333
 
5334
+ // src/config/credential-settle.ts
5335
+ import { z as z5 } from "zod";
5336
+ var credentialErrors = defineErrors({
5337
+ missingTarget: {
5338
+ exitCode: 2,
5339
+ description: "The command may mint a credential, and neither a flag nor storm.config.ts names the control plane team or project.",
5340
+ schema: z5.object({
5341
+ /** The settings no flag or config file gave. */
5342
+ missing: z5.array(z5.enum(["scope", "project"]))
5343
+ }),
5344
+ render: ({ missing }) => ({
5345
+ message: `No control plane ${missing.map((key) => key === "scope" ? "team" : "project").join(" or ")} to mint a credential for.`,
5346
+ next: [
5347
+ {
5348
+ type: "text",
5349
+ text: `Give ${missing.map((key) => `--${key}`).join(" and ")}, or set ${missing.join(" and ")} in storm.config.ts.`
5350
+ }
5351
+ ]
5352
+ })
5353
+ }
5354
+ });
5355
+ function requireTarget(scope, project) {
5356
+ if (scope === void 0 || project === void 0)
5357
+ return refused(
5358
+ credentialErrors.missingTarget({
5359
+ missing: [
5360
+ ...scope === void 0 ? ["scope"] : [],
5361
+ ...project === void 0 ? ["project"] : []
5362
+ ]
5363
+ })
5364
+ );
5365
+ return { ok: true, target: { team: scope.value, project: project.value } };
5366
+ }
5367
+ function givenTarget(scope, project) {
5368
+ return scope === void 0 || project === void 0 ? null : { team: scope.value, project: project.value };
5369
+ }
5370
+ function settleCredential(source, scope, project) {
5371
+ if (source === "github-actions" || source === "vercel-oidc") return { ok: true, credential: { source } };
5372
+ const required = requireTarget(scope, project);
5373
+ if (!required.ok) return required;
5374
+ return { ok: true, credential: { source, target: required.target } };
5375
+ }
5376
+
4422
5377
  // src/config/credential-resolver.ts
4423
5378
  var credentialSourceErrors = defineErrors({
4424
5379
  mintFailed: {
@@ -4438,23 +5393,36 @@ var credentialSourceErrors = defineErrors({
4438
5393
  message: `Couldn't request a GitHub Actions OIDC token: ${detail}.`,
4439
5394
  next: [{ type: "text", text: fix }]
4440
5395
  })
5396
+ },
5397
+ vercelOidcTokenFailed: {
5398
+ exitCode: 1,
5399
+ description: "With --credential vercel-oidc, VERCEL_OIDC_TOKEN is missing, empty, or not a valid Vercel project OIDC token.",
5400
+ schema: z6.object(vercelOidcTokenFailureShape),
5401
+ render: ({ detail, fix }) => ({
5402
+ message: `Couldn't use VERCEL_OIDC_TOKEN: ${detail}.`,
5403
+ next: [{ type: "text", text: fix }]
5404
+ })
4441
5405
  }
4442
5406
  });
4443
5407
  function credentialSourceError(failure) {
4444
- return failure.source === "mint" ? credentialSourceErrors.mintFailed({ ...failure.target, ...describeMintFailure(failure.failure, failure.target) }) : credentialSourceErrors.tokenRequestFailed(tokenRequestFailureFacts(failure.failure));
5408
+ switch (failure.source) {
5409
+ case "mint":
5410
+ return credentialSourceErrors.mintFailed({
5411
+ ...failure.target,
5412
+ ...describeMintFailure(failure.failure, failure.target)
5413
+ });
5414
+ case "github-actions":
5415
+ return credentialSourceErrors.tokenRequestFailed(tokenRequestFailureFacts(failure.failure));
5416
+ case "vercel-oidc":
5417
+ return credentialSourceErrors.vercelOidcTokenFailed(vercelOidcTokenFailureFacts(failure.failure));
5418
+ }
4445
5419
  }
4446
5420
  function credentialResolver(gateways) {
4447
5421
  return {
4448
5422
  source(choice, target, report = {}) {
4449
5423
  const chosen = settleCredential(choice, target.scope, target.project);
4450
5424
  if (!chosen.ok) return chosen;
4451
- const { progress } = report;
4452
- const source = credentialSourceFor(chosen.credential, gateways, {
4453
- emit: async (event) => {
4454
- if (event.kind === "minting") await progress?.(`Minting a credential for ${mintTargetText(event.target)}\u2026`);
4455
- else if (event.kind === "requesting-token") await progress?.(REQUESTING_TOKEN_LINE);
4456
- }
4457
- });
5425
+ const source = credentialSourceFor(chosen.credential, gateways, commandLines(report));
4458
5426
  return {
4459
5427
  ok: true,
4460
5428
  source: {
@@ -4465,6 +5433,25 @@ function credentialResolver(gateways) {
4465
5433
  origin: (credential) => source.origin(credential)
4466
5434
  }
4467
5435
  };
5436
+ },
5437
+ vercelProjectSource(choice, target, report = {}) {
5438
+ let credential;
5439
+ if (choice === "vercel-oidc") credential = { source: choice };
5440
+ else {
5441
+ const required = requireTarget(target.scope, target.project);
5442
+ if (!required.ok) return required;
5443
+ credential = { source: choice, target: required.target };
5444
+ }
5445
+ const { obtain } = vercelProjectSource(credential, gateways, commandLines(report));
5446
+ return { ok: true, source: { obtain } };
5447
+ }
5448
+ };
5449
+ }
5450
+ function commandLines({ progress }) {
5451
+ return {
5452
+ emit: async (event) => {
5453
+ if (event.kind === "minting") await progress?.(`Minting a credential for ${mintTargetText(event.target)}\u2026`);
5454
+ else if (event.kind === "requesting-token") await progress?.(REQUESTING_TOKEN_LINE);
4468
5455
  }
4469
5456
  };
4470
5457
  }
@@ -4569,12 +5556,15 @@ function configResolver(launcher) {
4569
5556
  export {
4570
5557
  liveGitHubActionsTokenGateway,
4571
5558
  liveCredentialGateway,
5559
+ liveVercelOidcTokenGateway,
4572
5560
  credentialSourceFor,
5561
+ vercelProjectSource,
4573
5562
  mintTargetText,
4574
5563
  credentialErrors,
4575
- requireTarget,
5564
+ givenTarget,
4576
5565
  settleCredential,
4577
5566
  credentialSourceErrors,
5567
+ credentialSourceError,
4578
5568
  credentialResolver,
4579
5569
  configErrors,
4580
5570
  RUNNER_SNAPSHOTS_SUBPATH,
@@ -4594,8 +5584,8 @@ export {
4594
5584
  liveRunnerSandboxGateway,
4595
5585
  liveRunnerTerminal,
4596
5586
  localUserName,
4597
- liveRunnerSnapshotCacheGateway,
4598
- unavailableRunnerSnapshotCacheGateway,
5587
+ liveRunnerSnapshotIndexGateway,
5588
+ unavailableRunnerSnapshotIndexGateway,
4599
5589
  prepareRunner,
4600
5590
  chooseSnapshotForRun,
4601
5591
  SANDBOX_TEST_EVENTS_PATH,
@@ -4603,7 +5593,10 @@ export {
4603
5593
  readCredentials,
4604
5594
  readUnsafeSecretEnvVars,
4605
5595
  openRunnerSession,
4606
- inspectSnapshotCache,
5596
+ inspectLocalSnapshotIndex,
5597
+ listSharedSnapshots,
5598
+ pickSnapshotAcrossIndexes,
5599
+ pruneSharedSnapshots,
4607
5600
  CONFIG_FILE_NAME,
4608
5601
  CONFIG_FILE_NAMES_TEXT,
4609
5602
  liveConfigGateway,