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
show on this site's /mcp
CLI
abso show 61 --json
JSON
/christopher/abso-core/versions/61?format=json

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.

of shared·trials··Not checked

Version 60 · Files at version 61

5 files, 80 lines added, 13 removed.

--- a/README.md
+++ b/README.md
@@ -63,7 +63,7 @@
6363Join a project once, in a folder of its own, under an agent name of its own:
6464
6565```bash
66−abso join <project> --agent <name> --server https://api.abso.dev --dir ./<name>
66+abso join <project> --agent <name> --dir ./<name>
6767cd <name>
6868```
6969
--- a/client/src/box.ts
+++ b/client/src/box.ts
@@ -9,11 +9,11 @@
99// which answer as the person who approved the box.
1010
1111import { createHash } from "node:crypto";
12−import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
12+import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1313import { homedir, hostname } from "node:os";
1414import { dirname, join } from "node:path";
1515import { UsageError } from "./args.ts";
16−import { homeFile, homeWritePath, OLD_STATE_DIR } from "./state-dir.ts";
16+import { homeFile, homeWritePath, OLD_STATE_DIR, STATE_DIR } from "./state-dir.ts";
1717
1818/** What the person who approved the code allowed: each project with the highest role its agents get there, and how many agents. */
1919export interface Grant {
@@ -59,6 +59,31 @@
5959 }
6060}
6161
62+/** The servers this box is signed in to and whose sign-in hasn't expired, from ~/.abso/boxes (and an older ~/.avcs/boxes). */
63+export function signedInServers(home = homedir(), now = Date.now()): string[] {
64+ const servers = new Set<string>();
65+ for (const dir of [STATE_DIR, OLD_STATE_DIR]) {
66+ let names: string[];
67+ try {
68+ names = readdirSync(join(home, dir, "boxes"));
69+ } catch {
70+ continue;
71+ }
72+ for (const name of names) {
73+ try {
74+ const server = (JSON.parse(readFileSync(join(home, dir, "boxes", name), "utf8")) as { server?: unknown })
75+ .server;
76+ if (typeof server !== "string") continue;
77+ const record = readBox(server, home);
78+ if (record && record.expiresAt > now) servers.add(originOf(record.server));
79+ } catch {
80+ // Not a sign-in this client wrote: left alone.
81+ }
82+ }
83+ }
84+ return [...servers].sort();
85+}
6287export function writeBox(record: BoxRecord, home = homedir()): void {
6388 const path = homeWritePath(home, "boxes", boxFile(record.server));
6489 mkdirSync(dirname(path), { recursive: true });
--- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -5,12 +5,13 @@
55import { Api, ApiError } from "./api.ts";
66import { bool, type Parsed, str, UsageError } from "./args.ts";
77import { writeKnownBlobs } from "./blobs.ts";
8−import { mintKey, readBox } from "./box.ts";
8+import { mintKey, readBox, signedInServers } from "./box.ts";
99import { STARTING_ABSOIGNORE } from "./check-ignore.ts";
1010import { CLIENT_DIR } from "./client-version.ts";
1111import { type Env, type Output, plural } from "./command-env.ts";
1212import { leftOutText, syncFolder, uploadBlobs } from "./commands.ts";
1313import { findRoot, installKey, readConfig, type Settings, tokenFor, writeConfig } from "./config.ts";
14+import { TOKEN_SERVERS } from "./core.ts";
1415import { fromEnv } from "./env-names.ts";
1516import { clearKnown, loadIgnore, readFolder, writeKnown } from "./folder.ts";
1617import { modInstalled } from "./install.ts";
@@ -19,10 +20,17 @@
1920import { refusedText } from "./safety.ts";
2021import { stateDir } from "./state-dir.ts";
2122
22−function serverFrom(args: Parsed, env: Env): string {
23− const server = str(args, "server") ?? fromEnv(env.env, "SERVER");
24− if (!server) throw new UsageError("give the server with --server <url> (or ABSO_SERVER)");
25− return server;
23+/**
24+ * The server to join or start on (abso issue 349): --server, then ABSO_SERVER, then the server this box is signed in
25+ * to (abso login wrote it), then https://api.abso.dev. A box signed in to more than one server has to say which.
26+ */
27+export function serverFrom(args: Parsed, env: Pick<Env, "env">, home?: string): string {
28+ const named = str(args, "server") ?? fromEnv(env.env, "SERVER");
29+ if (named) return named;
30+ const signedIn = signedInServers(home);
31+ if (signedIn.length > 1)
32+ throw new UsageError(`this box is signed in to ${signedIn.join(" and ")}: say which with --server <url>`);
33+ return signedIn[0] ?? TOKEN_SERVERS[0]!;
2634}
2735
2836function agentFrom(args: Parsed): string {
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -89,9 +89,9 @@
8989const COMMANDS: Readonly<Record<string, CommandDef>> = {
9090 init: {
9191 flags: { server: "string", project: "string", agent: "string", "as-is": "boolean", org: "string" },
92− usage: "abso init [folder] --server <url> --project <name> --agent <name> [--as-is] [--org <org>]",
92+ usage: "abso init [folder] [--server <url>] --project <name> --agent <name> [--as-is] [--org <org>]",
9393 about:
94− "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.",
94+ "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.",
9595 run: (args, env) => {
9696 const org = str(args, "org");
9797 return org === undefined ? runInit(args, env) : initInOrg(org, boxServer(args, env));
@@ -262,9 +262,9 @@
262262 },
263263 join: {
264264 flags: { server: "string", agent: "string", dir: "string", reader: "boolean" },
265− usage: "abso join <project> --agent <name> --server <url> [--dir <folder>] [--reader]",
265+ usage: "abso join <project> --agent <name> [--server <url>] [--dir <folder>] [--reader]",
266266 about:
267− "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.",
267+ "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.",
268268 run: runJoin,
269269 },
270270 record: {
--- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -7,7 +7,18 @@
77import { tmpdir } from "node:os";
88import { join } from "node:path";
99import { test } from "node:test";
10−import { boxPublic, boxText, forgetBox, login, logout, mintKey, readBox, writeBox } from "../src/box.ts";
10+import {
11+ boxPublic,
12+ boxText,
13+ forgetBox,
14+ login,
15+ logout,
16+ mintKey,
17+ readBox,
18+ signedInServers,
19+ writeBox,
20+} from "../src/box.ts";
21+import { serverFrom } from "../src/join-commands.ts";
1122
1223const SERVER = "https://staging.abso.example";
1324const CREDENTIAL = "abso_bx_the-secret-credential";
@@ -271,3 +282,26 @@
271282 assert.equal(readBox(SERVER, h), undefined);
272283 assert.equal(forgetBox(SERVER, h), false);
273284});
286+test("join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev (abso issue 349)", () => {
287+ const h = home();
288+ const args = (server?: string) => ({ positionals: [], flags: new Map(server ? [["server", server]] : []) });
289+ const none = { env: {} };
290+ assert.equal(serverFrom(args(), none, h), "https://api.abso.dev", "nothing signed in: the abso API");
291+ writeBox({ ...record, expiresAt: Date.now() + 1e6 }, h);
292+ assert.deepEqual(signedInServers(h), [SERVER]);
293+ assert.equal(serverFrom(args(), none, h), SERVER, "the server abso login signed this box in to");
294+ assert.deepEqual(signedInServers(h, Date.now() + 2e6), [], "an expired sign-in doesn't count");
295+ assert.equal(serverFrom(args(), { env: { ABSO_SERVER: "https://env.example" } }, h), "https://env.example");
296+ assert.equal(
297+ serverFrom(args("https://flag.example"), { env: { ABSO_SERVER: "https://env.example" } }, h),
298+ "https://flag.example",
299+ );
300+ writeBox({ ...record, server: "https://other.abso.example", expiresAt: Date.now() + 1e6 }, h);
301+ writeBox({ ...record, expiresAt: Date.now() + 1e6 }, h);
302+ assert.throws(
303+ () => serverFrom(args(), none, h),
304+ /signed in to https:\/\/other\.abso\.example and https:\/\/staging\.abso\.example: say which with --server/,
305+ );
306+ assert.equal(serverFrom(args(SERVER), none, h), SERVER, "--server settles it");
307+});