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

+129 −2 in 5 places
Lines 64–71 at 206 (were 64–69 at 205)
6464 readonly vis: Int32Array;
6565 /** For each deleted position in seq: the seqs of the atoms in the set that delete it, by priority. */
6666 readonly deletedBy: ReadonlyMap<number, readonly number[]>;
67+ /** Its visible lines' text, when laid out from the file's packed history: null for a line too long to pack. */
68+ readonly visText?: readonly (string | null)[];
6769 /** Positions by n, built the first time they're asked for. */
6870 seqIndex?: Map<number, number>;
6971 visIndex?: Map<number, number>;
Lines 453–459 at 206 (were 451–456 at 205)
451453 /** Lay out one file: its line tree from the set's atoms, linearized. */
452454 #layout(path: string, complete: boolean): FileState {
453455 const graph = this.graph;
456+ if (graph.packedFiles && !this.#scratchMoves()) return this.#layoutPacked(path, complete);
454457 if (this.#scratchMoves())
455458 return graph.withProjectionScratch((scratch) =>
456459 this.#layoutResolved(
Lines 465–597 at 206 (were 462–471 at 205)
462465 return this.#layoutResolved(path, complete);
463466 }
464467
468+ /** For each path, the files that lines moved into it were written in: worked out once per view. */
469+ #movedFrom: Map<string, Set<number>> | undefined;
470+ #movedInFrom(): Map<string, Set<number>> {
471+ if (this.#movedFrom) return this.#movedFrom;
472+ const graph = this.graph;
473+ const out = new Map<string, Set<number>>();
474+ if (this.#hasMoves) {
475+ const relocs = this.#relocationsN();
476+ // Where each node sits, walked once for the whole view: through the moves, up to a file's start.
477+ const memo = new Map<number, string>();
478+ const fileOf = (code: number): string => {
479+ const walked: number[] = [];
480+ let cur = code;
481+ let file: string | undefined;
482+ while (file === undefined) {
483+ if (cur < 0) file = graph.nodeOf(cur).slice(1);
484+ else {
485+ file = memo.get(cur);
486+ if (file === undefined) {
487+ walked.push(cur);
488+ cur = relocs.get(cur)?.parent ?? graph.parentCodeOf(cur);
489+ }
490+ }
491+ }
492+ for (const n of walked) memo.set(n, file);
493+ return file;
494+ };
495+ for (const [n, { parent }] of relocs) {
496+ const into = fileOf(parent);
497+ let from = out.get(into);
498+ if (!from) out.set(into, (from = new Set()));
499+ from.add(graph.writtenInIndex(n));
500+ }
501+ }
502+ this.#movedFrom = out;
503+ return out;
504+ }
506+ /**
507+ * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, and in the
508+ * files its moved-in lines came from, read a page at a time; the same tree and order as #layoutResolved, built in
509+ * memory with no read per line.
510+ */
511+ #layoutPacked(path: string, complete: boolean): FileState {
512+ const graph = this.graph;
513+ const attrs = this.#attributes(path);
514+ const start = graph.startCodeOf(path);
515+ if (start === undefined) return { attrs, complete, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
516+ const relocs = this.#hasMoves ? this.#relocationsN() : undefined;
517+ const files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);
518+ const children = new Map<number, Child[]>();
519+ const texts = new Map<number, string | null>();
520+ const deleters = new Map<number, number[]>();
521+ for (const file of files) {
522+ const lineTexts = graph.packedTexts(file);
523+ for (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {
524+ const text = lineTexts.next().value as string | null;
525+ if (!this.#has(seq)) continue;
526+ const moved = relocs?.get(n);
527+ let at = parent;
528+ let child: Child = { n, replaces, lamport: graph.lamportOfSeq(seq), seq, k };
529+ if (moved) {
530+ const mover = graph.atom(moved.r.atom).seq;
531+ child = { n, replaces: 0, lamport: graph.lamportOfSeq(mover), seq: mover, k: moved.r.k };
532+ at = moved.parent;
533+ }
534+ const list = children.get(at);
535+ if (list) list.push(child);
536+ else children.set(at, [child]);
537+ texts.set(n, text);
538+ }
539+ for (const [n, deleter] of graph.packedDeletes(file)) {
540+ if (!this.#has(deleter)) continue;
541+ const by = deleters.get(n);
542+ if (by) by.push(deleter);
543+ else deleters.set(n, [deleter]);
544+ }
545+ }
546+ const order = (a: Child, b: Child) =>
547+ b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;
548+ const priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;
549+ const seq: number[] = [];
550+ const vis: number[] = [];
551+ const visText: (string | null)[] = [];
552+ const deletedBy = new Map<number, readonly number[]>();
553+ const stack: number[] = [];
554+ const push = (code: number) => {
555+ const list = children.get(code);
556+ if (!list) return;
557+ if (list.length > 1) list.sort(order);
558+ for (let i = list.length - 1; i >= 0; i--) stack.push(list[i]!.n);
559+ };
560+ push(start);
561+ while (stack.length) {
562+ const n = stack.pop()!;
563+ const by = deleters.get(n);
564+ if (by) {
565+ if (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);
566+ } else {
567+ vis.push(n);
568+ visText.push(texts.get(n) ?? null);
569+ }
570+ if (complete) seq.push(n);
571+ push(n);
572+ }
573+ return { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy, visText };
574+ }
465576 #attributes(path: string): FileAttrs {
466577 const graph = this.graph;
467578 // For each attribute, the highest-priority setter in the set wins.
468579 const setters = new Map<string, { id: AtomId; value: string | null }>();
580+ const file = graph.packedFiles ? graph.pathIndexOf(path) : undefined;
581+ if (graph.packedFiles) {
582+ for (const [seq, name, value] of file === undefined ? [] : graph.packedAttrs(file)) {
583+ if (!this.#has(seq)) continue;
584+ const id = graph.idOfSeq(seq);
585+ const best = setters.get(name);
586+ if (!best || graph.comparePriority(best.id, id) < 0) setters.set(name, { id, value });
587+ }
588+ return {
589+ exists: setters.get("exists")?.value === "1",
590+ exec: setters.get("exec")?.value === "1",
591+ link: setters.get("link")?.value ?? null,
592+ blob: setters.get("blob")?.value ?? null,
593+ };
594+ }
469595 for (const id of graph.eachAtomIn(path)) {
470596 if (!this.#has(graph.atom(id).seq)) continue;
471597 for (const a of graph.atom(id).attrs ?? []) {
Lines 682–690 at 206 (were 556–564 at 205)
556682 /** The projected text of a file ("" if it has no visible lines). */
557683 text(path: string): string {
558684 if (this.#textCache?.path === path) return this.#textCache.text;
559− const vis = this.#file(path).vis;
685+ const { vis, visText } = this.#file(path);
560686 const lines: string[] = new Array(vis.length);
561− for (let i = 0; i < vis.length; i++) lines[i] = this.graph.textOf(vis[i]!);
687+ for (let i = 0; i < vis.length; i++) lines[i] = visText?.[i] ?? this.graph.textOf(vis[i]!);
562688 const text = joinLines(lines);
563689 this.#textCache = { path, text };
564690 return text;
Lines 868–874 at 206 (were 742–747 at 205)
742868 // headers are separate from their payload byte lengths below.
743869 n += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;
744870 n += f.seq.byteLength + f.vis.byteLength;
871+ if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);
745872 n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;
746873 for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;
747874 if (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;
MCP
compare on this site's /mcp
CLI
abso diff 205 206 src/engine/view.ts --json
JSON
/christopher/abso-core/compare/205..206?file=src%2Fengine%2Fview.ts&format=json