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 205 to 206

Compare

+94 −0 in 7 places
Lines 256–270 at 206 (were 256–261 at 205)
256256 return { seq, k };
257257}
258258
259+/** A line in its file's packed history: [n, parent code, writer seq, k, 1 when it replaces its parent]. */
260+export type PackedLine = [number, number, number, number, number];
261+/** A delete of a line in a file's packed history: [n, deleter seq]. */
262+export type PackedDelete = [number, number];
263+/** An attribute set on a file: [seq, name, value]. */
264+export type PackedAttr = [number, string, string | null];
265+/** Lines longer than this aren't packed with their file; their text is read on its own. */
266+const PACKED_TEXT = 4096;
259268export class Graph {
260269 readonly #storage?: GraphStateStorage;
261270 readonly #childCounts?: ChildCounts;
Lines 303–310 at 206 (were 294–299 at 205)
294303 storage?: GraphStateStorage;
295304 /** Optional derived indexing inside persistent atom acceptance; must be synchronous. */
296305 indexAcceptedAtom?: (atom: Atom, files: readonly string[], storage: GraphStateStorage) => void;
306+ /** false: a new stored graph keeps no packed file history, and lays files out line by line (tests of that path). */
307+ packFiles?: boolean;
297308 } = {},
298309 ) {
299310 if (options.indexAcceptedAtom && !options.storage)
Lines 594–651 at 206 (were 583–591 at 205)
583594 JSON.stringify(["number", Number(key)]),
584595 );
585596 this.#labels = storedMap(storage, "labels");
597+ this.#fileLines = storedLists<PackedLine>(storage, "file-lines");
598+ this.#fileTexts = storedLists<string | null>(storage, "file-texts");
599+ this.#fileDeletes = storedLists<PackedDelete>(storage, "file-deletes");
600+ this.#fileAttrs = storedLists<PackedAttr>(storage, "file-attrs");
601+ this.#packFiles = options.packFiles ?? true;
586602 }
587603 }
588604
605+ // Each file's line history packed, in pages (abso Capacity) ---------------------------------------------------
606+ // For each file, by its path index: every line written in it ([n, parent code, writer seq, k, replaces]) and its
607+ // text, every delete of one of those lines ([n, deleter seq]), and every attribute set on it ([seq, name, value]).
608+ // 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
609+ // a fresh adoption on; a graph adopted before has none, and views lay out as before.
611+ #fileLines: ReturnType<typeof storedLists<PackedLine>> | undefined;
612+ #fileTexts: ReturnType<typeof storedLists<string | null>> | undefined;
613+ #fileDeletes: ReturnType<typeof storedLists<PackedDelete>> | undefined;
614+ #fileAttrs: ReturnType<typeof storedLists<PackedAttr>> | undefined;
615+ /** Whether a new stored graph starts packing (GraphOptions.packFiles). */
616+ #packFiles = true;
617+ /** Whether this graph's files are packed: read once, when first asked, so opening reads nothing. */
618+ #packedKnown: boolean | undefined;
619+ get #packed(): boolean {
620+ this.#packedKnown ??= !!this.#storage && this.#storage.read("file-lines:meta", "format") === 1;
621+ return this.#packedKnown;
622+ }
624+ /** Whether this graph keeps each file's line history packed. */
625+ get packedFiles(): boolean {
626+ return this.#packed;
627+ }
628+ /** A path's index, or undefined when nothing was ever written or set in it. */
629+ pathIndexOf(path: string): number | undefined {
630+ return this.#pathIndex.get(path);
631+ }
632+ /** The index of the path line n was written in. */
633+ writtenInIndex(n: number): number {
634+ return this.#lineFile.at(n);
635+ }
636+ *packedLines(file: number): IterableIterator<PackedLine> {
637+ yield* this.#fileLines!.values(String(file));
638+ }
639+ *packedTexts(file: number): IterableIterator<string | null> {
640+ yield* this.#fileTexts!.values(String(file));
641+ }
642+ *packedDeletes(file: number): IterableIterator<PackedDelete> {
643+ yield* this.#fileDeletes!.values(String(file));
644+ }
645+ *packedAttrs(file: number): IterableIterator<PackedAttr> {
646+ yield* this.#fileAttrs!.values(String(file));
647+ }
589649 /** Where an atom's key and delete lists are when the graph doesn't keep them (#46): the stored atom. */
590650 #lists: ((seq: number) => AtomLists) | undefined;
591651 /** Recently read atoms' lists, most recent last, up to LIST_CACHE atoms. */
Lines 1437–1446 at 206 (were 1377–1382 at 205)
13771437 if (this.#atoms.length !== 0) throw new Error("ordered children require fresh adoption");
13781438 this.#storage.write("ordered-children", "format", 2);
13791439 }
1440+ if (this.#storage && this.#atoms.length === 0 && this.#packFiles) {
1441+ this.#storage.write("file-lines:meta", "format", 1);
1442+ this.#packedKnown = true;
1443+ }
13801444
13811445 if (this.#storage) this.withProjectionScratch((scratch) => this.#validateAcceptedAtom(atom, scratch));
13821446 else this.#validateAcceptedAtom(atom);
Lines 1489–1507 at 206 (were 1425–1435 at 205)
14251489 if (deletedN) yield* deletedN;
14261490 else for (const line of atom.deletes) yield graph.#lineN(line);
14271491 };
1492+ const packedDeletes = new Map<number, PackedDelete[]>();
14281493 for (const n of deletedNumbers(this)) {
1494+ if (this.#packed) {
1495+ const file = this.#lineFile.at(n);
1496+ const list = packedDeletes.get(file);
1497+ if (list) list.push([n, seq]);
1498+ else packedDeletes.set(file, [[n, seq]]);
1499+ }
14291500 if (this.#deleter.at(n) < 0) this.#deleter.set(n, seq);
14301501 else if (this.#moreDeleterPages) this.#moreDeleterPages.append(String(n), seq);
14311502 else pushIndex(this.#moreDeleters, n, seq);
14321503 }
1504+ for (const [file, list] of packedDeletes) this.#fileDeletes!.appendAll(String(file), list);
14331505 this.#lineBase.push(this.#lineTotal);
14341506 for (const run of atom.inserts) {
14351507 const file = this.#pathOf(run.file);
Lines 1522–1547 at 206 (were 1450–1455 at 205)
14501522
14511523 if (this.#runStartPages) this.#runStartPages.append(String(parent), first);
14521524 else pushOne(this.#runStarts, parent, first);
1525+ const replacesParent = deletes(run.parent) ? 1 : 0;
1526+ if (this.#packed) {
1527+ const base = this.#lineBase[seq]!;
1528+ this.#fileLines!.appendAll(
1529+ String(file),
1530+ run.lines.map(
1531+ (_, i): PackedLine => [
1532+ first + i,
1533+ i === 0 ? parent : first + i - 1,
1534+ seq,
1535+ first + i - base,
1536+ i === 0 ? replacesParent : 0,
1537+ ],
1538+ ),
1539+ );
1540+ this.#fileTexts!.appendAll(
1541+ String(file),
1542+ run.lines.map((text) => (typeof text === "string" && text.length <= PACKED_TEXT ? text : null)),
1543+ );
1544+ }
14531545 for (let i = 0; i < run.lines.length; i++) {
14541546 const n = this.#lineTotal;
14551547 this.#childCounts?.append(n);
Lines 1565–1572 at 206 (were 1473–1478 at 205)
14731565 else pushIndex(this.#relocatedToCode, parentCode, info);
14741566 });
14751567 if (frozen.moves) this.#movers.push(frozen.id);
1568+ if (this.#packed)
1569+ for (const a of frozen.attrs ?? []) this.#fileAttrs!.append(String(this.#pathOf(a.file)), [seq, a.name, a.value]);
14761570 for (const key of writes) {
14771571 const code = this.#code(key);
14781572 if (this.#writersPages) {
MCP
compare on this site's /mcp
CLI
abso diff 205 206 src/engine/graph.ts --json
JSON
/christopher/abso-core/compare/205..206?file=src%2Fengine%2Fgraph.ts&format=json