{"version":68,"agent":"pinch","message":"An npm install of abso says when npm has a later version: status and --version add 'abso X is out and this is Y: npm install -g @abso-cli/abso updates it.' npm is asked at most once a day, and its answer is kept in ~/.abso/npm-latest.json. A copy bundled for a server still compares commits with that server. newerCommitNote is now newerClientNote.","time":1791606091384,"timeIso":"2026-10-10T04:21:31.384Z","changes":4,"change":842,"files":["client/src/client-version.ts","client/src/main.ts","client/src/status-commands.ts","client/test/client-version.test.ts"],"draft":null,"diff":[{"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 {"},{"path":"client/src/main.ts","added":2,"removed":2,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -802,14 +802,14 @@\n \t\tif (command === \"--version\") {\n \t\t\t// Loaded only here: it runs git, and no other command needs it.\n \t\t\tconst { versionReport } = await import(\"./install.ts\");\n-\t\t\tconst { newerCommitNote } = await import(\"./client-version.ts\");\n+\t\t\tconst { newerClientNote } = await import(\"./client-version.ts\");\n \t\t\tconst report = versionReport(env.env);\n \t\t\tconst root = findRoot(env.cwd);\n \t\t\tlet behind: string | undefined;\n \t\t\tif (root) {\n \t\t\t\ttry {\n \t\t\t\t\tconst server = (JSON.parse(readFileSync(configPath(root), \"utf8\")) as { server?: string }).server;\n-\t\t\t\t\tif (server) behind = await newerCommitNote(server);\n+\t\t\t\t\tif (server) behind = await newerClientNote(server);\n \t\t\t\t} catch {}\n \t\t\t}\n \t\t\treturn {"},{"path":"client/src/status-commands.ts","added":2,"removed":2,"diff":"--- a/client/src/status-commands.ts\n+++ b/client/src/status-commands.ts\n@@ -9,7 +9,7 @@\n import { readKnownBlobs, writeKnownBlobs } from \"./blobs.ts\";\n import { ciText } from \"./ci.ts\";\n import { CleanFiles } from \"./clean-files.ts\";\n-import { newerCommitNote } from \"./client-version.ts\";\n+import { newerClientNote } from \"./client-version.ts\";\n import { type Env, heard, type Output, open, plural } from \"./command-env.ts\";\n import {\n \tLISTED,\n@@ -313,7 +313,7 @@\n \tconst space = (draft: string | null | undefined): string => (draft ? `draft ${draft}` : \"shared\");\n \tconst parked = (me?.parked ?? []).filter((p) => p.draftChanges > 0);\n \tconst credential = credentialLabel(root, config.server, env.env);\n-\tconst behind = await newerCommitNote(config.server);\n+\tconst behind = await newerClientNote(config.server);\n \tconst lines = [\n \t\t`Project ${config.project}: shared is at version ${status.version}. This folder is ${config.agent}${config.reader || me?.reader ? \", a reader (it records and publishes nothing)\" : \"\"}, working in ${space(me?.draft)}.${config.follow ? ` It follows label ${config.follow}: syncs take it to the newest version with that label.` : \"\"} Signed in with ${credential.kind}${credential.id ? ` ${credential.id}` : \"\"}.`,\n \t\t...(behind ? [behind] : []),"},{"path":"client/test/client-version.test.ts","added":92,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/client-version.test.ts\n@@ -0,0 +1,92 @@\n+// An npm install of abso says when npm has a later version, asking npm at most\n+// once a day. The registry here is a stand-in that counts how often it is asked.\n+\n+import assert from \"node:assert/strict\";\n+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n+import { createServer, type Server } from \"node:http\";\n+import type { AddressInfo } from \"node:net\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { after, before, beforeEach, describe, it } from \"node:test\";\n+import { newerClientNote } from \"../src/client-version.ts\";\n+\n+const DAY = 24 * 60 * 60 * 1000;\n+const stamp = globalThis as { __ABSO_PACKAGE_VERSION__?: string };\n+let registry: Server;\n+let registryUrl: string;\n+let latest = \"0.67.0\";\n+let asked = 0;\n+let home: string;\n+\n+before(async () => {\n+\tregistry = createServer((_req, res) => {\n+\t\tasked++;\n+\t\tres\n+\t\t\t.writeHead(200, { \"content-type\": \"application/json\" })\n+\t\t\t.end(JSON.stringify({ name: \"@abso-cli/abso\", version: latest }));\n+\t});\n+\tawait new Promise<void>((done) => registry.listen(0, \"127.0.0.1\", done));\n+\tregistryUrl = `http://127.0.0.1:${(registry.address() as AddressInfo).port}/@abso-cli/abso/latest`;\n+});\n+after(() => {\n+\tregistry.close();\n+\tdelete stamp.__ABSO_PACKAGE_VERSION__;\n+});\n+beforeEach(() => {\n+\thome = mkdtempSync(join(tmpdir(), \"abso-test-home-\"));\n+\tasked = 0;\n+\tlatest = \"0.67.0\";\n+});\n+\n+describe(\"newerClientNote for the npm package\", () => {\n+\tit(\"says so when npm has a later version, and asks npm once a day\", async () => {\n+\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.66.0\";\n+\t\tconst now = 1_000_000_000_000;\n+\t\tconst note = await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now });\n+\t\tassert.equal(note, \"abso 0.67.0 is out and this is 0.66.0: npm install -g @abso-cli/abso updates it.\");\n+\t\tassert.equal(asked, 1);\n+\t\tassert.ok(existsSync(join(home, \".abso\", \"npm-latest.json\")));\n+\n+\t\tlatest = \"0.68.0\";\n+\t\tconst kept = await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: now + DAY - 1 });\n+\t\tassert.match(kept ?? \"\", /^abso 0\\.67\\.0 is out/, \"within a day the kept answer is used\");\n+\t\tassert.equal(asked, 1);\n+\n+\t\tconst fresh = await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: now + DAY });\n+\t\tassert.match(fresh ?? \"\", /^abso 0\\.68\\.0 is out/);\n+\t\tassert.equal(asked, 2);\n+\t\trmSync(home, { recursive: true, force: true });\n+\t});\n+\n+\tit(\"says nothing when this is npm's latest or later, and compares numbers, not text\", async () => {\n+\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.67.0\";\n+\t\tassert.equal(await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: 1 }), undefined);\n+\t\trmSync(home, { recursive: true, force: true });\n+\n+\t\thome = mkdtempSync(join(tmpdir(), \"abso-test-home-\"));\n+\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.100.0\";\n+\t\tlatest = \"0.99.0\";\n+\t\tassert.equal(await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: 1 }), undefined);\n+\t\trmSync(home, { recursive: true, force: true });\n+\t});\n+\n+\tit(\"says nothing when npm can't be asked, and keeps no answer\", async () => {\n+\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.66.0\";\n+\t\tconst note = await newerClientNote(\"http://unused.test\", { home, registry: \"http://127.0.0.1:1/latest\", now: 1 });\n+\t\tassert.equal(note, undefined);\n+\t\tassert.equal(existsSync(join(home, \".abso\", \"npm-latest.json\")), false);\n+\t\trmSync(home, { recursive: true, force: true });\n+\t});\n+\n+\tit(\"asks npm again when the kept answer isn't JSON, and keeps the new one\", async () => {\n+\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.66.0\";\n+\t\tconst file = join(home, \".abso\", \"npm-latest.json\");\n+\t\tmkdirSync(join(home, \".abso\"), { recursive: true });\n+\t\twriteFileSync(file, \"not json\");\n+\t\tconst note = await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: 5 });\n+\t\tassert.match(note ?? \"\", /^abso 0\\.67\\.0 is out/);\n+\t\tassert.equal(asked, 1);\n+\t\tassert.deepEqual(JSON.parse(readFileSync(file, \"utf8\")), { checked: 5, latest: \"0.67.0\" });\n+\t\trmSync(home, { recursive: true, force: true });\n+\t});\n+});"}],"ci":null}