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 280 to 281

Compare

+46 −17 in 7 places
Lines 3–9 at 281 (were 3–9 at 280)
33import { randomUUID } from "node:crypto";
44import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
55import { join, relative, resolve } from "node:path";
6−import { Api, ApiError } from "./api.ts";
6+import { Api, ApiError, type SyncAnswer } from "./api.ts";
77import { bool, type Parsed, str, UsageError } from "./args.ts";
88import { writeKnownBlobs } from "./blobs.ts";
99import {
Lines 16–24 at 281 (were 16–24 at 280)
1616 readBox,
1717} from "./box.ts";
1818import { STARTING_ABSOIGNORE } from "./check-ignore.ts";
19−import { CLIENT_DIR } from "./client-version.ts";
19+import { builtCopy } from "./client-version.ts";
2020import { type Env, type Output, plural } from "./command-env.ts";
21−import { leftOutText, syncFolder, uploadBlobs } from "./commands.ts";
21+import { applyAnswer, leftOutText, pullAnswer, pullWritten, syncFolder, uploadBlobs } from "./commands.ts";
2222import {
2323 findRoot,
2424 installKey,
Lines 32–38 at 281 (were 32–38 at 280)
3232import { elsewhereText } from "./doctor.ts";
3333import { fromEnv } from "./env-names.ts";
3434import { clearKnown, loadIgnore, readFolder, writeKnown } from "./folder.ts";
35−import { modInstalled } from "./install.ts";
35+import { installerCommand, modInstalled } from "./install.ts";
3636import { type FullMode, foldModes, writeKnownModes } from "./modes.ts";
3737import { initInOrg, siteOf } from "./orgs.ts";
3838import { projectFileName, readProjectFile, startingProjectFileText, writeStartingProjectFile } from "./project-file.ts";
Lines 141–160 at 281 (were 141–152 at 280)
141141 say(`Signing in with ${credential?.words ?? `no credential: nothing here signs in to ${server}`}.
142142`);
143143 const api = new Api({ ...config, ...(token ? { token } : {}) });
144− await uploadBlobs(api, blobs);
145− const answer = await api.init(
146− Object.fromEntries(files),
147− modes,
148− Object.fromEntries([...blobs].map(([rel, b]) => [rel, b.sha])),
149− );
144+ let answer: Awaited<ReturnType<Api["init"]>>;
145+ try {
146+ await uploadBlobs(api, blobs);
147+ answer = await api.init(
148+ Object.fromEntries(files),
149+ modes,
150+ Object.fromEntries([...blobs].map(([rel, b]) => [rel, b.sha])),
151+ );
152+ } catch (error) {
153+ // No project was made: the starting files init wrote go too, so the folder is as it was.
154+ if (wroteIgnore) rmSync(absoignore, { force: true });
155+ if (typeof wroteProject !== "string") rmSync(join(root, projectFileName(root)), { force: true });
156+ throw error;
157+ }
150158 writeConfig(root, config);
151159 clearKnown(root);
152160 for (const [rel, text] of files) writeKnown(root, rel, text);
Lines 359–374 at 281 (were 351–356 at 280)
351359 };
352360}
353361
362+/** A join that failed before writing files: its state goes, but a key (already here, or made for it) stays for the next try. */
363+function takeBackJoin(root: string): void {
364+ const dir = stateDir(root);
365+ if (!existsSync(join(dir, "key"))) {
366+ rmSync(dir, { recursive: true, force: true });
367+ return;
368+ }
369+ for (const entry of readdirSync(dir)) if (entry !== "key") rmSync(join(dir, entry), { recursive: true, force: true });
370+}
354372export async function runJoin(args: Parsed, env: Env): Promise<Output> {
355373 if (args.positionals.length !== 1) throw new UsageError("join takes the project name: abso join <project>");
356374 const project = args.positionals[0]!;
Lines 417–450 at 281 (were 399–423 at 280)
399417 clearKnown(root);
400418 if (minted) installKey(root, JSON.stringify(minted));
401419 // The token file only with --token-file: readConfig reads it otherwise.
402− const read = readConfig(root, env.env, false);
420+ let read: ReturnType<typeof readConfig>;
421+ try {
422+ read = readConfig(root, env.env, false);
423+ } catch (error) {
424+ takeBackJoin(root);
425+ throw error;
426+ }
403427 const settings = tokenFileAsked ? { ...read, token: credential?.token } : read;
404428 (env.writeErr ?? env.write)(
405429 `Signing in with ${minted && box ? `a new key from this box's sign-in, ${box.id}` : hasKey ? "this folder's key" : (credential?.words ?? `no credential: nothing here signs in to ${server}`)}.
406430`,
407431 );
408432 const api = new Api(settings);
409− let synced: Awaited<ReturnType<typeof syncFolder>>;
433+ let answer: SyncAnswer;
410434 try {
411435 // Before the sync, so the server never takes a record from this folder.
412436 if (reader) await api.reader(true);
413437 // Every file, even when the server has seen this agent sync before: its plain sync answer would hold only what changed since (#37).
414− synced = await syncFolder(root, api, true);
438+ answer = await pullAnswer(root, api, true);
415439 } catch (error) {
440+ // Nothing is written yet: take back what join wrote so it can run again here.
441+ takeBackJoin(root);
416442 if (!(error instanceof ApiError && error.status === 401 && !box && !settings.token)) throw error;
417− rmSync(stateDir(root), { recursive: true, force: true });
418443 const why = await signedOut(config.server, project);
419444 throw new UsageError(!tokenFileAsked && tokenFile() !== undefined ? `${why} ${TOKEN_FILE_ASKED}` : why);
420445 }
446+ const synced = await applyAnswer(root, api, answer);
447+ pullWritten(root);
421448 return {
422449 text: [
423450 `Joined ${project} as ${config.agent} at version ${synced.version}: wrote ${plural(synced.written.length, "file")} into ${root}.${reader ? " It is a reader: status, pull, log, show, files and export work, and nothing it does is recorded or pushed." : ""}${minted ? ` It signs in with its own key, ${minted.id}, made from this box's sign-in.` : ""}`,
Lines 481–489 at 281 (were 454–460 at 280)
454481}
455482
456483function hookHint(env: Readonly<Record<string, string | undefined>>): string {
457− return modInstalled(env)
458− ? "Edits made by Claude Code here are recorded by the abso mod on this machine, signed in as this folder. Anything else: abso record."
459− : `Edits made by Claude Code reach the server through the abso mod, which isn't on this machine yet: node ${join(CLIENT_DIR, "install-mod.ts")} installs it, and new chats load it. Anything else: abso record.`;
484+ if (modInstalled(env))
485+ return "Edits made by Claude Code here are recorded by the abso mod on this machine, signed in as this folder. Anything else: abso record.";
486+ // A built copy (the npm package) has no installer to point at (abso-core 18).
487+ if (builtCopy()) return "abso record sends the edits made here, whoever made them.";
488+ return `Edits made by Claude Code reach the server through the abso mod, which isn't on this machine yet: ${installerCommand("install-mod.ts")} installs it, and new chats load it. Anything else: abso record.`;
460489}
MCP
compare on this site's /mcp
CLI
abso diff 280 281 client/src/join-commands.ts --json
JSON
/christopher/abso-core/compare/280..281?file=client%2Fsrc%2Fjoin-commands.ts&format=json