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

Versions 211 to 212

Compare

+72 −2 in 3 places
Lines 9–18 at 212 (were 9–16 at 211)
99 conflictKeys,
1010 type Graph,
1111 joinLines,
12+ type Key,
1213 parseKey,
1314 type ReadView,
15+ seqOf,
1416} from "../../src/engine/index.ts";
1517import { differenceSet, StableOverlaySet } from "../../src/engine/state-source.ts";
1618import { definedTwice } from "./definitions.ts";
Lines 46–65 at 212 (were 44–50 at 211)
4446 against: ReadonlySet<AtomId>,
4547 settled: ReadonlySet<AtomId>,
4648): Pair[] {
47− const out: Pair[] = [];
49+ return pairsFrom(g, claimantsIn(g, draft, against), against, settled);
50+}
52+/**
53+ * Each draft change's claimants in `against`, in seq order: the atoms whose claims meet its keys, before the
54+ * engine's rule is applied. A stored atom's keys are read from disk, so a caller checking one draft against many
55+ * (draft-collisions.ts) gathers once against all of them and filters with pairsFrom.
56+ */
57+export function claimantsIn(
58+ g: Graph,
59+ draft: readonly AtomId[],
60+ against: ReadonlySet<AtomId>,
61+): ReadonlyMap<AtomId, readonly AtomId[]> {
62+ const out = new Map<AtomId, AtomId[]>();
4863 for (const yours of draft) {
4964 const atom = g.atom(yours);
5065 const streams: IterableIterator<AtomId>[] = [];
Lines 67–128 at 212 (were 52–58 at 211)
5267 streams.push(g.eachWriterOf(key), g.eachReaderOf(key), g.eachHolderOf(key));
5368 }
5469 for (const key of claimsOf(atom)) streams.push(g.eachWriterOf(key));
55− for (const theirs of orderedClaimants(g, streams)) {
70+ const theirs: AtomId[] = [];
71+ for (const id of orderedClaimants(g, streams)) if (against.has(id)) theirs.push(id);
72+ out.set(yours, theirs);
73+ }
74+ return out;
75+}
77+/**
78+ * claimantsIn for a few atoms against each other: each atom's claimants among `atoms`, in seq order, from their own
79+ * keys held in memory. Walking each key's history of claimants read four lists from disk per key, and a draft deleting
80+ * a big file has thousands of keys (abso Capacity).
81+ */
82+export function claimantsAmong(g: Graph, atoms: readonly AtomId[]): ReadonlyMap<AtomId, readonly AtomId[]> {
83+ const claimers = new Map<Key, AtomId[]>();
84+ const writers = new Map<Key, AtomId[]>();
85+ const keys = new Map<AtomId, { writes: readonly Key[]; claims: readonly Key[] }>();
86+ const add = (index: Map<Key, AtomId[]>, key: Key, id: AtomId) => {
87+ const list = index.get(key);
88+ if (list) list.push(id);
89+ else index.set(key, [id]);
90+ };
91+ for (const id of atoms) {
92+ const atom = g.atom(id);
93+ const writes = [...atom.writes];
94+ // claimsOf, with the writes already read.
95+ const claims = [...new Set([...writes, ...atom.reads, ...atom.holds])].sort();
96+ keys.set(id, { writes, claims });
97+ for (const key of writes) add(writers, key, id);
98+ for (const key of claims) add(claimers, key, id);
99+ }
100+ const out = new Map<AtomId, AtomId[]>();
101+ for (const id of atoms) {
102+ const own = keys.get(id)!;
103+ const found = new Set<AtomId>();
104+ // As claimantsIn's streams: what claims a key it writes, and what writes a key it claims.
105+ for (const key of own.writes) for (const other of claimers.get(key) ?? []) found.add(other);
106+ for (const key of own.claims) for (const other of writers.get(key) ?? []) found.add(other);
107+ found.delete(id);
108+ out.set(
109+ id,
110+ [...found].sort((a, b) => seqOf(a) - seqOf(b)),
111+ );
112+ }
113+ return out;
114+}
116+/** The claimants in `against` that collide by the engine's rule and that no atom of `settled` resolves. */
117+export function pairsFrom(
118+ g: Graph,
119+ claimants: ReadonlyMap<AtomId, readonly AtomId[]>,
120+ against: ReadonlySet<AtomId>,
121+ settled: ReadonlySet<AtomId>,
122+): Pair[] {
123+ const out: Pair[] = [];
124+ for (const [yours, theirsList] of claimants) {
125+ for (const theirs of theirsList) {
56126 if (!against.has(theirs)) continue;
57127 const [lo, hi] = g.atom(yours).seq < g.atom(theirs).seq ? [yours, theirs] : [theirs, yours];
58128 const keys = conflictKeys(g.atom(lo), g.atom(hi), g.dependsOn(hi, lo));
MCP
compare on this site's /mcp
CLI
abso diff 211 212 worker/project/collisions.ts --json
JSON
/christopher/abso-core/compare/211..212?file=worker%2Fproject%2Fcollisions.ts&format=json