@re-cinq/floor-pipeline 0.5.5 → 0.6.1

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 +51 -4
  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
@@ -0,0 +1,28 @@
1
+ // The layout of a collection: `<line>/assembly-line.yaml`, `<line>/agents/<agent>.md` and `<line>/agents/<agent>.extra.md`. A line folder written before the file was renamed holds `pipeline.yaml`, which is read as the same thing.
2
+ /** The host's own top folders: the skills it serves its agents, not lines. */
3
+ const HOST_FOLDERS = ["skills", "agent-skills"];
4
+ const FOLDER = String.raw `(?!\.\.?\/)(?!(?:${HOST_FOLDERS.join("|")})\/)[^/]+`;
5
+ const PIPELINE_FILE = new RegExp(String.raw `^(${FOLDER})\/(assembly-line|pipeline)\.yaml$`);
6
+ /** The name a line's file has. */
7
+ export const LINE_FILE = "assembly-line.yaml";
8
+ /** The name it had, still read. */
9
+ export const FORMER_LINE_FILE = "pipeline.yaml";
10
+ const AGENT_FILE = new RegExp(String.raw `^${FOLDER}\/agents\/([^/]+?)(\.extra)?\.md$`);
11
+ /** The line folder a line's file sits in. */
12
+ export function pipelineFolderOf(path) {
13
+ return PIPELINE_FILE.exec(path)?.[1];
14
+ }
15
+ export function agentFileOf(path) {
16
+ const match = AGENT_FILE.exec(path);
17
+ return match ? { agent: match[1], isExtension: Boolean(match[2]) } : undefined;
18
+ }
19
+ /** A markdown or YAML file inside a line folder: read, or refused as a path a collection does not read. A file at the top, under `docs/`, under a host folder or under a dot folder is not the collection's. */
20
+ const LINE_FOLDER_FILE = new RegExp(String.raw `^(?!(?:docs|${HOST_FOLDERS.join("|")})\/)[^./][^/]*\/.+\.(md|ya?ml)$`);
21
+ export function isCollectionFile(path) {
22
+ return LINE_FOLDER_FILE.test(path);
23
+ }
24
+ /** A path a collection reads: a pipeline or an agent file. */
25
+ export function isReadPath(path) {
26
+ return pipelineFolderOf(path) !== undefined || agentFileOf(path) !== undefined;
27
+ }
28
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1,8 @@
1
+ import type { CollectionOverlayInput, OverlayAgent } from "./agents.js";
2
+ import { type Refusal } from "./refusal.js";
3
+ import { type Pipeline } from "../shape.js";
4
+ /** The pipelines the collection sets, its own and its versions of the lines the host ships. Each names its agents only: the agents are put on their own, so a pipeline is imported with no agent definitions of its own. */
5
+ export declare function pipelinesOverlay(input: CollectionOverlayInput, collectionAgents: ReadonlyMap<string, OverlayAgent>): {
6
+ pipelines: Pipeline[];
7
+ refused: Refusal[];
8
+ };
@@ -0,0 +1,56 @@
1
+ import { withEnvironment } from "./environment.js";
2
+ import { enforce } from "./enforce.js";
3
+ import { pipelineProblems } from "./lint-rules.js";
4
+ import { FORMER_LINE_FILE, LINE_FILE, pipelineFolderOf } from "./paths.js";
5
+ import { attempt } from "./refusal.js";
6
+ import { readPipelineFile } from "../file.js";
7
+ import { pipelineOf } from "../shape.js";
8
+ /** The pipelines the collection sets, its own and its versions of the lines the host ships. Each names its agents only: the agents are put on their own, so a pipeline is imported with no agent definitions of its own. */
9
+ export function pipelinesOverlay(input, collectionAgents) {
10
+ const pipelines = [];
11
+ const refused = [];
12
+ const lineFiles = pipelineFilesOf(input.files);
13
+ const superseded = supersededBy(lineFiles);
14
+ for (const file of lineFiles) {
15
+ const result = attempt(file.path, () => {
16
+ enforce(!superseded.has(file.path), `the folder ${file.folder} holds its line twice: ${LINE_FILE} is read, so remove ${FORMER_LINE_FILE}`);
17
+ return pipelineOfFile(file, input, collectionAgents);
18
+ });
19
+ if ("refusal" in result) {
20
+ refused.push(result.refusal);
21
+ continue;
22
+ }
23
+ pipelines.push(result.made);
24
+ }
25
+ return { pipelines, refused };
26
+ }
27
+ // The former name's file, in a folder that holds the line under its name too: two files would be two versions of one line.
28
+ function supersededBy(lineFiles) {
29
+ const named = new Set(lineFiles.filter((file) => file.path.endsWith(`/${LINE_FILE}`)).map((file) => file.folder));
30
+ const former = lineFiles.filter((file) => file.path.endsWith(`/${FORMER_LINE_FILE}`) && named.has(file.folder));
31
+ return new Set(former.map((file) => file.path));
32
+ }
33
+ function pipelineFilesOf(files) {
34
+ return files
35
+ .flatMap((file) => {
36
+ const folder = pipelineFolderOf(file.path);
37
+ return folder ? [{ ...file, folder }] : [];
38
+ })
39
+ .sort((left, right) => left.path.localeCompare(right.path));
40
+ }
41
+ function pipelineOfFile(file, { shipped, env }, collectionAgents) {
42
+ const filled = withEnvironment(file.text, env);
43
+ enforceNoProblems(filled, promptsOf(shipped.agents, collectionAgents));
44
+ const pipeline = pipelineOf(readPipelineFile(filled));
45
+ enforce(pipeline.line?.id === file.folder, `the folder ${file.folder} must hold the pipeline of that name, and its line is ${pipeline.line?.id}`);
46
+ return pipeline;
47
+ }
48
+ function enforceNoProblems(yamlText, prompts) {
49
+ const problems = pipelineProblems(yamlText, prompts);
50
+ enforce(problems.length === 0, problems.map((problem) => problem.detail).join("; "));
51
+ }
52
+ /** The prompts a pipeline can name: the shipped agents' and the collection's own. */
53
+ function promptsOf(shipped, collectionAgents) {
54
+ return new Map([...[...shipped].map(([name, agent]) => [name, agent.prompt]), ...[...collectionAgents].map(([name, agent]) => [name, agent.settings.prompt])]);
55
+ }
56
+ //# sourceMappingURL=pipelines.js.map
@@ -0,0 +1,11 @@
1
+ export interface Refusal {
2
+ path: string;
3
+ reason: string;
4
+ }
5
+ export type Attempt<Made> = {
6
+ made: Made;
7
+ } | {
8
+ refusal: Refusal;
9
+ };
10
+ /** Runs what builds one file's part of the overlay: a file that cannot be built is refused and the others still are. */
11
+ export declare function attempt<Made>(path: string, build: () => Made): Attempt<Made>;
@@ -0,0 +1,11 @@
1
+ /** Runs what builds one file's part of the overlay: a file that cannot be built is refused and the others still are. */
2
+ export function attempt(path, build) {
3
+ try {
4
+ return { made: build() };
5
+ }
6
+ catch (cause) {
7
+ const reason = cause instanceof Error ? cause.message : String(cause);
8
+ return { refusal: { path, reason } };
9
+ }
10
+ }
11
+ //# sourceMappingURL=refusal.js.map
package/dist/file.d.ts CHANGED
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  declare const content: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
4
4
  base64: z.ZodString;
