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
MCP
show on this site's /mcp
CLI
abso show 243 --json
JSON
/christopher/abso-core/versions/243?format=json

compare's summary: each changed file's size and SHA-256 instead of its texts (abso issue 680; disk-first 2; abso Capacity).

of shared·capacity··Not checked

compare 612 to 1224 on abso answers 13.2 MB: the full before and after text of about 3,000 changed files. Read Speed's shape lets the site ask for a summary and fetch a file's texts when it opens it.

  • view-changes.ts summariesBetween: the files changesBetween would list, each side as {size, sha256} for text (UTF-8 bytes, SHA-256 of the text), {blob} for a binary file (its hash; the Worker adds its size from the blob store), or null when absent; mode and blob as in the full answer. Each text is read, summed up and let go.
  • version-log compare takes summary and answers {from, to, summary: true, files}. ProjectHistory.compare and both engine-project.ts implementations take a fifth argument, summary; http.ts passes ?summary=1. The full answer is unchanged.

On abso adopted fresh: the summary for 612 to 1224 is 174 KB instead of 13.2 MB, with heap after at 38 MB. The time is the same (about 20 s cold): it still lays the files out to hash them. Stored per-version sizes and hashes would remove that; they're proposed with the author totals table.

New test compare-summary: on an in-memory and a writer-backed project, the summary lists the files the full compare does, with sizes and SHA-256s of its texts, blob hashes for a binary file, and no text. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.

Version 242 · Files at version 243

6 files, 133 lines added, 9 removed.

