@cnc-tools/storm 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/build-info.js +1 -1
  2. package/dist/commands/exec/command.d.ts +26 -0
  3. package/dist/commands/exec/live-view.js +29 -13
  4. package/dist/commands/exec/metadata.d.ts +4 -1
  5. package/dist/commands/exec/outcomes.d.ts +50 -0
  6. package/dist/commands/exec/outcomes.js +9 -0
  7. package/dist/commands/exec/progress.d.ts +14 -2
  8. package/dist/commands/exec/progress.js +54 -9
  9. package/dist/commands/exec/run-command.d.ts +8 -2
  10. package/dist/commands/exec/run-command.js +41 -8
  11. package/dist/commands/exec/run-metadata.d.ts +5 -2
  12. package/dist/commands/exec/run-metadata.js +5 -2
  13. package/dist/commands/exec/run-record.d.ts +83 -4
  14. package/dist/commands/exec/run-record.js +49 -1
  15. package/dist/commands/exec/view.js +36 -4
  16. package/dist/commands/runs/facts.d.ts +25 -0
  17. package/dist/commands/runs/facts.js +36 -3
  18. package/dist/commands/runs/list/command.d.ts +25 -0
  19. package/dist/commands/runs/list/outcomes.d.ts +25 -0
  20. package/dist/commands/runs/show/command.d.ts +25 -0
  21. package/dist/commands/runs/show/metadata.js +1 -1
  22. package/dist/commands/runs/show/outcomes.d.ts +25 -0
  23. package/dist/commands/runs/show/outcomes.js +30 -1
  24. package/dist/commands/vitest/command.d.ts +26 -0
  25. package/dist/commands/vitest/metadata.d.ts +4 -1
  26. package/dist/commands/vitest/outcomes.d.ts +25 -0
  27. package/dist/core/events.d.ts +9 -7
  28. package/dist/core/run-state.d.ts +30 -6
  29. package/dist/core/run-state.js +19 -4
  30. package/dist/core/run.d.ts +17 -4
  31. package/dist/core/run.js +61 -25
  32. package/dist/runner/events.d.ts +64 -1
  33. package/dist/runner/gateways.d.ts +17 -6
  34. package/dist/runner/index.d.ts +5 -4
  35. package/dist/runner/index.js +4 -3
  36. package/dist/runner/live/snapshot-records.js +18 -4
  37. package/dist/runner/prepare.d.ts +23 -4
  38. package/dist/runner/prepare.js +13 -3
  39. package/dist/runner/ready.d.ts +7 -3
  40. package/dist/runner/ready.js +11 -5
  41. package/dist/runner/scope.d.ts +17 -1
  42. package/dist/runner/scope.js +4 -0
  43. package/dist/runner/snapshot-build.d.ts +3 -1
  44. package/dist/runner/snapshot-build.js +12 -2
  45. package/dist/runner/snapshot-cache.d.ts +46 -8
  46. package/dist/runner/snapshot-cache.js +60 -11
  47. package/dist/runner/snapshot-key.d.ts +12 -1
  48. package/dist/runner/snapshot-key.js +17 -1
  49. package/dist/runner/snapshot-save.d.ts +53 -0
  50. package/dist/runner/snapshot-save.js +148 -0
  51. package/dist/story/align.d.ts +1 -1
  52. package/dist/story/align.js +1 -1
  53. package/dist/story/definition.d.ts +22 -15
  54. package/dist/story/definition.js +2 -2
  55. package/dist/story/errors.js +1 -1
  56. package/dist/story/gateways.d.ts +45 -25
  57. package/dist/story/gateways.js +2 -2
  58. package/dist/story/host.d.ts +11 -8
  59. package/dist/story/host.js +37 -37
  60. package/dist/story/index.d.ts +1 -1
  61. package/dist/story/index.js +4 -4
  62. package/dist/story/json.d.ts +1 -1
  63. package/dist/story/json.js +2 -2
  64. package/dist/story/live/recording-gateway.d.ts +2 -0
  65. package/dist/story/live/{artifact-gateway.js → recording-gateway.js} +33 -12
  66. package/dist/story/mode.d.ts +2 -2
  67. package/dist/story/mode.js +1 -1
  68. package/dist/story/orphans.d.ts +23 -5
  69. package/dist/story/orphans.js +44 -8
  70. package/dist/story/recording.d.ts +62 -0
  71. package/dist/story/{artifact.js → recording.js} +31 -27
  72. package/dist/story/report.d.ts +21 -9
  73. package/dist/story/report.js +37 -25
  74. package/dist/story/settle.d.ts +23 -21
  75. package/dist/story/settle.js +17 -16
  76. package/dist/story/{run.d.ts → start.d.ts} +18 -17
  77. package/dist/story/{run.js → start.js} +66 -43
  78. package/package.json +1 -1
  79. package/dist/story/artifact.d.ts +0 -60
  80. package/dist/story/live/artifact-gateway.d.ts +0 -2
