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?version=2&format=json
113 linesFirst import 100%Last change First import in version 0, 1 version changed it

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

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
9export const PROJECT_FILE = "avcs.json";
11/** Each key optional; an empty string counts as missing. */
12export interface ProjectFile {
13 readonly setup: string;
14 readonly check: string;
15 readonly build: string;
16 readonly out: string;
17 /** The merge queue (#39): publishes to shared land only once the project's check passes on them. */
18 readonly queue?: boolean;
21const KEYS = ["setup", "check", "build", "out"] as const;
23/** The folder's avcs.json, or why it can't be read; null when there is none. */
24export function readProjectFile(root: string): { file: ProjectFile } | { error: string } | null {
25 const path = join(root, PROJECT_FILE);
26 if (!existsSync(path)) return null;
27 let raw: unknown;
28 try {
29 raw = JSON.parse(readFileSync(path, "utf8"));
30 } catch (e) {
31 return { error: `${PROJECT_FILE} isn't valid JSON (${(e as Error).message})` };
32 }
33 if (typeof raw !== "object" || raw === null || Array.isArray(raw))
34 return { error: `${PROJECT_FILE} should hold an object, like {"check": "npm test"}` };
35 const o = raw as Record<string, unknown>;
36 for (const k of KEYS) {
37 if (o[k] !== undefined && typeof o[k] !== "string")
38 return { error: `"${k}" in ${PROJECT_FILE} should be a string` };
39 }
40 const get = (k: (typeof KEYS)[number]) => ((o[k] as string | undefined) ?? "").trim();
41 return {
42 file: {
43 setup: get("setup"),
44 check: get("check"),
45 build: get("build"),
46 out: get("out"),
47 ...(o.queue === true ? { queue: true } : {}),
48 },
49 };
52/** npm's placeholder test script, which always fails. */
53const NO_TEST = /no test specified/;
55/** A starting avcs.json, guessed from package.json; empty where nothing can be guessed. */
56export function guessProjectFile(root: string): ProjectFile {
57 let pkg: {
58 scripts?: Record<string, unknown>;
59 dependencies?: Record<string, unknown>;
60 devDependencies?: Record<string, unknown>;
61 } = {};
62 const hasPkg = existsSync(join(root, "package.json"));
63 if (hasPkg) {
64 try {
65 pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8")) ?? {};
66 } catch {
67 pkg = {};
68 }
69 }
70 const scripts = typeof pkg.scripts === "object" && pkg.scripts !== null ? pkg.scripts : {};
71 const has = (s: string) => typeof scripts[s] === "string" && !(s === "test" && NO_TEST.test(scripts[s] as string));
72 const check = has("check")
73 ? "npm run check"
74 : [has("typecheck") ? "npm run typecheck" : "", has("test") ? "npm test" : ""].filter((c) => c !== "").join(" && ");
75 const vite = "vite" in (pkg.devDependencies ?? {}) || "vite" in (pkg.dependencies ?? {});
76 const build = vite ? "npx --no-install vite build --base ./ --outDir dist" : has("build") ? "npm run build" : "";
77 const out = vite ? "dist" : "";
78 const setup = existsSync(join(root, "package-lock.json")) ? "npm ci" : hasPkg ? "npm install" : "";
79 return { setup, check, build, out };
82/**
83 * Writes a guessed avcs.json when the folder has none and package.json gives
84 * a check or a build to guess (#39, Agent VCS: a project with nothing to
85 * check shouldn't start boxes; CI skips a version with nothing to run).
86 * Answers what it wrote; 'exists' or 'nothing' when it wrote none.
87 */
88export function writeStartingProjectFile(root: string): ProjectFile | "exists" | "nothing" {
89 if (existsSync(join(root, PROJECT_FILE))) return "exists";
90 const guess = guessProjectFile(root);
91 if (guess.check === "" && guess.build === "") return "nothing";
92 writeFileSync(join(root, PROJECT_FILE), `${JSON.stringify(guess, null, 2)}\n`);
93 return guess;
96/** What init says about avcs.json. */
97export function startingProjectFileText(wrote: ProjectFile | "exists" | "nothing"): string[] {
98 if (wrote === "exists") return [];
99 if (wrote === "nothing") {
100 return [
101 `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, publish an ${PROJECT_FILE} like {"check": "npm test"} (abso ci --help says what it runs).`,
102 ];
103 }
104 const set = KEYS.filter((k) => wrote[k] !== "").map((k) => `${k} "${wrote[k]}"`);
105 const empty = KEYS.filter((k) => wrote[k] === "");
106 return [
107 [
108 `Wrote ${PROJECT_FILE}: CI will run on every new version of shared (${set.join(", ")}).`,
109 empty.length > 0 ? ` Fill in ${empty.join(", ")} when the project has them.` : "",
110 " abso publish --check with no command runs its build and check.",
111 ].join(""),
112 ];