Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 309 to 318

Compare

+370 −115 in 37 places
Lines 1524–1562 at 318 (were 1524–1566 at 309)
15241524 * the search never descends below the target's lamport.
15251525 */
15261526 #reaches(from: Iterable<AtomId>, target: AtomId): boolean {
1527− const floor = this.#lamportAt(this.#seq(target));
1528− if (this.#storage) {
1529− return this.withProjectionScratch((scratch) => {
1530− let length = 0;
1531− const push = (id: AtomId): void => {
1532− if (scratch.read("seen", id)) return;
1533− scratch.write("seen", id, true);
1534− scratch.write("stack", String(length++), id);
1535− };
1536− for (const id of from) {
1537− if (id === target) return true;
1538− if (this.#lamportAt(this.#seq(id)) > floor) push(id);
1539− }
1540− while (length > 0) {
1541− const key = String(--length);
1542− const current = scratch.read("stack", key) as AtomId;
1543− scratch.remove("stack", key);
1544− if (this.#lamportAt(this.#seq(current)) <= floor) continue;
1545− for (const dependency of this.atom(current).deps) {
1546− if (dependency === target) return true;
1547− push(dependency);
1548− }
1549− }
1550− return false;
1551− });
1527+ return this.#reachable(from, new Set([target])).has(target);
1528+ }
1530+ /**
1531+ * Which of `targets` are reachable along deps from any of `from` (themselves included), in one walk: it never
1532+ * descends below the lowest target's lamport, and stops once every target is found (abso 714, piece 4: record
1533+ * walked once per line writer).
1534+ * The walk's seen marks and stack are in memory, by atom number: one byte and four bytes an atom at most, so about
1535+ * 62 KB on abso's 12,454 atoms and 50 MB at 10 million, under a Worker's 128 MB. They were scratch rows in storage
1536+ * (abso-core 139, bounding memory with the graph), which cost a read and a write per atom visited: on abso's Oct 14
1537+ * tables, 41,000 of a 1470-shaped record's 77,767 statements.
1538+ */
1539+ #reachable(from: Iterable<AtomId>, targets: ReadonlySet<AtomId>): Set<AtomId> {
1540+ const found = new Set<AtomId>();
1541+ let floor = Number.POSITIVE_INFINITY;
1542+ for (const target of targets) floor = Math.min(floor, this.#lamportAt(this.#seq(target)));
1543+ const seen = new Uint8Array(this.#atoms.length);
1544+ const stack = new Int32Array(this.#atoms.length);
1545+ let length = 0;
1546+ const visit = (id: AtomId): void => {
1547+ if (targets.has(id)) found.add(id);
1548+ const seq = this.#seq(id);
1549+ if (seen[seq]) return;
1550+ seen[seq] = 1;
1551+ stack[length++] = seq;
1552+ };
1553+ for (const id of from) visit(id);
1554+ while (length > 0 && found.size < targets.size) {
1555+ const seq = stack[--length]!;
1556+ if (this.#lamportAt(seq) <= floor) continue;
1557+ for (const dependency of this.atom(atomId(seq)).deps) visit(dependency);
15521558 }
1553− const seen = new Set<AtomId>();
1554− const stack = [...from];
1555− while (stack.length > 0) {
1556− const cur = stack.pop()!;
1557− if (cur === target) return true;
1558− if (seen.has(cur)) continue;
1559− seen.add(cur);
1560− if (this.#lamportAt(this.#seq(cur)) <= floor) continue;
1561− for (const d of this.atom(cur).deps) if (!seen.has(d)) stack.push(d);
1562− }
1563− return false;
1559+ return found;
15641560 }
15651561
15661562 /**
Lines 1606–1633 at 318 (were 1610–1632 at 309)
16101606 for (const r of atom.reasons) if (!this.has(r.to)) bad(`reason points at unknown atom ${r.to}`);
16111607
16121608 // Everything it touches must come from its closure. Derived deps name the
1613− // writers directly, so this is usually one lookup per writer.
1614− const memoryBelow = scratch ? undefined : new Map<AtomId, boolean>();
1615− const below = {
1616− get: (key: AtomId) => (scratch ? (scratch.read("below", key) as boolean | undefined) : memoryBelow!.get(key)),
1617− set: (key: AtomId, value: boolean) => {
1618− if (scratch) scratch.write("below", key, value);
1619− else memoryBelow!.set(key, value);
1620− },
1621− };
1622− const inClosure = (writer: AtomId): boolean => {
1623− let hit = below.get(writer);
1624− if (hit === undefined) {
1625− hit = deps.has(writer) || this.#reaches(atom.deps, writer);
1626− below.set(writer, hit);
1609+ // writers directly, so this is usually one lookup per writer. The writers
1610+ // that aren't deps are walked for together, once (abso 714, piece 4).
1611+ const touched: LineId[] = [];
1612+ for (const run of atom.inserts) if (!isStartNode(run.parent)) touched.push(run.parent);
1613+ for (const m of atom.moves ?? []) {
1614+ touched.push(m.line);
1615+ if (!isStartNode(m.parent)) touched.push(m.parent);
1616+ }
1617+ touched.push(...atom.deletes);
1618+ for (const list of [atom.writes, atom.reads, atom.holds])
1619+ for (const key of list) {
1620+ const parsed = parseKey(key);
1621+ if (parsed.kind === "line" || ((parsed.kind === "gap" || parsed.kind === "pos") && !isStartNode(parsed.node)))
1622+ touched.push(parsed.node);
16271623 }
1628− return hit;
1629− };
1624+ const beyond = new Set<AtomId>();
1625+ for (const line of touched) {
1626+ const writer = this.lineAtom(line);
1627+ if (writer !== undefined && !deps.has(writer)) beyond.add(writer);
1628+ }
1629+ const reached = beyond.size > 0 ? this.#reachable(atom.deps, beyond) : beyond;
1630+ const inClosure = (writer: AtomId): boolean => deps.has(writer) || reached.has(writer);
16301631 const checkLine = (line: LineId, what: string): void => {
16311632 const writer = this.lineAtom(line);
16321633 if (writer === undefined) return bad(`${what} names unknown line ${line}`);
Lines 10–16 at 318 (were 10–16 at 309)
1010// made when a caller asks for them, and the latest asked for is kept.
1111
1212import type { Graph, RelocationInfo } from "./graph.ts";
13−import { isStartNode, lineId, seqOf } from "./keys.ts";
13+import { atomId, isStartNode, lineId, seqOf } from "./keys.ts";
1414import { resolveScratchMoves, scratchLayoutNodes } from "./relocation-scratch.ts";
1515import { isClosedSet, StableSet } from "./state-source.ts";
1616import { joinLines } from "./text.ts";
Lines 1095–1108 at 318 (were 1095–1101 at 309)
10951095 }
10961096
10971097 *lineChunks(path: string): IterableIterator<() => Iterable<string>> {
1098− for (const n of this.#file(path).vis) yield () => this.graph.textChunks(n);
1098+ // The texts the packed layout already holds, read a page at a time (abso Capacity, 714): a record's diff read each
1099+ // line's own row, 11,873 statements for abso's index.ts. Only a line too long to pack is read in chunks.
1100+ const { vis, visText } = this.#file(path);
1101+ for (let i = 0; i < vis.length; i++) {
1102+ const packed = visText?.[i];
1103+ if (packed != null) yield () => [packed];
1104+ else yield () => this.graph.textChunks(vis[i]!);
1105+ }
10991106 }
11001107
11011108 /** Visible lines without retaining their text in the view cache. */
Lines 1112–1118 at 318 (were 1105–1111 at 309)
11051112 yield {
11061113 id: graph.lineIdOf(n),
11071114 text: graph.textOf(n),
1108− atom: graph.idOfSeq(graph.writerSeqOf(n)),
1115+ atom: atomId(graph.writerSeqOf(n)),
11091116 };
11101117 }
11111118
Lines 1126–1137 at 318 (were 1119–1130 at 309)
11191126 const n = vis[i]!;
11201127 const packed = visText?.[i];
11211128 lines[i] = {
1122− id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
1129+ id: visWriter && visK ? lineId(atomId(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
11231130 textChunks: () => graph.textChunks(n),
11241131 get text() {
11251132 return packed ?? graph.textOf(n);
11261133 },
1127− atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
1134+ atom: atomId(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
11281135 };
11291136 }
11301137 return lines;
Lines 1143–1156 at 318 (were 1136–1147 at 309)
11361143 const graph = this.graph;
11371144 const { vis, visText, visWriter, visK } = this.#file(path);
11381145 const lines: VisibleLine[] = new Array(vis.length);
1146+ // Writer seqs come from the graph's own layout, so they're named with atomId, not checked by idOfSeq (abso 738):
1147+ // on a stored graph its check read the atom count once a line, about 0.9 s of a warm draft-state on abso.
11391148 for (let i = 0; i < vis.length; i++) {
11401149 const n = vis[i]!;
11411150 lines[i] = {
1142− id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
1151+ id: visWriter && visK ? lineId(atomId(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
11431152 text: visText?.[i] ?? graph.textOf(n),
1144− atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
1153+ atom: atomId(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
11451154 };
11461155 }
11471156 this.#linesCache = { path, lines };
Lines 1172–1184 at 318 (were 1163–1175 at 309)
11631172 const writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n);
11641173 let text: string | undefined;
11651174 out[i] = {
1166− id: seqWriter && seqK ? lineId(graph.idOfSeq(writer), seqK[i]!) : graph.lineIdOf(n),
1175+ id: seqWriter && seqK ? lineId(atomId(writer), seqK[i]!) : graph.lineIdOf(n),
11671176 get text() {
11681177 text ??= graph.textOf(n);
11691178 return text;
11701179 },
1171− atom: graph.idOfSeq(writer),
1172− deletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE,
1180+ atom: atomId(writer),
1181+ deletedBy: by ? by.map((s) => atomId(s)) : NONE,
11731182 visible: by === undefined,
11741183 };
11751184 }
Lines 68–74 at 318 (were 68–74 at 309)
6868 }
6969 for (const key of claimsOf(atom)) streams.push(g.eachWriterOf(key));
7070 const theirs: AtomId[] = [];
71− for (const id of orderedClaimants(g, streams)) if (against.has(id)) theirs.push(id);
71+ for (const id of orderedClaimants(streams)) if (against.has(id)) theirs.push(id);
7272 out.set(yours, theirs);
7373 }
7474 return out;
Lines 136–142 at 318 (were 136–142 at 309)
136136
137137/** Claim indexes append in canonical seq order. Merge one cursor per current
138138 * atom key, retaining no candidate set proportional to historical claims. */
139−function* orderedClaimants(g: Graph, streams: IterableIterator<AtomId>[]): IterableIterator<AtomId> {
139+function* orderedClaimants(streams: IterableIterator<AtomId>[]): IterableIterator<AtomId> {
140140 try {
141141 type Head = { id: AtomId; seq: number; stream: number };
142142 const heap: Head[] = [];
Lines 152–162 at 318 (were 152–160 at 309)
152152 }
153153 heap[at] = head;
154154 };
155+ // 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.
155157 const advance = (stream: number) => {
156158 const next = streams[stream]!.next();
157− if (!next.done) push({ id: next.value, seq: g.atom(next.value).seq, stream });
159+ if (!next.done) push({ id: next.value, seq: seqOf(next.value), stream });
158160 };
159161 for (let stream = 0; stream < streams.length; stream++) advance(stream);
160162 let previous = -1;
Lines 192–199 at 318 (were 190–197 at 309)
190192 let a = left.next();
191193 let b = right.next();
192194 while (!a.done && !b.done) {
193− const x = g.atom(a.value).seq;
194− const y = g.atom(b.value).seq;
195+ const x = seqOf(a.value);
196+ const y = seqOf(b.value);
195197 if (x === y && settled.has(a.value)) return true;
196198 if (x <= y) a = left.next();
197199 if (y <= x) b = right.next();
Lines 7–13 at 318 (were 7–13 at 309)
77import { type AtomId, type Graph, joinLines, type LineId, type ReadView } from "../../src/engine/index.ts";
88import { type Origin, touchedFiles } from "./collisions.ts";
99import { type Definition, definitionsIn, importsOf, usedNames } from "./definitions.ts";
10−import { definitionsBytes, type KeptParts, usesBytes } from "./kept-parts.ts";
10+import { definitionsBytes, filesBytes, type KeptParts, usesBytes } from "./kept-parts.ts";
1111import { codeOfLines, declaredIn, holdsNoCode } from "./names.ts";
1212import { definitionText } from "./news.ts";
1313import type { Collision } from "./project.ts";
Lines 37–43 at 318 (were 37–43 at 309)
3737 readonly parent: string;
3838}
3939
40−/** Definitions in the files newer work touched, before it and with it. */
40+/** Definitions in one file newer work touched, before it and with it. */
4141interface Changed {
4242 readonly baseDefs: ReturnType<typeof definitionsIn>;
4343 readonly nowDefs: ReturnType<typeof definitionsIn>;
Lines 52–62 at 318 (were 52–59 at 309)
5252 readonly #replacedCache = new Map<string, ReadonlySet<string>>();
5353 /** A draft's uses, kept while it is asked about with the same views: draft collisions ask once per other agent. */
5454 readonly #usesCache = new WeakMap<ReadonlySet<AtomId>, { view: ReadView; base: ReadView; uses: Uses }>();
55− /** The newer work's definitions before and after, kept while it is asked about with the same views. */
56− readonly #changedCache = new WeakMap<ReadonlySet<AtomId>, { base: ReadView; now: ReadView; defs: Changed }>();
55+ /** The files the newer work touched, kept while it is asked about with the same views. */
56+ readonly #touchedCache = new WeakMap<
57+ ReadonlySet<AtomId>,
58+ { base: ReadView; now: ReadView; files: ReadonlySet<string> }
59+ >();
5760
5861 constructor(graph: Graph, origin: (atom: AtomId, spaceName: string) => Origin) {
5962 this.#graph = graph;
Lines 125–135 at 318 (were 122–127 at 309)
122125 spaceName: string,
123126 kept?: { parts: KeptParts; uses: string; changed: string },
124127 names?: ReadonlySet<string>,
128+ /**
129+ * The files the newer work changed, when the caller knows them without placing its lines (land and draft-state:
130+ * shared's kept version files, abso 738); undefined, or one that answers undefined, and they're worked out here.
131+ */
132+ changedFiles?: () => ReadonlySet<string> | undefined,
125133 ): DefinitionCollision[] {
126134 if (draft.size === 0 || newer.size === 0) return [];
127135 const uses = kept
Lines 139–194 at 318 (were 131–161 at 309)
131139 // Only these names can collide (a publish's news, news.ts): a draft that uses none of them has none, and the
132140 // definitions changed since its base needn't be worked out.
133141 if (names && ![...uses.keys()].some((name) => names.has(name))) return [];
134− const nowOf = () => (typeof nowView === "function" ? nowView() : nowView);
135− const { baseDefs, nowDefs } = kept
136− ? kept.parts.get(
137− `changed ${kept.changed}`,
138− () => this.#changed(newer, baseView, nowOf()),
139− (c) => definitionsBytes(c.baseDefs) + definitionsBytes(c.nowDefs),
140− )
141− : this.#changedFor(newer, baseView, nowOf());
142− const out: DefinitionCollision[] = [];
143− for (const [name, where] of [...uses].sort(([a], [b]) => (a < b ? -1 : 1))) {
144− // Which definitions the uses mean: the file each use imports the name
145− // from, or its own file when it defines the name at the top level. A
146− // use with neither (a local, a parameter, a global, a name another
147− // language brings in some other way) means none: the rule only speaks
148− // when it knows which definition a use means.
142+ // Which definitions the uses mean: the file each use imports the name
143+ // from, or its own file when it defines the name at the top level. A
144+ // use with neither (a local, a parameter, a global, a name another
145+ // language brings in some other way) means none: the rule only speaks
146+ // when it knows which definition a use means.
147+ const scopes = new Map<string, ReadonlySet<string>>();
148+ for (const [name, where] of uses) {
149149 const scope = new Set<string>();
150150 for (const w of new Set(where.map((x) => x.file))) {
151151 const from = importsOf(view, w).get(name) ?? (definitionsIn(view, [w]).has(name) ? w : undefined);
152152 if (from !== undefined) scope.add(from);
153153 }
154− if (scope.size === 0) continue;
155− const inScope = (d: Definition): boolean => scope.has(d.file);
156− const before = baseDefs.get(name)?.filter(inScope);
157− if (!before?.length) continue; // not defined in what the drafter saw: nothing it relies on
158− const after = (nowDefs.get(name) ?? []).filter(inScope);
154+ if (scope.size > 0) scopes.set(name, scope);
155+ }
156+ if (scopes.size === 0) return [];
157+ const nowOf = () => (typeof nowView === "function" ? nowView() : nowView);
158+ // Only a file the newer work touched can hold a changed definition, and only one a use means can matter: just those
159+ // files are laid out, before and with the newer work (abso 738). Laying out every file the newer work touched cost
160+ // codex-prose-authorship-610's draft-state 494 files a view where its uses reach 7.
161+ const touched =
162+ changedFiles?.() ??
163+ (kept
164+ ? kept.parts.get(`touched ${kept.changed}`, () => this.#touched(newer, baseView, nowOf()), filesBytes)
165+ : this.#touchedFor(newer, baseView, nowOf()));
166+ const changed = new Map<string, Changed>();
167+ const changedIn = (file: string): Changed => {
168+ let c = changed.get(file);
169+ if (!c) {
170+ const make = (): Changed => ({
171+ baseDefs: definitionsIn(baseView, [file]),
172+ nowDefs: definitionsIn(nowOf(), [file]),
173+ });
174+ c = kept
175+ ? kept.parts.get(
176+ `changed ${kept.changed} ${file}`,
177+ make,
178+ (d) => definitionsBytes(d.baseDefs) + definitionsBytes(d.nowDefs),
179+ )
180+ : make();
181+ changed.set(file, c);
182+ }
183+ return c;
184+ };
185+ const out: DefinitionCollision[] = [];
186+ for (const [name, scope] of [...scopes].sort(([a], [b]) => (a < b ? -1 : 1))) {
187+ // In the order the newer work touched its files, as when every touched file was laid out.
188+ const files = [...touched].filter((f) => scope.has(f));
189+ const before = files.flatMap((f) => changedIn(f).baseDefs.get(name) ?? []);
190+ if (!before.length) continue; // not defined in what the drafter saw: nothing it relies on
191+ const after = files.flatMap((f) => changedIn(f).nowDefs.get(name) ?? []);
159192 if (signature(before) === signature(after)) continue;
160193 // Who changed it: newer writers of the new definition's lines, or newer deleters of the old one's.
161194 const by = new Set<AtomId>();
Lines 199–205 at 318 (were 166–171 at 309)
166199 const first = [...by].sort((p, q) => this.#graph.atom(p).seq - this.#graph.atom(q).seq)[0];
167200 if (first === undefined) continue;
168201 const origin = this.#origin(first, spaceName);
202+ const where = uses.get(name)!;
169203 const file = where[0]!.file;
170204 const indexes = where.filter((w) => w.file === file).map((w) => w.index);
171205 const lo = Math.min(...indexes);
Lines 239–257 at 318 (were 205–224 at 309)
205239 return kept.uses;
206240 }
207241
208− /** The newer work's definitions before and after, kept while it is asked about with the same views. */
209− #changedFor(newer: ReadonlySet<AtomId>, baseView: ReadView, now: ReadView): Changed {
210− let changed = this.#changedCache.get(newer);
211− if (!changed || changed.base !== baseView || changed.now !== now) {
212− changed = { base: baseView, now, defs: this.#changed(newer, baseView, now) };
213− this.#changedCache.set(newer, changed);
242+ /** The files the newer work touched, kept while it is asked about with the same views. */
243+ #touchedFor(newer: ReadonlySet<AtomId>, baseView: ReadView, now: ReadView): ReadonlySet<string> {
244+ let kept = this.#touchedCache.get(newer);
245+ if (!kept || kept.base !== baseView || kept.now !== now) {
246+ kept = { base: baseView, now, files: this.#touched(newer, baseView, now) };
247+ this.#touchedCache.set(newer, kept);
214248 }
215− return changed.defs;
249+ return kept.files;
216250 }
217251
218− /** Definitions in the files the newer work touched, before it and with it: only there can one have changed. */
219− #changed(newer: ReadonlySet<AtomId>, baseView: ReadView, now: ReadView): Changed {
220− const touched = touchedFiles(this.#graph, newer, [baseView, now]);
221− return { baseDefs: definitionsIn(baseView, touched), nowDefs: definitionsIn(now, touched) };
252+ /** The files the newer work touched, before it and with it: only there can a definition have changed. */
253+ #touched(newer: ReadonlySet<AtomId>, baseView: ReadView, now: ReadView): ReadonlySet<string> {
254+ return touchedFiles(this.#graph, newer, [baseView, now]);
222255 }
223256
224257 /** The names the draft's lines use and don't declare, less those the lines they replaced already used. */
Lines 62–90 at 318 (were 62–67 at 309)
6262 const g = host.graph;
6363 const mine = new Set(draft);
6464 const text = new MoveLineText(g);
65+ // The draft's own lines first, before laying out any file (abso 714, piece 3): a move needs a written line with
66+ // real content whose text the draft also deleted. An edit that only changes lines has none, and laying out its
67+ // files (12k lines twice for one changed line of worker/src/index.ts) cost the whole publish.
68+ const goneIds = new Set<LineId>();
69+ const goneTexts = new Set<number>();
70+ for (const id of draft)
71+ for (const line of g.deletedLines(id)) {
72+ goneIds.add(line);
73+ goneTexts.add(text.intern(line));
74+ }
75+ if (goneTexts.size === 0) return;
76+ let moved = false;
77+ for (const id of draft) {
78+ for (const line of g.eachInsertedLine(id)) {
79+ const t = text.intern(line);
80+ if (!text.plain[t] && goneTexts.has(t)) {
81+ moved = true;
82+ break;
83+ }
84+ }
85+ if (moved) break;
86+ }
87+ if (!moved) return;
6588 const after = host.agentView(agent);
6689 const before = host.beforeDraft
6790 ? host.beforeDraft(agent, draft)
Lines 104–111 at 318 (were 81–87 at 309)
81104 for (const file of [...touched].toSorted()) {
82105 let cur: Block | undefined;
83106 before.buildLines(file).forEach((l, i) => {
84− if (g.deletersOf(l.id).some((d) => mine.has(d))) {
107+ // Deleted by the draft: one of its atoms' deleted lines, with no lookup of each line's deleters.
108+ if (goneIds.has(l.id)) {
85109 if (!cur) gone.push((cur = { file, start: i, ids: [], texts: [] }));
86110 cur.ids.push(l.id);
87111 cur.texts.push(text.intern(l.id));
Lines 1–8 at 318 (were 1–8 at 309)
11// What draft collisions work out about each draft and each pair of drafts, kept between calls under a hard byte budget
2−// (abso Capacity, issue 664): the names a draft's new lines use, the definitions a draft's changes touch before and
3−// after, and the names a pair of drafts both define in a file. Keys name everything an entry depends on (shared's
4−// version, a draft's base and atoms), and a call drops every entry it didn't use, so a draft that changes, an agent that
5−// leaves and shared moving on all drop theirs at once.
2+// (abso Capacity, issue 664): the names a draft's new lines use, the files a draft's changes touch and the definitions
3+// in each before and after, and the names a pair of drafts both define in a file. Keys name everything an entry depends
4+// on (shared's version, a draft's base and atoms), and a call drops every entry it didn't use, so a draft that changes,
5+// an agent that leaves and shared moving on all drop theirs at once.
66
77import { stringBytes } from "../../src/engine/view.ts";
88import type { Definition } from "./definitions.ts";
Lines 100–109 at 318 (were 100–102 at 309)
100100 n += MAP_ENTRY_BYTES + stringBytes(name) + ARRAY_HEADER_BYTES + where.length * (REFERENCE_BYTES + OBJECT_BYTES);
101101 return n;
102102}
104+/** A set of paths (the files some work touched). */
105+export function filesBytes(files: ReadonlySet<string>): number {
106+ let n = MAP_HEADER_BYTES;
107+ for (const file of files) n += MAP_ENTRY_BYTES + stringBytes(file);
108+ return n;
109+}
Lines 29–36 at 318 (were 29–34 at 309)
2929 pairs(draft: readonly AtomId[], against: ReadonlySet<AtomId>, settled: ReadonlySet<AtomId>): Pair[];
3030 describe(pair: Pair, yoursView: ReadView, theirsView: ReadView, spaceName: string): Collision;
3131 definitionRule(): DefinitionRule;
32+ /** The files a space's versions after `from`, up to `to`, changed, when each one's are kept; else undefined. */
33+ changedSince(space: Space, from: number, to: number): ReadonlySet<string> | undefined;
3234 refuse(
3335 agent: AgentState,
3436 space: Space,
Lines 95–118 at 318 (were 93–103 at 309)
9395 ? host.viewAt(shared, sharedBaseOf(space), changes)
9496 : host.viewAt(space, space.versions.length - 1);
9597 const describeLand = (p: Pair): Collision => host.describe(p, draftView, host.sharedView(), SHARED);
98+ // Where shared changed since the draft's base, from the files each version since kept as it landed (abso 738): working
99+ // it out from the newer atoms placed every line they wrote or deleted, about 30% of a warm draft-state read.
100+ const changed = () => host.changedSince(shared, sharedBaseOf(space), host.version());
96101 const collisions = [
97102 ...host.pairs(changes, newer, union).map(describeLand),
98103 ...host
99104 .definitionRule()
100− .collisions(own, draftView, host.viewAt(shared, sharedBaseOf(space)), host.sharedView(), newer, SHARED)
105+ .collisions(
106+ own,
107+ draftView,
108+ host.viewAt(shared, sharedBaseOf(space)),
109+ host.sharedView(),
110+ newer,
111+ SHARED,
112+ undefined,
113+ undefined,
114+ changed,
115+ )
101116 .map((d) => d.collision),
102117 ];
103118 return { collisions, newer, union };
Lines 90–110 at 318 (were 90–95 at 309)
9090 return files && [...files].sort();
9191 }
9292
93+ /**
94+ * The files the versions after `from`, up to `to`, changed, from each version's kept row (abso 738): undefined when one
95+ * has none, and the caller works them out from the atoms. Every file whose text differs between the two versions is
96+ * in it, since some version between changed it.
97+ */
98+ keptChangesSince(space: Space, from: number, to: number): ReadonlySet<string> | undefined {
99+ const out = new Set<string>();
100+ for (let v = from + 1; v <= to; v++) {
101+ const files = this.#keptFiles(space, v);
102+ if (!files) return undefined;
103+ for (const f of files) out.add(f);
104+ }
105+ return out;
106+ }
93108 /** keptPaths as a set, kept for the newest version asked: never changed once made, so a view can hold it. */
94109 keptPathSet(space: Space, version: number): ReadonlySet<string> | undefined {
95110 let fold = this.#keptPaths.get(space);
Lines 155–162 at 318 (were 155–160 at 309)
155155 refusals(agent?: string, limit?: number): unknown;
156156 /** A file as it was at a version (#27). */
157157 fileAt(path: string, version: number, draft: string | null, agent?: string): unknown;
158+ /** fileAt for exactly this spelling, without the version's list of files (version-log.ts fileExactAt). */
159+ fileExactAt?(path: string, version: number, draft: string | null): unknown;
158160 /** Every file that differs between two versions (#27). */
159161 compare(from: number, to: number, draft: string | null, agent?: string, summary?: boolean): unknown;
160162 /** Version `version` of shared without the versions in `versions` (without.ts). */
Lines 222–228 at 318 (were 222–227 at 309)
222222 compare as versionCompare,
223223 compareSummary as versionCompareSummary,
224224 fileAt as versionFileAt,
225+ fileExactAt as versionFileExactAt,
225226 log as versionLog,
226227 ribbon as versionRibbon,
227228 show as versionShow,
Lines 2009–2019 at 318 (were 2008–2013 at 309)
20082009 return versionFileAt(this.#logHost, ...args);
20092010 }
20102011
2012+ /** fileAt for exactly this spelling, from the file's own lines: no list of the version's files (version-log.ts). */
2013+ fileExactAt(...args: Tail<Parameters<typeof versionFileExactAt>>): ReturnType<typeof versionFileExactAt> {
2014+ return versionFileExactAt(this.#logHost, ...args);
2015+ }
20112017 /** Every file that differs between two versions of shared (or a named draft) (version-log.ts). */
20122018 compare(...args: Tail<Parameters<typeof versionCompare>>): ReturnType<typeof versionCompare> {
20132019 return versionCompare(this.#logHost, ...args);
Lines 2499–2507 at 318 (were 2493–2498 at 309)
24932499 pairs: (draft, against, settled) => this.#pairs(draft, against, settled),
24942500 describe: (pair, yoursView, theirsView, spaceName) => this.#describe(pair, yoursView, theirsView, spaceName),
24952501 definitionRule: () => this.#definitionRule,
2502+ // Only from a stored writer's kept rows, as keptPaths: a project in memory keeps none, and works them out.
2503+ changedSince: (space, from, to) =>
2504+ this.#writerStorage ? this.#paths.keptChangesSince(space, from, to) : undefined,
24962505 refuse: (agent, space, via, time, collisions, entries) =>
24972506 this.#refuse(agent, space, via, time, collisions, entries),
24982507 requireClosed: (tie, union) => this.#requireClosed(tie, union),
Lines 3218–3236 at 318 (were 3209–3223 at 309)
32093218 const base = agent.mine.some((id) => at.has(id))
32103219 ? this.#view(differenceSet(at, new StableOverlaySet(agent.mine)))
32113220 : this.#viewAt(space, agent.base);
3221+ const to = version ?? last(space);
32123222 return this.#definitionRule.collisions(
32133223 draft,
32143224 this.#agentView(agent),
32153225 base,
3216− this.#viewAt(space, version ?? last(space)),
3226+ this.#viewAt(space, to),
32173227 newer,
32183228 space.name,
32193229 undefined,
32203230 names,
3231+ // Where the space changed since the agent's base, from each version's kept files on a stored writer, as land's
3232+ // (abso 714): walking every newer atom for them was 6.5 s of a publish 770 versions behind on abso.
3233+ () => (this.#writerStorage ? this.#paths.keptChangesSince(space, agent.base, to) : undefined),
32213234 );
32223235 }
32233236}
Lines 73–81 at 318 (were 73–79 at 309)
7373export function spellingOf(view: ReadView, path: string): string {
7474 if (view.hasFile(path)) return path;
7575 const key = pathKey(path);
76− // Known paths first, by key, then only those laid out (#46).
77− const twins = view.knownPaths().filter((p) => pathKey(p) === key && view.hasFile(p));
76+ // Every path the graph has ever had, by key, then only those the view has a file at (#46). Not the view's known paths
77+ // (abso Capacity, 714): those read every atom's membership and file list, 36,360 statements of a record on abso, as
78+ // clashIn found. A path the view never had has no file in it, so the answers are the same.
79+ const twins = [...view.graph.knownFiles()].filter((p) => pathKey(p) === key && view.hasFile(p));
7880 return twins.length === 1 ? twins[0]! : path;
7981}
new file, 55 lines
1+// Moves before laying out files (abso 714, piece 3): expressMoves looks at the draft's own written and deleted lines
2+// first, and lays out no file when none of its written lines with real content has a deleted line's text. moves.test.ts
3+// covers the moves themselves.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import type { Graph } from "../../../src/engine/index.ts";
8+import { type ExpressMovesHost, expressMoves } from "../express-moves.ts";
9+import type { AgentState } from "../project-types.ts";
11+/** A draft of two atoms: "del" deletes one line, "add" writes the others. Any view laid out throws. */
12+function host(deleted: string, written: string[]): ExpressMovesHost {
13+ const texts = [deleted, ...written];
14+ const graph = {
15+ deletedLines: (id: string) => (id === "del" ? ["line-0"] : []),
16+ *eachInsertedLine(id: string) {
17+ if (id === "add") for (let k = 1; k < texts.length; k++) yield `line-${k}`;
18+ },
19+ lineN: (line: string) => Number(line.slice("line-".length)),
20+ *textChunks(n: number) {
21+ yield texts[n]!;
22+ },
23+ textOf: (n: number) => texts[n]!,
24+ } as unknown as Graph;
25+ const laidOut = (): never => {
26+ throw new Error("laid out");
27+ };
28+ return {
29+ graph,
30+ draft: () => ["del", "add"],
31+ agentView: laidOut,
32+ beforeDraft: laidOut,
33+ view: laidOut,
34+ apply: laidOut,
35+ addDraft: laidOut,
36+ recordFile: laidOut,
37+ };
38+}
40+const agent = { name: "ann" } as AgentState;
42+test("an edit that only changes lines lays out no file", () => {
43+ expressMoves(host(" return pi * r * r;", [" return Math.PI * r * r;"]), agent, 1, []);
44+});
46+test("a deleted text written again with only brackets or blanks in common lays out no file", () => {
47+ expressMoves(host("}", [" const tree = parse(p);", "}", ""]), agent, 1, []);
48+});
50+test("a written line with real content that the draft also deleted goes on to the files", () => {
51+ assert.throws(
52+ () => expressMoves(host(" return pi * r * r;", ["", " return pi * r * r;"]), agent, 1, []),
53+ /laid out/,
54+ );
55+});
new file, 49 lines
1+// fileExactAt (version-log.ts, abso Capacity, 2026-10-17): the same answer as fileAt for exactly that spelling, at
2+// every version, read from the file's own lines without the version's list of files. abso's worker/test/
3+// project-files.test.ts checks it on the disk engine, where the list is what costs.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { MemoryStore, Project } from "../project.ts";
8+
9+/** Files added, edited, emptied, made binary and taken out, beside others, over six versions. */
10+function history(): Project {
11+ const p = new Project(new MemoryStore(), { hasBlob: () => true });
12+ p.init({ "README.md": "hi\n", "abso.json": '{ "check": "true" }\n', "src/a.ts": "a\n" }, 0);
13+ p.record("ann", { "abso.yml": "pipelines:\n ci:\n on: [push]\n", "docs/abso.yml": "not this one\n" }, 1);
14+ p.publish("ann", "a pipeline", 2);
15+ p.record("ann", { "abso.json": '{ "check": "false" }\n', "empty.txt": "" }, 3, {}, { "abso.yaml": "b".repeat(64) });
16+ p.publish("ann", "a binary, and an empty file", 4);
17+ p.record("ann", { "abso.yml": null, "avcs.json": "{}\n", "src/a.ts": "" }, 5);
18+ p.publish("ann", "the pipeline gone, a file emptied", 6);
19+ return p;
20+}
22+const PATHS = [
23+ "abso.yml",
24+ "abso.yaml",
25+ "abso.json",
26+ "avcs.json",
27+ "docs/abso.yml",
28+ "empty.txt",
29+ "src/a.ts",
30+ "README.md",
31+ "never.txt",
32+];
34+test("fileExactAt answers what fileAt answers for the same spelling, at every version", () => {
35+ const p = history();
36+ const last = p.version;
37+ assert.ok(last >= 3);
38+ for (let v = 0; v <= last; v++)
39+ for (const path of PATHS) assert.deepEqual(p.fileExactAt(path, v), p.fileAt(path, v), `${path} at ${v}`);
40+});
42+test("a name nothing ever wrote is null, and another spelling is that spelling, not the stored one", () => {
43+ const p = history();
44+ const last = p.version;
45+ assert.deepEqual(p.fileExactAt("never.txt", last), { path: "never.txt", version: last, text: null });
46+ // fileAt reads the stored spelling for any spelling (#41); fileExactAt reads only the one asked.
47+ assert.equal((p.fileAt("ABSO.json", last) as { text: string | null }).text, '{ "check": "false" }\n');
48+ assert.deepEqual(p.fileExactAt("ABSO.json", last), { path: "ABSO.json", version: last, text: null });
49+});
Lines 65–71 at 318 (were 65–73 at 309)
6565 drafts(owing);
6666 assert.deepEqual(owing.publish("ann", "parsePattern takes flags", 4), toldAnswer, "the publisher's answer");
6767 const owed = owing.takeOwedDefinitionNews();
68− assert.deepEqual(owed, [
69− { version: owing.version, space: owed[0]!.space, publisher: "ann", all: true },
70− ]);
68+ assert.deepEqual(owed, [{ version: owing.version, space: owed[0]!.space, publisher: "ann", all: true }]);
7169 assert.deepEqual(owing.takeOwedDefinitionNews(), [], "handed over once");
7270 // Not told yet: bob's news holds no definition news until it's delivered.
7371 assert.deepEqual(definitionNews(owing.news("bob").news), []);
Lines 168–175 at 318 (were 170–176 at 309)
170168 assert.deepEqual(owing.publish("ann", "parsePattern takes flags", 6), toldAnswer, "the publisher's answer");
171169 const [owed] = owing.takeOwedDefinitionNews();
172170 assert.equal(owed!.all, true);
173− for (const a of ["bob", "cat", "dee"]) assert.deepEqual(owing.news(a).news, [], `${a} is told nothing in the publish`);
171+ for (const a of ["bob", "cat", "dee"])
172+ assert.deepEqual(owing.news(a).news, [], `${a} is told nothing in the publish`);
174173 const names = owing.owedNewsNames(owed!);
175174 assert.deepEqual(names, ["parsePattern"]);
176175 // One agent at a time, as the host works it out.
Lines 244–278 at 318 (were 244–249 at 309)
244244 };
245245}
246246
247+/**
248+ * fileAt for exactly this spelling, from the file's own lines (abso Capacity, 2026-10-17): no spelling lookup and no
249+ * list of the version's files. fileAt's hasFile answers from the version's whole path list, folded from version 0
250+ * when nothing's kept, and a spelling it doesn't find reads every known path. A name nothing ever wrote is one read.
251+ * The pipeline's project files (abso.yml and the like) are read this way on every tick.
252+ */
253+export function fileExactAt(
254+ host: LogHost,
255+ path: string,
256+ version: number,
257+ options: { draft?: string | null; agent?: string } = {},
258+): { path: string; version: number; text: string | null; blob?: string } {
259+ host.needInit();
260+ checkReadPath(path);
261+ const space = host.spaceFor(options);
262+ host.checkVersion(space, version);
263+ if (!host.graph.hasAtomsIn(path)) return { path, version, text: null };
264+ const view = host.viewAt(space, version);
265+ const attrs = view.attrs(path);
266+ // hasFile's own test, without its path list: kept while empty, a link, a binary, or a visible line.
267+ const exists = attrs.exists || attrs.link !== null || attrs.blob !== null || view.lines(path).length > 0;
268+ return {
269+ path,
270+ version,
271+ text: exists ? view.text(path) : null,
272+ ...(attrs.blob !== null ? { blob: attrs.blob } : {}),
273+ };
274+}
247276/** The files that may differ between two versions, and both views: compare's and compareSummary's ground. */
248277function compared(
249278 host: LogHost,
MCP
compare on this site's /mcp
CLI
abso diff 309 318 --json
JSON
/christopher/abso-core/compare/309..318?format=json