{"version":76,"agent":"speed","message":"abso whoami and abso doctor, and plainer errors.\n\n- 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.\n- 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.\n- Neither prints a credential. Both are MCP tools too.\n- 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.","time":1791611187590,"timeIso":"2026-10-10T05:46:27.590Z","changes":6,"change":880,"files":["client/src/command-env.ts","client/src/doctor.ts","client/src/main.ts","client/src/mcp.ts","client/test/client.test.ts","client/test/doctor.test.ts"],"draft":null,"diff":[{"path":"client/src/command-env.ts","added":1,"removed":1,"diff":"--- a/client/src/command-env.ts\n+++ b/client/src/command-env.ts\n@@ -35,7 +35,7 @@\n \tconst root = findRoot(env.cwd);\n \tif (root === undefined)\n \t\tthrow new UsageError(\n-\t\t\t`${env.cwd} is not in an abso folder (no .abso/config.json here or above); run abso init or abso join first`,\n+\t\t\t`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.`,\n \t\t);\n \tconst config = readConfig(root, env.env);\n \treturn { root, config, api: new Api(config) };"},{"path":"client/src/doctor.ts","added":316,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/doctor.ts\n@@ -0,0 +1,316 @@\n+// abso whoami and abso doctor: who and where this box and folder are signed in, and a check of each thing\n+// a command needs (Node, the server, the box's sign-in, the folder's key), one line each, with the next step\n+// when one fails. Neither prints a credential. plainError words the commonest failures the same way.\n+\n+import { ApiError } from \"./api-error.ts\";\n+import { type Answer, type BoxRecord, boxGet, boxText, originOf, readBox } from \"./box.ts\";\n+import { builtCopy } from \"./client-version.ts\";\n+import { type Config, credentialLabel, findRoot, readConfig } from \"./config.ts\";\n+\n+/** The lowest Node major each kind of copy runs on: the npm package is built for 20, a checkout runs its .ts as is. */\n+export function nodeNeeded(built: boolean): number {\n+\treturn built ? 20 : 24;\n+}\n+\n+/** What whoami and doctor read from outside: the network, the clock, Node's version and the home folder. Tests give their own. */\n+export interface Probe {\n+\treadonly fetcher: typeof fetch;\n+\treadonly now: number;\n+\treadonly node: string;\n+\treadonly built: boolean;\n+\treadonly home?: string;\n+}\n+\n+export function realProbe(): Probe {\n+\treturn { fetcher: fetch, now: Date.now(), node: process.versions.node, built: builtCopy() };\n+}\n+\n+/** This folder's settings, or why they can't be read; undefined outside a folder. */\n+function folderOf(\n+\tcwd: string,\n+\tenv: Readonly<Record<string, string | undefined>>,\n+): { root: string; config?: Config; problem?: string } | undefined {\n+\tconst root = findRoot(cwd);\n+\tif (root === undefined) return undefined;\n+\ttry {\n+\t\treturn { root, config: readConfig(root, env) };\n+\t} catch (err) {\n+\t\treturn { root, problem: err instanceof Error ? err.message : String(err) };\n+\t}\n+}\n+\n+const day = (ms: number) => new Date(ms).toISOString().slice(0, 16).replace(\"T\", \" \");\n+\n+/** The server's view of this box: GET /box, as the box. */\n+async function serverBox(record: BoxRecord, probe: Probe): Promise<Answer | { unreachable: string }> {\n+\ttry {\n+\t\treturn await boxGet(record, \"/box\", timed(probe.fetcher, 10_000));\n+\t} catch (err) {\n+\t\treturn { unreachable: err instanceof Error ? err.message : String(err) };\n+\t}\n+}\n+\n+/** fetch with its own, shorter limit: a check that hangs says so rather than waiting out the command's. */\n+function timed(fetcher: typeof fetch, ms: number): typeof fetch {\n+\treturn ((input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) =>\n+\t\tfetcher(input, { ...init, signal: AbortSignal.timeout(ms) })) as typeof fetch;\n+}\n+\n+function credentialWords(root: string, server: string, env: Readonly<Record<string, string | undefined>>): string {\n+\tconst c = credentialLabel(root, server, env);\n+\treturn c.kind === \"agent key\" ? `the agent key ${c.id}` : c.kind === \"shared token\" ? \"the shared token\" : \"no key\";\n+}\n+\n+export async function whoami(\n+\tserver: string,\n+\tcwd: string,\n+\tenv: Readonly<Record<string, string | undefined>>,\n+\tprobe: Probe,\n+): Promise<{ text: string; json: Record<string, unknown> }> {\n+\tconst lines: string[] = [];\n+\tconst record = readBox(server, probe.home);\n+\tlet box: Record<string, unknown> | null = null;\n+\tif (!record) {\n+\t\tlines.push(`This box isn't signed in to ${originOf(server)}. Run abso login.`);\n+\t} else {\n+\t\tconst answer = await serverBox(record, probe);\n+\t\tconst [first, ...rest] = boxText(record, server, probe.now).split(\"\\n\");\n+\t\tbox = {\n+\t\t\tserver: record.server,\n+\t\t\tid: record.id,\n+\t\t\tgrant: record.grant,\n+\t\t\texpiresAt: new Date(record.expiresAt).toISOString(),\n+\t\t};\n+\t\tif (\"unreachable\" in answer) {\n+\t\t\tlines.push(first!, ...rest, `${originOf(server)} couldn't be reached to confirm it: ${answer.unreachable}`);\n+\t\t\tbox.confirmed = null;\n+\t\t} else if (answer.status === 200 && answer.body.revoked_at == null) {\n+\t\t\tconst by = typeof answer.body.approved_by === \"string\" ? `, approved by ${answer.body.approved_by}` : \"\";\n+\t\t\tlines.push(`${first!.replace(/\\.$/, \"\")}${by}.`, ...rest);\n+\t\t\tbox.confirmed = true;\n+\t\t\tif (by) box.approvedBy = answer.body.approved_by;\n+\t\t} else {\n+\t\t\tlines.push(`${originOf(server)} no longer accepts this box's sign-in (signed out or revoked). Run abso login.`);\n+\t\t\tbox.confirmed = false;\n+\t\t}\n+\t}\n+\tconst folder = folderOf(cwd, env);\n+\tlet here: Record<string, unknown> | null = null;\n+\tif (folder?.config) {\n+\t\tconst c = folder.config;\n+\t\tconst credential = credentialWords(folder.root, c.server, env);\n+\t\tlines.push(\n+\t\t\t`This folder is agent ${c.agent} in project ${c.project} on ${originOf(c.server)}, with ${credential}${c.reader ? \", as a reader\" : \"\"}.`,\n+\t\t);\n+\t\there = { root: folder.root, project: c.project, agent: c.agent, server: c.server, credential };\n+\t} else if (folder) {\n+\t\tlines.push(`This folder's settings can't be read: ${folder.problem}`);\n+\t\there = { root: folder.root, problem: folder.problem };\n+\t} else {\n+\t\tlines.push(\"You're not in an abso folder. abso join <project> makes one.\");\n+\t}\n+\treturn { text: lines.join(\"\\n\"), json: { server: originOf(server), box, folder: here } };\n+}\n+\n+export interface Check {\n+\treadonly check: \"node\" | \"server\" | \"box\" | \"folder\";\n+\t/** ok passes, fail needs the next step it gives, skip doesn't apply here. */\n+\treadonly result: \"ok\" | \"fail\" | \"skip\";\n+\treadonly text: string;\n+}\n+\n+export async function doctor(\n+\tserver: string,\n+\tcwd: string,\n+\tenv: Readonly<Record<string, string | undefined>>,\n+\tprobe: Probe,\n+): Promise<Check[]> {\n+\tconst checks: Check[] = [];\n+\tconst need = nodeNeeded(probe.built);\n+\tconst major = Number(probe.node.split(\".\")[0]);\n+\tchecks.push(\n+\t\tmajor >= need\n+\t\t\t? { check: \"node\", result: \"ok\", text: `Node ${probe.node} (abso needs ${need} or later).` }\n+\t\t\t: {\n+\t\t\t\t\tcheck: \"node\",\n+\t\t\t\t\tresult: \"fail\",\n+\t\t\t\t\ttext: `Node ${probe.node} is too old: abso needs ${need} or later. Install a newer Node from nodejs.org.`,\n+\t\t\t\t},\n+\t);\n+\n+\tconst folder = folderOf(cwd, env);\n+\t// The folder's own server when there is one: it's the one its commands talk to.\n+\tconst target = folder?.config?.server ?? server;\n+\tconst origin = originOf(target);\n+\tlet reachable = false;\n+\tconst started = Date.now();\n+\ttry {\n+\t\tconst res = await timed(probe.fetcher, 10_000)(`${origin}/version`);\n+\t\tconst body = (await res.json().catch(() => ({}))) as { commit?: unknown };\n+\t\treachable = res.ok;\n+\t\tchecks.push(\n+\t\t\tres.ok\n+\t\t\t\t? {\n+\t\t\t\t\t\tcheck: \"server\",\n+\t\t\t\t\t\tresult: \"ok\",\n+\t\t\t\t\t\ttext: `${origin} answers${typeof body.commit === \"string\" ? ` (version ${body.commit.slice(0, 7)})` : \"\"} in ${Date.now() - started} ms.`,\n+\t\t\t\t\t}\n+\t\t\t\t: {\n+\t\t\t\t\t\tcheck: \"server\",\n+\t\t\t\t\t\tresult: \"fail\",\n+\t\t\t\t\t\ttext: `${origin} answered ${res.status}. It may be down for a moment: try again shortly.`,\n+\t\t\t\t\t},\n+\t\t);\n+\t} catch (err) {\n+\t\tconst why = err instanceof Error && err.name === \"TimeoutError\" ? \"no answer within 10 s\" : plainCause(err);\n+\t\tchecks.push({\n+\t\t\tcheck: \"server\",\n+\t\t\tresult: \"fail\",\n+\t\t\ttext: `Can't reach ${origin}: ${why}. Check your connection${folder?.config ? \", and the server in .abso/config.json\" : \"\"}.`,\n+\t\t});\n+\t}\n+\n+\tconst record = readBox(target, probe.home);\n+\tif (!record) {\n+\t\tchecks.push({\n+\t\t\tcheck: \"box\",\n+\t\t\tresult: folder?.config ? \"skip\" : \"fail\",\n+\t\t\ttext: `This box isn't signed in to ${origin}. ${folder?.config ? \"Only abso join needs it; abso login signs it in.\" : \"Run abso login.\"}`,\n+\t\t});\n+\t} else if (record.expiresAt <= probe.now) {\n+\t\tchecks.push({\n+\t\t\tcheck: \"box\",\n+\t\t\tresult: \"fail\",\n+\t\t\ttext: `This box's sign-in expired ${day(record.expiresAt)} UTC. Run abso login.`,\n+\t\t});\n+\t} else if (!reachable) {\n+\t\tchecks.push({\n+\t\t\tcheck: \"box\",\n+\t\t\tresult: \"skip\",\n+\t\t\ttext: `Signed in as box ${record.id}; the server can't confirm it now.`,\n+\t\t});\n+\t} else {\n+\t\tconst answer = await serverBox(record, probe);\n+\t\tchecks.push(\n+\t\t\t\"unreachable\" in answer\n+\t\t\t\t? { check: \"box\", result: \"skip\", text: `Signed in as box ${record.id}; the server can't confirm it now.` }\n+\t\t\t\t: answer.status === 200 && answer.body.revoked_at == null\n+\t\t\t\t\t? {\n+\t\t\t\t\t\t\tcheck: \"box\",\n+\t\t\t\t\t\t\tresult: \"ok\",\n+\t\t\t\t\t\t\ttext: `Signed in as box ${record.id}, which ${origin} accepts, until ${day(record.expiresAt)} UTC.`,\n+\t\t\t\t\t\t}\n+\t\t\t\t\t: {\n+\t\t\t\t\t\t\tcheck: \"box\",\n+\t\t\t\t\t\t\tresult: \"fail\",\n+\t\t\t\t\t\t\ttext: `${origin} no longer accepts this box's sign-in (signed out or revoked). Run abso login.`,\n+\t\t\t\t\t\t},\n+\t\t);\n+\t}\n+\n+\tif (!folder) {\n+\t\tchecks.push({\n+\t\t\tcheck: \"folder\",\n+\t\t\tresult: \"skip\",\n+\t\t\ttext: \"You're not in an abso folder. abso join <project> makes one.\",\n+\t\t});\n+\t} else if (!folder.config) {\n+\t\tchecks.push({ check: \"folder\", result: \"fail\", text: `This folder's settings can't be read: ${folder.problem}` });\n+\t} else {\n+\t\tchecks.push(await folderCheck(folder.root, folder.config, env, reachable, probe));\n+\t}\n+\treturn checks;\n+}\n+\n+/** The folder's key against its project: GET head, which the server answers only after it has checked the key. */\n+async function folderCheck(\n+\troot: string,\n+\tc: Config,\n+\tenv: Readonly<Record<string, string | undefined>>,\n+\treachable: boolean,\n+\tprobe: Probe,\n+): Promise<Check> {\n+\tconst who = `agent ${c.agent} in ${c.project}`;\n+\tif (!c.token)\n+\t\treturn {\n+\t\t\tcheck: \"folder\",\n+\t\t\tresult: \"fail\",\n+\t\t\ttext: `This folder (${who}) has no key, and there's no shared token. Run abso login, then abso join ${c.project}.`,\n+\t\t};\n+\tconst credential = credentialWords(root, c.server, env);\n+\tif (!reachable)\n+\t\treturn {\n+\t\t\tcheck: \"folder\",\n+\t\t\tresult: \"skip\",\n+\t\t\ttext: `This folder is ${who}, with ${credential}; the server can't check it now.`,\n+\t\t};\n+\tlet status: number;\n+\ttry {\n+\t\tconst res = await timed(probe.fetcher, 10_000)(\n+\t\t\t`${c.server.replace(/\\/+$/, \"\")}/p/${encodeURIComponent(c.project)}/head`,\n+\t\t\t{ headers: { authorization: `Bearer ${c.token}` } },\n+\t\t);\n+\t\tstatus = res.status;\n+\t\tawait res.body?.cancel();\n+\t} catch {\n+\t\treturn {\n+\t\t\tcheck: \"folder\",\n+\t\t\tresult: \"skip\",\n+\t\t\ttext: `This folder is ${who}, with ${credential}; the server can't check it now.`,\n+\t\t};\n+\t}\n+\tif (status === 200)\n+\t\treturn {\n+\t\t\tcheck: \"folder\",\n+\t\t\tresult: \"ok\",\n+\t\t\ttext: `This folder is ${who}, with ${credential}, which the server accepts.`,\n+\t\t};\n+\tif (status === 404)\n+\t\treturn {\n+\t\t\tcheck: \"folder\",\n+\t\t\tresult: \"fail\",\n+\t\t\ttext: `${originOf(c.server)} has no project ${c.project}. Check the name in .abso/config.json, or abso init makes it.`,\n+\t\t};\n+\tif (status === 401 || status === 403)\n+\t\treturn {\n+\t\t\tcheck: \"folder\",\n+\t\t\tresult: \"fail\",\n+\t\t\ttext: `${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.`,\n+\t\t};\n+\treturn {\n+\t\tcheck: \"folder\",\n+\t\tresult: \"fail\",\n+\t\ttext: `${originOf(c.server)} answered ${status} for ${c.project}. Try again shortly.`,\n+\t};\n+}\n+\n+export function doctorText(checks: readonly Check[]): string {\n+\treturn checks.map((c) => `${c.result.padEnd(4)}  ${c.text}`).join(\"\\n\");\n+}\n+\n+function plainCause(err: unknown): string {\n+\tconst cause = (err as { cause?: { code?: string; message?: string } }).cause;\n+\tif (cause?.code === \"ENOTFOUND\" || cause?.code === \"EAI_AGAIN\") return \"the address doesn't resolve\";\n+\tif (cause?.code === \"ECONNREFUSED\") return \"the connection was refused\";\n+\treturn cause?.message ?? (err instanceof Error ? err.message : String(err));\n+}\n+\n+/**\n+ * The commonest failures in plain words, with the next step: no credential, a credential the server refuses, and a\n+ * server that can't be reached. Anything else is left as it was. `signedIn` is whether the call carried a key or token.\n+ */\n+export function plainError(err: unknown, signedIn: boolean): string | undefined {\n+\tif (!(err instanceof ApiError)) return undefined;\n+\tif (err.status === 401)\n+\t\treturn signedIn\n+\t\t\t? `The server didn't accept this folder's key: it may be revoked or expired. abso doctor checks it. (${err.message})`\n+\t\t\t: \"You're not signed in. Run abso login, then abso join <project>.\";\n+\tif (err.status === undefined && err.message.startsWith(\"could not reach \")) {\n+\t\tconst said = err.message.replace(/^could not reach /, \"Can't reach \");\n+\t\t// A message that already gives its next step (publish's \"Run the same command again.\") keeps it as the last word.\n+\t\treturn /\\bRun\\b[^.]*\\.$/.test(said)\n+\t\t\t? said\n+\t\t\t: `${said.replace(/\\.$/, \"\")}. Check your connection; abso doctor checks the rest.`;\n+\t}\n+\treturn undefined;\n+}"},{"path":"client/src/main.ts","added":36,"removed":1,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -38,6 +38,7 @@\n } from \"./commands.ts\";\n import { configPath, findRoot, installKey, readConfig, readToken } from \"./config.ts\";\n import { newsBlockLines, newsShown, TOKEN_SERVERS } from \"./core.ts\";\n+import { doctor, doctorText, plainError, realProbe, whoami } from \"./doctor.ts\";\n import { runDraftSync, runLand, runSwitch } from \"./drafts.ts\";\n import { runExport } from \"./export.ts\";\n import { runBlame, runWhere, runWho, runWhy } from \"./history.ts\";\n@@ -202,6 +203,27 @@\n \t\t\treturn { text: boxText(record, server), json: { box: boxPublic(record) } };\n \t\t},\n \t},\n+\twhoami: {\n+\t\tflags: { server: \"string\" },\n+\t\tusage: \"abso whoami [--server <url>]\",\n+\t\tabout:\n+\t\t\t\"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.\",\n+\t\trun: async (args, env) => {\n+\t\t\tconst out = await whoami(boxServer(args, env), env.cwd, env.env, realProbe());\n+\t\t\treturn { text: out.text, json: out.json };\n+\t\t},\n+\t},\n+\tdoctor: {\n+\t\tflags: { server: \"string\" },\n+\t\tusage: \"abso doctor [--server <url>]\",\n+\t\tabout:\n+\t\t\t\"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.\",\n+\t\trun: async (args, env) => {\n+\t\t\tconst checks = await doctor(boxServer(args, env), env.cwd, env.env, realProbe());\n+\t\t\tconst failed = checks.some((c) => c.result === \"fail\");\n+\t\t\treturn { text: doctorText(checks), json: { checks }, ...(failed ? { exit: EXIT.error } : {}) };\n+\t\t},\n+\t},\n \tlogout: {\n \t\tflags: { server: \"string\" },\n \t\tusage: \"abso logout [--server <url>]\",\n@@ -803,6 +825,16 @@\n \treturn newsBlockLines(news.map((n) => newsShown(n)));\n }\n \n+/** Whether this folder's calls carry a key or token, for how a refusal is worded. False when that can't be told. */\n+function carriesCredential(env: Env): boolean {\n+\ttry {\n+\t\tconst root = findRoot(env.cwd);\n+\t\treturn root ? readConfig(root, env.env).token !== undefined : readToken(env.env) !== undefined;\n+\t} catch {\n+\t\treturn false;\n+\t}\n+}\n+\n export async function main(argv: readonly string[], env: Env): Promise<MainResult> {\n \tconst command = argv[0];\n \tconst json = argv.includes(\"--json\") && command !== \"run\" && command !== \"logs\";\n@@ -865,7 +897,10 @@\n \t\tconst e = err as Error;\n \t\tconst code = err instanceof UsageError ? \"usage\" : err instanceof ApiError ? \"server\" : \"error\";\n \t\tconst message =\n-\t\t\terr instanceof UsageError || err instanceof ApiError ? e.message : `${e.message}${e.stack ? `\\n${e.stack}` : \"\"}`;\n+\t\t\tplainError(err, carriesCredential(env)) ??\n+\t\t\t(err instanceof UsageError || err instanceof ApiError\n+\t\t\t\t? e.message\n+\t\t\t\t: `${e.message}${e.stack ? `\\n${e.stack}` : \"\"}`);\n \t\t// The server refusing (409) is like a collision: exit 2, not a failure.\n \t\tconst exit = err instanceof ApiError && err.status === 409 ? EXIT.refused : EXIT.error;\n \t\t// News taken before the failure still shows."},{"path":"client/src/mcp.ts","added":2,"removed":0,"diff":"--- a/client/src/mcp.ts\n+++ b/client/src/mcp.ts\n@@ -56,6 +56,8 @@\n \t\"reply\",\n \t\"orgs\",\n \t\"org\",\n+\t\"whoami\",\n+\t\"doctor\",\n ] as const;\n \n const PROTOCOLS = [\"2025-06-18\", \"2025-03-26\", \"2024-11-05\"];"},{"path":"client/test/client.test.ts","added":5,"removed":2,"diff":"--- a/client/test/client.test.ts\n+++ b/client/test/client.test.ts\n@@ -1098,7 +1098,10 @@\n \t\tfake.dropRunStarts = 4;\n \t\tconst r = await main([\"run\", \"node\", \"hi.js\"], { cwd: folders.alice!, env: FAST, write: () => {} });\n \t\tassert.equal(r.exit, 1);\n-\t\tassert.match(r.stderr, /^abso run: could not reach .*\\(tried 4 times\\)\\n$/);\n+\t\tassert.match(\n+\t\t\tr.stderr,\n+\t\t\t/^abso run: Can't reach .*\\(tried 4 times\\)\\. Check your connection; abso doctor checks the rest\\.\\n$/,\n+\t\t);\n \t\tassert.equal(fake.runStarts.slice(before).filter((t) => t.started).length, 0);\n \t\tfake.dropRunStarts = 0;\n \t});\n@@ -2917,7 +2920,7 @@\n \t\tassert.equal(status.exit, 1);\n \t\tassert.match(\n \t\t\tstatus.stderr,\n-\t\t\t/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$/,\n+\t\t\t/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$/,\n \t\t);\n \t\tconst plain = await main([\"publish\", \"-m\", \"x\"], { cwd: folders.alice!, env: ENV, write: () => {} });\n \t\tassert.match(plain.stderr, /nothing reached the server\\. Nothing was published\\. Run the same command again\\.\\n$/);"},{"path":"client/test/doctor.test.ts","added":229,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/doctor.test.ts\n@@ -0,0 +1,229 @@\n+// abso whoami and abso doctor: each check's line, the next step when one fails, the server asked as the box and as\n+// the folder's key, and no credential in anything printed. plainError's wording of the commonest failures.\n+\n+import assert from \"node:assert/strict\";\n+import { mkdirSync, mkdtempSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { test } from \"node:test\";\n+import { ApiError } from \"../src/api-error.ts\";\n+import { writeBox } from \"../src/box.ts\";\n+import { doctor, doctorText, nodeNeeded, type Probe, plainError, whoami } from \"../src/doctor.ts\";\n+\n+const SERVER = \"https://staging.abso.example\";\n+const CREDENTIAL = \"abso_bx_the-secret-credential\";\n+const KEY = \"abso_sk_the-secret-key\";\n+const NOW = Date.parse(\"2026-10-10T06:00:00.000Z\");\n+const grant = { projects: [{ project: \"game\", role: \"writer\" }], max_agents: 3 };\n+const box = (expiresAt = Date.parse(\"2026-10-20T00:00:00.000Z\")) => ({\n+\tserver: SERVER,\n+\tid: \"b_0123abcd\",\n+\tcredential: CREDENTIAL,\n+\tgrant,\n+\texpiresAt,\n+});\n+\n+const temp = (name: string) => mkdtempSync(join(tmpdir(), `abso-doctor-${name}-`));\n+\n+function folder(): string {\n+\tconst root = temp(\"folder\");\n+\tmkdirSync(join(root, \".abso\"));\n+\twriteFileSync(\n+\t\tjoin(root, \".abso\", \"config.json\"),\n+\t\tJSON.stringify({ server: SERVER, project: \"game\", agent: \"builder\" }),\n+\t);\n+\twriteFileSync(join(root, \".abso\", \"key\"), JSON.stringify({ server: SERVER, key: KEY, id: \"k_00c0ffee\" }));\n+\treturn root;\n+}\n+\n+type Seen = { url: string; auth: string | null }[];\n+/** A server answering by path: /version, /box, /p/game/head. A missing path throws, like a refused connection. */\n+function server(answers: Record<string, [number, unknown]>, seen: Seen = []): typeof fetch {\n+\treturn (async (url, init) => {\n+\t\tconst u = new URL(String(url));\n+\t\tseen.push({ url: u.pathname, auth: new Headers(init?.headers).get(\"authorization\") });\n+\t\tconst answer = answers[u.pathname];\n+\t\tif (!answer)\n+\t\t\tthrow Object.assign(new TypeError(\"fetch failed\"), {\n+\t\t\t\tcause: { code: \"ECONNREFUSED\", message: \"connect ECONNREFUSED\" },\n+\t\t\t});\n+\t\treturn new Response(JSON.stringify(answer[1]), { status: answer[0] });\n+\t}) as typeof fetch;\n+}\n+\n+const probe = (fetcher: typeof fetch, home: string, node = \"24.7.0\", built = false): Probe => ({\n+\tfetcher,\n+\tnow: NOW,\n+\tnode,\n+\tbuilt,\n+\thome,\n+});\n+const accepted = { box_id: \"b_0123abcd\", revoked_at: null, approved_by: \"christopher\", grant };\n+\n+test(\"the npm package needs Node 20; a checkout, which runs its .ts as is, needs 24\", () => {\n+\tassert.equal(nodeNeeded(true), 20);\n+\tassert.equal(nodeNeeded(false), 24);\n+});\n+\n+test(\"doctor outside a folder with no sign-in: the box check fails with abso login, the folder check doesn't apply\", async () => {\n+\tconst checks = await doctor(\n+\t\tSERVER,\n+\t\ttemp(\"outside\"),\n+\t\t{},\n+\t\tprobe(server({ \"/version\": [200, { commit: \"ff7cd0e1\" }] }), temp(\"home\")),\n+\t);\n+\tassert.deepEqual(\n+\t\tchecks.map((c) => [c.check, c.result]),\n+\t\t[\n+\t\t\t[\"node\", \"ok\"],\n+\t\t\t[\"server\", \"ok\"],\n+\t\t\t[\"box\", \"fail\"],\n+\t\t\t[\"folder\", \"skip\"],\n+\t\t],\n+\t);\n+\tassert.match(checks[1]!.text, /answers \\(version ff7cd0e\\)/);\n+\tassert.match(checks[2]!.text, /isn't signed in to https:\\/\\/staging\\.abso\\.example\\. Run abso login\\./);\n+\tassert.match(checks[3]!.text, /abso join <project> makes one/);\n+});\n+\n+test(\"doctor in a folder, signed in: every check passes, the box and the key each go to their own check\", async () => {\n+\tconst home = temp(\"home\");\n+\twriteBox(box(), home);\n+\tconst seen: Seen = [];\n+\tconst checks = await doctor(\n+\t\tSERVER,\n+\t\tfolder(),\n+\t\t{},\n+\t\tprobe(\n+\t\t\tserver({ \"/version\": [200, { commit: \"ff7cd0e\" }], \"/box\": [200, accepted], \"/p/game/head\": [200, {}] }, seen),\n+\t\t\thome,\n+\t\t),\n+\t);\n+\tassert.deepEqual(\n+\t\tchecks.map((c) => c.result),\n+\t\t[\"ok\", \"ok\", \"ok\", \"ok\"],\n+\t);\n+\tassert.match(checks[3]!.text, /agent builder in game, with the agent key k_00c0ffee, which the server accepts/);\n+\tassert.deepEqual(seen, [\n+\t\t{ url: \"/version\", auth: null },\n+\t\t{ url: \"/box\", auth: `Box ${CREDENTIAL}` },\n+\t\t{ url: \"/p/game/head\", auth: `Bearer ${KEY}` },\n+\t]);\n+\tconst text = doctorText(checks);\n+\tassert.ok(!text.includes(CREDENTIAL) && !text.includes(KEY));\n+\tassert.match(text, /^ok {4}Node 24\\.7\\.0/);\n+});\n+\n+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 () => {\n+\tconst home = temp(\"home\");\n+\twriteBox(box(), home);\n+\tconst checks = await doctor(SERVER, folder(), {}, probe(server({}), home));\n+\tassert.deepEqual(\n+\t\tchecks.map((c) => c.result),\n+\t\t[\"ok\", \"fail\", \"skip\", \"skip\"],\n+\t);\n+\tassert.match(\n+\t\tchecks[1]!.text,\n+\t\t/Can't reach https:\\/\\/staging\\.abso\\.example: the connection was refused\\. Check your connection, and the server in \\.abso\\/config\\.json\\./,\n+\t);\n+});\n+\n+test(\"doctor when the server refuses the box and the key: each fails with what to do\", async () => {\n+\tconst home = temp(\"home\");\n+\twriteBox(box(), home);\n+\tconst checks = await doctor(\n+\t\tSERVER,\n+\t\tfolder(),\n+\t\t{},\n+\t\tprobe(\n+\t\t\tserver({\n+\t\t\t\t\"/version\": [200, {}],\n+\t\t\t\t\"/box\": [200, { ...accepted, revoked_at: NOW - 1000 }],\n+\t\t\t\t\"/p/game/head\": [401, { error: \"missing or wrong token\" }],\n+\t\t\t}),\n+\t\t\thome,\n+\t\t),\n+\t);\n+\tassert.deepEqual(\n+\t\tchecks.map((c) => c.result),\n+\t\t[\"ok\", \"ok\", \"fail\", \"fail\"],\n+\t);\n+\tassert.match(checks[2]!.text, /no longer accepts this box's sign-in \\(signed out or revoked\\)\\. Run abso login\\./);\n+\tassert.match(checks[3]!.text, /didn't accept the agent key k_00c0ffee for game.*abso join game again/);\n+});\n+\n+test(\"doctor: an expired sign-in and an old Node fail without asking the server about them\", async () => {\n+\tconst home = temp(\"home\");\n+\twriteBox(box(NOW - 60_000), home);\n+\tconst seen: Seen = [];\n+\tconst checks = await doctor(\n+\t\tSERVER,\n+\t\ttemp(\"outside\"),\n+\t\t{},\n+\t\tprobe(server({ \"/version\": [200, {}] }, seen), home, \"20.11.0\", false),\n+\t);\n+\tassert.equal(checks[0]!.result, \"fail\");\n+\tassert.match(checks[0]!.text, /Node 20\\.11\\.0 is too old: abso needs 24 or later\\./);\n+\tassert.equal(checks[2]!.result, \"fail\");\n+\tassert.match(checks[2]!.text, /expired 2026-10-10 05:59 UTC\\. Run abso login\\./);\n+\tassert.deepEqual(\n+\t\tseen.map((s) => s.url),\n+\t\t[\"/version\"],\n+\t);\n+});\n+\n+test(\"whoami: the box as the server sees it, who approved it, and this folder's agent and key, never a credential\", async () => {\n+\tconst home = temp(\"home\");\n+\twriteBox(box(), home);\n+\tconst out = await whoami(SERVER, folder(), {}, probe(server({ \"/box\": [200, accepted] }), home));\n+\tassert.match(\n+\t\tout.text,\n+\t\t/^Signed in to https:\\/\\/staging\\.abso\\.example as box b_0123abcd, approved by christopher\\.\\n/,\n+\t);\n+\tassert.match(out.text, /Projects: game \\(writer\\)\\. Up to 3 agents\\./);\n+\tassert.match(\n+\t\tout.text,\n+\t\t/This folder is agent builder in project game on https:\\/\\/staging\\.abso\\.example, with the agent key k_00c0ffee\\./,\n+\t);\n+\tassert.ok(!JSON.stringify(out).includes(CREDENTIAL) && !JSON.stringify(out).includes(KEY));\n+\tassert.equal((out.json.box as { confirmed: boolean }).confirmed, true);\n+});\n+\n+test(\"whoami signed out, outside a folder: the next step for each\", async () => {\n+\tconst out = await whoami(SERVER, temp(\"outside\"), {}, probe(server({}), temp(\"home\")));\n+\tassert.equal(\n+\t\tout.text,\n+\t\t\"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.\",\n+\t);\n+});\n+\n+test(\"whoami when the server says the box is revoked\", async () => {\n+\tconst home = temp(\"home\");\n+\twriteBox(box(), home);\n+\tconst out = await whoami(\n+\t\tSERVER,\n+\t\ttemp(\"outside\"),\n+\t\t{},\n+\t\tprobe(server({ \"/box\": [401, { error: \"missing or wrong token\" }] }), home),\n+\t);\n+\tassert.match(out.text, /no longer accepts this box's sign-in \\(signed out or revoked\\)\\. Run abso login\\./);\n+});\n+\n+test(\"plainError words a refusal by whether a credential went, and a server that can't be reached\", () => {\n+\tconst refused = new ApiError(\"GET /status answered 401: missing or wrong token\", 401);\n+\tassert.equal(plainError(refused, false), \"You're not signed in. Run abso login, then abso join <project>.\");\n+\tassert.match(plainError(refused, true)!, /^The server didn't accept this folder's key.*abso doctor checks it/);\n+\tassert.equal(\n+\t\tplainError(new ApiError(\"could not reach https://api.abso.dev: connect ECONNREFUSED\"), true),\n+\t\t\"Can't reach https://api.abso.dev: connect ECONNREFUSED. Check your connection; abso doctor checks the rest.\",\n+\t);\n+\tassert.equal(\n+\t\tplainError(\n+\t\t\tnew ApiError(\"could not reach http://x: refused. Nothing was published. Run the same command again.\"),\n+\t\t\ttrue,\n+\t\t),\n+\t\t\"Can't reach http://x: refused. Nothing was published. Run the same command again.\",\n+\t);\n+\tassert.equal(plainError(new ApiError(\"GET /log answered 500: boom\", 500), true), undefined);\n+\tassert.equal(plainError(new Error(\"anything else\"), true), undefined);\n+});"}],"ci":null}