@cnc-tools/storm 0.16.0 → 0.18.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 (290) hide show
  1. package/dist/bin/storm.js +54 -40
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-24UYAK4R.js} +465 -365
  4. package/dist/chunks/{chunk-DC2CDHNK.js → chunk-2JMWUKH3.js} +2074 -473
  5. package/dist/chunks/{chunk-FOZWA52V.js → chunk-3VXZONGE.js} +481 -376
  6. package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-55O4FCN4.js} +1 -1
  7. package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
  8. package/dist/chunks/chunk-AS37D43E.js +2173 -0
  9. package/dist/chunks/chunk-CQAY6GLP.js +1260 -0
  10. package/dist/chunks/chunk-DZLU7BYK.js +340 -0
  11. package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
  12. package/dist/chunks/{chunk-TJNFVNKR.js → chunk-EI3XDCEI.js} +1 -1
  13. package/dist/chunks/{chunk-HVNK3I45.js → chunk-FDUY3BNF.js} +1 -1
  14. package/dist/chunks/{chunk-FCQUJDA4.js → chunk-GUCCYCIO.js} +4 -189
  15. package/dist/chunks/{chunk-OIY3DMF2.js → chunk-HBI4LEMH.js} +3 -3
  16. package/dist/chunks/{chunk-2MAD5NKK.js → chunk-K4MDQPLW.js} +1 -18
  17. package/dist/chunks/chunk-KK7PAWIZ.js +198 -0
  18. package/dist/chunks/{chunk-G3PHMXH5.js → chunk-KQ5FXRUD.js} +18 -1
  19. package/dist/chunks/{chunk-5VXBKPW6.js → chunk-LKXHGGGX.js} +1 -1
  20. package/dist/chunks/{chunk-P357TZAY.js → chunk-LOGHIUUB.js} +21 -18
  21. package/dist/chunks/{chunk-CK2GZEPK.js → chunk-OEPFINFT.js} +2 -2
  22. package/dist/chunks/{chunk-DWEAHX4T.js → chunk-OI4AP6Z7.js} +5 -5
  23. package/dist/chunks/{chunk-V4IKA3WI.js → chunk-PMBQWVTW.js} +26 -19
  24. package/dist/chunks/chunk-SZMYIIG2.js +88 -0
  25. package/dist/chunks/{chunk-5CCP36QQ.js → chunk-TXCOFC7N.js} +1 -1
  26. package/dist/chunks/{chunk-VUPZH7J2.js → chunk-UXD3TVWM.js} +1 -1
  27. package/dist/chunks/{chunk-3L52KNQA.js → chunk-WNW2QXQK.js} +8 -8
  28. package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
  29. package/dist/chunks/{live-app-WECQOQ4C.js → live-app-UY7BEDUN.js} +17 -13
  30. package/dist/cli.d.ts +28 -0
  31. package/dist/cli.js +64 -0
  32. package/dist/commands/exec/across-sandboxes-outcomes.d.ts +2 -2
  33. package/dist/commands/exec/across-sandboxes-outcomes.js +3 -3
  34. package/dist/commands/exec/before-run.d.ts +123 -0
  35. package/dist/commands/exec/before-run.js +105 -0
  36. package/dist/commands/exec/command.d.ts +67 -14
  37. package/dist/commands/exec/command.js +31 -95
  38. package/dist/commands/exec/driver-plan.d.ts +9 -4
  39. package/dist/commands/exec/driver-plan.js +8 -8
  40. package/dist/commands/exec/exec-words.js +1 -1
  41. package/dist/commands/exec/execute-run.d.ts +39 -0
  42. package/dist/commands/exec/execute-run.js +325 -0
  43. package/dist/commands/exec/live-view.d.ts +3 -3
  44. package/dist/commands/exec/live-view.js +16 -15
  45. package/dist/commands/exec/metadata.js +1 -1
  46. package/dist/commands/exec/mint-failed.d.ts +38 -0
  47. package/dist/commands/exec/mint-failed.js +27 -4
  48. package/dist/commands/exec/outcomes.d.ts +104 -22
  49. package/dist/commands/exec/outcomes.js +73 -26
  50. package/dist/commands/exec/plan-run.d.ts +58 -150
  51. package/dist/commands/exec/plan-run.js +239 -90
  52. package/dist/commands/exec/progress.d.ts +10 -6
  53. package/dist/commands/exec/progress.js +38 -25
  54. package/dist/commands/exec/run-bin.d.ts +11 -11
  55. package/dist/commands/exec/run-bin.js +9 -9
  56. package/dist/commands/exec/run-flags.d.ts +69 -0
  57. package/dist/commands/exec/run-flags.js +58 -0
  58. package/dist/commands/exec/run-metadata.js +4 -4
  59. package/dist/commands/exec/run-summary.d.ts +58 -0
  60. package/dist/commands/exec/run-summary.js +205 -0
  61. package/dist/commands/exec/runner-refusals.d.ts +82 -0
  62. package/dist/commands/exec/runner-refusals.js +71 -0
  63. package/dist/commands/exec/sandbox-progress.js +3 -0
  64. package/dist/commands/exec/stopped-outcome.d.ts +12 -0
  65. package/dist/commands/exec/stopped-outcome.js +77 -0
  66. package/dist/commands/exec/view.d.ts +20 -11
  67. package/dist/commands/exec/view.js +103 -47
  68. package/dist/commands/runs/facts.d.ts +8 -4
  69. package/dist/commands/runs/facts.js +19 -10
  70. package/dist/commands/runs/list/command.d.ts +16 -8
  71. package/dist/commands/runs/list/command.js +10 -10
  72. package/dist/commands/runs/list/outcomes.d.ts +8 -4
  73. package/dist/commands/runs/logs/command.js +10 -10
  74. package/dist/commands/runs/show/command.d.ts +16 -8
  75. package/dist/commands/runs/show/command.js +31 -29
  76. package/dist/commands/runs/show/metadata.js +1 -1
  77. package/dist/commands/runs/show/outcomes.d.ts +8 -4
  78. package/dist/commands/runs/show/outcomes.js +8 -6
  79. package/dist/commands/snapshots/access.d.ts +111 -0
  80. package/dist/commands/snapshots/access.js +96 -0
  81. package/dist/commands/snapshots/build/command.d.ts +376 -101
  82. package/dist/commands/snapshots/build/command.js +447 -149
  83. package/dist/commands/snapshots/build/metadata.d.ts +10 -0
  84. package/dist/commands/snapshots/build/metadata.js +31 -11
  85. package/dist/commands/snapshots/build/outcomes.d.ts +242 -47
  86. package/dist/commands/snapshots/build/outcomes.js +200 -36
  87. package/dist/commands/snapshots/list/command.d.ts +368 -27
  88. package/dist/commands/snapshots/list/command.js +298 -68
  89. package/dist/commands/snapshots/list/metadata.d.ts +16 -0
  90. package/dist/commands/snapshots/list/metadata.js +29 -6
  91. package/dist/commands/snapshots/list/outcomes.d.ts +247 -15
  92. package/dist/commands/snapshots/list/outcomes.js +223 -52
  93. package/dist/commands/snapshots/metadata.js +1 -1
  94. package/dist/commands/snapshots/prune/command.d.ts +430 -0
  95. package/dist/commands/snapshots/prune/command.js +161 -0
  96. package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
  97. package/dist/commands/snapshots/prune/metadata.js +39 -0
  98. package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
  99. package/dist/commands/snapshots/prune/outcomes.js +78 -0
  100. package/dist/commands/suites/list/command.js +17 -17
  101. package/dist/commands/suites/list/outcomes.js +2 -2
  102. package/dist/commands/test/command.d.ts +67 -14
  103. package/dist/commands/test/command.js +49 -252
  104. package/dist/commands/test/outcomes.d.ts +33 -7
  105. package/dist/config/check-runner.d.ts +3 -3
  106. package/dist/config/check-runner.js +8 -7
  107. package/dist/config/credential-resolver.d.ts +50 -5
  108. package/dist/config/credential-resolver.js +51 -19
  109. package/dist/config/credential-settle.d.ts +6 -2
  110. package/dist/config/credential-settle.js +11 -5
  111. package/dist/config/index.d.ts +2 -2
  112. package/dist/config/index.js +1 -1
  113. package/dist/config/runner.d.ts +5 -5
  114. package/dist/config/runner.js +1 -1
  115. package/dist/config/schema.d.ts +2 -2
  116. package/dist/config/schema.js +1 -1
  117. package/dist/config-file/define.d.ts +1 -1
  118. package/dist/config-file/define.js +1 -1
  119. package/dist/config-file/runner.d.ts +5 -5
  120. package/dist/config-file/toolchain.d.ts +14 -4
  121. package/dist/config-file/toolchain.js +43 -7
  122. package/dist/context.d.ts +10 -6
  123. package/dist/context.js +8 -6
  124. package/dist/core/across-sandboxes.d.ts +7 -6
  125. package/dist/core/across-sandboxes.js +123 -152
  126. package/dist/core/coordinator.d.ts +166 -0
  127. package/dist/core/coordinator.js +233 -0
  128. package/dist/core/events.d.ts +2 -2
  129. package/dist/core/index.d.ts +4 -2
  130. package/dist/core/index.js +1 -1
  131. package/dist/core/outcomes.d.ts +148 -0
  132. package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
  133. package/dist/core/resources.d.ts +31 -53
  134. package/dist/core/resources.js +32 -70
  135. package/dist/core/run-state.d.ts +7 -1
  136. package/dist/core/run-state.js +2 -0
  137. package/dist/core/run.d.ts +32 -236
  138. package/dist/core/run.js +107 -267
  139. package/dist/core/state-directory.d.ts +1 -1
  140. package/dist/core/state-directory.js +2 -2
  141. package/dist/credential/gateways.d.ts +15 -1
  142. package/dist/credential/index.d.ts +4 -3
  143. package/dist/credential/index.js +3 -2
  144. package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
  145. package/dist/credential/live/vercel-cli-gateway.js +1 -1
  146. package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
  147. package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
  148. package/dist/credential/source.d.ts +73 -6
  149. package/dist/credential/source.js +55 -2
  150. package/dist/extension-commands.d.ts +1 -1
  151. package/dist/extension-commands.js +2 -2
  152. package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
  153. package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
  154. package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
  155. package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
  156. package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
  157. package/dist/extensions/testserver/credential-facts.d.ts +6 -2
  158. package/dist/extensions/testserver/credential-facts.js +29 -11
  159. package/dist/extensions/testserver/lifecycle.js +7 -1
  160. package/dist/extensions/testserver/limit.d.ts +3 -0
  161. package/dist/extensions/testserver/limit.js +3 -0
  162. package/dist/extensions/testserver/provision.d.ts +8 -1
  163. package/dist/extensions/testserver/provision.js +8 -3
  164. package/dist/extensions/testserver/refusals.d.ts +6 -1
  165. package/dist/extensions/testserver/refusals.js +16 -1
  166. package/dist/extensions/testserver/resource.d.ts +1 -1
  167. package/dist/extensions/testserver/resource.js +1 -1
  168. package/dist/extensions/testserver/result.d.ts +1 -1
  169. package/dist/extensions/testserver/result.js +9 -4
  170. package/dist/planning/driver-file-lists.d.ts +0 -15
  171. package/dist/planning/driver-file-lists.js +2 -21
  172. package/dist/planning/plan-only.d.ts +3 -14
  173. package/dist/planning/plan-only.js +11 -20
  174. package/dist/planning/run-kind-flags.js +2 -2
  175. package/dist/planning/run-plan.d.ts +45 -12
  176. package/dist/planning/run-plan.js +4 -3
  177. package/dist/planning/suites.d.ts +1 -1
  178. package/dist/planning/suites.js +2 -2
  179. package/dist/planning/test-plan.d.ts +9 -0
  180. package/dist/planning/test-plan.js +9 -0
  181. package/dist/run-directory/recording.js +3 -3
  182. package/dist/run-directory/run-record.d.ts +26 -11
  183. package/dist/run-directory/run-record.js +16 -13
  184. package/dist/runner/base.js +1 -1
  185. package/dist/runner/build-snapshots.d.ts +60 -29
  186. package/dist/runner/build-snapshots.js +136 -29
  187. package/dist/runner/context.d.ts +15 -7
  188. package/dist/runner/context.js +19 -6
  189. package/dist/runner/events.d.ts +16 -10
  190. package/dist/runner/gateways.d.ts +122 -23
  191. package/dist/runner/gateways.js +1 -1
  192. package/dist/runner/gh.d.ts +42 -0
  193. package/dist/runner/gh.js +58 -0
  194. package/dist/runner/index.d.ts +13 -8
  195. package/dist/runner/index.js +12 -6
  196. package/dist/runner/live/checkout-gateway.js +7 -0
  197. package/dist/runner/live/gh-output.d.ts +17 -0
  198. package/dist/runner/live/gh-output.js +37 -0
  199. package/dist/runner/live/gh-token-gateway.d.ts +13 -0
  200. package/dist/runner/live/gh-token-gateway.js +51 -0
  201. package/dist/runner/live/sandbox-errors.d.ts +2 -0
  202. package/dist/runner/live/sandbox-errors.js +4 -0
  203. package/dist/runner/live/sandbox-gateway.js +140 -4
  204. package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
  205. package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
  206. package/dist/runner/live/snapshot-records.js +12 -12
  207. package/dist/runner/local-snapshot-index.d.ts +205 -0
  208. package/dist/runner/local-snapshot-index.js +210 -0
  209. package/dist/runner/network-policy.d.ts +6 -6
  210. package/dist/runner/network-policy.js +7 -7
  211. package/dist/runner/policy-writes.d.ts +1 -1
  212. package/dist/runner/policy-writes.js +1 -1
  213. package/dist/runner/prepare.d.ts +14 -14
  214. package/dist/runner/prepare.js +20 -11
  215. package/dist/runner/ready.d.ts +19 -11
  216. package/dist/runner/ready.js +104 -33
  217. package/dist/runner/sandboxed-command.d.ts +3 -3
  218. package/dist/runner/sandboxed-command.js +3 -3
  219. package/dist/runner/scope.d.ts +15 -8
  220. package/dist/runner/scope.js +16 -5
  221. package/dist/runner/secrets.d.ts +41 -18
  222. package/dist/runner/secrets.js +226 -30
  223. package/dist/runner/session.d.ts +8 -8
  224. package/dist/runner/session.js +6 -3
  225. package/dist/runner/shared-snapshot-entry.d.ts +92 -0
  226. package/dist/runner/shared-snapshot-entry.js +168 -0
  227. package/dist/runner/shared-snapshot-list.d.ts +81 -0
  228. package/dist/runner/shared-snapshot-list.js +155 -0
  229. package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
  230. package/dist/runner/shared-snapshot-lookup.js +118 -0
  231. package/dist/runner/shared-snapshot-prune.d.ts +58 -0
  232. package/dist/runner/shared-snapshot-prune.js +133 -0
  233. package/dist/runner/snapshot-build.d.ts +42 -14
  234. package/dist/runner/snapshot-build.js +79 -47
  235. package/dist/runner/snapshot-choice.js +2 -1
  236. package/dist/runner/snapshot-inspect.d.ts +39 -40
  237. package/dist/runner/snapshot-inspect.js +52 -35
  238. package/dist/runner/snapshot-key.d.ts +32 -17
  239. package/dist/runner/snapshot-key.js +43 -18
  240. package/dist/runner/snapshot-source.d.ts +31 -0
  241. package/dist/runner/snapshot-source.js +122 -0
  242. package/dist/runner/steps.d.ts +1 -1
  243. package/dist/runner/steps.js +1 -1
  244. package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +4 -2
  245. package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +7 -2
  246. package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +59 -28
  247. package/dist/runner/{recipe.js → vercel-sandbox-options.js} +128 -84
  248. package/dist/runner/vercel-sandbox-secrets.d.ts +116 -0
  249. package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +159 -26
  250. package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
  251. package/dist/sdk/extension/credential-diagnosis.js +25 -5
  252. package/dist/sdk/extension/credential-source.d.ts +20 -3
  253. package/dist/sdk/extension/credential-source.js +4 -4
  254. package/dist/sdk/extension/index.d.ts +3 -2
  255. package/dist/sdk/extension/index.js +2 -1
  256. package/dist/sdk/extension/resource-definition.d.ts +1 -1
  257. package/dist/sdk/extension/secret-source.d.ts +1 -1
  258. package/dist/sdk/extension/secret-source.js +1 -1
  259. package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
  260. package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
  261. package/dist/shared/cleanup.d.ts +3 -3
  262. package/dist/shared/cleanup.js +15 -5
  263. package/dist/shared/snapshot-text.d.ts +4 -4
  264. package/dist/shared/snapshot-text.js +11 -11
  265. package/dist/time/duration.js +1 -1
  266. package/package.json +5 -3
  267. package/skills/overview.md +4 -4
  268. package/skills/plan-runs.md +1 -1
  269. package/skills/read-run-output.md +6 -6
  270. package/dist/application.d.ts +0 -21
  271. package/dist/application.js +0 -30
  272. package/dist/chunks/chunk-7EENF73W.js +0 -782
  273. package/dist/chunks/chunk-Z5PBVG3Y.js +0 -2599
  274. package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
  275. package/dist/commands/exec/across-sandboxes-run.js +0 -339
  276. package/dist/commands/exec/plan-only.d.ts +0 -10
  277. package/dist/commands/exec/plan-only.js +0 -45
  278. package/dist/commands/exec/run-command.d.ts +0 -475
  279. package/dist/commands/exec/run-command.js +0 -603
  280. package/dist/commands/exec/run-planned.d.ts +0 -20
  281. package/dist/commands/exec/run-planned.js +0 -22
  282. package/dist/commands/exec/sandbox-view.d.ts +0 -19
  283. package/dist/commands/exec/sandbox-view.js +0 -72
  284. package/dist/commands/test/plan.d.ts +0 -92
  285. package/dist/commands/test/plan.js +0 -125
  286. package/dist/core/sandbox-end.d.ts +0 -64
  287. package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
  288. package/dist/runner/recipe-secrets.d.ts +0 -67
  289. package/dist/runner/snapshot-cache.d.ts +0 -148
  290. package/dist/runner/snapshot-cache.js +0 -126
