@re-cinq/floor-studio 0.9.0 → 0.10.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 (122) hide show
  1. package/README.md +46 -4
  2. package/dist/backend/agent-run.d.ts +13 -0
  3. package/dist/backend/agent-run.js +32 -0
  4. package/dist/backend/collection-view.d.ts +2 -0
  5. package/dist/backend/collection-view.js +18 -8
  6. package/dist/backend/in-order.d.ts +1 -0
  7. package/dist/backend/in-order.js +10 -0
  8. package/dist/backend/last-tests.d.ts +10 -0
  9. package/dist/backend/last-tests.js +40 -0
  10. package/dist/backend/past-test-run-state.d.ts +2 -0
  11. package/dist/backend/past-test-run-state.js +19 -0
  12. package/dist/backend/past-test-runs.d.ts +2 -0
  13. package/dist/backend/past-test-runs.js +31 -0
  14. package/dist/backend/read-collection-view.d.ts +4 -0
  15. package/dist/backend/read-collection-view.js +19 -0
  16. package/dist/backend/read-test-line.d.ts +2 -0
  17. package/dist/backend/read-test-line.js +10 -0
  18. package/dist/backend/requests.d.ts +11 -1
  19. package/dist/backend/requests.js +4 -1
  20. package/dist/backend/run-cancel-request.d.ts +2 -1
  21. package/dist/backend/run-cancel-request.js +6 -3
  22. package/dist/backend/run-preview-request.d.ts +3 -2
  23. package/dist/backend/run-preview-request.js +6 -4
  24. package/dist/backend/run-start-request.js +2 -27
  25. package/dist/backend/start-studio.d.ts +4 -0
  26. package/dist/backend/start-studio.js +7 -13
  27. package/dist/backend/test-last-requests.d.ts +6 -0
  28. package/dist/backend/test-last-requests.js +6 -0
  29. package/dist/backend/test-list-requests.d.ts +9 -0
  30. package/dist/backend/test-list-requests.js +15 -0
  31. package/dist/backend/test-run-agent-visit.d.ts +13 -0
  32. package/dist/backend/test-run-agent-visit.js +73 -0
  33. package/dist/backend/test-run-folder.d.ts +5 -0
  34. package/dist/backend/test-run-folder.js +25 -0
  35. package/dist/backend/test-run-requests.d.ts +34 -0
  36. package/dist/backend/test-run-requests.js +112 -0
  37. package/dist/backend/test-run-session.d.ts +23 -0
  38. package/dist/backend/test-run-session.js +218 -0
  39. package/dist/backend/test-run-snapshot.d.ts +3 -0
  40. package/dist/backend/test-run-snapshot.js +25 -0
  41. package/dist/backend/test-run-supplied-files.d.ts +5 -0
  42. package/dist/backend/test-run-supplied-files.js +35 -0
  43. package/dist/backend/test-run-timeline.d.ts +6 -0
  44. package/dist/backend/test-run-timeline.js +13 -0
  45. package/dist/backend/test-run-visit-files.d.ts +8 -0
  46. package/dist/backend/test-run-visit-files.js +28 -0
  47. package/dist/cli.js +2 -2
  48. package/dist/folder-listing.d.ts +6 -0
  49. package/dist/folder-listing.js +2 -0
  50. package/dist/protocol.d.ts +179 -4
  51. package/dist/protocol.js +30 -4
  52. package/dist/run/result-line.d.ts +6 -0
  53. package/dist/run/result-line.js +18 -0
  54. package/dist/run/run-cost.d.ts +6 -0
  55. package/dist/run/run-cost.js +17 -0
  56. package/dist/run/run-outcome.d.ts +2 -0
  57. package/dist/run/run-outcome.js +4 -20
  58. package/dist/run/run-preview.d.ts +2 -0
  59. package/dist/run/run-preview.js +15 -6
  60. package/dist/run/run-process.d.ts +5 -3
  61. package/dist/run/run-process.js +13 -2
  62. package/dist/run/run-produces.d.ts +4 -0
  63. package/dist/run/run-produces.js +6 -1
  64. package/dist/run/run-records.d.ts +11 -0
  65. package/dist/run/run-result.js +15 -3
  66. package/dist/run/station-fixtures.d.ts +2 -1
  67. package/dist/run/station-fixtures.js +11 -0
  68. package/dist/shell/open-browser.d.ts +3 -3
  69. package/dist/shell/open-browser.js +7 -7
  70. package/dist/test-run/agent-report.d.ts +3 -0
  71. package/dist/test-run/agent-report.js +21 -0
  72. package/dist/test-run/brief.d.ts +6 -0
  73. package/dist/test-run/brief.js +25 -0
  74. package/dist/test-run/entered-value.d.ts +1 -0
  75. package/dist/test-run/entered-value.js +6 -0
  76. package/dist/test-run/event-answer.d.ts +13 -0
  77. package/dist/test-run/event-answer.js +13 -0
  78. package/dist/test-run/folder-names.d.ts +2 -0
  79. package/dist/test-run/folder-names.js +18 -0
  80. package/dist/test-run/next-transition.d.ts +3 -0
  81. package/dist/test-run/next-transition.js +10 -0
  82. package/dist/test-run/outcome-fields.d.ts +10 -0
  83. package/dist/test-run/outcome-fields.js +40 -0
  84. package/dist/test-run/past-listing.d.ts +3 -0
  85. package/dist/test-run/past-listing.js +5 -0
  86. package/dist/test-run/past-state.d.ts +5 -0
  87. package/dist/test-run/past-state.js +26 -0
  88. package/dist/test-run/run-bag.d.ts +5 -0
  89. package/dist/test-run/run-bag.js +12 -0
  90. package/dist/test-run/run-summary.d.ts +13 -0
  91. package/dist/test-run/run-summary.js +23 -0
  92. package/dist/test-run/stand-in-actions.d.ts +17 -0
  93. package/dist/test-run/stand-in-actions.js +26 -0
  94. package/dist/test-run/stand-in-report.d.ts +13 -0
  95. package/dist/test-run/stand-in-report.js +34 -0
  96. package/dist/test-run/start-blockers.d.ts +3 -0
  97. package/dist/test-run/start-blockers.js +21 -0
  98. package/dist/test-run/start-items.d.ts +12 -0
  99. package/dist/test-run/start-items.js +18 -0
  100. package/dist/test-run/test-line.d.ts +16 -0
  101. package/dist/test-run/test-line.js +24 -0
  102. package/dist/test-run/test-preview.d.ts +11 -0
  103. package/dist/test-run/test-preview.js +7 -0
  104. package/dist/test-run/test-run-state.d.ts +30 -0
  105. package/dist/test-run/test-run-state.js +2 -0
  106. package/dist/test-run/test-visit.d.ts +24 -0
  107. package/dist/test-run/test-visit.js +2 -0
  108. package/dist/test-run/timeline.d.ts +32 -0
  109. package/dist/test-run/timeline.js +4 -0
  110. package/dist/test-run/totals.d.ts +20 -0
  111. package/dist/test-run/totals.js +26 -0
  112. package/dist/test-run/visit-kind.d.ts +3 -0
  113. package/dist/test-run/visit-kind.js +10 -0
  114. package/dist/test-run/visit-record.d.ts +22 -0
  115. package/dist/test-run/visit-record.js +27 -0
  116. package/dist/view.d.ts +2 -0
  117. package/dist/web/assets/index-C5eUTmhR.css +1 -0
  118. package/dist/web/assets/index-mRcd501r.js +195 -0
  119. package/dist/web/index.html +2 -2
  120. package/package.json +5 -5
  121. package/dist/web/assets/index-ChU2BH_M.js +0 -195
  122. package/dist/web/assets/index-ChyDvQtL.css +0 -1
