Skip to content

abso-core

Public
Not checked

Versions 161 to 162

Compare

+55 −1 in 5 places
Lines 96–118 at 162 (were 96–101 at 161)
9696 }
9797
9898 /** Reject an oversized canonical frame before loading its text into JavaScript. */
99+ frameBytes(seq: number): number {
100+ if (!Number.isSafeInteger(seq) || seq < 0) throw Error("invalid canonical frame position");
101+ const size = this.storage.sql
102+ .exec(
103+ "SELECT COUNT(*) AS parts, COALESCE(SUM(LENGTH(CAST(text AS BLOB))), 0) AS bytes FROM log WHERE seq = ?",
104+ seq,
105+ )
106+ .toArray()[0] as { parts: number; bytes: number };
107+ if (!size || size.parts < 1 || size.parts > 256 || size.bytes < 1 || !Number.isSafeInteger(size.bytes))
108+ throw Error("canonical frame exceeds hard decoding bound or is missing");
109+ return size.bytes;
110+ }
111+ /** A larger first frame gets its own budget; later frames are deferred. */
112+ adoptionPageBytes(from: number): number {
113+ return Math.max(1_048_576, this.frameBytes(from));
114+ }
99116 boundedFrame(seq: number, maxBytes: number): string {
100117 if (
101118 !Number.isSafeInteger(seq) ||
Lines 139–164 at 162 (were 122–127 at 161)
122139 return rows.map((row) => row.text).join("");
123140 }
124141
142+ /** Stream one canonical frame without retaining its complete JSON text. */
143+ *frameChunks(seq: number): IterableIterator<string> {
144+ if (!Number.isSafeInteger(seq) || seq < 0) throw Error("invalid canonical frame position");
145+ let expected = 0;
146+ for (;;) {
147+ const rows = this.storage.sql
148+ .exec("SELECT part, text FROM log WHERE seq = ? AND part >= ? ORDER BY part LIMIT 1", seq, expected)
149+ .toArray() as { part: number; text: string }[];
150+ if (!rows.length) {
151+ if (!expected) throw Error("canonical frame is missing");
152+ return;
153+ }
154+ const row = rows[0]!;
155+ if (row.part !== expected || row.text.length > LOG_PART_CHARACTERS)
156+ throw Error("canonical frame parts are incomplete or oversized");
157+ expected++;
158+ yield row.text;
159+ }
160+ }
125162 /** Refreshes the in-memory cursor after an enclosing transaction rolls back. */
126163 refreshSequence(): void {
127164 const rows = this.storage.sql.exec("SELECT COALESCE(MAX(seq), -1) AS last FROM log").toArray() as {
Lines 561–578 at 162 (were 524–534 at 161)
524561 /** Reads stored entries by log position, for the feed and replay (#41); absent, those answer 501. */
525562 private readonly read: ((from: number, limit: number) => Entry[]) | undefined;
526563 private readonly store: SqliteLog | undefined;
564+ private readonly historical: (<T>(at: number, operation: (project: Project) => T) => T) | undefined;
527565
528− constructor(project: Project, read?: (from: number, limit: number) => Entry[], store?: SqliteLog) {
566+ constructor(
567+ project: Project,
568+ read?: (from: number, limit: number) => Entry[],
569+ store?: SqliteLog,
570+ historical?: <T>(at: number, operation: (project: Project) => T) => T,
571+ ) {
529572 this.project = project;
530573 this.read = read;
531574 this.store = store;
575+ this.historical = historical;
532576 }
533577
534578 /** The project's events from log position `from` (#41): reading consumes nothing. */
Lines 682–692 at 162 (were 638–643 at 161)
638682 return this.replica;
639683 }
640684 statusAt(at: number) {
685+ if (this.historical)
686+ return this.historical(Math.max(0, Math.min(at, this.project.logLength)), (p) => ({
687+ at: Math.min(at, this.project.logLength),
688+ ...(p.initialized ? p.status() : { version: -1, agents: [] }),
689+ }));
641690 const p = this.at(at);
642691 const answer = {
643692 at: Math.min(at, this.project.logLength),
Lines 696–706 at 162 (were 647–652 at 161)
647696 return answer;
648697 }
649698 whereAt(at: number) {
699+ if (this.historical)
700+ return this.historical(Math.max(0, Math.min(at, this.project.logLength)), (p) => ({
701+ at: Math.min(at, this.project.logLength),
702+ ...(p.initialized ? where(p) : { version: -1, files: {} }),
703+ }));
650704 const p = this.at(at);
651705 const answer = {
652706 at: Math.min(at, this.project.logLength),
MCP
compare on this site's /mcp
CLI
abso diff 161 162 server/src/engine-project.ts --json
JSON
/christopher/abso-core/compare/161..162?file=server%2Fsrc%2Fengine-project.ts&format=json