Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 155 to 156

Compare

+34 −2 in 2 places
Lines 8–54 at 156 (were 8–22 at 155)
88// - A command that works on this machine only ("local") takes no --server, and says so.
99// A value that isn't an http or https URL (a user name, a query or a fragment included) is refused before any
1010// call, as is an empty one.
11+//
12+// When nothing names a server (abso-core issue 9), every command picks it in one order (chooseServer):
13+// 1. --server <url>;
14+// 2. the server of the joined folder the command runs in (its .abso/config.json);
15+// 3. ABSO_SERVER (or the older AVCS_SERVER);
16+// 4. prod, https://api.abso.dev.
17+// Which servers this box is signed in to plays no part: signed in to staging and prod both, or to staging
18+// alone, a command with nothing named goes to prod, and staging is a deliberate --server, folder or ABSO_SERVER.
1119
1220import { readFileSync } from "node:fs";
1321import { type Parsed, UsageError } from "./args.ts";
1422import { configPath, findRoot } from "./config.ts";
15−import { serverBase } from "./core.ts";
23+import { serverBase, TOKEN_SERVERS } from "./core.ts";
24+import { fromEnv } from "./env-names.ts";
1625
1726/** How a command uses a server: its joined folder's, one it picks, or none. */
1827export type ServerUse = "folder" | "chosen" | "local";
1928
29+/** The server a command goes to when nothing names one: prod. */
30+export const PROD_SERVER = TOKEN_SERVERS[0]!;
32+/** The order of precedence, in the words help uses. */
33+export const SERVER_ORDER = `--server <url>, else the server of the abso folder you're in, else ABSO_SERVER, else prod (${PROD_SERVER})`;
35+/**
36+ * The server a command goes to: `flag` (checked by serverFlag), else the joined folder's, else ABSO_SERVER
37+ * (checked here), else prod. An explicit choice is returned as given, never swapped for another.
38+ */
39+export function chooseServer(
40+ flag: string | undefined,
41+ cwd: string,
42+ env: Readonly<Record<string, string | undefined>>,
43+): string {
44+ if (flag !== undefined) return flag;
45+ const folder = folderServer(cwd);
46+ if (folder !== undefined) return folder;
47+ const named = fromEnv(env, "SERVER");
48+ if (named !== undefined) return checkedServer(named, env.ABSO_SERVER ? "ABSO_SERVER" : "AVCS_SERVER");
49+ return PROD_SERVER;
50+}
2052/** The commands that pick a server for themselves rather than use a joined folder's. */
2153const CHOSEN: ReadonlySet<string> = new Set([
2254 "init",
Lines 133–139 at 156 (were 101–107 at 155)
101133 case "chosen":
102134 return command === "key"
103135 ? "--server <url>: the server the key is for; without it, this folder's. It is used as given, never swapped for another."
104− : "--server <url>: the server to use, as given, never swapped for another. Each server gets only its own sign-in.";
136+ : `--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.`;
105137 }
106138}
107139
MCP
compare on this site's /mcp
CLI
abso diff 155 156 client/src/server-choice.ts --json
JSON
/christopher/abso-core/compare/155..156?file=client%2Fsrc%2Fserver-choice.ts&format=json