@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.
- package/README.md +97 -31
- package/dist/agent-config-schema.d.ts +46 -0
- package/dist/agent-config-schema.js +45 -0
- package/dist/cli.js +30 -10
- package/dist/collection/agent-file.d.ts +36 -0
- package/dist/collection/agent-file.js +41 -0
- package/dist/collection/agents.d.ts +29 -0
- package/dist/collection/agents.js +54 -0
- package/dist/collection/apply.d.ts +8 -0
- package/dist/collection/apply.js +27 -0
- package/dist/collection/collection.d.ts +17 -0
- package/dist/collection/collection.js +28 -0
- package/dist/collection/enforce.d.ts +1 -0
- package/dist/collection/enforce.js +6 -0
- package/dist/collection/environment.d.ts +6 -0
- package/dist/collection/environment.js +28 -0
- package/dist/collection/graph-rules.d.ts +7 -0
- package/dist/collection/graph-rules.js +102 -0
- package/dist/collection/lint-directory.d.ts +32 -0
- package/dist/collection/lint-directory.js +67 -0
- package/dist/collection/lint-rules.d.ts +5 -0
- package/dist/collection/lint-rules.js +115 -0
- package/dist/collection/lint-shape.d.ts +89 -0
- package/dist/collection/lint-shape.js +99 -0
- package/dist/collection/lint-supply.d.ts +20 -0
- package/dist/collection/lint-supply.js +99 -0
- package/dist/collection/paths.d.ts +18 -0
- package/dist/collection/paths.js +28 -0
- package/dist/collection/pipelines.d.ts +8 -0
- package/dist/collection/pipelines.js +56 -0
- package/dist/collection/refusal.d.ts +11 -0
- package/dist/collection/refusal.js +11 -0
- package/dist/file.d.ts +2 -2
- package/dist/file.js +22 -9
- package/dist/floor-given.d.ts +2 -0
- package/dist/floor-given.js +8 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +12 -2
- package/dist/shape.d.ts +4 -0
- package/dist/shape.js +2 -0
- package/package.json +8 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Fills `${NAME}` placeholders from an environment: into a pipeline's text and an agent's settings, never into a prompt.
|
|
2
|
+
import { enforce } from "./enforce.js";
|
|
3
|
+
const PLACEHOLDER = /\$\{([A-Z][A-Z0-9_]*)\}/g;
|
|
4
|
+
/** The names a text asks for, each once, in the order they first appear. */
|
|
5
|
+
export function placeholdersIn(text) {
|
|
6
|
+
return [...new Set([...text.matchAll(PLACEHOLDER)].map((match) => match[1]))];
|
|
7
|
+
}
|
|
8
|
+
export function withEnvironment(yamlText, env) {
|
|
9
|
+
return yamlText.replace(PLACEHOLDER, (placeholder, name) => {
|
|
10
|
+
const value = env[name];
|
|
11
|
+
enforce(value, `${name} is not set, and a pipeline names it`);
|
|
12
|
+
return value;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function settingsWithEnvironment(settings, env) {
|
|
16
|
+
const { prompt, ...rest } = settings;
|
|
17
|
+
return { ...filledIn(rest, env), prompt };
|
|
18
|
+
}
|
|
19
|
+
function filledIn(value, env) {
|
|
20
|
+
if (typeof value === "string")
|
|
21
|
+
return withEnvironment(value, env);
|
|
22
|
+
if (Array.isArray(value))
|
|
23
|
+
return value.map((element) => filledIn(element, env));
|
|
24
|
+
if (!value || typeof value !== "object")
|
|
25
|
+
return value;
|
|
26
|
+
return Object.fromEntries(Object.entries(value).map(([key, field]) => [key, filledIn(field, env)]));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Checked, type Node, type PipelineProblem, type Station } from "./lint-shape.js";
|
|
2
|
+
export declare function ambiguousEdges(checked: Checked): PipelineProblem[];
|
|
3
|
+
export declare function unroutedOutcomes(checked: Checked, node: Node, station: Station): PipelineProblem[];
|
|
4
|
+
export declare function undeclaredOutcomes(checked: Checked): PipelineProblem[];
|
|
5
|
+
export declare function danglingEdges(checked: Checked): PipelineProblem[];
|
|
6
|
+
export declare function deadEnds(checked: Checked): PipelineProblem[];
|
|
7
|
+
export declare function unreachableNodes(checked: Checked): PipelineProblem[];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Whether a run can be routed through the graph at all.
|
|
2
|
+
import { outcomesLeaving, problem, stationOf, } from "./lint-shape.js";
|
|
3
|
+
// A station picks its outgoing edge from its OWN outcome, so two on one outcome have no tie-break.
|
|
4
|
+
export function ambiguousEdges(checked) {
|
|
5
|
+
const seen = new Map();
|
|
6
|
+
for (const edge of checked.line.edges) {
|
|
7
|
+
const key = `${edge.from}\n${edge.on ?? ""}`;
|
|
8
|
+
seen.set(key, (seen.get(key) ?? 0) + 1);
|
|
9
|
+
}
|
|
10
|
+
return [...seen]
|
|
11
|
+
.filter(([, count]) => count > 1)
|
|
12
|
+
.map(([key]) => key.split("\n"))
|
|
13
|
+
.map(([from, outcome]) => problem(checked, from, "ambiguous-edge", ambiguousDetail(outcome)));
|
|
14
|
+
}
|
|
15
|
+
function ambiguousDetail(outcome) {
|
|
16
|
+
return `two edges leave it on ${outcome}; a station reads its own outcome, never the verdict of the node that reached it`;
|
|
17
|
+
}
|
|
18
|
+
// An outcome no edge routes is a run that stops where nobody said it should.
|
|
19
|
+
export function unroutedOutcomes(checked, node, station) {
|
|
20
|
+
const unrouted = unroutedOf(checked, node, station);
|
|
21
|
+
return unrouted.length === 0
|
|
22
|
+
? []
|
|
23
|
+
: [
|
|
24
|
+
problem(checked, node.id, "outcome-without-edge", unroutedDetail(unrouted)),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
function unroutedOf(checked, node, station) {
|
|
28
|
+
const routed = outcomesLeaving(checked, node.id);
|
|
29
|
+
return routed.has("always")
|
|
30
|
+
? []
|
|
31
|
+
: station.outcomes.filter((outcome) => !routed.has(outcome));
|
|
32
|
+
}
|
|
33
|
+
function unroutedDetail(unrouted) {
|
|
34
|
+
const what = unrouted.length === 1 ? "that outcome" : "those outcomes";
|
|
35
|
+
return `declares ${unrouted.join(", ")} and no edge leaves it on ${what}`;
|
|
36
|
+
}
|
|
37
|
+
// An edge on an outcome its station never produces is a route nothing can take.
|
|
38
|
+
export function undeclaredOutcomes(checked) {
|
|
39
|
+
const { edges } = checked.line;
|
|
40
|
+
return edges
|
|
41
|
+
.filter((edge) => edge.on !== undefined && edge.on !== "always")
|
|
42
|
+
.filter((edge) => !declares(checked, edge.from, edge.on))
|
|
43
|
+
.map((edge) => problem(checked, edge.from, "undeclared-outcome", `an edge leaves it on ${edge.on}, which its station does not declare`));
|
|
44
|
+
}
|
|
45
|
+
function declares(checked, nodeId, outcome) {
|
|
46
|
+
const { nodes } = checked.line;
|
|
47
|
+
const node = nodes.find((each) => each.id === nodeId);
|
|
48
|
+
const station = node ? stationOf(checked, node) : undefined;
|
|
49
|
+
return !station || station.outcomes.length === 0
|
|
50
|
+
? true
|
|
51
|
+
: station.outcomes.includes(outcome ?? "");
|
|
52
|
+
}
|
|
53
|
+
// An edge naming a node the file never declares: the floor refuses the whole pipeline.
|
|
54
|
+
export function danglingEdges(checked) {
|
|
55
|
+
const { nodes, edges } = checked.line;
|
|
56
|
+
const declared = new Set(nodes.map((node) => node.id));
|
|
57
|
+
return edges.flatMap((edge) => danglingEnds(checked, edge, declared));
|
|
58
|
+
}
|
|
59
|
+
function danglingEnds(checked, edge, declared) {
|
|
60
|
+
return [
|
|
61
|
+
...(declared.has(edge.from) ? [] : [danglingEnd(checked, edge, edge.from)]),
|
|
62
|
+
...(declared.has(edge.to) ? [] : [danglingEnd(checked, edge, edge.to)]),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
function danglingEnd(checked, edge, missing) {
|
|
66
|
+
const where = missing === edge.from ? "leaves" : "leaves it to";
|
|
67
|
+
return problem(checked, edge.from, "dangling-edge", `an edge ${where} ${missing}, which this line does not declare`);
|
|
68
|
+
}
|
|
69
|
+
// A node a run can enter and never leave.
|
|
70
|
+
export function deadEnds(checked) {
|
|
71
|
+
const { nodes, exit, fail } = checked.line;
|
|
72
|
+
return nodes
|
|
73
|
+
.filter((node) => node.id !== exit && node.id !== fail)
|
|
74
|
+
.filter((node) => outcomesLeaving(checked, node.id).size === 0)
|
|
75
|
+
.map((node) => problem(checked, node.id, "dead-end", "no edge leaves it and it is neither the line's exit nor its fail node, so a run reaching it stops with nothing to do"));
|
|
76
|
+
}
|
|
77
|
+
// A node no run ever visits.
|
|
78
|
+
export function unreachableNodes(checked) {
|
|
79
|
+
const reached = reachableFrom(checked);
|
|
80
|
+
const { nodes } = checked.line;
|
|
81
|
+
return nodes
|
|
82
|
+
.filter((node) => !reached.has(node.id))
|
|
83
|
+
.map((node) => problem(checked, node.id, "unreachable", "no edge and no start event reaches it, so no run ever visits it"));
|
|
84
|
+
}
|
|
85
|
+
/** From the entry, and from every node a person may start by hand. */
|
|
86
|
+
function reachableFrom(checked) {
|
|
87
|
+
const { nodes, entry, edges } = checked.line;
|
|
88
|
+
const pending = [
|
|
89
|
+
entry,
|
|
90
|
+
...nodes.filter((node) => node.start).map((node) => node.id),
|
|
91
|
+
].filter((nodeId) => nodeId.length > 0);
|
|
92
|
+
const seen = new Set();
|
|
93
|
+
while (pending.length > 0) {
|
|
94
|
+
const nodeId = pending.pop();
|
|
95
|
+
if (!seen.has(nodeId)) {
|
|
96
|
+
seen.add(nodeId);
|
|
97
|
+
pending.push(...edges.filter((edge) => edge.from === nodeId).map((edge) => edge.to));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return seen;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=graph-rules.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ShippedCatalog } from "./agents.js";
|
|
2
|
+
import { type CollectionOverlay } from "./collection.js";
|
|
3
|
+
import type { Environment } from "./environment.js";
|
|
4
|
+
import { type CollectionFile } from "./paths.js";
|
|
5
|
+
export declare function lintCollectionDirectory(root: string, hostKeys?: readonly string[], shipped?: ShippedCatalog): Promise<CollectionOverlay>;
|
|
6
|
+
/** The collection in a directory, with `${NAME}` filled from the environment given, and the host keys given joined by the ones its `floor-collection.yaml` names. Nothing is shipped unless a catalog is given. */
|
|
7
|
+
export declare function readCollectionDirectory(root: string, given: {
|
|
8
|
+
hostKeys: readonly string[];
|
|
9
|
+
env: Environment;
|
|
10
|
+
shipped?: ShippedCatalog;
|
|
11
|
+
}): Promise<CollectionOverlay>;
|
|
12
|
+
/** The catalog a directory laid out as a collection stands for: the lines and the agents it holds are the ones shipped. */
|
|
13
|
+
export declare function shippedCatalogIn(root: string, hostKeys?: readonly string[]): Promise<ShippedCatalog>;
|
|
14
|
+
export interface LintCommand {
|
|
15
|
+
directory?: string;
|
|
16
|
+
hostKeys: readonly string[];
|
|
17
|
+
/** A directory in the layout of a collection, holding what the host ships. */
|
|
18
|
+
shippedDirectory?: string;
|
|
19
|
+
}
|
|
20
|
+
/** The `lint` command: the exit code is 0 clean, 1 refused, 2 when the call is wrong. */
|
|
21
|
+
export declare function lintCommand(given: LintCommand, usage: string, output: {
|
|
22
|
+
out: (line: string) => void;
|
|
23
|
+
err: (line: string) => void;
|
|
24
|
+
}): Promise<number>;
|
|
25
|
+
/** Prints the refused files and answers the exit code: 0 clean, 1 refused. */
|
|
26
|
+
export declare function printCollectionLint(root: string, hostKeys: readonly string[], print: (line: string) => void, shipped?: ShippedCatalog): Promise<number>;
|
|
27
|
+
/** The file at a collection's root that says what the collection expects of its host. */
|
|
28
|
+
export declare const COLLECTION_SETTINGS_FILE = "floor-collection.yaml";
|
|
29
|
+
/** The frontmatter keys the collection's host owns, as its `floor-collection.yaml` names them under `host_keys`; none without the file. */
|
|
30
|
+
export declare function hostKeysIn(root: string): Promise<string[]>;
|
|
31
|
+
/** The files of a collection on disk, each with its path from the root: the ones a collection reads or refuses. */
|
|
32
|
+
export declare function collectionFilesIn(root: string): Promise<CollectionFile[]>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// The overlay of a collection on a local directory, and the lines a lint prints about it: no floor, no network.
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { join, relative, sep } from "node:path";
|
|
4
|
+
import { parse } from "yaml";
|
|
5
|
+
import { agentsOverlay } from "./agents.js";
|
|
6
|
+
import { collectionOverlay } from "./collection.js";
|
|
7
|
+
import { enforce } from "./enforce.js";
|
|
8
|
+
import { isCollectionFile, pipelineFolderOf } from "./paths.js";
|
|
9
|
+
/** Stands in for the install's environment: whether a variable is set there is not the collection's to know. */
|
|
10
|
+
const ANY_ENVIRONMENT_VARIABLE = new Proxy({}, { get: (variables, name) => `${String(name)}-for-lint` });
|
|
11
|
+
/** Nothing is shipped: a collection is checked on its own. */
|
|
12
|
+
const NOTHING_SHIPPED = { pipelines: [], agents: new Map() };
|
|
13
|
+
export async function lintCollectionDirectory(root, hostKeys = [], shipped = NOTHING_SHIPPED) {
|
|
14
|
+
return readCollectionDirectory(root, { hostKeys, env: ANY_ENVIRONMENT_VARIABLE, shipped });
|
|
15
|
+
}
|
|
16
|
+
/** The collection in a directory, with `${NAME}` filled from the environment given, and the host keys given joined by the ones its `floor-collection.yaml` names. Nothing is shipped unless a catalog is given. */
|
|
17
|
+
export async function readCollectionDirectory(root, given) {
|
|
18
|
+
const hostKeys = [...given.hostKeys, ...(await hostKeysIn(root))];
|
|
19
|
+
return collectionOverlay({ files: await collectionFilesIn(root), ...given, hostKeys, shipped: given.shipped ?? NOTHING_SHIPPED });
|
|
20
|
+
}
|
|
21
|
+
/** The catalog a directory laid out as a collection stands for: the lines and the agents it holds are the ones shipped. */
|
|
22
|
+
export async function shippedCatalogIn(root, hostKeys = []) {
|
|
23
|
+
const files = await collectionFilesIn(root);
|
|
24
|
+
const { agents, refused } = agentsOverlay({ files, shipped: NOTHING_SHIPPED, env: ANY_ENVIRONMENT_VARIABLE, hostKeys });
|
|
25
|
+
enforce(refused.length === 0, refused.map(({ path, reason }) => `${path}: ${reason}`).join("\n"));
|
|
26
|
+
const folders = files.flatMap((file) => pipelineFolderOf(file.path) ?? []);
|
|
27
|
+
return { pipelines: [...new Set(folders)], agents: new Map([...agents].map(([name, agent]) => [name, agent.settings])) };
|
|
28
|
+
}
|
|
29
|
+
/** The `lint` command: the exit code is 0 clean, 1 refused, 2 when the call is wrong. */
|
|
30
|
+
export async function lintCommand(given, usage, output) {
|
|
31
|
+
if (!given.directory) {
|
|
32
|
+
output.err(usage);
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
35
|
+
const shipped = given.shippedDirectory ? await shippedCatalogIn(given.shippedDirectory, given.hostKeys) : undefined;
|
|
36
|
+
return printCollectionLint(given.directory, given.hostKeys, output.out, shipped);
|
|
37
|
+
}
|
|
38
|
+
/** Prints the refused files and answers the exit code: 0 clean, 1 refused. */
|
|
39
|
+
export async function printCollectionLint(root, hostKeys, print, shipped = NOTHING_SHIPPED) {
|
|
40
|
+
const { refused, counts } = await lintCollectionDirectory(root, hostKeys, shipped);
|
|
41
|
+
for (const { path, reason } of refused)
|
|
42
|
+
print(`${path}: ${reason}`);
|
|
43
|
+
if (refused.length > 0)
|
|
44
|
+
return 1;
|
|
45
|
+
print(`collection ok: ${counts.agents} agents, ${counts.pipelines} pipelines, ${counts.extensions} extensions`);
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
/** The file at a collection's root that says what the collection expects of its host. */
|
|
49
|
+
export const COLLECTION_SETTINGS_FILE = "floor-collection.yaml";
|
|
50
|
+
/** The frontmatter keys the collection's host owns, as its `floor-collection.yaml` names them under `host_keys`; none without the file. */
|
|
51
|
+
export async function hostKeysIn(root) {
|
|
52
|
+
const text = await readFile(join(root, COLLECTION_SETTINGS_FILE), "utf8").catch(() => "");
|
|
53
|
+
const settings = new Map(Object.entries(parse(text) ?? {}));
|
|
54
|
+
const hostKeys = settings.get("host_keys") ?? [];
|
|
55
|
+
enforce(Array.isArray(hostKeys) && hostKeys.every((key) => typeof key === "string"), `${COLLECTION_SETTINGS_FILE}: host_keys is a list of names`);
|
|
56
|
+
return hostKeys;
|
|
57
|
+
}
|
|
58
|
+
/** The files of a collection on disk, each with its path from the root: the ones a collection reads or refuses. */
|
|
59
|
+
export async function collectionFilesIn(root) {
|
|
60
|
+
const entries = await readdir(root, { recursive: true, withFileTypes: true });
|
|
61
|
+
const paths = entries
|
|
62
|
+
.filter((entry) => entry.isFile())
|
|
63
|
+
.map((entry) => relative(root, join(entry.parentPath, entry.name)).split(sep).join("/"))
|
|
64
|
+
.filter((path) => isCollectionFile(path) && !path.startsWith(".git/"));
|
|
65
|
+
return Promise.all(paths.map(async (path) => ({ path, text: await readFile(join(root, path), "utf8") })));
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=lint-directory.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AgentPrompts } from "./agent-file.js";
|
|
2
|
+
import { type PipelineProblem, type PipelineRule } from "./lint-shape.js";
|
|
3
|
+
export { PIPELINE_RULES } from "./lint-shape.js";
|
|
4
|
+
export type { PipelineProblem, PipelineRule };
|
|
5
|
+
export declare function pipelineProblems(yamlText: string, prompts: AgentPrompts): PipelineProblem[];
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// What a pipeline must hold to run at all, and why each rule.
|
|
2
|
+
import { ambiguousEdges, danglingEdges, deadEnds, undeclaredOutcomes, unreachableNodes, unroutedOutcomes, } from "./graph-rules.js";
|
|
3
|
+
import { supplyOf, unseededNeeds, unsuppliedInputs } from "./lint-supply.js";
|
|
4
|
+
import { problem, readPipeline, stationOf, } from "./lint-shape.js";
|
|
5
|
+
export { PIPELINE_RULES } from "./lint-shape.js";
|
|
6
|
+
export function pipelineProblems(yamlText, prompts) {
|
|
7
|
+
const checked = readPipeline(yamlText);
|
|
8
|
+
if (!checked) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
return [
|
|
12
|
+
...agentDeclarationProblems(checked, prompts),
|
|
13
|
+
...unkeyedLine(checked),
|
|
14
|
+
...undeclaredBags(checked),
|
|
15
|
+
...allNodeProblems(checked, prompts),
|
|
16
|
+
...graphRuleProblems(checked),
|
|
17
|
+
...unboundedRetries(checked),
|
|
18
|
+
...unresolvableConversationKeys(checked),
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
function graphRuleProblems(checked) {
|
|
22
|
+
return [
|
|
23
|
+
...ambiguousEdges(checked),
|
|
24
|
+
...undeclaredOutcomes(checked),
|
|
25
|
+
...danglingEdges(checked),
|
|
26
|
+
...deadEnds(checked),
|
|
27
|
+
...unreachableNodes(checked),
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
function allNodeProblems(checked, prompts) {
|
|
31
|
+
const supply = supplyOf(checked);
|
|
32
|
+
const { nodes } = checked.line;
|
|
33
|
+
return nodes.flatMap((node, index) => nodeProblems(supply, { node, index }, prompts));
|
|
34
|
+
}
|
|
35
|
+
// An agent is declared once, in its .md file: a pipeline file only names it from a station.
|
|
36
|
+
function agentDeclarationProblems(checked, prompts) {
|
|
37
|
+
return [
|
|
38
|
+
...agentSettingsInPipeline(checked),
|
|
39
|
+
...undeclaredAgents(checked, prompts),
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
function agentSettingsInPipeline(checked) {
|
|
43
|
+
return checked.agent_definitions === undefined
|
|
44
|
+
? []
|
|
45
|
+
: [
|
|
46
|
+
problem(checked, undefined, "agent-settings-in-pipeline", "the file carries an agent_definitions block; in a collection an agent's settings live in <line>/agents/<agent>.md"),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
function undeclaredAgents(checked, prompts) {
|
|
50
|
+
return Object.entries(checked.stations)
|
|
51
|
+
.map(([name, station]) => ({ name, agent: station.agent_definition }))
|
|
52
|
+
.filter(({ agent }) => agent !== undefined && !prompts.has(agent))
|
|
53
|
+
.map(({ name, agent }) => problem(checked, undefined, "undeclared-agent", `station "${name}" names agent definition "${agent}", and nothing defines it: a collection defines an agent in <line>/agents/<agent>.md`));
|
|
54
|
+
}
|
|
55
|
+
// The floor refuses a station missing either array with a 400 naming none.
|
|
56
|
+
function undeclaredBags(checked) {
|
|
57
|
+
return Object.entries(checked.stations)
|
|
58
|
+
.map(([name, station]) => ({ name, missing: missingBags(station) }))
|
|
59
|
+
.filter(({ missing }) => missing.length > 0)
|
|
60
|
+
.map(({ name, missing }) => problem(checked, undefined, "undeclared-bag", `station "${name}" declares no ${missing.join(" and no ")}; the floor requires both arrays`));
|
|
61
|
+
}
|
|
62
|
+
function missingBags(station) {
|
|
63
|
+
return [
|
|
64
|
+
...(station.needs ? [] : ["needs"]),
|
|
65
|
+
...(station.produces ? [] : ["produces"]),
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
// A run keyed on nothing cannot be the one run for its subject, so two starters make two.
|
|
69
|
+
function unkeyedLine(checked) {
|
|
70
|
+
const keys = Object.entries(checked.line.args)
|
|
71
|
+
.filter(([, arg]) => arg.subject === true)
|
|
72
|
+
.map(([name]) => name);
|
|
73
|
+
if (keys.length === 1) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
return [problem(checked, undefined, "unkeyed-line", unkeyedDetail(keys))];
|
|
77
|
+
}
|
|
78
|
+
function unkeyedDetail(keys) {
|
|
79
|
+
return keys.length === 0
|
|
80
|
+
? "no arg carries subject: true, so the floor cannot refuse a second run for the same subject"
|
|
81
|
+
: `${keys.join(", ")} all carry subject: true, and a run has one subject`;
|
|
82
|
+
}
|
|
83
|
+
function nodeProblems(supply, position, prompts) {
|
|
84
|
+
const { node, index } = position;
|
|
85
|
+
const { checked, line, bodies } = supply;
|
|
86
|
+
const station = stationOf(checked, node);
|
|
87
|
+
if (!station) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
const stationNode = {
|
|
91
|
+
node: line.nodes[index],
|
|
92
|
+
body: bodies.get(node.station ?? ""),
|
|
93
|
+
};
|
|
94
|
+
const definition = station.agent_definition ?? node.station ?? "";
|
|
95
|
+
return [
|
|
96
|
+
...unroutedOutcomes(checked, node, station),
|
|
97
|
+
...unsuppliedInputs(supply, stationNode, { definition, text: prompts.get(definition) }),
|
|
98
|
+
...unseededNeeds(supply, stationNode),
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
// A walk revisiting a node needs iteration_max to bound the loop.
|
|
102
|
+
function unboundedRetries(checked) {
|
|
103
|
+
const { edges } = checked.line;
|
|
104
|
+
const backEdges = edges.filter((edge) => edge.from === edge.to && edge.iteration_max === undefined);
|
|
105
|
+
return backEdges.map((edge) => problem(checked, edge.from, "unbounded-retry", `node "${edge.from}" has a back-edge to itself with no iteration_max; the walk would retry without bound`));
|
|
106
|
+
}
|
|
107
|
+
// conversation_key must name a declared arg so the floor can key the conversation.
|
|
108
|
+
function unresolvableConversationKeys(checked) {
|
|
109
|
+
const argNames = new Set(Object.keys(checked.line.args));
|
|
110
|
+
return Object.entries(checked.stations)
|
|
111
|
+
.filter(([, station]) => station.conversation_key !== undefined &&
|
|
112
|
+
!argNames.has(station.conversation_key))
|
|
113
|
+
.map(([name, station]) => problem(checked, undefined, "unresolvable-conversation-key", `station "${name}" sets conversation_key to "${station.conversation_key}", which is not a declared arg`));
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=lint-rules.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Every rule a collection's lint has, by the id its specification lists it under. */
|
|
3
|
+
export declare const PIPELINE_RULES: readonly ["agent-settings-in-pipeline", "ambiguous-edge", "dangling-edge", "dead-end", "undeclared-agent", "undeclared-bag", "outcome-without-edge", "undeclared-outcome", "unbounded-retry", "unkeyed-line", "unreachable", "unseeded-need", "unsupplied-input", "unresolvable-conversation-key"];
|
|
4
|
+
export type PipelineRule = (typeof PIPELINE_RULES)[number];
|
|
5
|
+
export interface PipelineProblem {
|
|
6
|
+
line: string;
|
|
7
|
+
node?: string;
|
|
8
|
+
rule: PipelineRule;
|
|
9
|
+
detail: string;
|
|
10
|
+
}
|
|
11
|
+
declare const bagItemSchema: z.ZodObject<{
|
|
12
|
+
name: z.ZodOptional<z.ZodString>;
|
|
13
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
14
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
collect: z.ZodOptional<z.ZodUnknown>;
|
|
16
|
+
}, z.core.$loose>;
|
|
17
|
+
declare const stationSchema: z.ZodObject<{
|
|
18
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
19
|
+
agent_definition: z.ZodOptional<z.ZodString>;
|
|
20
|
+
outcomes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
21
|
+
needs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
22
|
+
name: z.ZodOptional<z.ZodString>;
|
|
23
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
24
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
collect: z.ZodOptional<z.ZodUnknown>;
|
|
26
|
+
}, z.core.$loose>>>;
|
|
27
|
+
produces: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
28
|
+
name: z.ZodOptional<z.ZodString>;
|
|
29
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
30
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
+
collect: z.ZodOptional<z.ZodUnknown>;
|
|
32
|
+
}, z.core.$loose>>>;
|
|
33
|
+
conversation: z.ZodOptional<z.ZodString>;
|
|
34
|
+
conversation_key: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, z.core.$loose>;
|
|
36
|
+
declare const pipelineSchema: z.ZodObject<{
|
|
37
|
+
line: z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
entry: z.ZodDefault<z.ZodString>;
|
|
40
|
+
exit: z.ZodDefault<z.ZodString>;
|
|
41
|
+
fail: z.ZodOptional<z.ZodString>;
|
|
42
|
+
files: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
43
|
+
args: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
44
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
45
|
+
subject: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
}, z.core.$loose>>>;
|
|
47
|
+
nodes: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
48
|
+
id: z.ZodString;
|
|
49
|
+
station: z.ZodOptional<z.ZodString>;
|
|
50
|
+
start: z.ZodOptional<z.ZodString>;
|
|
51
|
+
bind: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
52
|
+
}, z.core.$loose>>>;
|
|
53
|
+
edges: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
54
|
+
from: z.ZodString;
|
|
55
|
+
to: z.ZodDefault<z.ZodString>;
|
|
56
|
+
on: z.ZodOptional<z.ZodString>;
|
|
57
|
+
iteration_max: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
}, z.core.$loose>>>;
|
|
59
|
+
}, z.core.$loose>;
|
|
60
|
+
stations: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
61
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
62
|
+
agent_definition: z.ZodOptional<z.ZodString>;
|
|
63
|
+
outcomes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
64
|
+
needs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
65
|
+
name: z.ZodOptional<z.ZodString>;
|
|
66
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
67
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
68
|
+
collect: z.ZodOptional<z.ZodUnknown>;
|
|
69
|
+
}, z.core.$loose>>>;
|
|
70
|
+
produces: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
71
|
+
name: z.ZodOptional<z.ZodString>;
|
|
72
|
+
kind: z.ZodOptional<z.ZodString>;
|
|
73
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
74
|
+
collect: z.ZodOptional<z.ZodUnknown>;
|
|
75
|
+
}, z.core.$loose>>>;
|
|
76
|
+
conversation: z.ZodOptional<z.ZodString>;
|
|
77
|
+
conversation_key: z.ZodOptional<z.ZodString>;
|
|
78
|
+
}, z.core.$loose>>>;
|
|
79
|
+
}, z.core.$loose>;
|
|
80
|
+
export type Checked = z.infer<typeof pipelineSchema>;
|
|
81
|
+
export type Station = z.infer<typeof stationSchema>;
|
|
82
|
+
export type BagItem = z.infer<typeof bagItemSchema>;
|
|
83
|
+
export type Node = Checked["line"]["nodes"][number];
|
|
84
|
+
/** The pipeline as the rules read it, or none when the text is not one. */
|
|
85
|
+
export declare function readPipeline(yamlText: string): Checked | null;
|
|
86
|
+
export declare function problem(checked: Checked, node: string | undefined, rule: PipelineRule, detail: string): PipelineProblem;
|
|
87
|
+
export declare function stationOf(checked: Checked, node: Node): Station | undefined;
|
|
88
|
+
export declare function outcomesLeaving(checked: Checked, nodeId: string): Set<string>;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// What every pipeline rule reads, and nothing else.
|
|
2
|
+
import { parse } from "yaml";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/** Every rule a collection's lint has, by the id its specification lists it under. */
|
|
5
|
+
export const PIPELINE_RULES = [
|
|
6
|
+
"agent-settings-in-pipeline",
|
|
7
|
+
"ambiguous-edge",
|
|
8
|
+
"dangling-edge",
|
|
9
|
+
"dead-end",
|
|
10
|
+
"undeclared-agent",
|
|
11
|
+
"undeclared-bag",
|
|
12
|
+
"outcome-without-edge",
|
|
13
|
+
"undeclared-outcome",
|
|
14
|
+
"unbounded-retry",
|
|
15
|
+
"unkeyed-line",
|
|
16
|
+
"unreachable",
|
|
17
|
+
"unseeded-need",
|
|
18
|
+
"unsupplied-input",
|
|
19
|
+
"unresolvable-conversation-key",
|
|
20
|
+
];
|
|
21
|
+
const bagItemSchema = z
|
|
22
|
+
.object({
|
|
23
|
+
name: z.string().optional(),
|
|
24
|
+
kind: z.string().optional(),
|
|
25
|
+
optional: z.boolean().optional(),
|
|
26
|
+
collect: z.unknown().optional(),
|
|
27
|
+
})
|
|
28
|
+
.loose();
|
|
29
|
+
const stationSchema = z
|
|
30
|
+
.object({
|
|
31
|
+
kind: z.string().optional(),
|
|
32
|
+
agent_definition: z.string().optional(),
|
|
33
|
+
outcomes: z.array(z.string()).default([]),
|
|
34
|
+
needs: z.array(bagItemSchema).optional(),
|
|
35
|
+
produces: z.array(bagItemSchema).optional(),
|
|
36
|
+
conversation: z.string().optional(),
|
|
37
|
+
conversation_key: z.string().optional(),
|
|
38
|
+
})
|
|
39
|
+
.loose();
|
|
40
|
+
// Every optional part is defaulted here rather than at each use.
|
|
41
|
+
const pipelineSchema = z
|
|
42
|
+
.object({
|
|
43
|
+
line: z
|
|
44
|
+
.object({
|
|
45
|
+
id: z.string(),
|
|
46
|
+
entry: z.string().default(""),
|
|
47
|
+
exit: z.string().default(""),
|
|
48
|
+
fail: z.string().optional(),
|
|
49
|
+
files: z.record(z.string(), z.unknown()).optional(),
|
|
50
|
+
args: z
|
|
51
|
+
.record(z.string(), z
|
|
52
|
+
.object({
|
|
53
|
+
kind: z.string().optional(),
|
|
54
|
+
subject: z.boolean().optional(),
|
|
55
|
+
})
|
|
56
|
+
.loose())
|
|
57
|
+
.default({}),
|
|
58
|
+
nodes: z
|
|
59
|
+
.array(z
|
|
60
|
+
.object({
|
|
61
|
+
id: z.string(),
|
|
62
|
+
station: z.string().optional(),
|
|
63
|
+
// A node a person starts by hand needs no edge into it.
|
|
64
|
+
start: z.string().optional(),
|
|
65
|
+
bind: z.record(z.string(), z.string()).optional(),
|
|
66
|
+
})
|
|
67
|
+
.loose())
|
|
68
|
+
.default([]),
|
|
69
|
+
edges: z
|
|
70
|
+
.array(z
|
|
71
|
+
.object({
|
|
72
|
+
from: z.string(),
|
|
73
|
+
to: z.string().default(""),
|
|
74
|
+
on: z.string().optional(),
|
|
75
|
+
iteration_max: z.number().optional(),
|
|
76
|
+
})
|
|
77
|
+
.loose())
|
|
78
|
+
.default([]),
|
|
79
|
+
})
|
|
80
|
+
.loose(),
|
|
81
|
+
stations: z.record(z.string(), stationSchema).default({}),
|
|
82
|
+
})
|
|
83
|
+
.loose();
|
|
84
|
+
/** The pipeline as the rules read it, or none when the text is not one. */
|
|
85
|
+
export function readPipeline(yamlText) {
|
|
86
|
+
const read = pipelineSchema.safeParse(parse(yamlText));
|
|
87
|
+
return read.success ? read.data : null;
|
|
88
|
+
}
|
|
89
|
+
export function problem(checked, node, rule, detail) {
|
|
90
|
+
return { line: checked.line.id, node, rule, detail };
|
|
91
|
+
}
|
|
92
|
+
export function stationOf(checked, node) {
|
|
93
|
+
return node.station ? checked.stations[node.station] : undefined;
|
|
94
|
+
}
|
|
95
|
+
export function outcomesLeaving(checked, nodeId) {
|
|
96
|
+
const { edges } = checked.line;
|
|
97
|
+
return new Set(edges.filter((edge) => edge.from === nodeId).map((edge) => edge.on ?? ""));
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=lint-shape.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type NeedContext } from "@re-cinq/floor-assembly-lines";
|
|
2
|
+
import type { LineBody, LineNode, StationBody } from "@re-cinq/floor-contracts";
|
|
3
|
+
import { type Checked, type PipelineProblem } from "./lint-shape.js";
|
|
4
|
+
export interface Supply {
|
|
5
|
+
checked: Checked;
|
|
6
|
+
line: LineBody;
|
|
7
|
+
bodies: Map<string, StationBody>;
|
|
8
|
+
context: NeedContext;
|
|
9
|
+
}
|
|
10
|
+
export declare function supplyOf(checked: Checked): Supply;
|
|
11
|
+
/** A node of the contract shape beside the body of the station it names. */
|
|
12
|
+
export interface StationNode {
|
|
13
|
+
node: LineNode;
|
|
14
|
+
body: StationBody;
|
|
15
|
+
}
|
|
16
|
+
export declare function unseededNeeds(supply: Supply, { node, body }: StationNode): PipelineProblem[];
|
|
17
|
+
export declare function unsuppliedInputs(supply: Supply, stationNode: StationNode, prompt: {
|
|
18
|
+
definition: string;
|
|
19
|
+
text: string | null | undefined;
|
|
20
|
+
}): PipelineProblem[];
|