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

Packed layout follows lines written in another file (disk-first 2; abso Capacity).

of shared·capacity··Not checked

where {} on typescript-rs left 11 lines out of erasable_syntax.rs in cloud-ts-12's draft. cloud-ts-12 moved one block between files several times, wrote lines under its last line while it sat in uninitialized_props_forms.rs, then moved the block on. Those lines followed their parent with no move of their own. The packed layout read only the file's own lines and the files its moved-in lines were written in, so it never read them.

  • Each file's packed history also keeps the runs written in another file under one of its lines (file-crossings). The packed layout follows them until no new file turns up.
  • New adoptions write packed format 2. A graph packed at format 1 has no such list, so it lays files out line by line: correct, but slower until it is adopted again.
  • packed-crossings.test.ts moves c.ts to d.ts, adds a line in d.ts, moves d.ts to e.ts, and checks files, where and every draft's text against the in-memory project.

Named tests: packed-crossings, packed-files, state-source, draft-reads-stored, version-files, project-writer-storage, writer-adoption, moves, queued-moves, files-reads, move-reconstruction (60 of 60); tsc and biome clean.

Version 220 · Files at version 221

3 files, 103 lines added, 11 removed.

--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -262,6 +262,8 @@
262262export type PackedDelete = [number, number];
263263/** An attribute set on a file: [seq, name, value]. */
264264export type PackedAttr = [number, string, string | null];
265+/** A run written in another file under one of a file's lines: [the parent's n, the run's file index]. */
266+export type PackedCrossing = [number, number];
265267const EMPTY_NUMBERS: readonly number[] = Object.freeze([]);
266268/** Lines longer than this aren't packed with their file; their text is read on its own. */
267269const PACKED_TEXT = 4096;
@@ -599,13 +601,16 @@
599601 this.#fileTexts = storedLists<string | null>(storage, "file-texts");
600602 this.#fileDeletes = storedLists<PackedDelete>(storage, "file-deletes");
601603 this.#fileAttrs = storedLists<PackedAttr>(storage, "file-attrs");
604+ this.#fileCrossings = storedLists<PackedCrossing>(storage, "file-crossings");
602605 this.#packFiles = options.packFiles ?? true;
603606 }
604607 }
605608
606609 // Each file's line history packed, in pages (abso Capacity) ---------------------------------------------------
607610 // For each file, by its path index: every line written in it ([n, parent code, writer seq, k, replaces]) and its
608− // text, every delete of one of those lines ([n, deleter seq]), and every attribute set on it ([seq, name, value]).
611+ // text, every delete of one of those lines ([n, deleter seq]), every attribute set on it ([seq, name, value]), and
612+ // every run written in another file under one of its lines ([parent n, the run's file]): a line follows its parent,
613+ // so a run written while its parent was moved elsewhere lays out wherever the parent is.
609614 // Appended as atoms are added, so a view lays a file out from a few pages instead of a row read per line. Kept from
610615 // a fresh adoption on; a graph adopted before has none, and views lay out as before.
611616
@@ -613,19 +618,39 @@
613618 #fileTexts: ReturnType<typeof storedLists<string | null>> | undefined;
614619 #fileDeletes: ReturnType<typeof storedLists<PackedDelete>> | undefined;
615620 #fileAttrs: ReturnType<typeof storedLists<PackedAttr>> | undefined;
621+ #fileCrossings: ReturnType<typeof storedLists<PackedCrossing>> | undefined;
616622 /** Whether a new stored graph starts packing (GraphOptions.packFiles). */
617623 #packFiles = true;
618− /** Whether this graph's files are packed: read once, when first asked, so opening reads nothing. */
619− #packedKnown: boolean | undefined;
624+ /**
625+ * How this graph's files are packed, read once when first asked so opening reads nothing: 0 not at all, 1 lines,
626+ * deletes and attributes, 2 the runs written across files as well.
627+ */
628+ #formatKnown: number | undefined;
629+ get #format(): number {
630+ if (this.#formatKnown === undefined) {
631+ const format = this.#storage?.read("file-lines:meta", "format");
632+ this.#formatKnown = format === 1 || format === 2 ? format : 0;
633+ }
634+ return this.#formatKnown;
635+ }
620636 get #packed(): boolean {
621− this.#packedKnown ??= !!this.#storage && this.#storage.read("file-lines:meta", "format") === 1;
622− return this.#packedKnown;
637+ return this.#format >= 1;
623638 }
639+ get #crossings(): boolean {
640+ return this.#format >= 2;
641+ }
624642
625643 /** Whether this graph keeps each file's line history packed. */
626644 get packedFiles(): boolean {
627645 return this.#packed;
628646 }
647+ /**
648+ * Whether a file can be laid out from packed history alone: it also keeps the runs written across files. A graph
649+ * packed before those were kept lays files out line by line.
650+ */
651+ get packedLayout(): boolean {
652+ return this.#crossings;
653+ }
629654 /** A path's index, or undefined when nothing was ever written or set in it. */
630655 pathIndexOf(path: string): number | undefined {
631656 return this.#pathIndex.get(path);
@@ -646,6 +671,9 @@
646671 *packedAttrs(file: number): IterableIterator<PackedAttr> {
647672 yield* this.#fileAttrs!.values(String(file));
648673 }
674+ *packedCrossings(file: number): IterableIterator<PackedCrossing> {
675+ yield* this.#fileCrossings!.values(String(file));
676+ }
649677
650678 /** Where an atom's key and delete lists are when the graph doesn't keep them (#46): the stored atom. */
651679 #lists: ((seq: number) => AtomLists) | undefined;
@@ -1449,8 +1477,8 @@
14491477 this.#storage.write("ordered-children", "format", 2);
14501478 }
14511479 if (this.#storage && this.#atoms.length === 0 && this.#packFiles) {
1452− this.#storage.write("file-lines:meta", "format", 1);
1453− this.#packedKnown = true;
1480+ this.#storage.write("file-lines:meta", "format", 2);
1481+ this.#formatKnown = 2;
14541482 }
14551483
14561484 if (this.#storage) this.withProjectionScratch((scratch) => this.#validateAcceptedAtom(atom, scratch));
@@ -1535,6 +1563,10 @@
15351563 else pushOne(this.#runStarts, parent, first);
15361564 const replacesParent = deletes(run.parent) ? 1 : 0;
15371565 if (this.#packed) {
1566+ if (this.#crossings && parent >= 0) {
1567+ const from = this.#lineFile.at(parent);
1568+ if (from !== file) this.#fileCrossings!.append(String(from), [parent, file]);
1569+ }
15381570 const base = this.#lineBase[seq]!;
15391571 this.#fileLines!.appendAll(
15401572 String(file),
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -597,7 +597,7 @@
597597 /** Lay out one file: its line tree from the set's atoms, linearized. */
598598 #layout(path: string, complete: boolean): FileState {
599599 const graph = this.graph;
600− if (graph.packedFiles && !this.#scratchMoves()) return this.#layoutPacked(path, complete);
600+ if (graph.packedLayout && !this.#scratchMoves()) return this.#layoutPacked(path, complete);
601601 if (this.#scratchMoves())
602602 return graph.withProjectionScratch((scratch) =>
603603 this.#layoutResolved(
@@ -632,9 +632,9 @@
632632 }
633633
634634 /**
635− * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, and in the
636− * files its moved-in lines came from, read a page at a time; the same tree and order as #layoutResolved, built in
637− * memory with no read per line.
635+ * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, in the files
636+ * its moved-in lines came from, and in the files runs under any of those lines were written in, read a page at a
637+ * time; the same tree and order as #layoutResolved, built in memory with no read per line.
638638 */
639639 #layoutPacked(path: string, complete: boolean): FileState {
640640 const graph = this.graph;
@@ -670,6 +670,8 @@
670670 if (by) by.push(deleter);
671671 else deleters.set(n, [deleter]);
672672 }
673+ // Runs written elsewhere under this file's lines follow them; the loop reads their files too.
674+ for (const [parent, into] of graph.packedCrossings(file)) if (texts.has(parent)) files.add(into);
673675 }
674676 const order = (a: Child, b: Child) =>
675677 b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;
--- /dev/null
+++ b/worker/project/test/packed-crossings.test.ts
@@ -0,0 +1,58 @@
1+// Packed file layout and lines written across files (abso Capacity). A line can be written in one file under a
2+// parent written in another: the parent was moved there. When a later move takes the parent on, the line follows
3+// it without a move of its own. Laid out from packed history, the file must still hold those lines, as the
4+// in-memory project's does.
5+
6+import assert from "node:assert/strict";
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";
12+import { where } from "../where.ts";
14+function writer() {
15+ const storage = new SqlState();
16+ const entries = storedArray<Entry>(storage, "canonical-log");
17+ const store: ProjectStore = {
18+ append(batch) {
19+ for (const entry of batch) entries.push(entry);
20+ },
21+ };
22+ return new Project(store, { writerStorage: storage });
23+}
25+const C = "const x = 1;\nconst y = 2;\n";
27+function history(project: Project) {
28+ let t = 0;
29+ project.init({ "c.ts": C, "other.ts": "other\n" }, t);
30+ project.sync("cy");
31+ project.move("ann", "c.ts", "d.ts", ++t);
32+ assert.equal(project.publish("ann", "Move c to d", ++t).ok, true);
33+ // bob adds a line at the end of d.ts: written in d.ts, under a line written in c.ts.
34+ project.sync("bob");
35+ project.record("bob", { "d.ts": `${C}const z = 3;\n` }, ++t);
36+ assert.equal(project.publish("bob", "Add z", ++t).ok, true);
37+ // dee moves d.ts on to e.ts. bob's line follows its parent there with no move of its own.
38+ project.sync("dee");
39+ project.move("dee", "d.ts", "e.ts", ++t);
40+ project.record("dee", { "other.ts": "other\nmore\n" }, ++t);
41+ project.sync("idle");
42+}
44+const text = (project: Project, agent: string, file: string) =>
45+ (project.draftOf(agent)?.view ?? project.sharedView()).text(file);
47+test("a file laid out from packed history keeps lines written in another file under its own lines", () => {
48+ const oracle = new Project(new MemoryStore());
49+ const project = writer();
50+ history(oracle);
51+ history(project);
52+ assert.equal(text(oracle, "dee", "e.ts"), `${C}const z = 3;\n`);
53+ assert.deepEqual(project.files(), oracle.files());
54+ assert.deepEqual(where(project), where(oracle));
55+ for (const agent of ["ann", "bob", "cy", "dee", "idle"])
56+ for (const file of ["c.ts", "d.ts", "e.ts"])
57+ assert.equal(text(project, agent, file), text(oracle, agent, file), `${agent} ${file}`);
58+});