@re-cinq/floor-studio 0.6.1 → 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.
package/README.md CHANGED
@@ -1,17 +1,21 @@
1
1
  # @re-cinq/floor-studio
2
2
 
3
- A local studio for a collection of assembly lines: the folder with one folder a line, each holding `assembly-line.yaml` and `agents/<agent>.md`. It reads the folder, draws nothing itself, and tells every client what the collection holds: each assembly line with its nodes, edges and problems, each agent with its settings and prompt, and each file it refused and why. A change to a file on disk reaches every client at once.
3
+ A local studio for a collection of assembly lines. A collection is a folder with one folder per assembly line, at the top or in a group folder, each holding `assembly-line.yaml` and `agents/<agent>.md`. The studio reads the folder and tells every client what it holds: each assembly line with its nodes, edges and problems, each agent with its settings and prompt, and each file it refused and why. A change to a file on disk reaches every client at once.
4
4
 
5
- This package is the backend, the protocol, the command that starts them, and the page that draws the lines (`web/`). It is not published to npm yet: run it from a checkout.
5
+ This package is the backend, the protocol, the command that starts them, and the page that draws the assembly lines (`web/`). It is published to npm, so this starts it without a checkout:
6
6
 
7
- ## The three parts
7
+ ```
8
+ npx @re-cinq/floor-studio path/to/collection
9
+ ```
10
+
11
+ ## The four parts
8
12
 
9
13
  | part | where | what it does |
10
14
  |---|---|---|
11
- | Backend | `src/backend`, exported as `@re-cinq/floor-studio/backend` | headless. `startStudio({ dir, port, hostKeys, origins })` listens on `127.0.0.1` and speaks WebSocket only. It serves no page and knows nothing about a browser |
12
- | Protocol | `src/protocol.ts`, exported as `@re-cinq/floor-studio/protocol` | every frame as a zod schema and its type. It imports nothing from Node, so a browser bundle can take it |
13
- | Shell | `src/cli.ts`, the command `floor-studio` | parses the arguments, starts the backend, serves the built page from `dist/web` over plain HTTP on `127.0.0.1`, and opens the browser. A desktop app would replace only this part |
14
- | Page | `web/`, built into `dist/web` | a Vite and React app, one client of the backend. It takes the socket and the token from its address and draws the collection |
15
+ | Backend | `src/backend`, exported as `@re-cinq/floor-studio/backend` | Headless. `startStudio({ dir, port, hostKeys, origins })` listens on `127.0.0.1` and speaks WebSocket only. It serves no page and knows nothing about a browser |
16
+ | Protocol | `src/protocol.ts`, exported as `@re-cinq/floor-studio/protocol` | Every frame as a zod schema and its type. It imports nothing from Node, so a browser bundle can take it |
17
+ | Shell | `src/cli.ts`, the command `floor-studio` | Parses the arguments, starts the backend, serves the built page from `dist/web` over plain HTTP on `127.0.0.1`, and opens the browser. A desktop app would replace only this part |
18
+ | Page | `web/`, built into `dist/web` | A Vite and React app, one client of the backend. It takes the socket and the token from its address and draws the collection |
15
19
 
16
20
  ## Run it from the checkout
17
21
 
@@ -27,30 +31,30 @@ floor-studio [dir] [--port <n>] [--host-key <name>]... [--no-open]
27
31
 
28
32
  | option | meaning |
29
33
  |---|---|
30
- | `dir` | the collection. Default: the current directory. A directory that does not exist is an error, exit 1 |
31
- | `--port <n>` | the port of the backend's socket on `127.0.0.1`. Default: a free one. The page's own port is always a free one |
32
- | `--host-key <name>` | a frontmatter key the host owns, accepted in an agent file and left out of its settings. As often as needed. The `host_keys` of the collection's `floor-collection.yaml` count too, read again when that file changes |
33
- | `--no-open` | print the url and do not open a browser. Without it the studio waits 3 seconds and opens the default browser with `xdg-open`, `open` or `start`, unless a page has connected by then, such as a tab left open from before a restart; failing to open one is not an error |
34
- | `--help` | print the usage and exit 0. A bad argument prints the usage to standard error and exits 2 |
34
+ | `dir` | The collection. Default: the current directory. A directory that does not exist is an error, exit 1 |
35
+ | `--port <n>` | The port of the backend's socket on `127.0.0.1`. Default: a free one. The page's own port is always a free one |
36
+ | `--host-key <name>` | A frontmatter key the host owns, accepted in an agent file and left out of its settings. Repeat it as often as needed. The `host_keys` of the collection's `floor-collection.yaml` count too, and are read again when that file changes. Studio reads its `groups` as well |
37
+ | `--no-open` | Print the url and do not open a browser. Without it the studio waits 3 seconds and opens the default browser with `xdg-open`, `open` or `start`. It skips that when a page has connected by then, such as a tab left open from before a restart. Failing to open a browser is not an error |
38
+ | `--help` | Print the usage and exit 0. A bad argument prints the usage to standard error and exits 2 |
35
39
 
36
- It prints one line, `floor-studio: <url>`. The url is the page's, and carries what the page needs in its fragment, which a browser does not send to a server:
40
+ It prints one line, `floor-studio: <url>`. The url is the page's. What the page needs is in the fragment, which a browser does not send to a server:
37
41
 
38
42
  ```
39
43
  http://127.0.0.1:<page port>/#socket=ws%3A%2F%2F127.0.0.1%3A<socket port>&token=<token>
40
44
  ```
41
45
 
42
- When `dist/web` does not exist the page server answers a plain page saying the page is not built. It serves only files under `dist/web`, with `Cache-Control: no-store`, and refuses a path that leaves the folder, by `..`, by a percent-encoded `..` or by a symlink.
46
+ When `dist/web` does not exist the page server answers a plain page saying the page is not built. It serves only files under `dist/web`, with `Cache-Control: no-store`. It refuses a path that leaves the folder, by `..`, by a percent-encoded `..` or by a symlink.
43
47
 
