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 248 to 318

Compare

+204 −11 in 24 places
Lines 36–47 at 318 (were 36–42 at 248)
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";
39+import {
40+ type AnnounceHost,
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";
4146import {
4247 type ChangeHost,
Lines 81–87 at 318 (were 76–81 at 248)
7681} from "./history.ts";
7782import { ingest as hostedIngest, type IngestHost } from "./ingest.ts";
7883import { init as hostedInit, type InitHost } from "./init.ts";
84+import { KeptParts } from "./kept-parts.ts";
7985import { label as hostedLabel, type LabelHost } from "./label.ts";
8086import {
8187 land as hostedLand,
Lines 105–117 at 318 (were 99–107 at 248)
99105 addressedItem,
100106 newsAboutOwnDraft as hostedNewsAboutOwnDraft,
101107 newsForOthers as hostedNewsForOthers,
108+ newsOwed as hostedNewsOwed,
109+ owedAgents as hostedOwedAgents,
110+ owedNewsNames as hostedOwedNewsNames,
102111 markedItem,
103112 type NewsHost,
104113 type NewsItem,
114+ type OwedDefinitionNews,
105115 reviewItem,
106116 settledItem,
107117} from "./news.ts";
Lines 161–167 at 318 (were 151–156 at 248)
151161 LandAnswer,
152162 MergedLine,
153163 Modes,
164+ NewsWritten,
154165 NoteAnswer,
155166 NoteBody,
156167 NoteRecord,
Lines 210–228 at 318 (were 199–210 at 248)
199210import { switchTo as hostedSwitchTo, type SwitchHost } from "./switch-to.ts";
200211import { sync as hostedSync, type SyncHost } from "./sync.ts";
201212import { treeHash } from "./tree.ts";
202−import { versionFiles as keptVersionFiles, type VersionFilesHost } from "./version-files.ts";
203213import {
214+ authoredVersion,
215+ authorTotalsAt,
216+ type FileTotals,
217+ versionFiles as keptVersionFiles,
218+ type VersionFilesHost,
219+} from "./version-files.ts";
220+import {
204221 type LogHost,
205222 compare as versionCompare,
206223 compareSummary as versionCompareSummary,
207224 fileAt as versionFileAt,
225+ fileExactAt as versionFileExactAt,
208226 log as versionLog,
209227 ribbon as versionRibbon,
210228 show as versionShow,
Lines 264–273 at 318 (were 246–251 at 248)
246264 */
247265const WRITER_CACHE_BYTES = 4 * 1_048_576;
248266const 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;
249271export interface WriterSource {
250272 readonly generation: number;
251273 readonly logLength: number;
Lines 292–310 at 318 (were 270–281 at 248)
270292 return "json" in frame ? (JSON.parse(frame.json) as Entry) : frame.entry;
271293}
272294
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+}
273300export class Project {
274301 readonly #store: ProjectStore;
275302 readonly #writerStorage?: GraphStateStorage;
276303 readonly #graph: Graph;
277304 /** Views laid out from atom sets, cached under a byte budget (views.ts). */
278305 readonly #views: ViewCache;
306+ /** What draft collisions keep between calls, under its own byte budget (kept-parts.ts). */
307+ #keptParts: KeptParts | undefined;
279308 /** Each agent's draft files, under the key they were worked out for (#draftFiles). */
280309 readonly #draftFilesKept = new Map<string, { key: string; files: Set<string> }>();
281310 /** Each version's files and each path's history (pathindex.ts). */
Lines 335–351 at 318 (were 306–314 at 248)
306335 * doesn't depend on it.
307336 */
308337 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[] = [];
309344 readonly #now: (() => number) | undefined;
345+ readonly #newsWritten: ((items: readonly NewsWritten[]) => void) | undefined;
310346 readonly #whole: ProjectOptions["whole"];
311347 readonly #shapes: ProjectOptions["shapes"];
348+ readonly #logLine: ProjectOptions["logLine"];
312349 /** For each log position, the newest time up to it (#41): time to position in one search. */
313350 readonly #timeAt: number[] = [];
314351 /** For each version of shared, the log position of the entry that made it (#41). */
Lines 431–437 at 318 (were 394–400 at 248)
394431 throw Error("accepted atom indexing requires writer storage");
395432 this.#store = store;
396433 this.#writerStorage = options.writerStorage
397− ? new CachedStateStorage(options.writerStorage, WRITER_CACHE_BYTES, WRITER_CACHE_ROWS)
434+ ? new CachedStateStorage(options.writerStorage, WRITER_CACHE_BYTES, WRITER_CACHE_ROWS, WRITER_CACHE_ROW_BYTES)
398435 : undefined;
399436 if (this.#writerStorage) {
400437 const storage = this.#writerStorage;
Lines 465–474 at 318 (were 428–435 at 248)
428465 }
429466 this.#hasBlob = options.hasBlob ?? (() => false);
430467 this.#now = options.now;
468+ this.#newsWritten = options.newsWritten;
431469 this.#whole = options.whole;
432470 this.#shapes = options.shapes;
471+ this.#logLine = options.logLine;
433472 // For tests (#46): AVCS_TEXT_FROM_LOG=1 runs a project on a MemoryStore with its text read back from the store.
434473 const testing =
435474 (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.AVCS_TEXT_FROM_LOG ===
Lines 1348–1396 at 318 (were 1309–1314 at 248)
13091348 return hostedAnnouncePerson(this.#announceHost, ...args);
13101349 }
13111350
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+ }
13121394 /**
13131395 * Say what the agent is starting on (#37, #13), before any edit lands:
13141396 * `text`, and the files it expects to change if it knows them. Nothing is
Lines 1492–1508 at 318 (were 1410–1415 at 248)
14101492 return hostedOverlapNews(this.#overlapHost, ...args);
14111493 }
14121494
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+ }
14131506 /** Hand over the news waiting for an agent (collisions, definitions, moves, announcements), once. */
14141507 news(agentName: string): { news: string[]; items: { text: string; at: number | null }[] } {
14151508 const entries: Entry[] = [];
Lines 1782–1799 at 318 (were 1689–1695 at 248)
16891782 if (this.#pending.length === 0) return;
16901783 const out = this.#pending;
16911784 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+ }
16921794 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);
16931797 this.#pending = [];
16941798 this.#stored += out.length;
16951799 this.#writeCheckpoint();
Lines 1888–1895 at 318 (were 1784–1789 at 248)
17841888 checkVersion: (space, version) => this.#checkVersion(space, version),
17851889 viewAt: (space, version) => this.#viewAt(space, version),
17861890 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),
17871893 agentView: (agent) => this.#agentView(agent as AgentState),
17881894 spellingIn: (view, asked) => this.spellingIn(view, asked),
17891895 pathsOf: (space) => this.#paths.pathsOf(space),
Lines 1905–1956 at 318 (were 1799–1804 at 248)
17991905 return this.#writerStorage && space.name === SHARED ? this.#paths.keptPaths(space, version) : undefined;
18001906 }
18011907
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+ }
18021954 /** One folder at a version (history.ts). */
18031955 tree(...args: Tail<Parameters<typeof historyTree>>): ReturnType<typeof historyTree> {
18041956 return historyTree(this.#history, ...args);
Lines 2009–2019 at 318 (were 1857–1862 at 248)
18572009 return versionFileAt(this.#logHost, ...args);
18582010 }
18592011
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+ }
18602017 /** Every file that differs between two versions of shared (or a named draft) (version-log.ts). */
18612018 compare(...args: Tail<Parameters<typeof versionCompare>>): ReturnType<typeof versionCompare> {
18622019 return versionCompare(this.#logHost, ...args);
Lines 2059–2070 at 318 (were 1902–1907 at 248)
19022059 agentView: (agent) => this.#agentView(agent as AgentState),
19032060 draftsView: (agents) => this.#draftsView(agents as readonly AgentState[]),
19042061 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+ },
19052068 };
19062069 return this.#draftCollisionHost;
19072070 }
Lines 2087–2095 at 318 (were 1924–1930 at 248)
19242087 );
19252088 if (this.#writerStorage && mine.length > 0 && view instanceof View && base instanceof View) {
19262089 view.shareMoves(base);
1927− 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)),
2092+ );
19282093 }
19292094 return view;
19302095 }
Lines 2184–2201 at 318 (were 2019–2026 at 248)
20192184 viewAt: (space, version) => this.#viewAt(space, version),
20202185 origin: (atom, spaceName) => this.#origin(atom, spaceName),
20212186 collision: (agent, pair) => this.#collision(agent, pair),
2022− definitionCollisions: (agent, newer) => this.#definitionCollisions(agent, newer),
2187+ definitionCollisions: (agent, newer, names) => this.#definitionCollisions(agent, newer, names),
20232188 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),
20242199 };
20252200 return this.#news;
20262201 }
Lines 2499–2507 at 318 (were 2324–2329 at 248)
23242499 pairs: (draft, against, settled) => this.#pairs(draft, against, settled),
23252500 describe: (pair, yoursView, theirsView, spaceName) => this.#describe(pair, yoursView, theirsView, spaceName),
23262501 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,
23272505 refuse: (agent, space, via, time, collisions, entries) =>
23282506 this.#refuse(agent, space, via, time, collisions, entries),
23292507 requireClosed: (tie, union) => this.#requireClosed(tie, union),
Lines 2962–2970 at 318 (were 2784–2790 at 248)
27842962 // view holds beyond its base is the draft and whatever the draft depends on that the base lacks (the view's
27852963 // set is closed): each of those can change a file, so all of them count.
27862964 const mine = agent.mine;
2787− 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)),
2967+ );
27882968 }
27892969 }
27902970 return view;
Lines 3061–3074 at 318 (were 2881–2893 at 248)
28813061 }
28823062
28833063 /** The space's atoms published after the agent's base, by others. */
2884− #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> {
28853066 const space = this.#spaceOf(agent);
28863067 const base = this.#at(space, agent.base);
2887− const current = this.#setOf(space);
3068+ const current = upTo === undefined ? this.#setOf(space) : this.#at(space, upTo);
28883069 const newer =
28893070 space.name === SHARED && space.membershipVersion
2890− ? new SharedAdditions(space, agent.base, base, current)
3071+ ? new SharedAdditions(space, agent.base, base, current, upTo ?? last(space))
28913072 : differenceSet(current, base);
28923073 return differenceSet(newer, new StableOverlaySet(agent.mine));
28933074 }
Lines 3204–3216 at 318 (were 3023–3029 at 248)
30233204 // The changed-definition rule (#11) -------------------------------------------
30243205
30253206 /** The rule for an agent's draft in its space. */
3026− #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[] {
30273214 const draft = new Set(this.#draft(agent));
30283215 if (draft.size === 0 || newer.size === 0) return [];
30293216 const space = this.#spaceOf(agent);
Lines 3218–3236 at 318 (were 3031–3043 at 248)
30313218 const base = agent.mine.some((id) => at.has(id))
30323219 ? this.#view(differenceSet(at, new StableOverlaySet(agent.mine)))
30333220 : this.#viewAt(space, agent.base);
3221+ const to = version ?? last(space);
30343222 return this.#definitionRule.collisions(
30353223 draft,
30363224 this.#agentView(agent),
30373225 base,
3038− this.#viewAt(space, last(space)),
3226+ this.#viewAt(space, to),
30393227 newer,
30403228 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),
30413234 );
30423235 }
30433236}
MCP
compare on this site's /mcp
CLI
abso diff 248 318 worker/project/project.ts --json
JSON
/christopher/abso-core/compare/248..318?file=worker%2Fproject%2Fproject.ts&format=json