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/project-file.ts?format=json
121 linesFirst import 82% · review 16% · rename 2% · infra-split 1%Last change rename in version 100, 4 versions changed it
1// avcs.json: what the project runs to check and build a version (#39). It is
2// recorded and published like any file, so each version carries its own; the
3// server's job for each new shared version reads it, and publish --check with
4// no command runs its check.
5
6import { existsSync, readFileSync, writeFileSync } from "node:fs";
7import { join } from "node:path";
8
9/** The project file's name: abso.json, or avcs.json from before the rename. A new one is written as abso.json. */
10export const PROJECT_FILE = "abso.json";
11export const OLD_PROJECT_FILE = "avcs.json";
13/** The name the folder's project file has: abso.json when it is there, else avcs.json when that is, else the new name. */
14export function projectFileName(root: string): string {
15 if (existsSync(join(root, PROJECT_FILE))) return PROJECT_FILE;
16 return existsSync(join(root, OLD_PROJECT_FILE)) ? OLD_PROJECT_FILE : PROJECT_FILE;
19/** Each key optional; an empty string counts as missing. */
20export interface ProjectFile {
21 readonly setup: string;
22 readonly check: string;
23 readonly build: string;
24 readonly out: string;
25 /** The merge queue (#39): publishes to shared land only once the project's check passes on them. */
26 readonly queue?: boolean;
29const KEYS = ["setup", "check", "build", "out"] as const;
31/** The folder's abso.json (or avcs.json), or why it can't be read; null when there is none. */
32export function readProjectFile(root: string): { file: ProjectFile } | { error: string } | null {
33 const name = projectFileName(root);
34 const path = join(root, name);
35 if (!existsSync(path)) return null;
36 let raw: unknown;
37 try {
38 raw = JSON.parse(readFileSync(path, "utf8"));
39 } catch (e) {
40 return { error: `${name} isn't valid JSON (${(e as Error).message})` };
41 }
42 if (typeof raw !== "object" || raw === null || Array.isArray(raw))
43 return { error: `${name} should hold an object, like {"check": "npm test"}` };
44 const o = raw as Record<string, unknown>;
45 for (const k of KEYS) {
46 if (o[k] !== undefined && typeof o[k] !== "string") return { error: `"${k}" in ${name} should be a string` };
47 }
48 const get = (k: (typeof KEYS)[number]) => ((o[k] as string | undefined) ?? "").trim();
49 return {
50 file: {
51 setup: get("setup"),
52 check: get("check"),
53 build: get("build"),
54 out: get("out"),
55 ...(o.queue === true ? { queue: true } : {}),
56 },
57 };
60/** npm's placeholder test script, which always fails. */
61const NO_TEST = /no test specified/;
63/** A starting abso.json, guessed from package.json; empty where nothing can be guessed. */
64export function guessProjectFile(root: string): ProjectFile {
65 let pkg: {
66 scripts?: Record<string, unknown>;
67 dependencies?: Record<string, unknown>;
68 devDependencies?: Record<string, unknown>;
69 } = {};
70 const hasPkg = existsSync(join(root, "package.json"));
71 if (hasPkg) {
72 try {
73 pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8")) ?? {};
74 } catch {
75 pkg = {};
76 }
77 }
78 const scripts = typeof pkg.scripts === "object" && pkg.scripts !== null ? pkg.scripts : {};
79 const has = (s: string) => typeof scripts[s] === "string" && !(s === "test" && NO_TEST.test(scripts[s] as string));
80 const check = has("check")
81 ? "npm run check"
82 : [has("typecheck") ? "npm run typecheck" : "", has("test") ? "npm test" : ""].filter((c) => c !== "").join(" && ");
83 const vite = "vite" in (pkg.devDependencies ?? {}) || "vite" in (pkg.dependencies ?? {});
84 const build = vite ? "npx --no-install vite build --base ./ --outDir dist" : has("build") ? "npm run build" : "";
85 const out = vite ? "dist" : "";
86 const setup = existsSync(join(root, "package-lock.json")) ? "npm ci" : hasPkg ? "npm install" : "";
87 return { setup, check, build, out };
90/**
91 * Writes a guessed abso.json (unless it has abso.json or avcs.json) when the folder has none and package.json gives
92 * a check or a build to guess (#39: a project with nothing to
93 * check shouldn't start boxes; CI skips a version with nothing to run).
94 * Answers what it wrote; 'exists' or 'nothing' when it wrote none.
95 */
96export function writeStartingProjectFile(root: string): ProjectFile | "exists" | "nothing" {
97 if (existsSync(join(root, PROJECT_FILE)) || existsSync(join(root, OLD_PROJECT_FILE))) return "exists";
98 const guess = guessProjectFile(root);
99 if (guess.check === "" && guess.build === "") return "nothing";
100 writeFileSync(join(root, PROJECT_FILE), `${JSON.stringify(guess, null, 2)}\n`);
101 return guess;
104/** What init says about abso.json. */
105export function startingProjectFileText(wrote: ProjectFile | "exists" | "nothing"): string[] {
106 if (wrote === "exists") return [];
107 if (wrote === "nothing") {
108 return [
109 `No ${PROJECT_FILE} written: package.json gives no check or build to guess, so CI has nothing to run on each new version. To give it a check, push an ${PROJECT_FILE} like {"check": "npm test"} (abso ci --help says what it runs).`,
110 ];
111 }
112 const set = KEYS.filter((k) => wrote[k] !== "").map((k) => `${k} "${wrote[k]}"`);
113 const empty = KEYS.filter((k) => wrote[k] === "");
114 return [
115 [
116 `Wrote ${PROJECT_FILE}: CI will run on every new version of shared (${set.join(", ")}).`,
117 empty.length > 0 ? ` Fill in ${empty.join(", ")} when the project has them.` : "",
118 " abso push --check with no command runs its build and check.",
119 ].join(""),
120 ];