{"version":61,"agent":"trials","message":"abso join and abso init no longer need --server (abso issue 349): --server, then ABSO_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. Usage, about text and the README's join line updated; box.test.ts covers the order.","time":1791600859268,"timeIso":"2026-10-10T02:54:19.268Z","changes":5,"change":797,"files":["README.md","client/src/box.ts","client/src/join-commands.ts","client/src/main.ts","client/test/box.test.ts"],"draft":null,"diff":[{"path":"README.md","added":1,"removed":1,"diff":"--- a/README.md\n+++ b/README.md\n@@ -63,7 +63,7 @@\n Join a project once, in a folder of its own, under an agent name of its own:\n \n ```bash\n-abso join <project> --agent <name> --server https://api.abso.dev --dir ./<name>\n+abso join <project> --agent <name> --dir ./<name>\n cd <name>\n ```\n "},{"path":"client/src/box.ts","added":27,"removed":2,"diff":"--- a/client/src/box.ts\n+++ b/client/src/box.ts\n@@ -9,11 +9,11 @@\n // which answer as the person who approved the box.\n \n import { createHash } from \"node:crypto\";\n-import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n+import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n import { homedir, hostname } from \"node:os\";\n import { dirname, join } from \"node:path\";\n import { UsageError } from \"./args.ts\";\n-import { homeFile, homeWritePath, OLD_STATE_DIR } from \"./state-dir.ts\";\n+import { homeFile, homeWritePath, OLD_STATE_DIR, STATE_DIR } from \"./state-dir.ts\";\n \n /** What the person who approved the code allowed: each project with the highest role its agents get there, and how many agents. */\n export interface Grant {\n@@ -59,6 +59,31 @@\n \t}\n }\n \n+/** The servers this box is signed in to and whose sign-in hasn't expired, from ~/.abso/boxes (and an older ~/.avcs/boxes). */\n+export function signedInServers(home = homedir(), now = Date.now()): string[] {\n+\tconst servers = new Set<string>();\n+\tfor (const dir of [STATE_DIR, OLD_STATE_DIR]) {\n+\t\tlet names: string[];\n+\t\ttry {\n+\t\t\tnames = readdirSync(join(home, dir, \"boxes\"));\n+\t\t} catch {\n+\t\t\tcontinue;\n+\t\t}\n+\t\tfor (const name of names) {\n+\t\t\ttry {\n+\t\t\t\tconst server = (JSON.parse(readFileSync(join(home, dir, \"boxes\", name), \"utf8\")) as { server?: unknown })\n+\t\t\t\t\t.server;\n+\t\t\t\tif (typeof server !== \"string\") continue;\n+\t\t\t\tconst record = readBox(server, home);\n+\t\t\t\tif (record && record.expiresAt > now) servers.add(originOf(record.server));\n+\t\t\t} catch {\n+\t\t\t\t// Not a sign-in this client wrote: left alone.\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn [...servers].sort();\n+}\n+\n export function writeBox(record: BoxRecord, home = homedir()): void {\n \tconst path = homeWritePath(home, \"boxes\", boxFile(record.server));\n \tmkdirSync(dirname(path), { recursive: true });"},{"path":"client/src/join-commands.ts","added":13,"removed":5,"diff":"--- a/client/src/join-commands.ts\n+++ b/client/src/join-commands.ts\n@@ -5,12 +5,13 @@\n import { Api, ApiError } from \"./api.ts\";\n import { bool, type Parsed, str, UsageError } from \"./args.ts\";\n import { writeKnownBlobs } from \"./blobs.ts\";\n-import { mintKey, readBox } from \"./box.ts\";\n+import { mintKey, readBox, signedInServers } from \"./box.ts\";\n import { STARTING_ABSOIGNORE } from \"./check-ignore.ts\";\n import { CLIENT_DIR } from \"./client-version.ts\";\n import { type Env, type Output, plural } from \"./command-env.ts\";\n import { leftOutText, syncFolder, uploadBlobs } from \"./commands.ts\";\n import { findRoot, installKey, readConfig, type Settings, tokenFor, writeConfig } from \"./config.ts\";\n+import { TOKEN_SERVERS } from \"./core.ts\";\n import { fromEnv } from \"./env-names.ts\";\n import { clearKnown, loadIgnore, readFolder, writeKnown } from \"./folder.ts\";\n import { modInstalled } from \"./install.ts\";\n@@ -19,10 +20,17 @@\n import { refusedText } from \"./safety.ts\";\n import { stateDir } from \"./state-dir.ts\";\n \n-function serverFrom(args: Parsed, env: Env): string {\n-\tconst server = str(args, \"server\") ?? fromEnv(env.env, \"SERVER\");\n-\tif (!server) throw new UsageError(\"give the server with --server <url> (or ABSO_SERVER)\");\n-\treturn server;\n+/**\n+ * The server to join or start on (abso issue 349): --server, then ABSO_SERVER, then the server this box is signed in\n+ * to (abso login wrote it), then https://api.abso.dev. A box signed in to more than one server has to say which.\n+ */\n+export function serverFrom(args: Parsed, env: Pick<Env, \"env\">, home?: string): string {\n+\tconst named = str(args, \"server\") ?? fromEnv(env.env, \"SERVER\");\n+\tif (named) return named;\n+\tconst signedIn = signedInServers(home);\n+\tif (signedIn.length > 1)\n+\t\tthrow new UsageError(`this box is signed in to ${signedIn.join(\" and \")}: say which with --server <url>`);\n+\treturn signedIn[0] ?? TOKEN_SERVERS[0]!;\n }\n \n function agentFrom(args: Parsed): string {"},{"path":"client/src/main.ts","added":4,"removed":4,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -89,9 +89,9 @@\n const COMMANDS: Readonly<Record<string, CommandDef>> = {\n \tinit: {\n \t\tflags: { server: \"string\", project: \"string\", agent: \"string\", \"as-is\": \"boolean\", org: \"string\" },\n-\t\tusage: \"abso init [folder] --server <url> --project <name> --agent <name> [--as-is] [--org <org>]\",\n+\t\tusage: \"abso init [folder] [--server <url>] --project <name> --agent <name> [--as-is] [--org <org>]\",\n \t\tabout:\n-\t\t\t\"Create a project on the server from a folder's text files. The folder becomes that agent's folder. It writes a starting .absoignore, and, when the folder has no avcs.json and package.json gives a check or a build to guess, an avcs.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import). --org <org> makes it an organization's project: for now that is done on the website, and abso says where.\",\n+\t\t\t\"Create a project on the server from a folder's text files (the server is chosen as abso join chooses it). The folder becomes that agent's folder. It writes a starting .absoignore, and, when the folder has no avcs.json and package.json gives a check or a build to guess, an avcs.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import). --org <org> makes it an organization's project: for now that is done on the website, and abso says where.\",\n \t\trun: (args, env) => {\n \t\t\tconst org = str(args, \"org\");\n \t\t\treturn org === undefined ? runInit(args, env) : initInOrg(org, boxServer(args, env));\n@@ -262,9 +262,9 @@\n \t},\n \tjoin: {\n \t\tflags: { server: \"string\", agent: \"string\", dir: \"string\", reader: \"boolean\" },\n-\t\tusage: \"abso join <project> --agent <name> --server <url> [--dir <folder>] [--reader]\",\n+\t\tusage: \"abso join <project> --agent <name> [--server <url>] [--dir <folder>] [--reader]\",\n \t\tabout:\n-\t\t\t\"Join a project as a new agent and write its shared files into the folder (default: here). --reader joins as a reader: it reads everything and records nothing, and the server refuses its edits, records and publishes.\",\n+\t\t\t\"Join a project as a new agent and write its shared files into the folder (default: here). The server is --server, else ABSO_SERVER, else the one this box signed in to with abso login, else https://api.abso.dev. --reader joins as a reader: it reads everything and records nothing, and the server refuses its edits, records and publishes.\",\n \t\trun: runJoin,\n \t},\n \trecord: {"},{"path":"client/test/box.test.ts","added":35,"removed":1,"diff":"--- a/client/test/box.test.ts\n+++ b/client/test/box.test.ts\n@@ -7,7 +7,18 @@\n import { tmpdir } from \"node:os\";\n import { join } from \"node:path\";\n import { test } from \"node:test\";\n-import { boxPublic, boxText, forgetBox, login, logout, mintKey, readBox, writeBox } from \"../src/box.ts\";\n+import {\n+\tboxPublic,\n+\tboxText,\n+\tforgetBox,\n+\tlogin,\n+\tlogout,\n+\tmintKey,\n+\treadBox,\n+\tsignedInServers,\n+\twriteBox,\n+} from \"../src/box.ts\";\n+import { serverFrom } from \"../src/join-commands.ts\";\n \n const SERVER = \"https://staging.abso.example\";\n const CREDENTIAL = \"abso_bx_the-secret-credential\";\n@@ -271,3 +282,26 @@\n \tassert.equal(readBox(SERVER, h), undefined);\n \tassert.equal(forgetBox(SERVER, h), false);\n });\n+\n+test(\"join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev (abso issue 349)\", () => {\n+\tconst h = home();\n+\tconst args = (server?: string) => ({ positionals: [], flags: new Map(server ? [[\"server\", server]] : []) });\n+\tconst none = { env: {} };\n+\tassert.equal(serverFrom(args(), none, h), \"https://api.abso.dev\", \"nothing signed in: the abso API\");\n+\twriteBox({ ...record, expiresAt: Date.now() + 1e6 }, h);\n+\tassert.deepEqual(signedInServers(h), [SERVER]);\n+\tassert.equal(serverFrom(args(), none, h), SERVER, \"the server abso login signed this box in to\");\n+\tassert.deepEqual(signedInServers(h, Date.now() + 2e6), [], \"an expired sign-in doesn't count\");\n+\tassert.equal(serverFrom(args(), { env: { ABSO_SERVER: \"https://env.example\" } }, h), \"https://env.example\");\n+\tassert.equal(\n+\t\tserverFrom(args(\"https://flag.example\"), { env: { ABSO_SERVER: \"https://env.example\" } }, h),\n+\t\t\"https://flag.example\",\n+\t);\n+\twriteBox({ ...record, server: \"https://other.abso.example\", expiresAt: Date.now() + 1e6 }, h);\n+\twriteBox({ ...record, expiresAt: Date.now() + 1e6 }, h);\n+\tassert.throws(\n+\t\t() => serverFrom(args(), none, h),\n+\t\t/signed in to https:\\/\\/other\\.abso\\.example and https:\\/\\/staging\\.abso\\.example: say which with --server/,\n+\t);\n+\tassert.equal(serverFrom(args(SERVER), none, h), SERVER, \"--server settles it\");\n+});"}],"ci":null}