{"version":206,"agent":"capacity","message":"Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.","time":1792031851789,"timeIso":"2026-10-15T02:37:31.789Z","changes":5,"change":3478,"files":["src/engine/graph.ts","src/engine/state-source.ts","src/engine/test/packed-files.test.ts","src/engine/test/state-source.test.ts","src/engine/view.ts"],"draft":null,"diff":[{"path":"src/engine/graph.ts","added":94,"removed":0,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -256,6 +256,15 @@\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+/** 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@@ -294,6 +303,8 @@\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@@ -583,9 +594,58 @@\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.#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]), and every attribute set on it ([seq, name, value]).\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/** Whether a new stored graph starts packing (GraphOptions.packFiles). */\n+\t#packFiles = true;\n+\t/** Whether this graph's files are packed: read once, when first asked, so opening reads nothing. */\n+\t#packedKnown: boolean | undefined;\n+\tget #packed(): boolean {\n+\t\tthis.#packedKnown ??= !!this.#storage && this.#storage.read(\"file-lines:meta\", \"format\") === 1;\n+\t\treturn this.#packedKnown;\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/** 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*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+\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@@ -1377,6 +1437,10 @@\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\", 1);\n+\t\t\tthis.#packedKnown = true;\n+\t\t}\n \n \t\tif (this.#storage) this.withProjectionScratch((scratch) => this.#validateAcceptedAtom(atom, scratch));\n \t\telse this.#validateAcceptedAtom(atom);\n@@ -1425,11 +1489,19 @@\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@@ -1450,6 +1522,26 @@\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\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\tthis.#childCounts?.append(n);\n@@ -1473,6 +1565,8 @@\n \t\t\telse pushIndex(this.#relocatedToCode, parentCode, info);\n \t\t});\n \t\tif (frozen.moves) this.#movers.push(frozen.id);\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) {"},{"path":"src/engine/state-source.ts","added":17,"removed":0,"diff":"--- a/src/engine/state-source.ts\n+++ b/src/engine/state-source.ts\n@@ -413,6 +413,23 @@\n \t\t\tstorage.write(`${name}:pages`, pageKey(key, index), values);\n \t\t\tstorage.write(`${name}:lengths`, key, count + 1);\n \t\t},\n+\t\t/** Append several values, writing each page they touch once. */\n+\t\tappendAll(key: string, more: readonly V[]): void {\n+\t\t\tif (more.length === 0) return;\n+\t\t\tconst count = length(key);\n+\t\t\tlet index = Math.floor(count / pageSize);\n+\t\t\tlet values = count % pageSize === 0 ? [] : page(key, index);\n+\t\t\tif (values.length !== count % pageSize) throw new Error(`invalid writer list length in ${name}`);\n+\t\t\tfor (const value of more) {\n+\t\t\t\tif (values.length === pageSize) {\n+\t\t\t\t\tstorage.write(`${name}:pages`, pageKey(key, index++), values);\n+\t\t\t\t\tvalues = [];\n+\t\t\t\t}\n+\t\t\t\tvalues.push(value);\n+\t\t\t}\n+\t\t\tstorage.write(`${name}:pages`, pageKey(key, index), values);\n+\t\t\tstorage.write(`${name}:lengths`, key, count + more.length);\n+\t\t},\n \t};\n }\n "},{"path":"src/engine/test/packed-files.test.ts","added":56,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/packed-files.test.ts\n@@ -0,0 +1,56 @@\n+// Each file's line history packed (abso Capacity, Graph.packedLines): a stored graph lays files out from a few pages,\n+// and must give exactly what the in-memory graph gives, through edits, deletes, moves between files and back.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { Graph, View } from \"../index.ts\";\n+import { StableOverlaySet } from \"../state-source.ts\";\n+import { lines, Repo } from \"./helpers.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"a packed file lays out as the in-memory graph does, at every step, moves included\", () => {\n+\tconst oracle = Repo.init({ \"a.txt\": lines(\"one\", \"two\", \"three\", \"four\"), \"b.txt\": lines(\"bee\"), \"c.txt\": \"\" });\n+\tconst sets: Set<string>[] = [new Set(oracle.shared)];\n+\tconst step = (change: Parameters<Repo[\"edit\"]>[0]) => {\n+\t\toracle.edit(change);\n+\t\tsets.push(new Set(oracle.shared));\n+\t};\n+\tstep({ edits: [{ file: \"a.txt\", old: \"two\", new: \"TWO\" }] });\n+\tstep({ move: { file: \"a.txt\", start: 1, end: 3, to: \"b.txt\", at: 1 } });\n+\tstep({ edits: [{ file: \"b.txt\", old: \"TWO\", new: \"two again\" }] });\n+\tstep({ edits: [{ file: \"a.txt\", old: \"four\", new: \"\" }] });\n+\tstep({ move: { file: \"b.txt\", start: 0, end: 2, to: \"c.txt\", at: 0 } });\n+\tstep({ edits: [{ file: \"c.txt\", old: \"bee\", new: \"bee\\nafter bee\" }] });\n+\tconst storage = new SqlState();\n+\ttry {\n+\t\tconst graph = new Graph({ storage });\n+\t\tfor (const atom of oracle.graph.atoms()) graph.add(atom);\n+\t\tconst reopened = new Graph({ storage });\n+\t\tassert.equal(reopened.packedFiles, true);\n+\t\tfor (const [i, set] of sets.entries()) {\n+\t\t\tconst packed = new View(reopened, new StableOverlaySet(set));\n+\t\t\tconst memory = new View(oracle.graph, set);\n+\t\t\tassert.deepEqual(packed.paths(), memory.paths(), `step ${i}: paths`);\n+\t\t\tfor (const path of [\"a.txt\", \"b.txt\", \"c.txt\"]) {\n+\t\t\t\tassert.equal(packed.text(path), memory.text(path), `step ${i}: ${path}`);\n+\t\t\t\tassert.deepEqual(packed.sequence(path), memory.sequence(path), `step ${i}: ${path}'s sequence`);\n+\t\t\t\tassert.deepEqual(packed.attrs(path), memory.attrs(path), `step ${i}: ${path}'s attributes`);\n+\t\t\t}\n+\t\t}\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});\n+\n+test(\"a graph made with packFiles off keeps no packed history\", () => {\n+\tconst oracle = Repo.init({ \"a.txt\": lines(\"one\") });\n+\tconst storage = new SqlState();\n+\ttry {\n+\t\tconst graph = new Graph({ storage, packFiles: false });\n+\t\tfor (const atom of oracle.graph.atoms()) graph.add(atom);\n+\t\tassert.equal(new Graph({ storage }).packedFiles, false);\n+\t\tassert.equal(new View(new Graph({ storage }), new StableOverlaySet(oracle.shared)).text(\"a.txt\"), \"one\\n\");\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});"},{"path":"src/engine/test/state-source.test.ts","added":14,"removed":7,"diff":"--- a/src/engine/test/state-source.test.ts\n+++ b/src/engine/test/state-source.test.ts\n@@ -47,6 +47,7 @@\n \t}\n });\n \n+// The line-by-line layout, which a graph adopted before packed file history still uses (packFiles: false).\n test(\"current visibility stops at the first included deletion while history retains every deleter\", () => {\n \tclass ObservedStorage extends SqlState {\n \t\tpageReads = 0;\n@@ -59,7 +60,7 @@\n \ttry {\n \t\tconst oracle = Repo.init({ \"a.txt\": \"gone\\nlive\\n\" });\n \t\tconst deletion = oracle.draft({ edits: [{ file: \"a.txt\", old: \"gone\\n\", new: \"\" }] });\n-\t\tconst graph = new Graph({ storage });\n+\t\tconst graph = new Graph({ storage, packFiles: false });\n \t\tgraph.add(oracle.graph.atom(\"a0\"));\n \t\tconst ids = [\"a0\"];\n \t\tfor (let seq = 1; seq <= 514; seq++) {\n@@ -68,7 +69,7 @@\n \t\t\toracle.graph.add(atom);\n \t\t\tids.push(atom.id);\n \t\t}\n-\t\tconst reopened = new Graph({ storage });\n+\t\tconst reopened = new Graph({ storage, packFiles: false });\n \t\tconst membership = new StableOverlaySet(ids);\n \t\tconst view = new View(reopened, membership);\n \t\tstorage.pageReads = 0;\n@@ -479,9 +480,9 @@\n \t\t\t}\n \t\t\tconst before = oracle.view().text(\"a.txt\");\n \t\t\toracle.edit({ edits: [{ file: \"a.txt\", old: before, new: \"live\\n\" }] });\n-\t\t\tconst graph = new Graph({ storage });\n+\t\t\tconst graph = new Graph({ storage, packFiles: false });\n \t\t\tfor (const id of oracle.shared) graph.add(oracle.graph.atom(id));\n-\t\t\tconst reopened = new Graph({ storage });\n+\t\t\tconst reopened = new Graph({ storage, packFiles: false });\n \t\t\treopened.eachChildN = () => {\n \t\t\t\tthrow Error(\"unordered child collection forbidden\");\n \t\t\t};\n@@ -540,14 +541,20 @@\n \tconst storage = new SqlState();\n \ttry {\n \t\tconst oracle = Repo.init({ \"a.txt\": \"one\\n\" });\n-\t\tconst graph = new Graph({ storage });\n+\t\tconst graph = new Graph({ storage, packFiles: false });\n \t\tgraph.add(oracle.graph.atom(\"a0\"));\n \t\tstorage.remove(\"ordered-children\", \"format\");\n-\t\tassert.throws(() => new View(new Graph({ storage }), new StableOverlaySet([\"a0\"])).text(\"a.txt\"), /fresh adoption/);\n \t\tassert.throws(\n-\t\t\t() => new Graph({ storage }).add(oracle.draft({ edits: [{ file: \"a.txt\", old: \"one\", new: \"two\" }] })),\n+\t\t\t() => new View(new Graph({ storage, packFiles: false }), new StableOverlaySet([\"a0\"])).text(\"a.txt\"),\n \t\t\t/fresh adoption/,\n \t\t);\n+\t\tassert.throws(\n+\t\t\t() =>\n+\t\t\t\tnew Graph({ storage, packFiles: false }).add(\n+\t\t\t\t\toracle.draft({ edits: [{ file: \"a.txt\", old: \"one\", new: \"two\" }] }),\n+\t\t\t\t),\n+\t\t\t/fresh adoption/,\n+\t\t);\n \t\tstorage.write(\"ordered-children\", \"format\", 2);\n \t\tconst parent = graph.startCodeOf(\"a.txt\")!;\n \t\tstorage.remove(\"ordered-children\", JSON.stringify([String(parent), \"meta\"]));"},{"path":"src/engine/view.ts","added":129,"removed":2,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -64,6 +64,8 @@\n \treadonly vis: Int32Array;\n \t/** For each deleted position in seq: the seqs of the atoms in the set that delete it, by priority. */\n \treadonly deletedBy: ReadonlyMap<number, readonly number[]>;\n+\t/** Its visible lines' text, when laid out from the file's packed history: null for a line too long to pack. */\n+\treadonly visText?: readonly (string | null)[];\n \t/** Positions by n, built the first time they're asked for. */\n \tseqIndex?: Map<number, number>;\n \tvisIndex?: Map<number, number>;\n@@ -451,6 +453,7 @@\n \t/** Lay out one file: its line tree from the set's atoms, linearized. */\n \t#layout(path: string, complete: boolean): FileState {\n \t\tconst graph = this.graph;\n+\t\tif (graph.packedFiles && !this.#scratchMoves()) return this.#layoutPacked(path, complete);\n \t\tif (this.#scratchMoves())\n \t\t\treturn graph.withProjectionScratch((scratch) =>\n \t\t\t\tthis.#layoutResolved(\n@@ -462,10 +465,133 @@\n \t\treturn this.#layoutResolved(path, complete);\n \t}\n \n+\t/** For each path, the files that lines moved into it were written in: worked out once per view. */\n+\t#movedFrom: Map<string, Set<number>> | undefined;\n+\t#movedInFrom(): Map<string, Set<number>> {\n+\t\tif (this.#movedFrom) return this.#movedFrom;\n+\t\tconst graph = this.graph;\n+\t\tconst out = new Map<string, Set<number>>();\n+\t\tif (this.#hasMoves) {\n+\t\t\tconst relocs = this.#relocationsN();\n+\t\t\t// Where each node sits, walked once for the whole view: through the moves, up to a file's start.\n+\t\t\tconst memo = new Map<number, string>();\n+\t\t\tconst fileOf = (code: number): string => {\n+\t\t\t\tconst walked: number[] = [];\n+\t\t\t\tlet cur = code;\n+\t\t\t\tlet file: string | undefined;\n+\t\t\t\twhile (file === undefined) {\n+\t\t\t\t\tif (cur < 0) file = graph.nodeOf(cur).slice(1);\n+\t\t\t\t\telse {\n+\t\t\t\t\t\tfile = memo.get(cur);\n+\t\t\t\t\t\tif (file === undefined) {\n+\t\t\t\t\t\t\twalked.push(cur);\n+\t\t\t\t\t\t\tcur = relocs.get(cur)?.parent ?? graph.parentCodeOf(cur);\n+\t\t\t\t\t\t}\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\tfor (const n of walked) memo.set(n, file);\n+\t\t\t\treturn file;\n+\t\t\t};\n+\t\t\tfor (const [n, { parent }] of relocs) {\n+\t\t\t\tconst into = fileOf(parent);\n+\t\t\t\tlet from = out.get(into);\n+\t\t\t\tif (!from) out.set(into, (from = new Set()));\n+\t\t\t\tfrom.add(graph.writtenInIndex(n));\n+\t\t\t}\n+\t\t}\n+\t\tthis.#movedFrom = out;\n+\t\treturn out;\n+\t}\n+\n+\t/**\n+\t * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, and in the\n+\t * files its moved-in lines came from, read a page at a time; the same tree and order as #layoutResolved, built in\n+\t * memory with no read per line.\n+\t */\n+\t#layoutPacked(path: string, complete: boolean): FileState {\n+\t\tconst graph = this.graph;\n+\t\tconst attrs = this.#attributes(path);\n+\t\tconst start = graph.startCodeOf(path);\n+\t\tif (start === undefined) return { attrs, complete, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };\n+\t\tconst relocs = this.#hasMoves ? this.#relocationsN() : undefined;\n+\t\tconst files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);\n+\t\tconst children = new Map<number, Child[]>();\n+\t\tconst texts = new Map<number, string | null>();\n+\t\tconst deleters = new Map<number, number[]>();\n+\t\tfor (const file of files) {\n+\t\t\tconst lineTexts = graph.packedTexts(file);\n+\t\t\tfor (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {\n+\t\t\t\tconst text = lineTexts.next().value as string | null;\n+\t\t\t\tif (!this.#has(seq)) continue;\n+\t\t\t\tconst moved = relocs?.get(n);\n+\t\t\t\tlet at = parent;\n+\t\t\t\tlet child: Child = { n, replaces, lamport: graph.lamportOfSeq(seq), seq, k };\n+\t\t\t\tif (moved) {\n+\t\t\t\t\tconst mover = graph.atom(moved.r.atom).seq;\n+\t\t\t\t\tchild = { n, replaces: 0, lamport: graph.lamportOfSeq(mover), seq: mover, k: moved.r.k };\n+\t\t\t\t\tat = moved.parent;\n+\t\t\t\t}\n+\t\t\t\tconst list = children.get(at);\n+\t\t\t\tif (list) list.push(child);\n+\t\t\t\telse children.set(at, [child]);\n+\t\t\t\ttexts.set(n, text);\n+\t\t\t}\n+\t\t\tfor (const [n, deleter] of graph.packedDeletes(file)) {\n+\t\t\t\tif (!this.#has(deleter)) continue;\n+\t\t\t\tconst by = deleters.get(n);\n+\t\t\t\tif (by) by.push(deleter);\n+\t\t\t\telse deleters.set(n, [deleter]);\n+\t\t\t}\n+\t\t}\n+\t\tconst order = (a: Child, b: Child) =>\n+\t\t\tb.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;\n+\t\tconst priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;\n+\t\tconst seq: number[] = [];\n+\t\tconst vis: number[] = [];\n+\t\tconst visText: (string | null)[] = [];\n+\t\tconst deletedBy = new Map<number, readonly number[]>();\n+\t\tconst stack: number[] = [];\n+\t\tconst push = (code: number) => {\n+\t\t\tconst list = children.get(code);\n+\t\t\tif (!list) return;\n+\t\t\tif (list.length > 1) list.sort(order);\n+\t\t\tfor (let i = list.length - 1; i >= 0; i--) stack.push(list[i]!.n);\n+\t\t};\n+\t\tpush(start);\n+\t\twhile (stack.length) {\n+\t\t\tconst n = stack.pop()!;\n+\t\t\tconst by = deleters.get(n);\n+\t\t\tif (by) {\n+\t\t\t\tif (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);\n+\t\t\t} else {\n+\t\t\t\tvis.push(n);\n+\t\t\t\tvisText.push(texts.get(n) ?? null);\n+\t\t\t}\n+\t\t\tif (complete) seq.push(n);\n+\t\t\tpush(n);\n+\t\t}\n+\t\treturn { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy, visText };\n+\t}\n+\n \t#attributes(path: string): FileAttrs {\n \t\tconst graph = this.graph;\n \t\t// For each attribute, the highest-priority setter in the set wins.\n \t\tconst setters = new Map<string, { id: AtomId; value: string | null }>();\n+\t\tconst file = graph.packedFiles ? graph.pathIndexOf(path) : undefined;\n+\t\tif (graph.packedFiles) {\n+\t\t\tfor (const [seq, name, value] of file === undefined ? [] : graph.packedAttrs(file)) {\n+\t\t\t\tif (!this.#has(seq)) continue;\n+\t\t\t\tconst id = graph.idOfSeq(seq);\n+\t\t\t\tconst best = setters.get(name);\n+\t\t\t\tif (!best || graph.comparePriority(best.id, id) < 0) setters.set(name, { id, value });\n+\t\t\t}\n+\t\t\treturn {\n+\t\t\t\texists: setters.get(\"exists\")?.value === \"1\",\n+\t\t\t\texec: setters.get(\"exec\")?.value === \"1\",\n+\t\t\t\tlink: setters.get(\"link\")?.value ?? null,\n+\t\t\t\tblob: setters.get(\"blob\")?.value ?? null,\n+\t\t\t};\n+\t\t}\n \t\tfor (const id of graph.eachAtomIn(path)) {\n \t\t\tif (!this.#has(graph.atom(id).seq)) continue;\n \t\t\tfor (const a of graph.atom(id).attrs ?? []) {\n@@ -556,9 +682,9 @@\n \t/** The projected text of a file (\"\" if it has no visible lines). */\n \ttext(path: string): string {\n \t\tif (this.#textCache?.path === path) return this.#textCache.text;\n-\t\tconst vis = this.#file(path).vis;\n+\t\tconst { vis, visText } = this.#file(path);\n \t\tconst lines: string[] = new Array(vis.length);\n-\t\tfor (let i = 0; i < vis.length; i++) lines[i] = this.graph.textOf(vis[i]!);\n+\t\tfor (let i = 0; i < vis.length; i++) lines[i] = visText?.[i] ?? this.graph.textOf(vis[i]!);\n \t\tconst text = joinLines(lines);\n \t\tthis.#textCache = { path, text };\n \t\treturn text;\n@@ -742,6 +868,7 @@\n \t\t\t\t// headers are separate from their payload byte lengths below.\n \t\t\t\tn += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;\n \t\t\t\tn += f.seq.byteLength + f.vis.byteLength;\n+\t\t\t\tif (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);\n \t\t\t\tn += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;\n \t\t\t\tfor (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;\n \t\t\t\tif (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;"}],"ci":null}