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 97 to 318

Compare

+123 −37 in 8 places
Lines 7–13 at 318 (were 7–12 at 97)
77// The engine's own key, so both sides match spellings the same way (#49). Not in core.ts: the edit mod installs core.ts alone.
88import {
99 type Api,
10+ ApiError,
1011 type Collision,
1112 type FileChange,
1213 type MergedLine,
Lines 42–48 at 318 (were 41–46 at 97)
4142import { withFolderLock } from "./lock.ts";
4243import type { OnDisk } from "./modes.ts";
4344import { applyMode, type FullMode, foldModes, onDisk, PLAIN, readKnownModes, writeKnownModes } from "./modes.ts";
45+import { batchRecordItems, sendRecordBatches } from "./record-batches.ts";
4446import { type Refused, screenAnswer, unsafePath } from "./safety.ts";
4547
4648export {
Lines 215–291 at 318 (were 213–250 at 97)
213215 .map(([rel]) => rel)
214216 .sort();
215217 if (sent === 0) return { sent: 0, paths, deleted, changed: [], news: undefined, leftOut, turnedBinary };
216− await uploadBlobs(api, blobs);
217− const answer = await api.record(
218− Object.fromEntries(files),
219− {},
220− modes,
221− Object.fromEntries([...blobs].map(([rel, b]) => [rel, b.sha])),
218+ const items = paths.map((path) => ({
219+ path,
220+ ...(files.has(path) ? { text: files.get(path) } : {}),
221+ ...(modes[path] !== undefined ? { mode: modes[path] } : {}),
222+ ...(blobs.has(path) ? { blob: blobs.get(path)?.sha } : {}),
223+ }));
224+ const batches = batchRecordItems(items);
225+ let batchBlobs = new Map<string, BlobToSend>();
226+ const uploaded = new Set<string>();
227+ const answers = await sendRecordBatches(
228+ api,
229+ batches,
230+ async (batch) => {
231+ batchBlobs = new Map(
232+ batch.paths.flatMap((path) => {
233+ const blob = blobs.get(path);
234+ return blob === undefined ? [] : [[path, blob] as const];
235+ }),
236+ );
237+ for (const [path, blob] of batchBlobs) {
238+ if (uploaded.has(blob.sha)) continue;
239+ await uploadBlobs(api, new Map([[path, blob]]));
240+ uploaded.add(blob.sha);
241+ }
242+ },
243+ async (batch, answer) => {
244+ const batchFiles = new Map(Object.entries(batch.files));
245+ // Commit known state only after this batch is confirmed; earlier successful batches stay committed on later failure.
246+ for (const [rel, text] of batchFiles) if (text === null) forgetKnown(root, rel);
247+ for (const [rel, text] of batchFiles) if (text !== null) writeKnown(root, rel, text);
248+ const knownBlobs = readKnownBlobs(root);
249+ if (Object.keys(batch.blobs).length > 0 || batch.paths.some((rel) => knownBlobs.has(rel))) {
250+ for (const rel of new Set([...Object.keys(batch.files), ...Object.keys(batch.blobs)])) knownBlobs.delete(rel);
251+ for (const [rel, sha] of Object.entries(batch.blobs)) {
252+ forgetKnown(root, rel);
253+ knownBlobs.set(rel, sha);
254+ }
255+ writeKnownBlobs(root, knownBlobs);
256+ }
257+ const gone = Object.entries(batch.files)
258+ .filter(([, text]) => text === null)
259+ .map(([rel]) => rel);
260+ const knownModes = readKnownModes(root);
261+ if (Object.keys(batch.modes).length > 0 || gone.some((rel) => knownModes.has(rel))) {
262+ foldModes(knownModes, batch.modes, gone);
263+ writeKnownModes(root, knownModes);
264+ }
265+ heard(root, [
266+ ...newsLines(answer.news),
267+ ...(answer.spelling ?? []).map(spellingText),
268+ ...(answer.uncomposed ?? []).map(uncomposedText),
269+ ]);
270+ },
222271 );
223− if (!answer.ok) throw new Error(`the server refused the record: ${answer.reason ?? "no reason given"}`);
224− // Forget before writing: after a rename that changes only case, known/a.ts and known/A.ts are one file on Windows and macOS.
225− for (const [rel, text] of files) if (text === null) forgetKnown(root, rel);
226− for (const [rel, text] of files) if (text !== null) writeKnown(root, rel, text);
227− const knownBlobs = readKnownBlobs(root);
228− if (blobs.size > 0 || [...files.keys()].some((rel) => knownBlobs.has(rel))) {
229− for (const rel of files.keys()) knownBlobs.delete(rel);
230− for (const [rel, b] of blobs) {
231− forgetKnown(root, rel);
232− knownBlobs.set(rel, b.sha);
233− }
234− writeKnownBlobs(root, knownBlobs);
235− }
236− const gone = [...files].filter(([, text]) => text === null).map(([rel]) => rel);
237− const knownModes = readKnownModes(root);
238− if (Object.keys(modes).length > 0 || gone.some((rel) => knownModes.has(rel))) {
239− foldModes(knownModes, modes, gone);
240− writeKnownModes(root, knownModes);
241− }
242− // Another spelling of an existing file went in as that file (#49); a new name not in composed form gets a gentle word.
243− heard(root, [
244− ...newsLines(answer.news),
245− ...(answer.spelling ?? []).map(spellingText),
246− ...(answer.uncomposed ?? []).map(uncomposedText),
247− ]);
272+ const changed = answers.flatMap((answer) => (Array.isArray(answer.changed) ? answer.changed : []));
273+ const changedCount = answers.some((answer) => typeof answer.changed === "number")
274+ ? answers.reduce(
275+ (sum, answer) =>
276+ sum +
277+ (typeof answer.changed === "number"
278+ ? answer.changed
279+ : Array.isArray(answer.changed)
280+ ? answer.changed.length
281+ : 0),
282+ 0,
283+ )
284+ : changed;
285+ const news = answers.flatMap((answer) => newsLines(answer.news));
286+ const spelling = answers.flatMap((answer) => answer.spelling ?? []);
287+ const uncomposed = answers.flatMap((answer) => answer.uncomposed ?? []);
288+ const answer = { changed: changedCount, news, spelling, uncomposed };
248289 const longPaths = longPathsOf(
249290 root,
250291 [...files].filter(([, text]) => text !== null).map(([path]) => path),
Lines 314–320 at 318 (were 273–279 at 97)
273314export function gitMarkerText(list: readonly { path: string; line: number }[] | undefined): string[] {
274315 return (list ?? []).map(
275316 (m) =>
276− `Note: ${m.path} has lines that look like a git conflict (from line ${m.line}). abso records them as ordinary text and will publish them as they are. If a merge was left unfinished, fix the file first.`,
317+ `Note: ${m.path} has lines that look like a git conflict (from line ${m.line}). abso records them as ordinary text and will push them as they are. If a merge was left unfinished, fix the file first.`,
277318 );
278319}
279320
Lines 361–367 at 318 (were 320–326 at 97)
320361}
321362
322363export const READER_REFUSES =
323− "this folder is a reader: it records and publishes nothing (abso reader off makes it a writer again)";
364+ "this folder is a reader: it records and pushes nothing (abso reader off makes it a writer again)";
324365
325366/** abso pause: send nothing from the folder (no hook, no record) until abso resume. */
326367export async function runPause(_args: Parsed, env: Env): Promise<Output> {
Lines 380–386 at 318 (were 339–345 at 97)
339380 rmSync(pausedPath(root), { force: true });
340381 return {
341382 text: was
342− ? "Recording again. Changes made while paused go at the next abso record (or publish, sync, ...); abso status lists them."
383+ ? "Recording again. Changes made while paused go at the next abso record (or push, pull, ...); abso status lists them."
343384 : "Recording was not paused.",
344385 json: { paused: false },
345386 };
Lines 432–485 at 318 (were 391–399 at 97)
391432 * overwritten.
392433 */
393434export async function syncFolder(root: string, api: Api, full = false): Promise<Applied> {
394− return applyAnswer(root, api, await api.sync({ full }));
435+ const applied = await applyAnswer(root, api, await pullAnswer(root, api, full));
436+ pullWritten(root);
437+ return applied;
395438}
396439
440+const PULLING_FILE = "pulling.json";
442+/**
443+ * Whether a pull here asked the server and never wrote its answer (abso-core 26): it timed out, or stopped
444+ * partway. The server moved the agent's base when it answered, and later pulls send only what changed since
445+ * that base, so the files it would have written stay behind until a pull asks for every file.
446+ */
447+export function pullUnfinished(root: string): boolean {
448+ return existsSync(join(stateDir(root), PULLING_FILE));
449+}
451+/**
452+ * Ask the server for a pull, noting first that one is under way, so a pull whose answer never gets written
453+ * leaves the note behind. With that note, or `full`, it asks for every file in the agent's view, which the
454+ * folder's own checks then write only where the folder differs. pullWritten takes the note away.
455+ */
456+export async function pullAnswer(root: string, api: Api, full = false): Promise<SyncAnswer> {
457+ const unfinished = pullUnfinished(root);
458+ writeFileAtomic(join(stateDir(root), PULLING_FILE), `${JSON.stringify({ at: new Date().toISOString() })}\n`);
459+ if (!full && !unfinished) return api.sync();
460+ try {
461+ return await api.sync({ full: true });
462+ } catch (err) {
463+ // A server from before full pulls (501): the plain pull is still better than none.
464+ if (unfinished && !full && err instanceof ApiError && err.status === 501) return api.sync();
465+ throw err;
466+ }
467+}
469+/** The pull's answer is written into the folder: take away pullAnswer's note. */
470+export function pullWritten(root: string): void {
471+ rmSync(join(stateDir(root), PULLING_FILE), { force: true });
472+}
474+/** Status's line, and pull's when it caught up. */
475+export function pullUnfinishedText(root: string): string[] {
476+ return pullUnfinished(root)
477+ ? [
478+ "A pull here didn't finish (its answer never arrived or wasn't written), so files may be behind this folder's base. abso pull fetches every file and writes the ones that differ.",
479+ ]
480+ : [];
481+}
397483/** What writing a sync or switch answer into the folder did. */
398484export interface Applied {
399485 readonly version: number;
Lines 564–577 at 318 (were 478–491 at 97)
478564 if (paths.length === 0) return [];
479565 const list = paths.map((p) => `${p} (version ${unwritten[p]!.version}: ${unwritten[p]!.why})`).join(", ");
480566 return [
481− `Stale here: a sync couldn't write ${paths.length === 1 ? "this file" : "these files"}, and no later sync sends ${paths.length === 1 ? "it" : "them"} again. Close whatever holds ${paths.length === 1 ? "it" : "them"}, then abso sync --full: ${list}`,
567+ `Stale here: a pull couldn't write ${paths.length === 1 ? "this file" : "these files"}, and no later pull sends ${paths.length === 1 ? "it" : "them"} again. Close whatever holds ${paths.length === 1 ? "it" : "them"}, then abso pull --full: ${list}`,
482568 ];
483569}
484570
485571/** Write the files a sync or switch answer lists into the folder (the same rules as sync). */
486572/** Write a sync's answer into the folder, holding its lock (#51). */
487573export async function applyAnswer(root: string, api: Api, unscreened: SyncAnswer): Promise<Applied> {
488− return withFolderLock(root, "sync", () => applyAnswerLocked(root, api, unscreened));
574+ return withFolderLock(root, "pull", () => applyAnswerLocked(root, api, unscreened));
489575}
490576
491577async function applyAnswerLocked(root: string, api: Api, unscreened: SyncAnswer): Promise<Applied> {
MCP
compare on this site's /mcp
CLI
abso diff 97 318 client/src/commands.ts --json
JSON
/christopher/abso-core/compare/97..318?file=client%2Fsrc%2Fcommands.ts&format=json