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

abso whoami and abso doctor, and plainer errors.

of shared·speed··Not checked

  • abso whoami: this box's sign-in as the server sees it (a revoked one shows as revoked), its projects, roles and expiry, and this folder's project, agent and kind of key. It names who approved the box when the server says.
  • abso doctor: one line per check, ok, fail or skip: Node's version (20 or later for the npm package, 24 for a checkout), that the server answers, this box's sign-in (present, unexpired, accepted), and this folder's key against its project (a GET of the project's head, which the server answers only after checking the key). A failed check gives the next step, and the exit is 1.
  • Neither prints a credential. Both are MCP tools too.
  • The commonest failures now say what to do: a 401 with no credential reads 'You're not signed in. Run abso login, then abso join <project>.'; a refused key points to abso doctor; a server that can't be reached reads 'Can't reach <server>...' with the next step, unless the message already gives one; and outside a folder, 'You're not in an abso folder' says how to make one.

Version 75 · Files at version 76

6 files, 589 lines added, 4 removed.

--- a/client/src/command-env.ts
+++ b/client/src/command-env.ts
@@ -35,7 +35,7 @@
3535 const root = findRoot(env.cwd);
3636 if (root === undefined)
3737 throw new UsageError(
38− `${env.cwd} is not in an abso folder (no .abso/config.json here or above); run abso init or abso join first`,
38+ `You're not in an abso folder: ${env.cwd} has no .abso/config.json, nor does any folder above it. abso join <project> makes one, or abso init a new project.`,
3939 );
4040 const config = readConfig(root, env.env);
4141 return { root, config, api: new Api(config) };
--- /dev/null
+++ b/client/src/doctor.ts
@@ -0,0 +1,316 @@
1+// abso whoami and abso doctor: who and where this box and folder are signed in, and a check of each thing
2+// a command needs (Node, the server, the box's sign-in, the folder's key), one line each, with the next step
3+// when one fails. Neither prints a credential. plainError words the commonest failures the same way.
4+
5+import { ApiError } from "./api-error.ts";
6+import { type Answer, type BoxRecord, boxGet, boxText, originOf, readBox } from "./box.ts";
7+import { builtCopy } from "./client-version.ts";
8+import { type Config, credentialLabel, findRoot, readConfig } from "./config.ts";
9+
10+/** The lowest Node major each kind of copy runs on: the npm package is built for 20, a checkout runs its .ts as is. */
11+export function nodeNeeded(built: boolean): number {
12+ return built ? 20 : 24;
13+}
15+/** What whoami and doctor read from outside: the network, the clock, Node's version and the home folder. Tests give their own. */
16+export interface Probe {
17+ readonly fetcher: typeof fetch;
18+ readonly now: number;
19+ readonly node: string;
20+ readonly built: boolean;
21+ readonly home?: string;
22+}
24+export function realProbe(): Probe {
25+ return { fetcher: fetch, now: Date.now(), node: process.versions.node, built: builtCopy() };
26+}
28+/** This folder's settings, or why they can't be read; undefined outside a folder. */
29+function folderOf(
30+ cwd: string,
31+ env: Readonly<Record<string, string | undefined>>,
32+): { root: string; config?: Config; problem?: string } | undefined {
33+ const root = findRoot(cwd);
34+ if (root === undefined) return undefined;
35+ try {
36+ return { root, config: readConfig(root, env) };
37+ } catch (err) {
38+ return { root, problem: err instanceof Error ? err.message : String(err) };
39+ }
40+}
42+const day = (ms: number) => new Date(ms).toISOString().slice(0, 16).replace("T", " ");
44+/** The server's view of this box: GET /box, as the box. */
45+async function serverBox(record: BoxRecord, probe: Probe): Promise<Answer | { unreachable: string }> {
46+ try {
47+ return await boxGet(record, "/box", timed(probe.fetcher, 10_000));
48+ } catch (err) {
49+ return { unreachable: err instanceof Error ? err.message : String(err) };
50+ }
51+}
53+/** fetch with its own, shorter limit: a check that hangs says so rather than waiting out the command's. */
54+function timed(fetcher: typeof fetch, ms: number): typeof fetch {
55+ return ((input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) =>
56+ fetcher(input, { ...init, signal: AbortSignal.timeout(ms) })) as typeof fetch;
57+}
59+function credentialWords(root: string, server: string, env: Readonly<Record<string, string | undefined>>): string {
60+ const c = credentialLabel(root, server, env);
61+ return c.kind === "agent key" ? `the agent key ${c.id}` : c.kind === "shared token" ? "the shared token" : "no key";
62+}
64+export async function whoami(
65+ server: string,
66+ cwd: string,
67+ env: Readonly<Record<string, string | undefined>>,
68+ probe: Probe,
69+): Promise<{ text: string; json: Record<string, unknown> }> {
70+ const lines: string[] = [];
71+ const record = readBox(server, probe.home);
72+ let box: Record<string, unknown> | null = null;
73+ if (!record) {
74+ lines.push(`This box isn't signed in to ${originOf(server)}. Run abso login.`);
75+ } else {
76+ const answer = await serverBox(record, probe);
77+ const [first, ...rest] = boxText(record, server, probe.now).split("\n");
78+ box = {
79+ server: record.server,
80+ id: record.id,
81+ grant: record.grant,
82+ expiresAt: new Date(record.expiresAt).toISOString(),
83+ };
84+ if ("unreachable" in answer) {
85+ lines.push(first!, ...rest, `${originOf(server)} couldn't be reached to confirm it: ${answer.unreachable}`);
86+ box.confirmed = null;
87+ } else if (answer.status === 200 && answer.body.revoked_at == null) {
88+ const by = typeof answer.body.approved_by === "string" ? `, approved by ${answer.body.approved_by}` : "";
89+ lines.push(`${first!.replace(/\.$/, "")}${by}.`, ...rest);
90+ box.confirmed = true;
91+ if (by) box.approvedBy = answer.body.approved_by;
92+ } else {
93+ lines.push(`${originOf(server)} no longer accepts this box's sign-in (signed out or revoked). Run abso login.`);
94+ box.confirmed = false;
95+ }
96+ }
97+ const folder = folderOf(cwd, env);
98+ let here: Record<string, unknown> | null = null;
99+ if (folder?.config) {
100+ const c = folder.config;
101+ const credential = credentialWords(folder.root, c.server, env);
102+ lines.push(
103+ `This folder is agent ${c.agent} in project ${c.project} on ${originOf(c.server)}, with ${credential}${c.reader ? ", as a reader" : ""}.`,
104+ );
105+ here = { root: folder.root, project: c.project, agent: c.agent, server: c.server, credential };
106+ } else if (folder) {
107+ lines.push(`This folder's settings can't be read: ${folder.problem}`);
108+ here = { root: folder.root, problem: folder.problem };
109+ } else {
110+ lines.push("You're not in an abso folder. abso join <project> makes one.");
111+ }
112+ return { text: lines.join("\n"), json: { server: originOf(server), box, folder: here } };
113+}
115+export interface Check {
116+ readonly check: "node" | "server" | "box" | "folder";
117+ /** ok passes, fail needs the next step it gives, skip doesn't apply here. */
118+ readonly result: "ok" | "fail" | "skip";
119+ readonly text: string;
120+}
122+export async function doctor(
123+ server: string,
124+ cwd: string,
125+ env: Readonly<Record<string, string | undefined>>,
126+ probe: Probe,
127+): Promise<Check[]> {
128+ const checks: Check[] = [];
129+ const need = nodeNeeded(probe.built);
130+ const major = Number(probe.node.split(".")[0]);
131+ checks.push(
132+ major >= need
133+ ? { check: "node", result: "ok", text: `Node ${probe.node} (abso needs ${need} or later).` }
134+ : {
135+ check: "node",
136+ result: "fail",
137+ text: `Node ${probe.node} is too old: abso needs ${need} or later. Install a newer Node from nodejs.org.`,
138+ },
139+ );
141+ const folder = folderOf(cwd, env);
142+ // The folder's own server when there is one: it's the one its commands talk to.
143+ const target = folder?.config?.server ?? server;
144+ const origin = originOf(target);
145+ let reachable = false;
146+ const started = Date.now();
147+ try {
148+ const res = await timed(probe.fetcher, 10_000)(`${origin}/version`);
149+ const body = (await res.json().catch(() => ({}))) as { commit?: unknown };
150+ reachable = res.ok;
151+ checks.push(
152+ res.ok
153+ ? {
154+ check: "server",
155+ result: "ok",
156+ text: `${origin} answers${typeof body.commit === "string" ? ` (version ${body.commit.slice(0, 7)})` : ""} in ${Date.now() - started} ms.`,
157+ }
158+ : {
159+ check: "server",
160+ result: "fail",
161+ text: `${origin} answered ${res.status}. It may be down for a moment: try again shortly.`,
162+ },
163+ );
164+ } catch (err) {
165+ const why = err instanceof Error && err.name === "TimeoutError" ? "no answer within 10 s" : plainCause(err);
166+ checks.push({
167+ check: "server",
168+ result: "fail",
169+ text: `Can't reach ${origin}: ${why}. Check your connection${folder?.config ? ", and the server in .abso/config.json" : ""}.`,
170+ });
171+ }
173+ const record = readBox(target, probe.home);
174+ if (!record) {
175+ checks.push({
176+ check: "box",
177+ result: folder?.config ? "skip" : "fail",
178+ text: `This box isn't signed in to ${origin}. ${folder?.config ? "Only abso join needs it; abso login signs it in." : "Run abso login."}`,
179+ });
180+ } else if (record.expiresAt <= probe.now) {
181+ checks.push({
182+ check: "box",
183+ result: "fail",
184+ text: `This box's sign-in expired ${day(record.expiresAt)} UTC. Run abso login.`,
185+ });
186+ } else if (!reachable) {
187+ checks.push({
188+ check: "box",
189+ result: "skip",
190+ text: `Signed in as box ${record.id}; the server can't confirm it now.`,
191+ });
192+ } else {
193+ const answer = await serverBox(record, probe);
194+ checks.push(
195+ "unreachable" in answer
196+ ? { check: "box", result: "skip", text: `Signed in as box ${record.id}; the server can't confirm it now.` }
197+ : answer.status === 200 && answer.body.revoked_at == null
198+ ? {
199+ check: "box",
200+ result: "ok",
201+ text: `Signed in as box ${record.id}, which ${origin} accepts, until ${day(record.expiresAt)} UTC.`,
202+ }
203+ : {
204+ check: "box",
205+ result: "fail",
206+ text: `${origin} no longer accepts this box's sign-in (signed out or revoked). Run abso login.`,
207+ },
208+ );
209+ }
211+ if (!folder) {
212+ checks.push({
213+ check: "folder",
214+ result: "skip",
215+ text: "You're not in an abso folder. abso join <project> makes one.",
216+ });
217+ } else if (!folder.config) {
218+ checks.push({ check: "folder", result: "fail", text: `This folder's settings can't be read: ${folder.problem}` });
219+ } else {
220+ checks.push(await folderCheck(folder.root, folder.config, env, reachable, probe));
221+ }
222+ return checks;
223+}
225+/** The folder's key against its project: GET head, which the server answers only after it has checked the key. */
226+async function folderCheck(
227+ root: string,
228+ c: Config,
229+ env: Readonly<Record<string, string | undefined>>,
230+ reachable: boolean,
231+ probe: Probe,
232+): Promise<Check> {
233+ const who = `agent ${c.agent} in ${c.project}`;
234+ if (!c.token)
235+ return {
236+ check: "folder",
237+ result: "fail",
238+ text: `This folder (${who}) has no key, and there's no shared token. Run abso login, then abso join ${c.project}.`,
239+ };
240+ const credential = credentialWords(root, c.server, env);
241+ if (!reachable)
242+ return {
243+ check: "folder",
244+ result: "skip",
245+ text: `This folder is ${who}, with ${credential}; the server can't check it now.`,
246+ };
247+ let status: number;
248+ try {
249+ const res = await timed(probe.fetcher, 10_000)(
250+ `${c.server.replace(/\/+$/, "")}/p/${encodeURIComponent(c.project)}/head`,
251+ { headers: { authorization: `Bearer ${c.token}` } },
252+ );
253+ status = res.status;
254+ await res.body?.cancel();
255+ } catch {
256+ return {
257+ check: "folder",
258+ result: "skip",
259+ text: `This folder is ${who}, with ${credential}; the server can't check it now.`,
260+ };
261+ }
262+ if (status === 200)
263+ return {
264+ check: "folder",
265+ result: "ok",
266+ text: `This folder is ${who}, with ${credential}, which the server accepts.`,
267+ };
268+ if (status === 404)
269+ return {
270+ check: "folder",
271+ result: "fail",
272+ text: `${originOf(c.server)} has no project ${c.project}. Check the name in .abso/config.json, or abso init makes it.`,
273+ };
274+ if (status === 401 || status === 403)
275+ return {
276+ check: "folder",
277+ result: "fail",
278+ text: `${originOf(c.server)} didn't accept ${credential} for ${c.project}: it may be revoked or expired. Ask the project's owner, or run abso join ${c.project} again from a signed-in box.`,
279+ };
280+ return {
281+ check: "folder",
282+ result: "fail",
283+ text: `${originOf(c.server)} answered ${status} for ${c.project}. Try again shortly.`,
284+ };
285+}
287+export function doctorText(checks: readonly Check[]): string {
288+ return checks.map((c) => `${c.result.padEnd(4)} ${c.text}`).join("\n");
289+}
291+function plainCause(err: unknown): string {
292+ const cause = (err as { cause?: { code?: string; message?: string } }).cause;
293+ if (cause?.code === "ENOTFOUND" || cause?.code === "EAI_AGAIN") return "the address doesn't resolve";
294+ if (cause?.code === "ECONNREFUSED") return "the connection was refused";
295+ return cause?.message ?? (err instanceof Error ? err.message : String(err));
296+}
298+/**
299+ * The commonest failures in plain words, with the next step: no credential, a credential the server refuses, and a
300+ * server that can't be reached. Anything else is left as it was. `signedIn` is whether the call carried a key or token.
301+ */
302+export function plainError(err: unknown, signedIn: boolean): string | undefined {
303+ if (!(err instanceof ApiError)) return undefined;
304+ if (err.status === 401)
305+ return signedIn
306+ ? `The server didn't accept this folder's key: it may be revoked or expired. abso doctor checks it. (${err.message})`
307+ : "You're not signed in. Run abso login, then abso join <project>.";
308+ if (err.status === undefined && err.message.startsWith("could not reach ")) {
309+ const said = err.message.replace(/^could not reach /, "Can't reach ");
310+ // A message that already gives its next step (publish's "Run the same command again.") keeps it as the last word.
311+ return /\bRun\b[^.]*\.$/.test(said)
312+ ? said
313+ : `${said.replace(/\.$/, "")}. Check your connection; abso doctor checks the rest.`;
314+ }
315+ return undefined;
316+}
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -38,6 +38,7 @@
3838} from "./commands.ts";
3939import { configPath, findRoot, installKey, readConfig, readToken } from "./config.ts";
4040import { newsBlockLines, newsShown, TOKEN_SERVERS } from "./core.ts";
41+import { doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts";
4142import { runDraftSync, runLand, runSwitch } from "./drafts.ts";
4243import { runExport } from "./export.ts";
4344import { runBlame, runWhere, runWho, runWhy } from "./history.ts";
@@ -202,6 +203,27 @@
202203 return { text: boxText(record, server), json: { box: boxPublic(record) } };
203204 },
204205 },
206+ whoami: {
207+ flags: { server: "string" },
208+ usage: "abso whoami [--server <url>]",
209+ about:
210+ "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+ run: async (args, env) => {
212+ const out = await whoami(boxServer(args, env), env.cwd, env.env, realProbe());
213+ return { text: out.text, json: out.json };
214+ },
215+ },
216+ doctor: {
217+ flags: { server: "string" },
218+ usage: "abso doctor [--server <url>]",
219+ about:
220+ "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+ run: async (args, env) => {
222+ const checks = await doctor(boxServer(args, env), env.cwd, env.env, realProbe());
223+ const failed = checks.some((c) => c.result === "fail");
224+ return { text: doctorText(checks), json: { checks }, ...(failed ? { exit: EXIT.error } : {}) };
225+ },
226+ },
205227 logout: {
206228 flags: { server: "string" },
207229 usage: "abso logout [--server <url>]",
@@ -803,6 +825,16 @@
803825 return newsBlockLines(news.map((n) => newsShown(n)));
804826}
805827
828+/** Whether this folder's calls carry a key or token, for how a refusal is worded. False when that can't be told. */
829+function carriesCredential(env: Env): boolean {
830+ try {
831+ const root = findRoot(env.cwd);
832+ return root ? readConfig(root, env.env).token !== undefined : readToken(env.env) !== undefined;
833+ } catch {
834+ return false;
835+ }
836+}
806838export async function main(argv: readonly string[], env: Env): Promise<MainResult> {
807839 const command = argv[0];
808840 const json = argv.includes("--json") && command !== "run" && command !== "logs";
@@ -865,7 +897,10 @@
865897 const e = err as Error;
866898 const code = err instanceof UsageError ? "usage" : err instanceof ApiError ? "server" : "error";
867899 const message =
868− err instanceof UsageError || err instanceof ApiError ? e.message : `${e.message}${e.stack ? `\n${e.stack}` : ""}`;
900+ plainError(err, carriesCredential(env)) ??
901+ (err instanceof UsageError || err instanceof ApiError
902+ ? e.message
903+ : `${e.message}${e.stack ? `\n${e.stack}` : ""}`);
869904 // The server refusing (409) is like a collision: exit 2, not a failure.
870905 const exit = err instanceof ApiError && err.status === 409 ? EXIT.refused : EXIT.error;
871906 // News taken before the failure still shows.
--- a/client/src/mcp.ts
+++ b/client/src/mcp.ts
@@ -56,6 +56,8 @@
5656 "reply",
5757 "orgs",
5858 "org",
59+ "whoami",
60+ "doctor",
5961] as const;
6062
6163const PROTOCOLS = ["2025-06-18", "2025-03-26", "2024-11-05"];
--- a/client/test/client.test.ts
+++ b/client/test/client.test.ts
@@ -1098,7 +1098,10 @@
10981098 fake.dropRunStarts = 4;
10991099 const r = await main(["run", "node", "hi.js"], { cwd: folders.alice!, env: FAST, write: () => {} });
11001100 assert.equal(r.exit, 1);
1101− assert.match(r.stderr, /^abso run: could not reach .*\(tried 4 times\)\n$/);
1101+ assert.match(
1102+ r.stderr,
1103+ /^abso run: Can't reach .*\(tried 4 times\)\. Check your connection; abso doctor checks the rest\.\n$/,
1104+ );
11021105 assert.equal(fake.runStarts.slice(before).filter((t) => t.started).length, 0);
11031106 fake.dropRunStarts = 0;
11041107 });
@@ -2917,7 +2920,7 @@
29172920 assert.equal(status.exit, 1);
29182921 assert.match(
29192922 status.stderr,
2920− /could not reach http:\/\/127\.0\.0\.1:\d+: .*Tried twice, the second time IPv4 first; the connection never opened, so nothing reached the server\n$/,
2923+ /Can't reach http:\/\/127\.0\.0\.1:\d+: .*Tried twice, the second time IPv4 first; the connection never opened, so nothing reached the server\. Check your connection; abso doctor checks the rest\.\n$/,
29212924 );
29222925 const plain = await main(["publish", "-m", "x"], { cwd: folders.alice!, env: ENV, write: () => {} });
29232926 assert.match(plain.stderr, /nothing reached the server\. Nothing was published\. Run the same command again\.\n$/);
--- /dev/null
+++ b/client/test/doctor.test.ts
@@ -0,0 +1,229 @@
1+// abso whoami and abso doctor: each check's line, the next step when one fails, the server asked as the box and as
2+// the folder's key, and no credential in anything printed. plainError's wording of the commonest failures.
3+
4+import assert from "node:assert/strict";
5+import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
6+import { tmpdir } from "node:os";
7+import { join } from "node:path";
8+import { test } from "node:test";
9+import { ApiError } from "../src/api-error.ts";
10+import { writeBox } from "../src/box.ts";
11+import { doctor, doctorText, nodeNeeded, type Probe, plainError, whoami } from "../src/doctor.ts";
13+const SERVER = "https://staging.abso.example";
14+const CREDENTIAL = "abso_bx_the-secret-credential";
15+const KEY = "abso_sk_the-secret-key";
16+const NOW = Date.parse("2026-10-10T06:00:00.000Z");
17+const grant = { projects: [{ project: "game", role: "writer" }], max_agents: 3 };
18+const box = (expiresAt = Date.parse("2026-10-20T00:00:00.000Z")) => ({
19+ server: SERVER,
20+ id: "b_0123abcd",
21+ credential: CREDENTIAL,
22+ grant,
23+ expiresAt,
24+});
26+const temp = (name: string) => mkdtempSync(join(tmpdir(), `abso-doctor-${name}-`));
28+function folder(): string {
29+ const root = temp("folder");
30+ mkdirSync(join(root, ".abso"));
31+ writeFileSync(
32+ join(root, ".abso", "config.json"),
33+ JSON.stringify({ server: SERVER, project: "game", agent: "builder" }),
34+ );
35+ writeFileSync(join(root, ".abso", "key"), JSON.stringify({ server: SERVER, key: KEY, id: "k_00c0ffee" }));
36+ return root;
37+}
39+type Seen = { url: string; auth: string | null }[];
40+/** A server answering by path: /version, /box, /p/game/head. A missing path throws, like a refused connection. */
41+function server(answers: Record<string, [number, unknown]>, seen: Seen = []): typeof fetch {
42+ return (async (url, init) => {
43+ const u = new URL(String(url));
44+ seen.push({ url: u.pathname, auth: new Headers(init?.headers).get("authorization") });
45+ const answer = answers[u.pathname];
46+ if (!answer)
47+ throw Object.assign(new TypeError("fetch failed"), {
48+ cause: { code: "ECONNREFUSED", message: "connect ECONNREFUSED" },
49+ });
50+ return new Response(JSON.stringify(answer[1]), { status: answer[0] });
51+ }) as typeof fetch;
52+}
54+const probe = (fetcher: typeof fetch, home: string, node = "24.7.0", built = false): Probe => ({
55+ fetcher,
56+ now: NOW,
57+ node,
58+ built,
59+ home,
60+});
61+const accepted = { box_id: "b_0123abcd", revoked_at: null, approved_by: "christopher", grant };
63+test("the npm package needs Node 20; a checkout, which runs its .ts as is, needs 24", () => {
64+ assert.equal(nodeNeeded(true), 20);
65+ assert.equal(nodeNeeded(false), 24);
66+});
68+test("doctor outside a folder with no sign-in: the box check fails with abso login, the folder check doesn't apply", async () => {
69+ const checks = await doctor(
70+ SERVER,
71+ temp("outside"),
72+ {},
73+ probe(server({ "/version": [200, { commit: "ff7cd0e1" }] }), temp("home")),
74+ );
75+ assert.deepEqual(
76+ checks.map((c) => [c.check, c.result]),
77+ [
78+ ["node", "ok"],
79+ ["server", "ok"],
80+ ["box", "fail"],
81+ ["folder", "skip"],
82+ ],
83+ );
84+ assert.match(checks[1]!.text, /answers \(version ff7cd0e\)/);
85+ assert.match(checks[2]!.text, /isn't signed in to https:\/\/staging\.abso\.example\. Run abso login\./);
86+ assert.match(checks[3]!.text, /abso join <project> makes one/);
87+});
89+test("doctor in a folder, signed in: every check passes, the box and the key each go to their own check", async () => {
90+ const home = temp("home");
91+ writeBox(box(), home);
92+ const seen: Seen = [];
93+ const checks = await doctor(
94+ SERVER,
95+ folder(),
96+ {},
97+ probe(
98+ server({ "/version": [200, { commit: "ff7cd0e" }], "/box": [200, accepted], "/p/game/head": [200, {}] }, seen),
99+ home,
100+ ),
101+ );
102+ assert.deepEqual(
103+ checks.map((c) => c.result),
104+ ["ok", "ok", "ok", "ok"],
105+ );
106+ assert.match(checks[3]!.text, /agent builder in game, with the agent key k_00c0ffee, which the server accepts/);
107+ assert.deepEqual(seen, [
108+ { url: "/version", auth: null },
109+ { url: "/box", auth: `Box ${CREDENTIAL}` },
110+ { url: "/p/game/head", auth: `Bearer ${KEY}` },
111+ ]);
112+ const text = doctorText(checks);
113+ assert.ok(!text.includes(CREDENTIAL) && !text.includes(KEY));
114+ assert.match(text, /^ok {4}Node 24\.7\.0/);
115+});
117+test("doctor when the server can't be reached: says so with the next step, and the checks that need it don't apply", async () => {
118+ const home = temp("home");
119+ writeBox(box(), home);
120+ const checks = await doctor(SERVER, folder(), {}, probe(server({}), home));
121+ assert.deepEqual(
122+ checks.map((c) => c.result),
123+ ["ok", "fail", "skip", "skip"],
124+ );
125+ assert.match(
126+ checks[1]!.text,
127+ /Can't reach https:\/\/staging\.abso\.example: the connection was refused\. Check your connection, and the server in \.abso\/config\.json\./,
128+ );
129+});
131+test("doctor when the server refuses the box and the key: each fails with what to do", async () => {
132+ const home = temp("home");
133+ writeBox(box(), home);
134+ const checks = await doctor(
135+ SERVER,
136+ folder(),
137+ {},
138+ probe(
139+ server({
140+ "/version": [200, {}],
141+ "/box": [200, { ...accepted, revoked_at: NOW - 1000 }],
142+ "/p/game/head": [401, { error: "missing or wrong token" }],
143+ }),
144+ home,
145+ ),
146+ );
147+ assert.deepEqual(
148+ checks.map((c) => c.result),
149+ ["ok", "ok", "fail", "fail"],
150+ );
151+ assert.match(checks[2]!.text, /no longer accepts this box's sign-in \(signed out or revoked\)\. Run abso login\./);
152+ assert.match(checks[3]!.text, /didn't accept the agent key k_00c0ffee for game.*abso join game again/);
153+});
155+test("doctor: an expired sign-in and an old Node fail without asking the server about them", async () => {
156+ const home = temp("home");
157+ writeBox(box(NOW - 60_000), home);
158+ const seen: Seen = [];
159+ const checks = await doctor(
160+ SERVER,
161+ temp("outside"),
162+ {},
163+ probe(server({ "/version": [200, {}] }, seen), home, "20.11.0", false),
164+ );
165+ assert.equal(checks[0]!.result, "fail");
166+ assert.match(checks[0]!.text, /Node 20\.11\.0 is too old: abso needs 24 or later\./);
167+ assert.equal(checks[2]!.result, "fail");
168+ assert.match(checks[2]!.text, /expired 2026-10-10 05:59 UTC\. Run abso login\./);
169+ assert.deepEqual(
170+ seen.map((s) => s.url),
171+ ["/version"],
172+ );
173+});
175+test("whoami: the box as the server sees it, who approved it, and this folder's agent and key, never a credential", async () => {
176+ const home = temp("home");
177+ writeBox(box(), home);
178+ const out = await whoami(SERVER, folder(), {}, probe(server({ "/box": [200, accepted] }), home));
179+ assert.match(
180+ out.text,
181+ /^Signed in to https:\/\/staging\.abso\.example as box b_0123abcd, approved by christopher\.\n/,
182+ );
183+ assert.match(out.text, /Projects: game \(writer\)\. Up to 3 agents\./);
184+ assert.match(
185+ out.text,
186+ /This folder is agent builder in project game on https:\/\/staging\.abso\.example, with the agent key k_00c0ffee\./,
187+ );
188+ assert.ok(!JSON.stringify(out).includes(CREDENTIAL) && !JSON.stringify(out).includes(KEY));
189+ assert.equal((out.json.box as { confirmed: boolean }).confirmed, true);
190+});
192+test("whoami signed out, outside a folder: the next step for each", async () => {
193+ const out = await whoami(SERVER, temp("outside"), {}, probe(server({}), temp("home")));
194+ assert.equal(
195+ out.text,
196+ "This box isn't signed in to https://staging.abso.example. Run abso login.\nYou're not in an abso folder. abso join <project> makes one.",
197+ );
198+});
200+test("whoami when the server says the box is revoked", async () => {
201+ const home = temp("home");
202+ writeBox(box(), home);
203+ const out = await whoami(
204+ SERVER,
205+ temp("outside"),
206+ {},
207+ probe(server({ "/box": [401, { error: "missing or wrong token" }] }), home),
208+ );
209+ assert.match(out.text, /no longer accepts this box's sign-in \(signed out or revoked\)\. Run abso login\./);
210+});
212+test("plainError words a refusal by whether a credential went, and a server that can't be reached", () => {
213+ const refused = new ApiError("GET /status answered 401: missing or wrong token", 401);
214+ assert.equal(plainError(refused, false), "You're not signed in. Run abso login, then abso join <project>.");
215+ assert.match(plainError(refused, true)!, /^The server didn't accept this folder's key.*abso doctor checks it/);
216+ assert.equal(
217+ plainError(new ApiError("could not reach https://api.abso.dev: connect ECONNREFUSED"), true),
218+ "Can't reach https://api.abso.dev: connect ECONNREFUSED. Check your connection; abso doctor checks the rest.",
219+ );
220+ assert.equal(
221+ plainError(
222+ new ApiError("could not reach http://x: refused. Nothing was published. Run the same command again."),
223+ true,
224+ ),
225+ "Can't reach http://x: refused. Nothing was published. Run the same command again.",
226+ );
227+ assert.equal(plainError(new ApiError("GET /log answered 500: boom", 500), true), undefined);
228+ assert.equal(plainError(new Error("anything else"), true), undefined);
229+});