Lines 1–12 at 318 (were 1–10 at 29)
11// The merge queue: publishes to shared waiting for their batch's check. 22// Writes go through QueueHost; today the host is Project. 4−import { type AtomId, buildAtom, type Graph, type View } from "../../src/engine/index.ts";
4+import { type AtomId, buildAtom, type Graph, type ReadView } from "../../src/engine/index.ts"; 5+import { unionOverlay } from "../../src/engine/state-source.ts"; 6+import { autoSettledOf } from "./autosettle.ts"; 57import type { Pair } from "./collisions.ts"; 68import { definedTwice } from "./definitions.ts"; 7−import { keptOf, lostLines } from "./markers.ts";
9+import { heldMessage, keptOf, lostLines } from "./markers.ts"; 810import { clip } from "./news.ts"; 911import { ProjectError } from "./project-error.ts"; 1012import { projectFileIn } from "./project-helpers.ts"; Lines 29–37 at 318 (were 27–33 at 29)
2729export interface QueueHost { 2830 readonly graph: Graph; 2931 checkerReady(): boolean; 30− sharedView(): View;
32+ sharedView(): ReadView; 33+ sharedOverlay?(atoms: readonly AtomId[]): ReadView; 34+ sharedAgentOverlay?(agent: AgentState, atoms: readonly AtomId[]): ReadView; 3135 queued(): readonly QueuedPublish[]; 3337 checkingHas(id: number): boolean; Lines 40–51 at 318 (were 36–47 at 29)
3842 setOf(space: Space): ReadonlySet<AtomId>; 39− view(set: ReadonlySet<AtomId>): View;
43+ view(set: ReadonlySet<AtomId>): ReadView; 4044 agentSet(agent: AgentState): Set<AtomId>; 41− agentView(agent: AgentState): View;
45+ agentView(agent: AgentState): ReadView; 4246 pairs(draft: readonly AtomId[], against: ReadonlySet<AtomId>, settled: ReadonlySet<AtomId>): Pair[]; 43− describe(pair: Pair, yoursView: View, theirsView: View, spaceName: string): Collision;
44− touchedFiles(ids: Iterable<AtomId>, views: readonly View[]): Set<string>;
47+ describe(pair: Pair, yoursView: ReadView, theirsView: ReadView, spaceName: string): Collision; 48+ touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>; Lines 53–59 at 318 (were 49–54 at 29)
5054 collisions: Collision[], 5257 ): { ok: false; collisions: Collision[] }; 5358 currentChange(agent: AgentState, time: number): number | undefined; Lines 85–91 at 318 (were 80–86 at 29)
8186 throw new ProjectError( 83− `${what} doesn't go through the merge queue yet; switch to shared, take the changes into your draft, and publish`,
88+ `${what} doesn't go through the merge queue yet; switch to shared, take the changes into your draft, and push`, Lines 121–133 at 318 (were 116–126 at 29)
116121 const ahead = queuedAtoms(host, agent.name); 117122 const now = host.setOf(space); 118123 if (ahead.size > 0) { 119− const landed = new Set([...now, ...ahead]);
120− const theirsView = host.view(landed);
121− const yoursView = host.view(new Set([...landed, ...host.agentSet(agent)]));
124+ const landed = unionOverlay(now, ahead); 125+ const theirsView = host.sharedOverlay ? host.sharedOverlay([...ahead]) : host.view(landed); 126+ const yoursView = host.sharedAgentOverlay 127+ ? host.sharedAgentOverlay(agent, [...ahead]) 128+ : host.view(unionOverlay(landed, host.agentSet(agent))); 122129 const queuedBy = (id: AtomId) => host.queued().find((q) => q.changes.includes(id)); 123− const collisions: Collision[] = host.pairs(changes, ahead, new Set([...landed, ...changes])).map((p) => {
130+ const collisions: Collision[] = host.pairs(changes, ahead, unionOverlay(landed, changes)).map((p) => { 124131 const c = host.describe(p, host.agentView(agent), theirsView, agent.space); 125132 const q = queuedBy(p.theirs); 126133 return q ? { ...c, theirs: { ...c.theirs, agent: q.agent, message: q.message, queued: q.id } } : c; Lines 144–153 at 318 (were 137–146 at 29)
137144 kind: "duplicate", 140− yours: { lines: [yours.start + 1, yours.end], text: yours.text + "\n" },
147+ yours: { lines: [yours.start + 1, yours.end], text: `${yours.text}\n` }, 142149 lines: [theirs.start + 1, theirs.end], 143− text: theirs.text + "\n",
150+ text: `${theirs.text}\n`, 145152 message: q.message, 146153 version: last(space), Lines 156–179 at 318 (were 149–167 at 29)
152− if (collisions.length > 0) return host.refuse(agent, space, "publish", time, collisions, entries);
159+ if (collisions.length > 0) return host.refuse(agent, space, "publish", time, collisions, entries, message); 154161 const view = host.agentView(agent); 162+ const auto = autoSettledOf(message); 155163 const settled: Settled[] = agent.marked 156164 .filter((r) => r.space === SHARED) 158166 const lines = view.hasFile(r.file) ? view.lines(r.file).map((l) => l.text) : []; 159167 const lost = lostLines(lines, r); 168+ const held = heldMessage(agent, r.file); 169+ const by = auto.get(r.file); 162172 kept: keptOf(lines, r), 163173 theirs: { agent: r.agent, version: r.version }, 164174 ...(lost.length > 0 ? { lost } : {}), 175+ ...(held ? { held } : {}), 176+ ...(by ? { auto: by } : {}), 167179 const id = host.queuedId() + 1; Lines 240–252 at 318 (were 228–234 at 29)
230242 const items = host.queued().slice(0, Math.max(0, n)); 231− const view = host.view(new Set([...host.setOf(host.shared()), ...items.flatMap((q) => q.changes)]));
243+ const changes = items.flatMap((q) => q.changes); 245+ changes.length === 0 247+ : host.sharedOverlay 248+ ? host.sharedOverlay(changes) 249+ : host.view(unionOverlay(host.setOf(host.shared()), changes)); 232250 const files = view.files(); 233251 const modes = modesOf(view); 234252 const blobs = view.blobs(); Lines 265–273 at 318 (were 247–254 at 29)
247265 for (const q of host.queued().slice(0, Math.max(0, n))) { 248266 const agent = host.agentOf(q.agent); 249267 const space = host.shared(); 250− const union = new Set([...host.setOf(space), ...q.changes]);
251− const tie = buildAtom(host.view(union), {
268+ const union = unionOverlay(host.setOf(space), q.changes); 269+ const view = host.sharedOverlay ? host.sharedOverlay(q.changes) : host.view(union); 270+ const tie = buildAtom(view, { 253272 message: q.message, Lines 299–305 at 318 (were 280–286 at 29)
280299 host.reviewNews(agent, version, entries); 283− [{ key: `landed ${q.id}`, text: `Your queued publish "${clip(q.message)}" landed as version ${version}.` }],
302+ [{ key: `landed ${q.id}`, text: `Your queued push "${clip(q.message)}" landed as version ${version}.` }], 286305 out.push({ id: q.id, version }); Lines 343–355 at 318 (were 324–336 at 29)
324343 ? `the project's check failed on it on top of version ${last(host.shared())}${tail ? `:\n${tail}` : ""}` 325344 : why === "withdrawn" 326345 ? "you withdrew it" 327− : `it builds on queued publish ${id}, which was pulled`;
346+ : `it builds on queued push ${id}, which was turned back`; 329348 host.agentOf(q.agent), 332351 key: `pulled ${q.id}`, 333− text: `Your queued publish "${clip(q.message)}" was pulled: ${said}. Its changes are still in your draft.`,
352+ text: `Your queued push "${clip(q.message)}" was turned back: ${said}. Its changes are still in your draft.`, Lines 369–375 at 318 (were 350–356 at 29)
351370 throw new ProjectError( 353− `queued publish ${busy.id} is being checked; it lands or is pulled in about a minute (abso drop takes it back after it lands)`,
372+ `queued push ${busy.id} is being checked; it lands or is turned back in about a minute (abso drop takes it back after it lands)`, 355374 const pulled: number[] = []; 356375 for (const q of mine)