@@ -1,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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnc-tools/storm",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Run a command against Vercel Testserver sandboxes",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,60 +0,0 @@
1
- import { type StoryJson } from "./json.ts";
2
- /** The artifact format this version of story writes and reads. */
3
- export declare const STORY_ARTIFACT_SCHEMA_VERSION = 1;
4
- /** Which story an artifact belongs to: the story file's name (no directory) and the story's full test name. */
5
- export interface StoryIdentity {
6
- readonly file: string;
7
- readonly name: string;
8
- }
9
- /**
10
- * One tool call: the agent, the tool, the input the tool ran with (after its schema parsed it), and what its
11
- * `observe` returned. (agent, tool, input) is the call's key.
12
- */
13
- export interface StoryCall {
14
- readonly agent: string;
15
- readonly tool: string;
16
- readonly input: StoryJson;
17
- readonly observation: StoryJson;
18
- }
19
- /** One story's artifact. */
20
- export interface StoryArtifact {
21
- readonly schemaVersion: typeof STORY_ARTIFACT_SCHEMA_VERSION;
22
- readonly story: StoryIdentity;
23
- readonly calls: readonly StoryCall[];
24
- }
25
- /** An artifact's text, read back: the artifact, or why it can't be one. */
26
- export type ParsedStoryArtifact = {
27
- readonly ok: true;
28
- readonly artifact: StoryArtifact;
29
- } | {
30
- readonly ok: false;
31
- readonly problem: string;
32
- };
33
- /**
34
- * The directory that holds a story file's artifacts: `<story file dir>/__story__/<story file name>`
35
- * (`__story__/slot-surface.story.test.ts`). Each story file has a directory of its own, so the path alone says which
36
- * file owns an artifact, whatever the artifact holds.
37
- */
38
- export declare function artifactDirectory(storyFile: string): string;
39
- /**
40
- * Where a story's artifact lives: `<artifactDirectory>/<slug>-<id8>.json`. The slug is the story's name for people,
41
- * cut to 80 characters; `id8`, the first 8 hex characters of the SHA-256 of the canonical JSON of
42
- * `{ file, story }` (the file's name and the story's full name), keeps two stories whose names slug alike apart.
43
- */
44
- export declare function artifactPath(storyFile: string, story: string): string;
45
- /**
46
- * `text` lowercased, each run of characters other than ASCII letters and digits replaced by one `-`, with no `-` at
47
- * either end, cut to `max` characters; `story` when nothing is left.
48
- */
49
- export declare function slugify(text: string, max: number): string;
50
- /**
51
- * The artifact's text: its fields in a fixed order (`schemaVersion`, `story`, `calls`, and each call's `agent`,
52
- * `tool`, `input`, `observation`), each input and observation's keys sorted, indented by 2 spaces, with a trailing
53
- * newline. The same artifact always gives the same bytes.
54
- */
55
- export declare function serializeArtifact(artifact: StoryArtifact): string;
56
- /**
57
- * `text` as an artifact, or the problem: it isn't JSON, its `schemaVersion` isn't 1, or its fields don't have the
58
- * artifact's shape (unknown fields included).
59
- */
60
- export declare function parseArtifact(text: string): ParsedStoryArtifact;
@@ -1,2 +0,0 @@
1
- import type { StoryArtifactGateway } from "../gateways.ts";
2
- export declare const liveStoryArtifactGateway: StoryArtifactGateway;