Lines 2–8 at 143 (were 2–8 at 142)
22// text that arrives somewhere else is the same line. Before a publish, those matches become move 33// atoms so the lines keep their ids. Writes go through ExpressMovesHost; today the host is Project. 5−import type { AtomId, AttrSet, EditInput, Graph, LineId, MoveInput, View } from "../../src/engine/index.ts";
5+import type { AtomId, AttrSet, EditInput, Graph, LineId, MoveInput, ReadView } from "../../src/engine/index.ts"; 66import { differenceSet, StableOverlaySet } from "../../src/engine/state-source.ts"; 77import { PLAIN_LINE } from "./collisions.ts"; 88import type { AgentState, Entry, Meta, Mode } from "./project-types.ts"; Lines 18–30 at 143 (were 18–29 at 142)
1818export interface ExpressMovesHost { 1919 readonly graph: Graph; 2020 draft(agent: AgentState): AtomId[]; 21− agentView(agent: AgentState): View;
22− view(set: ReadonlySet<AtomId>): View;
21+ agentView(agent: AgentState): ReadView; 22+ beforeDraft?(agent: AgentState, draft: readonly AtomId[]): ReadView; 23+ view(set: ReadonlySet<AtomId>): ReadView; 2324 apply(entry: Entry): void; 26− view: View,
2728 input: { edits: readonly EditInput[]; attrs?: readonly AttrSet[]; move?: MoveInput }, Lines 32–38 at 143 (were 31–37 at 142)
34− view: View,
3637 text: string | null | undefined, Lines 60–68 at 143 (were 59–65 at 142)
5960 const g = host.graph; 6061 const mine = new Set(draft); 6162 const after = host.agentView(agent); 62− const before = host.view(differenceSet(after.set, new StableOverlaySet(draft)));
63+ const before = host.beforeDraft 64+ ? host.beforeDraft(agent, draft) 65+ : host.view(differenceSet(after.set, new StableOverlaySet(draft))); 6366 const touched = new Set<string>(); 6467 for (const id of draft) for (const file of g.filesOf(id)) touched.add(file); Lines 174–181 at 143 (were 171–176 at 142)
177+ // Keep the intended membership, but reacquire its reader after each graph mutation. 178+ const finalAgent = { ...agent, mine: [...agent.mine] }; 174179 const discard: Entry = { type: "discard", agent: agent.name, atoms: draft.filter((id) => drop.has(id)) }; 175180 entries.push(discard); 176181 host.apply(discard); Lines 185–191 at 143 (were 180–186 at 142)
180185 const start = view.lineNumber(m.from, m.ids[0]!); 181186 if (start < 0 || m.ids.some((id, k) => view.lineNumber(m.from, id) !== start + k)) continue; 182187 // Land after the nearest line above it in the final text that is already there. 183− const finalLines = after.lines(m.to);
188+ const finalLines = host.agentView(finalAgent).lines(m.to); 185190 for (let i = m.at - 1; i >= 0; i--) { 186191 const n = view.lineNumber(m.to, finalLines[i]!.id); Lines 205–217 at 143 (were 200–211 at 142)
202207 for (const path of [...involved].toSorted()) { 203− const was = after.attrs(path);
208+ const finalView = host.agentView(finalAgent); 209+ const was = finalView.attrs(path); 206212 host.agentView(agent), 208− after.hasFile(path) ? after.text(path) : null,
214+ finalView.hasFile(path) ? finalView.text(path) : null,