@re-cinq/floor-studio 0.0.0-stage → 0.6.2

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 (96) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +208 -2
  3. package/dist/backend/agent-file-text.d.ts +16 -0
  4. package/dist/backend/agent-file-text.js +37 -0
  5. package/dist/backend/agent-views.d.ts +8 -0
  6. package/dist/backend/agent-views.js +28 -0
  7. package/dist/backend/collection-view.d.ts +3 -0
  8. package/dist/backend/collection-view.js +108 -0
  9. package/dist/backend/environment-usage.d.ts +5 -0
  10. package/dist/backend/environment-usage.js +19 -0
  11. package/dist/backend/fixture-files.d.ts +4 -0
  12. package/dist/backend/fixture-files.js +14 -0
  13. package/dist/backend/fixture-requests.d.ts +12 -0
  14. package/dist/backend/fixture-requests.js +25 -0
  15. package/dist/backend/guard.d.ts +14 -0
  16. package/dist/backend/guard.js +20 -0
  17. package/dist/backend/index.d.ts +2 -0
  18. package/dist/backend/index.js +3 -0
  19. package/dist/backend/present.d.ts +2 -0
  20. package/dist/backend/present.js +5 -0
  21. package/dist/backend/read-line.d.ts +11 -0
  22. package/dist/backend/read-line.js +46 -0
  23. package/dist/backend/requests.d.ts +47 -0
  24. package/dist/backend/requests.js +74 -0
  25. package/dist/backend/run-cancel-request.d.ts +6 -0
  26. package/dist/backend/run-cancel-request.js +12 -0
  27. package/dist/backend/run-files.d.ts +5 -0
  28. package/dist/backend/run-files.js +15 -0
  29. package/dist/backend/run-preview-request.d.ts +15 -0
  30. package/dist/backend/run-preview-request.js +25 -0
  31. package/dist/backend/run-read-request.d.ts +6 -0
  32. package/dist/backend/run-read-request.js +12 -0
  33. package/dist/backend/run-start-request.d.ts +6 -0
  34. package/dist/backend/run-start-request.js +35 -0
  35. package/dist/backend/skill-names.d.ts +3 -0
  36. package/dist/backend/skill-names.js +20 -0
  37. package/dist/backend/sources-on-disk.d.ts +2 -0
  38. package/dist/backend/sources-on-disk.js +9 -0
  39. package/dist/backend/start-studio.d.ts +19 -0
  40. package/dist/backend/start-studio.js +93 -0
  41. package/dist/backend/store-folder.d.ts +1 -0
  42. package/dist/backend/store-folder.js +10 -0
  43. package/dist/backend/watcher.d.ts +6 -0
  44. package/dist/backend/watcher.js +33 -0
  45. package/dist/cli.d.ts +2 -0
  46. package/dist/cli.js +15 -0
  47. package/dist/protocol.d.ts +261 -0
  48. package/dist/protocol.js +79 -0
  49. package/dist/run/agent-command.d.ts +14 -0
  50. package/dist/run/agent-command.js +33 -0
  51. package/dist/run/prepare-workspace.d.ts +2 -0
  52. package/dist/run/prepare-workspace.js +14 -0
  53. package/dist/run/render-prompt.d.ts +1 -0
  54. package/dist/run/render-prompt.js +6 -0
  55. package/dist/run/run-edge.d.ts +8 -0
  56. package/dist/run/run-edge.js +8 -0
  57. package/dist/run/run-outcome.d.ts +12 -0
  58. package/dist/run/run-outcome.js +26 -0
  59. package/dist/run/run-preview.d.ts +29 -0
  60. package/dist/run/run-preview.js +31 -0
  61. package/dist/run/run-process.d.ts +16 -0
  62. package/dist/run/run-process.js +26 -0
  63. package/dist/run/run-produces.d.ts +12 -0
  64. package/dist/run/run-produces.js +13 -0
  65. package/dist/run/run-records.d.ts +22 -0
  66. package/dist/run/run-records.js +11 -0
  67. package/dist/run/run-result.d.ts +13 -0
  68. package/dist/run/run-result.js +10 -0
  69. package/dist/run/station-fixtures.d.ts +3 -0
  70. package/dist/run/station-fixtures.js +3 -0
  71. package/dist/run/vendor.d.ts +2 -0
  72. package/dist/run/vendor.js +11 -0
  73. package/dist/run/workspace.d.ts +21 -0
  74. package/dist/run/workspace.js +27 -0
  75. package/dist/shell/arguments.d.ts +15 -0
  76. package/dist/shell/arguments.js +32 -0
  77. package/dist/shell/open-browser.d.ts +7 -0
  78. package/dist/shell/open-browser.js +17 -0
  79. package/dist/shell/page-url.d.ts +6 -0
  80. package/dist/shell/page-url.js +5 -0
  81. package/dist/shell/static-files.d.ts +7 -0
  82. package/dist/shell/static-files.js +75 -0
  83. package/dist/shell/studio-command.d.ts +20 -0
  84. package/dist/shell/studio-command.js +48 -0
  85. package/dist/view.d.ts +100 -0
  86. package/dist/view.js +2 -0
  87. package/dist/web/assets/ibm-plex-sans-latin-300-b4i7YzLG.woff2 +0 -0
  88. package/dist/web/assets/ibm-plex-sans-latin-400-CDDApCn2.woff2 +0 -0
  89. package/dist/web/assets/ibm-plex-sans-latin-500-6ng42L7E.woff2 +0 -0
  90. package/dist/web/assets/ibm-plex-sans-latin-600-CuJfVYMP.woff2 +0 -0
  91. package/dist/web/assets/ibm-plex-sans-latin-700-Bxkt5Cjx.woff2 +0 -0
  92. package/dist/web/assets/index-Bb0f0ToW.css +1 -0
  93. package/dist/web/assets/index-bPZxSQCP.js +195 -0
  94. package/dist/web/assets/jetbrains-mono-latin-wght-B9CIFXIH.woff2 +0 -0
  95. package/dist/web/index.html +26 -0
  96. package/package.json +78 -4