5
5
  }, z.core.$strict>]>;
6
- declare const pipelineFile: z.ZodObject<{
6
+ export declare const pipelineFileSchema: z.ZodObject<{
7
7
  line: z.ZodOptional<z.ZodObject<{
8
8
  id: z.ZodString;
9
9
  files: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
@@ -20,7 +20,7 @@ declare const pipelineFile: z.ZodObject<{
20
20
  schedules: z.ZodOptional<z.ZodArray<z.ZodString>>;
21
21
  }, z.core.$strict>>;
22
22
  }, z.core.$strict>;
23
- export type PipelineFile = z.infer<typeof pipelineFile>;
23
+ export type PipelineFile = z.infer<typeof pipelineFileSchema>;
24
24
  export type FileContent = z.infer<typeof content>;
25
25
  export declare function readPipelineFile(text: string): PipelineFile;
26
26
  /** A prompt is written as the block it is, and no line is folded: a prompt's line breaks are the prompt's. */
package/dist/file.js CHANGED
@@ -5,17 +5,30 @@ const fields = z.record(z.string(), z.unknown());
5
5
  const named = z.record(z.string(), fields);
6
6
  const names = z.array(z.string());
7
7
  /** Text as it is; anything else as base64. */
8
- const content = z.union([z.string(), z.strictObject({ base64: z.string() })]);
9
- const pipelineFile = z.strictObject({
10
- line: z.looseObject({ id: z.string().min(1), files: z.record(z.string(), content).optional() }).optional(),
11
- stations: named.optional(),
12
- agent_definitions: named.optional(),
13
- schedules: named.optional(),
14
- /** What this file takes away: a pipeline that is no longer wanted leaves by a file, as it came. */
15
- archive: z.strictObject({ lines: names.optional(), stations: names.optional(), agent_definitions: names.optional(), schedules: names.optional() }).optional(),
8
+ const content = z.union([z.string(), z.strictObject({ base64: z.string().describe("The file's bytes, in base64.") })]);
9
+ export const pipelineFileSchema = z.strictObject({
10
+ line: z
11
+ .looseObject({
12
+ id: z.string().min(1).describe("The line's id. In a collection it equals the name of the folder the file is in."),
13
+ files: z.record(z.string(), content).describe("Files put in the bag of every run at its start, by item name. A file is written as its text, or as `{ base64: ... }` for bytes that are not text.").optional(),
14
+ })
15
+ .describe("The assembly line. A file with none carries only stations, agent definitions, schedules or an archive.")
16
+ .optional(),
17
+ stations: named.describe("The stations, by id.").optional(),
18
+ agent_definitions: named.describe("The agent definitions, by id. A collection refuses this block and defines each agent in its own file.").optional(),
19
+ schedules: named.describe("The schedules, by name. Each sends the event `schedule.<name>.tick`.").optional(),
20
+ archive: z
21
+ .strictObject({
22
+ lines: names.describe("Ids of lines to archive.").optional(),
23
+ stations: names.describe("Ids of stations to archive.").optional(),
24
+ agent_definitions: names.describe("Ids of agent definitions to archive.").optional(),
25
+ schedules: names.describe("Names of schedules to archive.").optional(),
26
+ })
27
+ .describe("What importing this file takes away from the floor.")
28
+ .optional(),
16
29
  });
17
30
  export function readPipelineFile(text) {
18
- const read = pipelineFile.safeParse(parse(text));
31
+ const read = pipelineFileSchema.safeParse(parse(text));
19
32
  if (read.success)
20
33
  return read.data;
21
34
  const { issues } = read.error;
@@ -0,0 +1,2 @@
1
+ import type { Floor } from "./floor.js";
2
+ export declare function floorGiven(flag: string | undefined, env: Record<string, string | undefined>, usage: string): Floor;
@@ -0,0 +1,8 @@
1
+ export function floorGiven(flag, env, usage) {
2
+ const url = flag ?? env.FLOOR_API_URL;
3
+ const token = env.FLOOR_SERVICE_TOKEN;
4
+ if (!url || !token)
5
+ throw new Error(`a floor is named with --floor or FLOOR_API_URL, and reached with FLOOR_SERVICE_TOKEN\n\n${usage}`);
6
+ return { url: url.replace(/\/$/, ""), token };
7
+ }
8
+ //# sourceMappingURL=floor-given.js.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,16 @@
1
- export { readPipelineFile, writePipelineFile, type PipelineFile } from "./file.js";
2
- export { fileOf, pipelineOf, type Pipeline } from "./shape.js";
1
+ export { pipelineFileSchema, readPipelineFile, writePipelineFile, type PipelineFile } from "./file.js";
2
+ export { agentConfigSchema, type AgentConfig } from "./agent-config-schema.js";
3
+ export { FILE_SPELLING, fileOf, pipelineOf, type Pipeline } from "./shape.js";
3
4
  export { exportPipeline, lineIds } from "./export.js";
4
5
  export { importPipeline, type Put } from "./import.js";
5
6
  export { migrate, type Migrated, type MigrationFile } from "./migrate.js";
6
7
  export type { Floor } from "./floor.js";
8
+ export { collectionOverlay, type CollectionFile, type CollectionOverlay, type CollectionOverlayInput, type OverlayAgent, type AgentSource, type ShippedCatalog, type Refusal } from "./collection/collection.js";
9
+ export { attempt, type Attempt } from "./collection/refusal.js";
10
+ export { applyCollection } from "./collection/apply.js";
11
+ export { collectionFilesIn, COLLECTION_SETTINGS_FILE, hostKeysIn, lintCollectionDirectory, lintCommand, printCollectionLint, readCollectionDirectory, shippedCatalogIn, type LintCommand } from "./collection/lint-directory.js";
12
+ export { agentFrontmatterSchema, readAgentFile, floorSettingsOf, type ParsedAgentFile, type AgentFileSettings, type ShippedAgents, type AgentPrompts } from "./collection/agent-file.js";
13
+ export { placeholdersIn, withEnvironment, settingsWithEnvironment, type Environment } from "./collection/environment.js";
14
+ export { PIPELINE_RULES, pipelineProblems, type PipelineProblem, type PipelineRule } from "./collection/lint-rules.js";
15
+ export { agentFileOf, isCollectionFile, isReadPath, pipelineFolderOf } from "./collection/paths.js";
16
+ export { extendedPrompt } from "./collection/agents.js";
package/dist/index.js CHANGED
@@ -1,6 +1,16 @@
1
- export { readPipelineFile, writePipelineFile } from "./file.js";
2
- export { fileOf, pipelineOf } from "./shape.js";
1
+ export { pipelineFileSchema, readPipelineFile, writePipelineFile } from "./file.js";
2
+ export { agentConfigSchema } from "./agent-config-schema.js";
3
+ export { FILE_SPELLING, fileOf, pipelineOf } from "./shape.js";
3
4
  export { exportPipeline, lineIds } from "./export.js";
4
5
  export { importPipeline } from "./import.js";
5
6
  export { migrate } from "./migrate.js";
7
+ export { collectionOverlay } from "./collection/collection.js";
8
+ export { attempt } from "./collection/refusal.js";
9
+ export { applyCollection } from "./collection/apply.js";
10
+ export { collectionFilesIn, COLLECTION_SETTINGS_FILE, hostKeysIn, lintCollectionDirectory, lintCommand, printCollectionLint, readCollectionDirectory, shippedCatalogIn } from "./collection/lint-directory.js";
11
+ export { agentFrontmatterSchema, readAgentFile, floorSettingsOf } from "./collection/agent-file.js";
12
+ export { placeholdersIn, withEnvironment, settingsWithEnvironment } from "./collection/environment.js";
13
+ export { PIPELINE_RULES, pipelineProblems } from "./collection/lint-rules.js";
14
+ export { agentFileOf, isCollectionFile, isReadPath, pipelineFolderOf } from "./collection/paths.js";
15
+ export { extendedPrompt } from "./collection/agents.js";
6
16
  //# sourceMappingURL=index.js.map
package/dist/shape.d.ts CHANGED
@@ -19,6 +19,10 @@ export interface Pipeline {
19
19
  schedules: Named[];
20
20
  archive: Archive;
21
21
  }
22
+ type Spelling = Record<string, string>;
23
+ /** Every field the file spells its own way, floor's name to the file's: what a reference of the file is written in. */
24
+ export declare const FILE_SPELLING: Spelling;
22
25
  export declare function pipelineOf(file: PipelineFile): Pipeline;
23
26
  /** What is empty is left out: a file says what a pipeline has. */
24
27
  export declare function fileOf(pipeline: Pipeline): PipelineFile;
28
+ export {};
package/dist/shape.js CHANGED
@@ -4,6 +4,8 @@ const AS_THE_FLOOR_SPELLS = {
4
4
  settings: { timeout_minutes: "timeoutMinutes" },
5
5
  price: { input_per_million: "inputPerMillion", output_per_million: "outputPerMillion", cache_read_per_million: "cacheReadPerMillion", cache_write_per_million: "cacheWritePerMillion" },
6
6
  };
7
+ /** Every field the file spells its own way, floor's name to the file's: what a reference of the file is written in. */
8
+ export const FILE_SPELLING = turned({ ...AS_THE_FLOOR_SPELLS.edge, ...AS_THE_FLOOR_SPELLS.station, ...AS_THE_FLOOR_SPELLS.settings, ...AS_THE_FLOOR_SPELLS.price });
7
9
  const AS_THE_FILE_SPELLS = {
8
10
  edge: turned(AS_THE_FLOOR_SPELLS.edge),
9
11
  station: turned(AS_THE_FLOOR_SPELLS.station),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@re-cinq/floor-pipeline",
3
- "version": "0.5.5",
3
+ "version": "0.6.1",
4
4
  "description": "A floor's pipeline as one YAML file: an assembly line with its stations, its agent definitions and their prompts, its files and its schedules. Exports one from a floor, imports one into a floor, and applies a folder of them in order, each once. It speaks the floor's HTTP API and nothing else.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -29,6 +29,10 @@
29
29
  ".": {
30
30
  "types": "./dist/index.d.ts",
31
31
  "default": "./dist/index.js"
32
+ },
33
+ "./agent-config": {
34
+ "types": "./dist/agent-config-schema.d.ts",
35
+ "default": "./dist/agent-config-schema.js"
32
36
  }
33
37
  },
34
38
  "files": [
@@ -49,7 +53,9 @@
49
53
  "typecheck": "tsc --noEmit"
50
54
  },
51
55
  "dependencies": {
52
- "@re-cinq/floor-client": "0.5.5",
56
+ "@re-cinq/floor-assembly-lines": "0.6.1",
57
+ "@re-cinq/floor-client": "0.6.1",
58
+ "@re-cinq/floor-contracts": "0.6.1",
53
59
  "yaml": "^2.7.0",
54
60
  "zod": "^4.5.4"
55
61
  },