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

why: reasons pointing at a change indexed, and a moved line looked for among its push (disk-first 2; abso Capacity).

of shared·capacity··Not checked

why on abso, warm, one kept reader: 2.9 s a call with about 24,000 reads, 20,000 of them atoms.

  • Reasons in: why listed the changes whose reasons point at the line's change by reading every atom in the project. The graph now keeps, for each atom, the atoms whose reasons point at it, in seq order, once each (reasons-in, Graph.reasonsTo), from a fresh stored graph on. A graph made before keeps none, reasonsTo says undefined, and why looks at every atom as before.
  • Moved from: the trail looked for a deleted copy of a line's text among every atom within 5,000 of the change. Only atoms pushed with it can count, so where the change is published its version's atoms are the candidates (Project.versionAtoms, trail's pushmates). A change still in a draft goes with every other draft change, so it looks near by as before.
  • trail takes atoms' numbers from their ids instead of reading each atom.

On abso adopted fresh: why 244 ms on the first call, then 86 and 46 ms (was 2.9 s); 1,091 reads, then 469 and 73. It matches replay, which takes 951 ms. Heap after: 22.6 MB.

New test reasons-to: the atoms pointing at an atom, in seq order, once each, whatever the kind and however many reasons one gives, in memory and stored. A stored graph without the index says undefined. Every engine test (292 of 292), every worker/project test (341 of 341); tsc and biome clean.

Version 241 · Files at version 242

5 files, 137 lines added, 9 removed.

--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -612,6 +612,7 @@
612612 this.#dependentsPages = storedLists<AtomId>(storage, "dependents");
613613 this.#resolversPages = storedLists<AtomId>(storage, "resolvers");
614614 this.#togetherPages = storedLists<TogetherLink>(storage, "together");
615+ this.#reasonsInPages = storedLists<AtomId>(storage, "reasons-in");
615616 this.#fileAtomPages = storedLists<AtomId>(storage, "file-atoms");
616617 this.#runStartPages = storedLists<number>(storage, "run-starts", (key) =>
617618 JSON.stringify(["number", Number(key)]),
@@ -803,6 +804,16 @@
803804 #resolversPages: ReturnType<typeof storedLists<AtomId>> | undefined;
804805 #together: StateMap<AtomId, TogetherLink[]> = new Map();
805806 #togetherPages: ReturnType<typeof storedLists<TogetherLink>> | undefined;
807+ /** The atoms whose reasons point at each atom, in seq order, once each (abso Capacity). */
808+ #reasonsIn = new Map<AtomId, AtomId[]>();
809+ #reasonsInPages: ReturnType<typeof storedLists<AtomId>> | undefined;
810+ /** Whether a stored graph keeps reasons-in: from a fresh graph on, worked out when first needed. */
811+ #reasonsInKnown: boolean | undefined;
812+ get #reasonsInKept(): boolean {
813+ if (!this.#storage) return true;
814+ this.#reasonsInKnown ??= this.#storage.read("reasons-in:meta", "kept") === 1;
815+ return this.#reasonsInKnown;
816+ }
806817 #fileAtoms: StateMap<string, AtomId[]> = new Map();
807818 #fileAtomPages: ReturnType<typeof storedLists<AtomId>> | undefined;
808819 /** First lines of runs (their n), by the node they were written after: a line's n, or -1 - a path's index. */
@@ -1345,6 +1356,16 @@
13451356 else yield* listOf(this.#resolvers.get(id));
13461357 }
13471358
1359+ /**
1360+ * The atoms whose reasons point at this one, in seq order, once each; or undefined when a stored graph made before
1361+ * this index keeps none, and the caller looks at every atom (abso Capacity).
1362+ */
1363+ reasonsTo(id: AtomId): readonly AtomId[] | undefined {
1364+ if (!this.#reasonsInKept) return undefined;
1365+ if (this.#reasonsInPages) return [...this.#reasonsInPages.values(id)];
1366+ return this.#reasonsIn.get(id) ?? [];
1367+ }
13481369 /** `together` reasons touching this atom, in either direction. */
13491370 togetherLinks(id: AtomId): readonly TogetherLink[] {
13501371 return [...this.eachTogetherLink(id)];
@@ -1546,6 +1567,8 @@
15461567 }
15471568 if (this.#storage && this.#atoms.length === 0 && this.#packFiles) {
15481569 this.#storage.write("file-lines:meta", "format", 2);
1570+ this.#storage.write("reasons-in:meta", "kept", 1);
1571+ this.#reasonsInKnown = true;
15491572 this.#formatKnown = 2;
15501573 }
15511574
@@ -1723,6 +1746,15 @@
17231746 if (this.#fileAtomPages) this.#fileAtomPages.append(file, frozen.id);
17241747 else pushIndex(this.#fileAtoms, file, frozen.id);
17251748 }
1749+ if (this.#reasonsInKept) {
1750+ const pointed = new Set<AtomId>();
1751+ for (const r of frozen.reasons) {
1752+ if (pointed.has(r.to)) continue;
1753+ pointed.add(r.to);
1754+ if (this.#reasonsInPages) this.#reasonsInPages.append(r.to, frozen.id);
1755+ else pushIndex(this.#reasonsIn, r.to, frozen.id);
1756+ }
1757+ }
17261758 for (const r of frozen.reasons) {
17271759 if (r.kind !== "together" || r.to === frozen.id) continue;
17281760
--- /dev/null
+++ b/src/engine/test/reasons-to.test.ts
@@ -0,0 +1,56 @@
1+// The atoms whose reasons point at an atom (abso Capacity, Graph.reasonsTo): why's "reasons in" reads them instead of
2+// every atom. In seq order, once each, whatever the kind and however many reasons one atom gives; kept from a fresh
3+// stored graph on, and undefined on a stored graph made before, where the caller looks at every atom.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { Graph } from "../index.ts";
8+import { lines, Repo } from "./helpers.ts";
9+import { SqlState } from "./storage-helper.ts";
11+function history() {
12+ const repo = Repo.init({ "f.txt": lines("one", "two", "three") });
13+ const x = repo.edit({ author: "ann", message: "x", edits: [{ file: "f.txt", old: "one", new: "ONE" }] });
14+ repo.edit({
15+ author: "bob",
16+ message: "y",
17+ edits: [{ file: "f.txt", old: "two", new: "TWO" }],
18+ reasons: [
19+ { to: x.id, kind: "together", text: "same idea" },
20+ { to: x.id, kind: "because-of", text: "and because of it" },
21+ ],
22+ });
23+ repo.edit({ author: "cy", message: "unrelated", edits: [{ file: "f.txt", old: "three", new: "3" }] });
24+ repo.edit({
25+ author: "dee",
26+ message: "z",
27+ edits: [{ file: "f.txt", old: "3", new: "THREE" }],
28+ reasons: [{ to: x.id, kind: "supersedes", text: "replaces it" }],
29+ });
30+ return { repo, x };
31+}
33+/** Every atom whose reasons point at id, by looking at each one: what reasonsTo must give. */
34+const scanned = (graph: Graph, id: string) =>
35+ [...graph.atoms()].filter((a) => a.reasons.some((r) => r.to === id)).map((a) => a.id);
37+test("reasonsTo lists the atoms pointing at an atom, in seq order, once each", () => {
38+ const { repo, x } = history();
39+ const want = scanned(repo.graph, x.id);
40+ assert.equal(want.length, 2, "bob's two reasons and dee's");
41+ assert.deepEqual(repo.graph.reasonsTo(x.id), want);
42+ const storage = new SqlState();
43+ const stored = new Graph({ storage });
44+ for (const atom of repo.graph.atoms()) stored.add(atom);
45+ assert.deepEqual(new Graph({ storage }).reasonsTo(x.id), want);
46+ assert.deepEqual(new Graph({ storage }).reasonsTo("a0"), []);
47+});
49+test("a stored graph made before the index keeps none, and says so", () => {
50+ const { repo, x } = history();
51+ const storage = new SqlState();
52+ const stored = new Graph({ storage });
53+ for (const atom of repo.graph.atoms()) stored.add(atom);
54+ storage.remove("reasons-in:meta", "kept");
55+ assert.equal(new Graph({ storage }).reasonsTo(x.id), undefined);
56+});
--- a/worker/project/blame.ts
+++ b/worker/project/blame.ts
@@ -226,7 +226,9 @@
226226 toMessage: graph.atom(r.to).message,
227227 }));
228228 const reasonsIn: { from: AtomId; kind: string; text: string; fromAuthor: string; fromMessage: string }[] = [];
229− for (const other of graph.atoms()) {
229+ // The atoms that point at it, where the graph keeps them (abso Capacity): looking at every atom read each one.
230+ const pointing = graph.reasonsTo(atom.id);
231+ for (const other of pointing ? pointing.map((id) => graph.atom(id)) : graph.atoms()) {
230232 for (const r of other.reasons) {
231233 if (r.to === atom.id)
232234 reasonsIn.push({
@@ -305,7 +307,13 @@
305307 const graph = project.graph;
306308 // Changes pushed together: the same version of the same space, or both still in one agent's draft.
307309 const samePush = (a: Atom, b: Atom) => samePublish(publishOf(project, a.id), publishOf(project, b.id));
308− const { steps, more } = trail(graph, view, file, line, undefined, samePush);
310+ // What was pushed with a published atom is its version's atoms; an atom still in a draft goes with every other one,
311+ // so the trail looks near by as before.
312+ const pushmates = (a: Atom) => {
313+ const p = publishOf(project, a.id);
314+ return p ? project.versionAtoms(p.version, p.draft) : undefined;
315+ };
316+ const { steps, more } = trail(graph, view, file, line, undefined, samePush, pushmates);
309317 const groups: { steps: TrailStep[]; publish: Publish | null }[] = [];
310318 for (const s of steps) {
311319 const publish = publishOf(project, s.atom);
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -834,6 +834,12 @@
834834 return p && { agent: p.agent, message: p.message, time: p.time };
835835 }
836836
837+ /** The atoms a version of shared, or of a named draft, added to its space: what was pushed together (blame's trail). */
838+ versionAtoms(version: number, draft: string | null = null): readonly AtomId[] {
839+ const space = draft === null ? this.#shared : this.#spaces.get(draft);
840+ return space?.versions[version]?.atoms ?? [];
841+ }
837843 /** The graph, for reading (blame, history). Don't add to it. */
838844 get graph(): Graph {
839845 return this.#graph;
--- a/worker/project/trail.ts
+++ b/worker/project/trail.ts
@@ -12,7 +12,15 @@
1212// in another (a file split in two), which the trail follows into the file it
1313// came from.
1414
15−import type { Atom, AtomId, Graph, LineId, ReadView, SeqLine } from "../../src/engine/index.ts";
15+import {
16+ type Atom,
17+ type AtomId,
18+ type Graph,
19+ type LineId,
20+ type ReadView,
21+ type SeqLine,
22+ seqOf,
23+} from "../../src/engine/index.ts";
1624
1725/** One change in a line's past, newest first. */
1826export interface TrailStep {
@@ -194,6 +202,7 @@
194202 line: LineId,
195203 max = TRAIL_MAX,
196204 samePush: (a: Atom, b: Atom) => boolean = (a, b) => a.id === b.id,
205+ pushmates?: (atom: Atom) => Iterable<AtomId> | undefined,
197206): { steps: TrailStep[]; more: boolean } {
198207 const files = new Map<string, { seq: readonly SeqLine[]; index: Map<LineId, number> }>();
199208 const sequenceOf = (path: string) => {
@@ -218,7 +227,7 @@
218227 const { seq, index } = sequenceOf(path);
219228 const at = index.get(id);
220229 if (at === undefined) continue;
221− const hunk = hunkOf(graph, seq, at, graph.atom(seq[at]!.atom));
230+ const hunk = hunkOf(seq, at, graph.atom(seq[at]!.atom));
222231 const p = pairIn(
223232 hunk.before.map((i) => seq[i]!.text),
224233 hunk.after.map((i) => seq[i]!.text),
@@ -234,7 +243,15 @@
234243 let formatting = pair?.formatting ?? false;
235244 let searched = false;
236245 if (replaced === undefined) {
237− const moved = movedFrom(graph, view, atom, seq[at]!.text, new Set(hunk.before.map((i) => seq[i]!.id)), samePush);
246+ const moved = movedFrom(
247+ graph,
248+ view,
249+ atom,
250+ seq[at]!.text,
251+ new Set(hunk.before.map((i) => seq[i]!.id)),
252+ samePush,
253+ pushmates,
254+ );
238255 if (moved) [replaced, formatting, searched] = [moved, true, true];
239256 }
240257 const maybeMoved = searched || (replaced !== undefined && graph.lineFile(replaced) !== graph.lineFile(id));
@@ -277,14 +294,24 @@
277294 text: string,
278295 skip: ReadonlySet<LineId>,
279296 samePush: (a: Atom, b: Atom) => boolean,
297+ pushmates?: (atom: Atom) => Iterable<AtomId> | undefined,
280298): LineId | undefined {
281299 const want = normalize([text]);
282300 if (want.length < 12) return undefined;
283301 const all = graph.atoms();
284302 const exact: LineId[] = [];
285303 const same: LineId[] = [];
286− for (let s = Math.max(0, atom.seq - NEAR); s <= Math.min(all.length - 1, atom.seq + NEAR); s++) {
287− const other = all[s]!;
304+ // Only atoms pushed with this one can count (samePush), so where the caller can list them, those are the candidates
305+ // (abso Capacity): reading every atom within NEAR of it was 10,000 atom reads a step on abso. Otherwise, every atom
306+ // near by, as before.
307+ const mates = pushmates?.(atom);
308+ const near = (s: number) => s >= atom.seq - NEAR && s <= atom.seq + NEAR;
309+ const candidates: Iterable<Atom> = mates
310+ ? [...mates].filter((id) => near(seqOf(id))).map((id) => graph.atom(id))
311+ : (function* () {
312+ for (let s = Math.max(0, atom.seq - NEAR); s <= Math.min(all.length - 1, atom.seq + NEAR); s++) yield all[s]!;
313+ })();
314+ for (const other of candidates) {
288315 if (other.author !== atom.author || !view.set.has(other.id) || !samePush(other, atom)) continue;
289316 for (const d of other.deletes) {
290317 if (skip.has(d)) continue;
@@ -304,8 +331,7 @@
304331 * Lines nobody could see when it was made (written later, or already
305332 * deleted) are passed over; a line it left alone ends the hunk.
306333 */
307−function hunkOf(graph: Graph, seq: readonly SeqLine[], at: number, atom: Atom): { before: number[]; after: number[] } {
308− const seqOf = (id: AtomId) => graph.atom(id).seq;
334+function hunkOf(seq: readonly SeqLine[], at: number, atom: Atom): { before: number[]; after: number[] } {
309335 const role = (s: SeqLine): "wrote" | "deleted" | "unseen" | "kept" => {
310336 if (s.atom === atom.id) return "wrote";
311337 if (seqOf(s.atom) > atom.seq) return "unseen";