@re-cinq/floor-pipeline 0.5.6 → 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 (41) hide show
  1. package/README.md +97 -31
  2. package/dist/agent-config-schema.d.ts +46 -0
  3. package/dist/agent-config-schema.js +45 -0
  4. package/dist/cli.js +30 -10
  5. package/dist/collection/agent-file.d.ts +36 -0
  6. package/dist/collection/agent-file.js +41 -0
  7. package/dist/collection/agents.d.ts +29 -0
  8. package/dist/collection/agents.js +54 -0
  9. package/dist/collection/apply.d.ts +8 -0
  10. package/dist/collection/apply.js +27 -0
  11. package/dist/collection/collection.d.ts +17 -0
  12. package/dist/collection/collection.js +28 -0
  13. package/dist/collection/enforce.d.ts +1 -0
  14. package/dist/collection/enforce.js +6 -0
  15. package/dist/collection/environment.d.ts +6 -0
  16. package/dist/collection/environment.js +28 -0
  17. package/dist/collection/graph-rules.d.ts +7 -0
  18. package/dist/collection/graph-rules.js +102 -0
  19. package/dist/collection/lint-directory.d.ts +32 -0
  20. package/dist/collection/lint-directory.js +67 -0
  21. package/dist/collection/lint-rules.d.ts +5 -0
  22. package/dist/collection/lint-rules.js +115 -0
  23. package/dist/collection/lint-shape.d.ts +89 -0
  24. package/dist/collection/lint-shape.js +99 -0
  25. package/dist/collection/lint-supply.d.ts +20 -0
  26. package/dist/collection/lint-supply.js +99 -0
  27. package/dist/collection/paths.d.ts +18 -0
  28. package/dist/collection/paths.js +28 -0
  29. package/dist/collection/pipelines.d.ts +8 -0
  30. package/dist/collection/pipelines.js +56 -0
  31. package/dist/collection/refusal.d.ts +11 -0
  32. package/dist/collection/refusal.js +11 -0
  33. package/dist/file.d.ts +2 -2
  34. package/dist/file.js +22 -9
  35. package/dist/floor-given.d.ts +2 -0
  36. package/dist/floor-given.js +8 -0
  37. package/dist/index.d.ts +12 -2
  38. package/dist/index.js +12 -2
  39. package/dist/shape.d.ts +4 -0
  40. package/dist/shape.js +2 -0
  41. package/package.json +8 -2
package/README.md CHANGED
@@ -2,41 +2,40 @@
2
2
 
3
3
  A pipeline as one file: an assembly line with its stations, its agent definitions and their prompts, its files and its schedules. One file is one pipeline, and holds everything the pipeline needs that a file can hold.
4
4
 
