@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
@@ -10,7 +10,7 @@ export class StoryDivergenceError extends Error {
10
10
  this.stale = stale;
11
11
  }
12
12
  }
13
- /** A story's recording no longer fits it, and `STORY_RECORD=none` may not change it. */
13
+ /** A story's recording no longer fits it, and the answers level `check` may not change it. */
14
14
  export class StoryStaleError extends Error {
15
15
  name = "StoryStaleError";
16
16
  stale;
@@ -9,7 +9,7 @@ declare module "vitest" {
9
9
  export interface StoryHostOptions {
10
10
  /** Each story's timeout; default the Vitest project's `testTimeout`. */
11
11
  readonly timeout?: number;
12
- /** Where `STORY_RECORD` and `CI` come from; default `process.env`. */
12
+ /** Where the story launch comes from (`STORM_STORY`, which `storm story run` sets); default `process.env`. */
13
13
  readonly env?: Readonly<Record<string, string | undefined>>;
14
14
  }
15
15
  /** Declares one story, a Vitest test named `name`, whose body gets one handle per agent. */
@@ -4,7 +4,7 @@ import { basename } from "node:path";
4
4
  import { test } from "vitest";
5
5
  import { recordingPath } from "./recording.js";
6
6
  import { liveStoryRecordingGateway } from "./live/recording-gateway.js";
7
- import { resolveStoryRecordLevel } from "./mode.js";
7
+ import { storyAnswersLevel } from "./launch.js";
8
8
  import { findOrphans, looksForOrphans } from "./orphans.js";
9
9
  import { startStory } from "./start.js";
10
10
  /**
@@ -25,7 +25,7 @@ export function createStory(harness, options = {}) {
25
25
  test(name, { meta: { story: true }, ...(options.timeout === undefined ? {} : { timeout: options.timeout }) }, async (context) => {
26
26
  const file = context.task.file.filepath;
27
27
  const story = { file: basename(file), name: context.task.fullTestName };
28
- const level = resolveStoryRecordLevel(options.env ?? process.env);
28
+ const level = storyAnswersLevel(options.env ?? process.env);
29
29
  const started = startStory(harness, { story, path: recordingPath(file, story.name), level, signal: context.signal }, liveStoryRecordingGateway);
30
30
  const bodyEnded = await bodyEnd(() => body(started.handles), context.signal);
31
31
  const orphans = await fileOrphans(context);
@@ -1,8 +1,8 @@
1
1
  export { recordingDirectory, recordingPath, parseRecording, type ParsedStoryRecording, STORY_RECORDING_SCHEMA_VERSION, type StoryRecording, type StoryCall, type StoryIdentity, } from "./recording.ts";
2
2
  export { type AnyStoryTool, type StoryAgent, type StoryAgents, type StoryHandles, type StoryHarness, type StorySession, type StoryTool, type StoryToolCall, storyTool, } from "./definition.ts";
3
- export { InvalidCommandLine, splitCommandLine, type StoryExecutable, type StoryExecutableOptions, storyExecutable, } from "./command-line.ts";
3
+ export { InvalidCommandLine, splitCommandLine, type StoryExecutable } from "./command-line.ts";
4
4
  export { StoryDivergenceError, StoryStaleError } from "./errors.ts";
5
5
  export { createStory, type StoryFunction, type StoryHostOptions } from "./host.ts";
6
6
  export type { StoryJson } from "./json.ts";
7
- export { STORY_RECORD_VARIABLE, type StoryRecordLevel } from "./mode.ts";
7
+ export { type StoryAnswersLevel, type StoryExecutableOptions, storyExecutable } from "./launch.ts";
8
8
  export type { StoryDivergence, StoryStaleEntry } from "./settle.ts";
@@ -1,10 +1,11 @@
1
1
  // Story core, exported as `@vercel/storm/story`: stories whose agents call tools, each call's observation kept in
2
2
  // a recording beside the story file and compared on every later Vitest run. `README.md` beside this file is its design
3
3
  // and authoring guide. It depends only on Node builtins, `zod`, and `vitest` (an optional peer dependency of
4
- // `@vercel/storm`), and on nothing else in storm; `.oxlintrc.json` checks the boundary.
4
+ // `@vercel/storm`), and on nothing else in storm; `.oxlintrc.json` checks the boundary. The story launch, what
5
+ // `storm story run` hands the stories, is `launch.ts`, which loads no vitest, so the command imports it too.
5
6
  export { recordingDirectory, recordingPath, parseRecording, STORY_RECORDING_SCHEMA_VERSION, } from "./recording.js";
6
7
  export { storyTool, } from "./definition.js";
7
- export { InvalidCommandLine, splitCommandLine, storyExecutable, } from "./command-line.js";
8
+ export { InvalidCommandLine, splitCommandLine } from "./command-line.js";
8
9
  export { StoryDivergenceError, StoryStaleError } from "./errors.js";
9
10
  export { createStory } from "./host.js";
10
- export { STORY_RECORD_VARIABLE } from "./mode.js";
11
+ export { storyExecutable } from "./launch.js";
@@ -0,0 +1,70 @@
1
+ import { z } from "zod";
2
+ import type { StoryExecutable } from "./command-line.ts";
3
+ /** The environment variable that holds the story launch. */
4
+ export declare const STORY_LAUNCH_VARIABLE = "STORM_STORY";
5
+ /**
6
+ * The answers level: how much a story may change its recording.
7
+ *
8
+ * - `check` compares and writes nothing. A divergence or a stale entry fails the story.
9
+ * - `add` rewrites the recording so it fits the story again, when the only problems are stale entries: it records
10
+ * new calls, removes unmade ones, rewrites an unreadable recording and removes orphan recordings. A divergence
11
+ * still fails the story, and then nothing is written.
12
+ * - `accept` also accepts divergences, recording the new observations.
13
+ */
14
+ export declare const storyAnswersLevelSchema: z.ZodEnum<{
15
+ accept: "accept";
16
+ add: "add";
17
+ check: "check";
18
+ }>;
19
+ /** The answers level (`storyAnswersLevelSchema`). */
20
+ export type StoryAnswersLevel = z.output<typeof storyAnswersLevelSchema>;
21
+ /**
22
+ * The executable the stories invoke in place of the package's own (`--bin`), resolved (`resolveStoryExecutable`): its
23
+ * program, a relative one already resolved against the directory `storm story run` ran in, and the words it gets
24
+ * before a story's own arguments.
25
+ */
26
+ export declare const storyExecutableSchema: z.ZodObject<{
27
+ file: z.ZodString;
28
+ args: z.ZodReadonly<z.ZodArray<z.ZodString>>;
29
+ }, z.core.$strict>;
30
+ declare const storyLaunchSchema: z.ZodObject<{
31
+ version: z.ZodLiteral<1>;
32
+ answers: z.ZodEnum<{
33
+ accept: "accept";
34
+ add: "add";
35
+ check: "check";
36
+ }>;
37
+ bin: z.ZodNullable<z.ZodObject<{
38
+ file: z.ZodString;
39
+ args: z.ZodReadonly<z.ZodArray<z.ZodString>>;
40
+ }, z.core.$strict>>;
41
+ }, z.core.$strict>;
42
+ /** What `storm story run` hands the stories: its answers level and the executable `--bin` names. */
43
+ export type StoryLaunch = z.output<typeof storyLaunchSchema>;
44
+ /** The one variable that carries `launch`, to merge into the environment of the Vitest run the command starts. */
45
+ export declare function storyLaunchEnv(launch: StoryLaunch): Readonly<Record<string, string>>;
46
+ /**
47
+ * The story launch in `env`, or null when `env` holds none, as under a bare Vitest run or an IDE's test runner. A
48
+ * value that isn't JSON, or isn't a story launch this story core reads, such as one of another version, is a
49
+ * `TypeError` naming the variable.
50
+ */
51
+ export declare function readStoryLaunch(env: Readonly<Record<string, string | undefined>>): StoryLaunch | null;
52
+ /**
53
+ * The answers level the story launch in `env` names. Without one, as under a bare Vitest run or an IDE's test runner,
54
+ * in CI or not, the level is `check`: only `storm story run` writes a recording. A malformed launch is a `TypeError`
55
+ * naming its variable.
56
+ */
57
+ export declare function storyAnswersLevel(env: Readonly<Record<string, string | undefined>>): StoryAnswersLevel;
58
+ /** Where `storyExecutable` reads the executable a harness invokes. */
59
+ export interface StoryExecutableOptions {
60
+ /** The environment the story launch is in, such as `process.env`. */
61
+ readonly env: Readonly<Record<string, string | undefined>>;
62
+ /** The executable when the story launch names none: the package's own. */
63
+ readonly fallback: StoryExecutable;
64
+ }
65
+ /**
66
+ * The executable `storm story run --bin` names, from the story launch in `env`, already resolved, or `fallback` when
67
+ * there is no launch or it names none. A malformed launch is a `TypeError` naming its variable.
68
+ */
69
+ export declare function storyExecutable({ env, fallback }: StoryExecutableOptions): StoryExecutable;
70
+ export {};
@@ -0,0 +1,77 @@
1
+ // The story launch: what `storm story run` hands the stories in the Vitest run it starts, as one private environment
2
+ // variable, `STORM_STORY`, holding JSON, and what the stories read of it: the answers level and the executable to
3
+ // invoke. It loads only Node builtins and zod, never vitest, so the command that writes it and the story code that
4
+ // reads it share it. People never set the variable by hand: the flags of `storm story run` are the settings.
5
+ import { z } from "zod";
6
+ /** The environment variable that holds the story launch. */
7
+ export const STORY_LAUNCH_VARIABLE = "STORM_STORY";
8
+ /**
9
+ * The answers level: how much a story may change its recording.
10
+ *
11
+ * - `check` compares and writes nothing. A divergence or a stale entry fails the story.
12
+ * - `add` rewrites the recording so it fits the story again, when the only problems are stale entries: it records
13
+ * new calls, removes unmade ones, rewrites an unreadable recording and removes orphan recordings. A divergence
14
+ * still fails the story, and then nothing is written.
15
+ * - `accept` also accepts divergences, recording the new observations.
16
+ */
17
+ export const storyAnswersLevelSchema = z.enum(["check", "add", "accept"]);
18
+ /**
19
+ * The executable the stories invoke in place of the package's own (`--bin`), resolved (`resolveStoryExecutable`): its
20
+ * program, a relative one already resolved against the directory `storm story run` ran in, and the words it gets
21
+ * before a story's own arguments.
22
+ */
23
+ export const storyExecutableSchema = z
24
+ .object({ file: z.string().min(1), args: z.array(z.string()).readonly() })
25
+ .strict();
26
+ const storyLaunchSchema = z
27
+ .object({
28
+ version: z.literal(1),
29
+ answers: storyAnswersLevelSchema,
30
+ /** The executable `--bin` names (`storyExecutableSchema`); null without `--bin`. */
31
+ bin: storyExecutableSchema.nullable(),
32
+ })
33
+ .strict();
34
+ /** The one variable that carries `launch`, to merge into the environment of the Vitest run the command starts. */
35
+ export function storyLaunchEnv(launch) {
36
+ return { [STORY_LAUNCH_VARIABLE]: JSON.stringify(storyLaunchSchema.parse(launch)) };
37
+ }
38
+ /**
39
+ * The story launch in `env`, or null when `env` holds none, as under a bare Vitest run or an IDE's test runner. A
40
+ * value that isn't JSON, or isn't a story launch this story core reads, such as one of another version, is a
41
+ * `TypeError` naming the variable.
42
+ */
43
+ export function readStoryLaunch(env) {
44
+ const text = env[STORY_LAUNCH_VARIABLE];
45
+ if (text === undefined || text === "")
46
+ return null;
47
+ let value;
48
+ try {
49
+ value = JSON.parse(text);
50
+ }
51
+ catch (error) {
52
+ throw new TypeError(`story: ${STORY_LAUNCH_VARIABLE} isn't JSON: ${errorText(error)}`, { cause: error });
53
+ }
54
+ const parsed = storyLaunchSchema.safeParse(value);
55
+ if (!parsed.success) {
56
+ throw new TypeError(`story: ${STORY_LAUNCH_VARIABLE} isn't a story launch this story core reads (version 1, set by storm story run): ${text}`);
57
+ }
58
+ return parsed.data;
59
+ }
60
+ /**
61
+ * The answers level the story launch in `env` names. Without one, as under a bare Vitest run or an IDE's test runner,
62
+ * in CI or not, the level is `check`: only `storm story run` writes a recording. A malformed launch is a `TypeError`
63
+ * naming its variable.
64
+ */
65
+ export function storyAnswersLevel(env) {
66
+ return readStoryLaunch(env)?.answers ?? "check";
67
+ }
68
+ /**
69
+ * The executable `storm story run --bin` names, from the story launch in `env`, already resolved, or `fallback` when
70
+ * there is no launch or it names none. A malformed launch is a `TypeError` naming its variable.
71
+ */
72
+ export function storyExecutable({ env, fallback }) {
73
+ return readStoryLaunch(env)?.bin ?? fallback;
74
+ }
75
+ function errorText(error) {
76
+ return error instanceof Error ? error.message : String(error);
77
+ }
@@ -1,5 +1,5 @@
1
1
  import type { StoryCall, StoryIdentity } from "./recording.ts";
2
- import { type StoryRecordLevel } from "./mode.ts";
2
+ import type { StoryAnswersLevel } from "./launch.ts";
3
3
  import type { StorySettlement } from "./settle.ts";
4
4
  /** `user calls slot {"command":"list --json"}`, the input as compact JSON cut to 100 characters. */
5
5
  export declare function describeCall(call: Pick<StoryCall, "agent" | "tool" | "input">): string;
@@ -21,7 +21,7 @@ export interface StoryApplied {
21
21
  export declare function storyEventLines(settlement: StorySettlement, applied: StoryApplied): readonly string[];
22
22
  export interface StoryReportInput {
23
23
  readonly story: StoryIdentity;
24
- readonly level: StoryRecordLevel;
24
+ readonly level: StoryAnswersLevel;
25
25
  readonly settlement: StorySettlement;
26
26
  /** Whether the story's body threw, so nothing was written. */
27
27
  readonly bodyFailed: boolean;
@@ -1,7 +1,6 @@
1
1
  // What a story says about its calls: one event line per call, the report of a failed story, and what a passing story
2
2
  // changed. Pure.
3
3
  import { describeObservationDiff } from "./diff.js";
4
- import { STORY_RECORD_VARIABLE } from "./mode.js";
5
4
  /** How much of a call's input its line keeps. */
6
5
  const INPUT_CHARS = 100;
7
6
  /** `user calls slot {"command":"list --json"}`, the input as compact JSON cut to 100 characters. */
@@ -51,7 +50,7 @@ function callStatus(each, written, accepted) {
51
50
  */
52
51
  export function storyReport(input) {
53
52
  const { settlement } = input;
54
- const lines = [`story "${input.story.name}" (${input.story.file}), ${STORY_RECORD_VARIABLE}=${input.level}:`];
53
+ const lines = [`story "${input.story.name}" (${input.story.file}), answers level ${input.level}:`];
55
54
  for (const divergence of settlement.divergences) {
56
55
  lines.push(` divergence: ${describeCall(divergence.live)}`);
57
56
  for (const line of describeObservationDiff(divergence.recorded.observation, divergence.live.observation)) {
@@ -87,9 +86,9 @@ function summary(input) {
87
86
  if (input.bodyFailed)
88
87
  return `${counts} The story threw, so nothing was written.`;
89
88
  if (divergences.length > 0) {
90
- return `${counts} A divergence means the tool behaved differently. If that is intended, accept it with ${STORY_RECORD_VARIABLE}=all.`;
89
+ return `${counts} A divergence means the tool behaved differently. If that is intended, accept it with --answers accept, through storm story run or the package's story script.`;
91
90
  }
92
- return `${counts} The recording no longer fits the story. Rewrite it with ${STORY_RECORD_VARIABLE}=stale.`;
91
+ return `${counts} The recording no longer fits the story. Rewrite it with --answers add, through storm story run or the package's story script.`;
93
92
  }
94
93
  /**
95
94
  * What a passing story's end `applied`, or `undefined` when it changed nothing. Its first line counts what it did: the
@@ -1,6 +1,6 @@
1
1
  import { type StoryAlignedCall } from "./align.ts";
2
2
  import type { StoryRecording, StoryCall, StoryIdentity } from "./recording.ts";
3
- import type { StoryRecordLevel } from "./mode.ts";
3
+ import type { StoryAnswersLevel } from "./launch.ts";
4
4
  /** A recorded call and a live call with the same key and different observations: the tool behaved differently. */
5
5
  export interface StoryDivergence {
6
6
  readonly recorded: StoryCall;
@@ -52,7 +52,7 @@ export interface StorySettleInput {
52
52
  readonly story: StoryIdentity;
53
53
  /** The story's recording path, which an unreadable entry names. */
54
54
  readonly path: string;
55
- readonly level: StoryRecordLevel;
55
+ readonly level: StoryAnswersLevel;
56
56
  /** Whether the story's body returned without throwing. */
57
57
  readonly bodyPassed: boolean;
58
58
  readonly read: RecordingRead;
@@ -74,9 +74,9 @@ export interface StorySettlement {
74
74
  readonly change: RecordingChange;
75
75
  /** Whether the end removes the orphan recordings, the `orphan` entries in `stale`. */
76
76
  readonly removesOrphans: boolean;
77
- /** Whether the divergences are recorded as the new observations (`STORY_RECORD=all`). */
77
+ /** Whether the divergences are recorded as the new observations (the answers level `accept`). */
78
78
  readonly accepted: boolean;
79
- /** Why the story fails, beyond its body: a divergence, or a stale entry at `none`. */
79
+ /** Why the story fails, beyond its body: a divergence, or a stale entry at `check`. */
80
80
  readonly failure: "divergence" | "stale" | undefined;
81
81
  }
82
82
  /**
@@ -85,10 +85,10 @@ export interface StorySettlement {
85
85
  * entry. A story whose body threw changes nothing and fails with its own error; the recorded calls after its last
86
86
  * aligned call count as unreached, not unmade. Otherwise, by level:
87
87
  *
88
- * - `none` changes nothing, and fails on a divergence, else on a stale entry.
89
- * - `stale` fails on a divergence, changing nothing; otherwise it writes the recording and removes the orphan
88
+ * - `check` changes nothing, and fails on a divergence, else on a stale entry.
89
+ * - `add` fails on a divergence, changing nothing; otherwise it writes the recording and removes the orphan
90
90
  * recordings.
91
- * - `all` writes the recording and removes the orphan recordings, accepting any divergence.
91
+ * - `accept` writes the recording and removes the orphan recordings, accepting any divergence.
92
92
  *
93
93
  * The recording written holds the live calls. A story that made no call has no recording, so writing it removes one
94
94
  * that is there.
@@ -8,10 +8,10 @@ import { STORY_RECORDING_SCHEMA_VERSION } from "./recording.js";
8
8
  * entry. A story whose body threw changes nothing and fails with its own error; the recorded calls after its last
9
9
  * aligned call count as unreached, not unmade. Otherwise, by level:
10
10
  *
11
- * - `none` changes nothing, and fails on a divergence, else on a stale entry.
12
- * - `stale` fails on a divergence, changing nothing; otherwise it writes the recording and removes the orphan
11
+ * - `check` changes nothing, and fails on a divergence, else on a stale entry.
12
+ * - `add` fails on a divergence, changing nothing; otherwise it writes the recording and removes the orphan
13
13
  * recordings.
14
- * - `all` writes the recording and removes the orphan recordings, accepting any divergence.
14
+ * - `accept` writes the recording and removes the orphan recordings, accepting any divergence.
15
15
  *
16
16
  * The recording written holds the live calls. A story that made no call has no recording, so writing it removes one
17
17
  * that is there.
@@ -38,14 +38,14 @@ export function settleStory(input) {
38
38
  const leave = { change: { kind: "leave" }, removesOrphans: false, accepted: false };
39
39
  if (!input.bodyPassed)
40
40
  return { ...settled, ...leave, failure: undefined };
41
- if (input.level === "none") {
41
+ if (input.level === "check") {
42
42
  return {
43
43
  ...settled,
44
44
  ...leave,
45
45
  failure: divergences.length > 0 ? "divergence" : stale.length > 0 ? "stale" : undefined,
46
46
  };
47
47
  }
48
- if (input.level === "stale" && divergences.length > 0)
48
+ if (input.level === "add" && divergences.length > 0)
49
49
  return { ...settled, ...leave, failure: "divergence" };
50
50
  return {
51
51
  ...settled,
@@ -1,12 +1,12 @@
1
1
  import type { StoryIdentity } from "./recording.ts";
2
2
  import type { StoryAgents, StoryHandles, StoryHarness, StorySession } from "./definition.ts";
3
3
  import type { StoryRecordingGateway } from "./gateways.ts";
4
- import type { StoryRecordLevel } from "./mode.ts";
4
+ import type { StoryAnswersLevel } from "./launch.ts";
5
5
  export interface StoryStartOptions {
6
6
  readonly story: StoryIdentity;
7
7
  /** The story's recording path (`recordingPath`). */
8
8
  readonly path: string;
9
- readonly level: StoryRecordLevel;
9
+ readonly level: StoryAnswersLevel;
10
10
  /**
11
11
  * Aborts when the story is stopped, as by a timeout. A story stopped before its end compares as one whose body
12
12
  * threw, so it changes nothing; one stopped while its end changes the recording stops before the next change.
@@ -173,12 +173,17 @@ export interface Container {
173
173
  * `TypeError` for `featureFlags` that aren't `FeatureFlags` before sending anything, and a `TestserverCallError` when
174
174
  * the start fails.
175
175
  *
176
- * A start that may have reached Testserver and failed is followed by an attempt to end the container. When that end
177
- * fails too, throws an `AggregateError` holding both call errors, the start's first and as its `cause`, and tries no
178
- * more. Otherwise a start that timed out, couldn't connect, broke off, or got a 5xx other than 502 is tried once
179
- * more after 250ms, under a fresh test id. The caller's `testId` is tried again only after a failed connection:
180
- * ending a container retires its test id, and Testserver refuses every later request for a retired one. A start that
181
- * fails every attempt throws the last attempt's `TestserverCallError`, carrying the attempts.
176
+ * A start that may have reached Testserver and failed is followed by an attempt to end the container. A start that
177
+ * timed out, couldn't connect, broke off, or got a 5xx other than 502 is then tried once more after 250ms, under a
178
+ * fresh test id. The caller's `testId` is tried again only after a failed connection: ending a container retires its
179
+ * test id, and Testserver refuses every later request for a retired one. A start that fails every attempt throws the
180
+ * last attempt's `TestserverCallError`, carrying the attempts.
181
+ *
182
+ * When ending the container after a failed start fails too, the container may run on until Testserver's idle
183
+ * eviction stops it. An end whose connection failed (`dropped` or `connect-failed`) doesn't stop the next attempt,
184
+ * whose test id is fresh, and a start that then succeeds reports nothing of it. Any other failed end, and any failed
185
+ * end for the caller's `testId`, ends the attempts. A start that fails after an end failed throws an `AggregateError`
186
+ * holding the last attempt's start error, first and as its `cause`, then each failed end's call error.
182
187
  *
183
188
  * Once a start succeeds, sets `featureFlags` before returning, one `PATCH /_/external/flags/<client>` for each
184
189
  * client that has a flag, one after another, in `FEATURE_FLAG_CLIENTS` order, so they are in place before any
@@ -33,12 +33,17 @@ export function liveSdkContext(options = {}) {
33
33
  * `TypeError` for `featureFlags` that aren't `FeatureFlags` before sending anything, and a `TestserverCallError` when
34
34
  * the start fails.
35
35
  *
36
- * A start that may have reached Testserver and failed is followed by an attempt to end the container. When that end
37
- * fails too, throws an `AggregateError` holding both call errors, the start's first and as its `cause`, and tries no
38
- * more. Otherwise a start that timed out, couldn't connect, broke off, or got a 5xx other than 502 is tried once
39
- * more after 250ms, under a fresh test id. The caller's `testId` is tried again only after a failed connection:
40
- * ending a container retires its test id, and Testserver refuses every later request for a retired one. A start that
41
- * fails every attempt throws the last attempt's `TestserverCallError`, carrying the attempts.
36
+ * A start that may have reached Testserver and failed is followed by an attempt to end the container. A start that
37
+ * timed out, couldn't connect, broke off, or got a 5xx other than 502 is then tried once more after 250ms, under a
38
+ * fresh test id. The caller's `testId` is tried again only after a failed connection: ending a container retires its
39
+ * test id, and Testserver refuses every later request for a retired one. A start that fails every attempt throws the
40
+ * last attempt's `TestserverCallError`, carrying the attempts.
41
+ *
42
+ * When ending the container after a failed start fails too, the container may run on until Testserver's idle
43
+ * eviction stops it. An end whose connection failed (`dropped` or `connect-failed`) doesn't stop the next attempt,
44
+ * whose test id is fresh, and a start that then succeeds reports nothing of it. Any other failed end, and any failed
45
+ * end for the caller's `testId`, ends the attempts. A start that fails after an end failed throws an `AggregateError`
46
+ * holding the last attempt's start error, first and as its `cause`, then each failed end's call error.
42
47
  *
43
48
  * Once a start succeeds, sets `featureFlags` before returning, one `PATCH /_/external/flags/<client>` for each
44
49
  * client that has a flag, one after another, in `FEATURE_FLAG_CLIENTS` order, so they are in place before any
@@ -54,6 +59,7 @@ export async function startContainer(options, context = liveSdkContext()) {
54
59
  const { testserverUrl } = options;
55
60
  const firstStartedAt = context.clock.now();
56
61
  let first;
62
+ const endErrors = [];
57
63
  for (let attempt = 1;; attempt += 1) {
58
64
  const testId = options.testId ?? generateTestId();
59
65
  const started = await context.containers.start({
@@ -81,21 +87,37 @@ export async function startContainer(options, context = liveSdkContext()) {
81
87
  if (reached) {
82
88
  const ended = await context.containers.end({ testserverUrl, testId });
83
89
  if (!ended.ok) {
84
- const endError = new TestserverCallError({
85
- call: ended.call,
86
- testId,
87
- testserverUrl,
88
- failure: ended.failure,
89
- });
90
- throw new AggregateError([startError, endError], `${startError.message}; ending container ${testId} after the failed start also failed: ${endError.message}`, { cause: startError });
90
+ endErrors.push(new TestserverCallError({ call: ended.call, testId, testserverUrl, failure: ended.failure }));
91
+ // An end whose connection failed leaves the container to Testserver's idle eviction, and the next attempt's
92
+ // test id is fresh. Any other failed end, an answer or none in time, ends the attempts.
93
+ if (!connectionFailed(ended.failure))
94
+ throw startFailure(startError, endErrors);
91
95
  }
92
96
  }
93
- const retired = reached && options.testId !== undefined;
94
- if (attempt >= START_ATTEMPTS || retired || !retriesStart(started.failure))
95
- throw startError;
97
+ // The caller's test id can't be tried again: its end retired it, or failed, and it may hold a running container.
98
+ const spent = reached && options.testId !== undefined;
99
+ if (attempt >= START_ATTEMPTS || spent || !retriesStart(started.failure)) {
100
+ throw startFailure(startError, endErrors);
101
+ }
96
102
  await context.clock.sleep(START_RETRY_DELAY_MS);
97
103
  }
98
104
  }
105
+ /**
106
+ * What a failed start throws: its call error, or, when ending a container after a failed attempt failed too, an
107
+ * `AggregateError` holding the start's error, first and as its `cause`, then each end's.
108
+ */
109
+ function startFailure(startError, endErrors) {
110
+ if (endErrors.length === 0)
111
+ return startError;
112
+ const ends = endErrors.map((endError) => `ending container ${endError.testId} after its failed start also failed: ${endError.message}`);
113
+ return new AggregateError([startError, ...endErrors], [startError.message, ...ends].join("; "), {
114
+ cause: startError,
115
+ });
116
+ }
117
+ /** Whether a call failed for its connection, which never opened or broke off, rather than for Testserver's answer. */
118
+ function connectionFailed(failure) {
119
+ return failure.kind === "dropped" || failure.kind === "connect-failed";
120
+ }
99
121
  /**
100
122
  * Sets each client's feature flags in a container just started, one after another. A call that fails ends the
101
123
  * container and throws, as `startContainer` documents.
@@ -69,9 +69,10 @@ export declare function redactFailure(failure: TestserverFailure, redact: (text:
69
69
  * `container-stopped`, so Testserver had stopped the container, as its idle eviction does. The same call may work on
70
70
  * a new connection, in a new container. It matches no other failure kind, and not a call whose last attempt failed
71
71
  * otherwise after an earlier attempt's failed so. It also matches the `AggregateError` a failed start throws when
72
- * ending the container fails too, whose message starts with the start's, and any message that names a call the same
73
- * way, `<call> for test id <id> on <Testserver URL> failed: <description>`. For a test runner's retry condition, such
74
- * as vitest's `retry.condition`, which a config file can only give as a RegExp.
72
+ * ending a container failed too, whose message holds the start's and each failed end's, when any of them failed so,
73
+ * and any message that names a call the same way, `<call> for test id <id> on <Testserver URL> failed:
74
+ * <description>`. For a test runner's retry condition, such as vitest's `retry.condition`, which a config file can
75
+ * only give as a RegExp.
75
76
  */
76
77
  export declare const TESTSERVER_TRANSIENT_FAILURE: RegExp;
77
78
  /** The attempts a call that is retried made before it failed: how many, how long they took, and why the first failed. */
@@ -73,9 +73,10 @@ export function redactFailure(failure, redact) {
73
73
  * `container-stopped`, so Testserver had stopped the container, as its idle eviction does. The same call may work on
74
74
  * a new connection, in a new container. It matches no other failure kind, and not a call whose last attempt failed
75
75
  * otherwise after an earlier attempt's failed so. It also matches the `AggregateError` a failed start throws when
76
- * ending the container fails too, whose message starts with the start's, and any message that names a call the same
77
- * way, `<call> for test id <id> on <Testserver URL> failed: <description>`. For a test runner's retry condition, such
78
- * as vitest's `retry.condition`, which a config file can only give as a RegExp.
76
+ * ending a container failed too, whose message holds the start's and each failed end's, when any of them failed so,
77
+ * and any message that names a call the same way, `<call> for test id <id> on <Testserver URL> failed:
78
+ * <description>`. For a test runner's retry condition, such as vitest's `retry.condition`, which a config file can
79
+ * only give as a RegExp.
79
80
  */
80
81
  export const TESTSERVER_TRANSIENT_FAILURE = new RegExp(` for test id \\S+ on \\S+ failed: (?:${DROPPED_PHRASE}: |${CONNECT_FAILED_PHRASE} \\(|${CONTAINER_STOPPED_PHRASE}: )`);
81
82
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnc-tools/storm",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Run a command, on this machine or in a Vercel Sandbox, with the resources it needs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,6 +20,8 @@ commands: all
20
20
  - A **test result** is the final result of one test: `pass`, `fail` or `skip`, with its errors. The command saves test results only with the Vitest adapter's `stormReporter`.
21
21
  - **Test output** is what one test printed to the console, stdout and stderr together. storm keeps the last 8 MiB of the test output of each test. `droppedChars` counts the characters that storm did not keep.
22
22
  - A **runner secret** is a variable in your environment that the `secrets` key of the runner recipe declares, such as an npm token for a private package. A sandboxed run reads it on the machine that starts the run. The run does not start when the variable is not set, is empty, holds a line break or has fewer than 8 characters. A step of the recipe gets the variable only when the `secrets` key of that step names it. The command does not get it. storm shows the value as `<token>` in all that it prints and writes. storm does not write the value to a file. A step can leave the value in the sandbox, and a runner snapshot then keeps it. Do not let a step leave the value.
23
+ - A **story** is a Vitest test that records each tool call it makes, and compares the calls with its recording at each later run. `storm story run` runs the stories of a package on this machine. It is not a run: it uses no runner sandbox, resource or run directory.
24
+ - An **answers level** tells how much a story can change its recording: `check` only compares, `add` also rewrites the parts that no longer fit the story (it records new calls and removes calls the story no longer makes), and `accept` also accepts each changed answer.
23
25
  - A **run log** is a log in the run directory. The **command log** (`command`) holds all the output of the command. It also holds output that no test owns: output from a `beforeAll`, a global setup, a raw `process.stdout.write`, or a child process. A **step log** (`install`, `build`, `apply`, `snapshot`) holds the output of one step of a sandboxed run.
24
26
 
25
27
  ## Commands
@@ -29,6 +31,7 @@ commands: all
29
31
  - `storm runs list --json` lists the recent runs.
30
32
  - `storm runs show <run-id> --json` shows a run, the test plan of a `storm vitest` run, its test results, and with `--failed` or `--test` the errors and test output of tests.
31
33
  - `storm runs logs <run-id>` prints a run log.
34
+ - `storm story run --project <project> [--answers check|add|accept] [--bin <command line>]` runs the stories of a package with its vitest on this machine. `--answers` sets the answers level: `check` when `CI` is set, else `add`. `--bin` gives a different executable for the stories to start, such as a port of the tool. A package with stories has a `story` script that runs it. Do not run it unless the user asks you to run or record stories.
32
35
 
33
36
  ## Other skills
34
37
 
@@ -49,10 +49,10 @@ In a sandboxed run, storm installs and builds before it runs the command.
49
49
 
50
50
  ## 6. Run one test again in the runner sandbox
51
51
 
52
- A sandboxed run can keep its runner sandbox running after it ends.
52
+ A sandboxed run can keep its runner sandbox running after it ends. A run that saves a branch snapshot does not keep it. On a branch, after each commit, the first run whose command exits 0 saves a branch snapshot, so the next runs on the branch start from its install and build outputs. A run whose command fails saves no branch snapshot and keeps its runner sandbox.
53
53
 
54
54
  1. Run `storm runs show <run-id> --json`.
55
- 2. Read `where.keptMinutesLeft`. If it is `null` or 0, the runner sandbox is not running. Start a new run with `storm vitest` or `storm exec`.
55
+ 2. Read `where.keptMinutesLeft`. If it is `null` or 0, the runner sandbox is not running. Start a new run with `storm vitest` or `storm exec`, and add `--keep-sandbox 30m`. With that flag, the run saves no branch snapshot and keeps its runner sandbox for 30 minutes.
56
56
  3. Read `where.sandboxUrl`. Give a person the Connect page, `<sandboxUrl>/connect`. In it, a person can run one test again.
57
57
 
58
58
  ## 7. Read what a resource could not do