@@ -0,0 +1,28 @@
1
+ // The files of one visit in a local test run's folder: visits/<id>/visit.json, inputs.json, prompt.md and transcript.jsonl.
2
+ import { mkdir, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { jsonFileText } from "./test-run-folder.js";
5
+ export function visitFolderOf(runFolder, visitId) {
6
+ return join(runFolder, "visits", visitId);
7
+ }
8
+ export function outputsFolderOf(runFolder, visitId) {
9
+ return join(visitFolderOf(runFolder, visitId), "outputs");
10
+ }
11
+ export function writeVisitRecord(runFolder, record) {
12
+ return writeVisitFile(runFolder, record.id, "visit.json", jsonFileText(record));
13
+ }
14
+ export function writeVisitInputs(runFolder, visitId, needs) {
15
+ return writeVisitFile(runFolder, visitId, "inputs.json", jsonFileText(needs));
16
+ }
17
+ export function writeVisitPrompt(runFolder, visitId, prompt) {
18
+ return writeVisitFile(runFolder, visitId, "prompt.md", prompt);
19
+ }
20
+ export function writeVisitTranscript(runFolder, visitId, lines) {
21
+ return writeVisitFile(runFolder, visitId, "transcript.jsonl", lines.map(({ text }) => `${text}\n`).join(""));
22
+ }
23
+ async function writeVisitFile(runFolder, visitId, fileName, content) {
24
+ const visitFolder = visitFolderOf(runFolder, visitId);
25
+ await mkdir(visitFolder, { recursive: true });
26
+ await writeFile(join(visitFolder, fileName), content);
27
+ }
28
+ //# sourceMappingURL=test-run-visit-files.js.map
package/dist/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  // floor-studio: opens a page that draws a collection of assembly lines, over a backend that reads the folder.
3
3
  import { fileURLToPath } from "node:url";
4
- import { openBrowser } from "./shell/open-browser.js";
4
+ import { openOnDesktop } from "./shell/open-browser.js";
5
5
  import { studioCommand } from "./shell/studio-command.js";
6
6
  const PAGE_WAIT_MS = 3000;
7
7
  const PAGE_DIR = fileURLToPath(new URL("./web", import.meta.url));
8
- const outcome = await studioCommand(process.argv.slice(2), { out: console.log, err: console.error, pageDir: PAGE_DIR, openBrowser, pageWaitMs: PAGE_WAIT_MS });
8
+ const outcome = await studioCommand(process.argv.slice(2), { out: console.log, err: console.error, pageDir: PAGE_DIR, openBrowser: openOnDesktop, pageWaitMs: PAGE_WAIT_MS });
9
9
  if ("exitCode" in outcome)
10
10
  process.exit(outcome.exitCode);
11
11
  const { running } = outcome;
@@ -0,0 +1,6 @@
1
+ export interface FolderListing {
2
+ path: string;
3
+ parent: string | null;
4
+ folders: string[];
5
+ files: string[];
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=folder-listing.js.map
@@ -1,7 +1,11 @@
1
1
  import { z } from "zod";
2
2
  import type { RunLine } from "./run/run-process.js";
3
+ import type { RunEnding } from "./run/run-records.js";
3
4
  import type { RunPreview } from "./run/run-preview.js";
4
5
  import type { CollectionView } from "./view.js";
6
+ import type { FolderListing } from "./folder-listing.js";
7
+ import type { TestPreview } from "./test-run/test-preview.js";
8
+ import type { TestRunListing, TestRunState } from "./test-run/test-run-state.js";
5
9
  export type { AgentUse, AgentView, CollectionView, LineView, NodeAgent, NodeNeed, NodeView, RefusedFile, ViewProblem } from "./view.js";
6
10
  /** Sent in the first frame of a socket, so a client built for another protocol can say so. */
7
11
  export declare const PROTOCOL_VERSION = 1;
@@ -74,6 +78,72 @@ export declare const runReadRequest: z.ZodObject<{
74
78
  run: z.ZodString;
75
79
  after: z.ZodNumber;
76
80
  }, z.core.$strict>;
81
+ export declare const testStartRequest: z.ZodObject<{
82
+ id: z.ZodString;
83
+ type: z.ZodLiteral<"test.start">;
84
+ line: z.ZodString;
85
+ workspace: z.ZodString;
86
+ entered: z.ZodRecord<z.ZodString, z.ZodString>;
87
+ permission: z.ZodEnum<{
88
+ acceptEdits: "acceptEdits";
89
+ bypass: "bypass";
90
+ }>;
91
+ }, z.core.$strict>;
92
+ export declare const testReportRequest: z.ZodObject<{
93
+ id: z.ZodString;
94
+ type: z.ZodLiteral<"test.report">;
95
+ run: z.ZodString;
96
+ visit: z.ZodString;
97
+ outcome: z.ZodString;
98
+ produced: z.ZodRecord<z.ZodString, z.ZodString>;
99
+ files: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
100
+ picked: z.ZodString;
101
+ }, z.core.$strict>, z.ZodObject<{
102
+ pasted: z.ZodString;
103
+ }, z.core.$strict>]>>>;
104
+ }, z.core.$strict>;
105
+ export declare const testCancelRequest: z.ZodObject<{
106
+ id: z.ZodString;
107
+ type: z.ZodLiteral<"test.cancel">;
108
+ run: z.ZodString;
109
+ }, z.core.$strict>;
110
+ export declare const testReadRequest: z.ZodObject<{
111
+ id: z.ZodString;
112
+ type: z.ZodLiteral<"test.read">;
113
+ run: z.ZodString;
114
+ }, z.core.$strict>;
115
+ export declare const testPreviewRequest: z.ZodObject<{
116
+ id: z.ZodString;
117
+ type: z.ZodLiteral<"test.preview">;
118
+ line: z.ZodString;
119
+ entered: z.ZodRecord<z.ZodString, z.ZodString>;
120
+ }, z.core.$strict>;
121
+ export declare const testLastRequest: z.ZodObject<{
122
+ id: z.ZodString;
123
+ type: z.ZodLiteral<"test.last">;
124
+ line: z.ZodString;
125
+ }, z.core.$strict>;
126
+ export declare const testListRequest: z.ZodObject<{
127
+ id: z.ZodString;
128
+ type: z.ZodLiteral<"test.list">;
129
+ }, z.core.$strict>;
130
+ export declare const folderOpenRequest: z.ZodObject<{
131
+ id: z.ZodString;
132
+ type: z.ZodLiteral<"folder.open">;
133
+ path: z.ZodString;
134
+ }, z.core.$strict>;
135
+ export declare const folderListRequest: z.ZodObject<{
136
+ id: z.ZodString;
137
+ type: z.ZodLiteral<"folder.list">;
138
+ path: z.ZodOptional<z.ZodString>;
139
+ }, z.core.$strict>;
140
+ export declare const testEventRequest: z.ZodObject<{
141
+ id: z.ZodString;
142
+ type: z.ZodLiteral<"test.event">;
143
+ run: z.ZodString;
144
+ event: z.ZodString;
145
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
146
+ }, z.core.$strict>;
77
147
  /** A new request type is one schema here and one handler in the backend's table. */
