@cnc-tools/storm 0.6.0 → 0.7.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 (80) hide show
  1. package/dist/build-info.js +1 -1
  2. package/dist/commands/exec/command.d.ts +26 -0
  3. package/dist/commands/exec/live-view.js +29 -13
  4. package/dist/commands/exec/metadata.d.ts +4 -1
  5. package/dist/commands/exec/outcomes.d.ts +50 -0
  6. package/dist/commands/exec/outcomes.js +9 -0
  7. package/dist/commands/exec/progress.d.ts +14 -2
  8. package/dist/commands/exec/progress.js +54 -9
  9. package/dist/commands/exec/run-command.d.ts +8 -2
  10. package/dist/commands/exec/run-command.js +41 -8
  11. package/dist/commands/exec/run-metadata.d.ts +5 -2
  12. package/dist/commands/exec/run-metadata.js +5 -2
  13. package/dist/commands/exec/run-record.d.ts +83 -4
  14. package/dist/commands/exec/run-record.js +49 -1
  15. package/dist/commands/exec/view.js +36 -4
  16. package/dist/commands/runs/facts.d.ts +25 -0
  17. package/dist/commands/runs/facts.js +36 -3
  18. package/dist/commands/runs/list/command.d.ts +25 -0
  19. package/dist/commands/runs/list/outcomes.d.ts +25 -0
  20. package/dist/commands/runs/show/command.d.ts +25 -0
  21. package/dist/commands/runs/show/metadata.js +1 -1
  22. package/dist/commands/runs/show/outcomes.d.ts +25 -0
  23. package/dist/commands/runs/show/outcomes.js +30 -1
  24. package/dist/commands/vitest/command.d.ts +26 -0
  25. package/dist/commands/vitest/metadata.d.ts +4 -1
  26. package/dist/commands/vitest/outcomes.d.ts +25 -0
  27. package/dist/core/events.d.ts +9 -7
  28. package/dist/core/run-state.d.ts +30 -6
  29. package/dist/core/run-state.js +19 -4
  30. package/dist/core/run.d.ts +17 -4
  31. package/dist/core/run.js +61 -25
  32. package/dist/runner/events.d.ts +64 -1
  33. package/dist/runner/gateways.d.ts +17 -6
  34. package/dist/runner/index.d.ts +5 -4
  35. package/dist/runner/index.js +4 -3
  36. package/dist/runner/live/snapshot-records.js +18 -4
  37. package/dist/runner/prepare.d.ts +23 -4
  38. package/dist/runner/prepare.js +13 -3
  39. package/dist/runner/ready.d.ts +7 -3
  40. package/dist/runner/ready.js +11 -5
  41. package/dist/runner/scope.d.ts +17 -1
  42. package/dist/runner/scope.js +4 -0
  43. package/dist/runner/snapshot-build.d.ts +3 -1
  44. package/dist/runner/snapshot-build.js +12 -2
  45. package/dist/runner/snapshot-cache.d.ts +46 -8
  46. package/dist/runner/snapshot-cache.js +60 -11
  47. package/dist/runner/snapshot-key.d.ts +12 -1
  48. package/dist/runner/snapshot-key.js +17 -1
  49. package/dist/runner/snapshot-save.d.ts +53 -0
  50. package/dist/runner/snapshot-save.js +148 -0
  51. package/dist/story/align.d.ts +1 -1
  52. package/dist/story/align.js +1 -1
  53. package/dist/story/definition.d.ts +22 -15
  54. package/dist/story/definition.js +2 -2
  55. package/dist/story/errors.js +1 -1
  56. package/dist/story/gateways.d.ts +45 -25
  57. package/dist/story/gateways.js +2 -2
  58. package/dist/story/host.d.ts +11 -8
  59. package/dist/story/host.js +37 -37
  60. package/dist/story/index.d.ts +1 -1
  61. package/dist/story/index.js +4 -4
  62. package/dist/story/json.d.ts +1 -1
  63. package/dist/story/json.js +2 -2
  64. package/dist/story/live/recording-gateway.d.ts +2 -0
  65. package/dist/story/live/{artifact-gateway.js → recording-gateway.js} +33 -12
  66. package/dist/story/mode.d.ts +2 -2
  67. package/dist/story/mode.js +1 -1
  68. package/dist/story/orphans.d.ts +23 -5
  69. package/dist/story/orphans.js +44 -8
  70. package/dist/story/recording.d.ts +62 -0
  71. package/dist/story/{artifact.js → recording.js} +31 -27
  72. package/dist/story/report.d.ts +21 -9
  73. package/dist/story/report.js +37 -25
  74. package/dist/story/settle.d.ts +23 -21
  75. package/dist/story/settle.js +17 -16
  76. package/dist/story/{run.d.ts → start.d.ts} +18 -17
  77. package/dist/story/{run.js → start.js} +66 -43
  78. package/package.json +1 -1
  79. package/dist/story/artifact.d.ts +0 -60
  80. package/dist/story/live/artifact-gateway.d.ts +0 -2
@@ -1,3 +1,3 @@
1
1
  // Written by scripts/write-build-info.js when the package was built.
2
- export const sha = "0f00cceca649";
2
+ export const sha = "4c286290a36f";
3
3
  export const dirty = false;
@@ -20,6 +20,7 @@ export declare function command(cmd: CommandBuilder<StormApp>): import("@vercel/
20
20
  }>>;
21
21
  local: z.ZodDefault<z.ZodBoolean>;
22
22
  rebuildSnapshot: z.ZodDefault<z.ZodBoolean>;
23
+ saveSnapshot: z.ZodDefault<z.ZodBoolean>;
23
24
  showOutput: z.ZodDefault<z.ZodBoolean>;
24
25
  keepSandbox: z.ZodOptional<z.ZodString>;
25
26
  verbose: z.ZodDefault<z.ZodBoolean>;
