{"draft":null,"from":62,"to":63,"files":[{"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;"}],"unmatched":[]}