abso join <project> works with no --agent and no --dir (abso issue 351), so the project page can show npx abso-cli join <project>. Version 63 of shared· trials· Oct 10 (2026-10-10 03:05 UTC) · Not checked
Agent: the box's name (the hostname abso login sends), lower-cased; if taken, <name>-2, -3, up to 20 tries. Names this box already holds in the project (GET /box) are skipped without minting, since minting one again replaces that agent's key and would cut off its folder. A 409 for a taken name moves on; the agent-limit 409 says the limit and where to revoke. No box sign-in: abso login first, or --agent. Folder: --dir, else here when empty, else ./<project>, which must be new or empty; it prints cd <folder> when it isn't here. --agent, --dir and --server still win. Project names are checked before use as a folder. Tests: box.test.ts (mintFreeName: held name skipped, 409 moves on, agent limit), client.test.ts (empty folder, ./<project>, refusing a non-empty one); the git line-endings test now joins with --dir . since its folder has files.
Version 62 · Files at version 63
5 files, 148 lines added, 14 removed.
--- a/client/src/box.ts
+++ b/client/src/box.ts
@@ -277,6 +277,50 @@
277 277 return { key, id }; 280 + /** The agent name abso join takes when none is given (abso issue 351): the box's name, lower-cased. */ 281 + export function defaultAgentName(): string { 282 + return boxName().toLowerCase(); 286 + * abso join with no --agent (abso issue 351): mints a key under `base`, else `base`-2, -3 and so on. Names this 287 + * box already holds in the project are skipped without asking, since minting one again would replace that agent's 288 + * key and cut off its folder. A name the server says is taken (409) moves on to the next; any other refusal, the 289 + * box's agent limit among them, is said as it is. 291 + export async function mintFreeName( 295 + fetcher: typeof fetch = fetch, 297 + ): Promise<{ key: string; id: string; agent: string }> { 298 + const box = await boxGet(record, "/box", fetcher); 299 + if (box.status !== 200) 300 + throw new UsageError( 301 + `${originOf(record.server)} refused (${box.status}): ${String(box.body.error ?? "no reason given")}`, 303 + const agents = Array.isArray(box.body.agents) ? (box.body.agents as { project?: unknown; agent?: unknown }[]) : []; 304 + const held = new Set(agents.filter((a) => a.project === project).map((a) => String(a.agent))); 305 + for (let n = 1; n <= tries; n++) { 306 + const agent = n === 1 ? base : `${base}-${n}`; 307 + if (held.has(agent)) continue; 309 + return { ...(await mintKey(record, project, agent, fetcher)), agent }; 311 + if (err instanceof UsageError && /refused \(409\): that agent name/.test(err.message)) continue; 312 + if (err instanceof UsageError && /refused \(409\): this box is at its agent limit/.test(err.message)) 313 + throw new UsageError( 314 + `this box is at its agent limit (${record.grant.max_agents}): abso box shows its grant, and an agent can be revoked on the website's Boxes page`, 319 + throw new UsageError( 320 + `${base} through ${base}-${tries} are all taken in ${project}: give this agent a name with --agent <name>`, 280 324 /** Ends the box on the server, then forgets it here. Forgets it even when the server can't be reached. */ 281 325 export async function logout(record: BoxRecord, fetcher: typeof fetch = fetch, home = homedir()): Promise<boolean> { --- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -1,11 +1,11 @@
1 1 // abso init and abso join: start a project from a folder, or join one into a folder. 3 − import { existsSync, mkdirSync, rmSync, statSync, writeFileSync } from "node:fs";
4 − import { join, resolve } from "node:path";
3 + import { existsSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs"; 4 + import { join, relative, resolve } from "node:path"; 5 5 import { Api, ApiError } from "./api.ts"; 6 6 import { bool, type Parsed, str, UsageError } from "./args.ts"; 7 7 import { writeKnownBlobs } from "./blobs.ts"; 8 − import { mintKey, readBox, signedInServers } from "./box.ts";
8 + import { defaultAgentName, mintFreeName, mintKey, readBox, signedInServers } from "./box.ts"; 9 9 import { STARTING_ABSOIGNORE } from "./check-ignore.ts"; 10 10 import { CLIENT_DIR } from "./client-version.ts"; 11 11 import { type Env, type Output, plural } from "./command-env.ts"; @@ -33,10 +33,12 @@
33 33 return signedIn[0] ?? TOKEN_SERVERS[0]!; 36 + const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/; 36 38 function agentFrom(args: Parsed): string { 37 39 const agent = str(args, "agent"); 38 40 if (!agent) throw new UsageError("give this folder's agent name with --agent <name>"); 39 − if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(agent))
41 + if (!NAME.test(agent)) 40 42 throw new UsageError(`agent names are letters, digits, dot, dash and underscore (got ${JSON.stringify(agent)})`); @@ -103,18 +105,49 @@
109 + * Where abso join writes (abso issue 351): --dir, else here when this folder is empty, else ./<project>, which has 110 + * to be new or empty so nobody's files are written over. 112 + function joinFolder(args: Parsed, env: Env, project: string): string { 113 + const dir = str(args, "dir"); 114 + if (dir !== undefined) return resolve(env.cwd, dir); 115 + const empty = (path: string) => readdirSync(path).length === 0; 116 + if (empty(env.cwd)) return resolve(env.cwd); 117 + const sub = resolve(env.cwd, project); 118 + if (existsSync(sub) && (!statSync(sub).isDirectory() || !empty(sub))) 119 + throw new UsageError(`${sub} already has files in it: say where to join with --dir <folder>`); 106 123 export async function runJoin(args: Parsed, env: Env): Promise<Output> { 107 − if (args.positionals.length !== 1)
108 − throw new UsageError("join takes the project name: abso join <project> --agent <name>");
124 + if (args.positionals.length !== 1) throw new UsageError("join takes the project name: abso join <project>"); 109 125 const project = args.positionals[0]!; 110 − const root = resolve(env.cwd, str(args, "dir") ?? ".");
126 + if (!NAME.test(project)) 127 + throw new UsageError( 128 + `project names are letters, digits, dot, dash and underscore (got ${JSON.stringify(project)})`, 130 + const root = joinFolder(args, env, project); 111 131 mkdirSync(root, { recursive: true }); 112 132 if (findRoot(root) === root) throw new UsageError(`${root} already has .abso/config.json`); 113 133 const reader = bool(args, "reader"); 114 − const config = { ...makeSettings(args, env, project), ...(reader ? { reader: true } : {}) };
115 − const box = readBox(config.server);
116 − const minted =
117 − box && !existsSync(join(stateDir(root), "key")) ? await mintKey(box, project, config.agent) : undefined;
134 + const server = serverFrom(args, env); 135 + const box = readBox(server); 136 + const hasKey = existsSync(join(stateDir(root), "key")); 138 + let minted: { key: string; id: string } | undefined; 139 + if (str(args, "agent") !== undefined) { 140 + agent = agentFrom(args); 141 + minted = box && !hasKey ? await mintKey(box, project, agent) : undefined; 143 + // abso issue 351: no --agent takes the box's name, or the next free -2, -3. 144 + if (!box) throw new UsageError("abso login signs this box in first (or give --agent <name>)"); 145 + if (hasKey) throw new UsageError(`${root} already has a key: give its agent's name with --agent <name>`); 146 + const free = await mintFreeName(box, project, defaultAgentName()); 148 + minted = { key: free.key, id: free.id }; 150 + const config = { server, project, agent, ...(reader ? { reader: true } : {}) }; 118 151 writeConfig(root, config); 120 153 if (minted) installKey(root, JSON.stringify(minted)); @@ -142,6 +175,7 @@
143 176 ...setupHint(root), 144 177 hookHint(env.env), 178 + ...(root === resolve(env.cwd) ? [] : [`cd ${relative(env.cwd, root) || root}`]), --- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -262,9 +262,9 @@
264 264 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>] [--dir <folder>] [--server <url>] [--reader]", 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.",
267 + "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 publishes.", --- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -13,6 +13,7 @@
@@ -305,3 +306,35 @@
306 307 assert.equal(serverFrom(args(SERVER), none, h), SERVER, "--server settles it"); 310 + test("join with no --agent takes the box's name, skips names this box holds, and moves past a taken one (abso issue 351)", async () => { 311 + const seen: Seen = []; 312 + const fetcher = server( 314 + [200, { box_id: record.id, agents: [{ project: "abso", agent: "snow", key_id: "k_0" }] }], 315 + [409, { error: "that agent name is already in use in this project; pick a new one" }], 316 + [200, { key: "abso_sk_new", id: "k_3" }], 320 + const got = await mintFreeName(record, "abso", "snow", fetcher); 321 + assert.deepEqual(got, { key: "abso_sk_new", id: "k_3", agent: "snow-3" }); 323 + seen.map((s) => [new URL(s.url).pathname, (s.body as { agent?: string } | null)?.agent ?? null]), 326 + ["/box/agent-key", "snow-2"], 327 + ["/box/agent-key", "snow-3"], 329 + "snow is this box's already: never minted again, which would replace its key", 332 + const limit = server( 334 + [200, { box_id: record.id, agents: [] }], 335 + [409, { error: "this box is at its agent limit" }], 339 + await assert.rejects(mintFreeName(record, "abso", "snow", limit), /this box is at its agent limit \(5\)/); --- a/client/test/client.test.ts
+++ b/client/test/client.test.ts
@@ -525,7 +525,7 @@
525 525 git("init", "-q"); 526 526 git("config", "core.autocrlf", "false"); 527 527 write(bob, { ".gitattributes": "*.txt eol=crlf\n*.bin -text\n" }); 528 − assert.equal((await avcs(bob, "join", name, "--agent", "bob", "--server", fake.url)).exit, 0);
528 + assert.equal((await avcs(bob, "join", name, "--agent", "bob", "--server", fake.url, "--dir", ".")).exit, 0); 529 529 write(folders.alice!, { "a.txt": "one\ntwo\n", "b.md": "one\ntwo\n", "c.bin": "x\ny\n" }); 530 530 assert.equal((await avcs(folders.alice!, "publish", "-m", "three files")).exit, 0); 531 531 assert.equal((await avcs(bob, "sync")).exit, 0); @@ -2542,6 +2542,29 @@
2542 2542 assert.doesNotMatch(without.stdout, /Nothing is installed/); 2545 + it("join writes here when this folder is empty, else into ./<project>, never over someone's files (abso issue 351)", async () => { 2546 + const { name } = await project({ "a.ts": "one\n" }, "alice"); 2547 + const run = (cwd: string, agent: string) => 2548 + main(["join", name, "--agent", agent, "--server", fake.url], { cwd, env: ENV, write: () => {} }); 2549 + const empty = temp(); 2550 + const here = await run(empty, "bob"); 2551 + assert.equal(here.exit, 0, here.stderr); 2552 + assert.equal(read(empty, "a.ts"), "one\n", "an empty folder: here"); 2553 + assert.doesNotMatch(here.stdout, /^cd /m); 2554 + const busy = temp(); 2555 + write(busy, { "notes.md": "mine\n" }); 2556 + const sub = await run(busy, "carol"); 2557 + assert.equal(sub.exit, 0, sub.stderr); 2558 + assert.equal(read(join(busy, name), "a.ts"), "one\n", "a folder with files in it: ./<project>"); 2559 + assert.equal(read(busy, "notes.md"), "mine\n"); 2560 + assert.match(sub.stdout, new RegExp(`^cd ${name}$`, "m")); 2561 + const taken = temp(); 2562 + write(taken, { "notes.md": "mine\n", [`${name}/other.md`]: "theirs\n" }); 2563 + const refused = await run(taken, "dave"); 2564 + assert.notEqual(refused.exit, 0); 2565 + assert.match(refused.stderr, /already has files in it: say where to join with --dir <folder>/); 2545 2568 it("gives a call more time by what it sends: 1 s per 100 KB over the base (abso issue 34)", () => { 2546 2569 assert.equal(timeoutFor(30_000, undefined), 30_000); 2547 2570 assert.equal(timeoutFor(30_000, "{}"), 30_000);