{"version":252,"agent":"capacity","message":"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).\n\n- 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.\n- 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.\n- 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.\n- 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.\n- 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.\n\nOn 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.\n\nTests: 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).","time":1792089011644,"timeIso":"2026-10-15T18:30:11.644Z","changes":15,"change":3926,"files":["src/engine/view.ts","worker/project/blame.ts","worker/project/history.ts","worker/project/pathindex.ts","worker/project/project.ts","worker/project/spaces.ts","worker/project/test/author-totals.test.ts"],"draft":null,"diff":[{"path":"src/engine/view.ts","added":12,"removed":0,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -898,6 +898,18 @@\n \n \t/** Files with at least one visible line, sorted. */\n \tpaths(): string[] {\n+\t\t// Without walking every file the graph has ever had (abso Capacity): a draft's view over its base's has the base's\n+\t\t// files, with the ones its draft touches checked here; a published version's are kept (knowPaths).\n+\t\tconst shared = this.#filesFrom === undefined ? null : this.#sharedFiles();\n+\t\tif (shared) {\n+\t\t\tconst out = shared.from.paths().filter((p) => !shared.except.has(p));\n+\t\t\tfor (const p of shared.except) if (this.hasFile(p)) out.push(p);\n+\t\t\treturn out.sort();\n+\t\t}\n+\t\tif (this.#pathsFrom !== undefined) {\n+\t\t\tif (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null;\n+\t\t\tif (this.#knownPaths) return [...this.#knownPaths].sort();\n+\t\t}\n \t\tif (this.#stable) {\n \t\t\tconst paths: string[] = [];\n \t\t\tfor (const path of this.graph.knownFiles()) {"},{"path":"worker/project/blame.ts","added":10,"removed":0,"diff":"--- a/worker/project/blame.ts\n+++ b/worker/project/blame.ts\n@@ -411,12 +411,22 @@\n \tlet files = 0;\n \tlet total = 0;\n \tlet stored: string | undefined;\n+\t// Each file's lines by author as kept when versions land (abso Capacity, version-files.ts), where they answer.\n+\tconst totalsOf = project.authorTotalsFor({ version, ...where });\n \tfor (const path of view.paths()) {\n \t\tconst parts = path.split(\"/\");\n \t\tif (want.length > 0 && (parts.length <= want.length || pathKey(parts.slice(0, want.length).join(\"/\")) !== key))\n \t\t\tcontinue;\n \t\tstored ??= parts.slice(0, want.length).join(\"/\");\n \t\tfiles++;\n+\t\tconst totals = totalsOf?.(path);\n+\t\tif (totals) {\n+\t\t\tfor (const [author, n] of totals.authors) {\n+\t\t\t\tcounts.set(author, (counts.get(author) ?? 0) + n);\n+\t\t\t\ttotal += n;\n+\t\t\t}\n+\t\t\tcontinue;\n+\t\t}\n \t\tfor (const l of view.lines(path)) {\n \t\t\tconst author = authorOf(l.atom);\n \t\t\tcounts.set(author, (counts.get(author) ?? 0) + 1);"},{"path":"worker/project/history.ts","added":14,"removed":1,"diff":"--- a/worker/project/history.ts\n+++ b/worker/project/history.ts\n@@ -28,6 +28,15 @@\n \t\tversion: number,\n \t\tagent?: { readonly name: string; readonly space: string; readonly base: number },\n \t): ((path: string) => FileTotals | undefined) | undefined;\n+\t/**\n+\t * The files an agent's draft can make differ from its base (collisions.ts, touchedBeyond): every other file is the\n+\t * same in both. Undefined when that isn't known (a draft that moves lines): compare every file.\n+\t */\n+\tagentTouched?(agent: {\n+\t\treadonly name: string;\n+\t\treadonly space: string;\n+\t\treadonly base: number;\n+\t}): ReadonlySet<string> | undefined;\n \tagentView(agent: { readonly name: string; readonly space: string; readonly base: number }): ReadView;\n \tspellingIn(view: ReadView, asked: string): string;\n \tpathsOf(space: Space): Map<string, PathLifeRecord>;\n@@ -143,13 +152,17 @@\n \t};\n \t// Each file's lines by author and size kept as versions land (abso Capacity), for the files it can answer.\n \tconst totalsOf = options.authors ? h.authorTotals?.(space, version, agent) : undefined;\n+\t// Only a file the draft touches can differ from its base (abso Capacity): comparing every file laid each out in both\n+\t// views, 13 s of an agent's tree on abso.\n+\tconst touchedByDraft = agent ? h.agentTouched?.(agent) : undefined;\n \tfor (const path of paths) {\n \t\tconst e = entryOf(path);\n \t\tif (!e) continue;\n \t\te.files++;\n \t\tconst v = lastOf(path);\n \t\tif (v !== undefined && (e.last === undefined || v > e.last)) e.last = v;\n-\t\tif (agent && differs(base, view, path)) e.changed = true;\n+\t\tif (agent && (touchedByDraft === undefined || touchedByDraft.has(path)) && differs(base, view, path))\n+\t\t\te.changed = true;\n \t\tif (options.authors) {\n \t\t\tconst counts = (e.authors ??= new Map());\n \t\t\tconst blob = view.attrs(path).blob;"},{"path":"worker/project/pathindex.ts","added":38,"removed":1,"diff":"--- a/worker/project/pathindex.ts\n+++ b/worker/project/pathindex.ts\n@@ -23,6 +23,9 @@\n \treadonly shapes: ProjectOptions[\"shapes\"];\n }\n \n+/** Older versions' file lists kept per space (a few agents' bases): about 1,000 paths each on abso. */\n+const OLDER_PATH_SETS = 8;\n+\n export class PathIndex {\n \treadonly #deps: PathIndexDeps;\n \n@@ -43,8 +46,41 @@\n \n \t/** The files at the newest version folded so far from kept shapes, per space (keptPaths). */\n \treadonly #keptPaths = new WeakMap<Space, { version: number; files: Set<string> }>();\n+\t/** The files at a few older versions, worked back from the newest (agents' bases, mostly), most recent last. */\n+\treadonly #olderPaths = new WeakMap<Space, Map<number, Set<string>>>();\n \n \t/**\n+\t * The files at a version older than the newest folded (abso Capacity): the newest's files with each version since\n+\t * undone, its made files taken out and its gone ones put back. Folding from version 0 again for an agent's base\n+\t * read every version's kept row on each call.\n+\t */\n+\t#olderPathSet(\n+\t\tspace: Space,\n+\t\tfold: { version: number; files: Set<string> },\n+\t\tversion: number,\n+\t): ReadonlySet<string> | undefined {\n+\t\tlet older = this.#olderPaths.get(space);\n+\t\tif (!older) this.#olderPaths.set(space, (older = new Map()));\n+\t\tconst known = older.get(version);\n+\t\tif (known) {\n+\t\t\tolder.delete(version);\n+\t\t\tolder.set(version, known);\n+\t\t\treturn known;\n+\t\t}\n+\t\tconst files = new Set(fold.files);\n+\t\tfor (let v = fold.version; v > version; v--) {\n+\t\t\tif (!this.#keptFiles(space, v)) return undefined;\n+\t\t\tconst shape = this.#shapeCache.get(space)?.get(v);\n+\t\t\tif (!shape) return undefined;\n+\t\t\tfor (const f of shape.made) files.delete(f);\n+\t\t\tfor (const f of shape.gone) files.add(f);\n+\t\t}\n+\t\tolder.set(version, files);\n+\t\tif (older.size > OLDER_PATH_SETS) older.delete(older.keys().next().value!);\n+\t\treturn files;\n+\t}\n+\n+\t/**\n \t * The files a space has at a version, from the kept rows of every version up to it: each one's files made and\n \t * taken out, folded from version 0 (abso Capacity). Undefined when a version has no kept row that describes it;\n \t * then the caller lays the version out.\n@@ -58,7 +94,8 @@\n \tkeptPathSet(space: Space, version: number): ReadonlySet<string> | undefined {\n \t\tlet fold = this.#keptPaths.get(space);\n \t\tif (fold?.version === version) return fold.files;\n-\t\tif (!fold || fold.version > version) fold = { version: -1, files: new Set() };\n+\t\tif (fold && fold.version > version) return this.#olderPathSet(space, fold, version);\n+\t\tif (!fold) fold = { version: -1, files: new Set() };\n \t\tconst files = new Set(fold.files);\n \t\tfor (let v = fold.version + 1; v <= version; v++) {\n \t\t\tif (!this.#keptFiles(space, v)) return undefined;"},{"path":"worker/project/project.ts","added":30,"removed":3,"diff":"--- a/worker/project/project.ts\n+++ b/worker/project/project.ts\n@@ -1794,6 +1794,7 @@\n \t\t\tviewAt: (space, version) => this.#viewAt(space, version),\n \t\t\tkeptPaths: (space, version) => this.#keptPaths(space, version),\n \t\t\tauthorTotals: (space, version, agent) => this.#authorTotals(space, version, agent as AgentState | undefined),\n+\t\t\tagentTouched: (agent) => this.#agentTouched(agent as AgentState),\n \t\t\tagentView: (agent) => this.#agentView(agent as AgentState),\n \t\t\tspellingIn: (view, asked) => this.spellingIn(view, asked),\n \t\t\tpathsOf: (space) => this.#paths.pathsOf(space),\n@@ -1821,13 +1822,39 @@\n \t): ((path: string) => FileTotals | undefined) | undefined {\n \t\tconst storage = this.#writerStorage;\n \t\tif (!storage || space.name !== SHARED || authoredVersion(storage) === undefined) return undefined;\n-\t\tif (!agent || agent.mine.length === 0) return (path) => authorTotalsAt(storage, path, version);\n-\t\tconst base = this.#viewAt(space, version);\n-\t\tconst except = touchedBeyond(this.#graph, base.set, agent.mine, [base, this.#agentView(agent)]);\n+\t\tif (!agent) return (path) => authorTotalsAt(storage, path, version);\n+\t\tconst except = this.#agentTouched(agent);\n \t\tif (!except) return undefined;\n \t\treturn (path) => (except.has(path) ? undefined : authorTotalsAt(storage, path, version));\n \t}\n \n+\t/**\n+\t * The files an agent's draft, and whatever it depends on beyond its base, can make differ from its base\n+\t * (touchedBeyond); every other file is the same in both. Undefined when the draft moves lines.\n+\t */\n+\t#agentTouched(agent: AgentState): ReadonlySet<string> | undefined {\n+\t\tif (agent.mine.length === 0) return new Set();\n+\t\tconst base = this.#viewAt(this.#spaceOf(agent), agent.base);\n+\t\treturn touchedBeyond(this.#graph, base.set, agent.mine, [base, this.#agentView(agent)]);\n+\t}\n+\n+\t/**\n+\t * Kept author totals for a folder's blame (blame.ts), where blame reads: shared at a version (the newest by default) or\n+\t * an agent's view. A named draft has none. Undefined when none are kept.\n+\t */\n+\tauthorTotalsFor(where: {\n+\t\tversion?: number;\n+\t\tdraft?: string;\n+\t\tagent?: string;\n+\t}): ((path: string) => FileTotals | undefined) | undefined {\n+\t\tif (where.draft !== undefined) return undefined;\n+\t\tif (where.agent !== undefined) {\n+\t\t\tconst agent = this.#agents.get(where.agent);\n+\t\t\treturn agent ? this.#authorTotals(this.#spaceOf(agent), agent.base, agent) : undefined;\n+\t\t}\n+\t\treturn this.#authorTotals(this.#shared, where.version ?? last(this.#shared));\n+\t}\n+\n \t/** One folder at a version (history.ts). */\n \ttree(...args: Tail<Parameters<typeof historyTree>>): ReturnType<typeof historyTree> {\n \t\treturn historyTree(this.#history, ...args);"},{"path":"worker/project/spaces.ts","added":15,"removed":5,"diff":"--- a/worker/project/spaces.ts\n+++ b/worker/project/spaces.ts\n@@ -416,14 +416,24 @@\n \t\t\tthis.spaces = new Map([[SHARED, newSpace(SHARED)]]);\n \t\t\treturn;\n \t\t}\n+\t\t// The same space for the same stored row (abso Capacity): a space reads everything else through to storage, and\n+\t\t// each read decoding a new one emptied every cache kept by space (a path index, a version's files, its file list)\n+\t\t// on every call, so an agent's tree read all 1,225 of abso's kept version rows each time.\n+\t\tconst decoded = new Map<string, Space>();\n \t\tthis.spaces = new StoredMap(storage, \"membership:spaces\", {\n \t\t\tencode: (space) => ({ name: space.name, startedAt: space.startedAt }),\n \t\t\tdecode: (value) => {\n-\t\t\t\tconst meta = value as { name: string; startedAt?: number };\n-\t\t\t\treturn {\n-\t\t\t\t\t...newSpace(meta.name, storage),\n-\t\t\t\t\t...(meta.startedAt === undefined ? {} : { startedAt: meta.startedAt }),\n-\t\t\t\t};\n+\t\t\t\tconst raw = JSON.stringify(value);\n+\t\t\t\tlet space = decoded.get(raw);\n+\t\t\t\tif (!space) {\n+\t\t\t\t\tconst meta = value as { name: string; startedAt?: number };\n+\t\t\t\t\tspace = {\n+\t\t\t\t\t\t...newSpace(meta.name, storage),\n+\t\t\t\t\t\t...(meta.startedAt === undefined ? {} : { startedAt: meta.startedAt }),\n+\t\t\t\t\t};\n+\t\t\t\t\tdecoded.set(raw, space);\n+\t\t\t\t}\n+\t\t\t\treturn space;\n \t\t\t},\n \t\t});\n \t\tif (!this.spaces.has(SHARED)) storage.transaction(() => this.spaces.set(SHARED, newSpace(SHARED, storage)));"},{"path":"worker/project/test/author-totals.test.ts","added":21,"removed":8,"diff":"--- a/worker/project/test/author-totals.test.ts\n+++ b/worker/project/test/author-totals.test.ts\n@@ -8,6 +8,7 @@\n import { test } from \"node:test\";\n import { storedArray } from \"../../../src/engine/state-source.ts\";\n import { SqlState } from \"../../../src/engine/test/storage-helper.ts\";\n+import { folderBlame } from \"../blame.ts\";\n import { MemoryStore, Project } from \"../project.ts\";\n import type { Entry, ProjectStore } from \"../project-types.ts\";\n import { authoredVersion } from \"../version-files.ts\";\n@@ -70,19 +71,28 @@\n const trees = (project: Project) => {\n \tconst out: Record<string, unknown> = {};\n \tconst last = project.log().versions[0]!.version;\n+\tconst ask = (key: string, f: () => unknown) => {\n+\t\ttry {\n+\t\t\tout[key] = f();\n+\t\t} catch (e) {\n+\t\t\tout[key] = String(e);\n+\t\t}\n+\t};\n \tfor (let v = 0; v <= last; v++)\n-\t\tfor (const folder of [\"\", \"src\"])\n-\t\t\ttry {\n-\t\t\t\tout[`${v} ${folder}`] = project.tree(folder, { version: v, authors: true });\n-\t\t\t} catch (e) {\n-\t\t\t\tout[`${v} ${folder}`] = String(e);\n-\t\t\t}\n+\t\tfor (const folder of [\"\", \"src\"]) {\n+\t\t\task(`${v} ${folder}`, () => project.tree(folder, { version: v, authors: true }));\n+\t\t\task(`blame ${v} ${folder}`, () => folderBlame(project, folder, v));\n+\t\t}\n \tfor (const agent of AGENTS)\n-\t\tfor (const folder of [\"\", \"src\"]) out[`${agent} ${folder}`] = project.tree(folder, { agent, authors: true });\n+\t\tfor (const folder of [\"\", \"src\"]) {\n+\t\t\task(`${agent} ${folder}`, () => project.tree(folder, { agent, authors: true }));\n+\t\t\task(`blame ${agent} ${folder}`, () => folderBlame(project, folder, undefined, { agent }));\n+\t\t}\n+\task(\"blame newest\", () => folderBlame(project, \"\"));\n \treturn out;\n };\n \n-test(\"tree with authors from kept totals matches the in-memory project at every version and in every draft\", () => {\n+test(\"tree with authors and folder blame from kept totals match the in-memory project at every version and in every draft\", () => {\n \tconst oracle = new Project(new MemoryStore(), { hasBlob: () => true });\n \tconst { storage, project } = writer();\n \thistory(oracle);\n@@ -101,6 +111,9 @@\n \t\t{ agent: \"bob\", lines: 1 },\n \t]);\n \tassert.ok(JSON.stringify(expected).includes('\"agent\":\"cy\"'));\n+\t// Folder blame answered, not refused, at the newest version and in agents' views.\n+\tfor (const key of [\"blame newest\", \"blame 3 src\", \"blame eve \", \"blame fay src\"])\n+\t\tassert.ok((expected[key] as { lines?: number }).lines! > 0, `${key}: ${JSON.stringify(expected[key])}`);\n \tassert.equal(\n \t\t(expected[\"0 \"] as { entries: { name: string; blobs?: string[] }[] }).entries.find((e) => e.name === \"logo.png\")!\n \t\t\t.blobs![0],"}],"ci":null}