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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/src/pipeline-commands.ts?version=101&format=json
183 linesinfra-pipeline 51% · First import 22% · infra-split 21% · rename 5% · review 1%Last change rename in version 101, 5 versions changed it

You're reading version 101. The newest is 318, and no version since then changed this file. Go to the newestCompare with 318

1// `abso pipeline check [file]`: reads the folder's pipeline file and says what's
2// wrong with it, before a publish. Read-only, with no server: the reading and
3// checking are src/pipeline/pipeline.ts. `abso pipeline runs` asks the server
4// what the project's pipelines did: the runs, one run's jobs, a job's log.
5
6import { existsSync, readFileSync } from "node:fs";
7import { basename, join, resolve } from "node:path";
8import { readPipelineFile, triggerWord } from "../../src/pipeline/pipeline.ts";
9import { type PipelineEvent, plan } from "../../src/pipeline/plan.ts";
10import { type Parsed, str, UsageError } from "./args.ts";
11import { type Env, EXIT, type Output, open } from "./command-env.ts";
12import { findRoot } from "./config.ts";
14/** The names a pipeline file may have, in the order they're looked for. */
15export const PIPELINE_FILES = ["abso.yml", "abso.yaml", "abso.json", "avcs.json"] as const;
17export async function runPipeline(args: Parsed, env: Env): Promise<Output> {
18 const [sub, file, ...rest] = args.positionals;
19 if (sub === "runs") return runRuns(file, rest, args, env);
20 if (sub !== "check" || rest.length > 0)
21 throw new UsageError("abso pipeline check [file] | abso pipeline runs [<run>] [--log <pipeline.job>]");
22 const root = findRoot(env.cwd) ?? env.cwd;
23 let path: string;
24 if (file !== undefined) {
25 path = resolve(env.cwd, file);
26 if (!existsSync(path)) throw new UsageError(`no file ${file}`);
27 } else {
28 const found = PIPELINE_FILES.map((n) => join(root, n)).find((p) => existsSync(p));
29 if (!found) throw new UsageError(`no pipeline file in ${root}: looked for ${PIPELINE_FILES.join(", ")}`);
30 path = found;
31 }
32 const name = basename(path);
33 const checked = readPipelineFile(readFileSync(path, "utf8"), name);
34 if (!checked.ok) {
35 const problems = checked.problems.map((p) => ({ path: p.at, message: p.message }));
36 return {
37 text: `${name} has ${problems.length === 1 ? "1 problem" : `${problems.length} problems`}:\n${problems.map((p) => ` ${p.path}: ${p.message}`).join("\n")}\n`,
38 json: { file: name, problems },
39 exit: EXIT.error,
40 };
41 }
42 const { pipelines } = checked.file;
43 const on = str(args, "on");
44 if (on !== undefined) {
45 const event = eventFrom(on, args);
46 const planned = plan(checked.file, event);
47 const said =
48 event.kind === "schedule"
49 ? `On the schedule "${event.every}"`
50 : `On ${triggerWord(event.kind)}${event.kind === "hand" ? ` of ${event.pipeline}` : ""} in ${event.space}`;
51 const lines = [
52 ...planned.start.flatMap((p) => [
53 ` ${p.name} starts:`,
54 ...p.waves.map(
55 (w, i) => ` ${i + 1}. ${w.map((j) => `${j}${p.required.includes(j) ? " (required)" : ""}`).join(", ")}`,
56 ),
57 ]),
58 ...planned.skip.map((s) => ` ${s.name} doesn't start: ${s.why}`),
59 ];
60 return {
61 text: `${said}, ${planned.start.length === 0 ? "nothing in" : `${planned.start.length === 1 ? "1 pipeline" : `${planned.start.length} pipelines`} from`} ${name} starts; jobs on one line can run side by side.\n${lines.join("\n")}\n`,
62 json: { file: name, event: { ...event, kind: triggerWord(event.kind) }, ...planned },
63 };
64 }
65 const lines = pipelines.flatMap((p) => [
66 ` ${p.name}, on ${p.on.map((t) => (typeof t === "string" ? triggerWord(t) : `every ${t.every}`)).join(", ")}${p.only ? `, only ${p.only.join(", ")}` : ""}:`,
67 ...p.jobs.map(
68 (j) =>
69 ` ${j.name}${p.required.includes(j.name) ? " (required)" : ""}: ${j.uses ? `uses ${j.uses}` : j.run}${j.needs.length ? `, after ${j.needs.join(", ")}` : ""}`,
70 ),
71 ]);
72 return {
73 text: `${name} is fine: ${pipelines.length === 1 ? "1 pipeline" : `${pipelines.length} pipelines`}, jobs in the order they run.\n${lines.join("\n")}\n`,
74 json: {
75 file: name,
76 pipelines: pipelines.map((p) => ({ ...p, on: p.on.map((t) => (typeof t === "string" ? triggerWord(t) : t)) })),
77 },
78 };
81const KINDS = ["push", "draft", "green", "land", "hand", "schedule"] as const;
83/** --on, with --space, --pipeline (by hand) and --every (a schedule), as an event. */
84function eventFrom(on: string, args: Parsed): PipelineEvent {
85 if (!(KINDS as readonly string[]).includes(on)) throw new UsageError(`--on is one of ${KINDS.join(", ")}`);
86 const space = str(args, "space") ?? "shared";
87 if (on === "schedule") {
88 const every = str(args, "every");
89 if (!every) throw new UsageError('--on schedule takes --every "<when>", as the file writes it');
90 return { kind: "schedule", every };
91 }
92 if (on === "hand") {
93 const pipeline = str(args, "pipeline");
94 if (!pipeline) throw new UsageError("--on hand takes --pipeline <name>");
95 return { kind: "hand", pipeline, space };
96 }
97 return { kind: on === "push" ? "publish" : (on as "draft" | "green" | "land"), space };
100/** A run as the server's list gives it. */
101export interface RunSummary {
102 id: number | null;
103 version: number;
104 event: string;
105 file: string;
106 started: number;
107 ended: number | null;
108 state: string;
109 pipelines: { name: string; state: string }[];
112/** A job of one run, as the server keeps it. */
113export interface RunJob {
114 pipeline: string;
115 job: string;
116 needs: string[];
117 run?: string;
118 uses?: string;
119 state: string;
120 why?: string;
121 exit?: number | null;
122 seconds?: number;
123 since?: number;
124 log?: boolean;
125 npm?: { phase: string };
126 deploy?: { phase?: string };
129/** A time in ms as HH:MM UTC, with the date when it isn't today. */
130function at(ms: number, now: number): string {
131 const t = new Date(ms).toISOString();
132 return t.slice(0, 10) === new Date(now).toISOString().slice(0, 10)
133 ? `${t.slice(11, 16)} UTC`
134 : `${t.slice(0, 16).replace("T", " ")} UTC`;
137/** The runs, newest first, one line each. */
138export function runsText(runs: RunSummary[], now = Date.now()): string {
139 if (runs.length === 0) return "No pipeline runs yet.\n";
140 const lines = runs.map(
141 (r) =>
142 ` run ${r.id ?? "-"}: version ${r.version} (${r.event}, ${r.file}), ${r.state}, ${at(r.started, now)}${r.ended ? ` to ${at(r.ended, now)}` : ""}: ${r.pipelines.map((p) => `${p.name} ${p.state}`).join(", ")}`,
143 );
144 return `${lines.join("\n")}\nabso pipeline runs <run> shows its jobs.\n`;
147/** One run with its jobs: each job's state, why, exit, time and phase, and where its log is. */
148export function runText(run: RunSummary & { jobs: RunJob[] }, now = Date.now()): string {
149 const lines = run.jobs.map((j) => {
150 const parts = [
151 j.state,
152 j.npm ? `npm ${j.npm.phase}` : "",
153 j.deploy?.phase ? `deploy ${j.deploy.phase}` : "",
154 j.why ?? "",
155 j.exit !== undefined && j.exit !== null ? `exit ${j.exit}` : "",
156 j.seconds !== undefined ? `${j.seconds} s` : "",
157 j.state === "running" && j.since ? `since ${at(j.since, now)}` : "",
158 ].filter(Boolean);
159 const log = j.log ? `\n log: abso pipeline runs ${run.id} --log ${j.pipeline}.${j.job}` : "";
160 return ` ${j.pipeline}.${j.job} (${j.uses ? `uses ${j.uses}` : j.run}): ${parts.join(", ")}${log}`;
161 });
162 return `Run ${run.id}: version ${run.version} (${run.event}, ${run.file}), ${run.state}, ${at(run.started, now)}${run.ended ? ` to ${at(run.ended, now)}` : ""}.\n${lines.join("\n")}\n`;
165async function runRuns(runArg: string | undefined, rest: string[], args: Parsed, env: Env): Promise<Output> {
166 const usage = "abso pipeline runs [<run>] [--log <pipeline.job>]";
167 if (rest.length > 0) throw new UsageError(usage);
168 if (runArg !== undefined && !/^\d+$/.test(runArg))
169 throw new UsageError(`a run is a number (got ${runArg}): ${usage}`);
170 const log = str(args, "log");
171 if (log !== undefined && runArg === undefined) throw new UsageError(`--log needs a run: ${usage}`);
172 const { api } = open(env);
173 if (runArg === undefined) {
174 const { runs } = (await api.pipelineRuns()) as { runs: RunSummary[] };
175 return { text: runsText(runs), json: { runs } };
176 }
177 if (log !== undefined) {
178 const got = (await api.pipelineRuns(Number(runArg), log)) as { run: number; job: string; log: string };
179 return { text: got.log.endsWith("\n") ? got.log : `${got.log}\n`, json: got };
180 }
181 const got = (await api.pipelineRuns(Number(runArg))) as RunSummary & { jobs: RunJob[] };
182 return { text: runText(got), json: { ...got } };