A draft's view takes its base view's layout of every file the draft doesn't touch (disk-first 2; abso Capacity). Version 235 of shared· capacity· Oct 15 (2026-10-15 11:37 UTC) · Not checked
An agent's tree, files and folder blame lay out every file in the agent's view, and tree also lays out the base to see which files the draft changed. Each layout read the file's packed history again, though every file the draft doesn't touch lays out exactly as in the draft's base.
View.shareFiles(from, except): a view lays out a file by taking from's layout of it, unless the file is in except. except is worked out once, when a file is first needed. Project.#agentView sets it for a draft's view over its base's when the draft moves nothing (its moves are then the base's, as shareMoves already relies on). The touched files are touchedFiles over the draft's atoms, in both views: the files they write, delete in, set attributes on, and, where moves count, the files their deleted lines and their runs' parents sit in. On abso adopted fresh, one kept writer: an agent's tree with authors 23.4 s to 12 to 14 s. It's still slow because a whole abso layout is bigger than the views' byte budget, so it isn't kept between calls.
New test agent-views-shared: after a published move of a function into another file, drafts that edit a moved line, delete one, change another file, set an attribute, or move lines themselves each read every file (text, attributes, writers) as the in-memory project does, read twice; it fails when the touched files are taken from where lines were written only. Named tests: every engine test (288 of 288), every worker/project test (338 of 338); typescript-rs, all 27 answers match replay; tsc and biome clean.
Version 234 · Files at version 235
3 files, 105 lines added, 3 removed.
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -49,7 +49,7 @@
49 49 /** Structural read boundary shared by historical and transaction-bound projections. */ 50 50 export type ReadView = Omit< 51 51 Pick<View, keyof View>, 52 − "sameText" | "visibleCount" | "shareMoves" | "fileOfNumber" | "lineNumberOf" | "visibleWriters"
52 + "sameText" | "visibleCount" | "shareMoves" | "shareFiles" | "fileOfNumber" | "lineNumberOf" | "visibleWriters" 54 54 sameText(path: string, other: ReadView): boolean; @@ -389,6 +389,27 @@
389 389 this.#movesFrom = from; 393 + * Files laid out as another view lays them out (abso Capacity): a draft's view over its base's, for every file the 394 + * draft doesn't touch. The caller knows what the draft is; `except` is asked once, when a file is first needed, for 395 + * the files the draft touches, or undefined when nothing can be shared (a draft that moves lines). Without it, an 396 + * agent's tree, files and blame laid out every file of the project again for each agent. 398 + shareFiles(from: View, except: () => ReadonlySet<string> | undefined): void { 399 + if (from.graph !== this.graph || from === this || this.#filesFrom !== undefined) return; 400 + this.#filesFrom = { from, except }; 402 + #filesFrom: { from: View; except: () => ReadonlySet<string> | undefined } | null | undefined; 403 + #filesShared: { from: View; except: ReadonlySet<string> } | null | undefined; 404 + #sharedFiles(): { from: View; except: ReadonlySet<string> } | null { 405 + if (this.#filesShared === undefined) { 406 + const share = this.#filesFrom; 407 + const except = share ? share.except() : undefined; 408 + this.#filesShared = share && except ? { from: share.from, except } : null; 410 + return this.#filesShared; 392 413 #takeShared(): void { 393 414 const from = this.#movesFrom; 394 415 if (!from) return; @@ -1104,7 +1125,9 @@
1104 1125 #file(path: string, complete = false): FileState { 1105 1126 let state = this.#files.get(path); 1106 1127 if (!state || (complete && !state.complete)) { 1107 − state = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE;
1128 + const shared = this.#filesFrom === undefined ? null : this.#sharedFiles(); 1129 + if (shared && !shared.except.has(path)) state = shared.from.#file(path, complete); 1130 + else state = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE; 1108 1131 this.#files.set(path, state); --- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -2742,7 +2742,16 @@
2742 2742 // A draft that moves nothing resolves its moves as its base does (abso Capacity): take them from the base's view. 2743 2743 if (this.#writerStorage && agent.mine.length > 0 && view instanceof View) { 2744 2744 const base = this.#viewAt(this.#spaceOf(agent), agent.base); 2745 − if (base instanceof View) view.shareMoves(base);
2745 + if (base instanceof View) { 2746 + view.shareMoves(base); 2747 + // And its layout of every file the draft doesn't touch, when the draft moves nothing (abso Capacity). 2748 + const mine = agent.mine; 2749 + view.shareFiles(base, () => 2750 + mine.some((id) => (this.#graph.atom(id).moves?.length ?? 0) > 0) 2752 + : this.#touchedFiles(mine, [base, view]), --- /dev/null
+++ b/worker/project/test/agent-views-shared.test.ts
@@ -0,0 +1,70 @@
1 + // A draft's view takes its base view's layout of every file the draft doesn't touch (abso Capacity, View.shareFiles). 2 + // On a writer-backed project every agent's view must still read every file as the in-memory project does: a draft 3 + // that edits lines moved into another file by a published move, one that deletes such a line, one that only sets an 4 + // attribute, and one that moves lines itself (which shares nothing). 6 + import assert from "node:assert/strict"; 7 + import { test } from "node:test"; 8 + import { storedArray } from "../../../src/engine/state-source.ts"; 9 + import { SqlState } from "../../../src/engine/test/storage-helper.ts"; 10 + import { MemoryStore, Project } from "../project.ts"; 11 + import type { Entry, ProjectStore } from "../project-types.ts"; 14 + const storage = new SqlState(); 15 + const entries = storedArray<Entry>(storage, "canonical-log"); 16 + const store: ProjectStore = { 18 + for (const entry of batch) entries.push(entry); 21 + return new Project(store, { writerStorage: storage }); 24 + const AREA = "export function area(r: number) {\n const pi = 3.14;\n return pi * r * r;\n}\n"; 26 + "src/shapes.ts": `// shapes\n${AREA}\nexport function other() {\n return 1;\n}\n`, 27 + "src/geometry.ts": "// geometry\n", 28 + "src/plain.ts": "one\ntwo\nthree\n", 29 + "run.sh": "echo hi\n", 30 + "README.md": "readme\n", 33 + function history(project: Project) { 35 + project.init(FILES, t); 36 + // ann moves area() into geometry.ts and publishes: its lines were written in shapes.ts. 37 + project.edit("ann", { file: "src/shapes.ts", old: AREA, new: "" }, ++t); 38 + project.edit("ann", { file: "src/geometry.ts", content: `// geometry\n${AREA}` }, ++t); 39 + assert.equal(project.publish("ann", "Move area to geometry", ++t).ok, true); 40 + for (const agent of ["bob", "cy", "dee", "eve", "fay"]) project.sync(agent); 41 + // bob edits a moved line, cy deletes one, dee touches only plain.ts, eve sets an attribute, fay moves lines. 42 + project.edit("bob", { file: "src/geometry.ts", old: "3.14", new: "Math.PI" }, ++t); 43 + project.edit("cy", { file: "src/geometry.ts", old: " const pi = 3.14;\n", new: "" }, ++t); 44 + project.record("dee", { "src/plain.ts": "one\nTWO\nthree\n" }, ++t); 45 + project.record("eve", {}, ++t, { "run.sh": { exec: true } }); 46 + project.edit("fay", { file: "src/plain.ts", old: "one\ntwo\nthree\n", new: "" }, ++t); 47 + project.edit("fay", { file: "src/moved.ts", content: "one\ntwo\nthree\n" }, ++t); 50 + const read = (project: Project, agent: string) => { 51 + const view = project.draftOf(agent)!.view; 52 + const out: Record<string, unknown> = {}; 53 + for (const path of view.paths()) out[path] = [view.text(path), view.attrs(path), view.lines(path).map((l) => l.atom)]; 57 + test("every agent's view reads every file as the in-memory project's, with files shared from the base", () => { 58 + const oracle = new Project(new MemoryStore()); 59 + const project = writer(); 62 + for (const agent of ["ann", "bob", "cy", "dee", "eve", "fay"]) { 63 + // Twice: the second read takes the shared layouts the first one made. 64 + assert.deepEqual(read(project, agent), read(oracle, agent), agent); 65 + assert.deepEqual(read(project, agent), read(oracle, agent), `${agent} again`); 67 + assert.match(String(read(oracle, "bob")["src/geometry.ts"]), /Math\.PI/); 68 + assert.doesNotMatch(String(read(oracle, "cy")["src/geometry.ts"]), /const pi/); 69 + assert.deepEqual(project.tree("", { agent: "cy", authors: true }), oracle.tree("", { agent: "cy", authors: true }));