Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 0 to 1

Compare

+71 −0 in 1 place
new file, 71 lines
1+// Which pipelines an event starts, and their jobs in waves (abso issue 176,
2+// under 138). A pure function of a checked pipeline file (pipeline.ts) and the
3+// event: nothing runs here. A wave is every job whose needs are all in earlier
4+// waves, so the jobs of one wave can run side by side. `abso pipeline check
5+// --on <event>` shows it, and a runner reads the same plan.
6+
7+import type { Job, Pipeline, PipelineFile } from "./pipeline.ts";
8+
9+/** What happened, and in which space (shared, or a named draft). */
10+export type PipelineEvent =
11+ | { readonly kind: "publish" | "draft" | "green" | "land"; readonly space: string }
12+ /** Someone starts one pipeline by name. */
13+ | { readonly kind: "hand"; readonly pipeline: string; readonly space: string }
14+ /** A schedule's time came: `every` as the file wrote it. Schedules run on shared. */
15+ | { readonly kind: "schedule"; readonly every: string };
17+export interface PlannedPipeline {
18+ readonly name: string;
19+ /** Job names, wave by wave. */
20+ readonly waves: readonly (readonly string[])[];
21+ readonly required: readonly string[];
22+}
24+export interface Plan {
25+ readonly start: readonly PlannedPipeline[];
26+ /** The pipelines that don't start, each with why. */
27+ readonly skip: readonly { readonly name: string; readonly why: string }[];
28+}
30+export function plan(file: PipelineFile, event: PipelineEvent): Plan {
31+ const start: PlannedPipeline[] = [];
32+ const skip: { name: string; why: string }[] = [];
33+ const space = event.kind === "schedule" ? "shared" : event.space;
34+ for (const p of file.pipelines) {
35+ const why = notStarting(p, event, space);
36+ if (why) skip.push({ name: p.name, why });
37+ else start.push({ name: p.name, waves: waves(p.jobs), required: p.required });
38+ }
39+ return { start, skip };
40+}
42+/** Why `p` doesn't start on `event`, or undefined when it does. */
43+function notStarting(p: Pipeline, event: PipelineEvent, space: string): string | undefined {
44+ if (event.kind === "hand" && event.pipeline !== p.name) return "another pipeline was started by hand";
45+ const on =
46+ event.kind === "schedule"
47+ ? p.on.some((t) => typeof t !== "string" && t.every === event.every)
48+ : p.on.includes(event.kind);
49+ if (!on) return event.kind === "schedule" ? `has no schedule "${event.every}"` : `doesn't run on ${event.kind}`;
50+ if (p.only && !p.only.includes(space)) return `runs only for ${p.only.join(", ")}, not ${space}`;
51+ // The file check refuses this already; the plan holds the line too.
52+ if (event.kind === "draft" && p.jobs.some((j) => j.secrets.length > 0))
53+ return "holds secrets, and a draft runs unpublished code";
54+ return undefined;
55+}
57+/** The jobs in waves: each wave holds every job whose needs all came in earlier waves. */
58+export function waves(jobs: readonly Job[]): string[][] {
59+ const done = new Set<string>();
60+ const out: string[][] = [];
61+ let left = [...jobs];
62+ while (left.length > 0) {
63+ const wave = left.filter((j) => j.needs.every((n) => done.has(n)));
64+ // A checked file has no cycles; stop rather than loop if one ever got here.
65+ if (wave.length === 0) throw new Error(`jobs ${left.map((j) => j.name).join(", ")} wait on each other`);
66+ for (const j of wave) done.add(j.name);
67+ out.push(wave.map((j) => j.name));
68+ left = left.filter((j) => !done.has(j.name));
69+ }
70+ return out;
71+}
MCP
compare on this site's /mcp
CLI
abso diff 0 1 src/pipeline/plan.ts --json
JSON
/christopher/abso-core/compare/0..1?file=src%2Fpipeline%2Fplan.ts&format=json