Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
show on this site's /mcp
CLI
abso show 68 --json
JSON
/christopher/abso-core/versions/68?format=json

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.

of shared·pinch··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 @@
44// commit is read from .git without running git, since every command pays for
55// its start-up. (The mods carry their own stamp: src/install.ts.)
66
7−import { readFileSync, statSync } from "node:fs";
7+import { mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
8+import { homedir } from "node:os";
89import { dirname, join, resolve } from "node:path";
910import { fileURLToPath } from "node:url";
11+import { homeWritePath } from "./state-dir.ts";
1012
1113export const CLIENT_DIR = resolve(dirname(fileURLToPath(import.meta.url)), "..");
1214
@@ -76,12 +78,66 @@
7678
7779let version: string | undefined;
7880
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);
89+ return false;
90+}
7992/**
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.
8396 */
84−export async function newerCommitNote(server: string): Promise<string | undefined> {
97+async function newerPackageNote(
98+ mine: string,
99+ home: string,
100+ registry: string,
101+ now: number,
102+): Promise<string | undefined> {
103+ const file = homeWritePath(home, "npm-latest.json");
104+ let latest: string | undefined;
105+ try {
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;
109+ } catch {}
110+ if (latest === undefined) {
111+ try {
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;
116+ } catch {
117+ return undefined;
118+ }
119+ try {
120+ mkdirSync(dirname(file), { recursive: true });
121+ writeFileSync(file, `${JSON.stringify({ checked: now, latest })}\n`);
122+ } catch {}
123+ }
124+ return laterThan(latest, mine)
125+ ? `abso ${latest} is out and this is ${mine}: npm install -g @abso-cli/abso updates it.`
126+ : undefined;
127+}
129+/**
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.
134+ */
135+export async function newerClientNote(
136+ server: string,
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());
85141 const mine = bundledCommit();
86142 if (!mine) return undefined;
87143 try {
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -802,14 +802,14 @@
802802 if (command === "--version") {
803803 // Loaded only here: it runs git, and no other command needs it.
804804 const { versionReport } = await import("./install.ts");
805− const { newerCommitNote } = await import("./client-version.ts");
805+ const { newerClientNote } = await import("./client-version.ts");
806806 const report = versionReport(env.env);
807807 const root = findRoot(env.cwd);
808808 let behind: string | undefined;
809809 if (root) {
810810 try {
811811 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);
813813 } catch {}
814814 }
815815 return {
--- a/client/src/status-commands.ts
+++ b/client/src/status-commands.ts
@@ -9,7 +9,7 @@
99import { readKnownBlobs, writeKnownBlobs } from "./blobs.ts";
1010import { ciText } from "./ci.ts";
1111import { CleanFiles } from "./clean-files.ts";
12−import { newerCommitNote } from "./client-version.ts";
12+import { newerClientNote } from "./client-version.ts";
1313import { type Env, heard, type Output, open, plural } from "./command-env.ts";
1414import {
1515 LISTED,
@@ -313,7 +313,7 @@
313313 const space = (draft: string | null | undefined): string => (draft ? `draft ${draft}` : "shared");
314314 const parked = (me?.parked ?? []).filter((p) => p.draftChanges > 0);
315315 const credential = credentialLabel(root, config.server, env.env);
316− const behind = await newerCommitNote(config.server);
316+ const behind = await newerClientNote(config.server);
317317 const lines = [
318318 `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}` : ""}.`,
319319 ...(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.
3+
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 };
15+let registry: Server;
16+let registryUrl: string;
17+let latest = "0.67.0";
18+let asked = 0;
19+let home: string;
21+before(async () => {
22+ registry = createServer((_req, res) => {
23+ asked++;
24+ res
25+ .writeHead(200, { "content-type": "application/json" })
26+ .end(JSON.stringify({ name: "@abso-cli/abso", version: latest }));
27+ });
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`;
30+});
31+after(() => {
32+ registry.close();
33+ delete stamp.__ABSO_PACKAGE_VERSION__;
34+});
35+beforeEach(() => {
36+ home = mkdtempSync(join(tmpdir(), "abso-test-home-"));
37+ asked = 0;
38+ latest = "0.67.0";
39+});
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")));
50+ latest = "0.68.0";
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 });
59+ });
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";
68+ latest = "0.99.0";
69+ assert.equal(await newerClientNote("http://unused.test", { home, registry: registryUrl, now: 1 }), undefined);
70+ rmSync(home, { recursive: true, force: true });
71+ });
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 });
79+ });
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 });
91+ });
92+});