Folder blame from author totals; an agent's tree compares only its draft's files; file lists without a full walk; one space object per stored row (abso Capacity, issue 664). Version 252 of shared· capacity· Oct 15 (2026-10-15 18:30 UTC) · Not checked
Folder blame counts each file's kept author totals where they answer (Project.authorTotalsFor: shared at a version, or an agent's view for the files its draft doesn't touch), and lays out the rest as before. An agent's tree marked a file changed by comparing it in both views, which laid every file out twice (13 s of 14.6 s on abso). Only a file the draft touches can differ from its base (touchedBeyond, as the view's layout sharing uses), so only those are compared; a draft that moves lines compares every file as before. View.paths: a draft's view over its base's takes the base's file list and checks only the files its draft touches; a published version's view answers from its kept file list. Both walked every file the graph ever had. PathIndex.keptPathSet works an older version's file list back from the newest one (undoing each version's made and gone files), and keeps a few, instead of folding from version 0 again for every agent's base. Membership's stored spaces decode to the same object for the same stored row. A space reads everything else through to storage; a new object on every read emptied every cache kept by space (the path index, versions' files and shapes, the kept file lists) on every call. On a fresh abso adoption (my machine): an agent's tree with authors 582 ms first and 762 ms again (12.5 s and 0.6 to 1.5 s before); folder blame for an agent 404 ms and 248 ms (1.8 s and 2.0 s); tree with authors at 1224 again 19 ms. A full run matches 33 of 33 answers; held heap at most 40.2 MB.
Tests: author-totals now also compares folder blame at every version and in every agent's view, against the in-memory project. All of worker/project/test: 349 of 349 pass (one skipped).
Version 251 · Files at version 252
7 files, 140 lines added, 18 removed.
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -898,6 +898,18 @@
899 899 /** Files with at least one visible line, sorted. */ 900 900 paths(): string[] { 901 + // Without walking every file the graph has ever had (abso Capacity): a draft's view over its base's has the base's 902 + // files, with the ones its draft touches checked here; a published version's are kept (knowPaths). 903 + const shared = this.#filesFrom === undefined ? null : this.#sharedFiles(); 905 + const out = shared.from.paths().filter((p) => !shared.except.has(p)); 906 + for (const p of shared.except) if (this.hasFile(p)) out.push(p); 909 + if (this.#pathsFrom !== undefined) { 910 + if (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null; 911 + if (this.#knownPaths) return [...this.#knownPaths].sort(); 901 913 if (this.#stable) { 902 914 const paths: string[] = []; 903 915 for (const path of this.graph.knownFiles()) { --- a/worker/project/blame.ts
+++ b/worker/project/blame.ts
@@ -411,12 +411,22 @@
413 413 let stored: string | undefined; 414 + // Each file's lines by author as kept when versions land (abso Capacity, version-files.ts), where they answer. 415 + const totalsOf = project.authorTotalsFor({ version, ...where }); 414 416 for (const path of view.paths()) { 415 417 const parts = path.split("/"); 416 418 if (want.length > 0 && (parts.length <= want.length || pathKey(parts.slice(0, want.length).join("/")) !== key)) 418 420 stored ??= parts.slice(0, want.length).join("/"); 422 + const totals = totalsOf?.(path); 424 + for (const [author, n] of totals.authors) { 425 + counts.set(author, (counts.get(author) ?? 0) + n); 420 430 for (const l of view.lines(path)) { 421 431 const author = authorOf(l.atom); 422 432 counts.set(author, (counts.get(author) ?? 0) + 1); --- a/worker/project/history.ts
+++ b/worker/project/history.ts
@@ -28,6 +28,15 @@
29 29 agent?: { readonly name: string; readonly space: string; readonly base: number }, 30 30 ): ((path: string) => FileTotals | undefined) | undefined; 32 + * The files an agent's draft can make differ from its base (collisions.ts, touchedBeyond): every other file is the 33 + * same in both. Undefined when that isn't known (a draft that moves lines): compare every file. 35 + agentTouched?(agent: { 36 + readonly name: string; 37 + readonly space: string; 38 + readonly base: number; 39 + }): ReadonlySet<string> | undefined; 31 40 agentView(agent: { readonly name: string; readonly space: string; readonly base: number }): ReadView; 32 41 spellingIn(view: ReadView, asked: string): string; 33 42 pathsOf(space: Space): Map<string, PathLifeRecord>; @@ -143,13 +152,17 @@
144 153 // Each file's lines by author and size kept as versions land (abso Capacity), for the files it can answer. 145 154 const totalsOf = options.authors ? h.authorTotals?.(space, version, agent) : undefined; 155 + // Only a file the draft touches can differ from its base (abso Capacity): comparing every file laid each out in both 156 + // views, 13 s of an agent's tree on abso. 157 + const touchedByDraft = agent ? h.agentTouched?.(agent) : undefined; 146 158 for (const path of paths) { 147 159 const e = entryOf(path); 150 162 const v = lastOf(path); 151 163 if (v !== undefined && (e.last === undefined || v > e.last)) e.last = v; 152 − if (agent && differs(base, view, path)) e.changed = true;
164 + if (agent && (touchedByDraft === undefined || touchedByDraft.has(path)) && differs(base, view, path)) 153 166 if (options.authors) { 154 167 const counts = (e.authors ??= new Map()); 155 168 const blob = view.attrs(path).blob; --- a/worker/project/pathindex.ts
+++ b/worker/project/pathindex.ts
@@ -23,6 +23,9 @@
23 23 readonly shapes: ProjectOptions["shapes"]; 26 + /** Older versions' file lists kept per space (a few agents' bases): about 1,000 paths each on abso. */ 27 + const OLDER_PATH_SETS = 8; 26 29 export class PathIndex { 27 30 readonly #deps: PathIndexDeps; @@ -43,8 +46,41 @@
44 47 /** The files at the newest version folded so far from kept shapes, per space (keptPaths). */ 45 48 readonly #keptPaths = new WeakMap<Space, { version: number; files: Set<string> }>(); 49 + /** The files at a few older versions, worked back from the newest (agents' bases, mostly), most recent last. */ 50 + readonly #olderPaths = new WeakMap<Space, Map<number, Set<string>>>(); 53 + * The files at a version older than the newest folded (abso Capacity): the newest's files with each version since 54 + * undone, its made files taken out and its gone ones put back. Folding from version 0 again for an agent's base 55 + * read every version's kept row on each call. 59 + fold: { version: number; files: Set<string> }, 61 + ): ReadonlySet<string> | undefined { 62 + let older = this.#olderPaths.get(space); 63 + if (!older) this.#olderPaths.set(space, (older = new Map())); 64 + const known = older.get(version); 66 + older.delete(version); 67 + older.set(version, known); 70 + const files = new Set(fold.files); 71 + for (let v = fold.version; v > version; v--) { 72 + if (!this.#keptFiles(space, v)) return undefined; 73 + const shape = this.#shapeCache.get(space)?.get(v); 74 + if (!shape) return undefined; 75 + for (const f of shape.made) files.delete(f); 76 + for (const f of shape.gone) files.add(f); 78 + older.set(version, files); 79 + if (older.size > OLDER_PATH_SETS) older.delete(older.keys().next().value!); 48 84 * The files a space has at a version, from the kept rows of every version up to it: each one's files made and 49 85 * taken out, folded from version 0 (abso Capacity). Undefined when a version has no kept row that describes it; 50 86 * then the caller lays the version out. @@ -58,7 +94,8 @@
58 94 keptPathSet(space: Space, version: number): ReadonlySet<string> | undefined { 59 95 let fold = this.#keptPaths.get(space); 60 96 if (fold?.version === version) return fold.files; 61 − if (!fold || fold.version > version) fold = { version: -1, files: new Set() };
97 + if (fold && fold.version > version) return this.#olderPathSet(space, fold, version); 98 + if (!fold) fold = { version: -1, files: new Set() }; 62 99 const files = new Set(fold.files); 63 100 for (let v = fold.version + 1; v <= version; v++) { 64 101 if (!this.#keptFiles(space, v)) return undefined; --- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -1794,6 +1794,7 @@
1794 1794 viewAt: (space, version) => this.#viewAt(space, version), 1795 1795 keptPaths: (space, version) => this.#keptPaths(space, version), 1796 1796 authorTotals: (space, version, agent) => this.#authorTotals(space, version, agent as AgentState | undefined), 1797 + agentTouched: (agent) => this.#agentTouched(agent as AgentState), 1797 1798 agentView: (agent) => this.#agentView(agent as AgentState), 1798 1799 spellingIn: (view, asked) => this.spellingIn(view, asked), 1799 1800 pathsOf: (space) => this.#paths.pathsOf(space), @@ -1821,13 +1822,39 @@
1821 1822 ): ((path: string) => FileTotals | undefined) | undefined { 1822 1823 const storage = this.#writerStorage; 1823 1824 if (!storage || space.name !== SHARED || authoredVersion(storage) === undefined) return undefined; 1824 − if (!agent || agent.mine.length === 0) return (path) => authorTotalsAt(storage, path, version);
1825 − const base = this.#viewAt(space, version);
1826 − const except = touchedBeyond(this.#graph, base.set, agent.mine, [base, this.#agentView(agent)]);
1825 + if (!agent) return (path) => authorTotalsAt(storage, path, version); 1826 + const except = this.#agentTouched(agent); 1827 1827 if (!except) return undefined; 1828 1828 return (path) => (except.has(path) ? undefined : authorTotalsAt(storage, path, version)); 1832 + * The files an agent's draft, and whatever it depends on beyond its base, can make differ from its base 1833 + * (touchedBeyond); every other file is the same in both. Undefined when the draft moves lines. 1835 + #agentTouched(agent: AgentState): ReadonlySet<string> | undefined { 1836 + if (agent.mine.length === 0) return new Set(); 1837 + const base = this.#viewAt(this.#spaceOf(agent), agent.base); 1838 + return touchedBeyond(this.#graph, base.set, agent.mine, [base, this.#agentView(agent)]); 1842 + * Kept author totals for a folder's blame (blame.ts), where blame reads: shared at a version (the newest by default) or 1843 + * an agent's view. A named draft has none. Undefined when none are kept. 1845 + authorTotalsFor(where: { 1849 + }): ((path: string) => FileTotals | undefined) | undefined { 1850 + if (where.draft !== undefined) return undefined; 1851 + if (where.agent !== undefined) { 1852 + const agent = this.#agents.get(where.agent); 1853 + return agent ? this.#authorTotals(this.#spaceOf(agent), agent.base, agent) : undefined; 1855 + return this.#authorTotals(this.#shared, where.version ?? last(this.#shared)); 1831 1858 /** One folder at a version (history.ts). */ 1832 1859 tree(...args: Tail<Parameters<typeof historyTree>>): ReturnType<typeof historyTree> { 1833 1860 return historyTree(this.#history, ...args); --- a/worker/project/spaces.ts
+++ b/worker/project/spaces.ts
@@ -416,14 +416,24 @@
416 416 this.spaces = new Map([[SHARED, newSpace(SHARED)]]); 419 + // The same space for the same stored row (abso Capacity): a space reads everything else through to storage, and 420 + // each read decoding a new one emptied every cache kept by space (a path index, a version's files, its file list) 421 + // on every call, so an agent's tree read all 1,225 of abso's kept version rows each time. 422 + const decoded = new Map<string, Space>(); 419 423 this.spaces = new StoredMap(storage, "membership:spaces", { 420 424 encode: (space) => ({ name: space.name, startedAt: space.startedAt }), 421 425 decode: (value) => { 422 − const meta = value as { name: string; startedAt?: number };
423 − return {
424 − ...newSpace(meta.name, storage),
425 − ...(meta.startedAt === undefined ? {} : { startedAt: meta.startedAt }),
426 − };
426 + const raw = JSON.stringify(value); 427 + let space = decoded.get(raw); 429 + const meta = value as { name: string; startedAt?: number }; 431 + ...newSpace(meta.name, storage), 432 + ...(meta.startedAt === undefined ? {} : { startedAt: meta.startedAt }), 434 + decoded.set(raw, space); 429 439 if (!this.spaces.has(SHARED)) storage.transaction(() => this.spaces.set(SHARED, newSpace(SHARED, storage))); --- a/worker/project/test/author-totals.test.ts
+++ b/worker/project/test/author-totals.test.ts
@@ -8,6 +8,7 @@
8 8 import { test } from "node:test"; 9 9 import { storedArray } from "../../../src/engine/state-source.ts"; 10 10 import { SqlState } from "../../../src/engine/test/storage-helper.ts"; 11 + import { folderBlame } from "../blame.ts"; 11 12 import { MemoryStore, Project } from "../project.ts"; 12 13 import type { Entry, ProjectStore } from "../project-types.ts"; 13 14 import { authoredVersion } from "../version-files.ts"; @@ -70,19 +71,28 @@
70 71 const trees = (project: Project) => { 71 72 const out: Record<string, unknown> = {}; 72 73 const last = project.log().versions[0]!.version; 74 + const ask = (key: string, f: () => unknown) => { 78 + out[key] = String(e); 73 81 for (let v = 0; v <= last; v++) 74 − for (const folder of ["", "src"])
75 − try {
76 − out[`${v} ${folder}`] = project.tree(folder, { version: v, authors: true });
77 − } catch (e) {
78 − out[`${v} ${folder}`] = String(e);
79 − }
82 + for (const folder of ["", "src"]) { 83 + ask(`${v} ${folder}`, () => project.tree(folder, { version: v, authors: true })); 84 + ask(`blame ${v} ${folder}`, () => folderBlame(project, folder, v)); 80 86 for (const agent of AGENTS) 81 − for (const folder of ["", "src"]) out[`${agent} ${folder}`] = project.tree(folder, { agent, authors: true });
87 + for (const folder of ["", "src"]) { 88 + ask(`${agent} ${folder}`, () => project.tree(folder, { agent, authors: true })); 89 + ask(`blame ${agent} ${folder}`, () => folderBlame(project, folder, undefined, { agent })); 91 + ask("blame newest", () => folderBlame(project, "")); 85 − test("tree with authors from kept totals matches the in-memory project at every version and in every draft", () => {
95 + test("tree with authors and folder blame from kept totals match the in-memory project at every version and in every draft", () => { 86 96 const oracle = new Project(new MemoryStore(), { hasBlob: () => true }); 87 97 const { storage, project } = writer(); @@ -101,6 +111,9 @@
101 111 { agent: "bob", lines: 1 }, 103 113 assert.ok(JSON.stringify(expected).includes('"agent":"cy"')); 114 + // Folder blame answered, not refused, at the newest version and in agents' views. 115 + for (const key of ["blame newest", "blame 3 src", "blame eve ", "blame fay src"]) 116 + assert.ok((expected[key] as { lines?: number }).lines! > 0, `${key}: ${JSON.stringify(expected[key])}`); 105 118 (expected["0 "] as { entries: { name: string; blobs?: string[] }[] }).entries.find((e) => e.name === "logo.png")!