@@ -0,0 +1,210 @@
1
+ // Which runner snapshots in the local snapshot index a run may start from, and which one it picks. The index's files
2
+ // are the gateway's; their identity, expiry, and the choice among them are here: a run's path removes expired entries'
3
+ // files (`removeExpiredEntries`), and the classification of a list of entries changes no file
4
+ // (`classifySnapshotEntries`).
5
+ import { createHash } from "node:crypto";
6
+ /** The subpath of storm's state directory that holds the local snapshot index. */
7
+ export const RUNNER_SNAPSHOTS_SUBPATH = ["runner", "snapshots"];
8
+ /** How long a runner snapshot lives after it is built: 7 days. The Sandbox API needs 0 or at least a day. */
9
+ export const SNAPSHOT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000;
10
+ /** A run never picks a runner snapshot with this little left or less, 1 hour, so it can't expire before the start. */
11
+ export const SNAPSHOT_MIN_REMAINING_MS = 60 * 60 * 1000;
12
+ /** Whether two runner targets share the same snapshot scope (`name`, `region`, and `image`). */
13
+ export function sameRunnerTarget(a, b) {
14
+ return a.name === b.name && a.region === b.region && a.image === b.image;
15
+ }
16
+ /** Whether local snapshot index `entry` belongs to runner `target`. */
17
+ export function matchesRunnerTarget(entry, target) {
18
+ return sameRunnerTarget({ name: entry.runnerName, region: entry.region, image: entry.image }, target);
19
+ }
20
+ /**
21
+ * An entry's identity: the first 32 hex characters of sha256 over its team id, project id, region, image, runner
22
+ * name, snapshot key, and base, joined with NUL. Entries with one identity replace each other, so a team and project
23
+ * have one entry per runner, key, and base.
24
+ */
25
+ export function snapshotEntryIdentity(entry) {
26
+ return createHash("sha256")
27
+ .update([entry.teamId, entry.projectId, entry.region, entry.image, entry.runnerName, entry.snapshotKey, entry.base].join("\0"))
28
+ .digest("hex")
29
+ .slice(0, 32);
30
+ }
31
+ /** The name of the file that records `entry`: its identity and `.json`. */
32
+ export function snapshotEntryFileName(entry) {
33
+ return `${snapshotEntryIdentity(entry)}.json`;
34
+ }
35
+ /** Whether `entry`'s snapshot has expired at `now`. */
36
+ export function isExpiredEntry(entry, now) {
37
+ return Date.parse(entry.expiresAt) <= now.getTime();
38
+ }
39
+ /** Whether `entry`'s snapshot has more than `SNAPSHOT_MIN_REMAINING_MS` left at `now`. */
40
+ export function hasTimeLeft(entry, now) {
41
+ return Date.parse(entry.expiresAt) - now.getTime() > SNAPSHOT_MIN_REMAINING_MS;
42
+ }
43
+ /**
44
+ * Lists the local snapshot index and removes the files of expired entries, as a run's read does before it classifies
45
+ * the rest (`classifySnapshotEntries`). It gives the unexpired entries, and notes `expired-entry-not-removed` for a
46
+ * file it couldn't remove, whose entry it leaves out all the same. An index it can't list is empty, with the note
47
+ * `local-index-unreadable`. Only a run's path calls it: `storm snapshots list` removes no file.
48
+ */
49
+ export async function removeExpiredEntries(context) {
50
+ const { runnerSnapshots } = context;
51
+ const listed = await runnerSnapshots.listEntries();
52
+ if (!listed.ok)
53
+ return { entries: [], notes: [{ kind: "local-index-unreadable", failure: listed.failure }] };
54
+ const now = context.clock.now();
55
+ const entries = [];
56
+ const notes = [];
57
+ for (const entry of listed.value.entries) {
58
+ if (!isExpiredEntry(entry, now)) {
59
+ entries.push(entry);
60
+ continue;
61
+ }
62
+ const removed = await runnerSnapshots.removeEntry(entry);
63
+ if (!removed.ok)
64
+ notes.push({ kind: "expired-entry-not-removed", entry, failure: removed.failure });
65
+ }
66
+ return { entries, notes };
67
+ }
68
+ /**
69
+ * Checks which non-merge-base commits among `entries` (for `options`, unexpired with time left) are ancestors of
70
+ * `mergeBase`, returning each qualifying ancestor's commit distance behind `mergeBase`. Each distinct base SHA is
71
+ * queried in Git at most once.
72
+ */
73
+ export async function resolveAncestorDistances(context, request) {
74
+ const { checkout, clock } = context;
75
+ const { repoRoot, entries, options, mergeBase } = request;
76
+ const now = clock.now();
77
+ const seen = new Set([mergeBase]);
78
+ const distances = {};
79
+ for (const entry of entries) {
80
+ if (!matchesRunnerTarget(entry, options))
81
+ continue;
82
+ if (isExpiredEntry(entry, now) || !hasTimeLeft(entry, now))
83
+ continue;
84
+ if (seen.has(entry.base))
85
+ continue;
86
+ seen.add(entry.base);
87
+ const contained = await checkout.contains({ repoRoot, ancestor: entry.base, descendant: mergeBase });
88
+ if (!contained.ok)
89
+ return contained;
90
+ if (!contained.value)
91
+ continue;
92
+ const behindMergeBase = await checkout.commitCount({ repoRoot, from: entry.base, to: mergeBase });
93
+ if (!behindMergeBase.ok)
94
+ return behindMergeBase;
95
+ distances[entry.base] = behindMergeBase.value;
96
+ }
97
+ return { ok: true, value: distances };
98
+ }
99
+ /**
100
+ * Classifies `entries`, cache entries a caller listed, for a run of `options`: which ones it may start from, and why
101
+ * not from each other one of the runner's. It changes no file and asks Git nothing. Of the entries for the runner's
102
+ * region, image, and name, it keeps the ones with more than an hour left whose base is the run's merge-base (or an
103
+ * ancestor in `ancestorDistances`) and whose snapshot key is the run's. Candidates are sorted by
104
+ * `commitsBehindMergeBase` ascending, newest `createdAt` descending, and `snapshotId` ascending. Every other entry of
105
+ * the runner is `rejected`, with the first reason that rules it out, an expired one as `expired`. Each entry gets
106
+ * exactly one verdict, in the order given.
107
+ */
108
+ export function classifySnapshotEntries(context, request) {
109
+ const { entries, options, base, snapshotKey, commitsAfterBase, ancestorDistances } = request;
110
+ const now = context.clock.now();
111
+ const candidates = [];
112
+ const rejected = [];
113
+ const verdicts = [];
114
+ const reject = (entry, reason) => {
115
+ const rejection = { entry, reason };
116
+ rejected.push(rejection);
117
+ verdicts.push({ kind: "rejected", entry, rejection });
118
+ };
119
+ for (const entry of entries) {
120
+ if (!matchesRunnerTarget(entry, options)) {
121
+ verdicts.push({ kind: "other-runner", entry });
122
+ continue;
123
+ }
124
+ if (isExpiredEntry(entry, now)) {
125
+ reject(entry, "expired");
126
+ continue;
127
+ }
128
+ if (!hasTimeLeft(entry, now)) {
129
+ reject(entry, "expires-soon");
130
+ continue;
131
+ }
132
+ const commitsBehindMergeBase = entry.base === base
133
+ ? 0
134
+ : ancestorDistances !== undefined && Object.hasOwn(ancestorDistances, entry.base)
135
+ ? ancestorDistances[entry.base]
136
+ : undefined;
137
+ if (commitsBehindMergeBase === undefined) {
138
+ reject(entry, "other-base");
139
+ continue;
140
+ }
141
+ if (entry.snapshotKey !== snapshotKey) {
142
+ reject(entry, "steps-changed");
143
+ continue;
144
+ }
145
+ const candidate = {
146
+ entry,
147
+ builtBehind: commitsAfterBase + commitsBehindMergeBase,
148
+ commitsBehindMergeBase,
149
+ };
150
+ candidates.push(candidate);
151
+ verdicts.push({ kind: "candidate", entry, candidate });
152
+ }
153
+ candidates.sort((a, b) => compareSnapshotCandidates({
154
+ commitsBehindMergeBase: a.commitsBehindMergeBase,
155
+ createdAt: a.entry.createdAt,
156
+ tieBreaker: a.entry.snapshotId,
157
+ }, {
158
+ commitsBehindMergeBase: b.commitsBehindMergeBase,
159
+ createdAt: b.entry.createdAt,
160
+ tieBreaker: b.entry.snapshotId,
161
+ }));
162
+ return { candidates, rejected, verdicts };
163
+ }
164
+ /** Parses an ISO timestamp to milliseconds since epoch, or `-Infinity` when unparseable. */
165
+ export function parseTimestampMs(iso) {
166
+ const ms = Date.parse(iso);
167
+ return Number.isNaN(ms) ? Number.NEGATIVE_INFINITY : ms;
168
+ }
169
+ /**
170
+ * Orders snapshot candidates by preference: fewest commits behind the merge-base first, then newest `createdAt`,
171
+ * then ascending tie-breaker (`snapshotId` or `sandboxName`).
172
+ */
173
+ export function compareSnapshotCandidates(a, b) {
174
+ if (a.commitsBehindMergeBase !== b.commitsBehindMergeBase) {
175
+ return a.commitsBehindMergeBase - b.commitsBehindMergeBase;
176
+ }
177
+ const aCreated = parseTimestampMs(a.createdAt);
178
+ const bCreated = parseTimestampMs(b.createdAt);
179
+ if (aCreated !== bCreated)
180
+ return bCreated - aCreated;
181
+ return a.tieBreaker < b.tieBreaker ? -1 : a.tieBreaker > b.tieBreaker ? 1 : 0;
182
+ }
183
+ /**
184
+ * Whether a shared snapshot index entry `sharedCommitsBehindMergeBase` commits behind the run's merge-base beats the
185
+ * local snapshot index's pick, `localCommitsBehindMergeBase` behind it (undefined when the local snapshot index has
186
+ * none): only when it is strictly closer, so a tie keeps the local pick. A run (`chooseSnapshot`), its shared lookup
187
+ * (`lookupSharedSnapshot`), and `storm snapshots list --shared` (`pickSnapshotAcrossIndexes`) all decide with it.
188
+ */
189
+ export function sharedBeatsLocal(sharedCommitsBehindMergeBase, localCommitsBehindMergeBase) {
190
+ return localCommitsBehindMergeBase === undefined || sharedCommitsBehindMergeBase < localCommitsBehindMergeBase;
191
+ }
192
+ /**
193
+ * Why a run for `owner`'s team and project starts from none of the runner's cached snapshots, when the pick found no
194
+ * candidate of theirs: every candidate is then another team's or project's, `other-owner`; an entry for another team
195
+ * or project is `other-owner`, whatever else rules it out; and any other entry keeps the classification's reason.
196
+ */
197
+ export function snapshotRejections(read, owner) {
198
+ const owned = (entry) => entry.teamId === owner.teamId && entry.projectId === owner.projectId;
199
+ return [
200
+ ...read.candidates.map(({ entry }) => ({ entry, reason: "other-owner" })),
201
+ ...read.rejected.map(({ entry, reason }) => ({ entry, reason: owned(entry) ? reason : "other-owner" })),
202
+ ];
203
+ }
204
+ /**
205
+ * Picks the runner snapshot a run starts from, once the credential names its team and project: the first candidate in
206
+ * preference order (`classifySnapshotEntries`) for that team and project, or `undefined` when none matches.
207
+ */
208
+ export function pickSnapshot(candidates, owner) {
209
+ return candidates.find(({ entry }) => entry.teamId === owner.teamId && entry.projectId === owner.projectId);
210
+ }
@@ -1,7 +1,7 @@
1
1
  import type { SandboxCredential } from "../sdk/extension/index.ts";
