- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/pipeline/pipeline.ts?format=json
502 linesFirst import 76% · infra-pipeline 7% · onboard 7% · approvals-page 6% · rename 3% · review 1%Last change approvals-page in version 267, 10 versions changed it
1// The pipeline file (abso issue 147, under 138): what a project declares it
2// runs, as pipelines of named jobs with dependencies. This reads the file and
3// checks its shape; nothing runs it yet. The shape is a draft, not settled, and
4// the format is still open, so it reads YAML (abso.yml) and JSON (avcs.json)
5// both.
6//
7// A file holds `defaults` and `pipelines`. Each pipeline says when it runs
8// (`on`), optionally which spaces it runs for (`only`), its `jobs`, and which
9// jobs make a version green (`required`). A job runs a command (`run`) or a
10// built-in step (`uses`), after the jobs it `needs`, and may take another
11// job's kept files (`from`) and named `secrets`, and a run job may ask for an
12// abso key on its own project (`abso: reader` or `writer`) for the length of the job. A run job may
13// say how long each of its steps may take (`timeout`, in seconds: 300 unless it says, 900 at most).
14//
15// What the check refuses: a cycle in needs; needs, required or from naming a
16// job that doesn't exist; secrets in a pipeline a draft can start, since a
17// draft runs code nobody has published; and keys it doesn't know. Every
18// problem names its place in the file, like pipelines.release.jobs.site.needs.
20import { parse as parseYaml, YAMLParseError } from "yaml";
22/** What starts a pipeline: a version of shared, an agent's draft, a version going green, a merge-queue landing, by hand, or a schedule. */
23export type Trigger = "publish" | "draft" | "green" | "land" | "hand" | { readonly every: string };
25export type Size = "small" | "standard" | "large";
27/** Where a job runs: an image from the menu, or a Dockerfile in the project (which one is still open). */
28export interface Machine {
29 readonly image?: string;
30 readonly dockerfile?: string;
31 readonly size?: Size;
32}
34export interface Job extends Machine {
35 readonly name: string;
36 readonly needs: readonly string[];
37 readonly run?: string;
38 readonly uses?: BuiltIn;
39 /** Another job's kept files, as "pipeline.job". */
40 readonly from?: string;
41 readonly keep: readonly string[];
42 readonly cache: readonly string[];
43 readonly secrets: readonly string[];
44 /** An abso key on the project for the job's length (abso 343): none unless asked. */
45 readonly abso?: "reader" | "writer";
46 /** Seconds each step of a run job may take, when it says (JOB_TIMEOUT_DEFAULT otherwise). */
47 readonly timeout?: number;
48 /** The built-in step's own settings (deploy's worker, staging, live; notify's to), as written. */
49 readonly with: Readonly<Record<string, unknown>>;
50}
52export interface Pipeline {
53 readonly name: string;
54 readonly on: readonly Trigger[];
55 /** The spaces it runs for; absent means every space its triggers reach. */
56 readonly only?: readonly string[];
57 /** In an order where each job comes after the jobs it needs. */
58 readonly jobs: readonly Job[];
59 readonly required: readonly string[];
60}
62export interface PipelineFile {
63 readonly defaults: Machine;
64 readonly pipelines: readonly Pipeline[];
65}
67/** One thing wrong, and where: a dotted path into the file, or "file" for the file as a whole. */
68export interface Problem {
69 readonly at: string;
70 readonly message: string;
71}
73export type Checked =
74 | { readonly ok: true; readonly file: PipelineFile }
75 | { readonly ok: false; readonly problems: readonly Problem[] };
77export const BUILT_INS = ["deploy", "preview", "notify", "npm-publish", "agent"] as const;
78export type BuiltIn = (typeof BUILT_INS)[number];
80/** Each built-in step's own settings, beside the keys every job has. */
81const BUILT_IN_SETTINGS: Readonly<Record<BuiltIn, readonly string[]>> = {
82 deploy: ["worker", "staging", "live"],
83 preview: [],
84 notify: ["to"],
85 // The npm packages it may publish, from the .tgz files its from: job kept, and the dist-tag (latest if none).
86 "npm-publish": ["packages", "tag"],
87 // A model reads the version's diff and acts on it as the run's own seat (abso issue 688): the instructions file it
88 // follows (a built-in review when none), the model, and what the seat may do (note: notes on the changed lines).
89 agent: ["instructions", "model", "may"],
90};
92/** What an agent step's seat may do (688). Slice 1: leave notes on the version's changed lines. */
93export const AGENT_MAY = ["note"] as const;
94/** A model as the server's AI binding names it: provider/model or Workers AI's @cf/author/model. */
95const MODEL_NAME = /^(@cf\/)?[a-z0-9][a-z0-9_.-]*\/[a-z0-9][a-z0-9_.:-]*$/i;
97/** An npm dist-tag: npm refuses one that reads as a version, so it starts with a letter. */
98const DIST_TAG = /^[a-z][a-z0-9_-]{0,31}$/;
100/** An npm package name: lower case, URL-safe, optionally under a @scope/. */
101const NPM_NAME = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
103/** The words a pipeline file writes. The word `push` is the stored event "publish" (a log entry kind that stays). */
104const TRIGGERS = ["push", "draft", "green", "land", "hand"] as const;
106/** A trigger as a file and a person say it: the stored "publish" event is written `push`. */
107export function triggerWord(t: string): string {
108 return t === "publish" ? "push" : t;
109}
110const SIZES: readonly Size[] = ["small", "standard", "large"];
111const MACHINE_KEYS = ["image", "dockerfile", "size"] as const;
112const JOB_KEYS = [
113 "needs",
114 "run",
115 "uses",
116 "from",
117 "keep",
118 "cache",
119 "secrets",
120 "abso",
121 "timeout",
122 ...MACHINE_KEYS,
123] as const;
124/** A run job's step limit when it names none, and the most it may name (the customer runner's cap too). */
125export const JOB_TIMEOUT_DEFAULT = 300;
126export const JOB_TIMEOUT_MAX = 900;
127const PIPELINE_KEYS = ["on", "only", "jobs", "required"] as const;
128/** avcs.json's keys for today's CI (worker/src/ci.ts) and the merge queue: read elsewhere, left alone here. */
129const AVCS_JSON_KEYS = ["setup", "check", "build", "out", "queue", "whole"] as const;
131const NAME = /^[a-z][a-z0-9_-]*$/;
132const SECRET = /^[A-Z][A-Z0-9_]*$/;
134/**
135 * Reads a pipeline file's text. `fileName` picks the format: .json is JSON
136 * (avcs.json keeps its other keys, which this leaves to their readers), .yml
137 * and .yaml are YAML.
138 */
139export function readPipelineFile(text: string, fileName: string): Checked {
140 const json = /\.json$/i.test(fileName);
141 if (!json && !/\.ya?ml$/i.test(fileName))
142 return fail([{ at: "file", message: `${fileName} isn't .json, .yml or .yaml, so its format can't be told` }]);
143 let doc: unknown;
144 try {
145 // YAML 1.2, the library's default: `on` is a key, not true.
146 doc = json ? JSON.parse(text) : parseYaml(text, { uniqueKeys: true, prettyErrors: true });
147 } catch (e) {
148 const where = e instanceof YAMLParseError && e.linePos ? ` at line ${e.linePos[0].line}` : "";
149 const first = String(e instanceof Error ? e.message : e).split("\n")[0];
150 return fail([{ at: "file", message: `${fileName} isn't valid ${json ? "JSON" : "YAML"}${where}: ${first}` }]);
151 }
152 return checkPipelines(doc, { avcsJson: /(^|[\\/])(abso|avcs)\.json$/i.test(fileName) });
153}
155/** Checks a parsed file. With `avcsJson`, today's CI keys beside the pipelines are allowed. */
156export function checkPipelines(doc: unknown, { avcsJson = false } = {}): Checked {
157 const problems: Problem[] = [];
158 const say = (at: string, message: string) => problems.push({ at, message });
159 if (!isRecord(doc)) return fail([{ at: "file", message: "the file must be a map with pipelines in it" }]);
160 unknownKeys(doc, ["defaults", "pipelines", ...(avcsJson ? AVCS_JSON_KEYS : [])], "", say);
161 if (avcsJson && doc.pipelines === undefined) {
162 const ci = shorthand(doc, say);
163 if (ci) doc = { ...doc, pipelines: { ci } };
164 if (!isRecord(doc)) return fail(problems);
165 }
167 const defaults = machine(doc.defaults, "defaults", say, true);
168 const pipelines: Pipeline[] = [];
169 if (doc.pipelines === undefined) say("pipelines", "is missing");
170 else if (!isRecord(doc.pipelines)) say("pipelines", "must be a map of pipeline names to pipelines");
171 else {
172 if (Object.keys(doc.pipelines).length === 0) say("pipelines", "has no pipelines");
173 for (const [name, p] of Object.entries(doc.pipelines)) {
174 const read = pipeline(name, p, `pipelines.${name}`, say);
175 if (read) pipelines.push(read);
176 }
177 }
178 // from points across pipelines, so it's checked once every pipeline is read.
179 for (const p of pipelines)
180 for (const j of p.jobs) {
181 if (j.from === undefined) continue;
182 const at = `pipelines.${p.name}.jobs.${j.name}.from`;
183 const [pn, jn, ...rest] = j.from.split(".");
184 const source = pipelines.find((q) => q.name === pn);
185 const job = source?.jobs.find((k) => k.name === jn);
186 if (!pn || !jn || rest.length) say(at, `must be <pipeline>.<job>, not ${q(j.from)}`);
187 else if (!source) say(at, `names pipeline ${q(pn)}, which doesn't exist`);
188 else if (!job) say(at, `names job ${q(jn)}, which pipeline ${q(pn)} doesn't have`);
189 else if (job.keep.length === 0) say(at, `names ${q(j.from)}, which keeps no files (give it keep)`);
190 }
191 return problems.length ? fail(problems) : { ok: true, file: { defaults, pipelines } };
192}
194type Say = (at: string, message: string) => void;
196/**
197 * avcs.json's setup, check and build, with no pipelines beside them, as the one
198 * pipeline they are shorthand for (abso issue 162): ci, the job today's CI runs
199 * (worker/src/ci.ts). Setup, then build keeping its out folder, then check, in
200 * today's order; every step required, as a failed step fails today's job. On
201 * publish only: whether CI runs on drafts by default is still open, so the
202 * shorthand doesn't add it.
203 */
204function shorthand(doc: Record<string, unknown>, say: Say): Record<string, unknown> | undefined {
205 const step = (k: "setup" | "check" | "build") => {
206 const v = doc[k];
207 if (v === undefined) return undefined;
208 if (typeof v !== "string") say(k, "must be a command");
209 // An empty command counts as none, as today's CI reads it.
210 return typeof v === "string" && v.trim() ? v : undefined;
211 };
212 const setup = step("setup");
213 const build = step("build");
214 const check = step("check");
215 const out = doc.out ?? "dist";
216 if (typeof out !== "string" || !/^[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*$/.test(out) || out.split("/").includes(".."))
217 say("out", `must be a folder under the project, like dist, not ${q(out)}`);
218 if (!setup && !build && !check) return undefined;
219 const jobs: Record<string, unknown> = {};
220 let last: string | undefined;
221 for (const [name, run] of [
222 ["setup", setup],
223 ["build", build],
224 ["check", check],
225 ] as const) {
226 if (!run) continue;
227 jobs[name] = { run, ...(last ? { needs: [last] } : {}), ...(name === "build" ? { keep: [`${out}/**`] } : {}) };
228 last = name;
229 }
230 return { on: ["push"], jobs, required: Object.keys(jobs) };
231}
233function pipeline(name: string, p: unknown, at: string, say: Say): Pipeline | undefined {
234 if (!NAME.test(name))
235 say(at, `${q(name)} isn't a usable name: lower-case letters, digits, - and _, starting with a letter`);
236 if (!isRecord(p)) {
237 say(at, "must be a map with on and jobs");
238 return undefined;
239 }
240 unknownKeys(p, PIPELINE_KEYS, at, say);
241 const on = triggers(p.on, `${at}.on`, say);
242 const only = p.only === undefined ? undefined : strings(p.only, `${at}.only`, say, "a space name or a list of them");
243 if (only?.length === 0) say(`${at}.only`, "is empty, so the pipeline would never run");
245 const jobs: Job[] = [];
246 if (p.jobs === undefined) say(`${at}.jobs`, "is missing");
247 else if (!isRecord(p.jobs)) say(`${at}.jobs`, "must be a map of job names to jobs");
248 else {
249 if (Object.keys(p.jobs).length === 0) say(`${at}.jobs`, "has no jobs");
250 for (const [jn, j] of Object.entries(p.jobs)) {
251 const read = job(jn, j, `${at}.jobs.${jn}`, say);
252 if (read) jobs.push(read);
253 }
254 }
255 const names = new Set(jobs.map((j) => j.name));
256 for (const j of jobs)
257 j.needs.forEach((n, i) => {
258 if (!names.has(n))
259 say(
260 `${at}.jobs.${j.name}.needs[${i}]`,
261 n.includes(".")
262 ? `names ${q(n)}: needs reaches only jobs in this pipeline; take another pipeline's files with from`
263 : `names job ${q(n)}, which this pipeline doesn't have`,
264 );
265 if (n === j.name) say(`${at}.jobs.${j.name}.needs[${i}]`, "names the job itself");
266 });
267 const required =
268 p.required === undefined ? [] : (strings(p.required, `${at}.required`, say, "a list of job names") ?? []);
269 required.forEach((n, i) => {
270 if (!names.has(n)) say(`${at}.required[${i}]`, `names job ${q(n)}, which this pipeline doesn't have`);
271 });
273 // Secrets go only where no draft can reach them: a draft runs code nobody
274 // has published, which could send a secret anywhere.
275 // A writer key (343) the same: it changes the project, so only published work may hold one.
276 const holding = jobs.filter((j) => j.secrets.length > 0 || j.abso === "writer");
277 if (holding.length) {
278 const who = holding.map((j) => j.name).join(", ");
279 const what = holding.every((j) => j.secrets.length === 0)
280 ? "a writer key"
281 : holding.some((j) => j.abso === "writer")
282 ? "secrets or a writer key"
283 : "secrets";
284 const verb = `hold${holding.length === 1 ? "s" : ""}`;
285 if (on?.includes("draft"))
286 say(`${at}.on`, `includes draft, but ${who} ${verb} ${what}; a draft runs unpushed code`);
287 if (!only || only.some((s) => s !== "shared"))
288 say(
289 `${at}.only`,
290 `must be shared, because ${who} ${verb} ${what} and a named draft's version is no one's pushed work`,
291 );
292 }
294 const ordered = order(jobs, `${at}.jobs`, say);
295 if (!on || !ordered) return undefined;
296 return { name, on, ...(only ? { only } : {}), jobs: ordered, required };
297}
299function job(name: string, j: unknown, at: string, say: Say): Job | undefined {
300 if (!NAME.test(name))
301 say(at, `${q(name)} isn't a usable name: lower-case letters, digits, - and _, starting with a letter`);
302 if (!isRecord(j)) {
303 say(at, "must be a map with run or uses");
304 return undefined;
305 }
306 let uses: BuiltIn | undefined;
307 if (j.uses !== undefined) {
308 if (typeof j.uses === "string" && (BUILT_INS as readonly string[]).includes(j.uses)) uses = j.uses as BuiltIn;
309 else say(`${at}.uses`, `must be one of ${BUILT_INS.join(", ")}, not ${q(j.uses)}`);
310 }
311 const settings = uses ? BUILT_IN_SETTINGS[uses] : [];
312 unknownKeys(j, [...JOB_KEYS, ...settings], at, say, j.uses !== undefined && !uses);
313 const run = j.run;
314 if (run !== undefined && (typeof run !== "string" || !run.trim())) say(`${at}.run`, "must be a command");
315 if (run === undefined && j.uses === undefined) say(at, "needs run (a command) or uses (a built-in step)");
316 if (run !== undefined && j.uses !== undefined) say(at, "has both run and uses; a job does one");
317 if (j.from !== undefined && typeof j.from !== "string") say(`${at}.from`, "must be <pipeline>.<job>");
318 const secrets = list(j.secrets, `${at}.secrets`, say, "a list of secret names");
319 secrets.forEach((s, i) => {
320 if (!SECRET.test(s)) say(`${at}.secrets[${i}]`, `${q(s)} isn't a secret name: upper-case letters, digits and _`);
321 });
322 if (j.abso !== undefined) {
323 if (j.abso !== "reader" && j.abso !== "writer") say(`${at}.abso`, `must be reader or writer, not ${q(j.abso)}`);
324 else if (j.uses !== undefined)
325 say(`${at}.abso`, "gives a run job a key; a uses step runs on the server and has none");
326 }
327 const timeout = j.timeout;
328 const timed =
329 timeout !== undefined &&
330 typeof timeout === "number" &&
331 Number.isInteger(timeout) &&
332 timeout >= 1 &&
333 timeout <= JOB_TIMEOUT_MAX &&
334 j.uses === undefined;
335 if (timeout !== undefined && !timed)
336 say(
337 `${at}.timeout`,
338 j.uses !== undefined
339 ? "gives a run job's steps more time; a uses step runs on the server and has none"
340 : `must be whole seconds from 1 to ${JOB_TIMEOUT_MAX}, not ${q(timeout)}`,
341 );
342 const withs: Record<string, unknown> = {};
343 for (const k of settings) if (j[k] !== undefined) withs[k] = j[k];
344 if (uses === "deploy" && typeof j.worker !== "string")
345 say(`${at}.worker`, "names the Worker deploy ships, and is missing");
346 if (uses === "agent") {
347 const instructions = j.instructions;
348 if (
349 instructions !== undefined &&
350 (typeof instructions !== "string" ||
351 instructions === "" ||
352 instructions.startsWith("/") ||
353 instructions.split("/").includes(".."))
354 )
355 say(`${at}.instructions`, `names a file in the project, such as .abso/review.md, not ${q(instructions)}`);
356 if (j.model !== undefined && (typeof j.model !== "string" || !MODEL_NAME.test(j.model)))
357 say(`${at}.model`, `names a model such as anthropic/claude-sonnet-5, not ${q(j.model)}`);
358 if (j.may !== undefined) {
359 const may = typeof j.may === "string" ? [j.may] : j.may;
360 if (!Array.isArray(may) || may.length === 0)
361 say(`${at}.may`, `lists what the seat may do: ${AGENT_MAY.join(", ")}`);
362 else
363 may.forEach((m, i) => {
364 if (!(AGENT_MAY as readonly unknown[]).includes(m))
365 say(`${at}.may[${i}]`, `${q(m)} isn't something an agent step may do yet (${AGENT_MAY.join(", ")})`);
366 });
367 }
368 }
369 if (uses === "npm-publish") {
370 if (j.from === undefined)
371 say(`${at}.from`, "names the job whose kept .tgz files npm-publish pushes, and is missing");
372 const packages = j.packages;
373 if (!Array.isArray(packages) || packages.length === 0)
374 say(`${at}.packages`, "lists the npm packages npm-publish may push, and is missing");
375 else
376 packages.forEach((p, i) => {
377 if (typeof p !== "string" || p.length > 214 || !NPM_NAME.test(p))
378 say(`${at}.packages[${i}]`, `${q(p)} isn't an npm package name`);
379 });
380 if (j.tag !== undefined && (typeof j.tag !== "string" || !DIST_TAG.test(j.tag)))
381 say(`${at}.tag`, `${q(j.tag)} isn't an npm dist-tag (a lower-case name such as next, not a version)`);
382 }
383 return {
384 name,
385 needs: list(j.needs, `${at}.needs`, say, "a list of job names"),
386 ...(typeof run === "string" ? { run } : {}),
387 ...(uses ? { uses } : {}),
388 ...(typeof j.from === "string" ? { from: j.from } : {}),
389 keep: list(j.keep, `${at}.keep`, say, "a list of file patterns"),
390 cache: list(j.cache, `${at}.cache`, say, "a list of files"),
391 secrets,
392 ...((j.abso === "reader" || j.abso === "writer") && j.uses === undefined ? { abso: j.abso } : {}),
393 ...(timed ? { timeout: timeout as number } : {}),
394 with: withs,
395 ...machine(j, at, say, false),
396 };
397}
399/** image, dockerfile and size, from defaults (alone) or a job (among its other keys). */
400function machine(m: unknown, at: string, say: Say, alone: boolean): Machine {
401 if (m === undefined) return {};
402 if (!isRecord(m)) {
403 say(at, "must be a map");
404 return {};
405 }
406 if (alone) unknownKeys(m, MACHINE_KEYS, at, say);
407 const out: { image?: string; dockerfile?: string; size?: Size } = {};
408 if (m.image !== undefined) {
409 if (typeof m.image === "string" && m.image) out.image = m.image;
410 else say(`${at}.image`, "must be an image name");
411 }
412 if (m.dockerfile !== undefined) {
413 if (typeof m.dockerfile === "string" && m.dockerfile) out.dockerfile = m.dockerfile;
414 else say(`${at}.dockerfile`, "must be a path in the project");
415 }
416 if (out.image && out.dockerfile) say(at, "has both image and dockerfile; give one");
417 if (m.size !== undefined) {
418 if (SIZES.includes(m.size as Size)) out.size = m.size as Size;
419 else say(`${at}.size`, `must be one of ${SIZES.join(", ")}, not ${q(m.size)}`);
420 }
421 return out;
422}
424function triggers(on: unknown, at: string, say: Say): Trigger[] | undefined {
425 if (on === undefined) {
426 say(at, "is missing: say when the pipeline runs");
427 return undefined;
428 }
429 const all = Array.isArray(on) ? on : [on];
430 if (all.length === 0) {
431 say(at, "is empty, so the pipeline would never run");
432 return undefined;
433 }
434 const out: Trigger[] = [];
435 all.forEach((t, i) => {
436 const here = Array.isArray(on) ? `${at}[${i}]` : at;
437 if (typeof t === "string" && (TRIGGERS as readonly string[]).includes(t))
438 out.push((t === "push" ? "publish" : t) as Trigger);
439 else if (isRecord(t) && Object.keys(t).length === 1 && typeof t.every === "string" && t.every.trim())
440 out.push({ every: t.every });
441 else say(here, `must be one of ${TRIGGERS.join(", ")}, or { every: "<when>" }, not ${q(t)}`);
442 });
443 return out.length === all.length ? out : undefined;
444}
446/** The jobs in an order where each comes after the jobs it needs; a cycle is a problem, named by its jobs. */
447function order(jobs: readonly Job[], at: string, say: Say): Job[] | undefined {
448 const byName = new Map(jobs.map((j) => [j.name, j]));
449 const done = new Set<string>();
450 const out: Job[] = [];
451 const cycles = new Set<string>();
452 const visit = (j: Job, path: string[]) => {
453 if (done.has(j.name)) return;
454 const seen = path.indexOf(j.name);
455 if (seen >= 0) {
456 const loop = [...path.slice(seen), j.name];
457 // The same cycle found from another job is one problem.
458 const key = [...loop.slice(0, -1)].sort().join(",");
459 if (!cycles.has(key)) {
460 cycles.add(key);
461 say(at, `needs go round in a cycle: ${loop.join(" → ")}`);
462 }
463 return;
464 }
465 for (const n of j.needs) {
466 const k = byName.get(n);
467 if (k && k !== j) visit(k, [...path, j.name]);
468 }
469 if (!done.has(j.name)) {
470 done.add(j.name);
471 out.push(j);
472 }
473 };
474 for (const j of jobs) visit(j, []);
475 return cycles.size ? undefined : out;
476}
478function unknownKeys(m: Record<string, unknown>, known: readonly string[], at: string, say: Say, quiet = false) {
479 if (quiet) return;
480 for (const k of Object.keys(m))
481 if (!known.includes(k)) say(at ? `${at}.${k}` : k, `isn't a key here (known: ${known.join(", ")})`);
482}
484/** A list of strings, or one string as a list of one; a problem when it's neither. */
485function strings(v: unknown, at: string, say: Say, what: string): string[] | undefined {
486 const all = typeof v === "string" ? [v] : v;
487 if (!Array.isArray(all) || all.some((s) => typeof s !== "string" || !s)) {
488 say(at, `must be ${what}`);
489 return undefined;
490 }
491 return all as string[];
492}
494const list = (v: unknown, at: string, say: Say, what: string): string[] =>
495 v === undefined ? [] : (strings(v, at, say, what) ?? []);
497function isRecord(v: unknown): v is Record<string, unknown> {
498 return typeof v === "object" && v !== null && !Array.isArray(v);
499}
501const q = (v: unknown): string => JSON.stringify(v) ?? String(v);
502const fail = (problems: Problem[]): Checked => ({ ok: false, problems });