@re-cinq/floor-pipeline 0.7.0 → 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 CHANGED
@@ -141,6 +141,14 @@ floor-pipeline lint collection/ --shipped shipped/ --host-key execution_mode
141
141
 
142
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.
143
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
+
144
152
  ```
145
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
146
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
- 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 });
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}:`);
@@ -0,0 +1,3 @@
1
+ import type { LineChange } from "./changed-lines.js";
2
+ export declare const COMMENT_LIMIT = 65000;
3
+ export declare function changeReportOf(changes: LineChange[], limit?: number): string;
@@ -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,7 @@
1
+ import type { Fields, Pipeline } from "../shape.js";
2
+ export interface LineChange {
3
+ id: string;
4
+ base?: Fields;
5
+ head?: Fields;
6
+ }
7
+ export declare function changedLines(base: Pipeline[], head: Pipeline[]): LineChange[];
@@ -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,3 @@
1
+ import type { LineBody } from "@re-cinq/floor-contracts";
2
+ export declare function afterGraphOf(base: LineBody | undefined, head: LineBody): string;
3
+ export declare function beforeGraphOf(base: LineBody, head: LineBody | undefined): string;
@@ -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
@@ -17,12 +17,16 @@ export interface LintCommand {
17
17
  hostKeys: readonly string[];
18
18
  /** A directory in the layout of a collection, holding what the host ships. */
19
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;
20
22
  }
21
- /** The `lint` command: the exit code is 0 clean, 1 refused, 2 when the call is wrong. */
22
- export declare function lintCommand(given: LintCommand, usage: string, output: {
23
+ /** Where the lint command prints: out for what a caller reads, err for what a person reads. */
24
+ export interface LintOutput {
23
25
  out: (line: string) => void;
24
26
  err: (line: string) => void;
25
- }): Promise<number>;
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>;
26
30
  /** Prints the refused files and answers the exit code: 0 clean, 1 refused. */
27
31
  export declare function printCollectionLint(root: string, hostKeys: readonly string[], print: (line: string) => void, shipped?: ShippedCatalog): Promise<number>;
28
32
  /** The files of a collection on disk, each with its path from the root: the ones a collection reads or refuses. */
@@ -3,6 +3,8 @@ import { readdir, readFile } from "node:fs/promises";
3
3
  import { join, relative, sep } from "node:path";
4
4
  import { agentsOverlay } from "./agents.js";
5
5
  import { collectionOverlay } from "./collection.js";
6
+ import { changeReportOf } from "./change-report.js";
7
+ import { changedLines } from "./changed-lines.js";
6
8
  import { collectionSettingsIn } from "./collection-settings.js";
7
9
  export { COLLECTION_SETTINGS_FILE, hostKeysIn } from "./collection-settings.js";
8
10
  import { enforce } from "./enforce.js";
@@ -35,11 +37,28 @@ export async function lintCommand(given, usage, output) {
35
37
  return 2;
36
38
  }
37
39
  const shipped = given.shippedDirectory ? await shippedCatalogIn(given.shippedDirectory, given.hostKeys) : undefined;
38
- return printCollectionLint(given.directory, given.hostKeys, output.out, shipped);
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);
39
56
  }
40
57
  /** Prints the refused files and answers the exit code: 0 clean, 1 refused. */
41
58
  export async function printCollectionLint(root, hostKeys, print, shipped = NOTHING_SHIPPED) {
42
- const { refused, counts } = await lintCollectionDirectory(root, hostKeys, shipped);
59
+ return printLintOf(await lintCollectionDirectory(root, hostKeys, shipped), print);
60
+ }
61
+ function printLintOf({ refused, counts }, print) {
43
62
  for (const { path, reason } of refused)
44
63
  print(`${path}: ${reason}`);
45
64
  if (refused.length > 0)
@@ -0,0 +1 @@
1
+ export declare function noteWithin(ids: string[], room: number): string[];
@@ -0,0 +1,36 @@
1
+ // The note naming the lines left undrawn, cut to fit the room left in a comment.
2
+ const NOTE_LEAD = "These lines changed too, but their graphs would not fit in one comment: ";
3
+ const SEPARATOR = ", ";
4
+ export function noteWithin(ids, room) {
5
+ if (ids.length === 0)
6
+ return [];
7
+ const tags = ids.map((id) => `\`${id}\``);
8
+ return [`${NOTE_LEAD}${listOf(tags, room - NOTE_LEAD.length)}`, ""];
9
+ }
10
+ function listOf(tags, listRoom) {
11
+ const whole = `${tags.join(SEPARATOR)}.`;
12
+ if (whole.length <= listRoom)
13
+ return whole;
14
+ const listedCount = fittingCountOf(tags, listRoom);
15
+ const leftOut = tags.length - listedCount;
16
+ if (listedCount === 0)
17
+ return `${leftOut} more.`;
18
+ return `${tags.slice(0, listedCount).join(SEPARATOR)}${moreOf(leftOut)}`;
19
+ }
20
+ function fittingCountOf(tags, listRoom) {
21
+ let listedCount = 0;
22
+ let used = 0;
23
+ for (const [index, tag] of tags.entries()) {
24
+ used += tag.length + (index > 0 ? SEPARATOR.length : 0);
25
+ if (used > listRoom)
26
+ break;
27
+ const leftOut = tags.length - index - 1;
28
+ if (used + moreOf(leftOut).length <= listRoom)
29
+ listedCount = index + 1;
30
+ }
31
+ return listedCount;
32
+ }
33
+ function moreOf(leftOut) {
34
+ return ` and ${leftOut} more.`;
35
+ }
36
+ //# sourceMappingURL=note-within.js.map
@@ -0,0 +1,4 @@
1
+ import type { LintCommand } from "./collection/lint-directory.js";
2
+ type LintFlags = Partial<Record<"host-key", string[]> & Record<"shipped" | "graph-against", string>>;
3
+ export declare function lintCommandGiven(positionals: readonly string[], values: LintFlags): LintCommand;
4
+ export {};
@@ -0,0 +1,9 @@
1
+ export function lintCommandGiven(positionals, values) {
2
+ return {
3
+ directory: positionals[1],
4
+ hostKeys: values["host-key"] ?? [],
5
+ shippedDirectory: values.shipped,
6
+ graphAgainstDirectory: values["graph-against"],
7
+ };
8
+ }
9
+ //# sourceMappingURL=lint-command-given.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@re-cinq/floor-pipeline",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
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": {
@@ -57,9 +57,9 @@
57
57
  "typecheck": "tsc --noEmit"
58
58
  },
59
59
  "dependencies": {
60
- "@re-cinq/floor-assembly-lines": "0.7.0",
61
- "@re-cinq/floor-client": "0.7.0",
62
- "@re-cinq/floor-contracts": "0.7.0",
60
+ "@re-cinq/floor-assembly-lines": "0.8.0",
61
+ "@re-cinq/floor-client": "0.8.0",
62
+ "@re-cinq/floor-contracts": "0.8.0",
63
63
  "yaml": "^2.7.0",
64
64
  "zod": "^4.5.4"
65
65
  },