{"version":43,"agent":"speed","message":"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","time":1791556436079,"timeIso":"2026-10-09T14:33:56.079Z","changes":7,"change":552,"files":["client/src/install.ts","client/test/install.test.ts"],"draft":null,"diff":[{"path":"client/src/install.ts","added":61,"removed":2,"diff":"--- a/client/src/install.ts\n+++ b/client/src/install.ts\n@@ -45,7 +45,7 @@\n } from \"node:fs\";\n import { homedir, tmpdir } from \"node:os\";\n import { dirname, join, resolve } from \"node:path\";\n-import { CLIENT_DIR, clientPlace, clientVersion } from \"./client-version.ts\";\n+import { CLIENT_DIR, clientPlace, clientVersion, headCommit } from \"./client-version.ts\";\n \n export interface ModSpec {\n \t/** The mod's name, as its plugin.json has it. */\n@@ -167,6 +167,65 @@\n \treturn `${last.stdout.slice(0, 7)}${changed ? \".dirty\" : \"\"}`;\n }\n \n+/** A file changed this close to when an answer was kept can't be told apart from one changed just after it. */\n+const RACY_MS = 2_000;\n+\n+interface KeptModCommit {\n+\treadonly head: string;\n+\treadonly files: readonly string[];\n+\treadonly at: number;\n+\treadonly commit: string | null;\n+}\n+\n+/**\n+ * modCommit for the version report, which `abso status` asks on every run: it runs git twice per mod, so\n+ * the answer is kept in ~/.abso/mod-commits.json. A kept answer holds while the checkout's commit (read\n+ * from .git, without git) and each of the mod's files (size, modified time, inode) are as they were, and\n+ * every file was changed clearly before the answer was kept; anything else asks git again. Outside a git\n+ * checkout there is no commit, and git isn't run at all.\n+ */\n+export function keptModCommit(spec: ModSpec, home: string = homedir()): string | null {\n+\tconst head = headCommit(spec.from);\n+\tif (head === undefined) return null;\n+\tconst at = Date.now();\n+\tconst files = spec.files.map((rel) => {\n+\t\ttry {\n+\t\t\tconst s = statSync(join(spec.from, ...rel.split(\"/\")));\n+\t\t\treturn `${s.size}:${s.mtimeMs}:${s.ino}`;\n+\t\t} catch {\n+\t\t\treturn \"-\";\n+\t\t}\n+\t});\n+\tconst newest = Math.max(...files.map((f) => (f === \"-\" ? 0 : Number(f.split(\":\")[1]))));\n+\tconst path = join(home, \".abso\", \"mod-commits.json\");\n+\tconst key = `${resolve(spec.from)}|${spec.files.join(\"|\")}`;\n+\tlet kept: Record<string, KeptModCommit> = {};\n+\ttry {\n+\t\tconst parsed = JSON.parse(readFileSync(path, \"utf8\")) as { format?: unknown; mods?: unknown };\n+\t\tif (parsed.format === 1 && typeof parsed.mods === \"object\" && parsed.mods !== null)\n+\t\t\tkept = parsed.mods as Record<string, KeptModCommit>;\n+\t} catch {}\n+\tconst was = kept[key];\n+\tif (\n+\t\twas !== undefined &&\n+\t\twas.head === head &&\n+\t\tArray.isArray(was.files) &&\n+\t\twas.files.join() === files.join() &&\n+\t\tnewest < was.at - RACY_MS\n+\t)\n+\t\treturn was.commit;\n+\tconst commit = modCommit(spec);\n+\ttry {\n+\t\tmkdirSync(dirname(path), { recursive: true });\n+\t\tconst next = `${path}.${process.pid}.tmp`;\n+\t\twriteFileSync(next, JSON.stringify({ format: 1, mods: { ...kept, [key]: { head, files, at, commit } } }));\n+\t\trenameSync(next, path);\n+\t} catch {\n+\t\t// Best effort: the next run asks git again.\n+\t}\n+\treturn commit;\n+}\n+\n /** The files to install, stamped with `version`, in install order. */\n function filesFor(spec: ModSpec, version: string): Map<string, Buffer> {\n \tif (!/^[\\w.+-]+$/.test(version)) throw new Error(`can't stamp the version ${JSON.stringify(version)}`);\n@@ -486,7 +545,7 @@\n \t\t\tat: field(RECORD, \"at\"),\n \t\t\tcurrent: (() => {\n \t\t\t\ttry {\n-\t\t\t\t\treturn versionFor(spec);\n+\t\t\t\t\treturn versionFor(spec, keptModCommit(spec));\n \t\t\t\t} catch {\n \t\t\t\t\treturn \"not in this copy\";\n \t\t\t\t}"},{"path":"client/test/install.test.ts","added":65,"removed":0,"diff":"--- a/client/test/install.test.ts\n+++ b/client/test/install.test.ts\n@@ -27,6 +27,7 @@\n import {\n \tAVCS_MOD,\n \tinstallMod,\n+\tkeptModCommit,\n \ttype ModSpec,\n \tmodsBehindText,\n \tretireOldMod,\n@@ -301,6 +302,70 @@\n \t\t// Outside a git checkout there is no commit to add.\n \t\tassert.equal(versionFor(spec, null), \"0.1.0\");\n \t});\n+\n+\tit(\"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\", {\n+\t\tskip: !hasGit,\n+\t}, () => {\n+\t\tconst spec = source();\n+\t\tconst home = temp();\n+\t\tconst kept = join(home, \".abso\", \"mod-commits.json\");\n+\t\tconst git = (...args: string[]) =>\n+\t\t\tspawnSync(\"git\", [\"-c\", \"user.name=t\", \"-c\", \"user.email=t@t\", \"-C\", spec.from, ...args], {\n+\t\t\t\tencoding: \"utf8\",\n+\t\t\t}).stdout.trim();\n+\t\t// Every mod file a minute old, so a kept answer can be trusted.\n+\t\tconst age = () => {\n+\t\t\tconst old = new Date(Date.now() - 60_000);\n+\t\t\tfor (const rel of FILES) utimesSync(at(spec.from, rel), old, old);\n+\t\t};\n+\t\t// Swaps every kept answer for a made-up one: what comes back says whether git ran.\n+\t\tconst plant = () => {\n+\t\t\tconst file = JSON.parse(readFileSync(kept, \"utf8\"));\n+\t\t\tfor (const k of Object.keys(file.mods)) file.mods[k].commit = \"fffffff\";\n+\t\t\twriteFileSync(kept, JSON.stringify(file));\n+\t\t};\n+\t\t// Not a git checkout yet: no commit, and nothing kept.\n+\t\tassert.equal(keptModCommit(spec, home), null);\n+\t\tassert.equal(existsSync(kept), false);\n+\t\tgit(\"init\", \"-q\");\n+\t\tgit(\"add\", \".\");\n+\t\tgit(\"commit\", \"-q\", \"-m\", \"mod\");\n+\t\tconst mod = git(\"rev-parse\", \"--short=7\", \"HEAD\");\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), mod);\n+\t\tplant();\n+\t\tassert.equal(keptModCommit(spec, home), \"fffffff\", \"a kept answer is used while nothing moved\");\n+\n+\t\t// A file changed in the same moment the answer was kept is never trusted, even when its size and time match.\n+\t\twrite(spec.from, \"src/core.ts\", \"export const core = 2\\n\");\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\t\tplant();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`, \"too new to trust: git runs again\");\n+\n+\t\t// An edit that keeps the size, with its time set back a minute, still isn't the time that was kept.\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\t\tplant();\n+\t\twrite(spec.from, \"src/core.ts\", \"export const core = 3\\n\");\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\n+\t\t// A commit moves the checkout.\n+\t\tgit(\"commit\", \"-q\", \"-am\", \"core\");\n+\t\tage();\n+\t\tconst next = git(\"rev-parse\", \"--short=7\", \"HEAD\");\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t\tplant();\n+\t\tgit(\"commit\", \"-q\", \"--allow-empty\", \"-m\", \"empty\");\n+\t\tassert.equal(keptModCommit(spec, home), next, \"a new commit asks git again\");\n+\n+\t\t// A file it can't read, or doesn't know the format of, is the same as none.\n+\t\tplant();\n+\t\twriteFileSync(kept, JSON.stringify({ format: 2, mods: JSON.parse(readFileSync(kept, \"utf8\")).mods }));\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t\twriteFileSync(kept, \"not json\");\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t});\n });\n \n describe(\"which client this is\", () => {"}],"ci":null}