@@ -38,10 +39,35 @@ export declare function command(cmd: CommandBuilder<StormApp>): import("@vercel/
38
39
  runner: z.ZodNullable<z.ZodObject<{
39
40
  snapshotId: z.ZodString;
40
41
  base: z.ZodString;
42
+ snapshotBranch: z.ZodNullable<z.ZodString>;
43
+ snapshotHead: z.ZodNullable<z.ZodString>;
41
44
  built: z.ZodBoolean;
42
45
  vcpus: z.ZodNumber;
43
46
  region: z.ZodString;
44
47
  runtime: z.ZodString;
48
+ buildMs: z.ZodNumber;
49
+ save: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
50
+ kind: z.ZodLiteral<"saved">;
51
+ snapshotId: z.ZodString;
52
+ base: z.ZodString;
53
+ branch: z.ZodString;
54
+ head: z.ZodString;
55
+ ms: z.ZodNumber;
56
+ sizeBytes: z.ZodNumber;
57
+ entryWritten: z.ZodBoolean;
58
+ }, z.core.$strip>, z.ZodObject<{
59
+ kind: z.ZodLiteral<"skipped">;
60
+ reason: z.ZodLiteral<"detached-head">;
61
+ }, z.core.$strip>, z.ZodObject<{
62
+ kind: z.ZodLiteral<"failed">;
63
+ step: z.ZodEnum<{
64
+ "save-snapshot": "save-snapshot";
65
+ scrub: "scrub";
66
+ }>;
67
+ message: z.ZodString;
68
+ }, z.core.$strip>, z.ZodObject<{
69
+ kind: z.ZodLiteral<"stopped">;
70
+ }, z.core.$strip>], "kind">>;
45
71
  }, z.core.$strip>>;
46
72
  timeline: z.ZodObject<{
47
73
  startedAt: z.ZodString;
@@ -72,7 +72,7 @@ export function phaseFrame(state, phase, now, width, paint) {
72
72
  case "tests":
73
73
  return testsFrame(state, view);
74
74
  case "cleanup":
75
- return state.cleanup === undefined ? [] : [cleanupLine(state.cleanup, state.runner?.kept, view, false)];
75
+ return state.cleanup === undefined ? [] : [cleanupLine(state.cleanup, state.runner, view, false)];
76
76
  }
77
77
  }
78
78
  /**
@@ -102,7 +102,7 @@ export function phaseRecord(state, phase, width, paint) {
102
102
  case "tests":
103
103
  return state.command === undefined ? [] : [testsLine(state, state.command, view, false)];
104
104
  case "cleanup":
105
- return state.cleanup === undefined ? [] : [cleanupLine(state.cleanup, state.runner?.kept, view, true)];
105
+ return state.cleanup === undefined ? [] : [cleanupLine(state.cleanup, state.runner, view, true)];
106
106
  }
107
107
  }
108
108
  /** What a resource lane's presentation draws with: `view`, with its span's time and durations. */
@@ -354,27 +354,43 @@ function testsProgress(tests, view, room) {
354
354
  return visibleLength(full) <= room ? full : text(false);
355
355
  }
356
356
  /**
357
- * The cleanup row: what it does while it runs, what it did in its final form, with the runner sandbox it `kept`
358
- * running, if it kept one.
357
+ * The cleanup row: what it does while it runs, what it did in its final form, with the runner sandbox it kept
358
+ * running, if it kept one, or the branch snapshot it saved it as.
359
359
  */
