{"draft":null,"from":112,"to":113,"files":[{"path":"src/engine/state-source.ts","added":50,"removed":0,"diff":"--- a/src/engine/state-source.ts\n+++ b/src/engine/state-source.ts\n@@ -160,6 +160,56 @@\n const indexKey = (key: PropertyKey): key is string =>\n \ttypeof key === \"string\" && /^(0|[1-9][0-9]*)$/.test(key) && Number.isSafeInteger(Number(key));\n \n+/** Fixed-size numeric pages; callers retain no pages outside the bounded storage cache. */\n+export function storedNumbers(storage: GraphStateStorage, name: string) {\n+\tconst pageSize = 256;\n+\tconst meta = `${name}:meta`;\n+\tconst length = () => (storage.read(meta, \"length\") as number | undefined) ?? 0;\n+\t// Older experimental writer indexes must be rebuilt from their canonical log.\n+\t// Never interpret per-element rows as pages or silently lose existing history.\n+\tconst page = (index: number): number[] => {\n+\t\tif (storage.read(meta, \"format\") !== 2)\n+\t\t\tthrow new Error(`writer numeric index ${name} requires canonical-log adoption`);\n+\t\tconst values = storage.read(`${name}:pages`, String(Math.floor(index / pageSize))) as number[] | undefined;\n+\t\tif (!values) throw new Error(`missing writer numeric page in ${name}`);\n+\t\treturn values;\n+\t};\n+\treturn {\n+\t\tget length() {\n+\t\t\treturn length();\n+\t\t},\n+\t\tat(index: number): number {\n+\t\t\tif (!Number.isSafeInteger(index) || index < 0 || index >= length())\n+\t\t\t\tthrow new Error(`writer numeric index out of bounds in ${name}`);\n+\t\t\tconst value = page(index)[index % pageSize];\n+\t\t\tif (value === undefined) throw new Error(`incomplete writer numeric page in ${name}`);\n+\t\t\treturn value;\n+\t\t},\n+\t\tpush(value: number): void {\n+\t\t\tif (!Number.isSafeInteger(value)) throw new Error(\"writer numeric indexes require safe integers\");\n+\t\t\tconst index = length();\n+\t\t\tif (index > 0 && storage.read(meta, \"format\") !== 2)\n+\t\t\t\tthrow new Error(`writer numeric index ${name} requires canonical-log adoption`);\n+\t\t\tconst offset = index % pageSize;\n+\t\t\tconst values = offset === 0 ? [] : page(index);\n+\t\t\tif (values.length !== offset) throw new Error(`invalid writer numeric page length in ${name}`);\n+\t\t\tvalues.push(value);\n+\t\t\tstorage.write(`${name}:pages`, String(Math.floor(index / pageSize)), values);\n+\t\t\tif (index === 0) storage.write(meta, \"format\", 2);\n+\t\t\tstorage.write(meta, \"length\", index + 1);\n+\t\t},\n+\t\tset(index: number, value: number): void {\n+\t\t\tif (!Number.isSafeInteger(value)) throw new Error(\"writer numeric indexes require safe integers\");\n+\t\t\tif (!Number.isSafeInteger(index) || index < 0 || index >= length())\n+\t\t\t\tthrow new Error(`writer numeric index out of bounds in ${name}`);\n+\t\t\tconst values = page(index);\n+\t\t\tif (index % pageSize >= values.length) throw new Error(`incomplete writer numeric page in ${name}`);\n+\t\t\tvalues[index % pageSize] = value;\n+\t\t\tstorage.write(`${name}:pages`, String(Math.floor(index / pageSize)), values);\n+\t\t},\n+\t};\n+}\n+\n /** Array-shaped access without retaining its historical values in memory. */\n export function storedArray<T>(storage: GraphStateStorage, name: string, decode?: (value: T) => T): T[] {\n \tconst length = () => (storage.read(`${name}:meta`, \"length\") as number | undefined) ?? 0;"}],"unmatched":[]}