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
show on this site's /mcp
CLI
abso show 42 --json
JSON
/christopher/abso-core/versions/42?format=json

client/launch.mjs follow-ups from review: reads the commit in a git worktree too (.git as a file, following gitdir and commondir; info/exclude in the shared folder); a stale lock is renamed aside before it's removed, and put back if it turns out to be live, so two runs can't both take it over; the README says to point it at a checkout nobody edits in; the tests remove their temporary folders.

of shared·speed··Not checked

Version 41 · Files at version 42

3 files, 94 lines added, 14 removed.

--- a/client/README.md
+++ b/client/README.md
@@ -27,6 +27,9 @@
2727It never changes the command's output or exit code, and writes its own notices
2828to `~/.abso/launcher.log`.
2929
30+Point it at a clone or worktree that nobody edits in. The bundle is keyed on
31+the commit, so changes that aren't committed don't run until the next commit.
3033## Setting up a folder
3134
3235Folders and machines set up before abso had its name keep working: the older
--- a/client/launch.mjs
+++ b/client/launch.mjs
@@ -24,7 +24,7 @@
2424import { appendFileSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
2525import { createRequire } from "node:module";
2626import { homedir } from "node:os";
27−import { dirname, join } from "node:path";
27+import { dirname, join, resolve } from "node:path";
2828import { fileURLToPath, pathToFileURL } from "node:url";
2929
3030const repo = dirname(dirname(fileURLToPath(import.meta.url)));
@@ -38,29 +38,69 @@
3838/** Set by the bundle's first line: an error after it came from the command, so it's never run again. */
3939const STARTED = "__absoBundleStarted";
4040
41+/**
42+ * The checkout's git folders: its own (HEAD) and the shared one (refs, info/exclude). They are the same
43+ * folder in a plain clone; in a worktree .git is a file naming its own folder, which names the shared one.
44+ */
45+function gitDirs(root = repo) {
46+ const dot = join(root, ".git");
47+ try {
48+ if (statSync(dot).isDirectory()) return { own: dot, common: dot };
49+ const own = resolve(
50+ root,
51+ readFileSync(dot, "utf8")
52+ .trim()
53+ .replace(/^gitdir:\s*/, ""),
54+ );
55+ let common = own;
56+ try {
57+ common = resolve(own, readFileSync(join(own, "commondir"), "utf8").trim());
58+ } catch {}
59+ return { own, common };
60+ } catch {
61+ return undefined;
62+ }
63+}
4165/** The checkout's commit, read from .git without running git; undefined if it can't be read. */
4266function headCommit(root = repo) {
67+ const dirs = gitDirs(root);
68+ if (!dirs) return undefined;
4369 try {
44− const head = readFileSync(join(root, ".git", "HEAD"), "utf8").trim();
70+ const head = readFileSync(join(dirs.own, "HEAD"), "utf8").trim();
4571 if (!head.startsWith("ref:")) return head;
4672 const ref = head.slice(4).trim();
47− try {
48− return readFileSync(join(root, ".git", ...ref.split("/")), "utf8").trim();
49− } catch {
50− const line = readFileSync(join(root, ".git", "packed-refs"), "utf8")
51− .split("\n")
52− .find((l) => l.endsWith(` ${ref}`));
53− return line?.split(" ")[0];
73+ for (const dir of [dirs.own, dirs.common]) {
74+ try {
75+ return readFileSync(join(dir, ...ref.split("/")), "utf8").trim();
76+ } catch {}
5477 }
78+ const line = readFileSync(join(dirs.common, "packed-refs"), "utf8")
79+ .split("\n")
80+ .find((l) => l.endsWith(` ${ref}`));
81+ return line?.split(" ")[0];
5582 } catch {
5683 return undefined;
5784 }
5885}
5986
60−/** Runs fn under a lock folder; a lock older than 10 minutes is a dead run's and is cleared. */
87+/**
88+ * Runs fn under a lock folder, or not at all when another run holds it. A lock older than 10 minutes is a
89+ * dead run's: it is renamed aside before it's removed, so of two runs that find it stale only one takes it
90+ * over, and one that renamed away a lock taken over a moment ago puts it back.
91+ */
6192function locked(lock, fn) {
93+ const stale = (path) => Date.now() - statSync(path).mtimeMs > 10 * 60 * 1000;
6294 try {
63− if (Date.now() - statSync(lock).mtimeMs > 10 * 60 * 1000) rmSync(lock, { recursive: true, force: true });
95+ if (stale(lock)) {
96+ const aside = `${lock}.${process.pid}.stale`;
97+ renameSync(lock, aside);
98+ if (stale(aside)) rmSync(aside, { recursive: true, force: true });
99+ else {
100+ renameSync(aside, lock);
101+ return;
102+ }
103+ }
64104 } catch {}
65105 try {
66106 mkdirSync(lock);
@@ -124,7 +164,7 @@
124164 } catch {
125165 return;
126166 }
127− const exclude = join(repo, ".git", "info", "exclude");
167+ const exclude = join(gitDirs()?.common ?? join(repo, ".git"), "info", "exclude");
128168 try {
129169 if (!readFileSync(exclude, "utf8").split(/\r?\n/).includes("client/dist/"))
130170 appendFileSync(exclude, "\nclient/dist/\n");
--- a/client/test/launch.test.ts
+++ b/client/test/launch.test.ts
@@ -3,16 +3,31 @@
33
44import assert from "node:assert/strict";
55import { execFileSync, spawnSync } from "node:child_process";
6−import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
6+import {
7+ copyFileSync,
8+ existsSync,
9+ mkdirSync,
10+ mkdtempSync,
11+ readdirSync,
12+ readFileSync,
13+ rmSync,
14+ utimesSync,
15+ writeFileSync,
16+} from "node:fs";
717import { tmpdir } from "node:os";
818import { join } from "node:path";
9−import { describe, it } from "node:test";
19+import { after, describe, it } from "node:test";
1020
1121const LAUNCH = new URL("../launch.mjs", import.meta.url);
22+const roots: string[] = [];
23+after(() => {
24+ for (const root of roots) rmSync(root, { recursive: true, force: true });
25+});
1226
1327/** A checkout on main with one commit, launch.mjs and a stand-in client/abso.ts that names itself. */
1428function checkout(): { repo: string; home: string; head: string } {
1529 const root = mkdtempSync(join(tmpdir(), "abso-launch-"));
30+ roots.push(root);
1631 const repo = join(root, "repo");
1732 const home = join(root, "home");
1833 mkdirSync(join(repo, "client"), { recursive: true });
@@ -127,6 +142,28 @@
127142 assert.equal(existsSync(lock), true);
128143 });
129144
145+ it("takes over a lock a dead run left behind, and removes it after", () => {
146+ const c = checkout();
147+ const lock = join(c.home, ".abso", "client-update.lock");
148+ mkdirSync(lock);
149+ const old = new Date(Date.now() - 11 * 60 * 1000);
150+ utimesSync(lock, old, old);
151+ assert.equal(launch(c, [], { ABSO_LAUNCH_UPDATE: "1" }).status, 0);
152+ assert.deepEqual(
153+ readdirSync(join(c.home, ".abso")).filter((f) => f.includes("lock")),
154+ [],
155+ );
156+ });
158+ it("reads the commit in a git worktree, where .git is a file", () => {
159+ const c = checkout();
160+ const wt = join(c.repo, "..", "wt");
161+ execFileSync("git", ["-C", c.repo, "worktree", "add", "-q", "--detach", wt, "HEAD"]);
162+ bundle(wt, NAMES_ITSELF, c.head);
163+ const r = launch({ repo: wt, home: c.home }, ["status"]);
164+ assert.match(r.stdout, /^bundle /);
165+ });
130167 it("keeps the background step quiet when it can't fetch or build", () => {
131168 const c = checkout();
132169 const r = launch(c, [], { ABSO_LAUNCH_UPDATE: "1" });