{"version":155,"agent":"speed","message":"Every command that talks to a server now takes --server <url>, parsed and checked in one place (client/src/server-choice.ts). A missing, empty or malformed value is refused before anything is sent. In a joined folder, --server must be the folder's own server: another one is refused rather than swapped in, so a folder's work and key go only to the server it was joined on. Commands that pick their own server (join, init, login, whoami, doctor, box, logout, orgs, org, key) use the named one as given; doctor no longer swaps in the folder's server over an explicit one, and an explicit --server takes issues to that server's own Issues Worker instead of ABSO_ISSUES_SERVER. The five local-only commands refuse --server and say why. Help shows the same --server line for every command of a kind. For abso-core issue 10.","time":1791913490940,"timeIso":"2026-10-13T17:44:50.940Z","changes":23,"change":1920,"files":["client/src/command-env.ts","client/src/doctor.ts","client/src/issues.ts","client/src/main.ts","client/src/server-choice.ts","client/src/visitor.ts","client/test/server-flag.test.ts"],"draft":null,"diff":[{"path":"client/src/command-env.ts","added":5,"removed":0,"diff":"--- a/client/src/command-env.ts\n+++ b/client/src/command-env.ts\n@@ -25,6 +25,11 @@\n \treadonly runKind?: RunKind;\n \t/** What a -file flag of - reads: stdin, unless a test gives it. */\n \treadonly readStdin?: () => string;\n+\t/**\n+\t * The server --server named, checked (server-choice.ts), when the command was given one. It is used as given,\n+\t * so no environment setting redirects it (ABSO_ISSUES_SERVER included).\n+\t */\n+\treadonly server?: string;\n }\n \n export function plural(n: number, word: string): string {"},{"path":"client/src/doctor.ts","added":3,"removed":2,"diff":"--- a/client/src/doctor.ts\n+++ b/client/src/doctor.ts\n@@ -155,6 +155,7 @@\n \tcwd: string,\n \tenv: Readonly<Record<string, string | undefined>>,\n \tprobe: Probe,\n+\texplicit = false,\n ): Promise<Check[]> {\n \tconst checks: Check[] = [];\n \tconst need = nodeNeeded(probe.built);\n@@ -170,8 +171,8 @@\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+\t// The folder's own server when there is one (it's the one its commands talk to), unless --server named one.\n+\tconst target = explicit ? server : (folder?.config?.server ?? server);\n \tconst origin = originOf(target);\n \tlet reachable = false;\n \tconst started = Date.now();"},{"path":"client/src/issues.ts","added":4,"removed":1,"diff":"--- a/client/src/issues.ts\n+++ b/client/src/issues.ts\n@@ -36,7 +36,10 @@\n /** The folder, with its Api pointed at the Issues Worker: the token goes only where tokenGoesTo allows, as for the avcs server. */\n function openIssues(env: Env): { root: string; config: Config; api: Api } {\n \tconst { root, config, api } = open(env);\n-\tconst server = fromEnv(env.env, \"ISSUES_SERVER\") || issuesServerFor(config.server, readMachineServers(env.env));\n+\t// An explicit --server goes to that server's own Issues Worker: ABSO_ISSUES_SERVER doesn't redirect it.\n+\tconst server =\n+\t\t(env.server === undefined ? fromEnv(env.env, \"ISSUES_SERVER\") : undefined) ||\n+\t\tissuesServerFor(config.server, readMachineServers(env.env));\n \tif (server === undefined)\n \t\tthrow new UsageError(\n \t\t\t`${config.server} has no Issues Worker beside it that abso knows; ~/.abso/servers.json or ABSO_ISSUES_SERVER names one`,"},{"path":"client/src/main.ts","added":50,"removed":17,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -49,6 +49,7 @@\n import { initInOrg, runOrg, runOrgs } from \"./orgs.ts\";\n import { runUnqueue } from \"./queue.ts\";\n import { runNote, runNotes, runReview } from \"./review.ts\";\n+import { checkFolderServer, localRefusal, serverFlag, serverHelp, serverUse } from \"./server-choice.ts\";\n import { installSkill, SKILL, skillPath } from \"./skill.ts\";\n import { colorsPass, terminalText } from \"./terminal-text.ts\";\n import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from \"./versions.ts\";\n@@ -93,7 +94,7 @@\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] --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 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@@ -183,7 +184,7 @@\n \t\t\tdays: \"string\",\n \t\t},\n \t\tusage:\n-\t\t\t\"abso login [--server <url>] [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]\",\n+\t\t\t\"abso login [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]\",\n \t\tabout:\n \t\t\t\"Sign this box in once: it opens the approve page in your browser with the code filled in, prints the link and the code too, and waits while a person approves the code on the website, choosing the projects, the highest role and how many agents. Then abso join in any of those projects gives each agent its own key, with no approval. The box's sign-in is kept in your user folder, never in a project folder, and is never printed. Without --server, the folder's server, or https://api.abso.dev outside a folder. No browser opens with --no-browser or ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display.\",\n \t\trun: async (args, env) => {\n@@ -205,7 +206,7 @@\n \t},\n \tbox: {\n \t\tflags: { server: \"string\" },\n-\t\tusage: \"abso box [--server <url>]\",\n+\t\tusage: \"abso box\",\n \t\tabout:\n \t\t\t\"What this box's sign-in allows: its projects, the highest role its agents may have, how many agents it has made and may make, and when it expires. Never the credential.\",\n \t\trun: async (args, env) => {\n@@ -216,7 +217,7 @@\n \t},\n \twhoami: {\n \t\tflags: { server: \"string\" },\n-\t\tusage: \"abso whoami [--server <url>]\",\n+\t\tusage: \"abso whoami\",\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. 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.\",\n \t\trun: async (args, env) => {\n@@ -226,18 +227,24 @@\n \t},\n \tdoctor: {\n \t\tflags: { server: \"string\" },\n-\t\tusage: \"abso doctor [--server <url>]\",\n+\t\tusage: \"abso doctor\",\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. It picks the server as whoami does.\",\n \t\trun: async (args, env) => {\n-\t\t\tconst checks = await doctor(checkServer(str(args, \"server\"), env.cwd, env.env), env.cwd, env.env, realProbe());\n+\t\t\tconst checks = await doctor(\n+\t\t\t\tcheckServer(str(args, \"server\"), env.cwd, env.env),\n+\t\t\t\tenv.cwd,\n+\t\t\t\tenv.env,\n+\t\t\t\trealProbe(),\n+\t\t\t\tstr(args, \"server\") !== undefined,\n+\t\t\t);\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+\t\tusage: \"abso logout\",\n \t\tabout:\n \t\t\t\"End this box's sign-in on the server and forget it here. Keys its agents already have stop working with it.\",\n \t\trun: async (args, env) => {\n@@ -255,7 +262,7 @@\n \t},\n \torgs: {\n \t\tflags: { server: \"string\" },\n-\t\tusage: \"abso orgs [--server <url>]\",\n+\t\tusage: \"abso orgs\",\n \t\tabout:\n \t\t\t\"Your organizations and your role in each, and invitations waiting for you. It reads as the person who approved this box's sign-in (abso login).\",\n \t\trun: (args, env) => runOrgs(boxServer(args, env)),\n@@ -299,7 +306,7 @@\n \t},\n \tjoin: {\n \t\tflags: { server: \"string\", agent: \"string\", dir: \"string\", reader: \"boolean\" },\n-\t\tusage: \"abso join <project> [--agent <name>] [--dir <folder>] [--server <url>] [--reader]\",\n+\t\tusage: \"abso join <project> [--agent <name>] [--dir <folder>] [--reader]\",\n \t\tabout:\n \t\t\t\"Join a project as a new agent and write its shared files into a folder: --dir, else here when this folder is empty, else ./<project> (which has to be new or empty). Without --agent the agent is named after this box (the name abso login gave it, lower-cased), or the next free <name>-2, <name>-3; that needs the box signed in with abso login. 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 pushes. With --reader and no sign-in, a public project is joined to read signed out: the folder holds only its settings, sends no sign-in, and runs status, log, show, files, blame, why, where, issues, issue and search; every other command is refused.\",\n \t\trun: runJoin,\n@@ -803,12 +810,21 @@\n \n const HELP_INTRO = \"abso: version control for agents. This is its command-line client.\";\n const HELP_NOTE =\n-\t\"Every command takes --json. Settings live in .abso/config.json (.avcs/config.json in a folder from before the rename). The token comes from ABSO_TOKEN, or else ~/.abso/token (or ~/.avcs/token from before).\";\n+\t\"Every command takes --json. Settings live in .abso/config.json (.avcs/config.json in a folder from before the rename). The token comes from ABSO_TOKEN, or else ~/.abso/token (or ~/.avcs/token from before). \" +\n+\t\"Every command that talks to a server takes --server <url>; one that works only on this machine (skill, check-ignore, pause, resume, fix-eol) doesn't. In a joined folder --server must be the folder's own server: another is refused, never swapped in. An explicit --server is used as given, and no setting redirects it.\";\n \n+/** A command's flags: its own, and --server for every command that talks to a server (server-choice.ts). */\n+function flagsOf(name: string, def: CommandDef): FlagSpec {\n+\treturn serverUse(name) === \"local\" ? def.flags : { ...def.flags, server: \"string\" };\n+}\n+\n /** Every command as help shows it, in order: the table's, then the three it doesn't hold. */\n-function helpEntries(): { name: string; usage: string; about: string; flags: FlagSpec }[] {\n+function helpEntries(): { name: string; usage: string; about: string; flags: FlagSpec; server?: string }[] {\n \treturn [\n-\t\t...Object.entries(COMMANDS).map(([name, c]) => ({ name, usage: c.usage, about: c.about, flags: c.flags })),\n+\t\t...Object.entries(COMMANDS).map(([name, c]) => {\n+\t\t\tconst server = serverHelp(name);\n+\t\t\treturn { name, usage: c.usage, about: c.about, flags: flagsOf(name, c), ...(server ? { server } : {}) };\n+\t\t}),\n \t\t{\n \t\t\tname: \"hook\",\n \t\t\tusage: \"abso hook\",\n@@ -832,7 +848,11 @@\n }\n \n function help(): string {\n-\tconst entries = helpEntries().flatMap((c) => [`  ${c.usage}`, `      ${c.about}`]);\n+\tconst entries = helpEntries().flatMap((c) => [\n+\t\t`  ${c.usage}`,\n+\t\t`      ${c.about}`,\n+\t\t...(c.server ? [`      ${c.server}`] : []),\n+\t]);\n \treturn [HELP_INTRO, \"\", ...entries, \"\", HELP_NOTE].join(\"\\n\");\n }\n \n@@ -864,7 +884,7 @@\n export function commandTable(): Readonly<\n \tRecord<string, { readonly flags: FlagSpec; readonly usage: string; readonly about: string }>\n > {\n-\treturn COMMANDS;\n+\treturn Object.fromEntries(Object.entries(COMMANDS).map(([name, c]) => [name, { ...c, flags: flagsOf(name, c) }]));\n }\n \n function newsBlock(news: readonly string[]): string[] {\n@@ -932,21 +952,34 @@\n \t\t\t);\n \t\tconst gitOnly = gitOnlyForm(command, argv.slice(1));\n \t\tif (gitOnly) throw new UsageError(gitOnly);\n-\t\tconst parsed = parseArgs(command, argv.slice(1), withBodyFiles(command, def.flags), def.rest);\n+\t\tconst use = serverUse(command);\n+\t\tconst words = argv.includes(\"--\") ? argv.slice(1, argv.indexOf(\"--\")) : argv.slice(1);\n+\t\tif (use === \"local\" && words.some((w) => w === \"--server\" || w.startsWith(\"--server=\")))\n+\t\t\tthrow new UsageError(localRefusal(command));\n+\t\tconst parsed = parseArgs(command, argv.slice(1), withBodyFiles(command, flagsOf(command, def)), def.rest);\n \t\tif ((command === \"push\" || command === \"pull\") && parsed.positionals.length > 0)\n \t\t\tthrow new UsageError(\n \t\t\t\t`abso ${command} takes no remote or branch: it ${command === \"push\" ? \"adds your draft to shared\" : \"brings shared into this folder\"}. A named draft is abso switch <name>.`,\n \t\t\t);\n \t\tif (bool(parsed, \"help\")) {\n \t\t\tconst files = bodyFilesHelp(command, def.flags);\n-\t\t\treturn { stdout: `${def.usage}\\n  ${def.about}\\n${files ? `  ${files}\\n` : \"\"}`, stderr: \"\", exit: EXIT.ok };\n+\t\t\tconst server = serverHelp(command);\n+\t\t\treturn {\n+\t\t\t\tstdout: `${def.usage}\\n  ${def.about}\\n${server ? `  ${server}\\n` : \"\"}${files ? `  ${files}\\n` : \"\"}`,\n+\t\t\t\tstderr: \"\",\n+\t\t\t\texit: EXIT.ok,\n+\t\t\t};\n \t\t}\n+\t\t// --server is checked before anything is read or sent: a bad value, or (for a command on a joined folder)\n+\t\t// a server that isn't the folder's own, is refused here.\n+\t\tconst named = use === \"local\" ? undefined : serverFlag(parsed);\n+\t\tif (named !== undefined && use === \"folder\") checkFolderServer(command, named, env.cwd);\n \t\t// A folder that reads signed out runs its reads and nothing else, refused before any call.\n \t\tconst root = findRoot(env.cwd);\n \t\tif (root !== undefined && isVisitor(root)) checkVisitor(command, parsed, readConfig(root, env.env).project);\n \t\tconst args = readBodyFiles(command, parsed, env.cwd, env.readStdin);\n \t\ttakeNews(); // what an earlier call in this process left (tests run many)\n-\t\tconst out = await def.run(args, env);\n+\t\tconst out = await def.run(args, named === undefined ? env : { ...env, server: named });\n \t\tconst exit = out.exit ?? EXIT.ok;\n \t\t// Every command that took news while recording prints it (#37, News Report).\n \t\tconst news = takeNews();"},{"path":"client/src/server-choice.ts","added":111,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/server-choice.ts\n@@ -0,0 +1,111 @@\n+// The --server flag (abso-core issue 10). Every command that talks to a server takes --server <url>, parsed and\n+// checked here the same way for all of them:\n+//   - A command that works on a joined folder (\"folder\") talks only to that folder's server. --server there must\n+//     name that same server; another one is refused, never swapped in, so the folder's work and key never go to\n+//     a server it wasn't joined on. Outside a joined folder it is refused too, with how to join one there.\n+//   - A command that picks a server for itself (\"chosen\": join, init, login, whoami and the rest about this box)\n+//     uses the one --server names, as given.\n+//   - A command that works on this machine only (\"local\") takes no --server, and says so.\n+// A value that isn't an http or https URL (a user name, a query or a fragment included) is refused before any\n+// call, as is an empty one.\n+\n+import { readFileSync } from \"node:fs\";\n+import { type Parsed, UsageError } from \"./args.ts\";\n+import { configPath, findRoot } from \"./config.ts\";\n+import { serverBase } from \"./core.ts\";\n+\n+/** How a command uses a server: its joined folder's, one it picks, or none. */\n+export type ServerUse = \"folder\" | \"chosen\" | \"local\";\n+\n+/** The commands that pick a server for themselves rather than use a joined folder's. */\n+const CHOSEN: ReadonlySet<string> = new Set([\n+\t\"init\",\n+\t\"join\",\n+\t\"key\",\n+\t\"login\",\n+\t\"box\",\n+\t\"whoami\",\n+\t\"doctor\",\n+\t\"logout\",\n+\t\"orgs\",\n+\t\"org\",\n+]);\n+\n+/** The commands that never talk to a server. */\n+const LOCAL: ReadonlySet<string> = new Set([\"skill\", \"check-ignore\", \"pause\", \"resume\", \"fix-eol\"]);\n+\n+/** How `command` uses a server. Anything not named above works on a joined folder. */\n+export function serverUse(command: string): ServerUse {\n+\treturn CHOSEN.has(command) ? \"chosen\" : LOCAL.has(command) ? \"local\" : \"folder\";\n+}\n+\n+const EXAMPLE = \"https://api.abso.dev\";\n+\n+/** `value` as a server, or a refusal naming where it came from (--server, ABSO_SERVER). */\n+export function checkedServer(value: string, from: string): string {\n+\tconst v = value.trim();\n+\tif (v === \"\") throw new UsageError(`${from} needs a server's URL, like ${EXAMPLE}`);\n+\tif (serverBase(v) === undefined)\n+\t\tthrow new UsageError(\n+\t\t\t`${from} takes an http or https URL with no user name, query or fragment, like ${EXAMPLE} (got ${JSON.stringify(value)})`,\n+\t\t);\n+\treturn v;\n+}\n+\n+/** The server --server names, checked, or undefined when it isn't given. */\n+export function serverFlag(args: Parsed): string | undefined {\n+\tconst v = args.flags.get(\"server\");\n+\treturn typeof v === \"string\" ? checkedServer(v, \"--server\") : undefined;\n+}\n+\n+/** Whether two servers are the same one: the same scheme, host, port and path, ignoring case and a trailing slash. */\n+export function sameServer(a: string, b: string): boolean {\n+\treturn (serverBase(a) ?? a.trim()) === (serverBase(b) ?? b.trim());\n+}\n+\n+/** The server in the .abso/config.json of the folder `cwd` is in, or undefined outside one (or when it can't be read). */\n+export function folderServer(cwd: string): string | undefined {\n+\tconst root = findRoot(cwd);\n+\tif (root === undefined) return undefined;\n+\ttry {\n+\t\tconst server = (JSON.parse(readFileSync(configPath(root), \"utf8\")) as { server?: unknown }).server;\n+\t\treturn typeof server === \"string\" && server !== \"\" ? server : undefined;\n+\t} catch {\n+\t\treturn undefined;\n+\t}\n+}\n+\n+/**\n+ * For a command that works on a joined folder: refuses a --server that isn't the folder's own server, and one\n+ * given outside a joined folder. Nothing is sent before this.\n+ */\n+export function checkFolderServer(command: string, flag: string, cwd: string): void {\n+\tconst own = folderServer(cwd);\n+\tif (own === undefined)\n+\t\tthrow new UsageError(\n+\t\t\t`abso ${command} works on a joined folder, and ${cwd} isn't in one. To work with ${flag}: abso join <project> --server ${flag}, or abso init --server ${flag} for a new project.`,\n+\t\t);\n+\tif (!sameServer(own, flag))\n+\t\tthrow new UsageError(\n+\t\t\t`this folder is joined on ${own}, not ${flag}, so abso ${command} won't send its work or key there. Run it in a folder joined on ${flag} (abso join <project> --server ${flag}).`,\n+\t\t);\n+}\n+\n+/** What help says about --server for a command, the same words for every command of a kind. */\n+export function serverHelp(command: string): string | undefined {\n+\tswitch (serverUse(command)) {\n+\t\tcase \"local\":\n+\t\t\treturn undefined;\n+\t\tcase \"folder\":\n+\t\t\treturn \"--server <url>: this folder's own server, which it uses anyway. Another server is refused, never swapped in, so the folder's work and key go only to the server it was joined on.\";\n+\t\tcase \"chosen\":\n+\t\t\treturn command === \"key\"\n+\t\t\t\t? \"--server <url>: the server the key is for; without it, this folder's. It is used as given, never swapped for another.\"\n+\t\t\t\t: \"--server <url>: the server to use, as given, never swapped for another. Each server gets only its own sign-in.\";\n+\t}\n+}\n+\n+/** The refusal for --server on a command that works on this machine only. */\n+export function localRefusal(command: string): string {\n+\treturn `abso ${command} works on this machine only and talks to no server, so it takes no --server`;\n+}"},{"path":"client/src/visitor.ts","added":2,"removed":2,"diff":"--- a/client/src/visitor.ts\n+++ b/client/src/visitor.ts\n@@ -23,8 +23,8 @@\n /** Commands about this box, not the folder: they work from anywhere, a visitor folder too. */\n export const VISITOR_ELSEWHERE: readonly string[] = [\"login\", \"logout\"];\n \n-/** Flags every command takes. */\n-const EVERY = new Set([\"json\", \"help\"]);\n+/** Flags every command takes (--server is checked against the folder's own server before this, in main.ts). */\n+const EVERY = new Set([\"json\", \"help\", \"server\"]);\n \n export function visitorRefusal(project: string): string {\n \treturn `This folder reads ${project} signed out. To work on it: abso login, then abso join ${project} in a new folder.`;"},{"path":"client/test/server-flag.test.ts","added":218,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/server-flag.test.ts\n@@ -0,0 +1,218 @@\n+// --server on every command that talks to a server (abso-core issue 10). The rules, each a test:\n+// - every command is sorted: one that works on this machine only takes no --server and says so; every other one\n+//   takes it, and help says the same words about it for each kind;\n+// - a missing, empty or malformed value is refused before anything is sent, for every family of command;\n+// - in a joined folder, --server naming the folder's own server reaches it; another server is refused, never\n+//   swapped in, and nothing is sent; outside a joined folder a folder command with --server is refused too;\n+// - an explicit --server goes to that server's own Issues Worker, which ABSO_ISSUES_SERVER doesn't redirect;\n+// - a command that picks its server (whoami, box, logout) uses the one named, even inside a folder on another.\n+\n+import assert from \"node:assert/strict\";\n+import { mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\n+import { createServer, type Server } from \"node:http\";\n+import type { AddressInfo } from \"node:net\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { after, before, describe, it } from \"node:test\";\n+import { writeConfig } from \"../src/config.ts\";\n+import { commandTable, main } from \"../src/main.ts\";\n+import { sameServer, serverHelp, serverUse } from \"../src/server-choice.ts\";\n+\n+/** A made-up token: the tests never read the real ~/.abso/token. */\n+const TOKEN = \"abso_test-token-for-server-flag\";\n+\n+interface Listening {\n+\treadonly server: Server;\n+\treadonly url: string;\n+\treadonly paths: string[];\n+}\n+\n+/** A server that notes each path it is asked for and answers 500, so a command stops after its first call. */\n+async function listen(): Promise<Listening> {\n+\tconst paths: string[] = [];\n+\tconst server = createServer((req, res) => {\n+\t\tpaths.push(req.url ?? \"\");\n+\t\tres.writeHead(500, { \"content-type\": \"application/json\" });\n+\t\tres.end(JSON.stringify({ error: \"a test server\" }));\n+\t});\n+\tawait new Promise<void>((done) => server.listen(0, \"127.0.0.1\", done));\n+\treturn { server, url: `http://127.0.0.1:${(server.address() as AddressInfo).port}`, paths };\n+}\n+\n+const temps: string[] = [];\n+function temp(name: string): string {\n+\tconst dir = mkdtempSync(join(tmpdir(), `abso-server-flag-${name}-`));\n+\ttemps.push(dir);\n+\treturn dir;\n+}\n+\n+let home: Listening;\n+let other: Listening;\n+let issuesElsewhere: Listening;\n+let env: Record<string, string>;\n+\n+before(async () => {\n+\thome = await listen();\n+\tother = await listen();\n+\tissuesElsewhere = await listen();\n+\tconst servers = join(temp(\"servers\"), \"servers.json\");\n+\twriteFileSync(servers, \"{}\");\n+\tenv = { ABSO_TOKEN: TOKEN, ABSO_SERVERS_FILE: servers };\n+});\n+\n+after(() => {\n+\tfor (const l of [home, other, issuesElsewhere]) l.server.close();\n+\tfor (const dir of temps) rmSync(dir, { recursive: true, force: true });\n+});\n+\n+function folder(server = home.url): string {\n+\tconst root = temp(\"folder\");\n+\twriteConfig(root, { server, project: \"demo\", agent: \"alice\" });\n+\treturn root;\n+}\n+\n+const run = (cwd: string, argv: string[], extra: Record<string, string> = {}) =>\n+\tmain(argv, { cwd, env: { ...env, ...extra }, write: () => {} });\n+\n+function calls(): number {\n+\treturn home.paths.length + other.paths.length + issuesElsewhere.paths.length;\n+}\n+\n+function clear(): void {\n+\tfor (const l of [home, other, issuesElsewhere]) l.paths.length = 0;\n+}\n+\n+describe(\"--server on every command\", () => {\n+\tit(\"sorts every command: local ones take no --server, every other one does, and help says so alike\", async () => {\n+\t\tconst table = commandTable();\n+\t\tconst local = Object.keys(table).filter((name) => serverUse(name) === \"local\");\n+\t\tassert.deepEqual(local.sort(), [\"check-ignore\", \"fix-eol\", \"pause\", \"resume\", \"skill\"]);\n+\t\tfor (const [name, def] of Object.entries(table)) {\n+\t\t\tif (serverUse(name) === \"local\") {\n+\t\t\t\tassert.equal(def.flags.server, undefined, name);\n+\t\t\t\tassert.equal(serverHelp(name), undefined, name);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tassert.equal(def.flags.server, \"string\", name);\n+\t\t\tconst help = await run(process.cwd(), [name, \"--help\"]);\n+\t\t\tassert.ok(help.stdout.includes(`  ${serverHelp(name)}\\n`), `abso ${name} --help names --server`);\n+\t\t}\n+\t\tconst data = JSON.parse((await run(process.cwd(), [\"help\", \"--json\"])).stdout) as {\n+\t\t\tcommands: { name: string; server?: string; flags: Record<string, string> }[];\n+\t\t};\n+\t\tfor (const c of data.commands.filter((c) => c.name in table)) assert.equal(c.server, serverHelp(c.name), c.name);\n+\t\tconst text = (await run(process.cwd(), [\"help\"])).stdout;\n+\t\tassert.match(text, /Every command that talks to a server takes --server <url>/);\n+\t});\n+\n+\tit(\"refuses --server on a command that works on this machine only\", async () => {\n+\t\tfor (const argv of [\n+\t\t\t[\"skill\", \"show\", \"--server\", home.url],\n+\t\t\t[\"check-ignore\", \"a.txt\", `--server=${home.url}`],\n+\t\t\t[\"pause\", \"--server\", home.url],\n+\t\t]) {\n+\t\t\tconst r = await run(folder(), argv);\n+\t\t\tassert.equal(r.exit, 1, argv.join(\" \"));\n+\t\t\tassert.match(r.stderr, /works on this machine only and talks to no server, so it takes no --server/);\n+\t\t}\n+\t\tconst words = await run(folder(), [\"check-ignore\", \"--\", \"--server\"]);\n+\t\tassert.doesNotMatch(words.stderr, /takes no --server/, \"a path after -- is a path\");\n+\t});\n+\n+\tit(\"refuses a missing, empty or malformed value before anything is sent, in every family\", async () => {\n+\t\tconst root = folder();\n+\t\tconst outside = temp(\"outside\");\n+\t\tclear();\n+\t\tconst families: [string, string[]][] = [\n+\t\t\t[root, [\"status\"]],\n+\t\t\t[root, [\"issue\", \"new\", \"A title\"]],\n+\t\t\t[root, [\"ask\", \"bob\", \"Why?\"]],\n+\t\t\t[root, [\"news\"]],\n+\t\t\t[root, [\"pipeline\", \"runs\"]],\n+\t\t\t[outside, [\"whoami\"]],\n+\t\t\t[outside, [\"login\"]],\n+\t\t\t[outside, [\"join\", \"demo\"]],\n+\t\t\t[outside, [\"org\", \"acme\"]],\n+\t\t\t[outside, [\"key\", \"list\"]],\n+\t\t];\n+\t\tfor (const [cwd, argv] of families) {\n+\t\t\tconst missing = await run(cwd, [...argv, \"--server\"]);\n+\t\t\tassert.match(missing.stderr, /--server needs a value/, argv.join(\" \"));\n+\t\t\tconst empty = await run(cwd, [...argv, \"--server=\"]);\n+\t\t\tassert.match(empty.stderr, /--server needs a server's URL, like https:\\/\\/api\\.abso\\.dev/, argv.join(\" \"));\n+\t\t\tfor (const bad of [\"api.abso.dev\", \"ftp://api.abso.dev\", \"https://me@api.abso.dev\", \"https://x.example/?a=1\"]) {\n+\t\t\t\tconst r = await run(cwd, [...argv, \"--server\", bad]);\n+\t\t\t\tassert.equal(r.exit, 1, `${argv.join(\" \")} --server ${bad}`);\n+\t\t\t\tassert.match(r.stderr, /--server takes an http or https URL with no user name, query or fragment/);\n+\t\t\t}\n+\t\t}\n+\t\tassert.equal(calls(), 0, \"nothing was sent\");\n+\t});\n+\n+\tit(\"in a joined folder, reaches the folder's own server and refuses another without sending anything\", async () => {\n+\t\tconst root = folder();\n+\t\tfor (const argv of [[\"status\"], [\"log\"], [\"issues\"], [\"issue\", \"1\"], [\"news\"], [\"waiting\"], [\"ci\"]]) {\n+\t\t\tclear();\n+\t\t\tconst same = await run(root, [...argv, \"--server\", `${home.url.toUpperCase().replace(\"HTTP\", \"http\")}/`]);\n+\t\t\tassert.doesNotMatch(same.stderr, /joined on/, argv.join(\" \"));\n+\t\t\tassert.ok(home.paths.length > 0, `abso ${argv.join(\" \")} reached the folder's server`);\n+\t\t\tassert.equal(other.paths.length, 0);\n+\t\t\tclear();\n+\t\t\tconst refused = await run(root, [...argv, \"--server\", other.url]);\n+\t\t\tassert.equal(refused.exit, 1);\n+\t\t\tassert.match(\n+\t\t\t\trefused.stderr,\n+\t\t\t\tnew RegExp(\n+\t\t\t\t\t`this folder is joined on ${home.url}, not ${other.url}, so abso ${argv[0]} won't send its work or key there`,\n+\t\t\t\t),\n+\t\t\t);\n+\t\t\tassert.equal(calls(), 0, `abso ${argv.join(\" \")} sent nothing`);\n+\t\t}\n+\t});\n+\n+\tit(\"outside a joined folder, a folder command with --server says how to join one there\", async () => {\n+\t\tconst outside = temp(\"outside\");\n+\t\tfor (const argv of [[\"status\"], [\"issue\", \"new\", \"A title\"], [\"ask\", \"bob\", \"Why?\"], [\"news\"]]) {\n+\t\t\tconst r = await run(outside, [...argv, \"--server\", home.url]);\n+\t\t\tassert.equal(r.exit, 1);\n+\t\t\tassert.match(r.stderr, new RegExp(`abso join <project> --server ${home.url}`));\n+\t\t}\n+\t\tassert.equal(calls(), 0);\n+\t});\n+\n+\tit(\"an explicit --server takes issues to that server's own Issues Worker, past ABSO_ISSUES_SERVER\", async () => {\n+\t\tconst root = folder();\n+\t\tconst elsewhere = { ABSO_ISSUES_SERVER: issuesElsewhere.url };\n+\t\tclear();\n+\t\tawait run(root, [\"issue\", \"1\"], elsewhere);\n+\t\tassert.ok(issuesElsewhere.paths.length > 0, \"without --server, ABSO_ISSUES_SERVER names the Issues Worker\");\n+\t\tassert.ok(home.paths.every((p) => !p.startsWith(\"/issues/\")));\n+\t\tclear();\n+\t\tawait run(root, [\"issue\", \"1\", \"--server\", home.url], elsewhere);\n+\t\tassert.equal(issuesElsewhere.paths.length, 0, \"--server isn't redirected\");\n+\t\tassert.ok(home.paths.length > 0);\n+\t\tassert.ok(\n+\t\t\thome.paths.some((p) => p.startsWith(\"/issues/p/demo/\")),\n+\t\t\t`the open server keeps issues at /issues/p/<project>: ${home.paths}`,\n+\t\t);\n+\t});\n+\n+\tit(\"a command that picks its server uses the one named, even in a folder on another\", async () => {\n+\t\tconst root = folder(other.url);\n+\t\tfor (const argv of [[\"whoami\"], [\"box\"], [\"logout\"]]) {\n+\t\t\tconst r = await run(root, [...argv, \"--server\", home.url]);\n+\t\t\tassert.match(r.stdout, new RegExp(home.url.replace(/\\./g, \"\\\\.\")), argv.join(\" \"));\n+\t\t}\n+\t\tclear();\n+\t\tconst doctor = await run(root, [\"doctor\", \"--server\", home.url]);\n+\t\tassert.match(doctor.stdout, new RegExp(`${home.url.replace(/\\./g, \"\\\\.\")} answered 500`));\n+\t\tassert.equal(other.paths.filter((p) => p === \"/version\").length, 0, \"doctor didn't swap in the folder's server\");\n+\t});\n+\n+\tit(\"counts two spellings of one server as the same, and different ports or paths as different\", () => {\n+\t\tassert.ok(sameServer(\"https://API.abso.dev/\", \"https://api.abso.dev\"));\n+\t\tassert.ok(!sameServer(\"http://127.0.0.1:8787\", \"http://127.0.0.1:8788\"));\n+\t\tassert.ok(!sameServer(\"http://127.0.0.1:8787\", \"http://localhost:8787\"));\n+\t\tassert.ok(!sameServer(\"https://x.example/a\", \"https://x.example/b\"));\n+\t});\n+});"}],"ci":null}