{"draft":null,"from":162,"to":318,"files":[{"path":"server/src/engine-project.ts","added":70,"removed":8,"diff":"--- a/server/src/engine-project.ts\n+++ b/server/src/engine-project.ts\n@@ -3,11 +3,13 @@\n // 2 MB) is split across rows and joined on load. Ported from the platform's worker/src/engine-project.ts; the\n // writer-adoption and R2 version parts are left out.\n \n+import { jsonValueChunks } from \"../../src/engine/json-value-chunks.ts\";\n import { blame, folderBlame, why } from \"../../worker/project/blame.ts\";\n import { feedEvents } from \"../../worker/project/feed.ts\";\n import { type Entry, type ProjectStore as LogStore, MemoryStore, Project } from \"../../worker/project/project.ts\";\n import type { EditBody, ProjectCalls, ProjectHistory } from \"../../worker/project/project-api.ts\";\n import { where } from \"../../worker/project/where.ts\";\n+import type { PushSnapshotMetadata } from \"./push-snapshot.ts\";\n \n /** The parts of a Durable Object's storage the log and blob store use, declared structurally so tests can stand in. */\n export interface SqliteStorage {\n@@ -33,6 +35,22 @@\n \treturn parts;\n }\n \n+/** Retains one log row plus an encoder fragment, preserving legacy row boundaries. */\n+export function* streamedLogParts(value: unknown): IterableIterator<string> {\n+\tlet pending = \"\";\n+\tfor (const chunk of jsonValueChunks(value)) {\n+\t\tpending += chunk;\n+\t\twhile (pending.length > LOG_PART_CHARACTERS) {\n+\t\t\tlet end = LOG_PART_CHARACTERS;\n+\t\t\tconst last = pending.charCodeAt(end - 1);\n+\t\t\tif (last >= 0xd800 && last <= 0xdbff) end--;\n+\t\t\tyield pending.slice(0, end);\n+\t\t\tpending = pending.slice(end);\n+\t\t}\n+\t}\n+\tif (pending) yield pending;\n+}\n+\n /** The lines an entry's atoms write: what a loaded project's size grows with (#46, #56). */\n function linesIn(entry: Entry): number {\n \tlet n = 0;\n@@ -424,11 +442,11 @@\n \t\t\tif (keys > 0) this.storage.sql.exec(\"UPDATE counts SET value = value + ? WHERE name = 'keys'\", keys);\n \t\t\tlet chars = 0;\n \t\t\tfor (const entry of entries) {\n-\t\t\t\tconst json = JSON.stringify(entry);\n-\t\t\t\tlogParts(json).forEach((text, part) => {\n+\t\t\t\tlet part = 0;\n+\t\t\t\tfor (const text of streamedLogParts(entry)) {\n \t\t\t\t\tchars += text.length;\n-\t\t\t\t\tthis.storage.sql.exec(\"INSERT INTO log (seq, part, text) VALUES (?, ?, ?)\", next, part, text);\n-\t\t\t\t});\n+\t\t\t\t\tthis.storage.sql.exec(\"INSERT INTO log (seq, part, text) VALUES (?, ?, ?)\", next, part++, text);\n+\t\t\t\t}\n \t\t\t\tnext++;\n \t\t\t}\n \t\t\t// Chars are only added to once counted: a log from before the count is summed whole first (logSize).\n@@ -478,8 +496,12 @@\n \t\t\t...(folder !== undefined ? { folder } : {}),\n \t\t});\n \t}\n-\twhy(file: string, line: number, draft?: string, agent?: string) {\n-\t\treturn why(this.project, file, line, { ...(draft ? { draft } : {}), ...(agent ? { agent } : {}) });\n+\twhy(file: string, line: number, draft?: string, agent?: string, version?: number) {\n+\t\treturn why(this.project, file, line, {\n+\t\t\t...(draft ? { draft } : {}),\n+\t\t\t...(agent ? { agent } : {}),\n+\t\t\t...(version !== undefined ? { version } : {}),\n+\t\t});\n \t}\n \twhere() {\n \t\treturn where(this.project);\n@@ -501,9 +523,13 @@\n \tfileAt(path: string, version: number, draft: string | null, agent?: string) {\n \t\treturn this.project.fileAt(path, version, { draft, ...(agent ? { agent } : {}) });\n \t}\n-\tcompare(from: number, to: number, draft: string | null, agent?: string) {\n-\t\treturn this.project.compare(from, to, { draft, ...(agent ? { agent } : {}) });\n+\tcompare(from: number, to: number, draft: string | null, agent?: string, summary?: boolean) {\n+\t\tconst where = { draft, ...(agent ? { agent } : {}) };\n+\t\treturn summary ? this.project.compareSummary(from, to, where) : this.project.compare(from, to, where);\n \t}\n+\twithout(version: number, versions: readonly number[]) {\n+\t\treturn this.project.without(version, versions);\n+\t}\n \tshow(version: number, draft: string | null, agent?: string) {\n \t\treturn this.project.show(version, { draft, ...(agent ? { agent } : {}) });\n \t}\n@@ -546,6 +572,10 @@\n \tannouncePerson(person: { id: string; name: string }, text: string, to?: string[]) {\n \t\treturn this.project.announcePerson(person, text, to, Date.now());\n \t}\n+\t/** A seat's earlier chat hears that another chat used the seat (277, groups); as abso's worker has it. */\n+\tseatNotice(agent: string, place: string, key: string) {\n+\t\treturn this.project.seatNotice(agent, place, key);\n+\t}\n \tstarting(agent: string, text: string | null, files?: string[], options: { issue?: unknown; done?: unknown } = {}) {\n \t\treturn this.project.starting(agent, text, files, Date.now(), options);\n \t}\n@@ -790,6 +820,38 @@\n \tfilesAt(version: number) {\n \t\treturn this.project.viewAt(version).files();\n \t}\n+\tfileTextAt(version: number, path: string): string {\n+\t\treturn this.project.viewAt(version).text(path);\n+\t}\n+\t/** One scoped batch: at most 64 files and 64 Ki characters plus one whole file. */\n+\tfileTextsAt(version: number, paths: readonly string[]): Record<string, string> {\n+\t\tconst view = this.project.viewAt(version);\n+\t\tconst files: Record<string, string> = Object.create(null);\n+\t\tlet characters = 0;\n+\t\tfor (const path of paths.slice(0, 64)) {\n+\t\t\tconst text = view.attrs(path).link !== null ? \"\" : view.text(path);\n+\t\t\tfiles[path] = text;\n+\t\t\tcharacters += text.length;\n+\t\t\tif (characters >= 65536) break;\n+\t\t}\n+\t\treturn files;\n+\t}\n+\t/** Capture metadata now; each text read reopens the captured version in a fresh host scope. */\n+\tsharedPushMetadata(): PushSnapshotMetadata {\n+\t\tconst version = this.project.version;\n+\t\tconst view = this.project.viewAt(version);\n+\t\tconst paths: string[] = [];\n+\t\tconst modes: PushSnapshotMetadata[\"modes\"] = Object.create(null);\n+\t\tconst blobs: Record<string, string> = Object.create(null);\n+\t\tfor (const path of view.paths()) {\n+\t\t\tconst attrs = view.attrs(path);\n+\t\t\tmodes[path] = { exec: attrs.exec, link: attrs.link };\n+\t\t\tif (attrs.blob !== null) blobs[path] = attrs.blob;\n+\t\t\telse paths.push(path);\n+\t\t}\n+\t\tconst by = version > 0 ? this.project.published(version) : undefined;\n+\t\treturn { version, paths, modes, blobs, ...(by ? { last: { agent: by.agent, message: by.message } } : {}) };\n+\t}\n \tblobsAt(version: number) {\n \t\treturn this.project.viewAt(version).blobs();\n \t}"}],"unmatched":[]}