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 207 --json
JSON
/christopher/abso-core/versions/207?format=json

Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.

of shared·capacity··Not checked

Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before.

Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop.

On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.

Version 206 · Files at version 207

6 files, 291 lines added, 10 removed.

--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -47,7 +47,7 @@
4747}
4848
4949/** Structural read boundary shared by historical and transaction-bound projections. */
50−export type ReadView = Omit<Pick<View, keyof View>, "sameText"> & {
50+export type ReadView = Omit<Pick<View, keyof View>, "sameText" | "visibleCount" | "shareMoves"> & {
5151 sameText(path: string, other: ReadView): boolean;
5252};
5353
@@ -100,6 +100,8 @@
100100export const MOVED_LINES_KEPT = 20_000;
101101class TooManyMoves extends Error {}
102102const NO_LINES: readonly number[] = Object.freeze([]);
103+/** Lines whose place views sharing moves remember, at most: about 40 bytes each. */
104+const SHARED_FILE_MEMO = 200_000;
103105
104106/**
105107 * The projection of a closed set. Construct once, then ask for files, lines
@@ -274,6 +276,25 @@
274276 return relocs;
275277 }
276278
279+ /** Where lines sit, shared with views that took this one's moves (shareMoves): unbounded up to SHARED_FILE_MEMO. */
280+ #fileOfShared: Map<number, string> | undefined;
282+ /**
283+ * Take another view's resolved moves (abso Capacity). Only for a set that differs from that view's by atoms that
284+ * move nothing, drop nothing and change no closure: its moves resolve the same, and every line it shares with that
285+ * view sits where it sat there.
286+ */
287+ shareMoves(from: View): void {
288+ if (from.graph !== this.graph || from.#hasMoves !== this.#hasMoves || !this.#hasMoves) return;
289+ if (from.#scratchMoves()) return;
290+ this.#relocs = from.#relocations();
291+ this.#relocsN = from.#relocationsN();
292+ this.#movesOnDisk = false;
293+ this.#movedFrom = from.#movedInFrom();
294+ from.#fileOfShared ??= new Map();
295+ this.#fileOfShared = from.#fileOfShared;
296+ }
277298 /** Whether moves are resolved on disk for each layout: only a stored graph's view with more than MOVED_LINES_KEPT. */
278299 #scratchMoves(): boolean {
279300 if (!this.#hasMoves || !this.graph.hasOrderedChildren) return false;
@@ -349,13 +370,20 @@
349370 while (file === undefined) {
350371 if (cur < 0) file = graph.nodeOf(cur).slice(1);
351372 else {
352− file = this.#fileOf.get(cur);
373+ file = (this.#fileOfShared ?? this.#fileOf).get(cur);
353374 if (file === undefined) {
354− path[visited++ % FILE_LOCATION_MEMO_ENTRIES] = cur;
375+ if (this.#fileOfShared) path.push(cur);
376+ else path[visited++ % FILE_LOCATION_MEMO_ENTRIES] = cur;
355377 cur = relocs.get(cur)?.parent ?? graph.parentCodeOf(cur);
356378 }
357379 }
358380 }
381+ const shared = this.#fileOfShared;
382+ if (shared) {
383+ if (shared.size > SHARED_FILE_MEMO) shared.clear();
384+ for (const l of path) shared.set(l, file);
385+ return file;
386+ }
359387 for (const l of path) {
360388 if (!this.#fileOf.has(l) && this.#fileOf.size >= FILE_LOCATION_MEMO_ENTRIES)
361389 this.#fileOf.delete(this.#fileOf.keys().next().value!);
@@ -668,6 +696,11 @@
668696 return [...this.#known];
669697 }
670698
699+ /** How many visible lines a file has. */
700+ visibleCount(path: string): number {
701+ return this.#file(path).vis.length;
702+ }
671704 /** Whether the file exists in this projection (has a visible line). */
672705 hasFile(path: string): boolean {
673706 const attrs = this.attrs(path);
--- a/worker/project/pathindex.ts
+++ b/worker/project/pathindex.ts
@@ -64,11 +64,34 @@
6464 // Net changes only, as show has them: a file made and removed again before the publish isn't one (#37).
6565 const touched = this.#deps.touchedFiles([...p.atoms, ...(p.dropped ?? [])], [before, after]);
6666 const files = [...touched].filter((path) => differs(before, after, path)).sort();
67+ this.keep(space, version, files, before, after);
68+ return files;
69+ }
71+ /**
72+ * Keep a version's changed files, with its files made and taken out and its moves: worked out here, or as the
73+ * version landed (version-files.ts, abso Capacity), which says which files existed before and after.
74+ */
75+ keep(
76+ space: Space,
77+ version: number,
78+ files: string[],
79+ before: ReadView,
80+ after: ReadView,
81+ exists?: ReadonlyMap<string, readonly [boolean, boolean]>,
82+ ): void {
83+ let cache = this.#filesCache.get(space);
84+ if (!cache) this.#filesCache.set(space, (cache = new Map()));
85+ let shapes = this.#shapeCache.get(space);
86+ if (!shapes) this.#shapeCache.set(space, (shapes = new Map()));
87+ const p = space.versions[version]!;
6788 cache.set(version, files);
6889 // Files made and taken out, and which of those are one file moved (#41): an atom that moves lines
6990 // names both files, and a binary or empty file moved keeps its blob.
70− const made = files.filter((f) => !before.hasFile(f) && after.hasFile(f));
71− const gone = files.filter((f) => before.hasFile(f) && !after.hasFile(f));
91+ const had = (f: string) => exists?.get(f)?.[0] ?? before.hasFile(f);
92+ const has = (f: string) => exists?.get(f)?.[1] ?? after.hasFile(f);
93+ const made = files.filter((f) => !had(f) && has(f));
94+ const gone = files.filter((f) => had(f) && !has(f));
7295 const moves: [string, string][] = [];
7396 if (made.length > 0 && gone.length > 0) {
7497 const movers = new Set(this.#deps.graph.movers());
@@ -87,7 +110,6 @@
87110 }
88111 shapes.set(version, { made, gone, moves });
89112 this.#deps.shapes?.put(space.name, version, JSON.stringify({ stamp: shapeStamp(p), files, made, gone, moves }));
90− return files;
91113 }
92114
93115 /** A version's files kept from an earlier load (#41), when the row describes this very version; into the caches. */
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -12,8 +12,16 @@
1212// agents publish into under the same rules, and that lands in shared as one
1313// unit. Every agent works in one space at a time.
1414
15−import { type Atom, type AtomId, EngineError, Graph, type LineId, type ReadView } from "../../src/engine/index.ts";
1615import {
16+ type Atom,
17+ type AtomId,
18+ EngineError,
19+ Graph,
20+ type LineId,
21+ type ReadView,
22+ View,
23+} from "../../src/engine/index.ts";
24+import {
1725 CachedStateStorage,
1826 differenceSet,
1927 type GraphStateStorage,
@@ -176,11 +184,21 @@
176184import { recordFile as hostedRecordFile, type RecordFileHost } from "./record-file.ts";
177185import { refusals as hostedRefusals, refuse as hostedRefuse, type RefuseHost } from "./refuse.ts";
178186import { restore as hostedRestore, type RestoreHost } from "./restore.ts";
179−import { indexClosure, last, Membership, SHARED, SharedAdditions, type Space, sharedBaseOf } from "./spaces.ts";
187+import {
188+ closureChangedAt,
189+ indexClosure,
190+ last,
191+ Membership,
192+ SHARED,
193+ SharedAdditions,
194+ type Space,
195+ sharedBaseOf,
196+} from "./spaces.ts";
180197import { starting as hostedStarting, type StartingHost } from "./start.ts";
181198import { switchTo as hostedSwitchTo, type SwitchHost } from "./switch-to.ts";
182199import { sync as hostedSync, type SyncHost } from "./sync.ts";
183200import { treeHash } from "./tree.ts";
201+import { versionFiles as keptVersionFiles, type VersionFilesHost } from "./version-files.ts";
184202import {
185203 type LogHost,
186204 compare as versionCompare,
@@ -1588,8 +1606,25 @@
15881606 this.#applyEntry(entry, at, keptTime);
15891607 // Shared's closure, kept per version on disk (abso Capacity): after the entry, since its atoms join the graph after
15901608 // its membership.
1591− if (this.#writerStorage && (this.#spaces.get(SHARED)?.versions.length ?? 0) > versionsBefore)
1592− indexClosure(this.#writerStorage, this.#spaces.get(SHARED)!, this.#graph);
1609+ if (this.#writerStorage && (this.#spaces.get(SHARED)?.versions.length ?? 0) > versionsBefore) {
1610+ const shared = this.#spaces.get(SHARED)!;
1611+ const storage = this.#writerStorage;
1612+ indexClosure(storage, shared, this.#graph);
1613+ // Each new version's changed files, from what it touched (version-files.ts): kept in the shapes table when
1614+ // the host gives one, so the log, a path's history and the tree never lay versions out to find them.
1615+ const host: VersionFilesHost = {
1616+ storage,
1617+ graph: this.#graph,
1618+ at: (v) => this.#at(shared, v),
1619+ viewAt: (v) => this.#viewAt(shared, v),
1620+ empty: () => new View(this.#graph, []),
1621+ closureChangedAt: (v) => closureChangedAt(storage, v),
1622+ };
1623+ for (let v = versionsBefore; v < shared.versions.length; v++) {
1624+ const { files, exists } = keptVersionFiles(host, shared.versions[v]!);
1625+ this.#paths.keep(shared, v, files, v === 0 ? host.empty() : host.viewAt(v - 1), host.viewAt(v), exists);
1626+ }
1627+ }
15931628 } finally {
15941629 // Positions by version: where each version of shared was made.
15951630 const versionsAfter = this.#spaces.get(SHARED)?.versions.length ?? 0;
--- a/worker/project/spaces.ts
+++ b/worker/project/spaces.ts
@@ -133,6 +133,13 @@
133133 return membershipEvent(storage, CLOSURE, atom, version);
134134}
135135
136+/** Whether shared's closure changed at this version: its newest closure event is from it. */
137+export function closureChangedAt(storage: GraphStateStorage, version: number): boolean {
138+ const order = storedArray<MembershipEvent>(storage, `${CLOSURE}:events`);
139+ const length = order.length;
140+ return length > 0 && order[length - 1]!.version === version;
141+}
136143/** The newest shared version whose closure is indexed, or undefined when this writer has none. */
137144export function closureIndexed(storage: GraphStateStorage): number | undefined {
138145 return storage.read(`${CLOSURE}:meta`, "indexed") as number | undefined;
--- /dev/null
+++ b/worker/project/test/version-files.test.ts
@@ -0,0 +1,55 @@
1+// Each version's changed files kept as it lands (abso Capacity, version-files.ts): a writer-backed project's log,
2+// path histories and shows match the in-memory project's through edits, new and removed files, a line taken out and
3+// put back with the same text, moves and a drop.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { storedArray } from "../../../src/engine/state-source.ts";
8+import { SqlState } from "../../../src/engine/test/storage-helper.ts";
9+import { MemoryStore, Project } from "../project.ts";
10+import type { Entry, ProjectStore } from "../project-types.ts";
11+import { countedVersion } from "../version-files.ts";
13+function writer() {
14+ const storage = new SqlState();
15+ const entries = storedArray<Entry>(storage, "canonical-log");
16+ const store: ProjectStore = {
17+ append(batch) {
18+ for (const entry of batch) entries.push(entry);
19+ },
20+ };
21+ return { storage, project: new Project(store, { writerStorage: storage }) };
22+}
24+function history(project: Project) {
25+ let t = 0;
26+ const publish = (agent: string, files: Record<string, string | null>, message: string) => {
27+ project.record(agent, files, ++t);
28+ assert.equal(project.publish(agent, message, ++t).ok, true, message);
29+ };
30+ project.init({ "a.txt": "one\ntwo\nthree\n", "b.txt": "bee\n", "gone.txt": "soon\n" }, t);
31+ publish("ann", { "a.txt": "one\nTWO\nthree\n" }, "Edit a");
32+ publish("ann", { "c.txt": "new file\n" }, "Make c");
33+ publish("ann", { "gone.txt": null }, "Remove gone");
34+ publish("ann", { "b.txt": "" }, "Empty b");
35+ publish("ann", { "b.txt": "bee\n" }, "Same text back in b");
36+ project.move("ann", "c.txt", "d.txt", ++t);
37+ assert.equal(project.publish("ann", "Move c to d", ++t).ok, true);
38+ publish("bob", { "d.txt": "new file\nmore\n" }, "Edit d");
39+ publish("cy", { "e.txt": "e\n" }, "Make e");
40+ const dropped = project.drop("cy", [project.version], "Drop e", ++t);
41+ assert.equal(dropped.ok, true);
42+ publish("bob", { "a.txt": "one\nTWO\nthree\nfour\n" }, "Last");
43+}
45+test("kept version files match the in-memory project's log, paths and shows", () => {
46+ const oracle = new Project(new MemoryStore());
47+ const { storage, project } = writer();
48+ history(oracle);
49+ history(project);
50+ assert.equal(countedVersion(storage), oracle.version);
51+ assert.deepEqual(project.log({ limit: 100 }), oracle.log({ limit: 100 }));
52+ for (const path of ["a.txt", "b.txt", "c.txt", "d.txt", "e.txt", "gone.txt"])
53+ assert.deepEqual(project.log({ limit: 100, path }), oracle.log({ limit: 100, path }), path);
54+ for (let v = 0; v <= oracle.version; v++) assert.deepEqual(project.show(v), oracle.show(v), `version ${v}`);
55+});
--- /dev/null
+++ b/worker/project/version-files.ts
@@ -0,0 +1,129 @@
1+// Each version of shared's changed files, worked out as the version lands from what it touched (disk-first 2;
2+// abso Capacity). The log, a path's history and the tree read these lists; working them out from two layouts of every
3+// touched file per version cost game's whole history 460 s to adopt. Here a version costs about its own size:
4+// - a file it touched differs when its visible lines' count or texts changed, or its mode or blob did;
5+// - whether a file exists before and after comes from a running count of each file's visible lines;
6+// - only a version whose added and removed lines have the very same texts, or one with moves, drops or a change to
7+// shared's closure, is laid out as before.
8+// The answers are exactly differs() in view-changes.ts.
9+
10+import { type AtomId, type Graph, type ReadView, View } from "../../src/engine/index.ts";
11+import type { GraphStateStorage } from "../../src/engine/state-source.ts";
12+import { touchedFiles } from "./collisions.ts";
13+import type { Published } from "./spaces.ts";
14+import { differs } from "./view-changes.ts";
16+const COUNTS = "head-visible";
17+const META = "head-visible:meta";
19+/** The shared version the running counts describe, or undefined when this writer keeps none. */
20+export function countedVersion(storage: GraphStateStorage): number | undefined {
21+ return storage.read(META, "version") as number | undefined;
22+}
24+export interface VersionFilesHost {
25+ readonly storage: GraphStateStorage;
26+ readonly graph: Graph;
27+ /** Shared's set at a version (closed) and its view. */
28+ at(version: number): ReadonlySet<AtomId>;
29+ viewAt(version: number): ReadView;
30+ empty(): ReadView;
31+ /** Whether shared's closure changed at this version (spaces.ts). */
32+ closureChangedAt(version: number): boolean;
33+}
35+/** A file's visible lines in a view: a laid-out count, for the slow path. */
36+function visibleCount(view: ReadView, path: string): number {
37+ const counted = (view as { visibleCount?(path: string): number }).visibleCount;
38+ return counted ? counted.call(view, path) : view.lines(path).length;
39+}
41+/** The changed files of shared's version `v`, sorted, and which existed before and after; the running counts moved to `v`. */
42+export function versionFiles(
43+ host: VersionFilesHost,
44+ p: Published,
45+): { files: string[]; exists?: Map<string, readonly [boolean, boolean]> } {
46+ const { storage, graph } = host;
47+ const v = p.version;
48+ const counted = countedVersion(storage);
49+ const atoms = [...p.atoms, ...(p.dropped ?? [])];
50+ const before = v === 0 ? host.empty() : host.viewAt(v - 1);
51+ const after = host.viewAt(v);
52+ const fast =
53+ v > 0 &&
54+ counted === v - 1 &&
55+ !p.dropped?.length &&
56+ !p.atoms.some((id) => graph.atom(id).moves?.length) &&
57+ !host.closureChangedAt(v);
58+ // The same moves as the version before: share them, and where lines sit, instead of resolving them again.
59+ if (fast && before instanceof View && after instanceof View) after.shareMoves(before);
60+ const touched = touchedFiles(graph, atoms, [before, after]);
61+ let files: string[];
62+ if (!fast) {
63+ files = [...touched].filter((path) => differs(before, after, path)).sort();
64+ // Counts start with the first version; a writer adopted before has none and keeps none.
65+ if (counted === v - 1 || (v === 0 && counted === undefined)) {
66+ for (const path of files) storage.write(COUNTS, path, visibleCount(after, path));
67+ storage.write(META, "version", v);
68+ }
69+ return { files };
70+ }
71+ const beforeSet = host.at(v - 1);
72+ const afterSet = host.at(v);
73+ const visibleIn = (set: ReadonlySet<AtomId>, n: number) => {
74+ for (const seq of graph.eachDeleterSeqOf(n)) if (set.has(graph.idOfSeq(seq))) return false;
75+ return true;
76+ };
77+ const fileOf = (view: ReadView, line: string, n: number) =>
78+ view.hasMoves() ? view.fileOf(line) : graph.writtenIn(n);
79+ // Per file: visible lines added minus removed, and the texts' balance.
80+ const changes = new Map<string, { net: number; texts: Map<string, number>; lines: number }>();
81+ const change = (path: string) => {
82+ let c = changes.get(path);
83+ if (!c) changes.set(path, (c = { net: 0, texts: new Map(), lines: 0 }));
84+ return c;
85+ };
86+ for (const id of p.atoms) {
87+ for (const line of graph.eachInsertedLine(id)) {
88+ const n = graph.lineN(line);
89+ if (!visibleIn(afterSet, n)) continue;
90+ const c = change(fileOf(after, line, n));
91+ const text = graph.textOf(n);
92+ c.net++;
93+ c.lines++;
94+ c.texts.set(text, (c.texts.get(text) ?? 0) + 1);
95+ }
96+ for (const line of graph.deletedLines(id)) {
97+ const n = graph.lineN(line);
98+ if (!beforeSet.has(graph.idOfSeq(graph.writerSeqOf(n))) || !visibleIn(beforeSet, n)) continue;
99+ const c = change(fileOf(before, line, n));
100+ const text = graph.textOf(n);
101+ c.net--;
102+ c.lines++;
103+ c.texts.set(text, (c.texts.get(text) ?? 0) - 1);
104+ }
105+ }
106+ files = [];
107+ const exists = new Map<string, readonly [boolean, boolean]>();
108+ for (const path of touched) {
109+ const was = (storage.read(COUNTS, path) as number | undefined) ?? 0;
110+ const c = changes.get(path);
111+ const now = was + (c?.net ?? 0);
112+ const b = before.attrs(path);
113+ const a = after.attrs(path);
114+ const had = b.exists || b.link !== null || b.blob !== null || was > 0;
115+ const has = a.exists || a.link !== null || a.blob !== null || now > 0;
116+ let differ = had !== has || b.exec !== a.exec || b.link !== a.link || b.blob !== a.blob;
117+ if (!differ && had && c && c.lines > 0) {
118+ // Different texts in or out: the file's lines changed. The same texts in and out: compare the files.
119+ differ = [...c.texts.values()].some((count) => count !== 0) || !before.sameText(path, after);
120+ }
121+ if (differ) {
122+ files.push(path);
123+ exists.set(path, [had, has]);
124+ }
125+ if (now !== was) storage.write(COUNTS, path, now);
126+ }
127+ storage.write(META, "version", v);
128+ return { files: files.sort(), exists };
129+}