{"draft":null,"from":155,"to":156,"files":[{"path":"client/src/server-choice.ts","added":34,"removed":2,"diff":"--- a/client/src/server-choice.ts\n+++ b/client/src/server-choice.ts\n@@ -8,15 +8,47 @@\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+// When nothing names a server (abso-core issue 9), every command picks it in one order (chooseServer):\n+//   1. --server <url>;\n+//   2. the server of the joined folder the command runs in (its .abso/config.json);\n+//   3. ABSO_SERVER (or the older AVCS_SERVER);\n+//   4. prod, https://api.abso.dev.\n+// Which servers this box is signed in to plays no part: signed in to staging and prod both, or to staging\n+// alone, a command with nothing named goes to prod, and staging is a deliberate --server, folder or ABSO_SERVER.\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+import { serverBase, TOKEN_SERVERS } from \"./core.ts\";\n+import { fromEnv } from \"./env-names.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 server a command goes to when nothing names one: prod. */\n+export const PROD_SERVER = TOKEN_SERVERS[0]!;\n+\n+/** The order of precedence, in the words help uses. */\n+export const SERVER_ORDER = `--server <url>, else the server of the abso folder you're in, else ABSO_SERVER, else prod (${PROD_SERVER})`;\n+\n+/**\n+ * The server a command goes to: `flag` (checked by serverFlag), else the joined folder's, else ABSO_SERVER\n+ * (checked here), else prod. An explicit choice is returned as given, never swapped for another.\n+ */\n+export function chooseServer(\n+\tflag: string | undefined,\n+\tcwd: string,\n+\tenv: Readonly<Record<string, string | undefined>>,\n+): string {\n+\tif (flag !== undefined) return flag;\n+\tconst folder = folderServer(cwd);\n+\tif (folder !== undefined) return folder;\n+\tconst named = fromEnv(env, \"SERVER\");\n+\tif (named !== undefined) return checkedServer(named, env.ABSO_SERVER ? \"ABSO_SERVER\" : \"AVCS_SERVER\");\n+\treturn PROD_SERVER;\n+}\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@@ -101,7 +133,7 @@\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\t\t\t: `--server <url>: the server to use, as given, never swapped for another. The order: ${SERVER_ORDER}. This box's sign-in for one server is never sent to another.`;\n \t}\n }\n "}],"unmatched":[]}