78
148
  export declare const requestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
79
149
  id: z.ZodString;
@@ -135,6 +205,62 @@ export declare const requestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
135
205
  type: z.ZodLiteral<"run.read">;
136
206
  run: z.ZodString;
137
207
  after: z.ZodNumber;
208
+ }, z.core.$strict>, z.ZodObject<{
209
+ id: z.ZodString;
210
+ type: z.ZodLiteral<"test.start">;
211
+ line: z.ZodString;
212
+ workspace: z.ZodString;
213
+ entered: z.ZodRecord<z.ZodString, z.ZodString>;
214
+ permission: z.ZodEnum<{
215
+ acceptEdits: "acceptEdits";
216
+ bypass: "bypass";
217
+ }>;
218
+ }, z.core.$strict>, z.ZodObject<{
219
+ id: z.ZodString;
220
+ type: z.ZodLiteral<"test.report">;
221
+ run: z.ZodString;
222
+ visit: z.ZodString;
223
+ outcome: z.ZodString;
224
+ produced: z.ZodRecord<z.ZodString, z.ZodString>;
225
+ files: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
226
+ picked: z.ZodString;
227
+ }, z.core.$strict>, z.ZodObject<{
228
+ pasted: z.ZodString;
229
+ }, z.core.$strict>]>>>;
230
+ }, z.core.$strict>, z.ZodObject<{
231
+ id: z.ZodString;
232
+ type: z.ZodLiteral<"test.cancel">;
233
+ run: z.ZodString;
234
+ }, z.core.$strict>, z.ZodObject<{
235
+ id: z.ZodString;
236
+ type: z.ZodLiteral<"test.read">;
237
+ run: z.ZodString;
238
+ }, z.core.$strict>, z.ZodObject<{
239
+ id: z.ZodString;
240
+ type: z.ZodLiteral<"test.preview">;
241
+ line: z.ZodString;
242
+ entered: z.ZodRecord<z.ZodString, z.ZodString>;
243
+ }, z.core.$strict>, z.ZodObject<{
244
+ id: z.ZodString;
245
+ type: z.ZodLiteral<"folder.open">;
246
+ path: z.ZodString;
247
+ }, z.core.$strict>, z.ZodObject<{
248
+ id: z.ZodString;
249
+ type: z.ZodLiteral<"folder.list">;
250
+ path: z.ZodOptional<z.ZodString>;
251
+ }, z.core.$strict>, z.ZodObject<{
252
+ id: z.ZodString;
253
+ type: z.ZodLiteral<"test.event">;
254
+ run: z.ZodString;
255
+ event: z.ZodString;
256
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
257
+ }, z.core.$strict>, z.ZodObject<{
258
+ id: z.ZodString;
259
+ type: z.ZodLiteral<"test.last">;
260
+ line: z.ZodString;
261
+ }, z.core.$strict>, z.ZodObject<{
262
+ id: z.ZodString;
263
+ type: z.ZodLiteral<"test.list">;
138
264
  }, z.core.$strict>], "type">;
