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 238 to 239

Compare

+64 −0 in 1 place
Lines 583–652 at 239 (were 583–588 at 238)
583583}
584584
585585/** Read-only array access to individually stored values, without copying the list. */
586+/** How many values an atom's long list keeps to a row (readonlyPagedArray). */
587+export const LIST_PAGE = 256;
589+/** Write a list as readonlyPagedArray reads it: its values LIST_PAGE to a row, and its length. */
590+export function writePagedArray(storage: GraphStateStorage, name: string, values: readonly unknown[]): void {
591+ for (let start = 0; start < values.length; start += LIST_PAGE)
592+ storage.write(`${name}:pages`, String(start / LIST_PAGE), values.slice(start, start + LIST_PAGE));
593+ storage.write(`${name}:meta`, "length", values.length);
594+}
596+/**
597+ * A stored list read a page of LIST_PAGE values at a time (abso Capacity): an atom's long lists, which
598+ * readonlyStoredArray reads a row per value. Collisions read every key a draft's atoms write; a draft deleting a big
599+ * file has thousands, and that was a row each.
600+ */
601+export function readonlyPagedArray<T>(storage: GraphStateStorage, name: string): readonly T[] {
602+ const length = () => {
603+ const count = storage.read(`${name}:meta`, "length");
604+ if (!Number.isSafeInteger(count) || (count as number) < 0) throw Error("invalid stored list length");
605+ return count as number;
606+ };
607+ length();
608+ let held = -1;
609+ let page: readonly unknown[] = [];
610+ const at = (index: number): T => {
611+ const p = Math.floor(index / LIST_PAGE);
612+ if (p !== held) {
613+ const raw = storage.read(`${name}:pages`, String(p));
614+ if (!Array.isArray(raw)) throw Error("missing stored list page");
615+ page = raw;
616+ held = p;
617+ }
618+ const value = page[index % LIST_PAGE];
619+ if (value === undefined) throw Error("missing stored list element");
620+ return (value && typeof value === "object" ? Object.freeze(value) : value) as T;
621+ };
622+ function* inOrder(): IterableIterator<T> {
623+ const count = length();
624+ for (let index = 0; index < count; index++) yield at(index);
625+ }
626+ return new Proxy([] as T[], {
627+ get(target, key, receiver) {
628+ if (key === "length") return length();
629+ if (key === Symbol.iterator || key === "values") return inOrder;
630+ if (indexKey(key)) return Number(key) >= length() ? undefined : at(Number(key));
631+ return Reflect.get(target, key, receiver);
632+ },
633+ has(target, key) {
634+ return indexKey(key) ? Number(key) < length() : Reflect.has(target, key);
635+ },
636+ ownKeys() {
637+ return [...Array.from({ length: length() }, (_, index) => String(index)), "length"];
638+ },
639+ getOwnPropertyDescriptor(target, key) {
640+ if (indexKey(key) && Number(key) < length())
641+ return { configurable: true, enumerable: true, writable: false, value: at(Number(key)) };
642+ return Reflect.getOwnPropertyDescriptor(target, key);
643+ },
644+ set() {
645+ throw Error("stored lists are read-only");
646+ },
647+ });
648+}
586650export function readonlyStoredArray<T>(
587651 storage: GraphStateStorage,
588652 name: string,
MCP
compare on this site's /mcp
CLI
abso diff 238 239 src/engine/state-source.ts --json
JSON
/christopher/abso-core/compare/238..239?file=src%2Fengine%2Fstate-source.ts&format=json