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 42 to 43

Compare

+61 −2 in 3 places
Lines 45–51 at 43 (were 45–51 at 42)
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 { 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 167–231 at 43 (were 167–172 at 42)
167167 return `${last.stdout.slice(0, 7)}${changed ? ".dirty" : ""}`;
168168}
169169
170+/** A file changed this close to when an answer was kept can't be told apart from one changed just after it. */
171+const RACY_MS = 2_000;
173+interface KeptModCommit {
174+ readonly head: string;
175+ readonly files: readonly string[];
176+ readonly at: number;
177+ readonly commit: string | null;
178+}
180+/**
181+ * modCommit for the version report, which `abso status` asks on every run: it runs git twice per mod, so
182+ * the answer is kept in ~/.abso/mod-commits.json. A kept answer holds while the checkout's commit (read
183+ * from .git, without git) and each of the mod's files (size, modified time, inode) are as they were, and
184+ * every file was changed clearly before the answer was kept; anything else asks git again. Outside a git
185+ * checkout there is no commit, and git isn't run at all.
186+ */
187+export function keptModCommit(spec: ModSpec, home: string = homedir()): string | null {
188+ const head = headCommit(spec.from);
189+ if (head === undefined) return null;
190+ const at = Date.now();
191+ const files = spec.files.map((rel) => {
192+ try {
193+ const s = statSync(join(spec.from, ...rel.split("/")));
194+ return `${s.size}:${s.mtimeMs}:${s.ino}`;
195+ } catch {
196+ return "-";
197+ }
198+ });
199+ const newest = Math.max(...files.map((f) => (f === "-" ? 0 : Number(f.split(":")[1]))));
200+ const path = join(home, ".abso", "mod-commits.json");
201+ const key = `${resolve(spec.from)}|${spec.files.join("|")}`;
202+ let kept: Record<string, KeptModCommit> = {};
203+ try {
204+ const parsed = JSON.parse(readFileSync(path, "utf8")) as { format?: unknown; mods?: unknown };
205+ if (parsed.format === 1 && typeof parsed.mods === "object" && parsed.mods !== null)
206+ kept = parsed.mods as Record<string, KeptModCommit>;
207+ } catch {}
208+ const was = kept[key];
209+ if (
210+ was !== undefined &&
211+ was.head === head &&
212+ Array.isArray(was.files) &&
213+ was.files.join() === files.join() &&
214+ newest < was.at - RACY_MS
215+ )
216+ return was.commit;
217+ const commit = modCommit(spec);
218+ try {
219+ mkdirSync(dirname(path), { recursive: true });
220+ const next = `${path}.${process.pid}.tmp`;
221+ writeFileSync(next, JSON.stringify({ format: 1, mods: { ...kept, [key]: { head, files, at, commit } } }));
222+ renameSync(next, path);
223+ } catch {
224+ // Best effort: the next run asks git again.
225+ }
226+ return commit;
227+}
170229/** The files to install, stamped with `version`, in install order. */
171230function filesFor(spec: ModSpec, version: string): Map<string, Buffer> {
172231 if (!/^[\w.+-]+$/.test(version)) throw new Error(`can't stamp the version ${JSON.stringify(version)}`);
Lines 545–551 at 43 (were 486–492 at 42)
486545 at: field(RECORD, "at"),
487546 current: (() => {
488547 try {
489− return versionFor(spec);
548+ return versionFor(spec, keptModCommit(spec));
490549 } catch {
491550 return "not in this copy";
492551 }
MCP
compare on this site's /mcp
CLI
abso diff 42 43 client/src/install.ts --json
JSON
/christopher/abso-core/compare/42..43?file=client%2Fsrc%2Finstall.ts&format=json