139
265
  export type Request = z.infer<typeof requestSchema>;
140
266
  export type RequestKind = Request["type"];
@@ -168,10 +294,42 @@ export type ResultOf<Asked extends Request> = Asked extends {
168
294
  type: "run.read";
169
295
  } ? {
170
296
  lines: RunLine[];
171
- ended?: {
172
- exitCode: number | null;
173
- };
174
- } : never;
297
+ ended?: RunEnding;
298
+ } : Asked extends {
299
+ type: "test.start";
300
+ } ? {
301
+ run: string;
302
+ folder: string;
303
+ } : Asked extends {
304
+ type: "test.report";
305
+ } ? {
306
+ reported: string;
307
+ } : Asked extends {
308
+ type: "test.cancel";
309
+ } ? {
310
+ cancelled: string;
311
+ } : Asked extends {
312
+ type: "test.read";
313
+ } ? TestRunState : Asked extends {
314
+ type: "test.preview";
315
+ } ? TestPreview : Asked extends {
316
+ type: "folder.open";
317
+ } ? {
318
+ opened: string;
319
+ } : Asked extends {
320
+ type: "folder.list";
321
+ } ? FolderListing : Asked extends {
322
+ type: "test.event";
323
+ } ? {
324
+ answered: string[];
325
+ } : Asked extends {
326
+ type: "test.last";
327
+ } ? {
328
+ workspace: string;
329
+ entered: Record<string, string>;
330
+ } | null : Asked extends {
331
+ type: "test.list";
332
+ } ? TestRunListing[] : never;
175
333
  export declare const collectionViewSchema: z.ZodType<CollectionView>;
176
334
  export declare const helloFrame: z.ZodObject<{
177
335
  type: z.ZodLiteral<"hello">;
@@ -206,7 +364,11 @@ export declare const runEndedFrame: z.ZodObject<{
206
364
  type: z.ZodLiteral<"run.ended">;
207
365
  run: z.ZodString;
208
366
  exitCode: z.ZodNullable<z.ZodNumber>;
367
+ error: z.ZodOptional<z.ZodString>;
209
368
  outcome: z.ZodOptional<z.ZodString>;
369
+ costUsd: z.ZodOptional<z.ZodNumber>;
370
+ durationMs: z.ZodOptional<z.ZodNumber>;
371
+ producedValues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
210
372
  produced: z.ZodOptional<z.ZodArray<z.ZodObject<{
211
373
  name: z.ZodString;
212
374
  found: z.ZodBoolean;
@@ -219,6 +381,11 @@ export declare const runEndedFrame: z.ZodObject<{
219
381
  unattendedMax: z.ZodOptional<z.ZodNumber>;
220
382
  }, z.core.$strict>>;
221
383
  }, z.core.$strict>;
384
+ export declare const testChangedFrame: z.ZodObject<{
385
+ type: z.ZodLiteral<"test.changed">;
386
+ run: z.ZodString;
387
+ state: z.ZodType<TestRunState, unknown, z.core.$ZodTypeInternals<TestRunState, unknown>>;
388
+ }, z.core.$strict>;
222
389
  export declare const serverFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
223
390
  type: z.ZodLiteral<"hello">;
224
391
  version: z.ZodNumber;
@@ -247,7 +414,11 @@ export declare const serverFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
247
414
  type: z.ZodLiteral<"run.ended">;
248
415
  run: z.ZodString;
249
416
  exitCode: z.ZodNullable<z.ZodNumber>;
417
+ error: z.ZodOptional<z.ZodString>;
250
418
  outcome: z.ZodOptional<z.ZodString>;
419
+ costUsd: z.ZodOptional<z.ZodNumber>;
420
+ durationMs: z.ZodOptional<z.ZodNumber>;
421
+ producedValues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
251
422
  produced: z.ZodOptional<z.ZodArray<z.ZodObject<{
252
423
  name: z.ZodString;
253
424
  found: z.ZodBoolean;
@@ -259,5 +430,9 @@ export declare const serverFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
259
430
  iterationMax: z.ZodOptional<z.ZodNumber>;
260
431
  unattendedMax: z.ZodOptional<z.ZodNumber>;
261
432
  }, z.core.$strict>>;
433
+ }, z.core.$strict>, z.ZodObject<{
434
+ type: z.ZodLiteral<"test.changed">;
435
+ run: z.ZodString;
436
+ state: z.ZodType<TestRunState, unknown, z.core.$ZodTypeInternals<TestRunState, unknown>>;
262
437
  }, z.core.$strict>], "type">;
