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

Collisions step 2: shared with drafts on top is a kept view that borrows shared's layouts (abso Capacity, issue 664).

of shared·capacity··Not checked

Draft collisions asked for shared now with one agent's draft on top (and with two agents' for a name both define) as a fresh view each call, laid out from scratch. Project's draftsView keeps it under shared's version and the drafts' atoms, so it changes with any draft change, a dropped draft or shared moving.

It is laid out as shared is for every file the drafts don't touch, as an agent's view is (shareFiles, touchedBeyond). One agent based on shared's newest version is just its own view.

On the abso export (my machine): a warm collisions call takes 6.3 s instead of 7.7 s, with 45 layouts instead of 80. Same answer as replay. A full warm run's heap is 76.9 MB against 76.5 MB on 244, so borrowing adds nothing.

test/collisions-kept-views.test.ts: a writer against the in-memory project, each answer asked twice, through drafts with definition and duplicate collisions, after a draft changes, after shared moves on and after a draft is dropped. The collision, path and move tests pass (35 of 35).

Version 245 · Files at version 246

3 files, 97 lines added, 14 removed.

--- a/worker/project/draft-collisions.ts
+++ b/worker/project/draft-collisions.ts
@@ -2,7 +2,7 @@
22// is the project in memory.
33
44import { type AtomId, type Graph, parseKey, type ReadView } from "../../src/engine/index.ts";
5−import { StableSet, unionOverlay } from "../../src/engine/state-source.ts";
5+import { StableSet } from "../../src/engine/state-source.ts";
66import { claimantsAmong, describeSide, fileOfKey, pairsFrom } from "./collisions.ts";
77import type { DefinitionRule } from "./definition-rule.ts";
88import { type Definition, definedTwice } from "./definitions.ts";
@@ -25,7 +25,8 @@
2525 definitionRule(): DefinitionRule;
2626 draft(agent: Agent): AtomId[];
2727 agentView(agent: Agent): ReadView;
28− view(set: ReadonlySet<AtomId>): ReadView;
28+ /** Shared now with these agents' drafts on top. */
29+ draftsView(agents: readonly Agent[]): ReadView;
2930 touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;
3031}
3132
@@ -95,16 +96,9 @@
9596 if (!set) draftSets.set(agent, (set = new Set(host.draft(agent))));
9697 return set;
9798 };
98− // Shared now with each agent's draft on top, once per agent. Over shared's view's own set (abso Capacity): a view's set
99− // is closed under dependencies anyway, so shared's closed set and the drafts lay out what shared's atoms and the drafts
100− // do, and only the drafts' atoms are walked to close it.
101− const withDraftsView = (...drafts: readonly AtomId[][]) => host.view(unionOverlay(sharedView.set, drafts.flat()));
102− const nowViews = new Map<Agent, ReadView>();
103− const nowViewOf = (agent: Agent) => {
104− let view = nowViews.get(agent);
105− if (!view) nowViews.set(agent, (view = withDraftsView(host.draft(agent))));
106− return view;
107− };
99+ // Shared now with each agent's draft on top (project.ts, draftsView): kept between calls while shared and the
100+ // draft stay the same, and laid out as shared is for every file the draft doesn't touch (abso Capacity).
101+ const nowViewOf = (agent: Agent) => host.draftsView([agent]);
108102 // Each agent's touched files once, not once per pair (abso Capacity).
109103 const touched = new Map<Agent, Set<string>>();
110104 const touchedBy = (agent: Agent) => {
@@ -161,7 +155,7 @@
161155 const mineB = new Set(draftB);
162156 const filesA = touchedBy(a);
163157 for (const file of [...touchedBy(b)].filter((f) => filesA.has(f)).toSorted()) {
164− both ??= withDraftsView(draftA, draftB);
158+ both ??= host.draftsView([a, b]);
165159 if (!both.hasFile(file)) continue;
166160 for (const [name, defs] of definedTwice(both, file)) {
167161 const by = (mine: Set<AtomId>) => defs.find((d) => d.lines.some((l) => mine.has(host.graph.lineAtom(l)!)));
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -1900,12 +1900,35 @@
19001900 definitionRule: () => this.#definitionRule,
19011901 draft: (agent) => this.#draft(agent as AgentState),
19021902 agentView: (agent) => this.#agentView(agent as AgentState),
1903− view: (set) => this.#view(set),
1903+ draftsView: (agents) => this.#draftsView(agents as readonly AgentState[]),
19041904 touchedFiles: (ids, views) => this.#touchedFiles(ids, views),
19051905 };
19061906 return this.#draftCollisionHost;
19071907 }
19081908
1909+ /**
1910+ * Shared now with some agents' drafts on top, for draft collisions (abso Capacity). Kept under the drafts' atoms and
1911+ * shared's version, so a second ask with nothing changed lays nothing out again, and laid out as shared is for every
1912+ * file the drafts don't touch, as an agent's view is. One agent based on shared's newest version is its own view.
1913+ */
1914+ #draftsView(agents: readonly AgentState[]): ReadView {
1915+ const shared = this.#shared;
1916+ const version = last(shared);
1917+ const only = agents.length === 1 ? agents[0]! : undefined;
1918+ if (only && only.space === SHARED && only.base === version) return this.#agentView(only);
1919+ const drafts = agents.map((agent) => this.#draft(agent));
1920+ const mine = drafts.flat();
1921+ const base = this.#sharedView();
1922+ const view = this.#viewKeyed(`d ${SHARED}@${version}+${drafts.map((d) => d.join(",")).join("+")}`, () =>
1923+ unionOverlay(base.set, mine),
1924+ );
1925+ if (this.#writerStorage && mine.length > 0 && view instanceof View && base instanceof View) {
1926+ view.shareMoves(base);
1927+ view.shareFiles(base, () => touchedBeyond(this.#graph, base.set, mine, [base, view]));
1928+ }
1929+ return view;
1930+ }
19091932 /** Whether agents' unpublished changes would collide, by the publish rule (draft-collisions.ts). */
19101933 collisions(...args: Tail<Parameters<typeof draftCollisions>>): ReturnType<typeof draftCollisions> {
19111934 return draftCollisions(this.#draftCollisions, ...args);
--- /dev/null
+++ b/worker/project/test/collisions-kept-views.test.ts
@@ -0,0 +1,66 @@
1+// Draft collisions read shared with drafts on top through kept views (abso Capacity, Project's draftsView): kept under
2+// shared's version and the drafts' atoms, and laid out as shared is for the files the drafts don't touch. On a writer
3+// every answer must match the in-memory project's, asked twice, and again after a draft changes, after shared moves on
4+// and after a draft is dropped.
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 SHAPES = "export function area(r: number) {\n return 3.14 * r * r;\n}\n";
25+const IMPORT = 'import { area } from "./shapes";\n';
26+const MAIN = `${IMPORT}export const a = area(2);\n`;
28+let t = 0;
29+const steps: [string, (project: Project) => void][] = [
30+ [
31+ "drafts",
32+ (project) => {
33+ project.init({ "src/shapes.ts": SHAPES, "src/main.ts": IMPORT, "src/notes.md": "notes\n", "e.ts": "// e\n" }, t);
34+ project.sync("old");
35+ project.record("old", { "src/notes.md": "notes\nmore\n" }, ++t);
36+ project.record("mover", { "src/notes.md": null, "docs/notes.md": "notes\n" }, ++t);
37+ assert.equal(project.publish("mover", "Move notes", ++t).ok, true);
38+ // ann changes area(); bob's new line uses it; cy and dee define f in e.ts.
39+ project.edit("ann", { file: "src/shapes.ts", old: "area(r: number)", new: "area(r: number, scale = 1)" }, ++t);
40+ project.record("bob", { "src/main.ts": MAIN }, ++t);
41+ project.record("cy", { "e.ts": "// e\nexport function f() {}\n" }, ++t);
42+ project.record("dee", { "e.ts": "export function f() { return 1; }\n// e\n" }, ++t);
43+ },
44+ ],
45+ ["a draft changes", (project) => project.record("bob", { "src/main.ts": `${MAIN}export const b = area(3);\n` }, ++t)],
46+ ["shared moves on", (project) => assert.equal(project.publish("ann", "Add a scale", ++t).ok, true)],
47+ ["a draft is dropped", (project) => project.restore("cy", null, ++t)],
48+];
50+test("draft collisions through kept views match the in-memory project's as drafts and shared change", () => {
51+ const oracle = new Project(new MemoryStore());
52+ const project = writer();
53+ const seen = new Set<string>();
54+ for (const [name, step] of steps) {
55+ const at = t;
56+ step(oracle);
57+ t = at;
58+ step(project);
59+ const expected = oracle.collisions();
60+ for (const c of expected.collisions) seen.add(c.kind);
61+ assert.deepEqual(project.collisions(), expected, name);
62+ assert.deepEqual(project.collisions(), expected, `${name}, again`);
63+ }
64+ // The kinds that read through the kept views, so a history change can't empty the test.
65+ assert.ok(seen.has("definition"), [...seen].join(", "));
66+});