44
48
  ## The page
45
49
 
46
- `web/` holds the page: Vite, React and TypeScript, styled with plain CSS custom properties and CSS Modules in lore's look (tokens in `web/src/theme/theme.css`, IBM Plex Sans and JetBrains Mono as local files, light, dark or auto). It draws the assembly lines with lore's graph code (`web/src/graph`, where its README says what was copied and stripped), and loads nothing from another host. Everything it needs is bundled, so React, Vite and the test tools are devDependencies and the published package needs none of them at run time.
50
+ `web/` holds the page: Vite, React and TypeScript, styled with plain CSS custom properties and CSS Modules in lore's look. The tokens are in `web/src/theme/theme.css`, the fonts are IBM Plex Sans and JetBrains Mono as local files, and the theme is light, dark or auto. It draws the assembly lines with [`@re-cinq/floor-graph`](../graph/README.md) and loads nothing from another host. Everything the page needs is bundled, so React, Vite and the test tools are devDependencies and the published package needs none of them at run time.
47
51
 
48
52
  | where | what |
49
53
  |---|---|
50
54
  | `npm run build -w @re-cinq/floor-studio` | `tsc` writes `dist` except `dist/web`, then `vite build` writes only `dist/web` (it empties that folder and nothing else), so the two steps do not depend on their order |
51
- | `dist/web/index.html` | the built page, the one the command serves |
52
- | `npm run dev:web -w @re-cinq/floor-studio` | the Vite dev server with hot reload |
53
- | `npm run typecheck -w @re-cinq/floor-studio` | checks `src` and `web` |
55
+ | `dist/web/index.html` | The built page, the one the command serves |
56
+ | `npm run dev:web -w @re-cinq/floor-studio` | The Vite dev server with hot reload |
57
+ | `npm run typecheck -w @re-cinq/floor-studio` | Checks `src` and `web` |
54
58
 
55
59
  To work on the page, start a backend and give the dev server its address:
56
60
 
@@ -59,40 +63,91 @@ node packages/studio/dist/cli.js path/to/collection --no-open # prints floor
59
63
  npm run dev:web -w @re-cinq/floor-studio # serves http://localhost:5173/
60
64
  ```
61
65
 
62
- Open `http://localhost:5173/` with the fragment the command printed (`#socket=...&token=...`). The backend refuses a browser page whose origin it was not told, so start it with the dev server's origin allowed by calling `startStudio({ ..., origins: ["http://localhost:5173"] })` from a script; the command itself allows only its own page, as `127.0.0.1` or `localhost` on the page's port.
66
+ Open `http://localhost:5173/` with the fragment the command printed (`#socket=...&token=...`). The backend refuses a browser page whose origin it was not told. The command allows only its own page, as `127.0.0.1` or `localhost` on the page's port. To allow the dev server, start the backend from a script with `startStudio({ ..., origins: ["http://localhost:5173"] })`.
67
+
68
+ ### Selection
69
+
70
+ The page keeps the selected assembly line and node in the fragment (`&line=<id>&node=<id>&tab=<tab>`), so a reload keeps the place.
71
+
72
+ - Clicking an edge or its label selects that edge and drops the node (`&edge=<from>|<to>|<event>`). A Line inspector shows its stations, its event, whether it is on the main path and its iteration limit.
73
+ - Choosing another node keeps the tab, or falls back to the first tab when that node lacks it. Escape clears the node and the tab.
74
+ - A `collection` push redraws the page in place and keeps the selection while the assembly line and node still exist.
63
75
 
64
- The page keeps the selected line and node in the same fragment (`&line=<id>&node=<id>&tab=<tab>`), so a reload keeps the place. Clicking a graph line or its label selects that line instead (`&edge=<from>|<to>|<event>`, the node dropped), and a Line inspector shows its stations, event, whether it is on the main path and its iteration limit. Choosing another node keeps the tab (the first tab when that node lacks it); Escape clears the node and the tab. A `collection` push redraws it in place and keeps the selection while the line and node still exist. Its screens: no address, connecting, cannot connect (it retries with backoff and reads the collection again once it is back), refused (a wrong token, or another protocol version, is not retried), unreadable (the collection could not be read, with the reason; an unasked `refused` push, such as the folder being deleted, replaces a collection already drawn), an empty folder, and the line view. The right-hand inspector shows the selected node's id and station, with tabs by kind (the arrow keys move between them and wrap, Home and End go to the first and last): none for a marker, Station and Events for a station, plus Prompt, Run and the five settings tabs (Model, Tools, MCP, Pod, Other) for an agent. The Station tab shows the description, each need with a sentence on how it is covered, each produce with the downstream nodes that read it, and the outcomes. The Events tab lists what starts the node (an edge, an outside event, or the line's own start, with its condition), the outside events that answer it with the outcome each reports, and what it raises: its events, each outcome with the node the edge it takes starts (or that the run stops there), and the lines a settled run starts. The Prompt tab shows the agent's prompt with each `{placeholder}` marked by its state (by the same name rule the lint uses, `placeholderPattern`), a table of the placeholders with their source, state and the nodes that fill them, and the needs the prompt never uses. The settings tabs show each setting the agent file writes; without a studio connection it is a read-only `key: value` list, with objects and lists as compact JSON.
76
+ ### Screens
65
77
 