--- a/server/src/engine-project.ts
+++ b/server/src/engine-project.ts
@@ -523,8 +523,8 @@
523523 fileAt(path: string, version: number, draft: string | null, agent?: string) {
524524 return this.project.fileAt(path, version, { draft, ...(agent ? { agent } : {}) });
525525 }
526− compare(from: number, to: number, draft: string | null, agent?: string) {
527− return this.project.compare(from, to, { draft, ...(agent ? { agent } : {}) });
526+ compare(from: number, to: number, draft: string | null, agent?: string, summary?: boolean) {
527+ return this.project.compare(from, to, { draft, ...(agent ? { agent } : {}), ...(summary ? { summary } : {}) });
528528 }
529529 without(version: number, versions: readonly number[]) {
530530 return this.project.without(version, versions);
--- a/worker/project/http.ts
+++ b/worker/project/http.ts
@@ -392,7 +392,8 @@
392392 const from = int(q.from);
393393 const to = int(q.to);
394394 if (from === undefined || to === undefined) return fail(400, "compare needs ?from=<number>&to=<number>");
395− return { status: 200, body: history.compare(from, to, draft, who) };
395+ // summary=1: each file's size and SHA-256, not its texts (abso issue 680).
396+ return { status: 200, body: history.compare(from, to, draft, who, q.summary === "1") };
396397 }
397398 const version = Number(q.version);
398399 if (q.version === undefined || !Number.isInteger(version)) return fail(400, "show needs ?version=<number>");
--- a/worker/project/project-api.ts
+++ b/worker/project/project-api.ts
@@ -156,7 +156,7 @@
156156 /** A file as it was at a version (#27). */
157157 fileAt(path: string, version: number, draft: string | null, agent?: string): unknown;
158158 /** Every file that differs between two versions (#27). */
159− compare(from: number, to: number, draft: string | null, agent?: string): unknown;
159+ compare(from: number, to: number, draft: string | null, agent?: string, summary?: boolean): unknown;
160160 /** Version `version` of shared without the versions in `versions` (without.ts). */
161161 without(version: number, versions: readonly number[]): unknown;
162162 /** One version: who, why, and each file before and after (#27). */
--- /dev/null
+++ b/worker/project/test/compare-summary.test.ts
@@ -0,0 +1,72 @@
1+// compare's summary (abso issue 680): every file a full compare lists, with its size in UTF-8 bytes and SHA-256 before
2+// and after instead of its texts, or its blob's hash for a binary file. The same on a writer-backed project as in
3+// memory.
4+
5+import assert from "node:assert/strict";
6+import { createHash } from "node:crypto";
7+import { test } from "node:test";
8+import { storedArray } from "../../../src/engine/state-source.ts";
9+import { SqlState } from "../../../src/engine/test/storage-helper.ts";
10+import { MemoryStore, Project } from "../project.ts";
11+import type { Entry, ProjectStore } from "../project-types.ts";
13+const A = "a".repeat(64);
14+const B = "b".repeat(64);
15+const held = (sha: string) => sha === A || sha === B;
17+function writer() {
18+ const storage = new SqlState();
19+ const entries = storedArray<Entry>(storage, "canonical-log");
20+ const store: ProjectStore = {
21+ append(batch) {
22+ for (const entry of batch) entries.push(entry);
23+ },
24+ };
25+ return new Project(store, { writerStorage: storage, hasBlob: held });
26+}
28+function history(project: Project) {
29+ project.init(
30+ { "keep.txt": "same\n", "edit.txt": "one\n", "gone.txt": "bye\n", "run.sh": "echo\n" },
31+ 0,
32+ {},
33+ { "logo.png": A },
34+ );
35+ project.record(
36+ "ann",
37+ { "edit.txt": "one\nzwei ü\n", "gone.txt": null, "new.txt": "hello\n" },
38+ 1,
39+ { "run.sh": { exec: true } },
40+ { "logo.png": B },
41+ );
42+ assert.equal(project.publish("ann", "Changes", 2).ok, true);
43+}
45+const sha = (text: string) => createHash("sha256").update(text, "utf8").digest("hex");
47+test("compare's summary lists what compare does, as sizes and SHA-256s", () => {
48+ for (const project of [new Project(new MemoryStore(), { hasBlob: held }), writer()]) {
49+ history(project);
50+ const full = project.compare(0, 1);
51+ const summary = project.compare(0, 1, { summary: true });
52+ if ("summary" in full || !("summary" in summary)) throw Error("compare answered the wrong shape");
53+ assert.deepEqual(
54+ summary.files.map((f) => f.path),
55+ full.files.map((f) => f.path),
56+ );
57+ for (const f of full.files) {
58+ const s: (typeof summary.files)[number] = summary.files.find((x) => x.path === f.path)!;
59+ const sum = (text: string | null, blob: string | null | undefined) =>
60+ text === null ? null : blob ? { blob } : { size: Buffer.byteLength(text, "utf8"), sha256: sha(text) };
61+ assert.deepEqual(s.before, sum(f.before, f.blob?.before ?? null), `${f.path} before`);
62+ assert.deepEqual(s.after, sum(f.after, f.blob?.after ?? null), `${f.path} after`);
63+ assert.deepEqual(s.mode, f.mode);
64+ assert.deepEqual(s.blob, f.blob);
65+ }
66+ const edited = summary.files.find((f) => f.path === "edit.txt")!;
67+ assert.deepEqual(edited.after, { size: Buffer.byteLength("one\nzwei ü\n", "utf8"), sha256: sha("one\nzwei ü\n") });
68+ assert.equal(summary.files.find((f) => f.path === "gone.txt")!.after, null);
69+ assert.deepEqual(summary.files.find((f) => f.path === "logo.png")!.after, { blob: B });
70+ assert.ok(!JSON.stringify(summary).includes("zwei"), "no texts");
71+ }
72+});
--- a/worker/project/version-log.ts
+++ b/worker/project/version-log.ts
@@ -9,7 +9,7 @@
99import { ProjectError } from "./project-error.ts";
1010import type { FileChange, LogAnswer, LogEntry, ShowAnswer } from "./project-types.ts";
1111import { last, SHARED, type Space } from "./spaces.ts";
12−import { changesBetween } from "./view-changes.ts";
12+import { changesBetween, summariesBetween } from "./view-changes.ts";
1313
1414/** What the version list reads need from a project. */
1515export interface LogHost {
@@ -243,8 +243,10 @@
243243 host: LogHost,
244244 from: number,
245245 to: number,
246− options: { draft?: string | null; agent?: string } = {},
247−): { from: number; to: number; files: FileChange[] } {
246+ options: { draft?: string | null; agent?: string; summary?: boolean } = {},
247+):
248+ | { from: number; to: number; files: FileChange[] }
249+ | { from: number; to: number; summary: true; files: ReturnType<typeof summariesBetween> } {
248250 host.needInit();
249251 const space = host.spaceFor(options);
250252 host.checkVersion(space, from);
@@ -252,13 +254,18 @@
252254 const before = host.viewAt(space, from);
253255 const after = host.viewAt(space, to);
254256 const files = new Set<string>();
257+ // With summary, each file's size and SHA-256 instead of its texts (abso issue 680).
258+ const answer = (paths: Iterable<string>) =>
259+ options.summary
260+ ? { from, to, summary: true as const, files: summariesBetween(before, after, paths) }
261+ : { from, to, files: changesBetween(before, after, paths) };
255262 // A stored writer keeps each shared version's changed files (version-files.ts, abso Capacity): every file that
256263 // differs between two versions changed in one between them, so those lists are the candidates, not every atom
257264 // either set holds.
258265 if (space.name === SHARED && host.graph.packedFiles) {
259266 for (let v = Math.min(from, to) + 1; v <= Math.max(from, to); v++)
260267 for (const file of host.paths.versionFiles(space, v)) files.add(file);
261− return { from, to, files: changesBetween(before, after, files) };
268+ return answer(files);
262269 }
263270 const a = host.at(space, from);
264271 const b = host.at(space, to);
@@ -274,7 +281,7 @@
274281 ))
275282 files.add(file);
276283 }
277− return { from, to, files: changesBetween(before, after, files) };
284+ return answer(files);
278285}
279286
280287/** A version of shared (or of a named draft) as a ReadView, for reading lines (blame at a version). */
--- a/worker/project/view-changes.ts
+++ b/worker/project/view-changes.ts
@@ -1,3 +1,4 @@
1+import { createHash } from "node:crypto";
12import type { ReadView } from "../../src/engine/index.ts";
23import { ProjectError } from "./project-error.ts";
34import type { FileChange, Mode, Modes } from "./project-types.ts";
@@ -18,6 +19,49 @@
1819 return out;
1920}
2021
22+/** A changed file's text or blob, summed up: its size in UTF-8 bytes and its SHA-256, or a blob's hash. */
23+export type FileSummary = { size: number; sha256: string } | { blob: string };
25+/**
26+ * changesBetween without the texts (abso issue 680, compare's summary): each changed file before and after as its size
27+ * and SHA-256, or its blob's hash for a binary file. Each text is read, summed up and let go, so a compare of thousands
28+ * of files never holds them all.
29+ */
30+export function summariesBetween(
31+ before: ReadView,
32+ after: ReadView,
33+ files: Iterable<string>,
34+): {
35+ path: string;
36+ before: FileSummary | null;
37+ after: FileSummary | null;
38+ mode?: { before: Mode; after: Mode };
39+ blob?: { before: string | null; after: string | null };
40+}[] {
41+ const sum = (view: ReadView, path: string): FileSummary | null => {
42+ if (!view.hasFile(path)) return null;
43+ const blob = view.attrs(path).blob;
44+ if (blob !== null) return { blob };
45+ const text = view.text(path);
46+ return { size: Buffer.byteLength(text, "utf8"), sha256: createHash("sha256").update(text, "utf8").digest("hex") };
47+ };
48+ const out: ReturnType<typeof summariesBetween> = [];
49+ for (const path of [...new Set(files)].toSorted()) {
50+ if (!differs(before, after, path)) continue;
51+ const mode = modeChange(before, after, path);
52+ const bb = before.attrs(path).blob;
53+ const ab = after.attrs(path).blob;
54+ out.push({
55+ path,
56+ before: sum(before, path),
57+ after: sum(after, path),
58+ ...(mode ? { mode } : {}),
59+ ...(bb !== ab ? { blob: { before: bb, after: ab } } : {}),
60+ });
61+ }
62+ return out;
63+}
2165/** Whether a file differs between two views: its text, its mode, or its blob (what changesBetween lists). */
2266export function differs(before: ReadView, after: ReadView, path: string): boolean {
2367 const had = before.hasFile(path);