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 84 --json
JSON
/christopher/abso-core/versions/84?format=json

whoami and doctor pick the server as join does

of shared·speed··Not checked

After abso login --server <url>, whoami and doctor still looked at https://api.abso.dev outside a folder, so they said you weren't signed in, and doctor checked the wrong server. Both now take --server, then ABSO_SERVER, then the folder's server, then the server this box signed in to with abso login, then https://api.abso.dev. A box signed in to more than one server is asked to say which with --server, as join does. Help text says so. Test in client/test/doctor.test.ts.

Version 83 · Files at version 84

3 files, 55 lines added, 7 removed.

--- a/client/src/doctor.ts
+++ b/client/src/doctor.ts
@@ -3,9 +3,12 @@
33// when one fails. Neither prints a credential. plainError words the commonest failures the same way.
44
55import { ApiError } from "./api-error.ts";
6−import { type Answer, type BoxRecord, boxGet, boxText, originOf, readBox } from "./box.ts";
6+import { UsageError } from "./args.ts";
7+import { type Answer, type BoxRecord, boxGet, boxText, originOf, readBox, signedInServers } from "./box.ts";
78import { builtCopy } from "./client-version.ts";
89import { type Config, credentialLabel, findRoot, readConfig } from "./config.ts";
10+import { TOKEN_SERVERS } from "./core.ts";
11+import { fromEnv } from "./env-names.ts";
1013/** The lowest Node major each kind of copy runs on: the npm package is built for 20, a checkout runs its .ts as is. */
1114export function nodeNeeded(built: boolean): number {
@@ -39,6 +42,28 @@
3942 }
4043}
4144
45+/**
46+ * The server whoami and doctor look at, in the order join picks one: --server, then ABSO_SERVER, then this
47+ * folder's server, then the one this box signed in to with abso login, then https://api.abso.dev. A box signed
48+ * in to more than one server has to say which.
49+ */
50+export function checkServer(
51+ flag: string | undefined,
52+ cwd: string,
53+ env: Readonly<Record<string, string | undefined>>,
54+ home?: string,
55+ now = Date.now(),
56+): string {
57+ const named = flag ?? fromEnv(env, "SERVER");
58+ if (named) return named;
59+ const folder = folderOf(cwd, env)?.config?.server;
60+ if (folder) return folder;
61+ const signedIn = signedInServers(home, now);
62+ if (signedIn.length > 1)
63+ throw new UsageError(`this box is signed in to ${signedIn.join(" and ")}: say which with --server <url>`);
64+ return signedIn[0] ?? TOKEN_SERVERS[0]!;
65+}
4267const day = (ms: number) => new Date(ms).toISOString().slice(0, 16).replace("T", " ");
4368
4469/** The server's view of this box: GET /box, as the box. */
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -39,7 +39,7 @@
3939} from "./commands.ts";
4040import { configPath, findRoot, installKey, readConfig, readToken } from "./config.ts";
4141import { newsBlockLines, newsShown, TOKEN_SERVERS } from "./core.ts";
42−import { doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts";
42+import { checkServer, doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts";
4343import { runDraftSync, runLand, runSwitch } from "./drafts.ts";
4444import { runExport } from "./export.ts";
4545import { runBlame, runWhere, runWho, runWhy } from "./history.ts";
@@ -208,9 +208,9 @@
208208 flags: { server: "string" },
209209 usage: "abso whoami [--server <url>]",
210210 about:
211− "Who and where you're signed in: this box's sign-in, as the server sees it (so a revoked one shows), its projects, roles and expiry, and this folder's project, agent and kind of key. Never a credential.",
211+ "Who and where you're signed in: this box's sign-in, as the server sees it (so a revoked one shows), its projects, roles and expiry, and this folder's project, agent and kind of key. Never a credential. The server is --server, else ABSO_SERVER, else this folder's, else the one this box signed in to with abso login, else https://api.abso.dev.",
212212 run: async (args, env) => {
213− const out = await whoami(boxServer(args, env), env.cwd, env.env, realProbe());
213+ const out = await whoami(checkServer(str(args, "server"), env.cwd, env.env), env.cwd, env.env, realProbe());
214214 return { text: out.text, json: out.json };
215215 },
216216 },
@@ -218,9 +218,9 @@
218218 flags: { server: "string" },
219219 usage: "abso doctor [--server <url>]",
220220 about:
221− "Checks what commands need, one line each: Node's version, that the server answers, this box's sign-in (present, unexpired, accepted), and this folder's key against its project. A failed check says what to do next, and the exit is 1. Never prints a credential.",
221+ "Checks what commands need, one line each: Node's version, that the server answers, this box's sign-in (present, unexpired, accepted), and this folder's key against its project. A failed check says what to do next, and the exit is 1. Never prints a credential. It picks the server as whoami does.",
222222 run: async (args, env) => {
223− const checks = await doctor(boxServer(args, env), env.cwd, env.env, realProbe());
223+ const checks = await doctor(checkServer(str(args, "server"), env.cwd, env.env), env.cwd, env.env, realProbe());
224224 const failed = checks.some((c) => c.result === "fail");
225225 return { text: doctorText(checks), json: { checks }, ...(failed ? { exit: EXIT.error } : {}) };
226226 },
--- a/client/test/doctor.test.ts
+++ b/client/test/doctor.test.ts
@@ -8,7 +8,7 @@
88import { test } from "node:test";
99import { ApiError } from "../src/api-error.ts";
1010import { writeBox } from "../src/box.ts";
11−import { doctor, doctorText, nodeNeeded, type Probe, plainError, whoami } from "../src/doctor.ts";
11+import { checkServer, doctor, doctorText, nodeNeeded, type Probe, plainError, whoami } from "../src/doctor.ts";
1212
1313const SERVER = "https://staging.abso.example";
1414const CREDENTIAL = "abso_bx_the-secret-credential";
@@ -227,3 +227,26 @@
227227 assert.equal(plainError(new ApiError("GET /log answered 500: boom", 500), true), undefined);
228228 assert.equal(plainError(new Error("anything else"), true), undefined);
229229});
231+test("whoami and doctor pick the server as join does: --server, ABSO_SERVER, the folder's, the box's sign-in, then abso.dev", () => {
232+ const outside = temp("outside");
233+ const empty = temp("home");
234+ assert.equal(checkServer(undefined, outside, {}, empty, NOW), "https://api.abso.dev");
235+ const home = temp("home");
236+ writeBox(box(), home);
237+ assert.equal(checkServer(undefined, outside, {}, home, NOW), SERVER);
238+ assert.equal(checkServer(undefined, folder(), {}, empty, NOW), SERVER);
239+ assert.equal(checkServer(undefined, outside, { ABSO_SERVER: "http://env.example" }, home, NOW), "http://env.example");
240+ assert.equal(
241+ checkServer("http://flag.example", folder(), { ABSO_SERVER: "http://env.example" }, home, NOW),
242+ "http://flag.example",
243+ );
244+ const expired = temp("home");
245+ writeBox(box(NOW - 1), expired);
246+ assert.equal(checkServer(undefined, outside, {}, expired, NOW), "https://api.abso.dev");
247+ writeBox({ ...box(), server: "https://api.abso.dev" }, home);
248+ assert.throws(
249+ () => checkServer(undefined, outside, {}, home, NOW),
250+ /signed in to .* and .*: say which with --server/,
251+ );
252+});