{"version":63,"agent":"trials","message":"abso join <project> works with no --agent and no --dir (abso issue 351), so the project page can show npx abso-cli join <project>.\n\n- 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.\n- Folder: --dir, else here when empty, else ./<project>, which must be new or empty; it prints cd <folder> when it isn't here.\n- --agent, --dir and --server still win. Project names are checked before use as a folder.\nTests: 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.","time":1791601556423,"timeIso":"2026-10-10T03:05:56.423Z","changes":5,"change":810,"files":["client/src/box.ts","client/src/join-commands.ts","client/src/main.ts","client/test/box.test.ts","client/test/client.test.ts"],"draft":null,"diff":[{"path":"client/src/box.ts","added":44,"removed":0,"diff":"--- a/client/src/box.ts\n+++ b/client/src/box.ts\n@@ -277,6 +277,50 @@\n \treturn { key, id };\n }\n \n+/** The agent name abso join takes when none is given (abso issue 351): the box's name, lower-cased. */\n+export function defaultAgentName(): string {\n+\treturn boxName().toLowerCase();\n+}\n+\n+/**\n+ * abso join with no --agent (abso issue 351): mints a key under `base`, else `base`-2, -3 and so on. Names this\n+ * box already holds in the project are skipped without asking, since minting one again would replace that agent's\n+ * key and cut off its folder. A name the server says is taken (409) moves on to the next; any other refusal, the\n+ * box's agent limit among them, is said as it is.\n+ */\n+export async function mintFreeName(\n+\trecord: BoxRecord,\n+\tproject: string,\n+\tbase: string,\n+\tfetcher: typeof fetch = fetch,\n+\ttries = 20,\n+): Promise<{ key: string; id: string; agent: string }> {\n+\tconst box = await boxGet(record, \"/box\", fetcher);\n+\tif (box.status !== 200)\n+\t\tthrow new UsageError(\n+\t\t\t`${originOf(record.server)} refused (${box.status}): ${String(box.body.error ?? \"no reason given\")}`,\n+\t\t);\n+\tconst agents = Array.isArray(box.body.agents) ? (box.body.agents as { project?: unknown; agent?: unknown }[]) : [];\n+\tconst held = new Set(agents.filter((a) => a.project === project).map((a) => String(a.agent)));\n+\tfor (let n = 1; n <= tries; n++) {\n+\t\tconst agent = n === 1 ? base : `${base}-${n}`;\n+\t\tif (held.has(agent)) continue;\n+\t\ttry {\n+\t\t\treturn { ...(await mintKey(record, project, agent, fetcher)), agent };\n+\t\t} catch (err) {\n+\t\t\tif (err instanceof UsageError && /refused \\(409\\): that agent name/.test(err.message)) continue;\n+\t\t\tif (err instanceof UsageError && /refused \\(409\\): this box is at its agent limit/.test(err.message))\n+\t\t\t\tthrow new UsageError(\n+\t\t\t\t\t`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`,\n+\t\t\t\t);\n+\t\t\tthrow err;\n+\t\t}\n+\t}\n+\tthrow new UsageError(\n+\t\t`${base} through ${base}-${tries} are all taken in ${project}: give this agent a name with --agent <name>`,\n+\t);\n+}\n+\n /** Ends the box on the server, then forgets it here. Forgets it even when the server can't be reached. */\n export async function logout(record: BoxRecord, fetcher: typeof fetch = fetch, home = homedir()): Promise<boolean> {\n \tlet ended = true;"},{"path":"client/src/join-commands.ts","added":45,"removed":11,"diff":"--- a/client/src/join-commands.ts\n+++ b/client/src/join-commands.ts\n@@ -1,11 +1,11 @@\n // abso init and abso join: start a project from a folder, or join one into a folder.\n \n-import { existsSync, mkdirSync, rmSync, statSync, writeFileSync } from \"node:fs\";\n-import { join, resolve } from \"node:path\";\n+import { existsSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from \"node:fs\";\n+import { join, relative, resolve } from \"node:path\";\n import { Api, ApiError } from \"./api.ts\";\n import { bool, type Parsed, str, UsageError } from \"./args.ts\";\n import { writeKnownBlobs } from \"./blobs.ts\";\n-import { mintKey, readBox, signedInServers } from \"./box.ts\";\n+import { defaultAgentName, mintFreeName, mintKey, readBox, signedInServers } from \"./box.ts\";\n import { STARTING_ABSOIGNORE } from \"./check-ignore.ts\";\n import { CLIENT_DIR } from \"./client-version.ts\";\n import { type Env, type Output, plural } from \"./command-env.ts\";\n@@ -33,10 +33,12 @@\n \treturn signedIn[0] ?? TOKEN_SERVERS[0]!;\n }\n \n+const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n+\n function agentFrom(args: Parsed): string {\n \tconst agent = str(args, \"agent\");\n \tif (!agent) throw new UsageError(\"give this folder's agent name with --agent <name>\");\n-\tif (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(agent))\n+\tif (!NAME.test(agent))\n \t\tthrow new UsageError(`agent names are letters, digits, dot, dash and underscore (got ${JSON.stringify(agent)})`);\n \treturn agent;\n }\n@@ -103,18 +105,49 @@\n \t};\n }\n \n+/**\n+ * Where abso join writes (abso issue 351): --dir, else here when this folder is empty, else ./<project>, which has\n+ * to be new or empty so nobody's files are written over.\n+ */\n+function joinFolder(args: Parsed, env: Env, project: string): string {\n+\tconst dir = str(args, \"dir\");\n+\tif (dir !== undefined) return resolve(env.cwd, dir);\n+\tconst empty = (path: string) => readdirSync(path).length === 0;\n+\tif (empty(env.cwd)) return resolve(env.cwd);\n+\tconst sub = resolve(env.cwd, project);\n+\tif (existsSync(sub) && (!statSync(sub).isDirectory() || !empty(sub)))\n+\t\tthrow new UsageError(`${sub} already has files in it: say where to join with --dir <folder>`);\n+\treturn sub;\n+}\n+\n export async function runJoin(args: Parsed, env: Env): Promise<Output> {\n-\tif (args.positionals.length !== 1)\n-\t\tthrow new UsageError(\"join takes the project name: abso join <project> --agent <name>\");\n+\tif (args.positionals.length !== 1) throw new UsageError(\"join takes the project name: abso join <project>\");\n \tconst project = args.positionals[0]!;\n-\tconst root = resolve(env.cwd, str(args, \"dir\") ?? \".\");\n+\tif (!NAME.test(project))\n+\t\tthrow new UsageError(\n+\t\t\t`project names are letters, digits, dot, dash and underscore (got ${JSON.stringify(project)})`,\n+\t\t);\n+\tconst root = joinFolder(args, env, project);\n \tmkdirSync(root, { recursive: true });\n \tif (findRoot(root) === root) throw new UsageError(`${root} already has .abso/config.json`);\n \tconst reader = bool(args, \"reader\");\n-\tconst config = { ...makeSettings(args, env, project), ...(reader ? { reader: true } : {}) };\n-\tconst box = readBox(config.server);\n-\tconst minted =\n-\t\tbox && !existsSync(join(stateDir(root), \"key\")) ? await mintKey(box, project, config.agent) : undefined;\n+\tconst server = serverFrom(args, env);\n+\tconst box = readBox(server);\n+\tconst hasKey = existsSync(join(stateDir(root), \"key\"));\n+\tlet agent: string;\n+\tlet minted: { key: string; id: string } | undefined;\n+\tif (str(args, \"agent\") !== undefined) {\n+\t\tagent = agentFrom(args);\n+\t\tminted = box && !hasKey ? await mintKey(box, project, agent) : undefined;\n+\t} else {\n+\t\t// abso issue 351: no --agent takes the box's name, or the next free -2, -3.\n+\t\tif (!box) throw new UsageError(\"abso login signs this box in first (or give --agent <name>)\");\n+\t\tif (hasKey) throw new UsageError(`${root} already has a key: give its agent's name with --agent <name>`);\n+\t\tconst free = await mintFreeName(box, project, defaultAgentName());\n+\t\tagent = free.agent;\n+\t\tminted = { key: free.key, id: free.id };\n+\t}\n+\tconst config = { server, project, agent, ...(reader ? { reader: true } : {}) };\n \twriteConfig(root, config);\n \tclearKnown(root);\n \tif (minted) installKey(root, JSON.stringify(minted));\n@@ -142,6 +175,7 @@\n \t\t\t\t: []),\n \t\t\t...setupHint(root),\n \t\t\thookHint(env.env),\n+\t\t\t...(root === resolve(env.cwd) ? [] : [`cd ${relative(env.cwd, root) || root}`]),\n \t\t].join(\"\\n\"),\n \t\tjson: {\n \t\t\tproject,"},{"path":"client/src/main.ts","added":2,"removed":2,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -262,9 +262,9 @@\n \t},\n \tjoin: {\n \t\tflags: { server: \"string\", agent: \"string\", dir: \"string\", reader: \"boolean\" },\n-\t\tusage: \"abso join <project> --agent <name> [--server <url>] [--dir <folder>] [--reader]\",\n+\t\tusage: \"abso join <project> [--agent <name>] [--dir <folder>] [--server <url>] [--reader]\",\n \t\tabout:\n-\t\t\t\"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.\",\n+\t\t\t\"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.\",\n \t\trun: runJoin,\n \t},\n \trecord: {"},{"path":"client/test/box.test.ts","added":33,"removed":0,"diff":"--- a/client/test/box.test.ts\n+++ b/client/test/box.test.ts\n@@ -13,6 +13,7 @@\n \tforgetBox,\n \tlogin,\n \tlogout,\n+\tmintFreeName,\n \tmintKey,\n \treadBox,\n \tsignedInServers,\n@@ -305,3 +306,35 @@\n \t);\n \tassert.equal(serverFrom(args(SERVER), none, h), SERVER, \"--server settles it\");\n });\n+\n+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 () => {\n+\tconst seen: Seen = [];\n+\tconst fetcher = server(\n+\t\t[\n+\t\t\t[200, { box_id: record.id, agents: [{ project: \"abso\", agent: \"snow\", key_id: \"k_0\" }] }],\n+\t\t\t[409, { error: \"that agent name is already in use in this project; pick a new one\" }],\n+\t\t\t[200, { key: \"abso_sk_new\", id: \"k_3\" }],\n+\t\t],\n+\t\tseen,\n+\t);\n+\tconst got = await mintFreeName(record, \"abso\", \"snow\", fetcher);\n+\tassert.deepEqual(got, { key: \"abso_sk_new\", id: \"k_3\", agent: \"snow-3\" });\n+\tassert.deepEqual(\n+\t\tseen.map((s) => [new URL(s.url).pathname, (s.body as { agent?: string } | null)?.agent ?? null]),\n+\t\t[\n+\t\t\t[\"/box\", null],\n+\t\t\t[\"/box/agent-key\", \"snow-2\"],\n+\t\t\t[\"/box/agent-key\", \"snow-3\"],\n+\t\t],\n+\t\t\"snow is this box's already: never minted again, which would replace its key\",\n+\t);\n+\n+\tconst limit = server(\n+\t\t[\n+\t\t\t[200, { box_id: record.id, agents: [] }],\n+\t\t\t[409, { error: \"this box is at its agent limit\" }],\n+\t\t],\n+\t\t[],\n+\t);\n+\tawait assert.rejects(mintFreeName(record, \"abso\", \"snow\", limit), /this box is at its agent limit \\(5\\)/);\n+});"},{"path":"client/test/client.test.ts","added":24,"removed":1,"diff":"--- a/client/test/client.test.ts\n+++ b/client/test/client.test.ts\n@@ -525,7 +525,7 @@\n \t\tgit(\"init\", \"-q\");\n \t\tgit(\"config\", \"core.autocrlf\", \"false\");\n \t\twrite(bob, { \".gitattributes\": \"*.txt eol=crlf\\n*.bin -text\\n\" });\n-\t\tassert.equal((await avcs(bob, \"join\", name, \"--agent\", \"bob\", \"--server\", fake.url)).exit, 0);\n+\t\tassert.equal((await avcs(bob, \"join\", name, \"--agent\", \"bob\", \"--server\", fake.url, \"--dir\", \".\")).exit, 0);\n \t\twrite(folders.alice!, { \"a.txt\": \"one\\ntwo\\n\", \"b.md\": \"one\\ntwo\\n\", \"c.bin\": \"x\\ny\\n\" });\n \t\tassert.equal((await avcs(folders.alice!, \"publish\", \"-m\", \"three files\")).exit, 0);\n \t\tassert.equal((await avcs(bob, \"sync\")).exit, 0);\n@@ -2542,6 +2542,29 @@\n \t\tassert.doesNotMatch(without.stdout, /Nothing is installed/);\n \t});\n \n+\tit(\"join writes here when this folder is empty, else into ./<project>, never over someone's files (abso issue 351)\", async () => {\n+\t\tconst { name } = await project({ \"a.ts\": \"one\\n\" }, \"alice\");\n+\t\tconst run = (cwd: string, agent: string) =>\n+\t\t\tmain([\"join\", name, \"--agent\", agent, \"--server\", fake.url], { cwd, env: ENV, write: () => {} });\n+\t\tconst empty = temp();\n+\t\tconst here = await run(empty, \"bob\");\n+\t\tassert.equal(here.exit, 0, here.stderr);\n+\t\tassert.equal(read(empty, \"a.ts\"), \"one\\n\", \"an empty folder: here\");\n+\t\tassert.doesNotMatch(here.stdout, /^cd /m);\n+\t\tconst busy = temp();\n+\t\twrite(busy, { \"notes.md\": \"mine\\n\" });\n+\t\tconst sub = await run(busy, \"carol\");\n+\t\tassert.equal(sub.exit, 0, sub.stderr);\n+\t\tassert.equal(read(join(busy, name), \"a.ts\"), \"one\\n\", \"a folder with files in it: ./<project>\");\n+\t\tassert.equal(read(busy, \"notes.md\"), \"mine\\n\");\n+\t\tassert.match(sub.stdout, new RegExp(`^cd ${name}$`, \"m\"));\n+\t\tconst taken = temp();\n+\t\twrite(taken, { \"notes.md\": \"mine\\n\", [`${name}/other.md`]: \"theirs\\n\" });\n+\t\tconst refused = await run(taken, \"dave\");\n+\t\tassert.notEqual(refused.exit, 0);\n+\t\tassert.match(refused.stderr, /already has files in it: say where to join with --dir <folder>/);\n+\t});\n+\n \tit(\"gives a call more time by what it sends: 1 s per 100 KB over the base (abso issue 34)\", () => {\n \t\tassert.equal(timeoutFor(30_000, undefined), 30_000);\n \t\tassert.equal(timeoutFor(30_000, \"{}\"), 30_000);"}],"ci":null}