- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/draft-collisions.ts --json
- JSON
- /christopher/abso-core/blame/worker/project/draft-collisions.ts?format=json
234 linesFirst import 58% · capacity 39% · codex-capacity-chair 2% · pinch 1%Last change capacity in version 249,
234 lines from 12 changes in 7 versions.
init0Start the project1// Whether agents' unpublished changes would collide (#41, F22), read through DraftCollisionHost; today the host
2// is the project in memory.
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare4import { type AtomId, type Graph, parseKey, type ReadView } from "../../src/engine/index.ts";
capacity246Collisions step 2: shared with drafts on top is a kept view that borrows shared's layouts (abso Capacity, issue 664).
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).Compare5import { StableSet } from "../../src/engine/state-source.ts";
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 changesCompare6import { claimantsAmong, describeSide, fileOfKey, pairsFrom } from "./collisions.ts";
8import { type Definition, definedTwice } from "./definitions.ts";
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare9import { definitionsBytes, type KeptParts } from "./kept-parts.ts";
11import type { CollisionSide, DraftCollision } from "./project-types.ts";
12import { last, SHARED, type Space } from "./spaces.ts";
14interface Agent {
15 readonly name: string;
16 readonly space: string;
17}
19/** What the draft collision read needs from a project. */
20export interface DraftCollisionHost {
21 readonly graph: Graph;
22 readonly agents: ReadonlyMap<string, Agent>;
23 needInit(): void;
24 shared(): Space;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare25 sharedView(): ReadView;
27 draft(agent: Agent): AtomId[];
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare28 agentView(agent: Agent): ReadView;
capacity246Collisions step 2: shared with drafts on top is a kept view that borrows shared's layouts (abso Capacity, issue 664).
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).Compare29 /** Shared now with these agents' drafts on top. */
30 draftsView(agents: readonly Agent[]): ReadView;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare31 touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare32 /** What collisions keep between calls (kept-parts.ts), when the project keeps any. */
33 keptParts?(): KeptParts | undefined;
34 /** A key naming everything a draft's part of the answer depends on: shared's version, its base and its atoms. */
35 draftKey(agent: Agent): string;
38/**
39 * Whether agents' unpublished changes would collide (#41, F22), by the
40 * publish rule: for each pair of agents working in shared, one agent's
41 * changes as if published on shared now, then the other's checked against
42 * them, both ways round. Same lines, a definition one changes that the
43 * other's new lines use, the same attribute, and a name both define at the
44 * top of a file (refused once the second syncs onto the first's work). Exact for shared at `version`; as shared moves on, so can
45 * the answer, as a real publish's would. `file` or `folder` narrows it.
46 */
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity).
On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s.
- Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts.
- View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again.
- The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well.
On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view.
Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare47/**
48 * A set and some drafts' atoms, by lookup (abso Capacity): copying shared's atoms into a new set read every one of them
49 * from disk on a stored writer, once per pair of agents.
50 */
51class WithDrafts extends StableSet<AtomId> {
52 readonly retainedBytes: number;
53 readonly #base: ReadonlySet<AtomId>;
54 readonly #drafts: ReadonlySet<AtomId>;
55 constructor(base: ReadonlySet<AtomId>, drafts: Iterable<AtomId>) {
56 super();
57 this.#base = base;
58 this.#drafts = new Set(drafts);
59 this.retainedBytes = 64 + this.#drafts.size * 32;
60 }
61 has(atom: AtomId): boolean {
62 return this.#drafts.has(atom) || this.#base.has(atom);
63 }
64 *values(): SetIterator<AtomId> {
65 yield* this.#base;
66 for (const atom of this.#drafts) if (!this.#base.has(atom)) yield atom;
67 }
68}
71 host: DraftCollisionHost,
72 options: { file?: string; folder?: string } = {},
73): {
74 version: number;
75 agents: string[];
76 collisions: DraftCollision[];
77} {
78 host.needInit();
79 const working = [...host.agents.values()]
80 .filter((a) => a.space === SHARED && host.draft(a).length > 0)
81 .toSorted((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
82 const shared = host.shared().own;
83 const sharedView = host.sharedView();
84 const out: DraftCollision[] = [];
85 const side = (agent: string, file: string, s: CollisionSide) => ({ agent, file, lines: s.lines, text: s.text });
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 changesCompare86 // Every draft change's claimants among all the drafts, found once (abso Capacity): a stored atom's keys are read
87 // from disk, and a draft deleting a big file has thousands, read again for every other agent.
88 let claimants: ReadonlyMap<AtomId, readonly AtomId[]> | undefined;
89 const claimantsOf = (agent: Agent): ReadonlyMap<AtomId, readonly AtomId[]> => {
90 claimants ??= claimantsAmong(
91 host.graph,
92 working.flatMap((a) => host.draft(a)),
93 );
94 const all = claimants;
95 return new Map(host.draft(agent).map((id) => [id, all.get(id) ?? []]));
96 };
97 // One set per draft, so the definition rule keeps what it worked out about it (abso Capacity).
98 const draftSets = new Map<Agent, ReadonlySet<AtomId>>();
99 const draftSet = (agent: Agent) => {
100 let set = draftSets.get(agent);
101 if (!set) draftSets.set(agent, (set = new Set(host.draft(agent))));
102 return set;
103 };
capacity246Collisions step 2: shared with drafts on top is a kept view that borrows shared's layouts (abso Capacity, issue 664).
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).Compare104 // Shared now with each agent's draft on top (project.ts, draftsView): kept between calls while shared and the
105 // draft stay the same, and laid out as shared is for every file the draft doesn't touch (abso Capacity).
106 const nowViewOf = (agent: Agent) => host.draftsView([agent]);
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare107 // Each draft's uses and changed definitions, and each pair's names defined twice, kept between calls (kept-parts.ts,
108 // abso Capacity): what this call doesn't use is dropped at its end.
109 const parts = host.keptParts?.();
110 const keys = new Map<Agent, string>();
111 const keyOf = (agent: Agent) => {
112 let key = keys.get(agent);
113 if (key === undefined) keys.set(agent, (key = host.draftKey(agent)));
114 return key;
115 };
116 parts?.startRound();
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 changesCompare117 // Each agent's touched files once, not once per pair (abso Capacity).
118 const touched = new Map<Agent, Set<string>>();
119 const touchedBy = (agent: Agent) => {
120 let files = touched.get(agent);
121 if (!files) touched.set(agent, (files = host.touchedFiles(host.draft(agent), [host.agentView(agent)])));
122 return files;
123 };
125 for (let j = 0; j < working.length; j++) {
126 if (i === j) continue;
127 const a = working[i]!;
128 const b = working[j]!;
129 const draftA = host.draft(a);
130 const draftB = host.draft(b);
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 changesCompare131 const newer = draftSet(a);
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity).
On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s.
- Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts.
- View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again.
- The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well.
On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view.
Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare132 const union = new WithDrafts(shared, [...draftA, ...draftB]);
134 const viewB = host.agentView(b);
135 if (i < j) {
136 // Lines and attributes: the same either way round, so once per pair.
137 const paired = new Set<string>();
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 changesCompare138 for (const pair of pairsFrom(host.graph, claimantsOf(b), newer, union)) {
140 const file = fileOfKey(pair.keys[0]!.key, viewB);
141 const fileKeys = pair.keys.filter((k) => fileOfKey(k.key, viewB) === file).map((k) => k.key);
142 const attrs = fileKeys.map((k) => parseKey(k)).filter((k) => k.kind === "attr");
143 const fileA = viewA.hasFile(file) ? file : fileOfKey(pair.keys[0]!.key, viewA);
144 if (attrs.length === fileKeys.length) {
145 const name = attrs[0]!.attr!;
146 const valueOf = (atom: AtomId) =>
147 (host.graph.atom(atom).attrs ?? []).find((x) => x.file === file && x.name === name)?.value ?? "";
148 out.push({
149 kind: "attribute",
150 name,
151 file,
152 first: { agent: a.name, file, lines: [1, 0], text: valueOf(pair.theirs) },
153 second: { agent: b.name, file, lines: [1, 0], text: valueOf(pair.yours) },
154 });
155 } else {
156 out.push({
157 kind: "lines",
158 file,
159 first: side(a.name, fileA, describeSide(viewA, pair.theirs, fileA, fileKeys)),
160 second: side(b.name, file, describeSide(viewB, pair.yours, file, fileKeys)),
161 });
162 }
163 }
164 // A name both define at the top level of one file: what the second meets once it syncs onto the
165 // first's work, as the publish rule checks it then. Not when the two definitions are one lines collision.
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 changesCompare166 // The union's view only when the two share a file (abso Capacity): laying out shared plus both drafts
167 // cost a few seconds a pair on a stored writer.
168 let both: ReadView | undefined;
170 const mineB = new Set(draftB);
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 changesCompare171 const filesA = touchedBy(a);
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare172 const twiceIn = (file: string): ReadonlyMap<string, Definition[]> => {
173 const make = () => {
174 both ??= host.draftsView([a, b]);
175 return both.hasFile(file) ? definedTwice(both, file) : new Map<string, Definition[]>();
176 };
177 return parts ? parts.get(`twice ${keyOf(a)} | ${keyOf(b)} ${file}`, make, definitionsBytes) : make();
178 };
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 changesCompare179 for (const file of [...touchedBy(b)].filter((f) => filesA.has(f)).toSorted()) {
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare180 for (const [name, defs] of twiceIn(file)) {
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity).
On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s.
- Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts.
- View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again.
- The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well.
On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view.
Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare181 const by = (mine: Set<AtomId>) => defs.find((d) => d.lines.some((l) => mine.has(host.graph.lineAtom(l)!)));
183 const dB = by(mineB);
184 if (!dA || !dB || dA === dB) continue;
185 const atomsOf = (d: Definition, mine: Set<AtomId>) =>
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity).
On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s.
- Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts.
- View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again.
- The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well.
On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view.
Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare186 d.lines.map((l) => host.graph.lineAtom(l)!).filter((x) => mine.has(x));
init0Start the project187 if (atomsOf(dA, mineA).some((x) => atomsOf(dB, mineB).some((y) => paired.has(`${x} ${y}`)))) continue;
188 out.push({
189 kind: "duplicate",
190 name,
191 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.Compare192 first: { agent: a.name, file, lines: [dA.start + 1, dA.end], text: `${dA.text}\n` },
193 second: { agent: b.name, file, lines: [dB.start + 1, dB.end], text: `${dB.text}\n` },
195 }
196 }
197 }
198 // Definitions: b's new lines use a name whose definition a's changes change.
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 changesCompare199 const nowView = () => nowViewOf(a);
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare200 const kept = parts ? { parts, uses: keyOf(b), changed: keyOf(a) } : undefined;
201 for (const d of host.definitionRule().collisions(draftSet(b), viewB, sharedView, nowView, newer, SHARED, kept)) {
203 out.push({
204 kind: "definition",
205 name: c.name!,
206 file: c.file,
207 first: { agent: a.name, file: c.theirs.file ?? c.file, lines: c.theirs.lines, text: c.theirs.text },
208 second: side(b.name, c.file, c.yours),
209 });
210 }
211 }
212 }
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare213 parts?.endRound();
init0Start the project214 const fileKey = options.file !== undefined ? pathKey(options.file) : undefined;
215 const folderParts =
216 options.folder !== undefined ? options.folder.split("/").filter((s) => s !== "" && s !== ".") : undefined;
217 const under = (path: string): boolean => {
218 if (fileKey !== undefined && pathKey(path) !== fileKey) return false;
219 if (folderParts !== undefined && folderParts.length > 0) {
220 const parts = path.split("/");
221 if (
222 parts.length <= folderParts.length ||
223 pathKey(parts.slice(0, folderParts.length).join("/")) !== pathKey(folderParts.join("/"))
224 )
225 return false;
226 }
227 return true;
228 };
229 const narrowed =
230 fileKey === undefined && folderParts === undefined
231 ? out
232 : out.filter((c) => under(c.first.file) || under(c.second.file));
233 return { version: last(host.shared()), agents: working.map((a) => a.name), collisions: narrowed };
234}