@cnc-tools/storm 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/build-info.js +1 -1
  2. package/dist/combine-errors.js +2 -2
  3. package/dist/commands/dashboard.js +1 -1
  4. package/dist/commands/{run → exec}/cleanup.d.ts +1 -1
  5. package/dist/commands/{run → exec}/cleanup.js +1 -1
  6. package/dist/commands/{run/outcomes.d.ts → exec/command.d.ts} +103 -112
  7. package/dist/commands/exec/command.js +23 -0
  8. package/dist/commands/{run → exec}/job-summary.d.ts +5 -1
  9. package/dist/commands/{run → exec}/job-summary.js +5 -2
  10. package/dist/commands/{run → exec}/live-view.js +29 -13
  11. package/dist/commands/exec/metadata.d.ts +69 -0
  12. package/dist/commands/exec/metadata.js +55 -0
  13. package/dist/commands/{run → exec}/mint-failed.js +4 -4
  14. package/dist/commands/exec/outcomes.d.ts +664 -0
  15. package/dist/commands/exec/outcomes.js +347 -0
  16. package/dist/commands/{run → exec}/progress.d.ts +14 -2
  17. package/dist/commands/{run → exec}/progress.js +54 -9
  18. package/dist/commands/exec/run-command.d.ts +227 -0
  19. package/dist/commands/exec/run-command.js +696 -0
  20. package/dist/commands/exec/run-metadata.d.ts +59 -0
  21. package/dist/commands/exec/run-metadata.js +61 -0
  22. package/dist/commands/{run → exec}/run-record.d.ts +110 -5
  23. package/dist/commands/{run → exec}/run-record.js +57 -1
  24. package/dist/commands/exec/testserver-flags.d.ts +48 -0
  25. package/dist/commands/exec/testserver-flags.js +80 -0
  26. package/dist/commands/{run → exec}/view.js +36 -4
  27. package/dist/commands/runs/facts.d.ts +25 -0
  28. package/dist/commands/runs/facts.js +38 -5
  29. package/dist/commands/runs/list/command.d.ts +25 -0
  30. package/dist/commands/runs/list/outcomes.d.ts +25 -0
  31. package/dist/commands/runs/logs/metadata.js +1 -1
  32. package/dist/commands/runs/logs/outcomes.js +4 -1
  33. package/dist/commands/runs/past-run.d.ts +2 -2
  34. package/dist/commands/runs/past-run.js +2 -2
  35. package/dist/commands/runs/show/command.d.ts +25 -0
  36. package/dist/commands/runs/show/metadata.js +2 -2
  37. package/dist/commands/runs/show/outcomes.d.ts +25 -0
  38. package/dist/commands/runs/show/outcomes.js +37 -5
  39. package/dist/commands/vitest/command.d.ts +325 -0
  40. package/dist/commands/vitest/command.js +138 -0
  41. package/dist/commands/vitest/metadata.d.ts +69 -0
  42. package/dist/commands/vitest/metadata.js +35 -0
  43. package/dist/commands/vitest/outcomes.d.ts +298 -0
  44. package/dist/commands/vitest/outcomes.js +77 -0
  45. package/dist/config/index.d.ts +2 -1
  46. package/dist/config/index.js +1 -0
  47. package/dist/config/resolve.d.ts +3 -3
  48. package/dist/config/resolve.js +3 -3
  49. package/dist/config/resource-config.d.ts +2 -2
  50. package/dist/config/schema.d.ts +1 -1
  51. package/dist/config/set.d.ts +15 -4
  52. package/dist/config/set.js +28 -12
  53. package/dist/config-file/define.d.ts +8 -6
  54. package/dist/context.d.ts +6 -3
  55. package/dist/context.js +4 -2
  56. package/dist/core/command-provider.d.ts +1 -1
  57. package/dist/core/events.d.ts +9 -7
  58. package/dist/core/presentation.js +1 -1
  59. package/dist/core/presentations.js +1 -1
  60. package/dist/core/run-state.d.ts +30 -6
  61. package/dist/core/run-state.js +19 -4
  62. package/dist/core/run.d.ts +17 -4
  63. package/dist/core/run.js +61 -25
  64. package/dist/resources/testserver/command.d.ts +1 -1
  65. package/dist/resources/testserver/command.js +1 -1
  66. package/dist/resources/testserver/config.d.ts +1 -1
  67. package/dist/resources/testserver/config.js +3 -2
  68. package/dist/resources/testserver/credential-facts.js +1 -1
  69. package/dist/resources/testserver/resource.d.ts +2 -2
  70. package/dist/resources/testserver/sandbox/create.d.ts +2 -2
  71. package/dist/resources/testserver/sandbox/create.js +2 -2
  72. package/dist/resources.d.ts +9 -6
  73. package/dist/resources.js +3 -3
  74. package/dist/runner/events.d.ts +64 -1
  75. package/dist/runner/gateways.d.ts +17 -6
  76. package/dist/runner/index.d.ts +5 -4
  77. package/dist/runner/index.js +4 -3
  78. package/dist/runner/live/snapshot-records.js +18 -4
  79. package/dist/runner/prepare.d.ts +23 -4
  80. package/dist/runner/prepare.js +13 -3
  81. package/dist/runner/ready.d.ts +7 -3
  82. package/dist/runner/ready.js +11 -5
  83. package/dist/runner/scope.d.ts +17 -1
  84. package/dist/runner/scope.js +4 -0
  85. package/dist/runner/snapshot-build.d.ts +3 -1
  86. package/dist/runner/snapshot-build.js +12 -2
  87. package/dist/runner/snapshot-cache.d.ts +46 -8
  88. package/dist/runner/snapshot-cache.js +60 -11
  89. package/dist/runner/snapshot-key.d.ts +12 -1
  90. package/dist/runner/snapshot-key.js +17 -1
  91. package/dist/runner/snapshot-save.d.ts +53 -0
  92. package/dist/runner/snapshot-save.js +148 -0
  93. package/dist/sdk/index.js +1 -1
  94. package/dist/sdk/payload/payload.d.ts +2 -2
  95. package/dist/sdk/payload/payload.js +2 -2
  96. package/dist/story/align.d.ts +1 -1
  97. package/dist/story/align.js +1 -1
  98. package/dist/story/definition.d.ts +22 -15
  99. package/dist/story/definition.js +2 -2
  100. package/dist/story/errors.js +1 -1
  101. package/dist/story/gateways.d.ts +45 -25
  102. package/dist/story/gateways.js +2 -2
  103. package/dist/story/host.d.ts +11 -8
  104. package/dist/story/host.js +37 -37
  105. package/dist/story/index.d.ts +1 -1
  106. package/dist/story/index.js +4 -4
  107. package/dist/story/json.d.ts +1 -1
  108. package/dist/story/json.js +2 -2
  109. package/dist/story/live/recording-gateway.d.ts +2 -0
  110. package/dist/story/live/{artifact-gateway.js → recording-gateway.js} +33 -12
  111. package/dist/story/mode.d.ts +2 -2
  112. package/dist/story/mode.js +1 -1
  113. package/dist/story/orphans.d.ts +23 -5
  114. package/dist/story/orphans.js +44 -8
  115. package/dist/story/recording.d.ts +62 -0
  116. package/dist/story/{artifact.js → recording.js} +31 -27
  117. package/dist/story/report.d.ts +21 -9
  118. package/dist/story/report.js +37 -25
  119. package/dist/story/settle.d.ts +23 -21
  120. package/dist/story/settle.js +17 -16
  121. package/dist/story/{run.d.ts → start.d.ts} +18 -17
  122. package/dist/story/{run.js → start.js} +66 -43
  123. package/dist/vercel-cli/driver.d.ts +1 -1
  124. package/dist/vercel-cli/entry.d.ts +1 -1
  125. package/dist/vercel-cli/entry.js +1 -1
  126. package/dist/vercel-cli/verbose.d.ts +2 -2
  127. package/dist/vercel-cli/verbose.js +2 -2
  128. package/dist/vitest/config.d.ts +5 -5
  129. package/dist/vitest/config.js +5 -5
  130. package/dist/vitest/find-vitest.d.ts +7 -0
  131. package/dist/vitest/find-vitest.js +28 -0
  132. package/dist/vitest/fixtures.d.ts +2 -2
  133. package/dist/vitest/fixtures.js +3 -3
  134. package/dist/vitest/gateways.d.ts +37 -6
  135. package/dist/vitest/gateways.js +3 -2
  136. package/dist/vitest/live/list-gateway.d.ts +7 -3
  137. package/dist/vitest/live/list-gateway.js +55 -8
  138. package/dist/vitest/plan.d.ts +41 -8
  139. package/dist/vitest/plan.js +47 -16
  140. package/dist/vitest/sandbox.d.ts +1 -1
  141. package/dist/vitest/sandbox.js +1 -1
  142. package/dist/vitest/test-events.d.ts +2 -2
  143. package/dist/vitest/test-events.js +3 -3
  144. package/dist/vitest/test-results.d.ts +1 -1
  145. package/dist/vitest/test-results.js +1 -1
  146. package/dist/vitest/types.d.ts +1 -1
  147. package/package.json +2 -2
  148. package/skills/overview.md +5 -4
  149. package/skills/read-run-output.md +1 -1
  150. package/dist/commands/run/command.d.ts +0 -327
  151. package/dist/commands/run/command.js +0 -620
  152. package/dist/commands/run/metadata.d.ts +0 -47
  153. package/dist/commands/run/metadata.js +0 -83
  154. package/dist/commands/run/outcomes.js +0 -332
  155. package/dist/story/artifact.d.ts +0 -60
  156. package/dist/story/live/artifact-gateway.d.ts +0 -2
  157. /package/dist/commands/{run → exec}/live-view.d.ts +0 -0
  158. /package/dist/commands/{run → exec}/mint-failed.d.ts +0 -0
  159. /package/dist/commands/{run → exec}/redaction.d.ts +0 -0
  160. /package/dist/commands/{run → exec}/redaction.js +0 -0
  161. /package/dist/commands/{run → exec}/run-collector.d.ts +0 -0
  162. /package/dist/commands/{run → exec}/run-collector.js +0 -0
  163. /package/dist/commands/{run → exec}/tests-summary.d.ts +0 -0
  164. /package/dist/commands/{run → exec}/tests-summary.js +0 -0
  165. /package/dist/commands/{run → exec}/text.d.ts +0 -0
  166. /package/dist/commands/{run → exec}/text.js +0 -0
  167. /package/dist/commands/{run → exec}/view.d.ts +0 -0
  168. /package/dist/commands/{run → exec}/waterfall.d.ts +0 -0
  169. /package/dist/commands/{run → exec}/waterfall.js +0 -0
  170. /package/dist/commands/{run → exec}/worker-chart.d.ts +0 -0
  171. /package/dist/commands/{run → exec}/worker-chart.js +0 -0
