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 32 to 318

Compare

+130 −15 in 11 places
Lines 7–13 at 318 (were 7–13 at 32)
77// last commit that changed the mod's own files (0.1.0+702c616, or
88// 0.1.0+702c616.dirty when they differ from it), and hooks/stamp.ts says
99// the same, so the mod sends it with each call to the server
10−// (X-Avcs-Client). A commit that changes none of them changes nothing to
10+// (X-Abso-Client). A commit that changes none of them changes nothing to
1111// install, and nothing to restart for.
1212// 2. Checks the staged copy: `claude plugin validate`, then the mod's own
1313// tests in Claude Code's plugin test kit. If either fails, nothing in the
Lines 45–51 at 318 (were 45–51 at 32)
4545} from "node:fs";
4646import { homedir, tmpdir } from "node:os";
4747import { dirname, join, resolve } from "node:path";
48−import { CLIENT_DIR, clientPlace, clientVersion } from "./client-version.ts";
48+import { builtCopy, CLIENT_DIR, clientPlace, clientVersion, headCommit } from "./client-version.ts";
4949
5050export interface ModSpec {
5151 /** The mod's name, as its plugin.json has it. */
Lines 94–101 at 318 (were 94–99 at 32)
9494 /** For tests: the rename that moves each file into place. */
9595 readonly rename?: (from: string, to: string) => void;
9696 readonly now?: Date;
97+ /** For tests: the command stamped as HOOK_COMMAND, instead of this client's own `abso hook`. */
98+ readonly hookCommand?: readonly string[];
9799}
98100
99101const RECORD = ".avcs-install.json";
Lines 109–167 at 318 (were 107–133 at 32)
107109
108110/** The abso mod: what the hook imports first, plugin.json last. src/core.ts is the only client file it imports. */
109111export const AVCS_MOD: ModSpec = {
110− name: "avcs",
112+ name: "abso-hooks",
111113 from: CLIENT_DIR,
112114 files: ["src/core.ts", "hooks/stamp.ts", "hooks/register.ts", "hooks/hooks.json", ".claude-plugin/plugin.json"],
113115 test: "hooks/register.test.ts",
114116};
115117
116−/** The avcs-view mod (#12), from client/view. */
118+/** The abso-view mod (#12), from client/view. */
117119export const VIEW_MOD: ModSpec = {
118− name: "avcs-view",
120+ name: "abso-view",
119121 from: join(CLIENT_DIR, "view"),
120122 files: ["types/index.d.ts", "hooks/stamp.ts", "hooks/register.tsx", "hooks/hooks.json", ".claude-plugin/plugin.json"],
121123 test: "hooks/register.test.ts",
122124};
123125
126+/** The skills folders the mods had before the rename; an install moves them out of the way (see retireOldMod). */
127+export const OLD_MOD_NAMES: Readonly<Record<string, string>> = { "abso-hooks": "avcs", "abso-view": "avcs-view" };
124129/** Where Claude Code's skills folder keeps a mod. */
125130export const skillsFolder = (name: string, env: Readonly<Record<string, string | undefined>> = process.env) =>
126131 join(env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "skills", name);
127132
128133export const modInstalled = (env: Readonly<Record<string, string | undefined>> = process.env) =>
129− existsSync(at(skillsFolder(AVCS_MOD.name, env), MANIFEST));
134+ existsSync(at(skillsFolder(AVCS_MOD.name, env), MANIFEST)) ||
135+ existsSync(at(skillsFolder(OLD_MOD_NAMES[AVCS_MOD.name]!, env), MANIFEST));
130136
137+/** Whether the installed abso mod hands a local project's edits to abso hook: it was installed with a HOOK_COMMAND. */
138+export function modHandsLocal(env: Readonly<Record<string, string | undefined>> = process.env): boolean {
139+ try {
140+ return /HOOK_COMMAND[^=\n]*=\s*\[/.test(readFileSync(at(skillsFolder(AVCS_MOD.name, env), STAMP_FILE), "utf8"));
141+ } catch {
142+ return false;
143+ }
144+}
146+/**
147+ * After the new mod is in, the folder it replaces (skills/avcs, skills/avcs-view) would load beside it, so it
148+ * is moved, not deleted, to ~/.abso/retired-mods/<name>-<stamp>. Returns where it went, or undefined when there was none.
149+ */
150+export function retireOldMod(
151+ spec: ModSpec,
152+ env: Readonly<Record<string, string | undefined>> = process.env,
153+ now: Date = new Date(),
154+): string | undefined {
155+ const old = OLD_MOD_NAMES[spec.name];
156+ if (old === undefined) return undefined;
157+ const from = skillsFolder(old, env);
158+ if (!existsSync(from)) return undefined;
159+ const to = join(homedir(), ".abso", "retired-mods", `${old}-${now.toISOString().replace(/[:.]/g, "-")}`);
160+ mkdirSync(dirname(to), { recursive: true });
161+ renameRetrying(from, to);
162+ return to;
163+}
131165/** The version an install of `spec` gets: plugin.json's, plus the last commit that changed its files (and .dirty when they differ from it). */
132166export function versionFor(spec: ModSpec, commit?: string | null): string {
133167 const manifest = JSON.parse(readFileSync(at(spec.from, MANIFEST), "utf8")) as { version?: unknown };
Lines 178–247 at 318 (were 144–151 at 32)
144178 return `${last.stdout.slice(0, 7)}${changed ? ".dirty" : ""}`;
145179}
146180
147−/** The files to install, stamped with `version`, in install order. */
148−function filesFor(spec: ModSpec, version: string): Map<string, Buffer> {
181+/** A file changed this close to when an answer was kept can't be told apart from one changed just after it. */
182+const RACY_MS = 2_000;
184+interface KeptModCommit {
185+ readonly head: string;
186+ readonly files: readonly string[];
187+ readonly at: number;
188+ readonly commit: string | null;
189+}
191+/**
192+ * modCommit for the version report, which `abso status` asks on every run: it runs git twice per mod, so
193+ * the answer is kept in ~/.abso/mod-commits.json. A kept answer holds while the checkout's commit (read
194+ * from .git, without git) and each of the mod's files (size, modified time, inode) are as they were, and
195+ * every file was changed clearly before the answer was kept; anything else asks git again. Outside a git
196+ * checkout there is no commit, and git isn't run at all.
197+ */
198+export function keptModCommit(spec: ModSpec, home: string = homedir()): string | null {
199+ const head = headCommit(spec.from);
200+ if (head === undefined) return null;
201+ const at = Date.now();
202+ const files = spec.files.map((rel) => {
203+ try {
204+ const s = statSync(join(spec.from, ...rel.split("/")));
205+ return `${s.size}:${s.mtimeMs}:${s.ino}`;
206+ } catch {
207+ return "-";
208+ }
209+ });
210+ const newest = Math.max(...files.map((f) => (f === "-" ? 0 : Number(f.split(":")[1]))));
211+ const path = join(home, ".abso", "mod-commits.json");
212+ const key = `${resolve(spec.from)}|${spec.files.join("|")}`;
213+ let kept: Record<string, KeptModCommit> = {};
214+ try {
215+ const parsed = JSON.parse(readFileSync(path, "utf8")) as { format?: unknown; mods?: unknown };
216+ if (parsed.format === 1 && typeof parsed.mods === "object" && parsed.mods !== null)
217+ kept = parsed.mods as Record<string, KeptModCommit>;
218+ } catch {}
219+ const was = kept[key];
220+ if (
221+ was !== undefined &&
222+ was.head === head &&
223+ Array.isArray(was.files) &&
224+ was.files.join() === files.join() &&
225+ newest < was.at - RACY_MS
226+ )
227+ return was.commit;
228+ const commit = modCommit(spec);
229+ try {
230+ mkdirSync(dirname(path), { recursive: true });
231+ const next = `${path}.${process.pid}.tmp`;
232+ writeFileSync(next, JSON.stringify({ format: 1, mods: { ...kept, [key]: { head, files, at, commit } } }));
233+ renameSync(next, path);
234+ } catch {
235+ // Best effort: the next run asks git again.
236+ }
237+ return commit;
238+}
240+/** The command that runs this checkout's `abso hook`: what the mod hands a local project's edits to. */
241+export const hookCommand = (): readonly string[] => [process.execPath, join(CLIENT_DIR, "abso.ts"), "hook"];
243+/** The files to install, stamped with `version` (and HOOK_COMMAND, where a stamp.ts has it), in install order. */
244+function filesFor(spec: ModSpec, version: string, hook: readonly string[] = hookCommand()): Map<string, Buffer> {
149245 if (!/^[\w.+-]+$/.test(version)) throw new Error(`can't stamp the version ${JSON.stringify(version)}`);
150246 const out = new Map<string, Buffer>();
151247 for (const rel of spec.files) {
Lines 253–261 at 318 (were 157–163 at 32)
157253 const text = data.toString("utf8");
158254 const stamped = text.replace(/(STAMP[^=\n]*=\s*)undefined/, `$1'${version}'`);
159255 if (stamped === text) throw new Error(`${rel} has no "STAMP ... = undefined" line to stamp`);
160− data = Buffer.from(stamped);
256+ data = Buffer.from(
257+ stamped.replace(/(HOOK_COMMAND[^=\n]*=\s*)undefined/, (_, head: string) => head + JSON.stringify(hook)),
258+ );
161259 }
162260 out.set(rel, data);
163261 }
Lines 402–408 at 318 (were 304–310 at 32)
304402export function installMod(spec: ModSpec, options: InstallOptions): Installed {
305403 const target = resolve(options.target);
306404 const version = versionFor(spec, options.commit);
307− const next = filesFor(spec, version);
405+ const next = filesFor(spec, version, options.hookCommand);
308406 const existed = existsSync(target);
309407 mkdirSync(target, { recursive: true });
310408 try {
Lines 503–511 at 318 (were 405–410 at 32)
405503 }
406504 const unchecked = options.includes("--unchecked");
407505 const r = installMod(spec, { target, check: unchecked ? () => undefined : checkWithClaude(spec) });
506+ // Only for the real skills folder: an install to another folder leaves the old mod alone.
507+ const retired = target === resolve(skillsFolder(spec.name)) ? retireOldMod(spec) : undefined;
508+ if (retired) console.log(`Moved the old ${OLD_MOD_NAMES[spec.name]} mod out of the skills folder, to ${retired}.`);
408509 if (!r.changed) {
409510 console.log(`The ${spec.name} mod ${r.version} is already installed in ${target}; nothing changed.`);
410511 return;
Lines 533–550 at 318 (were 432–438 at 32)
432533 readonly current: string;
433534}
434535
435−/** `avcs --version`: this client, and the mods installed on this machine, compared with this client's. */
536+/**
537+ * The command that runs one of this client's installers (client/install-mod.ts or install-view.ts), by its full
538+ * path. They are .ts files, which Node runs itself from 22.18, so on an older Node it says which one it needs.
539+ */
540+export function installerCommand(installer: string): string {
541+ const command = `node ${join(CLIENT_DIR, installer)}`;
542+ return (process.features as { typescript?: unknown }).typescript
543+ ? command
544+ : `${command} (with Node 22.18 or later, which runs .ts files; this is Node ${process.versions.node})`;
545+}
547+/** `abso --version`: this client, and the mods installed on this machine, compared with this client's. */
436548export function versionReport(env: Readonly<Record<string, string | undefined>>): {
437549 text: string;
438550 json: Record<string, unknown>;
Lines 572–594 at 318 (were 460–479 at 32)
460572 at: field(RECORD, "at"),
461573 current: (() => {
462574 try {
463− return versionFor(spec);
575+ return versionFor(spec, keptModCommit(spec));
464576 } catch {
465577 return "not in this copy";
466578 }
467579 })(),
468580 };
469581 mods.push(m);
582+ // A built copy has no mod files to compare with or install from: it reports what is installed.
470583 if (m.version === undefined) {
471− lines.push(`the ${m.name} mod: not installed (node client/${installer})`);
584+ lines.push(`the ${m.name} mod: not installed${builtCopy() ? "" : ` (${installerCommand(installer)})`}`);
472585 continue;
473586 }
474587 const when = m.at ? `, installed ${m.at.slice(0, 16).replace("T", " ")} UTC` : "";
475588 const behind =
476− m.version === m.current ? "" : `; this client has ${m.current}: node client/${installer} installs it`;
589+ builtCopy() || m.version === m.current
590+ ? ""
591+ : `; this client has ${m.current}: ${installerCommand(installer)} installs it`;
477592 lines.push(`the ${m.name} mod: ${m.version} in ${m.folder}${when}${behind}`);
478593 }
479594 return { text: lines.join("\n"), json: { client, folder: CLIENT_DIR, mods } };
Lines 606–611 at 318 (were 491–496 at 32)
491606 .filter((m) => m.version?.includes("+") && /\+[0-9a-f]{7}$/.test(m.current) && m.version !== m.current)
492607 .map(
493608 (m) =>
494− `The ${m.name} mod installed on this machine is ${m.version}, and this client has ${m.current}: node client/${installers[m.name]} installs it (new chats load it).`,
609+ `The ${m.name} mod installed on this machine is ${m.version}, and this client has ${m.current}: ${installerCommand(installers[m.name]!)} installs it (new chats load it).`,
495610 );
496611}
MCP
compare on this site's /mcp
CLI
abso diff 32 318 client/src/install.ts --json
JSON
/christopher/abso-core/compare/32..318?file=client%2Fsrc%2Finstall.ts&format=json