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

+112 −104 in 3 places
Lines 20–26 at 162 (were 20–26 at 161)
2020 readonly next: number;
2121}
2222export type SequenceOperation =
23− | { kind: "insert"; rank: number; text: string }
23+ | { kind: "insert"; rank: number; text: string; hidden?: boolean }
2424 | { kind: "visibility"; id: number; delta: number }
2525 | { kind: "move"; from: number; length: number; to: number };
2626const safe = (value: unknown): value is number => Number.isSafeInteger(value) && Number(value) >= 0;
Lines 132–142 at 162 (were 132–137 at 161)
132132 return file;
133133 }
134134 update(state: SequenceState, operation: SequenceOperation): SequenceState {
135+ return this.updateMany(state, [operation]);
136+ }
137+ /** A small bounded group shares changed AVL nodes and one locator flush. */
138+ updateMany(state: SequenceState, operations: readonly SequenceOperation[]): SequenceState {
139+ if (operations.length < 1 || operations.length > 16) throw Error("invalid sequence operation batch");
135140 this.#state(state);
136141 return this.storage.transaction(() => {
137142 let map = state.map;
Lines 197–313 at 162 (were 192–305 at 161)
192197 };
193198 let root = state.root,
194199 next = state.next;
195− if (operation.kind === "insert") {
196− const { rank, text } = operation;
197− if (!Number.isInteger(rank) || rank < 0 || rank > count(root) || next >= 2 ** 32) throw Error("invalid insert");
198− const added = next++;
199− const insert = (id: Page, at: number, p: Page): number => {
200− if (id === null)
201− return put({
202− id: added,
203− parent: p,
204− left: null,
205− right: null,
206− text,
207− deletions: 0,
208− height: 1,
209− count: 1,
210− visible: 1,
211− fileStarts: text.startsWith("root:") ? 1 : 0,
212− });
213− const node = get(id),
214− leftCount = count(node.left);
215− if (at <= leftCount) save({ ...node, left: insert(node.left, at, id) });
216− else save({ ...node, right: insert(node.right, at - leftCount - 1, id) });
217− return balance(id);
218− };
219− root = insert(root, rank, null);
220− parent(root, null);
221− } else if (operation.kind === "move") {
222− const { from, length, to } = operation;
223− const total = count(root);
224− if (
225− ![from, length, to].every(Number.isSafeInteger) ||
226− from < 0 ||
227− length < 0 ||
228− from + length > total ||
229− to < 0 ||
230− to > total - length
231− )
232− throw Error("invalid move range");
233− // Join two AVL trees around one existing stable marker.
234− const join = (left: Page, pivot: number, right: Page): number => {
235− if (height(left) > height(right) + 1) {
236− const node = get(left!);
237− save({ ...node, right: join(node.right, pivot, right) });
238− const result = balance(left!);
239− parent(result, null);
240− return result;
241− }
242− if (height(right) > height(left) + 1) {
243− const node = get(right!);
244− save({ ...node, left: join(left, pivot, node.left) });
245− const result = balance(right!);
246− parent(result, null);
247− return result;
248− }
249− return save({ ...get(pivot), left, right, parent: null });
250− };
251− const split = (id: Page, at: number): [Page, Page] => {
252− if (id === null) return [null, null];
253− const node = get(id),
254− size = count(node.left);
255− if (at <= size) {
256− const [left, middle] = split(node.left, at);
257− const right = join(middle, id, node.right);
200+ for (const operation of operations) {
201+ if (operation.kind === "insert") {
202+ const { rank, text } = operation;
203+ if (!Number.isInteger(rank) || rank < 0 || rank > count(root) || next >= 2 ** 32)
204+ throw Error("invalid insert");
205+ const added = next++;
206+ const insert = (id: Page, at: number, p: Page): number => {
207+ if (id === null)
208+ return put({
209+ id: added,
210+ parent: p,
211+ left: null,
212+ right: null,
213+ text,
214+ deletions: operation.hidden ? 1 : 0,
215+ height: 1,
216+ count: 1,
217+ visible: operation.hidden ? 0 : 1,
218+ fileStarts: text.startsWith("root:") ? 1 : 0,
219+ });
220+ const node = get(id),
221+ leftCount = count(node.left);
222+ if (at <= leftCount) save({ ...node, left: insert(node.left, at, id) });
223+ else save({ ...node, right: insert(node.right, at - leftCount - 1, id) });
224+ return balance(id);
225+ };
226+ root = insert(root, rank, null);
227+ parent(root, null);
228+ } else if (operation.kind === "move") {
229+ const { from, length, to } = operation;
230+ const total = count(root);
231+ if (
232+ ![from, length, to].every(Number.isSafeInteger) ||
233+ from < 0 ||
234+ length < 0 ||
235+ from + length > total ||
236+ to < 0 ||
237+ to > total - length
238+ )
239+ throw Error("invalid move range");
240+ // Join two AVL trees around one existing stable marker.
241+ const join = (left: Page, pivot: number, right: Page): number => {
242+ if (height(left) > height(right) + 1) {
243+ const node = get(left!);
244+ save({ ...node, right: join(node.right, pivot, right) });
245+ const result = balance(left!);
246+ parent(result, null);
247+ return result;
248+ }
249+ if (height(right) > height(left) + 1) {
250+ const node = get(right!);
251+ save({ ...node, left: join(left, pivot, node.left) });
252+ const result = balance(right!);
253+ parent(result, null);
254+ return result;
255+ }
256+ return save({ ...get(pivot), left, right, parent: null });
257+ };
258+ const split = (id: Page, at: number): [Page, Page] => {
259+ if (id === null) return [null, null];
260+ const node = get(id),
261+ size = count(node.left);
262+ if (at <= size) {
263+ const [left, middle] = split(node.left, at);
264+ const right = join(middle, id, node.right);
265+ parent(left, null);
266+ parent(right, null);
267+ return [left, right];
268+ }
269+ const [middle, right] = split(node.right, at - size - 1);
270+ const left = join(node.left, id, middle);
258271 parent(left, null);
259272 parent(right, null);
260273 return [left, right];
274+ };
275+ const merge = (left: Page, right: Page): Page => {
276+ if (left === null) {
277+ parent(right, null);
278+ return right;
279+ }
280+ if (right === null) {
281+ parent(left, null);
282+ return left;
283+ }
284+ const [pivot, rest] = split(right, 1);
285+ return join(left, pivot!, rest);
286+ };
287+ if (length && from !== to) {
288+ const [left, tail] = split(root, from);
289+ const [moved, right] = split(tail, length);
290+ const remaining = merge(left, right);
291+ const [before, after] = split(remaining, to);
292+ root = merge(merge(before, moved), after);
293+ parent(root, null);
261294 }
262− const [middle, right] = split(node.right, at - size - 1);
263− const left = join(node.left, id, middle);
264− parent(left, null);
265− parent(right, null);
266− return [left, right];
267− };
268− const merge = (left: Page, right: Page): Page => {
269− if (left === null) {
270− parent(right, null);
271− return right;
295+ } else if (operation.kind === "visibility") {
296+ let node = get(operation.id);
297+ if (
298+ !node ||
299+ !Number.isInteger(operation.delta) ||
300+ Math.abs(operation.delta) !== 1 ||
301+ node.deletions + operation.delta < 0
302+ )
303+ throw Error("invalid visibility");
304+ save({ ...node, deletions: node.deletions + operation.delta });
305+ while (node.parent !== null) {
306+ node = get(node.parent);
307+ save(node);
272308 }
273− if (right === null) {
274− parent(left, null);
275− return left;
276− }
277− const [pivot, rest] = split(right, 1);
278− return join(left, pivot!, rest);
279− };
280− if (length && from !== to) {
281− const [left, tail] = split(root, from);
282− const [moved, right] = split(tail, length);
283− const remaining = merge(left, right);
284− const [before, after] = split(remaining, to);
285− root = merge(merge(before, moved), after);
286− parent(root, null);
287− }
288− } else if (operation.kind === "visibility") {
289− let node = get(operation.id);
290− if (
291− !node ||
292− !Number.isInteger(operation.delta) ||
293− Math.abs(operation.delta) !== 1 ||
294− node.deletions + operation.delta < 0
295− )
296− throw Error("invalid visibility");
297− save({ ...node, deletions: node.deletions + operation.delta });
298− while (node.parent !== null) {
299− node = get(node.parent);
300− save(node);
301− }
302− } else throw Error("unknown operation");
309+ } else throw Error("unknown operation");
310+ }
303311 // Keep locator staging bounded even if a valid split/merge changes more
304312 // than one batch. The enclosing transaction commits all batches together.
305313 let batch: Array<readonly [number, SequenceNode]> = [];
MCP
compare on this site's /mcp
CLI
abso diff 161 162 src/engine/experimental/projection-sequence.ts --json
JSON
/christopher/abso-core/compare/161..162?file=src%2Fengine%2Fexperimental%2Fprojection-sequence.ts&format=json