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 157 to 318

Compare

+137 −12 in 13 places
Lines 3–15 at 318 (were 3–13 at 157)
33// 2 MB) is split across rows and joined on load. Ported from the platform's worker/src/engine-project.ts; the
44// writer-adoption and R2 version parts are left out.
55
6+import { jsonValueChunks } from "../../src/engine/json-value-chunks.ts";
67import { blame, folderBlame, why } from "../../worker/project/blame.ts";
78import { feedEvents } from "../../worker/project/feed.ts";
89import { type Entry, type ProjectStore as LogStore, MemoryStore, Project } from "../../worker/project/project.ts";
910import type { EditBody, ProjectCalls, ProjectHistory } from "../../worker/project/project-api.ts";
1011import { where } from "../../worker/project/where.ts";
12+import type { PushSnapshotMetadata } from "./push-snapshot.ts";
1113
1214/** The parts of a Durable Object's storage the log and blob store use, declared structurally so tests can stand in. */
1315export interface SqliteStorage {
Lines 35–56 at 318 (were 33–38 at 157)
3335 return parts;
3436}
3537
38+/** Retains one log row plus an encoder fragment, preserving legacy row boundaries. */
39+export function* streamedLogParts(value: unknown): IterableIterator<string> {
40+ let pending = "";
41+ for (const chunk of jsonValueChunks(value)) {
42+ pending += chunk;
43+ while (pending.length > LOG_PART_CHARACTERS) {
44+ let end = LOG_PART_CHARACTERS;
45+ const last = pending.charCodeAt(end - 1);
46+ if (last >= 0xd800 && last <= 0xdbff) end--;
47+ yield pending.slice(0, end);
48+ pending = pending.slice(end);
49+ }
50+ }
51+ if (pending) yield pending;
52+}
3654/** The lines an entry's atoms write: what a loaded project's size grows with (#46, #56). */
3755function linesIn(entry: Entry): number {
3856 let n = 0;
Lines 114–136 at 318 (were 96–101 at 157)
96114 }
97115
98116 /** Reject an oversized canonical frame before loading its text into JavaScript. */
117+ frameBytes(seq: number): number {
118+ if (!Number.isSafeInteger(seq) || seq < 0) throw Error("invalid canonical frame position");
119+ const size = this.storage.sql
120+ .exec(
121+ "SELECT COUNT(*) AS parts, COALESCE(SUM(LENGTH(CAST(text AS BLOB))), 0) AS bytes FROM log WHERE seq = ?",
122+ seq,
123+ )
124+ .toArray()[0] as { parts: number; bytes: number };
125+ if (!size || size.parts < 1 || size.parts > 256 || size.bytes < 1 || !Number.isSafeInteger(size.bytes))
126+ throw Error("canonical frame exceeds hard decoding bound or is missing");
127+ return size.bytes;
128+ }
129+ /** A larger first frame gets its own budget; later frames are deferred. */
130+ adoptionPageBytes(from: number): number {
131+ return Math.max(1_048_576, this.frameBytes(from));
132+ }
99134 boundedFrame(seq: number, maxBytes: number): string {
100135 if (
101136 !Number.isSafeInteger(seq) ||
Lines 157–182 at 318 (were 122–127 at 157)
122157 return rows.map((row) => row.text).join("");
123158 }
124159
160+ /** Stream one canonical frame without retaining its complete JSON text. */
161+ *frameChunks(seq: number): IterableIterator<string> {
162+ if (!Number.isSafeInteger(seq) || seq < 0) throw Error("invalid canonical frame position");
163+ let expected = 0;
164+ for (;;) {
165+ const rows = this.storage.sql
166+ .exec("SELECT part, text FROM log WHERE seq = ? AND part >= ? ORDER BY part LIMIT 1", seq, expected)
167+ .toArray() as { part: number; text: string }[];
168+ if (!rows.length) {
169+ if (!expected) throw Error("canonical frame is missing");
170+ return;
171+ }
172+ const row = rows[0]!;
173+ if (row.part !== expected || row.text.length > LOG_PART_CHARACTERS)
174+ throw Error("canonical frame parts are incomplete or oversized");
175+ expected++;
176+ yield row.text;
177+ }
178+ }
125180 /** Refreshes the in-memory cursor after an enclosing transaction rolls back. */
126181 refreshSequence(): void {
127182 const rows = this.storage.sql.exec("SELECT COALESCE(MAX(seq), -1) AS last FROM log").toArray() as {
Lines 442–452 at 318 (were 387–397 at 157)
387442 if (keys > 0) this.storage.sql.exec("UPDATE counts SET value = value + ? WHERE name = 'keys'", keys);
388443 let chars = 0;
389444 for (const entry of entries) {
390− const json = JSON.stringify(entry);
391− logParts(json).forEach((text, part) => {
445+ let part = 0;
446+ for (const text of streamedLogParts(entry)) {
392447 chars += text.length;
393− this.storage.sql.exec("INSERT INTO log (seq, part, text) VALUES (?, ?, ?)", next, part, text);
394− });
448+ this.storage.sql.exec("INSERT INTO log (seq, part, text) VALUES (?, ?, ?)", next, part++, text);
449+ }
395450 next++;
396451 }
397452 // Chars are only added to once counted: a log from before the count is summed whole first (logSize).
Lines 496–507 at 318 (were 441–448 at 157)
441496 ...(folder !== undefined ? { folder } : {}),
442497 });
443498 }
444− why(file: string, line: number, draft?: string, agent?: string) {
445− return why(this.project, file, line, { ...(draft ? { draft } : {}), ...(agent ? { agent } : {}) });
499+ why(file: string, line: number, draft?: string, agent?: string, version?: number) {
500+ return why(this.project, file, line, {
501+ ...(draft ? { draft } : {}),
502+ ...(agent ? { agent } : {}),
503+ ...(version !== undefined ? { version } : {}),
504+ });
446505 }
447506 where() {
448507 return where(this.project);
Lines 523–535 at 318 (were 464–472 at 157)
464523 fileAt(path: string, version: number, draft: string | null, agent?: string) {
465524 return this.project.fileAt(path, version, { draft, ...(agent ? { agent } : {}) });
466525 }
467− compare(from: number, to: number, draft: string | null, agent?: string) {
468− return this.project.compare(from, to, { draft, ...(agent ? { agent } : {}) });
526+ compare(from: number, to: number, draft: string | null, agent?: string, summary?: boolean) {
527+ const where = { draft, ...(agent ? { agent } : {}) };
528+ return summary ? this.project.compareSummary(from, to, where) : this.project.compare(from, to, where);
469529 }
530+ without(version: number, versions: readonly number[]) {
531+ return this.project.without(version, versions);
532+ }
470533 show(version: number, draft: string | null, agent?: string) {
471534 return this.project.show(version, { draft, ...(agent ? { agent } : {}) });
472535 }
Lines 572–581 at 318 (were 509–514 at 157)
509572 announcePerson(person: { id: string; name: string }, text: string, to?: string[]) {
510573 return this.project.announcePerson(person, text, to, Date.now());
511574 }
575+ /** A seat's earlier chat hears that another chat used the seat (277, groups); as abso's worker has it. */
576+ seatNotice(agent: string, place: string, key: string) {
577+ return this.project.seatNotice(agent, place, key);
578+ }
512579 starting(agent: string, text: string | null, files?: string[], options: { issue?: unknown; done?: unknown } = {}) {
513580 return this.project.starting(agent, text, files, Date.now(), options);
514581 }
Lines 591–608 at 318 (were 524–534 at 157)
524591 /** Reads stored entries by log position, for the feed and replay (#41); absent, those answer 501. */
525592 private readonly read: ((from: number, limit: number) => Entry[]) | undefined;
526593 private readonly store: SqliteLog | undefined;
594+ private readonly historical: (<T>(at: number, operation: (project: Project) => T) => T) | undefined;
527595
528− constructor(project: Project, read?: (from: number, limit: number) => Entry[], store?: SqliteLog) {
596+ constructor(
597+ project: Project,
598+ read?: (from: number, limit: number) => Entry[],
599+ store?: SqliteLog,
600+ historical?: <T>(at: number, operation: (project: Project) => T) => T,
601+ ) {
529602 this.project = project;
530603 this.read = read;
531604 this.store = store;
605+ this.historical = historical;
532606 }
533607
534608 /** The project's events from log position `from` (#41): reading consumes nothing. */
Lines 610–632 at 318 (were 536–549 at 157)
536610 if (!this.read) throw Object.assign(new Error("the feed needs the log"), { code: "not-implemented" });
537611 const end = this.project.logLength;
538612 const start = Math.max(0, Math.min(from, end));
539− const entries = start < end ? this.read(start, Math.min(limit, end - start)) : [];
613+ // Discard each canonical payload after extracting its event. A feed page must
614+ // not retain every historical file payload in the requested range.
615+ const events = [];
616+ let next = start;
617+ while (next < end && next - start < limit) {
618+ const entries = this.read(next, 1);
619+ if (entries.length === 0) break;
620+ events.push(...feedEvents(entries, next));
621+ next += entries.length;
622+ }
540623 // A drop event names the files it took out (#41), so a timeline needs no read per drop.
541− const events = feedEvents(entries, start).map((e) => {
624+ const enriched = events.map((e) => {
542625 if (e.type !== "drop" || e.version === undefined) return e;
543626 const v = this.project.log({ limit: 1, before: e.version + 1 }).versions[0];
544627 return v && v.version === e.version ? { ...e, dropped: v.files } : e;
545628 });
546− return { next: start + entries.length, end, events };
629+ return { next, end, events: enriched };
547630 }
548631
549632 /** The log position for a time (ms since 1970) or a version of shared (#41). */
Lines 712–722 at 318 (were 629–634 at 157)
629712 return this.replica;
630713 }
631714 statusAt(at: number) {
715+ if (this.historical)
716+ return this.historical(Math.max(0, Math.min(at, this.project.logLength)), (p) => ({
717+ at: Math.min(at, this.project.logLength),
718+ ...(p.initialized ? p.status() : { version: -1, agents: [] }),
719+ }));
632720 const p = this.at(at);
633721 const answer = {
634722 at: Math.min(at, this.project.logLength),
Lines 726–736 at 318 (were 638–643 at 157)
638726 return answer;
639727 }
640728 whereAt(at: number) {
729+ if (this.historical)
730+ return this.historical(Math.max(0, Math.min(at, this.project.logLength)), (p) => ({
731+ at: Math.min(at, this.project.logLength),
732+ ...(p.initialized ? where(p) : { version: -1, files: {} }),
733+ }));
641734 const p = this.at(at);
642735 const answer = {
643736 at: Math.min(at, this.project.logLength),
Lines 820–857 at 318 (were 727–732 at 157)
727820 filesAt(version: number) {
728821 return this.project.viewAt(version).files();
729822 }
823+ fileTextAt(version: number, path: string): string {
824+ return this.project.viewAt(version).text(path);
825+ }
826+ /** One scoped batch: at most 64 files and 64 Ki characters plus one whole file. */
827+ fileTextsAt(version: number, paths: readonly string[]): Record<string, string> {
828+ const view = this.project.viewAt(version);
829+ const files: Record<string, string> = Object.create(null);
830+ let characters = 0;
831+ for (const path of paths.slice(0, 64)) {
832+ const text = view.attrs(path).link !== null ? "" : view.text(path);
833+ files[path] = text;
834+ characters += text.length;
835+ if (characters >= 65536) break;
836+ }
837+ return files;
838+ }
839+ /** Capture metadata now; each text read reopens the captured version in a fresh host scope. */
840+ sharedPushMetadata(): PushSnapshotMetadata {
841+ const version = this.project.version;
842+ const view = this.project.viewAt(version);
843+ const paths: string[] = [];
844+ const modes: PushSnapshotMetadata["modes"] = Object.create(null);
845+ const blobs: Record<string, string> = Object.create(null);
846+ for (const path of view.paths()) {
847+ const attrs = view.attrs(path);
848+ modes[path] = { exec: attrs.exec, link: attrs.link };
849+ if (attrs.blob !== null) blobs[path] = attrs.blob;
850+ else paths.push(path);
851+ }
852+ const by = version > 0 ? this.project.published(version) : undefined;
853+ return { version, paths, modes, blobs, ...(by ? { last: { agent: by.agent, message: by.message } } : {}) };
854+ }
730855 blobsAt(version: number) {
731856 return this.project.viewAt(version).blobs();
732857 }
MCP
compare on this site's /mcp
CLI
abso diff 157 318 server/src/engine-project.ts --json
JSON
/christopher/abso-core/compare/157..318?file=server%2Fsrc%2Fengine-project.ts&format=json