@cnc-tools/storm 0.15.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 (305) 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-SZEURWRS.js → chunk-4O5C2XGJ.js} +18 -15
  10. package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-4WAMTUWZ.js} +419 -340
  11. package/dist/chunks/{chunk-QVS7HRU7.js → chunk-6UHIJXZG.js} +3 -3
  12. package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
  13. package/dist/chunks/{chunk-4U4DZ7VG.js → chunk-7DZE67QM.js} +2 -2
  14. package/dist/chunks/{chunk-VUPZH7J2.js → chunk-BCBKYOHW.js} +1 -1
  15. package/dist/chunks/{chunk-QUHY6FGN.js → chunk-CKGZA25H.js} +1 -18
  16. package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-D27KILIA.js} +1 -1
  17. package/dist/chunks/{chunk-KC4KDJ5K.js → chunk-DADEYJDW.js} +174 -153
  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-CXAT7ZKP.js → chunk-FNBB6V4R.js} +1 -1
  21. package/dist/chunks/{chunk-OX7X4B2L.js → chunk-GRT3UIBV.js} +18 -1
  22. package/dist/chunks/chunk-HP3CURSZ.js +88 -0
  23. package/dist/chunks/{chunk-PN5ULTTH.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-XEVHP5ZW.js → chunk-M7EKRGVD.js} +8 -8
  27. package/dist/chunks/chunk-MR77L2GK.js +340 -0
  28. package/dist/chunks/{chunk-L36GBUBB.js → chunk-RNAS7JHE.js} +1755 -522
  29. package/dist/chunks/{chunk-5GBMR4HM.js → chunk-RWIXDDCK.js} +4 -192
  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-YV7GE6EV.js → chunk-YEPFSLQR.js} +480 -375
  33. package/dist/chunks/{live-app-PI3BAN6Y.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 +4 -3
  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 +39 -4
  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 +38 -9
  51. package/dist/commands/exec/outcomes.js +32 -25
  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/planned-outcome.js +8 -1
  55. package/dist/commands/exec/progress.d.ts +10 -6
  56. package/dist/commands/exec/progress.js +38 -25
  57. package/dist/commands/exec/run-bin.d.ts +11 -11
  58. package/dist/commands/exec/run-bin.js +9 -9
  59. package/dist/commands/exec/run-flags.d.ts +69 -0
  60. package/dist/commands/exec/run-flags.js +58 -0
  61. package/dist/commands/exec/run-metadata.js +5 -5
  62. package/dist/commands/exec/run-summary.d.ts +58 -0
  63. package/dist/commands/exec/run-summary.js +205 -0
  64. package/dist/commands/exec/runner-refusals.d.ts +82 -0
  65. package/dist/commands/exec/runner-refusals.js +71 -0
  66. package/dist/commands/exec/sandbox-progress.js +3 -0
  67. package/dist/commands/exec/stopped-outcome.d.ts +12 -0
  68. package/dist/commands/exec/stopped-outcome.js +77 -0
  69. package/dist/commands/exec/view.d.ts +20 -11
  70. package/dist/commands/exec/view.js +103 -47
  71. package/dist/commands/runs/facts.d.ts +9 -4
  72. package/dist/commands/runs/facts.js +28 -11
  73. package/dist/commands/runs/list/command.d.ts +16 -6
  74. package/dist/commands/runs/list/command.js +10 -10
  75. package/dist/commands/runs/list/outcomes.d.ts +8 -3
  76. package/dist/commands/runs/logs/command.d.ts +6 -2
  77. package/dist/commands/runs/logs/command.js +10 -10
  78. package/dist/commands/runs/logs/outcomes.d.ts +3 -1
  79. package/dist/commands/runs/past-run.d.ts +14 -5
  80. package/dist/commands/runs/past-run.js +16 -5
  81. package/dist/commands/runs/show/command.d.ts +20 -8
  82. package/dist/commands/runs/show/command.js +30 -28
  83. package/dist/commands/runs/show/outcomes.d.ts +10 -4
  84. package/dist/commands/runs/show/outcomes.js +7 -5
  85. package/dist/commands/snapshots/access.d.ts +111 -0
  86. package/dist/commands/snapshots/access.js +96 -0
  87. package/dist/commands/snapshots/build/command.d.ts +360 -93
  88. package/dist/commands/snapshots/build/command.js +446 -150
  89. package/dist/commands/snapshots/build/metadata.d.ts +10 -0
  90. package/dist/commands/snapshots/build/metadata.js +31 -11
  91. package/dist/commands/snapshots/build/outcomes.d.ts +234 -43
  92. package/dist/commands/snapshots/build/outcomes.js +200 -36
  93. package/dist/commands/snapshots/list/command.d.ts +368 -27
  94. package/dist/commands/snapshots/list/command.js +296 -66
  95. package/dist/commands/snapshots/list/metadata.d.ts +16 -0
  96. package/dist/commands/snapshots/list/metadata.js +29 -6
  97. package/dist/commands/snapshots/list/outcomes.d.ts +245 -13
  98. package/dist/commands/snapshots/list/outcomes.js +221 -50
  99. package/dist/commands/snapshots/metadata.js +1 -1
  100. package/dist/commands/snapshots/prune/command.d.ts +430 -0
  101. package/dist/commands/snapshots/prune/command.js +161 -0
  102. package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
  103. package/dist/commands/snapshots/prune/metadata.js +39 -0
  104. package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
  105. package/dist/commands/snapshots/prune/outcomes.js +78 -0
  106. package/dist/commands/suites/list/command.js +19 -18
  107. package/dist/commands/suites/list/outcomes.js +4 -4
  108. package/dist/commands/test/command.d.ts +39 -4
  109. package/dist/commands/test/command.js +50 -255
  110. package/dist/commands/test/metadata.js +1 -1
  111. package/dist/commands/test/outcomes.d.ts +19 -2
  112. package/dist/commands/test/outcomes.js +2 -2
  113. package/dist/config/check-runner.d.ts +5 -3
  114. package/dist/config/check-runner.js +33 -7
  115. package/dist/config/check-suites.js +1 -0
  116. package/dist/config/credential-resolver.d.ts +50 -5
  117. package/dist/config/credential-resolver.js +51 -19
  118. package/dist/config/credential-settle.d.ts +6 -2
  119. package/dist/config/credential-settle.js +11 -5
  120. package/dist/config/gateways.d.ts +7 -3
  121. package/dist/config/index.d.ts +4 -5
  122. package/dist/config/index.js +3 -4
  123. package/dist/config/live/config-gateway.js +5 -2
  124. package/dist/config/load.d.ts +21 -4
  125. package/dist/config/load.js +129 -15
  126. package/dist/config/runner.d.ts +7 -8
  127. package/dist/config/runner.js +1 -1
  128. package/dist/config/schema.d.ts +17 -5
  129. package/dist/config/schema.js +11 -3
  130. package/dist/config/typed-options.d.ts +1 -6
  131. package/dist/config/typed-options.js +2 -10
  132. package/dist/config-file/define.d.ts +1 -11
  133. package/dist/config-file/define.js +3 -3
  134. package/dist/config-file/runner.d.ts +5 -6
  135. package/dist/config-file/toolchain.d.ts +13 -7
  136. package/dist/config-file/toolchain.js +53 -37
  137. package/dist/context.d.ts +8 -6
  138. package/dist/context.js +7 -6
  139. package/dist/core/across-sandboxes.d.ts +7 -6
  140. package/dist/core/across-sandboxes.js +123 -152
  141. package/dist/core/coordinator.d.ts +166 -0
  142. package/dist/core/coordinator.js +233 -0
  143. package/dist/core/events.d.ts +2 -2
  144. package/dist/core/index.d.ts +4 -2
  145. package/dist/core/index.js +1 -1
  146. package/dist/core/outcomes.d.ts +148 -0
  147. package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
  148. package/dist/core/resources.d.ts +31 -53
  149. package/dist/core/resources.js +32 -70
  150. package/dist/core/run-state.d.ts +7 -1
  151. package/dist/core/run-state.js +2 -0
  152. package/dist/core/run.d.ts +32 -236
  153. package/dist/core/run.js +106 -266
  154. package/dist/core/state-directory.d.ts +1 -1
  155. package/dist/core/state-directory.js +2 -2
  156. package/dist/credential/gateways.d.ts +15 -1
  157. package/dist/credential/index.d.ts +4 -3
  158. package/dist/credential/index.js +3 -2
  159. package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
  160. package/dist/credential/live/vercel-cli-gateway.js +1 -1
  161. package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
  162. package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
  163. package/dist/credential/source.d.ts +73 -6
  164. package/dist/credential/source.js +55 -2
  165. package/dist/extension-commands.d.ts +6 -1
  166. package/dist/extension-commands.js +15 -1
  167. package/dist/extensions/github/resource.d.ts +1 -1
  168. package/dist/extensions/github/resource.js +1 -1
  169. package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
  170. package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
  171. package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
  172. package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
  173. package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
  174. package/dist/extensions/testserver/credential-facts.d.ts +6 -2
  175. package/dist/extensions/testserver/credential-facts.js +29 -11
  176. package/dist/extensions/testserver/lifecycle.js +7 -1
  177. package/dist/extensions/testserver/limit.d.ts +3 -0
  178. package/dist/extensions/testserver/limit.js +3 -0
  179. package/dist/extensions/testserver/provision.d.ts +8 -1
  180. package/dist/extensions/testserver/provision.js +8 -3
  181. package/dist/extensions/testserver/refusals.d.ts +6 -1
  182. package/dist/extensions/testserver/refusals.js +16 -1
  183. package/dist/extensions/testserver/resource.d.ts +2 -2
  184. package/dist/extensions/testserver/resource.js +2 -2
  185. package/dist/extensions/testserver/result.d.ts +1 -1
  186. package/dist/extensions/testserver/result.js +9 -4
  187. package/dist/planning/driver-file-lists.d.ts +0 -15
  188. package/dist/planning/driver-file-lists.js +2 -21
  189. package/dist/planning/plan-only.d.ts +7 -15
  190. package/dist/planning/plan-only.js +16 -22
  191. package/dist/planning/run-kind-flags.js +2 -2
  192. package/dist/planning/run-plan.d.ts +45 -13
  193. package/dist/planning/run-plan.js +4 -3
  194. package/dist/planning/suites.d.ts +1 -1
  195. package/dist/planning/suites.js +2 -2
  196. package/dist/planning/test-plan.d.ts +9 -0
  197. package/dist/planning/test-plan.js +10 -2
  198. package/dist/run-directory/recording.js +2 -2
  199. package/dist/run-directory/run-record.d.ts +21 -6
  200. package/dist/run-directory/run-record.js +12 -9
  201. package/dist/runner/base.d.ts +0 -6
  202. package/dist/runner/base.js +1 -16
  203. package/dist/runner/build-snapshots.d.ts +55 -29
  204. package/dist/runner/build-snapshots.js +135 -35
  205. package/dist/runner/context.d.ts +15 -7
  206. package/dist/runner/context.js +19 -6
  207. package/dist/runner/events.d.ts +16 -10
  208. package/dist/runner/gateways.d.ts +92 -21
  209. package/dist/runner/gateways.js +1 -1
  210. package/dist/runner/index.d.ts +11 -7
  211. package/dist/runner/index.js +9 -4
  212. package/dist/runner/live/sandbox-errors.d.ts +2 -0
  213. package/dist/runner/live/sandbox-errors.js +4 -0
  214. package/dist/runner/live/sandbox-gateway.js +141 -3
  215. package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
  216. package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
  217. package/dist/runner/live/snapshot-records.js +6 -7
  218. package/dist/runner/local-snapshot-index.d.ts +199 -0
  219. package/dist/runner/local-snapshot-index.js +211 -0
  220. package/dist/runner/network-policy.d.ts +6 -6
  221. package/dist/runner/network-policy.js +7 -7
  222. package/dist/runner/policy-writes.d.ts +1 -1
  223. package/dist/runner/policy-writes.js +1 -1
  224. package/dist/runner/prepare.d.ts +25 -24
  225. package/dist/runner/prepare.js +28 -20
  226. package/dist/runner/ready.d.ts +18 -10
  227. package/dist/runner/ready.js +104 -33
  228. package/dist/runner/sandboxed-command.d.ts +3 -3
  229. package/dist/runner/sandboxed-command.js +3 -3
  230. package/dist/runner/scope.d.ts +10 -6
  231. package/dist/runner/scope.js +10 -3
  232. package/dist/runner/secrets.d.ts +13 -13
  233. package/dist/runner/secrets.js +18 -15
  234. package/dist/runner/session.d.ts +8 -8
  235. package/dist/runner/session.js +3 -3
  236. package/dist/runner/shared-snapshot-entry.d.ts +92 -0
  237. package/dist/runner/shared-snapshot-entry.js +168 -0
  238. package/dist/runner/shared-snapshot-list.d.ts +81 -0
  239. package/dist/runner/shared-snapshot-list.js +155 -0
  240. package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
  241. package/dist/runner/shared-snapshot-lookup.js +118 -0
  242. package/dist/runner/shared-snapshot-prune.d.ts +58 -0
  243. package/dist/runner/shared-snapshot-prune.js +133 -0
  244. package/dist/runner/snapshot-build.d.ts +42 -14
  245. package/dist/runner/snapshot-build.js +38 -28
  246. package/dist/runner/snapshot-choice.js +1 -1
  247. package/dist/runner/snapshot-inspect.d.ts +39 -40
  248. package/dist/runner/snapshot-inspect.js +58 -38
  249. package/dist/runner/snapshot-key.d.ts +30 -21
  250. package/dist/runner/snapshot-key.js +49 -29
  251. package/dist/runner/steps.d.ts +1 -1
  252. package/dist/runner/steps.js +1 -1
  253. package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +2 -2
  254. package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +3 -2
  255. package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +82 -82
  256. package/dist/runner/vercel-sandbox-options.js +510 -0
  257. package/dist/runner/{recipe-secrets.d.ts → vercel-sandbox-secrets.d.ts} +6 -6
  258. package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +20 -20
  259. package/dist/sdk/extension/commands.d.ts +8 -3
  260. package/dist/sdk/extension/commands.js +3 -1
  261. package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
  262. package/dist/sdk/extension/credential-diagnosis.js +25 -5
  263. package/dist/sdk/extension/credential-source.d.ts +20 -3
  264. package/dist/sdk/extension/credential-source.js +4 -4
  265. package/dist/sdk/extension/index.d.ts +3 -2
  266. package/dist/sdk/extension/index.js +2 -1
  267. package/dist/sdk/extension/resource-definition.d.ts +4 -3
  268. package/dist/sdk/extension/resource-definition.js +3 -2
  269. package/dist/sdk/extension/resource-factory.js +3 -4
  270. package/dist/sdk/extension/secret-source.d.ts +1 -1
  271. package/dist/sdk/extension/secret-source.js +1 -1
  272. package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
  273. package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
  274. package/dist/sdk/run/present.d.ts +3 -3
  275. package/dist/sdk/run/present.js +1 -3
  276. package/dist/shared/cleanup.d.ts +3 -3
  277. package/dist/shared/cleanup.js +15 -5
  278. package/dist/shared/snapshot-text.d.ts +4 -4
  279. package/dist/shared/snapshot-text.js +11 -11
  280. package/dist/time/duration.js +1 -1
  281. package/package.json +3 -2
  282. package/skills/overview.md +6 -4
  283. package/skills/plan-runs.md +2 -2
  284. package/skills/read-run-output.md +6 -6
  285. package/dist/chunks/chunk-E4PJNZVG.js +0 -783
  286. package/dist/chunks/chunk-RAQEXKL6.js +0 -2591
  287. package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
  288. package/dist/commands/exec/across-sandboxes-run.js +0 -339
  289. package/dist/commands/exec/plan-only.d.ts +0 -10
  290. package/dist/commands/exec/plan-only.js +0 -46
  291. package/dist/commands/exec/run-command.d.ts +0 -476
  292. package/dist/commands/exec/run-command.js +0 -604
  293. package/dist/commands/exec/run-planned.d.ts +0 -20
  294. package/dist/commands/exec/run-planned.js +0 -22
  295. package/dist/commands/exec/sandbox-view.d.ts +0 -19
  296. package/dist/commands/exec/sandbox-view.js +0 -72
  297. package/dist/commands/test/plan.d.ts +0 -92
  298. package/dist/commands/test/plan.js +0 -128
  299. package/dist/config/recipe-run.d.ts +0 -33
  300. package/dist/config/recipe-run.js +0 -28
  301. package/dist/core/sandbox-end.d.ts +0 -64
  302. package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
  303. package/dist/runner/recipe.js +0 -425
  304. package/dist/runner/snapshot-cache.d.ts +0 -148
  305. package/dist/runner/snapshot-cache.js +0 -126
@@ -1,25 +1,25 @@
1
1
  // The runner's local checks: everything the run can find out on this machine before it mints, acquires or creates
2
- // anything, so a missing base, a checkout with submodules or a recipe storm can't use fails with nothing to
2
+ // anything, so a missing base, a checkout with submodules, or runner options storm can't use fails with nothing to
3
3
  // clean up.
4
4
  import { resolveBase } from "./base.js";
5
- import { resolveVcpus } from "./recipe.js";
6
- import { classifySnapshotEntries, removeExpiredEntries, } from "./snapshot-cache.js";
7
- import { snapshotStepsAt } from "./snapshot-key.js";
5
+ import { resolveVcpus } from "./vercel-sandbox-options.js";
6
+ import { classifySnapshotEntries, removeExpiredEntries, resolveAncestorDistances, } from "./local-snapshot-index.js";
7
+ import { snapshotInputsAt } from "./snapshot-key.js";
8
8
  /**
9
- * Runs the local checks in order: the repository's root, the base, the submodule refusal, the snapshot steps at
9
+ * Runs the local checks in order: the repository's root, the base, the submodule refusal, the snapshot inputs at
10
10
  * the base and their key, the runner's vCPUs, the upload, HEAD's count of commits after the base, and the cache read,
11
11
  * which removes expired entries' files (`removeExpiredEntries`) and classifies the rest (`classifySnapshotEntries`)
12
- * against the merge-base and its snapshot key. So every git call and step function call happens here, before anything
13
- * is minted. It never mints, acquires or creates.
12
+ * against the merge-base and its snapshot key. So every git call and declared base-file read happens here, before
13
+ * anything is minted. It never mints, acquires, or creates.
14
14
  */
15
15
  export async function prepareRunner(context, request) {
16
16
  const { checkout } = context;
17
- const { recipe } = request;
17
+ const { options } = request;
18
18
  const root = await checkout.repositoryRoot({ cwd: request.cwd });
19
19
  if (!root.ok)
20
20
  return { kind: "checkout-failed", failure: root.failure };
21
21
  const repoRoot = root.value;
22
- const resolved = await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
22
+ const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
23
23
  if (resolved.kind === "failed")
24
24
  return { kind: "checkout-failed", failure: resolved.failure };
25
25
  if (resolved.kind === "no-base-ref")
@@ -30,12 +30,12 @@ export async function prepareRunner(context, request) {
30
30
  return { kind: "checkout-failed", failure: submodules.failure };
31
31
  if (submodules.value.length > 0)
32
32
  return { kind: "submodules", paths: [...submodules.value] };
33
- const steps = await snapshotStepsAt(checkout, { repoRoot, base, recipe });
34
- if (!steps.ok)
35
- return { kind: "invalid-recipe", path: steps.path, problem: steps.problem };
36
- const vcpus = resolveVcpus(recipe, request.vcpusRun);
33
+ const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
34
+ if (!inputs.ok)
35
+ return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
36
+ const vcpus = resolveVcpus(options, request.vcpuRun);
37
37
  if (!vcpus.ok)
38
- return { kind: "invalid-recipe", path: ["vcpus"], problem: vcpus.problem };
38
+ return { kind: "invalid-runner", path: ["vcpus"], problem: vcpus.problem };
39
39
  const upload = await checkout.assembleUpload({ repoRoot, base });
40
40
  if (!upload.ok)
41
41
  return { kind: "checkout-failed", failure: upload.failure };
@@ -43,23 +43,31 @@ export async function prepareRunner(context, request) {
43
43
  if (!afterBase.ok)
44
44
  return { kind: "checkout-failed", failure: afterBase.failure };
45
45
  const listing = await removeExpiredEntries(context);
46
+ const ancestorDistances = await resolveAncestorDistances(context, {
47
+ repoRoot,
48
+ entries: listing.entries,
49
+ options,
50
+ mergeBase: base,
51
+ });
52
+ if (!ancestorDistances.ok)
53
+ return { kind: "checkout-failed", failure: ancestorDistances.failure };
46
54
  const cache = classifySnapshotEntries(context, {
47
55
  entries: listing.entries,
48
- recipe,
56
+ options,
49
57
  base,
50
- snapshotKey: steps.key,
58
+ snapshotKey: inputs.key,
51
59
  commitsAfterBase: afterBase.value,
60
+ ancestorDistances: ancestorDistances.value,
52
61
  });
53
62
  return {
54
63
  kind: "ok",
55
64
  prepared: {
56
- recipe,
65
+ options,
57
66
  repoRoot,
58
67
  base,
59
68
  baseRef: resolved.ref,
60
- toolchains: steps.toolchains,
61
- prebuild: steps.prebuild,
62
- snapshotKey: steps.key,
69
+ baseFiles: inputs.baseFiles,
70
+ snapshotKey: inputs.key,
63
71
  vcpus: vcpus.vcpus,
64
72
  upload: upload.value,
65
73
  candidates: cache.candidates,
@@ -1,7 +1,7 @@
1
1
  import type { SandboxCredential } from "../sdk/extension/index.ts";
2
2
  import { type RunnerContext } from "./context.ts";
3
3
  import type { RunnerFailure, RunnerProgress, RunnerStage } from "./events.ts";
4
- import type { CheckoutUpload, RunnerSandbox, RunnerSnapshotCacheFailure, RunnerSnapshotEntry, SandboxAccess, StagedFile } from "./gateways.ts";
4
+ import type { CheckoutUpload, RunnerSandbox, RunnerSnapshotEntry, RunnerSnapshotIndexFailure, SandboxAccess, StagedFile } from "./gateways.ts";
5
5
  import type { PreparedRunner } from "./prepare.ts";
6
6
  import type { RunnerSandboxScope } from "./scope.ts";
7
7
  /** The label of the step that applies and commits the run's changes in the runner sandbox. */
@@ -27,7 +27,7 @@ export interface ReadyRunner {
27
27
  readonly repoRoot: string;
28
28
  /** The command's directory in the runner sandbox. */
29
29
  readonly cwd: string;
30
- /** The recipe's extra environment for the command. */
30
+ /** The runner's extra environment for the command. */
31
31
  readonly env: Readonly<Record<string, string>>;
32
32
  /** A login shell's `PATH` in the runner sandbox. */
33
33
  readonly loginPath: string;
@@ -49,7 +49,7 @@ export type ReadyRunnerOutcome = {
49
49
  } | {
50
50
  readonly kind: "snapshot-gone";
51
51
  readonly entry: RunnerSnapshotEntry;
52
- readonly removal: RunnerSnapshotCacheFailure | undefined;
52
+ readonly removal: RunnerSnapshotIndexFailure | undefined;
53
53
  } | {
54
54
  readonly kind: "failed";
55
55
  readonly failure: RunnerFailure;
@@ -62,16 +62,21 @@ export interface ReadyRunnerRequest {
62
62
  /** The local user, for the build sandbox's and the runner sandbox's `user` tag. */
63
63
  readonly user: string;
64
64
  /**
65
- * The recipe's credentials, with their values (`readCredentials`). The firewall adds each one from before a build's
65
+ * The runner's credentials, with their values (`readCredentials`). The firewall adds each one from before a build's
66
66
  * first toolchain step to after its last prebuild step, and from before the install on, through the command; no value
67
67
  * enters a sandbox.
68
68
  */
69
69
  readonly credentials: readonly Required<SandboxCredential>[];
70
70
  }
71
- /** The runner snapshot a run chose to start from: its cache entry, and whether this run built it. */
71
+ /**
72
+ * The runner snapshot a run chose to start from: its cache entry, whether this run built it, how many commits HEAD has
73
+ * that its base lacks, and the checkout upload assembled against its base.
74
+ */
72
75
  export interface ChosenSnapshot {
73
76
  readonly entry: RunnerSnapshotEntry;
74
77
  readonly built: boolean;
78
+ readonly builtBehind: number;
79
+ readonly upload: CheckoutUpload;
75
80
  }
76
81
  /**
77
82
  * Readies the runner sandbox for a prepared run: it chooses the runner snapshot (`chooseSnapshot`), then readies a
@@ -82,10 +87,13 @@ export declare function readyRunner(context: RunnerContext, request: ReadyRunner
82
87
  readonly signal: AbortSignal;
83
88
  }, progress: RunnerProgress): Promise<ReadyRunnerOutcome>;
84
89
  /**
85
- * Chooses the runner snapshot a prepared run starts from, and starts no runner sandbox. It picks, of the prepared
86
- * candidates, the one for the access's team and project (`pickSnapshot`) and reports `snapshot-reused`; with no pick,
87
- * it builds a base snapshot at the run's base, saying why each cached snapshot of the recipe doesn't fit
88
- * (`no-snapshot`, `snapshotRejections`; `buildSnapshot`). A build sandbox it starts belongs to the scope.
90
+ * Chooses the runner snapshot a prepared run starts from, and starts no runner sandbox. It checks the local snapshot
91
+ * index first: an exact merge-base hit is reused at once, with no call to the shared snapshot index. Otherwise it
92
+ * queries the shared snapshot index and compares any shared hit against any local ancestor candidate: the shared hit
93
+ * wins only when it is closer (`sharedBeatsLocal`), and a winning shared hit is written to the local snapshot index.
94
+ * Whenever the chosen snapshot's base differs from `prepared.base`, it assembles the checkout upload against that base
95
+ * once here; otherwise it reuses `prepared.upload`. With no fitting snapshot in either index, it builds a base snapshot
96
+ * at `prepared.base` into the local snapshot index.
89
97
  */
90
98
  export declare function chooseSnapshot(context: RunnerContext, request: ReadyRunnerRequest, control: {
91
99
  readonly scope: RunnerSandboxScope;
@@ -93,7 +101,7 @@ export declare function chooseSnapshot(context: RunnerContext, request: ReadyRun
93
101
  }, progress: RunnerProgress): Promise<RunnerStage<ChosenSnapshot>>;
94
102
  /**
95
103
  * Readies a runner sandbox from the runner snapshot a run chose: it starts the runner sandbox from that snapshot,
96
- * uploads what the checkout changes on top of the run's base, applies it, grants it the recipe's credentials
104
+ * uploads what the checkout changes on top of the run's base, applies it, grants it the runner's credentials
97
105
  * (`RunnerSandboxScope.grantCredentials`), and runs the install and the build. It doesn't revoke them: they stay in
98
106
  * place for the command, and whoever ends the run revokes them, the runner session after the command, or the scope's
99
107
  * fence when the run ends before it. A failed grant ends it with `network-policy-failed` (`operation: "inject"`,
@@ -1,13 +1,14 @@
1
1
  // Readying the runner sandbox once the run's credential names its team and project, in two stages: choose the runner
2
2
  // snapshot it starts from (pick the cached one, or build a base snapshot), then start the runner sandbox from it,
3
- // upload and apply the run's changes, grant it the recipe's credentials, and install and build. A run does the first
3
+ // upload and apply the run's changes, grant it the runner's credentials, and install and build. A run does the first
4
4
  // stage once, and the second once for each runner sandbox it starts. The credentials stay in place after the build, for
5
5
  // the command: the runner session revokes them once the command has ended, and the scope's fence when the run ends
6
6
  // first.
7
7
  import { posix } from "node:path";
8
8
  import { runnerTags } from "./context.js";
9
+ import { pickSnapshot, sharedBeatsLocal, snapshotRejections } from "./local-snapshot-index.js";
9
10
  import { buildSnapshot } from "./snapshot-build.js";
10
- import { pickSnapshot, snapshotRejections } from "./snapshot-cache.js";
11
+ import { lookupSharedSnapshot } from "./shared-snapshot-lookup.js";
11
12
  import { applyScript, SANDBOX_ROOT, STAGED_FILES } from "./snapshot-key.js";
12
13
  import { networkPolicyStop, runStep, sandboxStop } from "./steps.js";
13
14
  /** The label of the step that applies and commits the run's changes in the runner sandbox. */
@@ -23,35 +24,105 @@ export async function readyRunner(context, request, control, progress) {
23
24
  return await readyFromSnapshot(context, { ...request, snapshot: chosen.value }, control, progress);
24
25
  }
25
26
  /**
26
- * Chooses the runner snapshot a prepared run starts from, and starts no runner sandbox. It picks, of the prepared
27
- * candidates, the one for the access's team and project (`pickSnapshot`) and reports `snapshot-reused`; with no pick,
28
- * it builds a base snapshot at the run's base, saying why each cached snapshot of the recipe doesn't fit
29
- * (`no-snapshot`, `snapshotRejections`; `buildSnapshot`). A build sandbox it starts belongs to the scope.
27
+ * Chooses the runner snapshot a prepared run starts from, and starts no runner sandbox. It checks the local snapshot
28
+ * index first: an exact merge-base hit is reused at once, with no call to the shared snapshot index. Otherwise it
29
+ * queries the shared snapshot index and compares any shared hit against any local ancestor candidate: the shared hit
30
+ * wins only when it is closer (`sharedBeatsLocal`), and a winning shared hit is written to the local snapshot index.
31
+ * Whenever the chosen snapshot's base differs from `prepared.base`, it assembles the checkout upload against that base
32
+ * once here; otherwise it reuses `prepared.upload`. With no fitting snapshot in either index, it builds a base snapshot
33
+ * at `prepared.base` into the local snapshot index.
30
34
  */
31
35
  export async function chooseSnapshot(context, request, control, progress) {
32
36
  const { prepared, access } = request;
33
- if (control.signal.aborted)
37
+ const { signal } = control;
38
+ if (signal.aborted)
34
39
  return { kind: "aborted" };
35
- const pick = pickSnapshot(prepared.candidates, access);
36
- if (pick !== undefined) {
37
- const { entry } = pick;
40
+ // The local snapshot index on this machine.
41
+ const localCandidate = pickSnapshot(prepared.candidates, access);
42
+ if (localCandidate !== undefined && localCandidate.commitsBehindMergeBase === 0) {
43
+ const { entry, builtBehind } = localCandidate;
38
44
  await progress.emit({
39
45
  kind: "snapshot-reused",
40
46
  snapshotId: entry.snapshotId,
41
47
  base: entry.base,
42
- builtBehind: pick.builtBehind,
48
+ builtBehind,
49
+ source: "local",
43
50
  });
44
- return { kind: "ok", value: { entry, built: false } };
51
+ return { kind: "ok", value: { entry, built: false, builtBehind, upload: prepared.upload } };
52
+ }
53
+ // The shared snapshot index in the Vercel project.
54
+ const shared = await lookupSharedSnapshot(context, {
55
+ access,
56
+ repoRoot: prepared.repoRoot,
57
+ runner: prepared.options,
58
+ snapshotKey: prepared.snapshotKey,
59
+ mergeBase: prepared.base,
60
+ ...(localCandidate === undefined ? {} : { maxCommitsBehindMergeBase: localCandidate.commitsBehindMergeBase }),
61
+ }, signal);
62
+ if (shared.kind === "aborted")
63
+ return { kind: "aborted" };
64
+ if (shared.kind === "unavailable") {
65
+ await progress.emit({ kind: "shared-snapshot-lookup-failed", message: shared.message });
66
+ }
67
+ const sharedHit = shared.kind === "hit" ? shared : undefined;
68
+ const useShared = sharedHit !== undefined &&
69
+ sharedBeatsLocal(sharedHit.commitsBehindMergeBase, localCandidate?.commitsBehindMergeBase);
70
+ const winner = useShared
71
+ ? { source: "shared", hit: sharedHit }
72
+ : localCandidate !== undefined
73
+ ? { source: "local", candidate: localCandidate }
74
+ : undefined;
75
+ if (winner !== undefined) {
76
+ let entry;
77
+ let builtBehind;
78
+ if (winner.source === "shared") {
79
+ entry = winner.hit.entry;
80
+ const written = await context.runnerSnapshots.writeEntry(entry);
81
+ if (!written.ok)
82
+ await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
83
+ builtBehind = prepared.commitsAfterBase + winner.hit.commitsBehindMergeBase;
84
+ }
85
+ else {
86
+ entry = winner.candidate.entry;
87
+ builtBehind = winner.candidate.builtBehind;
88
+ }
89
+ const upload = await uploadForBase(context, prepared, entry.base);
90
+ if (!upload.ok)
91
+ return { kind: "failed", failure: { kind: "checkout-failed", failure: upload.failure } };
92
+ if (signal.aborted)
93
+ return { kind: "aborted" };
94
+ await progress.emit({
95
+ kind: "snapshot-reused",
96
+ snapshotId: entry.snapshotId,
97
+ base: entry.base,
98
+ builtBehind,
99
+ source: winner.source,
100
+ });
101
+ return { kind: "ok", value: { entry, built: false, builtBehind, upload: upload.value } };
45
102
  }
46
103
  const why = { kind: "no-snapshot", rejected: snapshotRejections(prepared, access) };
47
104
  const building = await buildSnapshot(context, { prepared, access, user: request.user, credentials: request.credentials, why }, control, progress);
48
105
  if (building.kind !== "ok")
49
106
  return building;
50
- return { kind: "ok", value: { entry: building.value.entry, built: true } };
107
+ return {
108
+ kind: "ok",
109
+ value: {
110
+ entry: building.value.entry,
111
+ built: true,
112
+ builtBehind: prepared.commitsAfterBase,
113
+ upload: prepared.upload,
114
+ },
115
+ };
116
+ }
117
+ /** Reuses `prepared.upload` when `base` is `prepared.base`, or assembles the upload against `base`. */
118
+ async function uploadForBase(context, prepared, base) {
119
+ if (base === prepared.base)
120
+ return { ok: true, value: prepared.upload };
121
+ return await context.checkout.assembleUpload({ repoRoot: prepared.repoRoot, base });
51
122
  }
52
123
  /**
53
124
  * Readies a runner sandbox from the runner snapshot a run chose: it starts the runner sandbox from that snapshot,
54
- * uploads what the checkout changes on top of the run's base, applies it, grants it the recipe's credentials
125
+ * uploads what the checkout changes on top of the run's base, applies it, grants it the runner's credentials
55
126
  * (`RunnerSandboxScope.grantCredentials`), and runs the install and the build. It doesn't revoke them: they stay in
56
127
  * place for the command, and whoever ends the run revokes them, the runner session after the command, or the scope's
57
128
  * fence when the run ends before it. A failed grant ends it with `network-policy-failed` (`operation: "inject"`,
@@ -61,8 +132,8 @@ export async function chooseSnapshot(context, request, control, progress) {
61
132
  */
62
133
  export async function readyFromSnapshot(context, request, control, progress) {
63
134
  const { prepared, access } = request;
64
- const { entry, built } = request.snapshot;
65
- const { recipe, repoRoot } = prepared;
135
+ const { entry, built, builtBehind, upload } = request.snapshot;
136
+ const { options, repoRoot } = prepared;
66
137
  const { scope, signal } = control;
67
138
  const now = () => context.clock.now().getTime();
68
139
  if (signal.aborted)
@@ -71,10 +142,10 @@ export async function readyFromSnapshot(context, request, control, progress) {
71
142
  const startedAt = now();
72
143
  const started = await scope.startRunnerSandbox(access, {
73
144
  snapshotId: entry.snapshotId,
74
- region: recipe.region,
145
+ region: options.region,
75
146
  vcpus: prepared.vcpus,
76
- timeoutMs: recipe.timeoutMinutes * 60_000,
77
- tags: runnerTags(recipe.name, "runner", request.user),
147
+ timeoutMs: options.timeoutMinutes * 60_000,
148
+ tags: runnerTags(options.name, "runner", request.user),
78
149
  });
79
150
  if (!started.ok) {
80
151
  if (started.failure.kind === "snapshot-gone") {
@@ -88,25 +159,25 @@ export async function readyFromSnapshot(context, request, control, progress) {
88
159
  kind: "sandbox-started",
89
160
  role: "runner",
90
161
  name: sandbox.name,
91
- region: recipe.region,
162
+ region: options.region,
92
163
  vcpus: prepared.vcpus,
93
164
  ms: now() - startedAt,
94
165
  });
95
- const changes = await uploadChanges(context, { prepared, sandbox }, signal, progress);
166
+ const changes = await uploadChanges(context, { upload, sandbox }, signal, progress);
96
167
  if (changes.kind !== "ok")
97
168
  return changes;
98
169
  const applied = await stage(context, {
99
170
  sandbox,
100
171
  phase: "apply",
101
172
  step: { label: APPLY_LABEL, script: applyScript(changes.value.directory) },
102
- region: recipe.region,
173
+ region: options.region,
103
174
  }, signal, progress);
104
175
  if (applied.kind !== "ok")
105
176
  return applied;
106
177
  const loginPath = await context.runnerSandboxes.loginPath(sandbox, signal);
107
178
  if (!loginPath.ok)
108
179
  return sandboxStop("login-path", loginPath.failure);
109
- // Every credential the recipe declares goes on the requests of the install, the build, and the command: the upload
180
+ // Every credential the runner declares goes on the requests of the install, the build, and the command: the upload
110
181
  // and the apply come before the grant. Nothing here revokes them; a run that ends before the command leaves that to
111
182
  // the scope's fence.
112
183
  if (request.credentials.length > 0) {
@@ -114,10 +185,10 @@ export async function readyFromSnapshot(context, request, control, progress) {
114
185
  if (!granted.ok)
115
186
  return networkPolicyStop("inject", "run-steps", granted.failure);
116
187
  }
117
- const installed = await stage(context, { sandbox, phase: "install", step: recipe.run.install, region: recipe.region }, signal, progress);
188
+ const installed = await stage(context, { sandbox, phase: "install", step: options.run.install, region: options.region }, signal, progress);
118
189
  if (installed.kind !== "ok")
119
190
  return installed;
120
- const builtOutputs = await stage(context, { sandbox, phase: "build", step: recipe.run.build, region: recipe.region }, signal, progress);
191
+ const builtOutputs = await stage(context, { sandbox, phase: "build", step: options.run.build, region: options.region }, signal, progress);
121
192
  if (builtOutputs.kind !== "ok")
122
193
  return builtOutputs;
123
194
  return {
@@ -127,26 +198,26 @@ export async function readyFromSnapshot(context, request, control, progress) {
127
198
  snapshotId: entry.snapshotId,
128
199
  base: entry.base,
129
200
  built,
130
- builtBehind: prepared.commitsAfterBase,
201
+ builtBehind,
131
202
  uploadBytes: changes.value.bytes,
132
203
  buildMs: builtOutputs.value,
133
204
  vcpus: prepared.vcpus,
134
- region: recipe.region,
135
- runtime: recipe.runtime,
205
+ region: options.region,
206
+ runtime: options.runtime,
136
207
  repoRoot,
137
- cwd: posix.join(SANDBOX_ROOT, recipe.cwd),
138
- env: recipe.env,
208
+ cwd: posix.join(SANDBOX_ROOT, options.cwd),
209
+ env: options.env,
139
210
  loginPath: loginPath.value,
140
211
  },
141
212
  };
142
213
  }
143
214
  /**
144
- * Uploads what the checkout changes on top of the run's base, the prepared upload.
215
+ * Uploads what the checkout changes on top of the chosen snapshot's base.
145
216
  */
146
217
  async function uploadChanges(context, request, signal, progress) {
147
218
  await progress.emit({ kind: "uploading" });
148
219
  const startedAt = context.clock.now().getTime();
149
- const files = stagedChanges(request.prepared.upload);
220
+ const files = stagedChanges(request.upload);
150
221
  const staged = await context.runnerSandboxes.upload(request.sandbox, files, signal);
151
222
  if (!staged.ok)
152
223
  return sandboxStop("upload", staged.failure);
@@ -170,7 +241,7 @@ export function stagedChanges(upload) {
170
241
  }
171
242
  /**
172
243
  * Runs the apply, install, or build step, answering how long it took; the install and build get rule lines. The grant
173
- * of the recipe's credentials before the install is the caller's.
244
+ * of the runner's credentials before the install is the caller's.
174
245
  */
175
246
  async function stage(context, request, signal, progress) {
176
247
  if (signal.aborted)
@@ -17,11 +17,11 @@ export declare function sandboxedCommand(request: {
17
17
  };
18
18
  /**
19
19
  * What the command's environment adds to the runner sandbox's own: `PATH` with the sandbox `cwd`'s and the
20
- * repository's `node_modules/.bin` before the login shell's, no update checks, the recipe's `env`, any
20
+ * repository's `node_modules/.bin` before the login shell's, no update checks, the runner's `env`, any
21
21
  * `unsafeSecretEnvVars` values the run read on the launch machine, and `STORM_RUN` last, so nothing overrides it. When
22
- * the recipe's `env` sets neither `FORCE_COLOR` nor `NO_COLOR`, it also gets `FORCE_COLOR=1` when the local terminal
22
+ * the runner's `env` sets neither `FORCE_COLOR` nor `NO_COLOR`, it also gets `FORCE_COLOR=1` when the local terminal
23
23
  * asks for color (`"on"`), `NO_COLOR=1` when the launcher explicitly opted out (`"off"`), and neither on a plain
24
- * non-TTY launcher (`"auto"`), as a run with no runner does (`colorEnvironment` in `core/payload.ts`); a recipe that
24
+ * non-TTY launcher (`"auto"`), as a run with no runner does (`colorEnvironment` in `core/payload.ts`); a runner that
25
25
  * sets either gets neither from storm. Nothing else comes from the local environment.
26
26
  */
27
27
  export declare function sandboxEnvironment(request: {
@@ -17,11 +17,11 @@ export function sandboxedCommand(request) {
17
17
  }
18
18
  /**
19
19
  * What the command's environment adds to the runner sandbox's own: `PATH` with the sandbox `cwd`'s and the
20
- * repository's `node_modules/.bin` before the login shell's, no update checks, the recipe's `env`, any
20
+ * repository's `node_modules/.bin` before the login shell's, no update checks, the runner's `env`, any
21
21
  * `unsafeSecretEnvVars` values the run read on the launch machine, and `STORM_RUN` last, so nothing overrides it. When
22
- * the recipe's `env` sets neither `FORCE_COLOR` nor `NO_COLOR`, it also gets `FORCE_COLOR=1` when the local terminal
22
+ * the runner's `env` sets neither `FORCE_COLOR` nor `NO_COLOR`, it also gets `FORCE_COLOR=1` when the local terminal
23
23
  * asks for color (`"on"`), `NO_COLOR=1` when the launcher explicitly opted out (`"off"`), and neither on a plain
24
- * non-TTY launcher (`"auto"`), as a run with no runner does (`colorEnvironment` in `core/payload.ts`); a recipe that
24
+ * non-TTY launcher (`"auto"`), as a run with no runner does (`colorEnvironment` in `core/payload.ts`); a runner that
25
25
  * sets either gets neither from storm. Nothing else comes from the local environment.
26
26
  */
27
27
  export function sandboxEnvironment(request) {
@@ -1,7 +1,7 @@
1
1
  import type { SandboxCredential } from "../sdk/extension/index.ts";
2
2
  import type { Clock, Timer } from "../time/index.ts";
3
3
  import type { KeptSandbox, NotDeletedSandbox, NotKeptSandbox, NotStoppedSandbox, RunnerProgress } from "./events.ts";
4
- import type { RunnerSandbox, RunnerSandboxFailure, RunnerSandboxGateway, RunnerSandboxPlacement, RunnerSandboxResult, RunnerStartFailure, SandboxAccess, SavedSnapshot } from "./gateways.ts";
4
+ import type { RunnerBuildStartFailure, RunnerSandbox, RunnerSandboxFailure, RunnerSandboxGateway, RunnerSandboxPlacement, RunnerSandboxResult, RunnerStartFailure, SandboxAccess, SavedSnapshot } from "./gateways.ts";
5
5
  import { type NetworkPolicyWriteFailure, type NetworkPolicyWriteResult, type RunnerReachPolicy } from "./network-policy.ts";
6
6
  /** How long closing waits for a create in flight: 20 seconds. */
7
7
  export declare const CREATE_SETTLE_MS = 20000;
@@ -34,7 +34,7 @@ export interface RunnerScopeFacts {
34
34
  }
35
35
  /**
36
36
  * Why the scope saved no snapshot of a build sandbox: a Sandbox failure, or `credential-not-revoked` when its policy
37
- * may hold a credential (the recipe's or a resource's) and writing the policy without it failed (`failure`).
37
+ * may hold a credential (the runner's or a resource's) and writing the policy without it failed (`failure`).
38
38
  */
39
39
  export type ScopeSaveFailure = RunnerSandboxFailure | {
40
40
  readonly kind: "credential-not-revoked";
@@ -54,7 +54,8 @@ export type ScopedSandboxPlacement = Omit<RunnerSandboxPlacement, "networkPolicy
54
54
  export interface RunnerSandboxScope {
55
55
  startBuildSandbox(access: SandboxAccess, request: ScopedSandboxPlacement & {
56
56
  readonly runtime: string;
57
- }): Promise<RunnerSandboxResult<RunnerSandbox>>;
57
+ readonly name?: string;
58
+ }): Promise<RunnerSandboxResult<RunnerSandbox, RunnerBuildStartFailure>>;
58
59
  startRunnerSandbox(access: SandboxAccess, request: ScopedSandboxPlacement & {
59
60
  readonly snapshotId: string;
60
61
  }): Promise<RunnerSandboxResult<RunnerSandbox, RunnerStartFailure>>;
@@ -85,12 +86,15 @@ export interface RunnerSandboxScope {
85
86
  */
86
87
  revokeCredentials(sandbox: RunnerSandbox): Promise<NetworkPolicyWriteResult>;
87
88
  /**
88
- * Saves a build sandbox as a runner snapshot, then deletes it at once; a failed save leaves it to `close`. When the
89
- * sandbox's policy may hold a credential, it first writes the policy without the injection, and saves nothing
90
- * when that fails (`credential-not-revoked`).
89
+ * Saves a build sandbox as a runner snapshot, then deletes it at once unless `keepStopped` is true and the scope is
90
+ * still open (leaving the stopped named sandbox in the project as a shared snapshot index entry); a failed save or a
91
+ * cancel before the save completes leaves it to `close` to stop and delete. When the sandbox's policy may hold a
92
+ * credential, it first writes the policy without the injection, and saves nothing when that fails
93
+ * (`credential-not-revoked`).
91
94
  */
92
95
  saveSnapshot(sandbox: RunnerSandbox, request: {
93
96
  readonly expirationMs: number;
97
+ readonly keepStopped?: boolean;
94
98
  }): Promise<RunnerSandboxResult<SavedSnapshot, ScopeSaveFailure>>;
95
99
  /**
96
100
  * Fences every sandbox the scope holds, before its owner releases the run's resources. It waits up to
@@ -299,10 +299,17 @@ export function runnerSandboxScope(context, progress, settings) {
299
299
  if (!removed.ok)
300
300
  return { ok: false, failure: { kind: "credential-not-revoked", failure: removed.failure } };
301
301
  }
302
- const saved = await sandboxes.saveSnapshot(sandbox, request);
302
+ const saved = await sandboxes.saveSnapshot(sandbox, { expirationMs: request.expirationMs });
303
303
  const now = currentPhase();
304
- if (saved.ok && now.kind !== "closing" && now.sandboxes.delete(sandbox))
305
- await deleteSandbox(sandbox);
304
+ if (saved.ok) {
305
+ if (request.keepStopped === true) {
306
+ if (now.kind === "open")
307
+ now.sandboxes.delete(sandbox);
308
+ }
309
+ else if (now.kind !== "closing" && now.sandboxes.delete(sandbox)) {
310
+ await deleteSandbox(sandbox);
311
+ }
312
+ }
306
313
  return saved;
307
314
  })()),
308
315
  fence,
@@ -1,5 +1,5 @@
1
1
  import { type SandboxCredential, SECRET_MIN_LENGTH, type SecretProblem } from "../sdk/extension/index.ts";
2
- import type { CheckedRecipe } from "./recipe.ts";
2
+ import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
3
3
  export { SECRET_MIN_LENGTH, type SecretProblem };
4
4
  /**
5
5
  * An unsafe secret environment variable's value by the variable name exposed to the command, each an own property
@@ -14,8 +14,8 @@ export interface SecretVariableProblem {
14
14
  readonly problem: SecretProblem;
15
15
  }
16
16
  /**
17
- * The recipe's credentials with their values, in the recipe's order, or what keeps the run from starting: each
18
- * variable with a problem, once, in the order the recipe first names it.
17
+ * The runner's credentials with their values, in the runner's order, or what keeps the run from starting: each
18
+ * variable with a problem, once, in the order the runner options first name it.
19
19
  */
20
20
  export type CredentialRead = {
21
21
  readonly ok: true;
@@ -36,24 +36,24 @@ export type UnsafeSecretEnvVarRead = {
36
36
  readonly variables: readonly SecretVariableProblem[];
37
37
  };
38
38
  /**
39
- * The value of each credential and unsafe secret environment variable `recipe` declares that `env` sets, whatever a
39
+ * The value of each credential and unsafe secret environment variable `options` declares that `env` sets, whatever a
40
40
  * run would say of it: for a command that hides the values in what it prints but needs none, such as `storm snapshots
41
41
  * list` or `storm snapshots build`. A short or multiline value is kept, since hiding it there is safer than showing it.
42
42
  */
43
- export declare function declaredSecretValues(recipe: Pick<CheckedRecipe, "credentials" | "unsafeSecretEnvVars"> | undefined, env: Readonly<Record<string, string | undefined>>): string[];
43
+ export declare function declaredSecretValues(options: Pick<CheckedVercelSandboxOptions, "credentials" | "unsafeSecretEnvVars"> | undefined, env: Readonly<Record<string, string | undefined>>): string[];
44
44
  /**
45
- * Reads each of `recipe`'s credentials' values from `env`, the environment of the machine the run starts on, through
45
+ * Reads each of `options`'s credentials' values from `env`, the environment of the machine the run starts on, through
46
46
  * `readSecretSource`: each `{ kind: "env", name }` source holds the whole header value, such as `Bearer …`. It answers
47
- * the sandbox credentials the recipe's steps and the command run under, one per declared credential, in the recipe's
48
- * order, each with its domain, header, and `requests` from the recipe. A source's problem is the first that holds of
49
- * `missing`, `multiline`, and `short`, and a source two credentials share is read and reported once in first-seen
50
- * order. A value is used as it is, never trimmed.
47
+ * the sandbox credentials the runner's steps and the command run under, one per declared credential, in the runner's
48
+ * order, each with its domain, header, and `requests` from the runner options. A source's problem is the first that
49
+ * holds of `missing`, `multiline`, and `short`, and a source two credentials share is read and reported once in
50
+ * first-seen order. A value is used as it is, never trimmed.
51
51
  */
52
- export declare function readCredentials(recipe: Pick<CheckedRecipe, "credentials">, env: Readonly<Record<string, string | undefined>>): CredentialRead;
52
+ export declare function readCredentials(options: Pick<CheckedVercelSandboxOptions, "credentials">, env: Readonly<Record<string, string | undefined>>): CredentialRead;
53
53
  /**
54
- * Reads each of `recipe`'s unsafe secret environment variables (`runner.unsafeSecretEnvVars`) from `env`, the
54
+ * Reads each of `options`'s unsafe secret environment variables (`runner.unsafeSecretEnvVars`) from `env`, the
55
55
  * environment of the machine the run starts on, through `readSecretSource`, and maps each value to `entry.name` for
56
56
  * the command's environment. A source's problem is the first that holds of `missing`, `multiline`, and `short`, and a
57
57
  * source two entries share is read and reported once in first-seen order. A value is used as it is, never trimmed.
58
58
  */
59
- export declare function readUnsafeSecretEnvVars(recipe: Pick<CheckedRecipe, "unsafeSecretEnvVars">, env: Readonly<Record<string, string | undefined>>): UnsafeSecretEnvVarRead;
59
+ export declare function readUnsafeSecretEnvVars(options: Pick<CheckedVercelSandboxOptions, "unsafeSecretEnvVars">, env: Readonly<Record<string, string | undefined>>): UnsafeSecretEnvVarRead;