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 273 to 318

Compare

+127 −29 in 18 places
Lines 10–16 at 318 (were 10–16 at 273)
1010// made when a caller asks for them, and the latest asked for is kept.
1111
1212import type { Graph, RelocationInfo } from "./graph.ts";
13−import { isStartNode, lineId, seqOf } from "./keys.ts";
13+import { atomId, isStartNode, lineId, seqOf } from "./keys.ts";
1414import { resolveScratchMoves, scratchLayoutNodes } from "./relocation-scratch.ts";
1515import { isClosedSet, StableSet } from "./state-source.ts";
1616import { joinLines } from "./text.ts";
Lines 64–75 at 318 (were 64–70 at 273)
6464 sameText(path: string, other: ReadView): boolean;
6565};
6666
67−const NO_ATTRS: FileAttrs = { exists: false, exec: false, link: null, blob: null };
67+const NO_ATTRS: FileAttrs = {
68+ exists: false,
69+ exec: false,
70+ link: null,
71+ blob: null,
72+};
6873
6974/**
7075 * A file layout's bytes, less its lookup indexes, worked out once per layout (abso Capacity): a layout never changes
Lines 128–140 at 318 (were 123–129 at 273)
123128}
124129
125130const EMPTY_INTS = new Int32Array(0);
126−const NO_FILE: FileState = { attrs: NO_ATTRS, complete: true, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
131+const NO_FILE: FileState = {
132+ attrs: NO_ATTRS,
133+ complete: true,
134+ seq: EMPTY_INTS,
135+ vis: EMPTY_INTS,
136+ deletedBy: new Map(),
137+};
127138
128139/** A count of file uses shared by every view, so a cache can tell which layout across its views was used longest ago. */
129140let fileUses = 0;
Lines 184–193 at 318 (were 173–179 at 273)
173184 readonly #graph: Graph;
174185 #seen = 0;
175186 /** Movers in seq order, with the numbers of the lines each moves, in its moves' order. */
176− readonly movers: { readonly seq: number; readonly lines: readonly number[] }[] = [];
187+ readonly movers: {
188+ readonly seq: number;
189+ readonly lines: readonly number[];
190+ }[] = [];
177191 /** Every relocation of each moved line, by the line's number, in seq order. */
178192 readonly byLine = new Map<number, MoveEntry[]>();
179193 readonly #climbed = new Map<number, number>();
Lines 211–222 at 318 (were 197–203 at 273)
197211 const lines: number[] = [];
198212 graph.atom(id).moves!.forEach((m, k) => {
199213 const n = graph.lineN(m.line);
200− const r: RelocationInfo = Object.freeze({ atom: id, line: m.line, parent: m.parent, k });
214+ const r: RelocationInfo = Object.freeze({
215+ atom: id,
216+ line: m.line,
217+ parent: m.parent,
218+ k,
219+ });
201220 const entry: MoveEntry = { n, r, parent: graph.codeOf(m.parent)! };
202221 const list = this.byLine.get(n);
203222 if (list) list.push(entry);
Lines 544–553 at 318 (were 525–531 at 273)
525544 if (this.#relocsN) return this.#relocsN;
526545 const out = new Map<number, { readonly r: RelocationInfo; readonly parent: number }>();
527546 for (const [line, r] of this.#relocations())
528− out.set(this.graph.lineN(line), { r, parent: this.graph.codeOf(r.parent)! });
547+ out.set(this.graph.lineN(line), {
548+ r,
549+ parent: this.graph.codeOf(r.parent)!,
550+ });
529551 this.#relocsN = out;
530552 return out;
531553 }
Lines 649–661 at 318 (were 627–633 at 273)
627649 for (const n of graph.eachChildN(code)) {
628650 const seq = graph.writerSeqOf(n);
629651 if (!this.#has(seq) || relocs?.has(n)) continue;
630− out.push({ n, replaces: graph.replacesN(n) ? 1 : 0, lamport: graph.lamportOfSeq(seq), seq, k: graph.kOf(n) });
652+ out.push({
653+ n,
654+ replaces: graph.replacesN(n) ? 1 : 0,
655+ lamport: graph.lamportOfSeq(seq),
656+ seq,
657+ k: graph.kOf(n),
658+ });
631659 }
632660 if (relocs) {
633661 // The lines this set's moves put under each node, from the moves it already resolved: no row read per node
Lines 671–683 at 318 (were 643–649 at 273)
643671 for (const n of this.#movedInto.get(code) ?? NO_LINES) {
644672 const r = relocs.get(n)!.r;
645673 const seq = graph.atom(r.atom).seq;
646− out.push({ n, replaces: 0, lamport: graph.lamportOfSeq(seq), seq, k: r.k });
674+ out.push({
675+ n,
676+ replaces: 0,
677+ lamport: graph.lamportOfSeq(seq),
678+ seq,
679+ k: r.k,
680+ });
647681 }
648682 }
649683 // A line's replacements (runs of atoms that deleted it) first, then the
Lines 785–806 at 318 (were 751–761 at 273)
751785 const graph = this.graph;
752786 const attrs = this.#attributes(path);
753787 const start = graph.startCodeOf(path);
754− if (start === undefined) return { attrs, complete, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
788+ if (start === undefined)
789+ return {
790+ attrs,
791+ complete,
792+ seq: EMPTY_INTS,
793+ vis: EMPTY_INTS,
794+ deletedBy: new Map(),
795+ };
755796 const relocs = this.#hasMoves ? this.#relocationsN() : undefined;
756797 const files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);
757798 const children = new Map<number, Child[]>();
758− const texts = new Map<number, string | null>();
799+ // Where each line's text is: its file and its place in that file's packed history. Texts are read after the walk,
800+ // only for the lines it shows (abso Capacity): every text a file and its moved-in sources ever had was read for
801+ // every layout, and abso's worker files, split out of index.ts, read all of index.ts's history each.
802+ const textFile = new Map<number, number>();
803+ const textPlace = new Map<number, number>();
759804 const writers = new Map<number, number>();
760805 const places = new Map<number, number>();
761806 const deleters = new Map<number, number[]>();
Lines 815–864 at 318 (were 770–802 at 273)
770815 return lamport;
771816 };
772817 for (const file of files) {
773− const lineTexts = graph.packedTexts(file);
774− for (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {
775− const text = lineTexts.next().value as string | null;
818+ // The file's history decoded once and kept by the graph (abso Capacity): each view of it read every page again.
819+ const history = graph.packedHistory(file);
820+ const lines = history.lines;
821+ for (let i = 0, place = 0; i < lines.length; i += 5, place++) {
822+ const n = lines[i]!;
823+ const parent = lines[i + 1]!;
824+ const seq = lines[i + 2]!;
825+ const k = lines[i + 3]!;
826+ const replaces = lines[i + 4]!;
776827 if (!this.#has(seq)) continue;
777828 const moved = relocs?.get(n);
778829 let at = parent;
779830 let child: Child = { n, replaces, lamport: lamportOf(seq), seq, k };
780831 if (moved) {
781832 const mover = graph.atom(moved.r.atom).seq;
782− child = { n, replaces: 0, lamport: lamportOf(mover), seq: mover, k: moved.r.k };
833+ child = {
834+ n,
835+ replaces: 0,
836+ lamport: lamportOf(mover),
837+ seq: mover,
838+ k: moved.r.k,
839+ };
783840 at = moved.parent;
784841 }
785842 const list = children.get(at);
786843 if (list) list.push(child);
787844 else children.set(at, [child]);
788− texts.set(n, text);
845+ textFile.set(n, file);
846+ textPlace.set(n, place);
789847 writers.set(n, seq);
790848 places.set(n, k);
791849 }
792− for (const [n, deleter] of graph.packedDeletes(file)) {
850+ const dels = history.deletes;
851+ for (let at = 0; at < dels.length; at += 2) {
852+ const n = dels[at]!;
853+ const deleter = dels[at + 1]!;
793854 if (!this.#has(deleter)) continue;
794855 const by = deleters.get(n);
795856 if (by) by.push(deleter);
796857 else deleters.set(n, [deleter]);
797858 }
798859 // Runs written elsewhere under this file's lines follow them; the loop reads their files too.
799− for (const [parent, into] of graph.packedCrossings(file)) if (texts.has(parent)) files.add(into);
860+ const crossings = history.crossings;
861+ for (let at = 0; at < crossings.length; at += 2) if (writers.has(crossings[at]!)) files.add(crossings[at + 1]!);
800862 }
801863 const order = (a: Child, b: Child) =>
802864 b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;
Lines 871–888 at 318 (were 809–814 at 273)
809871 const seqWriter: number[] = [];
810872 const seqK: number[] = [];
811873 const deletedBy = new Map<number, readonly number[]>();
874+ // The text pages read for this layout, by file and page: each at most once.
875+ const pages = new Map<number, Map<number, readonly (string | null)[]>>();
876+ const textOf = (n: number): string | null => {
877+ const file = textFile.get(n)!;
878+ const place = textPlace.get(n)!;
879+ const page = Math.floor(place / 256);
880+ let byPage = pages.get(file);
881+ if (!byPage) pages.set(file, (byPage = new Map()));
882+ let texts = byPage.get(page);
883+ if (!texts) byPage.set(page, (texts = graph.packedTextPage(file, page)));
884+ return texts[place % 256] ?? null;
885+ };
812886 const stack: number[] = [];
813887 const push = (code: number) => {
814888 const list = children.get(code);
Lines 898–904 at 318 (were 824–830 at 273)
824898 if (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);
825899 } else {
826900 vis.push(n);
827− visText.push(texts.get(n) ?? null);
901+ visText.push(textOf(n));
828902 visWriter.push(writers.get(n)!);
829903 visK.push(places.get(n)!);
830904 }
Lines 982–994 at 318 (were 908–914 at 273)
908982 if (complete) seq.push(n);
909983 }
910984
911− return { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy };
985+ return {
986+ attrs,
987+ complete,
988+ seq: Int32Array.from(seq),
989+ vis: Int32Array.from(vis),
990+ deletedBy,
991+ };
912992 }
913993
914994 get #known(): string[] {
Lines 1095–1119 at 318 (were 1015–1028 at 273)
10151095 }
10161096
10171097 *lineChunks(path: string): IterableIterator<() => Iterable<string>> {
1018− for (const n of this.#file(path).vis) yield () => this.graph.textChunks(n);
1098+ // The texts the packed layout already holds, read a page at a time (abso Capacity, 714): a record's diff read each
1099+ // line's own row, 11,873 statements for abso's index.ts. Only a line too long to pack is read in chunks.
1100+ const { vis, visText } = this.#file(path);
1101+ for (let i = 0; i < vis.length; i++) {
1102+ const packed = visText?.[i];
1103+ if (packed != null) yield () => [packed];
1104+ else yield () => this.graph.textChunks(vis[i]!);
1105+ }
10191106 }
10201107
10211108 /** Visible lines without retaining their text in the view cache. */
10221109 *visibleLines(path: string): IterableIterator<VisibleLine> {
10231110 const graph = this.graph;
10241111 for (const n of this.#file(path).vis)
1025− yield { id: graph.lineIdOf(n), text: graph.textOf(n), atom: graph.idOfSeq(graph.writerSeqOf(n)) };
1112+ yield {
1113+ id: graph.lineIdOf(n),
1114+ text: graph.textOf(n),
1115+ atom: atomId(graph.writerSeqOf(n)),
1116+ };
10261117 }
10271118
10281119 /** Atom-building line handles; text is loaded only when requested. */
Lines 1126–1137 at 318 (were 1035–1046 at 273)
10351126 const n = vis[i]!;
10361127 const packed = visText?.[i];
10371128 lines[i] = {
1038− id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
1129+ id: visWriter && visK ? lineId(atomId(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
10391130 textChunks: () => graph.textChunks(n),
10401131 get text() {
10411132 return packed ?? graph.textOf(n);
10421133 },
1043− atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
1134+ atom: atomId(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
10441135 };
10451136 }
10461137 return lines;
Lines 1143–1156 at 318 (were 1052–1063 at 273)
10521143 const graph = this.graph;
10531144 const { vis, visText, visWriter, visK } = this.#file(path);
10541145 const lines: VisibleLine[] = new Array(vis.length);
1146+ // Writer seqs come from the graph's own layout, so they're named with atomId, not checked by idOfSeq (abso 738):
1147+ // on a stored graph its check read the atom count once a line, about 0.9 s of a warm draft-state on abso.
10551148 for (let i = 0; i < vis.length; i++) {
10561149 const n = vis[i]!;
10571150 lines[i] = {
1058− id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
1151+ id: visWriter && visK ? lineId(atomId(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
10591152 text: visText?.[i] ?? graph.textOf(n),
1060− atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
1153+ atom: atomId(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
10611154 };
10621155 }
10631156 this.#linesCache = { path, lines };
Lines 1172–1184 at 318 (were 1079–1091 at 273)
10791172 const writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n);
10801173 let text: string | undefined;
10811174 out[i] = {
1082− id: seqWriter && seqK ? lineId(graph.idOfSeq(writer), seqK[i]!) : graph.lineIdOf(n),
1175+ id: seqWriter && seqK ? lineId(atomId(writer), seqK[i]!) : graph.lineIdOf(n),
10831176 get text() {
10841177 text ??= graph.textOf(n);
10851178 return text;
10861179 },
1087− atom: graph.idOfSeq(writer),
1088− deletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE,
1180+ atom: atomId(writer),
1181+ deletedBy: by ? by.map((s) => atomId(s)) : NONE,
10891182 visible: by === undefined,
10901183 };
10911184 }
Lines 1334–1345 at 318 (were 1241–1247 at 273)
12411334 * Each laid-out file: its layout, when it was last used (a count shared by every view) and what it holds, for a
12421335 * cache that trims the least recently used layouts across its views before whole views (views.ts, abso Capacity).
12431336 */
1244− *laidOut(): IterableIterator<{ path: string; layout: object; used: number; bytes: number }> {
1337+ *laidOut(): IterableIterator<{
1338+ path: string;
1339+ layout: object;
1340+ used: number;
1341+ bytes: number;
1342+ }> {
12451343 for (const [path, f] of this.#files) {
12461344 if (f === NO_FILE) continue;
12471345 let bytes = 2 * MAP_ENTRY_BYTES + layoutBytes(f);
MCP
compare on this site's /mcp
CLI
abso diff 273 318 src/engine/view.ts --json
JSON
/christopher/abso-core/compare/273..318?file=src%2Fengine%2Fview.ts&format=json