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
MCP
blame on this site's /mcp
CLI
abso blame worker/project/version-log.ts --version 261 --json
JSON
/christopher/abso-core/blame/worker/project/version-log.ts?version=261&format=json
318 linesFirst import 81% · capacity 13% · codex-capacity-chair 6%Last change capacity in version 254,

318 lines from 7 changes in 7 versions.

codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare1import { View } from "../../src/engine/index.ts";
init0Start the project2// The version list reads: log (versions newest first, or one file's history), ribbon (who published each version),
3// show (one version's changes), fileAt, compare and viewAt. They read through LogHost; today the host is the project
4// in memory.
5
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare6import type { AtomId, Graph, ReadView } from "../../src/engine/index.ts";
init0Start the project7import { checkReadPath } from "./path-rules.ts";
8import type { PathIndex } from "./pathindex.ts";
9import { ProjectError } from "./project-error.ts";
10import type { FileChange, LogAnswer, LogEntry, ShowAnswer } from "./project-types.ts";
11import { last, SHARED, type Space } from "./spaces.ts";
capacity243compare's summary: each changed file's size and SHA-256 instead of its texts (abso issue 680; disk-first 2; abso Capacity). compare 612 to 1224 on abso answers 13.2 MB: the full before and after text of about 3,000 changed files. Read Speed's shape lets the site ask for a summary and fetch a file's texts when it opens it. - view-changes.ts summariesBetween: the files changesBetween would list, each side as {size, sha256} for text (UTF-8 bytes, SHA-256 of the text), {blob} for a binary file (its hash; the Worker adds its size from the blob store), or null when absent; mode and blob as in the full answer. Each text is read, summed up and let go. - version-log compare takes summary and answers {from, to, summary: true, files}. ProjectHistory.compare and both engine-project.ts implementations take a fifth argument, summary; http.ts passes ?summary=1. The full answer is unchanged. On abso adopted fresh: the summary for 612 to 1224 is 174 KB instead of 13.2 MB, with heap after at 38 MB. The time is the same (about 20 s cold): it still lays the files out to hash them. Stored per-version sizes and hashes would remove that; they're proposed with the author totals table. New test compare-summary: on an in-memory and a writer-backed project, the summary lists the files the full compare does, with sizes and SHA-256s of its texts, blob hashes for a binary file, and no text. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.Compare12import { changesBetween, summariesBetween } from "./view-changes.ts";
init0Start the project13
14/** What the version list reads need from a project. */
15export interface LogHost {
16 readonly graph: Graph;
17 readonly paths: Pick<PathIndex, "knowsFiles" | "versionFiles" | "versionShape">;
18 readonly labels: ReadonlyMap<string, readonly number[]>;
19 shared(): Space;
20 needInit(): void;
21 spaceFor(options: { draft?: string | null; agent?: string }): Space;
22 checkVersion(space: Space, version: number): void;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare23 viewAt(space: Space, version: number): ReadView;
24 view(set: ReadonlySet<AtomId>): ReadView;
init0Start the project25 at(space: Space, version: number): ReadonlySet<AtomId>;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare26 spellingIn(view: ReadView, path: string): string;
init0Start the project27 versionChange(space: Space, version: number): number | undefined;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare28 touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;
init0Start the project29}
31/**
32 * The versions of shared (or of a named draft), newest first: who
33 * published each, why, and which files it touched. `limit` defaults to 50.
34 */
35export function log(
36 host: LogHost,
37 options: {
38 draft?: string | null;
39 agent?: string;
40 limit?: number;
41 path?: string;
42 before?: number;
43 follow?: boolean;
44 } = {},
45): LogAnswer {
46 host.needInit();
47 const space = host.spaceFor(options);
48 const limit = Number.isInteger(options.limit) && options.limit! > 0 ? Math.min(options.limit!, 200) : 50;
49 if (options.path !== undefined) checkReadPath(options.path);
50 if (options.before !== undefined && (!Number.isInteger(options.before) || options.before < 0))
51 throw new ProjectError("bad-request", "before must be a version number");
52 const versions: LogEntry[] = [];
53 // Paging (#41, the website): `before` starts the page below that version; `next` is the `before` for the page after.
54 let v = Math.min(last(space), (options.before ?? last(space) + 1) - 1);
55 // Any spelling reads the stored one (#41, F7). With follow, the history follows moves (F27): before
56 // the version that moved the file in, it's the file it came from.
57 const path = options.path === undefined ? undefined : host.spellingIn(host.viewAt(space, last(space)), options.path);
58 const names = path === undefined ? [] : options.follow ? namesBefore(host, space, path) : [{ path, since: 0 }];
59 const nameAt = (version: number): string => names.find((n) => version >= n.since)?.path ?? path!;
60 // A file's history (#43): only versions whose changes name the file, or a file moves can carry lines from, can have changed it.
61 const sources = path === undefined ? undefined : new Set(names.flatMap((n) => [...moveSources(host.graph, n.path)]));
62 const g = host.graph;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare63 const views = new Map<number, ReadView>();
init0Start the project64 for (; v >= 0 && versions.length < limit; v--) {
65 if (sources && !host.paths.knowsFiles(space, v)) {
66 const p = space.versions[v]!;
67 if (![...p.atoms, ...(p.dropped ?? [])].some((id) => g.filesOf(id).some((f) => sources.has(f)))) continue;
68 }
capacity254A file's history checks each version's files before building its entry (abso Capacity, issue 664). log with a path built the full entry of every version it walked (every atom of the version read, to count its changes) and only then checked whether the version changed the file: down to the file's twentieth change that was 367 versions on abso. It now checks the version's files first (the same versionFiles the entry uses, kept by the path index) and builds entries only for the versions it lists. Same answers. On a fresh abso adoption (my machine): log for issues/src/index.ts, 20 entries, 108 ms first and 17 ms again (was about 0.45 s again). A full run matches 33 of 33 answers. All of worker/project/test pass (349).Compare69 // With a path: only the versions that changed that file (its history), under its name then. Their files first, and
70 // the whole entry (every atom of the version read) only for those (abso Capacity): a file's history read every
71 // version's atoms down to its twentieth change.
72 if (path !== undefined && !host.paths.versionFiles(space, v, views).includes(nameAt(v))) {
73 views.delete(v + 1);
74 continue;
75 }
init0Start the project76 const entry = logEntry(host, space, v, views);
77 // The walk goes down: a view above this version won't be needed again (#46).
78 views.delete(v + 1);
79 if (path === undefined) versions.push(entry);
capacity254A file's history checks each version's files before building its entry (abso Capacity, issue 664). log with a path built the full entry of every version it walked (every atom of the version read, to count its changes) and only then checked whether the version changed the file: down to the file's twentieth change that was 367 versions on abso. It now checks the version's files first (the same versionFiles the entry uses, kept by the path index) and builds entries only for the versions it lists. Same answers. On a fresh abso adoption (my machine): log for issues/src/index.ts, 20 entries, 108 ms first and 17 ms again (was about 0.45 s again). A full run matches 33 of 33 answers. All of worker/project/test pass (349).Compare80 else versions.push(nameAt(v) === path ? entry : { ...entry, path: nameAt(v) });
init0Start the project81 }
82 const next = v >= 0 && versions.length > 0 ? versions[versions.length - 1]!.version : undefined;
83 const movedFrom = names.slice(0, -1).map((n, i) => ({ path: names[i + 1]!.path, version: n.since }));
84 return {
85 draft: space.name === SHARED ? null : space.name,
86 version: last(space),
87 versions,
88 ...(next !== undefined ? { next } : {}),
89 ...(path !== undefined ? { path } : {}),
90 ...(movedFrom.length > 0 ? { movedFrom } : {}),
91 };
94/**
95 * A file's names back through moves (#41, F27), newest first: each with the
96 * version from which it had that name. Found from the atoms that moved lines
97 * into it (abso mv), so it never guesses from how alike two files are.
98 */
99function namesBefore(host: LogHost, space: Space, path: string): { path: string; since: number }[] {
100 const g = host.graph;
101 const out: { path: string; since: number }[] = [];
102 let cur = path;
103 let below = last(space) + 1;
104 const movers = g.movers();
105 for (;;) {
106 // The newest version below `below` that moved another file into `cur`.
107 const into = movers
108 .filter((id) => g.filesOf(id).includes(cur))
109 .map((id) => space.publishedIn.get(id))
110 .filter((v): v is number => v !== undefined && v < below)
111 .toSorted((a, b) => b - a);
112 let found: { from: string; version: number } | undefined;
113 for (const version of into) {
114 const move = host.paths.versionShape(space, version).moves.find(([, to]) => to === cur);
115 if (move) {
116 found = { from: move[0], version };
117 break;
118 }
119 }
120 out.push({ path: cur, since: found?.version ?? 0 });
121 if (!found) break;
122 cur = found.from;
123 below = found.version;
124 }
125 return out;
128/**
129 * The files whose lines can be in `path` (#43): itself, and any file a move
130 * shares with one already found. A line is in a file other than the one it
131 * was written in only when a move carried it, or a line before it, there;
132 * that move names both files.
133 */
134function moveSources(g: Graph, path: string): Set<string> {
135 const out = new Set([path]);
136 const movers = g.movers().map((id) => g.filesOf(id));
137 for (let grew = true; grew; ) {
138 grew = false;
139 for (const files of movers) {
140 if (!files.some((f) => out.has(f))) continue;
141 for (const f of files) if (!out.has(f)) out.add(f), (grew = true);
142 }
143 }
144 return out;
147/**
148 * Shared's versions in one small answer, for the website's version ribbon
149 * (#43): `authors[v]` indexes `agents`, which are in order of each agent's
150 * first version. No files, so it costs nothing on a long history.
151 */
152export function ribbon(host: LogHost): { version: number; agents: string[]; authors: number[] } {
153 host.needInit();
154 const shared = host.shared();
155 const agents: string[] = [];
156 const index = new Map<string, number>();
157 const authors = shared.versions.map((p) => {
158 let i = index.get(p.agent);
159 if (i === undefined) index.set(p.agent, (i = agents.push(p.agent) - 1));
160 return i;
161 });
162 return { version: last(shared), agents, authors };
165/** One version of shared (or of a named draft): who, why, and each file it changed, before and after. */
166export function show(
167 host: LogHost,
168 version: number,
169 options: { draft?: string | null; agent?: string } = {},
170): ShowAnswer {
171 host.needInit();
172 const space = host.spaceFor(options);
173 if (!Number.isInteger(version) || version < 0 || version > last(space)) {
174 throw new ProjectError(
175 "bad-request",
176 `there is no version ${String(version)}${space.name === SHARED ? "" : ` of draft ${space.name}`}`,
177 );
178 }
179 const entry = logEntry(host, space, version);
180 const before = version === 0 ? new View(host.graph, []) : host.viewAt(space, version - 1);
181 const after = host.viewAt(space, version);
182 return {
183 ...entry,
184 draft: space.name === SHARED ? null : space.name,
185 diff: changesBetween(before, after, entry.files),
186 };
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare189function logEntry(host: LogHost, space: Space, version: number, views?: Map<number, ReadView>): LogEntry {
init0Start the project190 const p = space.versions[version]!;
191 let changes = 0;
192 for (const id of p.atoms) {
193 const atom = host.graph.atom(id);
194 const ownLines = atom.inserts.length > 0 || host.graph.deleteCount(id) > 0;
195 if (ownLines) changes++;
196 }
197 const files = host.paths.versionFiles(space, version, views);
198 const change = host.versionChange(space, version);
199 const droppedIn = p.atoms.length > 0 ? space.droppedIn.get(p.atoms[p.atoms.length - 1]!) : undefined;
200 return {
201 version,
202 agent: p.agent,
203 message: p.message,
204 time: p.time,
205 changes,
206 ...(change !== undefined ? { change } : {}),
207 files: [...files],
208 ...(p.droppedVersions ? { drops: [...p.droppedVersions] } : {}),
209 ...(droppedIn !== undefined ? { droppedIn } : {}),
210 ...labelsOn(host, space, version),
211 ...(p.originalMessage !== undefined ? { originalMessage: p.originalMessage } : {}),
212 };
215function labelsOn(host: LogHost, space: Space, version: number): { labels?: string[] } {
216 if (space.name !== SHARED) return {};
217 const names = [...host.labels]
218 .filter(([, vs]) => vs.includes(version))
219 .map(([n]) => n)
220 .toSorted();
221 return names.length > 0 ? { labels: names } : {};
224/** A file as it was at a version of shared (or a named draft): its text, or null when it didn't exist. */
225export function fileAt(
226 host: LogHost,
227 path: string,
228 version: number,
229 options: { draft?: string | null; agent?: string } = {},
230): { path: string; version: number; text: string | null; blob?: string } {
231 host.needInit();
232 checkReadPath(path);
233 const space = host.spaceFor(options);
234 host.checkVersion(space, version);
235 const view = host.viewAt(space, version);
236 // Any spelling reads the stored one (#41, F7).
237 const file = host.spellingIn(view, path);
238 const blob = view.attrs(file).blob;
239 return {
240 path: file,
241 version,
242 text: view.hasFile(file) ? view.text(file) : null,
243 ...(blob !== null ? { blob } : {}),
244 };
capacity244compare keeps its own answer type; the summary is compareSummary (abso issue 680; abso Capacity). 243 gave compare one answer type for both shapes, full and summary. abso's own callers read compare(...).files as file changes (worker/src/engine-project.ts, scripts/versions-check.ts, test/versions.test.ts), and the union broke their types, which showed when I pinned 243 into abso. Core's own tests didn't catch it. - version-log.ts: compared() works out the files and both views; compare answers {from, to, files: FileChange[]} as before 243, and compareSummary answers {from, to, summary: true, files}. Project.compareSummary calls it. - server/src/engine-project.ts: compare(..., summary) calls compareSummary when summary is set. http.ts and ProjectHistory are unchanged from 243 (?summary=1, a fifth argument). - compare-summary.test.ts calls compareSummary. Answers are the same as 243's. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.Compare247/** The files that may differ between two versions, and both views: compare's and compareSummary's ground. */
248function compared(
init0Start the project249 host: LogHost,
250 from: number,
251 to: number,
capacity244compare keeps its own answer type; the summary is compareSummary (abso issue 680; abso Capacity). 243 gave compare one answer type for both shapes, full and summary. abso's own callers read compare(...).files as file changes (worker/src/engine-project.ts, scripts/versions-check.ts, test/versions.test.ts), and the union broke their types, which showed when I pinned 243 into abso. Core's own tests didn't catch it. - version-log.ts: compared() works out the files and both views; compare answers {from, to, files: FileChange[]} as before 243, and compareSummary answers {from, to, summary: true, files}. Project.compareSummary calls it. - server/src/engine-project.ts: compare(..., summary) calls compareSummary when summary is set. http.ts and ProjectHistory are unchanged from 243 (?summary=1, a fifth argument). - compare-summary.test.ts calls compareSummary. Answers are the same as 243's. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.Compare252 options: { draft?: string | null; agent?: string },
253): { before: ReadView; after: ReadView; files: Set<string> } {
init0Start the project254 host.needInit();
255 const space = host.spaceFor(options);
256 host.checkVersion(space, from);
257 host.checkVersion(space, to);
codex-capacity-chair163Integrate reviewed disk-backed operations, queue and bounded read cachesCompare258 const before = host.viewAt(space, from);
259 const after = host.viewAt(space, to);
init0Start the project260 const files = new Set<string>();
capacity208Compare on a stored writer takes its candidates from the kept version files of the versions between (abso Capacity): every file that differs between two shared versions changed in one between them. Before, it walked every atom either version's set holds. version-files.test.ts compares both ways, across a drop, against the in-memory project. On game's export, compare from 762 to 1525: 20 s to 5.4 s, same answer.Compare261 // A stored writer keeps each shared version's changed files (version-files.ts, abso Capacity): every file that
262 // differs between two versions changed in one between them, so those lists are the candidates, not every atom
263 // either set holds.
264 if (space.name === SHARED && host.graph.packedFiles) {
265 for (let v = Math.min(from, to) + 1; v <= Math.max(from, to); v++)
266 for (const file of host.paths.versionFiles(space, v)) files.add(file);
capacity244compare keeps its own answer type; the summary is compareSummary (abso issue 680; abso Capacity). 243 gave compare one answer type for both shapes, full and summary. abso's own callers read compare(...).files as file changes (worker/src/engine-project.ts, scripts/versions-check.ts, test/versions.test.ts), and the union broke their types, which showed when I pinned 243 into abso. Core's own tests didn't catch it. - version-log.ts: compared() works out the files and both views; compare answers {from, to, files: FileChange[]} as before 243, and compareSummary answers {from, to, summary: true, files}. Project.compareSummary calls it. - server/src/engine-project.ts: compare(..., summary) calls compareSummary when summary is set. http.ts and ProjectHistory are unchanged from 243 (?summary=1, a fifth argument). - compare-summary.test.ts calls compareSummary. Answers are the same as 243's. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.Compare267 return { before, after, files };
capacity208Compare on a stored writer takes its candidates from the kept version files of the versions between (abso Capacity): every file that differs between two shared versions changed in one between them. Before, it walked every atom either version's set holds. version-files.test.ts compares both ways, across a drop, against the in-memory project. On game's export, compare from 762 to 1525: 20 s to 5.4 s, same answer.Compare268 }
init0Start the project269 const a = host.at(space, from);
270 const b = host.at(space, to);
271 for (const [x, y] of [
272 [a, b],
273 [b, a],
274 ] as const) {
275 for (const file of host.touchedFiles(
codex-capacity-chair163Integrate reviewed disk-backed operations, queue and bounded read cachesCompare276 (function* () {
277 for (const id of x) if (!y.has(id)) yield id;
278 })(),
279 [before, after],
init0Start the project280 ))
281 files.add(file);
282 }
capacity244compare keeps its own answer type; the summary is compareSummary (abso issue 680; abso Capacity). 243 gave compare one answer type for both shapes, full and summary. abso's own callers read compare(...).files as file changes (worker/src/engine-project.ts, scripts/versions-check.ts, test/versions.test.ts), and the union broke their types, which showed when I pinned 243 into abso. Core's own tests didn't catch it. - version-log.ts: compared() works out the files and both views; compare answers {from, to, files: FileChange[]} as before 243, and compareSummary answers {from, to, summary: true, files}. Project.compareSummary calls it. - server/src/engine-project.ts: compare(..., summary) calls compareSummary when summary is set. http.ts and ProjectHistory are unchanged from 243 (?summary=1, a fifth argument). - compare-summary.test.ts calls compareSummary. Answers are the same as 243's. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.Compare283 return { before, after, files };
init0Start the project286/** Every file that differs between two versions of shared (or a named draft), before (at `from`) and after (at `to`). */
287export function compare(
capacity244compare keeps its own answer type; the summary is compareSummary (abso issue 680; abso Capacity). 243 gave compare one answer type for both shapes, full and summary. abso's own callers read compare(...).files as file changes (worker/src/engine-project.ts, scripts/versions-check.ts, test/versions.test.ts), and the union broke their types, which showed when I pinned 243 into abso. Core's own tests didn't catch it. - version-log.ts: compared() works out the files and both views; compare answers {from, to, files: FileChange[]} as before 243, and compareSummary answers {from, to, summary: true, files}. Project.compareSummary calls it. - server/src/engine-project.ts: compare(..., summary) calls compareSummary when summary is set. http.ts and ProjectHistory are unchanged from 243 (?summary=1, a fifth argument). - compare-summary.test.ts calls compareSummary. Answers are the same as 243's. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.Compare288 host: LogHost,
289 from: number,
290 to: number,
291 options: { draft?: string | null; agent?: string } = {},
292): { from: number; to: number; files: FileChange[] } {
293 const { before, after, files } = compared(host, from, to, options);
294 return { from, to, files: changesBetween(before, after, files) };
297/** compare's files as each one's size and SHA-256 before and after, not its texts (abso issue 680). */
298export function compareSummary(
299 host: LogHost,
300 from: number,
301 to: number,
302 options: { draft?: string | null; agent?: string } = {},
303): { from: number; to: number; summary: true; files: ReturnType<typeof summariesBetween> } {
304 const { before, after, files } = compared(host, from, to, options);
305 return { from, to, summary: true, files: summariesBetween(before, after, files) };
init0Start the project306}
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare308/** A version of shared (or of a named draft) as a ReadView, for reading lines (blame at a version). */
309export function viewAt(
310 host: LogHost,
311 version: number,
312 options: { draft?: string | null; agent?: string } = {},
313): ReadView {
init0Start the project314 host.needInit();
315 const space = host.spaceFor(options);
316 host.checkVersion(space, version);
317 return host.viewAt(space, version);