{"file":"worker/project/view-changes.ts","version":318,"total":111,"from":1,"to":111,"lines":[{"n":1,"text":"import { createHash } from \"node:crypto\";","atom":"a2488","author":"capacity","version":243},{"n":2,"text":"import type { ReadView } from \"../../src/engine/index.ts\";","atom":"a1364","author":"codex-capacity-chair","version":143},{"n":3,"text":"import { ProjectError } from \"./project-error.ts\";","atom":"a0","author":"init","version":0},{"n":4,"text":"import type { FileChange, Mode, Modes } from \"./project-types.ts\";","atom":"a0","author":"init","version":0},{"n":5,"text":"","atom":"a0","author":"init","version":0},{"n":6,"text":"/** The listed files whose text differs between two views, before and after. */","atom":"a0","author":"init","version":0},{"n":7,"text":"export function changesBetween(before: ReadView, after: ReadView, files: Iterable<string>): FileChange[] {","atom":"a1364","author":"codex-capacity-chair","version":143},{"n":8,"text":"\tconst out: FileChange[] = [];","atom":"a0","author":"init","version":0},{"n":9,"text":"\tfor (const path of [...new Set(files)].toSorted()) {","atom":"a0","author":"init","version":0},{"n":10,"text":"\t\tconst b = before.hasFile(path) ? before.text(path) : null;","atom":"a0","author":"init","version":0},{"n":11,"text":"\t\tconst a = after.hasFile(path) ? after.text(path) : null;","atom":"a0","author":"init","version":0},{"n":12,"text":"\t\tconst mode = modeChange(before, after, path);","atom":"a0","author":"init","version":0},{"n":13,"text":"\t\tconst bb = before.attrs(path).blob;","atom":"a0","author":"init","version":0},{"n":14,"text":"\t\tconst ab = after.attrs(path).blob;","atom":"a0","author":"init","version":0},{"n":15,"text":"\t\tconst blob = bb !== ab ? { before: bb, after: ab } : undefined;","atom":"a0","author":"init","version":0},{"n":16,"text":"\t\tif (a !== b || mode || blob)","atom":"a0","author":"init","version":0},{"n":17,"text":"\t\t\tout.push({ path, before: b, after: a, ...(mode ? { mode } : {}), ...(blob ? { blob } : {}) });","atom":"a0","author":"init","version":0},{"n":18,"text":"\t}","atom":"a2488","author":"capacity","version":243},{"n":19,"text":"\treturn out;","atom":"a2488","author":"capacity","version":243},{"n":20,"text":"}","atom":"a2488","author":"capacity","version":243},{"n":21,"text":"","atom":"a2488","author":"capacity","version":243},{"n":22,"text":"/** A changed file's text or blob, summed up: its size in UTF-8 bytes and its SHA-256, or a blob's hash. */","atom":"a2488","author":"capacity","version":243},{"n":23,"text":"export type FileSummary = { size: number; sha256: string } | { blob: string };","atom":"a2488","author":"capacity","version":243},{"n":24,"text":"","atom":"a2488","author":"capacity","version":243},{"n":25,"text":"/**","atom":"a2488","author":"capacity","version":243},{"n":26,"text":" * changesBetween without the texts (abso issue 680, compare's summary): each changed file before and after as its size","atom":"a2488","author":"capacity","version":243},{"n":27,"text":" * and SHA-256, or its blob's hash for a binary file. Each text is read, summed up and let go, so a compare of thousands","atom":"a2488","author":"capacity","version":243},{"n":28,"text":" * of files never holds them all.","atom":"a2488","author":"capacity","version":243},{"n":29,"text":" */","atom":"a2488","author":"capacity","version":243},{"n":30,"text":"export function summariesBetween(","atom":"a2488","author":"capacity","version":243},{"n":31,"text":"\tbefore: ReadView,","atom":"a2488","author":"capacity","version":243},{"n":32,"text":"\tafter: ReadView,","atom":"a2488","author":"capacity","version":243},{"n":33,"text":"\tfiles: Iterable<string>,","atom":"a2488","author":"capacity","version":243},{"n":34,"text":"): {","atom":"a2488","author":"capacity","version":243},{"n":35,"text":"\tpath: string;","atom":"a2488","author":"capacity","version":243},{"n":36,"text":"\tbefore: FileSummary | null;","atom":"a2488","author":"capacity","version":243},{"n":37,"text":"\tafter: FileSummary | null;","atom":"a2488","author":"capacity","version":243},{"n":38,"text":"\tmode?: { before: Mode; after: Mode };","atom":"a2488","author":"capacity","version":243},{"n":39,"text":"\tblob?: { before: string | null; after: string | null };","atom":"a2488","author":"capacity","version":243},{"n":40,"text":"}[] {","atom":"a2488","author":"capacity","version":243},{"n":41,"text":"\tconst sum = (view: ReadView, path: string): FileSummary | null => {","atom":"a2488","author":"capacity","version":243},{"n":42,"text":"\t\tif (!view.hasFile(path)) return null;","atom":"a2488","author":"capacity","version":243},{"n":43,"text":"\t\tconst blob = view.attrs(path).blob;","atom":"a2488","author":"capacity","version":243},{"n":44,"text":"\t\tif (blob !== null) return { blob };","atom":"a2488","author":"capacity","version":243},{"n":45,"text":"\t\tconst text = view.text(path);","atom":"a2488","author":"capacity","version":243},{"n":46,"text":"\t\treturn { size: Buffer.byteLength(text, \"utf8\"), sha256: createHash(\"sha256\").update(text, \"utf8\").digest(\"hex\") };","atom":"a2488","author":"capacity","version":243},{"n":47,"text":"\t};","atom":"a2488","author":"capacity","version":243},{"n":48,"text":"\tconst out: ReturnType<typeof summariesBetween> = [];","atom":"a2488","author":"capacity","version":243},{"n":49,"text":"\tfor (const path of [...new Set(files)].toSorted()) {","atom":"a2488","author":"capacity","version":243},{"n":50,"text":"\t\tif (!differs(before, after, path)) continue;","atom":"a2488","author":"capacity","version":243},{"n":51,"text":"\t\tconst mode = modeChange(before, after, path);","atom":"a2488","author":"capacity","version":243},{"n":52,"text":"\t\tconst bb = before.attrs(path).blob;","atom":"a2488","author":"capacity","version":243},{"n":53,"text":"\t\tconst ab = after.attrs(path).blob;","atom":"a2488","author":"capacity","version":243},{"n":54,"text":"\t\tout.push({","atom":"a2488","author":"capacity","version":243},{"n":55,"text":"\t\t\tpath,","atom":"a2488","author":"capacity","version":243},{"n":56,"text":"\t\t\tbefore: sum(before, path),","atom":"a2488","author":"capacity","version":243},{"n":57,"text":"\t\t\tafter: sum(after, path),","atom":"a2488","author":"capacity","version":243},{"n":58,"text":"\t\t\t...(mode ? { mode } : {}),","atom":"a2488","author":"capacity","version":243},{"n":59,"text":"\t\t\t...(bb !== ab ? { blob: { before: bb, after: ab } } : {}),","atom":"a2488","author":"capacity","version":243},{"n":60,"text":"\t\t});","atom":"a2488","author":"capacity","version":243},{"n":61,"text":"\t}","atom":"a0","author":"init","version":0},{"n":62,"text":"\treturn out;","atom":"a0","author":"init","version":0},{"n":63,"text":"}","atom":"a0","author":"init","version":0},{"n":64,"text":"","atom":"a0","author":"init","version":0},{"n":65,"text":"/** Whether a file differs between two views: its text, its mode, or its blob (what changesBetween lists). */","atom":"a0","author":"init","version":0},{"n":66,"text":"export function differs(before: ReadView, after: ReadView, path: string): boolean {","atom":"a1364","author":"codex-capacity-chair","version":143},{"n":67,"text":"\tconst had = before.hasFile(path);","atom":"a0","author":"init","version":0},{"n":68,"text":"\tif (had !== after.hasFile(path)) return true;","atom":"a0","author":"init","version":0},{"n":69,"text":"\tif (had && !before.sameText(path, after)) return true;","atom":"a0","author":"init","version":0},{"n":70,"text":"\tconst b = before.attrs(path);","atom":"a0","author":"init","version":0},{"n":71,"text":"\tconst a = after.attrs(path);","atom":"a0","author":"init","version":0},{"n":72,"text":"\treturn b.exec !== a.exec || b.link !== a.link || b.blob !== a.blob;","atom":"a0","author":"init","version":0},{"n":73,"text":"}","atom":"a0","author":"init","version":0},{"n":74,"text":"","atom":"a0","author":"init","version":0},{"n":75,"text":"/** A file's executable bit and link target, before and after, when either changed. */","atom":"a0","author":"init","version":0},{"n":76,"text":"export function modeChange(before: ReadView, after: ReadView, path: string): { before: Mode; after: Mode } | undefined {","atom":"a1364","author":"codex-capacity-chair","version":143},{"n":77,"text":"\tconst b = before.attrs(path);","atom":"a0","author":"init","version":0},{"n":78,"text":"\tconst a = after.attrs(path);","atom":"a0","author":"init","version":0},{"n":79,"text":"\tif (b.exec === a.exec && b.link === a.link) return undefined;","atom":"a0","author":"init","version":0},{"n":80,"text":"\treturn { before: { exec: b.exec, link: b.link }, after: { exec: a.exec, link: a.link } };","atom":"a0","author":"init","version":0},{"n":81,"text":"}","atom":"a0","author":"init","version":0},{"n":82,"text":"","atom":"a0","author":"init","version":0},{"n":83,"text":"/** Every executable file and link in a view. */","atom":"a0","author":"init","version":0},{"n":84,"text":"export function modesOf(view: ReadView): Modes {","atom":"a1364","author":"codex-capacity-chair","version":143},{"n":85,"text":"\tconst out: Modes = {};","atom":"a0","author":"init","version":0},{"n":86,"text":"\tfor (const path of view.paths()) {","atom":"a0","author":"init","version":0},{"n":87,"text":"\t\tconst a = view.attrs(path);","atom":"a0","author":"init","version":0},{"n":88,"text":"\t\tif (a.exec || a.link !== null)","atom":"a0","author":"init","version":0},{"n":89,"text":"\t\t\tout[path] = { ...(a.exec ? { exec: true } : {}), ...(a.link !== null ? { link: a.link } : {}) };","atom":"a0","author":"init","version":0},{"n":90,"text":"\t}","atom":"a0","author":"init","version":0},{"n":91,"text":"\treturn out;","atom":"a0","author":"init","version":0},{"n":92,"text":"}","atom":"a0","author":"init","version":0},{"n":93,"text":"","atom":"a0","author":"init","version":0},{"n":94,"text":"export function checkModes(modes: unknown): Modes {","atom":"a0","author":"init","version":0},{"n":95,"text":"\tif (typeof modes !== \"object\" || modes === null || Array.isArray(modes))","atom":"a0","author":"init","version":0},{"n":96,"text":"\t\tthrow new ProjectError(\"bad-request\", \"modes must be {path: {exec, link}}\");","atom":"a0","author":"init","version":0},{"n":97,"text":"\tfor (const [path, m] of Object.entries(modes as Record<string, unknown>)) {","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\tconst mode = m as Mode;","atom":"a0","author":"init","version":0},{"n":99,"text":"\t\tif (typeof m !== \"object\" || m === null) throw new ProjectError(\"bad-request\", `${path}: a mode is {exec?, link?}`);","atom":"a0","author":"init","version":0},{"n":100,"text":"\t\tif (mode.exec !== undefined && typeof mode.exec !== \"boolean\")","atom":"a0","author":"init","version":0},{"n":101,"text":"\t\t\tthrow new ProjectError(\"bad-request\", `${path}: exec is true or false`);","atom":"a0","author":"init","version":0},{"n":102,"text":"\t\tif (","atom":"a0","author":"init","version":0},{"n":103,"text":"\t\t\tmode.link !== undefined &&","atom":"a0","author":"init","version":0},{"n":104,"text":"\t\t\tmode.link !== null &&","atom":"a0","author":"init","version":0},{"n":105,"text":"\t\t\t(typeof mode.link !== \"string\" || mode.link === \"\" || /[\\n\\r]/.test(mode.link))","atom":"a0","author":"init","version":0},{"n":106,"text":"\t\t) {","atom":"a0","author":"init","version":0},{"n":107,"text":"\t\t\tthrow new ProjectError(\"bad-request\", `${path}: link is a target path or null`);","atom":"a0","author":"init","version":0},{"n":108,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":109,"text":"\t}","atom":"a0","author":"init","version":0},{"n":110,"text":"\treturn modes as Modes;","atom":"a0","author":"init","version":0},{"n":111,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a1364","author":"codex-capacity-chair","message":"","time":1791854964720,"timeIso":"2026-10-13T01:29:24.720Z","publish":{"draft":null,"version":143,"agent":"codex-capacity-chair","message":"Add inactive disk projection provider and verified transactional readers (#16)","time":1791855032023,"timeIso":"2026-10-13T01:30:32.023Z"}},{"atom":"a2488","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"}}]}