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 161 to 162

Compare

+40 −30 in 1 place
Lines 63–114 at 162 (were 63–104 at 161)
6363 this.#storage.write(this.#collection, "next", next + 1);
6464 return next;
6565 }
66− /** Persist only pages reachable from the final root of a bounded update batch. */
66+ /** Update each touched branch once, retaining at most 256 decoded values. */
6767 setMany(root: Page, values: ReadonlyArray<readonly [number, T]>): Page {
6868 page(root);
6969 if (values.length > 256) throw Error("locator batch limit");
7070 return this.#storage.transaction(() => {
71− const staged = new Map<string, unknown>();
72− const storage: GraphStateStorage = {
73− read: (collection, key) =>
74− collection === this.#collection && staged.has(key) ? staged.get(key) : this.#storage.read(collection, key),
75− write: (collection, key, value) => {
76− if (collection !== this.#collection) throw Error("unexpected batch collection");
77− staged.set(key, value);
78− },
79− remove: () => {
80− throw Error("unexpected batch removal");
81− },
82− entries: () => {
83− throw Error("unexpected batch scan");
84− },
85− transaction: (body) => body(),
71+ if (!values.length) return root;
72+ let next = this.#storage.read(this.#collection, "next") ?? 0;
73+ if (!safe(next)) throw Error("invalid locator allocation");
74+ const write = (node: Node): number => {
75+ if (!safe(next) || !Number.isSafeInteger(next + 1)) throw Error("invalid locator allocation");
76+ if (this.#storage.read(this.#collection, String(next)) !== undefined)
77+ throw Error("locator allocation collision");
78+ const id = next++;
79+ this.#storage.write(this.#collection, String(id), node);
80+ return id;
8681 };
87− // The namespace is encoded into the collection at construction.
88− const namespace = JSON.parse(this.#collection.slice("experimental-locator:".length)) as string;
89− const index = new ProjectionLocator<T>(storage, namespace, this.#decode);
90− let result = root;
91− for (const [id, value] of values) result = index.set(result, id, value);
92− const retained = new Set<number>();
93− const visit = (id: Page): void => {
94− if (id === null || retained.has(id) || !staged.has(String(id))) return;
95− retained.add(id);
96− const node = staged.get(String(id)) as Node;
97− if (node.kind === "branch") for (const child of Object.values(node.children)) visit(child);
82+ const checked = new Map<string, T>();
83+ for (const [id, value] of values) checked.set(keyOf(id), structuredClone(this.#decode(structuredClone(value))));
84+ const updates = [...checked].sort(([a], [b]) => a.localeCompare(b));
85+ const visit = (current: Page, edits: [string, T][], parent?: string, digit?: string, depth = 0): Page => {
86+ if (!edits.length) return current;
87+ if (depth > 8) throw Error("invalid locator depth");
88+ const node = current === null ? undefined : this.#read(current, parent, digit);
89+ let prefix = node?.prefix ?? edits[0]![0];
90+ for (const [key] of edits) {
91+ let common = 0;
92+ while (common < prefix.length && prefix[common] === key[common]) common++;
93+ prefix = prefix.slice(0, common);
94+ }
95+ if (prefix.length === 8) return write({ format: 1, kind: "leaf", prefix, value: edits[edits.length - 1]![1] });
96+ const children: Record<string, number> =
97+ node?.kind === "branch" && node.prefix === prefix ? { ...node.children } : {};
98+ if (node && node.prefix !== prefix) children[node.prefix[prefix.length]!] = current!;
99+ const groups = new Map<string, [string, T][]>();
100+ for (const edit of edits) {
101+ const edge = edit[0][prefix.length]!;
102+ const group = groups.get(edge) ?? [];
103+ group.push(edit);
104+ groups.set(edge, group);
105+ }
106+ for (const [edge, group] of groups)
107+ children[edge] = visit(children[edge] ?? null, group, prefix, edge, depth + 1)!;
108+ return write({ format: 1, kind: "branch", prefix, children });
98109 };
99− visit(result);
100− for (const id of retained) this.#storage.write(this.#collection, String(id), staged.get(String(id)));
101− if (staged.has("next")) this.#storage.write(this.#collection, "next", staged.get("next"));
110+ const result = visit(root, updates);
111+ this.#storage.write(this.#collection, "next", next);
102112 return result;
103113 });
104114 }
MCP
compare on this site's /mcp
CLI
abso diff 161 162 src/engine/experimental/projection-locator.ts --json
JSON
/christopher/abso-core/compare/161..162?file=src%2Fengine%2Fexperimental%2Fprojection-locator.ts&format=json