263
438
  export type ServerFrame = z.infer<typeof serverFrameSchema>;
package/dist/protocol.js CHANGED
@@ -3,17 +3,28 @@ import { z } from "zod";
3
3
  /** Sent in the first frame of a socket, so a client built for another protocol can say so. */
4
4
  export const PROTOCOL_VERSION = 1;
5
5
  const requestId = z.string().min(1).describe("Chosen by the client; the answer carries it.");
6
+ const permissionSchema = z.enum(["acceptEdits", "bypass"]);
6
7
  export const collectionReadRequest = z.strictObject({ id: requestId, type: z.literal("collection.read") });
7
8
  export const agentWriteRequest = z.strictObject({ id: requestId, type: z.literal("agent.write"), line: z.string(), agent: z.string(), prompt: z.string(), settings: z.record(z.string(), z.unknown()).optional(), version: z.string() });
8
9
  export const extraWriteRequest = z.strictObject({ id: requestId, type: z.literal("extra.write"), line: z.string(), agent: z.string(), text: z.string(), version: z.string() });
9
10
  export const fixtureWriteRequest = z.strictObject({ id: requestId, type: z.literal("fixture.write"), line: z.string(), node: z.string(), needs: z.record(z.string(), z.string()) });
10
11
  export const fixtureReadRequest = z.strictObject({ id: requestId, type: z.literal("fixture.read"), line: z.string(), node: z.string() });
11
- export const runPreviewRequest = z.strictObject({ id: requestId, type: z.literal("run.preview"), line: z.string(), node: z.string(), fixture: z.record(z.string(), z.string()), folder: z.string(), permission: z.enum(["acceptEdits", "bypass"]) });
12
- export const runStartRequest = z.strictObject({ id: requestId, type: z.literal("run.start"), line: z.string(), node: z.string(), fixture: z.record(z.string(), z.string()), folder: z.string(), permission: z.enum(["acceptEdits", "bypass"]) });
12
+ export const runPreviewRequest = z.strictObject({ id: requestId, type: z.literal("run.preview"), line: z.string(), node: z.string(), fixture: z.record(z.string(), z.string()), folder: z.string(), permission: permissionSchema });
13
+ export const runStartRequest = z.strictObject({ id: requestId, type: z.literal("run.start"), line: z.string(), node: z.string(), fixture: z.record(z.string(), z.string()), folder: z.string(), permission: permissionSchema });
13
14
  export const runCancelRequest = z.strictObject({ id: requestId, type: z.literal("run.cancel"), run: z.string() });
14
15
  export const runReadRequest = z.strictObject({ id: requestId, type: z.literal("run.read"), run: z.string(), after: z.number().int().min(0) });
16
+ export const testStartRequest = z.strictObject({ id: requestId, type: z.literal("test.start"), line: z.string(), workspace: z.string(), entered: z.record(z.string(), z.string()), permission: permissionSchema });
17
+ export const testReportRequest = z.strictObject({ id: requestId, type: z.literal("test.report"), run: z.string(), visit: z.string(), outcome: z.string(), produced: z.record(z.string(), z.string()), files: z.record(z.string(), z.union([z.strictObject({ picked: z.string() }), z.strictObject({ pasted: z.string() })])).optional() });
18
+ export const testCancelRequest = z.strictObject({ id: requestId, type: z.literal("test.cancel"), run: z.string() });
19
+ export const testReadRequest = z.strictObject({ id: requestId, type: z.literal("test.read"), run: z.string() });
20
+ export const testPreviewRequest = z.strictObject({ id: requestId, type: z.literal("test.preview"), line: z.string(), entered: z.record(z.string(), z.string()) });
21
+ export const testLastRequest = z.strictObject({ id: requestId, type: z.literal("test.last"), line: z.string() });
22
+ export const testListRequest = z.strictObject({ id: requestId, type: z.literal("test.list") });
23
+ export const folderOpenRequest = z.strictObject({ id: requestId, type: z.literal("folder.open"), path: z.string() });
24
+ export const folderListRequest = z.strictObject({ id: requestId, type: z.literal("folder.list"), path: z.string().optional() });
25
+ export const testEventRequest = z.strictObject({ id: requestId, type: z.literal("test.event"), run: z.string(), event: z.string(), payload: z.record(z.string(), z.unknown()) });
15
26
  /** A new request type is one schema here and one handler in the backend's table. */
16
- export const requestSchema = z.discriminatedUnion("type", [collectionReadRequest, agentWriteRequest, extraWriteRequest, fixtureWriteRequest, fixtureReadRequest, runPreviewRequest, runStartRequest, runCancelRequest, runReadRequest]);
27
+ export const requestSchema = z.discriminatedUnion("type", [collectionReadRequest, agentWriteRequest, extraWriteRequest, fixtureWriteRequest, fixtureReadRequest, runPreviewRequest, runStartRequest, runCancelRequest, runReadRequest, testStartRequest, testReportRequest, testCancelRequest, testReadRequest, testPreviewRequest, folderOpenRequest, folderListRequest, testEventRequest, testLastRequest, testListRequest]);
17
28
  export const REQUEST_TYPES = requestSchema.options.map(({ shape }) => shape.type.value);
