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/pathindex.ts --version 316 --json
JSON
/christopher/abso-core/blame/worker/project/pathindex.ts?version=316&format=json
304 linesFirst import 61% · capacity 35% · codex-capacity-chair 4%Last change capacity in version 316,

304 lines from 10 changes in 8 versions.

codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare1import { View } from "../../src/engine/index.ts";
init0Start the project2// Each version's files and shape, and each path's history in a space (#41; #46, disk-first 1). Built the first
3// time it's asked for and kept up as versions land; a version's files are also kept in the shapes table, so a
4// load needn't lay them out again.
5
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare6import type { AtomId, Graph, LineId, ReadView } from "../../src/engine/index.ts";
init0Start the project7import {
8 differs,
9 type LastChange,
10 type PathLife,
11 type ProjectOptions,
12 shapeStamp,
13 type VersionShape,
14} from "./project.ts";
15import { last, SHARED, type Space } from "./spaces.ts";
17/** What the path index needs from a project. */
18export interface PathIndexDeps {
19 readonly graph: Graph;
20 at(space: Space, version: number): ReadonlySet<AtomId>;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare21 viewAt(space: Space, version: number): ReadView;
22 touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;
init0Start the project23 readonly shapes: ProjectOptions["shapes"];
capacity252Folder blame from author totals; an agent's tree compares only its draft's files; file lists without a full walk; one space object per stored row (abso Capacity, issue 664). - Folder blame counts each file's kept author totals where they answer (Project.authorTotalsFor: shared at a version, or an agent's view for the files its draft doesn't touch), and lays out the rest as before. - An agent's tree marked a file changed by comparing it in both views, which laid every file out twice (13 s of 14.6 s on abso). Only a file the draft touches can differ from its base (touchedBeyond, as the view's layout sharing uses), so only those are compared; a draft that moves lines compares every file as before. - View.paths: a draft's view over its base's takes the base's file list and checks only the files its draft touches; a published version's view answers from its kept file list. Both walked every file the graph ever had. - PathIndex.keptPathSet works an older version's file list back from the newest one (undoing each version's made and gone files), and keeps a few, instead of folding from version 0 again for every agent's base. - Membership's stored spaces decode to the same object for the same stored row. A space reads everything else through to storage; a new object on every read emptied every cache kept by space (the path index, versions' files and shapes, the kept file lists) on every call. On a fresh abso adoption (my machine): an agent's tree with authors 582 ms first and 762 ms again (12.5 s and 0.6 to 1.5 s before); folder blame for an agent 404 ms and 248 ms (1.8 s and 2.0 s); tree with authors at 1224 again 19 ms. A full run matches 33 of 33 answers; held heap at most 40.2 MB. Tests: author-totals now also compares folder blame at every version and in every agent's view, against the in-memory project. All of worker/project/test: 349 of 349 pass (one skipped).Compare26/** Older versions' file lists kept per space (a few agents' bases): about 1,000 paths each on abso. */
27const OLDER_PATH_SETS = 8;
init0Start the project29export class PathIndex {
30 readonly #deps: PathIndexDeps;
32 constructor(deps: PathIndexDeps) {
33 this.#deps = deps;
34 }
36 /** Whether a version's files are already worked out (a file's log skips versions that can't name it, #43). */
37 knowsFiles(space: Space, version: number): boolean {
38 return this.#filesCache.get(space)?.has(version) ?? false;
39 }
41 /** Each version's changed files (#43): a published version never changes, so they're worked out once. */
42 readonly #filesCache = new WeakMap<Space, Map<number, string[]>>();
44 /** Each version's files made and taken out, and moves (#41), worked out with its files. */
45 readonly #shapeCache = new WeakMap<Space, Map<number, VersionShape>>();
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare47 /** The files at the newest version folded so far from kept shapes, per space (keptPaths). */
48 readonly #keptPaths = new WeakMap<Space, { version: number; files: Set<string> }>();
capacity252Folder blame from author totals; an agent's tree compares only its draft's files; file lists without a full walk; one space object per stored row (abso Capacity, issue 664). - Folder blame counts each file's kept author totals where they answer (Project.authorTotalsFor: shared at a version, or an agent's view for the files its draft doesn't touch), and lays out the rest as before. - An agent's tree marked a file changed by comparing it in both views, which laid every file out twice (13 s of 14.6 s on abso). Only a file the draft touches can differ from its base (touchedBeyond, as the view's layout sharing uses), so only those are compared; a draft that moves lines compares every file as before. - View.paths: a draft's view over its base's takes the base's file list and checks only the files its draft touches; a published version's view answers from its kept file list. Both walked every file the graph ever had. - PathIndex.keptPathSet works an older version's file list back from the newest one (undoing each version's made and gone files), and keeps a few, instead of folding from version 0 again for every agent's base. - Membership's stored spaces decode to the same object for the same stored row. A space reads everything else through to storage; a new object on every read emptied every cache kept by space (the path index, versions' files and shapes, the kept file lists) on every call. On a fresh abso adoption (my machine): an agent's tree with authors 582 ms first and 762 ms again (12.5 s and 0.6 to 1.5 s before); folder blame for an agent 404 ms and 248 ms (1.8 s and 2.0 s); tree with authors at 1224 again 19 ms. A full run matches 33 of 33 answers; held heap at most 40.2 MB. Tests: author-totals now also compares folder blame at every version and in every agent's view, against the in-memory project. All of worker/project/test: 349 of 349 pass (one skipped).Compare49 /** The files at a few older versions, worked back from the newest (agents' bases, mostly), most recent last. */
50 readonly #olderPaths = new WeakMap<Space, Map<number, Set<string>>>();
52 /**
53 * The files at a version older than the newest folded (abso Capacity): the newest's files with each version since
54 * undone, its made files taken out and its gone ones put back. Folding from version 0 again for an agent's base
55 * read every version's kept row on each call.
56 */
57 #olderPathSet(
58 space: Space,
59 fold: { version: number; files: Set<string> },
60 version: number,
61 ): ReadonlySet<string> | undefined {
62 let older = this.#olderPaths.get(space);
63 if (!older) this.#olderPaths.set(space, (older = new Map()));
64 const known = older.get(version);
65 if (known) {
66 older.delete(version);
67 older.set(version, known);
68 return known;
69 }
70 const files = new Set(fold.files);
71 for (let v = fold.version; v > version; v--) {
72 if (!this.#keptFiles(space, v)) return undefined;
73 const shape = this.#shapeCache.get(space)?.get(v);
74 if (!shape) return undefined;
75 for (const f of shape.made) files.delete(f);
76 for (const f of shape.gone) files.add(f);
77 }
78 older.set(version, files);
79 if (older.size > OLDER_PATH_SETS) older.delete(older.keys().next().value!);
80 return files;
81 }
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare82
83 /**
84 * The files a space has at a version, from the kept rows of every version up to it: each one's files made and
85 * taken out, folded from version 0 (abso Capacity). Undefined when a version has no kept row that describes it;
86 * then the caller lays the version out.
87 */
88 keptPaths(space: Space, version: number): string[] | undefined {
capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare89 const files = this.keptPathSet(space, version);
90 return files && [...files].sort();
91 }
capacity316Land and draft-state take where shared changed since a draft's base from each version's kept files (abso 738). The definition rule placed every line the newer atoms wrote or deleted to find the files they touched: about 30% of a warm draft-state read. LandHost.changedSince unions PathIndex's kept version files over the versions since the base, on a stored writer only, and the rule falls back to working them out when a version has none. Every file whose text differs between the base and now is in it. Known difference: it also names files only the draft's own atoms already in shared changed; a collision there still needs a newer atom on the definition's lines. On abso's Oct 14 tables both named drafts' states are identical by hash; codex-prose-authorship-610's warm read goes from 18,256 statements and 3.4 s to 8,863 and 2.3 s.Compare93 /**
94 * The files the versions after `from`, up to `to`, changed, from each version's kept row (abso 738): undefined when one
95 * has none, and the caller works them out from the atoms. Every file whose text differs between the two versions is
96 * in it, since some version between changed it.
97 */
98 keptChangesSince(space: Space, from: number, to: number): ReadonlySet<string> | undefined {
99 const out = new Set<string>();
100 for (let v = from + 1; v <= to; v++) {
101 const files = this.#keptFiles(space, v);
102 if (!files) return undefined;
103 for (const f of files) out.add(f);
104 }
105 return out;
106 }
capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare108 /** keptPaths as a set, kept for the newest version asked: never changed once made, so a view can hold it. */
109 keptPathSet(space: Space, version: number): ReadonlySet<string> | undefined {
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare110 let fold = this.#keptPaths.get(space);
capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare111 if (fold?.version === version) return fold.files;
capacity252Folder blame from author totals; an agent's tree compares only its draft's files; file lists without a full walk; one space object per stored row (abso Capacity, issue 664). - Folder blame counts each file's kept author totals where they answer (Project.authorTotalsFor: shared at a version, or an agent's view for the files its draft doesn't touch), and lays out the rest as before. - An agent's tree marked a file changed by comparing it in both views, which laid every file out twice (13 s of 14.6 s on abso). Only a file the draft touches can differ from its base (touchedBeyond, as the view's layout sharing uses), so only those are compared; a draft that moves lines compares every file as before. - View.paths: a draft's view over its base's takes the base's file list and checks only the files its draft touches; a published version's view answers from its kept file list. Both walked every file the graph ever had. - PathIndex.keptPathSet works an older version's file list back from the newest one (undoing each version's made and gone files), and keeps a few, instead of folding from version 0 again for every agent's base. - Membership's stored spaces decode to the same object for the same stored row. A space reads everything else through to storage; a new object on every read emptied every cache kept by space (the path index, versions' files and shapes, the kept file lists) on every call. On a fresh abso adoption (my machine): an agent's tree with authors 582 ms first and 762 ms again (12.5 s and 0.6 to 1.5 s before); folder blame for an agent 404 ms and 248 ms (1.8 s and 2.0 s); tree with authors at 1224 again 19 ms. A full run matches 33 of 33 answers; held heap at most 40.2 MB. Tests: author-totals now also compares folder blame at every version and in every agent's view, against the in-memory project. All of worker/project/test: 349 of 349 pass (one skipped).Compare112 if (fold && fold.version > version) return this.#olderPathSet(space, fold, version);
113 if (!fold) fold = { version: -1, files: new Set() };
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare114 const files = new Set(fold.files);
115 for (let v = fold.version + 1; v <= version; v++) {
116 if (!this.#keptFiles(space, v)) return undefined;
capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare117 // Not yet when the version is still being kept (keep asks its views which files exist).
118 const shape = this.#shapeCache.get(space)?.get(v);
119 if (!shape) return undefined;
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare120 for (const f of shape.gone) files.delete(f);
121 for (const f of shape.made) files.add(f);
122 }
123 this.#keptPaths.set(space, { version, files });
capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare124 return files;
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare125 }
init0Start the project127 /** Each space's path index (#41): built the first time it's asked for, then kept up as versions land. */
128 readonly #pathIndex = new WeakMap<Space, { upTo: number; paths: Map<string, PathLife> }>();
130 /** The files a version changed. `views` holds views by version, so a run of versions builds each once. */
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare131 versionFiles(space: Space, version: number, views = new Map<number, ReadView>()): string[] {
init0Start the project132 let cache = this.#filesCache.get(space);
133 if (!cache) this.#filesCache.set(space, (cache = new Map()));
134 const known = cache.get(version);
135 if (known) return known;
136 const kept = this.#keptFiles(space, version);
137 if (kept) return kept;
138 const shapes = this.#shapeCache.get(space)!;
139 const p = space.versions[version]!;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare140 const viewAt = (v: number): ReadView => {
init0Start the project141 let view = views.get(v);
142 if (!view) views.set(v, (view = v < 0 ? new View(this.#deps.graph, []) : this.#deps.viewAt(space, v)));
143 return view;
144 };
145 const before = viewAt(version - 1);
146 const after = viewAt(version);
147 // Net changes only, as show has them: a file made and removed again before the publish isn't one (#37).
148 const touched = this.#deps.touchedFiles([...p.atoms, ...(p.dropped ?? [])], [before, after]);
149 const files = [...touched].filter((path) => differs(before, after, path)).sort();
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.Compare150 this.keep(space, version, files, before, after);
init0Start the project151 return files;
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.Compare152 }
154 /**
155 * Keep a version's changed files, with its files made and taken out and its moves: worked out here, or as the
156 * version landed (version-files.ts, abso Capacity), which says which files existed before and after.
157 */
158 keep(
159 space: Space,
160 version: number,
161 files: string[],
162 before: ReadView,
163 after: ReadView,
164 exists?: ReadonlyMap<string, readonly [boolean, boolean]>,
165 ): void {
166 let cache = this.#filesCache.get(space);
167 if (!cache) this.#filesCache.set(space, (cache = new Map()));
168 let shapes = this.#shapeCache.get(space);
169 if (!shapes) this.#shapeCache.set(space, (shapes = new Map()));
170 const p = space.versions[version]!;
init0Start the project171 cache.set(version, files);
172 // Files made and taken out, and which of those are one file moved (#41): an atom that moves lines
173 // names both files, and a binary or empty file moved keeps its blob.
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.Compare174 const had = (f: string) => exists?.get(f)?.[0] ?? before.hasFile(f);
175 const has = (f: string) => exists?.get(f)?.[1] ?? after.hasFile(f);
176 const made = files.filter((f) => !had(f) && has(f));
177 const gone = files.filter((f) => had(f) && !has(f));
init0Start the project178 const moves: [string, string][] = [];
179 if (made.length > 0 && gone.length > 0) {
180 const movers = new Set(this.#deps.graph.movers());
181 const moving = p.atoms.filter((id) => movers.has(id)).map((id) => this.#deps.graph.filesOf(id));
182 const taken = new Set<string>();
183 for (const to of made) {
184 const blob = after.attrs(to).blob;
185 const from = gone.find(
186 (g) =>
187 !taken.has(g) &&
188 (moving.some((fs) => fs.includes(g) && fs.includes(to)) ||
189 (blob !== null && before.attrs(g).blob === blob)),
190 );
191 if (from !== undefined) taken.add(from), moves.push([from, to]);
192 }
193 }
194 shapes.set(version, { made, gone, moves });
195 this.#deps.shapes?.put(space.name, version, JSON.stringify({ stamp: shapeStamp(p), files, made, gone, moves }));
196 }
198 /** A version's files kept from an earlier load (#41), when the row describes this very version; into the caches. */
199 #keptFiles(space: Space, version: number): string[] | undefined {
200 let cache = this.#filesCache.get(space);
201 if (!cache) this.#filesCache.set(space, (cache = new Map()));
202 let shapes = this.#shapeCache.get(space);
203 if (!shapes) this.#shapeCache.set(space, (shapes = new Map()));
204 const known = cache.get(version);
205 if (known) return known;
206 const row = this.#deps.shapes?.get(space.name, version);
207 if (row === undefined) return undefined;
208 const kept = JSON.parse(row) as { stamp: string; files: string[] } & VersionShape;
209 if (kept.stamp !== shapeStamp(space.versions[version]!)) return undefined;
210 cache.set(version, kept.files);
211 shapes.set(version, { made: kept.made, gone: kept.gone, moves: kept.moves });
212 return kept.files;
213 }
215 /** A version's files made and taken out, and moves (#41). */
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare216 versionShape(space: Space, version: number, views?: Map<number, ReadView>): VersionShape {
init0Start the project217 const known = this.#shapeCache.get(space)?.get(version);
218 if (known) return known;
219 this.#filesCache.get(space)?.delete(version);
220 this.versionFiles(space, version, views);
221 return this.#shapeCache.get(space)!.get(version)!;
222 }
224 /**
225 * The space's path index (#41): for each path ever in it, the versions that
226 * changed it, and the versions that made it and took it out. The first ask
227 * after a restart walks every version, as a cold log over all of them does;
228 * later asks only walk the versions since.
229 */
230 pathsOf(space: Space): Map<string, PathLife> {
231 let index = this.#pathIndex.get(space);
232 if (!index) this.#pathIndex.set(space, (index = { upTo: -1, paths: new Map() }));
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare233 const views = new Map<number, ReadView>();
init0Start the project234 // Shared's sets grow version by version, so walk them forward rather than build each from the
235 // start; the views stay out of the cache, which they would only push other views from. A version
236 // whose files are kept (#41) needs no views at all.
237 let running: Set<AtomId> | undefined;
238 let runningAt = -1;
239 const setAt = (u: number): Set<AtomId> => {
240 if (!running || runningAt > u) (running = new Set(u < 0 ? [] : this.#deps.at(space, u))), (runningAt = u);
241 while (runningAt < u) {
242 const q = space.versions[++runningAt]!;
243 for (const id of q.atoms) running.add(id);
244 for (const id of q.dropped ?? []) running.delete(id);
245 }
246 return running;
247 };
248 for (let v = index.upTo + 1; v <= last(space); v++) {
codex-capacity-chair164Fix disk-backed historical paths, empty queues and canonical frame integrityCompare249 // Persistent graphs use the indexed version reader; a raw View would
250 // rebuild move scratch state and copy historical membership during a read.
251 if (space.name === SHARED && !this.#deps.graph.hasOrderedChildren && !this.#keptFiles(space, v)) {
init0Start the project252 if (v > 0 && !views.has(v - 1)) views.set(v - 1, new View(this.#deps.graph, new Set(setAt(v - 1))));
253 views.set(v, new View(this.#deps.graph, new Set(setAt(v))));
254 }
255 const files = this.versionFiles(space, v, views);
256 const shape = this.versionShape(space, v, views);
257 views.delete(v - 1);
258 const life = (path: string): PathLife => {
259 let l = index!.paths.get(path);
260 if (!l) index!.paths.set(path, (l = { changed: [], events: [] }));
261 return l;
262 };
263 for (const f of files) life(f).changed.push(v);
264 const from = new Map(shape.moves.map(([a, b]) => [b, a]));
265 const to = new Map(shape.moves);
266 for (const f of shape.made)
267 life(f).events.push({ version: v, made: true, ...(from.has(f) ? { other: from.get(f)! } : {}) });
268 for (const f of shape.gone)
269 life(f).events.push({ version: v, made: false, ...(to.has(f) ? { other: to.get(f)! } : {}) });
270 index.upTo = v;
271 }
272 return index.paths;
273 }
275 lastChange(space: Space, version: number): LastChange {
276 const p = space.versions[version]!;
277 return { version, agent: p.agent, time: p.time, message: p.message };
278 }
280 /** The newest version in a sorted list no later than `version`, or undefined. */
281 static atOrBefore(list: readonly number[], version: number): number | undefined {
282 let lo = 0;
283 let hi = list.length;
284 while (lo < hi) {
285 const mid = (lo + hi) >> 1;
286 if (list[mid]! <= version) lo = mid + 1;
287 else hi = mid;
288 }
289 return lo > 0 ? list[lo - 1] : undefined;
290 }
292 /** The newest version in (from, to] that took a line out: one deleting it, or a drop of the change that wrote it. */
293 removedIn(space: Space, from: number, to: number, line: LineId): { removed?: number } {
294 const g = this.#deps.graph;
295 const deleters = new Set(g.deletersOf(line));
296 const writer = g.line(line)?.atom;
297 for (let v = to; v > from; v--) {
298 const p = space.versions[v]!;
299 if (p.atoms.some((id) => deleters.has(id)) || (writer !== undefined && p.dropped?.includes(writer)))
300 return { removed: v };
301 }
302 return {};
303 }