@@ -0,0 +1,10 @@
1
+ // The dot folder the studio keeps its own files in, ignored by git from the first write.
2
+ import { mkdir, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ export async function storeFolderIn(dir, ...parts) {
5
+ const store = join(dir, ".floor-studio");
6
+ await mkdir(join(store, ...parts), { recursive: true });
7
+ await writeFile(join(store, ".gitignore"), "*", { flag: "wx" }).catch(() => undefined);
8
+ return join(store, ...parts);
9
+ }
10
+ //# sourceMappingURL=store-folder.js.map
@@ -0,0 +1,6 @@
1
+ export interface CollectionWatcher {
2
+ close(): void;
3
+ }
4
+ /** A path the collection reads, its settings file, and not under a dot folder: `.floor-studio` and `.git` change all the time and are not the collection's. */
5
+ export declare function isWatchedPath(path: string): boolean;
6
+ export declare function watchCollection(dir: string, onChange: () => void, debounceMs?: number): CollectionWatcher;
@@ -0,0 +1,33 @@
1
+ // Changes under a collection's folder, as one notification after the editor has finished: an editor saves with several writes and a rename.
2
+ import { watch } from "node:fs";
3
+ import { sep } from "node:path";
4
+ import { COLLECTION_SETTINGS_FILE, isReadPath } from "@re-cinq/floor-pipeline";
5
+ import { isSkillPath } from "./skill-names.js";
6
+ const DEBOUNCE_MS = 100;
7
+ /** A path the collection reads, its settings file, and not under a dot folder: `.floor-studio` and `.git` change all the time and are not the collection's. */
8
+ export function isWatchedPath(path) {
9
+ const slashed = path.split(sep).join("/");
10
+ return (isReadPath(slashed) || isSkillPath(slashed) || slashed === COLLECTION_SETTINGS_FILE) && !slashed.split("/").some((part) => part.startsWith("."));
11
+ }
12
+ export function watchCollection(dir, onChange, debounceMs = DEBOUNCE_MS) {
13
+ let timer;
14
+ const changed = () => {
15
+ clearTimeout(timer);
16
+ timer = setTimeout(onChange, debounceMs);
17
+ };
18
+ const watcher = watch(dir, { recursive: true }, (...given) => {
19
+ const filename = given[1];
20
+ // A name the platform leaves out may be any file.
21
+ if (filename === null || isWatchedPath(filename))
22
+ changed();
23
+ });
24
+ // A folder removed under the watcher ends it with an error; the studio keeps answering its sockets, and a read says what is gone.
25
+ watcher.on("error", () => undefined);
26
+ return {
27
+ close: () => {
28
+ clearTimeout(timer);
29
+ watcher.close();
30
+ },
31
+ };
32
+ }
33
+ //# sourceMappingURL=watcher.js.map
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ // floor-studio: opens a page that draws a collection of assembly lines, over a backend that reads the folder.
3
+ import { fileURLToPath } from "node:url";
4
+ import { openBrowser } from "./shell/open-browser.js";
5
+ import { studioCommand } from "./shell/studio-command.js";
6
+ const PAGE_WAIT_MS = 3000;
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 });
9
+ if ("exitCode" in outcome)
10
+ process.exit(outcome.exitCode);
11
+ const { running } = outcome;
12
+ const stop = () => void running.close().then(() => process.exit(0));
13
+ process.once("SIGINT", stop);
14
+ process.once("SIGTERM", stop);
15
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1,261 @@
1
+ import { z } from "zod";
2
+ import type { RunLine } from "./run/run-process.js";
3
+ import type { RunPreview } from "./run/run-preview.js";
4
+ import type { CollectionView } from "./view.js";
5
+ export type { AgentUse, AgentView, CollectionView, LineView, NodeAgent, NodeNeed, NodeView, RefusedFile, ViewProblem } from "./view.js";
6
+ /** Sent in the first frame of a socket, so a client built for another protocol can say so. */
7
+ export declare const PROTOCOL_VERSION = 1;
8
+ export declare const collectionReadRequest: z.ZodObject<{
9
+ id: z.ZodString;
10
+ type: z.ZodLiteral<"collection.read">;
11
+ }, z.core.$strict>;
12
+ export declare const agentWriteRequest: z.ZodObject<{
13
+ id: z.ZodString;
14
+ type: z.ZodLiteral<"agent.write">;
15
+ line: z.ZodString;
16
+ agent: z.ZodString;
17
+ prompt: z.ZodString;
18
+ settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
19
+ version: z.ZodString;
20
+ }, z.core.$strict>;
21
+ export declare const extraWriteRequest: z.ZodObject<{
22
+ id: z.ZodString;
23
+ type: z.ZodLiteral<"extra.write">;
24
+ line: z.ZodString;
25
+ agent: z.ZodString;
26
+ text: z.ZodString;
27
+ version: z.ZodString;
28
+ }, z.core.$strict>;
29
+ export declare const fixtureWriteRequest: z.ZodObject<{
30
+ id: z.ZodString;
31
+ type: z.ZodLiteral<"fixture.write">;
32
+ line: z.ZodString;
33
+ node: z.ZodString;
34
+ needs: z.ZodRecord<z.ZodString, z.ZodString>;
35
+ }, z.core.$strict>;
36
+ export declare const fixtureReadRequest: z.ZodObject<{
37
+ id: z.ZodString;
38
+ type: z.ZodLiteral<"fixture.read">;
39
+ line: z.ZodString;
40
+ node: z.ZodString;
41
+ }, z.core.$strict>;
42
+ export declare const runPreviewRequest: z.ZodObject<{
43
+ id: z.ZodString;
44
+ type: z.ZodLiteral<"run.preview">;
45
+ line: z.ZodString;
46
+ node: z.ZodString;
47
+ fixture: z.ZodRecord<z.ZodString, z.ZodString>;
48
+ folder: z.ZodString;
49
+ permission: z.ZodEnum<{
50
+ acceptEdits: "acceptEdits";
51
+ bypass: "bypass";
52
+ }>;
53
+ }, z.core.$strict>;
54
+ export declare const runStartRequest: z.ZodObject<{
55
+ id: z.ZodString;
56
+ type: z.ZodLiteral<"run.start">;
57
+ line: z.ZodString;
58
+ node: z.ZodString;
59
+ fixture: z.ZodRecord<z.ZodString, z.ZodString>;
60
+ folder: z.ZodString;
61
+ permission: z.ZodEnum<{
62
+ acceptEdits: "acceptEdits";
63
+ bypass: "bypass";
64
+ }>;
65
+ }, z.core.$strict>;
66
+ export declare const runCancelRequest: z.ZodObject<{
67
+ id: z.ZodString;
68
+ type: z.ZodLiteral<"run.cancel">;
69
+ run: z.ZodString;
70
+ }, z.core.$strict>;
71
+ export declare const runReadRequest: z.ZodObject<{
72
+ id: z.ZodString;
73
+ type: z.ZodLiteral<"run.read">;
74
+ run: z.ZodString;
75
+ after: z.ZodNumber;
76
+ }, z.core.$strict>;
77
+ /** A new request type is one schema here and one handler in the backend's table. */
78
+ export declare const requestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
79
+ id: z.ZodString;
80
+ type: z.ZodLiteral<"collection.read">;
81
+ }, z.core.$strict>, z.ZodObject<{
82
+ id: z.ZodString;
83
+ type: z.ZodLiteral<"agent.write">;
84
+ line: z.ZodString;
85
+ agent: z.ZodString;
86
+ prompt: z.ZodString;
87
+ settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
88
+ version: z.ZodString;
89
+ }, z.core.$strict>, z.ZodObject<{
90
+ id: z.ZodString;
91
+ type: z.ZodLiteral<"extra.write">;
92
+ line: z.ZodString;
93
+ agent: z.ZodString;
94
+ text: z.ZodString;
95
+ version: z.ZodString;
96
+ }, z.core.$strict>, z.ZodObject<{
97
+ id: z.ZodString;
98
+ type: z.ZodLiteral<"fixture.write">;
99
+ line: z.ZodString;
100
+ node: z.ZodString;
101
+ needs: z.ZodRecord<z.ZodString, z.ZodString>;
102
+ }, z.core.$strict>, z.ZodObject<{
103
+ id: z.ZodString;
104
+ type: z.ZodLiteral<"fixture.read">;
105
+ line: z.ZodString;
106
+ node: z.ZodString;
107
+ }, z.core.$strict>, z.ZodObject<{
108
+ id: z.ZodString;
109
+ type: z.ZodLiteral<"run.preview">;
110
+ line: z.ZodString;
111
+ node: z.ZodString;
112
+ fixture: z.ZodRecord<z.ZodString, z.ZodString>;
113
+ folder: z.ZodString;
114
+ permission: z.ZodEnum<{
115
+ acceptEdits: "acceptEdits";
116
+ bypass: "bypass";
117
+ }>;
118
+ }, z.core.$strict>, z.ZodObject<{
119
+ id: z.ZodString;
120
+ type: z.ZodLiteral<"run.start">;
121
+ line: z.ZodString;
122
+ node: z.ZodString;
123
+ fixture: z.ZodRecord<z.ZodString, z.ZodString>;
124
+ folder: z.ZodString;
125
+ permission: z.ZodEnum<{
126
+ acceptEdits: "acceptEdits";
127
+ bypass: "bypass";
128
+ }>;
129
+ }, z.core.$strict>, z.ZodObject<{
130
+ id: z.ZodString;
131
+ type: z.ZodLiteral<"run.cancel">;
132
+ run: z.ZodString;
133
+ }, z.core.$strict>, z.ZodObject<{
134
+ id: z.ZodString;
135
+ type: z.ZodLiteral<"run.read">;
136
+ run: z.ZodString;
137
+ after: z.ZodNumber;
138
+ }, z.core.$strict>], "type">;
139
+ export type Request = z.infer<typeof requestSchema>;
140
+ export type RequestKind = Request["type"];
141
+ export declare const REQUEST_TYPES: RequestKind[];
142
+ /** What a request is answered with, in a `result` frame. */
143
+ export type ResultOf<Asked extends Request> = Asked extends {
144
+ type: "collection.read";
145
+ } ? CollectionView : Asked extends {
146
+ type: "agent.write" | "extra.write";
147
+ } ? {
148
+ written: string;
149
+ } : Asked extends {
150
+ type: "fixture.write";
151
+ } ? {
152
+ written: string;
153
+ } : Asked extends {
154
+ type: "fixture.read";
155
+ } ? {
156
+ needs: Record<string, string>;
157
+ } : Asked extends {
158
+ type: "run.preview";
159
+ } ? RunPreview : Asked extends {
160
+ type: "run.start";
161
+ } ? {
162
+ run: string;
163
+ } : Asked extends {
164
+ type: "run.cancel";
165
+ } ? {
166
+ cancelled: string;
167
+ } : Asked extends {
168
+ type: "run.read";
169
+ } ? {
170
+ lines: RunLine[];
171
+ ended?: {
172
+ exitCode: number | null;
173
+ };
174
+ } : never;
175
+ export declare const collectionViewSchema: z.ZodType<CollectionView>;
176
+ export declare const helloFrame: z.ZodObject<{
177
+ type: z.ZodLiteral<"hello">;
178
+ version: z.ZodNumber;
179
+ }, z.core.$strict>;
180
+ export declare const resultFrame: z.ZodObject<{
181
+ id: z.ZodString;
182
+ type: z.ZodLiteral<"result">;
183
+ result: z.ZodUnknown;
184
+ }, z.core.$strict>;
185
+ export declare const refusedFrame: z.ZodObject<{
186
+ id: z.ZodOptional<z.ZodString>;
187
+ type: z.ZodLiteral<"refused">;
188
+ reason: z.ZodString;
189
+ }, z.core.$strict>;
190
+ export declare const collectionFrame: z.ZodObject<{
191
+ type: z.ZodLiteral<"collection">;
192
+ collection: z.ZodType<CollectionView, unknown, z.core.$ZodTypeInternals<CollectionView, unknown>>;
193
+ }, z.core.$strict>;
194
+ export declare const runOutputFrame: z.ZodObject<{
195
+ type: z.ZodLiteral<"run.output">;
196
+ run: z.ZodString;
197
+ line: z.ZodObject<{
198
+ stream: z.ZodEnum<{
199
+ stderr: "stderr";
200
+ stdout: "stdout";
201
+ }>;
202
+ text: z.ZodString;
203
+ }, z.core.$strict>;
204
+ }, z.core.$strict>;
205
+ export declare const runEndedFrame: z.ZodObject<{
206
+ type: z.ZodLiteral<"run.ended">;
207
+ run: z.ZodString;
208
+ exitCode: z.ZodNullable<z.ZodNumber>;
209
+ outcome: z.ZodOptional<z.ZodString>;
210
+ produced: z.ZodOptional<z.ZodArray<z.ZodObject<{
211
+ name: z.ZodString;
212
+ found: z.ZodBoolean;
213
+ }, z.core.$strict>>>;
214
+ edge: z.ZodOptional<z.ZodObject<{
215
+ from: z.ZodString;
216
+ to: z.ZodString;
217
+ on: z.ZodString;
218
+ iterationMax: z.ZodOptional<z.ZodNumber>;
219
+ }, z.core.$strict>>;
220
+ }, z.core.$strict>;
221
+ export declare const serverFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
222
+ type: z.ZodLiteral<"hello">;
223
+ version: z.ZodNumber;
224
+ }, z.core.$strict>, z.ZodObject<{
225
+ id: z.ZodString;
226
+ type: z.ZodLiteral<"result">;
227
+ result: z.ZodUnknown;
228
+ }, z.core.$strict>, z.ZodObject<{
229
+ id: z.ZodOptional<z.ZodString>;
230
+ type: z.ZodLiteral<"refused">;
231
+ reason: z.ZodString;
232
+ }, z.core.$strict>, z.ZodObject<{
233
+ type: z.ZodLiteral<"collection">;
234
+ collection: z.ZodType<CollectionView, unknown, z.core.$ZodTypeInternals<CollectionView, unknown>>;
235
+ }, z.core.$strict>, z.ZodObject<{
236
+ type: z.ZodLiteral<"run.output">;
237
+ run: z.ZodString;
238
+ line: z.ZodObject<{
239
+ stream: z.ZodEnum<{
240
+ stderr: "stderr";
241
+ stdout: "stdout";
242
+ }>;
243
+ text: z.ZodString;
244
+ }, z.core.$strict>;
245
+ }, z.core.$strict>, z.ZodObject<{
246
+ type: z.ZodLiteral<"run.ended">;
247
+ run: z.ZodString;
248
+ exitCode: z.ZodNullable<z.ZodNumber>;
249
+ outcome: z.ZodOptional<z.ZodString>;
250
+ produced: z.ZodOptional<z.ZodArray<z.ZodObject<{
251
+ name: z.ZodString;
252
+ found: z.ZodBoolean;
253
+ }, z.core.$strict>>>;
254
+ edge: z.ZodOptional<z.ZodObject<{
255
+ from: z.ZodString;
256
+ to: z.ZodString;
257
+ on: z.ZodString;
258
+ iterationMax: z.ZodOptional<z.ZodNumber>;
259
+ }, z.core.$strict>>;
260
+ }, z.core.$strict>], "type">;
261
+ export type ServerFrame = z.infer<typeof serverFrameSchema>;
@@ -0,0 +1,79 @@
1
+ // Every frame between a client and the backend. No Node import here: a browser bundle takes this file, and the types of `view.ts`, which are erased.
2
+ import { z } from "zod";
3
+ /** Sent in the first frame of a socket, so a client built for another protocol can say so. */
4
+ export const PROTOCOL_VERSION = 1;
5
+ const requestId = z.string().min(1).describe("Chosen by the client; the answer carries it.");
6
+ export const collectionReadRequest = z.strictObject({ id: requestId, type: z.literal("collection.read") });
7
+ 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
+ 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
+ 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
+ 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"]) });
13
+ export const runCancelRequest = z.strictObject({ id: requestId, type: z.literal("run.cancel"), run: z.string() });
14
+ export const runReadRequest = z.strictObject({ id: requestId, type: z.literal("run.read"), run: z.string(), after: z.number().int().min(0) });
15
+ /** 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]);
17
+ export const REQUEST_TYPES = requestSchema.options.map(({ shape }) => shape.type.value);
18
+ // 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
+ const presentObject = () => z.custom((value) => typeof value === "object" && value !== null);
20
+ const nodeAgentSchema = z.looseObject({ name: z.string(), file: z.string(), version: z.string().nullable(), prompt: z.string().nullable(), settings: z.record(z.string(), z.unknown()) });
21
+ const nodeViewSchema = z.looseObject({
22
+ id: z.string(),
23
+ station: z.string().optional(),
24
+ fanout: z.looseObject({ over: z.string(), to: z.string() }).optional(),
25
+ kind: z.custom().optional(),
26
+ description: z.string().optional(),
27
+ outcomes: z.array(z.string()),
28
+ needs: z.array(presentObject()),
29
+ produces: z.array(presentObject()),
30
+ agentDefinition: z.string().optional(),
31
+ events: presentObject(),
32
+ agent: nodeAgentSchema.optional(),
33
+ placeholders: z.custom().optional(),
34
+ extra: z.looseObject({ file: z.string(), text: z.string(), version: z.string() }).optional(),
35
+ });
36
+ const viewProblemSchema = z.looseObject({ rule: z.string(), node: z.string().optional(), message: z.string() });
37
+ const lineViewSchema = z.looseObject({
38
+ id: z.string(),
39
+ file: z.string(),
40
+ entry: z.string(),
41
+ exit: z.string(),
42
+ fail: z.string().optional(),
43
+ start: z.custom().optional(),
44
+ args: z.record(z.string(), z.custom()),
45
+ nodes: z.array(nodeViewSchema),
46
+ edges: z.array(z.custom()),
47
+ problems: z.array(viewProblemSchema),
48
+ });
49
+ const agentViewSchema = z.looseObject({
50
+ name: z.string(),
51
+ file: z.string(),
52
+ extraFile: z.string().optional(),
53
+ source: z.enum(["collection-new", "replaced", "extended"]),
54
+ settings: z.record(z.string(), z.unknown()),
55
+ prompt: z.string().nullable(),
56
+ usedBy: z.array(z.looseObject({ line: z.string(), node: z.string() })),
57
+ });
58
+ export const collectionViewSchema = z.looseObject({
59
+ folder: z.string().optional(),
60
+ skills: z.array(z.string()).optional(),
61
+ environment: z.array(z.looseObject({ name: z.string(), files: z.array(z.string()) })).optional(),
62
+ lines: z.array(lineViewSchema),
63
+ agents: z.array(agentViewSchema),
64
+ refused: z.array(z.looseObject({ path: z.string(), reason: z.string() })),
65
+ counts: z.looseObject({ lines: z.number(), agents: z.number(), refused: z.number(), problems: z.number() }),
66
+ });
67
+ export const helloFrame = z.strictObject({ type: z.literal("hello"), version: z.number().int() });
68
+ export const resultFrame = z.strictObject({ id: requestId, type: z.literal("result"), result: z.unknown() });
69
+ export const refusedFrame = z.strictObject({ id: requestId.optional(), type: z.literal("refused"), reason: z.string() });
70
+ export const collectionFrame = z.strictObject({ type: z.literal("collection"), collection: collectionViewSchema });
71
+ 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
+ export const runEndedFrame = z.strictObject({ type: z.literal("run.ended"), run: z.string(),
73
+ exitCode: z.number().nullable(),
74
+ outcome: z.string().optional(),
75
+ produced: z.array(z.strictObject({ name: z.string(), found: z.boolean() })).optional(),
76
+ edge: z.strictObject({ from: z.string(), to: z.string(), on: z.string(), iterationMax: z.number().optional() }).optional(),
77
+ });
78
+ export const serverFrameSchema = z.discriminatedUnion("type", [helloFrame, resultFrame, refusedFrame, collectionFrame, runOutputFrame, runEndedFrame]);
79
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1,14 @@
1
+ import type { Vendor } from "./vendor.js";
2
+ export interface AgentCommandSettings {
3
+ model?: string;
4
+ maxTurns?: number;
5
+ disallowedTools?: string[];
6
+ }
7
+ export interface AgentCommandInput {
8
+ vendor: Vendor;
9
+ settings: AgentCommandSettings;
10
+ prompt: string;
11
+ permission: "acceptEdits" | "bypass";
12
+ }
13
+ export declare const runnableVendors: string[];
14
+ export declare function agentCommand(input: AgentCommandInput): string[];
@@ -0,0 +1,33 @@
1
+ const permissionFlags = {
2
+ acceptEdits: ["--permission-mode", "acceptEdits"],
3
+ bypass: ["--dangerously-skip-permissions"],
4
+ };
5
+ /** `--setting-sources project`: the person's own settings and hooks stay out of the run, as in the pod, while their login still works (`--bare` would drop it). */
6
+ function claudeCommand({ settings, prompt, permission }) {
7
+ const disallowedTools = settings.disallowedTools ?? [];
8
+ const maxTurns = settings.maxTurns && settings.maxTurns > 0 ? String(settings.maxTurns) : undefined;
9
+ return ["claude", "--print", "--verbose", "--output-format", "stream-json", "--setting-sources", "project", ...optionalFlag("--model", settings.model), ...permissionFlags[permission], ...disallowedTools.flatMap((tool) => ["--disallowedTools", tool]), ...optionalFlag("--max-turns", maxTurns), "--", prompt];
10
+ }
11
+ function optionalFlag(flag, value) {
12
+ return value ? [flag, value] : [];
13
+ }
14
+ const codexPermissionFlags = {
15
+ acceptEdits: [],
16
+ bypass: ["--dangerously-bypass-approvals-and-sandbox"],
17
+ };
18
+ // Codex governs tools through its sandbox, as agentcore's codex/agent.d does, so it has no max-turns or disallowed-tools flags
19
+ function codexCommand({ settings, prompt, permission }) {
20
+ return ["codex", "exec", "--json", ...optionalFlag("--model", settings.model), ...codexPermissionFlags[permission], "--", prompt];
21
+ }
22
+ const commandBuilders = {
23
+ claude: claudeCommand,
24
+ codex: codexCommand,
25
+ };
26
+ export const runnableVendors = Object.keys(commandBuilders);
27
+ export function agentCommand(input) {
28
+ const build = commandBuilders[input.vendor];
29
+ if (!build)
30
+ throw new Error(`No agent command for vendor ${input.vendor}`);
31
+ return build(input);
32
+ }
33
+ //# sourceMappingURL=agent-command.js.map
@@ -0,0 +1,2 @@
1
+ import type { Workspace } from "./workspace.js";
2
+ export declare function prepareWorkspace({ copies, links }: Pick<Workspace, "copies" | "links">): Promise<void>;
@@ -0,0 +1,14 @@
1
+ // Lays the copies and links of a workspace onto disk, creating parent folders first.
2
+ import { copyFile, mkdir, symlink } from "node:fs/promises";
3
+ import { dirname } from "node:path";
4
+ export async function prepareWorkspace({ copies, links }) {
5
+ await Promise.all([
6
+ ...copies.map((copy) => placed(copy, copyFile)),
7
+ ...links.map((link) => placed(link, (from, to) => symlink(from, to, "dir"))),
8
+ ]);
9
+ }
10
+ async function placed({ from, to }, place) {
11
+ await mkdir(dirname(to), { recursive: true });
12
+ await place(from, to);
13
+ }
14
+ //# sourceMappingURL=prepare-workspace.js.map
@@ -0,0 +1 @@
1
+ export declare function renderPrompt(template: string, parameters: Readonly<Record<string, string>>): string;
@@ -0,0 +1,6 @@
1
+ // Fills {name} placeholders from run parameters, leaving unknown ones as written; ported from agentcore's prompt.d.
2
+ import { placeholderPattern } from "@re-cinq/floor-assembly-lines/placeholder-pattern";
3
+ export function renderPrompt(template, parameters) {
4
+ return template.replace(placeholderPattern("g"), (token, name) => Object.hasOwn(parameters, name) ? parameters[name] : token);
5
+ }
6
+ //# sourceMappingURL=render-prompt.js.map
@@ -0,0 +1,8 @@
1
+ import type { LineBody } from "@re-cinq/floor-contracts";
2
+ interface EdgeQuery {
3
+ line: LineBody;
4
+ node: string;
5
+ outcome: string;
6
+ }
7
+ export declare function edgeTaken({ line, node, outcome }: EdgeQuery): import("@re-cinq/floor-assembly-lines").WalkEdge | undefined;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ // Names the edge the floor would take from a node for an outcome.
2
+ import { isTerminalNode, selectEdge } from "@re-cinq/floor-assembly-lines";
3
+ export function edgeTaken({ line, node, outcome }) {
4
+ if (isTerminalNode(line, node))
5
+ return undefined;
6
+ return selectEdge({ name: "", ...line }, node, outcome) ?? undefined;
7
+ }
8
+ //# sourceMappingURL=run-edge.js.map
@@ -0,0 +1,12 @@
1
+ import type { StationBody } from "@re-cinq/floor-contracts";
2
+ import type { RunLine } from "./run-process.js";
3
+ interface RunOutcomeInput {
4
+ lines: RunLine[];
5
+ station: StationBody;
6
+ }
7
+ /** The outcome the agent reported, and its final answer. */
8
+ export declare function runOutcome({ lines, station }: RunOutcomeInput): {
9
+ outcome: string;
10
+ answer?: string;
11
+ };
12
+ export {};
@@ -0,0 +1,26 @@
1
+ // Reads how an agent run ended from the final "result" line of its stream-json transcript.
2
+ import { readAgentVerdict, requiredVerdict } from "@re-cinq/floor-assembly-lines";
3
+ /** The outcome the agent reported, and its final answer. */
4
+ export function runOutcome({ lines, station }) {
5
+ const answer = finalAgentText(lines);
6
+ 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
+ }
25
+ }
26
+ //# sourceMappingURL=run-outcome.js.map
@@ -0,0 +1,29 @@
1
+ import type { StationBody } from "@re-cinq/floor-contracts";
2
+ import { type AgentCommandInput } from "./agent-command.js";
3
+ import { type NeedCopy, type NeedLink } from "./workspace.js";
4
+ export interface StationSettings {
5
+ model?: string;
6
+ config?: {
7
+ max_turns?: number;
8
+ disallowed_tools?: string[];
9
+ env?: Record<string, string>;
10
+ };
11
+ }
12
+ export interface RunPreviewInput {
13
+ station: StationBody;
14
+ prompt: string;
15
+ settings: StationSettings;
16
+ fixture: Readonly<Record<string, string>>;
17
+ folder: string;
18
+ permission: AgentCommandInput["permission"];
19
+ }
20
+ export interface RunPreview {
21
+ prompt: string;
22
+ command: string[];
23
+ copies: NeedCopy[];
24
+ links: NeedLink[];
25
+ blockers: string[];
26
+ /** The agent's `config.env`, laid over the studio's environment for the run. */
27
+ env: Record<string, string>;
28
+ }
29
+ export declare function runPreview({ station, prompt, settings, fixture, folder, permission }: RunPreviewInput): RunPreview;
@@ -0,0 +1,31 @@
1
+ // What a run of one agent station would do, before it is started.
2
+ import { isAbsolute } from "node:path";
3
+ import { agentCommand, runnableVendors } from "./agent-command.js";
4
+ import { renderPrompt } from "./render-prompt.js";
5
+ import { vendorOf } from "./vendor.js";
6
+ import { workspaceOf } from "./workspace.js";
7
+ export function runPreview({ station, prompt, settings, fixture, folder, permission }) {
8
+ const { parameters, copies, links, missing } = workspaceOf({ station, fixture, folder });
9
+ const rendered = inFolder(renderPrompt(prompt, parameters), folder);
10
+ const vendor = vendorOf(settings.model ?? "");
11
+ const unrunnable = runnableVendors.includes(vendor) ? [] : [unrunnableBlocker(settings.model ?? "", vendor)];
12
+ 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)] };
14
+ }
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);
18
+ }
19
+ function agentEnvOf({ config }) {
20
+ return config?.env ?? {};
21
+ }
22
+ function relativeFolderBlockers(folder) {
23
+ return isAbsolute(folder) ? [] : [`the folder must be an absolute path: ${folder}`];
24
+ }
25
+ function unrunnableBlocker(model, vendor) {
26
+ return `the studio runs ${runnableVendors.join(" and ")} agents; ${model} is a ${vendor} model`;
27
+ }
28
+ function commandSettingsOf({ model, config }) {
29
+ return { model, maxTurns: config?.max_turns, disallowedTools: config?.disallowed_tools };
30
+ }
31
+ //# sourceMappingURL=run-preview.js.map
@@ -0,0 +1,16 @@
1
+ export interface RunProcessRequest {
2
+ command: string[];
3
+ folder: string;
4
+ env?: Record<string, string>;
5
+ }
6
+ export interface RunLine {
7
+ stream: "stdout" | "stderr";
8
+ text: string;
9
+ }
10
+ export interface RunningProcess {
11
+ done: Promise<{
12
+ exitCode: number | null;
13
+ }>;
14
+ cancel(): void;
15
+ }
16
+ export declare function runProcess(request: RunProcessRequest, onLine: (line: RunLine) => void): RunningProcess;
@@ -0,0 +1,26 @@
1
+ // Spawns an agent CLI in a folder, streaming its stdout and stderr line by line, with cancel.
2
+ import { spawn } from "node:child_process";
3
+ import { createInterface } from "node:readline";
4
+ export function runProcess(request, onLine) {
5
+ const [program, ...args] = request.command;
6
+ const child = spawn(program, args, {
7
+ cwd: request.folder,
8
+ env: { ...process.env, ...request.env },
9
+ stdio: ["ignore", "pipe", "pipe"],
10
+ detached: true,
11
+ });
12
+ readLines(child.stdout, "stdout", onLine);
13
+ readLines(child.stderr, "stderr", onLine);
14
+ const done = new Promise((resolve) => {
15
+ child.on("close", (exitCode) => resolve({ exitCode }));
16
+ });
17
+ const cancel = () => {
18
+ if (child.pid !== undefined)
19
+ process.kill(-child.pid, "SIGTERM");
20
+ };
21
+ return { done, cancel };
22
+ }
23
+ function readLines(input, stream, onLine) {
24
+ createInterface({ input }).on("line", (text) => onLine({ stream, text }));
25
+ }
26
+ //# sourceMappingURL=run-process.js.map