{"draft":null,"from":42,"to":43,"files":[{"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}"}],"unmatched":[]}