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

Versions 62 to 63

Compare

+45 −11 in 4 places
Lines 1–11 at 63 (were 1–11 at 62)
11// abso init and abso join: start a project from a folder, or join one into a folder.
22
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";
55import { Api, ApiError } from "./api.ts";
66import { bool, type Parsed, str, UsageError } from "./args.ts";
77import { writeKnownBlobs } from "./blobs.ts";
8−import { mintKey, readBox, signedInServers } from "./box.ts";
8+import { defaultAgentName, mintFreeName, 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";
Lines 33–44 at 63 (were 33–42 at 62)
3333 return signedIn[0] ?? TOKEN_SERVERS[0]!;
3434}
3535
36+const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
3638function agentFrom(args: Parsed): string {
3739 const agent = str(args, "agent");
3840 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))
4042 throw new UsageError(`agent names are letters, digits, dot, dash and underscore (got ${JSON.stringify(agent)})`);
4143 return agent;
4244}
Lines 105–153 at 63 (were 103–120 at 62)
103105 };
104106}
105107
108+/**
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.
111+ */
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>`);
120+ return sub;
121+}
106123export 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>");
109125 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)})`,
129+ );
130+ const root = joinFolder(args, env, project);
111131 mkdirSync(root, { recursive: true });
112132 if (findRoot(root) === root) throw new UsageError(`${root} already has .abso/config.json`);
113133 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"));
137+ let agent: string;
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;
142+ } else {
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());
147+ agent = free.agent;
148+ minted = { key: free.key, id: free.id };
149+ }
150+ const config = { server, project, agent, ...(reader ? { reader: true } : {}) };
118151 writeConfig(root, config);
119152 clearKnown(root);
120153 if (minted) installKey(root, JSON.stringify(minted));
Lines 175–181 at 63 (were 142–147 at 62)
142175 : []),
143176 ...setupHint(root),
144177 hookHint(env.env),
178+ ...(root === resolve(env.cwd) ? [] : [`cd ${relative(env.cwd, root) || root}`]),
145179 ].join("\n"),
146180 json: {
147181 project,
MCP
compare on this site's /mcp
CLI
abso diff 62 63 client/src/join-commands.ts --json
JSON
/christopher/abso-core/compare/62..63?file=client%2Fsrc%2Fjoin-commands.ts&format=json