{"version":215,"agent":"capacity","message":"Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts.\n\n- view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves.\n- project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies.\n\nTests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.","time":1792039881566,"timeIso":"2026-10-15T04:51:21.566Z","changes":2,"change":3551,"files":["src/engine/view.ts","worker/project/project.ts"],"draft":null,"diff":[{"path":"src/engine/view.ts","added":131,"removed":85,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -95,7 +95,6 @@\n const MAP_ENTRY_BYTES = 40;\n const SET_ENTRY_BYTES = 32;\n const REFERENCE_BYTES = 8;\n-const FILE_LOCATION_MEMO_ENTRIES = 256;\n /**\n  * Moved lines a view resolves once and keeps (abso Capacity): a stored graph otherwise resolved every move again on\n  * disk for each file it laid out. Game's whole history has 290; past this many, the view goes back to that.\n@@ -103,10 +102,86 @@\n export const MOVED_LINES_KEPT = 20_000;\n class TooManyMoves extends Error {}\n const NO_LINES: readonly number[] = Object.freeze([]);\n-/** Lines whose place views sharing moves remember, at most: about 40 bytes each. */\n-const SHARED_FILE_MEMO = 200_000;\n+/** Nodes whose nearest moved line above a graph remembers, at most: about 40 bytes each. */\n+const CLIMB_MEMO = 200_000;\n \n+/** One relocation of a moved line, with its line's number and its new parent's code. */\n+interface MoveEntry {\n+\treadonly n: number;\n+\treadonly r: RelocationInfo;\n+\treadonly parent: number;\n+}\n+\n /**\n+ * A graph's moves, whatever the set (abso Capacity): each mover's moved lines, each moved line's relocations in seq\n+ * order, and for any node the nearest node at or above it, by where lines were written, that a move ever relocated,\n+ * or its file's start. Worked out once per graph and extended as it grows. A view's moves then resolve over the moved\n+ * lines alone: before, every view walked each moved line's file up to its start, a read per line.\n+ */\n+class MoveSkeleton {\n+\treadonly #graph: Graph;\n+\t#seen = 0;\n+\t/** Movers in seq order, with the numbers of the lines each moves, in its moves' order. */\n+\treadonly movers: { readonly seq: number; readonly lines: readonly number[] }[] = [];\n+\t/** Every relocation of each moved line, by the line's number, in seq order. */\n+\treadonly byLine = new Map<number, MoveEntry[]>();\n+\treadonly #climbed = new Map<number, number>();\n+\n+\tconstructor(graph: Graph) {\n+\t\tthis.#graph = graph;\n+\t}\n+\n+\t/** Take in movers the graph gained since. */\n+\tupdate(): this {\n+\t\tconst graph = this.#graph;\n+\t\tconst all = graph.movers();\n+\t\tif (this.#seen === all.length) return this;\n+\t\tfor (; this.#seen < all.length; this.#seen++) {\n+\t\t\tconst id = all[this.#seen]!;\n+\t\t\tconst lines: number[] = [];\n+\t\t\tgraph.atom(id).moves!.forEach((m, k) => {\n+\t\t\t\tconst n = graph.lineN(m.line);\n+\t\t\t\tconst r: RelocationInfo = Object.freeze({ atom: id, line: m.line, parent: m.parent, k });\n+\t\t\t\tconst entry: MoveEntry = { n, r, parent: graph.codeOf(m.parent)! };\n+\t\t\t\tconst list = this.byLine.get(n);\n+\t\t\t\tif (list) list.push(entry);\n+\t\t\t\telse this.byLine.set(n, [entry]);\n+\t\t\t\tlines.push(n);\n+\t\t\t});\n+\t\t\tthis.movers.push({ seq: seqOf(id), lines });\n+\t\t}\n+\t\t// A new moved line can sit between a node and the one it climbed to.\n+\t\tthis.#climbed.clear();\n+\t\treturn this;\n+\t}\n+\n+\t/** The nearest node at or above this one, by where lines were written, that a move ever relocated; or its file's start. */\n+\tclimb(code: number): number {\n+\t\tconst walked: number[] = [];\n+\t\tlet c = code;\n+\t\twhile (c >= 0 && !this.byLine.has(c)) {\n+\t\t\tconst known = this.#climbed.get(c);\n+\t\t\tif (known !== undefined) {\n+\t\t\t\tc = known;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\twalked.push(c);\n+\t\t\tc = this.#graph.parentCodeOf(c);\n+\t\t}\n+\t\tif (this.#climbed.size + walked.length > CLIMB_MEMO) this.#climbed.clear();\n+\t\tfor (const w of walked) this.#climbed.set(w, c);\n+\t\treturn c;\n+\t}\n+}\n+\n+const skeletons = new WeakMap<Graph, MoveSkeleton>();\n+function skeletonOf(graph: Graph): MoveSkeleton {\n+\tlet skeleton = skeletons.get(graph);\n+\tif (!skeleton) skeletons.set(graph, (skeleton = new MoveSkeleton(graph)));\n+\treturn skeleton.update();\n+}\n+\n+/**\n  * The projection of a closed set. Construct once, then ask for files, lines\n  * and sequences. Throws `not-closed` if some atom's dependency is missing.\n  * Each file is laid out the first time it is asked for, so a view of a large\n@@ -136,8 +211,6 @@\n \t#movedInto: Map<number, number[]> | undefined;\n \t/** Whether this view's moves are too many to keep, so they're resolved on disk per layout; undefined until asked. */\n \t#movesOnDisk: boolean | undefined;\n-\t/** Bounded memo: ancestry can span the entire history even for one visible line. */\n-\t#fileOf = new Map<number, string>();\n \t/** The latest records asked for: one file's lines, one file's sequence, one file's text. */\n \t#linesCache: { path: string; lines: readonly VisibleLine[] } | undefined;\n \t#seqCache: { path: string; seq: readonly SeqLine[] } | undefined;\n@@ -223,34 +296,46 @@\n \t#relocations(): Map<LineId, RelocationInfo> {\n \t\tif (this.#relocs) return this.#relocs;\n \t\tconst graph = this.graph;\n+\t\tconst skeleton = skeletonOf(graph);\n \t\tconst stronger = (a: RelocationInfo, b: RelocationInfo): boolean => graph.comparePriority(a.atom, b.atom) > 0;\n-\t\t// Persistent reads decode new objects. Cycle suppression must identify the\n-\t\t// logical move, not one particular decoded JavaScript object.\n \t\tconst identity = (r: RelocationInfo): string => JSON.stringify([r.atom, r.k]);\n \t\tconst ignored = new Set<string>();\n-\t\tconst pick = (line: LineId): RelocationInfo | undefined => {\n-\t\t\tlet best: RelocationInfo | undefined;\n-\t\t\tfor (const r of graph.eachRelocationOf(line)) {\n-\t\t\t\tif (this.#has(graph.atom(r.atom).seq) && !ignored.has(identity(r)) && (!best || stronger(r, best))) best = r;\n+\t\tconst pick = (n: number): MoveEntry | undefined => {\n+\t\t\tlet best: MoveEntry | undefined;\n+\t\t\tfor (const e of skeleton.byLine.get(n) ?? []) {\n+\t\t\t\tif (this.#has(seqOf(e.r.atom)) && !ignored.has(identity(e.r)) && (!best || stronger(e.r, best.r))) best = e;\n \t\t\t}\n \t\t\treturn best;\n \t\t};\n-\t\tconst relocs = new Map<LineId, RelocationInfo>();\n-\t\tfor (const id of this.#eachMover()) {\n-\t\t\tfor (const m of graph.atom(id).moves!) {\n-\t\t\t\tif (!relocs.has(m.line)) relocs.set(m.line, pick(m.line)!);\n+\t\t// By the moved line's number, in the order its movers come (seq order, then each mover's moves).\n+\t\tconst relocs = new Map<number, MoveEntry>();\n+\t\tfor (const mover of skeleton.movers) {\n+\t\t\tif (!this.#has(mover.seq)) continue;\n+\t\t\tfor (const n of mover.lines) {\n+\t\t\t\tif (!relocs.has(n)) relocs.set(n, pick(n)!);\n \t\t\t\tif (graph.hasOrderedChildren && relocs.size > MOVED_LINES_KEPT) throw new TooManyMoves();\n \t\t\t}\n \t\t}\n-\t\tconst parentOf = (line: LineId): NodeId => relocs.get(line)?.parent ?? graph.lineParent(line)!;\n-\t\tconst reaches = new Set<LineId>();\n+\t\t// From a node, the next node that matters for loops: a line moved in this set, or a file's start.\n+\t\tconst hop = (code: number): number => {\n+\t\t\tlet c = skeleton.climb(code);\n+\t\t\twhile (c >= 0 && !relocs.has(c)) c = skeleton.climb(graph.parentCodeOf(c));\n+\t\t\treturn c;\n+\t\t};\n+\t\tconst step = (n: number): number => {\n+\t\t\tconst e = relocs.get(n);\n+\t\t\treturn hop(e ? e.parent : graph.parentCodeOf(n));\n+\t\t};\n+\t\t// Two moves made apart can loop lines into each other, so no start node reaches them; then the oldest\n+\t\t// relocation on the loop is ignored, and the next newest of that line counts, until none loop.\n+\t\tconst reaches = new Set<number>();\n \t\tfor (const line of [...relocs.keys()]) {\n \t\t\tfor (;;) {\n-\t\t\t\tconst path: LineId[] = [];\n-\t\t\t\tconst onPath = new Map<LineId, number>();\n-\t\t\t\tlet cur: NodeId = line;\n+\t\t\t\tconst path: number[] = [];\n+\t\t\t\tconst onPath = new Map<number, number>();\n+\t\t\t\tlet cur = line;\n \t\t\t\tlet loopAt = -1;\n-\t\t\t\twhile (!isStartNode(cur) && !reaches.has(cur)) {\n+\t\t\t\twhile (cur >= 0 && !reaches.has(cur)) {\n \t\t\t\t\tconst at = onPath.get(cur);\n \t\t\t\t\tif (at !== undefined) {\n \t\t\t\t\t\tloopAt = at;\n@@ -258,30 +343,28 @@\n \t\t\t\t\t}\n \t\t\t\t\tonPath.set(cur, path.length);\n \t\t\t\t\tpath.push(cur);\n-\t\t\t\t\tcur = parentOf(cur);\n+\t\t\t\t\tcur = step(cur);\n \t\t\t\t}\n \t\t\t\tif (loopAt < 0) {\n \t\t\t\t\tfor (const l of path) reaches.add(l);\n \t\t\t\t\tbreak;\n \t\t\t\t}\n-\t\t\t\tlet weakest: RelocationInfo | undefined;\n+\t\t\t\tlet weakest: MoveEntry | undefined;\n \t\t\t\tfor (const l of path.slice(loopAt)) {\n-\t\t\t\t\tconst r = relocs.get(l);\n-\t\t\t\t\tif (r && (!weakest || stronger(weakest, r))) weakest = r;\n+\t\t\t\t\tconst e = relocs.get(l);\n+\t\t\t\t\tif (e && (!weakest || stronger(weakest.r, e.r))) weakest = e;\n \t\t\t\t}\n-\t\t\t\tignored.add(identity(weakest!));\n-\t\t\t\tconst next = pick(weakest!.line);\n-\t\t\t\tif (next) relocs.set(weakest!.line, next);\n-\t\t\t\telse relocs.delete(weakest!.line);\n+\t\t\t\tignored.add(identity(weakest!.r));\n+\t\t\t\tconst next = pick(weakest!.n);\n+\t\t\t\tif (next) relocs.set(weakest!.n, next);\n+\t\t\t\telse relocs.delete(weakest!.n);\n \t\t\t}\n \t\t}\n-\t\tthis.#relocs = relocs;\n-\t\treturn relocs;\n+\t\tthis.#relocsN = new Map([...relocs].map(([n, e]) => [n, { r: e.r, parent: e.parent }]));\n+\t\tthis.#relocs = new Map([...relocs.values()].map((e) => [e.r.line, e.r]));\n+\t\treturn this.#relocs;\n \t}\n \n-\t/** Where lines sit, shared with views that took this one's moves (shareMoves): unbounded up to SHARED_FILE_MEMO. */\n-\t#fileOfShared: Map<number, string> | undefined;\n-\n \t/**\n \t * Take another view's resolved moves (abso Capacity), when both sets hold the very same atoms that move lines: the\n \t * moves then resolve the same, and every line sits where it sits there. Checked here, so any caller may ask.\n@@ -297,8 +380,6 @@\n \t\tthis.#relocsN = from.#relocationsN();\n \t\tthis.#movesOnDisk = false;\n \t\tthis.#movedFrom = from.#movedInFrom();\n-\t\tfrom.#fileOfShared ??= new Map();\n-\t\tthis.#fileOfShared = from.#fileOfShared;\n \t}\n \n \t/** Whether moves are resolved on disk for each layout: only a stored graph's view with more than MOVED_LINES_KEPT. */\n@@ -366,36 +447,21 @@\n \t\t\t\twhile (!isStartNode(current)) current = moves.parent(current);\n \t\t\t\treturn current.slice(1);\n \t\t\t});\n+\t\treturn this.#fileOfCode(n);\n+\t}\n+\n+\t/** The file a node sits in, in this set: up by where lines were written, through the moves that count here. */\n+\t#fileOfCode(code: number): string {\n+\t\tconst graph = this.graph;\n \t\tconst relocs = this.#relocationsN();\n-\t\t// Keep only a fixed tail of the walk for path compression. The selected\n-\t\t// relocation graph is acyclic, so traversal needs no history-sized stack.\n-\t\tconst path: number[] = [];\n-\t\tlet visited = 0;\n-\t\tlet cur = n;\n-\t\tlet file: string | undefined;\n-\t\twhile (file === undefined) {\n-\t\t\tif (cur < 0) file = graph.nodeOf(cur).slice(1);\n-\t\t\telse {\n-\t\t\t\tfile = (this.#fileOfShared ?? this.#fileOf).get(cur);\n-\t\t\t\tif (file === undefined) {\n-\t\t\t\t\tif (this.#fileOfShared) path.push(cur);\n-\t\t\t\t\telse path[visited++ % FILE_LOCATION_MEMO_ENTRIES] = cur;\n-\t\t\t\t\tcur = relocs.get(cur)?.parent ?? graph.parentCodeOf(cur);\n-\t\t\t\t}\n-\t\t\t}\n+\t\tconst skeleton = skeletonOf(graph);\n+\t\tlet c = code;\n+\t\tfor (;;) {\n+\t\t\tc = skeleton.climb(c);\n+\t\t\tif (c < 0) return graph.nodeOf(c).slice(1);\n+\t\t\tconst e = relocs.get(c);\n+\t\t\tc = e ? e.parent : graph.parentCodeOf(c);\n \t\t}\n-\t\tconst shared = this.#fileOfShared;\n-\t\tif (shared) {\n-\t\t\tif (shared.size > SHARED_FILE_MEMO) shared.clear();\n-\t\t\tfor (const l of path) shared.set(l, file);\n-\t\t\treturn file;\n-\t\t}\n-\t\tfor (const l of path) {\n-\t\t\tif (!this.#fileOf.has(l) && this.#fileOf.size >= FILE_LOCATION_MEMO_ENTRIES)\n-\t\t\t\tthis.#fileOf.delete(this.#fileOf.keys().next().value!);\n-\t\t\tthis.#fileOf.set(l, file);\n-\t\t}\n-\t\treturn file;\n \t}\n \n \t/** The lines hanging off a node in this set, in layout order. */\n@@ -507,25 +573,7 @@\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\tconst fileOf = (code: number): string => this.#fileOfCode(code);\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@@ -909,13 +957,11 @@\n \t\tn += 2 * ARRAY_HEADER_BYTES + this.#membershipSeq.byteLength + this.#membershipValue.byteLength;\n \t\tif (this.#movers) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#movers.length;\n \t\tn += MAP_HEADER_BYTES; // #files exists from construction.\n-\t\tn += MAP_HEADER_BYTES; // #fileOf exists from construction.\n \t\tif (this.#stable) n += this.#stable.retainedBytes;\n \t\telse if (this.#set) n += OBJECT_BYTES + SET_ENTRY_BYTES * this.#set.size;\n \t\tif (this.#knownList) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#knownList.length;\n \t\tif (this.#relocs) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * this.#relocs.size;\n \t\tif (this.#relocsN) n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + OBJECT_BYTES) * this.#relocsN.size;\n-\t\tn += MAP_ENTRY_BYTES * this.#fileOf.size;\n \t\tfor (const f of this.#files.values()) {\n \t\t\tn += MAP_ENTRY_BYTES;\n \t\t\tif (f !== NO_FILE) {"},{"path":"worker/project/project.ts","added":11,"removed":3,"diff":"--- a/worker/project/project.ts\n+++ b/worker/project/project.ts\n@@ -2769,8 +2769,16 @@\n \t\tif (set instanceof StableSet) {\n \t\t\t// Keep indexed membership external. Only dependencies absent from\n \t\t\t// that snapshot belong in the operation's closure overlay. Over a stored closed base (abso Capacity),\n-\t\t\t// only the overlay's atoms can reach outside it.\n-\t\t\tconst walk = set instanceof StableUnionSet && isClosedSet(set.left) ? set.right : set;\n+\t\t\t// only the atoms outside it can reach outside it: unions are opened down to their closed parts.\n+\t\t\tconst walk: Iterable<AtomId>[] = [];\n+\t\t\tconst open = (part: ReadonlySet<AtomId>): void => {\n+\t\t\t\tif (isClosedSet(part)) return;\n+\t\t\t\tif (part instanceof StableUnionSet) {\n+\t\t\t\t\topen(part.left);\n+\t\t\t\t\topen(part.right);\n+\t\t\t\t} else walk.push(part);\n+\t\t\t};\n+\t\t\topen(set);\n \t\t\tconst missing = new Set<AtomId>();\n \t\t\tconst visit = (id: AtomId) => {\n \t\t\t\tconst stack = [id];\n@@ -2783,7 +2791,7 @@\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t};\n-\t\t\tfor (const id of walk) visit(id);\n+\t\t\tfor (const part of walk) for (const id of part) visit(id);\n \t\t\treturn markClosed(missing.size ? new StableUnionSet(set, new StableOverlaySet(missing)) : set);\n \t\t}\n \t\treturn this.#graph.closureOf(set);"}],"ci":null}