Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 162 to 318

Compare

+380 −17 in 36 places
Lines 12–32 at 318 (were 12–22 at 162)
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.
1414
15−import { type Atom, type AtomId, EngineError, Graph, type LineId, type ReadView } from "../../src/engine/index.ts";
1615import {
16+ type Atom,
17+ type AtomId,
18+ EngineError,
19+ Graph,
20+ type LineId,
21+ type ReadView,
22+ View,
23+} from "../../src/engine/index.ts";
24+import {
1725 CachedStateStorage,
1826 differenceSet,
1927 type GraphStateStorage,
28+ isClosedSet,
29+ markClosed,
2030 StableOverlaySet,
2131 StableSet,
2232 StableUnionSet,
Lines 36–47 at 318 (were 26–32 at 162)
2636} from "../../src/engine/state-source.ts";
2737import { type AddDraftHost, addDraft as hostedAddDraft } from "./add-draft.ts";
2838import { type AmendHost, amend as hostedAmend } from "./amend.ts";
29−import { type AnnounceHost, announce as hostedAnnounce, announcePerson as hostedAnnouncePerson } from "./announce.ts";
39+import {
40+ type AnnounceHost,
41+ announce as hostedAnnounce,
42+ announcePerson as hostedAnnouncePerson,
43+ seatNotice as hostedSeatNotice,
44+} from "./announce.ts";
3045import { type ApplyEntryHost, applyEntry as hostedApplyEntry } from "./apply-entry.ts";
3146import {
3247 type ChangeHost,
Lines 63–69 at 318 (were 48–53 at 162)
4863 type Pair,
4964 pairsIn,
5065 strandedFiles,
66+ touchedBeyond,
5167 touchedFiles,
5268} from "./collisions.ts";
5369import { type DefinitionCollision, DefinitionRule } from "./definition-rule.ts";
Lines 81–87 at 318 (were 65–70 at 162)
6581} from "./history.ts";
6682import { ingest as hostedIngest, type IngestHost } from "./ingest.ts";
6783import { init as hostedInit, type InitHost } from "./init.ts";
84+import { KeptParts } from "./kept-parts.ts";
6885import { label as hostedLabel, type LabelHost } from "./label.ts";
6986import {
7087 land as hostedLand,
Lines 105–117 at 318 (were 88–96 at 162)
88105 addressedItem,
89106 newsAboutOwnDraft as hostedNewsAboutOwnDraft,
90107 newsForOthers as hostedNewsForOthers,
108+ newsOwed as hostedNewsOwed,
109+ owedAgents as hostedOwedAgents,
110+ owedNewsNames as hostedOwedNewsNames,
91111 markedItem,
92112 type NewsHost,
93113 type NewsItem,
114+ type OwedDefinitionNews,
94115 reviewItem,
95116 settledItem,
96117} from "./news.ts";
Lines 161–167 at 318 (were 140–145 at 162)
140161 LandAnswer,
141162 MergedLine,
142163 Modes,
164+ NewsWritten,
143165 NoteAnswer,
144166 NoteBody,
145167 NoteRecord,
Lines 196–228 at 318 (were 174–188 at 162)
174196import { recordFile as hostedRecordFile, type RecordFileHost } from "./record-file.ts";
175197import { refusals as hostedRefusals, refuse as hostedRefuse, type RefuseHost } from "./refuse.ts";
176198import { restore as hostedRestore, type RestoreHost } from "./restore.ts";
177−import { last, Membership, SHARED, SharedAdditions, type Space, sharedBaseOf } from "./spaces.ts";
199+import {
200+ closureChangedAt,
201+ indexClosure,
202+ last,
203+ Membership,
204+ SHARED,
205+ SharedAdditions,
206+ type Space,
207+ sharedBaseOf,
208+} from "./spaces.ts";
178209import { starting as hostedStarting, type StartingHost } from "./start.ts";
179210import { switchTo as hostedSwitchTo, type SwitchHost } from "./switch-to.ts";
180211import { sync as hostedSync, type SyncHost } from "./sync.ts";
181212import { treeHash } from "./tree.ts";
182213import {
214+ authoredVersion,
215+ authorTotalsAt,
216+ type FileTotals,
217+ versionFiles as keptVersionFiles,
218+ type VersionFilesHost,
219+} from "./version-files.ts";
220+import {
183221 type LogHost,
184222 compare as versionCompare,
223+ compareSummary as versionCompareSummary,
185224 fileAt as versionFileAt,
225+ fileExactAt as versionFileExactAt,
186226 log as versionLog,
187227 ribbon as versionRibbon,
188228 show as versionShow,
Lines 242–248 at 318 (were 202–207 at 162)
202242 wholeRules as hostedWholeRules,
203243 type WholeHost,
204244} from "./whole-files.ts";
245+import { without as hostedWithout, type WithoutHost } from "./without.ts";
205246import { WriterAgents } from "./writer-agents.ts";
206247
207248export { MemoryStore } from "./memory-store.ts";
Lines 258–273 at 318 (were 217–222 at 162)
217258/** A start note lasts this long after the agent's last activity (#44). */
218259const NOTE_IDLE = 2 * 60 * 60 * 1000;
219260const WRITER_REOPEN = Symbol("verified writer checkpoint");
261+/**
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.
264+ */
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;
220271export interface WriterSource {
221272 readonly generation: number;
222273 readonly logLength: number;
Lines 292–310 at 318 (were 241–252 at 162)
241292 return "json" in frame ? (JSON.parse(frame.json) as Entry) : frame.entry;
242293}
243294
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;
298+}
244300export class Project {
245301 readonly #store: ProjectStore;
246302 readonly #writerStorage?: GraphStateStorage;
247303 readonly #graph: Graph;
248304 /** Views laid out from atom sets, cached under a byte budget (views.ts). */
249305 readonly #views: ViewCache;
306+ /** What draft collisions keep between calls, under its own byte budget (kept-parts.ts). */
307+ #keptParts: KeptParts | undefined;
250308 /** Each agent's draft files, under the key they were worked out for (#draftFiles). */
251309 readonly #draftFilesKept = new Map<string, { key: string; files: Set<string> }>();
252310 /** Each version's files and each path's history (pathindex.ts). */
Lines 335–351 at 318 (were 277–285 at 162)
277335 * doesn't depend on it.
278336 */
279337 checkerReady = false;
338+ /**
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.
341+ */
342+ owesDefinitionNews = false;
343+ #owed: OwedDefinitionNews[] = [];
280344 readonly #now: (() => number) | undefined;
345+ readonly #newsWritten: ((items: readonly NewsWritten[]) => void) | undefined;
281346 readonly #whole: ProjectOptions["whole"];
282347 readonly #shapes: ProjectOptions["shapes"];
348+ readonly #logLine: ProjectOptions["logLine"];
283349 /** For each log position, the newest time up to it (#41): time to position in one search. */
284350 readonly #timeAt: number[] = [];
285351 /** For each version of shared, the log position of the entry that made it (#41). */
Lines 430–438 at 318 (were 364–370 at 162)
364430 if (options.indexAcceptedAtom && !options.writerStorage)
365431 throw Error("accepted atom indexing requires writer storage");
366432 this.#store = store;
367− 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)
435+ : undefined;
368436 if (this.#writerStorage) {
369437 const storage = this.#writerStorage;
370438 // A stored Graph cannot be replayed over itself. Check before any
Lines 465–474 at 318 (were 397–404 at 162)
397465 }
398466 this.#hasBlob = options.hasBlob ?? (() => false);
399467 this.#now = options.now;
468+ this.#newsWritten = options.newsWritten;
400469 this.#whole = options.whole;
401470 this.#shapes = options.shapes;
471+ this.#logLine = options.logLine;
402472 // For tests (#46): AVCS_TEXT_FROM_LOG=1 runs a project on a MemoryStore with its text read back from the store.
403473 const testing =
404474 (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.AVCS_TEXT_FROM_LOG ===
Lines 874–885 at 318 (were 804–809 at 162)
804874 return p && { agent: p.agent, message: p.message, time: p.time };
805875 }
806876
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 ?? [];
881+ }
807883 /** The graph, for reading (blame, history). Don't add to it. */
808884 get graph(): Graph {
809885 return this.#graph;
Lines 1348–1396 at 318 (were 1272–1277 at 162)
12721348 return hostedAnnouncePerson(this.#announceHost, ...args);
12731349 }
12741350
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;
1354+ this.#owed = [];
1355+ return owed;
1356+ }
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);
1361+ }
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);
1366+ }
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);
1371+ }
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);
1376+ }
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);
1384+ }
1385+ this.#flush(entries);
1386+ return entries.length;
1387+ }
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);
1392+ }
12751394 /**
12761395 * Say what the agent is starting on (#37, #13), before any edit lands:
12771396 * `text`, and the files it expects to change if it knows them. Nothing is
Lines 1492–1508 at 318 (were 1373–1378 at 162)
13731492 return hostedOverlapNews(this.#overlapHost, ...args);
13741493 }
13751494
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 })) : [];
1499+ }
1501+ /** Whether the project has this agent. Read only. */
1502+ hasAgent(agentName: string): boolean {
1503+ return typeof agentName === "string" && this.#agents.get(agentName) !== undefined;
1504+ }
13761506 /** Hand over the news waiting for an agent (collisions, definitions, moves, announcements), once. */
13771507 news(agentName: string): { news: string[]; items: { text: string; at: number | null }[] } {
13781508 const entries: Entry[] = [];
Lines 1713–1739 at 318 (were 1583–1588 at 162)
15831713 const versionsBefore = this.#spaces.get(SHARED)?.versions.length ?? 0;
15841714 try {
15851715 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
1717+ // its membership.
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 = {
1725+ storage,
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),
1731+ };
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);
1735+ }
1736+ }
15861737 } finally {
15871738 // Positions by version: where each version of shared was made.
15881739 const versionsAfter = this.#spaces.get(SHARED)?.versions.length ?? 0;
Lines 1782–1799 at 318 (were 1631–1637 at 162)
16311782 if (this.#pending.length === 0) return;
16321783 const out = this.#pending;
16331784 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 });
1791+ });
1792+ if (items.length > 0) this.#newsWritten(items);
1793+ }
16341794 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);
16351797 this.#pending = [];
16361798 this.#stored += out.length;
16371799 this.#writeCheckpoint();
Lines 1887–1895 at 318 (were 1725–1730 at 162)
17251887 spaceNamed: (name) => this.#spaceNamed(name),
17261888 checkVersion: (space, version) => this.#checkVersion(space, version),
17271889 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),
17281893 agentView: (agent) => this.#agentView(agent as AgentState),
17291894 spellingIn: (view, asked) => this.spellingIn(view, asked),
17301895 pathsOf: (space) => this.#paths.pathsOf(space),
Lines 1900–1956 at 318 (were 1735–1740 at 162)
17351900 return this.#host;
17361901 }
17371902
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;
1906+ }
1908+ /**
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.
1912+ */
1913+ #authorTotals(
1914+ space: Space,
1915+ version: number,
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));
1924+ }
1926+ /**
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.
1929+ */
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));
1935+ }
1937+ /**
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.
1940+ */
1941+ authorTotalsFor(where: {
1942+ version?: number;
1943+ draft?: string;
1944+ agent?: string;
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;
1950+ }
1951+ return this.#authorTotals(this.#shared, where.version ?? last(this.#shared));
1952+ }
17381954 /** One folder at a version (history.ts). */
17391955 tree(...args: Tail<Parameters<typeof historyTree>>): ReturnType<typeof historyTree> {
17401956 return historyTree(this.#history, ...args);
Lines 2009–2044 at 318 (were 1793–1803 at 162)
17932009 return versionFileAt(this.#logHost, ...args);
17942010 }
17952011
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);
2015+ }
17962017 /** Every file that differs between two versions of shared (or a named draft) (version-log.ts). */
17972018 compare(...args: Tail<Parameters<typeof versionCompare>>): ReturnType<typeof versionCompare> {
17982019 return versionCompare(this.#logHost, ...args);
17992020 }
18002021
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);
2025+ }
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),
2038+ };
2039+ return hostedWithout(host, version, versions);
2040+ }
18012042 /** A version of shared (or of a named draft) as a ReadView (version-log.ts). */
18022043 viewAt(...args: Tail<Parameters<typeof versionViewAt>>): ReturnType<typeof versionViewAt> {
18032044 return versionViewAt(this.#logHost, ...args);
Lines 2057–2099 at 318 (were 1816–1828 at 162)
18162057 definitionRule: () => this.#definitionRule,
18172058 draft: (agent) => this.#draft(agent as AgentState),
18182059 agentView: (agent) => this.#agentView(agent as AgentState),
1819− view: (set) => this.#view(set),
1820− pairs: (draft, against, settled) => this.#pairs(draft, against, settled),
2060+ draftsView: (agents) => this.#draftsView(agents as readonly AgentState[]),
18212061 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(",")}`;
2067+ },
18222068 };
18232069 return this.#draftCollisionHost;
18242070 }
18252071
2072+ /**
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.
2076+ */
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),
2087+ );
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)),
2092+ );
2093+ }
2094+ return view;
2095+ }
18262097 /** Whether agents' unpublished changes would collide, by the publish rule (draft-collisions.ts). */
18272098 collisions(...args: Tail<Parameters<typeof draftCollisions>>): ReturnType<typeof draftCollisions> {
18282099 return draftCollisions(this.#draftCollisions, ...args);
Lines 2108–2117 at 318 (were 1837–1842 at 162)
18372108 needInit: () => this.#needInit(),
18382109 draft: (agent) => this.#draft(agent as AgentState),
18392110 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)) });
2114+ },
18402115 view: (set) => this.#view(set),
18412116 touchedFiles: (ids, views) => this.#touchedFiles(ids, views),
18422117 };
Lines 2184–2201 at 318 (were 1909–1916 at 162)
19092184 viewAt: (space, version) => this.#viewAt(space, version),
19102185 origin: (atom, spaceName) => this.#origin(atom, spaceName),
19112186 collision: (agent, pair) => this.#collision(agent, pair),
1912− definitionCollisions: (agent, newer) => this.#definitionCollisions(agent, newer),
2187+ definitionCollisions: (agent, newer, names) => this.#definitionCollisions(agent, newer, names),
19132188 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),
19142199 };
19152200 return this.#news;
19162201 }
Lines 2378–2395 at 318 (were 2093–2098 at 162)
20932378 graph: this.#graph,
20942379 checkerReady: () => this.checkerReady,
20952380 sharedView: () => this.#sharedView(),
2381+ sharedOverlay: (atoms) =>
2382+ this.#viewKeyed(`a @${last(this.#shared)}+${atoms.join(",")}`, () =>
2383+ unionOverlay(this.#setOf(this.#shared), atoms),
2384+ ),
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));
2392+ },
20962393 queued: () => this.#queue,
20972394 queuedId: () => this.#queuedId,
20982395 checkingHas: (id) => this.#checking.has(id),
Lines 2499–2507 at 318 (were 2202–2207 at 162)
22022499 pairs: (draft, against, settled) => this.#pairs(draft, against, settled),
22032500 describe: (pair, yoursView, theirsView, spaceName) => this.#describe(pair, yoursView, theirsView, spaceName),
22042501 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,
22052505 refuse: (agent, space, via, time, collisions, entries) =>
22062506 this.#refuse(agent, space, via, time, collisions, entries),
22072507 requireClosed: (tie, union) => this.#requireClosed(tie, union),
Lines 2548–2555 at 318 (were 2248–2253 at 162)
22482548 view: (set) => this.#view(set),
22492549 agentSet: (agent) => this.#agentSet(agent),
22502550 agentView: (agent) => this.#agentView(agent),
2551+ agentViewWithout: (agent, excluded) =>
2552+ this.#agentView({ ...agent, mine: agent.mine.filter((id) => !excluded.has(id)) }),
22512553 recordFile: (agent, view, path, text, time, meta, entries, mode, blob, hunks) =>
22522554 this.#recordFile(agent, view, path, text, time, meta, entries, mode, blob, hunks),
22532555 flush: (entries) => this.#flush(entries),
Lines 2580–2591 at 318 (were 2278–2283 at 162)
22782580 agent: (name, entries) => this.#agent(name, entries),
22792581 spaceOf: (agent) => this.#spaceOf(agent),
22802582 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);
2588+ },
22812589 at: (space, version) => this.#at(space, version),
22822590 draft: (agent) => this.#draft(agent),
22832591 strandedFiles: (draft, set) => this.#strandedFiles(draft, set),
Lines 2871–2877 at 318 (were 2563–2568 at 162)
25632871 spaceNamed: (name) => this.#spaceNamed(name),
25642872 checkVersion: (space, version) => this.#checkVersion(space, version),
25652873 viewAt: (space, version) => this.#viewAt(space, version),
2874+ keptPaths: (space, version) => this.#keptPaths(space, version),
25662875 agentView: (agent) => this.#agentView(agent),
25672876 version: () => this.version,
25682877 projectFile: () => (this.initialized ? projectFileIn(this.#sharedView()) : undefined),
Lines 2947–2973 at 318 (were 2638–2649 at 162)
26382947 }
26392948
26402949 #agentView(agent: AgentState): ReadView {
2641− return this.#viewKeyed(this.#agentViewKey(agent), () => {
2950+ const view = this.#viewKeyed(this.#agentViewKey(agent), () => {
26422951 const base = this.#at(this.#spaceOf(agent), agent.base);
26432952 return base instanceof StableSet
26442953 ? new StableUnionSet(base, new StableOverlaySet(agent.mine))
26452954 : new Set([...base, ...agent.mine]);
26462955 });
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)),
2967+ );
2968+ }
2969+ }
2970+ return view;
26472971 }
26482972
26492973 /** 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 2980–3007 at 318 (were 2656–2668 at 162)
26562980
26572981 /** A space at a version: published versions never change, so the key is just their names (#46). */
26582982 #viewAt(space: Space, version: number): ReadView {
2659− return this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version));
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));
2987+ return view;
26602988 }
26612989
26622990 #sharedView(): ReadView {
26632991 return this.#viewAt(this.#shared, last(this.#shared));
26642992 }
26652993
2994+ /**
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).
2999+ */
3000+ afterRead(): void {
3001+ this.#views.trim();
3002+ if (this.#agents instanceof WriterAgents) this.#agents.release();
3003+ }
26663005 /** A view of a set, cached by the set's exact contents (views.ts). */
26673006 #view(set: ReadonlySet<AtomId>): ReadView {
26683007 this.#views.assertUnkeyedAllowed();
Lines 3018–3037 at 318 (were 2679–2687 at 162)
26793018 * (abso issue 80). A closed set is unchanged.
26803019 */
26813020 #closed(set: Iterable<AtomId>): ReadonlySet<AtomId> {
3021+ if (isClosedSet(set)) return set as ReadonlySet<AtomId>;
26823022 if (set instanceof StableSet) {
26833023 // Keep indexed membership external. Only dependencies absent from
2684− // 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) {
3030+ open(part.left);
3031+ open(part.right);
3032+ } else walk.push(part);
3033+ };
3034+ open(set);
26853035 const missing = new Set<AtomId>();
26863036 const visit = (id: AtomId) => {
26873037 const stack = [id];
Lines 3044–3051 at 318 (were 2694–2701 at 162)
26943044 }
26953045 }
26963046 };
2697− for (const id of set) visit(id);
2698− 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);
26993049 }
27003050 return this.#graph.closureOf(set);
27013051 }
Lines 3061–3074 at 318 (were 2711–2723 at 162)
27113061 }
27123062
27133063 /** The space's atoms published after the agent's base, by others. */
2714− #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> {
27153066 const space = this.#spaceOf(agent);
27163067 const base = this.#at(space, agent.base);
2717− const current = this.#setOf(space);
3068+ const current = upTo === undefined ? this.#setOf(space) : this.#at(space, upTo);
27183069 const newer =
27193070 space.name === SHARED && space.membershipVersion
2720− ? new SharedAdditions(space, agent.base, base, current)
3071+ ? new SharedAdditions(space, agent.base, base, current, upTo ?? last(space))
27213072 : differenceSet(current, base);
27223073 return differenceSet(newer, new StableOverlaySet(agent.mine));
27233074 }
Lines 3204–3216 at 318 (were 2853–2859 at 162)
28533204 // The changed-definition rule (#11) -------------------------------------------
28543205
28553206 /** The rule for an agent's draft in its space. */
2856− #definitionCollisions(agent: AgentState, newer: ReadonlySet<AtomId>): DefinitionCollision[] {
3207+ #definitionCollisions(
3208+ agent: AgentState,
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). */
3212+ version?: number,
3213+ ): DefinitionCollision[] {
28573214 const draft = new Set(this.#draft(agent));
28583215 if (draft.size === 0 || newer.size === 0) return [];
28593216 const space = this.#spaceOf(agent);
Lines 3218–3236 at 318 (were 2861–2873 at 162)
28613218 const base = agent.mine.some((id) => at.has(id))
28623219 ? this.#view(differenceSet(at, new StableOverlaySet(agent.mine)))
28633220 : this.#viewAt(space, agent.base);
3221+ const to = version ?? last(space);
28643222 return this.#definitionRule.collisions(
28653223 draft,
28663224 this.#agentView(agent),
28673225 base,
2868− this.#viewAt(space, last(space)),
3226+ this.#viewAt(space, to),
28693227 newer,
28703228 space.name,
3229+ undefined,
3230+ names,
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),
28713234 );
28723235 }
28733236}
MCP
compare on this site's /mcp
CLI
abso diff 162 318 worker/project/project.ts --json
JSON
/christopher/abso-core/compare/162..318?file=worker%2Fproject%2Fproject.ts&format=json