@re-cinq/floor-pipeline 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/cli.js +6 -3
- package/dist/collection/agents.d.ts +2 -0
- package/dist/collection/change-report.d.ts +3 -0
- package/dist/collection/change-report.js +57 -0
- package/dist/collection/changed-lines.d.ts +7 -0
- package/dist/collection/changed-lines.js +17 -0
- package/dist/collection/collection-settings.d.ts +12 -0
- package/dist/collection/collection-settings.js +27 -0
- package/dist/collection/collection.d.ts +1 -1
- package/dist/collection/collection.js +3 -1
- package/dist/collection/group-precedence.d.ts +3 -0
- package/dist/collection/group-precedence.js +20 -0
- package/dist/collection/line-layout.d.ts +11 -0
- package/dist/collection/line-layout.js +46 -0
- package/dist/collection/line-mermaid.d.ts +3 -0
- package/dist/collection/line-mermaid.js +79 -0
- package/dist/collection/lint-directory.d.ts +8 -7
- package/dist/collection/lint-directory.js +26 -15
- package/dist/collection/lint-rules.js +3 -3
- package/dist/collection/lint-shape.d.ts +7 -1
- package/dist/collection/lint-shape.js +3 -0
- package/dist/collection/note-within.d.ts +1 -0
- package/dist/collection/note-within.js +36 -0
- package/dist/collection/paths.d.ts +12 -1
- package/dist/collection/paths.js +28 -7
- package/dist/collection/pipelines.d.ts +1 -2
- package/dist/collection/pipelines.js +10 -34
- package/dist/collection/unknown-keys.d.ts +3 -0
- package/dist/collection/unknown-keys.js +35 -0
- package/dist/definition-schemas.d.ts +220 -0
- package/dist/definition-schemas.js +141 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/lint-command-given.d.ts +4 -0
- package/dist/lint-command-given.js +9 -0
- package/dist/shape.js +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ schedules:
|
|
|
91
91
|
|
|
92
92
|
## A collection
|
|
93
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.
|
|
94
|
+
A collection is a folder of assembly lines. Each one has its own folder, with its pipeline and its agents. A line folder may sit one level down, in a group folder such as `stock/`. The group is in no name, and a line's id is unique in the whole collection. 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
95
|
|
|
96
96
|
```
|
|
97
97
|
code-review/
|
|
@@ -113,10 +113,13 @@ floor-pipeline lint collection/ --host-key execution_mode
|
|
|
113
113
|
|
|
114
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
115
|
|
|
116
|
+
The same file may hold `groups`, a list of group folder names. A line or an agent held in several listed groups is read from the group listed last, and the earlier files are left out. A duplicate the list does not settle is refused with `<name> is already set by <path>`. `collectionSettingsOf(text)` reads `{ hostKeys, groups }` from the file's text, and `collectionSettingsIn(directory)` from a directory.
|
|
117
|
+
|
|
116
118
|
`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
119
|
|
|
118
120
|
- `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
121
|
- `unsupplied-input` is a `{name}` in an agent's prompt that the station does not give.
|
|
122
|
+
- `unknown-key` is a key the floor does not know and would drop without a word, such as `optional` on a produce or a misspelt `iteration-max`. Its message names the key and where it is.
|
|
120
123
|
|
|
121
124
|
What a station gives a prompt:
|
|
122
125
|
|
|
@@ -138,6 +141,14 @@ floor-pipeline lint collection/ --shipped shipped/ --host-key execution_mode
|
|
|
138
141
|
|
|
139
142
|
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
143
|
|
|
144
|
+
`--graph-against <base-dir>` draws what a pull request changes. Standard output holds only a markdown comment with two mermaid graphs of each assembly line that differs from the collection in `<base-dir>`, the line before with its removed and changed nodes and edges marked and the line after with its added and changed ones marked, and nothing when no line differs. Lint's own lines go to standard error. A refused collection prints no comment, and neither does one compared with a refused collection. The comment stays under 65,000 characters, which GitHub's limit of 65,536 allows: lines are drawn in order while they fit, and the rest are named in a note, cut with `and N more` when even the names do not fit.
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
floor-pipeline lint head/ --graph-against base/ > report.md
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The [pull request workflow](https://re-cinq.github.io/floor/tutorials/check-a-pack-on-every-pull-request/) posts it as one comment and updates that comment on every push.
|
|
151
|
+
|
|
141
152
|
```
|
|
142
153
|
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
154
|
```
|
package/dist/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ import { importPipeline } from "./import.js";
|
|
|
10
10
|
import { migrate } from "./migrate.js";
|
|
11
11
|
import { applyCollection } from "./collection/apply.js";
|
|
12
12
|
import { lintCommand, readCollectionDirectory } from "./collection/lint-directory.js";
|
|
13
|
+
import { lintCommandGiven } from "./lint-command-given.js";
|
|
13
14
|
import { waitUntilReady } from "./ready.js";
|
|
14
15
|
import { fileOf, pipelineOf } from "./shape.js";
|
|
15
16
|
const USAGE = `floor-pipeline <what to do> --floor <url> with FLOOR_SERVICE_TOKEN
|
|
@@ -27,10 +28,13 @@ const USAGE = `floor-pipeline <what to do> --floor <url> with FLOOR_SERVICE
|
|
|
27
28
|
Needs no floor and no token. A key the host owns is named with --host-key <name>,
|
|
28
29
|
as often as needed. The agents and lines the host ships are a directory in the
|
|
29
30
|
same layout, named with --shipped <dir>. Exits 2 when no directory is given
|
|
31
|
+
--graph-against <base-dir> prints to stdout the change report, as markdown with
|
|
32
|
+
mermaid graphs, of the assembly lines that differ from <base-dir>;
|
|
33
|
+
lint's own lines then go to stderr
|
|
30
34
|
|
|
31
35
|
--wait-ready <seconds> first waits up to that long for the floor's /readyz to answer 200,
|
|
32
36
|
for a job that starts with the floor`;
|
|
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" } };
|
|
37
|
+
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" }, "graph-against": { type: "string" } };
|
|
34
38
|
function given() {
|
|
35
39
|
return parseArgs({ options: OPTIONS, allowPositionals: true });
|
|
36
40
|
}
|
|
@@ -101,8 +105,7 @@ async function applied(floor, told) {
|
|
|
101
105
|
said(dir, await applyCollection(floor, overlay));
|
|
102
106
|
}
|
|
103
107
|
async function linted(told) {
|
|
104
|
-
|
|
105
|
-
process.exitCode = await lintCommand({ directory, hostKeys: told.values["host-key"] ?? [], shippedDirectory: told.values.shipped }, USAGE, { out: console.log, err: console.error });
|
|
108
|
+
process.exitCode = await lintCommand(lintCommandGiven(told.positionals, told.values), USAGE, { out: console.log, err: console.error });
|
|
106
109
|
}
|
|
107
110
|
function said(file, put) {
|
|
108
111
|
console.log(`${file}:`);
|
|
@@ -14,6 +14,8 @@ export interface CollectionOverlayInput {
|
|
|
14
14
|
env: Environment;
|
|
15
15
|
/** Frontmatter keys that are the host's own: accepted in an agent file, and never in its settings. */
|
|
16
16
|
hostKeys?: readonly string[];
|
|
17
|
+
/** Group folder names, in order: a name held in several of them is read from the one listed last. */
|
|
18
|
+
groups?: readonly string[];
|
|
17
19
|
}
|
|
18
20
|
export type AgentSource = "collection-new" | "replaced" | "extended";
|
|
19
21
|
export interface OverlayAgent {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The pull request comment that draws every assembly line the change touches.
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { definitionSchemas } from "../definition-schemas.js";
|
|
4
|
+
import { afterGraphOf, beforeGraphOf } from "./line-mermaid.js";
|
|
5
|
+
import { noteWithin } from "./note-within.js";
|
|
6
|
+
const { lineBodySchema } = definitionSchemas(z.object);
|
|
7
|
+
export const COMMENT_LIMIT = 65000;
|
|
8
|
+
const NOTE_LINE_BREAKS = 2;
|
|
9
|
+
export function changeReportOf(changes, limit = COMMENT_LIMIT) {
|
|
10
|
+
if (changes.length === 0)
|
|
11
|
+
return "";
|
|
12
|
+
return reportOf(changes, drawnCountOf(changes, limit), limit);
|
|
13
|
+
}
|
|
14
|
+
function drawnCountOf(changes, limit) {
|
|
15
|
+
for (let count = 1; count <= changes.length; count++) {
|
|
16
|
+
if (reportOf(changes, count, limit).length > limit)
|
|
17
|
+
return count - 1;
|
|
18
|
+
}
|
|
19
|
+
return changes.length;
|
|
20
|
+
}
|
|
21
|
+
function reportOf(changes, drawnCount, limit) {
|
|
22
|
+
const opening = [
|
|
23
|
+
"<!-- floor-pack-graph -->",
|
|
24
|
+
"### Assembly lines changed in this pull request",
|
|
25
|
+
"",
|
|
26
|
+
...changes.slice(0, drawnCount).flatMap(sectionOf),
|
|
27
|
+
];
|
|
28
|
+
const undrawnIds = changes.slice(drawnCount).map(({ id }) => id);
|
|
29
|
+
const closing = [
|
|
30
|
+
"<sub>green added · red dashed removed · amber changed</sub>",
|
|
31
|
+
"",
|
|
32
|
+
];
|
|
33
|
+
const frame = [...opening, ...closing].join("\n");
|
|
34
|
+
const noteRoom = limit - frame.length - NOTE_LINE_BREAKS;
|
|
35
|
+
return [...opening, ...noteWithin(undrawnIds, noteRoom), ...closing].join("\n");
|
|
36
|
+
}
|
|
37
|
+
function sectionOf({ id, base, head }) {
|
|
38
|
+
const baseBody = lineBodyOf(base);
|
|
39
|
+
const headBody = lineBodyOf(head);
|
|
40
|
+
return [
|
|
41
|
+
...(baseBody ? beforeBlockOf(id, baseBody, headBody) : []),
|
|
42
|
+
...(headBody ? afterBlockOf(id, baseBody, headBody) : []),
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
function beforeBlockOf(id, base, head) {
|
|
46
|
+
return blockOf(`**${id}** · before`, beforeGraphOf(base, head));
|
|
47
|
+
}
|
|
48
|
+
function afterBlockOf(id, base, head) {
|
|
49
|
+
return blockOf(`**${id}** · proposed changes`, afterGraphOf(base, head));
|
|
50
|
+
}
|
|
51
|
+
function blockOf(title, graph) {
|
|
52
|
+
return [title, "", "```mermaid", graph, "```", ""];
|
|
53
|
+
}
|
|
54
|
+
function lineBodyOf(fields) {
|
|
55
|
+
return fields && lineBodySchema.parse(fields);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=change-report.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The lines whose body differs between a base collection and a head collection.
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
export function changedLines(base, head) {
|
|
4
|
+
const baseBodies = bodiesById(base);
|
|
5
|
+
const headBodies = bodiesById(head);
|
|
6
|
+
const differing = [...headBodies]
|
|
7
|
+
.filter(([id, body]) => !isDeepStrictEqual(baseBodies.get(id), body))
|
|
8
|
+
.map(([id, body]) => ({ id, base: baseBodies.get(id), head: body }));
|
|
9
|
+
const removed = [...baseBodies]
|
|
10
|
+
.filter(([id]) => !headBodies.has(id))
|
|
11
|
+
.map(([id, body]) => ({ id, base: body }));
|
|
12
|
+
return [...differing, ...removed];
|
|
13
|
+
}
|
|
14
|
+
function bodiesById(pipelines) {
|
|
15
|
+
return new Map(pipelines.flatMap(({ line }) => (line ? [[line.id, line.body]] : [])));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=changed-lines.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The file at a collection's root that says what the collection expects of its host. */
|
|
2
|
+
export declare const COLLECTION_SETTINGS_FILE = "floor-collection.yaml";
|
|
3
|
+
export interface CollectionSettings {
|
|
4
|
+
hostKeys: string[];
|
|
5
|
+
groups: string[];
|
|
6
|
+
}
|
|
7
|
+
/** What the text of a `floor-collection.yaml` says: the frontmatter keys its host owns under `host_keys`, and the group folders under `groups`; empty for either left out. */
|
|
8
|
+
export declare function collectionSettingsOf(text: string): CollectionSettings;
|
|
9
|
+
/** The settings in a directory's `floor-collection.yaml`; empty without the file. */
|
|
10
|
+
export declare function collectionSettingsIn(root: string): Promise<CollectionSettings>;
|
|
11
|
+
/** The frontmatter keys the collection's host owns, as its `floor-collection.yaml` names them under `host_keys`; none without the file. */
|
|
12
|
+
export declare function hostKeysIn(root: string): Promise<string[]>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parse } from "yaml";
|
|
4
|
+
import { enforce } from "./enforce.js";
|
|
5
|
+
/** The file at a collection's root that says what the collection expects of its host. */
|
|
6
|
+
export const COLLECTION_SETTINGS_FILE = "floor-collection.yaml";
|
|
7
|
+
/** What the text of a `floor-collection.yaml` says: the frontmatter keys its host owns under `host_keys`, and the group folders under `groups`; empty for either left out. */
|
|
8
|
+
export function collectionSettingsOf(text) {
|
|
9
|
+
const settings = new Map(Object.entries(parse(text) ?? {}));
|
|
10
|
+
const hostKeys = settings.get("host_keys") ?? [];
|
|
11
|
+
enforce(Array.isArray(hostKeys) && hostKeys.every((key) => typeof key === "string"), `${COLLECTION_SETTINGS_FILE}: host_keys is a list of names`);
|
|
12
|
+
const groups = settings.get("groups") ?? [];
|
|
13
|
+
enforce(isDistinctFolderNames(groups), `${COLLECTION_SETTINGS_FILE}: groups is a list of distinct folder names`);
|
|
14
|
+
return { hostKeys, groups };
|
|
15
|
+
}
|
|
16
|
+
function isDistinctFolderNames(value) {
|
|
17
|
+
return Array.isArray(value) && value.every((name) => typeof name === "string" && !name.includes("/")) && new Set(value).size === value.length;
|
|
18
|
+
}
|
|
19
|
+
/** The settings in a directory's `floor-collection.yaml`; empty without the file. */
|
|
20
|
+
export async function collectionSettingsIn(root) {
|
|
21
|
+
return collectionSettingsOf(await readFile(join(root, COLLECTION_SETTINGS_FILE), "utf8").catch(() => ""));
|
|
22
|
+
}
|
|
23
|
+
/** The frontmatter keys the collection's host owns, as its `floor-collection.yaml` names them under `host_keys`; none without the file. */
|
|
24
|
+
export async function hostKeysIn(root) {
|
|
25
|
+
return (await collectionSettingsIn(root)).hostKeys;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=collection-settings.js.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { withoutReplacedFiles } from "./group-precedence.js";
|
|
1
2
|
import { agentsOverlay } from "./agents.js";
|
|
2
3
|
import { pipelinesOverlay } from "./pipelines.js";
|
|
3
4
|
import { isReadPath } from "./paths.js";
|
|
4
|
-
export function collectionOverlay(
|
|
5
|
+
export function collectionOverlay(whole) {
|
|
6
|
+
const input = { ...whole, files: withoutReplacedFiles(whole.files, whole.groups ?? []) };
|
|
5
7
|
const agentsSet = agentsOverlay(input);
|
|
6
8
|
const pipelinesSet = pipelinesOverlay(input, agentsSet.agents);
|
|
7
9
|
const { agents } = agentsSet;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type CollectionFile } from "./paths.js";
|
|
2
|
+
/** The collection's files, less each line file and agent file that sits in a listed group when a later listed group holds the same line or agent; the folder of a line is no group. */
|
|
3
|
+
export declare function withoutReplacedFiles(files: readonly CollectionFile[], groups: readonly string[]): CollectionFile[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { agentFileGroupOf, agentFileOf, lineFilePlaceOf } from "./paths.js";
|
|
2
|
+
/** The collection's files, less each line file and agent file that sits in a listed group when a later listed group holds the same line or agent; the folder of a line is no group. */
|
|
3
|
+
export function withoutReplacedFiles(files, groups) {
|
|
4
|
+
const lineFolders = new Set(files.flatMap((file) => lineFilePlaceOf(file.path)?.folderPath ?? []));
|
|
5
|
+
const claims = files.flatMap((file) => claimOf(file, lineFolders));
|
|
6
|
+
const kept = new Set(withoutEarlierGroups(claims, groups).map((claim) => claim.file));
|
|
7
|
+
const claimed = new Set(claims.map((claim) => claim.file));
|
|
8
|
+
return files.filter((file) => kept.has(file) || !claimed.has(file));
|
|
9
|
+
}
|
|
10
|
+
function claimOf(file, lineFolders) {
|
|
11
|
+
const line = lineFilePlaceOf(file.path);
|
|
12
|
+
const agent = agentFileOf(file.path);
|
|
13
|
+
const claim = line ? { name: `line ${line.folder}`, group: line.group } : agent && { name: `agent ${agent.agent}`, group: agentFileGroupOf(file.path) };
|
|
14
|
+
return claim ? [{ file, name: claim.name, group: claim.group && !lineFolders.has(claim.group) ? claim.group : undefined }] : [];
|
|
15
|
+
}
|
|
16
|
+
function withoutEarlierGroups(claims, groups) {
|
|
17
|
+
const rankOf = (group) => (group === undefined ? -1 : groups.indexOf(group));
|
|
18
|
+
return claims.filter((claim) => rankOf(claim.group) < 0 || !claims.some((other) => other.name === claim.name && rankOf(other.group) > rankOf(claim.group)));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=group-precedence.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CollectionFile, type LineFilePlace } from "./paths.js";
|
|
2
|
+
import { type Refusal } from "./refusal.js";
|
|
3
|
+
/** A line file of a collection, with its place: the line's name and the group folder it may sit in. */
|
|
4
|
+
export type LineFile = CollectionFile & LineFilePlace;
|
|
5
|
+
/** The line files a collection reads, in the order lines are put to the host, and the refusals of the rest. */
|
|
6
|
+
export interface LineLayout {
|
|
7
|
+
read: LineFile[];
|
|
8
|
+
refused: Refusal[];
|
|
9
|
+
}
|
|
10
|
+
/** The line files a collection reads, and the ones its layout refuses, decided from paths alone. */
|
|
11
|
+
export declare function lineLayoutOf(files: readonly CollectionFile[]): LineLayout;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Which line files a collection reads, decided from paths alone: a line held twice in one folder, a line folder used as a group, and a second folder for one line name are refused.
|
|
2
|
+
import { enforce } from "./enforce.js";
|
|
3
|
+
import { FORMER_LINE_FILE, LINE_FILE, lineFilePlaceOf } from "./paths.js";
|
|
4
|
+
import { attempt } from "./refusal.js";
|
|
5
|
+
/** The line files a collection reads, and the ones its layout refuses, decided from paths alone. */
|
|
6
|
+
export function lineLayoutOf(files) {
|
|
7
|
+
const lineFiles = lineFilesOf(files);
|
|
8
|
+
const superseded = supersededBy(lineFiles);
|
|
9
|
+
const lineFolders = new Set(lineFiles.map((file) => file.folderPath));
|
|
10
|
+
const setBy = new Map();
|
|
11
|
+
const read = [];
|
|
12
|
+
const refused = [];
|
|
13
|
+
for (const file of lineFiles) {
|
|
14
|
+
const result = attempt(file.path, () => {
|
|
15
|
+
enforce(!superseded.has(file.path), `the folder ${file.folder} holds its line twice: ${LINE_FILE} is read, so remove ${FORMER_LINE_FILE}`);
|
|
16
|
+
enforce(file.group === undefined || !lineFolders.has(file.group), `the folder ${file.group} holds a line, so it is not a group: move ${file.folder} out of it`);
|
|
17
|
+
enforce(!setBy.has(file.folder), `${file.folder} is already set by ${setBy.get(file.folder)}`);
|
|
18
|
+
setBy.set(file.folder, file.path);
|
|
19
|
+
});
|
|
20
|
+
if ("refusal" in result) {
|
|
21
|
+
refused.push(result.refusal);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
read.push(file);
|
|
25
|
+
}
|
|
26
|
+
return { read, refused };
|
|
27
|
+
}
|
|
28
|
+
// 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.
|
|
29
|
+
function supersededBy(lineFiles) {
|
|
30
|
+
const named = new Set(lineFiles.filter((file) => file.path.endsWith(`/${LINE_FILE}`)).map((file) => file.folderPath));
|
|
31
|
+
const former = lineFiles.filter((file) => file.path.endsWith(`/${FORMER_LINE_FILE}`) && named.has(file.folderPath));
|
|
32
|
+
return new Set(former.map((file) => file.path));
|
|
33
|
+
}
|
|
34
|
+
function lineFilesOf(files) {
|
|
35
|
+
return files
|
|
36
|
+
.flatMap((file) => {
|
|
37
|
+
const place = lineFilePlaceOf(file.path);
|
|
38
|
+
return place ? [{ ...file, ...place }] : [];
|
|
39
|
+
})
|
|
40
|
+
.sort(byLineNameThenPath);
|
|
41
|
+
}
|
|
42
|
+
// By line name, not path, so a line moved into a group folder keeps its place in the order lines are put to the host; among files of one name, path order decides which is read.
|
|
43
|
+
function byLineNameThenPath(left, right) {
|
|
44
|
+
return left.folder.localeCompare(right.folder) || left.path.localeCompare(right.path);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=line-layout.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// A line change drawn as two Mermaid flowcharts: before marks what head removes, after marks what head adds; both mark what changed.
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
const CHANGE_STYLES = {
|
|
4
|
+
added: "stroke:#2da44e,stroke-width:3px",
|
|
5
|
+
removed: "stroke:#cf222e,stroke-width:3px,stroke-dasharray:4 3",
|
|
6
|
+
changed: "stroke:#bf8700,stroke-width:3px",
|
|
7
|
+
};
|
|
8
|
+
const STYLED_CHANGES = ["added", "removed", "changed"];
|
|
9
|
+
const LABEL_ENTITIES = [
|
|
10
|
+
['"', "#quot;"],
|
|
11
|
+
["<", "#lt;"],
|
|
12
|
+
[">", "#gt;"],
|
|
13
|
+
["|", "#124;"],
|
|
14
|
+
];
|
|
15
|
+
const EMPTY_GRAPH = { nodes: [], edges: [] };
|
|
16
|
+
export function afterGraphOf(base, head) {
|
|
17
|
+
return flowchartOf(head, base ?? EMPTY_GRAPH, "added");
|
|
18
|
+
}
|
|
19
|
+
export function beforeGraphOf(base, head) {
|
|
20
|
+
return flowchartOf(base, head ?? EMPTY_GRAPH, "removed");
|
|
21
|
+
}
|
|
22
|
+
function flowchartOf(shown, other, onlyShownChange) {
|
|
23
|
+
const nodes = classifyAgainst(shown.nodes, other.nodes, (node) => node.id, onlyShownChange);
|
|
24
|
+
const edges = classifyAgainst(shown.edges, other.edges, edgeKeyOf, onlyShownChange);
|
|
25
|
+
return [
|
|
26
|
+
"flowchart LR",
|
|
27
|
+
...nodes.map(({ part }) => ` ${mermaidIdOf(part.id)}["${labelOf(part.id)}"]`),
|
|
28
|
+
...edges.map(({ part }) => ` ${mermaidIdOf(part.from)} -->|"${labelOf(edgeLabelOf(part))}"| ${mermaidIdOf(part.to)}`),
|
|
29
|
+
...classLinesOf(nodes),
|
|
30
|
+
...linkStyleLinesOf(edges),
|
|
31
|
+
].join("\n");
|
|
32
|
+
}
|
|
33
|
+
function classifyAgainst(shownParts, otherParts, keyOf, onlyShownChange) {
|
|
34
|
+
const otherByKey = new Map(otherParts.map((part) => [keyOf(part), part]));
|
|
35
|
+
return shownParts.map((part) => {
|
|
36
|
+
const key = keyOf(part);
|
|
37
|
+
if (!otherByKey.has(key))
|
|
38
|
+
return { part, change: onlyShownChange };
|
|
39
|
+
const change = isDeepStrictEqual(otherByKey.get(key), part)
|
|
40
|
+
? "kept"
|
|
41
|
+
: "changed";
|
|
42
|
+
return { part, change };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function edgeKeyOf(edge) {
|
|
46
|
+
return `${edge.from}|${edge.to}|${edge.on}`;
|
|
47
|
+
}
|
|
48
|
+
function edgeLabelOf(edge) {
|
|
49
|
+
const iterationCap = edge.iterationMax === undefined ? "" : ` (max ${edge.iterationMax})`;
|
|
50
|
+
const unattendedCap = edge.unattendedMax === undefined
|
|
51
|
+
? ""
|
|
52
|
+
: ` (unattended ${edge.unattendedMax})`;
|
|
53
|
+
return `${edge.on}${iterationCap}${unattendedCap}`;
|
|
54
|
+
}
|
|
55
|
+
function classLinesOf(nodes) {
|
|
56
|
+
return STYLED_CHANGES.flatMap((change) => {
|
|
57
|
+
const ids = nodes
|
|
58
|
+
.filter((node) => node.change === change)
|
|
59
|
+
.map((node) => mermaidIdOf(node.part.id));
|
|
60
|
+
return ids.length === 0
|
|
61
|
+
? []
|
|
62
|
+
: [
|
|
63
|
+
` classDef ${change} ${CHANGE_STYLES[change]}`,
|
|
64
|
+
` class ${ids.join(",")} ${change}`,
|
|
65
|
+
];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function linkStyleLinesOf(edges) {
|
|
69
|
+
return STYLED_CHANGES.flatMap((change) => edges.flatMap((edge, index) => edge.change === change
|
|
70
|
+
? [` linkStyle ${index} ${CHANGE_STYLES[change]}`]
|
|
71
|
+
: []));
|
|
72
|
+
}
|
|
73
|
+
function mermaidIdOf(id) {
|
|
74
|
+
return id.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
75
|
+
}
|
|
76
|
+
function labelOf(id) {
|
|
77
|
+
return LABEL_ENTITIES.reduce((label, [character, entity]) => label.replaceAll(character, entity), id);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=line-mermaid.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ShippedCatalog } from "./agents.js";
|
|
2
2
|
import { type CollectionOverlay } from "./collection.js";
|
|
3
|
+
export { COLLECTION_SETTINGS_FILE, hostKeysIn } from "./collection-settings.js";
|
|
3
4
|
import type { Environment } from "./environment.js";
|
|
4
5
|
import { type CollectionFile } from "./paths.js";
|
|
5
6
|
export declare function lintCollectionDirectory(root: string, hostKeys?: readonly string[], shipped?: ShippedCatalog): Promise<CollectionOverlay>;
|
|
@@ -16,17 +17,17 @@ export interface LintCommand {
|
|
|
16
17
|
hostKeys: readonly string[];
|
|
17
18
|
/** A directory in the layout of a collection, holding what the host ships. */
|
|
18
19
|
shippedDirectory?: string;
|
|
20
|
+
/** A directory holding the collection to compare with: lint's lines go to err and out holds only the change report. */
|
|
21
|
+
graphAgainstDirectory?: string;
|
|
19
22
|
}
|
|
20
|
-
/**
|
|
21
|
-
export
|
|
23
|
+
/** Where the lint command prints: out for what a caller reads, err for what a person reads. */
|
|
24
|
+
export interface LintOutput {
|
|
22
25
|
out: (line: string) => void;
|
|
23
26
|
err: (line: string) => void;
|
|
24
|
-
}
|
|
27
|
+
}
|
|
28
|
+
/** The `lint` command: the exit code is 0 clean, 1 refused, 2 when the call is wrong. */
|
|
29
|
+
export declare function lintCommand(given: LintCommand, usage: string, output: LintOutput): Promise<number>;
|
|
25
30
|
/** Prints the refused files and answers the exit code: 0 clean, 1 refused. */
|
|
26
31
|
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
32
|
/** The files of a collection on disk, each with its path from the root: the ones a collection reads or refuses. */
|
|
32
33
|
export declare function collectionFilesIn(root: string): Promise<CollectionFile[]>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// The overlay of a collection on a local directory, and the lines a lint prints about it: no floor, no network.
|
|
2
2
|
import { readdir, readFile } from "node:fs/promises";
|
|
3
3
|
import { join, relative, sep } from "node:path";
|
|
4
|
-
import { parse } from "yaml";
|
|
5
4
|
import { agentsOverlay } from "./agents.js";
|
|
6
5
|
import { collectionOverlay } from "./collection.js";
|
|
6
|
+
import { changeReportOf } from "./change-report.js";
|
|
7
|
+
import { changedLines } from "./changed-lines.js";
|
|
8
|
+
import { collectionSettingsIn } from "./collection-settings.js";
|
|
9
|
+
export { COLLECTION_SETTINGS_FILE, hostKeysIn } from "./collection-settings.js";
|
|
7
10
|
import { enforce } from "./enforce.js";
|
|
8
11
|
import { isCollectionFile, pipelineFolderOf } from "./paths.js";
|
|
9
12
|
/** Stands in for the install's environment: whether a variable is set there is not the collection's to know. */
|
|
@@ -15,8 +18,9 @@ export async function lintCollectionDirectory(root, hostKeys = [], shipped = NOT
|
|
|
15
18
|
}
|
|
16
19
|
/** 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
20
|
export async function readCollectionDirectory(root, given) {
|
|
18
|
-
const
|
|
19
|
-
|
|
21
|
+
const settings = await collectionSettingsIn(root);
|
|
22
|
+
const hostKeys = [...given.hostKeys, ...settings.hostKeys];
|
|
23
|
+
return collectionOverlay({ files: await collectionFilesIn(root), ...given, hostKeys, groups: settings.groups, shipped: given.shipped ?? NOTHING_SHIPPED });
|
|
20
24
|
}
|
|
21
25
|
/** The catalog a directory laid out as a collection stands for: the lines and the agents it holds are the ones shipped. */
|
|
22
26
|
export async function shippedCatalogIn(root, hostKeys = []) {
|
|
@@ -33,11 +37,28 @@ export async function lintCommand(given, usage, output) {
|
|
|
33
37
|
return 2;
|
|
34
38
|
}
|
|
35
39
|
const shipped = given.shippedDirectory ? await shippedCatalogIn(given.shippedDirectory, given.hostKeys) : undefined;
|
|
36
|
-
|
|
40
|
+
if (!given.graphAgainstDirectory)
|
|
41
|
+
return printCollectionLint(given.directory, given.hostKeys, output.out, shipped);
|
|
42
|
+
const head = await lintCollectionDirectory(given.directory, given.hostKeys, shipped);
|
|
43
|
+
const code = printLintOf(head, output.err);
|
|
44
|
+
if (code !== 0)
|
|
45
|
+
return code;
|
|
46
|
+
printChangeReport(head, await lintCollectionDirectory(given.graphAgainstDirectory, given.hostKeys, shipped), output);
|
|
47
|
+
return code;
|
|
48
|
+
}
|
|
49
|
+
/** Prints what a graph-against run adds to the head's lint: the change report, or why there is none. */
|
|
50
|
+
function printChangeReport(head, base, output) {
|
|
51
|
+
if (base.refused.length > 0)
|
|
52
|
+
return output.err("no change report: the collection to compare with is refused");
|
|
53
|
+
const report = changeReportOf(changedLines(base.pipelines, head.pipelines));
|
|
54
|
+
if (report)
|
|
55
|
+
output.out(report);
|
|
37
56
|
}
|
|
38
57
|
/** Prints the refused files and answers the exit code: 0 clean, 1 refused. */
|
|
39
58
|
export async function printCollectionLint(root, hostKeys, print, shipped = NOTHING_SHIPPED) {
|
|
40
|
-
|
|
59
|
+
return printLintOf(await lintCollectionDirectory(root, hostKeys, shipped), print);
|
|
60
|
+
}
|
|
61
|
+
function printLintOf({ refused, counts }, print) {
|
|
41
62
|
for (const { path, reason } of refused)
|
|
42
63
|
print(`${path}: ${reason}`);
|
|
43
64
|
if (refused.length > 0)
|
|
@@ -45,16 +66,6 @@ export async function printCollectionLint(root, hostKeys, print, shipped = NOTHI
|
|
|
45
66
|
print(`collection ok: ${counts.agents} agents, ${counts.pipelines} pipelines, ${counts.extensions} extensions`);
|
|
46
67
|
return 0;
|
|
47
68
|
}
|
|
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
69
|
/** The files of a collection on disk, each with its path from the root: the ones a collection reads or refuses. */
|
|
59
70
|
export async function collectionFilesIn(root) {
|
|
60
71
|
const entries = await readdir(root, { recursive: true, withFileTypes: true });
|
|
@@ -98,11 +98,11 @@ function nodeProblems(supply, position, prompts) {
|
|
|
98
98
|
...unseededNeeds(supply, stationNode),
|
|
99
99
|
];
|
|
100
100
|
}
|
|
101
|
-
// A walk revisiting a node needs iteration_max to bound the loop.
|
|
101
|
+
// A walk revisiting a node needs iteration_max or unattended_max to bound the loop.
|
|
102
102
|
function unboundedRetries(checked) {
|
|
103
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`));
|
|
104
|
+
const backEdges = edges.filter((edge) => edge.from === edge.to && edge.iteration_max === undefined && edge.unattended_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 and no unattended_max; the walk would retry without bound`));
|
|
106
106
|
}
|
|
107
107
|
// conversation_key must name a declared arg so the floor can key the conversation.
|
|
108
108
|
function unresolvableConversationKeys(checked) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
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"];
|
|
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", "unknown-key", "unreachable", "unseeded-need", "unsupplied-input", "unresolvable-conversation-key"];
|
|
4
4
|
export type PipelineRule = (typeof PIPELINE_RULES)[number];
|
|
5
5
|
export interface PipelineProblem {
|
|
6
6
|
line: string;
|
|
@@ -12,6 +12,7 @@ declare const bagItemSchema: z.ZodObject<{
|
|
|
12
12
|
name: z.ZodOptional<z.ZodString>;
|
|
13
13
|
kind: z.ZodOptional<z.ZodString>;
|
|
14
14
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
15
16
|
collect: z.ZodOptional<z.ZodUnknown>;
|
|
16
17
|
}, z.core.$loose>;
|
|
17
18
|
declare const stationSchema: z.ZodObject<{
|
|
@@ -22,12 +23,14 @@ declare const stationSchema: z.ZodObject<{
|
|
|
22
23
|
name: z.ZodOptional<z.ZodString>;
|
|
23
24
|
kind: z.ZodOptional<z.ZodString>;
|
|
24
25
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
26
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
25
27
|
collect: z.ZodOptional<z.ZodUnknown>;
|
|
26
28
|
}, z.core.$loose>>>;
|
|
27
29
|
produces: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
28
30
|
name: z.ZodOptional<z.ZodString>;
|
|
29
31
|
kind: z.ZodOptional<z.ZodString>;
|
|
30
32
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
31
34
|
collect: z.ZodOptional<z.ZodUnknown>;
|
|
32
35
|
}, z.core.$loose>>>;
|
|
33
36
|
conversation: z.ZodOptional<z.ZodString>;
|
|
@@ -55,6 +58,7 @@ declare const pipelineSchema: z.ZodObject<{
|
|
|
55
58
|
to: z.ZodDefault<z.ZodString>;
|
|
56
59
|
on: z.ZodOptional<z.ZodString>;
|
|
57
60
|
iteration_max: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
unattended_max: z.ZodOptional<z.ZodNumber>;
|
|
58
62
|
}, z.core.$loose>>>;
|
|
59
63
|
}, z.core.$loose>;
|
|
60
64
|
stations: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
@@ -65,12 +69,14 @@ declare const pipelineSchema: z.ZodObject<{
|
|
|
65
69
|
name: z.ZodOptional<z.ZodString>;
|
|
66
70
|
kind: z.ZodOptional<z.ZodString>;
|
|
67
71
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
68
73
|
collect: z.ZodOptional<z.ZodUnknown>;
|
|
69
74
|
}, z.core.$loose>>>;
|
|
70
75
|
produces: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
71
76
|
name: z.ZodOptional<z.ZodString>;
|
|
72
77
|
kind: z.ZodOptional<z.ZodString>;
|
|
73
78
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
79
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
74
80
|
collect: z.ZodOptional<z.ZodUnknown>;
|
|
75
81
|
}, z.core.$loose>>>;
|
|
76
82
|
conversation: z.ZodOptional<z.ZodString>;
|
|
@@ -13,6 +13,7 @@ export const PIPELINE_RULES = [
|
|
|
13
13
|
"undeclared-outcome",
|
|
14
14
|
"unbounded-retry",
|
|
15
15
|
"unkeyed-line",
|
|
16
|
+
"unknown-key",
|
|
16
17
|
"unreachable",
|
|
17
18
|
"unseeded-need",
|
|
18
19
|
"unsupplied-input",
|
|
@@ -23,6 +24,7 @@ const bagItemSchema = z
|
|
|
23
24
|
name: z.string().optional(),
|
|
24
25
|
kind: z.string().optional(),
|
|
25
26
|
optional: z.boolean().optional(),
|
|
27
|
+
fresh: z.boolean().optional(),
|
|
26
28
|
collect: z.unknown().optional(),
|
|
27
29
|
})
|
|
28
30
|
.loose();
|
|
@@ -73,6 +75,7 @@ const pipelineSchema = z
|
|
|
73
75
|
to: z.string().default(""),
|
|
74
76
|
on: z.string().optional(),
|
|
75
77
|
iteration_max: z.number().optional(),
|
|
78
|
+
unattended_max: z.number().optional(),
|
|
76
79
|
})
|
|
77
80
|
.loose())
|
|
78
81
|
.default([]),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function noteWithin(ids: string[], room: number): string[];
|