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

Compare

+52 −12 in 3 places
Lines 24–30 at 318 (were 24–30 at 39)
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)));
Lines 38–106 at 318 (were 38–66 at 39)
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);
Lines 164–170 at 318 (were 124–130 at 39)
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");
MCP
compare on this site's /mcp
CLI
abso diff 39 318 client/launch.mjs --json
JSON
/christopher/abso-core/compare/39..318?file=client%2Flaunch.mjs&format=json