{"draft":null,"from":248,"to":249,"files":[{"path":"worker/project/draft-collisions.ts","added":26,"removed":4,"diff":"--- a/worker/project/draft-collisions.ts\n+++ b/worker/project/draft-collisions.ts\n@@ -6,6 +6,7 @@\n import { claimantsAmong, describeSide, fileOfKey, pairsFrom } from \"./collisions.ts\";\n import type { DefinitionRule } from \"./definition-rule.ts\";\n import { type Definition, definedTwice } from \"./definitions.ts\";\n+import { definitionsBytes, type KeptParts } from \"./kept-parts.ts\";\n import { pathKey } from \"./pathkey.ts\";\n import type { CollisionSide, DraftCollision } from \"./project-types.ts\";\n import { last, SHARED, type Space } from \"./spaces.ts\";\n@@ -28,6 +29,10 @@\n \t/** Shared now with these agents' drafts on top. */\n \tdraftsView(agents: readonly Agent[]): ReadView;\n \ttouchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;\n+\t/** What collisions keep between calls (kept-parts.ts), when the project keeps any. */\n+\tkeptParts?(): KeptParts | undefined;\n+\t/** A key naming everything a draft's part of the answer depends on: shared's version, its base and its atoms. */\n+\tdraftKey(agent: Agent): string;\n }\n \n /**\n@@ -99,6 +104,16 @@\n \t// Shared now with each agent's draft on top (project.ts, draftsView): kept between calls while shared and the\n \t// draft stay the same, and laid out as shared is for every file the draft doesn't touch (abso Capacity).\n \tconst nowViewOf = (agent: Agent) => host.draftsView([agent]);\n+\t// Each draft's uses and changed definitions, and each pair's names defined twice, kept between calls (kept-parts.ts,\n+\t// abso Capacity): what this call doesn't use is dropped at its end.\n+\tconst parts = host.keptParts?.();\n+\tconst keys = new Map<Agent, string>();\n+\tconst keyOf = (agent: Agent) => {\n+\t\tlet key = keys.get(agent);\n+\t\tif (key === undefined) keys.set(agent, (key = host.draftKey(agent)));\n+\t\treturn key;\n+\t};\n+\tparts?.startRound();\n \t// Each agent's touched files once, not once per pair (abso Capacity).\n \tconst touched = new Map<Agent, Set<string>>();\n \tconst touchedBy = (agent: Agent) => {\n@@ -154,10 +169,15 @@\n \t\t\t\tconst mineA = new Set(draftA);\n \t\t\t\tconst mineB = new Set(draftB);\n \t\t\t\tconst filesA = touchedBy(a);\n+\t\t\t\tconst twiceIn = (file: string): ReadonlyMap<string, Definition[]> => {\n+\t\t\t\t\tconst make = () => {\n+\t\t\t\t\t\tboth ??= host.draftsView([a, b]);\n+\t\t\t\t\t\treturn both.hasFile(file) ? definedTwice(both, file) : new Map<string, Definition[]>();\n+\t\t\t\t\t};\n+\t\t\t\t\treturn parts ? parts.get(`twice ${keyOf(a)} | ${keyOf(b)} ${file}`, make, definitionsBytes) : make();\n+\t\t\t\t};\n \t\t\t\tfor (const file of [...touchedBy(b)].filter((f) => filesA.has(f)).toSorted()) {\n-\t\t\t\t\tboth ??= host.draftsView([a, b]);\n-\t\t\t\t\tif (!both.hasFile(file)) continue;\n-\t\t\t\t\tfor (const [name, defs] of definedTwice(both, file)) {\n+\t\t\t\t\tfor (const [name, defs] of twiceIn(file)) {\n \t\t\t\t\t\tconst by = (mine: Set<AtomId>) => defs.find((d) => d.lines.some((l) => mine.has(host.graph.lineAtom(l)!)));\n \t\t\t\t\t\tconst dA = by(mineA);\n \t\t\t\t\t\tconst dB = by(mineB);\n@@ -177,7 +197,8 @@\n \t\t\t}\n \t\t\t// Definitions: b's new lines use a name whose definition a's changes change.\n \t\t\tconst nowView = () => nowViewOf(a);\n-\t\t\tfor (const d of host.definitionRule().collisions(draftSet(b), viewB, sharedView, nowView, newer, SHARED)) {\n+\t\t\tconst kept = parts ? { parts, uses: keyOf(b), changed: keyOf(a) } : undefined;\n+\t\t\tfor (const d of host.definitionRule().collisions(draftSet(b), viewB, sharedView, nowView, newer, SHARED, kept)) {\n \t\t\t\tconst c = d.collision;\n \t\t\t\tout.push({\n \t\t\t\t\tkind: \"definition\",\n@@ -189,6 +210,7 @@\n \t\t\t}\n \t\t}\n \t}\n+\tparts?.endRound();\n \tconst fileKey = options.file !== undefined ? pathKey(options.file) : undefined;\n \tconst folderParts =\n \t\toptions.folder !== undefined ? options.folder.split(\"/\").filter((s) => s !== \"\" && s !== \".\") : undefined;"}],"unmatched":[]}