@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
@@ -56,6 +56,10 @@ declare const snapshotSchema: z.ZodObject<{
56
56
  base: z.ZodString;
57
57
  built: z.ZodBoolean;
58
58
  builtBehind: z.ZodNullable<z.ZodNumber>;
59
+ source: z.ZodExactOptional<z.ZodNullable<z.ZodEnum<{
60
+ local: "local";
61
+ shared: "shared";
62
+ }>>>;
59
63
  }, z.core.$strip>;
60
64
  /**
61
65
  * The runner snapshot a runner sandbox started from: its id, the base it is of, which the run's changes were uploaded
@@ -68,8 +72,8 @@ declare const whereSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
68
72
  kind: z.ZodLiteral<"launch-machine">;
69
73
  }, z.core.$strip>, z.ZodObject<{
70
74
  kind: z.ZodLiteral<"vercel-sandbox">;
71
- team: z.ZodString;
72
- project: z.ZodString;
75
+ team: z.ZodNullable<z.ZodString>;
76
+ project: z.ZodNullable<z.ZodString>;
73
77
  region: z.ZodString;
74
78
  runtime: z.ZodString;
75
79
  vcpus: z.ZodNumber;
@@ -81,6 +85,10 @@ declare const whereSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
81
85
  base: z.ZodString;
82
86
  built: z.ZodBoolean;
83
87
  builtBehind: z.ZodNullable<z.ZodNumber>;
88
+ source: z.ZodExactOptional<z.ZodNullable<z.ZodEnum<{
89
+ local: "local";
90
+ shared: "shared";
91
+ }>>>;
84
92
  }, z.core.$strip>>;
85
93
  keptUntil: z.ZodNullable<z.ZodString>;
86
94
  uploadBytes: z.ZodNullable<z.ZodNumber>;
@@ -191,8 +199,8 @@ declare const runRecordSchema: z.ZodObject<{
191
199
  kind: z.ZodLiteral<"launch-machine">;
192
200
  }, z.core.$strip>, z.ZodObject<{
193
201
  kind: z.ZodLiteral<"vercel-sandbox">;
194
- team: z.ZodString;
195
- project: z.ZodString;
202
+ team: z.ZodNullable<z.ZodString>;
203
+ project: z.ZodNullable<z.ZodString>;
196
204
  region: z.ZodString;
197
205
  runtime: z.ZodString;
198
206
  vcpus: z.ZodNumber;
@@ -204,6 +212,10 @@ declare const runRecordSchema: z.ZodObject<{
204
212
  base: z.ZodString;
205
213
  built: z.ZodBoolean;
206
214
  builtBehind: z.ZodNullable<z.ZodNumber>;
215
+ source: z.ZodExactOptional<z.ZodNullable<z.ZodEnum<{
216
+ local: "local";
217
+ shared: "shared";
218
+ }>>>;
207
219
  }, z.core.$strip>>;
208
220
  keptUntil: z.ZodNullable<z.ZodString>;
209
221
  uploadBytes: z.ZodNullable<z.ZodNumber>;
@@ -295,8 +307,11 @@ export declare function runEnd(outcome: RunOutcome, ran: RunState["command"], te
295
307
  * Where the command runs, as `run.json` records it as the run starts: on the launch machine (`launch-machine`), or in
296
308
  * a Vercel Sandbox (`vercel-sandbox`), with no sandbox or snapshot yet.
297
309
  */
298
- export declare function startedWhere(run: {
299
- readonly runner?: RunRunnerRequest | undefined;
310
+ export declare function startedWhere(runner: {
311
+ readonly kind: "launch-machine";
312
+ } | {
313
+ readonly kind: "vercel-sandbox";
314
+ readonly session: RunRunnerRequest;
300
315
  }): RunRecordWhere;
301
316
  /**
302
317
  * `where` once the run is over, from the runner's final state: for a run in a runner sandbox, the runner sandbox the
@@ -30,13 +30,15 @@ const snapshotSchema = z.object({
30
30
  base: z.string(),
31
31
  built: z.boolean(),
32
32
  builtBehind: z.number().nullable(),
33
+ /** Where a reused snapshot came from (`local` or `shared`); null when built, or absent in older records. */
34
+ source: z.enum(["local", "shared"]).nullable().exactOptional(),
33
35
  });
