{"version":64,"agent":"trials","message":"join: a folder prepared with abso key install --server is joined where it is again (Pinch's catch on 63).\n\n- --agent keeps 'here' as the default, as before 63, so scripts that join into a prepared folder still do. The ./<project> rule is only for a join with no --agent.\n- A folder holding only abso's own state folder (.abso, or the older .avcs) counts as empty.\n- New tests: joinFolder's rule (empty, only .abso, files here, --agent, --dir, a taken ./<project>), and a runJoin test that installs a key with --server and joins with --agent and no --dir: it joins here and sends that key (the shared token is wrong, so only the key gets through). The git line-endings test is back to joining without --dir.\n- Issue numbers taken out of the new code comments and test names.","time":1791601975047,"timeIso":"2026-10-10T03:12:55.047Z","changes":4,"change":818,"files":["client/src/box.ts","client/src/join-commands.ts","client/test/box.test.ts","client/test/client.test.ts"],"draft":null,"diff":[{"path":"client/src/box.ts","added":2,"removed":2,"diff":"--- a/client/src/box.ts\n+++ b/client/src/box.ts\n@@ -277,13 +277,13 @@\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+/** The agent name abso join takes when none is given: 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+ * abso join with no --agent: 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."},{"path":"client/src/join-commands.ts","added":10,"removed":7,"diff":"--- a/client/src/join-commands.ts\n+++ b/client/src/join-commands.ts\n@@ -18,10 +18,10 @@\n import { type FullMode, foldModes, writeKnownModes } from \"./modes.ts\";\n import { projectFileName, readProjectFile, startingProjectFileText, writeStartingProjectFile } from \"./project-file.ts\";\n import { refusedText } from \"./safety.ts\";\n-import { stateDir } from \"./state-dir.ts\";\n+import { OLD_STATE_DIR, STATE_DIR, stateDir } from \"./state-dir.ts\";\n \n /**\n- * The server to join or start on (abso issue 349): --server, then ABSO_SERVER, then the server this box is signed in\n+ * The server to join or start on: --server, then ABSO_SERVER, then the server this box is signed in\n  * to (abso login wrote it), then https://api.abso.dev. A box signed in to more than one server has to say which.\n  */\n export function serverFrom(args: Parsed, env: Pick<Env, \"env\">, home?: string): string {\n@@ -106,13 +106,16 @@\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+ * Where abso join writes: --dir, else here when --agent is given (as before, so a folder prepared with\n+ * abso key install --server is joined where its key is). With no --agent: here when this folder is empty, else\n+ * ./<project>, which has to be new or empty so nobody's files are written over. A folder holding only abso's own\n+ * state folder counts as empty.\n  */\n-function joinFolder(args: Parsed, env: Env, project: string): string {\n+export function joinFolder(args: Parsed, env: Pick<Env, \"cwd\">, 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 (str(args, \"agent\") !== undefined) return resolve(env.cwd);\n+\tconst empty = (path: string) => readdirSync(path).every((name) => name === STATE_DIR || name === OLD_STATE_DIR);\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@@ -140,7 +143,7 @@\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\t// No --agent: 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());"},{"path":"client/test/box.test.ts","added":2,"removed":2,"diff":"--- a/client/test/box.test.ts\n+++ b/client/test/box.test.ts\n@@ -284,7 +284,7 @@\n \tassert.equal(forgetBox(SERVER, h), false);\n });\n \n-test(\"join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev (abso issue 349)\", () => {\n+test(\"join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev\", () => {\n \tconst h = home();\n \tconst args = (server?: string) => ({ positionals: [], flags: new Map(server ? [[\"server\", server]] : []) });\n \tconst none = { env: {} };\n@@ -307,7 +307,7 @@\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+test(\"join with no --agent takes the box's name, skips names this box holds, and moves past a taken one\", async () => {\n \tconst seen: Seen = [];\n \tconst fetcher = server(\n \t\t["},{"path":"client/test/client.test.ts","added":46,"removed":20,"diff":"--- a/client/test/client.test.ts\n+++ b/client/test/client.test.ts\n@@ -23,7 +23,7 @@\n import { createServer as createHttpServer } from \"node:http\";\n import { type AddressInfo, createServer as createTcpServer } from \"node:net\";\n import { tmpdir } from \"node:os\";\n-import { dirname, join, relative, sep } from \"node:path\";\n+import { dirname, join, relative, resolve, sep } from \"node:path\";\n import { after, before, describe, it } from \"node:test\";\n import { fileURLToPath } from \"node:url\";\n import { Api, LOG_PAGE, PUBLISH_TIMEOUT_MS, timeoutFor } from \"../src/api.ts\";\n@@ -33,6 +33,7 @@\n import { restoreLines, sinceTest } from \"../src/changes.ts\";\n import { ciText } from \"../src/ci.ts\";\n import { collisionText, parallelScript, runCommand, sameVersionHint, undoGitBashPaths } from \"../src/commands.ts\";\n+import { installKey } from \"../src/config.ts\";\n import {\n \tisLocalOnly,\n \tisSkippedPart,\n@@ -48,6 +49,7 @@\n import { unifiedDiff } from \"../src/diff.ts\";\n import { absolute, knownPath, unrecorded, writeFileAtomic } from \"../src/folder.ts\";\n import { runHook } from \"../src/hook.ts\";\n+import { joinFolder } from \"../src/join-commands.ts\";\n import { tryFolderLock } from \"../src/lock.ts\";\n import { boxServer, commandTable, main } from \"../src/main.ts\";\n import { argvFor, confineCall, mcpTools } from \"../src/mcp.ts\";\n@@ -525,7 +527,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, \"--dir\", \".\")).exit, 0);\n+\t\tassert.equal((await avcs(bob, \"join\", name, \"--agent\", \"bob\", \"--server\", fake.url)).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,29 +2544,53 @@\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+\tit(\"join with no --agent writes here when this folder is empty, else into ./<project>, never over someone's files\", () => {\n+\t\tconst args = (...words: string[]) => parseArgs(\"join\", [\"p\", ...words], { agent: \"string\", dir: \"string\" });\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\tassert.equal(joinFolder(args(), { cwd: empty }, \"p\"), resolve(empty));\n+\t\tconst prepared = temp();\n+\t\tmkdirSync(join(prepared, \".abso\"));\n+\t\tassert.equal(joinFolder(args(), { cwd: prepared }, \"p\"), resolve(prepared), \"only abso's own folder: still empty\");\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\tassert.equal(joinFolder(args(), { cwd: busy }, \"p\"), resolve(busy, \"p\"), \"files here: ./<project>\");\n+\t\tassert.equal(joinFolder(args(\"--agent\", \"bob\"), { cwd: busy }, \"p\"), resolve(busy), \"--agent: here, as before\");\n+\t\tassert.equal(joinFolder(args(\"--dir\", \"x\"), { cwd: busy }, \"p\"), resolve(busy, \"x\"));\n+\t\twrite(busy, { \"p/other.md\": \"theirs\\n\" });\n+\t\tassert.throws(\n+\t\t\t() => joinFolder(args(), { cwd: busy }, \"p\"),\n+\t\t\t/already has files in it: say where to join with --dir <folder>/,\n+\t\t);\n \t});\n \n+\tit(\"join --agent joins a folder prepared with abso key install --server where it is, and sends that key\", async () => {\n+\t\tconst KEY = \"abso_sk_prepared-before-join-0123456789\";\n+\t\tconst keyed = await startFake(0, KEY);\n+\t\ttry {\n+\t\t\tconst seed = temp();\n+\t\t\twrite(seed, { \"a.ts\": \"one\\n\" });\n+\t\t\tconst env = { ...ENV, AVCS_TOKEN: KEY };\n+\t\t\tconst init = await main([\"init\", \"--server\", keyed.url, \"--project\", \"prep\", \"--agent\", \"alice\"], {\n+\t\t\t\tcwd: seed,\n+\t\t\t\tenv,\n+\t\t\t\twrite: () => {},\n+\t\t\t});\n+\t\t\tassert.equal(init.exit, 0, init.stderr);\n+\t\t\tconst dir = temp();\n+\t\t\tinstallKey(dir, JSON.stringify({ key: KEY, id: \"k_0123abcd\" }), keyed.url);\n+\t\t\tconst joined = await main([\"join\", \"prep\", \"--agent\", \"bob\", \"--server\", keyed.url], {\n+\t\t\t\tcwd: dir,\n+\t\t\t\tenv: { ...ENV, AVCS_TOKEN: \"not-the-key\" },\n+\t\t\t\twrite: () => {},\n+\t\t\t});\n+\t\t\tassert.equal(joined.exit, 0, joined.stderr);\n+\t\t\tassert.equal(read(dir, \"a.ts\"), \"one\\n\", \"joined here, not in ./prep\");\n+\t\t\tassert.doesNotMatch(joined.stdout, /^cd /m);\n+\t\t} finally {\n+\t\t\tawait keyed.close();\n+\t\t}\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}