{"file":"server/src/engine-project.ts","version":318,"total":884,"from":1,"to":884,"lines":[{"n":1,"text":"// The engine's Project (worker/project/project.ts) behind the server's calls, with its append-only log kept in the","atom":"a1445","author":"speed","version":150},{"n":2,"text":"// Durable Object's SQLite. An entry longer than one row allows (init holds every starting file; SQLite rows stop at","atom":"a1445","author":"speed","version":150},{"n":3,"text":"// 2 MB) is split across rows and joined on load. Ported from the platform's worker/src/engine-project.ts; the","atom":"a1445","author":"speed","version":150},{"n":4,"text":"// writer-adoption and R2 version parts are left out.","atom":"a1445","author":"speed","version":150},{"n":5,"text":"","atom":"a1445","author":"speed","version":150},{"n":6,"text":"import { jsonValueChunks } from \"../../src/engine/json-value-chunks.ts\";","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":7,"text":"import { blame, folderBlame, why } from \"../../worker/project/blame.ts\";","atom":"a1445","author":"speed","version":150},{"n":8,"text":"import { feedEvents } from \"../../worker/project/feed.ts\";","atom":"a1445","author":"speed","version":150},{"n":9,"text":"import { type Entry, type ProjectStore as LogStore, MemoryStore, Project } from \"../../worker/project/project.ts\";","atom":"a1483","author":"speed","version":150},{"n":10,"text":"import type { EditBody, ProjectCalls, ProjectHistory } from \"../../worker/project/project-api.ts\";","atom":"a1445","author":"speed","version":150},{"n":11,"text":"import { where } from \"../../worker/project/where.ts\";","atom":"a1445","author":"speed","version":150},{"n":12,"text":"import type { PushSnapshotMetadata } from \"./push-snapshot.ts\";","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":13,"text":"","atom":"a1445","author":"speed","version":150},{"n":14,"text":"/** The parts of a Durable Object's storage the log and blob store use, declared structurally so tests can stand in. */","atom":"a1445","author":"speed","version":150},{"n":15,"text":"export interface SqliteStorage {","atom":"a1445","author":"speed","version":150},{"n":16,"text":"\tsql: { exec(query: string, ...bindings: unknown[]): { toArray(): unknown[] } };","atom":"a1445","author":"speed","version":150},{"n":17,"text":"\ttransactionSync<T>(fn: () => T): T;","atom":"a1445","author":"speed","version":150},{"n":18,"text":"}","atom":"a1445","author":"speed","version":150},{"n":19,"text":"","atom":"a1445","author":"speed","version":150},{"n":20,"text":"// Characters per row. SQLite's 2 MB cap is in bytes, and a character is at","atom":"a1445","author":"speed","version":150},{"n":21,"text":"// most 3 bytes of UTF-8 (an emoji is 2 characters and 4 bytes), so 600,000 stays under it.","atom":"a1445","author":"speed","version":150},{"n":22,"text":"export const LOG_PART_CHARACTERS = 600_000;","atom":"a1589","author":"codex-capacity-chair","version":157},{"n":23,"text":"","atom":"a1445","author":"speed","version":150},{"n":24,"text":"/** An entry's JSON in rows of at most LOG_PART_CHARACTERS characters, never cutting an emoji's two halves apart. */","atom":"a1589","author":"codex-capacity-chair","version":157},{"n":25,"text":"export function logParts(text: string): string[] {","atom":"a1445","author":"speed","version":150},{"n":26,"text":"\tconst parts: string[] = [];","atom":"a1445","author":"speed","version":150},{"n":27,"text":"\tlet at = 0;","atom":"a1445","author":"speed","version":150},{"n":28,"text":"\tdo {","atom":"a1445","author":"speed","version":150},{"n":29,"text":"\t\tlet end = Math.min(at + LOG_PART_CHARACTERS, text.length);","atom":"a1589","author":"codex-capacity-chair","version":157},{"n":30,"text":"\t\tconst c = text.charCodeAt(end - 1);","atom":"a1445","author":"speed","version":150},{"n":31,"text":"\t\tif (end < text.length && c >= 0xd800 && c <= 0xdbff) end--;","atom":"a1445","author":"speed","version":150},{"n":32,"text":"\t\tparts.push(text.slice(at, end));","atom":"a1445","author":"speed","version":150},{"n":33,"text":"\t\tat = end;","atom":"a1445","author":"speed","version":150},{"n":34,"text":"\t} while (at < text.length);","atom":"a1445","author":"speed","version":150},{"n":35,"text":"\treturn parts;","atom":"a1445","author":"speed","version":150},{"n":36,"text":"}","atom":"a1445","author":"speed","version":150},{"n":37,"text":"","atom":"a1445","author":"speed","version":150},{"n":38,"text":"/** Retains one log row plus an encoder fragment, preserving legacy row boundaries. */","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":39,"text":"export function* streamedLogParts(value: unknown): IterableIterator<string> {","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":40,"text":"\tlet pending = \"\";","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":41,"text":"\tfor (const chunk of jsonValueChunks(value)) {","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":42,"text":"\t\tpending += chunk;","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":43,"text":"\t\twhile (pending.length > LOG_PART_CHARACTERS) {","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":44,"text":"\t\t\tlet end = LOG_PART_CHARACTERS;","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":45,"text":"\t\t\tconst last = pending.charCodeAt(end - 1);","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":46,"text":"\t\t\tif (last >= 0xd800 && last <= 0xdbff) end--;","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":47,"text":"\t\t\tyield pending.slice(0, end);","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":48,"text":"\t\t\tpending = pending.slice(end);","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":49,"text":"\t\t}","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":50,"text":"\t}","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":51,"text":"\tif (pending) yield pending;","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":52,"text":"}","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":53,"text":"","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":54,"text":"/** The lines an entry's atoms write: what a loaded project's size grows with (#46, #56). */","atom":"a1445","author":"speed","version":150},{"n":55,"text":"function linesIn(entry: Entry): number {","atom":"a1445","author":"speed","version":150},{"n":56,"text":"\tlet n = 0;","atom":"a1445","author":"speed","version":150},{"n":57,"text":"\tfor (const a of [","atom":"a1445","author":"speed","version":150},{"n":58,"text":"\t\t(entry as { atom?: { inserts?: { lines: unknown[] }[] } }).atom,","atom":"a1445","author":"speed","version":150},{"n":59,"text":"\t\t(entry as { tie?: { inserts?: { lines: unknown[] }[] } }).tie,","atom":"a1445","author":"speed","version":150},{"n":60,"text":"\t]) {","atom":"a1445","author":"speed","version":150},{"n":61,"text":"\t\tfor (const r of a?.inserts ?? []) n += r.lines.length;","atom":"a1445","author":"speed","version":150},{"n":62,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":63,"text":"\treturn n;","atom":"a1445","author":"speed","version":150},{"n":64,"text":"}","atom":"a1445","author":"speed","version":150},{"n":65,"text":"","atom":"a1445","author":"speed","version":150},{"n":66,"text":"/** The version of shared an entry makes, or undefined (abso issue 78: the access check reads it without loading). */","atom":"a1445","author":"speed","version":150},{"n":67,"text":"function sharedVersionOf(entry: Entry): number | undefined {","atom":"a1445","author":"speed","version":150},{"n":68,"text":"\tif (entry.type === \"init\") return 0;","atom":"a1445","author":"speed","version":150},{"n":69,"text":"\tif (entry.type === \"land\" || entry.type === \"drop\") return entry.version;","atom":"a1445","author":"speed","version":150},{"n":70,"text":"\tif (entry.type === \"publish\" && (entry.space ?? \"\") === \"\") return entry.version;","atom":"a1445","author":"speed","version":150},{"n":71,"text":"\treturn undefined;","atom":"a1445","author":"speed","version":150},{"n":72,"text":"}","atom":"a1445","author":"speed","version":150},{"n":73,"text":"","atom":"a1445","author":"speed","version":150},{"n":74,"text":"/** Who made that version of shared, and when. Init is not a publish (abso issue 86). */","atom":"a1445","author":"speed","version":150},{"n":75,"text":"function lastPublishOf(entry: Entry): { agent: string; time: number } | undefined {","atom":"a1445","author":"speed","version":150},{"n":76,"text":"\tif (entry.type === \"land\" || entry.type === \"drop\") return { agent: entry.agent, time: entry.time };","atom":"a1445","author":"speed","version":150},{"n":77,"text":"\tif (entry.type === \"publish\" && (entry.space ?? \"\") === \"\") return { agent: entry.agent, time: entry.time };","atom":"a1445","author":"speed","version":150},{"n":78,"text":"\treturn undefined;","atom":"a1445","author":"speed","version":150},{"n":79,"text":"}","atom":"a1445","author":"speed","version":150},{"n":80,"text":"","atom":"a1445","author":"speed","version":150},{"n":81,"text":"/** An entry's claim keys and deletes (#46): with entries and lines, what the load guard estimates memory by. */","atom":"a1445","author":"speed","version":150},{"n":82,"text":"function keysIn(entry: Entry): number {","atom":"a1445","author":"speed","version":150},{"n":83,"text":"\tlet n = 0;","atom":"a1445","author":"speed","version":150},{"n":84,"text":"\tfor (const a of [","atom":"a1445","author":"speed","version":150},{"n":85,"text":"\t\t(entry as { atom?: Partial<Record<\"writes\" | \"reads\" | \"holds\" | \"deletes\", unknown[]>> }).atom,","atom":"a1445","author":"speed","version":150},{"n":86,"text":"\t\t(entry as { tie?: Partial<Record<\"writes\" | \"reads\" | \"holds\" | \"deletes\", unknown[]>> }).tie,","atom":"a1445","author":"speed","version":150},{"n":87,"text":"\t]) {","atom":"a1445","author":"speed","version":150},{"n":88,"text":"\t\tif (a) n += (a.writes?.length ?? 0) + (a.reads?.length ?? 0) + (a.holds?.length ?? 0) + (a.deletes?.length ?? 0);","atom":"a1445","author":"speed","version":150},{"n":89,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":90,"text":"\treturn n;","atom":"a1445","author":"speed","version":150},{"n":91,"text":"}","atom":"a1445","author":"speed","version":150},{"n":92,"text":"","atom":"a1445","author":"speed","version":150},{"n":93,"text":"export class SqliteLog implements LogStore {","atom":"a1445","author":"speed","version":150},{"n":94,"text":"\tprivate storage: SqliteStorage;","atom":"a1445","author":"speed","version":150},{"n":95,"text":"\tprivate next: number;","atom":"a1445","author":"speed","version":150},{"n":96,"text":"","atom":"a1445","author":"speed","version":150},{"n":97,"text":"\tconstructor(storage: SqliteStorage) {","atom":"a1445","author":"speed","version":150},{"n":98,"text":"\t\tthis.storage = storage;","atom":"a1445","author":"speed","version":150},{"n":99,"text":"\t\tstorage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":100,"text":"\t\t\t\"CREATE TABLE IF NOT EXISTS log (seq INTEGER, part INTEGER, text TEXT NOT NULL, PRIMARY KEY (seq, part))\",","atom":"a1445","author":"speed","version":150},{"n":101,"text":"\t\t);","atom":"a1445","author":"speed","version":150},{"n":102,"text":"\t\tstorage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":103,"text":"\t\t\t\"CREATE TABLE IF NOT EXISTS shapes (space TEXT NOT NULL, version INTEGER NOT NULL, value TEXT NOT NULL, PRIMARY KEY (space, version))\",","atom":"a1445","author":"speed","version":150},{"n":104,"text":"\t\t);","atom":"a1445","author":"speed","version":150},{"n":105,"text":"\t\tstorage.sql.exec(\"CREATE TABLE IF NOT EXISTS counts (name TEXT PRIMARY KEY, value INTEGER NOT NULL)\");","atom":"a1445","author":"speed","version":150},{"n":106,"text":"\t\tstorage.sql.exec(\"CREATE TABLE IF NOT EXISTS marks (name TEXT PRIMARY KEY, value TEXT NOT NULL)\");","atom":"a1445","author":"speed","version":150},{"n":107,"text":"\t\tconst rows = storage.sql.exec(\"SELECT COALESCE(MAX(seq), -1) AS last FROM log\").toArray() as { last: number }[];","atom":"a1445","author":"speed","version":150},{"n":108,"text":"\t\tthis.next = (rows[0]?.last ?? -1) + 1;","atom":"a1445","author":"speed","version":150},{"n":109,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":110,"text":"","atom":"a1445","author":"speed","version":150},{"n":111,"text":"\t/** The seq the next entry would take. A copy's next page must start here. */","atom":"a1445","author":"speed","version":150},{"n":112,"text":"\tseq(): number {","atom":"a1445","author":"speed","version":150},{"n":113,"text":"\t\treturn this.next;","atom":"a1445","author":"speed","version":150},{"n":114,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":115,"text":"","atom":"a1446","author":"speed","version":150},{"n":116,"text":"\t/** Reject an oversized canonical frame before loading its text into JavaScript. */","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":117,"text":"\tframeBytes(seq: number): number {","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":118,"text":"\t\tif (!Number.isSafeInteger(seq) || seq < 0) throw Error(\"invalid canonical frame position\");","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":119,"text":"\t\tconst size = this.storage.sql","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":120,"text":"\t\t\t.exec(","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":121,"text":"\t\t\t\t\"SELECT COUNT(*) AS parts, COALESCE(SUM(LENGTH(CAST(text AS BLOB))), 0) AS bytes FROM log WHERE seq = ?\",","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":122,"text":"\t\t\t\tseq,","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":123,"text":"\t\t\t)","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":124,"text":"\t\t\t.toArray()[0] as { parts: number; bytes: number };","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":125,"text":"\t\tif (!size || size.parts < 1 || size.parts > 256 || size.bytes < 1 || !Number.isSafeInteger(size.bytes))","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":126,"text":"\t\t\tthrow Error(\"canonical frame exceeds hard decoding bound or is missing\");","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":127,"text":"\t\treturn size.bytes;","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":128,"text":"\t}","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":129,"text":"\t/** A larger first frame gets its own budget; later frames are deferred. */","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":130,"text":"\tadoptionPageBytes(from: number): number {","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":131,"text":"\t\treturn Math.max(1_048_576, this.frameBytes(from));","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":132,"text":"\t}","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":133,"text":"","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":134,"text":"\tboundedFrame(seq: number, maxBytes: number): string {","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":135,"text":"\t\tif (","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":136,"text":"\t\t\t!Number.isSafeInteger(seq) ||","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":137,"text":"\t\t\tseq < 0 ||","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":138,"text":"\t\t\t!Number.isSafeInteger(maxBytes) ||","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":139,"text":"\t\t\tmaxBytes < 1 ||","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":140,"text":"\t\t\tmaxBytes > 8_000_000","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":141,"text":"\t\t)","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":142,"text":"\t\t\tthrow new Error(\"invalid canonical frame bound\");","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":143,"text":"\t\tconst size = this.storage.sql","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":144,"text":"\t\t\t.exec(","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":145,"text":"\t\t\t\t\"SELECT COUNT(*) AS parts, COALESCE(SUM(LENGTH(CAST(text AS BLOB))), 0) AS bytes FROM log WHERE seq = ?\",","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":146,"text":"\t\t\t\tseq,","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":147,"text":"\t\t\t)","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":148,"text":"\t\t\t.toArray()[0] as { parts: number; bytes: number };","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":149,"text":"\t\tif (!size || size.parts < 1 || size.parts > 256 || size.bytes > maxBytes)","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":150,"text":"\t\t\tthrow new Error(\"canonical frame exceeds adoption bound or is missing\");","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":151,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT part, text FROM log WHERE seq = ? ORDER BY part\", seq).toArray() as {","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":152,"text":"\t\t\tpart: number;","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":153,"text":"\t\t\ttext: string;","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":154,"text":"\t\t}[];","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":155,"text":"\t\tif (rows.length !== size.parts || rows.some((row, part) => row.part !== part))","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":156,"text":"\t\t\tthrow new Error(\"canonical frame parts are incomplete\");","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":157,"text":"\t\treturn rows.map((row) => row.text).join(\"\");","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":158,"text":"\t}","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":159,"text":"","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":160,"text":"\t/** Stream one canonical frame without retaining its complete JSON text. */","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":161,"text":"\t*frameChunks(seq: number): IterableIterator<string> {","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":162,"text":"\t\tif (!Number.isSafeInteger(seq) || seq < 0) throw Error(\"invalid canonical frame position\");","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":163,"text":"\t\tlet expected = 0;","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":164,"text":"\t\tfor (;;) {","atom":"a1125","author":"codex-capacity-chair","version":134},{"n":165,"text":"\t\t\tconst rows = this.storage.sql","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":166,"text":"\t\t\t\t.exec(\"SELECT part, text FROM log WHERE seq = ? AND part >= ? ORDER BY part LIMIT 1\", seq, expected)","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":167,"text":"\t\t\t\t.toArray() as { part: number; text: string }[];","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":168,"text":"\t\t\tif (!rows.length) {","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":169,"text":"\t\t\t\tif (!expected) throw Error(\"canonical frame is missing\");","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":170,"text":"\t\t\t\treturn;","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":171,"text":"\t\t\t}","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":172,"text":"\t\t\tconst row = rows[0]!;","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":173,"text":"\t\t\tif (row.part !== expected || row.text.length > LOG_PART_CHARACTERS)","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":174,"text":"\t\t\t\tthrow Error(\"canonical frame parts are incomplete or oversized\");","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":175,"text":"\t\t\texpected++;","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":176,"text":"\t\t\tyield row.text;","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":177,"text":"\t\t}","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":178,"text":"\t}","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":179,"text":"","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":180,"text":"\t/** Refreshes the in-memory cursor after an enclosing transaction rolls back. */","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":181,"text":"\trefreshSequence(): void {","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":182,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT COALESCE(MAX(seq), -1) AS last FROM log\").toArray() as {","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":183,"text":"\t\t\tlast: number;","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":184,"text":"\t\t}[];","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":185,"text":"\t\tthis.next = (rows[0]?.last ?? -1) + 1;","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":186,"text":"\t}","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":187,"text":"","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":188,"text":"\t/** Monotonic cache invalidation epoch for every canonical log mutation. */","atom":"a1445","author":"speed","version":150},{"n":189,"text":"\tgeneration(): number {","atom":"a1445","author":"speed","version":150},{"n":190,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM marks WHERE name = ?\", \"generation\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":191,"text":"\t\t\tvalue: string;","atom":"a1445","author":"speed","version":150},{"n":192,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":193,"text":"\t\tconst generation = Number(rows[0]?.value ?? 0);","atom":"a1445","author":"speed","version":150},{"n":194,"text":"\t\tif (!Number.isSafeInteger(generation) || generation < 0) throw new Error(\"canonical log generation is invalid\");","atom":"a1445","author":"speed","version":150},{"n":195,"text":"\t\treturn generation;","atom":"a1445","author":"speed","version":150},{"n":196,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":197,"text":"","atom":"a1445","author":"speed","version":150},{"n":198,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":199,"text":"\t * Lines ever recorded (#46, #56): what loading the project costs grows with","atom":"a1445","author":"speed","version":150},{"n":200,"text":"\t * this, not with the log's size, so a guard can read it without loading.","atom":"a1445","author":"speed","version":150},{"n":201,"text":"\t * Kept with each append; undefined for a log written before the count,","atom":"a1445","author":"speed","version":150},{"n":202,"text":"\t * until it next loads.","atom":"a1445","author":"speed","version":150},{"n":203,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":204,"text":"\tlineCount(): number | undefined {","atom":"a1445","author":"speed","version":150},{"n":205,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM counts WHERE name = 'lines'\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":206,"text":"\t\t\tvalue: number;","atom":"a1445","author":"speed","version":150},{"n":207,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":208,"text":"\t\treturn rows[0]?.value;","atom":"a1445","author":"speed","version":150},{"n":209,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":210,"text":"","atom":"a1445","author":"speed","version":150},{"n":211,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":212,"text":"\t * The newest version of shared, without loading the project (abso issue 78: the website's access check asked","atom":"a1445","author":"speed","version":150},{"n":213,"text":"\t * every project's engine for it). Kept with each append; a log from before the count is read once by streaming.","atom":"a1445","author":"speed","version":150},{"n":214,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":215,"text":"\tsharedVersion(): number {","atom":"a1445","author":"speed","version":150},{"n":216,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM counts WHERE name = 'shared'\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":217,"text":"\t\t\tvalue: number;","atom":"a1445","author":"speed","version":150},{"n":218,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":219,"text":"\t\tif (rows[0] !== undefined) return rows[0].value;","atom":"a1445","author":"speed","version":150},{"n":220,"text":"\t\tlet version = -1;","atom":"a1445","author":"speed","version":150},{"n":221,"text":"\t\tfor (const e of this.#entries()) version = sharedVersionOf(e) ?? version;","atom":"a1445","author":"speed","version":150},{"n":222,"text":"\t\tif (version >= 0)","atom":"a1445","author":"speed","version":150},{"n":223,"text":"\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('shared', ?)\", version);","atom":"a1445","author":"speed","version":150},{"n":224,"text":"\t\treturn version;","atom":"a1445","author":"speed","version":150},{"n":225,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":226,"text":"","atom":"a1445","author":"speed","version":150},{"n":227,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":228,"text":"\t * Who published shared's newest version, and when, without loading the project (abso issue 86).","atom":"a1445","author":"speed","version":150},{"n":229,"text":"\t * Null when shared has no publish yet. A log from before the mark is read once by streaming.","atom":"a1445","author":"speed","version":150},{"n":230,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":231,"text":"\tlastPublish(): { agent: string; time: number } | null {","atom":"a1445","author":"speed","version":150},{"n":232,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM marks WHERE name = ?\", \"last\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":233,"text":"\t\t\tvalue: string;","atom":"a1445","author":"speed","version":150},{"n":234,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":235,"text":"\t\tif (rows[0] !== undefined) return JSON.parse(rows[0].value) as { agent: string; time: number };","atom":"a1445","author":"speed","version":150},{"n":236,"text":"\t\tlet last: { agent: string; time: number } | null = null;","atom":"a1445","author":"speed","version":150},{"n":237,"text":"\t\tfor (const e of this.#entries()) {","atom":"a1445","author":"speed","version":150},{"n":238,"text":"\t\t\tconst found = lastPublishOf(e);","atom":"a1445","author":"speed","version":150},{"n":239,"text":"\t\t\tif (found) last = found;","atom":"a1445","author":"speed","version":150},{"n":240,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":241,"text":"\t\tif (last)","atom":"a1445","author":"speed","version":150},{"n":242,"text":"\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO marks (name, value) VALUES (?, ?)\", \"last\", JSON.stringify(last));","atom":"a1445","author":"speed","version":150},{"n":243,"text":"\t\treturn last;","atom":"a1445","author":"speed","version":150},{"n":244,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":245,"text":"","atom":"a1445","author":"speed","version":150},{"n":246,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":247,"text":"\t * How big the log is, without loading the project or scanning it twice (ask 160).","atom":"a1445","author":"speed","version":150},{"n":248,"text":"\t * Entries are the next seq. Chars are kept like lines; a log from before the","atom":"a1445","author":"speed","version":150},{"n":249,"text":"\t * count is summed once, then kept. GET /projects' 2-second wait needs this","atom":"a1445","author":"speed","version":150},{"n":250,"text":"\t * to stay a storage read: SUM(LENGTH(text)) over abso's log misses it.","atom":"a1445","author":"speed","version":150},{"n":251,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":252,"text":"\tlogSize(): { chars: number; entries: number } {","atom":"a1445","author":"speed","version":150},{"n":253,"text":"\t\tconst entries = this.next;","atom":"a1445","author":"speed","version":150},{"n":254,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM counts WHERE name = 'chars'\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":255,"text":"\t\t\tvalue: number;","atom":"a1445","author":"speed","version":150},{"n":256,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":257,"text":"\t\tif (rows[0] !== undefined) return { chars: rows[0].value, entries };","atom":"a1445","author":"speed","version":150},{"n":258,"text":"\t\tif (entries === 0) return { chars: 0, entries: 0 };","atom":"a1445","author":"speed","version":150},{"n":259,"text":"\t\tconst summed = this.storage.sql.exec(\"SELECT COALESCE(SUM(LENGTH(text)), 0) AS chars FROM log\").toArray()[0] as","atom":"a1445","author":"speed","version":150},{"n":260,"text":"\t\t\t| { chars: number }","atom":"a1445","author":"speed","version":150},{"n":261,"text":"\t\t\t| undefined;","atom":"a1445","author":"speed","version":150},{"n":262,"text":"\t\tconst chars = summed?.chars ?? 0;","atom":"a1445","author":"speed","version":150},{"n":263,"text":"\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('chars', ?)\", chars);","atom":"a1445","author":"speed","version":150},{"n":264,"text":"\t\treturn { chars, entries };","atom":"a1445","author":"speed","version":150},{"n":265,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":266,"text":"","atom":"a1445","author":"speed","version":150},{"n":267,"text":"\t/** Claim keys and deletes ever recorded (#46), kept like the line count; undefined before they were counted. */","atom":"a1445","author":"speed","version":150},{"n":268,"text":"\tkeyCount(): number | undefined {","atom":"a1445","author":"speed","version":150},{"n":269,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM counts WHERE name = 'keys'\").toArray() as { value: number }[];","atom":"a1445","author":"speed","version":150},{"n":270,"text":"\t\treturn rows[0]?.value;","atom":"a1445","author":"speed","version":150},{"n":271,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":272,"text":"","atom":"a1445","author":"speed","version":150},{"n":273,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":274,"text":"\t * The lines and keys ever recorded, counting a log from before either count without loading the project","atom":"a1445","author":"speed","version":150},{"n":275,"text":"\t * (#46): one entry parsed at a time, so a log the load guard would refuse can still be measured. Kept once counted.","atom":"a1445","author":"speed","version":150},{"n":276,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":277,"text":"\tcountSizes(): { lines: number; keys: number } {","atom":"a1445","author":"speed","version":150},{"n":278,"text":"\t\tconst lines = this.lineCount();","atom":"a1445","author":"speed","version":150},{"n":279,"text":"\t\tconst keys = this.keyCount();","atom":"a1445","author":"speed","version":150},{"n":280,"text":"\t\tif (lines !== undefined && keys !== undefined) return { lines, keys };","atom":"a1445","author":"speed","version":150},{"n":281,"text":"\t\tlet l = 0;","atom":"a1445","author":"speed","version":150},{"n":282,"text":"\t\tlet k = 0;","atom":"a1445","author":"speed","version":150},{"n":283,"text":"\t\tfor (const e of this.#entries()) {","atom":"a1445","author":"speed","version":150},{"n":284,"text":"\t\t\tl += linesIn(e);","atom":"a1445","author":"speed","version":150},{"n":285,"text":"\t\t\tk += keysIn(e);","atom":"a1445","author":"speed","version":150},{"n":286,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":287,"text":"\t\tthis.#keep(lines === undefined ? l : undefined, keys === undefined ? k : undefined);","atom":"a1445","author":"speed","version":150},{"n":288,"text":"\t\treturn { lines: lines ?? l, keys: keys ?? k };","atom":"a1445","author":"speed","version":150},{"n":289,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":290,"text":"","atom":"a1445","author":"speed","version":150},{"n":291,"text":"\t/** Stores the counts given. */","atom":"a1445","author":"speed","version":150},{"n":292,"text":"\t#keep(lines: number | undefined, keys: number | undefined): void {","atom":"a1445","author":"speed","version":150},{"n":293,"text":"\t\tif (lines !== undefined)","atom":"a1445","author":"speed","version":150},{"n":294,"text":"\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('lines', ?)\", lines);","atom":"a1445","author":"speed","version":150},{"n":295,"text":"\t\tif (keys !== undefined)","atom":"a1445","author":"speed","version":150},{"n":296,"text":"\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('keys', ?)\", keys);","atom":"a1445","author":"speed","version":150},{"n":297,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":298,"text":"","atom":"a1445","author":"speed","version":150},{"n":299,"text":"\t/** Every stored entry, in order. Rows are read one at a time, so loading never holds the whole log's text at once (#43). */","atom":"a1445","author":"speed","version":150},{"n":300,"text":"\t*entries(): Iterable<Entry> {","atom":"a1445","author":"speed","version":150},{"n":301,"text":"\t\t// A log from before the counts: counted as it loads, and kept.","atom":"a1445","author":"speed","version":150},{"n":302,"text":"\t\tconst countLines = this.lineCount() === undefined;","atom":"a1445","author":"speed","version":150},{"n":303,"text":"\t\tconst countKeys = this.keyCount() === undefined;","atom":"a1445","author":"speed","version":150},{"n":304,"text":"\t\tlet lines = 0;","atom":"a1445","author":"speed","version":150},{"n":305,"text":"\t\tlet keys = 0;","atom":"a1445","author":"speed","version":150},{"n":306,"text":"\t\tfor (const e of this.#entries()) {","atom":"a1445","author":"speed","version":150},{"n":307,"text":"\t\t\tif (countLines) lines += linesIn(e);","atom":"a1445","author":"speed","version":150},{"n":308,"text":"\t\t\tif (countKeys) keys += keysIn(e);","atom":"a1445","author":"speed","version":150},{"n":309,"text":"\t\t\tyield e;","atom":"a1445","author":"speed","version":150},{"n":310,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":311,"text":"\t\tthis.#keep(countLines ? lines : undefined, countKeys ? keys : undefined);","atom":"a1445","author":"speed","version":150},{"n":312,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":313,"text":"","atom":"a1445","author":"speed","version":150},{"n":314,"text":"\t*#entries(from = 0): Iterable<Entry> {","atom":"a1445","author":"speed","version":150},{"n":315,"text":"\t\t// A Workers cursor is iterable; a test's stand-in may only have toArray.","atom":"a1445","author":"speed","version":150},{"n":316,"text":"\t\tconst cursor = this.storage.sql.exec(\"SELECT seq, text FROM log WHERE seq >= ? ORDER BY seq, part\", from) as {","atom":"a1445","author":"speed","version":150},{"n":317,"text":"\t\t\ttoArray(): unknown[];","atom":"a1445","author":"speed","version":150},{"n":318,"text":"\t\t} & Partial<Iterable<unknown>>;","atom":"a1445","author":"speed","version":150},{"n":319,"text":"\t\tconst rows = (cursor[Symbol.iterator] ? cursor : cursor.toArray()) as Iterable<{ seq: number; text: string }>;","atom":"a1445","author":"speed","version":150},{"n":320,"text":"\t\tlet seq = -1;","atom":"a1445","author":"speed","version":150},{"n":321,"text":"\t\tlet text = \"\";","atom":"a1445","author":"speed","version":150},{"n":322,"text":"\t\tfor (const r of rows) {","atom":"a1445","author":"speed","version":150},{"n":323,"text":"\t\t\tif (r.seq !== seq && seq >= 0) yield JSON.parse(text) as Entry;","atom":"a1445","author":"speed","version":150},{"n":324,"text":"\t\t\tif (r.seq !== seq) text = \"\";","atom":"a1445","author":"speed","version":150},{"n":325,"text":"\t\t\tseq = r.seq;","atom":"a1445","author":"speed","version":150},{"n":326,"text":"\t\t\ttext += r.text;","atom":"a1445","author":"speed","version":150},{"n":327,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":328,"text":"\t\tif (seq >= 0) yield JSON.parse(text) as Entry;","atom":"a1445","author":"speed","version":150},{"n":329,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":330,"text":"","atom":"a1445","author":"speed","version":150},{"n":331,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":332,"text":"\t * For backups (#29): the entries from seq `from` on as their stored JSON","atom":"a1445","author":"speed","version":150},{"n":333,"text":"\t * text (not parsed, so an export holds the project up as little as it","atom":"a1445","author":"speed","version":150},{"n":334,"text":"\t * can), at most `limit` of them and about 8 MB (always at least one), and","atom":"a1445","author":"speed","version":150},{"n":335,"text":"\t * the seq to ask for next, or null at the end.","atom":"a1445","author":"speed","version":150},{"n":336,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":337,"text":"\tpage(from: number, limit: number): { texts: string[]; next: number | null } {","atom":"a1445","author":"speed","version":150},{"n":338,"text":"\t\tconst rows = this.storage.sql","atom":"a1445","author":"speed","version":150},{"n":339,"text":"\t\t\t.exec(\"SELECT seq, text FROM log WHERE seq >= ? AND seq < ? ORDER BY seq, part\", from, from + limit)","atom":"a1445","author":"speed","version":150},{"n":340,"text":"\t\t\t.toArray() as { seq: number; text: string }[];","atom":"a1445","author":"speed","version":150},{"n":341,"text":"\t\tconst texts: string[] = [];","atom":"a1445","author":"speed","version":150},{"n":342,"text":"\t\tlet seq = -1;","atom":"a1445","author":"speed","version":150},{"n":343,"text":"\t\tlet text = \"\";","atom":"a1445","author":"speed","version":150},{"n":344,"text":"\t\tlet size = 0;","atom":"a1445","author":"speed","version":150},{"n":345,"text":"\t\tlet next: number | null = null;","atom":"a1445","author":"speed","version":150},{"n":346,"text":"\t\tfor (const r of rows) {","atom":"a1445","author":"speed","version":150},{"n":347,"text":"\t\t\tif (r.seq < from || r.seq >= from + limit) continue;","atom":"a1445","author":"speed","version":150},{"n":348,"text":"\t\t\tif (r.seq !== seq && seq >= 0) {","atom":"a1445","author":"speed","version":150},{"n":349,"text":"\t\t\t\ttexts.push(text);","atom":"a1445","author":"speed","version":150},{"n":350,"text":"\t\t\t\tsize += text.length;","atom":"a1445","author":"speed","version":150},{"n":351,"text":"\t\t\t\tif (size > 8_000_000) {","atom":"a1445","author":"speed","version":150},{"n":352,"text":"\t\t\t\t\tnext = r.seq;","atom":"a1445","author":"speed","version":150},{"n":353,"text":"\t\t\t\t\tbreak;","atom":"a1445","author":"speed","version":150},{"n":354,"text":"\t\t\t\t}","atom":"a1445","author":"speed","version":150},{"n":355,"text":"\t\t\t}","atom":"a1445","author":"speed","version":150},{"n":356,"text":"\t\t\tif (r.seq !== seq) text = \"\";","atom":"a1445","author":"speed","version":150},{"n":357,"text":"\t\t\tseq = r.seq;","atom":"a1445","author":"speed","version":150},{"n":358,"text":"\t\t\ttext += r.text;","atom":"a1445","author":"speed","version":150},{"n":359,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":360,"text":"\t\tif (next === null && seq >= 0) texts.push(text);","atom":"a1445","author":"speed","version":150},{"n":361,"text":"\t\tif (next === null && from + limit < this.next) next = from + limit;","atom":"a1445","author":"speed","version":150},{"n":362,"text":"\t\treturn { texts, next };","atom":"a1445","author":"speed","version":150},{"n":363,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":364,"text":"","atom":"a1445","author":"speed","version":150},{"n":365,"text":"\t/** Up to `limit` entries from position `from`, parsed (#41: the feed and replay). */","atom":"a1445","author":"speed","version":150},{"n":366,"text":"\tsince(from: number, limit: number): Entry[] {","atom":"a1445","author":"speed","version":150},{"n":367,"text":"\t\tconst out: Entry[] = [];","atom":"a1445","author":"speed","version":150},{"n":368,"text":"\t\tfor (let at = from; out.length < limit; ) {","atom":"a1445","author":"speed","version":150},{"n":369,"text":"\t\t\tconst { texts, next } = this.page(at, limit - out.length);","atom":"a1445","author":"speed","version":150},{"n":370,"text":"\t\t\tfor (const t of texts) out.push(JSON.parse(t) as Entry);","atom":"a1445","author":"speed","version":150},{"n":371,"text":"\t\t\tif (next === null || texts.length === 0) break;","atom":"a1445","author":"speed","version":150},{"n":372,"text":"\t\t\tat = next;","atom":"a1445","author":"speed","version":150},{"n":373,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":374,"text":"\t\treturn out;","atom":"a1445","author":"speed","version":150},{"n":375,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":376,"text":"","atom":"a1445","author":"speed","version":150},{"n":377,"text":"\t/** Removes every entry: only for a restore whose log didn't load (#29). */","atom":"a1445","author":"speed","version":150},{"n":378,"text":"\tclear(): void {","atom":"a1445","author":"speed","version":150},{"n":379,"text":"\t\tconst generation = this.generation() + 1;","atom":"a1445","author":"speed","version":150},{"n":380,"text":"\t\tthis.storage.transactionSync(() => {","atom":"a1445","author":"speed","version":150},{"n":381,"text":"\t\t\tthis.storage.sql.exec(\"DELETE FROM log\");","atom":"a1445","author":"speed","version":150},{"n":382,"text":"\t\t\tthis.storage.sql.exec(\"DELETE FROM shapes\");","atom":"a1445","author":"speed","version":150},{"n":383,"text":"\t\t\tthis.storage.sql.exec(\"DELETE FROM counts\");","atom":"a1445","author":"speed","version":150},{"n":384,"text":"\t\t\tthis.storage.sql.exec(\"DELETE FROM marks WHERE name != ?\", \"generation\");","atom":"a1445","author":"speed","version":150},{"n":385,"text":"\t\t\tthis.storage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":386,"text":"\t\t\t\t\"INSERT OR REPLACE INTO marks (name, value) VALUES (?, ?)\",","atom":"a1445","author":"speed","version":150},{"n":387,"text":"\t\t\t\t\"generation\",","atom":"a1445","author":"speed","version":150},{"n":388,"text":"\t\t\t\tString(generation),","atom":"a1445","author":"speed","version":150},{"n":389,"text":"\t\t\t);","atom":"a1445","author":"speed","version":150},{"n":390,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":391,"text":"\t\tthis.next = 0;","atom":"a1445","author":"speed","version":150},{"n":392,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":393,"text":"","atom":"a1445","author":"speed","version":150},{"n":394,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":395,"text":"\t * Each version's changed files, kept between loads (#41, the Files pages):","atom":"a1445","author":"speed","version":150},{"n":396,"text":"\t * worked out from the log, never part of it, so an older Worker ignores","atom":"a1445","author":"speed","version":150},{"n":397,"text":"\t * the table and nothing about the project depends on it.","atom":"a1445","author":"speed","version":150},{"n":398,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":399,"text":"\tshapes(): {","atom":"a1445","author":"speed","version":150},{"n":400,"text":"\t\tget(space: string, version: number): string | undefined;","atom":"a1445","author":"speed","version":150},{"n":401,"text":"\t\tput(space: string, version: number, value: string): void;","atom":"a1445","author":"speed","version":150},{"n":402,"text":"\t} {","atom":"a1445","author":"speed","version":150},{"n":403,"text":"\t\tconst sql = this.storage.sql;","atom":"a1445","author":"speed","version":150},{"n":404,"text":"\t\treturn {","atom":"a1445","author":"speed","version":150},{"n":405,"text":"\t\t\tget: (space, version) =>","atom":"a1445","author":"speed","version":150},{"n":406,"text":"\t\t\t\t(","atom":"a1445","author":"speed","version":150},{"n":407,"text":"\t\t\t\t\tsql.exec(\"SELECT value FROM shapes WHERE space = ? AND version = ?\", space, version).toArray() as {","atom":"a1445","author":"speed","version":150},{"n":408,"text":"\t\t\t\t\t\tvalue: string;","atom":"a1445","author":"speed","version":150},{"n":409,"text":"\t\t\t\t\t}[]","atom":"a1445","author":"speed","version":150},{"n":410,"text":"\t\t\t\t)[0]?.value,","atom":"a1445","author":"speed","version":150},{"n":411,"text":"\t\t\tput: (space, version, value) =>","atom":"a1445","author":"speed","version":150},{"n":412,"text":"\t\t\t\tvoid sql.exec(\"INSERT OR REPLACE INTO shapes (space, version, value) VALUES (?, ?, ?)\", space, version, value),","atom":"a1445","author":"speed","version":150},{"n":413,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":414,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":415,"text":"","atom":"a1445","author":"speed","version":150},{"n":416,"text":"\tappend(entries: readonly Entry[]): void {","atom":"a1445","author":"speed","version":150},{"n":417,"text":"\t\tif (!entries.length) return;","atom":"a1445","author":"speed","version":150},{"n":418,"text":"\t\tlet next = this.next;","atom":"a1445","author":"speed","version":150},{"n":419,"text":"\t\tthis.storage.transactionSync(() => {","atom":"a1445","author":"speed","version":150},{"n":420,"text":"\t\t\tconst lines = entries.reduce((n, e) => n + linesIn(e), 0);","atom":"a1445","author":"speed","version":150},{"n":421,"text":"\t\t\tif (lines > 0)","atom":"a1445","author":"speed","version":150},{"n":422,"text":"\t\t\t\tthis.storage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":423,"text":"\t\t\t\t\t\"INSERT INTO counts (name, value) VALUES ('lines', ?) ON CONFLICT(name) DO UPDATE SET value = value + ?\",","atom":"a1445","author":"speed","version":150},{"n":424,"text":"\t\t\t\t\tlines,","atom":"a1445","author":"speed","version":150},{"n":425,"text":"\t\t\t\t\tlines,","atom":"a1445","author":"speed","version":150},{"n":426,"text":"\t\t\t\t);","atom":"a1445","author":"speed","version":150},{"n":427,"text":"\t\t\t// The newest version of shared: appended entries are the newest, so the last one that makes a version wins.","atom":"a1445","author":"speed","version":150},{"n":428,"text":"\t\t\tfor (const e of entries) {","atom":"a1445","author":"speed","version":150},{"n":429,"text":"\t\t\t\tconst v = sharedVersionOf(e);","atom":"a1445","author":"speed","version":150},{"n":430,"text":"\t\t\t\tif (v !== undefined)","atom":"a1445","author":"speed","version":150},{"n":431,"text":"\t\t\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('shared', ?)\", v);","atom":"a1445","author":"speed","version":150},{"n":432,"text":"\t\t\t\tconst last = lastPublishOf(e);","atom":"a1445","author":"speed","version":150},{"n":433,"text":"\t\t\t\tif (last)","atom":"a1445","author":"speed","version":150},{"n":434,"text":"\t\t\t\t\tthis.storage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":435,"text":"\t\t\t\t\t\t\"INSERT OR REPLACE INTO marks (name, value) VALUES (?, ?)\",","atom":"a1445","author":"speed","version":150},{"n":436,"text":"\t\t\t\t\t\t\"last\",","atom":"a1445","author":"speed","version":150},{"n":437,"text":"\t\t\t\t\t\tJSON.stringify(last),","atom":"a1445","author":"speed","version":150},{"n":438,"text":"\t\t\t\t\t);","atom":"a1445","author":"speed","version":150},{"n":439,"text":"\t\t\t}","atom":"a1445","author":"speed","version":150},{"n":440,"text":"\t\t\t// Keys are only added to once counted: a log from before the key count is counted whole first (countSizes).","atom":"a1445","author":"speed","version":150},{"n":441,"text":"\t\t\tconst keys = entries.reduce((n, e) => n + keysIn(e), 0);","atom":"a1445","author":"speed","version":150},{"n":442,"text":"\t\t\tif (keys > 0) this.storage.sql.exec(\"UPDATE counts SET value = value + ? WHERE name = 'keys'\", keys);","atom":"a1445","author":"speed","version":150},{"n":443,"text":"\t\t\tlet chars = 0;","atom":"a1445","author":"speed","version":150},{"n":444,"text":"\t\t\tfor (const entry of entries) {","atom":"a1445","author":"speed","version":150},{"n":445,"text":"\t\t\t\tlet part = 0;","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":446,"text":"\t\t\t\tfor (const text of streamedLogParts(entry)) {","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":447,"text":"\t\t\t\t\tchars += text.length;","atom":"a1445","author":"speed","version":150},{"n":448,"text":"\t\t\t\t\tthis.storage.sql.exec(\"INSERT INTO log (seq, part, text) VALUES (?, ?, ?)\", next, part++, text);","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":449,"text":"\t\t\t\t}","atom":"a1817","author":"codex-capacity-chair","version":167},{"n":450,"text":"\t\t\t\tnext++;","atom":"a1445","author":"speed","version":150},{"n":451,"text":"\t\t\t}","atom":"a1445","author":"speed","version":150},{"n":452,"text":"\t\t\t// Chars are only added to once counted: a log from before the count is summed whole first (logSize).","atom":"a1445","author":"speed","version":150},{"n":453,"text":"\t\t\tif (chars > 0) this.storage.sql.exec(\"UPDATE counts SET value = value + ? WHERE name = 'chars'\", chars);","atom":"a1445","author":"speed","version":150},{"n":454,"text":"\t\t\tconst generation = this.generation() + 1;","atom":"a1445","author":"speed","version":150},{"n":455,"text":"\t\t\tthis.storage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":456,"text":"\t\t\t\t\"INSERT OR REPLACE INTO marks (name, value) VALUES (?, ?)\",","atom":"a1445","author":"speed","version":150},{"n":457,"text":"\t\t\t\t\"generation\",","atom":"a1445","author":"speed","version":150},{"n":458,"text":"\t\t\t\tString(generation),","atom":"a1445","author":"speed","version":150},{"n":459,"text":"\t\t\t);","atom":"a1445","author":"speed","version":150},{"n":460,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":461,"text":"\t\tthis.next = next;","atom":"a1445","author":"speed","version":150},{"n":462,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":463,"text":"}","atom":"a1445","author":"speed","version":150},{"n":464,"text":"","atom":"a1445","author":"speed","version":150},{"n":465,"text":"/** The engine's Project as the Worker's ProjectCalls; the clock comes from here. */","atom":"a1445","author":"speed","version":150},{"n":466,"text":"export class EngineProject implements ProjectCalls, ProjectHistory {","atom":"a1445","author":"speed","version":150},{"n":467,"text":"\tblame(file: string, from?: number, to?: number, version?: number, draft?: string, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":468,"text":"\t\treturn blame(this.project, file, from, to, version, { ...(draft ? { draft } : {}), ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":469,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":470,"text":"\tfolderBlame(folder: string, version?: number, draft?: string, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":471,"text":"\t\treturn folderBlame(this.project, folder, version, { ...(draft ? { draft } : {}), ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":472,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":473,"text":"\ttree(folder: string, version?: number, draft?: string | null, agent?: string, authors?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":474,"text":"\t\treturn this.project.tree(folder, {","atom":"a1445","author":"speed","version":150},{"n":475,"text":"\t\t\t...(version !== undefined ? { version } : {}),","atom":"a1445","author":"speed","version":150},{"n":476,"text":"\t\t\tdraft: draft ?? null,","atom":"a1445","author":"speed","version":150},{"n":477,"text":"\t\t\t...(agent !== undefined ? { agent } : {}),","atom":"a1445","author":"speed","version":150},{"n":478,"text":"\t\t\t...(authors ? { authors } : {}),","atom":"a1445","author":"speed","version":150},{"n":479,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":480,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":481,"text":"\tpathLife(path: string, version?: number, draft?: string | null) {","atom":"a1445","author":"speed","version":150},{"n":482,"text":"\t\treturn this.project.pathLife(path, { ...(version !== undefined ? { version } : {}), draft: draft ?? null });","atom":"a1445","author":"speed","version":150},{"n":483,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":484,"text":"\tfollow(path: string, version: number, from: number, to: number, at?: number, draft?: string | null) {","atom":"a1445","author":"speed","version":150},{"n":485,"text":"\t\treturn this.project.follow(path, version, from, to, { ...(at !== undefined ? { at } : {}), draft: draft ?? null });","atom":"a1445","author":"speed","version":150},{"n":486,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":487,"text":"\tpathsOf(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":488,"text":"\t\treturn this.project.pathsOf(agent);","atom":"a1445","author":"speed","version":150},{"n":489,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":490,"text":"\tdraftState(name: string) {","atom":"a1445","author":"speed","version":150},{"n":491,"text":"\t\treturn this.project.draftState(name);","atom":"a1445","author":"speed","version":150},{"n":492,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":493,"text":"\tcollisions(file?: string, folder?: string) {","atom":"a1445","author":"speed","version":150},{"n":494,"text":"\t\treturn this.project.collisions({","atom":"a1445","author":"speed","version":150},{"n":495,"text":"\t\t\t...(file !== undefined ? { file } : {}),","atom":"a1445","author":"speed","version":150},{"n":496,"text":"\t\t\t...(folder !== undefined ? { folder } : {}),","atom":"a1445","author":"speed","version":150},{"n":497,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":498,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":499,"text":"\twhy(file: string, line: number, draft?: string, agent?: string, version?: number) {","atom":"a2173","author":"whytrail","version":193},{"n":500,"text":"\t\treturn why(this.project, file, line, {","atom":"a2173","author":"whytrail","version":193},{"n":501,"text":"\t\t\t...(draft ? { draft } : {}),","atom":"a2173","author":"whytrail","version":193},{"n":502,"text":"\t\t\t...(agent ? { agent } : {}),","atom":"a2173","author":"whytrail","version":193},{"n":503,"text":"\t\t\t...(version !== undefined ? { version } : {}),","atom":"a2173","author":"whytrail","version":193},{"n":504,"text":"\t\t});","atom":"a2173","author":"whytrail","version":193},{"n":505,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":506,"text":"\twhere() {","atom":"a1445","author":"speed","version":150},{"n":507,"text":"\t\treturn where(this.project);","atom":"a1445","author":"speed","version":150},{"n":508,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":509,"text":"\trefusals(agent?: string, limit?: number) {","atom":"a1445","author":"speed","version":150},{"n":510,"text":"\t\treturn this.project.refusals({ ...(agent ? { agent } : {}), ...(limit !== undefined ? { limit } : {}) });","atom":"a1445","author":"speed","version":150},{"n":511,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":512,"text":"","atom":"a1445","author":"speed","version":150},{"n":513,"text":"\tlog(draft: string | null, limit?: number, path?: string, agent?: string, before?: number, follow?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":514,"text":"\t\treturn this.project.log({","atom":"a1445","author":"speed","version":150},{"n":515,"text":"\t\t\tdraft,","atom":"a1445","author":"speed","version":150},{"n":516,"text":"\t\t\t...(limit !== undefined ? { limit } : {}),","atom":"a1445","author":"speed","version":150},{"n":517,"text":"\t\t\t...(path !== undefined ? { path } : {}),","atom":"a1445","author":"speed","version":150},{"n":518,"text":"\t\t\t...(agent ? { agent } : {}),","atom":"a1445","author":"speed","version":150},{"n":519,"text":"\t\t\t...(before !== undefined ? { before } : {}),","atom":"a1445","author":"speed","version":150},{"n":520,"text":"\t\t\t...(follow ? { follow } : {}),","atom":"a1445","author":"speed","version":150},{"n":521,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":522,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":523,"text":"\tfileAt(path: string, version: number, draft: string | null, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":524,"text":"\t\treturn this.project.fileAt(path, version, { draft, ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":525,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":526,"text":"\tcompare(from: number, to: number, draft: string | null, agent?: string, summary?: boolean) {","atom":"a2484","author":"capacity","version":243},{"n":527,"text":"\t\tconst where = { draft, ...(agent ? { agent } : {}) };","atom":"a2490","author":"capacity","version":244},{"n":528,"text":"\t\treturn summary ? this.project.compareSummary(from, to, where) : this.project.compare(from, to, where);","atom":"a2490","author":"capacity","version":244},{"n":529,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":530,"text":"\twithout(version: number, versions: readonly number[]) {","atom":"a2081","author":"candidates","version":186},{"n":531,"text":"\t\treturn this.project.without(version, versions);","atom":"a2081","author":"candidates","version":186},{"n":532,"text":"\t}","atom":"a2081","author":"candidates","version":186},{"n":533,"text":"\tshow(version: number, draft: string | null, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":534,"text":"\t\treturn this.project.show(version, { draft, ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":535,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":536,"text":"\tdiff(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":537,"text":"\t\treturn this.project.diff(agent);","atom":"a1445","author":"speed","version":150},{"n":538,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":539,"text":"\tsyncFull(agent: string, label?: string) {","atom":"a1445","author":"speed","version":150},{"n":540,"text":"\t\treturn this.project.sync(agent, { full: true, ...(label !== undefined ? { label } : {}) });","atom":"a1445","author":"speed","version":150},{"n":541,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":542,"text":"\tagentPaths(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":543,"text":"\t\treturn this.project.agentPaths(agent);","atom":"a1445","author":"speed","version":150},{"n":544,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":545,"text":"\tpathsAt(version?: number, draft?: string | null) {","atom":"a1445","author":"speed","version":150},{"n":546,"text":"\t\treturn this.project.pathsAt(version, draft ?? null);","atom":"a1445","author":"speed","version":150},{"n":547,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":548,"text":"\tsyncTo(agent: string, label: string) {","atom":"a1445","author":"speed","version":150},{"n":549,"text":"\t\treturn this.project.sync(agent, { label });","atom":"a1445","author":"speed","version":150},{"n":550,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":551,"text":"\tlabel(agent: string, name: string, version?: number, remove?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":552,"text":"\t\treturn this.project.label(agent, name, version, Date.now(), { remove: remove === true });","atom":"a1445","author":"speed","version":150},{"n":553,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":554,"text":"\tlabels() {","atom":"a1445","author":"speed","version":150},{"n":555,"text":"\t\treturn this.project.labels();","atom":"a1445","author":"speed","version":150},{"n":556,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":557,"text":"\tamend(agent: string, message: string) {","atom":"a1445","author":"speed","version":150},{"n":558,"text":"\t\treturn this.project.amend(agent, message, Date.now());","atom":"a1445","author":"speed","version":150},{"n":559,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":560,"text":"\tpluck(agent: string, draft: string, versions: number[], message: string, withDependencies?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":561,"text":"\t\treturn this.project.pluck(agent, draft, versions, message, Date.now(), {","atom":"a1445","author":"speed","version":150},{"n":562,"text":"\t\t\twithDependencies: withDependencies === true,","atom":"a1445","author":"speed","version":150},{"n":563,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":564,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":565,"text":"\tdrop(agent: string, versions: number[], message: string, withDependents?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":566,"text":"\t\treturn this.project.drop(agent, versions, message, Date.now(), { withDependents: withDependents === true });","atom":"a1445","author":"speed","version":150},{"n":567,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":568,"text":"\tannounce(agent: string, text: string, to?: string[], how?: string) {","atom":"a1445","author":"speed","version":150},{"n":569,"text":"\t\treturn this.project.announce(agent, text, to, Date.now(), how);","atom":"a1445","author":"speed","version":150},{"n":570,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":571,"text":"","atom":"a1445","author":"speed","version":150},{"n":572,"text":"\tannouncePerson(person: { id: string; name: string }, text: string, to?: string[]) {","atom":"a1445","author":"speed","version":150},{"n":573,"text":"\t\treturn this.project.announcePerson(person, text, to, Date.now());","atom":"a1445","author":"speed","version":150},{"n":574,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":575,"text":"\t/** A seat's earlier chat hears that another chat used the seat (277, groups); as abso's worker has it. */","atom":"a2793","author":"capacity","version":284},{"n":576,"text":"\tseatNotice(agent: string, place: string, key: string) {","atom":"a2793","author":"capacity","version":284},{"n":577,"text":"\t\treturn this.project.seatNotice(agent, place, key);","atom":"a2793","author":"capacity","version":284},{"n":578,"text":"\t}","atom":"a2793","author":"capacity","version":284},{"n":579,"text":"\tstarting(agent: string, text: string | null, files?: string[], options: { issue?: unknown; done?: unknown } = {}) {","atom":"a1445","author":"speed","version":150},{"n":580,"text":"\t\treturn this.project.starting(agent, text, files, Date.now(), options);","atom":"a1445","author":"speed","version":150},{"n":581,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":582,"text":"\tnews(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":583,"text":"\t\treturn this.project.news(agent);","atom":"a1445","author":"speed","version":150},{"n":584,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":585,"text":"\trestore(agent: string, files: string[] | null) {","atom":"a1445","author":"speed","version":150},{"n":586,"text":"\t\treturn this.project.restore(agent, files, Date.now());","atom":"a1445","author":"speed","version":150},{"n":587,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":588,"text":"","atom":"a1445","author":"speed","version":150},{"n":589,"text":"\tprivate project: Project;","atom":"a1445","author":"speed","version":150},{"n":590,"text":"","atom":"a1445","author":"speed","version":150},{"n":591,"text":"\t/** Reads stored entries by log position, for the feed and replay (#41); absent, those answer 501. */","atom":"a1445","author":"speed","version":150},{"n":592,"text":"\tprivate readonly read: ((from: number, limit: number) => Entry[]) | undefined;","atom":"a1445","author":"speed","version":150},{"n":593,"text":"\tprivate readonly store: SqliteLog | undefined;","atom":"a1445","author":"speed","version":150},{"n":594,"text":"\tprivate readonly historical: (<T>(at: number, operation: (project: Project) => T) => T) | undefined;","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":595,"text":"","atom":"a1445","author":"speed","version":150},{"n":596,"text":"\tconstructor(","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":597,"text":"\t\tproject: Project,","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":598,"text":"\t\tread?: (from: number, limit: number) => Entry[],","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":599,"text":"\t\tstore?: SqliteLog,","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":600,"text":"\t\thistorical?: <T>(at: number, operation: (project: Project) => T) => T,","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":601,"text":"\t) {","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":602,"text":"\t\tthis.project = project;","atom":"a1445","author":"speed","version":150},{"n":603,"text":"\t\tthis.read = read;","atom":"a1445","author":"speed","version":150},{"n":604,"text":"\t\tthis.store = store;","atom":"a1445","author":"speed","version":150},{"n":605,"text":"\t\tthis.historical = historical;","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":606,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":607,"text":"","atom":"a1445","author":"speed","version":150},{"n":608,"text":"\t/** The project's events from log position `from` (#41): reading consumes nothing. */","atom":"a1445","author":"speed","version":150},{"n":609,"text":"\tfeed(from: number, limit = 500) {","atom":"a1445","author":"speed","version":150},{"n":610,"text":"\t\tif (!this.read) throw Object.assign(new Error(\"the feed needs the log\"), { code: \"not-implemented\" });","atom":"a1445","author":"speed","version":150},{"n":611,"text":"\t\tconst end = this.project.logLength;","atom":"a1445","author":"speed","version":150},{"n":612,"text":"\t\tconst start = Math.max(0, Math.min(from, end));","atom":"a1445","author":"speed","version":150},{"n":613,"text":"\t\t// Discard each canonical payload after extracting its event. A feed page must","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":614,"text":"\t\t// not retain every historical file payload in the requested range.","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":615,"text":"\t\tconst events = [];","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":616,"text":"\t\tlet next = start;","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":617,"text":"\t\twhile (next < end && next - start < limit) {","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":618,"text":"\t\t\tconst entries = this.read(next, 1);","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":619,"text":"\t\t\tif (entries.length === 0) break;","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":620,"text":"\t\t\tevents.push(...feedEvents(entries, next));","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":621,"text":"\t\t\tnext += entries.length;","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":622,"text":"\t\t}","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":623,"text":"\t\t// A drop event names the files it took out (#41), so a timeline needs no read per drop.","atom":"a1445","author":"speed","version":150},{"n":624,"text":"\t\tconst enriched = events.map((e) => {","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":625,"text":"\t\t\tif (e.type !== \"drop\" || e.version === undefined) return e;","atom":"a1445","author":"speed","version":150},{"n":626,"text":"\t\t\tconst v = this.project.log({ limit: 1, before: e.version + 1 }).versions[0];","atom":"a1445","author":"speed","version":150},{"n":627,"text":"\t\t\treturn v && v.version === e.version ? { ...e, dropped: v.files } : e;","atom":"a1445","author":"speed","version":150},{"n":628,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":629,"text":"\t\treturn { next, end, events: enriched };","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":630,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":631,"text":"","atom":"a1445","author":"speed","version":150},{"n":632,"text":"\t/** The log position for a time (ms since 1970) or a version of shared (#41). */","atom":"a1445","author":"speed","version":150},{"n":633,"text":"\tposition(q: { time?: number; version?: number }) {","atom":"a1445","author":"speed","version":150},{"n":634,"text":"\t\treturn this.project.position(q);","atom":"a1445","author":"speed","version":150},{"n":635,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":636,"text":"\t/** Whether the Worker runs the queue's check; until it does, \"queue\": true does nothing. */","atom":"a1445","author":"speed","version":150},{"n":637,"text":"\tsetCheckerReady(ready: boolean): void {","atom":"a1445","author":"speed","version":150},{"n":638,"text":"\t\tthis.project.checkerReady = ready;","atom":"a1445","author":"speed","version":150},{"n":639,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":640,"text":"\t/** An agent withdraws what it has queued (#39). */","atom":"a1445","author":"speed","version":150},{"n":641,"text":"\tunqueue(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":642,"text":"\t\treturn this.project.unqueue(agent, Date.now());","atom":"a1445","author":"speed","version":150},{"n":643,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":644,"text":"\t/** The log length now: what a long-poll waits to see grow. */","atom":"a1445","author":"speed","version":150},{"n":645,"text":"\tlogLength() {","atom":"a1445","author":"speed","version":150},{"n":646,"text":"\t\treturn this.project.logLength;","atom":"a1445","author":"speed","version":150},{"n":647,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":648,"text":"\t/** An agent's draft diff for a reader: never creates the agent (#41). */","atom":"a1445","author":"speed","version":150},{"n":649,"text":"\tdiffOf(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":650,"text":"\t\treturn this.project.diffOf(agent);","atom":"a1445","author":"speed","version":150},{"n":651,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":652,"text":"\t/** Every agent with unpublished changes: its files and how many changes (#41). */","atom":"a1445","author":"speed","version":150},{"n":653,"text":"\tchange(id: number) {","atom":"a1445","author":"speed","version":150},{"n":654,"text":"\t\treturn this.project.change(id);","atom":"a1445","author":"speed","version":150},{"n":655,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":656,"text":"","atom":"a1445","author":"speed","version":150},{"n":657,"text":"\tchanges(since: number, limit: number, before?: number, issue?: number) {","atom":"a1445","author":"speed","version":150},{"n":658,"text":"\t\treturn this.project.changes(since, limit, before, issue);","atom":"a1445","author":"speed","version":150},{"n":659,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":660,"text":"","atom":"a1445","author":"speed","version":150},{"n":661,"text":"\tmove(agent: string, from: string, to: string) {","atom":"a1445","author":"speed","version":150},{"n":662,"text":"\t\treturn this.project.move(agent, from, to, Date.now());","atom":"a1445","author":"speed","version":150},{"n":663,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":664,"text":"","atom":"a1445","author":"speed","version":150},{"n":665,"text":"\tnote(agent: string, body: Record<string, unknown>) {","atom":"a1445","author":"speed","version":150},{"n":666,"text":"\t\treturn this.project.note(agent, body, Date.now());","atom":"a1445","author":"speed","version":150},{"n":667,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":668,"text":"","atom":"a1445","author":"speed","version":150},{"n":669,"text":"\tnotePerson(person: { id: string; name: string }, body: Record<string, unknown>) {","atom":"a1445","author":"speed","version":150},{"n":670,"text":"\t\treturn this.project.notePerson(person, body, Date.now());","atom":"a1445","author":"speed","version":150},{"n":671,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":672,"text":"","atom":"a1445","author":"speed","version":150},{"n":673,"text":"\tcloseNotePerson(person: { id: string; name: string }, id: number, how: unknown) {","atom":"a1445","author":"speed","version":150},{"n":674,"text":"\t\treturn this.project.closeNotePerson(person, id, how, Date.now());","atom":"a1445","author":"speed","version":150},{"n":675,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":676,"text":"","atom":"a1445","author":"speed","version":150},{"n":677,"text":"\tcloseNote(agent: string, id: number, how: unknown) {","atom":"a1445","author":"speed","version":150},{"n":678,"text":"\t\treturn this.project.closeNote(agent, id, how, Date.now());","atom":"a1445","author":"speed","version":150},{"n":679,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":680,"text":"","atom":"a1445","author":"speed","version":150},{"n":681,"text":"\tnotes(options: { file?: string; change?: number; open?: boolean }) {","atom":"a1445","author":"speed","version":150},{"n":682,"text":"\t\treturn this.project.notes(options);","atom":"a1445","author":"speed","version":150},{"n":683,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":684,"text":"","atom":"a1445","author":"speed","version":150},{"n":685,"text":"\tribbon() {","atom":"a1445","author":"speed","version":150},{"n":686,"text":"\t\treturn this.project.ribbon();","atom":"a1445","author":"speed","version":150},{"n":687,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":688,"text":"","atom":"a1445","author":"speed","version":150},{"n":689,"text":"\tdrafts() {","atom":"a1445","author":"speed","version":150},{"n":690,"text":"\t\tconst s = this.project.status();","atom":"a1445","author":"speed","version":150},{"n":691,"text":"\t\treturn {","atom":"a1445","author":"speed","version":150},{"n":692,"text":"\t\t\tversion: s.version,","atom":"a1445","author":"speed","version":150},{"n":693,"text":"\t\t\tdrafts: s.agents","atom":"a1445","author":"speed","version":150},{"n":694,"text":"\t\t\t\t.filter((a) => a.draftChanges > 0)","atom":"a1445","author":"speed","version":150},{"n":695,"text":"\t\t\t\t.map((a) => ({ agent: a.agent, draft: a.draft, base: a.base, draftChanges: a.draftChanges, files: a.files })),","atom":"a1445","author":"speed","version":150},{"n":696,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":697,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":698,"text":"\t/** The last copy replay loaded: scrubbing forward from it applies only the entries after it. */","atom":"a1445","author":"speed","version":150},{"n":699,"text":"\tprivate replica: Project | undefined;","atom":"a1445","author":"speed","version":150},{"n":700,"text":"","atom":"a1445","author":"speed","version":150},{"n":701,"text":"\t/** The project as it stood with the first `at` log entries (#41, replay). */","atom":"a1445","author":"speed","version":150},{"n":702,"text":"\tprivate at(at: number): Project {","atom":"a1445","author":"speed","version":150},{"n":703,"text":"\t\tif (!this.read) throw Object.assign(new Error(\"replay needs the log\"), { code: \"not-implemented\" });","atom":"a1445","author":"speed","version":150},{"n":704,"text":"\t\tconst n = Math.max(0, Math.min(at, this.project.logLength));","atom":"a1445","author":"speed","version":150},{"n":705,"text":"\t\tconst r = this.replica;","atom":"a1445","author":"speed","version":150},{"n":706,"text":"\t\tif (r && r.logLength === n) return r;","atom":"a1445","author":"speed","version":150},{"n":707,"text":"\t\tif (r && r.logLength < n) {","atom":"a1445","author":"speed","version":150},{"n":708,"text":"\t\t\tr.catchUp(this.read(r.logLength, n - r.logLength));","atom":"a1445","author":"speed","version":150},{"n":709,"text":"\t\t\treturn r;","atom":"a1445","author":"speed","version":150},{"n":710,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":711,"text":"\t\tthis.replica = Project.load(this.read(0, n), new MemoryStore());","atom":"a1445","author":"speed","version":150},{"n":712,"text":"\t\treturn this.replica;","atom":"a1445","author":"speed","version":150},{"n":713,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":714,"text":"\tstatusAt(at: number) {","atom":"a1445","author":"speed","version":150},{"n":715,"text":"\t\tif (this.historical)","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":716,"text":"\t\t\treturn this.historical(Math.max(0, Math.min(at, this.project.logLength)), (p) => ({","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":717,"text":"\t\t\t\tat: Math.min(at, this.project.logLength),","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":718,"text":"\t\t\t\t...(p.initialized ? p.status() : { version: -1, agents: [] }),","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":719,"text":"\t\t\t}));","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":720,"text":"\t\tconst p = this.at(at);","atom":"a1445","author":"speed","version":150},{"n":721,"text":"\t\tconst answer = {","atom":"a1445","author":"speed","version":150},{"n":722,"text":"\t\t\tat: Math.min(at, this.project.logLength),","atom":"a1445","author":"speed","version":150},{"n":723,"text":"\t\t\t...(p.initialized ? p.status() : { version: -1, agents: [] }),","atom":"a1445","author":"speed","version":150},{"n":724,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":725,"text":"\t\tthis.release();","atom":"a1445","author":"speed","version":150},{"n":726,"text":"\t\treturn answer;","atom":"a1445","author":"speed","version":150},{"n":727,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":728,"text":"\twhereAt(at: number) {","atom":"a1445","author":"speed","version":150},{"n":729,"text":"\t\tif (this.historical)","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":730,"text":"\t\t\treturn this.historical(Math.max(0, Math.min(at, this.project.logLength)), (p) => ({","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":731,"text":"\t\t\t\tat: Math.min(at, this.project.logLength),","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":732,"text":"\t\t\t\t...(p.initialized ? where(p) : { version: -1, files: {} }),","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":733,"text":"\t\t\t}));","atom":"a1747","author":"codex-capacity-chair","version":162},{"n":734,"text":"\t\tconst p = this.at(at);","atom":"a1445","author":"speed","version":150},{"n":735,"text":"\t\tconst answer = {","atom":"a1445","author":"speed","version":150},{"n":736,"text":"\t\t\tat: Math.min(at, this.project.logLength),","atom":"a1445","author":"speed","version":150},{"n":737,"text":"\t\t\t...(p.initialized ? where(p) : { version: -1, files: {} }),","atom":"a1445","author":"speed","version":150},{"n":738,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":739,"text":"\t\tthis.release();","atom":"a1445","author":"speed","version":150},{"n":740,"text":"\t\treturn answer;","atom":"a1445","author":"speed","version":150},{"n":741,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":742,"text":"","atom":"a1445","author":"speed","version":150},{"n":743,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":744,"text":"\t * Drop the replay copy after each read (#46): a second copy of a large","atom":"a1445","author":"speed","version":150},{"n":745,"text":"\t * project's history doubles its memory, past a Durable Object's 128 MB.","atom":"a1445","author":"speed","version":150},{"n":746,"text":"\t * Each scrub replays from the start instead (about 0.2 s on game).","atom":"a1445","author":"speed","version":150},{"n":747,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":748,"text":"\tprivate release(): void {","atom":"a1445","author":"speed","version":150},{"n":749,"text":"\t\tthis.replica = undefined;","atom":"a1445","author":"speed","version":150},{"n":750,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":751,"text":"","atom":"a1445","author":"speed","version":150},{"n":752,"text":"\t/** hasBlob says whether the project holds a blob's bytes (#27); without it, every blob is refused. */","atom":"a1445","author":"speed","version":150},{"n":753,"text":"\t/** whole stores and reads files kept whole (#46); without it every text file is tracked by line. */","atom":"a1445","author":"speed","version":150},{"n":754,"text":"\tstatic open(","atom":"a1445","author":"speed","version":150},{"n":755,"text":"\t\tstorage: SqliteStorage,","atom":"a1445","author":"speed","version":150},{"n":756,"text":"\t\thasBlob?: (sha256: string) => boolean,","atom":"a1445","author":"speed","version":150},{"n":757,"text":"\t\twhole?: { keep(text: string): string; read(sha: string): string | null },","atom":"a1445","author":"speed","version":150},{"n":758,"text":"\t): EngineProject {","atom":"a1445","author":"speed","version":150},{"n":759,"text":"\t\tconst log = new SqliteLog(storage);","atom":"a1445","author":"speed","version":150},{"n":760,"text":"\t\treturn new EngineProject(","atom":"a1445","author":"speed","version":150},{"n":761,"text":"\t\t\tProject.load(log.entries(), log, {","atom":"a1445","author":"speed","version":150},{"n":762,"text":"\t\t\t\t...(hasBlob ? { hasBlob } : {}),","atom":"a1445","author":"speed","version":150},{"n":763,"text":"\t\t\t\t...(whole ? { whole } : {}),","atom":"a1445","author":"speed","version":150},{"n":764,"text":"\t\t\t\tnow: () => Date.now(),","atom":"a1445","author":"speed","version":150},{"n":765,"text":"\t\t\t\tshapes: log.shapes(),","atom":"a1445","author":"speed","version":150},{"n":766,"text":"\t\t\t\tentryAt: (at) => log.since(at, 1)[0]!,","atom":"a1445","author":"speed","version":150},{"n":767,"text":"\t\t\t}),","atom":"a1445","author":"speed","version":150},{"n":768,"text":"\t\t\t(from, limit) => log.since(from, limit),","atom":"a1445","author":"speed","version":150},{"n":769,"text":"\t\t\tlog,","atom":"a1445","author":"speed","version":150},{"n":770,"text":"\t\t);","atom":"a1445","author":"speed","version":150},{"n":771,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":772,"text":"","atom":"a1445","author":"speed","version":150},{"n":773,"text":"\texists() {","atom":"a1445","author":"speed","version":150},{"n":774,"text":"\t\treturn this.project.initialized;","atom":"a1445","author":"speed","version":150},{"n":775,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":776,"text":"\t/** Committed log epoch for host-side cache invalidation; it does not dispatch work. */","atom":"a1445","author":"speed","version":150},{"n":777,"text":"\tcommittedGeneration(): number {","atom":"a1445","author":"speed","version":150},{"n":778,"text":"\t\treturn this.store?.generation() ?? 0;","atom":"a1445","author":"speed","version":150},{"n":779,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":780,"text":"\tinit(","atom":"a1445","author":"speed","version":150},{"n":781,"text":"\t\tfiles: Record<string, string>,","atom":"a1445","author":"speed","version":150},{"n":782,"text":"\t\tmodes?: Record<string, { exec?: boolean; link?: string | null }>,","atom":"a1445","author":"speed","version":150},{"n":783,"text":"\t\tblobs?: Record<string, string>,","atom":"a1445","author":"speed","version":150},{"n":784,"text":"\t) {","atom":"a1445","author":"speed","version":150},{"n":785,"text":"\t\treturn this.project.init(files, Date.now(), modes ?? {}, blobs ?? {});","atom":"a1445","author":"speed","version":150},{"n":786,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":787,"text":"\tedit(agent: string, body: EditBody) {","atom":"a1445","author":"speed","version":150},{"n":788,"text":"\t\treturn this.project.edit(agent, body as Parameters<Project[\"edit\"]>[1], Date.now());","atom":"a1445","author":"speed","version":150},{"n":789,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":790,"text":"\trecord(","atom":"a1445","author":"speed","version":150},{"n":791,"text":"\t\tagent: string,","atom":"a1445","author":"speed","version":150},{"n":792,"text":"\t\tfiles: Record<string, string | null>,","atom":"a1445","author":"speed","version":150},{"n":793,"text":"\t\tmodes?: Record<string, { exec?: boolean; link?: string | null }>,","atom":"a1445","author":"speed","version":150},{"n":794,"text":"\t\tblobs?: Record<string, string>,","atom":"a1445","author":"speed","version":150},{"n":795,"text":"\t\tmeta?: { session?: string; subagent?: string; client?: string },","atom":"a1445","author":"speed","version":150},{"n":796,"text":"\t) {","atom":"a1445","author":"speed","version":150},{"n":797,"text":"\t\treturn this.project.record(agent, files, Date.now(), modes ?? {}, blobs ?? {}, meta ?? {});","atom":"a1445","author":"speed","version":150},{"n":798,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":799,"text":"\tpublish(agent: string, message: string, asIs?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":800,"text":"\t\treturn this.project.publish(agent, message, Date.now(), { asIs: asIs === true });","atom":"a1445","author":"speed","version":150},{"n":801,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":802,"text":"\tsync(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":803,"text":"\t\treturn this.project.sync(agent);","atom":"a1445","author":"speed","version":150},{"n":804,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":805,"text":"\tstatus() {","atom":"a1445","author":"speed","version":150},{"n":806,"text":"\t\treturn this.project.status();","atom":"a1445","author":"speed","version":150},{"n":807,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":808,"text":"\tswitchTo(agent: string, name: string | null, carry = false) {","atom":"a1445","author":"speed","version":150},{"n":809,"text":"\t\treturn this.project.switchTo(agent, name, Date.now(), { carry });","atom":"a1445","author":"speed","version":150},{"n":810,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":811,"text":"\tland(agent: string, message: string) {","atom":"a1445","author":"speed","version":150},{"n":812,"text":"\t\treturn this.project.land(agent, message, Date.now());","atom":"a1445","author":"speed","version":150},{"n":813,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":814,"text":"\tingest(input: Parameters<Project[\"ingest\"]>[0], time: number) {","atom":"a1445","author":"speed","version":150},{"n":815,"text":"\t\treturn this.project.ingest(input, time);","atom":"a1445","author":"speed","version":150},{"n":816,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":817,"text":"\tsyncDraft(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":818,"text":"\t\treturn this.project.syncDraft(agent, Date.now());","atom":"a1445","author":"speed","version":150},{"n":819,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":820,"text":"\tfilesAt(version: number) {","atom":"a1445","author":"speed","version":150},{"n":821,"text":"\t\treturn this.project.viewAt(version).files();","atom":"a1445","author":"speed","version":150},{"n":822,"text":"\t}","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":823,"text":"\tfileTextAt(version: number, path: string): string {","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":824,"text":"\t\treturn this.project.viewAt(version).text(path);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":825,"text":"\t}","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":826,"text":"\t/** One scoped batch: at most 64 files and 64 Ki characters plus one whole file. */","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":827,"text":"\tfileTextsAt(version: number, paths: readonly string[]): Record<string, string> {","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":828,"text":"\t\tconst view = this.project.viewAt(version);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":829,"text":"\t\tconst files: Record<string, string> = Object.create(null);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":830,"text":"\t\tlet characters = 0;","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":831,"text":"\t\tfor (const path of paths.slice(0, 64)) {","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":832,"text":"\t\t\tconst text = view.attrs(path).link !== null ? \"\" : view.text(path);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":833,"text":"\t\t\tfiles[path] = text;","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":834,"text":"\t\t\tcharacters += text.length;","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":835,"text":"\t\t\tif (characters >= 65536) break;","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":836,"text":"\t\t}","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":837,"text":"\t\treturn files;","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":838,"text":"\t}","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":839,"text":"\t/** Capture metadata now; each text read reopens the captured version in a fresh host scope. */","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":840,"text":"\tsharedPushMetadata(): PushSnapshotMetadata {","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":841,"text":"\t\tconst version = this.project.version;","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":842,"text":"\t\tconst view = this.project.viewAt(version);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":843,"text":"\t\tconst paths: string[] = [];","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":844,"text":"\t\tconst modes: PushSnapshotMetadata[\"modes\"] = Object.create(null);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":845,"text":"\t\tconst blobs: Record<string, string> = Object.create(null);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":846,"text":"\t\tfor (const path of view.paths()) {","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":847,"text":"\t\t\tconst attrs = view.attrs(path);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":848,"text":"\t\t\tmodes[path] = { exec: attrs.exec, link: attrs.link };","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":849,"text":"\t\t\tif (attrs.blob !== null) blobs[path] = attrs.blob;","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":850,"text":"\t\t\telse paths.push(path);","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":851,"text":"\t\t}","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":852,"text":"\t\tconst by = version > 0 ? this.project.published(version) : undefined;","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":853,"text":"\t\treturn { version, paths, modes, blobs, ...(by ? { last: { agent: by.agent, message: by.message } } : {}) };","atom":"a1918","author":"codex-capacity-chair","version":177},{"n":854,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":855,"text":"\tblobsAt(version: number) {","atom":"a1445","author":"speed","version":150},{"n":856,"text":"\t\treturn this.project.viewAt(version).blobs();","atom":"a1445","author":"speed","version":150},{"n":857,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":858,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":859,"text":"\t * Shared's newest version. Its files and modes are laid out on first read: every call reads shared().version","atom":"a1445","author":"speed","version":150},{"n":860,"text":"\t * before and after its op, and laying out the files reads each file's text from the log, about 0.5 s on abso","atom":"a1445","author":"speed","version":150},{"n":861,"text":"\t * (abso 299).","atom":"a1445","author":"speed","version":150},{"n":862,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":863,"text":"\tshared() {","atom":"a1445","author":"speed","version":150},{"n":864,"text":"\t\tconst version = this.project.version;","atom":"a1445","author":"speed","version":150},{"n":865,"text":"\t\tconst by = version > 0 ? this.project.published(version) : undefined;","atom":"a1445","author":"speed","version":150},{"n":866,"text":"\t\tconst blobs = this.project.blobs();","atom":"a1445","author":"speed","version":150},{"n":867,"text":"\t\tconst project = this.project;","atom":"a1445","author":"speed","version":150},{"n":868,"text":"\t\tlet files: Record<string, string> | undefined;","atom":"a1445","author":"speed","version":150},{"n":869,"text":"\t\tlet modes: ReturnType<Project[\"modes\"]> | undefined;","atom":"a1445","author":"speed","version":150},{"n":870,"text":"\t\treturn {","atom":"a1445","author":"speed","version":150},{"n":871,"text":"\t\t\tversion,","atom":"a1445","author":"speed","version":150},{"n":872,"text":"\t\t\tget files() {","atom":"a1445","author":"speed","version":150},{"n":873,"text":"\t\t\t\tfiles ??= project.files();","atom":"a1445","author":"speed","version":150},{"n":874,"text":"\t\t\t\treturn files;","atom":"a1445","author":"speed","version":150},{"n":875,"text":"\t\t\t},","atom":"a1445","author":"speed","version":150},{"n":876,"text":"\t\t\tget modes() {","atom":"a1445","author":"speed","version":150},{"n":877,"text":"\t\t\t\tmodes ??= project.modes();","atom":"a1445","author":"speed","version":150},{"n":878,"text":"\t\t\t\treturn modes;","atom":"a1445","author":"speed","version":150},{"n":879,"text":"\t\t\t},","atom":"a1445","author":"speed","version":150},{"n":880,"text":"\t\t\t...(Object.keys(blobs).length > 0 ? { blobs } : {}),","atom":"a1445","author":"speed","version":150},{"n":881,"text":"\t\t\t...(by ? { last: { agent: by.agent, message: by.message } } : {}),","atom":"a1445","author":"speed","version":150},{"n":882,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":883,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":884,"text":"}","atom":"a1445","author":"speed","version":150}],"atoms":[{"atom":"a1125","author":"codex-capacity-chair","message":"","time":1791843086262,"timeIso":"2026-10-12T22:11:26.262Z","publish":{"draft":null,"version":134,"agent":"codex-capacity-chair","message":"Stream project conflict candidates and resolver intersections","time":1791843192862,"timeIso":"2026-10-12T22:13:12.862Z"}},{"atom":"a1445","author":"speed","message":"","time":1791906648241,"timeIso":"2026-10-13T15:50:48.241Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}},{"atom":"a1446","author":"speed","message":"","time":1791906648556,"timeIso":"2026-10-13T15:50:48.556Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}},{"atom":"a1483","author":"speed","message":"","time":1791907425388,"timeIso":"2026-10-13T16:03:45.388Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}},{"atom":"a1582","author":"codex-capacity-chair","message":"","time":1791914678514,"timeIso":"2026-10-13T18:04:38.514Z","publish":{"draft":null,"version":157,"agent":"codex-capacity-chair","message":"Share the SQLite writer and projection host with the open server","time":1791915928641,"timeIso":"2026-10-13T18:25:28.641Z"}},{"atom":"a1589","author":"codex-capacity-chair","message":"","time":1791915569981,"timeIso":"2026-10-13T18:19:29.981Z","publish":{"draft":null,"version":157,"agent":"codex-capacity-chair","message":"Share the SQLite writer and projection host with the open server","time":1791915928641,"timeIso":"2026-10-13T18:25:28.641Z"}},{"atom":"a1594","author":"codex-capacity-chair","message":"","time":1791916379418,"timeIso":"2026-10-13T18:32:59.418Z","publish":{"draft":null,"version":158,"agent":"codex-capacity-chair","message":"Integrate opt-in disk-first project runtime with cold-object transactions","time":1791917879117,"timeIso":"2026-10-13T18:57:59.117Z"}},{"atom":"a1747","author":"codex-capacity-chair","message":"","time":1791945013341,"timeIso":"2026-10-14T02:30:13.341Z","publish":{"draft":null,"version":162,"agent":"codex-capacity-chair","message":"Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gate","time":1791945013341,"timeIso":"2026-10-14T02:30:13.341Z"}},{"atom":"a1817","author":"codex-capacity-chair","message":"","time":1791956752682,"timeIso":"2026-10-14T05:45:52.682Z","publish":{"draft":null,"version":167,"agent":"codex-capacity-chair","message":"Stream canonical log append and bound JSON string decoding allocations","time":1791956852426,"timeIso":"2026-10-14T05:47:32.426Z"}},{"atom":"a1918","author":"codex-capacity-chair","message":"","time":1791973146673,"timeIso":"2026-10-14T10:19:06.673Z","publish":{"draft":null,"version":177,"agent":"codex-capacity-chair","message":"Read Artifacts snapshots in version-pinned batches; cleared in review ask 45","time":1791973148753,"timeIso":"2026-10-14T10:19:08.753Z"}},{"atom":"a2081","author":"candidates","message":"","time":1792003409924,"timeIso":"2026-10-14T18:43:29.924Z","publish":{"draft":null,"version":186,"agent":"candidates","message":"Read a version of shared without some earlier versions: abso show <N> --without A,B shows what differs and abso export <dir> --version N --without A,B writes the files. The server's GET without?version=&versions= checks the set left exactly as asked: when a version it keeps builds on one left out, it refuses with that chain, the files and the wider set that works, and never widens it. Atoms keep their ids and authors; shared and its log don't change; the same ask gives the same tree hash.","time":1792004002371,"timeIso":"2026-10-14T18:53:22.371Z"}},{"atom":"a2173","author":"whytrail","message":"","time":1792019576836,"timeIso":"2026-10-14T23:12:56.836Z","publish":{"draft":null,"version":193,"agent":"whytrail","message":"abso why follows a line back past formatting to its reason, and names git commits\n\nwhy now lists a line's earlier changes, newest first, with what the line read before each. A change that rewrote a line left the line it replaced in the file's history; why pairs the two (same code formatted differently, the same code rewrapped, or the most similar line) and follows the pairs back. A change that only touched formatting (whitespace, line wrapping, quotes, trailing commas, line-end semicolons, parentheses around a lone arrow parameter) is skipped by default, and why names it: 'Skipped 1 formatting change since: version 366'. --all shows those too. --at <version> reads the line as it was at that version.\n\nA push imported from git (client/scripts/import-git.ts, or a plain git push) names its commit and author in why and blame. import-git.ts now also records where the repository's issues are, from origin on GitHub or GitLab or --issues, and why says which issue #N in an imported message or line means. A project imported before this can say it once in abso.json: \"gitIssues\": \"https://github.com/owner/repo/issues\".\n\nCloses issues 20 and 21's tool side.","time":1792019638939,"timeIso":"2026-10-14T23:13:58.939Z"}},{"atom":"a2484","author":"capacity","message":"","time":1792072853745,"timeIso":"2026-10-15T14:00:53.745Z","publish":{"draft":null,"version":243,"agent":"capacity","message":"compare's summary: each changed file's size and SHA-256 instead of its texts (abso issue 680; disk-first 2; abso Capacity).\n\ncompare 612 to 1224 on abso answers 13.2 MB: the full before and after text of about 3,000 changed files. Read Speed's shape lets the site ask for a summary and fetch a file's texts when it opens it.\n\n- view-changes.ts summariesBetween: the files changesBetween would list, each side as {size, sha256} for text (UTF-8 bytes, SHA-256 of the text), {blob} for a binary file (its hash; the Worker adds its size from the blob store), or null when absent; mode and blob as in the full answer. Each text is read, summed up and let go.\n- version-log compare takes summary and answers {from, to, summary: true, files}. ProjectHistory.compare and both engine-project.ts implementations take a fifth argument, summary; http.ts passes ?summary=1. The full answer is unchanged.\n\nOn abso adopted fresh: the summary for 612 to 1224 is 174 KB instead of 13.2 MB, with heap after at 38 MB. The time is the same (about 20 s cold): it still lays the files out to hash them. Stored per-version sizes and hashes would remove that; they're proposed with the author totals table.\n\nNew test compare-summary: on an in-memory and a writer-backed project, the summary lists the files the full compare does, with sizes and SHA-256s of its texts, blob hashes for a binary file, and no text. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.","time":1792072854373,"timeIso":"2026-10-15T14:00:54.373Z"}},{"atom":"a2490","author":"capacity","message":"","time":1792079189228,"timeIso":"2026-10-15T15:46:29.228Z","publish":{"draft":null,"version":244,"agent":"capacity","message":"compare keeps its own answer type; the summary is compareSummary (abso issue 680; abso Capacity).\n\n243 gave compare one answer type for both shapes, full and summary. abso's own callers read compare(...).files as file changes (worker/src/engine-project.ts, scripts/versions-check.ts, test/versions.test.ts), and the union broke their types, which showed when I pinned 243 into abso. Core's own tests didn't catch it.\n\n- version-log.ts: compared() works out the files and both views; compare answers {from, to, files: FileChange[]} as before 243, and compareSummary answers {from, to, summary: true, files}. Project.compareSummary calls it.\n- server/src/engine-project.ts: compare(..., summary) calls compareSummary when summary is set. http.ts and ProjectHistory are unchanged from 243 (?summary=1, a fifth argument).\n- compare-summary.test.ts calls compareSummary.\n\nAnswers are the same as 243's. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.","time":1792079189805,"timeIso":"2026-10-15T15:46:29.805Z"}},{"atom":"a2793","author":"capacity","message":"","time":1792118119764,"timeIso":"2026-10-16T02:35:19.764Z","publish":{"draft":null,"version":284,"agent":"capacity","message":"server/src/engine-project.ts: EngineProject passes seatNotice through (277 added it to ProjectHistory; the server's check failed on it since, 283's too). The same pass-through abso's worker has (abso 1430). Root and server tsc clean.","time":1792118185051,"timeIso":"2026-10-16T02:36:25.051Z"}}]}