2
2
  import type { Timer } from "../time/index.ts";
3
3
  import type { RunnerNetworkPolicy, RunnerSandbox, RunnerSandboxFailure, RunnerSandboxGateway } from "./gateways.ts";
4
- import type { CheckedRecipe } from "./recipe.ts";
4
+ import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
5
5
  /**
6
6
  * How long a policy write may take: 10 seconds. Writes take well under a second. A write with no answer by then is
7
7
  * aborted, and may still take effect at any time.
@@ -27,12 +27,12 @@ export type RunnerReachPolicy = Exclude<RunnerNetworkPolicy, {
27
27
  readonly kind: "deny-all";
28
28
  }>;
29
29
  /**
30
- * The network policy of a sandbox storm creates for `recipe`, with no credential, which every write without
31
- * credentials gives again: `allow-all` when the recipe lists no allowed domains (`allowedDomains`), and otherwise
32
- * `custom` with exactly those domains. A credential's domain is reachable only while the credential is in place
33
- * (`withCredentials`).
30
+ * The network policy of a sandbox storm creates for `options`, with no credential, which every write without
31
+ * credentials gives again: `allow-all` when the runner options list no allowed domains (`allowedDomains`), and
32
+ * otherwise `custom` with exactly those domains. A credential's domain is reachable only while the credential is in
33
+ * place (`withCredentials`).
34
34
  */
