@cnc-tools/storm 0.10.0 → 0.11.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 (198) hide show
  1. package/dist/bin/storm.js +17 -9
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-YF3ICDBY.js → chunk-3ZZVZPMG.js} +1 -1
  4. package/dist/chunks/{chunk-JQ2HK4RN.js → chunk-4EU4AH7E.js} +141 -6
  5. package/dist/chunks/{chunk-ZJ2USLAT.js → chunk-4PRAB24Y.js} +2 -22
  6. package/dist/chunks/chunk-AMTYHUYB.js +257 -0
  7. package/dist/chunks/{chunk-WF4KJ7YG.js → chunk-ETCZ6WP7.js} +1 -1
  8. package/dist/chunks/chunk-FVMQKYTT.js +10 -0
  9. package/dist/chunks/{chunk-XHJGHJBW.js → chunk-GRMD7G4J.js} +33 -275
  10. package/dist/chunks/chunk-ICB4BZJX.js +22 -0
  11. package/dist/chunks/{chunk-AGWW3HDT.js → chunk-KR7WIYLG.js} +1826 -2201
  12. package/dist/chunks/{chunk-OVXD7GES.js → chunk-L4ZPMSKQ.js} +4 -37
  13. package/dist/chunks/chunk-NPPJ57W7.js +569 -0
  14. package/dist/chunks/{chunk-VJQLMGOH.js → chunk-O4BUT7BE.js} +361 -1716
  15. package/dist/chunks/chunk-OJOKQRM6.js +1457 -0
  16. package/dist/chunks/chunk-SLNKW4ZM.js +40 -0
  17. package/dist/chunks/{chunk-AKKNF3WZ.js → chunk-TRFEAYNC.js} +277 -348
  18. package/dist/chunks/chunk-VZZTHCBW.js +93 -0
  19. package/dist/chunks/chunk-WNIQA5J6.js +19 -0
  20. package/dist/chunks/chunk-WSIF7SR6.js +10 -0
  21. package/dist/chunks/{live-app-RIJM3QFD.js → live-app-LOGYUBKB.js} +52 -7
  22. package/dist/commands/exec/cleanup.d.ts +3 -3
  23. package/dist/commands/exec/cleanup.js +6 -2
  24. package/dist/commands/exec/command.d.ts +3 -3
  25. package/dist/commands/exec/command.js +17 -10
  26. package/dist/commands/exec/job-summary.d.ts +1 -1
  27. package/dist/commands/exec/job-summary.js +1 -1
  28. package/dist/commands/exec/live-view.js +5 -5
  29. package/dist/commands/exec/mint-failed.js +1 -1
  30. package/dist/commands/exec/outcomes.d.ts +2 -2
  31. package/dist/commands/exec/outcomes.js +7 -8
  32. package/dist/commands/exec/plan-run.d.ts +3 -5
  33. package/dist/commands/exec/progress.d.ts +3 -3
  34. package/dist/commands/exec/progress.js +6 -6
  35. package/dist/commands/exec/resource-refusals.d.ts +1 -1
  36. package/dist/commands/exec/resource-refusals.js +1 -1
  37. package/dist/commands/exec/run-command.d.ts +14 -9
  38. package/dist/commands/exec/run-command.js +91 -202
  39. package/dist/commands/exec/run-metadata.d.ts +2 -2
  40. package/dist/commands/exec/run-metadata.js +3 -3
  41. package/dist/commands/exec/test-plan.d.ts +1 -35
  42. package/dist/commands/exec/test-plan.js +4 -24
  43. package/dist/commands/exec/view.js +3 -3
  44. package/dist/commands/exec/waterfall.d.ts +3 -1
  45. package/dist/commands/exec/waterfall.js +18 -1
  46. package/dist/commands/runs/facts.d.ts +2 -1
  47. package/dist/commands/runs/facts.js +1 -1
  48. package/dist/commands/runs/list/command.js +10 -9
  49. package/dist/commands/runs/logs/command.js +14 -12
  50. package/dist/commands/runs/past-run.d.ts +3 -27
  51. package/dist/commands/runs/past-run.js +3 -37
  52. package/dist/commands/runs/show/command.js +24 -21
  53. package/dist/commands/runs/show/outcomes.js +2 -2
  54. package/dist/commands/vitest/command.d.ts +3 -3
  55. package/dist/commands/vitest/command.js +24 -17
  56. package/dist/commands/vitest/outcomes.d.ts +1 -1
  57. package/dist/commands/vitest/outcomes.js +1 -1
  58. package/dist/config/credential-resolver.d.ts +6 -3
  59. package/dist/config/credential-resolver.js +6 -5
  60. package/dist/context.d.ts +27 -9
  61. package/dist/context.js +19 -8
  62. package/dist/core/before-run.d.ts +5 -4
  63. package/dist/core/before-run.js +6 -6
  64. package/dist/core/definition-lookup.d.ts +22 -0
  65. package/dist/core/definition-lookup.js +34 -0
  66. package/dist/core/events.d.ts +5 -19
  67. package/dist/core/gateways.d.ts +22 -162
  68. package/dist/core/index.d.ts +10 -11
  69. package/dist/core/index.js +9 -11
  70. package/dist/core/launcher-supplies.js +2 -2
  71. package/dist/core/live/terminal-command-gateway.d.ts +8 -0
  72. package/dist/core/live/terminal-command-gateway.js +49 -0
  73. package/dist/core/presentations.d.ts +4 -3
  74. package/dist/core/presentations.js +4 -5
  75. package/dist/core/resource-registry.d.ts +35 -51
  76. package/dist/core/resource-registry.js +27 -54
  77. package/dist/core/resource-reports.d.ts +37 -4
  78. package/dist/core/resource-reports.js +34 -5
  79. package/dist/core/resources.d.ts +4 -3
  80. package/dist/core/resources.js +2 -4
  81. package/dist/core/run-state.d.ts +1 -1
  82. package/dist/core/run-state.js +1 -1
  83. package/dist/core/run.d.ts +19 -37
  84. package/dist/core/run.js +59 -114
  85. package/dist/core/timeline.js +2 -1
  86. package/dist/credential/events.d.ts +20 -0
  87. package/dist/credential/events.js +4 -0
  88. package/dist/credential/index.d.ts +2 -1
  89. package/dist/credential/index.js +6 -5
  90. package/dist/credential/source.d.ts +38 -26
  91. package/dist/credential/source.js +25 -34
  92. package/dist/extension-commands.d.ts +12 -6
  93. package/dist/extension-commands.js +18 -11
  94. package/dist/extensions/story/command-tree.d.ts +6 -0
  95. package/dist/extensions/story/command-tree.js +21 -0
  96. package/dist/extensions/story/commands/app.d.ts +23 -0
  97. package/dist/extensions/story/commands/app.js +5 -0
  98. package/dist/extensions/story/commands/run/command.d.ts +211 -0
  99. package/dist/extensions/story/commands/run/command.js +259 -0
  100. package/dist/extensions/story/commands/run/metadata.d.ts +4 -0
  101. package/dist/extensions/story/commands/run/metadata.js +8 -0
  102. package/dist/extensions/story/commands/run/outcomes.d.ts +101 -0
  103. package/dist/extensions/story/commands/run/outcomes.js +73 -0
  104. package/dist/extensions/story/commands/tree.d.ts +2 -0
  105. package/dist/extensions/story/commands/tree.js +6 -0
  106. package/dist/extensions/story/extension.d.ts +2 -0
  107. package/dist/extensions/story/extension.js +8 -0
  108. package/dist/extensions/testserver/command-tree.d.ts +1 -1
  109. package/dist/extensions/testserver/command-tree.js +0 -1
  110. package/dist/extensions/testserver/commands/pool/create/command.js +14 -8
  111. package/dist/extensions/testserver/commands/pool/list/command.js +8 -4
  112. package/dist/extensions/testserver/vitest/config.d.ts +7 -5
  113. package/dist/extensions/testserver/vitest/config.js +7 -5
  114. package/dist/extensions/testserver/vitest/fixtures.d.ts +2 -0
  115. package/dist/extensions/testserver/vitest/fixtures.js +36 -5
  116. package/dist/extensions.d.ts +12 -21
  117. package/dist/extensions.js +22 -34
  118. package/dist/forward-sigterm.d.ts +8 -0
  119. package/dist/forward-sigterm.js +18 -0
  120. package/dist/launcher-resolvers/index.d.ts +1 -0
  121. package/dist/launcher-resolvers/index.js +2 -1
  122. package/dist/launcher-resolvers/local-services.d.ts +57 -0
  123. package/dist/launcher-resolvers/local-services.js +7 -0
  124. package/dist/live-app.js +2 -1
  125. package/dist/local-services.d.ts +19 -0
  126. package/dist/local-services.js +37 -0
  127. package/dist/run-directory/gateways.d.ts +167 -0
  128. package/dist/run-directory/gateways.js +2 -0
  129. package/dist/run-directory/index.d.ts +8 -0
  130. package/dist/run-directory/index.js +13 -0
  131. package/dist/run-directory/plan.d.ts +35 -0
  132. package/dist/run-directory/plan.js +24 -0
  133. package/dist/run-directory/reader.d.ts +70 -0
  134. package/dist/run-directory/reader.js +51 -0
  135. package/dist/run-directory/recording.d.ts +92 -0
  136. package/dist/run-directory/recording.js +85 -0
  137. package/dist/{commands/exec → run-directory}/run-collector.d.ts +9 -8
  138. package/dist/{commands/exec → run-directory}/run-collector.js +8 -10
  139. package/dist/{core → run-directory}/run-directory.d.ts +3 -3
  140. package/dist/{core → run-directory}/run-directory.js +2 -2
  141. package/dist/{commands/exec → run-directory}/run-record.d.ts +29 -7
  142. package/dist/{commands/exec → run-directory}/run-record.js +79 -5
  143. package/dist/{commands/exec → run-directory}/timeline-facts.d.ts +4 -8
  144. package/dist/{commands/exec → run-directory}/timeline-facts.js +8 -24
  145. package/dist/runner/events.d.ts +6 -5
  146. package/dist/runner/index.d.ts +13 -17
  147. package/dist/runner/index.js +10 -14
  148. package/dist/runner/prepare.d.ts +28 -6
  149. package/dist/runner/prepare.js +15 -9
  150. package/dist/runner/recipe.d.ts +14 -0
  151. package/dist/runner/recipe.js +12 -0
  152. package/dist/runner/scope.d.ts +18 -11
  153. package/dist/runner/scope.js +12 -10
  154. package/dist/runner/session.d.ts +100 -0
  155. package/dist/runner/session.js +109 -0
  156. package/dist/runner/snapshot-save.d.ts +3 -2
  157. package/dist/runner/snapshot-save.js +6 -5
  158. package/dist/sdk/extension/ci.d.ts +2 -0
  159. package/dist/sdk/extension/ci.js +6 -0
  160. package/dist/sdk/extension/commands.d.ts +11 -13
  161. package/dist/sdk/extension/commands.js +5 -5
  162. package/dist/sdk/extension/index.d.ts +1 -0
  163. package/dist/sdk/extension/index.js +1 -0
  164. package/dist/sdk/extension/lifecycle.d.ts +4 -3
  165. package/dist/sdk/extension/progress.js +2 -2
  166. package/dist/sdk/extension/resource.js +1 -1
  167. package/dist/story/align.d.ts +1 -1
  168. package/dist/story/align.js +1 -1
  169. package/dist/story/command-line.d.ts +6 -16
  170. package/dist/story/command-line.js +11 -23
  171. package/dist/story/errors.d.ts +1 -1
  172. package/dist/story/errors.js +1 -1
  173. package/dist/story/host.d.ts +1 -1
  174. package/dist/story/host.js +2 -2
  175. package/dist/story/index.d.ts +2 -2
  176. package/dist/story/index.js +4 -3
  177. package/dist/story/launch.d.ts +70 -0
  178. package/dist/story/launch.js +77 -0
  179. package/dist/story/report.d.ts +2 -2
  180. package/dist/story/report.js +3 -4
  181. package/dist/story/settle.d.ts +7 -7
  182. package/dist/story/settle.js +5 -5
  183. package/dist/story/start.d.ts +2 -2
  184. package/dist/vendor/testserver-sdk/container/container.d.ts +11 -6
  185. package/dist/vendor/testserver-sdk/container/container.js +38 -16
  186. package/dist/vendor/testserver-sdk/testserver/failure.d.ts +4 -3
  187. package/dist/vendor/testserver-sdk/testserver/failure.js +4 -3
  188. package/package.json +1 -1
  189. package/skills/overview.md +3 -0
  190. package/skills/read-run-output.md +2 -2
  191. package/dist/chunks/chunk-H2VCSNVU.js +0 -351
  192. package/dist/chunks/chunk-J6ZNYUDV.js +0 -21
  193. package/dist/core/mint.d.ts +0 -10
  194. package/dist/core/mint.js +0 -14
  195. package/dist/story/mode.d.ts +0 -17
  196. package/dist/story/mode.js +0 -21
  197. /package/dist/{core → run-directory}/live/run-directory-gateway.d.ts +0 -0
  198. /package/dist/{core → run-directory}/live/run-directory-gateway.js +0 -0
