Lines 1–12 at 318 (were 1–10 at 91)
11// Add the agent's draft to its space. Writes go through PublishHost; today 22// the host is Project. Ingest calls publishDraft, the inner step. 4−import { type AtomId, buildAtom, type Hunk, joinLines, type View } from "../../src/engine/index.ts";
4+import { type AtomId, buildAtom, type Hunk, joinLines, type ReadView } from "../../src/engine/index.ts"; 5+import { differenceSet, unionOverlay } from "../../src/engine/state-source.ts"; 6+import { autoSettledOf } from "./autosettle.ts"; 57import type { Pair } from "./collisions.ts"; 68import type { DefinitionCollision } from "./definition-rule.ts"; 7−import { keptOf, lostLines, settleLines } from "./markers.ts";
9+import { heldMessage, keptOf, lostLines, settleLines } from "./markers.ts"; 810import { ProjectError } from "./project-error.ts"; 911import type { AgentState, Collision, Entry, Meta, Mode, PublishAnswer, Settled } from "./project-types.ts"; 1012import { last, SHARED, type Space } from "./spaces.ts"; Lines 24–33 at 318 (were 22–31 at 91)
2224 strandedFiles(draft: readonly AtomId[], set: ReadonlySet<AtomId>): string[]; 2325 setOf(space: Space): ReadonlySet<AtomId>; 2426 markedFiles(agent: AgentState): string[]; 25− agentView(agent: AgentState): View;
27+ agentView(agent: AgentState): ReadView; 28− view: View,
3032 text: string | null | undefined, Lines 49–55 at 318 (were 47–52 at 91)
4850 collisions: Collision[], 5053 ): { ok: false; collisions: Collision[] }; 5154 markerCollisions(agent: AgentState): Collision[]; Lines 60–69 at 318 (were 57–65 at 91)
5760 resolves: readonly AtomId[], 60− view(set: ReadonlySet<AtomId>): View;
63+ view(set: ReadonlySet<AtomId>): ReadView; 64+ spaceOverlay?(space: Space, atoms: readonly AtomId[]): ReadView; 6165 requireClosed(tie: { deps: readonly AtomId[] }, union: ReadonlySet<AtomId>): void; 62− newerFor(agent: AgentState): Set<AtomId>;
66+ newerFor(agent: AgentState): ReadonlySet<AtomId>; 6367 currentChange(agent: AgentState, time: number): number | undefined; 6468 apply(entry: Entry): void; 6569 newsForOthers(publisher: AgentState, space: Space, version: number, entries: Entry[]): void; Lines 85–91 at 318 (were 81–87 at 91)
8286 options: { asIs?: boolean } = {}, 84− if (typeof message !== "string") throw new ProjectError("bad-request", "publish needs a message");
88+ if (typeof message !== "string") throw new ProjectError("bad-request", "push needs a message"); 8589 const known = host.agents.get(agentName); 8690 if (known && known.space === SHARED) 8791 host.checkClash(host.draft(known), host.queueOn() ? host.queuedAtoms(known.name) : undefined); Lines 110–117 at 318 (were 106–113 at 91)
106110 if (stranded.length > 0) { 107111 throw new ProjectError( 109− `your unpublished changes to ${stranded.join(", ")} build on lines a drop took out of shared; ` +
110− `restore those files (abso restore ${stranded.join(" ")}), sync, and make the change again`,
113+ `your unpushed changes to ${stranded.join(", ")} build on lines a drop took out of shared; ` + 114+ `restore those files (abso restore ${stranded.join(" ")}), pull, and make the change again`, 113117 // asIs (#11): every block of markers keeps both sides, and the publish says which files it settled that way. Lines 130–143 at 318 (were 126–139 at 91)
126130 const draft = host.draft(agent); 127131 if (draft.length === 0) return { ok: true, version: last(space), changes: 0 }; 128132 const now = host.setOf(space); 129− const union = new Set([...now, ...draft]);
133+ const union = unionOverlay(now, draft); 130134 const newer = host.newerFor(agent); 131135 const collisions = [ 132136 ...host.pairs(draft, newer, union).map((p) => host.collision(agent, p)), 133137 ...host.definitionCollisions(agent, newer).map((d) => d.collision), 134138 ...host.duplicates(agent), 136− if (collisions.length > 0) return host.refuse(agent, space, "publish", time, collisions, entries);
140+ if (collisions.length > 0) return host.refuse(agent, space, "publish", time, collisions, entries, message); 137141 // Settled means the markers are gone (#11): refused while the draft adds any. 138142 const marked = host.markerCollisions(agent); 139143 if (marked.length > 0) return host.refuse(agent, space, "publish", time, marked, entries); Lines 147–153 at 318 (were 143–149 at 91)
143147 // (#37: twenty goals twice, shared red for three versions). So 144148 // that is refused unless the agent says to publish as it is (asIs); then, 145149 // like any other seen collision, publishing settles it. 146− const seen = host.pairs(draft, new Set([...now].filter((id) => !newer.has(id))), union);
150+ const seen = host.pairs(draft, differenceSet(now, newer), union); 148152 const untouched = seen 149153 .map((p) => host.collision(agent, p)) Lines 158–165 at 318 (were 154–160 at 91)
154158 const resolves = [...new Set(seen.flatMap((p) => [p.yours, p.theirs]))]; 155159 if (space.name === SHARED && !direct && host.queueOn()) 156160 return host.enqueue(agent, message, time, draft, resolves, entries); 157− const tie = buildAtom(host.view(union), { author: agent.name, message, time, needs: draft, resolves });
161+ const candidate = host.spaceOverlay ? host.spaceOverlay(space, draft) : host.view(union); 162+ const tie = buildAtom(candidate, { author: agent.name, message, time, needs: draft, resolves }); 158163 host.requireClosed(tie, union); 159164 const version = last(space) + 1; 160165 const othersPublished = space.versions.slice(agent.base + 1).some((p) => p.agent !== agent.name); Lines 170–190 at 318 (were 165–180 at 91)
165170 .map((p) => ({ version: p.version, agent: p.agent, message: p.message })); 166171 // What each marked collision kept, judged from the file as published (#11). 167172 const view = host.agentView(agent); 173+ const auto = autoSettledOf(message); 168174 const settled: Settled[] = agent.marked 169175 .filter((r) => r.space === space.name) 171177 const lines = view.hasFile(r.file) ? view.lines(r.file).map((l) => l.text) : []; 172178 const lost = lostLines(lines, r); 179+ const held = heldMessage(agent, r.file); 180+ const by = auto.get(r.file); 175183 kept: keptOf(lines, r), 176184 theirs: { agent: r.agent, version: r.version }, 177185 ...(lost.length > 0 ? { lost } : {}), 186+ ...(held ? { held } : {}), 187+ ...(by ? { auto: by } : {}),