35
- export declare function runnerNetworkPolicy(recipe: Pick<CheckedRecipe, "allowedDomains">): RunnerReachPolicy;
35
+ export declare function runnerNetworkPolicy(options: Pick<CheckedVercelSandboxOptions, "allowedDomains">): RunnerReachPolicy;
36
36
  /**
37
37
  * `base` with `credentials` in place of its own, each with its own `requests`. Under `custom`, each credential's
38
38
  * domain is reachable while the policy holds it, beside the allowed domains.
@@ -8,15 +8,15 @@ import { callWithin } from "./time-limit.js";
8
8
  */
9
9
  export const NETWORK_POLICY_WRITE_LIMIT_MS = 10_000;
10
10
  /**
11
- * The network policy of a sandbox storm creates for `recipe`, with no credential, which every write without
12
- * credentials gives again: `allow-all` when the recipe lists no allowed domains (`allowedDomains`), and otherwise
13
- * `custom` with exactly those domains. A credential's domain is reachable only while the credential is in place
14
- * (`withCredentials`).
11
+ * The network policy of a sandbox storm creates for `options`, with no credential, which every write without
12
+ * credentials gives again: `allow-all` when the runner options list no allowed domains (`allowedDomains`), and
13
+ * otherwise `custom` with exactly those domains. A credential's domain is reachable only while the credential is in
14
+ * place (`withCredentials`).
15
15
  */
