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 107 to 108

Compare

+71 −31 in 2 places
Lines 41–47 at 108 (were 41–46 at 107)
4141import { withFolderLock } from "./lock.ts";
4242import type { OnDisk } from "./modes.ts";
4343import { applyMode, type FullMode, foldModes, onDisk, PLAIN, readKnownModes, writeKnownModes } from "./modes.ts";
44+import { batchRecordItems, sendRecordBatches } from "./record-batches.ts";
4445import { type Refused, screenAnswer, unsafePath } from "./safety.ts";
4546
4647export {
Lines 214–290 at 108 (were 213–250 at 107)
213214 .map(([rel]) => rel)
214215 .sort();
215216 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])),
217+ const items = paths.map((path) => ({
218+ path,
219+ ...(files.has(path) ? { text: files.get(path) } : {}),
220+ ...(modes[path] !== undefined ? { mode: modes[path] } : {}),
221+ ...(blobs.has(path) ? { blob: blobs.get(path)?.sha } : {}),
222+ }));
223+ const batches = batchRecordItems(items);
224+ let batchBlobs = new Map<string, BlobToSend>();
225+ const uploaded = new Set<string>();
226+ const answers = await sendRecordBatches(
227+ api,
228+ batches,
229+ async (batch) => {
230+ batchBlobs = new Map(
231+ batch.paths.flatMap((path) => {
232+ const blob = blobs.get(path);
233+ return blob === undefined ? [] : [[path, blob] as const];
234+ }),
235+ );
236+ for (const [path, blob] of batchBlobs) {
237+ if (uploaded.has(blob.sha)) continue;
238+ await uploadBlobs(api, new Map([[path, blob]]));
239+ uploaded.add(blob.sha);
240+ }
241+ },
242+ async (batch, answer) => {
243+ const batchFiles = new Map(Object.entries(batch.files));
244+ // Commit known state only after this batch is confirmed; earlier successful batches stay committed on later failure.
245+ for (const [rel, text] of batchFiles) if (text === null) forgetKnown(root, rel);
246+ for (const [rel, text] of batchFiles) if (text !== null) writeKnown(root, rel, text);
247+ const knownBlobs = readKnownBlobs(root);
248+ if (Object.keys(batch.blobs).length > 0 || batch.paths.some((rel) => knownBlobs.has(rel))) {
249+ for (const rel of new Set([...Object.keys(batch.files), ...Object.keys(batch.blobs)])) knownBlobs.delete(rel);
250+ for (const [rel, sha] of Object.entries(batch.blobs)) {
251+ forgetKnown(root, rel);
252+ knownBlobs.set(rel, sha);
253+ }
254+ writeKnownBlobs(root, knownBlobs);
255+ }
256+ const gone = Object.entries(batch.files)
257+ .filter(([, text]) => text === null)
258+ .map(([rel]) => rel);
259+ const knownModes = readKnownModes(root);
260+ if (Object.keys(batch.modes).length > 0 || gone.some((rel) => knownModes.has(rel))) {
261+ foldModes(knownModes, batch.modes, gone);
262+ writeKnownModes(root, knownModes);
263+ }
264+ heard(root, [
265+ ...newsLines(answer.news),
266+ ...(answer.spelling ?? []).map(spellingText),
267+ ...(answer.uncomposed ?? []).map(uncomposedText),
268+ ]);
269+ },
222270 );
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− ]);
271+ const changed = answers.flatMap((answer) => (Array.isArray(answer.changed) ? answer.changed : []));
272+ const changedCount = answers.some((answer) => typeof answer.changed === "number")
273+ ? answers.reduce(
274+ (sum, answer) =>
275+ sum +
276+ (typeof answer.changed === "number"
277+ ? answer.changed
278+ : Array.isArray(answer.changed)
279+ ? answer.changed.length
280+ : 0),
281+ 0,
282+ )
283+ : changed;
284+ const news = answers.flatMap((answer) => newsLines(answer.news));
285+ const spelling = answers.flatMap((answer) => answer.spelling ?? []);
286+ const uncomposed = answers.flatMap((answer) => answer.uncomposed ?? []);
287+ const answer = { changed: changedCount, news, spelling, uncomposed };
248288 const longPaths = longPathsOf(
249289 root,
250290 [...files].filter(([, text]) => text !== null).map(([path]) => path),
MCP
compare on this site's /mcp
CLI
abso diff 107 108 client/src/commands.ts --json
JSON
/christopher/abso-core/compare/107..108?file=client%2Fsrc%2Fcommands.ts&format=json