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
MCP
blame on this site's /mcp
CLI
abso blame client/src/server-choice.ts --json
JSON
/christopher/abso-core/blame/client/src/server-choice.ts?format=json
143 linesspeed 100%Last change speed in version 156,

143 lines from 3 changes in 3 versions.

speed155Every 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.Compare1// The --server flag (abso-core issue 10). Every command that talks to a server takes --server <url>, parsed and
2// checked here the same way for all of them:
3// - A command that works on a joined folder ("folder") talks only to that folder's server. --server there must
4// name that same server; another one is refused, never swapped in, so the folder's work and key never go to
5// a server it wasn't joined on. Outside a joined folder it is refused too, with how to join one there.
6// - A command that picks a server for itself ("chosen": join, init, login, whoami and the rest about this box)
7// uses the one --server names, as given.
8// - A command that works on this machine only ("local") takes no --server, and says so.
9// A value that isn't an http or https URL (a user name, a query or a fragment included) is refused before any
10// call, as is an empty one.
speed156With nothing naming a server, the client now uses prod (https://api.abso.dev). Every command picks its server in one order: --server, else the joined folder's own server, else ABSO_SERVER, else prod. Which servers this box is signed in to no longer picks one, so a box signed in to staging and prod both, or to staging alone, goes to prod instead of refusing or quietly using staging; staging is a deliberate --server, a joined staging folder, or ABSO_SERVER. An explicit choice is used as given. A malformed ABSO_SERVER is refused like a malformed --server. When this box isn't signed in to the chosen server but is to others, whoami and join name them and how to pick one. Help states the order for every command that picks its server. For abso-core issue 9.Compare11//
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.
speed155Every 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.Compare19
20import { readFileSync } from "node:fs";
21import { type Parsed, UsageError } from "./args.ts";
22import { configPath, findRoot } from "./config.ts";
speed156With nothing naming a server, the client now uses prod (https://api.abso.dev). Every command picks its server in one order: --server, else the joined folder's own server, else ABSO_SERVER, else prod. Which servers this box is signed in to no longer picks one, so a box signed in to staging and prod both, or to staging alone, goes to prod instead of refusing or quietly using staging; staging is a deliberate --server, a joined staging folder, or ABSO_SERVER. An explicit choice is used as given. A malformed ABSO_SERVER is refused like a malformed --server. When this box isn't signed in to the chosen server but is to others, whoami and join name them and how to pick one. Help states the order for every command that picks its server. For abso-core issue 9.Compare23import { serverBase, TOKEN_SERVERS } from "./core.ts";
speed84whoami and doctor pick the server as join does After abso login --server <url>, whoami and doctor still looked at https://api.abso.dev outside a folder, so they said you weren't signed in, and doctor checked the wrong server. Both now take --server, then ABSO_SERVER, then the folder's 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 with --server, as join does. Help text says so. Test in client/test/doctor.test.ts.Compare24import { fromEnv } from "./env-names.ts";
speed155Every 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.Compare25
26/** How a command uses a server: its joined folder's, one it picks, or none. */
27export type ServerUse = "folder" | "chosen" | "local";
speed156With nothing naming a server, the client now uses prod (https://api.abso.dev). Every command picks its server in one order: --server, else the joined folder's own server, else ABSO_SERVER, else prod. Which servers this box is signed in to no longer picks one, so a box signed in to staging and prod both, or to staging alone, goes to prod instead of refusing or quietly using staging; staging is a deliberate --server, a joined staging folder, or ABSO_SERVER. An explicit choice is used as given. A malformed ABSO_SERVER is refused like a malformed --server. When this box isn't signed in to the chosen server but is to others, whoami and join name them and how to pick one. Help states the order for every command that picks its server. For abso-core issue 9.Compare29/** The server a command goes to when nothing names one: prod. */
30export const PROD_SERVER = TOKEN_SERVERS[0]!;
32/** The order of precedence, in the words help uses. */
33export 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 */
39export function chooseServer(
speed84whoami and doctor pick the server as join does After abso login --server <url>, whoami and doctor still looked at https://api.abso.dev outside a folder, so they said you weren't signed in, and doctor checked the wrong server. Both now take --server, then ABSO_SERVER, then the folder's 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 with --server, as join does. Help text says so. Test in client/test/doctor.test.ts.Compare40 flag: string | undefined,
41 cwd: string,
42 env: Readonly<Record<string, string | undefined>>,
speed156With nothing naming a server, the client now uses prod (https://api.abso.dev). Every command picks its server in one order: --server, else the joined folder's own server, else ABSO_SERVER, else prod. Which servers this box is signed in to no longer picks one, so a box signed in to staging and prod both, or to staging alone, goes to prod instead of refusing or quietly using staging; staging is a deliberate --server, a joined staging folder, or ABSO_SERVER. An explicit choice is used as given. A malformed ABSO_SERVER is refused like a malformed --server. When this box isn't signed in to the chosen server but is to others, whoami and join name them and how to pick one. Help states the order for every command that picks its server. For abso-core issue 9.Compare43): 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;
speed155Every 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.Compare52/** The commands that pick a server for themselves rather than use a joined folder's. */
53const CHOSEN: ReadonlySet<string> = new Set([
54 "init",
55 "join",
56 "key",
57 "login",
58 "box",
59 "whoami",
60 "doctor",
61 "logout",
62 "orgs",
63 "org",
64]);
66/** The commands that never talk to a server. */
67const LOCAL: ReadonlySet<string> = new Set(["skill", "check-ignore", "pause", "resume", "fix-eol"]);
69/** How `command` uses a server. Anything not named above works on a joined folder. */
70export function serverUse(command: string): ServerUse {
71 return CHOSEN.has(command) ? "chosen" : LOCAL.has(command) ? "local" : "folder";
74const EXAMPLE = "https://api.abso.dev";
76/** `value` as a server, or a refusal naming where it came from (--server, ABSO_SERVER). */
77export function checkedServer(value: string, from: string): string {
78 const v = value.trim();
79 if (v === "") throw new UsageError(`${from} needs a server's URL, like ${EXAMPLE}`);
80 if (serverBase(v) === undefined)
81 throw new UsageError(
82 `${from} takes an http or https URL with no user name, query or fragment, like ${EXAMPLE} (got ${JSON.stringify(value)})`,
83 );
84 return v;
87/** The server --server names, checked, or undefined when it isn't given. */
88export function serverFlag(args: Parsed): string | undefined {
89 const v = args.flags.get("server");
90 return typeof v === "string" ? checkedServer(v, "--server") : undefined;
93/** Whether two servers are the same one: the same scheme, host, port and path, ignoring case and a trailing slash. */
94export function sameServer(a: string, b: string): boolean {
95 return (serverBase(a) ?? a.trim()) === (serverBase(b) ?? b.trim());
98/** The server in the .abso/config.json of the folder `cwd` is in, or undefined outside one (or when it can't be read). */
99export function folderServer(cwd: string): string | undefined {
100 const root = findRoot(cwd);
101 if (root === undefined) return undefined;
102 try {
103 const server = (JSON.parse(readFileSync(configPath(root), "utf8")) as { server?: unknown }).server;
104 return typeof server === "string" && server !== "" ? server : undefined;
105 } catch {
106 return undefined;
107 }
110/**
111 * For a command that works on a joined folder: refuses a --server that isn't the folder's own server, and one
112 * given outside a joined folder. Nothing is sent before this.
113 */
114export function checkFolderServer(command: string, flag: string, cwd: string): void {
115 const own = folderServer(cwd);
116 if (own === undefined)
117 throw new UsageError(
118 `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.`,
119 );
120 if (!sameServer(own, flag))
121 throw new UsageError(
122 `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}).`,
123 );
126/** What help says about --server for a command, the same words for every command of a kind. */
127export function serverHelp(command: string): string | undefined {
128 switch (serverUse(command)) {
129 case "local":
130 return undefined;
131 case "folder":
132 return "--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.";
133 case "chosen":
134 return command === "key"
135 ? "--server <url>: the server the key is for; without it, this folder's. It is used as given, never swapped for another."
speed156With nothing naming a server, the client now uses prod (https://api.abso.dev). Every command picks its server in one order: --server, else the joined folder's own server, else ABSO_SERVER, else prod. Which servers this box is signed in to no longer picks one, so a box signed in to staging and prod both, or to staging alone, goes to prod instead of refusing or quietly using staging; staging is a deliberate --server, a joined staging folder, or ABSO_SERVER. An explicit choice is used as given. A malformed ABSO_SERVER is refused like a malformed --server. When this box isn't signed in to the chosen server but is to others, whoami and join name them and how to pick one. Help states the order for every command that picks its server. For abso-core issue 9.Compare136 : `--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.`;
speed155Every 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.Compare137 }
140/** The refusal for --server on a command that works on this machine only. */
141export function localRefusal(command: string): string {
142 return `abso ${command} works on this machine only and talks to no server, so it takes no --server`;