@@ -2,13 +2,8 @@ import {
2
2
  versionText
3
3
  } from "./chunk-I5GZLOLQ.js";
4
4
  import {
5
- testsChart,
6
- testsSummaryLines,
7
- waterfallLines
8
- } from "./chunk-JQ2HK4RN.js";
9
- import {
10
- NodeSignalCancellation
11
- } from "./chunk-WF4KJ7YG.js";
5
+ forwardSigterm
6
+ } from "./chunk-WNIQA5J6.js";
12
7
  import {
13
8
  RESOURCE_FLAG_HELP,
14
9
  RESOURCE_USAGE_FLAGS,
@@ -17,51 +12,42 @@ import {
17
12
  resourceFlagFields,
18
13
  resourceFlagProblems,
19
14
  resourceFlagValues,
20
- runRecordText,
21
- saveSchema,
22
15
  testPlanLine,
23
- testTotals,
24
- timelineFacts,
25
- timelineSchema
26
- } from "./chunk-H2VCSNVU.js";
16
+ testsChart,
17
+ testsSummaryLines,
18
+ waterfallLines
19
+ } from "./chunk-4EU4AH7E.js";
20
+ import {
21
+ REGISTRY,
22
+ RESOURCES
23
+ } from "./chunk-NPPJ57W7.js";
27
24
  import {
28
- EMPTY_RUN_STATE,
29
- RESOURCES,
30
- RESOURCE_PRESENTATIONS,
31
- RESOURCE_REPORTS,
32
- RUN_CLEANUP,
33
- RUN_DIRECTORIES_KEPT,
34
- applyStormEvent,
35
- cleanupProblems,
36
- commandExitStatus,
37
- executeRun,
38
25
  isoSecondsText,
39
26
  keepTimeText,
40
- keptText,
41
- megabytesText,
42
- notDeletedText,
43
- notKeptText,
44
- notStoppedText,
45
- observeAll,
46
27
  paint,
47
28
  releaseText,
48
- resourceLifecycles,
49
- runDirectoryObserver,
50
- runnerCleanupWarnings,
29
+ sandboxConnectPage,
51
30
  seconds,
52
- secondsOf,
53
- secondsText,
54
31
  short,
55
32
  shortFile,
56
33
  spread,
57
- stepLog,
58
- stormTimeline,
59
- testEventsPath,
60
- timedProgress,
61
34
  truncate,
62
- visibleLength,
35
+ visibleLength
36
+ } from "./chunk-VZZTHCBW.js";
37
+ import {
38
+ EMPTY_RUN_STATE,
39
+ cleanupProblems,
40
+ commandExitStatus,
41
+ executeRun,
42
+ megabytesText,
43
+ recordRun,
44
+ saveSchema,
45
+ secondsOf,
46
+ secondsText,
47
+ timedProgress,
48
+ timelineSchema,
63
49
  warningTally
64
- } from "./chunk-AGWW3HDT.js";
50
+ } from "./chunk-KR7WIYLG.js";
65
51
  import {
66
52
  RUNNER_SECRET_MIN_LENGTH,
67
53
  configErrors,
@@ -71,42 +57,141 @@ import {
71
57
  loadSettingsFile,
72
58
  mintTargetText,
73
59
  parseKeepTime,
74
- parseTestEvent,
75
60
  prepareRunner,
76
61
  readRunnerSecrets,
77
62
  recipeRun,
78
63
  redactSecrets,
79
64
  requireTarget,
65
+ runStepTakesSecret,
80
66
  settleCredential,
81
- settleRunResources,
82
- testEventLine
83
- } from "./chunk-VJQLMGOH.js";
67
+ settleRunResources
68
+ } from "./chunk-O4BUT7BE.js";
84
69
  import {
85
- describeMintFailure
86
- } from "./chunk-XHJGHJBW.js";
70
+ describeMintFailure,
71
+ isCi
72
+ } from "./chunk-AMTYHUYB.js";
87
73
  import {
88
74
  defineErrors,
89
75
  defineOutcomes,
90
76
  refused,
91
77
  renderOutcome
92
- } from "./chunk-ZJ2USLAT.js";
78
+ } from "./chunk-4PRAB24Y.js";
93
79
 
94
80
  // src/commands/exec/outcomes.ts