16
- export function runnerNetworkPolicy(recipe) {
17
- if (recipe.allowedDomains === undefined)
16
+ export function runnerNetworkPolicy(options) {
17
+ if (options.allowedDomains === undefined)
18
18
  return { kind: "allow-all", credentials: [] };
19
- return { kind: "custom", allowedDomains: [...recipe.allowedDomains], credentials: [] };
19
+ return { kind: "custom", allowedDomains: [...options.allowedDomains], credentials: [] };
20
20
  }
21
21
  /**
22
22
  * `base` with `credentials` in place of its own, each with its own `requests`. Under `custom`, each credential's
@@ -22,7 +22,7 @@ export interface SandboxPolicyWriter {
22
22
  /**
23
23
  * A policy writer over `context.runnerSandboxes`, waiting with `context.timer`. `basePolicy` is the policy the run's
24
24
  * sandboxes are created with, which holds no injection: it writes it whenever it removes an injection, so a removal
25
- * keeps the recipe's allowed domains. `onTimedOut` hears of each sandbox once, as its first write times out.
25
+ * keeps the runner's allowed domains. `onTimedOut` hears of each sandbox once, as its first write times out.
26
26
  */
27
27
  export declare function sandboxPolicyWriter(context: {
28
28
  readonly runnerSandboxes: RunnerSandboxGateway;
@@ -7,7 +7,7 @@ import { ABORTED, untilAborted } from "./time-limit.js";
7
7
  /**
8
8
  * A policy writer over `context.runnerSandboxes`, waiting with `context.timer`. `basePolicy` is the policy the run's
9
9
  * sandboxes are created with, which holds no injection: it writes it whenever it removes an injection, so a removal
10
- * keeps the recipe's allowed domains. `onTimedOut` hears of each sandbox once, as its first write times out.
10
+ * keeps the runner's allowed domains. `onTimedOut` hears of each sandbox once, as its first write times out.
11
11
  */
12
12
  export function sandboxPolicyWriter(context, basePolicy, onTimedOut) {
13
13
  /** Each sandbox's policy writes, for the sandboxes it wrote one to. */
@@ -1,44 +1,44 @@
1
1
  import { type RefusedBaseRef } from "./base.ts";
2
2
  import type { CheckoutFailure, CheckoutUpload } from "./gateways.ts";
3
- import { type CheckedRecipe, type VcpuRun } from "./recipe.ts";
4
- import { type RejectedSnapshot, type RunnerSnapshotCandidate, type SnapshotCacheContext, type SnapshotCacheNote } from "./snapshot-cache.ts";
3
+ import { type CheckedVercelSandboxOptions, type VcpuRun } from "./vercel-sandbox-options.ts";
4
+ import { type LocalSnapshotIndexContext, type RejectedSnapshot, type RunnerSnapshotCandidate, type SnapshotIndexNote } from "./local-snapshot-index.ts";
5
5
  import { type DeclaredBaseFile } from "./snapshot-key.ts";
6
- /** What `prepareRunner` needs: the checkout, the runner snapshot cache and the clock. */
7
- export type RunnerPrepareContext = SnapshotCacheContext;
6
+ /** What `prepareRunner` needs: the checkout, the local snapshot index, and the clock. */
7
+ export type RunnerPrepareContext = LocalSnapshotIndexContext;
8
8
  /** What `prepareRunner` checks a run with. */
9
9
  export interface PrepareRunnerRequest {
10
10
  /** The directory the run started in, inside the checkout. */
11
11
  readonly cwd: string;
12
- readonly recipe: CheckedRecipe;
12
+ readonly options: CheckedVercelSandboxOptions;
13
13
  /** The run's resolved resource options and sandbox count, for evaluating a declared `vcpus` rule. */
14
14
  readonly vcpuRun: VcpuRun;
15
15
  }
16
16
  /** The runner, checked on this machine, ready for the runner sandbox. */
17
17
  export interface PreparedRunner {
18
- readonly recipe: CheckedRecipe;
18
+ readonly options: CheckedVercelSandboxOptions;
19
19
  readonly repoRoot: string;
20
20
  /** The run's base, HEAD's merge-base with a base ref, as a full SHA, and that ref. */
21
21
  readonly base: string;
22
22
  readonly baseRef: string;
23
23
  /** Declared base files read at the base, to stage in `/vercel/sandbox/<path>` before toolchain steps. */
24
24
  readonly baseFiles: readonly DeclaredBaseFile[];
25
- /** The recipe's snapshot key at the base. */
25
+ /** The runner's snapshot key at the base. */
26
26
  readonly snapshotKey: string;
27
27
  /** The runner sandbox's vCPUs for the run. */
28
28
  readonly vcpus: number;
29
29
  /** What the run uploads on top of the base. */
30
30
  readonly upload: CheckoutUpload;
31
31
  /**
32
- * The cached runner snapshots the run may start from, each at the run's base with its snapshot key, before the team
33
- * and project filter (`pickSnapshot`).
32
+ * The cached runner snapshots the run may start from, each at the run's base or an ancestor of it with the run's
33
+ * snapshot key, sorted closest first, before the team and project filter (`pickSnapshot`).
34
34
  */
35
35
  readonly candidates: readonly RunnerSnapshotCandidate[];
36
- /** The recipe's other cached snapshots, each with why the run doesn't start from it, before that filter. */
36
+ /** The runner's other cached snapshots, each with why the run doesn't start from it, before that filter. */
37
37
  readonly rejected: readonly RejectedSnapshot[];
38
38
  /** How many commits HEAD has that the run's base lacks. */
39
39
  readonly commitsAfterBase: number;
40
40
  /** What removing expired entries noticed (`removeExpiredEntries`), for the run to report. */
41
- readonly notes: readonly SnapshotCacheNote[];
41
+ readonly notes: readonly SnapshotIndexNote[];
42
42
  }
43
43
  /**
44
44
  * How the local checks ended.
@@ -46,8 +46,8 @@ export interface PreparedRunner {
46
46
  * - `ok`: the checks passed, so the runner can ready the runner sandbox.
47
47
  * - `no-base-ref`: no ref in `baseRefs` exists locally and shares history with HEAD; `refs` says why for each.
48
48
  * - `submodules`: the checkout has Git submodules, at `paths`.
49
- * - `invalid-recipe`: a declared base file couldn't be read at the run's base or a `vcpus` rule's resource option
50
- * wasn't a non-negative number for the run; `path` is the key inside the recipe.
49
+ * - `invalid-runner`: a declared base file couldn't be read at the run's base or a `vcpus` rule's resource option
50
+ * wasn't a non-negative number for the run; `path` is the key inside the runner options.
51
51
  * - `checkout-failed`: git or tar failed, such as outside a Git checkout.
52
52
  */
53
53
  export type PrepareRunnerOutcome = {
@@ -60,7 +60,7 @@ export type PrepareRunnerOutcome = {
60
60
  readonly kind: "submodules";
61
61
  readonly paths: readonly string[];
62
62
  } | {
63
- readonly kind: "invalid-recipe";
63
+ readonly kind: "invalid-runner";
64
64
  readonly path: readonly string[];
65
65
  readonly problem: string;
66
66
  } | {
@@ -1,9 +1,9 @@
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";
5
+ import { resolveVcpus } from "./vercel-sandbox-options.js";
6
+ import { classifySnapshotEntries, removeExpiredEntries, resolveAncestorDistances, } from "./local-snapshot-index.js";
7
7
  import { snapshotInputsAt } from "./snapshot-key.js";
8
8
  /**
9
9
  * Runs the local checks in order: the repository's root, the base, the submodule refusal, the snapshot inputs at
@@ -14,12 +14,12 @@ import { snapshotInputsAt } from "./snapshot-key.js";
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 inputs = await snapshotInputsAt(checkout, { repoRoot, base, recipe });
33
+ const inputs = await snapshotInputsAt(checkout, { repoRoot, base, options });
34
34
  if (!inputs.ok)
35
- return { kind: "invalid-recipe", path: inputs.path, problem: inputs.problem };
36
- const vcpus = resolveVcpus(recipe, request.vcpuRun);
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,17 +43,26 @@ 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
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,
@@ -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. */
@@ -22,12 +22,12 @@ export interface ReadyRunner {
22
22
  readonly buildMs: number;
23
23
  readonly vcpus: number;
24
24
  readonly region: string;
25
- readonly runtime: string;
25
+ readonly image: string;
26
26
  /** The checkout's root on this machine, which `/vercel/sandbox/` in output is rewritten to. */
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"`,