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
blame on this site's /mcp
CLI
abso blame worker/project/collisions.ts --version 317 --json
JSON
/christopher/abso-core/blame/worker/project/collisions.ts?version=317&format=json
452 linesFirst import 55% · capacity 26% · codex-capacity-chair 18% · pinch 1%Last change capacity in version 317,

452 lines from 12 changes in 11 versions.

init0Start the project1// Collisions (#11, #37): which draft changes collide with other work by the
2// engine's rule, how a collision reads, who published the other side, and
3// duplicate top-level names. The project calls these and decides who hears what.
4
5import {
6 type AtomId,
7 type ConflictKey,
8 claimsOf,
9 conflictKeys,
10 type Graph,
11 joinLines,
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare12 type Key,
init0Start the project13 parseKey,
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare14 type ReadView,
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare15 seqOf,
init0Start the project16} from "../../src/engine/index.ts";
codex-capacity-chair142Avoid full-base membership copies during collision checksCompare17import { differenceSet, StableOverlaySet } from "../../src/engine/state-source.ts";
init0Start the project18import { definedTwice } from "./definitions.ts";
19import type { AgentState, Collision, CollisionSide } from "./project-types.ts";
20import { SHARED, type Space } from "./spaces.ts";
22export interface Pair {
23 readonly yours: AtomId;
24 readonly theirs: AtomId;
25 readonly keys: readonly ConflictKey[];
28/** Where a published atom came from. */
29export interface Origin {
30 readonly agent: string;
31 readonly message: string;
32 readonly version: number;
33 readonly draft?: string;
36/** A line too plain to identify on its own: blank, or only brackets and punctuation. */
37export const PLAIN_LINE = /^[\s{}()[\];,.]*$/;
39/**
40 * Pairs of a draft change and an atom of `against` that collide by the
41 * engine's rule, and that no atom of `settled` resolves.
42 */
43export function pairsIn(
44 g: Graph,
45 draft: readonly AtomId[],
46 against: ReadonlySet<AtomId>,
47 settled: ReadonlySet<AtomId>,
48): Pair[] {
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare49 return pairsFrom(g, claimantsIn(g, draft, against), against, settled);
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 */
57export 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[]>();
init0Start the project63 for (const yours of draft) {
64 const atom = g.atom(yours);
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare65 const streams: IterableIterator<AtomId>[] = [];
init0Start the project66 for (const key of atom.writes) {
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare67 streams.push(g.eachWriterOf(key), g.eachReaderOf(key), g.eachHolderOf(key));
init0Start the project68 }
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare69 for (const key of claimsOf(atom)) streams.push(g.eachWriterOf(key));
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare70 const theirs: AtomId[] = [];
capacity317A draft-state or land on a stored graph no longer reads a row per line to describe its collisions, or a row per claimant to pair them (abso 738). - View's line readers (lines, sequence and the uncached visible lines) name each line's writer with atomId, not graph.idOfSeq. The seq comes from the graph's own layout. idOfSeq's bounds check read the stored atom count once per line, and describing reads both sides' files in full. That was about 0.9 s of a warm draft-state on abso. - The claimant walk (orderedClaimants) and hasCommonResolver take each atom's seq from its id, as graph.atom itself does, instead of loading the stored atom to read it. On abso's Oct 14 tables, both named drafts' states are identical by hash (codex-prose-authorship-610: 71db868585a419a4). codex-prose-authorship-610: - warm: 8,863 statements and 2.3 s become 7,820 and 0.92 s. Describing goes from 0.6 s to under 0.1 s, and pairing from 0.4 s to 0.1 s. - read cold after the other draft: 12,688 statements and 4.1 s become 11,645 and 2.25 s. What's left of the warm read is mostly the draft's own lines' uses (0.3 s, in proportion to the draft), the clash check and membership values. Checks: 1,450 tests pass, 0 fail, 2 skipped. tsc is clean and biome is clean.Compare71 for (const id of orderedClaimants(streams)) if (against.has(id)) theirs.push(id);
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare72 out.set(yours, theirs);
73 }
74 return out;
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 */
82export 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;
116/** The claimants in `against` that collide by the engine's rule and that no atom of `settled` resolves. */
117export function pairsFrom(
118 g: Graph,
119 claimants: ReadonlyMap<AtomId, readonly AtomId[]>,
120 against: ReadonlySet<AtomId>,
121 settled: ReadonlySet<AtomId>,
122): Pair[] {
init0Start the project123 const out: Pair[] = [];
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare124 for (const [yours, theirsList] of claimants) {
125 for (const theirs of theirsList) {
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare126 if (!against.has(theirs)) continue;
init0Start the project127 const [lo, hi] = g.atom(yours).seq < g.atom(theirs).seq ? [yours, theirs] : [theirs, yours];
128 const keys = conflictKeys(g.atom(lo), g.atom(hi), g.dependsOn(hi, lo));
129 if (keys.length === 0 || sideBySide(g, lo, hi, keys)) continue;
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare130 if (hasCommonResolver(g, lo, hi, settled)) continue;
init0Start the project131 out.push({ yours, theirs, keys });
132 }
133 }
134 return out;
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare135}
137/** Claim indexes append in canonical seq order. Merge one cursor per current
138 * atom key, retaining no candidate set proportional to historical claims. */
capacity317A draft-state or land on a stored graph no longer reads a row per line to describe its collisions, or a row per claimant to pair them (abso 738). - View's line readers (lines, sequence and the uncached visible lines) name each line's writer with atomId, not graph.idOfSeq. The seq comes from the graph's own layout. idOfSeq's bounds check read the stored atom count once per line, and describing reads both sides' files in full. That was about 0.9 s of a warm draft-state on abso. - The claimant walk (orderedClaimants) and hasCommonResolver take each atom's seq from its id, as graph.atom itself does, instead of loading the stored atom to read it. On abso's Oct 14 tables, both named drafts' states are identical by hash (codex-prose-authorship-610: 71db868585a419a4). codex-prose-authorship-610: - warm: 8,863 statements and 2.3 s become 7,820 and 0.92 s. Describing goes from 0.6 s to under 0.1 s, and pairing from 0.4 s to 0.1 s. - read cold after the other draft: 12,688 statements and 4.1 s become 11,645 and 2.25 s. What's left of the warm read is mostly the draft's own lines' uses (0.3 s, in proportion to the draft), the clash check and membership values. Checks: 1,450 tests pass, 0 fail, 2 skipped. tsc is clean and biome is clean.Compare139function* orderedClaimants(streams: IterableIterator<AtomId>[]): IterableIterator<AtomId> {
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare140 try {
codex-capacity-chair162Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gateCompare141 type Head = { id: AtomId; seq: number; stream: number };
142 const heap: Head[] = [];
143 const less = (a: Head, b: Head) => a.seq < b.seq || (a.seq === b.seq && a.stream < b.stream);
144 const push = (head: Head) => {
145 let at = heap.length;
146 heap.push(head);
147 while (at > 0) {
148 const parent = (at - 1) >>> 1;
149 if (!less(head, heap[parent]!)) break;
150 heap[at] = heap[parent]!;
151 at = parent;
152 }
153 heap[at] = head;
154 };
capacity317A draft-state or land on a stored graph no longer reads a row per line to describe its collisions, or a row per claimant to pair them (abso 738). - View's line readers (lines, sequence and the uncached visible lines) name each line's writer with atomId, not graph.idOfSeq. The seq comes from the graph's own layout. idOfSeq's bounds check read the stored atom count once per line, and describing reads both sides' files in full. That was about 0.9 s of a warm draft-state on abso. - The claimant walk (orderedClaimants) and hasCommonResolver take each atom's seq from its id, as graph.atom itself does, instead of loading the stored atom to read it. On abso's Oct 14 tables, both named drafts' states are identical by hash (codex-prose-authorship-610: 71db868585a419a4). codex-prose-authorship-610: - warm: 8,863 statements and 2.3 s become 7,820 and 0.92 s. Describing goes from 0.6 s to under 0.1 s, and pairing from 0.4 s to 0.1 s. - read cold after the other draft: 12,688 statements and 4.1 s become 11,645 and 2.25 s. What's left of the warm read is mostly the draft's own lines' uses (0.3 s, in proportion to the draft), the clash check and membership values. Checks: 1,450 tests pass, 0 fail, 2 skipped. tsc is clean and biome is clean.Compare155 // Each claimant's seq from its id, as the graph reads it (abso 738): loading the stored atom for it read a row a
156 // claimant, most of a warm draft-state's pairing on abso.
codex-capacity-chair162Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gateCompare157 const advance = (stream: number) => {
158 const next = streams[stream]!.next();
capacity317A draft-state or land on a stored graph no longer reads a row per line to describe its collisions, or a row per claimant to pair them (abso 738). - View's line readers (lines, sequence and the uncached visible lines) name each line's writer with atomId, not graph.idOfSeq. The seq comes from the graph's own layout. idOfSeq's bounds check read the stored atom count once per line, and describing reads both sides' files in full. That was about 0.9 s of a warm draft-state on abso. - The claimant walk (orderedClaimants) and hasCommonResolver take each atom's seq from its id, as graph.atom itself does, instead of loading the stored atom to read it. On abso's Oct 14 tables, both named drafts' states are identical by hash (codex-prose-authorship-610: 71db868585a419a4). codex-prose-authorship-610: - warm: 8,863 statements and 2.3 s become 7,820 and 0.92 s. Describing goes from 0.6 s to under 0.1 s, and pairing from 0.4 s to 0.1 s. - read cold after the other draft: 12,688 statements and 4.1 s become 11,645 and 2.25 s. What's left of the warm read is mostly the draft's own lines' uses (0.3 s, in proportion to the draft), the clash check and membership values. Checks: 1,450 tests pass, 0 fail, 2 skipped. tsc is clean and biome is clean.Compare159 if (!next.done) push({ id: next.value, seq: seqOf(next.value), stream });
codex-capacity-chair162Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gateCompare160 };
161 for (let stream = 0; stream < streams.length; stream++) advance(stream);
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare162 let previous = -1;
codex-capacity-chair162Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gateCompare163 while (heap.length) {
164 const head = heap[0]!;
165 const tail = heap.pop()!;
166 if (heap.length) {
167 let at = 0;
168 while (at * 2 + 1 < heap.length) {
169 let child = at * 2 + 1;
170 if (child + 1 < heap.length && less(heap[child + 1]!, heap[child]!)) child++;
171 if (!less(heap[child]!, tail)) break;
172 heap[at] = heap[child]!;
173 at = child;
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare174 }
codex-capacity-chair162Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gateCompare175 heap[at] = tail;
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare176 }
codex-capacity-chair162Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gateCompare177 advance(head.stream);
178 if (head.seq === previous) continue;
179 previous = head.seq;
180 yield head.id;
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare181 }
182 } finally {
183 for (const stream of streams) stream.return?.();
184 }
187/** Resolver indexes share the same append order, so intersection needs two cursors. */
188function hasCommonResolver(g: Graph, lo: AtomId, hi: AtomId, settled: ReadonlySet<AtomId>): boolean {
189 const left = g.eachResolverOf(lo);
190 const right = g.eachResolverOf(hi);
191 try {
192 let a = left.next();
193 let b = right.next();
194 while (!a.done && !b.done) {
capacity317A draft-state or land on a stored graph no longer reads a row per line to describe its collisions, or a row per claimant to pair them (abso 738). - View's line readers (lines, sequence and the uncached visible lines) name each line's writer with atomId, not graph.idOfSeq. The seq comes from the graph's own layout. idOfSeq's bounds check read the stored atom count once per line, and describing reads both sides' files in full. That was about 0.9 s of a warm draft-state on abso. - The claimant walk (orderedClaimants) and hasCommonResolver take each atom's seq from its id, as graph.atom itself does, instead of loading the stored atom to read it. On abso's Oct 14 tables, both named drafts' states are identical by hash (codex-prose-authorship-610: 71db868585a419a4). codex-prose-authorship-610: - warm: 8,863 statements and 2.3 s become 7,820 and 0.92 s. Describing goes from 0.6 s to under 0.1 s, and pairing from 0.4 s to 0.1 s. - read cold after the other draft: 12,688 statements and 4.1 s become 11,645 and 2.25 s. What's left of the warm read is mostly the draft's own lines' uses (0.3 s, in proportion to the draft), the clash check and membership values. Checks: 1,450 tests pass, 0 fail, 2 skipped. tsc is clean and biome is clean.Compare195 const x = seqOf(a.value);
196 const y = seqOf(b.value);
codex-capacity-chair134Stream project conflict candidates and resolver intersectionsCompare197 if (x === y && settled.has(a.value)) return true;
198 if (x <= y) a = left.next();
199 if (y <= x) b = right.next();
200 }
201 return false;
202 } finally {
203 left.return?.();
204 right.return?.();
205 }
init0Start the project206}
208/**
209 * Two pure insertions at the same point, and nothing else between them
210 * (#37, the game trial): both only write the gap after one line. Neither
211 * loses anything (both are kept, one after the other), so that alone is
212 * not a collision. It still is when they share a line with real content (the
213 * same import added twice would be doubled), or when the gap is the top of
214 * a file (two agents creating the same file).
215 */
216function sideBySide(g: Graph, a: AtomId, b: AtomId, keys: readonly ConflictKey[]): boolean {
217 const gaps = new Set<string>();
218 for (const k of keys) {
219 if (k.relation !== "write" || !k.key.startsWith("G:") || k.key.startsWith("G:^")) return false;
220 gaps.add(k.key.slice(2));
221 }
222 const linesAt = (id: AtomId): Set<string> => {
223 const out = new Set<string>();
224 for (const run of g.atom(id).inserts) {
225 if (!gaps.has(run.parent)) continue;
226 for (const l of run.lines) if (!PLAIN_LINE.test(l)) out.add(l.trim());
227 }
228 return out;
229 };
230 const ours = linesAt(a);
231 for (const l of linesAt(b)) if (ours.has(l)) return false;
232 return true;
235/** Describe a pair for the agent: its side in `yoursView`, theirs in `theirsView`, with who published theirs. */
236export function describePair(
237 g: Graph,
238 origin: (atom: AtomId, spaceName: string) => Origin,
239 pair: Pair,
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare240 yoursView: ReadView,
241 theirsView: ReadView,
init0Start the project242 spaceName: string,
243): Collision {
244 const file = fileOfKey(pair.keys[0]!.key, yoursView);
245 const fileKeys = pair.keys.filter((k) => fileOfKey(k.key, yoursView) === file).map((k) => k.key);
246 const attrsOnly = fileKeys.map((k) => parseKey(k)).filter((k) => k.kind === "attr");
247 if (attrsOnly.length === fileKeys.length) {
248 // Both set the same attribute of the file: show each side's value.
249 const name = attrsOnly[0]!.attr!;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare250 const valueIn = (view: ReadView, atom: AtomId): string => {
init0Start the project251 const set = (g.atom(atom).attrs ?? []).find((a) => a.file === file && a.name === name);
252 return set?.value ?? (name === "exec" ? "" : String(view.attrs(file)[name] ?? ""));
253 };
254 return {
255 kind: "attribute",
256 name,
257 file,
258 yours: { lines: [1, 0], text: valueIn(yoursView, pair.yours) },
259 theirs: { lines: [1, 0], text: valueIn(theirsView, pair.theirs), ...origin(pair.theirs, spaceName) },
260 };
261 }
262 return {
263 kind: "lines",
264 file,
265 yours: describeSide(yoursView, pair.yours, file, fileKeys),
266 theirs: { ...describeSide(theirsView, pair.theirs, file, fileKeys), ...origin(pair.theirs, spaceName) },
267 };
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare270export function fileOfKey(key: string, view: ReadView): string {
init0Start the project271 const { kind, node } = parseKey(key);
272 if (kind === "attr") return node;
273 return node.startsWith("^") ? node.slice(1) : view.fileOf(node);
276/**
277 * The files some atoms change: the graph's files of each, and, in views
278 * with moves (#28), wherever the lines they touch are in those views.
279 */
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare280export function touchedFiles(g: Graph, ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string> {
init0Start the project281 const out = new Set<string>();
282 const moved = views.filter((v) => v.hasMoves());
283 for (const id of ids) {
284 for (const file of g.filesOf(id)) out.add(file);
285 if (moved.length === 0) continue;
286 const atom = g.atom(id);
capacity238Collisions: deleted lines found by number, and the move index skips graphs that gained nothing (disk-first 2; abso Capacity). Collisions on website took 20.7 s cold with one opened writer (replay 0.4 s), and 46 s on typescript-rs (replay 5 s). - touchedFiles finds each deleted line's file by its number where the view can (fileOfNumber). A draft deleting a big file has thousands; making each one's id only to look its number up again was most of the time. - Graph.accepted counts the atoms a graph object has taken in, in memory. The move index (MoveSkeleton) is brought up to date on every lookup of a line's file. It now reads the movers list only when that count has changed: checking the stored list's length and last mover each time cost 3.3 s of collisions on website. A rolled-back add still counts, which only makes it look again. On website adopted fresh, cold: collisions 20.7 s to 9.6 s. On typescript-rs: 46 s to 11.7 s. Both match replay, and all 27 typescript-rs answers match. Still slow: reading every draft atom's write keys, a row per key once there are more than 256 (75,000 rows on website). Named tests: every engine test (288 of 288), every worker/project test (341 of 341); tsc and biome clean.Compare287 const lines: string[] = [];
init0Start the project288 for (const run of atom.inserts) if (!run.parent.startsWith("^")) lines.push(run.parent);
289 for (const m of atom.moves ?? []) {
290 lines.push(m.line);
291 if (!m.parent.startsWith("^")) lines.push(m.parent);
292 }
capacity238Collisions: deleted lines found by number, and the move index skips graphs that gained nothing (disk-first 2; abso Capacity). Collisions on website took 20.7 s cold with one opened writer (replay 0.4 s), and 46 s on typescript-rs (replay 5 s). - touchedFiles finds each deleted line's file by its number where the view can (fileOfNumber). A draft deleting a big file has thousands; making each one's id only to look its number up again was most of the time. - Graph.accepted counts the atoms a graph object has taken in, in memory. The move index (MoveSkeleton) is brought up to date on every lookup of a line's file. It now reads the movers list only when that count has changed: checking the stored list's length and last mover each time cost 3.3 s of collisions on website. A rolled-back add still counts, which only makes it look again. On website adopted fresh, cold: collisions 20.7 s to 9.6 s. On typescript-rs: 46 s to 11.7 s. Both match replay, and all 27 typescript-rs answers match. Still slow: reading every draft atom's write keys, a row per key once there are more than 256 (75,000 rows on website). Named tests: every engine test (288 of 288), every worker/project test (341 of 341); tsc and biome clean.Compare293 for (const v of moved) {
294 for (const line of lines) out.add(v.fileOf(line));
295 // Deleted lines by number where the view can (abso Capacity): a draft deleting a big file has thousands, and
296 // making each one's id only to look its number up again was most of collisions on website.
297 const byNumber = (v as { fileOfNumber?: (n: number) => string }).fileOfNumber;
298 if (byNumber) for (const n of g.deletedNumbers(id)) out.add(byNumber.call(v, n));
299 else for (const line of g.deletedLines(id)) out.add(v.fileOf(line));
300 }
init0Start the project301 }
302 return out;
capacity237touchedBeyond, with named tests for 235's wrong draft diff (disk-first 2; abso Capacity). 236 fixed the wrong diff Disk-first Testing found on typescript-rs with 235 (cloud-ts-01's diff showed lib.rs and passes.rs from its older base). This moves that fix into a named function with its own tests, as Agent VCS asked. - collisions.ts touchedBeyond(graph, below, mine, views): the files a view over below plus mine can lay out differently from below, or undefined when any of it moves lines. It counts mine and whatever mine depends on that below lacks, since a view's set is closed. Project.#agentView's shareFiles uses it. - touched-beyond.test.ts: a publish's tie writes no files, but it depends on the published change. Counted from version 0 its files include the changed file, which 235's count (the atoms alone) missed. A move beyond the base turns sharing off. - agent-views-shared.test.ts adds a merge-queue landing with a move, then more drafting in the moved-to file. Checks: typescript-rs adopted fresh, diff for cloud-ts-01 matches replay (it differs on 235). Every worker/project test (341 of 341) and every engine test; tsc and biome clean.Compare305/**
306 * The files a view over `below` plus `mine` can lay out differently from `below` (abso Capacity, View.shareFiles), or
capacity266A draft that moves lines shares its base's layouts too (abso Capacity, issue 664). touchedBeyond gave up on any draft with moves, so such an agent's view shared nothing with its base: it laid out every file, took no author totals, compared every file to mark what it changed, and its file list walked every file the graph ever had, laying each out (and, dropping the absent ones again, re-laying them on every call). View.placedDifferently now says where the two views place a moved line differently (a different relocation wins, or a different parent), in either view; besides the files the draft's atoms name, those are the only files its moves can change, since a line's descendants follow it. touchedBeyond adds them, and gives up only when a view resolves its moves in scratch. On typescript-rs (Testing's fresh 262 adoption, cloud-ts-01, a draft with two moving atoms; my machine): the draft now touches 3 files. Agent tree with authors 432 ms first and 19 ms again (2.7 s and 579 ms before); agent folder blame 388 ms and 14 ms (1.7 s and 525 ms); agent files 374 ms and 0 ms (1.5 s and 350 ms). Exactness: the tests with drafts that move lines (agent-views-shared's fay, author-totals' fay, known-paths' dee, moves, touched-beyond) compare every read against the in-memory project. All of src/engine/test (294) and worker/project/test (354) pass.Compare307 * undefined when any of it moves lines and `placedDifferently` can't say where those land differently. A view's set is closed under dependencies, so it holds `mine` and whatever
capacity237touchedBeyond, with named tests for 235's wrong draft diff (disk-first 2; abso Capacity). 236 fixed the wrong diff Disk-first Testing found on typescript-rs with 235 (cloud-ts-01's diff showed lib.rs and passes.rs from its older base). This moves that fix into a named function with its own tests, as Agent VCS asked. - collisions.ts touchedBeyond(graph, below, mine, views): the files a view over below plus mine can lay out differently from below, or undefined when any of it moves lines. It counts mine and whatever mine depends on that below lacks, since a view's set is closed. Project.#agentView's shareFiles uses it. - touched-beyond.test.ts: a publish's tie writes no files, but it depends on the published change. Counted from version 0 its files include the changed file, which 235's count (the atoms alone) missed. A move beyond the base turns sharing off. - agent-views-shared.test.ts adds a merge-queue landing with a move, then more drafting in the moved-to file. Checks: typescript-rs adopted fresh, diff for cloud-ts-01 matches replay (it differs on 235). Every worker/project test (341 of 341) and every engine test; tsc and biome clean.Compare308 * `mine` depends on that `below` lacks; each of those can change a file, so all of them count. Counting `mine` alone
309 * missed the files of work the draft depends on (Testing's typescript-rs diff for cloud-ts-01, core 235).
310 */
311export function touchedBeyond(
312 g: Graph,
313 below: ReadonlySet<AtomId>,
314 mine: Iterable<AtomId>,
315 views: readonly ReadView[],
capacity266A draft that moves lines shares its base's layouts too (abso Capacity, issue 664). touchedBeyond gave up on any draft with moves, so such an agent's view shared nothing with its base: it laid out every file, took no author totals, compared every file to mark what it changed, and its file list walked every file the graph ever had, laying each out (and, dropping the absent ones again, re-laying them on every call). View.placedDifferently now says where the two views place a moved line differently (a different relocation wins, or a different parent), in either view; besides the files the draft's atoms name, those are the only files its moves can change, since a line's descendants follow it. touchedBeyond adds them, and gives up only when a view resolves its moves in scratch. On typescript-rs (Testing's fresh 262 adoption, cloud-ts-01, a draft with two moving atoms; my machine): the draft now touches 3 files. Agent tree with authors 432 ms first and 19 ms again (2.7 s and 579 ms before); agent folder blame 388 ms and 14 ms (1.7 s and 525 ms); agent files 374 ms and 0 ms (1.5 s and 350 ms). Exactness: the tests with drafts that move lines (agent-views-shared's fay, author-totals' fay, known-paths' dee, moves, touched-beyond) compare every read against the in-memory project. All of src/engine/test (294) and worker/project/test (354) pass.Compare316 placedDifferently?: () => ReadonlySet<string> | undefined,
capacity237touchedBeyond, with named tests for 235's wrong draft diff (disk-first 2; abso Capacity). 236 fixed the wrong diff Disk-first Testing found on typescript-rs with 235 (cloud-ts-01's diff showed lib.rs and passes.rs from its older base). This moves that fix into a named function with its own tests, as Agent VCS asked. - collisions.ts touchedBeyond(graph, below, mine, views): the files a view over below plus mine can lay out differently from below, or undefined when any of it moves lines. It counts mine and whatever mine depends on that below lacks, since a view's set is closed. Project.#agentView's shareFiles uses it. - touched-beyond.test.ts: a publish's tie writes no files, but it depends on the published change. Counted from version 0 its files include the changed file, which 235's count (the atoms alone) missed. A move beyond the base turns sharing off. - agent-views-shared.test.ts adds a merge-queue landing with a move, then more drafting in the moved-to file. Checks: typescript-rs adopted fresh, diff for cloud-ts-01 matches replay (it differs on 235). Every worker/project test (341 of 341) and every engine test; tsc and biome clean.Compare317): Set<string> | undefined {
318 const beyond = new Set<AtomId>();
319 const stack = [...mine];
320 while (stack.length) {
321 const id = stack.pop()!;
322 if (beyond.has(id) || below.has(id)) continue;
323 beyond.add(id);
324 for (const dep of g.atom(id).deps) if (!beyond.has(dep) && !below.has(dep)) stack.push(dep);
325 }
capacity266A draft that moves lines shares its base's layouts too (abso Capacity, issue 664). touchedBeyond gave up on any draft with moves, so such an agent's view shared nothing with its base: it laid out every file, took no author totals, compared every file to mark what it changed, and its file list walked every file the graph ever had, laying each out (and, dropping the absent ones again, re-laying them on every call). View.placedDifferently now says where the two views place a moved line differently (a different relocation wins, or a different parent), in either view; besides the files the draft's atoms name, those are the only files its moves can change, since a line's descendants follow it. touchedBeyond adds them, and gives up only when a view resolves its moves in scratch. On typescript-rs (Testing's fresh 262 adoption, cloud-ts-01, a draft with two moving atoms; my machine): the draft now touches 3 files. Agent tree with authors 432 ms first and 19 ms again (2.7 s and 579 ms before); agent folder blame 388 ms and 14 ms (1.7 s and 525 ms); agent files 374 ms and 0 ms (1.5 s and 350 ms). Exactness: the tests with drafts that move lines (agent-views-shared's fay, author-totals' fay, known-paths' dee, moves, touched-beyond) compare every read against the in-memory project. All of src/engine/test (294) and worker/project/test (354) pass.Compare326 const files = touchedFiles(g, beyond, views);
327 // Moves change more than the files their atoms name only where a moved line lands differently (View.placedDifferently,
328 // abso Capacity); without that comparison, a draft that moves lines shares nothing.
329 if ([...beyond].some((id) => (g.atom(id).moves?.length ?? 0) > 0)) {
330 const placed = placedDifferently?.();
331 if (!placed) return undefined;
332 for (const file of placed) files.add(file);
333 }
334 return files;
capacity237touchedBeyond, with named tests for 235's wrong draft diff (disk-first 2; abso Capacity). 236 fixed the wrong diff Disk-first Testing found on typescript-rs with 235 (cloud-ts-01's diff showed lib.rs and passes.rs from its older base). This moves that fix into a named function with its own tests, as Agent VCS asked. - collisions.ts touchedBeyond(graph, below, mine, views): the files a view over below plus mine can lay out differently from below, or undefined when any of it moves lines. It counts mine and whatever mine depends on that below lacks, since a view's set is closed. Project.#agentView's shareFiles uses it. - touched-beyond.test.ts: a publish's tie writes no files, but it depends on the published change. Counted from version 0 its files include the changed file, which 235's count (the atoms alone) missed. A move beyond the base turns sharing off. - agent-views-shared.test.ts adds a merge-queue landing with a move, then more drafting in the moved-to file. Checks: typescript-rs adopted fresh, diff for cloud-ts-01 matches replay (it differs on 235). Every worker/project test (341 of 341) and every engine test; tsc and biome clean.Compare335}
init0Start the project337/** The atom's visible lines in a file of a view, or where it acted when none are left. */
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare338export function describeSide(view: ReadView, atom: AtomId, file: string, keys: readonly string[]): CollisionSide {
init0Start the project339 const visible = view.lines(file);
340 let first = -1;
341 let lastLine = -1;
342 visible.forEach((line, i) => {
343 if (line.atom === atom) {
344 if (first < 0) first = i;
345 lastLine = i;
346 }
347 });
348 if (first >= 0) {
349 return { lines: [first + 1, lastLine + 1], text: joinLines(visible.slice(first, lastLine + 1).map((l) => l.text)) };
350 }
351 // No lines of its own here (a deletion): point at where the first key sits.
352 let at = 1;
353 const { node } = parseKey(keys[0]!);
354 if (!node.startsWith("^")) {
355 const sequence = view.sequence(file);
356 const index = view.sequenceIndex(file, node);
357 at = 1 + sequence.slice(0, Math.max(index, 0)).filter((l) => l.visible).length;
358 }
359 return { lines: [at, at - 1], text: "" };
362/** What origin, open pairs and duplicate-name collisions need from a project. */
363export interface CollisionHost {
364 readonly graph: Graph;
365 readonly spaces: ReadonlyMap<string, Space>;
366 version(): number;
367 spaceOf(agent: AgentState): Space;
codex-capacity-chair142Avoid full-base membership copies during collision checksCompare368 agentSet(agent: AgentState): ReadonlySet<AtomId>;
init0Start the project369 draft(agent: AgentState): AtomId[];
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare370 agentView(agent: AgentState): ReadView;
init0Start the project371 at(space: Space, version: number): ReadonlySet<AtomId>;
372 shared(): Space;
375/** Who published an atom, looking in the given space first and then in shared. */
376export function originOf(host: CollisionHost, atom: AtomId, spaceName: string): Origin {
377 for (const name of [spaceName, SHARED]) {
378 const space = host.spaces.get(name)!;
379 const version = space.publishedIn.get(atom);
380 if (version === undefined) continue;
381 const p = space.versions[version]!;
382 return { agent: p.agent, message: p.message, version, ...(name !== SHARED ? { draft: name } : {}) };
383 }
384 return { agent: host.graph.atom(atom).author, message: "", version: host.version() };
387/**
388 * Draft changes that build on atoms a set doesn't have (a drop took them
389 * out): the files they touch. Those changes can't move onto that set.
390 */
391export function strandedFiles(g: Graph, draft: readonly AtomId[], set: ReadonlySet<AtomId>): string[] {
392 const mine = new Set(draft);
393 const files = new Set<string>();
394 for (const id of draft) {
395 if (g.atom(id).deps.some((d) => !set.has(d) && !mine.has(d))) for (const f of g.filesOf(id)) files.add(f);
396 }
397 return [...files].toSorted();
400/**
401 * Names the agent's draft defines at the top level of a file where other
402 * work defines them too, so they are defined twice there (#25, Fuzzer).
403 */
404export function duplicateCollisions(host: CollisionHost, agent: AgentState): Collision[] {
405 const draft = host.draft(agent);
406 if (draft.length === 0) return [];
407 const mine = new Set(draft);
408 const view = host.agentView(agent);
409 const space = host.spaceOf(agent);
410 const out: Collision[] = [];
411 for (const file of [...touchedFiles(host.graph, draft, [view])].toSorted()) {
412 if (!view.hasFile(file)) continue;
413 for (const [name, defs] of definedTwice(view, file)) {
414 const yours = defs.find((d) => d.lines.some((l) => mine.has(host.graph.line(l)!.atom)));
415 const theirs = defs.find((d) => d.lines.every((l) => !mine.has(host.graph.line(l)!.atom)));
416 if (!yours || !theirs) continue;
417 const by = host.graph.line(theirs.lines[0]!)!.atom;
418 out.push({
419 kind: "duplicate",
420 name,
421 file,
pinch78Biome is silent: about 90 hints cleared. String joins as templates, dotted keys, unused imports, variables and a private method removed, optional chains (one kept boolean with === true), the preset field instead of the deprecated recommended. Two rules off where they don't fit: noExplicitAny in the hook modules, whose engine types come from the host, and noTemplateCurlyInString in tests, which hold source text as data.Compare422 yours: { lines: [yours.start + 1, yours.end], text: `${yours.text}\n` },
423 theirs: { lines: [theirs.start + 1, theirs.end], text: `${theirs.text}\n`, ...originOf(host, by, space.name) },
init0Start the project424 });
425 }
426 }
427 return out;
430/**
431 * Collisions the agent has synced into and not settled: its draft against
432 * its space at its base. In a named draft, also the draft's own changes
433 * against shared work the draft was moved onto.
434 */
435export function openPairs(host: CollisionHost, agent: AgentState): Pair[] {
436 const space = host.spaceOf(agent);
437 const set = host.agentSet(agent);
codex-capacity-chair142Avoid full-base membership copies during collision checksCompare438 const mine = new StableOverlaySet(agent.mine);
init0Start the project439 const out: Pair[] = [];
440 const draft = host.draft(agent);
441 if (draft.length > 0) {
codex-capacity-chair142Avoid full-base membership copies during collision checksCompare442 const seen = differenceSet(host.at(space, agent.base), mine);
init0Start the project443 out.push(...pairsIn(host.graph, draft, seen, set));
444 }
445 if (space.name !== SHARED) {
446 const shared = host.shared();
447 const pending = [...space.own].filter((id) => set.has(id) && !shared.own.has(id));
448 const sharedSeen = new Set([...set].filter((id) => shared.own.has(id)));
449 out.push(...pairsIn(host.graph, pending, sharedSeen, set));
450 }
451 return out;