360
- function cleanupLine(cleanup, kept, view, record) {
360
+ function cleanupLine(cleanup, runner, view, record) {
361
361
  const done = record || cleanup.status !== "running";
362
362
  const releases = RESOURCE_PRESENTATIONS.releaseTexts(cleanup.holdings, done ? "done" : "doing");
363
363
  const release = releases.length === 0 ? undefined : releases.join(", ");
364
- const sandbox = kept !== undefined
365
- ? `kept the runner sandbox until ${isoSecondsText(kept.stopsAt)}`
366
- : !done && cleanup.keepSandboxMs > 0
367
- ? `keeping the runner sandbox running ${keepTimeText(cleanup.keepSandboxMs)}`
368
- : `${done ? "stopped and deleted" : "stopping and deleting"} the runner sandbox`;
364
+ const { runnerSandbox } = cleanup;
369
365
  const text = !done && cleanup.waiting
370
366
  ? `${WAITING_FOR_SNAPSHOT}…`
371
- : cleanup.runner
372
- ? `${sandbox}${release === undefined ? "" : `, ${release}`}`
373
- : (release ?? "nothing to release");
367
+ : runnerSandbox === null
368
+ ? (release ?? "nothing to release")
369
+ : `${runnerSandboxText(runnerSandbox, runner, done)}${release === undefined ? "" : `, ${release}`}`;
374
370
  const leftBehind = cleanupProblems(cleanup);
375
371
  const ending = done ? (leftBehind === 0 ? "" : `: ${leftBehind} left behind`) : "…";
376
372
  return view.row(` ${view.glyph(cleanup.status)} cleanup ${text}${!done && cleanup.waiting ? "" : ending}`, elapsed(view, cleanup.startedAt, cleanup.endedAt));
377
373
  }
374
+ /**
375
+ * What cleanup does with the runner sandbox, as the cleanup row says: kept it running, keeps it running while cleanup
376
+ * runs (`keep`), saves it or saved it as a branch snapshot (`save`), or else stops and deletes it.
377
+ */
378
+ function runnerSandboxText(sandbox, runner, done) {
379
+ const kept = runner?.kept;
380
+ if (kept !== undefined)
381
+ return `kept the runner sandbox until ${isoSecondsText(kept.stopsAt)}`;
382
+ const removed = `${done ? "stopped and deleted" : "stopping and deleting"} the runner sandbox`;
383
+ switch (sandbox.kind) {
384
+ case "keep":
385
+ return !done && sandbox.ms > 0 ? `keeping the runner sandbox running ${keepTimeText(sandbox.ms)}` : removed;
386
+ case "save": {
387
+ const save = runner?.save;
388
+ if (save?.kind === "saved")
389
+ return `saved branch snapshot ${save.id} of ${save.branch}`;
390
+ return !done && save?.kind !== "not-saved" ? `saving a branch snapshot of ${sandbox.branch}` : removed;
391
+ }
392
+ }
393
+ }
378
394
  function statusGlyph(status, now, paint) {
379
395
  switch (status) {
380
396
  case "pending":
@@ -34,7 +34,10 @@ export declare const metadata: {
34
34
  readonly description: "Run the command on this machine instead of in a runner sandbox. Without it, the command runs in a Vercel Sandbox started from a runner snapshot of the base, with this checkout's changes applied, installed and built, from the runner key of storm.config.ts, and its output streams back with paths rewritten to this checkout's. No config key.";
35
35
  };
36
36
  rebuildSnapshot: {
37
- readonly description: "Build a runner snapshot of the base whatever the runner snapshot cache holds, replacing an entry for the same base. Not with --local. No config key.";
37
+ readonly description: "Build a runner snapshot of the base whatever the runner snapshot cache holds, replacing an entry for the same base, and drop this branch's saved branch snapshots from the cache. Not with --local. No config key.";
38
+ };
39
+ saveSnapshot: {
40
+ readonly description: "Once the command ends on its own after a successful install and build, save the runner sandbox as this branch's runner snapshot, so the next run on the branch starts from this run's install and build outputs. The run resets the working tree to the snapshot's base, keeps .git and ignored files such as node_modules and build outputs, and empties /tmp; the snapshot keeps whatever the command wrote there and to $HOME, a resource's token included. A run with it on a branch keeps no runner sandbox, even when it fails or stops before the save. With a detached HEAD it says so as it starts and keeps the runner sandbox as without the flag. Not with --local, or with --keep-sandbox above 0. No config key.";
38
41
  };
39
42
  keepSandbox: {
40
43
  readonly valueLabel: "DURATION";
@@ -64,10 +64,35 @@ export declare const ranSchema: z.ZodObject<{
64
64
  runner: z.ZodNullable<z.ZodObject<{
65
65
  snapshotId: z.ZodString;
66
66
  base: z.ZodString;
67
+ snapshotBranch: z.ZodNullable<z.ZodString>;
68
+ snapshotHead: z.ZodNullable<z.ZodString>;
67
69
  built: z.ZodBoolean;
68
70
  vcpus: z.ZodNumber;
69
71
  region: z.ZodString;
70
72
  runtime: z.ZodString;
73
+ buildMs: z.ZodNumber;
74
+ save: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
75
+ kind: z.ZodLiteral<"saved">;
76
+ snapshotId: z.ZodString;
77
+ base: z.ZodString;
78
+ branch: z.ZodString;
79
+ head: z.ZodString;
80
+ ms: z.ZodNumber;
81
+ sizeBytes: z.ZodNumber;
82
+ entryWritten: z.ZodBoolean;
83
+ }, z.core.$strip>, z.ZodObject<{
84
+ kind: z.ZodLiteral<"skipped">;
85
+ reason: z.ZodLiteral<"detached-head">;
86
+ }, z.core.$strip>, z.ZodObject<{
87
+ kind: z.ZodLiteral<"failed">;
88
+ step: z.ZodEnum<{
89
+ "save-snapshot": "save-snapshot";
90
+ scrub: "scrub";
91
+ }>;
92
+ message: z.ZodString;
93
+ }, z.core.$strip>, z.ZodObject<{
94
+ kind: z.ZodLiteral<"stopped">;
95
+ }, z.core.$strip>], "kind">>;
71
96
  }, z.core.$strip>>;
72
97
  timeline: z.ZodObject<{
73
98
  startedAt: z.ZodString;
@@ -380,10 +405,35 @@ export declare const outcomes: import("@vercel/clinkr").Outcomes<{
380
405
  runner: z.ZodNullable<z.ZodObject<{
381
406
  snapshotId: z.ZodString;
382
407
  base: z.ZodString;
408
+ snapshotBranch: z.ZodNullable<z.ZodString>;
409
+ snapshotHead: z.ZodNullable<z.ZodString>;
383
410
  built: z.ZodBoolean;
384
411
  vcpus: z.ZodNumber;
385
412
  region: z.ZodString;
386
413
  runtime: z.ZodString;
414
+ buildMs: z.ZodNumber;
415
+ save: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
416
+ kind: z.ZodLiteral<"saved">;
417
+ snapshotId: z.ZodString;
418
+ base: z.ZodString;
419
+ branch: z.ZodString;
420
+ head: z.ZodString;
421
+ ms: z.ZodNumber;
422
+ sizeBytes: z.ZodNumber;
423
+ entryWritten: z.ZodBoolean;
424
+ }, z.core.$strip>, z.ZodObject<{
425
+ kind: z.ZodLiteral<"skipped">;
426
+ reason: z.ZodLiteral<"detached-head">;
427
+ }, z.core.$strip>, z.ZodObject<{
428
+ kind: z.ZodLiteral<"failed">;
429
+ step: z.ZodEnum<{
430
+ "save-snapshot": "save-snapshot";
431
+ scrub: "scrub";
432
+ }>;
433
+ message: z.ZodString;
434
+ }, z.core.$strip>, z.ZodObject<{
435
+ kind: z.ZodLiteral<"stopped">;
436
+ }, z.core.$strip>], "kind">>;
387
437
  }, z.core.$strip>>;
388
438
  timeline: z.ZodObject<{
389
439
  startedAt: z.ZodString;
@@ -6,6 +6,7 @@ import { configErrors } from "../../config/index.js";
6
6
  import { credentialErrors } from "../../credential/index.js";
7
7
  import { keptText, runnerCleanupWarnings } from "./cleanup.js";
8
8
  import { mintFailedErrors } from "./mint-failed.js";
9
+ import { saveSchema } from "./run-record.js";
9
10
  /** Why the runner couldn't run the command. */
10
11
  const runnerFailureSchema = z.union([
11
12
  z.object({
@@ -140,11 +141,19 @@ export const ranSchema = z.object({
140
141
  snapshotId: z.string(),
141
142
  /** The runner snapshot's base, a full SHA. */
142
143
  base: z.string(),
144
+ /** For a branch snapshot, the local branch of the run that saved it; null for a base snapshot. */
145
+ snapshotBranch: z.string().nullable(),
146
+ /** For a branch snapshot, the HEAD commit of the run that saved it, a full SHA; null for a base snapshot. */
147
+ snapshotHead: z.string().nullable(),
143
148
  /** Whether this run built the runner snapshot. */
144
149
  built: z.boolean(),
145
150
  vcpus: z.number(),
146
151
  region: z.string(),
147
152
  runtime: z.string(),
153
+ /** How long the build step took, in milliseconds. */
154
+ buildMs: z.number(),
155
+ /** How saving the runner sandbox as a branch snapshot ended (--save-snapshot); null without the flag. */
156
+ save: saveSchema.nullable(),
148
157
  })
149
158
  .nullable(),
150
159
  /** The run's waterfall, as the run directory's timeline.json holds it: each lane's span and steps in milliseconds since the run started, how they ended, idle time, and the critical path. */
@@ -1,6 +1,6 @@
1
1
  import { type RanCommand } from "../../core/index.ts";
2
2
  import { type StormRunLane, type StormRunObserver, type StormTimedRunEvent } from "../../resources.ts";
3
- import type { RunnerSnapshotCacheFailure, SnapshotCacheNote } from "../../runner/index.ts";
3
+ import type { RunnerEvent, RunnerSnapshotCacheFailure, SnapshotCacheNote } from "../../runner/index.ts";
4
4
  /** The lane a plain progress line names after its elapsed time: what part of the run it is about. */
5
5
  export type ProgressLane = "run" | "mint" | StormRunLane | "command" | "cleanup";
6
6
  /**
@@ -33,12 +33,24 @@ export declare function plainRenderer(options: LineProgressOptions): (timed: Sto
33
33
  export declare function progressLine(elapsedMs: number, lane: ProgressLane, text: string): string;
34
34
  /** The widest lane a plain line names: `command`, `cleanup`, or a resource's lane, such as `testserver`. */
35
35
  export declare const LANE_WIDTH: number;
36
+ /** How saving a branch snapshot ended, as its line says. */
37
+ export declare function branchSnapshotSaveText(event: Extract<RunnerEvent, {
38
+ readonly kind: "branch-snapshot-saved" | "branch-snapshot-not-saved";
39
+ }>): string;
40
+ /** What `--rebuild-snapshot` did to the branch's branch snapshot entries, as its line says. */
41
+ export declare function branchSnapshotsDropText(event: Extract<RunnerEvent, {
42
+ readonly kind: "branch-snapshots-dropped" | "branch-snapshots-not-dropped";
43
+ }>): string;
36
44
  /** How a command ended, as its end line and the live view say. */
37
45
  export declare function commandEnd(outcome: RanCommand): string;
38
- /** In a runner run, what the local checks noticed: nested Git repositories left out, and the cache read's notes. */
46
+ /**
47
+ * In a runner run, what the local checks noticed: nested Git repositories left out, the cache read's notes, and that
48
+ * `--save-snapshot` saves nothing on a detached HEAD.
49
+ */
39
50
  export declare function preparedNoteTexts(prepared: {
40
51
  readonly nestedRepositories: readonly string[];
41
52
  readonly notes: readonly SnapshotCacheNote[];
53
+ readonly saveSkipped: boolean;
42
54
  }): string[];
43
55
  /** The runner snapshot cache couldn't record a runner snapshot the run built. */
44
56
  export declare function cacheWriteFailureText(failure: RunnerSnapshotCacheFailure): string;
@@ -119,7 +119,7 @@ function eventLines(event, now, state, line, options) {
119
119
  case "cleanup-started":
120
120
  state.cleanupStartedAt = now;
121
121
  return [
122
- line("cleanup", cleanupText(event.runner, event.keepSandboxMs, RESOURCE_PRESENTATIONS.releaseTexts(event.holdings, "doing"))),
122
+ line("cleanup", cleanupText(event.runnerSandbox, RESOURCE_PRESENTATIONS.releaseTexts(event.holdings, "doing"))),
123
123
  ];
124
124
  case "cleanup-finished": {
125
125
  const problems = [
@@ -150,7 +150,7 @@ function eventLines(event, now, state, line, options) {
150
150
  function runnerLines(event, state, line, options) {
151
151
  switch (event.kind) {
152
152
  case "snapshot-reused":
153
- return [line("runner", `reusing runner snapshot ${event.snapshotId} of base ${short(event.base)}`)];
153
+ return [line("runner", snapshotReusedText(event))];
154
154
  case "snapshot-build-started":
155
155
  return [
156
156
  line("runner", `building a runner snapshot of base ${short(event.base)} (${event.reason === "rebuild" ? "--rebuild-snapshot" : "no cached runner snapshot fits"}); this takes a few minutes: ${event.summary}`),
@@ -204,8 +204,46 @@ function runnerLines(event, state, line, options) {
204
204
  ];
205
205
  case "sandbox-kept":
206
206
  return [line("cleanup", `kept the runner sandbox ${event.name} running until ${isoSecondsText(event.stopsAt)}`)];
207
+ // The cleanup line says the run saves a branch snapshot.
208
+ case "branch-snapshot-saving":
209
+ return [];
210
+ case "branch-snapshot-saved":
211
+ case "branch-snapshot-not-saved":
212
+ return [line("cleanup", branchSnapshotSaveText(event))];
213
+ case "branch-snapshots-dropped":
214
+ case "branch-snapshots-not-dropped":
215
+ return [line("runner", branchSnapshotsDropText(event))];
207
216
  }
208
217
  }
218
+ /** The line that says which runner snapshot the run starts from, and for a branch snapshot, which run saved it. */
219
+ function snapshotReusedText(event) {
220
+ const reused = `reusing runner snapshot ${event.snapshotId} of base ${short(event.base)}`;
221
+ return event.branch === null || event.head === null
222
+ ? reused
223
+ : `${reused} (branch ${event.branch} at ${short(event.head)})`;
224
+ }
225
+ /** How saving a branch snapshot ended, as its line says. */
226
+ export function branchSnapshotSaveText(event) {
227
+ if (event.kind === "branch-snapshot-saved") {
228
+ return `saved branch snapshot ${event.snapshotId} for ${event.branch} at ${short(event.head)} in ${seconds(event.ms)} (${megabytesText(event.sizeBytes)})`;
229
+ }
230
+ return `not saving a branch snapshot: ${notSavedReason(event.save)}`;
231
+ }
232
+ function notSavedReason(save) {
233
+ switch (save.kind) {
234
+ case "failed":
235
+ return `the ${save.step === "scrub" ? "scrub" : "save"} failed: ${save.message}`;
236
+ case "stopped":
237
+ return "the run is stopping";
238
+ }
239
+ }
240
+ /** What `--rebuild-snapshot` did to the branch's branch snapshot entries, as its line says. */
241
+ export function branchSnapshotsDropText(event) {
242
+ if (event.kind === "branch-snapshots-not-dropped")
243
+ return `couldn't drop a branch snapshot of ${event.branch} from the cache at ${event.failure.path}: ${event.failure.message}; a later run on the branch may start from it`;
244
+ const count = event.snapshotIds.length;
245
+ return `dropped ${count} branch ${count === 1 ? "snapshot" : "snapshots"} of ${event.branch} from the cache: ${event.snapshotIds.join(", ")}`;
246
+ }
209
247
  /** What a stopping run says it releases of the resources it holds, such as ` and releasing the leases`. */
210
248
  function releasingText(held) {
211
249
  return RESOURCE_PRESENTATIONS.stoppingTexts(held)
@@ -220,15 +258,18 @@ function closeFold(state) {
220
258
  return ["::endgroup::"];
221
259
  }
222
260
  /**
223
- * What cleaning up does, as its first line says: in a runner run, keeping the runner sandbox running `keepMs` when that
224
- * is above 0, else stopping and deleting the runner's sandboxes; then what releasing each resource does (`releases`).
261
+ * What cleaning up does, as its first line says: in a runner run (`sandbox`, null in a local run), saving the runner
262
+ * sandbox as a branch snapshot while the resources are released, or keeping it running when its keep time is above 0,
263
+ * else stopping and deleting the runner's sandboxes; then what releasing each resource does (`releases`).
225
264
  */
226
- function cleanupText(runner, keepMs, releases) {
265
+ function cleanupText(sandbox, releases) {
227
266
  const release = releases.length === 0 ? undefined : releases.join(", ");
228
- if (!runner)
267
+ if (sandbox === null)
229
268
  return release === undefined ? "nothing to release" : `${release}…`;
230
- const sandboxes = keepMs > 0
231
- ? `keeping the runner sandbox running ${keepTimeText(keepMs)}`
269
+ if (sandbox.kind === "save")
270
+ return `saving a branch snapshot of ${sandbox.branch}${release === undefined ? "" : ` while ${release}`}…`;
271
+ const sandboxes = sandbox.ms > 0
272
+ ? `keeping the runner sandbox running ${keepTimeText(sandbox.ms)}`
232
273
  : "stopping and deleting the runner's sandboxes";
233
274
  return `${sandboxes}${release === undefined ? "" : `, then ${release}`}…`;
234
275
  }
@@ -262,13 +303,17 @@ function targetText(target) {
262
303
  // The notices: what a run reports that the live view's phases can't hold, so it prints them above the live region
263
304
  // as plain lines, and plain progress prints among its other lines. Each builder answers the lines' text, which the
264
305
  // caller prefixes with the time and the lane (`progressLine`). A resource's own notices are its presentation's.
265
- /** In a runner run, what the local checks noticed: nested Git repositories left out, and the cache read's notes. */
306
+ /**
307
+ * In a runner run, what the local checks noticed: nested Git repositories left out, the cache read's notes, and that
308
+ * `--save-snapshot` saves nothing on a detached HEAD.
309
+ */
266
310
  export function preparedNoteTexts(prepared) {
267
311
  return [
268
312
  ...(prepared.nestedRepositories.length === 0
269
313
  ? []
270
314
  : [`leaving out untracked nested Git repositories: ${prepared.nestedRepositories.join(", ")}`]),
271
315
  ...prepared.notes.map(noteText),
316
+ ...(prepared.saveSkipped ? ["not saving a branch snapshot: HEAD is detached"] : []),
272
317
  ];
273
318
  }
274
319
  /** The runner snapshot cache couldn't record a runner snapshot the run built. */
@@ -22,6 +22,7 @@ export declare const RUN_REQUEST_FIELDS: {
22
22
  }>>;
23
23
  local: z.ZodDefault<z.ZodBoolean>;
24
24
  rebuildSnapshot: z.ZodDefault<z.ZodBoolean>;
25
+ saveSnapshot: z.ZodDefault<z.ZodBoolean>;
25
26
  showOutput: z.ZodDefault<z.ZodBoolean>;
26
27
  keepSandbox: z.ZodOptional<z.ZodString>;
27
28
  verbose: z.ZodDefault<z.ZodBoolean>;
@@ -47,6 +48,7 @@ declare const runRequestSchema: z.ZodObject<{
47
48
  }>>;
48
49
  local: z.ZodDefault<z.ZodBoolean>;
49
50
  rebuildSnapshot: z.ZodDefault<z.ZodBoolean>;
51
+ saveSnapshot: z.ZodDefault<z.ZodBoolean>;
50
52
  showOutput: z.ZodDefault<z.ZodBoolean>;
51
53
  keepSandbox: z.ZodOptional<z.ZodString>;
52
54
  verbose: z.ZodDefault<z.ZodBoolean>;
@@ -123,7 +125,11 @@ export interface RunCommandSpec<TPlan, TRan, TRefusal> {
123
125
  * for the runner sandbox, so it needs `scope` and `project` whatever resources it holds. In a runner run, the first
124
126
  * SIGINT, SIGTERM or SIGHUP stops the run in any phase: the remote command is killed, every sandbox the run started is
125
127
  * stopped and deleted, the leases are released, and the run cancels. `--rebuild-snapshot` (no config key, not with
126
- * `--local`) builds a runner snapshot whatever the cache holds.
128
+ * `--local`) builds a runner snapshot whatever the cache holds, and drops HEAD's branch's branch snapshots from it.
129
+ * `--save-snapshot` (no config key, not with `--local` or a `--keep-sandbox` above 0) saves the runner sandbox as a
130
+ * branch snapshot once the command ended on its own, while the leases are released, so the next run on the branch
131
+ * starts from it; a run with it on a branch keeps no runner sandbox, however it ends, and one on a detached HEAD says
132
+ * so as it starts and keeps its runner sandbox as without the flag.
127
133
  *
128
134
  * `--credential` (no config key) picks the credential source: `mint`, the default, or `github-actions`, which requests
129
135
  * a GitHub Actions OIDC token instead and so needs no `--scope` or `--project`; any given are unused. A runner run
@@ -149,7 +155,7 @@ export interface RunCommandSpec<TPlan, TRan, TRefusal> {
149
155
  */
150
156
  export declare function runCommand<TPlan extends RunRecordPlan | undefined, TRan extends CommandResult, TRefusal extends CommandError = never>({ app, ui, signal }: ExecutionContext<StormApp>, request: RunCommandRequest, spec: RunCommandSpec<TPlan, TRan, TRefusal>): Promise<TRan | TRefusal | import("@vercel/clinkr").ClinkrError<"canceled"> | CommandError<"credential_unused"> | CommandError<"invalid_config"> | CommandError<"invalid_resource_options"> | CommandError<"mint_failed"> | CommandError<"missing_runner"> | CommandError<"missing_target"> | CommandError<"no_base_ref"> | CommandError<"runner_failed"> | CommandError<"snapshot_gone"> | CommandError<"spawn_failed"> | CommandError<"submodules_refused"> | CommandError<"credential_rejected" | "github_fixture_repo_unavailable" | "github_token_missing" | "no_sandboxes" | "no_usable_sandboxes" | "pool_unavailable" | "pool_unreadable" | "token_request_failed">>;
151
157
  /** What is wrong with a run's request that its schema can't say, as `validate` reports it. */
152
- export declare function runProblems({ set, credential, local, rebuildSnapshot, showOutput, keepSandbox, ...rest }: RunCommandRequest): readonly ArgumentIssue[];
158
+ export declare function runProblems({ set, credential, local, rebuildSnapshot, saveSnapshot, showOutput, keepSandbox, ...rest }: RunCommandRequest): readonly ArgumentIssue[];
153
159
  /**
154
160
  * A run canceled before it started, while it was settled or prepared: nothing was minted, leased or started, and the
155
161
  * command didn't run.
@@ -35,6 +35,7 @@ export const RUN_REQUEST_FIELDS = {
35
35
  credential: z.enum(["mint", "github-actions"]).optional(),
36
36
  local: z.boolean().default(false),
37
37
  rebuildSnapshot: z.boolean().default(false),
38
+ saveSnapshot: z.boolean().default(false),
38
39
  showOutput: z.boolean().default(false),
39
40
  keepSandbox: z.string().optional(),
40
41
  verbose: z.boolean().default(false),
@@ -79,7 +80,11 @@ const runRequestSchema = z.object(RUN_REQUEST_FIELDS);
79
80
  * for the runner sandbox, so it needs `scope` and `project` whatever resources it holds. In a runner run, the first
80
81
  * SIGINT, SIGTERM or SIGHUP stops the run in any phase: the remote command is killed, every sandbox the run started is
81
82
  * stopped and deleted, the leases are released, and the run cancels. `--rebuild-snapshot` (no config key, not with
82
- * `--local`) builds a runner snapshot whatever the cache holds.
83
+ * `--local`) builds a runner snapshot whatever the cache holds, and drops HEAD's branch's branch snapshots from it.
84
+ * `--save-snapshot` (no config key, not with `--local` or a `--keep-sandbox` above 0) saves the runner sandbox as a
85
+ * branch snapshot once the command ended on its own, while the leases are released, so the next run on the branch
86
+ * starts from it; a run with it on a branch keeps no runner sandbox, however it ends, and one on a detached HEAD says
87
+ * so as it starts and keeps its runner sandbox as without the flag.
83
88
  *
84
89
  * `--credential` (no config key) picks the credential source: `mint`, the default, or `github-actions`, which requests
85
90
  * a GitHub Actions OIDC token instead and so needs no `--scope` or `--project`; any given are unused. A runner run
@@ -150,9 +155,11 @@ export async function runCommand({ app, ui, signal }, request, spec) {
150
155
  recipe: where.recipe,
151
156
  resources: RESOURCE_REPORTS.runnerResources(options),
152
157
  rebuild: request.rebuildSnapshot,
158
+ saveSnapshot: request.saveSnapshot,
153
159
  });
154
160
  if (prepared.kind !== "ok")
155
161
  return prepareRefusal(prepared, configFile);
162
+ const { save } = prepared.prepared;
156
163
  run = {
157
164
  ...base,
158
165
  resources: settlement.requests,
@@ -160,7 +167,9 @@ export async function runCommand({ app, ui, signal }, request, spec) {
160
167
  prepared: prepared.prepared,
161
168
  target: where.target,
162
169
  user: app.user,
163
- keepSandboxMs: keepSandboxMinutes(request.keepSandbox, where.recipe, app.env) * 60_000,
170
+ sandbox: save?.kind === "branch"
171
+ ? { kind: "save", branch: save.branch }
172
+ : { kind: "keep", ms: keepSandboxMinutes(request.keepSandbox, where.recipe, app.env) * 60_000 },
164
173
  },
165
174
  };
166
175
  }
@@ -256,10 +265,14 @@ export async function runCommand({ app, ui, signal }, request, spec) {
256
265
  : {
257
266
  snapshotId: outcome.runner.snapshotId,
258
267
  base: outcome.runner.base,
268
+ snapshotBranch: outcome.runner.snapshotBranch,
269
+ snapshotHead: outcome.runner.snapshotHead,
259
270
  built: outcome.runner.built,
260
271
  vcpus: outcome.runner.vcpus,
261
272
  region: outcome.runner.region,
262
273
  runtime: outcome.runner.runtime,
274
+ buildMs: outcome.runner.buildMs,
275
+ save: outcome.runner.save,
263
276
  },
264
277
  timeline: timelineFacts(ran),
265
278
  runId: directory?.id ?? null,
@@ -301,7 +314,7 @@ export async function runCommand({ app, ui, signal }, request, spec) {
301
314
  }
302
315
  }
303
316
  /** What is wrong with a run's request that its schema can't say, as `validate` reports it. */
304
- export function runProblems({ set, credential, local, rebuildSnapshot, showOutput, keepSandbox, ...rest }) {
317
+ export function runProblems({ set, credential, local, rebuildSnapshot, saveSnapshot, showOutput, keepSandbox, ...rest }) {
305
318
  return [
306
319
  ...setProblems(set).map((problem) => ({ field: "set", message: `${problem}.` })),
307
320
  ...testserverFlagProblems(rest),
@@ -330,6 +343,17 @@ export function runProblems({ set, credential, local, rebuildSnapshot, showOutpu
330
343
  ...(keepSandbox !== undefined && local
331
344
  ? [{ field: "keepSandbox", message: "--keep-sandbox keeps a runner run's runner sandbox; drop it or --local." }]
332
345
  : []),
346
+ ...(saveSnapshot && local
347
+ ? [{ field: "saveSnapshot", message: "--save-snapshot saves a runner run's runner sandbox; drop it or --local." }]
348
+ : []),
349
+ ...(saveSnapshot && keepSandbox !== undefined && (parseKeepTime(keepSandbox) ?? 0) > 0
350
+ ? [
351
+ {
352
+ field: "saveSnapshot",
353
+ message: "--save-snapshot saves the runner sandbox instead of keeping it; drop --keep-sandbox or set it to 0.",
354
+ },
355
+ ]
356
+ : []),
333
357
  ];
334
358
  }
335
359
  /**
@@ -389,7 +413,7 @@ async function summarize(app, run) {
389
413
  directory?.writeTimeline(JSON.stringify(ran, null, 2));
390
414
  directory?.writeRun(runRecordText({
391
415
  ...run.record,
392
- where: endedWhere(run.record.where, state.runner),
416
+ where: endedWhere(run.record.where, state.runner, run.outcome.kind === "ran" ? (run.outcome.runner?.save ?? null) : null),
393
417
  ended: runEnd(run.outcome, state.command, tests, run.requests),
394
418
  }));
395
419
  const writeFailure = await directory?.close();
@@ -527,14 +551,16 @@ function startedWhere(runner) {
527
551
  sandbox: null,
528
552
  snapshot: null,
529
553
  keptUntil: null,
554
+ save: null,
530
555
  };
531
556
  }
532
557
  /**
533
558
  * `where` once the run is over, from the runner's final state: for a runner run, the runner sandbox the run started,
534
- * the runner snapshot it started from, which the run reused or built, and when its timeout stops the runner sandbox it
535
- * kept running. Each is null when the run stopped before it, or kept no runner sandbox.
559
+ * the runner snapshot it started from, which the run reused or built, when its timeout stops the runner sandbox it
560
+ * kept running, and how saving it as a branch snapshot ended (`save`). Each is null when the run stopped before it,
561
+ * kept no runner sandbox, or saved none.
536
562
  */
537
- function endedWhere(where, runner) {
563
+ function endedWhere(where, runner, save) {
538
564
  if (where.kind === "local")
539
565
  return where;
540
566
  const snapshot = runner?.snapshot;
@@ -543,8 +569,15 @@ function endedWhere(where, runner) {
543
569
  sandbox: runner?.sandbox?.name ?? null,
544
570
  snapshot: snapshot === undefined || snapshot.kind === "building"
545
571
  ? null
546
- : { id: snapshot.id, base: snapshot.base, built: snapshot.kind === "built" },
572
+ : {
573
+ id: snapshot.id,
574
+ base: snapshot.base,
575
+ built: snapshot.kind === "built",
576
+ branch: snapshot.branch,
577
+ head: snapshot.head,
578
+ },
547
579
  keptUntil: runner?.kept?.stopsAt ?? null,
580
+ save,
548
581
  };
549
582
  }
550
583
  /** For each runner step that failed, where its whole output is: the summary's lines after the critical path. */
@@ -1,5 +1,5 @@
1
1
  /** The flags every run takes, as a usage line names them, before the command's own arguments. */
2
- export declare const RUN_USAGE_FLAGS = "[--testserver-sandboxes <N>] [--testserver-build <BUILD>] [--testserver-min-time-left <DURATION>] [--testserver-ttl <DURATION> | --testserver-no-create] [--set <KEY=VALUE>]... [--credential <SOURCE>] [--scope <TEAM> --project <PROJECT>] [--local | [--rebuild-snapshot] [--show-output] [--keep-sandbox <DURATION>]] [--verbose]";
2
+ export declare const RUN_USAGE_FLAGS = "[--testserver-sandboxes <N>] [--testserver-build <BUILD>] [--testserver-min-time-left <DURATION>] [--testserver-ttl <DURATION> | --testserver-no-create] [--set <KEY=VALUE>]... [--credential <SOURCE>] [--scope <TEAM> --project <PROJECT>] [--local | [--rebuild-snapshot] [--save-snapshot] [--show-output] [--keep-sandbox <DURATION>]] [--verbose]";
3
3
  /** The field descriptions of the flags every run takes. */
4
4
  export declare const RUN_FIELDS: {
5
5
  readonly testserverSandboxes: {
@@ -33,7 +33,10 @@ export declare const RUN_FIELDS: {
33
33
  readonly description: "Run the command on this machine instead of in a runner sandbox. Without it, the command runs in a Vercel Sandbox started from a runner snapshot of the base, with this checkout's changes applied, installed and built, from the runner key of storm.config.ts, and its output streams back with paths rewritten to this checkout's. No config key.";
34
34
  };
35
35
  readonly rebuildSnapshot: {
36
- readonly description: "Build a runner snapshot of the base whatever the runner snapshot cache holds, replacing an entry for the same base. Not with --local. No config key.";
36
+ readonly description: "Build a runner snapshot of the base whatever the runner snapshot cache holds, replacing an entry for the same base, and drop this branch's saved branch snapshots from the cache. Not with --local. No config key.";
37
+ };
38
+ readonly saveSnapshot: {
39
+ readonly description: "Once the command ends on its own after a successful install and build, save the runner sandbox as this branch's runner snapshot, so the next run on the branch starts from this run's install and build outputs. The run resets the working tree to the snapshot's base, keeps .git and ignored files such as node_modules and build outputs, and empties /tmp; the snapshot keeps whatever the command wrote there and to $HOME, a resource's token included. A run with it on a branch keeps no runner sandbox, even when it fails or stops before the save. With a detached HEAD it says so as it starts and keeps the runner sandbox as without the flag. Not with --local, or with --keep-sandbox above 0. No config key.";
37
40
  };
38
41
  readonly keepSandbox: {
39
42
  readonly valueLabel: "DURATION";
@@ -1,7 +1,7 @@
1
1
  // The help every run's command shares, `exec`'s and `vitest`'s: the usage of the flags every run takes, and their field
2
2
  // descriptions. Clinkr loads each command's metadata eagerly for navigation, so this module imports nothing.
3
3
  /** The flags every run takes, as a usage line names them, before the command's own arguments. */
4
- export const RUN_USAGE_FLAGS = "[--testserver-sandboxes <N>] [--testserver-build <BUILD>] [--testserver-min-time-left <DURATION>] [--testserver-ttl <DURATION> | --testserver-no-create] [--set <KEY=VALUE>]... [--credential <SOURCE>] [--scope <TEAM> --project <PROJECT>] [--local | [--rebuild-snapshot] [--show-output] [--keep-sandbox <DURATION>]] [--verbose]";
4
+ export const RUN_USAGE_FLAGS = "[--testserver-sandboxes <N>] [--testserver-build <BUILD>] [--testserver-min-time-left <DURATION>] [--testserver-ttl <DURATION> | --testserver-no-create] [--set <KEY=VALUE>]... [--credential <SOURCE>] [--scope <TEAM> --project <PROJECT>] [--local | [--rebuild-snapshot] [--save-snapshot] [--show-output] [--keep-sandbox <DURATION>]] [--verbose]";
5
5
  /** The field descriptions of the flags every run takes. */
6
6
  export const RUN_FIELDS = {
7
7
  testserverSandboxes: {
@@ -35,7 +35,10 @@ export const RUN_FIELDS = {
35
35
  description: "Run the command on this machine instead of in a runner sandbox. Without it, the command runs in a Vercel Sandbox started from a runner snapshot of the base, with this checkout's changes applied, installed and built, from the runner key of storm.config.ts, and its output streams back with paths rewritten to this checkout's. No config key.",
36
36
  },
37
37
  rebuildSnapshot: {
38
- description: "Build a runner snapshot of the base whatever the runner snapshot cache holds, replacing an entry for the same base. Not with --local. No config key.",
38
+ description: "Build a runner snapshot of the base whatever the runner snapshot cache holds, replacing an entry for the same base, and drop this branch's saved branch snapshots from the cache. Not with --local. No config key.",
39
+ },
40
+ saveSnapshot: {
41
+ description: "Once the command ends on its own after a successful install and build, save the runner sandbox as this branch's runner snapshot, so the next run on the branch starts from this run's install and build outputs. The run resets the working tree to the snapshot's base, keeps .git and ignored files such as node_modules and build outputs, and empties /tmp; the snapshot keeps whatever the command wrote there and to $HOME, a resource's token included. A run with it on a branch keeps no runner sandbox, even when it fails or stops before the save. With a detached HEAD it says so as it starts and keeps the runner sandbox as without the flag. Not with --local, or with --keep-sandbox above 0. No config key.",
39
42
  },
40
43
  keepSandbox: {
41
44
  valueLabel: "DURATION",