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-files.ts --json
JSON
/christopher/abso-core/blame/worker/project/version-files.ts?format=json
272 linescapacity 100% · First import 1%Last change capacity in version 258,

272 lines from 8 changes in 5 versions.

capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare1// Each version of shared's changed files, worked out as the version lands from what it touched (disk-first 2;
2// abso Capacity). The log, a path's history and the tree read these lists; working them out from two layouts of every
3// touched file per version cost game's whole history 460 s to adopt. Here a version costs about its own size:
4// - a file it touched differs when its visible lines' count or texts changed, or its mode or blob did;
5// - whether a file exists before and after comes from a running count of each file's visible lines;
6// - only a version whose added and removed lines have the very same texts, or one with moves, drops or a change to
7// shared's closure, is laid out as before.
8// The answers are exactly differs() in view-changes.ts.
9
10import { type AtomId, type Graph, type ReadView, View } from "../../src/engine/index.ts";
11import type { GraphStateStorage } from "../../src/engine/state-source.ts";
12import { touchedFiles } from "./collisions.ts";
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare13import { utf8Bytes } from "./project-helpers.ts";
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare14import type { Published } from "./spaces.ts";
15import { differs } from "./view-changes.ts";
17const COUNTS = "head-visible";
18const META = "head-visible:meta";
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare19
20// Author totals (docs/disk-first-2.md, abso Capacity, issue 664): each shared file's lines by author and its text's size
21// in UTF-8 bytes, as tree with authors counts them, so it reads one value per file instead of laying every file out.
22// AUTHORS holds each file's totals at the newest version kept; AUTHORS_LOG each file's totals at every version that
23// changed them, oldest first. Shared only, never a draft (Security on ask 2096). They live in the writer's state, so
24// whatever clears or replaces that state (a new adoption, a restore, a drop of the project) takes them with it.
25const AUTHORS = "head-authors";
26const AUTHORS_LOG = "author-totals";
27const AUTHORS_META = "head-authors:meta";
29/** A file's lines by author and its text's size, stored: authors by name, none at zero; null when it has no lines. */
30type StoredTotals = { a: [string, number][]; b: number };
32/** A shared file's lines by author and its text's size in UTF-8 bytes. */
33export interface FileTotals {
34 readonly authors: ReadonlyMap<string, number>;
35 readonly bytes: number;
38const NO_TOTALS: FileTotals = { authors: new Map(), bytes: 0 };
40/** The newest shared version whose author totals are kept, or undefined when this writer keeps none. */
41export function authoredVersion(storage: GraphStateStorage): number | undefined {
42 return storage.read(AUTHORS_META, "version") as number | undefined;
45/** A shared file's totals at version `v`, or undefined when they aren't kept that far: lay the file out instead. */
46export function authorTotalsAt(storage: GraphStateStorage, path: string, v: number): FileTotals | undefined {
47 const upTo = authoredVersion(storage);
48 if (upTo === undefined || v > upTo) return undefined;
49 const log = storage.read(AUTHORS_LOG, path) as [number, StoredTotals | null][] | undefined;
50 if (!log) return NO_TOTALS;
51 // The newest entry at or before v.
52 let lo = 0;
53 let hi = log.length - 1;
54 let found = -1;
55 while (lo <= hi) {
56 const mid = (lo + hi) >> 1;
57 if (log[mid]![0] <= v) {
58 found = mid;
59 lo = mid + 1;
60 } else hi = mid - 1;
61 }
62 const totals = found < 0 ? null : log[found]![1];
63 return totals ? { authors: new Map(totals.a), bytes: totals.b } : NO_TOTALS;
66/** Each atom's author, read once. */
67function authorsOf(graph: Graph): (id: AtomId) => string {
68 const known = new Map<AtomId, string>();
69 return (id) => {
70 let author = known.get(id);
71 if (author === undefined) known.set(id, (author = graph.atom(id).author));
72 return author;
73 };
76/** Totals in stored form: authors sorted, none at zero; null for a file with no lines. */
77function normalTotals(authors: ReadonlyMap<string, number>, bytes: number): StoredTotals | null {
78 const a = [...authors].filter(([, n]) => n !== 0).sort(([x], [y]) => (x < y ? -1 : x > y ? 1 : 0));
79 return a.length === 0 && bytes === 0 ? null : { a, b: bytes };
capacity258Told lists out of agent rows, in 64 bucket rows per agent; layout pages read through the writer cache; a laid-out file's authors counted by writer (abso Capacity, issue 664; Security yes on ask 2102; Agent VCS approved). - writer-agents.ts: each agent's told keys (the news it has been told) live in 64 rows of their own, project:agents:told, keyed by the agent's name and a fixed hash bucket (FNV-1a mod 64), each holding its bucket's keys sorted; the agent row no longer carries them. told.has reads one bucket and told.add rewrites one; status, where and drafts never read them. A row written before keeps its list, read alongside the buckets (StoredTold.listed) until the agent's row is next written, which moves the list into the buckets; a fresh adoption writes the new form from the start. Removing an agent clears its buckets; delete and purge clear the writer state with them. abso's 109 agent rows were 4.3 MB, the largest 100.9 KB. - CachedStateStorage can read collections straight through; the writer passes file-lines, file-texts and file-deletes pages, which are read only to lay a file out (the view keeps the layout) and pushed out the small rows read on every call. - authorsInView: a laid-out file's lines by author from its visible lines' writers, each writer's author once (tree with authors, folder blame, and the totals adoption keeps), instead of an atom id and line id per line. Tests: told-buckets (new: news on a stored writer against the in-memory project, every step's news asked twice, before and after an agent's told keys are half in an old row's list and half in buckets, with a writer opened afresh; the old list moves into the buckets on the agent's next write; an agent never reads another's buckets; a rollback leaves the buckets as they were). state-cache: a collection read straight through is never kept and pushes nothing out. All of src/engine/test (295) and worker/project/test (351, one skipped) pass.Compare82/**
83 * A laid-out file's lines by author, from its visible lines' writers (abso Capacity): each writer's author once, instead
84 * of making an atom id and a line id for every line (an agent's tree spent 0.4 s on that for its draft's files).
85 */
86export function authorsInView(
87 view: ReadView,
88 path: string,
89 graph: Graph,
90 authorOf: (id: AtomId) => string,
91): Map<string, number> {
92 const out = new Map<string, number>();
93 const writers = (view as { visibleWriters?(path: string): readonly number[] }).visibleWriters?.call(view, path);
94 if (!writers) {
init0Start the project95 for (const l of view.lines(path)) {
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare96 const author = authorOf(l.atom);
capacity258Told lists out of agent rows, in 64 bucket rows per agent; layout pages read through the writer cache; a laid-out file's authors counted by writer (abso Capacity, issue 664; Security yes on ask 2102; Agent VCS approved). - writer-agents.ts: each agent's told keys (the news it has been told) live in 64 rows of their own, project:agents:told, keyed by the agent's name and a fixed hash bucket (FNV-1a mod 64), each holding its bucket's keys sorted; the agent row no longer carries them. told.has reads one bucket and told.add rewrites one; status, where and drafts never read them. A row written before keeps its list, read alongside the buckets (StoredTold.listed) until the agent's row is next written, which moves the list into the buckets; a fresh adoption writes the new form from the start. Removing an agent clears its buckets; delete and purge clear the writer state with them. abso's 109 agent rows were 4.3 MB, the largest 100.9 KB. - CachedStateStorage can read collections straight through; the writer passes file-lines, file-texts and file-deletes pages, which are read only to lay a file out (the view keeps the layout) and pushed out the small rows read on every call. - authorsInView: a laid-out file's lines by author from its visible lines' writers, each writer's author once (tree with authors, folder blame, and the totals adoption keeps), instead of an atom id and line id per line. Tests: told-buckets (new: news on a stored writer against the in-memory project, every step's news asked twice, before and after an agent's told keys are half in an old row's list and half in buckets, with a writer opened afresh; the old list moves into the buckets on the agent's next write; an agent never reads another's buckets; a rollback leaves the buckets as they were). state-cache: a collection read straight through is never kept and pushes nothing out. All of src/engine/test (295) and worker/project/test (351, one skipped) pass.Compare97 out.set(author, (out.get(author) ?? 0) + 1);
98 }
99 return out;
100 }
101 const bySeq = new Map<number, number>();
102 for (const seq of writers) bySeq.set(seq, (bySeq.get(seq) ?? 0) + 1);
103 for (const [seq, n] of bySeq) {
104 const author = authorOf(graph.idOfSeq(seq));
105 out.set(author, (out.get(author) ?? 0) + n);
106 }
107 return out;
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare110/** A file's totals from its layout in a view, as tree with authors counts them. */
111function laidOutTotals(view: ReadView, path: string, authorOf: (id: AtomId) => string): StoredTotals | null {
112 if (!view.hasFile(path)) return null;
capacity258Told lists out of agent rows, in 64 bucket rows per agent; layout pages read through the writer cache; a laid-out file's authors counted by writer (abso Capacity, issue 664; Security yes on ask 2102; Agent VCS approved). - writer-agents.ts: each agent's told keys (the news it has been told) live in 64 rows of their own, project:agents:told, keyed by the agent's name and a fixed hash bucket (FNV-1a mod 64), each holding its bucket's keys sorted; the agent row no longer carries them. told.has reads one bucket and told.add rewrites one; status, where and drafts never read them. A row written before keeps its list, read alongside the buckets (StoredTold.listed) until the agent's row is next written, which moves the list into the buckets; a fresh adoption writes the new form from the start. Removing an agent clears its buckets; delete and purge clear the writer state with them. abso's 109 agent rows were 4.3 MB, the largest 100.9 KB. - CachedStateStorage can read collections straight through; the writer passes file-lines, file-texts and file-deletes pages, which are read only to lay a file out (the view keeps the layout) and pushed out the small rows read on every call. - authorsInView: a laid-out file's lines by author from its visible lines' writers, each writer's author once (tree with authors, folder blame, and the totals adoption keeps), instead of an atom id and line id per line. Tests: told-buckets (new: news on a stored writer against the in-memory project, every step's news asked twice, before and after an agent's told keys are half in an old row's list and half in buckets, with a writer opened afresh; the old list moves into the buckets on the agent's next write; an agent never reads another's buckets; a rollback leaves the buckets as they were). state-cache: a collection read straight through is never kept and pushes nothing out. All of src/engine/test (295) and worker/project/test (351, one skipped) pass.Compare113 const authors = authorsInView(view, path, view.graph, authorOf);
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare114 return normalTotals(authors, authors.size === 0 ? 0 : utf8Bytes(view.text(path)));
117/** Keep a file's totals at version `v`, when they differ from what it had. */
118function keepTotals(storage: GraphStateStorage, v: number, path: string, totals: StoredTotals | null): void {
119 const was = (storage.read(AUTHORS, path) as StoredTotals | undefined) ?? null;
120 if (JSON.stringify(was) === JSON.stringify(totals)) return;
121 if (totals) storage.write(AUTHORS, path, totals);
122 else storage.remove(AUTHORS, path);
123 const log = (storage.read(AUTHORS_LOG, path) as [number, StoredTotals | null][] | undefined) ?? [];
124 storage.write(AUTHORS_LOG, path, [...log, [v, totals]]);
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare126
127/** The shared version the running counts describe, or undefined when this writer keeps none. */
128export function countedVersion(storage: GraphStateStorage): number | undefined {
129 return storage.read(META, "version") as number | undefined;
132export interface VersionFilesHost {
133 readonly storage: GraphStateStorage;
134 readonly graph: Graph;
135 /** Shared's set at a version (closed) and its view. */
136 at(version: number): ReadonlySet<AtomId>;
137 viewAt(version: number): ReadView;
138 empty(): ReadView;
139 /** Whether shared's closure changed at this version (spaces.ts). */
140 closureChangedAt(version: number): boolean;
143/** A file's visible lines in a view: a laid-out count, for the slow path. */
144function visibleCount(view: ReadView, path: string): number {
145 const counted = (view as { visibleCount?(path: string): number }).visibleCount;
146 return counted ? counted.call(view, path) : view.lines(path).length;
149/** The changed files of shared's version `v`, sorted, and which existed before and after; the running counts moved to `v`. */
150export function versionFiles(
151 host: VersionFilesHost,
152 p: Published,
153): { files: string[]; exists?: Map<string, readonly [boolean, boolean]> } {
154 const { storage, graph } = host;
155 const v = p.version;
156 const counted = countedVersion(storage);
157 const atoms = [...p.atoms, ...(p.dropped ?? [])];
158 const before = v === 0 ? host.empty() : host.viewAt(v - 1);
159 const after = host.viewAt(v);
160 const fast =
161 v > 0 &&
162 counted === v - 1 &&
163 !p.dropped?.length &&
164 !p.atoms.some((id) => graph.atom(id).moves?.length) &&
165 !host.closureChangedAt(v);
166 // The same moves as the version before: share them, and where lines sit, instead of resolving them again.
167 if (fast && before instanceof View && after instanceof View) after.shareMoves(before);
168 const touched = touchedFiles(graph, atoms, [before, after]);
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare169 // Author totals start with the first version too, and are kept only while every version since has kept them.
170 const authored = authoredVersion(storage);
171 const authoring = authored === v - 1 || (v === 0 && authored === undefined);
172 const authorOf = authorsOf(graph);
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare173 let files: string[];
174 if (!fast) {
175 files = [...touched].filter((path) => differs(before, after, path)).sort();
176 // Counts start with the first version; a writer adopted before has none and keeps none.
177 if (counted === v - 1 || (v === 0 && counted === undefined)) {
178 for (const path of files) storage.write(COUNTS, path, visibleCount(after, path));
179 storage.write(META, "version", v);
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare180 }
181 // Every touched file's totals from its layout: one whose lines are the same texts by someone else isn't among
182 // the changed files, but its authors changed.
183 if (authoring) {
184 for (const path of touched) keepTotals(storage, v, path, laidOutTotals(after, path, authorOf));
185 storage.write(AUTHORS_META, "version", v);
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare186 }
187 return { files };
188 }
189 const beforeSet = host.at(v - 1);
190 const afterSet = host.at(v);
191 const visibleIn = (set: ReadonlySet<AtomId>, n: number) => {
192 for (const seq of graph.eachDeleterSeqOf(n)) if (set.has(graph.idOfSeq(seq))) return false;
193 return true;
194 };
195 const fileOf = (view: ReadView, line: string, n: number) =>
196 view.hasMoves() ? view.fileOf(line) : graph.writtenIn(n);
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare197 // Per file: visible lines added minus removed, and the texts' balance; and, while totals are kept, each author's lines
198 // and the bytes added minus removed (a line and its newline, as joinLines makes the file).
199 const changes = new Map<
200 string,
201 { net: number; texts: Map<string, number>; lines: number; authors: Map<string, number>; bytes: number }
202 >();
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare203 const change = (path: string) => {
204 let c = changes.get(path);
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare205 if (!c) changes.set(path, (c = { net: 0, texts: new Map(), lines: 0, authors: new Map(), bytes: 0 }));
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare206 return c;
207 };
208 for (const id of p.atoms) {
209 for (const line of graph.eachInsertedLine(id)) {
210 const n = graph.lineN(line);
211 if (!visibleIn(afterSet, n)) continue;
212 const c = change(fileOf(after, line, n));
213 const text = graph.textOf(n);
214 c.net++;
215 c.lines++;
216 c.texts.set(text, (c.texts.get(text) ?? 0) + 1);
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare217 if (authoring) {
218 const author = authorOf(id);
219 c.authors.set(author, (c.authors.get(author) ?? 0) + 1);
220 c.bytes += utf8Bytes(text) + 1;
221 }
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare222 }
223 for (const line of graph.deletedLines(id)) {
224 const n = graph.lineN(line);
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare225 const writer = graph.idOfSeq(graph.writerSeqOf(n));
226 if (!beforeSet.has(writer) || !visibleIn(beforeSet, n)) continue;
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare227 const c = change(fileOf(before, line, n));
228 const text = graph.textOf(n);
229 c.net--;
230 c.lines++;
231 c.texts.set(text, (c.texts.get(text) ?? 0) - 1);
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare232 if (authoring) {
233 const author = authorOf(writer);
234 c.authors.set(author, (c.authors.get(author) ?? 0) - 1);
235 c.bytes -= utf8Bytes(text) + 1;
236 }
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare237 }
capacity251Author totals: each shared file's lines by author and its size, kept as versions land, so tree with authors reads them instead of laying every file out (abso Capacity, issue 664; docs/disk-first-2.md; Security yes on ask 2096). version-files.ts keeps, beside the head line counts, each file's totals at the newest version (head-authors) and at every version that changed them (author-totals), from version 0 on and only while every version since has kept them. A version on the fast path adds each inserted visible line to its author and takes each deleted one off its writer's, with its UTF-8 bytes and newline (joinLines). A version with moves, drops or a closure change counts every touched file from its layout, so a line rewritten with the same text by someone else still moves its author. Shared only; a draft's view takes its base's totals for the files the draft doesn't touch (touchedBeyond) and lays out the rest, and a named draft never reads them. Kept in the writer's state, so whatever replaces or clears it (a new adoption, a restore, a live drop) takes them too. A writer adopted before this keeps none and lays out as before. On a fresh abso adoption (my machine): tree with authors at 1224 takes 333 ms first and 50 ms again (11 to 16 s and 1.8 to 2.4 s before); an agent's tree with authors 619 ms again (2 to 3.4 s). Adoption 7.2 min, the same as before. A full run matches 33 of 33 answers. Test: author-totals.test.ts, tree with authors at every version and in every agent's view, the stored writer against the in-memory project: moved lines, a rename by record and by move, a drop, a binary file, text beyond ASCII, drafts that edit, move lines or have nothing. With the path, move, drop, draft, adoption and version-files tests: 47 of 47.Compare238 }
239 if (authoring) {
240 for (const [path, c] of changes) {
241 if (c.lines === 0) continue;
242 const was = storage.read(AUTHORS, path) as StoredTotals | undefined;
243 const authors = new Map(was?.a ?? []);
244 for (const [author, d] of c.authors) authors.set(author, (authors.get(author) ?? 0) + d);
245 keepTotals(storage, v, path, normalTotals(authors, (was?.b ?? 0) + c.bytes));
246 }
247 storage.write(AUTHORS_META, "version", v);
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare248 }
249 files = [];
250 const exists = new Map<string, readonly [boolean, boolean]>();
251 for (const path of touched) {
252 const was = (storage.read(COUNTS, path) as number | undefined) ?? 0;
253 const c = changes.get(path);
254 const now = was + (c?.net ?? 0);
255 const b = before.attrs(path);
256 const a = after.attrs(path);
257 const had = b.exists || b.link !== null || b.blob !== null || was > 0;
258 const has = a.exists || a.link !== null || a.blob !== null || now > 0;
259 let differ = had !== has || b.exec !== a.exec || b.link !== a.link || b.blob !== a.blob;
260 if (!differ && had && c && c.lines > 0) {
261 // Different texts in or out: the file's lines changed. The same texts in and out: compare the files.
262 differ = [...c.texts.values()].some((count) => count !== 0) || !before.sameText(path, after);
263 }
264 if (differ) {
265 files.push(path);
266 exists.set(path, [had, has]);
267 }
268 if (now !== was) storage.write(COUNTS, path, now);
269 }
270 storage.write(META, "version", v);
271 return { files: files.sort(), exists };