Versions 2 to 318
new file, 346 lines
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+
6+import { type Answer, type BoxRecord, boxGet, boxText, originOf, readBox, signedInServers } from "./box.ts";
10+
12+ * The lowest Node major each kind of copy runs on: a built one (the npm package, or a checkout's client/bin/abso.mjs)
13+ * is built for 20; a checkout's client/abso.ts runs its .ts as is, which takes Node's type stripping.
18+
19+/** What whoami and doctor read from outside: the network, the clock, Node's version and the home folder. Tests give their own. */
27+
29+ // Bundled, this module is client/bin/abso.mjs (or the npm package's file); from client/abso.ts, it is this .ts.
37+
51+
53+ * The servers other than `server` this box is signed in to, as one sentence for a refusal or a report to end
56+export function elsewhereText(server: string, command: string, home?: string, now = Date.now()): string {
59+ return ` This box is signed in to ${others.join(" and ")}: ${command} --server <url> uses ${others.length === 1 ? "it" : "one"}.`;
61+
63+
65+async function serverBox(record: BoxRecord, probe: Probe): Promise<Answer | { unreachable: string }> {
72+
73+/** fetch with its own, shorter limit: a check that hangs says so rather than waiting out the command's. */
78+
79+function credentialWords(root: string, server: string, env: Readonly<Record<string, string | undefined>>): string {
91+
103+ `This box isn't signed in to ${originOf(server)}. Run abso login.${elsewhereText(server, "abso whoami", probe.home, probe.now)}`,
115+ lines.push(first!, ...rest, `${originOf(server)} couldn't be reached to confirm it: ${answer.unreachable}`);
118+ const by = typeof answer.body.approved_by === "string" ? `, approved by ${answer.body.approved_by}` : "";
123+ lines.push(`${originOf(server)} no longer accepts this box's sign-in (signed out or revoked). Run abso login.`);
133+ `This folder is agent ${c.agent} in project ${c.project} on ${originOf(c.server)}, with ${credential}${c.reader ? ", as a reader" : ""}.`,
135+ here = { root: folder.root, project: c.project, agent: c.agent, server: c.server, credential };
144+
151+
167+ text: `Node ${probe.node} is too old: abso needs ${need} or later. Install a newer Node from nodejs.org.`,
170+
172+ // Chosen as every command chooses (server-choice.ts): --server, else the folder's own, else ABSO_SERVER, else prod.
186+ text: `${origin} answers${typeof body.commit === "string" ? ` (version ${body.commit.slice(0, 7)})` : ""} in ${Date.now() - started} ms.`,
195+ const why = err instanceof Error && err.name === "TimeoutError" ? "no answer within 10 s" : plainCause(err);
199+ text: `Can't reach ${origin}: ${why}. Check your connection${folder?.config ? ", and the server in .abso/config.json" : ""}.`,
202+
208+ text: `This box isn't signed in to ${origin}. ${folder?.config ? "Only abso join needs it; abso login signs it in." : "Run abso login."}`,
226+ ? { check: "box", result: "skip", text: `Signed in as box ${record.id}; the server can't confirm it now.` }
231+ text: `Signed in as box ${record.id}, which ${origin} accepts, until ${day(record.expiresAt)} UTC.`,
236+ text: `${origin} no longer accepts this box's sign-in (signed out or revoked). Run abso login.`,
240+
248+ checks.push({ check: "folder", result: "fail", text: `This folder's settings can't be read: ${folder.problem}` });
254+
255+/** The folder's key against its project: GET head, which the server answers only after it has checked the key. */
268+ text: `This folder (${who}) has no key, and there's no shared token. Run abso login, then abso join ${c.project}.`,
302+ text: `${originOf(c.server)} has no project ${c.project}. Check the name in .abso/config.json, or abso init makes it.`,
308+ 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.`,
316+
320+
323+ if (cause?.code === "ENOTFOUND" || cause?.code === "EAI_AGAIN") return "the address doesn't resolve";
327+
329+ * The commonest failures in plain words, with the next step: no credential, a credential the server refuses, and a
330+ * server that can't be reached. Anything else is left as it was. `sent` names the key or token the call carried, if any.
332+export function plainError(err: unknown, sent: string | undefined, tokenFileUnasked = false): string | undefined {
336+ ? `The server didn't accept ${sent}: it may be revoked or expired. abso doctor checks it. (${err.message})`
337+ : `You're not signed in. Run abso login, then abso join <project>.${tokenFileUnasked ? " ~/.abso/token is used only with --token-file." : ""}`;
340+ // A message that already gives its next step (publish's "Run the same command again.") keeps it as the last word.
- MCP
- compare on this site's /mcp
- CLI
- abso diff 2 318 client/src/doctor.ts --json
- JSON
- /christopher/abso-core/compare/2..318?file=client%2Fsrc%2Fdoctor.ts&format=json