Lines 1–13 at 318 (were 1–12 at 92)
11// Land a named draft in shared as one unit. Writes go through LandHost; today 22// the host is Project. Ingest and pluck call landDraft, the inner step. 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 { differenceSet, StableOverlaySet, unionOverlay } from "../../src/engine/state-source.ts"; 56import type { Pair } from "./collisions.ts"; 67import type { DefinitionRule } from "./definition-rule.ts"; 78import { ProjectError } from "./project-error.ts"; 89import type { AgentState, Collision, Entry, LandAnswer } from "./project-types.ts"; 9−import { SHARED, type Space, sharedBaseOf } from "./spaces.ts";
10+import { SHARED, SharedAdditions, type Space, sharedBaseOf } from "./spaces.ts"; 1112/** What landing a named draft needs from a project. */ 1213export interface LandHost { Lines 23–36 at 318 (were 22–32 at 92)
2324 setOf(space: Space): ReadonlySet<AtomId>; 2425 at(space: Space, version: number): ReadonlySet<AtomId>; 25− view(set: ReadonlySet<AtomId>): View;
26− sharedView(): View;
26+ view(set: ReadonlySet<AtomId>): ReadView; 27+ viewAt(space: Space, version: number, changes?: readonly AtomId[]): ReadView; 28+ sharedView(): ReadView; 2729 pairs(draft: readonly AtomId[], against: ReadonlySet<AtomId>, settled: ReadonlySet<AtomId>): Pair[]; 28− describe(pair: Pair, yoursView: View, theirsView: View, spaceName: string): Collision;
30+ describe(pair: Pair, yoursView: ReadView, theirsView: ReadView, spaceName: string): Collision; 2931 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; Lines 74–118 at 318 (were 70–90 at 92)
73−): { collisions: Collision[]; newer: Set<AtomId>; union: Set<AtomId> } {
77+): { collisions: Collision[]; newer: ReadonlySet<AtomId>; union: ReadonlySet<AtomId> } { 7478 const shared = host.shared(); 7579 const base = host.at(shared, sharedBaseOf(space)); 76− const own = new Set(changes);
77− const union = new Set([...shared.own, ...changes]);
80+ const own = new StableOverlaySet(changes); 81+ const current = host.at(shared, host.version()); 82+ const union = unionOverlay(current, changes); 7883 // The draft's own changes (some already plucked into shared) are never newer work to it. 79− const newer = new Set([...shared.own].filter((id) => !base.has(id) && !own.has(id) && !space.own.has(id)));
84+ const newer = differenceSet( 86+ shared.membershipVersion 87+ ? new SharedAdditions(shared, sharedBaseOf(space), base, current) 88+ : differenceSet(current, base), 8093 // A pluck is checked as the draft's base plus only the plucked changes. 81− const draftView = host.view(pick ? new Set([...base, ...changes]) : host.setOf(space));
94+ const draftView = pick 95+ ? host.viewAt(shared, sharedBaseOf(space), changes) 96+ : host.viewAt(space, space.versions.length - 1); 8297 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()); 83101 const collisions = [ 84102 ...host.pairs(changes, newer, union).map(describeLand), 87− .collisions(own, draftView, host.view(base), host.sharedView(), newer, SHARED)
108+ host.viewAt(shared, sharedBaseOf(space)), 88116 .map((d) => d.collision), 90118 return { collisions, newer, union }; Lines 135–149 at 318 (were 107–115 at 92)
107135 if (changes.length === 0) return { ok: true, version: host.version(), changes: 0 }; 108136 const { collisions, newer, union } = landCollisions(host, space, changes, !!pick); 109137 if (collisions.length > 0) return host.refuse(agent, space, "land", time, collisions, entries); 110− const seen = host.pairs(changes, new Set([...shared.own].filter((id) => !newer.has(id))), union);
138+ const seen = host.pairs(changes, differenceSet(host.at(shared, host.version()), newer), union); 111139 const resolves = [...new Set(seen.flatMap((p) => [p.yours, p.theirs]))]; 112− const tie = buildAtom(host.view(union), { author: agent.name, message, time, needs: changes, resolves });
140+ const tie = buildAtom(host.viewAt(shared, host.version(), changes), { 113147 host.requireClosed(tie, union); 114148 const version = host.version() + 1; 115149 // A pluck leaves the draft where it is: the rest of it lands later.