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 286 to 287

Compare

+80 −21 in 11 places
Lines 2–8 at 287 (were 2–8 at 286)
22
33import { randomUUID } from "node:crypto";
44import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
5−import { join, relative, resolve } from "node:path";
5+import { isAbsolute, join, relative, resolve, sep } from "node:path";
66import { Api, ApiError, type SyncAnswer } from "./api.ts";
77import { bool, type Parsed, str, UsageError } from "./args.ts";
88import { writeKnownBlobs } from "./blobs.ts";
Lines 33–39 at 287 (were 33–38 at 286)
3333import { fromEnv } from "./env-names.ts";
3434import { clearKnown, loadIgnore, readFolder, writeKnown } from "./folder.ts";
3535import { installerCommand, modInstalled } from "./install.ts";
36+import { LOCAL, NO_STORE, storeDir } from "./local-store.ts";
3637import { type FullMode, foldModes, writeKnownModes } from "./modes.ts";
3738import { initInOrg, siteOf } from "./orgs.ts";
3839import { projectFileName, readProjectFile, startingProjectFileText, writeStartingProjectFile } from "./project-file.ts";
Lines 102–149 at 287 (were 101–106 at 286)
101102 return undefined;
102103}
103104
105+/**
106+ * --local (abso init, abso join): the project's history is in a store on this machine, not on a server. The store is
107+ * --store, else ABSO_STORE, else the OS's data folder; one given with --store is kept in the folder's config.
108+ */
109+function localFrom(args: Parsed, env: Env, command: string): { dir: string; settings: { store?: string } } | undefined {
110+ const store = str(args, "store");
111+ if (!bool(args, "local")) {
112+ if (store !== undefined)
113+ throw new UsageError("--store goes with --local: it says where a local project's history is");
114+ return undefined;
115+ }
116+ if (str(args, "server") !== undefined)
117+ throw new UsageError("--local or --server, not both: a local project has no server");
118+ if (str(args, "org") !== undefined || bool(args, "public") || bool(args, "private") || bool(args, "reader"))
119+ throw new UsageError(
120+ `abso ${command} --local takes --project, --agent, --store and --as-is; a local project has no server to share it`,
121+ );
122+ const dir = storeDir(env.env, store, env.cwd);
123+ if (dir === undefined) throw new UsageError(NO_STORE);
124+ return { dir, settings: store === undefined ? {} : { store: dir } };
125+}
127+/** A store inside the project folder is left out of its files: a line in .absoignore. Its relative path, if so. */
128+function ignoreStoreInside(root: string, dir: string): string | undefined {
129+ const rel = relative(root, dir);
130+ if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) return undefined;
131+ const line = `/${rel.split(sep).join("/")}/`;
132+ const file = join(root, ".absoignore");
133+ const had = existsSync(file) ? readFileSync(file, "utf8") : "";
134+ const lines = had.split(/\r?\n/);
135+ if (!lines.includes(line)) {
136+ const gap = had === "" || had.endsWith("\n") ? "" : "\n";
137+ writeFileSync(file, `${had}${gap}${line}\n`);
138+ }
139+ return rel;
140+}
142+/** What init and join say about a local project's store. */
143+function localText(dir: string, project: string, ignored?: string): string {
144+ return `It's a local project: its history is in ${join(dir, project)}, on this machine, and no server is needed.${ignored === undefined ? "" : ` .absoignore leaves the store, ${ignored}, out of the project's files.`}`;
145+}
104147/** Why a token file is no fallback: said when one is here and nothing else signs in. */
105148const TOKEN_FILE_ASKED = "~/.abso/token is used only with --token-file.";
106149
Lines 155–195 at 287 (were 112–146 at 286)
112155 const project = str(args, "project");
113156 if (!project) throw new UsageError("give the project a name with --project <name>");
114157 if (bool(args, "public") && bool(args, "private")) throw new UsageError("--public or --private, not both");
158+ const local = localFrom(args, env, "init");
115159 // A box signed in here, and no other credential asked for: the project is made as the person who approved the box,
116160 // the way the website makes one (abso 663). The token file only with --token-file, never by itself.
117− const server = serverFrom(args, env);
118− const box = readBox(server);
119− const credential = tokenCredential(args, env.env, server, root);
161+ const server = local ? LOCAL : serverFrom(args, env);
162+ const box = local ? undefined : readBox(server);
163+ const credential = local ? undefined : tokenCredential(args, env.env, server, root);
120164 const say = env.writeErr ?? env.write;
121165 if (box && credential === undefined) {
122166 say(`Signing in with this box's sign-in, ${box.id}.
123167`);
124168 return initFromBox(args, env, root, project, server, box);
125169 }
126− if (credential === undefined && tokenFile() !== undefined)
170+ if (!local && credential === undefined && tokenFile() !== undefined)
127171 throw new UsageError(
128172 `abso init signs in with this box's sign-in, and this box isn't signed in to ${server}: abso login signs it in. ${TOKEN_FILE_ASKED}`,
129173 );
130174 const org = str(args, "org");
131175 if (org !== undefined) return initInOrg(org, server);
132− const config = makeSettings(args, env, project);
176+ const config: Settings = local
177+ ? { server: LOCAL, project, agent: agentFrom(args, str(args, "agent") ?? defaultAgentName()), ...local.settings }
178+ : makeSettings(args, env, project);
133179 const asIs = bool(args, "as-is");
134180 const absoignore = join(root, ".absoignore");
135181 const wroteIgnore = !asIs && !existsSync(absoignore) && !existsSync(join(root, ".avcsignore"));
136182 if (wroteIgnore) writeFileSync(absoignore, STARTING_ABSOIGNORE);
183+ // A store kept inside the project folder, like a virtual environment, isn't the project's files.
184+ const ignoredStore = local ? ignoreStoreInside(root, local.dir) : undefined;
137185 // What the server runs on each new version (#39), guessed from package.json; recorded with the rest.
138186 const wroteProject = asIs ? "exists" : writeStartingProjectFile(root);
139187 const { files, blobs, modes, leftOut } = readFolder(root, loadIgnore(root));
140188 const token = credential?.token;
141− say(`Signing in with ${credential?.words ?? `no credential: nothing here signs in to ${server}`}.
189+ if (!local)
190+ say(`Signing in with ${credential?.words ?? `no credential: nothing here signs in to ${server}`}.
142191`);
143− const api = new Api({ ...config, ...(token ? { token } : {}) });
192+ const api = new Api({ ...config, ...(token ? { token } : {}), ...(local ? { localStore: local.dir } : {}) });
144193 let answer: Awaited<ReturnType<Api["init"]>>;
145194 try {
146195 await uploadBlobs(api, blobs);
Lines 219–232 at 287 (were 170–181 at 286)
170219 ...(wroteIgnore
171220 ? ["Wrote a starting .absoignore (Claude Code state and operating system files); edit it like .gitignore."]
172221 : []),
173− ...startingProjectFileText(wroteProject),
222+ // A local project has no CI to run abso.json, so no word about one that isn't there.
223+ ...(local && wroteProject === "nothing" ? [] : startingProjectFileText(wroteProject)),
174224 ...(answer.skipped && answer.skipped.length > 0 ? [`The server skipped: ${answer.skipped.join(", ")}.`] : []),
225+ ...(local ? [localText(local.dir, project, ignoredStore)] : []),
175226 `This folder is agent ${config.agent}. Settings are in .abso/config.json.`,
176227 ...refusedText(synced.refused),
177228 ...(synced.kept.length > 0 ? [`Kept your copy of ${synced.kept.join(", ")}.`] : []),
178− hookHint(env.env),
229+ hookHint(env.env, local !== undefined),
179230 ].join("\n"),
180231 json: {
181232 project,
Lines 237–243 at 287 (were 186–191 at 286)
186237 wroteAbsoignore: wroteIgnore,
187238 wroteProjectFile: typeof wroteProject === "string" ? null : wroteProject,
188239 leftOut,
240+ ...(local ? { store: local.dir } : {}),
189241 },
190242 };
191243}
Lines 432–448 at 287 (were 380–393 at 286)
380432 mkdirSync(root, { recursive: true });
381433 if (findRoot(root) === root) throw new UsageError(`${root} already has .abso/config.json`);
382434 const reader = bool(args, "reader");
383− const server = serverFrom(args, env);
384− const box = readBox(server);
385− const hasKey = existsSync(join(stateDir(root), "key"));
386− const credential = tokenCredential(args, env.env, server, root);
435+ // A local project: no box, key or credential, and the agent is --agent or this computer's name.
436+ const local = localFrom(args, env, "join");
437+ const server = local ? LOCAL : serverFrom(args, env);
438+ const box = local ? undefined : readBox(server);
439+ const hasKey = !local && existsSync(join(stateDir(root), "key"));
440+ const credential = local ? undefined : tokenCredential(args, env.env, server, root);
387441 const tokenFileAsked = bool(args, "token-file");
388442 let agent: string;
389443 let minted: { key: string; id: string } | undefined;
390− if (str(args, "agent") !== undefined) {
444+ if (local) agent = agentFrom(args, str(args, "agent") ?? defaultAgentName());
445+ else if (str(args, "agent") !== undefined) {
391446 agent = agentFrom(args);
392447 minted =
393448 box && !hasKey && !fromEnv(env.env, "KEY_FILE") && !tokenFileAsked
Lines 467–473 at 287 (were 412–418 at 286)
412467 agent = free.agent;
413468 minted = { key: free.key, id: free.id };
414469 }
415− const config = { server, project, agent, ...(reader ? { reader: true } : {}) };
470+ const config = { server, project, agent, ...(reader ? { reader: true } : {}), ...local?.settings };
416471 writeConfig(root, config);
417472 clearKnown(root);
418473 if (minted) installKey(root, JSON.stringify(minted));
Lines 480–490 at 287 (were 425–434 at 286)
425480 throw error;
426481 }
427482 const settings = tokenFileAsked ? { ...read, token: credential?.token } : read;
428− (env.writeErr ?? env.write)(
429− `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}`)}.
483+ if (!local)
484+ (env.writeErr ?? env.write)(
485+ `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}`)}.
430486`,
431− );
487+ );
432488 const api = new Api(settings);
433489 let answer: SyncAnswer;
434490 try {
Lines 510–519 at 287 (were 454–462 at 286)
454510 `These files were already here and differ from shared, so they were left alone: ${synced.kept.join(", ")}. abso record sends them as your changes.`,
455511 ]
456512 : []),
513+ ...(local ? [localText(local.dir, project)] : []),
457514 ...emptyHint(synced.version, synced.written.length, synced.kept.length, reader),
458515 ...setupHint(root),
459− hookHint(env.env),
516+ hookHint(env.env, local !== undefined),
460517 ...(root === resolve(env.cwd) ? [] : [`cd ${relative(env.cwd, root) || root}`]),
461518 ].join("\n"),
462519 json: {
Lines 537–545 at 287 (were 480–486 at 286)
480537 : [`Nothing is installed yet. Before building or testing here, run ${projectFileName(root)}'s setup: ${setup}`];
481538}
482539
483−function hookHint(env: Readonly<Record<string, string | undefined>>): string {
540+function hookHint(env: Readonly<Record<string, string | undefined>>, local = false): string {
541+ // The mod sends each edit to the folder's server itself, and a local project has none.
542+ if (local) return "abso record sends the edits made here: the abso mod doesn't record local projects yet.";
484543 if (modInstalled(env))
485544 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.";
486545 // A built copy (the npm package) has no installer to point at (abso-core 18).
MCP
compare on this site's /mcp
CLI
abso diff 286 287 client/src/join-commands.ts --json
JSON
/christopher/abso-core/compare/286..287?file=client%2Fsrc%2Fjoin-commands.ts&format=json