Lines 36–47 at 318 (were 36–42 at 263)
3636} from "../../src/engine/state-source.ts"; 3737import { type AddDraftHost, addDraft as hostedAddDraft } from "./add-draft.ts"; 3838import { type AmendHost, amend as hostedAmend } from "./amend.ts"; 39−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"; 4045import { type ApplyEntryHost, applyEntry as hostedApplyEntry } from "./apply-entry.ts"; Lines 105–117 at 318 (were 100–108 at 263)
101106 newsAboutOwnDraft as hostedNewsAboutOwnDraft, 102107 newsForOthers as hostedNewsForOthers, 108+ newsOwed as hostedNewsOwed, 109+ owedAgents as hostedOwedAgents, 110+ owedNewsNames as hostedOwedNewsNames, 114+ type OwedDefinitionNews, 108117} from "./news.ts"; Lines 161–167 at 318 (were 152–157 at 263)
Lines 222–228 at 318 (were 212–217 at 263)
212222 compare as versionCompare, 213223 compareSummary as versionCompareSummary, 214224 fileAt as versionFileAt, 225+ fileExactAt as versionFileExactAt, 215226 log as versionLog, 216227 ribbon as versionRibbon, 217228 show as versionShow, Lines 292–302 at 318 (were 281–286 at 263)
281292 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; 284300export class Project { 285301 readonly #store: ProjectStore; 286302 readonly #writerStorage?: GraphStateStorage; Lines 335–351 at 318 (were 319–327 at 263)
319335 * doesn't depend on it. 321337 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[] = []; 322344 readonly #now: (() => number) | undefined; 345+ readonly #newsWritten: ((items: readonly NewsWritten[]) => void) | undefined; 323346 readonly #whole: ProjectOptions["whole"]; 324347 readonly #shapes: ProjectOptions["shapes"]; 348+ readonly #logLine: ProjectOptions["logLine"]; 325349 /** For each log position, the newest time up to it (#41): time to position in one search. */ 326350 readonly #timeAt: number[] = []; 327351 /** For each version of shared, the log position of the entry that made it (#41). */ Lines 465–474 at 318 (were 441–448 at 263)
442466 this.#hasBlob = options.hasBlob ?? (() => false); 443467 this.#now = options.now; 468+ this.#newsWritten = options.newsWritten; 444469 this.#whole = options.whole; 445470 this.#shapes = options.shapes; 471+ this.#logLine = options.logLine; 446472 // For tests (#46): AVCS_TEXT_FROM_LOG=1 runs a project on a MemoryStore with its text read back from the store. 448474 (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.AVCS_TEXT_FROM_LOG === Lines 1348–1396 at 318 (were 1322–1327 at 263)
13221348 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); 13261395 * Say what the agent is starting on (#37, #13), before any edit lands: 13271396 * `text`, and the files it expects to change if it knows them. Nothing is Lines 1492–1508 at 318 (were 1423–1428 at 263)
14231492 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; 14261506 /** Hand over the news waiting for an agent (collisions, definitions, moves, announcements), once. */ 14271507 news(agentName: string): { news: string[]; items: { text: string; at: number | null }[] } { 14281508 const entries: Entry[] = []; Lines 1782–1796 at 318 (were 1702–1707 at 263)
17021782 if (this.#pending.length === 0) return; 17031783 const out = this.#pending; 17041784 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); 17051794 this.#persistMutable(); 17061795 // A few more agents' old told lists into their buckets at each write, until every row has moved (writer-agents.ts). 17071796 if (this.#agents instanceof WriterAgents) this.#agents.moveOldTold(OLD_TOLD_PER_WRITE); Lines 1930–1937 at 318 (were 1841–1847 at 263)
18411930 #agentTouched(agent: AgentState): ReadonlySet<string> | undefined { 18421931 if (agent.mine.length === 0) return new Set(); 18431932 const base = this.#viewAt(this.#spaceOf(agent), agent.base); 1844− return touchedBeyond(this.#graph, base.set, agent.mine, [base, this.#agentView(agent)]);
1933+ const view = this.#agentView(agent); 1934+ return touchedBeyond(this.#graph, base.set, agent.mine, [base, view], () => placedBetween(view, base)); Lines 2009–2019 at 318 (were 1919–1924 at 263)
19192009 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); 19222017 /** Every file that differs between two versions of shared (or a named draft) (version-log.ts). */ 19232018 compare(...args: Tail<Parameters<typeof versionCompare>>): ReturnType<typeof versionCompare> { 19242019 return versionCompare(this.#logHost, ...args); Lines 2087–2095 at 318 (were 1992–1998 at 263)
19932088 if (this.#writerStorage && mine.length > 0 && view instanceof View && base instanceof View) { 19942089 view.shareMoves(base); 1995− view.shareFiles(base, () => touchedBeyond(this.#graph, base.set, mine, [base, view]));
2090+ view.shareFiles(base, () => 2091+ touchedBeyond(this.#graph, base.set, mine, [base, view], () => placedBetween(view, base)), Lines 2184–2201 at 318 (were 2087–2094 at 263)
20872184 viewAt: (space, version) => this.#viewAt(space, version), 20882185 origin: (atom, spaceName) => this.#origin(atom, spaceName), 20892186 collision: (agent, pair) => this.#collision(agent, pair), 2090− definitionCollisions: (agent, newer) => this.#definitionCollisions(agent, newer),
2187+ definitionCollisions: (agent, newer, names) => this.#definitionCollisions(agent, newer, names), 20912188 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), 20932200 return this.#news; Lines 2499–2507 at 318 (were 2392–2397 at 263)
23922499 pairs: (draft, against, settled) => this.#pairs(draft, against, settled), 23932500 describe: (pair, yoursView, theirsView, spaceName) => this.#describe(pair, yoursView, theirsView, spaceName), 23942501 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, 23952505 refuse: (agent, space, via, time, collisions, entries) => 23962506 this.#refuse(agent, space, via, time, collisions, entries), 23972507 requireClosed: (tie, union) => this.#requireClosed(tie, union), Lines 2962–2970 at 318 (were 2852–2858 at 263)
28522962 // view holds beyond its base is the draft and whatever the draft depends on that the base lacks (the view's 28532963 // set is closed): each of those can change a file, so all of them count. 28542964 const mine = agent.mine; 2855− view.shareFiles(base, () => touchedBeyond(this.#graph, base.set, mine, [base, view]));
2965+ view.shareFiles(base, () => 2966+ touchedBeyond(this.#graph, base.set, mine, [base, view], () => placedBetween(view, base)), Lines 3061–3074 at 318 (were 2949–2961 at 263)
29513063 /** The space's atoms published after the agent's base, by others. */ 2952− #newerFor(agent: AgentState): ReadonlySet<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> { 29533066 const space = this.#spaceOf(agent); 29543067 const base = this.#at(space, agent.base); 2955− const current = this.#setOf(space);
3068+ const current = upTo === undefined ? this.#setOf(space) : this.#at(space, upTo); 29573070 space.name === SHARED && space.membershipVersion 2958− ? new SharedAdditions(space, agent.base, base, current)
3071+ ? new SharedAdditions(space, agent.base, base, current, upTo ?? last(space)) 29593072 : differenceSet(current, base); 29603073 return differenceSet(newer, new StableOverlaySet(agent.mine)); Lines 3204–3216 at 318 (were 3091–3097 at 263)
30913204 // The changed-definition rule (#11) ------------------------------------------- 30933206 /** The rule for an agent's draft in its space. */ 3094− #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[] { 30953214 const draft = new Set(this.#draft(agent)); 30963215 if (draft.size === 0 || newer.size === 0) return []; 30973216 const space = this.#spaceOf(agent); Lines 3218–3236 at 318 (were 3099–3111 at 263)
30993218 const base = agent.mine.some((id) => at.has(id)) 31003219 ? this.#view(differenceSet(at, new StableOverlaySet(agent.mine))) 31013220 : this.#viewAt(space, agent.base); 3221+ const to = version ?? last(space); 31023222 return this.#definitionRule.collisions( 31043224 this.#agentView(agent), 3106− 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),