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 184 to 185

Compare

+121 −3 in 4 places
Lines 1–20 at 185 (were 1–11 at 184)
11// abso init and abso join: start a project from a folder, or join one into a folder.
22
3−import { existsSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
3+import { randomUUID } from "node:crypto";
4+import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
45import { join, relative, resolve } from "node:path";
56import { Api, ApiError } from "./api.ts";
67import { bool, type Parsed, str, UsageError } from "./args.ts";
78import { writeKnownBlobs } from "./blobs.ts";
8−import { defaultAgentName, mintFreeName, mintKey, readBox } from "./box.ts";
9+import {
10+ type BoxRecord,
11+ boxCreateProject,
12+ defaultAgentName,
13+ mintFreeName,
14+ mintKey,
15+ type NewProject,
16+ readBox,
17+} from "./box.ts";
918import { STARTING_ABSOIGNORE } from "./check-ignore.ts";
1019import { CLIENT_DIR } from "./client-version.ts";
1120import { type Env, type Output, plural } from "./command-env.ts";
Lines 25–31 at 185 (were 16–22 at 184)
1625import { clearKnown, loadIgnore, readFolder, writeKnown } from "./folder.ts";
1726import { modInstalled } from "./install.ts";
1827import { type FullMode, foldModes, writeKnownModes } from "./modes.ts";
19−import { siteOf } from "./orgs.ts";
28+import { initInOrg, siteOf } from "./orgs.ts";
2029import { projectFileName, readProjectFile, startingProjectFileText, writeStartingProjectFile } from "./project-file.ts";
2130import { refusedText } from "./safety.ts";
2231import { chooseServer, serverFlag } from "./server-choice.ts";
Lines 57–71 at 185 (were 48–53 at 184)
4857 if (findRoot(root) === root) throw new UsageError(`${root} already has .abso/config.json`);
4958 const project = str(args, "project");
5059 if (!project) throw new UsageError("give the project a name with --project <name>");
60+ if (bool(args, "public") && bool(args, "private")) throw new UsageError("--public or --private, not both");
61+ // A box signed in here, and no token for this server: the project is made as the person who approved the box,
62+ // the way the website makes one (abso 663).
63+ const server = serverFrom(args, env);
64+ const box = readBox(server);
65+ if (box && !tokenFor(server, env.env) && !fromEnv(env.env, "KEY_FILE"))
66+ return initFromBox(args, env, root, project, server, box);
67+ const org = str(args, "org");
68+ if (org !== undefined) return initInOrg(org, server);
5169 const config = makeSettings(args, env, project);
5270 const asIs = bool(args, "as-is");
5371 const absoignore = join(root, ".absoignore");
Lines 117–223 at 185 (were 99–105 at 184)
99117 };
100118}
101119
120+/** The most a new project's folder may be from a box: the server takes a body up to 25 MB, base64 and JSON included. */
121+const BOX_INIT_MAX = 24 * 1024 * 1024;
122+/** The Idempotency-Key of an abso init that didn't finish, so running it again makes the same project (abso 663). */
123+const INIT_KEY = "init-key";
102125/**
126+ * abso init from a signed-in box (abso 663): the server makes the project as the person who approved the box, the way the
127+ * website's New project does (owner, visibility, address), with the folder as its first version. This folder then
128+ * joins it like abso join, with its own key from the box, so it works at once with no new approval.
129+ */
130+async function initFromBox(
131+ args: Parsed,
132+ env: Env,
133+ root: string,
134+ project: string,
135+ server: string,
136+ box: BoxRecord,
137+): Promise<Output> {
138+ if (!NAME.test(project))
139+ throw new UsageError(
140+ `project names are letters, digits, dot, dash and underscore (got ${JSON.stringify(project)})`,
141+ );
142+ const named = str(args, "agent");
143+ if (named !== undefined) agentFrom(args);
144+ const asIs = bool(args, "as-is");
145+ const absoignore = join(root, ".absoignore");
146+ const wroteIgnore = !asIs && !existsSync(absoignore) && !existsSync(join(root, ".avcsignore"));
147+ if (wroteIgnore) writeFileSync(absoignore, STARTING_ABSOIGNORE);
148+ const wroteProject = asIs ? "exists" : writeStartingProjectFile(root);
149+ const { files, blobs, leftOut } = readFolder(root, loadIgnore(root));
150+ const listed: NonNullable<NewProject["files"]>[number][] = [
151+ ...[...files].map(([path, text]) => ({ path, text })),
152+ ...[...blobs].map(([path, b]) => ({ path, base64: Buffer.from(b.bytes).toString("base64") })),
153+ ];
154+ const org = str(args, "org");
155+ const body: NewProject = {
156+ name: project,
157+ ...(org === undefined ? {} : { owner: org }),
158+ ...(bool(args, "public")
159+ ? { visibility: "public" as const }
160+ : bool(args, "private")
161+ ? { visibility: "private" as const }
162+ : {}),
163+ ...(listed.length > 0 ? { files: listed } : {}),
164+ };
165+ if (JSON.stringify(body).length > BOX_INIT_MAX)
166+ throw new UsageError(
167+ `${root} is over 24 MB to send. Make ${project} with abso init on a smaller folder (or on the website), then copy the rest in and push.`,
168+ );
169+ // One key per folder until it finishes: running the same abso init again is the same project, never a second.
170+ const keyPath = join(stateDir(root), INIT_KEY);
171+ let key = existsSync(keyPath) ? readFileSync(keyPath, "utf8").trim() : "";
172+ if (!/^[0-9a-f-]{36}$/.test(key)) {
173+ key = randomUUID();
174+ mkdirSync(stateDir(root), { recursive: true });
175+ writeFileSync(keyPath, key);
176+ }
177+ const made = await boxCreateProject(box, body, key);
178+ const visibility = typeof made.visibility === "string" ? made.visibility : "private";
179+ const minted =
180+ named !== undefined
181+ ? { ...(await mintKey(box, project, named)), agent: named }
182+ : await mintFreeName(box, project, defaultAgentName());
183+ const config = { server, project, agent: minted.agent };
184+ writeConfig(root, config);
185+ clearKnown(root);
186+ installKey(root, JSON.stringify({ key: minted.key, id: minted.id }));
187+ rmSync(keyPath, { force: true });
188+ const synced = await syncFolder(root, new Api(readConfig(root, env.env)), true);
189+ const owner = org ?? "you";
190+ return {
191+ text: [
192+ `Created project ${project} (${visibility}, owned by ${owner}) at version ${synced.version} from ${plural(listed.length, "file")} in ${root}.`,
193+ ...leftOutText(leftOut),
194+ ...(wroteIgnore
195+ ? ["Wrote a starting .absoignore (Claude Code state and operating system files); edit it like .gitignore."]
196+ : []),
197+ ...startingProjectFileText(wroteProject),
198+ `This folder is agent ${minted.agent}, with its own key, ${minted.id}, made from this box's sign-in. Settings are in .abso/config.json.`,
199+ ...refusedText(synced.refused),
200+ ...(synced.written.length > 0 ? [`Wrote ${plural(synced.written.length, "file")} from shared.`] : []),
201+ hookHint(env.env),
202+ ].join("\n"),
203+ json: {
204+ project,
205+ id: made.id ?? null,
206+ owner: made.owner ?? null,
207+ visibility,
208+ version: synced.version,
209+ files: listed.length,
210+ root,
211+ agent: minted.agent,
212+ key_id: minted.id,
213+ wroteAbsoignore: wroteIgnore,
214+ wroteProjectFile: typeof wroteProject === "string" ? null : wroteProject,
215+ leftOut,
216+ },
217+ };
218+}
220+/**
103221 * Where abso join writes: --dir, else here when --agent is given (as before, so a folder prepared with
104222 * abso key install --server is joined where its key is). With no --agent: here when this folder is empty, else
105223 * ./<project>, which has to be new or empty so nobody's files are written over. A folder holding only abso's own
MCP
compare on this site's /mcp
CLI
abso diff 184 185 client/src/join-commands.ts --json
JSON
/christopher/abso-core/compare/184..185?file=client%2Fsrc%2Fjoin-commands.ts&format=json