Skip to content

abso-core

Public

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

Check passed
MCP
show on this site's /mcp
CLI
abso show 314 --json
JSON
/christopher/abso-core/versions/314?format=json

Definition rule: lay out only the touched files the draft's uses reach (abso 738). The rule found changed definitions by laying out every file the newer work touched, in two views; for codex-prose-authorship-610 that was 494 files a view where its uses reach 7. It now works out which files the uses mean first and lays out only the touched ones among them. Same answers: the rule already ignored untouched files. Draft collisions keep each file's definitions, and the touched files, under the newer work's key.

of shared·capacity··Not checked

Definition rule: lay out only the touched files the draft's uses reach (abso 738). The rule found changed definitions by laying out every file the newer work touched, in two views; for codex-prose-authorship-610 that was 494 files a view where its uses reach 7.

It now works out which files the uses mean first and lays out only the touched ones among them. Same answers: the rule already ignored untouched files. Draft collisions keep each file's definitions, and the touched files, under the newer work's key.

Version 313 · Files at version 314

2 files, 72 lines added, 39 removed.

--- a/worker/project/definition-rule.ts
+++ b/worker/project/definition-rule.ts
@@ -7,7 +7,7 @@
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";
@@ -37,7 +37,7 @@
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>;
@@ -52,8 +52,11 @@
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;
@@ -131,31 +134,54 @@
131134 // Only these names can collide (a publish's news, news.ts): a draft that uses none of them has none, and the
132135 // definitions changed since its base needn't be worked out.
133136 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.
137+ // Which definitions the uses mean: the file each use imports the name
138+ // from, or its own file when it defines the name at the top level. A
139+ // use with neither (a local, a parameter, a global, a name another
140+ // language brings in some other way) means none: the rule only speaks
141+ // when it knows which definition a use means.
142+ const scopes = new Map<string, ReadonlySet<string>>();
143+ for (const [name, where] of uses) {
149144 const scope = new Set<string>();
150145 for (const w of new Set(where.map((x) => x.file))) {
151146 const from = importsOf(view, w).get(name) ?? (definitionsIn(view, [w]).has(name) ? w : undefined);
152147 if (from !== undefined) scope.add(from);
153148 }
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);
149+ if (scope.size > 0) scopes.set(name, scope);
150+ }
151+ if (scopes.size === 0) return [];
152+ const nowOf = () => (typeof nowView === "function" ? nowView() : nowView);
153+ // Only a file the newer work touched can hold a changed definition, and only one a use means can matter: just those
154+ // files are laid out, before and with the newer work (abso 738). Laying out every file the newer work touched cost
155+ // codex-prose-authorship-610's draft-state 494 files a view where its uses reach 7.
156+ const touched = kept
157+ ? kept.parts.get(`touched ${kept.changed}`, () => this.#touched(newer, baseView, nowOf()), filesBytes)
158+ : this.#touchedFor(newer, baseView, nowOf());
159+ const changed = new Map<string, Changed>();
160+ const changedIn = (file: string): Changed => {
161+ let c = changed.get(file);
162+ if (!c) {
163+ const make = (): Changed => ({
164+ baseDefs: definitionsIn(baseView, [file]),
165+ nowDefs: definitionsIn(nowOf(), [file]),
166+ });
167+ c = kept
168+ ? kept.parts.get(
169+ `changed ${kept.changed} ${file}`,
170+ make,
171+ (d) => definitionsBytes(d.baseDefs) + definitionsBytes(d.nowDefs),
172+ )
173+ : make();
174+ changed.set(file, c);
175+ }
176+ return c;
177+ };
178+ const out: DefinitionCollision[] = [];
179+ for (const [name, scope] of [...scopes].sort(([a], [b]) => (a < b ? -1 : 1))) {
180+ // In the order the newer work touched its files, as when every touched file was laid out.
181+ const files = [...touched].filter((f) => scope.has(f));
182+ const before = files.flatMap((f) => changedIn(f).baseDefs.get(name) ?? []);
183+ if (!before.length) continue; // not defined in what the drafter saw: nothing it relies on
184+ const after = files.flatMap((f) => changedIn(f).nowDefs.get(name) ?? []);
159185 if (signature(before) === signature(after)) continue;
160186 // Who changed it: newer writers of the new definition's lines, or newer deleters of the old one's.
161187 const by = new Set<AtomId>();
@@ -166,6 +192,7 @@
166192 const first = [...by].sort((p, q) => this.#graph.atom(p).seq - this.#graph.atom(q).seq)[0];
167193 if (first === undefined) continue;
168194 const origin = this.#origin(first, spaceName);
195+ const where = uses.get(name)!;
169196 const file = where[0]!.file;
170197 const indexes = where.filter((w) => w.file === file).map((w) => w.index);
171198 const lo = Math.min(...indexes);
@@ -205,20 +232,19 @@
205232 return kept.uses;
206233 }
207234
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);
235+ /** The files the newer work touched, kept while it is asked about with the same views. */
236+ #touchedFor(newer: ReadonlySet<AtomId>, baseView: ReadView, now: ReadView): ReadonlySet<string> {
237+ let kept = this.#touchedCache.get(newer);
238+ if (!kept || kept.base !== baseView || kept.now !== now) {
239+ kept = { base: baseView, now, files: this.#touched(newer, baseView, now) };
240+ this.#touchedCache.set(newer, kept);
214241 }
215− return changed.defs;
242+ return kept.files;
216243 }
217244
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) };
245+ /** The files the newer work touched, before it and with it: only there can a definition have changed. */
246+ #touched(newer: ReadonlySet<AtomId>, baseView: ReadView, now: ReadView): ReadonlySet<string> {
247+ return touchedFiles(this.#graph, newer, [baseView, now]);
222248 }
223249
224250 /** The names the draft's lines use and don't declare, less those the lines they replaced already used. */
--- a/worker/project/kept-parts.ts
+++ b/worker/project/kept-parts.ts
@@ -1,8 +1,8 @@
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";
@@ -100,3 +100,10 @@
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+}