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 174 to 175

Compare

+75 −10 in 8 places
Lines 3–9 at 175 (were 3–8 at 174)
33// atoms and keeps indexes so those questions are cheap.
44
55import { ChildCounts } from "./child-counts.ts";
6+import { JsonStringChunks, registerJsonChunkValue } from "./json-value-chunks.ts";
67import {
78 atomId,
89 attrKey,
Lines 359–366 at 175 (were 358–363 at 174)
358359 encoded.textFormat === 1 || encoded.listFormat === 1 || encoded.insertionFormat === 1
359360 ? encoded.atom!
360361 : value;
362+ if (encoded.insertionFormat === 1 && (!Array.isArray(atom.inserts) || atom.inserts.length !== 0))
363+ throw Error("invalid stored insertion placeholder");
361364 const text =
362365 encoded.textFormat === 1
363366 ? (start: number, length: number): readonly string[] => {
Lines 371–377 at 175 (were 368–374 at 174)
368371 if (index >= start && index < start + length) {
369372 const reference = raw as unknown as TextReference;
370373 if (typeof raw === "string") result.push(raw);
371− else if (reference && typeof reference.text === "string")
374+ else if (reference && reference.text === JSON.stringify([String(atom.seq), index]))
372375 result.push(atomText.read(reference.text));
373376 else throw Error("invalid stored atom text reference");
374377 }
Lines 380–430 at 175 (were 377–389 at 174)
377380 throw Error("stored atom text range missing");
378381 }
379382 : undefined;
383+ const streamed = (target: Atom): Atom => {
384+ registerJsonChunkValue(target, () => {
385+ const line = (raw: unknown, index: number): unknown => {
386+ if (typeof raw === "string") return raw;
387+ const reference = raw as TextReference;
388+ if (!reference || reference.text !== JSON.stringify([String(atom.seq), index]))
389+ throw Error("invalid stored atom text reference");
390+ return new JsonStringChunks(() => atomText.chunks(reference.text));
391+ };
392+ let inserts: readonly unknown[];
393+ if (encoded.insertionFormat === 1) {
394+ const collection = `atom-inserts:${atom.seq}`;
395+ inserts = readonlyStoredArray(storage, collection, (raw, index) => {
396+ const run = raw as { file: string; parent: string; lines: string };
397+ const lines = `${collection}:lines:${index}`;
398+ if (run.lines !== lines || typeof run.file !== "string" || typeof run.parent !== "string")
399+ throw Error("invalid stored insertion run");
400+ let start = 0;
401+ for (let prior = 0; prior < index; prior++)
402+ start += readonlyStoredArray(storage, `${collection}:lines:${prior}`).length;
403+ return {
404+ file: run.file,
405+ parent: run.parent,
406+ lines: readonlyStoredArray(storage, lines, (raw, i) => line(raw, start + i)),
407+ };
408+ });
409+ } else {
410+ let index = 0;
411+ inserts = atom.inserts.map((run) => ({
412+ file: run.file,
413+ parent: run.parent,
414+ lines: run.lines.map((raw) => line(raw, index++)),
415+ }));
416+ }
417+ return { ...target, inserts };
418+ });
419+ return target;
420+ };
380421 const frozen = freezeAtom(
381422 atom,
382423 (id) => id,
383424 (author) => author,
384425 text,
385426 );
386− if (encoded.listFormat !== 1 && encoded.insertionFormat !== 1) return frozen;
427+ if (encoded.listFormat !== 1 && encoded.insertionFormat !== 1) return streamed(frozen);
387428 const result = { ...frozen };
388429 if (encoded.insertionFormat === 1) {
389430 const collection = `atom-inserts:${atom.seq}`;
Lines 437–450 at 175 (were 396–405 at 174)
396437 return Object.freeze({
397438 file: run.file,
398439 parent: run.parent,
399− lines: readonlyStoredArray<string>(storage, lines, (rawLine) => {
440+ lines: readonlyStoredArray<string>(storage, lines, (rawLine, lineIndex) => {
400441 if (typeof rawLine === "string") return rawLine;
401442 const ref = rawLine as TextReference;
402− if (!ref || typeof ref.text !== "string") throw Error("invalid stored insertion text");
443+ let atomLine = lineIndex;
444+ for (let prior = 0; prior < index; prior++)
445+ atomLine += readonlyStoredArray(storage, `${collection}:lines:${prior}`).length;
446+ if (!ref || ref.text !== JSON.stringify([String(atom.seq), atomLine]))
447+ throw Error("invalid stored insertion text");
403448 return atomText.read(ref.text);
404449 }),
405450 });
Lines 458–464 at 175 (were 413–419 at 174)
413458 throw Error("invalid stored atom list reference");
414459 Object.defineProperty(result, field, { value: readonlyStoredArray(storage, collection), enumerable: true });
415460 }
416− return Object.freeze(result);
461+ return streamed(Object.freeze(result));
417462 },
418463 (input, key) => {
419464 const atom = { ...input };
Lines 824–848 at 175 (were 779–784 at 174)
779824 return this.#text(n);
780825 }
781826
827+ /** Historical text in bounded chunks, without decoding a whole stored line. */
828+ *textChunks(n: number): IterableIterator<string> {
829+ if (!this.#storage) {
830+ const text = this.#text(n);
831+ for (let offset = 0; offset < text.length; offset += StoredText.chunkCharacters)
832+ yield text.slice(offset, offset + StoredText.chunkCharacters);
833+ return;
834+ }
835+ if (!Number.isSafeInteger(n) || n < 0 || n >= this.#lineText!.length) throw Error("invalid line number");
836+ const value = this.#storage.read("line-text", String(n));
837+ if (typeof value === "string") {
838+ yield value;
839+ return;
840+ }
841+ const reference = value as { format?: number; text?: string } | undefined;
842+ if (reference?.format !== 1 || typeof reference.text !== "string") throw Error("invalid long line reference");
843+ yield* new StoredText(this.#storage, "atom-text:long").chunks(reference.text);
844+ }
782846 /** The seq of the atom that wrote line n. */
783847 writerSeqOf(n: number): number {
784848 return this.#lineAtom.at(n);
Lines 1040–1052 at 175 (were 976–987 at 174)
9761040
9771041 /** The line ids an atom inserted, in k order. */
9781042 linesOf(id: AtomId): LineId[] {
979− const atom = this.atom(id);
980− const out: LineId[] = [];
981− const seq = atom.seq;
1043+ return [...this.eachInsertedLine(id)];
1044+ }
1045+ /** Inserted identities without decoding or allocating the atom's text. */
1046+ *eachInsertedLine(id: AtomId): IterableIterator<LineId> {
1047+ const seq = this.atom(id).seq;
9821048 const count = (seq + 1 < this.#lineBase.length ? this.#lineBase[seq + 1]! : this.#lineTotal) - this.#lineBase[seq]!;
983− for (let k = 0; k < count; k++) out.push(lineId(id, k));
984− return out;
1049+ for (let k = 0; k < count; k++) yield lineId(id, k);
9851050 }
9861051
9871052 /** Every atom that deletes this line (across the whole graph). */
MCP
compare on this site's /mcp
CLI
abso diff 174 175 src/engine/graph.ts --json
JSON
/christopher/abso-core/compare/174..175?file=src%2Fengine%2Fgraph.ts&format=json