{"draft":null,"from":57,"to":318,"files":[{"path":"src/engine/graph.ts","added":1148,"removed":159,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -2,6 +2,8 @@\n // the codebase) are separate values; the graph only answers questions about\n // atoms and keeps indexes so those questions are cheap.\n \n+import { ChildCounts } from \"./child-counts.ts\";\n+import { JsonStringChunks, registerJsonChunkValue } from \"./json-value-chunks.ts\";\n import {\n \tatomId,\n \tattrKey,\n@@ -15,7 +17,21 @@\n \tseqOf,\n \tstartNode,\n } from \"./keys.ts\";\n+import { OrderedIndex, orderedChildKey } from \"./ordered-index.ts\";\n+import { withProjectionScratch } from \"./projection-scratch.ts\";\n import {\n+\ttype GraphStateStorage,\n+\treadonlyPagedArray,\n+\treadonlyStoredArray,\n+\ttype StateMap,\n+\tstoredArray,\n+\tstoredLists,\n+\tstoredMap,\n+\tstoredNumbers,\n+\twritePagedArray,\n+} from \"./state-source.ts\";\n+import { StoredText } from \"./stored-text.ts\";\n+import {\n \tATTR_NAMES,\n \ttype Atom,\n \ttype AtomId,\n@@ -76,21 +92,25 @@\n  * are two (#46): most keys name one atom, and a list for each costs more than\n  * the value.\n  */\n-function pushOne<K, V>(map: Map<K, V | V[]>, key: K, value: V): void {\n+function pushOne<K, V>(map: StateMap<K, V | V[]>, key: K, value: V): void {\n \tconst had = map.get(key);\n \tif (had === undefined) map.set(key, value);\n-\telse if (Array.isArray(had)) had.push(value);\n-\telse map.set(key, [had, value]);\n+\telse if (Array.isArray(had)) {\n+\t\thad.push(value);\n+\t\tmap.set(key, had);\n+\t} else map.set(key, [had, value]);\n }\n \n function listOf<V>(had: V | V[] | undefined): readonly V[] {\n \treturn had === undefined ? EMPTY : Array.isArray(had) ? had : [had];\n }\n \n-function pushIndex<K, V>(map: Map<K, V[]>, key: K, value: V): void {\n+function pushIndex<K, V>(map: StateMap<K, V[]>, key: K, value: V): void {\n \tconst list = map.get(key);\n-\tif (list) list.push(value);\n-\telse map.set(key, [value]);\n+\tif (list) {\n+\t\tlist.push(value);\n+\t\tmap.set(key, list);\n+\t} else map.set(key, [value]);\n }\n \n const EMPTY: readonly never[] = Object.freeze([]);\n@@ -176,7 +196,14 @@\n }\n \n /** A growable array of 32-bit integers: a line's fields cost 4 bytes each, not an object and its strings (#46). */\n-class Ints {\n+interface NumberIndex {\n+\treadonly length: number;\n+\tpush(n: number): void;\n+\tat(i: number): number;\n+\tset(i: number, n: number): void;\n+}\n+\n+class Ints implements NumberIndex {\n \t#buf: Int32Array | Uint8Array;\n \t/** bytes: values 0-255 only, one byte each. */\n \tconstructor(bytes = false) {\n@@ -231,41 +258,554 @@\n \treturn { seq, k };\n }\n \n+/** A line in its file's packed history: [n, parent code, writer seq, k, 1 when it replaces its parent]. */\n+export type PackedLine = [number, number, number, number, number];\n+/** A delete of a line in a file's packed history: [n, deleter seq]. */\n+export type PackedDelete = [number, number];\n+/** An attribute set on a file: [seq, name, value]. */\n+export type PackedAttr = [number, string, string | null];\n+/** A run written in another file under one of a file's lines: [the parent's n, the run's file index]. */\n+export type PackedCrossing = [number, number];\n+\n+/**\n+ * A file's packed history decoded, without texts (Graph.packedHistory): PackedLine's five numbers per line, then\n+ * PackedDelete's two per delete and PackedCrossing's two per crossing, each list flat.\n+ */\n+export interface PackedHistory {\n+\treadonly lines: ArrayLike<number>;\n+\treadonly deletes: ArrayLike<number>;\n+\treadonly crossings: ArrayLike<number>;\n+}\n+\n+/**\n+ * Bytes of decoded file histories a stored graph keeps between layouts (abso Capacity). Every view of a file read its\n+ * whole history from pages: compare lays each file out once per side, collisions once per draft touching it, and a\n+ * file whose lines moved in from another read that one's history too (abso's worker files, split out of index.ts).\n+ * abso's index.ts, 46,000 lines of history, takes about 1 MB.\n+ */\n+export const PACKED_HISTORY_BUDGET = 4_000_000;\n+\n+/** Numbers packed flat: 4 bytes each while they fit in 32 bits, else 8. */\n+function packNumbers(rows: Iterable<readonly number[]>): Int32Array | Float64Array {\n+\tconst flat: number[] = [];\n+\tlet small = true;\n+\tfor (const row of rows)\n+\t\tfor (const value of row) {\n+\t\t\tif ((value | 0) !== value) small = false;\n+\t\t\tflat.push(value);\n+\t\t}\n+\treturn small ? Int32Array.from(flat) : Float64Array.from(flat);\n+}\n+const EMPTY_NUMBERS: readonly number[] = Object.freeze([]);\n+/** At most this many path names kept in memory (Graph.#pathName). */\n+const PATH_NAMES = 4096;\n+/** Lines longer than this aren't packed with their file; their text is read on its own. */\n+const PACKED_TEXT = 4096;\n+\n export class Graph {\n+\treadonly #storage?: GraphStateStorage;\n+\treadonly #childCounts?: ChildCounts;\n \t#atoms: Atom[] = [];\n \t#lamport: number[] = [];\n+\t/**\n+\t * A stored graph's lamport numbers, 256 to a row (abso Capacity). A graph that already has them a row each (#lamport)\n+\t * keeps that; the choice is made when first needed, so opening reads nothing.\n+\t */\n+\t#lamportPaged: ReturnType<typeof storedNumbers> | undefined;\n+\t#lamportPagesKnown: ReturnType<typeof storedNumbers> | null | undefined;\n+\tget #lamportPages(): ReturnType<typeof storedNumbers> | null {\n+\t\tif (this.#lamportPagesKnown === undefined)\n+\t\t\tthis.#lamportPagesKnown =\n+\t\t\t\tthis.#lamportPaged && this.#storage!.read(\"lamport:meta\", \"length\") === undefined ? this.#lamportPaged : null;\n+\t\treturn this.#lamportPagesKnown;\n+\t}\n \t// Lines, packed (#46): line n is the k-th line atom seq wrote, n = #lineBase[seq] + k. Each holds its\n \t// atom's seq, the file it was written in (an index into #paths) and its parent (a line's n, or -1 - a\n \t// path's index for a file's start). Its text stays in the atom. Ids and LineInfo objects are made only\n \t// when asked for, so a line costs about 16 bytes here instead of a record, its id and its parent's id.\n \t#lineBase: number[] = [];\n-\t#lineAtom = new Ints();\n-\t#lineFile = new Ints();\n-\t#lineParent = new Ints();\n+\t#lineAtom: NumberIndex = new Ints();\n+\t#lineFile: NumberIndex = new Ints();\n+\t#lineParent: NumberIndex = new Ints();\n \t/** Lines' text, when the graph keeps it; without it, it comes from `texts` (#46, text on disk). */\n \t#lineText: string[] | undefined = [];\n-\t#lineTotal = 0;\n+\tget #lineTotal(): number {\n+\t\treturn this.#lineAtom.length;\n+\t}\n \t/** Where an atom's lines' text is when the graph doesn't keep it: each run's lines, by the atom's seq. */\n \t#texts: ((seq: number) => readonly (readonly string[])[]) | undefined;\n \t/** Recently read atoms' text, flattened, most recent last, up to TEXT_CACHE characters. */\n \t#textCache = new Map<number, readonly string[]>();\n \t#textCached = 0;\n \n+\treadonly #indexAcceptedAtom?: (atom: Atom, files: readonly string[], storage: GraphStateStorage) => void;\n+\n \t/**\n \t * `texts`, when given, says where each atom's lines' text can be read back\n \t * (#46): the graph then keeps no text, only each line's place, and reads an\n \t * atom's text when a line of it is asked for, keeping the most recent.\n \t */\n \tconstructor(\n-\t\toptions: { texts?: (seq: number) => readonly (readonly string[])[]; lists?: (seq: number) => AtomLists } = {},\n+\t\toptions: {\n+\t\t\ttexts?: (seq: number) => readonly (readonly string[])[];\n+\t\t\tlists?: (seq: number) => AtomLists;\n+\t\t\tstorage?: GraphStateStorage;\n+\t\t\t/** Optional derived indexing inside persistent atom acceptance; must be synchronous. */\n+\t\t\tindexAcceptedAtom?: (atom: Atom, files: readonly string[], storage: GraphStateStorage) => void;\n+\t\t\t/** false: a new stored graph keeps no packed file history, and lays files out line by line (tests of that path). */\n+\t\t\tpackFiles?: boolean;\n+\t\t} = {},\n \t) {\n+\t\tif (options.indexAcceptedAtom && !options.storage)\n+\t\t\tthrow Error(\"accepted atom indexing requires persistent storage\");\n+\t\tthis.#indexAcceptedAtom = options.indexAcceptedAtom;\n \t\tif (options.texts) {\n \t\t\tthis.#texts = options.texts;\n \t\t\tthis.#lineText = undefined;\n \t\t}\n \t\tif (options.lists) this.#lists = options.lists;\n+\t\tthis.#storage = options.storage;\n+\t\tif (options.storage) this.#childCounts = new ChildCounts(options.storage);\n+\t\tif (options.storage) {\n+\t\t\tconst storage = options.storage;\n+\t\t\tconst numbers = (name: string): NumberIndex => storedNumbers(storage, name);\n+\t\t\tconst atomText = new StoredText(storage, \"atom-text:long\");\n+\t\t\ttype TextReference = { text: string };\n+\t\t\tconst listFields = [\n+\t\t\t\t\"deletes\",\n+\t\t\t\t\"writes\",\n+\t\t\t\t\"reads\",\n+\t\t\t\t\"holds\",\n+\t\t\t\t\"needs\",\n+\t\t\t\t\"resolves\",\n+\t\t\t\t\"deps\",\n+\t\t\t\t\"reasons\",\n+\t\t\t\t\"attrs\",\n+\t\t\t\t\"moves\",\n+\t\t\t] as const;\n+\t\t\ttype EncodedAtom = {\n+\t\t\t\tinsertionFormat?: 1;\n+\t\t\t\tinsertionRuns?: string;\n+\t\t\t\ttextFormat?: 1;\n+\t\t\t\tlistFormat?: 1 | 2;\n+\t\t\t\tlistCount?: number;\n+\t\t\t\tlists?: Partial<Record<(typeof listFields)[number], string>>;\n+\t\t\t\tatom: Atom;\n+\t\t\t};\n+\t\t\tthis.#atoms = storedArray<Atom>(\n+\t\t\t\tstorage,\n+\t\t\t\t\"atoms\",\n+\t\t\t\t(value) => {\n+\t\t\t\t\tconst encoded = value as unknown as Partial<EncodedAtom>;\n+\t\t\t\t\tif (encoded.textFormat !== undefined && encoded.textFormat !== 1)\n+\t\t\t\t\t\tthrow Error(\"invalid stored atom text format\");\n+\t\t\t\t\tif (encoded.listFormat !== undefined && encoded.listFormat !== 1 && encoded.listFormat !== 2)\n+\t\t\t\t\t\tthrow Error(\"invalid stored atom list format\");\n+\t\t\t\t\tif (encoded.listFormat === 1 || encoded.listFormat === 2) {\n+\t\t\t\t\t\tif (\n+\t\t\t\t\t\t\t!encoded.lists ||\n+\t\t\t\t\t\t\ttypeof encoded.lists !== \"object\" ||\n+\t\t\t\t\t\t\tArray.isArray(encoded.lists) ||\n+\t\t\t\t\t\t\t!Number.isSafeInteger(encoded.listCount) ||\n+\t\t\t\t\t\t\tencoded.listCount! < 1 ||\n+\t\t\t\t\t\t\tObject.keys(encoded.lists).length !== encoded.listCount ||\n+\t\t\t\t\t\t\tObject.keys(encoded.lists).some((field) => !listFields.includes(field as (typeof listFields)[number]))\n+\t\t\t\t\t\t)\n+\t\t\t\t\t\t\tthrow Error(\"invalid stored atom list references\");\n+\t\t\t\t\t}\n+\t\t\t\t\tif (encoded.insertionFormat !== undefined && encoded.insertionFormat !== 1)\n+\t\t\t\t\t\tthrow Error(\"invalid stored insertion format\");\n+\t\t\t\t\tconst atom =\n+\t\t\t\t\t\tencoded.textFormat === 1 ||\n+\t\t\t\t\t\tencoded.listFormat === 1 ||\n+\t\t\t\t\t\tencoded.listFormat === 2 ||\n+\t\t\t\t\t\tencoded.insertionFormat === 1\n+\t\t\t\t\t\t\t? encoded.atom!\n+\t\t\t\t\t\t\t: value;\n+\t\t\t\t\tif (encoded.insertionFormat === 1 && (!Array.isArray(atom.inserts) || atom.inserts.length !== 0))\n+\t\t\t\t\t\tthrow Error(\"invalid stored insertion placeholder\");\n+\t\t\t\t\tconst text =\n+\t\t\t\t\t\tencoded.textFormat === 1\n+\t\t\t\t\t\t\t? (start: number, length: number): readonly string[] => {\n+\t\t\t\t\t\t\t\t\tconst result: string[] = [];\n+\t\t\t\t\t\t\t\t\tlet index = 0;\n+\t\t\t\t\t\t\t\t\tfor (const run of atom.inserts)\n+\t\t\t\t\t\t\t\t\t\tfor (const raw of run.lines) {\n+\t\t\t\t\t\t\t\t\t\t\tif (index >= start && index < start + length) {\n+\t\t\t\t\t\t\t\t\t\t\t\tconst reference = raw as unknown as TextReference;\n+\t\t\t\t\t\t\t\t\t\t\t\tif (typeof raw === \"string\") result.push(raw);\n+\t\t\t\t\t\t\t\t\t\t\t\telse if (reference && reference.text === JSON.stringify([String(atom.seq), index]))\n+\t\t\t\t\t\t\t\t\t\t\t\t\tresult.push(atomText.read(reference.text));\n+\t\t\t\t\t\t\t\t\t\t\t\telse throw Error(\"invalid stored atom text reference\");\n+\t\t\t\t\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t\t\t\t\t\tif (++index >= start + length) return result;\n+\t\t\t\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t\t\t\tthrow Error(\"stored atom text range missing\");\n+\t\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t\t: undefined;\n+\t\t\t\t\t// Sequential reads advance once per run without retaining a history-sized offset array.\n+\t\t\t\t\tlet offsetRun = 0;\n+\t\t\t\t\tlet offsetLine = 0;\n+\t\t\t\t\tconst insertionStart = (index: number): number => {\n+\t\t\t\t\t\tif (index < offsetRun) {\n+\t\t\t\t\t\t\toffsetRun = 0;\n+\t\t\t\t\t\t\toffsetLine = 0;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\twhile (offsetRun < index) {\n+\t\t\t\t\t\t\toffsetLine += readonlyStoredArray(storage, `atom-inserts:${atom.seq}:lines:${offsetRun}`).length;\n+\t\t\t\t\t\t\toffsetRun++;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\treturn offsetLine;\n+\t\t\t\t\t};\n+\t\t\t\t\tconst streamed = (target: Atom): Atom => {\n+\t\t\t\t\t\tregisterJsonChunkValue(target, () => {\n+\t\t\t\t\t\t\tconst line = (raw: unknown, index: number): unknown => {\n+\t\t\t\t\t\t\t\tif (typeof raw === \"string\") return raw;\n+\t\t\t\t\t\t\t\tconst reference = raw as TextReference;\n+\t\t\t\t\t\t\t\tif (!reference || reference.text !== JSON.stringify([String(atom.seq), index]))\n+\t\t\t\t\t\t\t\t\tthrow Error(\"invalid stored atom text reference\");\n+\t\t\t\t\t\t\t\treturn new JsonStringChunks(() => atomText.chunks(reference.text));\n+\t\t\t\t\t\t\t};\n+\t\t\t\t\t\t\tlet inserts: readonly unknown[];\n+\t\t\t\t\t\t\tif (encoded.insertionFormat === 1) {\n+\t\t\t\t\t\t\t\tconst collection = `atom-inserts:${atom.seq}`;\n+\t\t\t\t\t\t\t\tinserts = readonlyStoredArray(storage, collection, (raw, index) => {\n+\t\t\t\t\t\t\t\t\tconst run = raw as {\n+\t\t\t\t\t\t\t\t\t\tfile: string;\n+\t\t\t\t\t\t\t\t\t\tparent: string;\n+\t\t\t\t\t\t\t\t\t\tlines: string;\n+\t\t\t\t\t\t\t\t\t};\n+\t\t\t\t\t\t\t\t\tconst lines = `${collection}:lines:${index}`;\n+\t\t\t\t\t\t\t\t\tif (run.lines !== lines || typeof run.file !== \"string\" || typeof run.parent !== \"string\")\n+\t\t\t\t\t\t\t\t\t\tthrow Error(\"invalid stored insertion run\");\n+\t\t\t\t\t\t\t\t\tconst start = insertionStart(index);\n+\t\t\t\t\t\t\t\t\treturn {\n+\t\t\t\t\t\t\t\t\t\tfile: run.file,\n+\t\t\t\t\t\t\t\t\t\tparent: run.parent,\n+\t\t\t\t\t\t\t\t\t\tlines: readonlyStoredArray(storage, lines, (raw, i) => line(raw, start + i)),\n+\t\t\t\t\t\t\t\t\t};\n+\t\t\t\t\t\t\t\t});\n+\t\t\t\t\t\t\t} else {\n+\t\t\t\t\t\t\t\tlet index = 0;\n+\t\t\t\t\t\t\t\tinserts = atom.inserts.map((run) => ({\n+\t\t\t\t\t\t\t\t\tfile: run.file,\n+\t\t\t\t\t\t\t\t\tparent: run.parent,\n+\t\t\t\t\t\t\t\t\tlines: run.lines.map((raw) => line(raw, index++)),\n+\t\t\t\t\t\t\t\t}));\n+\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t\treturn { ...target, inserts };\n+\t\t\t\t\t\t});\n+\t\t\t\t\t\treturn target;\n+\t\t\t\t\t};\n+\t\t\t\t\tconst frozen = freezeAtom(\n+\t\t\t\t\t\tatom,\n+\t\t\t\t\t\t(id) => id,\n+\t\t\t\t\t\t(author) => author,\n+\t\t\t\t\t\ttext,\n+\t\t\t\t\t);\n+\t\t\t\t\tif (encoded.listFormat !== 1 && encoded.listFormat !== 2 && encoded.insertionFormat !== 1)\n+\t\t\t\t\t\treturn streamed(frozen);\n+\t\t\t\t\tconst result = { ...frozen };\n+\t\t\t\t\tif (encoded.insertionFormat === 1) {\n+\t\t\t\t\t\tconst collection = `atom-inserts:${atom.seq}`;\n+\t\t\t\t\t\tif (encoded.insertionRuns !== collection) throw Error(\"invalid stored insertion reference\");\n+\t\t\t\t\t\tconst inserts = readonlyStoredArray<InsertRun>(storage, collection, (raw, index) => {\n+\t\t\t\t\t\t\tconst run = raw as {\n+\t\t\t\t\t\t\t\tfile: string;\n+\t\t\t\t\t\t\t\tparent: InsertRun[\"parent\"];\n+\t\t\t\t\t\t\t\tlines: string;\n+\t\t\t\t\t\t\t};\n+\t\t\t\t\t\t\tconst lines = `${collection}:lines:${index}`;\n+\t\t\t\t\t\t\tif (run.lines !== lines || typeof run.file !== \"string\" || typeof run.parent !== \"string\")\n+\t\t\t\t\t\t\t\tthrow Error(\"invalid stored insertion run\");\n+\t\t\t\t\t\t\treturn Object.freeze({\n+\t\t\t\t\t\t\t\tfile: run.file,\n+\t\t\t\t\t\t\t\tparent: run.parent,\n+\t\t\t\t\t\t\t\tlines: readonlyStoredArray<string>(storage, lines, (rawLine, lineIndex) => {\n+\t\t\t\t\t\t\t\t\tif (typeof rawLine === \"string\") return rawLine;\n+\t\t\t\t\t\t\t\t\tconst ref = rawLine as TextReference;\n+\t\t\t\t\t\t\t\t\tconst atomLine = insertionStart(index) + lineIndex;\n+\t\t\t\t\t\t\t\t\tif (!ref || ref.text !== JSON.stringify([String(atom.seq), atomLine]))\n+\t\t\t\t\t\t\t\t\t\tthrow Error(\"invalid stored insertion text\");\n+\t\t\t\t\t\t\t\t\treturn atomText.read(ref.text);\n+\t\t\t\t\t\t\t\t}),\n+\t\t\t\t\t\t\t});\n+\t\t\t\t\t\t});\n+\t\t\t\t\t\tObject.defineProperty(result, \"inserts\", {\n+\t\t\t\t\t\t\tvalue: inserts,\n+\t\t\t\t\t\t\tenumerable: true,\n+\t\t\t\t\t\t});\n+\t\t\t\t\t}\n+\t\t\t\t\tfor (const field of listFields) {\n+\t\t\t\t\t\tconst collection = encoded.lists?.[field];\n+\t\t\t\t\t\tif (collection === undefined) continue;\n+\t\t\t\t\t\tif (typeof collection !== \"string\" || collection !== `atom-list:${atom.seq}:${field}`)\n+\t\t\t\t\t\t\tthrow Error(\"invalid stored atom list reference\");\n+\t\t\t\t\t\tconst list =\n+\t\t\t\t\t\t\tencoded.listFormat === 2\n+\t\t\t\t\t\t\t\t? readonlyPagedArray(storage, collection)\n+\t\t\t\t\t\t\t\t: readonlyStoredArray(storage, collection);\n+\t\t\t\t\t\tObject.defineProperty(result, field, {\n+\t\t\t\t\t\t\tvalue: list,\n+\t\t\t\t\t\t\tenumerable: true,\n+\t\t\t\t\t\t});\n+\t\t\t\t\t}\n+\t\t\t\t\treturn streamed(Object.freeze(result));\n+\t\t\t\t},\n+\t\t\t\t(input, key) => {\n+\t\t\t\t\tconst atom = { ...input };\n+\t\t\t\t\tconst lists: Partial<Record<(typeof listFields)[number], string>> = {};\n+\t\t\t\t\tfor (const field of listFields) {\n+\t\t\t\t\t\tconst values = input[field];\n+\t\t\t\t\t\tif (!values || values.length <= 256) continue;\n+\t\t\t\t\t\t// 256 to a row from list format 2 on (abso Capacity); an atom stored before keeps a row per value.\n+\t\t\t\t\t\tconst collection = `atom-list:${input.seq}:${field}`;\n+\t\t\t\t\t\twritePagedArray(storage, collection, values);\n+\t\t\t\t\t\tlists[field] = collection;\n+\t\t\t\t\t\tObject.defineProperty(atom, field, { value: [], enumerable: true });\n+\t\t\t\t\t}\n+\t\t\t\t\tconst listCount = Object.keys(lists).length;\n+\t\t\t\t\tconst hasLists = listCount > 0;\n+\t\t\t\t\tlet insertionCharacters = 0;\n+\t\t\t\t\tif (\n+\t\t\t\t\t\tatom.inserts.length > 256 ||\n+\t\t\t\t\t\tatom.inserts.some((run) => run.lines.length > 256) ||\n+\t\t\t\t\t\tatom.inserts.some((run) => run.lines.some((line) => (insertionCharacters += line.length) > 65536))\n+\t\t\t\t\t) {\n+\t\t\t\t\t\tconst collection = `atom-inserts:${input.seq}`;\n+\t\t\t\t\t\tconst runs = storedArray<unknown>(storage, collection);\n+\t\t\t\t\t\tlet runIndex = 0;\n+\t\t\t\t\t\tlet lineIndex = 0;\n+\t\t\t\t\t\tfor (const run of atom.inserts) {\n+\t\t\t\t\t\t\tconst lineCollection = `${collection}:lines:${runIndex++}`;\n+\t\t\t\t\t\t\tconst lines = storedArray<unknown>(storage, lineCollection);\n+\t\t\t\t\t\t\tfor (const line of run.lines) {\n+\t\t\t\t\t\t\t\tconst text = JSON.stringify([key, lineIndex++]);\n+\t\t\t\t\t\t\t\tif (line.length > StoredText.chunkCharacters) {\n+\t\t\t\t\t\t\t\t\tatomText.write(text, line);\n+\t\t\t\t\t\t\t\t\tlines.push({ text });\n+\t\t\t\t\t\t\t\t} else lines.push(line);\n+\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t\truns.push({\n+\t\t\t\t\t\t\t\tfile: run.file,\n+\t\t\t\t\t\t\t\tparent: run.parent,\n+\t\t\t\t\t\t\t\tlines: lineCollection,\n+\t\t\t\t\t\t\t});\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\treturn {\n+\t\t\t\t\t\t\tinsertionFormat: 1,\n+\t\t\t\t\t\t\tinsertionRuns: collection,\n+\t\t\t\t\t\t\t...(hasLists ? { listFormat: 2, listCount, lists } : {}),\n+\t\t\t\t\t\t\tatom: { ...atom, inserts: [] },\n+\t\t\t\t\t\t};\n+\t\t\t\t\t}\n+\t\t\t\t\tif (!atom.inserts.some((run) => run.lines.some((line) => line.length > StoredText.chunkCharacters)))\n+\t\t\t\t\t\treturn hasLists ? { listFormat: 2, listCount, lists, atom } : atom;\n+\t\t\t\t\tlet index = 0;\n+\t\t\t\t\tconst inserts = atom.inserts.map((run) => ({\n+\t\t\t\t\t\t...run,\n+\t\t\t\t\t\tlines: run.lines.map((line) => {\n+\t\t\t\t\t\t\tconst text = JSON.stringify([key, index++]);\n+\t\t\t\t\t\t\tif (line.length <= StoredText.chunkCharacters) return line;\n+\t\t\t\t\t\t\tatomText.write(text, line);\n+\t\t\t\t\t\t\treturn { text };\n+\t\t\t\t\t\t}),\n+\t\t\t\t\t}));\n+\t\t\t\t\treturn {\n+\t\t\t\t\t\ttextFormat: 1,\n+\t\t\t\t\t\t...(hasLists ? { listFormat: 2, listCount, lists } : {}),\n+\t\t\t\t\t\tatom: { ...atom, inserts },\n+\t\t\t\t\t};\n+\t\t\t\t},\n+\t\t\t);\n+\t\t\tthis.#lamport = storedArray(storage, \"lamport\");\n+\t\t\tthis.#lamportPaged = storedNumbers(storage, \"lamport-pages\");\n+\t\t\tthis.#lineBase = storedArray(storage, \"line-base\");\n+\t\t\tthis.#paths = storedArray(storage, \"paths\");\n+\t\t\tthis.#movers = storedArray(storage, \"movers\");\n+\t\t\tthis.#atomFiles = storedArray(storage, \"atom-files\");\n+\t\t\tthis.#atomDeletes = storedArray(storage, \"atom-deletes\");\n+\t\t\tthis.#lineAtom = numbers(\"line-atom\");\n+\t\t\tthis.#lineFile = numbers(\"line-file\");\n+\t\t\tthis.#lineParent = numbers(\"line-parent\");\n+\t\t\tthis.#deleter = numbers(\"deleter\");\n+\t\t\tthis.#replacing = numbers(\"replacing\");\n+\t\t\tconst longText = atomText;\n+\t\t\tthis.#lineText = storedArray<string>(\n+\t\t\t\tstorage,\n+\t\t\t\t\"line-text\",\n+\t\t\t\t(value) => {\n+\t\t\t\t\tif (typeof value === \"string\") return value;\n+\t\t\t\t\tconst reference = value as unknown as {\n+\t\t\t\t\t\tformat: number;\n+\t\t\t\t\t\ttext: string;\n+\t\t\t\t\t};\n+\t\t\t\t\tif (reference?.format !== 1 || typeof reference.text !== \"string\") throw Error(\"invalid long line reference\");\n+\t\t\t\t\treturn longText.read(reference.text);\n+\t\t\t\t},\n+\t\t\t\t(value, key) => {\n+\t\t\t\t\tif (value.length <= StoredText.chunkCharacters) return value;\n+\t\t\t\t\tconst number = Number(key);\n+\t\t\t\t\tconst seq = this.#lineAtom.at(number);\n+\t\t\t\t\tconst text = JSON.stringify([String(seq), number - this.#lineBase[seq]!]);\n+\t\t\t\t\tconst header = storage.read(\"atom-text:long\", text) as { characters?: number } | undefined;\n+\t\t\t\t\tif (header?.characters !== value.length) throw Error(\"long line atom text is missing\");\n+\t\t\t\t\treturn { format: 1, text };\n+\t\t\t\t},\n+\t\t\t);\n+\t\t\tthis.#pathIndex = storedMap(storage, \"path-index\");\n+\t\t\tthis.#moreDeleterPages = storedLists<number>(storage, \"more-deleters\", (key) =>\n+\t\t\t\tJSON.stringify([\"number\", Number(key)]),\n+\t\t\t);\n+\t\t\tthis.#writersPages = storedLists<AtomId>(storage, \"writers\", (key) => key);\n+\t\t\tthis.#readersPages = storedLists<AtomId>(storage, \"readers\", (key) => key);\n+\t\t\tthis.#holdersPages = storedLists<AtomId>(storage, \"holders\", (key) => key);\n+\t\t\tthis.#dependentsPages = storedLists<AtomId>(storage, \"dependents\");\n+\t\t\tthis.#resolversPages = storedLists<AtomId>(storage, \"resolvers\");\n+\t\t\tthis.#togetherPages = storedLists<TogetherLink>(storage, \"together\");\n+\t\t\tthis.#reasonsInPages = storedLists<AtomId>(storage, \"reasons-in\");\n+\t\t\tthis.#fileAtomPages = storedLists<AtomId>(storage, \"file-atoms\");\n+\t\t\tthis.#runStartPages = storedLists<number>(storage, \"run-starts\", (key) =>\n+\t\t\t\tJSON.stringify([\"number\", Number(key)]),\n+\t\t\t);\n+\t\t\tthis.#relocationPages = storedLists<RelocationInfo>(storage, \"relocations\");\n+\t\t\tthis.#relocatedToPages = storedLists<RelocationInfo>(storage, \"relocated-to\");\n+\t\t\tthis.#relocatedToCodePages = storedLists<RelocationInfo>(storage, \"relocated-to-code\", (key) =>\n+\t\t\t\tJSON.stringify([\"number\", Number(key)]),\n+\t\t\t);\n+\t\t\tthis.#labels = storedMap(storage, \"labels\");\n+\t\t\tthis.#fileLines = storedLists<PackedLine>(storage, \"file-lines\");\n+\t\t\tthis.#fileTexts = storedLists<string | null>(storage, \"file-texts\");\n+\t\t\tthis.#fileDeletes = storedLists<PackedDelete>(storage, \"file-deletes\");\n+\t\t\tthis.#fileAttrs = storedLists<PackedAttr>(storage, \"file-attrs\");\n+\t\t\tthis.#fileCrossings = storedLists<PackedCrossing>(storage, \"file-crossings\");\n+\t\t\tthis.#packFiles = options.packFiles ?? true;\n+\t\t}\n \t}\n \n+\t// Each file's line history packed, in pages (abso Capacity) ---------------------------------------------------\n+\t// For each file, by its path index: every line written in it ([n, parent code, writer seq, k, replaces]) and its\n+\t// text, every delete of one of those lines ([n, deleter seq]), every attribute set on it ([seq, name, value]), and\n+\t// every run written in another file under one of its lines ([parent n, the run's file]): a line follows its parent,\n+\t// so a run written while its parent was moved elsewhere lays out wherever the parent is.\n+\t// Appended as atoms are added, so a view lays a file out from a few pages instead of a row read per line. Kept from\n+\t// a fresh adoption on; a graph adopted before has none, and views lay out as before.\n+\n+\t#fileLines: ReturnType<typeof storedLists<PackedLine>> | undefined;\n+\t#fileTexts: ReturnType<typeof storedLists<string | null>> | undefined;\n+\t#fileDeletes: ReturnType<typeof storedLists<PackedDelete>> | undefined;\n+\t#fileAttrs: ReturnType<typeof storedLists<PackedAttr>> | undefined;\n+\t#fileCrossings: ReturnType<typeof storedLists<PackedCrossing>> | undefined;\n+\t/** Whether a new stored graph starts packing (GraphOptions.packFiles). */\n+\t#packFiles = true;\n+\t/**\n+\t * How this graph's files are packed, read once when first asked so opening reads nothing: 0 not at all, 1 lines,\n+\t * deletes and attributes, 2 the runs written across files as well.\n+\t */\n+\t#formatKnown: number | undefined;\n+\tget #format(): number {\n+\t\tif (this.#formatKnown === undefined) {\n+\t\t\tconst format = this.#storage?.read(\"file-lines:meta\", \"format\");\n+\t\t\tthis.#formatKnown = format === 1 || format === 2 ? format : 0;\n+\t\t}\n+\t\treturn this.#formatKnown;\n+\t}\n+\tget #packed(): boolean {\n+\t\treturn this.#format >= 1;\n+\t}\n+\tget #crossings(): boolean {\n+\t\treturn this.#format >= 2;\n+\t}\n+\n+\t/** Whether this graph keeps each file's line history packed. */\n+\tget packedFiles(): boolean {\n+\t\treturn this.#packed;\n+\t}\n+\t/**\n+\t * Whether a file can be laid out from packed history alone: it also keeps the runs written across files. A graph\n+\t * packed before those were kept lays files out line by line.\n+\t */\n+\tget packedLayout(): boolean {\n+\t\treturn this.#crossings;\n+\t}\n+\t/** A path's index, or undefined when nothing was ever written or set in it. */\n+\tpathIndexOf(path: string): number | undefined {\n+\t\treturn this.#pathIndex.get(path);\n+\t}\n+\t/** The index of the path line n was written in. */\n+\twrittenInIndex(n: number): number {\n+\t\treturn this.#lineFile.at(n);\n+\t}\n+\t*packedLines(file: number): IterableIterator<PackedLine> {\n+\t\tyield* this.#fileLines!.values(String(file));\n+\t}\n+\t*packedTexts(file: number): IterableIterator<string | null> {\n+\t\tyield* this.#fileTexts!.values(String(file));\n+\t}\n+\t/**\n+\t * The texts at positions [page * 256, (page + 1) * 256) of packedTexts(file) (abso Capacity): a layout reads only the\n+\t * pages holding a line it shows.\n+\t */\n+\tpackedTextPage(file: number, page: number): readonly (string | null)[] {\n+\t\treturn this.#fileTexts!.pageAt(String(file), page);\n+\t}\n+\t*packedDeletes(file: number): IterableIterator<PackedDelete> {\n+\t\tyield* this.#fileDeletes!.values(String(file));\n+\t}\n+\t*packedAttrs(file: number): IterableIterator<PackedAttr> {\n+\t\tyield* this.#fileAttrs!.values(String(file));\n+\t}\n+\t*packedCrossings(file: number): IterableIterator<PackedCrossing> {\n+\t\tyield* this.#fileCrossings!.values(String(file));\n+\t}\n+\n+\t/** Decoded file histories by path index, most recently used last, under PACKED_HISTORY_BUDGET bytes. */\n+\treadonly #histories = new Map<number, { counts: string; history: PackedHistory; bytes: number }>();\n+\t#historyBytes = 0;\n+\n+\t/**\n+\t * A file's line, delete and crossing history, decoded once and kept while it fits (abso Capacity). Kept under its\n+\t * three lists' lengths: the lists only grow, and add() lets every kept history go, so a kept one is always whole.\n+\t */\n+\tpackedHistory(file: number): PackedHistory {\n+\t\tconst key = String(file);\n+\t\tconst counts = `${this.#fileLines!.length(key)} ${this.#fileDeletes!.length(key)} ${this.#fileCrossings!.length(key)}`;\n+\t\tconst kept = this.#histories.get(file);\n+\t\tif (kept) {\n+\t\t\tthis.#histories.delete(file);\n+\t\t\tif (kept.counts === counts) {\n+\t\t\t\tthis.#histories.set(file, kept);\n+\t\t\t\treturn kept.history;\n+\t\t\t}\n+\t\t\tthis.#historyBytes -= kept.bytes;\n+\t\t}\n+\t\tconst history: PackedHistory = {\n+\t\t\tlines: packNumbers(this.#fileLines!.values(key)),\n+\t\t\tdeletes: packNumbers(this.#fileDeletes!.values(key)),\n+\t\t\tcrossings: packNumbers(this.#fileCrossings!.values(key)),\n+\t\t};\n+\t\tconst bytes =\n+\t\t\t(history.lines as Int32Array).byteLength +\n+\t\t\t(history.deletes as Int32Array).byteLength +\n+\t\t\t(history.crossings as Int32Array).byteLength +\n+\t\t\t200;\n+\t\tif (bytes <= PACKED_HISTORY_BUDGET) {\n+\t\t\tthis.#histories.set(file, { counts, history, bytes });\n+\t\t\tthis.#historyBytes += bytes;\n+\t\t\tfor (const [old, entry] of this.#histories) {\n+\t\t\t\tif (this.#historyBytes <= PACKED_HISTORY_BUDGET) break;\n+\t\t\t\tthis.#histories.delete(old);\n+\t\t\t\tthis.#historyBytes -= entry.bytes;\n+\t\t\t}\n+\t\t}\n+\t\treturn history;\n+\t}\n+\n+\t/** Bytes of decoded file histories kept (packedHistory). */\n+\tget historyBytes(): number {\n+\t\treturn this.#historyBytes;\n+\t}\n+\n \t/** Where an atom's key and delete lists are when the graph doesn't keep them (#46): the stored atom. */\n \t#lists: ((seq: number) => AtomLists) | undefined;\n \t/** Recently read atoms' lists, most recent last, up to LIST_CACHE atoms. */\n@@ -352,30 +892,54 @@\n \t\treturn this.#textOf(seq)[n - this.#lineBase[seq]!]!;\n \t}\n \t#paths: string[] = [];\n-\t#pathIndex = new Map<string, number>();\n+\t#pathIndex: StateMap<string, number> = new Map();\n \t/** The first atom that deletes each line (its seq), or -1; a line deleted by more than one has the rest in #moreDeleters. */\n-\t#deleter = new Ints();\n-\t#moreDeleters = new Map<number, number[]>();\n-\t#writers = new Map<Key | number, AtomId | AtomId[]>();\n-\t#readers = new Map<Key | number, AtomId | AtomId[]>();\n-\t#holders = new Map<Key | number, AtomId | AtomId[]>();\n-\t#dependents = new Map<AtomId, AtomId | AtomId[]>();\n-\t#resolvers = new Map<AtomId, AtomId | AtomId[]>();\n-\t#together = new Map<AtomId, TogetherLink[]>();\n-\t#fileAtoms = new Map<string, AtomId[]>();\n+\t#deleter: NumberIndex = new Ints();\n+\t#moreDeleters: StateMap<number, number[]> = new Map();\n+\t#moreDeleterPages: ReturnType<typeof storedLists<number>> | undefined;\n+\t#writers: StateMap<Key | number, AtomId | AtomId[]> = new Map();\n+\t#writersPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n+\t#readers: StateMap<Key | number, AtomId | AtomId[]> = new Map();\n+\t#readersPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n+\t#holders: StateMap<Key | number, AtomId | AtomId[]> = new Map();\n+\t#holdersPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n+\t#dependents: StateMap<AtomId, AtomId | AtomId[]> = new Map();\n+\t#dependentsPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n+\t#resolvers: StateMap<AtomId, AtomId | AtomId[]> = new Map();\n+\t#resolversPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n+\t#together: StateMap<AtomId, TogetherLink[]> = new Map();\n+\t#togetherPages: ReturnType<typeof storedLists<TogetherLink>> | undefined;\n+\t/** The atoms whose reasons point at each atom, in seq order, once each (abso Capacity). */\n+\t#reasonsIn = new Map<AtomId, AtomId[]>();\n+\t#reasonsInPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n+\t/** Whether a stored graph keeps reasons-in: from a fresh graph on, worked out when first needed. */\n+\t#reasonsInKnown: boolean | undefined;\n+\tget #reasonsInKept(): boolean {\n+\t\tif (!this.#storage) return true;\n+\t\tthis.#reasonsInKnown ??= this.#storage.read(\"reasons-in:meta\", \"kept\") === 1;\n+\t\treturn this.#reasonsInKnown;\n+\t}\n+\t#fileAtoms: StateMap<string, AtomId[]> = new Map();\n+\t#fileAtomPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n \t/** First lines of runs (their n), by the node they were written after: a line's n, or -1 - a path's index. */\n-\t#runStarts = new Map<number, number | number[]>();\n+\t#runStarts: StateMap<number, number | number[]> = new Map();\n+\t#runStartPages: ReturnType<typeof storedLists<number>> | undefined;\n \t/** 1 for the first line of a run whose atom deleted the line it hangs off: the run replaces it. */\n-\t#replacing = new Ints(true);\n-\t#relocations = new Map<LineId, RelocationInfo[]>();\n-\t#relocatedTo = new Map<NodeId, RelocationInfo[]>();\n+\t#replacing: NumberIndex = new Ints(true);\n+\t#relocations: StateMap<LineId, RelocationInfo[]> = new Map();\n+\t#relocationPages: ReturnType<typeof storedLists<RelocationInfo>> | undefined;\n+\t#relocatedTo: StateMap<NodeId, RelocationInfo[]> = new Map();\n+\t#relocatedToPages: ReturnType<typeof storedLists<RelocationInfo>> | undefined;\n \t/** The same relocations by node code (a line's n, or -1 - a path's index), for views laid out by number. */\n-\t#relocatedToCode = new Map<number, RelocationInfo[]>();\n+\t#relocatedToCode: StateMap<number, RelocationInfo[]> = new Map();\n+\t#relocatedToCodePages: ReturnType<typeof storedLists<RelocationInfo>> | undefined;\n \t#movers: AtomId[] = [];\n+\t/** A stored graph's movers, read once (abso Capacity): every view walks them, a row each. */\n+\t#moverList: AtomId[] | undefined;\n \t#atomFiles: (readonly string[])[] = [];\n \t/** Each atom's deleted lines by n, packed (#46), or undefined when it deletes none. */\n-\t#atomDeletes: (Int32Array | undefined)[] = [];\n-\t#labels = new Map<string, Label>();\n+\t#atomDeletes: (readonly number[] | Int32Array | undefined)[] = [];\n+\t#labels: StateMap<string, Label> = new Map();\n \t/** Each author's name kept once (#46). */\n \t#authors = new Map<string, string>();\n \n@@ -384,6 +948,16 @@\n \t\treturn this.#atoms.length;\n \t}\n \n+\t/**\n+\t * How many atoms this graph object has accepted since it was made (abso Capacity): in memory, so a cache over the\n+\t * graph can tell nothing was added without reading storage. A rolled-back add still counts, which only makes such a\n+\t * cache look again.\n+\t */\n+\tget accepted(): number {\n+\t\treturn this.#accepted;\n+\t}\n+\t#accepted = 0;\n+\n \t/** The id the next accepted atom must have. */\n \tnextId(): AtomId {\n \t\treturn atomId(this.#atoms.length);\n@@ -408,8 +982,8 @@\n \n \t/** lamport(a) = 1 + max lamport of its deps; 0 for an atom with no deps (such as a0). */\n \tlamport(id: AtomId): number {\n-\t\tthis.atom(id);\n-\t\treturn this.#lamport[this.#seq(id)]!;\n+\t\tif (!this.has(id)) throw new EngineError(\"unknown-atom\", `no atom ${id}`);\n+\t\treturn this.#lamportAt(this.#seq(id));\n \t}\n \n \t/** Compare by priority (lamport, then seq). Negative when a comes first (is lower). */\n@@ -423,9 +997,9 @@\n \t\tconst seq = this.#lineAtom.at(n);\n \t\treturn {\n \t\t\tid,\n-\t\t\tatom: this.#atoms[seq]!.id,\n+\t\t\tatom: this.idOfSeq(seq),\n \t\t\tk: n - this.#lineBase[seq]!,\n-\t\t\tfile: this.#paths[this.#lineFile.at(n)]!,\n+\t\t\tfile: this.#pathName(this.#lineFile.at(n)),\n \t\t\tparent: this.#nodeName(this.#lineParent.at(n)),\n \t\t\ttext: this.#text(n),\n \t\t};\n@@ -440,13 +1014,13 @@\n \t/** The atom that wrote a line, or undefined: line(id).atom without making the record. */\n \tlineAtom(id: LineId): AtomId | undefined {\n \t\tconst n = this.#lineN(id);\n-\t\treturn n < 0 ? undefined : this.#atoms[this.#lineAtom.at(n)]!.id;\n+\t\treturn n < 0 ? undefined : this.idOfSeq(this.#lineAtom.at(n));\n \t}\n \n \t/** The file a line was written in, or undefined: line(id).file without making the record. */\n \tlineFile(id: LineId): string | undefined {\n \t\tconst n = this.#lineN(id);\n-\t\treturn n < 0 ? undefined : this.#paths[this.#lineFile.at(n)];\n+\t\treturn n < 0 ? undefined : this.#pathName(this.#lineFile.at(n));\n \t}\n \n \t/** The node a line was written after, or undefined: line(id).parent without making the record. */\n@@ -471,6 +1045,15 @@\n \n \t/** The lines an atom deletes, from the graph's own packed copy (#46): never a read of the log. */\n \tdeletedLines(id: AtomId): readonly LineId[] {\n+\t\tconst seq = this.#seq(id);\n+\t\tconst count = this.#storage?.read(\"atom-delete-counts\", String(seq));\n+\t\tif (count !== undefined) {\n+\t\t\tconst out: LineId[] = [];\n+\t\t\tfor (const n of storedLists<number>(this.#storage!, \"atom-deletes\").values(String(seq)))\n+\t\t\t\tout.push(this.#lineName(n));\n+\t\t\tif (out.length !== count) throw Error(\"incomplete atom deletion index\");\n+\t\t\treturn out;\n+\t\t}\n \t\tconst ns = this.#atomDeletes[this.#seq(id)];\n \t\tif (!ns) return EMPTY;\n \t\tconst out: LineId[] = new Array(ns.length);\n@@ -478,15 +1061,50 @@\n \t\treturn out;\n \t}\n \n+\t/** The numbers of the lines an atom deletes, from the graph's packed copy: no lookup per line id. */\n+\t*deletedNumbers(id: AtomId): IterableIterator<number> {\n+\t\tconst seq = this.#seq(id);\n+\t\tif (this.#storage?.read(\"atom-delete-counts\", String(seq)) !== undefined) {\n+\t\t\tyield* storedLists<number>(this.#storage!, \"atom-deletes\").values(String(seq));\n+\t\t\treturn;\n+\t\t}\n+\t\tyield* this.#atomDeletes[seq] ?? EMPTY_NUMBERS;\n+\t}\n+\n \t/** How many lines an atom deletes, without reading its lists. */\n \tdeleteCount(id: AtomId): number {\n-\t\treturn this.#atomDeletes[this.#seq(id)]?.length ?? 0;\n+\t\tconst seq = this.#seq(id);\n+\t\tconst count = this.#storage?.read(\"atom-delete-counts\", String(seq));\n+\t\tif (count !== undefined) {\n+\t\t\tif (!Number.isSafeInteger(count) || (count as number) < 0) throw Error(\"invalid atom deletion count\");\n+\t\t\treturn count as number;\n+\t\t}\n+\t\treturn this.#atomDeletes[seq]?.length ?? 0;\n \t}\n \n \ttextOf(n: number): string {\n \t\treturn this.#text(n);\n \t}\n \n+\t/** Historical text in bounded chunks, without decoding a whole stored line. */\n+\t*textChunks(n: number): IterableIterator<string> {\n+\t\tif (!this.#storage) {\n+\t\t\tconst text = this.#text(n);\n+\t\t\tfor (let offset = 0; offset < text.length; offset += StoredText.chunkCharacters)\n+\t\t\t\tyield text.slice(offset, offset + StoredText.chunkCharacters);\n+\t\t\treturn;\n+\t\t}\n+\t\tif (!Number.isSafeInteger(n) || n < 0 || n >= this.#lineText!.length) throw Error(\"invalid line number\");\n+\t\tconst value = this.#storage.read(\"line-text\", String(n));\n+\t\tif (typeof value === \"string\") {\n+\t\t\tyield value;\n+\t\t\treturn;\n+\t\t}\n+\t\tconst reference = value as { format?: number; text?: string } | undefined;\n+\t\tif (reference?.format !== 1 || typeof reference.text !== \"string\") throw Error(\"invalid long line reference\");\n+\t\tyield* new StoredText(this.#storage, \"atom-text:long\").chunks(reference.text);\n+\t}\n+\n \t/** The seq of the atom that wrote line n. */\n \twriterSeqOf(n: number): number {\n \t\treturn this.#lineAtom.at(n);\n@@ -499,16 +1117,22 @@\n \n \t/** The atom id with this seq, as the graph keeps it. */\n \tidOfSeq(seq: number): AtomId {\n-\t\treturn this.#atoms[seq]!.id;\n+\t\tif (!Number.isSafeInteger(seq) || seq < 0 || seq >= this.#atoms.length)\n+\t\t\tthrow new EngineError(\"unknown-atom\", `no atom at sequence ${seq}`);\n+\t\treturn atomId(seq);\n \t}\n \n+\t#lamportAt(seq: number): number {\n+\t\treturn this.#lamportPages ? this.#lamportPages.at(seq) : this.#lamport[seq]!;\n+\t}\n+\n \tlamportOfSeq(seq: number): number {\n-\t\treturn this.#lamport[seq]!;\n+\t\treturn this.#lamportAt(seq);\n \t}\n \n \t/** The file line n was written in. */\n \twrittenIn(n: number): string {\n-\t\treturn this.#paths[this.#lineFile.at(n)]!;\n+\t\treturn this.#pathName(this.#lineFile.at(n));\n \t}\n \n \t/** The code of the node line n was written after. */\n@@ -533,36 +1157,112 @@\n \t}\n \n \t/** The lines (their n) written right after a node, as childrenOf, into `out`. */\n+\n \tchildrenN(code: number, out: number[]): void {\n+\t\tfor (const n of this.eachChildN(code)) out.push(n);\n+\t}\n+\t*eachChildN(code: number): IterableIterator<number> {\n \t\tif (\n \t\t\tcode >= 0 &&\n \t\t\tcode + 1 < this.#lineTotal &&\n \t\t\tthis.#lineAtom.at(code + 1) === this.#lineAtom.at(code) &&\n \t\t\tthis.#lineParent.at(code + 1) === code\n \t\t)\n-\t\t\tout.push(code + 1);\n-\t\tconst starts = this.#runStarts.get(code);\n-\t\tif (starts === undefined) return;\n-\t\tif (Array.isArray(starts)) out.push(...starts);\n-\t\telse out.push(starts);\n+\t\t\tyield code + 1;\n+\t\tif (this.#runStartPages) {\n+\t\t\t// The paged child counts say a line has no other children without a row read per line (abso Capacity).\n+\t\t\tif (code >= 0 && this.#childCounts && this.#childCounts.at(code, this.#lineTotal) === 0) return;\n+\t\t\tyield* this.#runStartPages.values(String(code));\n+\t\t} else yield* listOf(this.#runStarts.get(code));\n \t}\n \n+\tget hasOrderedChildren(): boolean {\n+\t\treturn this.#storage !== undefined;\n+\t}\n+\t/** Synchronous derived work against one graph identity. Scratch never commits. */\n+\twithProjectionScratch<T>(operation: (scratch: GraphStateStorage) => T): T {\n+\t\tif (!this.#storage) throw new Error(\"projection scratch requires persistent graph storage\");\n+\t\tconst size = this.size;\n+\t\tconst lines = this.lineCount;\n+\t\treturn withProjectionScratch(\n+\t\t\tthis.#storage,\n+\t\t\t() => {\n+\t\t\t\tif (this.size !== size || this.lineCount !== lines) throw new Error(\"projection graph identity changed\");\n+\t\t\t},\n+\t\t\toperation,\n+\t\t);\n+\t}\n+\t#childPriority(n: number): string {\n+\t\tconst seq = this.writerSeqOf(n);\n+\t\treturn orderedChildKey({\n+\t\t\tn,\n+\t\t\treplaces: this.replacesN(n) ? 1 : 0,\n+\t\t\tlamport: this.lamportOfSeq(seq),\n+\t\t\tseq,\n+\t\t\tk: this.kOf(n),\n+\t\t});\n+\t}\n+\t/** Persistent layout order with a strict successor cursor; moves are separate. */\n+\t*orderedChildrenN(code: number, after?: number): IterableIterator<number> {\n+\t\tif (!this.#storage) throw new Error(\"ordered children require indexed storage\");\n+\t\tconst index = new OrderedIndex(this.#storage, \"ordered-children\", String(code));\n+\t\tif (this.#storage.read(\"ordered-children\", \"format\") !== 2)\n+\t\t\tthrow new Error(\"ordered children require fresh adoption\");\n+\t\tconst count = code >= 0 ? this.#childCounts!.at(code, this.#lineTotal) : index.size;\n+\t\tif ((code < 0 || count > 0) && (count !== index.size || count !== this.#runStartPages!.length(String(code))))\n+\t\t\tthrow new Error(\"ordered child index count mismatch\");\n+\t\tlet implicit: number | undefined;\n+\t\tif (\n+\t\t\tcode >= 0 &&\n+\t\t\tcode + 1 < this.#lineTotal &&\n+\t\t\tthis.#lineAtom.at(code + 1) === this.#lineAtom.at(code) &&\n+\t\t\tthis.#lineParent.at(code + 1) === code\n+\t\t)\n+\t\t\timplicit = code + 1;\n+\t\t// Most historical run lines have no explicit child. With zero or one\n+\t\t// child, traversal needs no priority decoding or radix lookup. Keep the\n+\t\t// format/count checks above even on this path.\n+\t\tif (count === 0 && (after === undefined || after === implicit)) {\n+\t\t\tif (implicit !== undefined && after !== implicit) yield implicit;\n+\t\t\treturn;\n+\t\t}\n+\t\tconst cursor = after === undefined ? undefined : this.#childPriority(after);\n+\t\tif (implicit !== undefined && cursor !== undefined && this.#childPriority(implicit) <= cursor) implicit = undefined;\n+\t\tfor (const n of index.values(cursor)) {\n+\t\t\tif (implicit !== undefined && this.#childPriority(implicit) < this.#childPriority(n)) {\n+\t\t\t\tyield implicit;\n+\t\t\t\timplicit = undefined;\n+\t\t\t}\n+\t\t\tyield n;\n+\t\t}\n+\t\tif (implicit !== undefined) yield implicit;\n+\t}\n+\n \treplacesN(n: number): boolean {\n \t\treturn this.#replacing.at(n) === 1;\n \t}\n \n \t/** The seqs of every atom that deletes line n (none: an empty list, shared). */\n \tdeleterSeqsOf(n: number): readonly number[] {\n+\t\treturn [...this.eachDeleterSeqOf(n)];\n+\t}\n+\t*eachDeleterSeqOf(n: number): IterableIterator<number> {\n \t\tconst first = this.#deleter.at(n);\n-\t\tif (first < 0) return EMPTY;\n-\t\tconst more = this.#moreDeleters.get(n);\n-\t\treturn more ? [first, ...more] : [first];\n+\t\tif (first < 0) return;\n+\t\tyield first;\n+\t\tif (this.#moreDeleterPages) yield* this.#moreDeleterPages.values(String(n));\n+\t\telse yield* this.#moreDeleters.get(n) ?? EMPTY;\n \t}\n \n \t/** Every relocation that puts a line right after the node with this code. */\n \trelocatedToCode(code: number): readonly RelocationInfo[] {\n+\t\tif (this.#relocatedToCodePages) return [...this.eachRelocatedToCode(code)];\n \t\treturn this.#relocatedToCode.get(code) ?? EMPTY;\n \t}\n+\t*eachRelocatedToCode(code: number): IterableIterator<RelocationInfo> {\n+\t\tif (this.#relocatedToCodePages) yield* this.#relocatedToCodePages.values(String(code));\n+\t\telse yield* this.#relocatedToCode.get(code) ?? EMPTY;\n+\t}\n \n \t/** How many lines every atom together has written. */\n \tget lineCount(): number {\n@@ -581,7 +1281,7 @@\n \t/** A line's id from its n. */\n \t#lineName(n: number): LineId {\n \t\tconst seq = this.#lineAtom.at(n);\n-\t\treturn `${this.#atoms[seq]!.id}.${n - this.#lineBase[seq]!}`;\n+\t\treturn `${this.idOfSeq(seq)}.${n - this.#lineBase[seq]!}`;\n \t}\n \n \t/** A node's code: a line's n, or -1 - a path's index for a start node; undefined when unknown. */\n@@ -595,9 +1295,30 @@\n \t}\n \n \t#nodeName(code: number): NodeId {\n-\t\treturn code >= 0 ? this.#lineName(code) : startNode(this.#paths[-1 - code]!);\n+\t\treturn code >= 0 ? this.#lineName(code) : startNode(this.#pathName(-1 - code));\n \t}\n \n+\t/**\n+\t * A path's name by its index, kept in memory once read (abso Capacity): finding a deleted line's file names the file\n+\t * it reaches, and a stored graph read the path list each time. Cleared when the graph accepts an atom, so a name a\n+\t * rolled-back add made never stays.\n+\t */\n+\t#pathName(index: number): string {\n+\t\tif (this.#pathNamesAt !== this.#accepted) {\n+\t\t\tthis.#pathNames.clear();\n+\t\t\tthis.#pathNamesAt = this.#accepted;\n+\t\t}\n+\t\tlet name = this.#pathNames.get(index);\n+\t\tif (name === undefined) {\n+\t\t\tname = this.#paths[index]!;\n+\t\t\tif (this.#pathNames.size >= PATH_NAMES) this.#pathNames.clear();\n+\t\t\tthis.#pathNames.set(index, name);\n+\t\t}\n+\t\treturn name;\n+\t}\n+\treadonly #pathNames = new Map<number, string>();\n+\t#pathNamesAt = -1;\n+\n \t#pathOf(file: string): number {\n \t\tlet p = this.#pathIndex.get(file);\n \t\tif (p === undefined) {\n@@ -609,71 +1330,84 @@\n \n \t/** The line ids an atom inserted, in k order. */\n \tlinesOf(id: AtomId): LineId[] {\n-\t\tconst atom = this.atom(id);\n-\t\tconst out: LineId[] = [];\n-\t\tconst seq = atom.seq;\n+\t\treturn [...this.eachInsertedLine(id)];\n+\t}\n+\t/** Inserted identities without decoding or allocating the atom's text. */\n+\t*eachInsertedLine(id: AtomId): IterableIterator<LineId> {\n+\t\tconst seq = this.atom(id).seq;\n \t\tconst count = (seq + 1 < this.#lineBase.length ? this.#lineBase[seq + 1]! : this.#lineTotal) - this.#lineBase[seq]!;\n-\t\tfor (let k = 0; k < count; k++) out.push(lineId(id, k));\n-\t\treturn out;\n+\t\tfor (let k = 0; k < count; k++) yield lineId(id, k);\n \t}\n \n \t/** Every atom that deletes this line (across the whole graph). */\n \tdeletersOf(line: LineId): readonly AtomId[] {\n \t\tconst n = this.#lineN(line);\n \t\tif (n < 0) return EMPTY;\n-\t\tconst first = this.#deleter.at(n);\n-\t\tif (first < 0) return EMPTY;\n-\t\tconst more = this.#moreDeleters.get(n);\n-\t\tconst out = [this.#atoms[first]!.id];\n-\t\tif (more) for (const seq of more) out.push(this.#atoms[seq]!.id);\n-\t\treturn out;\n+\t\treturn [...this.eachDeleterSeqOf(n)].map((seq) => this.idOfSeq(seq));\n \t}\n \n \twritersOf(key: Key): readonly AtomId[] {\n-\t\treturn listOf(this.#writers.get(this.#code(key)));\n+\t\treturn [...this.eachWriterOf(key)];\n \t}\n+\t*eachWriterOf(key: Key): IterableIterator<AtomId> {\n+\t\tconst code = this.#code(key);\n+\t\tif (this.#writersPages) yield* this.#writersPages.values(JSON.stringify([typeof code, code]));\n+\t\telse yield* listOf(this.#writers.get(code));\n+\t}\n \n \t/** Atoms whose implicit reads include the key. */\n \treadersOf(key: Key): readonly AtomId[] {\n-\t\treturn listOf(this.#readers.get(this.#code(key)));\n+\t\treturn [...this.eachReaderOf(key)];\n \t}\n+\t*eachReaderOf(key: Key): IterableIterator<AtomId> {\n+\t\tconst code = this.#code(key);\n+\t\tif (this.#readersPages) yield* this.#readersPages.values(JSON.stringify([typeof code, code]));\n+\t\telse yield* listOf(this.#readers.get(code));\n+\t}\n \n \t/** Atoms whose explicit holds include the key. */\n \tholdersOf(key: Key): readonly AtomId[] {\n-\t\treturn listOf(this.#holders.get(this.#code(key)));\n+\t\treturn [...this.eachHolderOf(key)];\n \t}\n+\t*eachHolderOf(key: Key): IterableIterator<AtomId> {\n+\t\tconst code = this.#code(key);\n+\t\tif (this.#holdersPages) yield* this.#holdersPages.values(JSON.stringify([typeof code, code]));\n+\t\telse yield* listOf(this.#holders.get(code));\n+\t}\n \n \t/** Every atom that inserts or deletes a line of the file, in seq order. */\n \tatomsIn(file: string): readonly AtomId[] {\n+\t\tif (this.#fileAtomPages) return [...this.#fileAtomPages.values(file)];\n \t\treturn this.#fileAtoms.get(file) ?? EMPTY;\n \t}\n+\t*eachAtomIn(file: string): IterableIterator<AtomId> {\n+\t\tif (this.#fileAtomPages) yield* this.#fileAtomPages.values(file);\n+\t\telse yield* this.#fileAtoms.get(file) ?? EMPTY;\n+\t}\n+\thasAtomsIn(file: string): boolean {\n+\t\treturn this.#fileAtomPages ? this.#fileAtomPages.length(file) > 0 : this.#fileAtoms.has(file);\n+\t}\n \n+\t/** Unique historical file paths, streamed without collecting their names. */\n+\t*knownFiles(): IterableIterator<string> {\n+\t\tyield* this.#fileAtomPages ? this.#fileAtomPages.keys() : this.#fileAtoms.keys();\n+\t}\n+\n \t/**\n \t * The files an atom inserts, deletes or moves lines in, or sets attributes\n \t * of, sorted. For lines, the file each was written in (or, for a move to a\n \t * start node, that file): a set's moves can have taken them elsewhere.\n \t */\n \tfilesOf(id: AtomId): readonly string[] {\n-\t\tthis.atom(id);\n+\t\tif (!this.has(id)) throw new EngineError(\"unknown-atom\", `no atom ${id}`);\n \t\treturn this.#atomFiles[this.#seq(id)]!;\n \t}\n \n \t/** Lines written right after a node (not counting moves), in seq order. */\n+\n \tchildrenOf(node: NodeId): LineId[] {\n-\t\tconst out: LineId[] = [];\n \t\tconst code = this.#nodeCode(node);\n-\t\tif (code === undefined) return out;\n-\t\t// The next line of the same run hangs off this one.\n-\t\tif (\n-\t\t\tcode >= 0 &&\n-\t\t\tcode + 1 < this.#lineTotal &&\n-\t\t\tthis.#lineAtom.at(code + 1) === this.#lineAtom.at(code) &&\n-\t\t\tthis.#lineParent.at(code + 1) === code\n-\t\t) {\n-\t\t\tout.push(this.#lineName(code + 1));\n-\t\t}\n-\t\tfor (const n of listOf(this.#runStarts.get(code))) out.push(this.#lineName(n));\n-\t\treturn out;\n+\t\treturn code === undefined ? [] : [...this.eachChildN(code)].map((n) => this.#lineName(n));\n \t}\n \n \t/** Whether a line starts a run whose atom deleted the line it hangs off. */\n@@ -684,33 +1418,67 @@\n \n \t/** Every relocation of a line, in seq order. */\n \trelocationsOf(line: LineId): readonly RelocationInfo[] {\n+\t\tif (this.#relocationPages) return [...this.eachRelocationOf(line)];\n \t\treturn this.#relocations.get(line) ?? EMPTY;\n \t}\n+\t*eachRelocationOf(line: LineId): IterableIterator<RelocationInfo> {\n+\t\tif (this.#relocationPages) yield* this.#relocationPages.values(line);\n+\t\telse yield* this.#relocations.get(line) ?? EMPTY;\n+\t}\n \n \t/** Every relocation that puts a line right after this node, in seq order. */\n \trelocatedTo(node: NodeId): readonly RelocationInfo[] {\n+\t\tif (this.#relocatedToPages) return [...this.#relocatedToPages.values(node)];\n \t\treturn this.#relocatedTo.get(node) ?? EMPTY;\n \t}\n \n \t/** Atoms that move lines, in seq order. */\n \tmovers(): readonly AtomId[] {\n-\t\treturn this.#movers;\n+\t\tif (!this.#storage) return this.#movers;\n+\t\t// Checked against the stored list's length and last mover, so a rolled-back add can't leave one behind.\n+\t\tconst length = this.#movers.length;\n+\t\tconst list = this.#moverList;\n+\t\tif (list && list.length === length && (length === 0 || list[length - 1] === this.#movers[length - 1])) return list;\n+\t\tthis.#moverList = [...this.#movers];\n+\t\treturn this.#moverList;\n \t}\n \n \t/** Atoms that list this one directly in their deps. */\n \tdependentsOf(id: AtomId): readonly AtomId[] {\n-\t\treturn listOf(this.#dependents.get(id));\n+\t\treturn [...this.eachDependentOf(id)];\n \t}\n+\t*eachDependentOf(id: AtomId): IterableIterator<AtomId> {\n+\t\tif (this.#dependentsPages) yield* this.#dependentsPages.values(id);\n+\t\telse yield* listOf(this.#dependents.get(id));\n+\t}\n \n \t/** Atoms whose `resolves` names this one. */\n \tresolversOf(id: AtomId): readonly AtomId[] {\n-\t\treturn listOf(this.#resolvers.get(id));\n+\t\treturn [...this.eachResolverOf(id)];\n \t}\n+\t*eachResolverOf(id: AtomId): IterableIterator<AtomId> {\n+\t\tif (this.#resolversPages) yield* this.#resolversPages.values(id);\n+\t\telse yield* listOf(this.#resolvers.get(id));\n+\t}\n \n+\t/**\n+\t * The atoms whose reasons point at this one, in seq order, once each; or undefined when a stored graph made before\n+\t * this index keeps none, and the caller looks at every atom (abso Capacity).\n+\t */\n+\treasonsTo(id: AtomId): readonly AtomId[] | undefined {\n+\t\tif (!this.#reasonsInKept) return undefined;\n+\t\tif (this.#reasonsInPages) return [...this.#reasonsInPages.values(id)];\n+\t\treturn this.#reasonsIn.get(id) ?? [];\n+\t}\n+\n \t/** `together` reasons touching this atom, in either direction. */\n \ttogetherLinks(id: AtomId): readonly TogetherLink[] {\n-\t\treturn this.#together.get(id) ?? EMPTY;\n+\t\treturn [...this.eachTogetherLink(id)];\n \t}\n+\t*eachTogetherLink(id: AtomId): IterableIterator<TogetherLink> {\n+\t\tif (this.#togetherPages) yield* this.#togetherPages.values(id);\n+\t\telse yield* this.#together.get(id) ?? EMPTY;\n+\t}\n \n \t/**\n \t * The atom plus everything it depends on, transitively. Computed on demand\n@@ -756,18 +1524,39 @@\n \t * the search never descends below the target's lamport.\n \t */\n \t#reaches(from: Iterable<AtomId>, target: AtomId): boolean {\n-\t\tconst floor = this.#lamport[this.#seq(target)]!;\n-\t\tconst seen = new Set<AtomId>();\n-\t\tconst stack = [...from];\n-\t\twhile (stack.length > 0) {\n-\t\t\tconst cur = stack.pop()!;\n-\t\t\tif (cur === target) return true;\n-\t\t\tif (seen.has(cur)) continue;\n-\t\t\tseen.add(cur);\n-\t\t\tif (this.#lamport[this.#seq(cur)]! <= floor) continue;\n-\t\t\tfor (const d of this.atom(cur).deps) if (!seen.has(d)) stack.push(d);\n+\t\treturn this.#reachable(from, new Set([target])).has(target);\n+\t}\n+\n+\t/**\n+\t * Which of `targets` are reachable along deps from any of `from` (themselves included), in one walk: it never\n+\t * descends below the lowest target's lamport, and stops once every target is found (abso 714, piece 4: record\n+\t * walked once per line writer).\n+\t * The walk's seen marks and stack are in memory, by atom number: one byte and four bytes an atom at most, so about\n+\t * 62 KB on abso's 12,454 atoms and 50 MB at 10 million, under a Worker's 128 MB. They were scratch rows in storage\n+\t * (abso-core 139, bounding memory with the graph), which cost a read and a write per atom visited: on abso's Oct 14\n+\t * tables, 41,000 of a 1470-shaped record's 77,767 statements.\n+\t */\n+\t#reachable(from: Iterable<AtomId>, targets: ReadonlySet<AtomId>): Set<AtomId> {\n+\t\tconst found = new Set<AtomId>();\n+\t\tlet floor = Number.POSITIVE_INFINITY;\n+\t\tfor (const target of targets) floor = Math.min(floor, this.#lamportAt(this.#seq(target)));\n+\t\tconst seen = new Uint8Array(this.#atoms.length);\n+\t\tconst stack = new Int32Array(this.#atoms.length);\n+\t\tlet length = 0;\n+\t\tconst visit = (id: AtomId): void => {\n+\t\t\tif (targets.has(id)) found.add(id);\n+\t\t\tconst seq = this.#seq(id);\n+\t\t\tif (seen[seq]) return;\n+\t\t\tseen[seq] = 1;\n+\t\t\tstack[length++] = seq;\n+\t\t};\n+\t\tfor (const id of from) visit(id);\n+\t\twhile (length > 0 && found.size < targets.size) {\n+\t\t\tconst seq = stack[--length]!;\n+\t\t\tif (this.#lamportAt(seq) <= floor) continue;\n+\t\t\tfor (const dependency of this.atom(atomId(seq)).deps) visit(dependency);\n \t\t}\n-\t\treturn false;\n+\t\treturn found;\n \t}\n \n \t/**\n@@ -776,6 +1565,27 @@\n \t * The atom is frozen. Adding to the graph does not add it to any set.\n \t */\n \tadd(atom: Atom): void {\n+\t\t// A new atom appends to its files' histories; a failed one may leave a kept history longer than the lists.\n+\t\tthis.#histories.clear();\n+\t\tthis.#historyBytes = 0;\n+\t\tif (this.#storage)\n+\t\t\tthis.#storage.transaction(() => {\n+\t\t\t\tthis.#add(atom);\n+\t\t\t\tconst result: unknown = this.#indexAcceptedAtom?.(atom, this.filesOf(atom.id), this.#storage!);\n+\t\t\t\tif (result && typeof result === \"object\" && \"then\" in result)\n+\t\t\t\t\tthrow Error(\"accepted atom indexing must be synchronous\");\n+\t\t\t});\n+\t\telse this.#add(atom);\n+\t}\n+\n+\t#validateAcceptedAtom(atom: Atom, scratch?: GraphStateStorage): void {\n+\t\tconst membership = <T extends string>(name: string): { has(key: T): boolean; add(key: T): unknown } => {\n+\t\t\tif (!scratch) return new Set<T>();\n+\t\t\treturn {\n+\t\t\t\thas: (key) => scratch.read(name, key) === true,\n+\t\t\t\tadd: (key) => scratch.write(name, key, true),\n+\t\t\t};\n+\t\t};\n \t\tvalidateShape(atom);\n \t\tconst seq = this.#atoms.length;\n \t\tconst bad = (why: string): never => {\n@@ -783,28 +1593,41 @@\n \t\t};\n \t\tif (atom.seq !== seq || atom.id !== atomId(seq)) bad(`expected id ${atomId(seq)} with seq ${seq}`);\n \n-\t\tconst deps = new Set<AtomId>();\n+\t\tconst deps = membership<AtomId>(\"deps\");\n \t\tfor (const d of atom.deps) {\n \t\t\tif (!this.has(d)) bad(`dependency ${d} is not in the graph`);\n \t\t\tif (deps.has(d)) bad(`dependency ${d} listed twice`);\n \t\t\tdeps.add(d);\n \t\t}\n-\t\tfor (const d of [...atom.needs, ...atom.resolves]) {\n-\t\t\tif (!deps.has(d)) bad(`${d} is in needs/resolves but not in deps`);\n-\t\t}\n+\t\tfor (const list of [atom.needs, atom.resolves])\n+\t\t\tfor (const d of list) {\n+\t\t\t\tif (!deps.has(d)) bad(`${d} is in needs/resolves but not in deps`);\n+\t\t\t}\n \t\tfor (const r of atom.reasons) if (!this.has(r.to)) bad(`reason points at unknown atom ${r.to}`);\n \n \t\t// Everything it touches must come from its closure. Derived deps name the\n-\t\t// writers directly, so this is usually one lookup per writer.\n-\t\tconst below = new Map<AtomId, boolean>();\n-\t\tconst inClosure = (writer: AtomId): boolean => {\n-\t\t\tlet hit = below.get(writer);\n-\t\t\tif (hit === undefined) {\n-\t\t\t\thit = deps.has(writer) || this.#reaches(deps, writer);\n-\t\t\t\tbelow.set(writer, hit);\n+\t\t// writers directly, so this is usually one lookup per writer. The writers\n+\t\t// that aren't deps are walked for together, once (abso 714, piece 4).\n+\t\tconst touched: LineId[] = [];\n+\t\tfor (const run of atom.inserts) if (!isStartNode(run.parent)) touched.push(run.parent);\n+\t\tfor (const m of atom.moves ?? []) {\n+\t\t\ttouched.push(m.line);\n+\t\t\tif (!isStartNode(m.parent)) touched.push(m.parent);\n+\t\t}\n+\t\ttouched.push(...atom.deletes);\n+\t\tfor (const list of [atom.writes, atom.reads, atom.holds])\n+\t\t\tfor (const key of list) {\n+\t\t\t\tconst parsed = parseKey(key);\n+\t\t\t\tif (parsed.kind === \"line\" || ((parsed.kind === \"gap\" || parsed.kind === \"pos\") && !isStartNode(parsed.node)))\n+\t\t\t\t\ttouched.push(parsed.node);\n \t\t\t}\n-\t\t\treturn hit;\n-\t\t};\n+\t\tconst beyond = new Set<AtomId>();\n+\t\tfor (const line of touched) {\n+\t\t\tconst writer = this.lineAtom(line);\n+\t\t\tif (writer !== undefined && !deps.has(writer)) beyond.add(writer);\n+\t\t}\n+\t\tconst reached = beyond.size > 0 ? this.#reachable(atom.deps, beyond) : beyond;\n+\t\tconst inClosure = (writer: AtomId): boolean => deps.has(writer) || reached.has(writer);\n \t\tconst checkLine = (line: LineId, what: string): void => {\n \t\t\tconst writer = this.lineAtom(line);\n \t\t\tif (writer === undefined) return bad(`${what} names unknown line ${line}`);\n@@ -819,105 +1642,248 @@\n \t\t\t\tcheckLine(run.parent, \"an insert\");\n \t\t\t}\n \t\t}\n-\t\tconst moved = new Set<LineId>();\n+\t\tconst writes = membership<Key>(\"writes\");\n+\t\tfor (const key of atom.writes) writes.add(key);\n+\t\tconst moved = membership<LineId>(\"moved\");\n \t\tfor (const m of atom.moves ?? []) {\n \t\t\tcheckLine(m.line, \"a move\");\n \t\t\tif (!isStartNode(m.parent)) checkLine(m.parent, \"a move\");\n \t\t\tif (m.line === m.parent) bad(`moves ${m.line} after itself`);\n \t\t\tif (moved.has(m.line)) bad(`moves ${m.line} twice`);\n \t\t\tmoved.add(m.line);\n-\t\t\tif (!atom.writes.includes(posKey(m.line)) || !atom.writes.includes(gapKey(m.parent))) {\n+\t\t\tif (!writes.has(posKey(m.line)) || !writes.has(gapKey(m.parent))) {\n \t\t\t\tbad(`moves ${m.line} without writing ${posKey(m.line)} and ${gapKey(m.parent)}`);\n \t\t\t}\n \t\t}\n-\t\tconst deleted = new Set<LineId>();\n+\t\tconst deleted = membership<LineId>(\"deleted\");\n \t\tfor (const line of atom.deletes) {\n \t\t\tcheckLine(line, \"a delete\");\n \t\t\tif (deleted.has(line)) bad(`deletes ${line} twice`);\n \t\t\tdeleted.add(line);\n \t\t}\n-\t\tconst writes = new Set(atom.writes);\n-\t\tfor (const line of deleted) if (!writes.has(lineKey(line))) bad(`deletes ${line} without writing ${lineKey(line)}`);\n-\t\tfor (const key of [...atom.writes, ...atom.reads, ...atom.holds]) {\n-\t\t\tconst parsed = parseKey(key);\n-\t\t\tif (parsed.kind === \"line\") checkLine(parsed.node, `key ${key}`);\n-\t\t\telse if ((parsed.kind === \"gap\" || parsed.kind === \"pos\") && !isStartNode(parsed.node))\n-\t\t\t\tcheckLine(parsed.node, `key ${key}`);\n+\t\tfor (const line of atom.deletes)\n+\t\t\tif (!writes.has(lineKey(line))) bad(`deletes ${line} without writing ${lineKey(line)}`);\n+\t\tfor (const list of [atom.writes, atom.reads, atom.holds])\n+\t\t\tfor (const key of list) {\n+\t\t\t\tconst parsed = parseKey(key);\n+\t\t\t\tif (parsed.kind === \"line\") checkLine(parsed.node, `key ${key}`);\n+\t\t\t\telse if ((parsed.kind === \"gap\" || parsed.kind === \"pos\") && !isStartNode(parsed.node))\n+\t\t\t\t\tcheckLine(parsed.node, `key ${key}`);\n+\t\t\t}\n+\t}\n+\n+\t#add(atom: Atom): void {\n+\t\tif (this.#storage && this.#storage.read(\"ordered-children\", \"format\") !== 2) {\n+\t\t\tif (this.#atoms.length !== 0) throw new Error(\"ordered children require fresh adoption\");\n+\t\t\tthis.#storage.write(\"ordered-children\", \"format\", 2);\n \t\t}\n+\t\tif (this.#storage && this.#atoms.length === 0 && this.#packFiles) {\n+\t\t\tthis.#storage.write(\"file-lines:meta\", \"format\", 2);\n+\t\t\tthis.#storage.write(\"reasons-in:meta\", \"kept\", 1);\n+\t\t\tthis.#reasonsInKnown = true;\n+\t\t\tthis.#formatKnown = 2;\n+\t\t}\n \n+\t\tif (this.#storage) this.withProjectionScratch((scratch) => this.#validateAcceptedAtom(atom, scratch));\n+\t\telse this.#validateAcceptedAtom(atom);\n+\t\tconst seq = this.#atoms.length;\n+\t\tconst deps = atom.deps;\n+\t\tconst deleted = this.#storage ? undefined : new Set(atom.deletes);\n+\t\tconst writes = this.#storage ? atom.writes : new Set(atom.writes);\n+\n \t\t// Accept.\n-\t\tconst frozen = freezeAtom(\n-\t\t\tatom,\n-\t\t\t(id) => this.#atoms[seqOf(id)]!.id,\n-\t\t\t(author) => {\n-\t\t\t\tlet a = this.#authors.get(author);\n-\t\t\t\tif (a === undefined) this.#authors.set(author, (a = author));\n-\t\t\t\treturn a;\n-\t\t\t},\n-\t\t\tthis.#texts ? this.#reader(seq) : undefined,\n-\t\t\tthis.#lists ? this.#listReader(seq) : undefined,\n-\t\t);\n-\t\tthis.#atoms.push(frozen);\n+\t\t// Persistent storage copies the accepted atom; a second frozen copy only duplicates its lists.\n+\t\tconst frozen = this.#storage\n+\t\t\t? atom\n+\t\t\t: freezeAtom(\n+\t\t\t\t\tatom,\n+\t\t\t\t\t(id) => this.idOfSeq(seqOf(id)),\n+\t\t\t\t\t(author) => {\n+\t\t\t\t\t\tif (this.#storage) return author;\n+\t\t\t\t\t\tlet a = this.#authors.get(author);\n+\t\t\t\t\t\tif (a === undefined) this.#authors.set(author, (a = author));\n+\t\t\t\t\t\treturn a;\n+\t\t\t\t\t},\n+\t\t\t\t\tthis.#texts ? this.#reader(seq) : undefined,\n+\t\t\t\t\tthis.#lists ? this.#listReader(seq) : undefined,\n+\t\t\t\t);\n+\t\tthis.#atoms.push(this.#storage ? atom : frozen);\n+\t\tthis.#accepted++;\n \t\tlet lam = 0;\n \t\tfor (const d of deps) lam = Math.max(lam, this.lamport(d) + 1);\n-\t\tthis.#lamport.push(lam);\n+\t\tif (this.#lamportPages) this.#lamportPages.push(lam);\n+\t\telse this.#lamport.push(lam);\n \n \t\t// The run starts' parents and the deleted lines, as codes, before this atom's own lines exist.\n \t\t// The atom as given: with lists kept elsewhere, the frozen one reads them back from the log.\n-\t\tconst deletes = atom.deletes.length > 0 ? new Set(atom.deletes) : undefined;\n-\t\tconst deletedN = atom.deletes.map((line) => this.#lineN(line));\n-\t\tthis.#atomDeletes.push(deletedN.length > 0 ? Int32Array.from(deletedN) : undefined);\n+\t\tconst deletes = (line: LineId | NodeId): boolean => {\n+\t\t\tif (isStartNode(line)) return false;\n+\t\t\tif (deleted) return deleted.has(line);\n+\t\t\tconst n = this.#lineN(line);\n+\t\t\treturn this.#deleter.at(n) === seq || this.#moreDeleterPages!.last(String(n)) === seq;\n+\t\t};\n+\t\tconst deletedN = this.#storage ? undefined : atom.deletes.map((line) => this.#lineN(line));\n+\t\tthis.#atomDeletes.push(deletedN?.length ? Int32Array.from(deletedN) : undefined);\n+\t\tif (this.#storage) {\n+\t\t\tconst pages = storedLists<number>(this.#storage, \"atom-deletes\");\n+\t\t\tfor (const line of atom.deletes) pages.append(String(seq), this.#lineN(line));\n+\t\t\tthis.#storage.write(\"atom-delete-counts\", String(seq), atom.deletes.length);\n+\t\t}\n+\t\tconst deletedNumbers = function* (graph: Graph) {\n+\t\t\tif (deletedN) yield* deletedN;\n+\t\t\telse for (const line of atom.deletes) yield graph.#lineN(line);\n+\t\t};\n+\t\tconst packedDeletes = new Map<number, PackedDelete[]>();\n+\t\tfor (const n of deletedNumbers(this)) {\n+\t\t\tif (this.#packed) {\n+\t\t\t\tconst file = this.#lineFile.at(n);\n+\t\t\t\tconst list = packedDeletes.get(file);\n+\t\t\t\tif (list) list.push([n, seq]);\n+\t\t\t\telse packedDeletes.set(file, [[n, seq]]);\n+\t\t\t}\n+\t\t\tif (this.#deleter.at(n) < 0) this.#deleter.set(n, seq);\n+\t\t\telse if (this.#moreDeleterPages) this.#moreDeleterPages.append(String(n), seq);\n+\t\t\telse pushIndex(this.#moreDeleters, n, seq);\n+\t\t}\n+\t\tfor (const [file, list] of packedDeletes) this.#fileDeletes!.appendAll(String(file), list);\n \t\tthis.#lineBase.push(this.#lineTotal);\n \t\tfor (const run of atom.inserts) {\n \t\t\tconst file = this.#pathOf(run.file);\n \t\t\tlet parent = isStartNode(run.parent) ? -1 - file : this.#lineN(run.parent);\n \t\t\tconst first = this.#lineTotal;\n-\t\t\tpushOne(this.#runStarts, parent, first);\n+\t\t\tif (parent >= 0) this.#childCounts?.increment(parent, first);\n+\t\t\tif (this.#storage)\n+\t\t\t\tnew OrderedIndex(this.#storage, \"ordered-children\", String(parent)).insert(\n+\t\t\t\t\torderedChildKey({\n+\t\t\t\t\t\tn: first,\n+\t\t\t\t\t\treplaces: deletes(run.parent) ? 1 : 0,\n+\t\t\t\t\t\tlamport: lam,\n+\t\t\t\t\t\tseq,\n+\t\t\t\t\t\tk: first - this.#lineBase[seq]!,\n+\t\t\t\t\t}),\n+\t\t\t\t\tfirst,\n+\t\t\t\t);\n+\n+\t\t\tif (this.#runStartPages) this.#runStartPages.append(String(parent), first);\n+\t\t\telse pushOne(this.#runStarts, parent, first);\n+\t\t\tconst replacesParent = deletes(run.parent) ? 1 : 0;\n+\t\t\tif (this.#packed) {\n+\t\t\t\tif (this.#crossings && parent >= 0) {\n+\t\t\t\t\tconst from = this.#lineFile.at(parent);\n+\t\t\t\t\tif (from !== file) this.#fileCrossings!.append(String(from), [parent, file]);\n+\t\t\t\t}\n+\t\t\t\tconst base = this.#lineBase[seq]!;\n+\t\t\t\tthis.#fileLines!.appendAll(\n+\t\t\t\t\tString(file),\n+\t\t\t\t\trun.lines.map(\n+\t\t\t\t\t\t(_, i): PackedLine => [\n+\t\t\t\t\t\t\tfirst + i,\n+\t\t\t\t\t\t\ti === 0 ? parent : first + i - 1,\n+\t\t\t\t\t\t\tseq,\n+\t\t\t\t\t\t\tfirst + i - base,\n+\t\t\t\t\t\t\ti === 0 ? replacesParent : 0,\n+\t\t\t\t\t\t],\n+\t\t\t\t\t),\n+\t\t\t\t);\n+\t\t\t\tthis.#fileTexts!.appendAll(\n+\t\t\t\t\tString(file),\n+\t\t\t\t\trun.lines.map((text) => (typeof text === \"string\" && text.length <= PACKED_TEXT ? text : null)),\n+\t\t\t\t);\n+\t\t\t}\n \t\t\tfor (let i = 0; i < run.lines.length; i++) {\n-\t\t\t\tconst n = this.#lineTotal++;\n+\t\t\t\tconst n = this.#lineTotal;\n+\t\t\t\tthis.#childCounts?.append(n);\n \t\t\t\tthis.#lineAtom.push(seq);\n \t\t\t\tthis.#lineFile.push(file);\n \t\t\t\tthis.#lineParent.push(parent);\n \t\t\t\tthis.#lineText?.push(run.lines[i]!);\n \t\t\t\tthis.#deleter.push(-1);\n-\t\t\t\tthis.#replacing.push(i === 0 && deletes?.has(run.parent) ? 1 : 0);\n+\t\t\t\tthis.#replacing.push(i === 0 && deletes(run.parent) ? 1 : 0);\n \t\t\t\tparent = n;\n \t\t\t}\n \t\t}\n \t\t(frozen.moves ?? []).forEach((m, i) => {\n-\t\t\tconst info: RelocationInfo = Object.freeze({ atom: frozen.id, line: m.line, parent: m.parent, k: i });\n-\t\t\tpushIndex(this.#relocations, m.line, info);\n-\t\t\tpushIndex(this.#relocatedTo, m.parent, info);\n-\t\t\tpushIndex(\n-\t\t\t\tthis.#relocatedToCode,\n-\t\t\t\tisStartNode(m.parent) ? -1 - this.#pathOf(m.parent.slice(1)) : this.#lineN(m.parent),\n-\t\t\t\tinfo,\n-\t\t\t);\n+\t\t\tconst info: RelocationInfo = Object.freeze({\n+\t\t\t\tatom: frozen.id,\n+\t\t\t\tline: m.line,\n+\t\t\t\tparent: m.parent,\n+\t\t\t\tk: i,\n+\t\t\t});\n+\t\t\tif (this.#relocationPages) this.#relocationPages.append(m.line, info);\n+\t\t\telse pushIndex(this.#relocations, m.line, info);\n+\t\t\tif (this.#relocatedToPages) this.#relocatedToPages.append(m.parent, info);\n+\t\t\telse pushIndex(this.#relocatedTo, m.parent, info);\n+\t\t\tconst parentCode = isStartNode(m.parent) ? -1 - this.#pathOf(m.parent.slice(1)) : this.#lineN(m.parent);\n+\t\t\tif (this.#relocatedToCodePages) this.#relocatedToCodePages.append(String(parentCode), info);\n+\t\t\telse pushIndex(this.#relocatedToCode, parentCode, info);\n \t\t});\n \t\tif (frozen.moves) this.#movers.push(frozen.id);\n-\t\tfor (const n of deletedN) {\n-\t\t\tif (this.#deleter.at(n) < 0) this.#deleter.set(n, seq);\n-\t\t\telse pushIndex(this.#moreDeleters, n, seq);\n+\t\tif (this.#packed)\n+\t\t\tfor (const a of frozen.attrs ?? []) this.#fileAttrs!.append(String(this.#pathOf(a.file)), [seq, a.name, a.value]);\n+\t\tfor (const key of writes) {\n+\t\t\tconst code = this.#code(key);\n+\t\t\tif (this.#writersPages) {\n+\t\t\t\tconst key = JSON.stringify([typeof code, code]);\n+\t\t\t\tif (this.#writersPages.last(key) !== frozen.id) this.#writersPages.append(key, frozen.id);\n+\t\t\t} else pushOne(this.#writers, code, frozen.id);\n \t\t}\n-\t\tfor (const key of new Set(atom.writes)) pushOne(this.#writers, this.#code(key), frozen.id);\n-\t\tfor (const key of new Set(atom.reads)) pushOne(this.#readers, this.#code(key), frozen.id);\n-\t\tfor (const key of new Set(atom.holds)) pushOne(this.#holders, this.#code(key), frozen.id);\n-\t\tfor (const d of deps) pushOne(this.#dependents, d, frozen.id);\n-\t\tfor (const r of new Set(frozen.resolves)) pushOne(this.#resolvers, r, frozen.id);\n+\t\tfor (const key of this.#storage ? atom.reads : new Set(atom.reads)) {\n+\t\t\tconst code = this.#code(key);\n+\t\t\tif (this.#readersPages) {\n+\t\t\t\tconst key = JSON.stringify([typeof code, code]);\n+\t\t\t\tif (this.#readersPages.last(key) !== frozen.id) this.#readersPages.append(key, frozen.id);\n+\t\t\t} else pushOne(this.#readers, code, frozen.id);\n+\t\t}\n+\t\tfor (const key of this.#storage ? atom.holds : new Set(atom.holds)) {\n+\t\t\tconst code = this.#code(key);\n+\t\t\tif (this.#holdersPages) {\n+\t\t\t\tconst key = JSON.stringify([typeof code, code]);\n+\t\t\t\tif (this.#holdersPages.last(key) !== frozen.id) this.#holdersPages.append(key, frozen.id);\n+\t\t\t} else pushOne(this.#holders, code, frozen.id);\n+\t\t}\n+\t\tfor (const d of deps) {\n+\t\t\tif (this.#dependentsPages) this.#dependentsPages.append(d, frozen.id);\n+\t\t\telse pushOne(this.#dependents, d, frozen.id);\n+\t\t}\n+\t\tfor (const r of this.#storage ? frozen.resolves : new Set(frozen.resolves)) {\n+\t\t\tif (this.#resolversPages) {\n+\t\t\t\tif (this.#resolversPages.last(r) !== frozen.id) this.#resolversPages.append(r, frozen.id);\n+\t\t\t} else pushOne(this.#resolvers, r, frozen.id);\n+\t\t}\n \t\tconst files = new Set<string>();\n \t\tfor (const run of atom.inserts) files.add(run.file);\n-\t\tfor (const n of deletedN) files.add(this.#paths[this.#lineFile.at(n)]!);\n+\t\tfor (const n of deletedNumbers(this)) files.add(this.#pathName(this.#lineFile.at(n)));\n \t\tfor (const a of frozen.attrs ?? []) files.add(a.file);\n \t\tfor (const m of frozen.moves ?? []) {\n \t\t\tfiles.add(this.lineFile(m.line)!);\n \t\t\tfiles.add(isStartNode(m.parent) ? m.parent.slice(1) : this.lineFile(m.parent)!);\n \t\t}\n \t\tthis.#atomFiles.push(Object.freeze([...files].sort()));\n-\t\tfor (const file of files) pushIndex(this.#fileAtoms, file, frozen.id);\n+\t\tfor (const file of files) {\n+\t\t\tif (this.#fileAtomPages) this.#fileAtomPages.append(file, frozen.id);\n+\t\t\telse pushIndex(this.#fileAtoms, file, frozen.id);\n+\t\t}\n+\t\tif (this.#reasonsInKept) {\n+\t\t\tconst pointed = new Set<AtomId>();\n+\t\t\tfor (const r of frozen.reasons) {\n+\t\t\t\tif (pointed.has(r.to)) continue;\n+\t\t\t\tpointed.add(r.to);\n+\t\t\t\tif (this.#reasonsInPages) this.#reasonsInPages.append(r.to, frozen.id);\n+\t\t\t\telse pushIndex(this.#reasonsIn, r.to, frozen.id);\n+\t\t\t}\n+\t\t}\n \t\tfor (const r of frozen.reasons) {\n \t\t\tif (r.kind !== \"together\" || r.to === frozen.id) continue;\n-\t\t\tpushIndex(this.#together, frozen.id, { other: r.to, text: r.text, from: frozen.id });\n-\t\t\tpushIndex(this.#together, r.to, { other: frozen.id, text: r.text, from: frozen.id });\n+\n+\t\t\tconst forward = { other: r.to, text: r.text, from: frozen.id };\n+\t\t\tconst reverse = { other: frozen.id, text: r.text, from: frozen.id };\n+\t\t\tif (this.#togetherPages) {\n+\t\t\t\tthis.#togetherPages.append(frozen.id, forward);\n+\t\t\t\tthis.#togetherPages.append(r.to, reverse);\n+\t\t\t} else {\n+\t\t\t\tpushIndex(this.#together, frozen.id, forward);\n+\t\t\t\tpushIndex(this.#together, r.to, reverse);\n+\t\t\t}\n \t\t}\n \t}\n \n@@ -974,6 +1940,10 @@\n \t * their base instead, so their contents don't change.\n \t */\n \tremoveLabel(name: string): boolean {\n+\t\treturn this.#storage ? this.#storage.transaction(() => this.#removeLabel(name)) : this.#removeLabel(name);\n+\t}\n+\n+\t#removeLabel(name: string): boolean {\n \t\tconst gone = this.#labels.get(name);\n \t\tif (!gone) return false;\n \t\tthis.#labels.delete(name);\n@@ -986,7 +1956,12 @@\n \t// JSON -------------------------------------------------------------------\n \n \ttoJSON(): GraphJSON {\n-\t\treturn { format: GRAPH_FORMAT, version: 1, atoms: this.#atoms, labels: this.labels() };\n+\t\treturn {\n+\t\t\tformat: GRAPH_FORMAT,\n+\t\t\tversion: 1,\n+\t\t\tatoms: this.#atoms,\n+\t\t\tlabels: this.labels(),\n+\t\t};\n \t}\n \n \t/** Load a saved graph. Every atom is re-validated as it is added. */\n@@ -1086,7 +2061,12 @@\n \t// With text kept elsewhere (#46), a run's lines are read when asked for.\n \tlet k = 0;\n \tconst run = (r: InsertRun): InsertRun => {\n-\t\tif (!text) return Object.freeze({ file: r.file, parent: r.parent, lines: Object.freeze([...r.lines]) });\n+\t\tif (!text)\n+\t\t\treturn Object.freeze({\n+\t\t\t\tfile: r.file,\n+\t\t\t\tparent: r.parent,\n+\t\t\t\tlines: Object.freeze([...r.lines]),\n+\t\t\t});\n \t\tconst start = k;\n \t\tconst length = r.lines.length;\n \t\tk += length;\n@@ -1101,16 +2081,25 @@\n \t\tinserts: Object.freeze(atom.inserts.map(run)),\n \t\t...(lists\n \t\t\t? {}\n-\t\t\t: { deletes: list(atom.deletes), writes: list(atom.writes), reads: list(atom.reads), holds: list(atom.holds) }),\n+\t\t\t: {\n+\t\t\t\t\tdeletes: list(atom.deletes),\n+\t\t\t\t\twrites: list(atom.writes),\n+\t\t\t\t\treads: list(atom.reads),\n+\t\t\t\t\tholds: list(atom.holds),\n+\t\t\t\t}),\n \t\tneeds: list(atom.needs, canon),\n \t\tresolves: list(atom.resolves, canon),\n \t\treasons: list(atom.reasons, (r) => Object.freeze({ to: canon(r.to), kind: r.kind, text: r.text })),\n \t\tdeps: list(atom.deps, canon),\n \t\t...(atom.attrs && atom.attrs.length > 0\n-\t\t\t? { attrs: Object.freeze(atom.attrs.map((a) => Object.freeze({ file: a.file, name: a.name, value: a.value }))) }\n+\t\t\t? {\n+\t\t\t\t\tattrs: Object.freeze(atom.attrs.map((a) => Object.freeze({ file: a.file, name: a.name, value: a.value }))),\n+\t\t\t\t}\n \t\t\t: {}),\n \t\t...(atom.moves\n-\t\t\t? { moves: Object.freeze(atom.moves.map((m) => Object.freeze({ line: m.line, parent: m.parent }))) }\n+\t\t\t? {\n+\t\t\t\t\tmoves: Object.freeze(atom.moves.map((m) => Object.freeze({ line: m.line, parent: m.parent }))),\n+\t\t\t\t}\n \t\t\t: {}),\n \t} as Atom;\n \treturn Object.freeze(lists ? (new ListedAtom(copy, lists) as unknown as Atom) : copy);"}],"unmatched":[]}