@@ -1,15 +1,24 @@
1
- import type { StoryCall, StoryIdentity } from "./artifact.ts";
1
+ import type { StoryCall, StoryIdentity } from "./recording.ts";
2
2
  import { type StoryRecordLevel } from "./mode.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;
6
6
  /**
7
- * One line per aligned call, then one per unreadable artifact and orphan, each with its status in brackets:
8
- * `matched`, `divergence`, `unrecorded` or `unmade`, `orphan` or `unreadable`. When the story's end `applied` its
9
- * change, an unrecorded call reads `recorded`, an accepted divergence `divergence accepted`, an unmade call
10
- * `unmade removed`, an unreadable artifact `unreadable rewritten` and an orphan `orphan removed`.
7
+ * What a story's end changed: whether it wrote or removed the story's own recording, and the orphan recordings it
8
+ * removed, or found already gone. An end that fails partway keeps what it changed before the failure.
11
9
  */
12
- export declare function storyEventLines(settlement: StorySettlement, applied: boolean): readonly string[];
10
+ export interface StoryApplied {
11
+ readonly recording: boolean;
12
+ readonly orphans: readonly string[];
13
+ }
14
+ /**
15
+ * One line per aligned call, then one per unreadable recording and orphan, each with its status in brackets:
16
+ * `matched`, `divergence`, `unrecorded` or `unmade`, `orphan` or `unreadable`. When the story's end `applied` the
17
+ * change to its recording, an unrecorded call reads `recorded`, an accepted divergence `divergence accepted`, an
18
+ * unmade call `unmade removed` and an unreadable recording `unreadable rewritten`; each orphan it removed reads
19
+ * `orphan removed`.
20
+ */
21
+ export declare function storyEventLines(settlement: StorySettlement, applied: StoryApplied): readonly string[];
13
22
  export interface StoryReportInput {
14
23
  readonly story: StoryIdentity;
15
24
  readonly level: StoryRecordLevel;
@@ -24,7 +33,10 @@ export interface StoryReportInput {
24
33
  */
25
34
  export declare function storyReport(input: StoryReportInput): string;
26
35
  /**
27
- * The line for what a passing story's end changed, or `undefined` when it changed nothing: how many calls it
28
- * recorded, divergences it accepted, unmade calls it removed, unreadable artifacts it rewrote and orphans it removed.
36
+ * What a passing story's end `applied`, or `undefined` when it changed nothing. Its first line counts what it did: the
37
+ * calls it recorded, the divergences it accepted, the unmade calls it removed, an unreadable recording it rewrote and
38
+ * the orphans it removed. One line follows for each call it rewrote and each recording it rewrote or removed, as
39
+ * `storyEventLines` gives it, so a call whose input changed with its answer shows as the unmade call removed and the
40
+ * new call recorded.
29
41
  */
30
- export declare function storyChangeLine(story: StoryIdentity, path: string, settlement: StorySettlement): string | undefined;
42
+ export declare function storyChangeReport(story: StoryIdentity, path: string, settlement: StorySettlement, applied: StoryApplied): string | undefined;
@@ -1,5 +1,5 @@
1
- // What a story says about its calls: one event line per call, the report of a failed story, and the line for what a
2
- // passing story changed. Pure.
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
+ // changed. Pure.
3
3
  import { describeObservationDiff } from "./diff.js";
4
4
  import { STORY_RECORD_VARIABLE } from "./mode.js";
5
5
  /** How much of a call's input its line keeps. */
@@ -10,22 +10,24 @@ export function describeCall(call) {
10
10
  return `${call.agent} calls ${call.tool} ${input.length > INPUT_CHARS ? `${input.slice(0, INPUT_CHARS - 1)}…` : input}`;
11
11
  }
12
12
  /**
13
- * One line per aligned call, then one per unreadable artifact and orphan, each with its status in brackets:
14
- * `matched`, `divergence`, `unrecorded` or `unmade`, `orphan` or `unreadable`. When the story's end `applied` its
15
- * change, an unrecorded call reads `recorded`, an accepted divergence `divergence accepted`, an unmade call
16
- * `unmade removed`, an unreadable artifact `unreadable rewritten` and an orphan `orphan removed`.
13
+ * One line per aligned call, then one per unreadable recording and orphan, each with its status in brackets:
14
+ * `matched`, `divergence`, `unrecorded` or `unmade`, `orphan` or `unreadable`. When the story's end `applied` the
15
+ * change to its recording, an unrecorded call reads `recorded`, an accepted divergence `divergence accepted`, an
16
+ * unmade call `unmade removed` and an unreadable recording `unreadable rewritten`; each orphan it removed reads
17
+ * `orphan removed`.
17
18
  */
18
19
  export function storyEventLines(settlement, applied) {
19
- const written = applied && settlement.change.kind !== "leave";
20
- const calls = settlement.aligned.map((each) => `${describeAligned(each)} [${callStatus(each, written, settlement.accepted)}]`);
21
- const files = settlement.stale.flatMap((entry) => entry.kind === "unreadable"
22
- ? [`artifact ${entry.path} [${written ? "unreadable rewritten" : "unreadable"}]`]
20
+ const calls = settlement.aligned.map((each) => `${describeAligned(each)} [${callStatus(each, applied.recording, settlement.accepted)}]`);
21
+ return [...calls, ...recordingLines(settlement, applied)];
22
+ }
23
+ /** One line per unreadable recording and orphan recording, each with its status, as `storyEventLines` gives it. */
24
+ function recordingLines(settlement, applied) {
25
+ const removed = new Set(applied.orphans);
26
+ return settlement.stale.flatMap((entry) => entry.kind === "unreadable"
27
+ ? [`recording ${entry.path} [${applied.recording ? "unreadable rewritten" : "unreadable"}]`]
23
28
  : entry.kind === "orphan"
24
- ? [
25
- `artifact ${entry.path} [${applied && settlement.removeOrphans.includes(entry.path) ? "orphan removed" : "orphan"}]`,
26
- ]
29
+ ? [`recording ${entry.path} [${removed.has(entry.path) ? "orphan removed" : "orphan"}]`]
27
30
  : []);
28
- return [...calls, ...files];
29
31
  }
30
32
  function describeAligned(each) {
31
33
  return describeCall(each.kind === "unmade" ? each.recorded : each.live);
@@ -85,18 +87,20 @@ function summary(input) {
85
87
  if (input.bodyFailed)
86
88
  return `${counts} The story threw, so nothing was written.`;
87
89
  if (divergences.length > 0) {
88
- return `${counts} A divergence means the tool behaved differently. If that is intended, record it with ${STORY_RECORD_VARIABLE}=all.`;
90
+ return `${counts} A divergence means the tool behaved differently. If that is intended, accept it with ${STORY_RECORD_VARIABLE}=all.`;
89
91
  }
90
- return `${counts} The recording no longer fits the story. Record it again with ${STORY_RECORD_VARIABLE}=stale.`;
92
+ return `${counts} The recording no longer fits the story. Rewrite it with ${STORY_RECORD_VARIABLE}=stale.`;
91
93
  }
92
94
  /**
93
- * The line for what a passing story's end changed, or `undefined` when it changed nothing: how many calls it
94
- * recorded, divergences it accepted, unmade calls it removed, unreadable artifacts it rewrote and orphans it removed.
95
+ * What a passing story's end `applied`, or `undefined` when it changed nothing. Its first line counts what it did: the
96
+ * calls it recorded, the divergences it accepted, the unmade calls it removed, an unreadable recording it rewrote and
97
+ * the orphans it removed. One line follows for each call it rewrote and each recording it rewrote or removed, as
98
+ * `storyEventLines` gives it, so a call whose input changed with its answer shows as the unmade call removed and the
99
+ * new call recorded.
95
100
  */
96
- export function storyChangeLine(story, path, settlement) {
101
+ export function storyChangeReport(story, path, settlement, applied) {
97
102
  const parts = [];
98
- const written = settlement.change.kind !== "leave";
99
- if (written) {
103
+ if (applied.recording) {
100
104
  const kinds = (kind) => settlement.stale.filter((entry) => entry.kind === kind).length;
101
105
  if (kinds("unrecorded") > 0)
102
106
  parts.push(`recorded ${count(kinds("unrecorded"), "call")}`);
@@ -105,13 +109,21 @@ export function storyChangeLine(story, path, settlement) {
105
109
  if (kinds("unmade") > 0)
106
110
  parts.push(`removed ${count(kinds("unmade"), "unmade call")}`);
107
111
  if (kinds("unreadable") > 0)
108
- parts.push("rewrote an unreadable artifact");
112
+ parts.push("rewrote an unreadable recording");
109
113
  }
110
- if (settlement.removeOrphans.length > 0)
111
- parts.push(`removed ${count(settlement.removeOrphans.length, "orphan")}`);
114
+ if (applied.orphans.length > 0)
115
+ parts.push(`removed ${count(applied.orphans.length, "orphan recording")}`);
112
116
  if (parts.length === 0)
113
117
  return undefined;
114
- return `story "${story.name}": ${parts.join(", ")} (${path})`;
118
+ const changed = [
119
+ ...(applied.recording ? rewrittenCallLines(settlement) : []),
120
+ ...recordingLines(settlement, applied),
121
+ ];
122
+ return [`story "${story.name}": ${parts.join(", ")} (${path})`, ...changed.map((line) => ` ${line}`)].join("\n");
123
+ }
124
+ /** The event line of each aligned call a written recording changed: every one but the matched ones. */
125
+ function rewrittenCallLines(settlement) {
126
+ return settlement.aligned.flatMap((each) => each.kind === "matched" ? [] : [`${describeAligned(each)} [${callStatus(each, true, settlement.accepted)}]`]);
115
127
  }
116
128
  function count(n, one, many = `${one}s`) {
117
129
  return `${n} ${n === 1 ? one : many}`;
@@ -1,5 +1,5 @@
1
1
  import { type StoryAlignedCall } from "./align.ts";
2
- import type { StoryArtifact, StoryCall, StoryIdentity } from "./artifact.ts";
2
+ import type { StoryRecording, StoryCall, StoryIdentity } from "./recording.ts";
3
3
  import type { StoryRecordLevel } from "./mode.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 {
@@ -11,8 +11,9 @@ export interface StoryDivergence {
11
11
  *
12
12
  * - `unrecorded`: a live call with no recorded call.
13
13
  * - `unmade`: a recorded call with no live call.
14
- * - `orphan`: an artifact in the story file's artifact directory that belongs to no story in the file.
15
- * - `unreadable`: the story's artifact doesn't parse, or has another schema version.
14
+ * - `orphan`: a recording in the story file's recording directory that belongs to no story in the file, or one in the
15
+ * recording directory of a story file that is gone.
16
+ * - `unreadable`: the story's recording doesn't parse, or has another schema version.
16
17
  */
17
18
  export type StoryStaleEntry = {
18
19
  readonly kind: "unrecorded";
@@ -28,20 +29,20 @@ export type StoryStaleEntry = {
28
29
  readonly path: string;
29
30
  readonly problem: string;
30
31
  };
31
- /** The story's artifact as its run found it. */
32
- export type StoryRecording = {
32
+ /** The story's recording as the story's end read it: found, missing, or unreadable (a read that didn't fail). */
33
+ export type RecordingRead = {
33
34
  readonly kind: "found";
34
- readonly artifact: StoryArtifact;
35
+ readonly recording: StoryRecording;
35
36
  } | {
36
37
  readonly kind: "missing";
37
38
  } | {
38
39
  readonly kind: "unreadable";
39
40
  readonly problem: string;
40
41
  };
41
- /** What to do with the story's own artifact: write it, remove it, or leave it. */
42
- export type StoryArtifactChange = {
42
+ /** What to do with the story's own recording: write it, remove it, or leave it. */
43
+ export type RecordingChange = {
43
44
  readonly kind: "write";
44
- readonly artifact: StoryArtifact;
45
+ readonly recording: StoryRecording;
45
46
  } | {
46
47
  readonly kind: "remove";
47
48
  } | {
@@ -49,15 +50,15 @@ export type StoryArtifactChange = {
49
50
  };
50
51
  export interface StorySettleInput {
51
52
  readonly story: StoryIdentity;
52
- /** The story's artifact path, which an unreadable entry names. */
53
+ /** The story's recording path, which an unreadable entry names. */
53
54
  readonly path: string;
54
55
  readonly level: StoryRecordLevel;
55
56
  /** Whether the story's body returned without throwing. */
56
57
  readonly bodyPassed: boolean;
57
- readonly recording: StoryRecording;
58
+ readonly read: RecordingRead;
58
59
  /** The calls the story made, in order. */
59
60
  readonly live: readonly StoryCall[];
60
- /** The story file's orphans, when this story's end checks for them; none otherwise. */
61
+ /** The orphan recordings, when this story's end looks for them (`findOrphans`); none otherwise. */
61
62
  readonly orphans: readonly string[];
62
63
  }
63
64
  export interface StorySettlement {
@@ -70,9 +71,9 @@ export interface StorySettlement {
70
71
  readonly unreached: number;
71
72
  readonly divergences: readonly StoryDivergence[];
72
73
  readonly stale: readonly StoryStaleEntry[];
73
- readonly change: StoryArtifactChange;
74
- /** The orphans to remove. */
75
- readonly removeOrphans: readonly string[];
74
+ readonly change: RecordingChange;
75
+ /** Whether the end removes the orphan recordings, the `orphan` entries in `stale`. */
76
+ readonly removesOrphans: boolean;
76
77
  /** Whether the divergences are recorded as the new observations (`STORY_RECORD=all`). */
77
78
  readonly accepted: boolean;
78
79
  /** Why the story fails, beyond its body: a divergence, or a stale entry at `none`. */
@@ -80,15 +81,16 @@ export interface StorySettlement {
80
81
  }
81
82
  /**
82
83
  * Settles one story's end. Its live calls are aligned with the recorded ones (`alignCalls`); each `divergence` is a
83
- * divergence, and each `unrecorded` and `unmade` call, an unreadable artifact and each orphan is a stale entry. A
84
- * story whose body threw changes nothing and fails with its own error; the recorded calls after its last aligned call
85
- * count as unreached, not unmade. Otherwise, by level:
84
+ * divergence, and each `unrecorded` and `unmade` call, an unreadable recording and each orphan recording is a stale
85
+ * entry. A story whose body threw changes nothing and fails with its own error; the recorded calls after its last
86
+ * aligned call count as unreached, not unmade. Otherwise, by level:
86
87
  *
87
88
  * - `none` changes nothing, and fails on a divergence, else on a stale entry.
88
- * - `stale` fails on a divergence, changing nothing; otherwise it writes the artifact and removes the orphans.
89
- * - `all` writes the artifact and removes the orphans, accepting any divergence.
89
+ * - `stale` fails on a divergence, changing nothing; otherwise it writes the recording and removes the orphan
90
+ * recordings.
91
+ * - `all` writes the recording and removes the orphan recordings, accepting any divergence.
90
92
  *
91
- * The artifact written holds the live calls. A story that made no call has no artifact, so writing it removes one
93
+ * The recording written holds the live calls. A story that made no call has no recording, so writing it removes one
92
94
  * that is there.
93
95
  */
94
96
  export declare function settleStory(input: StorySettleInput): StorySettlement;
@@ -1,30 +1,31 @@
1
- // What a story's end decides: how its live calls compare with its artifact, which divergences and stale entries
1
+ // What a story's end decides: how its live calls compare with its recording, which divergences and stale entries
2
2
  // there are, what to write, and whether the story fails. Pure.
3
3
  import { alignCalls } from "./align.js";
4
- import { STORY_ARTIFACT_SCHEMA_VERSION } from "./artifact.js";
4
+ import { STORY_RECORDING_SCHEMA_VERSION } from "./recording.js";
5
5
  /**
6
6
  * Settles one story's end. Its live calls are aligned with the recorded ones (`alignCalls`); each `divergence` is a
7
- * divergence, and each `unrecorded` and `unmade` call, an unreadable artifact and each orphan is a stale entry. A
8
- * story whose body threw changes nothing and fails with its own error; the recorded calls after its last aligned call
9
- * count as unreached, not unmade. Otherwise, by level:
7
+ * divergence, and each `unrecorded` and `unmade` call, an unreadable recording and each orphan recording is a stale
8
+ * entry. A story whose body threw changes nothing and fails with its own error; the recorded calls after its last
9
+ * aligned call count as unreached, not unmade. Otherwise, by level:
10
10
  *
11
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 artifact and removes the orphans.
13
- * - `all` writes the artifact and removes the orphans, accepting any divergence.
12
+ * - `stale` fails on a divergence, changing nothing; otherwise it writes the recording and removes the orphan
13
+ * recordings.
14
+ * - `all` writes the recording and removes the orphan recordings, accepting any divergence.
14
15
  *
15
- * The artifact written holds the live calls. A story that made no call has no artifact, so writing it removes one
16
+ * The recording written holds the live calls. A story that made no call has no recording, so writing it removes one
16
17
  * that is there.
17
18
  */
18
19
  export function settleStory(input) {
19
- const recorded = input.recording.kind === "found" ? input.recording.artifact.calls : [];
20
+ const recorded = input.read.kind === "found" ? input.read.recording.calls : [];
20
21
  const all = alignCalls(recorded, input.live);
21
22
  const reached = input.bodyPassed ? all.length : lastLiveIndex(all) + 1;
22
23
  const aligned = all.slice(0, reached);
23
24
  const unreached = all.length - reached;
24
25
  const divergences = aligned.flatMap((each) => each.kind === "divergence" ? [{ recorded: each.recorded, live: each.live }] : []);
25
26
  const stale = [
26
- ...(input.recording.kind === "unreadable"
27
- ? [{ kind: "unreadable", path: input.path, problem: input.recording.problem }]
27
+ ...(input.read.kind === "unreadable"
28
+ ? [{ kind: "unreadable", path: input.path, problem: input.read.problem }]
28
29
  : []),
29
30
  ...aligned.flatMap((each) => each.kind === "unrecorded"
30
31
  ? [{ kind: "unrecorded", call: each.live }]
@@ -34,7 +35,7 @@ export function settleStory(input) {
34
35
  ...input.orphans.map((path) => ({ kind: "orphan", path })),
35
36
  ];
36
37
  const settled = { aligned, unreached, divergences, stale };
37
- const leave = { change: { kind: "leave" }, removeOrphans: [], accepted: false };
38
+ const leave = { change: { kind: "leave" }, removesOrphans: false, accepted: false };
38
39
  if (!input.bodyPassed)
39
40
  return { ...settled, ...leave, failure: undefined };
40
41
  if (input.level === "none") {
@@ -49,20 +50,20 @@ export function settleStory(input) {
49
50
  return {
50
51
  ...settled,
51
52
  change: desiredChange(input),
52
- removeOrphans: input.orphans,
53
+ removesOrphans: true,
53
54
  accepted: divergences.length > 0,
54
55
  failure: undefined,
55
56
  };
56
57
  }
57
- /** The artifact that fits the story's live calls: one holding them, or none when it made no call. */
58
+ /** The recording that fits the story's live calls: one holding them, or none when it made no call. */
58
59
  function desiredChange(input) {
59
60
  if (input.live.length > 0) {
60
61
  return {
61
62
  kind: "write",
62
- artifact: { schemaVersion: STORY_ARTIFACT_SCHEMA_VERSION, story: input.story, calls: input.live },
63
+ recording: { schemaVersion: STORY_RECORDING_SCHEMA_VERSION, story: input.story, calls: input.live },
63
64
  };
64
65
  }
65
- return input.recording.kind === "missing" ? { kind: "leave" } : { kind: "remove" };
66
+ return input.read.kind === "missing" ? { kind: "leave" } : { kind: "remove" };
66
67
  }
67
68
  /** The index of the last aligned call the story made, -1 when it made none. */
68
69
  function lastLiveIndex(aligned) {
@@ -1,49 +1,50 @@
1
- import type { StoryIdentity } from "./artifact.ts";
1
+ import type { StoryIdentity } from "./recording.ts";
2
2
  import type { StoryAgents, StoryHandles, StoryHarness, StorySession } from "./definition.ts";
3
- import type { StoryArtifactGateway } from "./gateways.ts";
3
+ import type { StoryRecordingGateway } from "./gateways.ts";
4
4
  import type { StoryRecordLevel } from "./mode.ts";
5
- export interface StoryRunOptions {
5
+ export interface StoryStartOptions {
6
6
  readonly story: StoryIdentity;
7
- /** The story's artifact path (`artifactPath`). */
7
+ /** The story's recording path (`recordingPath`). */
8
8
  readonly path: string;
9
9
  readonly level: StoryRecordLevel;
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
- * threw, so it changes nothing; one stopped while its end changes the artifact stops before the next change.
12
+ * threw, so it changes nothing; one stopped while its end changes the recording stops before the next change.
13
13
  */
14
14
  readonly signal?: AbortSignal;
15
15
  }
16
16
  /** How a story's end went. */
17
- export interface StoryRunEnd {
18
- /** One line per call, unreadable artifact and orphan (`storyEventLines`). */
17
+ export interface StoryEnd {
18
+ /** One line per call, unreadable recording and orphan recording (`storyEventLines`). */
19
19
  readonly events: readonly string[];
20
20
  /** The report, when the story fails or its body threw with something to report; otherwise `undefined`. */
21
21
  readonly report: string | undefined;
22
- /** What a passing story changed (`storyChangeLine`), or `undefined`. */
23
- readonly changeLine: string | undefined;
22
+ /** What a passing story changed, naming each call it rewrote (`storyChangeReport`), or `undefined`. */
23
+ readonly changeReport: string | undefined;
24
24
  /**
25
- * Why the story fails beyond its body: a `StoryDivergenceError`, a `StoryStaleError`, an artifact that couldn't be
25
+ * Why the story fails beyond its body: a `StoryDivergenceError`, a `StoryStaleError`, a recording that couldn't be
26
26
  * read, written or removed, or a session whose `close()` threw. `undefined` when nothing did.
27
27
  */
28
28
  readonly error: Error | undefined;
29
29
  }
30
- /** How a story's body ended, and the story file's orphans when this story's end checks for them (none otherwise). */
31
- export interface StoryRunFinish {
30
+ /** How a story's body ended, and the orphan recordings when this story's end looks for them (none otherwise). */
31
+ export interface StoryEndInput {
32
32
  readonly bodyPassed: boolean;
33
33
  readonly orphans: readonly string[];
34
34
  }
35
- export interface StoryRun<Agents> {
35
+ /** A story that started: its body calls tools through `handles` until the story ends. */
36
+ export interface StartedStory<Agents> {
36
37
  /** What the story's body gets: one handle per agent, each with a function per tool. */
37
38
  readonly handles: StoryHandles<Agents>;
38
39
  /**
39
- * Ends the story, once: whether its body passed, and the story file's orphans when this end checks for them.
40
+ * Ends the story, once: whether its body passed, and the orphan recordings when this end looks for them.
40
41
  * Closes the session, if one started, whatever else happens.
41
42
  */
42
- finish(end: StoryRunFinish): Promise<StoryRunEnd>;
43
+ end(input: StoryEndInput): Promise<StoryEnd>;
43
44
  }
44
45
  /**
45
- * Starts one story's run. Each tool call checks its input against the tool's schema (a `TypeError` when it doesn't
46
+ * Starts one story. Each tool call checks its input against the tool's schema (a `TypeError` when it doesn't
46
47
  * match), starts the session on the first call, runs the tool, and keeps its observation; a tool that throws keeps
47
48
  * nothing. Its input and observation must be JSON (a `TypeError` otherwise).
48
49
  */
49
- export declare function startStoryRun<Session extends StorySession, Agents extends StoryAgents<Session>>(harness: StoryHarness<Session, Agents>, options: StoryRunOptions, gateway: StoryArtifactGateway): StoryRun<Agents>;
50
+ export declare function startStory<Session extends StorySession, Agents extends StoryAgents<Session>>(harness: StoryHarness<Session, Agents>, options: StoryStartOptions, gateway: StoryRecordingGateway): StartedStory<Agents>;
@@ -1,25 +1,25 @@
1
- // One story's run, apart from Vitest: the handles its body calls tools through, and its end, which compares the
2
- // calls with the artifact, changes what the level allows, and closes the session. Domain logic over the artifact
3
- // gateway.
1
+ // One story from its start to its end, apart from Vitest: the handles its body calls tools through, and its end, which
2
+ // compares the calls with the recording, changes what the level allows, and closes the session. Domain logic over the
3
+ // recording gateway.
4
4
  import { StoryDivergenceError, StoryStaleError } from "./errors.js";
5
5
  import { toStoryJson } from "./json.js";
6
- import { storyChangeLine, storyEventLines, storyReport } from "./report.js";
6
+ import { storyChangeReport, storyEventLines, storyReport } from "./report.js";
7
7
  import { settleStory } from "./settle.js";
8
8
  /**
9
- * Starts one story's run. Each tool call checks its input against the tool's schema (a `TypeError` when it doesn't
9
+ * Starts one story. Each tool call checks its input against the tool's schema (a `TypeError` when it doesn't
10
10
  * match), starts the session on the first call, runs the tool, and keeps its observation; a tool that throws keeps
11
11
  * nothing. Its input and observation must be JSON (a `TypeError` otherwise).
12
12
  */
13
- export function startStoryRun(harness, options, gateway) {
13
+ export function startStory(harness, options, gateway) {
14
14
  const live = [];
15
15
  let session;
16
- let finished = false;
16
+ let ended = false;
17
17
  const startSession = () => {
18
18
  session ??= Promise.resolve().then(() => harness.start());
19
19
  return session;
20
20
  };
21
21
  const callTool = async (agent, name, raw) => {
22
- if (finished)
22
+ if (ended)
23
23
  throw new Error(`story: ${agent} calls ${name} after the story ended`);
24
24
  const tool = harness.agents[agent]?.tools[name];
25
25
  if (tool === undefined)
@@ -33,10 +33,10 @@ export function startStoryRun(harness, options, gateway) {
33
33
  const input = toStoryJson(parsed.data, `${agent} calls ${name} with input that must be JSON`);
34
34
  const index = live.push({ kind: "running" }) - 1;
35
35
  try {
36
- const result = await tool.run(await startSession(), parsed.data);
37
- const observation = toStoryJson(tool.observe(result), `${agent}'s ${name} tool observes its result as JSON`);
36
+ const returned = await tool.run(await startSession(), parsed.data);
37
+ const observation = toStoryJson(tool.observe(returned), `${agent}'s ${name} tool observes its return value as JSON`);
38
38
  live[index] = { kind: "done", call: { agent, tool: name, input, observation } };
39
- return result;
39
+ return returned;
40
40
  }
41
41
  catch (error) {
42
42
  live[index] = { kind: "threw" };
@@ -60,58 +60,79 @@ export function startStoryRun(harness, options, gateway) {
60
60
  return new Error(`story: the session's close() threw: ${messageOf(error)}`, { cause: error });
61
61
  }
62
62
  };
63
- const apply = async (settlement) => {
64
- const { change } = settlement;
63
+ /** Writes or removes the story's own recording, as `change` says; the error when that failed or was stopped. */
64
+ const changeRecording = async (change) => {
65
65
  const { signal } = options;
66
66
  if (change.kind === "write") {
67
- const written = await gateway.writeArtifact({
67
+ const written = await gateway.writeRecording({
68
68
  path: options.path,
69
- artifact: change.artifact,
69
+ recording: change.recording,
70
70
  ...signalOf(signal),
71
71
  });
72
72
  if (written.kind === "canceled")
73
- return stoppedBefore(`writing the artifact ${options.path}`);
73
+ return stoppedBefore(`writing the recording ${options.path}`);
74
74
  if (written.kind === "failed")
75
- return new Error(`story: couldn't write the artifact ${options.path}: ${written.message}`);
75
+ return new Error(`story: couldn't write the recording ${options.path}: ${written.message}`);
76
76
  }
77
77
  else if (change.kind === "remove") {
78
- const removed = await gateway.removeArtifact({ path: options.path, ...signalOf(signal) });
78
+ const removed = await gateway.removeRecording({ path: options.path, ...signalOf(signal) });
79
79
  if (removed.kind === "canceled")
80
- return stoppedBefore(`removing the artifact ${options.path}`);
80
+ return stoppedBefore(`removing the recording ${options.path}`);
81
81
  if (removed.kind === "failed")
82
- return new Error(`story: couldn't remove the artifact ${options.path}: ${removed.message}`);
82
+ return new Error(`story: couldn't remove the recording ${options.path}: ${removed.message}`);
83
83
  }
84
- for (const orphan of settlement.removeOrphans) {
85
- const removed = await gateway.removeArtifact({ path: orphan, ...signalOf(signal) });
84
+ return undefined;
85
+ };
86
+ /**
87
+ * Makes the changes `settlement` decided, in order: the story's own recording, then each orphan recording. Returns
88
+ * what it changed, up to the first change that failed or was stopped, and that change's error.
89
+ */
90
+ const apply = async (settlement) => {
91
+ const recordingError = await changeRecording(settlement.change);
92
+ if (recordingError !== undefined)
93
+ return { applied: { recording: false, orphans: [] }, error: recordingError };
94
+ const orphans = [];
95
+ const applied = (error) => ({
96
+ applied: { recording: settlement.change.kind !== "leave", orphans },
97
+ error,
98
+ });
99
+ if (!settlement.removesOrphans)
100
+ return applied(undefined);
101
+ // Two story files that end at once may both find a deleted story file's recordings, so one already gone
102
+ // (`missing`) is no failure.
103
+ for (const entry of settlement.stale) {
104
+ if (entry.kind !== "orphan")
105
+ continue;
106
+ const removed = await gateway.removeRecording({ path: entry.path, ...signalOf(options.signal) });
86
107
  if (removed.kind === "canceled")
87
- return stoppedBefore(`removing the orphan ${orphan}`);
88
- if (removed.kind === "failed")
89
- return new Error(`story: couldn't remove the orphan ${orphan}: ${removed.message}`);
108
+ return applied(stoppedBefore(`removing the orphan ${entry.path}`));
109
+ if (removed.kind === "failed") {
110
+ return applied(new Error(`story: couldn't remove the orphan ${entry.path}: ${removed.message}`));
111
+ }
112
+ orphans.push(entry.path);
90
113
  }
91
- return undefined;
114
+ return applied(undefined);
92
115
  };
93
- const settle = async (end) => {
116
+ const settle = async (input) => {
94
117
  const calls = live.flatMap((slot) => (slot.kind === "done" ? [slot.call] : []));
95
- const read = await gateway.readArtifact({ path: options.path });
118
+ const read = await gateway.readRecording({ path: options.path });
96
119
  if (read.kind === "failed") {
97
- const error = new Error(`story: couldn't read the artifact ${options.path}: ${read.message}`);
98
- return { events: [], report: undefined, changeLine: undefined, error };
120
+ const error = new Error(`story: couldn't read the recording ${options.path}: ${read.message}`);
121
+ return { events: [], report: undefined, changeReport: undefined, error };
99
122
  }
100
- const recording = read;
101
- // A story stopped while it ended, reading its artifact or finding its file's orphans, compares as one whose body
123
+ // A story stopped while it ended, reading its recording or finding orphan recordings, compares as one whose body
102
124
  // threw: the test has already failed, so nothing may be written for it.
103
- const bodyPassed = end.bodyPassed && options.signal?.aborted !== true;
125
+ const bodyPassed = input.bodyPassed && options.signal?.aborted !== true;
104
126
  const settlement = settleStory({
105
127
  story: options.story,
106
128
  path: options.path,
107
129
  level: options.level,
108
130
  bodyPassed,
109
- recording,
131
+ read,
110
132
  live: calls,
111
- orphans: end.orphans,
133
+ orphans: input.orphans,
112
134
  });
113
- const applyError = await apply(settlement);
114
- const applied = applyError === undefined;
135
+ const { applied, error: applyError } = await apply(settlement);
115
136
  const something = settlement.divergences.length > 0 || settlement.stale.length > 0 || settlement.unreached > 0;
116
137
  let report;
117
138
  let failure;
@@ -127,17 +148,19 @@ export function startStoryRun(harness, options, gateway) {
127
148
  return {
128
149
  events: storyEventLines(settlement, applied),
129
150
  report,
130
- changeLine: applied && bodyPassed ? storyChangeLine(options.story, options.path, settlement) : undefined,
151
+ changeReport: applyError === undefined && bodyPassed
152
+ ? storyChangeReport(options.story, options.path, settlement, applied)
153
+ : undefined,
131
154
  error: applyError ?? failure,
132
155
  };
133
156
  };
134
- const finish = async (end) => {
135
- if (finished)
157
+ const end = async (input) => {
158
+ if (ended)
136
159
  throw new Error("story: the story already ended");
137
- finished = true;
160
+ ended = true;
138
161
  let settled;
139
162
  try {
140
- settled = await settle(end);
163
+ settled = await settle(input);
141
164
  }
142
165
  finally {
143
166
  const closeError = await closeSession();
@@ -147,7 +170,7 @@ export function startStoryRun(harness, options, gateway) {
147
170
  }
148
171
  return settled;
149
172
  };
150
- return { handles, finish };
173
+ return { handles, end };
151
174
  }
152
175
  function signalOf(signal) {
153
176
  return signal === undefined ? {} : { signal };
@@ -39,7 +39,7 @@ export interface VercelCliOptions {
39
39
  /**
40
40
  * Hears each invocation once it has ended, or failed to start, tokens redacted, such as to print it with
41
41
  * `describeInvocation` as the test goes. What it throws is dropped. Without one, `vercelCli` prints each invocation
42
- * with `describeInvocation` to stderr in a verbose run (`storm run --verbose`) and does nothing otherwise; a
42
+ * with `describeInvocation` to stderr in a verbose run (its `--verbose`) and does nothing otherwise; a
43
43
  * listener replaces that, so `() => {}` silences it.
44
44
  */
45
45
  readonly onInvocationEnd?: (invocation: VercelInvocation) => void;
@@ -3,6 +3,6 @@ import { type VercelCli, type VercelCliOptions } from "./driver.ts";
3
3
  * A `VercelCli` for one test, running `vercel` as real processes with `PATH`, `SystemRoot` and `TEMP` from
4
4
  * `process.env` unless `hostEnv` says otherwise. It creates `<home>/global-config` and `<home>/work` first. Without an
5
5
  * `onInvocationEnd`, it prints each invocation with `describeInvocation` to stderr in a verbose run
6
- * (`storm run --verbose`, read from `process.env`'s run payload), and nothing otherwise.
6
+ * (a run's `--verbose`, read from `process.env`'s run payload), and nothing otherwise.
7
7
  */
8
8
  export declare function vercelCli(options: VercelCliOptions): Promise<VercelCli>;
@@ -5,7 +5,7 @@ import { defaultInvocationListener } from "./verbose.js";
5
5
  * A `VercelCli` for one test, running `vercel` as real processes with `PATH`, `SystemRoot` and `TEMP` from
6
6
  * `process.env` unless `hostEnv` says otherwise. It creates `<home>/global-config` and `<home>/work` first. Without an
7
7
  * `onInvocationEnd`, it prints each invocation with `describeInvocation` to stderr in a verbose run
8
- * (`storm run --verbose`, read from `process.env`'s run payload), and nothing otherwise.
8
+ * (a run's `--verbose`, read from `process.env`'s run payload), and nothing otherwise.
9
9
  */
10
10
  export function vercelCli(options) {
11
11
  const onInvocationEnd = options.onInvocationEnd ?? defaultInvocationListener(process.env, (text) => console.error(text));
@@ -1,7 +1,7 @@
1
1
  import type { VercelInvocation } from "./invocation.ts";
2
2
  /**
3
3
  * The listener `vercelCli` uses when the caller passes no `onInvocationEnd`: one that prints each invocation with
4
- * `describeInvocation` to `print`, when `env`'s run payload says the run is verbose (`storm run --verbose`), or
5
- * `undefined` outside `storm run`, in a run that isn't verbose, or when the run payload can't be read.
4
+ * `describeInvocation` to `print`, when `env`'s run payload says the run is verbose (its `--verbose`), or
5
+ * `undefined` outside a storm run, in a run that isn't verbose, or when the run payload can't be read.
6
6
  */
7
7
  export declare function defaultInvocationListener(env: Readonly<Record<string, string | undefined>>, print: (text: string) => void): ((invocation: VercelInvocation) => void) | undefined;