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 245 --json
JSON
/christopher/abso-core/versions/245?format=json

Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664).

of shared·capacity··Not checked

A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out.

On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244.

test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.

Version 244 · Files at version 245

4 files, 151 lines added, 4 removed.

--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -49,7 +49,14 @@
4949/** Structural read boundary shared by historical and transaction-bound projections. */
5050export type ReadView = Omit<
5151 Pick<View, keyof View>,
52− "sameText" | "visibleCount" | "shareMoves" | "shareFiles" | "fileOfNumber" | "lineNumberOf" | "visibleWriters"
52+ | "sameText"
53+ | "visibleCount"
54+ | "shareMoves"
55+ | "shareFiles"
56+ | "knowPaths"
57+ | "fileOfNumber"
58+ | "lineNumberOf"
59+ | "visibleWriters"
5360> & {
5461 sameText(path: string, other: ReadView): boolean;
5562};
@@ -427,6 +434,17 @@
427434 this.#filesFrom = { from, except };
428435 }
429436 #filesFrom: { from: View; except: () => ReadonlySet<string> | undefined } | null | undefined;
438+ /**
439+ * The files this view's set has, from what the project keeps for a published version (abso Capacity): hasFile
440+ * answers from it, not a layout of the file. Collisions resolving an import tried up to seven names, and each one
441+ * laid its file out. `paths` is asked once, when first needed; undefined lays files out as before.
442+ */
443+ knowPaths(paths: () => ReadonlySet<string> | undefined): void {
444+ if (this.#pathsFrom === undefined) this.#pathsFrom = paths;
445+ }
446+ #pathsFrom: (() => ReadonlySet<string> | undefined) | undefined;
447+ #knownPaths: ReadonlySet<string> | null | undefined;
430448 #filesShared: { from: View; except: ReadonlySet<string> } | null | undefined;
431449 #sharedFiles(): { from: View; except: ReadonlySet<string> } | null {
432450 if (this.#filesShared === undefined) {
@@ -899,6 +917,15 @@
899917
900918 /** Whether the file exists in this projection (has a visible line). */
901919 hasFile(path: string): boolean {
920+ if (!this.#files.has(path)) {
921+ // A file the draft doesn't touch exists as it does in the base; a published version's files are kept.
922+ const shared = this.#filesFrom === undefined ? null : this.#sharedFiles();
923+ if (shared && !shared.except.has(path)) return shared.from.hasFile(path);
924+ if (this.#pathsFrom !== undefined) {
925+ if (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null;
926+ if (this.#knownPaths) return this.#knownPaths.has(path);
927+ }
928+ }
902929 const attrs = this.attrs(path);
903930 return attrs.exists || attrs.link !== null || attrs.blob !== null || this.#file(path).vis.length > 0;
904931 }
--- a/worker/project/pathindex.ts
+++ b/worker/project/pathindex.ts
@@ -50,17 +50,26 @@
5050 * then the caller lays the version out.
5151 */
5252 keptPaths(space: Space, version: number): string[] | undefined {
53+ const files = this.keptPathSet(space, version);
54+ return files && [...files].sort();
55+ }
57+ /** keptPaths as a set, kept for the newest version asked: never changed once made, so a view can hold it. */
58+ keptPathSet(space: Space, version: number): ReadonlySet<string> | undefined {
5359 let fold = this.#keptPaths.get(space);
60+ if (fold?.version === version) return fold.files;
5461 if (!fold || fold.version > version) fold = { version: -1, files: new Set() };
5562 const files = new Set(fold.files);
5663 for (let v = fold.version + 1; v <= version; v++) {
5764 if (!this.#keptFiles(space, v)) return undefined;
58− const shape = this.#shapeCache.get(space)!.get(v)!;
65+ // Not yet when the version is still being kept (keep asks its views which files exist).
66+ const shape = this.#shapeCache.get(space)?.get(v);
67+ if (!shape) return undefined;
5968 for (const f of shape.gone) files.delete(f);
6069 for (const f of shape.made) files.add(f);
6170 }
6271 this.#keptPaths.set(space, { version, files });
63− return [...files].sort();
72+ return files;
6473 }
6574
6675 /** Each space's path index (#41): built the first time it's asked for, then kept up as versions land. */
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -2777,7 +2777,11 @@
27772777
27782778 /** A space at a version: published versions never change, so the key is just their names (#46). */
27792779 #viewAt(space: Space, version: number): ReadView {
2780− return this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version));
2780+ const view = this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version));
2781+ // Which files it has from the kept path list (abso Capacity, View.knowPaths), as pathsAt answers.
2782+ if (view instanceof View && this.#writerStorage && space.name === SHARED)
2783+ view.knowPaths(() => this.#paths.keptPathSet(space, version));
2784+ return view;
27812785 }
27822786
27832787 #sharedView(): ReadView {
--- /dev/null
+++ b/worker/project/test/known-paths.test.ts
@@ -0,0 +1,107 @@
1+// Whether a file exists, answered without laying it out (abso Capacity, View.knowPaths): a published version's view
2+// on a writer answers from the kept path list, and a draft's view asks its base for every file the draft doesn't
3+// touch. Each must say what the in-memory project says, at every version and in every draft: files deleted or
4+// renamed by a published version, and by a draft, by record and by moving lines.
5+
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";
13+function writer() {
14+ const storage = new SqlState();
15+ const entries = storedArray<Entry>(storage, "canonical-log");
16+ const store: ProjectStore = {
17+ append(batch) {
18+ for (const entry of batch) entries.push(entry);
19+ },
20+ };
21+ return new Project(store, { writerStorage: storage });
22+}
24+const AREA = "export function area(r: number) {\n return 3.14 * r * r;\n}\n";
25+const FILES = {
26+ "src/shapes.ts": `// shapes\n${AREA}`,
27+ "src/old-name.ts": "export const x = 1;\n",
28+ "src/gone.ts": "export const y = 2;\n",
29+ "src/keep.ts": 'import { x } from "./old-name";\n',
30+ "notes.md": "notes\n",
31+};
33+/** Every name to ask about: each path any version or draft has had, and names that never existed. */
34+const NAMES = [
35+ ...Object.keys(FILES),
36+ "src/new-name.ts",
37+ "src/geometry.ts",
38+ "src/draft-new.ts",
39+ "src/draft-renamed.ts",
40+ "src/never.ts",
41+ "src/old-name",
42+ "src/old-name.js",
43+];
45+function history(project: Project) {
46+ let t = 0;
47+ project.init(FILES, t);
48+ project.sync("v0");
49+ // Version 1: ann deletes a file and renames another with record.
50+ project.record(
51+ "ann",
52+ { "src/gone.ts": null, "src/old-name.ts": null, "src/new-name.ts": FILES["src/old-name.ts"] },
53+ ++t,
54+ );
55+ assert.equal(project.publish("ann", "Delete gone, rename old-name", ++t).ok, true);
56+ project.sync("v1");
57+ // Version 2: ann moves area() into a new file by moving its lines.
58+ project.edit("ann", { file: "src/shapes.ts", old: AREA, new: "" }, ++t);
59+ project.edit("ann", { file: "src/geometry.ts", content: AREA }, ++t);
60+ assert.equal(project.publish("ann", "Move area", ++t).ok, true);
61+ for (const agent of ["v2", "bob", "cy", "dee", "eve"]) project.sync(agent);
62+ // Drafts over version 2: bob deletes a file, cy renames one with record, dee moves lines into a new file, eve adds one.
63+ project.record("bob", { "src/keep.ts": null }, ++t);
64+ project.record("cy", { "src/new-name.ts": null, "src/draft-renamed.ts": FILES["src/old-name.ts"] }, ++t);
65+ project.edit("dee", { file: "src/geometry.ts", old: AREA, new: "" }, ++t);
66+ project.edit("dee", { file: "src/draft-new.ts", content: AREA }, ++t);
67+ project.record("eve", { "src/draft-new.ts": "new\n" }, ++t);
68+}
70+const exists = (project: Project, agent: string) => {
71+ const view = project.draftOf(agent)!.view;
72+ return Object.fromEntries(NAMES.map((name) => [name, view.hasFile(name)]));
73+};
75+test("whether each file exists, at every version and in every draft, as the in-memory project says", () => {
76+ const oracle = new Project(new MemoryStore());
77+ const project = writer();
78+ history(oracle);
79+ history(project);
80+ for (const agent of ["v0", "v1", "v2", "bob", "cy", "dee", "eve"]) {
81+ // Before any layout, and again after every file has been read.
82+ assert.deepEqual(exists(project, agent), exists(oracle, agent), agent);
83+ const view = project.draftOf(agent)!.view;
84+ for (const path of view.paths()) view.lines(path);
85+ assert.deepEqual(exists(project, agent), exists(oracle, agent), `${agent} after reading`);
86+ assert.deepEqual(view.paths(), oracle.draftOf(agent)!.view.paths(), `${agent} paths`);
87+ }
88+ // The cases the test is for, so a history change can't empty it.
89+ const at = (agent: string) => exists(oracle, agent);
90+ assert.equal(at("v0")["src/gone.ts"], true);
91+ assert.equal(at("v1")["src/gone.ts"], false);
92+ assert.equal(at("v1")["src/old-name.ts"], false);
93+ assert.equal(at("v1")["src/new-name.ts"], true);
94+ assert.equal(at("v2")["src/geometry.ts"], true);
95+ assert.equal(at("bob")["src/keep.ts"], false);
96+ assert.equal(at("cy")["src/new-name.ts"], false);
97+ assert.equal(at("cy")["src/draft-renamed.ts"], true);
98+ assert.equal(at("dee")["src/draft-new.ts"], true);
99+ assert.equal(at("dee")["src/geometry.ts"], false);
100+ assert.equal(at("eve")["src/draft-new.ts"], true);
101+ for (const [version, agent] of [
102+ [0, "v0"],
103+ [1, "v1"],
104+ [2, "v2"],
105+ ] as const)
106+ assert.deepEqual(project.pathsAt(version).files, oracle.draftOf(agent)!.view.paths(), `paths at ${version}`);
107+});