34
36
  const whereSchema = z.discriminatedUnion("kind", [
35
37
  z.object({ kind: z.literal("launch-machine") }),
36
38
  z.object({
37
39
  kind: z.literal("vercel-sandbox"),
38
- team: z.string(),
39
- project: z.string(),
40
+ team: z.string().nullable(),
41
+ project: z.string().nullable(),
40
42
  region: z.string(),
41
43
  runtime: z.string(),
42
44
  vcpus: z.number().int().positive(),
@@ -178,16 +180,16 @@ function commandMs(ran) {
178
180
  * Where the command runs, as `run.json` records it as the run starts: on the launch machine (`launch-machine`), or in
179
181
  * a Vercel Sandbox (`vercel-sandbox`), with no sandbox or snapshot yet.
180
182
  */
181
- export function startedWhere(run) {
182
- if (run.runner === undefined)
183
+ export function startedWhere(runner) {
184
+ if (runner.kind === "launch-machine")
183
185
  return { kind: "launch-machine" };
184
- const { prepared, target } = run.runner;
186
+ const { prepared, target } = runner.session;
185
187
  return {
186
188
  kind: "vercel-sandbox",
187
- team: target.team,
188
- project: target.project,
189
- region: prepared.recipe.region,
190
- runtime: prepared.recipe.runtime,
189
+ team: target?.team ?? null,
190
+ project: target?.project ?? null,
191
+ region: prepared.options.region,
192
+ runtime: prepared.options.runtime,
191
193
  vcpus: prepared.vcpus,
192
194
  base: prepared.base,
193
195
  baseRef: prepared.baseRef,
@@ -216,6 +218,7 @@ export function endedWhere(where, runner) {
216
218
  base: snapshot.base,
217
219
  built: snapshot.kind === "built",
218
220
  builtBehind: snapshot.builtBehind,
221
+ source: snapshot.kind === "reused" ? snapshot.source : null,
219
222
  },
220
223
  keptUntil: runner?.kept?.stopsAt ?? null,
221
224
  uploadBytes: runner?.uploadBytes ?? null,
@@ -1,5 +1,4 @@
1
1
  import type { CheckoutFailure, CheckoutGateway } from "./gateways.ts";
2
- import type { RunnerStepContext } from "./recipe.ts";
3
2
  /** Why one of `baseRefs` gave no base: it doesn't exist locally, or it shares no history with HEAD. */
4
3
  export interface RefusedBaseRef {
5
4
  readonly ref: string;
@@ -33,8 +32,3 @@ export declare function resolveBase(checkout: CheckoutGateway, request: {
33
32
  readonly repoRoot: string;
34
33
  readonly baseRefs: readonly string[];
35
34
  }): Promise<BaseResolution>;
36
- /** The context a recipe's step functions get at `base`: `readBaseFile` rejects for a file the base doesn't have. */
37
- export declare function baseStepContext(checkout: CheckoutGateway, request: {
38
- readonly repoRoot: string;
39
- readonly base: string;
40
- }): RunnerStepContext;
@@ -1,4 +1,4 @@
1
- // The base the runner builds on: HEAD's merge-base with one of the recipe's `baseRefs`, from local refs only.
1
+ // The base the runner builds on: HEAD's merge-base with one of the runner's `baseRefs`, from local refs only.
2
2
  /**
3
3
  * Resolves a run's base from `baseRefs`, local refs only. Of the refs that exist and share history with HEAD, the
4
4
  * newest merge-base wins: a later ref's merge-base replaces the best so far only when the best is its ancestor, so a
@@ -35,18 +35,3 @@ export async function resolveBase(checkout, request) {
35
35
  }
36
36
  return best === undefined ? { kind: "no-base-ref", refs: refused } : { kind: "resolved", ...best };
37
37
  }
38
- /** The context a recipe's step functions get at `base`: `readBaseFile` rejects for a file the base doesn't have. */
39
- export function baseStepContext(checkout, request) {
40
- const { repoRoot, base } = request;
41
- return {
42
- base,
43
- readBaseFile: async (path) => {
44
- const file = await checkout.readFileAt({ repoRoot, commit: base, path });
45
- if (file.kind === "found")
46
- return file.text;
47
- if (file.kind === "missing")
48
- throw new Error(`${path} doesn't exist at ${base.slice(0, 12)}`);
49
- throw new Error(`can't read ${path} at ${base.slice(0, 12)}: ${file.failure.message}`);
50
- },
51
- };
52
- }
@@ -1,31 +1,33 @@
1
1
  import type { SandboxCredential } from "../sdk/extension/index.ts";
2
- import type { RunnerContext } from "./context.ts";
2
+ import { type RunnerContext } from "./context.ts";
3
3
  import type { RunnerFailure, RunnerProgress } from "./events.ts";
4
- import type { CheckoutHead, RunnerSnapshotCacheFailure, RunnerSnapshotEntry, SandboxAccess } from "./gateways.ts";
4
+ import type { CheckoutHead, RunnerSnapshotEntry, RunnerSnapshotIndexFailure, SandboxAccess } from "./gateways.ts";
5
5
  import type { PrepareRunnerOutcome, RunnerPrepareContext } from "./prepare.ts";
6
- import type { CheckedRecipe } from "./recipe.ts";
6
+ import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
7
7
  import { type RunnerScopeFacts } from "./scope.ts";
8
- import { type BaseSnapshotPlan } from "./snapshot-build.ts";
9
- /** What `prepareSnapshotBuild` checks: where, which recipe, and what to build. */
8
+ import { type RunnerSnapshotPlan } from "./snapshot-build.ts";
9
+ /** What `prepareSnapshotBuild` checks: where, which runner, and what to build. */
10
10
  export interface SnapshotBuildRequest {
11
11
  /** The directory the command started in, inside the checkout. */
12
12
  readonly cwd: string;
13
- readonly recipe: CheckedRecipe;
13
+ readonly options: CheckedVercelSandboxOptions;
14
14
  /** The ref `--base` names; undefined builds at the merge-base. */
15
15
  readonly ref: string | undefined;
16
- /** `--full`: build whatever the cache holds. */
16
+ /** `--full`: build whatever the local snapshot index holds. */
17
17
  readonly full: boolean;
18
18
  }
19
19
  /**
20
- * A build, checked on this machine: the base snapshot it builds (`plan`), HEAD, whose `dirty` says the working tree
21
- * has uncommitted changes, which a base snapshot doesn't hold, the ref `--base` named (null for the merge-base), HEAD's
22
- * merge-base and its ref (null for a `--base` build in a checkout where no base ref shares history with HEAD), whether
23
- * the commit it builds at is that merge-base (`atMergeBase`: a run here starts only from a snapshot at its merge-base,
24
- * though a run in another checkout, or after a later merge-base, still might), and the base snapshots of `plan`'s base
25
- * and key the cache holds with more than an hour left (`cached`, before the team and project filter).
20
+ * A build, checked on this machine: the runner snapshot it builds (`plan`), HEAD, whose `dirty` says the working tree
21
+ * has uncommitted changes, which a runner snapshot doesn't hold, the ref `--base` named (null for the merge-base),
22
+ * HEAD's merge-base and its ref (null for a `--base` build in a checkout where no base ref shares history with HEAD),
23
+ * whether the commit it builds at is that merge-base (`atMergeBase`) or an ancestor of it (`ancestorOfMergeBase`, false
24
+ * at the merge-base itself: a run here starts only from a snapshot at its merge-base or at a commit behind it on the
25
+ * base ref, though a run in another checkout, or after a later merge-base, still might), and the runner snapshots of
26
+ * `plan`'s base and key the local snapshot index holds with more than an hour left (`indexed`, at exactly that base,
27
+ * before the team and project filter).
26
28
  */
27
29
  export interface PreparedSnapshotBuild {
28
- readonly plan: BaseSnapshotPlan;
30
+ readonly plan: RunnerSnapshotPlan;
29
31
  readonly head: CheckoutHead;
30
32
  readonly ref: string | null;
31
33
  readonly mergeBase: {
@@ -33,11 +35,12 @@ export interface PreparedSnapshotBuild {
33
35
  readonly ref: string;
34
36
  } | null;
35
37
  readonly atMergeBase: boolean;
36
- readonly cached: readonly RunnerSnapshotEntry[];
38
+ readonly ancestorOfMergeBase: boolean;
39
+ readonly indexed: readonly RunnerSnapshotEntry[];
37
40
  readonly full: boolean;
38
41
  }
39
42
  /**
40
- * How a build's local checks ended: a run's refusals, but `submodules`'s and `invalid-recipe`'s and `checkout-failed`'s
43
+ * How a build's local checks ended: a run's refusals, including `submodules`, `invalid-runner`, and `checkout-failed`
41
44
  * that the build shares, or `ref-not-found` when `--base` names no local commit.
42
45
  */
43
46
  export type PrepareSnapshotBuildOutcome = {
@@ -53,7 +56,8 @@ export type PrepareSnapshotBuildOutcome = {
53
56
  * Runs a build's local checks, before anything is minted or started: the repository's root, HEAD, the submodule
54
57
  * refusal, HEAD's merge-base (`resolveBase`, which refuses with `no-base-ref` only without `--base`), the commit
55
58
  * `--base` resolves to locally, the snapshot steps and key at the commit it builds, the cache's base snapshots of it,
56
- * and, when it builds at the merge-base, HEAD's count of commits after it. It never mints, acquires or creates, and removes no cache file.
59
+ * whether a commit other than the merge-base is an ancestor of it, and, when it builds at the merge-base, HEAD's count
60
+ * of commits after it. It never mints, acquires or creates, and removes no cache file.
57
61
  */
58
62
  export declare function prepareSnapshotBuild(context: RunnerPrepareContext, request: SnapshotBuildRequest): Promise<PrepareSnapshotBuildOutcome>;
59
63
  /** What `buildSnapshots` is handed: the checked build, where its sandboxes run, who starts them, and the credentials. */
@@ -63,32 +67,52 @@ export interface BuildSnapshotsRequest {
63
67
  readonly access: SandboxAccess;
64
68
  /** The local user, for each sandbox's `user` tag. */
65
69
  readonly user: string;
66
- /** The recipe's credentials, with their values: the firewall adds every one while the recipe's snapshot steps run. */
70
+ /** The runner's credentials, with their values: the firewall adds every one while the runner's snapshot steps run. */
67
71
  readonly credentials: readonly Required<SandboxCredential>[];
72
+ /**
73
+ * `--publish`: check the shared snapshot index instead of the local snapshot index, and publish the build there,
74
+ * keeping its build sandbox stopped under the index entry's name. By default it neither reads nor writes the shared
75
+ * snapshot index.
76
+ */
77
+ readonly publish?: boolean;
68
78
  }
69
79
  /**
70
80
  * How a build ended, before its sandbox scope closed.
71
81
  *
72
- * - `up-to-date`: the cache holds `snapshot`, a base snapshot at the commit for the access's team and project, so
73
- * nothing started.
74
- * - `built`: it built `snapshot` in `ms` (`sizeBytes`), and the cache recorded it.
75
- * - `not-cached`: it built `snapshot`, but the cache couldn't write its entry (`failure`), so no run finds it.
76
- * - `failed`: a step, a Sandbox call or the checkout failed.
77
- * - `aborted`: the signal aborted. A base snapshot's save runs to its end once started, so a signal during it still
78
- * leaves a saved snapshot, which `snapshot` names with whether the cache wrote its entry; null when it saved none.
82
+ * - `up-to-date`: the local snapshot index holds `snapshot`, a runner snapshot at the commit for the access's team and
83
+ * project, so nothing started. With `publish`, the shared snapshot index holds it instead, in the stopped sandbox
84
+ * `sandboxName`, and the local snapshot index now records it too, unless the write failed.
85
+ * - `built`: it built `snapshot` in `ms` (`sizeBytes`), and the local snapshot index recorded it. With `publish`, the
86
+ * shared snapshot index holds it in the stopped sandbox `sandboxName`, so a local snapshot index entry that couldn't
87
+ * be written (`localIndexFailure`) doesn't fail the build: a run finds the snapshot in the shared snapshot index.
88
+ * - `already-building`: with `publish`, the index entry's sandbox `sandboxName` already exists with a status a build
89
+ * still owns (`status`; null when another build took the name first while this one started), so nothing started.
90
+ * - `not-indexed`: it built `snapshot`, but the local snapshot index couldn't write its entry (`failure`), so no run
91
+ * finds it.
92
+ * - `failed`: a step, a Sandbox call, or the checkout failed.
93
+ * - `aborted`: the signal aborted. A runner snapshot's save runs to its end once started, so a signal during it still
94
+ * leaves a saved snapshot, which `snapshot` names with whether the local snapshot index wrote its entry; null when it
95
+ * saved none.
79
96
  */
80
97
  export type SnapshotBuildEnd = {
81
98
  readonly kind: "up-to-date";
82
99
  readonly snapshot: RunnerSnapshotEntry;
100
+ readonly sandboxName?: string;
83
101
  } | {
84
102
  readonly kind: "built";
85
103
  readonly snapshot: RunnerSnapshotEntry;
86
104
  readonly ms: number;
87
105
  readonly sizeBytes: number;
106
+ readonly sandboxName?: string;
107
+ readonly localIndexFailure?: RunnerSnapshotIndexFailure;
88
108
  } | {
89
- readonly kind: "not-cached";
109
+ readonly kind: "already-building";
110
+ readonly sandboxName: string;
111
+ readonly status: string | null;
112
+ } | {
113
+ readonly kind: "not-indexed";
90
114
  readonly snapshot: RunnerSnapshotEntry;
91
- readonly failure: RunnerSnapshotCacheFailure;
115
+ readonly failure: RunnerSnapshotIndexFailure;
92
116
  } | {
93
117
  readonly kind: "failed";
94
118
  readonly failure: RunnerFailure;
@@ -96,7 +120,7 @@ export type SnapshotBuildEnd = {
96
120
  readonly kind: "aborted";
97
121
  readonly snapshot: {
98
122
  readonly entry: RunnerSnapshotEntry;
99
- readonly cached: boolean;
123
+ readonly indexed: boolean;
100
124
  } | null;
101
125
  };
102
126
  /** How a build ended (`SnapshotBuildEnd`), with what closing its sandbox scope left (`cleanup`). */
@@ -108,7 +132,9 @@ export type SnapshotBuildOutcome = SnapshotBuildEnd & {
108
132
  * ends, keeping none. A cached base snapshot at the commit for the access's team and project is up to date, unless
109
133
  * `full`, which builds a new one that replaces its cache entry. `signal` cancels it in any stage: the scope says so,
110
134
  * revokes every credential at once, and stops its sandboxes. A base snapshot's save isn't stopped by the signal, so
111
- * after it the build checks the signal once and ends `aborted` with what it saved.
135
+ * after it the build checks the signal once and ends `aborted` with what it saved. With `publish`, it checks the shared
136
+ * snapshot index instead of the cache (`publishIn`), and the build sandbox it saves stays in the project, stopped, as
137
+ * the index entry.
112
138
  */
113
139
  export declare function buildSnapshots(context: RunnerContext, request: BuildSnapshotsRequest, control: {
114
140
  readonly signal: AbortSignal;
@@ -1,22 +1,28 @@
1
- // `storm snapshots build`: building one base snapshot that the runner snapshot cache lacks, with no run: at the
1
+ // `storm snapshots build`: building one runner snapshot that the local snapshot index lacks, with no run: at the
2
2
  // merge-base by default, or at the commit `--base <ref>` names, which a run starts from only once that commit is its
3
- // merge-base. It owns its sandbox scope from its first stage to its end, as a run's runner session does. It
4
- // acquires no resource, runs no command, and keeps no sandbox.
3
+ // merge-base or an ancestor of its merge-base. It owns its sandbox scope from its first stage to its end, as a run's
4
+ // runner session does. It acquires no resource, runs no command, and keeps no running sandbox. With `publish`, it also
5
+ // publishes the build to the shared snapshot index: the build sandbox takes the index entry's name and stays in the
6
+ // project, stopped.
5
7
  import { resolveBase } from "./base.js";
8
+ import { snapshotIndexTags } from "./context.js";
9
+ import { hasTimeLeft, SNAPSHOT_EXPIRATION_MS } from "./local-snapshot-index.js";
6
10
  import { runnerNetworkPolicy } from "./network-policy.js";
7
11
  import { runnerSandboxScope } from "./scope.js";
8
12
  import { buildSnapshot } from "./snapshot-build.js";
9
- import { hasTimeLeft } from "./snapshot-cache.js";
10
- import { snapshotStepsAt } from "./snapshot-key.js";
13
+ import { classifyUnverifiedSharedSandbox, sharedSnapshotBucket, sharedSnapshotSandboxName, usableSharedEntry, } from "./shared-snapshot-entry.js";
14
+ import { snapshotInputsAt } from "./snapshot-key.js";
15
+ import { sandboxApiFailure } from "./steps.js";
11
16
  /**
12
17
  * Runs a build's local checks, before anything is minted or started: the repository's root, HEAD, the submodule
13
18
  * refusal, HEAD's merge-base (`resolveBase`, which refuses with `no-base-ref` only without `--base`), the commit
14
19
  * `--base` resolves to locally, the snapshot steps and key at the commit it builds, the cache's base snapshots of it,
15
- * and, when it builds at the merge-base, HEAD's count of commits after it. It never mints, acquires or creates, and removes no cache file.
20
+ * whether a commit other than the merge-base is an ancestor of it, and, when it builds at the merge-base, HEAD's count
21
+ * of commits after it. It never mints, acquires or creates, and removes no cache file.
16
22
  */
17
23
  export async function prepareSnapshotBuild(context, request) {
18
24
  const { checkout } = context;
19
- const { recipe, ref } = request;
25
+ const { options, ref } = request;
20
26
  const root = await checkout.repositoryRoot({ cwd: request.cwd });
21
27
  if (!root.ok)
22
28
  return { kind: "checkout-failed", failure: root.failure };
@@ -24,7 +30,7 @@ export async function prepareSnapshotBuild(context, request) {
24
30
  const head = await checkout.head({ repoRoot });
25
31
  if (!head.ok)
26
32
  return { kind: "checkout-failed", failure: head.failure };
27
- const resolved = await resolveBase(checkout, { repoRoot, baseRefs: recipe.baseRefs });
33
+ const resolved = await resolveBase(checkout, { repoRoot, baseRefs: options.baseRefs });
28
34
  if (resolved.kind === "failed")
29
35
  return { kind: "checkout-failed", failure: resolved.failure };
30
36
  const mergeBase = resolved.kind === "resolved" ? { commit: resolved.base, ref: resolved.ref } : null;
@@ -47,20 +53,20 @@ export async function prepareSnapshotBuild(context, request) {
47
53
  return { kind: "ref-not-found", ref };
48
54
  base = commit.value;
49
55
  }
50
- const steps = await snapshotStepsAt(checkout, { repoRoot, base, recipe });
51
- if (!steps.ok)
52
- return { kind: "invalid-recipe", path: steps.path, problem: steps.problem };
53
- // An unreadable cache holds nothing to reuse: the build goes on, and builds.
56
+ const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
57
+ if (!inputs.ok)
58
+ return { kind: "invalid-runner", path: inputs.path, problem: inputs.problem };
59
+ // An unreadable local snapshot index holds nothing to reuse: the build goes on, and builds.
54
60
  const listed = await context.runnerSnapshots.listEntries();
55
61
  const now = context.clock.now();
56
- const cached = (listed.ok ? listed.value.entries : []).filter((entry) => entry.base === base &&
57
- entry.recipeName === recipe.name &&
58
- entry.region === recipe.region &&
59
- entry.runtime === recipe.runtime &&
60
- entry.snapshotKey === steps.key &&
62
+ const indexed = (listed.ok ? listed.value.entries : []).filter((entry) => entry.base === base &&
63
+ entry.runnerName === options.name &&
64
+ entry.region === options.region &&
65
+ entry.runtime === options.runtime &&
66
+ entry.snapshotKey === inputs.key &&
61
67
  hasTimeLeft(entry, now));
62
68
  const atMergeBase = base === mergeBase?.commit;
63
- // The built snapshot's count behind HEAD, for a build at the merge-base, the one snapshot a run here starts from.
69
+ // The built snapshot's count behind HEAD, for a build at the merge-base, the snapshot a run here starts from first.
64
70
  let commitsAfterBase = null;
65
71
  if (atMergeBase) {
66
72
  const counted = await checkout.commitCount({ repoRoot, from: base, to: "HEAD" });
@@ -68,23 +74,31 @@ export async function prepareSnapshotBuild(context, request) {
68
74
  return { kind: "checkout-failed", failure: counted.failure };
69
75
  commitsAfterBase = counted.value;
70
76
  }
77
+ // Whether a run here may start from a snapshot at another commit: one behind the merge-base on its base ref's line.
78
+ let ancestorOfMergeBase = false;
79
+ if (!atMergeBase && mergeBase !== null) {
80
+ const contained = await checkout.contains({ repoRoot, ancestor: base, descendant: mergeBase.commit });
81
+ if (!contained.ok)
82
+ return { kind: "checkout-failed", failure: contained.failure };
83
+ ancestorOfMergeBase = contained.value;
84
+ }
71
85
  return {
72
86
  kind: "ok",
73
87
  build: {
74
88
  plan: {
75
- recipe,
89
+ options,
76
90
  repoRoot,
77
91
  base,
78
- toolchains: steps.toolchains,
79
- prebuild: steps.prebuild,
80
- snapshotKey: steps.key,
92
+ baseFiles: inputs.baseFiles,
93
+ snapshotKey: inputs.key,
81
94
  commitsAfterBase,
82
95
  },
83
96
  head: head.value,
84
97
  ref: ref ?? null,
85
98
  mergeBase,
86
99
  atMergeBase,
87
- cached,
100
+ ancestorOfMergeBase,
101
+ indexed,
88
102
  full: request.full,
89
103
  },
90
104
  };
@@ -94,14 +108,16 @@ export async function prepareSnapshotBuild(context, request) {
94
108
  * ends, keeping none. A cached base snapshot at the commit for the access's team and project is up to date, unless
95
109
  * `full`, which builds a new one that replaces its cache entry. `signal` cancels it in any stage: the scope says so,
96
110
  * revokes every credential at once, and stops its sandboxes. A base snapshot's save isn't stopped by the signal, so
97
- * after it the build checks the signal once and ends `aborted` with what it saved.
111
+ * after it the build checks the signal once and ends `aborted` with what it saved. With `publish`, it checks the shared
112
+ * snapshot index instead of the cache (`publishIn`), and the build sandbox it saves stays in the project, stopped, as
113
+ * the index entry.
98
114
  */
99
115
  export async function buildSnapshots(context, request, control, progress) {
100
116
  const { signal } = control;
101
117
  // When the build is canceled, the scope stops its sandboxes and revokes every credential at once.
102
118
  const scope = runnerSandboxScope(context, progress, {
103
119
  keepMs: 0,
104
- basePolicy: runnerNetworkPolicy(request.build.plan.recipe),
120
+ basePolicy: runnerNetworkPolicy(request.build.plan.options),
105
121
  signal,
106
122
  });
107
123
  try {
@@ -118,25 +134,109 @@ async function buildIn(context, request, control, progress) {
118
134
  const { signal } = control;
119
135
  if (signal.aborted)
120
136
  return { kind: "aborted", snapshot: null };
121
- const cached = build.cached.find((entry) => entry.teamId === access.teamId && entry.projectId === access.projectId);
122
- if (!build.full && cached !== undefined)
123
- return { kind: "up-to-date", snapshot: cached };
137
+ if (request.publish === true)
138
+ return await publishIn(context, request, control, progress);
139
+ const indexed = build.indexed.find((entry) => entry.teamId === access.teamId && entry.projectId === access.projectId);
140
+ if (!build.full && indexed !== undefined)
141
+ return { kind: "up-to-date", snapshot: indexed };
142
+ const built = await buildSnapshot(context, { prepared: build.plan, access, user, credentials, why: buildReason(build) }, control, progress);
143
+ if (built.kind === "aborted")
144
+ return { kind: "aborted", snapshot: null };
145
+ if (built.kind !== "ok")
146
+ return built;
147
+ const { entry, localIndexFailure, ms, sizeBytes } = built.value;
148
+ if (signal.aborted)
149
+ return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
150
+ return localIndexFailure === null
151
+ ? { kind: "built", snapshot: entry, ms, sizeBytes }
152
+ : { kind: "not-indexed", snapshot: entry, failure: localIndexFailure };
153
+ }
154
+ /** Why a build builds, for the line that says so. */
155
+ function buildReason(build) {
124
156
  const why = build.full ? "full" : build.ref === null ? "no-snapshot" : "base";
157
+ return why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why };
158
+ }
159
+ /**
160
+ * A published build: it reads the shared snapshot index entry for the plan's base (`sharedSnapshotSandboxName`). An
161
+ * entry whose sandbox a build still owns ends `already-building`. A stopped entry whose snapshot is `created` with
162
+ * more than an hour left is up to date, unless `full`, and the cache records it. Any other entry (expired, gone, not
163
+ * `created`, without a snapshot, failed, or aborted, or any entry under `full`) is deleted to free its name, keeping
164
+ * its snapshot. Then it builds under that name and keeps the build sandbox stopped as the new entry.
165
+ */
166
+ async function publishIn(context, request, control, progress) {
167
+ const { build, access, user, credentials } = request;
168
+ const { plan } = build;
169
+ const { options } = plan;
170
+ const { signal } = control;
171
+ const { runnerSandboxes } = context;
172
+ const bucket = sharedSnapshotBucket({
173
+ teamId: access.teamId,
174
+ projectId: access.projectId,
175
+ region: options.region,
176
+ runtime: options.runtime,
177
+ runnerName: options.name,
178
+ snapshotKey: plan.snapshotKey,
179
+ });
180
+ const name = sharedSnapshotSandboxName(bucket, plan.base);
181
+ const found = await runnerSandboxes.getNamedSandbox(access, { name }, signal);
182
+ if (!found.ok)
183
+ return callStop("get-named-sandbox", found.failure);
184
+ if (found.value.kind === "found") {
185
+ const { sandbox } = found.value;
186
+ const unverified = classifyUnverifiedSharedSandbox(sandbox);
187
+ if (unverified.kind === "settled" && unverified.status === "building")
188
+ return { kind: "already-building", sandboxName: name, status: sandbox.status };
189
+ if (!build.full && unverified.kind === "needs-snapshot") {
190
+ const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
191
+ if (!verified.ok)
192
+ return callStop("get-snapshot", verified.failure);
193
+ const entry = verified.value.kind === "found"
194
+ ? usableSharedEntry(access, options, plan.snapshotKey, plan.base, sandbox, verified.value.snapshot, context.clock.now())
195
+ : null;
196
+ if (entry !== null) {
197
+ // Best effort: a run that misses the cache finds the snapshot in the index.
198
+ const written = await context.runnerSnapshots.writeEntry(entry);
199
+ if (!written.ok)
200
+ await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
201
+ return { kind: "up-to-date", snapshot: entry, sandboxName: name };
202
+ }
203
+ }
204
+ const removed = await runnerSandboxes.deleteNamedSandbox(access, { name }, signal);
205
+ if (!removed.ok)
206
+ return callStop("delete-named-sandbox", removed.failure);
207
+ }
208
+ if (signal.aborted)
209
+ return { kind: "aborted", snapshot: null };
210
+ const expiresAt = new Date(context.clock.now().getTime() + SNAPSHOT_EXPIRATION_MS).toISOString();
125
211
  const built = await buildSnapshot(context, {
126
- prepared: build.plan,
212
+ prepared: plan,
127
213
  access,
128
214
  user,
129
215
  credentials,
130
- why: why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why },
216
+ why: buildReason(build),
217
+ publish: { name, tags: snapshotIndexTags(options.name, user, plan.base, expiresAt) },
131
218
  }, control, progress);
219
+ if (built.kind === "name-taken")
220
+ return { kind: "already-building", sandboxName: name, status: null };
132
221
  if (built.kind === "aborted")
133
222
  return { kind: "aborted", snapshot: null };
134
223
  if (built.kind !== "ok")
135
224
  return built;
136
- const { entry, cacheFailure, ms, sizeBytes } = built.value;
225
+ const { entry, localIndexFailure, ms, sizeBytes } = built.value;
137
226
  if (signal.aborted)
138
- return { kind: "aborted", snapshot: { entry, cached: cacheFailure === null } };
139
- return cacheFailure === null
140
- ? { kind: "built", snapshot: entry, ms, sizeBytes }
141
- : { kind: "not-cached", snapshot: entry, failure: cacheFailure };
227
+ return { kind: "aborted", snapshot: { entry, indexed: localIndexFailure === null } };
228
+ return {
229
+ kind: "built",
230
+ snapshot: entry,
231
+ ms,
232
+ sizeBytes,
233
+ sandboxName: name,
234
+ ...(localIndexFailure === null ? {} : { localIndexFailure }),
235
+ };
236
+ }
237
+ /** How a build ends on a failed Sandbox call about the index entry: aborted for the signal, failed otherwise. */
238
+ function callStop(operation, failure) {
239
+ return failure.kind === "aborted"
240
+ ? { kind: "aborted", snapshot: null }
241
+ : { kind: "failed", failure: sandboxApiFailure(operation, failure) };
142
242
  }
@@ -1,13 +1,21 @@
1
1
  import type { Timer } from "../time/index.ts";
2
2
  import type { RunnerSandboxGateway, RunnerSandboxRole, RunnerTerminal } from "./gateways.ts";
3
- import type { SnapshotCacheContext } from "./snapshot-cache.ts";
4
- /** The runner's gateways and seams: the checkout, the cache, Vercel Sandbox, the terminal, the clock and the timer. */
5
- export interface RunnerContext extends SnapshotCacheContext {
3
+ import type { LocalSnapshotIndexContext } from "./local-snapshot-index.ts";
4
+ /**
5
+ * The runner's gateways and seams: the checkout, the local snapshot index, Vercel Sandbox, the terminal, the clock,
6
+ * and the timer.
7
+ */
8
+ export interface RunnerContext extends LocalSnapshotIndexContext {
6
9
  readonly runnerSandboxes: RunnerSandboxGateway;
7
10
  readonly runnerTerminal: RunnerTerminal;
8
11
  readonly timer: Timer;
9
12
  }
10
- /** The `purpose` tag of a recipe's sandboxes. */
11
- export declare function runnerPurpose(recipeName: string): string;
12
- /** The tags of a sandbox: the recipe's `purpose`, the local `user` who started it, and its `role`. */
13
- export declare function runnerTags(recipeName: string, role: RunnerSandboxRole, user: string): Readonly<Record<string, string>>;
13
+ /** The `purpose` tag of a Vercel Sandbox runner's sandboxes. */
14
+ export declare function runnerPurpose(runnerName: string): string;
15
+ /** The tags of a sandbox: the runner's `purpose`, the local `user` who started it, and its `role`. */
16
+ export declare function runnerTags(runnerName: string, role: RunnerSandboxRole, user: string): Readonly<Record<string, string>>;
17
+ /**
18
+ * The 5 tags of a named build sandbox kept stopped as a shared snapshot index entry: the runner's `purpose`, the
19
+ * `user` who built it, `role: "snapshot-index"`, its `base` commit SHA, and `expires-at`.
20
+ */
21
+ export declare function snapshotIndexTags(runnerName: string, user: string, base: string, expiresAt: string): Readonly<Record<string, string>>;
@@ -1,10 +1,23 @@
1
1
  // What the runner reaches the world through as it readies and uses a runner sandbox, and the tags every sandbox it
2
2
  // creates carries.
3
- /** The `purpose` tag of a recipe's sandboxes. */
4
- export function runnerPurpose(recipeName) {
5
- return `storm-runner-${recipeName}`;
3
+ /** The `purpose` tag of a Vercel Sandbox runner's sandboxes. */
4
+ export function runnerPurpose(runnerName) {
5
+ return `storm-runner-${runnerName}`;
6
6
  }
7
- /** The tags of a sandbox: the recipe's `purpose`, the local `user` who started it, and its `role`. */
8
- export function runnerTags(recipeName, role, user) {
9
- return { purpose: runnerPurpose(recipeName), user, role };
7
+ /** The tags of a sandbox: the runner's `purpose`, the local `user` who started it, and its `role`. */
8
+ export function runnerTags(runnerName, role, user) {
9
+ return { purpose: runnerPurpose(runnerName), user, role };
10
+ }
11
+ /**
12
+ * The 5 tags of a named build sandbox kept stopped as a shared snapshot index entry: the runner's `purpose`, the
13
+ * `user` who built it, `role: "snapshot-index"`, its `base` commit SHA, and `expires-at`.
14
+ */
15
+ export function snapshotIndexTags(runnerName, user, base, expiresAt) {
16
+ return {
17
+ purpose: runnerPurpose(runnerName),
18
+ user,
19
+ role: "snapshot-index",
20
+ base,
21
+ "expires-at": expiresAt,
22
+ };
10
23
  }