Lines 12–47 at 318 (were 12–30 at 116)
1212// agents publish into under the same rules, and that lands in shared as one 1313// unit. Every agent works in one space at a time. 15−import { type Atom, type AtomId, EngineError, Graph, type LineId, type View } from "../../src/engine/index.ts";
23+} from "../../src/engine/index.ts"; 1827 type GraphStateStorage, 2436} from "../../src/engine/state-source.ts"; 2537import { type AddDraftHost, addDraft as hostedAddDraft } from "./add-draft.ts"; 2638import { type AmendHost, amend as hostedAmend } from "./amend.ts"; 27−import { type AnnounceHost, announce as hostedAnnounce, announcePerson as hostedAnnouncePerson } from "./announce.ts";
41+ announce as hostedAnnounce, 42+ announcePerson as hostedAnnouncePerson, 43+ seatNotice as hostedSeatNotice, 44+} from "./announce.ts"; 2845import { type ApplyEntryHost, applyEntry as hostedApplyEntry } from "./apply-entry.ts"; Lines 63–69 at 318 (were 46–51 at 116)
5068} from "./collisions.ts"; 5169import { type DefinitionCollision, DefinitionRule } from "./definition-rule.ts"; Lines 81–87 at 318 (were 63–68 at 116)
6381} from "./history.ts"; 6482import { ingest as hostedIngest, type IngestHost } from "./ingest.ts"; 6583import { init as hostedInit, type InitHost } from "./init.ts"; 84+import { KeptParts } from "./kept-parts.ts"; 6685import { label as hostedLabel, type LabelHost } from "./label.ts"; Lines 105–117 at 318 (were 86–94 at 116)
87106 newsAboutOwnDraft as hostedNewsAboutOwnDraft, 88107 newsForOthers as hostedNewsForOthers, 108+ newsOwed as hostedNewsOwed, 109+ owedAgents as hostedOwedAgents, 110+ owedNewsNames as hostedOwedNewsNames, 114+ type OwedDefinitionNews, Lines 161–167 at 318 (were 138–143 at 116)
Lines 196–228 at 318 (were 172–186 at 116)
172196import { recordFile as hostedRecordFile, type RecordFileHost } from "./record-file.ts"; 173197import { refusals as hostedRefusals, refuse as hostedRefuse, type RefuseHost } from "./refuse.ts"; 174198import { restore as hostedRestore, type RestoreHost } from "./restore.ts"; 175−import { last, Membership, SHARED, type Space, sharedBaseOf } from "./spaces.ts";
208+} from "./spaces.ts"; 176209import { starting as hostedStarting, type StartingHost } from "./start.ts"; 177210import { switchTo as hostedSwitchTo, type SwitchHost } from "./switch-to.ts"; 178211import { sync as hostedSync, type SyncHost } from "./sync.ts"; 179212import { treeHash } from "./tree.ts"; 217+ versionFiles as keptVersionFiles, 218+ type VersionFilesHost, 219+} from "./version-files.ts"; 182222 compare as versionCompare, 223+ compareSummary as versionCompareSummary, 183224 fileAt as versionFileAt, 225+ fileExactAt as versionFileExactAt, 184226 log as versionLog, 185227 ribbon as versionRibbon, 186228 show as versionShow, Lines 242–248 at 318 (were 200–205 at 116)
200242 wholeRules as hostedWholeRules, 202244} from "./whole-files.ts"; 245+import { without as hostedWithout, type WithoutHost } from "./without.ts"; 203246import { WriterAgents } from "./writer-agents.ts"; 205248export { MemoryStore } from "./memory-store.ts"; Lines 258–273 at 318 (were 215–220 at 116)
215258/** A start note lasts this long after the agent's last activity (#44). */ 216259const NOTE_IDLE = 2 * 60 * 60 * 1000; 217260const WRITER_REOPEN = Symbol("verified writer checkpoint"); 262+ * The stored writer's read cache (abso Capacity). An agent's diff on typescript-rs touches more rows than the old 263+ * 4,096 held, so it read many of them again: 59,000 reads cold, against 22,000 at this size. 265+const WRITER_CACHE_BYTES = 4 * 1_048_576; 266+const WRITER_CACHE_ROWS = 16_384; 267+/** The biggest row the writer cache keeps (abso Capacity): an agent and all the news it was told can be 100 KB. */ 268+const WRITER_CACHE_ROW_BYTES = 16_384; 269+/** Old-form agent rows moved to told buckets at each write (abso Capacity): abso's 109 take about 28 writes. */ 270+const OLD_TOLD_PER_WRITE = 4; 218271export interface WriterSource { 219272 readonly generation: number; 220273 readonly logLength: number; Lines 279–310 at 318 (were 226–237 at 116)
282+/** A decoded entry is supplied by a host that binds its bytes to canonical authority. */ 283+export type WriterAdoptionFrame = { seq: number; json: string } | { seq: number; bytes: number; entry: Entry }; 284+function adoptionFrameBytes(frame: WriterAdoptionFrame): number { 285+ return "json" in frame 286+ ? typeof frame.json === "string" 287+ ? new TextEncoder().encode(frame.json).byteLength 291+function adoptionFrameEntry(frame: WriterAdoptionFrame): Entry { 292+ return "json" in frame ? (JSON.parse(frame.json) as Entry) : frame.entry; 295+/** Where a view and its base place moved lines differently (View.placedDifferently), when both are Views. */ 296+function placedBetween(view: ReadView, base: ReadView): ReadonlySet<string> | undefined { 297+ return view instanceof View && base instanceof View ? view.placedDifferently(base) : undefined; 229300export class Project { 230301 readonly #store: ProjectStore; 231302 readonly #writerStorage?: GraphStateStorage; 232303 readonly #graph: Graph; 233304 /** Views laid out from atom sets, cached under a byte budget (views.ts). */ 234305 readonly #views: ViewCache; 306+ /** What draft collisions keep between calls, under its own byte budget (kept-parts.ts). */ 307+ #keptParts: KeptParts | undefined; 235308 /** Each agent's draft files, under the key they were worked out for (#draftFiles). */ 236309 readonly #draftFilesKept = new Map<string, { key: string; files: Set<string> }>(); 237310 /** Each version's files and each path's history (pathindex.ts). */ Lines 335–351 at 318 (were 262–270 at 116)
262335 * doesn't depend on it. 264337 checkerReady = false; 339+ * Owed news (abso Capacity, 2026-10-15): a publish's definition news for other agents is left for after its write 340+ * (takeOwedDefinitionNews, definitionNewsOwed, deliverOwedNews). The disk route sets it; the replay engine doesn't. 342+ owesDefinitionNews = false; 343+ #owed: OwedDefinitionNews[] = []; 265344 readonly #now: (() => number) | undefined; 345+ readonly #newsWritten: ((items: readonly NewsWritten[]) => void) | undefined; 266346 readonly #whole: ProjectOptions["whole"]; 267347 readonly #shapes: ProjectOptions["shapes"]; 348+ readonly #logLine: ProjectOptions["logLine"]; 268349 /** For each log position, the newest time up to it (#41): time to position in one search. */ 269350 readonly #timeAt: number[] = []; 270351 /** For each version of shared, the log position of the entry that made it (#41). */ Lines 427–438 at 318 (were 346–353 at 116)
346427 readonly #hasBlob: (sha256: string) => boolean; 348429 constructor(store: ProjectStore, options: ProjectOptions = {}, checkpoint?: typeof WRITER_REOPEN) { 430+ if (options.indexAcceptedAtom && !options.writerStorage) 431+ throw Error("accepted atom indexing requires writer storage"); 349432 this.#store = store; 350− this.#writerStorage = options.writerStorage ? new CachedStateStorage(options.writerStorage) : undefined;
433+ this.#writerStorage = options.writerStorage 434+ ? new CachedStateStorage(options.writerStorage, WRITER_CACHE_BYTES, WRITER_CACHE_ROWS, WRITER_CACHE_ROW_BYTES) 351436 if (this.#writerStorage) { 352437 const storage = this.#writerStorage; 353438 // A stored Graph cannot be replayed over itself. Check before any Lines 465–474 at 318 (were 380–387 at 116)
381466 this.#hasBlob = options.hasBlob ?? (() => false); 382467 this.#now = options.now; 468+ this.#newsWritten = options.newsWritten; 383469 this.#whole = options.whole; 384470 this.#shapes = options.shapes; 471+ this.#logLine = options.logLine; 385472 // For tests (#46): AVCS_TEXT_FROM_LOG=1 runs a project on a MemoryStore with its text read back from the store. 387474 (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.AVCS_TEXT_FROM_LOG === Lines 487–497 at 318 (were 400–410 at 116)
401488 // Line text and each atom's deletes and claim keys stay in the log (#46), read back when asked for. 402489 this.#graph = this.#writerStorage 403− ? new Graph({ storage: this.#writerStorage })
490+ ? new Graph({ storage: this.#writerStorage, indexAcceptedAtom: options.indexAcceptedAtom }) 405492 ? new Graph({ texts: (seq) => stored(seq).inserts.map((r) => r.lines), lists: (seq) => stored(seq) }) 407− this.#views = new ViewCache(this.#graph);
494+ this.#views = new ViewCache(this.#graph, options.readViewProvider); 408495 this.#paths = new PathIndex({ 409496 graph: this.#graph, 410497 at: (space, version) => this.#at(space, version), Lines 563–608 at 318 (were 476–481 at 116)
476563 return new Project(store, { ...options, writerStorage: storage }, WRITER_REOPEN); 566+ /** Open a host-verified historical prefix. Its state must be immutable and 567+ * scoped to canonical authority; adoption readiness describes the live writer, 568+ * not whether this individual prefix has a complete checkpoint. */ 569+ static openHistorical( 570+ storage: GraphStateStorage, 572+ scratch: GraphStateStorage, 573+ assertScope: () => void = () => { 574+ storage.read("project:meta", "checkpoint"); 576+ readViewProvider?: ProjectOptions["readViewProvider"], 578+ const refuse = (): never => { 579+ throw new Error("historical project is read-only"); 581+ const selected = (collection: string) => { 582+ // Revalidate the historical scope even when accessing derived scratch. 584+ return collection.startsWith("projection-scratch:") ? scratch : storage; 586+ return Project.#openWriter( 589+ read: (collection, key) => selected(collection).read(collection, key), 590+ entries: (collection) => selected(collection).entries(collection), 591+ write: (collection, key, value) => { 592+ if (selected(collection) !== scratch) refuse(); 593+ scratch.write(collection, key, value); 595+ remove: (collection, key) => { 596+ if (selected(collection) !== scratch) refuse(); 597+ scratch.remove(collection, key); 599+ transaction: (body) => storage.transaction(() => scratch.transaction(body)), 602+ { readViewProvider }, 480607 * Derive one bounded page from the host's canonical frames. The host reads 481608 * those frames from its own log and revalidates the source inside this same Lines 613–627 at 318 (were 486–495 at 116)
487614 source: WriterSource; 489− frames: Iterable<{ seq: number; json: string }>;
616+ frames: Iterable<WriterAdoptionFrame>; 490617 maxEntries: number; 619+ /** The host supplies disk-backed decoded entries and verified byte counts. */ 620+ decodedFrames?: boolean; 492621 currentSource(): WriterSource; 622+ /** Select the host's derived historical revision before applying a frame. 623+ * Each selected revision receives a complete Project checkpoint. */ 624+ beginRevision?(logLength: number): void; 494626 options: Omit<ProjectOptions, "writerStorage"> = {}, 495627 ): { next: number; ready: boolean; entries: number; bytes: number } { Lines 637–643 at 318 (were 505–511 at 116)
505637 input.maxEntries > 256 || 506638 !Number.isSafeInteger(input.maxBytes) || 507639 input.maxBytes < 1 || 508− input.maxBytes > 8_000_000
640+ (input.maxBytes > 8_000_000 && input.decodedFrames !== true) 510642 throw new Error("invalid writer adoption bounds or source"); 511643 return storage.transaction(() => { Lines 661–684 at 318 (were 529–547 at 116)
531663 for (const frame of input.frames) { 664+ if (input.decodedFrames && "json" in frame) throw new Error("decoded adoption requires decoded frames"); 665+ const size = adoptionFrameBytes(frame); 533667 count >= input.maxEntries || 534668 frame.seq !== input.from + count || 535669 frame.seq >= input.source.logLength || 536− typeof frame.json !== "string" ||
537− frame.json.length > input.maxBytes - bytes
670+ !Number.isSafeInteger(size) || 672+ size > input.maxBytes - bytes 539674 throw new Error("writer adoption page exceeds bounds or has a noncontiguous frame"); 540− bytes += new TextEncoder().encode(frame.json).byteLength;
541676 if (bytes > input.maxBytes) throw new Error("writer adoption page exceeds byte bound"); 542− project.#apply(JSON.parse(frame.json) as Entry);
677+ input.beginRevision?.(frame.seq + 1); 678+ project.#apply(adoptionFrameEntry(frame)); 543679 project.#stored++; 544680 project.#persistMutable(); 681+ if (input.beginRevision) project.#writeCheckpoint(); 547684 if (count === 0) throw new Error("writer adoption page must advance"); Lines 696–776 at 318 (were 559–567 at 116)
562− * Apply more stored entries to a copy loaded for reading (#41, replay):
563− * scrubbing forward applies only what's new. Never for the live project.
699+ * Extend derived historical indexes from an already checkpointed prefix. 700+ * The host supplies only new canonical frames inside its commit transaction. 702+ static extendHistoricalPage( 703+ storage: GraphStateStorage, 706+ frames: Iterable<WriterAdoptionFrame>; 709+ /** The host supplies disk-backed decoded entries and verified byte counts. */ 710+ decodedFrames?: boolean; 711+ beginRevision(logLength: number): void; 712+ /** Verify both the saved prefix and the new frames against canonical authority. */ 713+ validateAuthority(): void; 715+ ): { next: number; entries: number; bytes: number } { 717+ !Number.isSafeInteger(input.from) || 719+ !Number.isSafeInteger(input.maxEntries) || 720+ input.maxEntries < 1 || 721+ input.maxEntries > 256 || 722+ !Number.isSafeInteger(input.maxBytes) || 723+ input.maxBytes < 1 || 724+ (input.maxBytes > 8_000_000 && input.decodedFrames !== true) 726+ throw new Error("invalid historical extension bounds"); 727+ const validate = () => { 728+ const result: unknown = input.validateAuthority(); 729+ if (result && (typeof result === "object" || typeof result === "function") && "then" in result) 730+ throw new Error("historical authority must be synchronous"); 732+ return storage.transaction(() => { 734+ const project = Project.#openWriter( 737+ throw new Error("history derivation cannot append canonical entries"); 744+ project.#loading = true; 747+ for (const frame of input.frames) { 748+ if (input.decodedFrames && "json" in frame) throw new Error("decoded adoption requires decoded frames"); 749+ const size = adoptionFrameBytes(frame); 751+ entries >= input.maxEntries || 752+ frame.seq !== input.from + entries || 753+ !Number.isSafeInteger(size) || 755+ size > input.maxBytes - bytes 757+ throw new Error("historical extension exceeds bounds or is not contiguous"); 759+ if (bytes > input.maxBytes) throw new Error("historical extension exceeds byte bound"); 760+ input.beginRevision(frame.seq + 1); 761+ project.#apply(adoptionFrameEntry(frame)); 763+ project.#persistMutable(); 764+ project.#writeCheckpoint(); 767+ if (!entries) throw new Error("historical extension must advance"); 769+ return { next: input.from + entries, entries, bytes }; 773+ /** Apply more entries to a replay copy. Never for the live project. */ 565774 catchUp(entries: Iterable<Entry>): void { 566775 this.#loading = true; Lines 813–820 at 318 (were 604–611 at 116)
604813 return modesOf(this.#sharedView()); 607− /** Shared as a View, for reading lines (blame, why). Don't hold on to it across calls. */
608− sharedView(): View {
816+ /** Shared as a ReadView, for reading lines (blame, why). Don't hold on to it across calls. */ 817+ sharedView(): ReadView { 609818 return this.#sharedView(); Lines 828–834 at 318 (were 619–625 at 116)
619828 * The view is laid out on first use: where asks every agent, most have no changes, and a big project has more 620829 * agents than the view cache holds, so building every view cost each call about 0.7 s. 622− draftOf(agentName: string): { atoms: AtomId[]; readonly view: View } | undefined {
831+ draftOf(agentName: string): { atoms: AtomId[]; readonly view: ReadView } | undefined { 623832 const agent = this.#agents.get(agentName); 624833 if (!agent) return undefined; 625834 const view = () => this.#agentView(agent); Lines 874–885 at 318 (were 665–670 at 116)
665874 return p && { agent: p.agent, message: p.message, time: p.time }; 877+ /** The atoms a version of shared, or of a named draft, added to its space: what was pushed together (blame's trail). */ 878+ versionAtoms(version: number, draft: string | null = null): readonly AtomId[] { 879+ const space = draft === null ? this.#shared : this.#spaces.get(draft); 880+ return space?.versions[version]?.atoms ?? []; 668883 /** The graph, for reading (blame, history). Don't add to it. */ 669884 get graph(): Graph { 670885 return this.#graph; Lines 970–976 at 318 (were 755–761 at 116)
755970 * last makes it one-way: a file kept whole stays whole while it exists, 756971 * even if it shrinks or the rule changes, so it never flips back and forth. 758− #isWhole(path: string, length: number, view: View | undefined, rules: readonly string[]): boolean {
973+ #isWhole(path: string, length: number, view: ReadView | undefined, rules: readonly string[]): boolean { 759974 return hostedIsWhole(this.#wholeHost, path, length, view, rules); Lines 978–984 at 318 (were 763–769 at 116)
764979 files: Readonly<Record<string, string | null>>, 765980 blobs: Readonly<Record<string, string>>, 766− view: View | undefined,
981+ view: ReadView | undefined, 768983 ): { files: Record<string, string | null>; blobs: Record<string, string> } { 769984 return hostedWholeOut(this.#wholeHost, files, blobs, view, config); Lines 1107–1113 at 318 (were 892–897 at 116)
8931108 /** The project's reviewers per area (#44): avcs.json's `"review": [{"paths": [...], "reviewer": "..."}]` in shared. */ 8941109 #reviewRules(): ReviewRule[] { 1110+ if (["abso.json", "avcs.json"].every((path) => this.#graph.startCodeOf(path) === undefined)) return []; 8951111 return reviewRulesIn(projectFileIn(this.#sharedView())?.text); Lines 1299–1305 at 318 (were 1083–1089 at 116)
10841300 #mergeIdentical( 10851301 agent: AgentState, 1086− before: View,
10871303 oldBase: ReadonlySet<AtomId>, 10881304 oldVersion: number, Lines 1348–1396 at 318 (were 1132–1137 at 116)
11321348 return hostedAnnouncePerson(this.#announceHost, ...args); 1351+ /** The definition news the writes since the last call owe other agents, handed over once (news.ts). */ 1352+ takeOwedDefinitionNews(): OwedDefinitionNews[] { 1353+ const owed = this.#owed; 1358+ /** What a publish owes, worked out against its version (news.ts newsOwed), for `only` these agents if given. Reads only. */ 1359+ newsOwed(owed: OwedDefinitionNews, only?: readonly string[]): { agent: string; items: NewsItem[] }[] { 1360+ return hostedNewsOwed(this.#newsHost, owed, only); 1363+ /** newsOwed, under the name owed definition news had before abso 714. */ 1364+ definitionNewsOwed(owed: OwedDefinitionNews, only?: readonly string[]): { agent: string; items: NewsItem[] }[] { 1365+ return this.newsOwed(owed, only); 1368+ /** The names a publish's definitions changed (news.ts owedNewsNames), worked out once for its owed news. Reads only. */ 1369+ owedNewsNames(owed: OwedDefinitionNews): string[] { 1370+ return hostedOwedNewsNames(this.#newsHost, owed); 1373+ /** The agents a publish's owed news may be for (news.ts owedAgents). Reads only. */ 1374+ owedAgents(owed: OwedDefinitionNews): string[] { 1375+ return hostedOwedAgents(this.#newsHost, owed); 1378+ /** Tells each agent its owed items, as queueNews does: what an agent was already told adds nothing. */ 1379+ deliverOwedNews(found: readonly { agent: string; items: readonly NewsItem[] }[]): number { 1380+ const entries: Entry[] = []; 1381+ for (const { agent: name, items } of found) { 1382+ const agent = this.#agents.get(name); 1383+ if (agent) this.#queueNews(agent, items, entries); 1385+ this.#flush(entries); 1386+ return entries.length; 1389+ /** A seat's earlier chat hears that another chat just used the seat (announce.ts seatNotice). */ 1390+ seatNotice(...args: Tail<Parameters<typeof hostedSeatNotice>>): ReturnType<typeof hostedSeatNotice> { 1391+ return hostedSeatNotice(this.#announceHost, ...args); 11361395 * Say what the agent is starting on (#37, #13), before any edit lands: 11371396 * `text`, and the files it expects to change if it knows them. Nothing is Lines 1429–1435 at 318 (were 1170–1176 at 116)
11721431 /** The collided changes behind each block whose marker lines `atom` deletes (#11). */ 1173− #markersSettled(agent: AgentState, view: View, atom: Atom): AtomId[] {
1432+ #markersSettled(agent: AgentState, view: ReadView, atom: Atom): AtomId[] { 11741433 return hostedMarkersSettled(this.#markerHost, agent, view, atom); Lines 1492–1508 at 318 (were 1233–1238 at 116)
12331492 return hostedOverlapNews(this.#overlapHost, ...args); 1495+ /** The news waiting for an agent, read only: nothing is taken, heard or written. None for an agent it hasn't got. */ 1496+ peekNews(agentName: string): { text: string; at: number | null }[] { 1497+ const agent = typeof agentName === "string" ? this.#agents.get(agentName) : undefined; 1498+ return agent ? agent.news.map((text, i) => ({ text, at: agent.newsAt[i] ?? null })) : []; 1501+ /** Whether the project has this agent. Read only. */ 1502+ hasAgent(agentName: string): boolean { 1503+ return typeof agentName === "string" && this.#agents.get(agentName) !== undefined; 12361506 /** Hand over the news waiting for an agent (collisions, definitions, moves, announcements), once. */ 12371507 news(agentName: string): { news: string[]; items: { text: string; at: number | null }[] } { 12381508 const entries: Entry[] = []; Lines 1591–1597 at 318 (were 1321–1327 at 116)
13221592 changes: AtomId[], 1324− ): { collisions: Collision[]; newer: Set<AtomId>; union: Set<AtomId> } {
1594+ ): { collisions: Collision[]; newer: ReadonlySet<AtomId>; union: ReadonlySet<AtomId> } { 13251595 return hostedLandCollisions(this.#landHost, space, changes, pick); Lines 1686–1692 at 318 (were 1416–1422 at 116)
14161686 * the one file ever in the view it matches, for a file since taken out. 14171687 * A path that matches two files is answered exactly. 1419− spellingIn(view: View, path: string): string {
1689+ spellingIn(view: ReadView, path: string): string { 14201690 if (view.hasFile(path)) return path; 14211691 const key = pathKey(path); 14221692 const live = view.knownPaths().filter((p) => pathKey(p) === key && view.hasFile(p)); Lines 1713–1739 at 318 (were 1443–1448 at 116)
14431713 const versionsBefore = this.#spaces.get(SHARED)?.versions.length ?? 0; 14451715 this.#applyEntry(entry, at, keptTime); 1716+ // Shared's closure, kept per version on disk (abso Capacity): after the entry, since its atoms join the graph after 1718+ if (this.#writerStorage && (this.#spaces.get(SHARED)?.versions.length ?? 0) > versionsBefore) { 1719+ const shared = this.#spaces.get(SHARED)!; 1720+ const storage = this.#writerStorage; 1721+ indexClosure(storage, shared, this.#graph); 1722+ // Each new version's changed files, from what it touched (version-files.ts): kept in the shapes table when 1723+ // the host gives one, so the log, a path's history and the tree never lay versions out to find them. 1724+ const host: VersionFilesHost = { 1726+ graph: this.#graph, 1727+ at: (v) => this.#at(shared, v), 1728+ viewAt: (v) => this.#viewAt(shared, v), 1729+ empty: () => new View(this.#graph, []), 1730+ closureChangedAt: (v) => closureChangedAt(storage, v), 1732+ for (let v = versionsBefore; v < shared.versions.length; v++) { 1733+ const { files, exists } = keptVersionFiles(host, shared.versions[v]!); 1734+ this.#paths.keep(shared, v, files, v === 0 ? host.empty() : host.viewAt(v - 1), host.viewAt(v), exists); 14471738 // Positions by version: where each version of shared was made. 14481739 const versionsAfter = this.#spaces.get(SHARED)?.versions.length ?? 0; Lines 1782–1799 at 318 (were 1491–1497 at 116)
14911782 if (this.#pending.length === 0) return; 14921783 const out = this.#pending; 14931784 this.#store.append(out); 1785+ if (this.#newsWritten) { 1786+ const items: NewsWritten[] = []; 1787+ out.forEach((entry, i) => { 1788+ if (entry.type !== "news") return; 1789+ for (const text of entry.text) 1790+ items.push({ agent: entry.agent, text, at: entry.time ?? null, seq: this.#stored + i }); 1792+ if (items.length > 0) this.#newsWritten(items); 14941794 this.#persistMutable(); 1795+ // A few more agents' old told lists into their buckets at each write, until every row has moved (writer-agents.ts). 1796+ if (this.#agents instanceof WriterAgents) this.#agents.moveOldTold(OLD_TOLD_PER_WRITE); 14951797 this.#pending = []; 14961798 this.#stored += out.length; 14971799 this.#writeCheckpoint(); Lines 1887–1895 at 318 (were 1585–1590 at 116)
15851887 spaceNamed: (name) => this.#spaceNamed(name), 15861888 checkVersion: (space, version) => this.#checkVersion(space, version), 15871889 viewAt: (space, version) => this.#viewAt(space, version), 1890+ keptPaths: (space, version) => this.#keptPaths(space, version), 1891+ authorTotals: (space, version, agent) => this.#authorTotals(space, version, agent as AgentState | undefined), 1892+ agentTouched: (agent) => this.#agentTouched(agent as AgentState), 15881893 agentView: (agent) => this.#agentView(agent as AgentState), 15891894 spellingIn: (view, asked) => this.spellingIn(view, asked), 15901895 pathsOf: (space) => this.#paths.pathsOf(space), Lines 1900–1956 at 318 (were 1595–1600 at 116)
15951900 return this.#host; 1903+ /** Shared's file list from kept shapes on a stored writer, where a version's layout reads its files from disk. */ 1904+ #keptPaths(space: Space, version: number): string[] | undefined { 1905+ return this.#writerStorage && space.name === SHARED ? this.#paths.keptPaths(space, version) : undefined; 1909+ * Each file's kept author totals for tree with authors (version-files.ts), on a stored writer and for shared only. An 1910+ * agent's view takes its base's totals for every file its draft doesn't touch, as its layout does (touchedBeyond), 1911+ * and lays out the rest; a draft that moves lines lays out everything. 1916+ agent?: AgentState, 1917+ ): ((path: string) => FileTotals | undefined) | undefined { 1918+ const storage = this.#writerStorage; 1919+ if (!storage || space.name !== SHARED || authoredVersion(storage) === undefined) return undefined; 1920+ if (!agent) return (path) => authorTotalsAt(storage, path, version); 1921+ const except = this.#agentTouched(agent); 1922+ if (!except) return undefined; 1923+ return (path) => (except.has(path) ? undefined : authorTotalsAt(storage, path, version)); 1927+ * The files an agent's draft, and whatever it depends on beyond its base, can make differ from its base 1928+ * (touchedBeyond); every other file is the same in both. Undefined when the draft moves lines. 1930+ #agentTouched(agent: AgentState): ReadonlySet<string> | undefined { 1931+ if (agent.mine.length === 0) return new Set(); 1932+ const base = this.#viewAt(this.#spaceOf(agent), agent.base); 1933+ const view = this.#agentView(agent); 1934+ return touchedBeyond(this.#graph, base.set, agent.mine, [base, view], () => placedBetween(view, base)); 1938+ * Kept author totals for a folder's blame (blame.ts), where blame reads: shared at a version (the newest by default) or 1939+ * an agent's view. A named draft has none. Undefined when none are kept. 1941+ authorTotalsFor(where: { 1945+ }): ((path: string) => FileTotals | undefined) | undefined { 1946+ if (where.draft !== undefined) return undefined; 1947+ if (where.agent !== undefined) { 1948+ const agent = this.#agents.get(where.agent); 1949+ return agent ? this.#authorTotals(this.#spaceOf(agent), agent.base, agent) : undefined; 1951+ return this.#authorTotals(this.#shared, where.version ?? last(this.#shared)); 15981954 /** One folder at a version (history.ts). */ 15991955 tree(...args: Tail<Parameters<typeof historyTree>>): ReturnType<typeof historyTree> { 16001956 return historyTree(this.#history, ...args); Lines 2009–2045 at 318 (were 1653–1664 at 116)
16532009 return versionFileAt(this.#logHost, ...args); 2012+ /** fileAt for exactly this spelling, from the file's own lines: no list of the version's files (version-log.ts). */ 2013+ fileExactAt(...args: Tail<Parameters<typeof versionFileExactAt>>): ReturnType<typeof versionFileExactAt> { 2014+ return versionFileExactAt(this.#logHost, ...args); 16562017 /** Every file that differs between two versions of shared (or a named draft) (version-log.ts). */ 16572018 compare(...args: Tail<Parameters<typeof versionCompare>>): ReturnType<typeof versionCompare> { 16582019 return versionCompare(this.#logHost, ...args); 1661− /** A version of shared (or of a named draft) as a View (version-log.ts). */
2022+ /** compare as each file's size and SHA-256, not its texts (version-log.ts, abso issue 680). */ 2023+ compareSummary(...args: Tail<Parameters<typeof versionCompareSummary>>): ReturnType<typeof versionCompareSummary> { 2024+ return versionCompareSummary(this.#logHost, ...args); 2027+ /** A version of shared without some earlier versions, or the refusal naming what builds on them (without.ts). */ 2028+ without(version: number, versions: readonly number[]): ReturnType<typeof hostedWithout> { 2029+ const host: WithoutHost = { 2030+ graph: this.#graph, 2031+ shared: () => this.#shared, 2032+ needInit: () => this.#needInit(), 2033+ checkVersion: (space, v) => this.#checkVersion(space, v), 2034+ viewAt: (space, v) => this.#viewAt(space, v), 2035+ at: (space, v) => this.#at(space, v), 2036+ closed: (set) => this.#closed(set), 2037+ touchedFiles: (ids, views) => this.#touchedFiles(ids, views), 2039+ return hostedWithout(host, version, versions); 2042+ /** A version of shared (or of a named draft) as a ReadView (version-log.ts). */ 16622043 viewAt(...args: Tail<Parameters<typeof versionViewAt>>): ReturnType<typeof versionViewAt> { 16632044 return versionViewAt(this.#logHost, ...args); Lines 2057–2099 at 318 (were 1676–1688 at 116)
16762057 definitionRule: () => this.#definitionRule, 16772058 draft: (agent) => this.#draft(agent as AgentState), 16782059 agentView: (agent) => this.#agentView(agent as AgentState), 1679− view: (set) => this.#view(set),
1680− pairs: (draft, against, settled) => this.#pairs(draft, against, settled),
2060+ draftsView: (agents) => this.#draftsView(agents as readonly AgentState[]), 16812061 touchedFiles: (ids, views) => this.#touchedFiles(ids, views), 2062+ // On a stored writer only, as a reader kept between calls is (abso Capacity). 2063+ keptParts: () => (this.#writerStorage ? (this.#keptParts ??= new KeptParts()) : undefined), 2064+ draftKey: (agent) => { 2065+ const a = agent as AgentState; 2066+ return `${last(this.#shared)} ${a.space}@${a.base} ${this.#draft(a).join(",")}`; 16832069 return this.#draftCollisionHost; 2073+ * Shared now with some agents' drafts on top, for draft collisions (abso Capacity). Kept under the drafts' atoms and 2074+ * shared's version, so a second ask with nothing changed lays nothing out again, and laid out as shared is for every 2075+ * file the drafts don't touch, as an agent's view is. One agent based on shared's newest version is its own view. 2077+ #draftsView(agents: readonly AgentState[]): ReadView { 2078+ const shared = this.#shared; 2079+ const version = last(shared); 2080+ const only = agents.length === 1 ? agents[0]! : undefined; 2081+ if (only && only.space === SHARED && only.base === version) return this.#agentView(only); 2082+ const drafts = agents.map((agent) => this.#draft(agent)); 2083+ const mine = drafts.flat(); 2084+ const base = this.#sharedView(); 2085+ const view = this.#viewKeyed(`d ${SHARED}@${version}+${drafts.map((d) => d.join(",")).join("+")}`, () => 2086+ unionOverlay(base.set, mine), 2088+ if (this.#writerStorage && mine.length > 0 && view instanceof View && base instanceof View) { 2089+ view.shareMoves(base); 2090+ view.shareFiles(base, () => 2091+ touchedBeyond(this.#graph, base.set, mine, [base, view], () => placedBetween(view, base)), 16862097 /** Whether agents' unpublished changes would collide, by the publish rule (draft-collisions.ts). */ 16872098 collisions(...args: Tail<Parameters<typeof draftCollisions>>): ReturnType<typeof draftCollisions> { 16882099 return draftCollisions(this.#draftCollisions, ...args); Lines 2108–2117 at 318 (were 1697–1702 at 116)
16972108 needInit: () => this.#needInit(), 16982109 draft: (agent) => this.#draft(agent as AgentState), 16992110 agentView: (agent) => this.#agentView(agent as AgentState), 2111+ agentViewWithout: (agent, excluded) => { 2112+ const state = agent as AgentState; 2113+ return this.#agentView({ ...state, mine: state.mine.filter((id) => !excluded.has(id)) }); 17002115 view: (set) => this.#view(set), 17012116 touchedFiles: (ids, views) => this.#touchedFiles(ids, views), Lines 2138–2153 at 318 (were 1723–1728 at 116)
17232138 this.#movesHost ??= { 17242139 graph: this.#graph, 17252140 draft: (agent) => this.#unqueuedDraft(agent), 2141+ beforeDraft: (agent, draft) => { 2142+ const base = this.#at(this.#spaceOf(agent), agent.base); 2143+ if (draft.some((id) => base.has(id))) 2144+ return this.#view(differenceSet(this.#agentView(agent).set, new StableOverlaySet(draft))); 2145+ const removed = new Set(draft), 2146+ kept = agent.mine.filter((id) => !removed.has(id)); 2147+ return kept.length === 0 2148+ ? this.#viewAt(this.#spaceOf(agent), agent.base) 2149+ : this.#viewKeyed(`a ${agent.space}@${agent.base}+${kept.join(",")}`, () => unionOverlay(base, kept)); 17262151 agentView: (agent) => this.#agentView(agent), 17272152 view: (set) => this.#view(set), 17282153 apply: (entry) => this.#apply(entry), Lines 2184–2201 at 318 (were 1759–1766 at 116)
17592184 viewAt: (space, version) => this.#viewAt(space, version), 17602185 origin: (atom, spaceName) => this.#origin(atom, spaceName), 17612186 collision: (agent, pair) => this.#collision(agent, pair), 1762− definitionCollisions: (agent, newer) => this.#definitionCollisions(agent, newer),
2187+ definitionCollisions: (agent, newer, names) => this.#definitionCollisions(agent, newer, names), 17632188 queueNews: (agent, items, entries) => this.#queueNews(agent, items, entries), 2189+ logLine: (line) => this.#logLine?.(line), 2190+ owesDefinitionNews: () => this.owesDefinitionNews, 2191+ owe: (owed) => void this.#owed.push(owed), 2192+ spaceNamed: (name) => (name === SHARED ? this.#shared : this.#spaces.get(name)), 2193+ newerAt: (agent, version) => this.#newerFor(agent, version), 2194+ definitionCollisionsAt: (agent, newer, names, version) => 2195+ this.#definitionCollisions(agent, newer, names, version), 2196+ setAt: (space, version) => this.#at(space, version), 2197+ collisionAt: (agent, pair, version) => 2198+ this.#describe(pair, this.#agentView(agent), this.#viewAt(this.#spaceOf(agent), version), agent.space), 17652200 return this.#news; Lines 2207–2213 at 318 (were 1772–1778 at 116)
17722207 spaces: this.#spaces, 17732208 version: () => this.version, 17742209 spaceOf: (agent) => this.#spaceOf(agent), 1775− agentSet: (agent) => this.#agentSet(agent),
2210+ agentSet: (agent) => unionOverlay(this.#at(this.#spaceOf(agent), agent.base), agent.mine), 17762211 draft: (agent) => this.#draft(agent), 17772212 agentView: (agent) => this.#agentView(agent), 17782213 at: (space, version) => this.#at(space, version), Lines 2349–2365 at 318 (were 1914–1926 at 116)
19142349 collision: (agent, pair) => this.#collision(agent, pair), 19152350 definitionCollisions: (agent, newer) => this.#definitionCollisions(agent, newer), 19162351 duplicates: (agent) => this.#duplicates(agent), 1917− refuse: (agent, space, via, time, collisions, entries) =>
1918− this.#refuse(agent, space, via, time, collisions, entries),
2352+ refuse: (agent, space, via, time, collisions, entries, message) => 2353+ this.#refuse(agent, space, via, time, collisions, entries, message), 19192354 markerCollisions: (agent) => this.#markerCollisions(agent), 19202355 enqueue: (agent, message, time, draft, resolves, entries) => 19212356 this.#enqueue(agent, message, time, draft, resolves, entries), 19222357 view: (set) => this.#view(set), 19232358 requireClosed: (tie, union) => this.#requireClosed(tie, union), 2359+ spaceOverlay: (space, atoms) => 2360+ this.#viewKeyed(`a ${space.name}@${last(space)}+${atoms.join(",")}`, () => 2361+ unionOverlay(this.#setOf(space), atoms), 19242363 newerFor: (agent) => this.#newerFor(agent), 19252364 currentChange: (agent, time) => this.#currentChange(agent, time), 19262365 apply: (entry) => this.#apply(entry), Lines 2378–2395 at 318 (were 1939–1944 at 116)
19392378 graph: this.#graph, 19402379 checkerReady: () => this.checkerReady, 19412380 sharedView: () => this.#sharedView(), 2381+ sharedOverlay: (atoms) => 2382+ this.#viewKeyed(`a @${last(this.#shared)}+${atoms.join(",")}`, () => 2383+ unionOverlay(this.#setOf(this.#shared), atoms), 2385+ sharedAgentOverlay: (agent, atoms) => { 2386+ const current = this.#setOf(this.#shared); 2387+ const added = new Set([...atoms, ...agent.mine]); 2388+ // Retain old-base atoms absent from current shared, without copying shared history. 2389+ if (agent.base !== last(this.#shared)) 2390+ for (const id of this.#at(this.#spaceOf(agent), agent.base)) if (!current.has(id)) added.add(id); 2391+ return this.#viewKeyed(`a @${last(this.#shared)}+${[...added].join(",")}`, () => unionOverlay(current, added)); 19422393 queued: () => this.#queue, 19432394 queuedId: () => this.#queuedId, 19442395 checkingHas: (id) => this.#checking.has(id), Lines 2408–2415 at 318 (were 1957–1964 at 116)
19572408 pairs: (draft, against, settled) => this.#pairs(draft, against, settled), 19582409 describe: (pair, yoursView, theirsView, spaceName) => this.#describe(pair, yoursView, theirsView, spaceName), 19592410 touchedFiles: (ids, views) => this.#touchedFiles(ids, views), 1960− refuse: (agent, space, via, time, collisions, entries) =>
1961− this.#refuse(agent, space, via, time, collisions, entries),
2411+ refuse: (agent, space, via, time, collisions, entries, message) => 2412+ this.#refuse(agent, space, via, time, collisions, entries, message), 19622413 currentChange: (agent, time) => this.#currentChange(agent, time), 19632414 nextAt: () => this.#nextAt, 19642415 apply: (entry) => this.#apply(entry), Lines 2476–2487 at 318 (were 2025–2030 at 116)
20252476 #landers?: LandHost; 20262477 get #landHost(): LandHost { 20272478 this.#landers ??= { 2479+ viewAt: (space, version, changes) => 2481+ ? this.#viewKeyed(`a ${space.name}@${version}+${changes.join(",")}`, () => 2482+ unionOverlay(this.#at(space, version), changes), 2484+ : this.#viewAt(space, version), 20282485 agents: this.#agents, 20292486 graph: this.#graph, 20302487 spaces: this.#spaces, Lines 2499–2507 at 318 (were 2042–2047 at 116)
20422499 pairs: (draft, against, settled) => this.#pairs(draft, against, settled), 20432500 describe: (pair, yoursView, theirsView, spaceName) => this.#describe(pair, yoursView, theirsView, spaceName), 20442501 definitionRule: () => this.#definitionRule, 2502+ // Only from a stored writer's kept rows, as keptPaths: a project in memory keeps none, and works them out. 2503+ changedSince: (space, from, to) => 2504+ this.#writerStorage ? this.#paths.keptChangesSince(space, from, to) : undefined, 20452505 refuse: (agent, space, via, time, collisions, entries) => 20462506 this.#refuse(agent, space, via, time, collisions, entries), 20472507 requireClosed: (tie, union) => this.#requireClosed(tie, union), Lines 2548–2555 at 318 (were 2088–2093 at 116)
20882548 view: (set) => this.#view(set), 20892549 agentSet: (agent) => this.#agentSet(agent), 20902550 agentView: (agent) => this.#agentView(agent), 2551+ agentViewWithout: (agent, excluded) => 2552+ this.#agentView({ ...agent, mine: agent.mine.filter((id) => !excluded.has(id)) }), 20912553 recordFile: (agent, view, path, text, time, meta, entries, mode, blob, hunks) => 20922554 this.#recordFile(agent, view, path, text, time, meta, entries, mode, blob, hunks), 20932555 flush: (entries) => this.#flush(entries), Lines 2580–2591 at 318 (were 2118–2123 at 116)
21182580 agent: (name, entries) => this.#agent(name, entries), 21192581 spaceOf: (agent) => this.#spaceOf(agent), 21202582 agentView: (agent) => this.#agentView(agent), 2583+ captureAgentView: (agent) => { 2584+ const key = this.#agentViewKey(agent); 2585+ const original = this.#agentView(agent); 2586+ // Projected readers reopen the immutable key; only the in-memory fallback uses the original set. 2587+ return () => this.#viewKeyed(key, () => original.set); 21212589 at: (space, version) => this.#at(space, version), 21222590 draft: (agent) => this.#draft(agent), 21232591 strandedFiles: (draft, set) => this.#strandedFiles(draft, set), Lines 2652–2664 at 318 (were 2184–2191 at 116)
21842652 get #checkClashHost(): CheckClashHost { 21852653 this.#checkClashes ??= { 21862654 shared: () => this.#shared, 2655+ setOf: (space) => this.#setOf(space), 21872656 view: (set) => this.#view(set), 21882657 sharedView: () => this.#sharedView(), 2658+ sharedOverlay: (atoms) => 2659+ this.#viewKeyed(`a @${last(this.#shared)}+${atoms.join(",")}`, () => 2660+ unionOverlay(this.#setOf(this.#shared), atoms), 21892662 touchedFiles: (ids, views) => this.#touchedFiles(ids, views), 21912664 return this.#checkClashes; Lines 2871–2877 at 318 (were 2398–2403 at 116)
23982871 spaceNamed: (name) => this.#spaceNamed(name), 23992872 checkVersion: (space, version) => this.#checkVersion(space, version), 24002873 viewAt: (space, version) => this.#viewAt(space, version), 2874+ keptPaths: (space, version) => this.#keptPaths(space, version), 24012875 agentView: (agent) => this.#agentView(agent), 24022876 version: () => this.version, 24032877 projectFile: () => (this.initialized ? projectFileIn(this.#sharedView()) : undefined), Lines 2946–2973 at 318 (were 2472–2484 at 116)
24722946 return new Set([...this.#at(this.#spaceOf(agent), agent.base), ...agent.mine]); 2475− #agentView(agent: AgentState): View {
2476− return this.#viewKeyed(this.#agentViewKey(agent), () => {
2949+ #agentView(agent: AgentState): ReadView { 2950+ const view = this.#viewKeyed(this.#agentViewKey(agent), () => { 24772951 const base = this.#at(this.#spaceOf(agent), agent.base); 24782952 return base instanceof StableSet 24792953 ? new StableUnionSet(base, new StableOverlaySet(agent.mine)) 24802954 : new Set([...base, ...agent.mine]); 2956+ // A draft that moves nothing resolves its moves as its base does (abso Capacity): take them from the base's view. 2957+ if (this.#writerStorage && agent.mine.length > 0 && view instanceof View) { 2958+ const base = this.#viewAt(this.#spaceOf(agent), agent.base); 2959+ if (base instanceof View) { 2960+ view.shareMoves(base); 2961+ // And its layout of every file the draft doesn't touch, when the draft moves nothing (abso Capacity). What the 2962+ // view holds beyond its base is the draft and whatever the draft depends on that the base lacks (the view's 2963+ // set is closed): each of those can change a file, so all of them count. 2964+ const mine = agent.mine; 2965+ view.shareFiles(base, () => 2966+ touchedBeyond(this.#graph, base.set, mine, [base, view], () => placedBetween(view, base)), 24842973 /** An agent's view, keyed by what the set is made of, not by sorting every atom in it (#46): that cost more than the work. */ Lines 2979–3015 at 318 (were 2490–2510 at 116)
24922981 /** A space at a version: published versions never change, so the key is just their names (#46). */ 2493− #viewAt(space: Space, version: number): View {
2494− return this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version));
2982+ #viewAt(space: Space, version: number): ReadView { 2983+ const view = this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version)); 2984+ // Which files it has from the kept path list (abso Capacity, View.knowPaths), as pathsAt answers. 2985+ if (view instanceof View && this.#writerStorage && space.name === SHARED) 2986+ view.knowPaths(() => this.#paths.keptPathSet(space, version)); 2497− #sharedView(): View {
2990+ #sharedView(): ReadView { 24982991 return this.#viewAt(this.#shared, last(this.#shared)); 2995+ * After each read of a reader kept between calls, one that changed nothing (abso Capacity): the cached views back 2996+ * under their budget, since views grow while a call lays files out and the cache weighs them only when they are 2997+ * asked for again (on abso, a tree with authors left 38 MB of views held against the 24 MB budget), and the agents 2998+ * the read decoded let go, read again from storage by the next call (7 MB on abso, every agent's news told). 3000+ afterRead(): void { 3001+ this.#views.trim(); 3002+ if (this.#agents instanceof WriterAgents) this.#agents.release(); 25013005 /** A view of a set, cached by the set's exact contents (views.ts). */ 2502− #view(set: ReadonlySet<AtomId>): View {
3006+ #view(set: ReadonlySet<AtomId>): ReadView { 3007+ this.#views.assertUnkeyedAllowed(); 25033008 return this.#views.view(this.#closed(set)); 25063011 /** A view cached under `key` (views.ts). */ 2507− #viewKeyed(key: string, set: () => ReadonlySet<AtomId>): View {
3012+ #viewKeyed(key: string, set: () => ReadonlySet<AtomId>): ReadView { 25083013 return this.#views.keyed(key, () => this.#closed(set())); Lines 3018–3037 at 318 (were 2513–2521 at 116)
25133018 * (abso issue 80). A closed set is unchanged. 25153020 #closed(set: Iterable<AtomId>): ReadonlySet<AtomId> { 3021+ if (isClosedSet(set)) return set as ReadonlySet<AtomId>; 25163022 if (set instanceof StableSet) { 25173023 // Keep indexed membership external. Only dependencies absent from 2518− // that snapshot belong in the operation's closure overlay.
3024+ // that snapshot belong in the operation's closure overlay. Over a stored closed base (abso Capacity), 3025+ // only the atoms outside it can reach outside it: unions are opened down to their closed parts. 3026+ const walk: Iterable<AtomId>[] = []; 3027+ const open = (part: ReadonlySet<AtomId>): void => { 3028+ if (isClosedSet(part)) return; 3029+ if (part instanceof StableUnionSet) { 3032+ } else walk.push(part); 25193035 const missing = new Set<AtomId>(); 25203036 const visit = (id: AtomId) => { 25213037 const stack = [id]; Lines 3044–3051 at 318 (were 2528–2535 at 116)
2531− for (const id of set) visit(id);
2532− return missing.size ? new StableUnionSet(set, new StableOverlaySet(missing)) : set;
3047+ for (const part of walk) for (const id of part) visit(id); 3048+ return markClosed(missing.size ? new StableUnionSet(set, new StableOverlaySet(missing)) : set); 25343050 return this.#graph.closureOf(set); Lines 3061–3076 at 318 (were 2545–2555 at 116)
25473063 /** The space's atoms published after the agent's base, by others. */ 2548− #newerFor(agent: AgentState): Set<AtomId> {
3064+ /** `upTo`: the work published after the agent's base up to that version only (owed news, news.ts). */ 3065+ #newerFor(agent: AgentState, upTo?: number): ReadonlySet<AtomId> { 25493066 const space = this.#spaceOf(agent); 25503067 const base = this.#at(space, agent.base); 2551− const mine = new Set(agent.mine);
2552− return new Set([...this.#setOf(space)].filter((id) => !base.has(id) && !mine.has(id)));
3068+ const current = upTo === undefined ? this.#setOf(space) : this.#at(space, upTo); 3070+ space.name === SHARED && space.membershipVersion 3071+ ? new SharedAdditions(space, agent.base, base, current, upTo ?? last(space)) 3072+ : differenceSet(current, base); 3073+ return differenceSet(newer, new StableOverlaySet(agent.mine)); 25553076 /** The files whose text in the agent's view differs from `before`, and its open collisions. */ Lines 3186–3192 at 318 (were 2665–2671 at 116)
2668− #describe(pair: Pair, yoursView: View, theirsView: View, spaceName: string): Collision {
3189+ #describe(pair: Pair, yoursView: ReadView, theirsView: ReadView, spaceName: string): Collision { 26693190 return describePair( 26713192 (atom, space) => this.#origin(atom, space), Lines 3197–3236 at 318 (were 2676–2701 at 116)
2679− #touchedFiles(ids: Iterable<AtomId>, views: readonly View[]): Set<string> {
3200+ #touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string> { 26803201 return touchedFiles(this.#graph, ids, views); 26833204 // The changed-definition rule (#11) ------------------------------------------- 26853206 /** The rule for an agent's draft in its space. */ 2686− #definitionCollisions(agent: AgentState, newer: ReadonlySet<AtomId>): DefinitionCollision[] {
3207+ #definitionCollisions( 3209+ newer: ReadonlySet<AtomId>, 3210+ names?: ReadonlySet<string>, 3211+ /** The space's version to compare against: its newest, or an owed publish's (news.ts). */ 3213+ ): DefinitionCollision[] { 26873214 const draft = new Set(this.#draft(agent)); 26883215 if (draft.size === 0 || newer.size === 0) return []; 26893216 const space = this.#spaceOf(agent); 2690− const mine = new Set(agent.mine);
2691− const base = this.#view(new Set([...this.#at(space, agent.base)].filter((id) => !mine.has(id))));
3217+ const at = this.#at(space, agent.base); 3218+ const base = agent.mine.some((id) => at.has(id)) 3219+ ? this.#view(differenceSet(at, new StableOverlaySet(agent.mine))) 3220+ : this.#viewAt(space, agent.base); 3221+ const to = version ?? last(space); 26923222 return this.#definitionRule.collisions( 26943224 this.#agentView(agent), 2696− this.#viewAt(space, last(space)),
3226+ this.#viewAt(space, to), 3231+ // Where the space changed since the agent's base, from each version's kept files on a stored writer, as land's 3232+ // (abso 714): walking every newer atom for them was 6.5 s of a publish 770 versions behind on abso. 3233+ () => (this.#writerStorage ? this.#paths.keptChangesSince(space, agent.base, to) : undefined),