66
- **Editing.** Connected to a studio, the Prompt tab has an editor and "Save prompt", and each settings tab a form (a field per setting, nested ones such as `config` as YAML) and "Save settings". A save sends `agent.write` with the version of the file the edit started from; the backend refuses it when the file changed on disk since, or when the agent file it would write fails the same check the collection read uses, and the tab shows the reason. Numbers stay numbers. With no unsaved edits, a change on disk shows at once; with unsaved edits, the edits are kept and the tab offers "Take the version on disk" or "Keep my edits", and a save before choosing is refused. An agent extended by `<line>/agents/<agent>.extra.md` also gets an "Extra prompt" editor for that file's text on its own: the studio is told no shipped agents, so it shows no merged prompt and the collection still lists the extension as refused, but its text can be edited and saved, with the same version check.
78
+ - No address.
79
+ - Connecting.
80
+ - Cannot connect. The page retries with backoff and reads the collection again once it is back.
81
+ - Refused: a wrong token or another protocol version. It is not retried.
82
+ - Unreadable: the collection could not be read, shown with the reason. An unasked `refused` push, such as the folder being deleted, replaces a collection already drawn.
83
+ - An empty folder.
84
+ - The line view.
67
85
 
68
86
  ### The inspector tabs
69
87
 
88
+ The right-hand inspector shows the selected node's id and station, with tabs by kind. A marker has none. A station has Station and Events. An agent adds Prompt, Run and the five settings tabs. The arrow keys move between tabs and wrap, and Home and End go to the first and last.
89
+
70
90
  | tab | what it shows |
71
91
  |---|---|
