status: keep each mod's commit between runs (~/.abso/mod-commits.json), keyed on the checkout's commit read from .git and each mod file's size, time and inode, so status runs no git while nothing moved; files changed too recently to trust are asked again; outside a git checkout git isn't run Version 43 of shared· speed· Oct 9 (2026-10-09 14:33 UTC) · Not checked
Version 42 · Files at version 43
2 files, 126 lines added, 2 removed.
--- a/client/src/install.ts
+++ b/client/src/install.ts
@@ -45,7 +45,7 @@
46 46 import { homedir, tmpdir } from "node:os"; 47 47 import { 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"; 50 50 export interface ModSpec { 51 51 /** The mod's name, as its plugin.json has it. */ @@ -167,6 +167,65 @@
167 167 return `${last.stdout.slice(0, 7)}${changed ? ".dirty" : ""}`; 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; 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. 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) => { 193 + const s = statSync(join(spec.from, ...rel.split("/"))); 194 + return `${s.size}:${s.mtimeMs}:${s.ino}`; 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> = {}; 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>; 208 + const was = kept[key]; 210 + was !== undefined && 211 + was.head === head && 212 + Array.isArray(was.files) && 213 + was.files.join() === files.join() && 214 + newest < was.at - RACY_MS 217 + const commit = modCommit(spec); 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); 224 + // Best effort: the next run asks git again. 170 229 /** The files to install, stamped with `version`, in install order. */ 171 230 function filesFor(spec: ModSpec, version: string): Map<string, Buffer> { 172 231 if (!/^[\w.+-]+$/.test(version)) throw new Error(`can't stamp the version ${JSON.stringify(version)}`); @@ -486,7 +545,7 @@
486 545 at: field(RECORD, "at"), 489 − return versionFor(spec);
548 + return versionFor(spec, keptModCommit(spec)); 491 550 return "not in this copy"; --- a/client/test/install.test.ts
+++ b/client/test/install.test.ts
@@ -27,6 +27,7 @@
@@ -301,6 +302,70 @@
301 302 // Outside a git checkout there is no commit to add. 302 303 assert.equal(versionFor(spec, null), "0.1.0"); 306 + it("keeps the mod's commit between runs, and asks git again when the checkout or a file moves, or a file is too new to trust", { 309 + const spec = source(); 310 + const home = temp(); 311 + const kept = join(home, ".abso", "mod-commits.json"); 312 + const git = (...args: string[]) => 313 + spawnSync("git", ["-c", "user.name=t", "-c", "user.email=t@t", "-C", spec.from, ...args], { 316 + // Every mod file a minute old, so a kept answer can be trusted. 318 + const old = new Date(Date.now() - 60_000); 319 + for (const rel of FILES) utimesSync(at(spec.from, rel), old, old); 321 + // Swaps every kept answer for a made-up one: what comes back says whether git ran. 322 + const plant = () => { 323 + const file = JSON.parse(readFileSync(kept, "utf8")); 324 + for (const k of Object.keys(file.mods)) file.mods[k].commit = "fffffff"; 325 + writeFileSync(kept, JSON.stringify(file)); 327 + // Not a git checkout yet: no commit, and nothing kept. 328 + assert.equal(keptModCommit(spec, home), null); 329 + assert.equal(existsSync(kept), false); 332 + git("commit", "-q", "-m", "mod"); 333 + const mod = git("rev-parse", "--short=7", "HEAD"); 335 + assert.equal(keptModCommit(spec, home), mod); 337 + assert.equal(keptModCommit(spec, home), "fffffff", "a kept answer is used while nothing moved"); 339 + // A file changed in the same moment the answer was kept is never trusted, even when its size and time match. 340 + write(spec.from, "src/core.ts", "export const core = 2\n"); 341 + assert.equal(keptModCommit(spec, home), `${mod}.dirty`); 343 + assert.equal(keptModCommit(spec, home), `${mod}.dirty`, "too new to trust: git runs again"); 345 + // An edit that keeps the size, with its time set back a minute, still isn't the time that was kept. 347 + assert.equal(keptModCommit(spec, home), `${mod}.dirty`); 349 + write(spec.from, "src/core.ts", "export const core = 3\n"); 351 + assert.equal(keptModCommit(spec, home), `${mod}.dirty`); 353 + // A commit moves the checkout. 354 + git("commit", "-q", "-am", "core"); 356 + const next = git("rev-parse", "--short=7", "HEAD"); 357 + assert.equal(keptModCommit(spec, home), next); 359 + git("commit", "-q", "--allow-empty", "-m", "empty"); 360 + assert.equal(keptModCommit(spec, home), next, "a new commit asks git again"); 362 + // A file it can't read, or doesn't know the format of, is the same as none. 364 + writeFileSync(kept, JSON.stringify({ format: 2, mods: JSON.parse(readFileSync(kept, "utf8")).mods })); 365 + assert.equal(keptModCommit(spec, home), next); 366 + writeFileSync(kept, "not json"); 367 + assert.equal(keptModCommit(spec, home), next); 306 371 describe("which client this is", () => {