18
29
  // Strict down to a node's agent; events, placeholders, needs, produces, edges, args, start and kind come from other packages and are only checked to be objects where required.
19
30
  const presentObject = () => z.custom((value) => typeof value === "object" && value !== null);
@@ -28,6 +39,7 @@ const nodeViewSchema = z.looseObject({
28
39
  needs: z.array(presentObject()),
29
40
  produces: z.array(presentObject()),
30
41
  agentDefinition: z.string().optional(),
42
+ resultRequired: z.boolean().optional(),
31
43
  events: presentObject(),
32
44
  agent: nodeAgentSchema.optional(),
33
45
  placeholders: z.custom().optional(),
@@ -71,9 +83,23 @@ export const collectionFrame = z.strictObject({ type: z.literal("collection"), c
71
83
  export const runOutputFrame = z.strictObject({ type: z.literal("run.output"), run: z.string(), line: z.strictObject({ stream: z.enum(["stdout", "stderr"]), text: z.string() }) });
72
84
  export const runEndedFrame = z.strictObject({ type: z.literal("run.ended"), run: z.string(),
73
85
  exitCode: z.number().nullable(),
86
+ error: z.string().optional(),
74
87
  outcome: z.string().optional(),
88
+ costUsd: z.number().optional(),
89
+ durationMs: z.number().optional(),
90
+ producedValues: z.record(z.string(), z.string()).optional(),
75
91
  produced: z.array(z.strictObject({ name: z.string(), found: z.boolean() })).optional(),
76
92
  edge: z.strictObject({ from: z.string(), to: z.string(), on: z.string(), iterationMax: z.number().optional(), unattendedMax: z.number().optional() }).optional(),
77
93
  });
78
- export const serverFrameSchema = z.discriminatedUnion("type", [helloFrame, resultFrame, refusedFrame, collectionFrame, runOutputFrame, runEndedFrame]);
94
+ const testRunStateSchema = z.strictObject({
95
+ folder: z.string(),
96
+ lineId: z.string(),
97
+ status: z.enum(["running", "waiting", "settled"]),
98
+ ending: z.strictObject({ outcome: z.enum(["finished", "iteration_max", "error", "failed", "cancelled"]), reason: z.string().optional() }).optional(),
99
+ visits: z.array(presentObject()),
100
+ actions: z.record(z.string(), z.array(presentObject())),
101
+ bag: z.optional(z.array(z.strictObject({ name: z.string(), kind: z.enum(["value", "file", "git"]), ref: z.string(), by: z.string() }))),
102
+ });
103
+ export const testChangedFrame = z.strictObject({ type: z.literal("test.changed"), run: z.string(), state: testRunStateSchema });
104
+ export const serverFrameSchema = z.discriminatedUnion("type", [helloFrame, resultFrame, refusedFrame, collectionFrame, runOutputFrame, runEndedFrame, testChangedFrame]);
79
105
  //# sourceMappingURL=protocol.js.map
@@ -0,0 +1,6 @@
1
+ import type { RunLine } from "./run-process.js";
2
+ export interface ResultLine {
3
+ result?: string;
4
+ [field: string]: unknown;
5
+ }
6
+ export declare function lastResultLine(lines: RunLine[]): ResultLine | undefined;
@@ -0,0 +1,18 @@
1
+ export function lastResultLine(lines) {
2
+ return lines
3
+ .filter(({ stream }) => stream === "stdout")
4
+ .map(({ text }) => parseJsonLine(text))
5
+ .filter((parsed) => parsed?.type === "result")
6
+ .at(-1);
7
+ }
8
+ function parseJsonLine(text) {
9
+ if (!text.startsWith("{"))
10
+ return undefined;
11
+ try {
12
+ return JSON.parse(text);
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ }
18
+ //# sourceMappingURL=result-line.js.map
@@ -0,0 +1,6 @@
1
+ import type { RunLine } from "./run-process.js";
2
+ export interface RunCost {
3
+ costUsd?: number;
4
+ durationMs?: number;
5
+ }
6
+ export declare function runCost(lines: RunLine[]): RunCost;
@@ -0,0 +1,17 @@
1
+ // Reads what an agent run cost and how long it took from the final "result" line of its stream-json transcript.
2
+ import { lastResultLine } from "./result-line.js";
3
+ export function runCost(lines) {
4
+ const stated = lastResultLine(lines);
5
+ const costUsd = statedAmount(stated?.total_cost_usd);
6
+ const durationMs = statedAmount(stated?.duration_ms);
7
+ const cost = {};
8
+ if (costUsd !== undefined)
9
+ cost.costUsd = costUsd;
10
+ if (durationMs !== undefined)
11
+ cost.durationMs = durationMs;
12
+ return cost;
13
+ }
14
+ function statedAmount(value) {
15
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
16
+ }
17
+ //# sourceMappingURL=run-cost.js.map
@@ -8,5 +8,7 @@ interface RunOutcomeInput {
8
8
  export declare function runOutcome({ lines, station }: RunOutcomeInput): {
9
9
  outcome: string;
10
10
  answer?: string;
11
+ error?: string;
12
+ produced: Record<string, string>;
11
13
  };
12
14
  export {};
@@ -1,26 +1,10 @@
1
- // Reads how an agent run ended from the final "result" line of its stream-json transcript.
1
+ // Reads how an agent run ended, its final answer and the values it stated, from the final "result" line of its stream-json transcript.
2
2
  import { readAgentVerdict, requiredVerdict } from "@re-cinq/floor-assembly-lines";
3
+ import { lastResultLine } from "./result-line.js";
3
4
  /** The outcome the agent reported, and its final answer. */
4
5
  export function runOutcome({ lines, station }) {
5
- const answer = finalAgentText(lines);
6
+ const answer = lastResultLine(lines)?.result;
6
7
  const verdict = requiredVerdict(readAgentVerdict(answer, station.outcomes), station);
7
- return { outcome: verdict.outcome, answer };
8
- }
9
- function finalAgentText(lines) {
10
- const results = lines
11
- .filter(({ stream }) => stream === "stdout")
12
- .map(({ text }) => parseJsonLine(text))
13
- .filter((parsed) => parsed?.type === "result");
14
- return results.at(-1)?.result;
15
- }
16
- function parseJsonLine(text) {
17
- if (!text.startsWith("{"))
18
- return undefined;
19
- try {
20
- return JSON.parse(text);
21
- }
22
- catch {
23
- return undefined;
24
- }
8
+ return { outcome: verdict.outcome, answer, produced: verdict.produced, ...(verdict.error && { error: verdict.error }) };
25
9
  }
26
10
  //# sourceMappingURL=run-outcome.js.map
@@ -27,3 +27,5 @@ export interface RunPreview {
27
27
  env: Record<string, string>;
28
28
  }
29
29
  export declare function runPreview({ station, prompt, settings, fixture, folder, permission }: RunPreviewInput): RunPreview;
30
+ export declare function blockerReasonOf({ blockers }: RunPreview): string;
31
+ export declare function leavesFolder(folder: string, path: string): boolean;
@@ -1,24 +1,33 @@
1
1
  // What a run of one agent station would do, before it is started.
2
- import { isAbsolute } from "node:path";
2
+ import { isAbsolute, join, relative, sep } from "node:path";
3
3
  import { agentCommand, runnableVendors } from "./agent-command.js";
4
4
  import { renderPrompt } from "./render-prompt.js";
5
5
  import { vendorOf } from "./vendor.js";
6
6
  import { workspaceOf } from "./workspace.js";
7
+ /** The pod's `/workspace` in the prompt's own text, pointed at the picked folder as written, as the parameters already are. */
8
+ const POD_WORKSPACE = /\/workspace(?![\w-])/;
7
9
  export function runPreview({ station, prompt, settings, fixture, folder, permission }) {
8
10
  const { parameters, copies, links, missing } = workspaceOf({ station, fixture, folder });
9
- const rendered = inFolder(renderPrompt(prompt, parameters), folder);
11
+ const rendered = prompt.split(POD_WORKSPACE).map((piece) => renderPrompt(piece, parameters)).join(folder);
10
12
  const vendor = vendorOf(settings.model ?? "");
11
13
  const unrunnable = runnableVendors.includes(vendor) ? [] : [unrunnableBlocker(settings.model ?? "", vendor)];
12
14
  const command = unrunnable.length ? [] : agentCommand({ vendor, settings: commandSettingsOf(settings), prompt: rendered, permission });
13
- return { prompt: rendered, command, copies, links, env: agentEnvOf(settings), blockers: [...missing.map((name) => `"${name}" has no value`), ...unrunnable, ...relativeFolderBlockers(folder)] };
15
+ return { prompt: rendered, command, copies, links, env: agentEnvOf(settings), blockers: [...missing.map((name) => `"${name}" has no value`), ...outsideFolderBlockers(station, folder), ...unrunnable, ...relativeFolderBlockers(folder)] };
14
16
  }
15
- /** The pod's `/workspace` in the prompt's own text, pointed at the picked folder, as the parameters already are. */
16
- function inFolder(text, folder) {
17
- return text.replace(/\/workspace(?![\w-])/g, folder);
17
+ export function blockerReasonOf({ blockers }) {
18
+ return blockers.join("; ");
18
19
  }
19
20
  function agentEnvOf({ config }) {
20
21
  return config?.env ?? {};
21
22
  }
23
+ function outsideFolderBlockers({ needs, produces }, folder) {
24
+ const outside = [...needs, ...produces].filter((place) => place.path !== undefined && leavesFolder(folder, place.path));
25
+ return outside.map((place) => `"${place.name}": ${place.path} leaves the run folder`);
26
+ }
27
+ export function leavesFolder(folder, path) {
28
+ const placed = relative(folder, join(folder, path));
29
+ return placed === ".." || placed.startsWith(`..${sep}`) || isAbsolute(placed);
30
+ }
22
31
  function relativeFolderBlockers(folder) {
23
32
  return isAbsolute(folder) ? [] : [`the folder must be an absolute path: ${folder}`];
24
33
  }
@@ -7,10 +7,12 @@ export interface RunLine {
7
7
  stream: "stdout" | "stderr";
8
8
  text: string;
9
9
  }
10
+ export interface ProcessEnding {
11
+ exitCode: number | null;
12
+ error?: string;
13
+ }
10
14
  export interface RunningProcess {
11
- done: Promise<{
12
- exitCode: number | null;
13
- }>;
15
+ done: Promise<ProcessEnding>;
14
16
  cancel(): void;
15
17
  }
16
18
  export declare function runProcess(request: RunProcessRequest, onLine: (line: RunLine) => void): RunningProcess;
@@ -1,4 +1,4 @@
1
- // Spawns an agent CLI in a folder, streaming its stdout and stderr line by line, with cancel.
1
+ // Spawns an agent CLI in a folder, streaming its stdout and stderr line by line, with cancel; ends with its exit code or why it could not start.
2
2
  import { spawn } from "node:child_process";
3
3
  import { createInterface } from "node:readline";
4
4
  export function runProcess(request, onLine) {
@@ -12,14 +12,25 @@ export function runProcess(request, onLine) {
12
12
  readLines(child.stdout, "stdout", onLine);
13
13
  readLines(child.stderr, "stderr", onLine);
14
14
  const done = new Promise((resolve) => {
15
+ child.on("error", (cause) => resolve({ exitCode: null, error: `could not start ${program}: ${cause.message}` }));
15
16
  child.on("close", (exitCode) => resolve({ exitCode }));
16
17
  });
17
18
  const cancel = () => {
18
19
  if (child.pid !== undefined)
19
- process.kill(-child.pid, "SIGTERM");
20
+ terminateGroup(child.pid);
20
21
  };
21
22
  return { done, cancel };
22
23
  }
24
+ function terminateGroup(pid) {
25
+ try {
26
+ process.kill(-pid, "SIGTERM");
27
+ }
28
+ catch (error) {
29
+ const hasExited = error instanceof Error && "code" in error && error.code === "ESRCH";
30
+ if (!hasExited)
31
+ throw error;
32
+ }
33
+ }
23
34
  function readLines(input, stream, onLine) {
24
35
  createInterface({ input }).on("line", (text) => onLine({ stream, text }));
25
36
  }
@@ -9,4 +9,8 @@ export declare function producesFound({ station, folder, answer }: ProducesFound
9
9
  name: string;
10
10
  found: boolean;
11
11
  }[]>;
12
+ export declare function valuesStated({ station, stated }: {
13
+ station: StationBody;
14
+ stated: Record<string, string>;
15
+ }): Record<string, string>;
12
16
  export {};
@@ -1,10 +1,15 @@
1
- // Checks which declared produces of a station a run left: a file produce in the run folder, a produce from output in the agent's final answer.
1
+ // Checks which declared produces of a station a run left (a file in the run folder, or from output in the agent's final answer) and which declared values the agent stated.
2
2
  import { access } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  export function producesFound({ station, folder, answer }) {
5
5
  const checked = station.produces.filter((produce) => produce.kind === "file" && (produce.path || produce.from === "output"));
6
6
  return Promise.all(checked.map(async (produce) => ({ name: produce.name, found: await isFound(produce, folder, answer) })));
7
7
  }
8
+ export function valuesStated({ station, stated }) {
9
+ const values = station.produces.filter((produce) => produce.kind === "value");
10
+ const declared = new Set(values.map((produce) => produce.name));
11
+ return Object.fromEntries(Object.entries(stated).filter(([name]) => declared.has(name)));
12
+ }
8
13
  function isFound(produce, folder, answer) {
9
14
  if (produce.from === "output")
10
15
  return Promise.resolve(Boolean(answer?.trim()));
@@ -2,12 +2,23 @@ import type { LineEdge } from "@re-cinq/floor-contracts";
2
2
  import type { RunLine, RunningProcess } from "./run-process.js";
3
3
  export interface RunEnding {
4
4
  exitCode: number | null;
5
+ /** Why the floor failed the run. */
6
+ error?: string;
7
+ /** The outcome the floor would take from the visit. */
5
8
  outcome?: string;
9
+ /** The values the agent stated for the station's declared value produces. */
10
+ producedValues?: Record<string, string>;
11
+ /** Each declared file produce and whether the run left it. */
6
12
  produced?: {
7
13
  name: string;
8
14
  found: boolean;
9
15
  }[];
16
+ /** The line edge the floor would follow from this outcome. */
10
17
  edge?: LineEdge;
18
+ /** What the run cost in US dollars. */
19
+ costUsd?: number;
20
+ /** How long the run took in milliseconds. */
21
+ durationMs?: number;
11
22
  }
12
23
  /** The part of a record a page reads back. */
13
24
  export interface RunTranscript {
@@ -1,10 +1,22 @@
1
+ import { runCost } from "./run-cost.js";
1
2
  import { edgeTaken } from "./run-edge.js";
2
3
  import { runOutcome } from "./run-outcome.js";
3
- import { producesFound } from "./run-produces.js";
4
+ import { producesFound, valuesStated } from "./run-produces.js";
4
5
  export async function runResult({ exitCode, lines, station, line, node, folder }) {
5
6
  if (exitCode === null)
6
7
  return {};
7
- const { outcome, answer } = runOutcome({ lines, station });
8
- return { outcome, produced: await producesFound({ station, folder, answer }), edge: edgeTaken({ line, node, outcome }) };
8
+ const { outcome, answer, error, produced } = runOutcome({ lines, station });
9
+ return {
10
+ outcome,
11
+ ...presentWhenFilled("error", error),
12
+ ...presentWhenFilled("producedValues", valuesStated({ station, stated: produced })),
13
+ produced: await producesFound({ station, folder, answer }),
14
+ edge: edgeTaken({ line, node, outcome }),
15
+ ...runCost(lines),
16
+ };
17
+ }
18
+ function presentWhenFilled(key, value) {
19
+ const isFilled = typeof value === "string" ? value !== "" : value !== undefined && Object.keys(value).length > 0;
20
+ return isFilled ? { [key]: value } : {};
9
21
  }
10
22
  //# sourceMappingURL=run-result.js.map
@@ -1,3 +1,4 @@
1
- import type { StationBody } from "@re-cinq/floor-contracts";
1
+ import type { LineBody, StationBody } from "@re-cinq/floor-contracts";
2
2
  export declare const agentStation: StationBody;
3
3
  export declare const stationNeeding: (needs: StationBody["needs"]) => StationBody;
4
+ export declare const workLine: LineBody;