Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
show on this site's /mcp
CLI
abso show 252 --json
JSON
/christopher/abso-core/versions/252?format=json

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).

of shared·capacity··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 @@
898898
899899 /** Files with at least one visible line, sorted. */
900900 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();
904+ if (shared) {
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);
907+ return out.sort();
908+ }
909+ if (this.#pathsFrom !== undefined) {
910+ if (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null;
911+ if (this.#knownPaths) return [...this.#knownPaths].sort();
912+ }
901913 if (this.#stable) {
902914 const paths: string[] = [];
903915 for (const path of this.graph.knownFiles()) {
--- a/worker/project/blame.ts
+++ b/worker/project/blame.ts
@@ -411,12 +411,22 @@
411411 let files = 0;
412412 let total = 0;
413413 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 });
414416 for (const path of view.paths()) {
415417 const parts = path.split("/");
416418 if (want.length > 0 && (parts.length <= want.length || pathKey(parts.slice(0, want.length).join("/")) !== key))
417419 continue;
418420 stored ??= parts.slice(0, want.length).join("/");
419421 files++;
422+ const totals = totalsOf?.(path);
423+ if (totals) {
424+ for (const [author, n] of totals.authors) {
425+ counts.set(author, (counts.get(author) ?? 0) + n);
426+ total += n;
427+ }
428+ continue;
429+ }
420430 for (const l of view.lines(path)) {
421431 const author = authorOf(l.atom);
422432 counts.set(author, (counts.get(author) ?? 0) + 1);
--- a/worker/project/history.ts
+++ b/worker/project/history.ts
@@ -28,6 +28,15 @@
2828 version: number,
2929 agent?: { readonly name: string; readonly space: string; readonly base: number },
3030 ): ((path: string) => FileTotals | undefined) | undefined;
31+ /**
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.
34+ */
35+ agentTouched?(agent: {
36+ readonly name: string;
37+ readonly space: string;
38+ readonly base: number;
39+ }): ReadonlySet<string> | undefined;
3140 agentView(agent: { readonly name: string; readonly space: string; readonly base: number }): ReadView;
3241 spellingIn(view: ReadView, asked: string): string;
3342 pathsOf(space: Space): Map<string, PathLifeRecord>;
@@ -143,13 +152,17 @@
143152 };
144153 // Each file's lines by author and size kept as versions land (abso Capacity), for the files it can answer.
145154 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;
146158 for (const path of paths) {
147159 const e = entryOf(path);
148160 if (!e) continue;
149161 e.files++;
150162 const v = lastOf(path);
151163 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))
165+ e.changed = true;
153166 if (options.authors) {
154167 const counts = (e.authors ??= new Map());
155168 const blob = view.attrs(path).blob;
--- a/worker/project/pathindex.ts
+++ b/worker/project/pathindex.ts
@@ -23,6 +23,9 @@
2323 readonly shapes: ProjectOptions["shapes"];
2424}
2525
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;
2629export class PathIndex {
2730 readonly #deps: PathIndexDeps;
2831
@@ -43,8 +46,41 @@
4346
4447 /** The files at the newest version folded so far from kept shapes, per space (keptPaths). */
4548 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>>>();
4651
4752 /**
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.
56+ */
57+ #olderPathSet(
58+ space: Space,
59+ fold: { version: number; files: Set<string> },
60+ version: number,
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);
65+ if (known) {
66+ older.delete(version);
67+ older.set(version, known);
68+ return known;
69+ }
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);
77+ }
78+ older.set(version, files);
79+ if (older.size > OLDER_PATH_SETS) older.delete(older.keys().next().value!);
80+ return files;
81+ }
83+ /**
4884 * The files a space has at a version, from the kept rows of every version up to it: each one's files made and
4985 * taken out, folded from version 0 (abso Capacity). Undefined when a version has no kept row that describes it;
5086 * then the caller lays the version out.
@@ -58,7 +94,8 @@
5894 keptPathSet(space: Space, version: number): ReadonlySet<string> | undefined {
5995 let fold = this.#keptPaths.get(space);
6096 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() };
6299 const files = new Set(fold.files);
63100 for (let v = fold.version + 1; v <= version; v++) {
64101 if (!this.#keptFiles(space, v)) return undefined;
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -1794,6 +1794,7 @@
17941794 viewAt: (space, version) => this.#viewAt(space, version),
17951795 keptPaths: (space, version) => this.#keptPaths(space, version),
17961796 authorTotals: (space, version, agent) => this.#authorTotals(space, version, agent as AgentState | undefined),
1797+ agentTouched: (agent) => this.#agentTouched(agent as AgentState),
17971798 agentView: (agent) => this.#agentView(agent as AgentState),
17981799 spellingIn: (view, asked) => this.spellingIn(view, asked),
17991800 pathsOf: (space) => this.#paths.pathsOf(space),
@@ -1821,13 +1822,39 @@
18211822 ): ((path: string) => FileTotals | undefined) | undefined {
18221823 const storage = this.#writerStorage;
18231824 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);
18271827 if (!except) return undefined;
18281828 return (path) => (except.has(path) ? undefined : authorTotalsAt(storage, path, version));
18291829 }
18301830
1831+ /**
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.
1834+ */
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)]);
1839+ }
1841+ /**
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.
1844+ */
1845+ authorTotalsFor(where: {
1846+ version?: number;
1847+ draft?: string;
1848+ agent?: string;
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;
1854+ }
1855+ return this.#authorTotals(this.#shared, where.version ?? last(this.#shared));
1856+ }
18311858 /** One folder at a version (history.ts). */
18321859 tree(...args: Tail<Parameters<typeof historyTree>>): ReturnType<typeof historyTree> {
18331860 return historyTree(this.#history, ...args);
--- a/worker/project/spaces.ts
+++ b/worker/project/spaces.ts
@@ -416,14 +416,24 @@
416416 this.spaces = new Map([[SHARED, newSpace(SHARED)]]);
417417 return;
418418 }
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>();
419423 this.spaces = new StoredMap(storage, "membership:spaces", {
420424 encode: (space) => ({ name: space.name, startedAt: space.startedAt }),
421425 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);
428+ if (!space) {
429+ const meta = value as { name: string; startedAt?: number };
430+ space = {
431+ ...newSpace(meta.name, storage),
432+ ...(meta.startedAt === undefined ? {} : { startedAt: meta.startedAt }),
433+ };
434+ decoded.set(raw, space);
435+ }
436+ return space;
427437 },
428438 });
429439 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 @@
88import { test } from "node:test";
99import { storedArray } from "../../../src/engine/state-source.ts";
1010import { SqlState } from "../../../src/engine/test/storage-helper.ts";
11+import { folderBlame } from "../blame.ts";
1112import { MemoryStore, Project } from "../project.ts";
1213import type { Entry, ProjectStore } from "../project-types.ts";
1314import { authoredVersion } from "../version-files.ts";
@@ -70,19 +71,28 @@
7071const trees = (project: Project) => {
7172 const out: Record<string, unknown> = {};
7273 const last = project.log().versions[0]!.version;
74+ const ask = (key: string, f: () => unknown) => {
75+ try {
76+ out[key] = f();
77+ } catch (e) {
78+ out[key] = String(e);
79+ }
80+ };
7381 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));
85+ }
8086 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 }));
90+ }
91+ ask("blame newest", () => folderBlame(project, ""));
8292 return out;
8393};
8494
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", () => {
8696 const oracle = new Project(new MemoryStore(), { hasBlob: () => true });
8797 const { storage, project } = writer();
8898 history(oracle);
@@ -101,6 +111,9 @@
101111 { agent: "bob", lines: 1 },
102112 ]);
103113 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])}`);
104117 assert.equal(
105118 (expected["0 "] as { entries: { name: string; blobs?: string[] }[] }).entries.find((e) => e.name === "logo.png")!
106119 .blobs![0],