{"draft":null,"from":67,"to":68,"files":[{"path":"client/src/client-version.ts","added":61,"removed":5,"diff":"--- a/client/src/client-version.ts\n+++ b/client/src/client-version.ts\n@@ -4,9 +4,11 @@\n // commit is read from .git without running git, since every command pays for\n // its start-up. (The mods carry their own stamp: src/install.ts.)\n \n-import { readFileSync, statSync } from \"node:fs\";\n+import { mkdirSync, readFileSync, statSync, writeFileSync } from \"node:fs\";\n+import { homedir } from \"node:os\";\n import { dirname, join, resolve } from \"node:path\";\n import { fileURLToPath } from \"node:url\";\n+import { homeWritePath } from \"./state-dir.ts\";\n \n export const CLIENT_DIR = resolve(dirname(fileURLToPath(import.meta.url)), \"..\");\n \n@@ -76,12 +78,66 @@\n \n let version: string | undefined;\n \n+const NPM_LATEST = \"https://registry.npmjs.org/@abso-cli/abso/latest\";\n+const DAY = 24 * 60 * 60 * 1000;\n+\n+/** Whether x.y.z version a comes after b. */\n+function laterThan(a: string, b: string): boolean {\n+\tconst x = a.split(\".\").map(Number);\n+\tconst y = b.split(\".\").map(Number);\n+\tfor (let i = 0; i < 3; i++) if (x[i] !== y[i]) return (x[i] ?? 0) > (y[i] ?? 0);\n+\treturn false;\n+}\n+\n /**\n- * When this client was bundled for a server and that server is now a different\n- * commit. Undefined when they match, when the server can't be asked, or when\n- * this client runs from a checkout, which abso sync updates and no server serves.\n+ * For the npm package: npm's latest version when it comes after this one. npm\n+ * is asked at most once a day, and its answer is kept in ~/.abso/npm-latest.json,\n+ * so status doesn't wait on the registry each time.\n  */\n-export async function newerCommitNote(server: string): Promise<string | undefined> {\n+async function newerPackageNote(\n+\tmine: string,\n+\thome: string,\n+\tregistry: string,\n+\tnow: number,\n+): Promise<string | undefined> {\n+\tconst file = homeWritePath(home, \"npm-latest.json\");\n+\tlet latest: string | undefined;\n+\ttry {\n+\t\tconst kept = JSON.parse(readFileSync(file, \"utf8\")) as { checked?: unknown; latest?: unknown };\n+\t\tif (typeof kept.checked === \"number\" && now - kept.checked < DAY && typeof kept.latest === \"string\")\n+\t\t\tlatest = kept.latest;\n+\t} catch {}\n+\tif (latest === undefined) {\n+\t\ttry {\n+\t\t\tconst response = await fetch(registry, { signal: AbortSignal.timeout(3000) });\n+\t\t\tconst body = (await response.json()) as { version?: unknown };\n+\t\t\tif (typeof body.version !== \"string\" || !/^\\d+\\.\\d+\\.\\d+$/.test(body.version)) return undefined;\n+\t\t\tlatest = body.version;\n+\t\t} catch {\n+\t\t\treturn undefined;\n+\t\t}\n+\t\ttry {\n+\t\t\tmkdirSync(dirname(file), { recursive: true });\n+\t\t\twriteFileSync(file, `${JSON.stringify({ checked: now, latest })}\\n`);\n+\t\t} catch {}\n+\t}\n+\treturn laterThan(latest, mine)\n+\t\t? `abso ${latest} is out and this is ${mine}: npm install -g @abso-cli/abso updates it.`\n+\t\t: undefined;\n+}\n+\n+/**\n+ * When a built copy of this client is behind: the npm package when npm has a\n+ * later version, or a client bundled for a server when that server is now a\n+ * different commit. Undefined when it isn't, when the answer can't be had, or\n+ * when this client runs from a checkout, which abso sync updates.\n+ */\n+export async function newerClientNote(\n+\tserver: string,\n+\tat: { home?: string; registry?: string; now?: number } = {},\n+): Promise<string | undefined> {\n+\tconst pkg = packageVersion();\n+\tif (pkg) return newerPackageNote(pkg, at.home ?? homedir(), at.registry ?? NPM_LATEST, at.now ?? Date.now());\n \tconst mine = bundledCommit();\n \tif (!mine) return undefined;\n \ttry {"}],"unmatched":[]}