95
- import { z as z3 } from "zod";
81
+ import { z as z4 } from "zod";
96
82
 
97
- // src/commands/exec/mint-failed.ts
83
+ // src/commands/exec/cleanup.ts
98
84
  import { z } from "zod";
85
+ var notStoppedSchema = z.object({
86
+ name: z.string(),
87
+ role: z.enum(["runner", "snapshot-build"]),
88
+ /** The sandbox's own timeout, in minutes, within which it stops. */
89
+ timeoutMinutes: z.number(),
90
+ message: z.string()
91
+ });
92
+ var notDeletedSchema = z.object({
93
+ name: z.string(),
94
+ role: z.enum(["runner", "snapshot-build"]),
95
+ message: z.string()
96
+ });
97
+ var keptSchema = z.object({
98
+ name: z.string(),
99
+ /** When its timeout stops it, as an ISO time: the keep time from when the run ended, or later. */
100
+ stopsAt: z.string(),
101
+ /** Its Connect page in the Vercel dashboard, which says how to open a shell in it. */
102
+ url: z.string()
103
+ });
104
+ var notKeptSchema = z.object({ name: z.string(), message: z.string() });
105
+ var runnerCleanupSchema = z.object({
106
+ kept: keptSchema.nullable(),
107
+ notKept: notKeptSchema.nullable(),
108
+ notStopped: z.array(notStoppedSchema),
109
+ notDeleted: z.array(notDeletedSchema)
110
+ });
111
+ function sandboxRole(role) {
112
+ return role === "runner" ? "runner sandbox" : "build sandbox";
113
+ }
114
+ function notStoppedText(sandbox) {
115
+ return `Couldn't stop the ${sandboxRole(sandbox.role)} ${sandbox.name}: ${sandbox.message}. Its own timeout stops it within ${sandbox.timeoutMinutes} minutes.`;
116
+ }
117
+ function notDeletedText(sandbox) {
118
+ return `Stopped the ${sandboxRole(sandbox.role)} ${sandbox.name}, but couldn't delete it: ${sandbox.message}. It stays listed in the Vercel project.`;
119
+ }
120
+ function keptText(kept) {
121
+ return `Kept the runner sandbox ${kept.name} running until ${isoSecondsText(kept.stopsAt)}, so you can connect to it: ${kept.url}`;
122
+ }
123
+ function notKeptText(sandbox) {
124
+ return `Couldn't keep the runner sandbox ${sandbox.name} running: ${sandbox.message}. Stopped and deleted it instead.`;
125
+ }
126
+ function runnerCleanupRows(cleanup) {
127
+ if (cleanup === null) return [];
128
+ const { kept, notKept } = cleanup;
129
+ return [
130
+ ...kept === null ? [] : [["Sandbox kept", [`${kept.name}, running until ${isoSecondsText(kept.stopsAt)}`, kept.url]]],
131
+ ...notKept === null ? [] : [["Sandbox not kept", notKeptText(notKept)]],
132
+ ...cleanup.notStopped.length === 0 ? [] : [["Sandboxes not stopped", cleanup.notStopped.map(notStoppedText)]],
133
+ ...cleanup.notDeleted.length === 0 ? [] : [["Sandboxes not deleted", cleanup.notDeleted.map(notDeletedText)]]
134
+ ];
135
+ }
136
+ function runnerCleanupWarnings(cleanup) {
137
+ if (cleanup === null) return [];
138
+ return [
139
+ ...cleanup.notKept === null ? [] : [{ reason: "runner_sandbox_not_kept", message: notKeptText(cleanup.notKept) }],
140
+ ...cleanup.notStopped.map((sandbox) => ({
141
+ reason: "runner_sandbox_not_stopped",
142
+ message: notStoppedText(sandbox)
143
+ })),
144
+ ...cleanup.notDeleted.map((sandbox) => ({
145
+ reason: "runner_sandbox_not_deleted",
146
+ message: notDeletedText(sandbox)
147
+ }))
148
+ ];
149
+ }
150
+ function runCleanupOf(reports) {
151
+ const schema = z.object({ runner: runnerCleanupSchema.nullable(), resources: reports.cleanupSchema });
152
+ const rows = (cleanup) => [
153
+ ...runnerCleanupRows(cleanup.runner),
154
+ ...reports.cleanupRows(cleanup.resources)
155
+ ];
156
+ return {
157
+ schema,
158
+ facts: ({ runnerCleanup, resourceCleanup }) => ({
159
+ runner: runnerCleanupOf(runnerCleanup),
160
+ resources: reports.cleanupFacts(resourceCleanup)
161
+ }),
162
+ rows
163
+ };
164
+ }
165
+ var RUN_CLEANUP = runCleanupOf(REGISTRY.reports);
166
+ function runnerCleanupOf(report) {
167
+ if (report === null) return null;
168
+ const { kept, target } = report;
169
+ return {
170
+ kept: kept === null ? null : { name: kept.name, stopsAt: kept.stopsAt, url: sandboxConnectPage(target, kept.name) },
171
+ notKept: report.notKept === null ? null : { ...report.notKept },
172
+ notStopped: report.notStopped.map(({ name, role, timeoutMinutes, message }) => ({
173
+ name,
174
+ role,
175
+ timeoutMinutes,
176
+ message
177
+ })),
178
+ notDeleted: report.notDeleted.map(({ name, role, message }) => ({ name, role, message }))
179
+ };
180
+ }
181
+
182
+ // src/commands/exec/mint-failed.ts
183
+ import { z as z2 } from "zod";
99
184
  var mintFailedErrors = defineErrors({
100
185
  mintFailed: {
101
186
  exitCode: 1,
102
187
  description: "The vercel CLI couldn't mint a credential, so the command didn't run. In a sandboxed run, the credential was for the runner sandbox, which always needs one; in an unsandboxed run, for a resource that couldn't go on without it.",
103
- schema: z.object({
104
- team: z.string(),
105
- project: z.string(),
106
- cause: z.string(),
107
- fix: z.string(),
188
+ schema: z2.object({
189
+ team: z2.string(),
190
+ project: z2.string(),
191
+ cause: z2.string(),
192
+ fix: z2.string(),
108
193
  /** Whether the credential was for the runner sandbox, not for a resource. */
109
- runner: z.boolean(),
194
+ runner: z2.boolean(),
110
195
  /** What the run couldn't clean up. */
111
196
  cleanup: RUN_CLEANUP.schema
112
197
  }),
@@ -122,14 +207,14 @@ var mintFailedErrors = defineErrors({
122
207
  });
123
208
 
124
209
  // src/commands/exec/resource-refusals.ts
125
- import { z as z2 } from "zod";
210
+ import { z as z3 } from "zod";
126
211
  var refusalShape = {
127
212
  /** The resource instance that refused, by its resource key. */
128
- resource: z2.string().min(1),
213
+ resource: z3.string().min(1),
129
214
  /** The resource's own snake_case reason for refusing. */
130
- refusal: z2.string(),
215
+ refusal: z3.string(),
131
216
  /** The resource's own data about the refusal, which differs by resource and reason. */
132
- data: z2.record(z2.string(), z2.unknown())
217
+ data: z3.record(z3.string(), z3.unknown())
133
218
  };
134
219
  function contentOf({ message, next, rows: own = [] }, rows) {
135
220
  const all = [...own, ...rows];
@@ -139,17 +224,17 @@ var resourceRefusalErrors = defineErrors({
139
224
  resourceRefusedBeforeRun: {
140
225
  exitCode: 2,
141
226
  description: "A resource's beforeRun refused the run before it started, so nothing was minted, acquired or started. data.resource names the resource by its key, data.refusal is the resource's own reason, and data.data its own data.",
142
- schema: z2.object({
227
+ schema: z3.object({
143
228
  ...refusalShape,
144
229
  /** The config file that applied (its absolute path); null when none did. */
145
- configFile: z2.string().nullable()
230
+ configFile: z3.string().nullable()
146
231
  }),
147
232
  render: (_data, refusal) => contentOf(refusal, [])
148
233
  },
149
234
  resourceRefused: {
150
235
  exitCode: 1,
151
236
  description: "A resource refused while the run acquired its resources, so the command didn't run. data.resource names the resource by its key, data.refusal is the resource's own reason, and data.data its own data.",
152
- schema: z2.object({
237
+ schema: z3.object({
153
238
  ...refusalShape,
154
239
  /** What the run couldn't clean up. */
155
240
  cleanup: RUN_CLEANUP.schema
@@ -173,32 +258,32 @@ function resourceRefused(outcome, cleanup) {
173
258
  }
174
259
 
175
260
  // src/commands/exec/outcomes.ts
176
- var runnerFailureSchema = z3.union([
177
- z3.object({
178
- kind: z3.enum(["snapshot-build-step-failed", "apply-failed", "install-failed", "build-failed"]),
261
+ var runnerFailureSchema = z4.union([
262
+ z4.object({
263
+ kind: z4.enum(["snapshot-build-step-failed", "apply-failed", "install-failed", "build-failed"]),
179
264
  /** The step's label. */
180
- label: z3.string(),
265
+ label: z4.string(),
181
266
  /** Its exit code; null when it ended without one. */
182
- exitCode: z3.number().nullable(),
267
+ exitCode: z4.number().nullable(),
183
268
  /** Its last 40 output lines. */
184
- tail: z3.array(z3.string())
269
+ tail: z4.array(z4.string())
185
270
  }),
186
- z3.object({
187
- kind: z3.literal("sandbox-api-failed"),
271
+ z4.object({
272
+ kind: z4.literal("sandbox-api-failed"),
188
273
  /** The Sandbox call that failed. */
189
- operation: z3.string(),
274
+ operation: z4.string(),
190
275
  /** The HTTP status the Sandbox API answered; null when it answered none. */
191
- status: z3.number().nullable(),
192
- message: z3.string()
276
+ status: z4.number().nullable(),
277
+ message: z4.string()
193
278
  }),
194
- z3.object({
195
- kind: z3.literal("checkout-failed"),
279
+ z4.object({
280
+ kind: z4.literal("checkout-failed"),
196
281
  /** What git or tar said. */
197
- message: z3.string(),
282
+ message: z4.string(),
198
283
  /** The failed command; null when there was none. */
199
- command: z3.string().nullable()
284
+ command: z4.string().nullable()
200
285
  }),
201
- z3.object({ kind: z3.literal("credential-claims-missing"), team: z3.string(), project: z3.string() })
286
+ z4.object({ kind: z4.literal("credential-claims-missing"), team: z4.string(), project: z4.string() })
202
287
  ]);
203
288
  function listed(names) {
204
289
  if (names.length <= 1) return names.join("");
@@ -246,19 +331,19 @@ function runnerFailureText(failure) {
246
331
  };
247
332
  }
248
333
  }
249
- var ranSchema = z3.object({
334
+ var ranSchema = z4.object({
250
335
  /** storm's version. */
251
- version: z3.string(),
336
+ version: z4.string(),
252
337
  /** The git commit storm was built from, as its version line shows it (`3f2a9c1b7d4e`, `-dirty` appended when built from a tree with uncommitted changes); null when unknown. */
253
- commit: z3.string().nullable(),
338
+ commit: z4.string().nullable(),
254
339
  /** The config file the run's settings came from (its absolute path); null when none applied. */
255
- configFile: z3.string().nullable(),
340
+ configFile: z4.string().nullable(),
256
341
  /**
257
342
  * What each acquired resource instance that reports something says of itself, keyed by resource key: its
258
343
  * definition's name (`definition`), its facts (`facts`, what its acquire answered, unknown to the schema, or null
259
344
  * when it answered none) and the warnings its acquire reported (`warnings`).
260
345
  */
261
- resources: RESOURCE_REPORTS.ranSchema,
346
+ resources: REGISTRY.reports.ranSchema,
262
347
  /**
263
348
  * What the run's cleanup left: the runner sandbox it kept running and the runner's sandboxes it couldn't stop or
264
349
  * delete (`runner`, null without a runner sandbox), and what releasing each of its resource instances couldn't do,
@@ -269,36 +354,36 @@ var ranSchema = z3.object({
269
354
  * How the command ended: its exit code, or the signal that ended it; both null for a command in the runner sandbox
270
355
  * that ended without an exit code.
271
356
  */
272
- command: z3.object({ exitCode: z3.number().nullable(), signal: z3.string().nullable() }),
357
+ command: z4.object({ exitCode: z4.number().nullable(), signal: z4.string().nullable() }),
273
358
  /** The runner sandbox the command ran in; null without one. */
274
- runner: z3.object({
359
+ runner: z4.object({
275
360
  /** The runner snapshot it started from. */
276
- snapshotId: z3.string(),
361
+ snapshotId: z4.string(),
277
362
  /** The runner snapshot's base, a full SHA. */
278
- base: z3.string(),
363
+ base: z4.string(),
279
364
  /** For a branch snapshot, the local branch of the run that saved it; null for a base snapshot. */
280
- snapshotBranch: z3.string().nullable(),
365
+ snapshotBranch: z4.string().nullable(),
281
366
  /** For a branch snapshot, the HEAD commit of the run that saved it, a full SHA; null for a base snapshot. */
282
- snapshotHead: z3.string().nullable(),
367
+ snapshotHead: z4.string().nullable(),
283
368
  /** Whether this run built the runner snapshot. */
284
- built: z3.boolean(),
285
- vcpus: z3.number(),
286
- region: z3.string(),
287
- runtime: z3.string(),
369
+ built: z4.boolean(),
370
+ vcpus: z4.number(),
371
+ region: z4.string(),
372
+ runtime: z4.string(),
288
373
  /** How long the build step took, in milliseconds. */
289
- buildMs: z3.number(),
290
- /** How saving the runner sandbox as a branch snapshot ended (--save-snapshot); null without the flag. */
374
+ buildMs: z4.number(),
375
+ /** How saving the runner sandbox as a branch snapshot ended; null when the run started no save. */
291
376
  save: saveSchema.nullable()
292
377
  }).nullable(),
293
378
  /** The run's waterfall, as the run directory's timeline.json holds it: each lane's label, span and steps in milliseconds since the run started, how they ended, idle time, and the critical path. */
294
379
  timeline: timelineSchema,
295
380
  /** The run's run directory's run id, which `storm runs show` takes; null when the run couldn't make one. */
296
- runId: z3.string().nullable()
381
+ runId: z4.string().nullable()
297
382
  });
298
383
  var RAN_DESCRIPTION = "The command ran and ended. storm exits with its code, or 128 + n when signal n ended it, whatever this result's exit code.";
299
384
  function renderRan(ran) {
300
385
  const warnings = [
301
- ...RESOURCE_REPORTS.ranWarnings(ran.resources),
386
+ ...REGISTRY.reports.ranWarnings(ran.resources),
302
387
  ...ran.runner !== null && ran.command.exitCode === null && ran.command.signal === null ? [
303
388
  {
304
389
  reason: "sandboxed_no_exit_code",
@@ -306,7 +391,7 @@ function renderRan(ran) {
306
391
  }
307
392
  ] : [],
308
393
  ...runnerCleanupWarnings(ran.cleanup.runner),
309
- ...RESOURCE_REPORTS.cleanupWarnings(ran.cleanup.resources)
394
+ ...REGISTRY.reports.cleanupWarnings(ran.cleanup.resources)
310
395
  ];
311
396
  const kept = ran.cleanup.runner?.kept ?? null;
312
397
  return renderOutcome({
@@ -318,11 +403,11 @@ var runErrors = defineErrors({
318
403
  credentialUnused: {
319
404
  exitCode: 2,
320
405
  description: "--credential was given to a run with no resource that takes a credential.",
321
- schema: z3.object({
406
+ schema: z4.object({
322
407
  /** The flags given that none of the run's resources takes, as typed, such as --credential. */
323
- flags: z3.array(z3.string()),
408
+ flags: z4.array(z4.string()),
324
409
  /** The config file that applied; null when none did. */
325
- configFile: z3.string().nullable()
410
+ configFile: z4.string().nullable()
326
411
  }),
327
412
  render: ({ flags }) => ({
328
413
  message: `${flags.join(", ")} ${flags.length === 1 ? "applies" : "apply"} only to a run with a resource that takes a credential, and this run has none.`,
@@ -337,9 +422,9 @@ var runErrors = defineErrors({
337
422
  missingRunner: {
338
423
  exitCode: 2,
339
424
  description: "A sandboxed run (no --unsandboxed) needs a runner recipe, and no storm.config.ts gives a runner key.",
340
- schema: z3.object({
425
+ schema: z4.object({
341
426
  /** The config file that applied; null when none did. */
342
- configFile: z3.string().nullable()
427
+ configFile: z4.string().nullable()
343
428
  }),
344
429
  render: ({ configFile }) => ({
345
430
  message: configFile === null ? "A sandboxed run needs a runner recipe, and no storm.config.ts applies." : `A sandboxed run needs a runner recipe, and ${configFile} has no runner key.`,
@@ -354,13 +439,13 @@ var runErrors = defineErrors({
354
439
  runnerSecretsInvalid: {
355
440
  exitCode: 2,
356
441
  description: "In a sandboxed run, launcher environment variables the runner recipe's secrets key names can't be used, so the run didn't start: it minted, acquired and created nothing. Each variable has one problem, the first of: missing, unset or empty; multiline, its value holds a carriage return or a line feed, which line-by-line output would split past storm's redaction; short, its value holds fewer than 8 characters, and storm shows each value as <token> wherever it appears in what it prints and writes, so a value that short would hide ordinary output.",
357
- schema: z3.object({
442
+ schema: z4.object({
358
443
  /** Each variable storm can't use and why, in the recipe's order. */
359
- variables: z3.array(z3.object({ name: z3.string(), problem: z3.enum(["missing", "multiline", "short"]) })),
444
+ variables: z4.array(z4.object({ name: z4.string(), problem: z4.enum(["missing", "multiline", "short"]) })),
360
445
  /** The fewest characters a runner secret's value may have. */
361
- minLength: z3.number(),
446
+ minLength: z4.number(),
362
447
  /** The config file that gave the runner recipe. */
363
- configFile: z3.string().nullable()
448
+ configFile: z4.string().nullable()
364
449
  }),
365
450
  render: ({ variables, minLength, configFile }) => {
366
451
  const named = (problem) => variables.filter((variable) => variable.problem === problem).map(({ name }) => name);
@@ -394,9 +479,9 @@ var runErrors = defineErrors({
394
479
  noBaseRef: {
395
480
  exitCode: 1,
396
481
  description: "In a sandboxed run, none of the runner recipe's baseRefs exists locally and shares history with HEAD, so there is no base. storm never fetches.",
397
- schema: z3.object({
482
+ schema: z4.object({
398
483
  /** Each ref in baseRefs, and why it gave no base. */
399
- refs: z3.array(z3.object({ ref: z3.string(), reason: z3.enum(["missing", "unrelated"]) }))
484
+ refs: z4.array(z4.object({ ref: z4.string(), reason: z4.enum(["missing", "unrelated"]) }))
400
485
  }),
401
486
  render: ({ refs }) => ({
402
487
  message: `No base for the runner: none of ${refs.map(({ ref }) => ref).join(", ")} exists locally and shares history with HEAD. The command didn't run.`,
@@ -419,7 +504,7 @@ var runErrors = defineErrors({
419
504
  submodulesRefused: {
420
505
  exitCode: 1,
421
506
  description: "In a sandboxed run, the checkout has Git submodules, which neither the upload nor the base's files carry.",
422
- schema: z3.object({ paths: z3.array(z3.string()) }),
507
+ schema: z4.object({ paths: z4.array(z4.string()) }),
423
508
  render: ({ paths }) => ({
424
509
  message: `The checkout has Git submodules, which the runner can't carry: ${paths.join(", ")}. The command didn't run.`,
425
510
  next: [{ type: "text", text: "Run on this machine with --unsandboxed." }]
@@ -428,12 +513,12 @@ var runErrors = defineErrors({
428
513
  snapshotGone: {
429
514
  exitCode: 1,
430
515
  description: "In a sandboxed run, the cached runner snapshot the run picked was gone (the Sandbox API answered 410), so its cache entry was removed and the command didn't run. The next run picks another runner snapshot or builds one.",
431
- schema: z3.object({
432
- snapshotId: z3.string(),
516
+ schema: z4.object({
517
+ snapshotId: z4.string(),
433
518
  /** The runner snapshot's base, a full SHA. */
434
- base: z3.string(),
519
+ base: z4.string(),
435
520
  /** Why its cache entry couldn't be removed; null when it was. */
436
- removal: z3.object({ path: z3.string(), message: z3.string() }).nullable(),
521
+ removal: z4.object({ path: z4.string(), message: z4.string() }).nullable(),
437
522
  /** What the run couldn't clean up. */
438
523
  cleanup: RUN_CLEANUP.schema
439
524
  }),
@@ -454,7 +539,7 @@ var runErrors = defineErrors({
454
539
  runnerFailed: {
455
540
  exitCode: 1,
456
541
  description: "In a sandboxed run, the runner couldn't run the command: a snapshot build step, applying the changes, the install or the build failed (with the step's last 40 output lines), a Vercel Sandbox call failed, git or tar failed on this machine, or the credential names no team and project ids.",
457
- schema: z3.object({
542
+ schema: z4.object({
458
543
  failure: runnerFailureSchema,
459
544
  /** What the run couldn't clean up; its `runner` is null when the run failed before it started a sandbox. */
460
545
  cleanup: RUN_CLEANUP.schema
@@ -472,11 +557,11 @@ var runErrors = defineErrors({
472
557
  spawnFailed: {
473
558
  exitCode: 1,
474
559
  description: "The command couldn't start.",
475
- schema: z3.object({
560
+ schema: z4.object({
476
561
  /** The command's first argument: what storm tried to run. */
477
- executable: z3.string(),
562
+ executable: z4.string(),
478
563
  /** What the OS said. */
479
- message: z3.string(),
564
+ message: z4.string(),
480
565
  /**
481
566
  * What the run couldn't clean up; its `runner` is null, since only a run without a runner sandbox spawns its
482
567
  * command here.
@@ -610,7 +695,7 @@ function canceledBeforeStart() {
610
695
  }
611
696
 
612
697
  // src/commands/exec/run-command.ts
613
- import { z as z4 } from "zod";
698
+ import { z as z5 } from "zod";
614
699
 
615
700
  // src/commands/exec/job-summary.ts
616
701
  function jobSummaryMarkdown(timeline, extras) {
@@ -664,7 +749,7 @@ function plainRenderer(options) {
664
749
  cleanupStartedAt: void 0,
665
750
  folded: false
666
751
  };
667
- const resources = RESOURCE_PRESENTATIONS.plain({ verbose: options.verbose === true });
752
+ const resources = REGISTRY.presentations.plain({ verbose: options.verbose === true });
668
753
  return ({ event, at }) => {
669
754
  const now = at.getTime();
670
755
  state.origin ??= now;
@@ -678,7 +763,7 @@ function progressLine(elapsedMs, lane, text) {
678
763
  return `[+${secondsText(secondsOf(elapsedMs))}] ${lane.padEnd(LANE_WIDTH)} ${text}`;
679
764
  }
680
765
  var LANE_WIDTH = Math.max(
681
- ...["run", "mint", "runner", "command", "cleanup", ...RESOURCE_PRESENTATIONS.laneKinds.map(({ lane }) => lane)].map(
766
+ ...["run", "mint", "runner", "command", "cleanup", ...REGISTRY.presentations.laneKinds.map(({ lane }) => lane)].map(
682
767
  (lane) => lane.length
683
768
  )
684
769
  );
@@ -949,10 +1034,10 @@ function activePhase(state) {
949
1034
  return void 0;
950
1035
  }
951
1036
  function instanceLanes(state) {
952
- return RESOURCE_PRESENTATIONS.lanes(state.instances ?? []);
1037
+ return REGISTRY.presentations.lanes(state.instances ?? []);
953
1038
  }
954
1039
  function startedLanes(state) {
955
- return RESOURCE_PRESENTATIONS.lanes(
1040
+ return REGISTRY.presentations.lanes(
956
1041
  Object.entries(state.resources).map(([resource, { definition }]) => ({ resource, definition }))
957
1042
  );
958
1043
  }
@@ -1318,7 +1403,7 @@ function liveView(context, colors, options) {
1318
1403
  observer: {
1319
1404
  observe: async (timed) => {
1320
1405
  if (finished) return;
1321
- state = applyStormEvent(state, timed);
1406
+ state = REGISTRY.applyEvent(state, timed);
1322
1407
  const next = activePhase(state);
1323
1408
  if (next !== phase) {
1324
1409
  print([
@@ -1363,7 +1448,7 @@ function noticeLines(timed, origin, verbose) {
1363
1448
  case "runner":
1364
1449
  return runnerNoticeLines(event.event, line);
1365
1450
  case "resource":
1366
- return RESOURCE_PRESENTATIONS.notices(event, { verbose }).map(({ lane, text }) => line(lane, text));
1451
+ return REGISTRY.presentations.notices(event, { verbose }).map(({ lane, text }) => line(lane, text));
1367
1452
  // A line a resource instance reported prints as it is, in its lane, and a warning marked as one.
1368
1453
  case "resource-notice":
1369
1454
  return [line(event.lane, event.text)];
@@ -1424,77 +1509,23 @@ function runnerNoticeLines(event, line) {
1424
1509
  }
1425
1510
  }
1426
1511
 
1427
- // src/commands/exec/run-collector.ts
1428
- function runCollector(directory) {
1429
- let state = EMPTY_RUN_STATE;
1430
- const events = [];
1431
- let unreadable = 0;
1432
- let incomplete;
1433
- let workerOffsetMs = Infinity;
1434
- const collect = (event) => {
1435
- directory?.appendTestEvent(testEventLine(event));
1436
- events.push(summaryEvent(event));
1437
- };
1438
- return {
1439
- observer: {
1440
- observe: async (timed) => {
1441
- const { event } = timed;
1442
- if (event.kind === "runner" && event.event.kind === "step-output") return;
1443
- state = applyStormEvent(state, timed);
1444
- if (event.kind === "test") {
1445
- collect(event.event);
1446
- if (event.event.kind !== "test-result")
1447
- workerOffsetMs = Math.min(workerOffsetMs, timed.at.getTime() - event.event.at);
1448
- } else if (event.kind === "test-event-unreadable") unreadable += 1;
1449
- else if (event.kind === "test-events-incomplete") incomplete ??= event.message;
1450
- }
1451
- },
1452
- readStaged: async (runDirectory, redact) => {
1453
- const read = await runDirectory.readTestEvents((line) => {
1454
- const event = parseTestEvent(line);
1455
- if (event === void 0) unreadable += 1;
1456
- else collect(redactStrings(event, redact));
1457
- });
1458
- if (!read.ok) incomplete ??= read.failure.message;
1459
- },
1460
- finish: () => ({
1461
- state,
1462
- tests: { events, unreadable, incomplete },
1463
- workerOffsetMs: workerOffsetMs === Infinity ? 0 : workerOffsetMs
1464
- })
1465
- };
1466
- }
1467
- function summaryEvent(event) {
1468
- if (event.kind !== "test-result") return event;
1469
- return {
1470
- kind: event.kind,
1471
- id: event.id,
1472
- file: event.file,
1473
- test: event.test,
1474
- state: event.state,
1475
- retryCount: event.retryCount,
1476
- flaky: event.flaky,
1477
- at: event.at
1478
- };
1479
- }
1480
-
1481
1512
  // src/commands/exec/run-command.ts
1482
1513
  var OWN_RUN_FIELDS = {
1483
- scope: z4.string().min(1).optional(),
1484
- project: z4.string().min(1).optional(),
1485
- credential: z4.enum(["mint", "github-actions"]).optional(),
1486
- unsandboxed: z4.boolean().default(false),
1487
- rebuildSnapshot: z4.boolean().default(false),
1488
- saveSnapshot: z4.boolean().default(false),
1489
- showOutput: z4.boolean().default(false),
1490
- keepSandbox: z4.string().optional(),
1491
- verbose: z4.boolean().default(false)
1514
+ scope: z5.string().min(1).optional(),
1515
+ project: z5.string().min(1).optional(),
1516
+ credential: z5.enum(["mint", "github-actions"]).optional(),
1517
+ unsandboxed: z5.boolean().default(false),
1518
+ rebuildSnapshot: z5.boolean().default(false),
1519
+ saveSnapshot: z5.boolean().optional(),
1520
+ showOutput: z5.boolean().default(false),
1521
+ keepSandbox: z5.string().optional(),
1522
+ verbose: z5.boolean().default(false)
1492
1523
  };
1493
1524
  var RUN_REQUEST_FIELDS = { ...OWN_RUN_FIELDS, ...resourceFlagFields(Object.keys(OWN_RUN_FIELDS)) };
1494
1525
  var RUN_CLI_OPTIONS = { project: { short: "p" } };
1495
- var runRequestSchema = z4.object(RUN_REQUEST_FIELDS);
1526
+ var runRequestSchema = z5.object(RUN_REQUEST_FIELDS);
1496
1527
  async function runCommand({ app, ui, signal }, request, spec) {
1497
- const lifecycles = resourceLifecycles(app.worlds);
1528
+ const lifecycles = REGISTRY.lifecycles(app.worlds);
1498
1529
  const planned = await planRun(
1499
1530
  app,
1500
1531
  lifecycles,
@@ -1525,13 +1556,7 @@ async function runCommand({ app, ui, signal }, request, spec) {
1525
1556
  const { run } = requested;
1526
1557
  const secrets = [...used.secrets, ...Object.values(run.runner?.secrets ?? {})];
1527
1558
  const redact = redactor(secrets);
1528
- const terminate = new AbortController();
1529
- const forward = () => {
1530
- const reason = signal.reason;
1531
- if (reason instanceof NodeSignalCancellation && reason.signal === "SIGTERM") terminate.abort(reason);
1532
- };
1533
- if (signal.aborted) forward();
1534
- else signal.addEventListener("abort", forward, { once: true });
1559
+ const sigterm = forwardSigterm(signal);
1535
1560
  const view = runView({
1536
1561
  presentation: app.presentation,
1537
1562
  progress: ui.progress,
@@ -1540,57 +1565,37 @@ async function runCommand({ app, ui, signal }, request, spec) {
1540
1565
  verbose: request.verbose
1541
1566
  });
1542
1567
  const git = await checkoutGit(app.context.checkout, app.cwd);
1543
- const startedAt = app.context.clock.now();
1544
- const record = redactStrings(
1545
- {
1546
- version: 3,
1547
- startedAt: startedAt.toISOString(),
1548
- cwd: app.cwd,
1549
- configFile,
1550
- argv,
1551
- ...plan === void 0 ? {} : { plan },
1552
- where: startedWhere(run),
1553
- git
1554
- },
1555
- redact
1556
- );
1557
- const opened = await app.context.runDirectories.open({
1558
- startedAt,
1559
- keep: RUN_DIRECTORIES_KEPT,
1560
- run: runRecordText(record)
1568
+ const recording = await recordRun(app.context.runDirectories, {
1569
+ registry: REGISTRY,
1570
+ startedAt: app.context.clock.now(),
1571
+ cwd: app.cwd,
1572
+ configFile,
1573
+ argv,
1574
+ plan,
1575
+ run,
1576
+ git,
1577
+ redact: (value) => redactStrings(value, redact)
1561
1578
  });
1562
- const directory = opened.ok ? opened.directory : void 0;
1563
- const collector = runCollector(directory);
1564
- const observers = [collector.observer, view.observer];
1565
- if (directory !== void 0) observers.push(runDirectoryObserver(directory));
1566
- const observer = observeAll(...observers);
1567
- const terminal = teeTerminal(view.runnerTerminal, directory);
1579
+ const observer = recording.observer(view.observer);
1580
+ const terminal = recording.terminal(view.runnerTerminal);
1568
1581
  let outcome;
1569
1582
  try {
1570
1583
  const ended = await executeRun(
1571
- RESOURCES,
1584
+ REGISTRY,
1572
1585
  { ...app.context, runnerTerminal: secrets.length === 0 ? terminal : redactingTerminal(terminal, redact) },
1573
1586
  app.worlds,
1574
- run.runner === void 0 && directory !== void 0 ? { ...run, testEvents: testEventsPath(directory.path) } : run,
1575
- { signal, terminate: terminate.signal },
1587
+ run.runner === void 0 && recording.testEvents !== void 0 ? { ...run, testEvents: recording.testEvents } : run,
1588
+ { signal, terminate: sigterm.terminate },
1576
1589
  timedProgress(app.context.clock, secrets.length === 0 ? observer : redactingObserver(observer, redact))
1577
1590
  );
1578
1591
  outcome = secrets.length === 0 ? ended : redactStrings(ended, redact);
1579
1592
  } catch (error) {
1580
1593
  await view.finish([]);
1581
- await directory?.close();
1594
+ await recording.abandon();
1582
1595
  throw error;
1583
1596
  }
1584
- signal.removeEventListener("abort", forward);
1585
- const ran = await summarize(app, {
1586
- command: spec.name,
1587
- view,
1588
- collector,
1589
- opened,
1590
- redact,
1591
- record,
1592
- outcome
1593
- });
1597
+ sigterm.release();
1598
+ const ran = await summarize(app, { command: spec.name, view, recording, outcome });
1594
1599
  switch (outcome.kind) {
1595
1600
  case "ran": {
1596
1601
  app.exit.status = commandExitStatus(outcome.command);
@@ -1600,7 +1605,7 @@ async function runCommand({ app, ui, signal }, request, spec) {
1600
1605
  version: app.version,
1601
1606
  commit: app.commit,
1602
1607
  configFile,
1603
- resources: RESOURCE_REPORTS.ranFacts(outcome.resources),
1608
+ resources: REGISTRY.reports.ranFacts(outcome.resources),
1604
1609
  cleanup: RUN_CLEANUP.facts(outcome),
1605
1610
  command: command.kind === "exited" ? { exitCode: command.code, signal: null } : command.kind === "signaled" ? { exitCode: null, signal: command.signal } : { exitCode: null, signal: null },
1606
1611
  runner: outcome.runner === void 0 ? null : {
@@ -1616,7 +1621,7 @@ async function runCommand({ app, ui, signal }, request, spec) {
1616
1621
  save: outcome.runner.save
1617
1622
  },
1618
1623
  timeline: ran,
1619
- runId: directory?.id ?? null
1624
+ runId: recording.opened.ok ? recording.opened.id : null
1620
1625
  },
1621
1626
  { testPlan, options: planOptions }
1622
1627
  );
@@ -1689,13 +1694,13 @@ function runProblems(request) {
1689
1694
  message: "--keep-sandbox keeps a sandboxed run's runner sandbox; drop it or --unsandboxed."
1690
1695
  }
1691
1696
  ] : [],
1692
- ...saveSnapshot && unsandboxed ? [
1697
+ ...saveSnapshot === true && unsandboxed ? [
1693
1698
  {
1694
1699
  field: "saveSnapshot",
1695
1700
  message: "--save-snapshot saves a sandboxed run's runner sandbox; drop it or --unsandboxed."
1696
1701
  }
1697
1702
  ] : [],
1698
- ...saveSnapshot && keepSandbox !== void 0 && (parseKeepTime(keepSandbox) ?? 0) > 0 ? [
1703
+ ...saveSnapshot === true && keepsSandbox(keepSandbox) ? [
1699
1704
  {
1700
1705
  field: "saveSnapshot",
1701
1706
  message: "--save-snapshot saves the runner sandbox instead of keeping it; drop --keep-sandbox or set it to 0."
@@ -1720,7 +1725,8 @@ async function runRequestFor(app, options) {
1720
1725
  // The recipe's `vcpus` reads each of the run's resources by its definition: one its `beforeRun` skipped isn't.
1721
1726
  vcpusRun: recipeRun(recipeResources(used.requests)),
1722
1727
  rebuild: request.rebuildSnapshot,
1723
- saveSnapshot: request.saveSnapshot
1728
+ save: saveMode(request, where.recipe, app.env),
1729
+ trustBranchSnapshots: request.saveSnapshot ?? where.recipe.saveSnapshot === true
1724
1730
  });
1725
1731
  if (prepared.kind !== "ok") {
1726
1732
  const refusal = prepareRefusal(prepared, configFile);
@@ -1731,6 +1737,7 @@ async function runRequestFor(app, options) {
1731
1737
  };
1732
1738
  }
1733
1739
  const { save } = prepared.prepared;
1740
+ const keepMs = keepSandboxMinutes(request.keepSandbox, where.recipe, app.env) * 6e4;
1734
1741
  const run = {
1735
1742
  ...base,
1736
1743
  resources: used.requests,
@@ -1740,7 +1747,7 @@ async function runRequestFor(app, options) {
1740
1747
  target: where.target,
1741
1748
  user: app.user,
1742
1749
  secrets: where.secrets,
1743
- sandbox: save?.kind === "branch" ? { kind: "save", branch: save.branch } : { kind: "keep", ms: keepSandboxMinutes(request.keepSandbox, where.recipe, app.env) * 6e4 }
1750
+ sandbox: save?.kind === "branch" ? { kind: "save", branch: save.branch, always: save.always, otherwiseKeepMs: keepMs } : { kind: "keep", ms: keepMs }
1744
1751
  }
1745
1752
  };
1746
1753
  return { ok: true, run };
@@ -1766,36 +1773,19 @@ function checkoutFailedRefusal(failure) {
1766
1773
  });
1767
1774
  }
1768
1775
  async function summarize(app, run) {
1769
- const { view, opened } = run;
1770
- const directory = opened.ok ? opened.directory : void 0;
1771
- if (directory !== void 0) await run.collector.readStaged(directory, run.redact);
1772
- const collected = run.collector.finish();
1773
- const { state, tests } = collected;
1774
- const ran = stormTimeline(state);
1775
- const timeline = timelineFacts(ran);
1776
- directory?.publishTestEvents();
1777
- directory?.writeTimeline(JSON.stringify(timeline, null, 2));
1778
- directory?.writeRun(
1779
- runRecordText({
1780
- ...run.record,
1781
- where: endedWhere(
1782
- run.record.where,
1783
- state.runner,
1784
- run.outcome.kind === "ran" ? run.outcome.runner?.save ?? null : null
1785
- ),
1786
- ended: runEnd(run.outcome, state.command, tests)
1787
- })
1788
- );
1789
- const writeFailure = await directory?.close();
1776
+ const { view, recording } = run;
1777
+ const recorded = await recording.end(run.outcome);
1778
+ const { timeline, tests } = recorded;
1779
+ const logs = recording.opened.ok ? recording.opened.path : void 0;
1790
1780
  const failed = tests.events.some((event) => event.kind === "test-result" && event.state === "fail");
1791
1781
  const testsLines = testsSummaryLines(tests.events, tests.unreadable, tests.incomplete);
1792
- const stepLogs = failedStepLogs(ran, directory?.path, app.env);
1793
- const clock = workerClock(ran, collected);
1782
+ const stepLogs = failedStepLogs(timeline, recording, app.env);
1783
+ const clock = workerClock(recorded);
1794
1784
  const charted = clock === void 0 ? void 0 : testsChart(tests.events, tests.unreadable, clock, tests.incomplete);
1795
1785
  const summarized = await app.context.jobSummary.appendJobSummary(
1796
1786
  jobSummaryMarkdown(timeline, {
1797
1787
  command: run.command,
1798
- logs: directory?.path,
1788
+ logs,
1799
1789
  details: [...testsLines, ...stepLogs]
1800
1790
  })
1801
1791
  );
@@ -1803,7 +1793,7 @@ async function summarize(app, run) {
1803
1793
  waterfallLines(timeline, {
1804
1794
  width: view.width,
1805
1795
  paint: view.paint,
1806
- logs: logsText(opened, writeFailure, app.env, failed),
1796
+ logs: logsText(recording, recorded.writeFailure, app.env, failed),
1807
1797
  ...charted === void 0 ? {} : { workers: charted.lanes },
1808
1798
  details: [
1809
1799
  ...charted?.notes ?? testsLines,
@@ -1814,55 +1804,26 @@ async function summarize(app, run) {
1814
1804
  );
1815
1805
  return timeline;
1816
1806
  }
1817
- function workerClock(ran, collected) {
1818
- const tests = ran.rows.find((row) => row.name === "tests");
1807
+ function workerClock({ timeline, workerOffsetMs }) {
1808
+ const tests = timeline.rows.find((row) => row.name === "tests");
1819
1809
  if (tests === void 0) return void 0;
1820
- return { runStartedAt: Date.parse(ran.startedAt), offsetMs: collected.workerOffsetMs, tests };
1821
- }
1822
- function teeTerminal(terminal, directory) {
1823
- if (directory === void 0) return terminal;
1824
- return {
1825
- color: terminal.color,
1826
- writeStdout: (text) => {
1827
- directory.appendCommandOutput(text);
1828
- terminal.writeStdout(text);
1829
- },
1830
- writeStderr: (text) => {
1831
- directory.appendCommandOutput(text);
1832
- terminal.writeStderr(text);
1833
- }
1834
- };
1810
+ return { runStartedAt: Date.parse(timeline.startedAt), offsetMs: workerOffsetMs, tests };
1835
1811
  }
1836
1812
  function displayPath(path, env) {
1837
1813
  const home = env["HOME"];
1838
1814
  if (home === void 0 || home === "" || !path.startsWith(`${home}/`)) return path;
1839
1815
  return `~${path.slice(home.length)}`;
1840
1816
  }
1841
- function logsText(opened, writeFailure, env, failed) {
1817
+ function logsText({ opened }, writeFailure, env, failed) {
1842
1818
  if (!opened.ok) return `none: couldn't make ${opened.failure.path}: ${opened.failure.message}`;
1843
- const path = `${displayPath(opened.directory.path, env)}/`;
1819
+ const path = `${displayPath(opened.path, env)}/`;
1844
1820
  const problems = [
1845
1821
  ...writeFailure === void 0 ? [] : [`couldn't write ${writeFailure.path}: ${writeFailure.message}`],
1846
1822
  ...opened.pruneFailures.slice(0, 1).map((failure) => `couldn't remove ${failure.path}: ${failure.message}`)
1847
1823
  ];
1848
- const show = `storm runs show ${opened.directory.id}${failed ? " --failed" : ""}`;
1824
+ const show = `storm runs show ${opened.id}${failed ? " --failed" : ""}`;
1849
1825
  return `${problems.length === 0 ? path : `${path} (${problems.join("; ")})`} \xB7 ${show}`;
1850
1826
  }
1851
- function runEnd(outcome, ran, tests) {
1852
- const command = outcome.kind === "ran" ? outcome.command : void 0;
1853
- const ranRecords = outcome.kind === "ran" ? outcome.resources : void 0;
1854
- const ms = ran?.outcome === void 0 || ran.outcome === "stopped" || ran.endedAt === void 0 ? null : ran.endedAt - ran.startedAt;
1855
- return {
1856
- outcome: outcome.kind,
1857
- exitCode: command === void 0 ? null : commandExitStatus(command),
1858
- signal: command?.kind === "signaled" ? command.signal : null,
1859
- ms,
1860
- tests: testTotals(tests.events),
1861
- testsIncomplete: tests.incomplete ?? null,
1862
- resources: ranRecords === void 0 ? null : RESOURCE_REPORTS.ranFacts(ranRecords),
1863
- resourceRows: ranRecords === void 0 ? [] : RESOURCE_REPORTS.ranRows(ranRecords)
1864
- };
1865
- }
1866
1827
  async function checkoutGit(checkout, cwd) {
1867
1828
  const root = await checkout.repositoryRoot({ cwd });
1868
1829
  if (!root.ok) return null;
@@ -1877,55 +1838,23 @@ function recipeResources(requests) {
1877
1838
  })
1878
1839
  );
1879
1840
  }
1841
+ function keepsSandbox(flag) {
1842
+ return flag !== void 0 && (parseKeepTime(flag) ?? 0) > 0;
1843
+ }
1844
+ function saveMode(request, recipe, env) {
1845
+ const choice = request.saveSnapshot ?? (keepsSandbox(request.keepSandbox) ? false : recipe.saveSnapshot);
1846
+ if (choice !== void 0) return choice ? "always" : "never";
1847
+ return isCi(env) || runStepTakesSecret(recipe) ? "never" : "new-head";
1848
+ }
1880
1849
  var DEFAULT_KEEP_SANDBOX_MINUTES = 30;
1881
1850
  function keepSandboxMinutes(flag, recipe, env) {
1882
1851
  const fromFlag = flag === void 0 ? void 0 : parseKeepTime(flag);
1883
1852
  return fromFlag ?? recipe.keepSandboxMinutes ?? (isCi(env) ? 0 : DEFAULT_KEEP_SANDBOX_MINUTES);
1884
1853
  }
1885
- function isCi(env) {
1886
- const ci = env["CI"];
1887
- return ci !== void 0 && ci !== "" && ci !== "0" && ci.toLowerCase() !== "false";
1888
- }
1889
- function startedWhere(run) {
1890
- if (run.runner === void 0) return { kind: "unsandboxed" };
1891
- const { prepared, target } = run.runner;
1892
- return {
1893
- kind: "runner",
1894
- team: target.team,
1895
- project: target.project,
1896
- region: prepared.recipe.region,
1897
- runtime: prepared.recipe.runtime,
1898
- vcpus: prepared.vcpus,
1899
- base: prepared.base,
1900
- baseRef: prepared.baseRef,
1901
- sandbox: null,
1902
- snapshot: null,
1903
- keptUntil: null,
1904
- save: null
1905
- };
1906
- }
1907
- function endedWhere(where, runner, save) {
1908
- if (where.kind === "unsandboxed") return where;
1909
- const snapshot = runner?.snapshot;
1910
- return {
1911
- ...where,
1912
- sandbox: runner?.sandbox?.name ?? null,
1913
- snapshot: snapshot === void 0 || snapshot.kind === "building" ? null : {
1914
- id: snapshot.id,
1915
- base: snapshot.base,
1916
- built: snapshot.kind === "built",
1917
- branch: snapshot.branch,
1918
- head: snapshot.head
1919
- },
1920
- keptUntil: runner?.kept?.stopsAt ?? null,
1921
- save
1922
- };
1923
- }
1924
- function failedStepLogs(ran, directory, env) {
1925
- if (directory === void 0) return [];
1926
- const runner = ran.rows.find((row) => row.name === "runner");
1854
+ function failedStepLogs(timeline, recording, env) {
1855
+ const runner = timeline.rows.find((row) => row.name === "runner");
1927
1856
  return (runner?.steps ?? []).filter((step) => step.outcome === "failed").flatMap((step) => {
1928
- const log = stepLog(directory, step.name);
1857
+ const log = recording.stepLog(step.name);
1929
1858
  return log === void 0 ? [] : [` failed ${step.name}, whole output: ${displayPath(log, env)}`];
1930
1859
  });
1931
1860
  }
@@ -1952,7 +1881,7 @@ function canceledChanges(outcome) {
1952
1881
  ];
1953
1882
  const cleanup = RUN_CLEANUP.facts(outcome).runner;
1954
1883
  if (cleanup !== null) lines.push(...runnerCleanupLines(cleanup));
1955
- lines.push(...RESOURCE_REPORTS.canceledLines(outcome.resourceCleanup));
1884
+ lines.push(...REGISTRY.reports.canceledLines(outcome.resourceCleanup));
1956
1885
  return lines.join("\n");
1957
1886
  }
1958
1887
  function runnerCleanupLines({ kept, notKept, notStopped, notDeleted }) {
@@ -1970,7 +1899,7 @@ function runnerCleanupLines({ kept, notKept, notStopped, notDeleted }) {
1970
1899
  }
1971
1900
 
1972
1901
  // src/commands/exec/run-metadata.ts
1973
- var RUN_USAGE_FLAGS = `${RESOURCE_USAGE_FLAGS} [--credential <SOURCE>] [--scope <TEAM> --project <PROJECT>] [--unsandboxed | [--rebuild-snapshot] [--save-snapshot] [--show-output] [--keep-sandbox <DURATION>]] [--verbose]`;
1902
+ var RUN_USAGE_FLAGS = `${RESOURCE_USAGE_FLAGS} [--credential <SOURCE>] [--scope <TEAM> --project <PROJECT>] [--unsandboxed | [--rebuild-snapshot] [--save-snapshot[=false]] [--show-output] [--keep-sandbox <DURATION>]] [--verbose]`;
1974
1903
  var OWN_RUN_FIELDS2 = {
1975
1904
  credential: {
1976
1905
  valueLabel: "SOURCE",
@@ -1983,11 +1912,11 @@ var OWN_RUN_FIELDS2 = {
1983
1912
  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 --unsandboxed. No config key."
1984
1913
  },
1985
1914
  saveSnapshot: {
1986
- 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 --unsandboxed, or with --keep-sandbox above 0. No config key."
1915
+ description: "Whether the run saves the runner sandbox as this branch's runner snapshot once the command ends on its own, after a successful install and build, so the next run on the branch starts from this run's install and build outputs. Without the flag, a sandboxed run on a branch saves one when the command exits 0, unless it started from a branch snapshot that HEAD's commit saved, so each commit saves once; it saves none when the command fails, when CI is set, with --keep-sandbox above 0, with a detached HEAD, or when the runner recipe's install or build step names a runner secret, since those steps would run in a later run on top of what this run's command wrote; such a recipe also reuses no branch snapshot unless --save-snapshot or saveSnapshot: true trusts it. --save-snapshot saves whatever the command's exit code and whatever the run started from, under CI too, and with a detached HEAD says as the run starts that it saves nothing; not with --unsandboxed, or with --keep-sandbox above 0. --save-snapshot=false saves none. The save 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 that starts a save keeps no runner sandbox, however the save ends; a run that starts none, such as one a signal stops, one whose install or build fails, or, without the flag, one whose command fails, keeps it for the keep time. Without the flag and without --keep-sandbox above 0, saveSnapshot in the runner recipe says the same as the flag for every run: false saves none, true saves as --save-snapshot does."
1987
1916
  },
1988
1917
  keepSandbox: {
1989
1918
  valueLabel: "DURATION",
1990
- description: "How long the runner sandbox keeps running once the run ends, however it ends, so you can connect to it from its page in the Vercel dashboard: 0, which stops and deletes it with the run's other sandboxes, or a whole number of minutes or hours up to 5h (30m, 2h). The run asks Vercel Sandbox to extend the runner sandbox's timeout when it would stop sooner; it never shortens it, so the sandbox may run past the keep time until its own timeout. The run says until when it runs, and storm runs show and runs list say so too. Default: keepSandbox in the runner recipe, else 30m, or 0 when CI is set. Not with --unsandboxed."
1919
+ description: "How long the runner sandbox keeps running once the run ends, however it ends, so you can connect to it from its page in the Vercel dashboard: 0, which stops and deletes it with the run's other sandboxes, or a whole number of minutes or hours up to 5h (30m, 2h). A run that starts saving a branch snapshot keeps no runner sandbox (see --save-snapshot); given above 0, this flag has the run save none. The run asks Vercel Sandbox to extend the runner sandbox's timeout when it would stop sooner; it never shortens it, so the sandbox may run past the keep time until its own timeout. The run says until when it runs, and storm runs show and runs list say so too. Default: keepSandbox in the runner recipe, else 30m, or 0 when CI is set. Not with --unsandboxed."
1991
1920
  },
1992
1921
  showOutput: {
1993
1922
  description: "In a sandboxed run on a terminal, print the runner's step output (a snapshot build, the install, the build) above the live view instead of keeping only each step's last line there. Plain output always prints it. Either way, the run directory keeps it whole. Not with --unsandboxed. No config key."