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. Version 68 of shared· pinch· Oct 10 (2026-10-10 04:21 UTC) · Not checked
Version 67 · Files at version 68
4 files, 157 lines added, 9 removed.
--- a/client/src/client-version.ts
+++ b/client/src/client-version.ts
@@ -4,9 +4,11 @@
4 4 // commit is read from .git without running git, since every command pays for 5 5 // its start-up. (The mods carry their own stamp: src/install.ts.) 7 − import { readFileSync, statSync } from "node:fs";
7 + import { mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs"; 8 + import { homedir } from "node:os"; 8 9 import { dirname, join, resolve } from "node:path"; 9 10 import { fileURLToPath } from "node:url"; 11 + import { homeWritePath } from "./state-dir.ts"; 11 13 export const CLIENT_DIR = resolve(dirname(fileURLToPath(import.meta.url)), ".."); @@ -76,12 +78,66 @@
77 79 let version: string | undefined; 81 + const NPM_LATEST = "https://registry.npmjs.org/@abso-cli/abso/latest"; 82 + const DAY = 24 * 60 * 60 * 1000; 84 + /** Whether x.y.z version a comes after b. */ 85 + function laterThan(a: string, b: string): boolean { 86 + const x = a.split(".").map(Number); 87 + const y = b.split(".").map(Number); 88 + for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return (x[i] ?? 0) > (y[i] ?? 0); 80 − * When this client was bundled for a server and that server is now a different
81 − * commit. Undefined when they match, when the server can't be asked, or when
82 − * this client runs from a checkout, which abso sync updates and no server serves.
93 + * For the npm package: npm's latest version when it comes after this one. npm 94 + * is asked at most once a day, and its answer is kept in ~/.abso/npm-latest.json, 95 + * so status doesn't wait on the registry each time. 84 − export async function newerCommitNote(server: string): Promise<string | undefined> {
97 + async function newerPackageNote( 102 + ): Promise<string | undefined> { 103 + const file = homeWritePath(home, "npm-latest.json"); 104 + let latest: string | undefined; 106 + const kept = JSON.parse(readFileSync(file, "utf8")) as { checked?: unknown; latest?: unknown }; 107 + if (typeof kept.checked === "number" && now - kept.checked < DAY && typeof kept.latest === "string") 108 + latest = kept.latest; 110 + if (latest === undefined) { 112 + const response = await fetch(registry, { signal: AbortSignal.timeout(3000) }); 113 + const body = (await response.json()) as { version?: unknown }; 114 + if (typeof body.version !== "string" || !/^\d+\.\d+\.\d+$/.test(body.version)) return undefined; 115 + latest = body.version; 120 + mkdirSync(dirname(file), { recursive: true }); 121 + writeFileSync(file, `${JSON.stringify({ checked: now, latest })}\n`); 124 + return laterThan(latest, mine) 125 + ? `abso ${latest} is out and this is ${mine}: npm install -g @abso-cli/abso updates it.` 130 + * When a built copy of this client is behind: the npm package when npm has a 131 + * later version, or a client bundled for a server when that server is now a 132 + * different commit. Undefined when it isn't, when the answer can't be had, or 133 + * when this client runs from a checkout, which abso sync updates. 135 + export async function newerClientNote( 137 + at: { home?: string; registry?: string; now?: number } = {}, 138 + ): Promise<string | undefined> { 139 + const pkg = packageVersion(); 140 + if (pkg) return newerPackageNote(pkg, at.home ?? homedir(), at.registry ?? NPM_LATEST, at.now ?? Date.now()); 85 141 const mine = bundledCommit(); 86 142 if (!mine) return undefined; --- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -802,14 +802,14 @@
802 802 if (command === "--version") { 803 803 // Loaded only here: it runs git, and no other command needs it. 804 804 const { versionReport } = await import("./install.ts"); 805 − const { newerCommitNote } = await import("./client-version.ts");
805 + const { newerClientNote } = await import("./client-version.ts"); 806 806 const report = versionReport(env.env); 807 807 const root = findRoot(env.cwd); 808 808 let behind: string | undefined; 811 811 const server = (JSON.parse(readFileSync(configPath(root), "utf8")) as { server?: string }).server; 812 − if (server) behind = await newerCommitNote(server);
812 + if (server) behind = await newerClientNote(server); --- a/client/src/status-commands.ts
+++ b/client/src/status-commands.ts
@@ -9,7 +9,7 @@
9 9 import { readKnownBlobs, writeKnownBlobs } from "./blobs.ts"; 10 10 import { ciText } from "./ci.ts"; 11 11 import { CleanFiles } from "./clean-files.ts"; 12 − import { newerCommitNote } from "./client-version.ts";
12 + import { newerClientNote } from "./client-version.ts"; 13 13 import { type Env, heard, type Output, open, plural } from "./command-env.ts"; @@ -313,7 +313,7 @@
313 313 const space = (draft: string | null | undefined): string => (draft ? `draft ${draft}` : "shared"); 314 314 const parked = (me?.parked ?? []).filter((p) => p.draftChanges > 0); 315 315 const credential = credentialLabel(root, config.server, env.env); 316 − const behind = await newerCommitNote(config.server);
316 + const behind = await newerClientNote(config.server); 318 318 `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}` : ""}.`, 319 319 ...(behind ? [behind] : []), --- /dev/null
+++ b/client/test/client-version.test.ts
@@ -0,0 +1,92 @@
1 + // An npm install of abso says when npm has a later version, asking npm at most 2 + // once a day. The registry here is a stand-in that counts how often it is asked. 4 + import assert from "node:assert/strict"; 5 + import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; 6 + import { createServer, type Server } from "node:http"; 7 + import type { AddressInfo } from "node:net"; 8 + import { tmpdir } from "node:os"; 9 + import { join } from "node:path"; 10 + import { after, before, beforeEach, describe, it } from "node:test"; 11 + import { newerClientNote } from "../src/client-version.ts"; 13 + const DAY = 24 * 60 * 60 * 1000; 14 + const stamp = globalThis as { __ABSO_PACKAGE_VERSION__?: string }; 16 + let registryUrl: string; 17 + let latest = "0.67.0"; 22 + registry = createServer((_req, res) => { 25 + .writeHead(200, { "content-type": "application/json" }) 26 + .end(JSON.stringify({ name: "@abso-cli/abso", version: latest })); 28 + await new Promise<void>((done) => registry.listen(0, "127.0.0.1", done)); 29 + registryUrl = `http://127.0.0.1:${(registry.address() as AddressInfo).port}/@abso-cli/abso/latest`; 33 + delete stamp.__ABSO_PACKAGE_VERSION__; 36 + home = mkdtempSync(join(tmpdir(), "abso-test-home-")); 41 + describe("newerClientNote for the npm package", () => { 42 + it("says so when npm has a later version, and asks npm once a day", async () => { 43 + stamp.__ABSO_PACKAGE_VERSION__ = "0.66.0"; 44 + const now = 1_000_000_000_000; 45 + const note = await newerClientNote("http://unused.test", { home, registry: registryUrl, now }); 46 + assert.equal(note, "abso 0.67.0 is out and this is 0.66.0: npm install -g @abso-cli/abso updates it."); 47 + assert.equal(asked, 1); 48 + assert.ok(existsSync(join(home, ".abso", "npm-latest.json"))); 51 + const kept = await newerClientNote("http://unused.test", { home, registry: registryUrl, now: now + DAY - 1 }); 52 + assert.match(kept ?? "", /^abso 0\.67\.0 is out/, "within a day the kept answer is used"); 53 + assert.equal(asked, 1); 55 + const fresh = await newerClientNote("http://unused.test", { home, registry: registryUrl, now: now + DAY }); 56 + assert.match(fresh ?? "", /^abso 0\.68\.0 is out/); 57 + assert.equal(asked, 2); 58 + rmSync(home, { recursive: true, force: true }); 61 + it("says nothing when this is npm's latest or later, and compares numbers, not text", async () => { 62 + stamp.__ABSO_PACKAGE_VERSION__ = "0.67.0"; 63 + assert.equal(await newerClientNote("http://unused.test", { home, registry: registryUrl, now: 1 }), undefined); 64 + rmSync(home, { recursive: true, force: true }); 66 + home = mkdtempSync(join(tmpdir(), "abso-test-home-")); 67 + stamp.__ABSO_PACKAGE_VERSION__ = "0.100.0"; 69 + assert.equal(await newerClientNote("http://unused.test", { home, registry: registryUrl, now: 1 }), undefined); 70 + rmSync(home, { recursive: true, force: true }); 73 + it("says nothing when npm can't be asked, and keeps no answer", async () => { 74 + stamp.__ABSO_PACKAGE_VERSION__ = "0.66.0"; 75 + const note = await newerClientNote("http://unused.test", { home, registry: "http://127.0.0.1:1/latest", now: 1 }); 76 + assert.equal(note, undefined); 77 + assert.equal(existsSync(join(home, ".abso", "npm-latest.json")), false); 78 + rmSync(home, { recursive: true, force: true }); 81 + it("asks npm again when the kept answer isn't JSON, and keeps the new one", async () => { 82 + stamp.__ABSO_PACKAGE_VERSION__ = "0.66.0"; 83 + const file = join(home, ".abso", "npm-latest.json"); 84 + mkdirSync(join(home, ".abso"), { recursive: true }); 85 + writeFileSync(file, "not json"); 86 + const note = await newerClientNote("http://unused.test", { home, registry: registryUrl, now: 5 }); 87 + assert.match(note ?? "", /^abso 0\.67\.0 is out/); 88 + assert.equal(asked, 1); 89 + assert.deepEqual(JSON.parse(readFileSync(file, "utf8")), { checked: 5, latest: "0.67.0" }); 90 + rmSync(home, { recursive: true, force: true });