5
- The tool speaks the HTTP API of a [floor](https://github.com/re-cinq/floor) and nothing else. It is a client like any other, with the service token.
6
-
7
5
  ```
8
6
  npm install @re-cinq/floor-pipeline # the command is floor-pipeline
9
7
 
10
8
  export FLOOR_SERVICE_TOKEN=...
9
+ export FLOOR_API_URL=http://localhost:8180
11
10
 
12
- floor-pipeline export code-review --floor http://localhost:8180 > code-review.yaml
13
- floor-pipeline export --all --dir backup/ --floor http://localhost:8180
14
- floor-pipeline import code-review.yaml --floor http://localhost:8180
15
- floor-pipeline migrate pipelines/ --floor http://localhost:8180
11
+ floor-pipeline export code-review > code-review.yaml
12
+ floor-pipeline export --all --dir backup/
13
+ floor-pipeline import code-review.yaml
14
+ floor-pipeline migrate pipelines/
16
15
  floor-pipeline migrate pipelines/ --floor http://floor-api:8080 --wait-ready 180
17
16
  ```
18
17
 
18
+ `--floor <url>` names the floor for one call and wins over `FLOOR_API_URL`, the name a station's worker reads too.
19
+
19
20
  | command | what it does |
20
21
  |---|---|
21
- | `export <line>` | writes the line's latest version, and what it names, as one file |
22
- | `export --all --dir <dir>` | one file a line, named after it: a backup |
23
- | `import <file>...` | puts each file to the floor. The same file twice changes nothing: a version is its content |
24
- | `migrate <dir>` | the folder's files in the order of their names, each once |
25
- | `--wait-ready <seconds>` | first polls the floor's `/readyz` until it answers 200, and fails, naming the floor and the seconds, if it does not in time. For a job that starts with the floor, such as the chart's seed Job |
22
+ | `export <line>` | Writes the assembly line's latest version, and what it names, as one file |
23
+ | `export --all --dir <dir>` | One file per assembly line, named after it: a backup |
24
+ | `import <file>...` | Puts each file to the floor. The same file twice changes nothing, because a version is its content |
25
+ | `migrate <dir>` | Runs the folder's files in the order of their names, each once |
26
+ | `--wait-ready <seconds>` | First polls the floor's `/readyz` until it answers 200. If it does not in time, it fails, naming the floor and the seconds. For a job that starts with the floor, such as the chart's seed Job |
26
27
 
27
28
  ## Where this fits
28
29
 
29
- A client and nothing more: it speaks the floor's HTTP API with a service token, exactly as lore or
30
- a worker does, and links none of floor's own packages. Where
31
- [`@floor/lore-converter`](https://github.com/re-cinq/floor/blob/main/packages/lore-converter/README.md) brings an assembly line *in* from lore, this
32
- moves a whole pipeline between a file and a floor — to review it, to keep it in git, or to put the
33
- same one into another floor. It moves definitions only; assembly runs stay where they happened.
30
+ The tool is a client of a [floor](https://github.com/re-cinq/floor) and nothing more. It speaks the floor's HTTP API with a service token, as lore or a worker does, and links none of floor's own packages.
31
+
32
+ [`@floor/lore-converter`](https://github.com/re-cinq/floor/blob/main/packages/lore-converter/README.md) brings an assembly line in from lore. This tool moves a whole pipeline between a file and a floor, to review it, to keep it in git, or to put the same one into another floor. It moves definitions only. Assembly runs stay where they happened.
34
33
 
35
34
  See [the map](https://github.com/re-cinq/floor/blob/main/README.md).
36
35
 
37
36
  ## The file
38
37
 
39
- YAML, in `snake_case`, as the docs write definitions. Every prompt is in it, as the block it is.
38
+ The file is YAML in `snake_case`, as the docs write definitions. Every prompt is in it as a block.
40
39
 
41
40
  ```yaml
42
41
  line:
@@ -76,19 +75,86 @@ schedules:
76
75
  nightly: { cron: "0 3 * * *", payload: { pr_url: https://pr/1 } }
77
76
  ```
78
77
 
79
- - **A line may name a `fail` node beside its `exit`**: `fail: failed`, with `- { id: failed }` among its nodes. A run that an edge leads there settles as `failed`. Written back, it comes right after `exit`.
80
- - **The floor's own fields change spelling**, `timeout_minutes` to `timeoutMinutes`. Names a person chose do not: a model's name, a repository's, a key of `config` or of `env`.
81
- - **A file a line ships is in the file by its content.** Text as it is; anything else as `{ base64: ... }`. The floor keeps it by its hash, and a hash is no backup.
82
- - **A station two lines use is in both files.** Put twice with the same content, it is one version.
83
- - **What is exported is what runs now**: each definition's latest version. Older versions stay on the floor and are not in the file.
78
+ - An assembly line may name a `fail` node beside its `exit`: `fail: failed`, with `- { id: failed }` among its nodes. An assembly run that an edge leads there settles as `failed`. Written back, `fail` comes right after `exit`.
79
+ - The floor's own fields change spelling, `timeout_minutes` to `timeoutMinutes`. Names a person chose do not: a model's name, a repository's, a key of `config` or of `env`.
80
+ - A file an assembly line ships is in the pipeline file by its content. Text is kept as it is, anything else as `{ base64: ... }`. The floor keeps it by its hash, and a hash is no backup.
81
+ - A station two assembly lines use is in both files. Put twice with the same content, it is one version.
82
+ - What is exported is what runs now, which is each definition's latest version. Older versions stay on the floor and are not in the file.
84
83
 
85
84
  ## What a file cannot hold
86
85
 
87
86
  | | where it is |
88
87
  |---|---|
89
- | Secrets: a model's key, an MCP server's token | in the cluster's `agent-secrets`. A definition names the key, and never the value |
90
- | The program behind a service station | wherever it runs. The file declares the station; the program that posts a review is lore's |
91
- | Runs, visits, their records and costs | in the floor's database. This is a backup of what a floor is told to do, and not of what it did |
88
+ | Secrets: a model's key, an MCP server's token | In the cluster's `agent-secrets`. A definition names the key, and never the value |
89
+ | The program behind a service station | Wherever it runs. The file declares the station. The program that posts a review is lore's |
90
+ | Runs, visits, their records and costs | In the floor's database. This is a backup of what a floor is told to do, and not of what it did |
91
+
92
+ ## A collection
93
+
94
+ A collection is a folder of assembly lines. Each one has its own folder, with its pipeline and its agents. An agent is a markdown file: the frontmatter holds its settings, and the body is its prompt. A file named `<agent>.extra.md` adds to the prompt of an agent the host already ships.
95
+
96
+ ```
97
+ code-review/
98
+ assembly-line.yaml
99
+ agents/
100
+ reviewer.md
101
+ reviewer.extra.md
102
+ ```
103
+
104
+ With Claude Code, the [floor skills](https://re-cinq.github.io/floor/reference/skills/) write these files and run `lint` after every change.
105
+
106
+ ### lint
107
+
108
+ `lint` checks a collection without a floor and without a token.
109
+
110
+ ```
111
+ floor-pipeline lint collection/ --host-key execution_mode
112
+ ```
113
+
114
+ A key that belongs to the host is named in the collection's `floor-collection.yaml` (`host_keys: [execution_mode]`), or with `--host-key`, as often as needed. `lint` and `apply` use both.
115
+
116
+ `lint` asks the same questions the floor asks of an assembly line, through [`@re-cinq/floor-assembly-lines`](../assembly-lines/README.md). Two of its rules:
117
+
118
+ - `unseeded-need` is a need that is neither a line argument or file nor produced on every path into its node. Its message gives one path that arrives without it.
119
+ - `unsupplied-input` is a `{name}` in an agent's prompt that the station does not give.
120
+
121
+ What a station gives a prompt:
122
+
123
+ | source | placeholder |
124
+ |---|---|
125
+ | a value need | `{name}` |
126
+ | a file or git need, and a produce with a path | `{name_path}` |
127
+ | the floor | `{run_id}`, `{line_id}`, `{node_id}` |
128
+ | the floor, for a retry or a fan-out branch | `{previous_error}`, `{previous_failures}`, `{item}` |
129
+ | the floor, for a station with a git need | `{git_credential}`, `{git_credential_url}` |
130
+
131
+ A prompt's `{name}` is made of letters, digits, `_`, `.` and `-`, and starts with a letter or `_`, so a JSON object in a prompt is never read as one.
132
+
133
+ A collection may extend an agent the host ships with an `.extra.md` file, or name a shipped agent without defining it. Without the host's catalog `lint` refuses both. `--shipped <dir>` names a directory in the same layout, whose assembly lines and agents are the shipped ones.
134
+
135
+ ```
136
+ floor-pipeline lint collection/ --shipped shipped/ --host-key execution_mode
137
+ ```
138
+
139
+ A refused file prints one line and the exit code is 1. A call with no directory prints the usage and the exit code is 2.
140
+
141
+ ```
142
+ code-review/assembly-line.yml: a collection does not read this path: a line folder holds assembly-line.yaml, agents/<agent>.md and agents/<agent>.extra.md
143
+ ```
144
+
145
+ A clean collection prints a summary and the exit code is 0.
146
+
147
+ ```
148
+ collection ok: 1 agents, 1 pipelines, 0 extensions
149
+ ```
150
+
151
+ ### apply
152
+
153
+ `apply` puts a collection to a floor: its agents, then each assembly line with its stations. `${NAME}` in its files is filled from the environment. When a file is refused, nothing is put.
154
+
155
+ ```
156
+ floor-pipeline apply collection/
157
+ ```
92
158
 
93
159
  ## Migrations
94
160
 
@@ -102,10 +168,10 @@ pipelines/
102
168
  0004-remove-gap-fill.yaml archive: { lines: [gap-fill] }
103
169
  ```
104
170
 
105
- - **The floor remembers which files ran**, by name and by the sha256 of what they held: `GET /migrations`.
106
- - **A file that ran is not run again.** So what a person changes over HTTP stays, until a later file changes that pipeline.
107
- - **A file that ran and was changed since is refused.** What it did is done. A change is a new file.
108
- - **A file the floor refused is not remembered**, and runs when it is mended.
109
- - **A pipeline leaves as it came, by a file**: `archive` names the lines, stations, agent definitions and schedules to archive. The floor refuses to archive a line with open runs.
171
+ - The floor remembers which files ran, by name and by the sha256 of what they held: `GET /migrations`.
172
+ - A file that ran is not run again. So what a person changes over HTTP stays, until a later file changes that pipeline.
173
+ - A file that ran and was changed since is refused. What it did is done. A change is a new file.
174
+ - A file the floor refused is not remembered, and runs when it is mended.
175
+ - A pipeline leaves as it came, by a file. `archive` names the assembly lines, stations, agent definitions and schedules to archive. The floor refuses to archive an assembly line with open runs.
110
176
 
111
- A file is several requests, and not one: a file the floor refuses half way has put what came before. Putting is safe to repeat, so the mended file puts the rest.
177
+ A file is several requests, so a file the floor refuses half way has put what came before. Putting is safe to repeat, so the mended file puts the rest.
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ export declare const agentConfigSchema: z.ZodObject<{
3
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
4
+ skills_source: z.ZodOptional<z.ZodURL>;
5
+ mcp_servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
6
+ name: z.ZodString;
7
+ transport: z.ZodEnum<{
8
+ http: "http";
9
+ sse: "sse";
10
+ stdio: "stdio";
11
+ }>;
12
+ command: z.ZodOptional<z.ZodString>;
13
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
+ url: z.ZodOptional<z.ZodURL>;
15
+ headers_secret: z.ZodOptional<z.ZodString>;
16
+ headers: z.ZodOptional<z.ZodArray<z.ZodObject<{
17
+ name: z.ZodString;
18
+ ref: z.ZodString;
19
+ }, z.core.$strip>>>;
20
+ env: z.ZodOptional<z.ZodArray<z.ZodObject<{
21
+ name: z.ZodString;
22
+ ref: z.ZodString;
23
+ }, z.core.$strip>>>;
24
+ }, z.core.$strip>>>;
25
+ disallowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
27
+ permission_mode: z.ZodOptional<z.ZodEnum<{
28
+ auto: "auto";
29
+ bypass: "bypass";
30
+ }>>;
31
+ max_turns: z.ZodOptional<z.ZodNumber>;
32
+ model_secret_key: z.ZodOptional<z.ZodString>;
33
+ pod_resources: z.ZodOptional<z.ZodObject<{
34
+ requests: z.ZodOptional<z.ZodObject<{
35
+ cpu: z.ZodOptional<z.ZodString>;
36
+ memory: z.ZodOptional<z.ZodString>;
37
+ "ephemeral-storage": z.ZodOptional<z.ZodString>;
38
+ }, z.core.$strict>>;
39
+ limits: z.ZodOptional<z.ZodObject<{
40
+ cpu: z.ZodOptional<z.ZodString>;
41
+ memory: z.ZodOptional<z.ZodString>;
42
+ "ephemeral-storage": z.ZodOptional<z.ZodString>;
43
+ }, z.core.$strict>>;
44
+ }, z.core.$strict>>;
45
+ }, z.core.$loose>;
46
+ export type AgentConfig = z.infer<typeof agentConfigSchema>;
@@ -0,0 +1,45 @@
1
+ // The schema of an agent definition's `config`, under the names the agent file specification gives them (website/src/content/docs/specs/agent-file.md, "2.2 Config"), which are lore's own. Pure zod, so the browser can import it.
2
+ import { z } from "zod";
3
+ // A header or env var the server needs, valued from the key `ref` of the cluster's agent-secrets.
4
+ const secretRef = z.object({
5
+ name: z.string().min(1).describe("The name of the header or environment variable."),
6
+ ref: z.string().min(1).describe("The key in `agent-secrets`, the Kubernetes Secret in the agents' namespace, whose value it gets."),
7
+ });
8
+ // One of the two ways to reach a server, never neither: a process the pod starts, or an address it calls.
9
+ const mcpServer = z
10
+ .object({
11
+ name: z.string().min(1).describe("The name the agent knows the server by."),
12
+ transport: z.enum(["stdio", "http", "sse"]).describe("How the server is reached. `stdio` is a process the pod starts. `http` and `sse` are an address it calls."),
13
+ command: z.string().min(1).describe("`stdio` only, and required there. The command that starts the server.").optional(),
14
+ args: z.array(z.string()).describe("`stdio` only. The command's arguments.").optional(),
15
+ url: z.url().describe("`http` and `sse` only, and required there. The server's address.").optional(),
16
+ headers_secret: z.string().min(1).describe("The key in `agent-secrets`, the Kubernetes Secret in the agents' namespace, holding one whole header line, such as `Authorization: Bearer <token>`.").optional(),
17
+ headers: z.array(secretRef).describe("`http` and `sse` only. Headers sent to the server, each taking its value from a key in `agent-secrets`.").optional(),
18
+ env: z.array(secretRef).describe("`stdio` only. Environment variables of the server's process, each taking its value from a key in `agent-secrets`.").optional(),
19
+ })
20
+ .refine((server) => (server.transport === "stdio" ? Boolean(server.command) : Boolean(server.url)), {
21
+ message: "a stdio server needs a command, any other a url",
22
+ });
23
+ const KUBERNETES_QUANTITY = /^\d+(\.\d+)?(m|k|M|G|T|Ki|Mi|Gi|Ti)?$/;
24
+ const quantity = z.string().regex(KUBERNETES_QUANTITY, "a Kubernetes quantity such as 250m, 1, 512Mi or 2Gi");
25
+ const resourceQuantities = z.strictObject({
26
+ cpu: quantity.describe("A Kubernetes quantity, such as `500m`.").optional(),
27
+ memory: quantity.describe("A Kubernetes quantity, such as `2Gi`.").optional(),
28
+ "ephemeral-storage": quantity.describe("A Kubernetes quantity, such as `6Gi`.").optional(),
29
+ });
30
+ const podResources = z.strictObject({
31
+ requests: resourceQuantities.describe("What the pod asks for.").optional(),
32
+ limits: resourceQuantities.describe("What the pod may not exceed.").optional(),
33
+ });
34
+ export const agentConfigSchema = z.looseObject({
35
+ skills: z.array(z.string()).describe("Names of the skills the agent is given.").optional(),
36
+ skills_source: z.url().describe("The address the pod downloads the agent's skills from, usually the host's skills service. Without it the pod asks the floor, which has no skills to give.").optional(),
37
+ mcp_servers: z.array(mcpServer).describe("The MCP servers the agent can call.").optional(),
38
+ disallowed_tools: z.array(z.string()).describe("Tools the agent may not use.").optional(),
39
+ env: z.record(z.string(), z.string()).describe("Environment variables of the agent, as plain values.").optional(),
40
+ permission_mode: z.enum(["auto", "bypass"]).describe("`bypass` (the default) lets the agent run any tool without asking. `auto` keeps the CLI's own permission checks, so in the pod, where nobody can answer, an action that needs approval is refused.").optional(),
41
+ max_turns: z.number().int().positive().describe("The most turns the agent takes in one visit.").optional(),
42
+ model_secret_key: z.string().min(1).describe("Which key in `agent-secrets`, the Kubernetes Secret in the agents' namespace, holds the model's API key. Without it, the key the install sets for the model's family is used.").optional(),
43
+ pod_resources: podResources.describe("The resources of the agent's container. With none, the cluster's default applies.").optional(),
44
+ });
45
+ //# sourceMappingURL=agent-config-schema.js.map
package/dist/cli.js CHANGED
@@ -5,32 +5,45 @@ import { join } from "node:path";
5
5
  import { parseArgs } from "node:util";
6
6
  import { exportPipeline, lineIds } from "./export.js";
7
7
  import { readPipelineFile, writePipelineFile } from "./file.js";
8
+ import { floorGiven } from "./floor-given.js";
8
9
  import { importPipeline } from "./import.js";
9
10
  import { migrate } from "./migrate.js";
11
+ import { applyCollection } from "./collection/apply.js";
12
+ import { lintCommand, readCollectionDirectory } from "./collection/lint-directory.js";
10
13
  import { waitUntilReady } from "./ready.js";
11
14
  import { fileOf, pipelineOf } from "./shape.js";
12
15
  const USAGE = `floor-pipeline <what to do> --floor <url> with FLOOR_SERVICE_TOKEN
16
+ --floor may be left out when FLOOR_API_URL names the floor
13
17
 
14
18
  export <line> one pipeline, written to standard output, or to --out <file>
15
19
  export --all --dir <dir> every pipeline, one file each, named after its line: a backup
16
20
  import <file>... puts each file to the floor. The same file twice changes nothing
17
21
  migrate <dir> the folder's files in the order of their names, each once.
18
22
  The floor remembers which ran
23
+ apply <dir> puts a collection to the floor: its agents, then each line with its stations.
24
+ \${NAME} in its files is filled from this environment. Nothing is put
25
+ when a file is refused
26
+ lint <dir> checks a collection: one folder a line, with its assembly-line.yaml and agents/.
27
+ Needs no floor and no token. A key the host owns is named with --host-key <name>,
28
+ as often as needed. The agents and lines the host ships are a directory in the
29
+ same layout, named with --shipped <dir>. Exits 2 when no directory is given
19
30
 
20
31
  --wait-ready <seconds> first waits up to that long for the floor's /readyz to answer 200,
21
32
  for a job that starts with the floor`;
22
- const OPTIONS = { floor: { type: "string" }, out: { type: "string" }, dir: { type: "string" }, all: { type: "boolean" }, "wait-ready": { type: "string" } };
33
+ const OPTIONS = { floor: { type: "string" }, out: { type: "string" }, dir: { type: "string" }, all: { type: "boolean" }, "wait-ready": { type: "string" }, "host-key": { type: "string", multiple: true }, shipped: { type: "string" } };
23
34
  function given() {
24
35
  return parseArgs({ options: OPTIONS, allowPositionals: true });
25
36
  }
26
37
  async function main() {
27
38
  const told = given();
28
39
  const [command = ""] = told.positionals;
29
- const commands = { export: exported, import: imported, migrate: migrated };
40
+ if (command === "lint")
41
+ return linted(told);
42
+ const commands = { export: exported, import: imported, migrate: migrated, apply: applied };
30
43
  const run = commands[command];
31
44
  if (!run)
32
45
  throw new Error(USAGE);
33
- const floor = floorOf(told);
46
+ const floor = floorGiven(told.values.floor, process.env, USAGE);
34
47
  await waitedFor(floor, told.values["wait-ready"]);
35
48
  await run(floor, told);
36
49
  }
@@ -42,13 +55,6 @@ async function waitedFor(floor, waitReady) {
42
55
  throw new Error(`--wait-ready is a number of seconds above 0, and not "${waitReady}"`);
43
56
  await waitUntilReady({ floorUrl: floor.url, seconds });
44
57
  }
45
- function floorOf(told) {
46
- const token = process.env.FLOOR_SERVICE_TOKEN;
47
- const url = told.values.floor;
48
- if (!url || !token)
49
- throw new Error(`a floor is named with --floor, and reached with FLOOR_SERVICE_TOKEN\n\n${USAGE}`);
50
- return { url: url.replace(/\/$/, ""), token };
51
- }
52
58
  async function exported(floor, told) {
53
59
  const [, line] = told.positionals;
54
60
  if (told.values.all)
@@ -84,6 +90,20 @@ async function migrated(floor, told) {
84
90
  const all = await migrate(floor, files);
85
91
  all.forEach((each) => (each.ran ? said(each.name, each.put) : console.log(`${each.name}: ran before`)));
86
92
  }
93
+ async function applied(floor, told) {
94
+ const [, dir] = told.positionals;
95
+ if (!dir)
96
+ throw new Error(USAGE);
97
+ const overlay = await readCollectionDirectory(dir, { hostKeys: told.values["host-key"] ?? [], env: process.env });
98
+ const refusals = overlay.refused.map(({ path, reason }) => `${path}: ${reason}`);
99
+ if (refusals.length > 0)
100
+ throw new Error(refusals.join("\n"));
101
+ said(dir, await applyCollection(floor, overlay));
102
+ }
103
+ async function linted(told) {
104
+ const [, directory] = told.positionals;
105
+ process.exitCode = await lintCommand({ directory, hostKeys: told.values["host-key"] ?? [], shippedDirectory: told.values.shipped }, USAGE, { out: console.log, err: console.error });
106
+ }
87
107
  function said(file, put) {
88
108
  console.log(`${file}:`);
89
109
  put.forEach((each) => console.log(` ${each.kind}/${each.id}: ${each.changed ? "changed" : "as it was"}`));
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ /** Strict, unlike the stored config: a misspelled key in a file is a bug to fail on, not a field to carry. What `config` may hold is the floor's to say, when the agent is put. */
3
+ export declare const agentFrontmatterSchema: z.ZodObject<{
4
+ model: z.ZodOptional<z.ZodString>;
5
+ image: z.ZodOptional<z.ZodString>;
6
+ timeout_minutes: z.ZodOptional<z.ZodNumber>;
7
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
+ prices: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
9
+ input_per_million: z.ZodNumber;
10
+ output_per_million: z.ZodNumber;
11
+ cache_read_per_million: z.ZodOptional<z.ZodNumber>;
12
+ cache_write_per_million: z.ZodOptional<z.ZodNumber>;
13
+ }, z.core.$strict>>>;
14
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
15
+ }, z.core.$strict>;
16
+ type Frontmatter = z.infer<typeof agentFrontmatterSchema>;
17
+ export interface ParsedAgentFile {
18
+ name: string;
19
+ frontmatter: Frontmatter;
20
+ /** As written, host keys included: the validated copy reorders config's keys, and the floor is handed the file's order. */
21
+ written: Record<string, unknown>;
22
+ prompt: string | null;
23
+ }
24
+ /** The settings block of an agent definition, as a pipeline file holds it. */
25
+ export type AgentFileSettings = Pick<Frontmatter, "model" | "image" | "timeout_minutes" | "tags" | "prices" | "config"> & {
26
+ prompt: string | null;
27
+ };
28
+ /** The agents a host ships, by name, their settings as the files write them. */
29
+ export type ShippedAgents = ReadonlyMap<string, AgentFileSettings>;
30
+ /** The prompt of each agent a pipeline can name. */
31
+ export type AgentPrompts = ReadonlyMap<string, string | null>;
32
+ /** A key in `hostKeys` is the host's own: accepted with any value, kept in `written`, and never in the settings. */
33
+ export declare function readAgentFile(name: string, text: string, hostKeys?: readonly string[]): ParsedAgentFile;
34
+ /** The keys a pipeline file's `settings` held, in the file's order. A key the file leaves out stays out. */
35
+ export declare function floorSettingsOf(file: ParsedAgentFile): AgentFileSettings;
36
+ export {};
@@ -0,0 +1,41 @@
1
+ // One agent file: `<name>.md`, its frontmatter the agent's settings, its body its prompt.
2
+ import { parse as parseYaml } from "yaml";
3
+ import { z } from "zod";
4
+ import { enforce } from "./enforce.js";
5
+ const perMillion = z.number();
6
+ const price = z.strictObject({
7
+ input_per_million: perMillion.describe("US dollars for a million input tokens."),
8
+ output_per_million: perMillion.describe("US dollars for a million output tokens."),
9
+ cache_read_per_million: perMillion.describe("US dollars for a million tokens read from the cache. The input price when not stated.").optional(),
10
+ cache_write_per_million: perMillion.describe("US dollars for a million tokens written to the cache. The input price when not stated.").optional(),
11
+ });
12
+ /** Strict, unlike the stored config: a misspelled key in a file is a bug to fail on, not a field to carry. What `config` may hold is the floor's to say, when the agent is put. */
13
+ export const agentFrontmatterSchema = z.strictObject({
14
+ model: z.string().describe("The model the agent runs on.").optional(),
15
+ image: z.string().describe("The container image the agent runs in. Required in a file that defines an agent.").optional(),
16
+ timeout_minutes: z.number().int().positive().describe("How long a visit may run, in minutes. Required in a file that defines an agent.").optional(),
17
+ tags: z.array(z.string()).describe("Which cluster agents may run it. A cluster agent claims a visit only when it offers every tag.").optional(),
18
+ prices: z.record(z.string(), price).describe("Model name to what it costs, for a model that reports tokens and no cost.").optional(),
19
+ config: z.record(z.string(), z.unknown()).describe("Settings for the agent's pod. A key the floor does not know is kept and not acted on.").optional(),
20
+ });
21
+ const FRONTMATTER = /^---\n([\s\S]*?)\n---(?:\n|$)/;
22
+ /** A key in `hostKeys` is the host's own: accepted with any value, kept in `written`, and never in the settings. */
23
+ export function readAgentFile(name, text, hostKeys = []) {
24
+ const match = FRONTMATTER.exec(text);
25
+ enforce(match, `${name}.md: missing the --- frontmatter block`);
26
+ const written = (parseYaml(match[1]) ?? {});
27
+ const body = text.slice(match[0].length);
28
+ return { name, frontmatter: validated(name, written, hostKeys), written, prompt: body === "" ? null : body };
29
+ }
30
+ function validated(name, written, hostKeys) {
31
+ const own = Object.fromEntries(Object.entries(written).filter(([key]) => !hostKeys.includes(key)));
32
+ const parsed = agentFrontmatterSchema.safeParse(own);
33
+ enforce(parsed.success, `${name}.md: ${parsed.success ? "" : z.prettifyError(parsed.error)}`);
34
+ return parsed.data;
35
+ }
36
+ const SETTINGS_KEYS = new Set(["model", "image", "timeout_minutes", "tags", "prices", "config"]);
37
+ /** The keys a pipeline file's `settings` held, in the file's order. A key the file leaves out stays out. */
38
+ export function floorSettingsOf(file) {
39
+ return { ...Object.fromEntries(Object.entries(file.written).filter(([key]) => SETTINGS_KEYS.has(key))), prompt: file.prompt };
40
+ }
41
+ //# sourceMappingURL=agent-file.js.map
@@ -0,0 +1,29 @@
1
+ import { type AgentFileSettings, type ShippedAgents } from "./agent-file.js";
2
+ import { type Environment } from "./environment.js";
3
+ import { type CollectionFile } from "./paths.js";
4
+ import { type Refusal } from "./refusal.js";
5
+ export interface ShippedCatalog {
6
+ /** The names of the pipelines the host ships. */
7
+ pipelines: readonly string[];
8
+ /** The shipped agents, their settings as the md files write them (environment not yet filled in). */
9
+ agents: ShippedAgents;
10
+ }
11
+ export interface CollectionOverlayInput {
12
+ files: readonly CollectionFile[];
13
+ shipped: ShippedCatalog;
14
+ env: Environment;
15
+ /** Frontmatter keys that are the host's own: accepted in an agent file, and never in its settings. */
16
+ hostKeys?: readonly string[];
17
+ }
18
+ export type AgentSource = "collection-new" | "replaced" | "extended";
19
+ export interface OverlayAgent {
20
+ settings: AgentFileSettings;
21
+ source: AgentSource;
22
+ }
23
+ /** The agents the collection sets, the first file to name an agent winning. */
24
+ export declare function agentsOverlay(input: CollectionOverlayInput): {
25
+ agents: Map<string, OverlayAgent>;
26
+ refused: Refusal[];
27
+ };
28
+ /** A shipped agent's prompt with the collection's extension appended. */
29
+ export declare function extendedPrompt(base: string, extra: string): string;
@@ -0,0 +1,54 @@
1
+ // The agents a collection sets: a full definition replaces or adds one, an extension appends to a shipped agent's prompt.
2
+ import { floorSettingsOf, readAgentFile } from "./agent-file.js";
3
+ import { settingsWithEnvironment } from "./environment.js";
4
+ import { enforce } from "./enforce.js";
5
+ import { agentFileOf } from "./paths.js";
6
+ import { attempt } from "./refusal.js";
7
+ const REQUIRED_SETTINGS = ["image", "timeout_minutes", "prompt"];
8
+ /** The agents the collection sets, the first file to name an agent winning. */
9
+ export function agentsOverlay(input) {
10
+ const agents = new Map();
11
+ const setBy = new Map();
12
+ const refused = [];
13
+ for (const file of agentFilesOf(input.files)) {
14
+ const result = attempt(file.path, () => agentOf(file, input, setBy));
15
+ if ("refusal" in result) {
16
+ refused.push(result.refusal);
17
+ continue;
18
+ }
19
+ agents.set(file.agent, result.made);
20
+ setBy.set(file.agent, file.path);
21
+ }
22
+ return { agents, refused };
23
+ }
24
+ /** A shipped agent's prompt with the collection's extension appended. */
25
+ export function extendedPrompt(base, extra) {
26
+ return `${base}\n\n${extra}`;
27
+ }
28
+ function agentFilesOf(files) {
29
+ const agentFiles = [...files]
30
+ .sort((left, right) => left.path.localeCompare(right.path))
31
+ .flatMap((file) => {
32
+ const named = agentFileOf(file.path);
33
+ return named ? [{ ...file, ...named }] : [];
34
+ });
35
+ // A full definition goes first, so an extension of the same agent is the one refused.
36
+ return [...agentFiles.filter((file) => !file.isExtension), ...agentFiles.filter((file) => file.isExtension)];
37
+ }
38
+ function agentOf(file, { shipped, env, hostKeys }, setBy) {
39
+ const base = shipped.agents.get(file.agent);
40
+ enforce(!setBy.has(file.agent), `${file.agent} is already set by ${setBy.get(file.agent)}`);
41
+ return file.isExtension ? extendedAgent(file, base, env) : definedAgent(file, base, env, hostKeys);
42
+ }
43
+ function extendedAgent(file, base, env) {
44
+ enforce(base, `an extension needs a shipped agent, and nothing ships ${file.agent}`);
45
+ return { source: "extended", settings: settingsWithEnvironment({ ...base, prompt: extendedPrompt(base.prompt ?? "", file.text) }, env) };
46
+ }
47
+ function definedAgent(file, base, env, hostKeys) {
48
+ const settings = floorSettingsOf(readAgentFile(file.agent, file.text, hostKeys));
49
+ for (const field of REQUIRED_SETTINGS) {
50
+ enforce(settings[field], `${file.agent} has no ${field}, and a full agent definition needs a prompt, an image and timeout_minutes`);
51
+ }
52
+ return { source: base ? "replaced" : "collection-new", settings: settingsWithEnvironment(settings, env) };
53
+ }
54
+ //# sourceMappingURL=agents.js.map
@@ -0,0 +1,8 @@
1
+ import { type Floor } from "../floor.js";
2
+ import { type Put } from "../import.js";
3
+ import { type Fields, type Named } from "../shape.js";
4
+ import type { OverlayAgent } from "./agents.js";
5
+ import type { CollectionOverlay } from "./collection.js";
6
+ export declare function applyCollection(floor: Floor, overlay: Pick<CollectionOverlay, "agents" | "pipelines">): Promise<Put[]>;
7
+ /** Each agent's settings as the floor spells them, over what the floor holds for it: a collection sets an agent's settings, and a repository's variant is not its to take away. */
8
+ export declare function agentDefinitionsOf(agents: ReadonlyMap<string, OverlayAgent>, held: ReadonlyMap<string, Fields>): Named[];
@@ -0,0 +1,27 @@
1
+ // A collection, put to a floor: its agents first, then each line with its stations, since the floor refuses a station naming an agent it does not have. Putting the same collection twice changes nothing.
2
+ import { asked } from "../floor.js";
3
+ import { importPipeline } from "../import.js";
4
+ import { pipelineOf } from "../shape.js";
5
+ const NOTHING_ELSE = { files: {}, stations: [], schedules: [], archive: { lines: [], stations: [], agentDefinitions: [], schedules: [] } };
6
+ export async function applyCollection(floor, overlay) {
7
+ const agentDefinitions = agentDefinitionsOf(overlay.agents, await heldDefinitions(floor, [...overlay.agents.keys()]));
8
+ const agents = await importPipeline(floor, { ...NOTHING_ELSE, agentDefinitions });
9
+ const lines = [];
10
+ // One after another, in the order of their folders: a line may name a station an earlier folder defines.
11
+ for (const pipeline of overlay.pipelines)
12
+ lines.push(...(await importPipeline(floor, withoutAgents(pipeline))));
13
+ return [...agents, ...lines];
14
+ }
15
+ /** Each agent's settings as the floor spells them, over what the floor holds for it: a collection sets an agent's settings, and a repository's variant is not its to take away. */
16
+ export function agentDefinitionsOf(agents, held) {
17
+ const written = Object.fromEntries([...agents].map(([name, agent]) => [name, { settings: agent.settings }]));
18
+ return pipelineOf({ agent_definitions: written }).agentDefinitions.map(({ id, body }) => ({ id, body: { ...held.get(id), settings: body.settings } }));
19
+ }
20
+ function withoutAgents(pipeline) {
21
+ return { ...pipeline, agentDefinitions: [] };
22
+ }
23
+ async function heldDefinitions(floor, names) {
24
+ const rows = await Promise.all(names.map(async (name) => asked(floor, { method: "GET", path: `/agent-definitions/${name}` })));
25
+ return new Map(names.flatMap((name, index) => (rows[index] ? [[name, rows[index].body]] : [])));
26
+ }
27
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1,17 @@
1
+ import type { Pipeline } from "../shape.js";
2
+ import { type CollectionOverlayInput, type OverlayAgent } from "./agents.js";
3
+ import type { Refusal } from "./refusal.js";
4
+ export type { AgentSource, CollectionOverlayInput, OverlayAgent, ShippedCatalog } from "./agents.js";
5
+ export type { CollectionFile } from "./paths.js";
6
+ export type { Refusal } from "./refusal.js";
7
+ export interface CollectionOverlay {
8
+ agents: Map<string, OverlayAgent>;
9
+ pipelines: Pipeline[];
10
+ counts: {
11
+ agents: number;
12
+ pipelines: number;
13
+ extensions: number;
14
+ };
15
+ refused: Refusal[];
16
+ }
17
+ export declare function collectionOverlay(input: CollectionOverlayInput): CollectionOverlay;
@@ -0,0 +1,28 @@
1
+ import { agentsOverlay } from "./agents.js";
2
+ import { pipelinesOverlay } from "./pipelines.js";
3
+ import { isReadPath } from "./paths.js";
4
+ export function collectionOverlay(input) {
5
+ const agentsSet = agentsOverlay(input);
6
+ const pipelinesSet = pipelinesOverlay(input, agentsSet.agents);
7
+ const { agents } = agentsSet;
8
+ const { pipelines } = pipelinesSet;
9
+ return {
10
+ agents,
11
+ pipelines,
12
+ refused: byPath([...agentsSet.refused, ...pipelinesSet.refused, ...unreadPathsOf(input)]),
13
+ counts: { agents: agents.size, pipelines: pipelines.length, extensions: extensionsIn(agents) },
14
+ };
15
+ }
16
+ function extensionsIn(agents) {
17
+ return [...agents.values()].filter((agent) => agent.source === "extended").length;
18
+ }
19
+ const UNREAD_PATH = "a collection does not read this path: a line folder holds assembly-line.yaml, agents/<agent>.md and agents/<agent>.extra.md";
20
+ /** A file in a line folder that would be skipped in silence: a misspelt name must show, not quietly do nothing. */
21
+ function unreadPathsOf({ files }) {
22
+ const unread = files.filter((file) => !isReadPath(file.path));
23
+ return unread.map((file) => ({ path: file.path, reason: UNREAD_PATH }));
24
+ }
25
+ function byPath(refused) {
26
+ return refused.sort((left, right) => left.path.localeCompare(right.path));
27
+ }
28
+ //# sourceMappingURL=collection.js.map
@@ -0,0 +1 @@
1
+ export declare function enforce(condition: unknown, message: string): asserts condition;
@@ -0,0 +1,6 @@
1
+ // A bouncer for a condition: either it holds, or the message is thrown.
2
+ export function enforce(condition, message) {
3
+ if (!condition)
4
+ throw new Error(message);
5
+ }
6
+ //# sourceMappingURL=enforce.js.map
@@ -0,0 +1,6 @@
1
+ import type { AgentFileSettings } from "./agent-file.js";
2
+ export type Environment = Record<string, string | undefined>;
3
+ /** The names a text asks for, each once, in the order they first appear. */
4
+ export declare function placeholdersIn(text: string): string[];
5
+ export declare function withEnvironment(yamlText: string, env: Environment): string;
6
+ export declare function settingsWithEnvironment(settings: unknown, env: Environment): AgentFileSettings;