72
- | Station | description, needs and their coverage, produces and readers, outcomes |
73
- | Events | what starts the node, what answers it, what it raises |
74
- | Prompt | the prompt, its placeholders, unused needs; an editor when connected |
75
- | Run | runs this one station on your machine; see below |
92
+ | Station | The description, each need with a sentence on how it is covered, each produce with the downstream nodes that read it, and the outcomes |
93
+ | Events | What starts the node: an edge, an outside event, or the assembly line's own start, with its condition. The outside events that answer it, with the outcome each reports. What it raises: its events, each outcome with the node its edge starts (or that the run stops there), and the assembly lines a settled run starts |
94
+ | Prompt | The agent's prompt with each `{placeholder}` marked by its state, by the same name rule the lint uses (`placeholderPattern`). A table of the placeholders with their source, state and the nodes that fill them. The needs the prompt never uses. An editor when connected |
95
+ | Run | Runs this one station on your machine, see [Running one station](#running-one-station) |
76
96
  | Model | `model`, `permission_mode`, `max_turns`, `model_secret_key` |
77
97
  | Tools | `skills`, `skills_source`, `disallowed_tools` |
78
98
  | MCP | `mcp_servers` |
79
99
  | Pod | `image`, `timeout_minutes`, `env`, `pod_resources` |
80
100
  | Other | `tags`, `prices` and the rest of `config` |
81
101
 
102
+ The settings tabs show each setting the agent file writes. Without a studio connection a settings tab is a read-only `key: value` list, with objects and lists as compact JSON.
103
+
104
+ ### Editing
105
+
106
+ Connected to a studio, the Prompt tab has an editor and "Save prompt". Each settings tab has a form and "Save settings", with a field per setting and nested ones such as `config` as YAML. Numbers stay numbers.
107
+
108
+ A save sends `agent.write` with the version of the file the edit started from. The backend refuses it when the file changed on disk since, or when the agent file it would write fails the same check the collection read uses. The tab shows the reason.
109
+
110
+ With no unsaved edits, a change on disk shows at once. With unsaved edits, the edits are kept and the tab offers "Take the version on disk" or "Keep my edits". A save before choosing is refused.
111
+
112
+ An agent extended by `<line>/agents/<agent>.extra.md` (or `<group>/<line>/agents/<agent>.extra.md`) also gets an "Extra prompt" editor for that file's text on its own, saved with the same version check. The studio is told no shipped agents, so it shows no merged prompt and the collection still lists the extension as refused.
113
+
82
114
  ### Running one station
83
115
 
84
- The Run tab of an agent node runs that station alone, with the agent CLI on your machine. It runs `claude` or `codex`, by the agent's model; any other family is a blocker.
116
+ The Run tab of an agent node runs that station alone, with the agent CLI on your machine. It runs `claude` or `codex`, by the agent's model. Any other model family is a blocker.
117
+
118
+ The tab has a field for each need:
119
+
120
+ | need | what you give | what the studio does |
121
+ |---|---|---|
122
+ | value | text | passes it as is |
123
+ | file | the path of a file | copies it to the need's path in the folder |
124
+ | git | the path of a checkout | links it at the need's path. It links the real checkout, so the agent's commits land in it |
125
+
126
+ Folder is where the run happens. Permission is `acceptEdits` or `bypass`, as in the pod.
127
+
128
+ Preview shows the rendered prompt, the command and the blockers. A blocker is a required need with no value, a source path that does not exist, or a model the studio cannot run. A run with blockers is refused.
85
129
 
86
- - It has a field for each need: a value is text, a file is the path of a file to copy to the need's path in the folder, a git need is the path of a checkout to link at its path. A git need links the real checkout, so the agent's commits land in it.
87
- - Folder is where it runs. Permission is `acceptEdits` or `bypass` (as in the pod).
88
- - Preview shows the rendered prompt, the command and the blockers: a required need with no value, a source path that does not exist, or a model the studio cannot run. A run with blockers is refused.
89
- - Run starts it and Cancel stops it. The transcript streams in. When it ends the tab shows the outcome (the agent's verdict, read from its final result), the exit code (none when cancelled), each file produce as found or missing, and the events raised next. The edge the outcome takes is lit on the graph.
130
+ Run starts it and Cancel stops it. The transcript streams in as what the agent said, each tool it called (`› Read tests.json`), each refusal in red, and the run's turns, time and cost. Raw shows the lines as `claude` printed them.
90
131
 
91
- The need values are saved in `.floor-studio/fixtures/<line>/<node>.json` and each run in `.floor-studio/runs/<id>.json`, both in the collection folder. The store folder gets a `.gitignore` of `*` on its first write. The run's id is kept in the page's fragment (`&run=<id>`), so after a reload the tab reads the transcript again with `run.read`, also for a run still going. Closing the studio cancels its runs.
132
+ When the run ends the tab shows the agent's final answer under Answer. Its words are text, and any JSON object in it is laid out field by field, each list item a numbered block, with the `LORE_NODE_RESULT` line left out. Below it, each under its label:
133
+
134
+ - the outcome, which is the agent's verdict read from its final result
135
+ - the exit code, none when cancelled
136
+ - each produce as found or missing. A produce `from: output` is found when the agent gave a final answer
137
+ - the edge taken, which is also lit on the graph
138
+ - the events raised next
139
+
140
+ Two things match the pod. The run gets the agent's `config.env` over the studio's own environment, so `CLAUDE_CODE_DISABLE_CLAUDE_MDS` and the like apply. And `/workspace`, as the pod spells the working folder, is replaced by the picked folder in the prompt's text and in the `<name>_path` parameters.
141
+
142
+ The need values are saved in `.floor-studio/fixtures/<line>/<node>.json` and each run in `.floor-studio/runs/<id>.json`, both in the collection folder. They are keyed by the line's name, so they do not move when a line folder moves into a group folder. The store folder gets a `.gitignore` of `*` on its first write. The run's id is kept in the page's fragment (`&run=<id>`), so after a reload the tab reads the transcript again with `run.read`, also for a run still going. Closing the studio cancels its runs.
92
143
 
93
144
  ### The environment
94
145
 
95
- The sidebar lists the variables the settings name as `${NAME}`, with the files using each. A setting written that way shows as a chip, `env: NAME`; the studio does not fill it. Override opens the field to type a value in its place; saved with nothing typed, the setting keeps its `${NAME}`. The install that applies the collection fills it in once, and applying fails when it is not set. In Lore it is set on lore-api by its Helm chart, or in `.env.local` when Lore runs locally.
146
+ The sidebar lists the variables the settings name as `${NAME}`, with the files using each. A setting written that way shows as a chip, `env: NAME`. The studio does not fill it.
147
+
148
+ Override opens the field to type a value in its place. Saved with nothing typed, the setting keeps its `${NAME}`.
149
+
150
+ The install that applies the collection fills the variable in once, and applying fails when it is not set. In Lore it is set on lore-api by its Helm chart, or in `.env.local` when Lore runs locally.
96
151
 
97
152
  ## Use the backend on its own
98
153
 
@@ -104,7 +159,7 @@ const studio = await startStudio({ dir: "collection", port: 0, hostKeys: ["revie
104
159
  await studio.close();
105
160
  ```
106
161
 
107
- `startStudio` resolves to `{ url, token, close }`. `url` has the real port and not the token. `close()` closes the sockets, the server and the watcher. It rejects when `dir` is not a directory.
162
+ `startStudio` resolves to `{ url, token, close }`. `url` has the real port and not the token. `close()` closes the sockets, the server and the watcher. `startStudio` rejects when `dir` is not a directory.
108
163
 
109
164
  ## The protocol
110
165
 
@@ -112,43 +167,43 @@ Every frame is JSON in one WebSocket message. A request carries an `id` the clie
112
167
 
113
168
  | direction | frame | when |
114
169
  |---|---|---|
115
- | backend to client | `{ type: "hello", version }` | first, when a socket opens. `version` is `PROTOCOL_VERSION` |
116
- | client to backend | `{ id, type: "collection.read" }` | the client wants the whole collection |
117
- | client to backend | `{ id, type: "agent.write", line, agent, prompt, settings?, version }` | rewrite an agent file: the body becomes `prompt`, the frontmatter `settings` when given (comments and key order kept); `version` is the sha256 of the file as the client read it (each node's `agent.version`). Refused when the line has no such agent, the file changed since, or the file it would write fails the agent-file check. The result is `{ written: <file> }` |
118
- | client to backend | `{ id, type: "extra.write", line, agent, text, version }` | replace the whole text of the agent's `.extra.md` (each node's `extra`); `version` is the sha256 of the file as read. Refused when the line has no extra file for that agent or the file changed since. The text is saved ending in one newline. The result is `{ written: <file> }` |
119
- | client to backend | `{ id, type: "fixture.write", line, node, needs }` | save the need values (`needs`, a text for each need name) of a node in `.floor-studio/fixtures/<line>/<node>.json`. The result is `{ written: <file> }` |
120
- | client to backend | `{ id, type: "fixture.read", line, node }` | read the saved need values of a node. The result is `{ needs }`, empty when none were saved |
121
- | client to backend | `{ id, type: "run.preview", line, node, fixture, folder, permission }` | what a run would do: the result is `{ prompt, command, copies, links, blockers }`. `permission` is `acceptEdits` or `bypass` |
122
- | client to backend | `{ id, type: "run.start", line, node, fixture, folder, permission }` | start a run of an agent node. Refused when the preview has blockers. The result is `{ run }`, the run's id |
123
- | client to backend | `{ id, type: "run.cancel", run }` | stop a running run. Refused when none runs under that id. The result is `{ cancelled: run }` |
124
- | client to backend | `{ id, type: "run.read", run, after }` | the transcript of a run from line number `after` on, running or ended, also after a restart. The result is `{ lines, ended? }` |
125
- | backend to client | `{ id, type: "result", result }` | the answer to a request. For `collection.read`, `result` is the collection view |
126
- | backend to client | `{ id?, type: "refused", reason }` | a frame that is not JSON, fails its schema, or has an unknown `type`, or a request that failed. The `id` is there when one could be read. Also pushed unasked, without an `id`, when a re-read after a change on disk fails, such as the folder being deleted. The socket stays open |
127
- | backend to client | `{ type: "collection", collection }` | a file the collection reads changed on disk, whoever changed it: the whole view again |
128
- | backend to client | `{ type: "run.output", run, line: { stream, text } }` | one line a run wrote, on `stdout` or `stderr`, sent to every socket |
129
- | backend to client | `{ type: "run.ended", run, exitCode, outcome?, produced?, edge? }` | a run ended. `exitCode` is `null` when it was cancelled, and then the rest is absent. Otherwise `outcome` is the agent's verdict, `produced` lists each file produce as `{ name, found }`, and `edge` is the `{ from, to, on }` the outcome takes (none from a terminal node) |
170
+ | backend to client | `{ type: "hello", version }` | First, when a socket opens. `version` is `PROTOCOL_VERSION` |
171
+ | client to backend | `{ id, type: "collection.read" }` | The client wants the whole collection |
172
+ | client to backend | `{ id, type: "agent.write", line, agent, prompt, settings?, version }` | Rewrite an agent file. The body becomes `prompt`, and the frontmatter becomes `settings` when given, with comments and key order kept. `version` is the sha256 of the file as the client read it (each node's `agent.version`). Refused when the assembly line has no such agent, the file changed since, or the file it would write fails the agent-file check. The result is `{ written: <file> }` |
173
+ | client to backend | `{ id, type: "extra.write", line, agent, text, version }` | Replace the whole text of the agent's `.extra.md` (each node's `extra`). `version` is the sha256 of the file as read. Refused when the assembly line has no extra file for that agent or the file changed since. The text is saved ending in one newline. The result is `{ written: <file> }` |
174
+ | client to backend | `{ id, type: "fixture.write", line, node, needs }` | Save the need values (`needs`, a text for each need name) of a node in `.floor-studio/fixtures/<line>/<node>.json`. The result is `{ written: <file> }` |
175
+ | client to backend | `{ id, type: "fixture.read", line, node }` | Read the saved need values of a node. The result is `{ needs }`, empty when none were saved |
176
+ | client to backend | `{ id, type: "run.preview", line, node, fixture, folder, permission }` | What a run would do. The result is `{ prompt, command, copies, links, blockers }`. `permission` is `acceptEdits` or `bypass` |
177
+ | client to backend | `{ id, type: "run.start", line, node, fixture, folder, permission }` | Start a run of an agent node. Refused when the preview has blockers. The result is `{ run }`, the run's id |
178
+ | client to backend | `{ id, type: "run.cancel", run }` | Stop a running run. Refused when none runs under that id. The result is `{ cancelled: run }` |
179
+ | client to backend | `{ id, type: "run.read", run, after }` | The transcript of a run from line number `after` on, running or ended, also after a restart. The result is `{ lines, ended? }` |
180
+ | backend to client | `{ id, type: "result", result }` | The answer to a request. For `collection.read`, `result` is the collection view |
181
+ | backend to client | `{ id?, type: "refused", reason }` | A frame that is not JSON, fails its schema or has an unknown `type`, or a request that failed. The `id` is there when one could be read. Also pushed unasked, without an `id`, when a re-read after a change on disk fails, such as the folder being deleted. The socket stays open |
182
+ | backend to client | `{ type: "collection", collection }` | A file the collection reads changed on disk, whoever changed it. The whole view is sent again |
183
+ | backend to client | `{ type: "run.output", run, line: { stream, text } }` | One line a run wrote, on `stdout` or `stderr`, sent to every socket |
184
+ | backend to client | `{ type: "run.ended", run, exitCode, outcome?, produced?, edge? }` | A run ended. `exitCode` is `null` when it was cancelled, and then the rest is absent. Otherwise `outcome` is the agent's verdict, `produced` lists each file produce as `{ name, found }`, and `edge` is the `{ from, to, on }` the outcome takes (none from a terminal node) |
130
185
 
131
186
  A new request type is one schema in `src/protocol.ts` and one handler in the table in `src/backend/requests.ts`.
132
187
 
133
188
  ### The collection view
134
189
 
135
- `collectionView(files, hostKeys)` is pure and takes `{ path, text }` values. It answers plain JSON: `lines`, `agents`, `refused` and `counts`. The backend adds `folder`, the name of the collection's folder, to what it sends. A node that names a `fanout` carries it as `fanout: { over, to }`. Its types are in `src/view.ts` and exported from the protocol.
190
+ `collectionView(files, hostKeys)` is pure and takes `{ path, text }` values. It answers plain JSON: `lines`, `agents`, `refused` and `counts`. The backend adds `folder`, the name of the collection's folder, to what it sends. A node that names a `fanout` carries it as `fanout: { over, to }`. The types are in `src/view.ts` and exported from the protocol.
136
191
 
137
- - A line with problems is still a line. It is read on its own, so a line the collection's overlay would refuse for its problems appears with `problems` listing each one: `rule`, the `node` when there is one, and the `message`. The rules of the lint and the floor's own check of a line body are both there, and a fault they both name is listed once, as the lint's rule.
138
- - A file that cannot be read at all, such as YAML that does not parse, an agent file with no frontmatter, or a `pipeline.yaml` beside an `assembly-line.yaml`, is in `refused` with its path and the reason. The other files still draw.
139
- - Settings are shown as the file writes them: `${NAME}` is not filled from the environment.
140
- - Each node holds its station's `kind`, `description`, `outcomes`, `needs` and `produces`, each need with its `coverage` from `needCoverage`, each produce with `readBy`, the nodes downstream of it (by `downstreamOf`) whose station needs it, its `events` from `nodeEvents`, and, for an agent station whose agent a file defines, `agent` and the `placeholders` of that agent's prompt from `promptPlaceholders`.
192
+ - An assembly line with problems is still shown. Each assembly line is read on its own, so one the collection's overlay would refuse appears with `problems` listing each one: `rule`, the `node` when there is one, and the `message`. The rules of the lint and the floor's own check of a line body are both there. A fault they both name is listed once, as the lint's rule.
193
+ - A file that cannot be read at all is in `refused` with its path and the reason. Examples are YAML that does not parse, an agent file with no frontmatter, or a `pipeline.yaml` beside an `assembly-line.yaml`. The other files still draw.
194
+ - Settings are shown as the file writes them. `${NAME}` is not filled from the environment.
195
+ - Each node holds its station's `kind`, `description`, `outcomes`, `needs` and `produces`. Each need has its `coverage` from `needCoverage`. Each produce has `readBy`, the nodes downstream of it (by `downstreamOf`) whose station needs it. The node has its `events` from `nodeEvents`. For an agent station whose agent a file defines, it also has `agent` and the `placeholders` of that agent's prompt from `promptPlaceholders`.
141
196
 
142
197
  ## Security
143
198
 
144
- The backend writes files and starts processes, so no web page may reach it. Three rules hold it shut.
199
+ The backend writes files and starts processes, so no web page may reach it. Three rules keep it shut.
145
200
 
146
201
  - It listens on `127.0.0.1` and never on `0.0.0.0`.
147
202
  - A random token of 256 bits is made at start. A socket is accepted only when its url carries `?token=<token>`, compared in constant time. Without it the upgrade is refused with 401.
148
- - A browser always sends an `Origin`. A socket that has one is accepted only when it is in the `origins` list given to `startStudio`; the shell passes the origin of its own page, as `127.0.0.1` and as `localhost` on the same port. Any other origin is refused with 403, whatever the token. A client that sends no `Origin` is not a browser, and the token is enough.
203
+ - A browser always sends an `Origin`. A socket that has one is accepted only when it is in the `origins` list given to `startStudio`. The shell passes the origin of its own page, as `127.0.0.1` and as `localhost` on the same port. Any other origin is refused with 403, whatever the token. A client that sends no `Origin` is not a browser, and the token is enough.
149
204
 
150
205
  A refused upgrade gets no socket at all.
151
206
 
152
207
  ## Change watching
153
208
 
154
- The backend watches `dir` with `fs.watch` and `recursive: true`. It ignores a path the collection does not read and anything under a dot folder, waits about 100 ms for the changes to settle, then pushes one `collection` frame to every open socket, or one `refused` frame without an `id` when the read fails. A file that is deleted or renamed is handled the same way. A watcher error does not stop the backend.
209
+ The backend watches `dir` with `fs.watch` and `recursive: true`. It ignores a path the collection does not read and anything under a dot folder. It waits about 100 ms for the changes to settle, then pushes one `collection` frame to every open socket, or one `refused` frame without an `id` when the read fails. A file that is deleted or renamed is handled the same way. A watcher error does not stop the backend.
@@ -1,3 +1,3 @@
1
1
  import { type CollectionFile } from "@re-cinq/floor-pipeline";
2
2
  import type { CollectionView } from "../view.js";
3
- export declare function collectionView(files: readonly CollectionFile[], hostKeys: readonly string[]): CollectionView;
3
+ export declare function collectionView(files: readonly CollectionFile[], hostKeys: readonly string[], groups?: readonly string[]): CollectionView;
@@ -1,6 +1,6 @@
1
1
  // The studio's picture of a collection: every line with its nodes, every agent, and what was refused. Pure and tolerant: a collection with problems still has a view, and nothing a person wrote makes it throw.
2
2
  import { coverageContextOf, downstreamOf, needCoverage, nodeEvents, promptPlaceholders } from "@re-cinq/floor-assembly-lines";
3
- import { attempt, collectionOverlay, pipelineFolderOf } from "@re-cinq/floor-pipeline";
3
+ import { attempt, collectionOverlay, lineFolderPathOf, lineLayoutOf, withoutReplacedFiles } from "@re-cinq/floor-pipeline";
4
4
  import { textVersion } from "./agent-file-text.js";
5
5
  import { agentFilesByName, agentViews } from "./agent-views.js";
6
6
  import { present } from "./present.js";
@@ -9,26 +9,18 @@ import { readLine } from "./read-line.js";
9
9
  const AS_WRITTEN = new Proxy({}, { get: (...given) => `\${${String(given[1])}}` });
10
10
  /** Nothing is shipped: the studio shows the collection on its own. */
11
11
  const NOTHING_SHIPPED = { pipelines: [], agents: new Map() };
12
- export function collectionView(files, hostKeys) {
13
- const overlay = collectionOverlay({ files, shipped: NOTHING_SHIPPED, env: AS_WRITTEN, hostKeys });
14
- const lineFiles = lineFilesOf(files);
12
+ export function collectionView(files, hostKeys, groups = []) {
13
+ const readFiles = withoutReplacedFiles(files, groups);
14
+ const overlay = collectionOverlay({ files: readFiles, shipped: NOTHING_SHIPPED, env: AS_WRITTEN, hostKeys, groups });
15
+ const lineFiles = lineLayoutOf(readFiles).read;
15
16
  const reads = lineFiles.map((file) => attempt(file.path, () => readLine(file, file.folder, promptsOf(overlay.agents))));
16
17
  const read = reads.flatMap((result) => ("made" in result ? [result.made] : []));
17
- const surroundings = { lines: read.map(({ id, body }) => ({ id, body })), agents: overlay.agents, agentFiles: agentFilesByName(files), files };
18
+ const surroundings = { lines: read.map(({ id, body }) => ({ id, body })), agents: overlay.agents, agentFiles: agentFilesByName(readFiles), files: readFiles };
18
19
  const views = read.map((line) => attempt(line.file, () => lineViewOf(line, surroundings)));
19
20
  const lines = views.flatMap((result) => ("made" in result ? [result.made] : []));
20
21
  const refused = refusedOf(overlay, { lineFiles, failures: [...reads, ...views] });
21
22
  return { lines, agents: agentViews(overlay.agents, surroundings.agentFiles, lines), refused, counts: countsOf(lines, overlay, refused) };
22
23
  }
23
- /** The line files that are read: a folder's former `pipeline.yaml` beside its `assembly-line.yaml` is the overlay's to refuse. */
24
- function lineFilesOf(files) {
25
- const named = files.flatMap((file) => {
26
- const folder = pipelineFolderOf(file.path);
27
- return folder ? [{ ...file, folder }] : [];
28
- });
29
- const foldersWithCurrentName = new Set(named.filter((file) => file.path.endsWith("/assembly-line.yaml")).map((file) => file.folder));
30
- return named.filter((file) => file.path.endsWith("/assembly-line.yaml") || !foldersWithCurrentName.has(file.folder)).sort((left, right) => left.path.localeCompare(right.path));
31
- }
32
24
  function promptsOf(agents) {
33
25
  return new Map([...agents].map(([name, agent]) => [name, agent.settings.prompt]));
34
26
  }
@@ -59,7 +51,7 @@ function nodeViewOf(node, line, surroundings, needContext) {
59
51
  };
60
52
  }
61
53
  function extraOf(agentName, line, files) {
62
- const file = `${pipelineFolderOf(line.file)}/agents/${agentName}.extra.md`;
54
+ const file = `${lineFolderPathOf(line.file)}/agents/${agentName}.extra.md`;
63
55
  const text = agentName === undefined ? undefined : files.find((candidate) => candidate.path === file)?.text;
64
56
  return text === undefined ? {} : { extra: { file, text, version: textVersion(text) } };
65
57
  }
@@ -18,7 +18,7 @@ export const runStartHandler = {
18
18
  const record = { lines: [] };
19
19
  context.runs.set(run, record);
20
20
  await context.writeRun(run, record);
21
- const running = runProcess({ command: preview.command, folder: request.folder, env: context.runEnv }, (line) => {
21
+ const running = runProcess({ command: preview.command, folder: request.folder, env: { ...preview.env, ...context.runEnv } }, (line) => {
22
22
  appendLine(record, line);
23
23
  context.broadcast({ type: "run.output", run, line });
24
24
  });
@@ -4,7 +4,7 @@ import { readFile, stat, writeFile } from "node:fs/promises";
4
4
  import { createServer } from "node:http";
5
5
  import { basename, join, resolve } from "node:path";
6
6
  import { enforce } from "@re-cinq/floor-assembly-lines";
7
- import { collectionFilesIn, hostKeysIn, readAgentFile } from "@re-cinq/floor-pipeline";
7
+ import { collectionFilesIn, collectionSettingsIn, hostKeysIn, readAgentFile } from "@re-cinq/floor-pipeline";
8
8
  import { WebSocket, WebSocketServer } from "ws";
9
9
  import { PROTOCOL_VERSION } from "../protocol.js";
10
10
  import { collectionView } from "./collection-view.js";
@@ -28,7 +28,7 @@ export async function startStudio(options) {
28
28
  const token = randomBytes(TOKEN_BYTES).toString("hex");
29
29
  const sockets = new WebSocketServer({ noServer: true, maxPayload: MAX_FRAME_BYTES });
30
30
  const allHostKeys = async () => [...hostKeys, ...(await hostKeysIn(dir))];
31
- const readCollection = async () => collectionRead(dir, await allHostKeys());
31
+ const readCollection = () => collectionRead(dir, hostKeys);
32
32
  const writeAgent = async (file, edit) => {
33
33
  const path = join(dir, file);
34
34
  const text = editedAgentText(file, await readFile(path, "utf8"), edit);
@@ -55,7 +55,8 @@ export async function startStudio(options) {
55
55
  }
56
56
  async function collectionRead(dir, hostKeys) {
57
57
  const files = (await collectionFilesIn(dir)).filter((file) => !isSkillPath(file.path));
58
- return { ...collectionView(files, hostKeys), folder: basename(resolve(dir)), skills: await skillNamesIn(dir), environment: environmentOf(files) };
58
+ const settings = await collectionSettingsIn(dir);
59
+ return { ...collectionView(files, [...hostKeys, ...settings.hostKeys], settings.groups), folder: basename(resolve(dir)), skills: await skillNamesIn(dir), environment: environmentOf(files) };
59
60
  }
60
61
  async function writeExtraFile(path, { text, version }) {
61
62
  enforce(version === textVersion(await readFile(path, "utf8")), `${basename(path)} changed on disk since it was read`);
@@ -216,6 +216,7 @@ export declare const runEndedFrame: z.ZodObject<{
216
216
  to: z.ZodString;
217
217
  on: z.ZodString;
218
218
  iterationMax: z.ZodOptional<z.ZodNumber>;
219
+ unattendedMax: z.ZodOptional<z.ZodNumber>;
219
220
  }, z.core.$strict>>;
220
221
  }, z.core.$strict>;
221
222
  export declare const serverFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -256,6 +257,7 @@ export declare const serverFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
256
257
  to: z.ZodString;
257
258
  on: z.ZodString;
258
259
  iterationMax: z.ZodOptional<z.ZodNumber>;
260
+ unattendedMax: z.ZodOptional<z.ZodNumber>;
259
261
  }, z.core.$strict>>;
260
262
  }, z.core.$strict>], "type">;
261
263
  export type ServerFrame = z.infer<typeof serverFrameSchema>;
package/dist/protocol.js CHANGED
@@ -73,7 +73,7 @@ export const runEndedFrame = z.strictObject({ type: z.literal("run.ended"), run:
73
73
  exitCode: z.number().nullable(),
74
74
  outcome: z.string().optional(),
75
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(),
76
+ edge: z.strictObject({ from: z.string(), to: z.string(), on: z.string(), iterationMax: z.number().optional(), unattendedMax: z.number().optional() }).optional(),
77
77
  });
78
78
  export const serverFrameSchema = z.discriminatedUnion("type", [helloFrame, resultFrame, refusedFrame, collectionFrame, runOutputFrame, runEndedFrame]);
79
79
  //# sourceMappingURL=protocol.js.map
@@ -2,10 +2,11 @@ const permissionFlags = {
2
2
  acceptEdits: ["--permission-mode", "acceptEdits"],
3
3
  bypass: ["--dangerously-skip-permissions"],
4
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). */
5
6
  function claudeCommand({ settings, prompt, permission }) {
6
7
  const disallowedTools = settings.disallowedTools ?? [];
7
8
  const maxTurns = settings.maxTurns && settings.maxTurns > 0 ? String(settings.maxTurns) : undefined;
8
- return ["claude", "--print", "--verbose", "--output-format", "stream-json", ...optionalFlag("--model", settings.model), ...permissionFlags[permission], ...disallowedTools.flatMap((tool) => ["--disallowedTools", tool]), ...optionalFlag("--max-turns", maxTurns), "--", prompt];
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];
9
10
  }
10
11
  function optionalFlag(flag, value) {
11
12
  return value ? [flag, value] : [];
@@ -4,7 +4,9 @@ interface RunOutcomeInput {
4
4
  lines: RunLine[];
5
5
  station: StationBody;
6
6
  }
7
+ /** The outcome the agent reported, and its final answer. */
7
8
  export declare function runOutcome({ lines, station }: RunOutcomeInput): {
8
9
  outcome: string;
10
+ answer?: string;
9
11
  };
10
12
  export {};
@@ -1,8 +1,10 @@
1
1
  // Reads how an agent run ended from the final "result" line of its stream-json transcript.
2
2
  import { readAgentVerdict, requiredVerdict } from "@re-cinq/floor-assembly-lines";
3
+ /** The outcome the agent reported, and its final answer. */
3
4
  export function runOutcome({ lines, station }) {
4
- const verdict = requiredVerdict(readAgentVerdict(finalAgentText(lines), station.outcomes), station);
5
- return { outcome: verdict.outcome };
5
+ const answer = finalAgentText(lines);
6
+ const verdict = requiredVerdict(readAgentVerdict(answer, station.outcomes), station);
7
+ return { outcome: verdict.outcome, answer };
6
8
  }
7
9
  function finalAgentText(lines) {
8
10
  const results = lines
@@ -6,6 +6,7 @@ export interface StationSettings {
6
6
  config?: {
7
7
  max_turns?: number;
8
8
  disallowed_tools?: string[];
9
+ env?: Record<string, string>;
9
10
  };
10
11
  }
11
12
  export interface RunPreviewInput {
@@ -22,5 +23,7 @@ export interface RunPreview {
22
23
  copies: NeedCopy[];
23
24
  links: NeedLink[];
24
25
  blockers: string[];
26
+ /** The agent's `config.env`, laid over the studio's environment for the run. */
27
+ env: Record<string, string>;
25
28
  }
26
29
  export declare function runPreview({ station, prompt, settings, fixture, folder, permission }: RunPreviewInput): RunPreview;
@@ -6,11 +6,18 @@ import { vendorOf } from "./vendor.js";
6
6
  import { workspaceOf } from "./workspace.js";
7
7
  export function runPreview({ station, prompt, settings, fixture, folder, permission }) {
8
8
  const { parameters, copies, links, missing } = workspaceOf({ station, fixture, folder });
9
- const rendered = renderPrompt(prompt, parameters);
9
+ const rendered = inFolder(renderPrompt(prompt, parameters), folder);
10
10
  const vendor = vendorOf(settings.model ?? "");
11
11
  const unrunnable = runnableVendors.includes(vendor) ? [] : [unrunnableBlocker(settings.model ?? "", vendor)];
12
12
  const command = unrunnable.length ? [] : agentCommand({ vendor, settings: commandSettingsOf(settings), prompt: rendered, permission });
13
- return { prompt: rendered, command, copies, links, blockers: [...missing.map((name) => `"${name}" has no value`), ...unrunnable, ...relativeFolderBlockers(folder)] };
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 ?? {};
14
21
  }
15
22
  function relativeFolderBlockers(folder) {
16
23
  return isAbsolute(folder) ? [] : [`the folder must be an absolute path: ${folder}`];
@@ -2,8 +2,10 @@ import type { StationBody } from "@re-cinq/floor-contracts";
2
2
  interface ProducesFoundInput {
3
3
  station: StationBody;
4
4
  folder: string;
5
+ /** The agent's final answer, which a produce `from: output` holds. */
6
+ answer?: string;
5
7
  }
6
- export declare function producesFound({ station, folder }: ProducesFoundInput): Promise<{
8
+ export declare function producesFound({ station, folder, answer }: ProducesFoundInput): Promise<{
7
9
  name: string;
8
10
  found: boolean;
9
11
  }[]>;
@@ -1,11 +1,13 @@
1
- // Checks which declared file produces of a station exist in the run folder.
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.
2
2
  import { access } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
- export function producesFound({ station, folder }) {
5
- const fileProduces = station.produces.filter((produce) => produce.kind === "file" && produce.path);
6
- return Promise.all(fileProduces.map(async ({ name, path }) => ({
7
- name,
8
- found: await access(join(folder, path)).then(() => true, () => false),
9
- })));
4
+ export function producesFound({ station, folder, answer }) {
5
+ const checked = station.produces.filter((produce) => produce.kind === "file" && (produce.path || produce.from === "output"));
6
+ return Promise.all(checked.map(async (produce) => ({ name: produce.name, found: await isFound(produce, folder, answer) })));
7
+ }
8
+ function isFound(produce, folder, answer) {
9
+ if (produce.from === "output")
10
+ return Promise.resolve(Boolean(answer?.trim()));
11
+ return access(join(folder, produce.path)).then(() => true, () => false);
10
12
  }
11
13
  //# sourceMappingURL=run-produces.js.map
@@ -4,7 +4,7 @@ import { producesFound } from "./run-produces.js";
4
4
  export async function runResult({ exitCode, lines, station, line, node, folder }) {
5
5
  if (exitCode === null)
6
6
  return {};
7
- const { outcome } = runOutcome({ lines, station });
8
- return { outcome, produced: await producesFound({ station, folder }), edge: edgeTaken({ line, node, outcome }) };
7
+ const { outcome, answer } = runOutcome({ lines, station });
8
+ return { outcome, produced: await producesFound({ station, folder, answer }), edge: edgeTaken({ line, node, outcome }) };
9
9
  }
10
10
  //# sourceMappingURL=run-result.js.map