{"file":"src/engine/state-source.ts","version":318,"total":757,"from":1,"to":757,"lines":[{"n":1,"text":"/**","atom":"a970","author":"codex-capacity-chair","version":109},{"n":2,"text":" * Indexed graph storage. Values must be copied on write and read: a caller","atom":"a970","author":"codex-capacity-chair","version":109},{"n":3,"text":" * mutating a returned list must not silently change persisted state. Hosts","atom":"a970","author":"codex-capacity-chair","version":109},{"n":4,"text":" * provide transactions that roll back every write when the callback throws.","atom":"a970","author":"codex-capacity-chair","version":109},{"n":5,"text":" * The namespace belongs to one graph and must not be shared by concurrent","atom":"a970","author":"codex-capacity-chair","version":109},{"n":6,"text":" * Graph instances. Opening a graph does not scan its stored collections.","atom":"a970","author":"codex-capacity-chair","version":109},{"n":7,"text":" */","atom":"a970","author":"codex-capacity-chair","version":109},{"n":8,"text":"export interface GraphStateStorage {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":9,"text":"\tread(collection: string, key: string): unknown;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":10,"text":"\twrite(collection: string, key: string, value: unknown): void;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":11,"text":"\tremove(collection: string, key: string): void;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":12,"text":"\tentries(collection: string): Iterable<readonly [string, unknown]>;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":13,"text":"\ttransaction<T>(body: () => T): T;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":14,"text":"}","atom":"a970","author":"codex-capacity-chair","version":109},{"n":15,"text":"","atom":"a970","author":"codex-capacity-chair","version":109},{"n":16,"text":"/**","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":17,"text":" * Operation-local read cache with fixed payload and entry limits. Private numeric","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":18,"text":" * pages, immutable scalars and serialized objects preserve the copy contract. Discard it after an outer host","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":19,"text":" * rollback or any mutation made through another storage instance.","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":20,"text":" */","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":21,"text":"type CachedValue = { bytes: number } & (","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":22,"text":"\t| { kind: \"scalar\"; value: string | number | boolean | null | undefined }","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":23,"text":"\t| { kind: \"numbers\"; value: readonly number[] }","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":24,"text":"\t| { kind: \"json\"; json: string }","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":25,"text":");","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":26,"text":"","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":27,"text":"export class CachedStateStorage implements GraphStateStorage {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":28,"text":"\treadonly #source: GraphStateStorage;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":29,"text":"\treadonly #cache = new Map<string, CachedValue>();","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":30,"text":"\treadonly #maxBytes: number;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":31,"text":"\treadonly #maxEntries: number;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":32,"text":"\t#bytes = 0;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":33,"text":"\t/**","atom":"a2589","author":"capacity","version":253},{"n":34,"text":"\t * The keys written or removed in each open transaction, innermost last (abso Capacity). A rollback drops only those:","atom":"a2589","author":"capacity","version":253},{"n":35,"text":"\t * every projection scratch scope ends in a rollback, and dropping the whole cache there read the same rows from","atom":"a2589","author":"capacity","version":253},{"n":36,"text":"\t * storage again within a call and on every call of a kept reader.","atom":"a2589","author":"capacity","version":253},{"n":37,"text":"\t */","atom":"a2589","author":"capacity","version":253},{"n":38,"text":"\treadonly #touched: Set<string>[] = [];","atom":"a2589","author":"capacity","version":253},{"n":39,"text":"\t/**","atom":"a2594","author":"capacity","version":253},{"n":40,"text":"\t * The biggest one row may be and still be kept (abso Capacity). A few big rows read on every call (each agent with","atom":"a2594","author":"capacity","version":253},{"n":41,"text":"\t * all the news it was told: 4.3 MB for abso's 109 agents) otherwise push every small page out of the cache.","atom":"a2594","author":"capacity","version":253},{"n":42,"text":"\t */","atom":"a2594","author":"capacity","version":253},{"n":43,"text":"\treadonly #maxEntryBytes: number;","atom":"a2594","author":"capacity","version":253},{"n":44,"text":"\tconstructor(source: GraphStateStorage, maxBytes = 1_048_576, maxEntries = 4096, maxEntryBytes = maxBytes) {","atom":"a2643","author":"capacity","version":260},{"n":45,"text":"\t\tif (","atom":"a2594","author":"capacity","version":253},{"n":46,"text":"\t\t\t!Number.isSafeInteger(maxBytes) ||","atom":"a2594","author":"capacity","version":253},{"n":47,"text":"\t\t\tmaxBytes < 0 ||","atom":"a2594","author":"capacity","version":253},{"n":48,"text":"\t\t\t!Number.isSafeInteger(maxEntries) ||","atom":"a2594","author":"capacity","version":253},{"n":49,"text":"\t\t\tmaxEntries < 0 ||","atom":"a2594","author":"capacity","version":253},{"n":50,"text":"\t\t\t!Number.isSafeInteger(maxEntryBytes) ||","atom":"a2594","author":"capacity","version":253},{"n":51,"text":"\t\t\tmaxEntryBytes < 0","atom":"a2594","author":"capacity","version":253},{"n":52,"text":"\t\t)","atom":"a2594","author":"capacity","version":253},{"n":53,"text":"\t\t\tthrow new Error(\"invalid writer cache limits\");","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":54,"text":"\t\tthis.#source = source;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":55,"text":"\t\tthis.#maxBytes = maxBytes;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":56,"text":"\t\tthis.#maxEntries = maxEntries;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":57,"text":"\t\tthis.#maxEntryBytes = Math.min(maxEntryBytes, maxBytes);","atom":"a2594","author":"capacity","version":253},{"n":58,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":59,"text":"\tget retainedBytes(): number {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":60,"text":"\t\treturn this.#bytes;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":61,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":62,"text":"\tget retainedEntries(): number {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":63,"text":"\t\treturn this.#cache.size;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":64,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":65,"text":"\tclear(): void {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":66,"text":"\t\tthis.#cache.clear();","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":67,"text":"\t\tthis.#bytes = 0;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":68,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":69,"text":"\t#drop(key: string): void {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":70,"text":"\t\tconst previous = this.#cache.get(key);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":71,"text":"\t\tif (previous) {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":72,"text":"\t\t\tthis.#cache.delete(key);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":73,"text":"\t\t\tthis.#bytes -= previous.bytes;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":74,"text":"\t\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":75,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":76,"text":"\tread(collection: string, key: string): unknown {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":77,"text":"\t\tconst cacheKey = JSON.stringify([collection, key]);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":78,"text":"\t\tconst hit = this.#cache.get(cacheKey);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":79,"text":"\t\tif (hit) {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":80,"text":"\t\t\tthis.#cache.delete(cacheKey);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":81,"text":"\t\t\tthis.#cache.set(cacheKey, hit);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":82,"text":"\t\t\tif (hit.kind === \"scalar\") return hit.value;","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":83,"text":"\t\t\tif (hit.kind === \"numbers\") return hit.value.slice();","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":84,"text":"\t\t\treturn (JSON.parse(hit.json) as { value?: unknown }).value;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":85,"text":"\t\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":86,"text":"\t\tconst value = this.#source.read(collection, key);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":87,"text":"\t\tconst overhead = 2 * cacheKey.length + 160;","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":88,"text":"\t\tlet entry: CachedValue;","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":89,"text":"\t\tif (","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":90,"text":"\t\t\tvalue === undefined ||","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":91,"text":"\t\t\tvalue === null ||","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":92,"text":"\t\t\ttypeof value === \"string\" ||","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":93,"text":"\t\t\ttypeof value === \"boolean\" ||","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":94,"text":"\t\t\t(typeof value === \"number\" && Number.isFinite(value))","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":95,"text":"\t\t) {","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":96,"text":"\t\t\tentry = { kind: \"scalar\", value, bytes: overhead + (typeof value === \"string\" ? 2 * value.length : 16) };","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":97,"text":"\t\t} else if (","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":98,"text":"\t\t\tArray.isArray(value) &&","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":99,"text":"\t\t\tvalue.length <= 256 &&","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":100,"text":"\t\t\tObject.keys(value).length === value.length &&","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":101,"text":"\t\t\tvalue.every(Number.isSafeInteger)","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":102,"text":"\t\t) {","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":103,"text":"\t\t\t// Store one private, bounded numeric page. Public reads still receive a","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":104,"text":"\t\t\t// fresh copy; neither the source result nor a reader can mutate the cache.","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":105,"text":"\t\t\tentry = { kind: \"numbers\", value: value.slice(), bytes: overhead + 32 + value.length * 8 };","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":106,"text":"\t\t} else {","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":107,"text":"\t\t\tconst json = JSON.stringify({ value });","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":108,"text":"\t\t\tentry = { kind: \"json\", json, bytes: overhead + 2 * json.length };","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":109,"text":"\t\t}","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":110,"text":"\t\tthis.#remember(cacheKey, entry);","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":111,"text":"\t\t// A projection scope's own rows are never read again once it ends in its rollback: forget them with it.","atom":"a2593","author":"capacity","version":253},{"n":112,"text":"\t\tif (collection.startsWith(\"projection-scratch:\")) this.#touched.at(-1)?.add(cacheKey);","atom":"a2593","author":"capacity","version":253},{"n":113,"text":"\t\treturn value;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":114,"text":"\t}","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":115,"text":"\t#remember(cacheKey: string, entry: CachedValue): void {","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":116,"text":"\t\tthis.#drop(cacheKey);","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":117,"text":"\t\t// Payload accounting is bounded, not a measurement of actual isolate heap.","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":118,"text":"\t\tif (entry.bytes <= this.#maxEntryBytes && this.#maxEntries > 0) {","atom":"a2595","author":"capacity","version":253},{"n":119,"text":"\t\t\twhile (this.#bytes + entry.bytes > this.#maxBytes || this.#cache.size >= this.#maxEntries)","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":120,"text":"\t\t\t\tthis.#drop(this.#cache.keys().next().value!);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":121,"text":"\t\t\tthis.#cache.set(cacheKey, entry);","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":122,"text":"\t\t\tthis.#bytes += entry.bytes;","atom":"a1133","author":"codex-capacity-chair","version":136},{"n":123,"text":"\t\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":124,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":125,"text":"\twrite(collection: string, key: string, value: unknown): void {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":126,"text":"\t\tconst cacheKey = JSON.stringify([collection, key]);","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":127,"text":"\t\tthis.#drop(cacheKey);","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":128,"text":"\t\tthis.#touched.at(-1)?.add(cacheKey);","atom":"a2590","author":"capacity","version":253},{"n":129,"text":"\t\tthis.#source.write(collection, key, value);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":130,"text":"\t\t// Allocation counters are immutable scalars. Keep successful writes within","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":131,"text":"\t\t// the existing cache budget instead of immediately reading them back.","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":132,"text":"\t\tif (typeof value === \"number\" && Number.isSafeInteger(value) && !Object.is(value, -0))","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":133,"text":"\t\t\tthis.#remember(cacheKey, { kind: \"scalar\", value, bytes: 2 * cacheKey.length + 176 });","atom":"a1377","author":"codex-capacity-chair","version":145},{"n":134,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":135,"text":"\tremove(collection: string, key: string): void {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":136,"text":"\t\tconst cacheKey = JSON.stringify([collection, key]);","atom":"a2591","author":"capacity","version":253},{"n":137,"text":"\t\tthis.#drop(cacheKey);","atom":"a2591","author":"capacity","version":253},{"n":138,"text":"\t\tthis.#touched.at(-1)?.add(cacheKey);","atom":"a2591","author":"capacity","version":253},{"n":139,"text":"\t\tthis.#source.remove(collection, key);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":140,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":141,"text":"\tentries(collection: string): Iterable<readonly [string, unknown]> {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":142,"text":"\t\treturn this.#source.entries(collection);","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":143,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":144,"text":"\ttransaction<T>(body: () => T): T {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":145,"text":"\t\tconst touched = new Set<string>();","atom":"a2592","author":"capacity","version":253},{"n":146,"text":"\t\tthis.#touched.push(touched);","atom":"a2592","author":"capacity","version":253},{"n":147,"text":"\t\ttry {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":148,"text":"\t\t\tconst result = this.#source.transaction(body);","atom":"a2592","author":"capacity","version":253},{"n":149,"text":"\t\t\tthis.#touched.pop();","atom":"a2592","author":"capacity","version":253},{"n":150,"text":"\t\t\t// Committed into the outer transaction, which may still roll back.","atom":"a2592","author":"capacity","version":253},{"n":151,"text":"\t\t\tconst outer = this.#touched.at(-1);","atom":"a2592","author":"capacity","version":253},{"n":152,"text":"\t\t\tif (outer) for (const key of touched) outer.add(key);","atom":"a2592","author":"capacity","version":253},{"n":153,"text":"\t\t\treturn result;","atom":"a2592","author":"capacity","version":253},{"n":154,"text":"\t\t} catch (error) {","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":155,"text":"\t\t\tthis.#touched.pop();","atom":"a2592","author":"capacity","version":253},{"n":156,"text":"\t\t\t// What the transaction wrote, and anything read back after it wrote it, is gone with the rollback.","atom":"a2592","author":"capacity","version":253},{"n":157,"text":"\t\t\tfor (const key of touched) this.#drop(key);","atom":"a2592","author":"capacity","version":253},{"n":158,"text":"\t\t\tthrow error;","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":159,"text":"\t\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":160,"text":"\t}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":161,"text":"}","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":162,"text":"","atom":"a1011","author":"codex-capacity-chair","version":111},{"n":163,"text":"/**","atom":"a2300","author":"capacity","version":205},{"n":164,"text":" * Sets known to be closed under dependencies (abso Capacity): every atom's deps are in the set. A view or a project","atom":"a2300","author":"capacity","version":205},{"n":165,"text":" * given one skips proving it again, which read every atom and every dependency in the history.","atom":"a2300","author":"capacity","version":205},{"n":166,"text":" */","atom":"a2300","author":"capacity","version":205},{"n":167,"text":"const closedSets = new WeakSet<object>();","atom":"a2300","author":"capacity","version":205},{"n":168,"text":"export function markClosed<S extends ReadonlySet<unknown>>(set: S): S {","atom":"a2300","author":"capacity","version":205},{"n":169,"text":"\tclosedSets.add(set);","atom":"a2300","author":"capacity","version":205},{"n":170,"text":"\treturn set;","atom":"a2300","author":"capacity","version":205},{"n":171,"text":"}","atom":"a2300","author":"capacity","version":205},{"n":172,"text":"export function isClosedSet(set: unknown): boolean {","atom":"a2300","author":"capacity","version":205},{"n":173,"text":"\treturn typeof set === \"object\" && set !== null && closedSets.has(set);","atom":"a2300","author":"capacity","version":205},{"n":174,"text":"}","atom":"a2300","author":"capacity","version":205},{"n":175,"text":"","atom":"a2300","author":"capacity","version":205},{"n":176,"text":"/** Immutable membership whose implementation does not retain its enumerated keys. */","atom":"a996","author":"codex-capacity-chair","version":109},{"n":177,"text":"export abstract class StableSet<T> implements ReadonlySet<T> {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":178,"text":"\tabstract has(value: T): boolean;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":179,"text":"\tabstract values(): SetIterator<T>;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":180,"text":"\t/** Only resident membership data; external storage is not charged as heap. */","atom":"a996","author":"codex-capacity-chair","version":109},{"n":181,"text":"\tabstract readonly retainedBytes: number;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":182,"text":"\tget [Symbol.toStringTag](): string {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":183,"text":"\t\treturn \"Set\";","atom":"a996","author":"codex-capacity-chair","version":109},{"n":184,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":185,"text":"\tget size(): number {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":186,"text":"\t\tlet count = 0;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":187,"text":"\t\tfor (const _ of this) count++;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":188,"text":"\t\treturn count;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":189,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":190,"text":"\tkeys(): SetIterator<T> {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":191,"text":"\t\treturn this.values();","atom":"a996","author":"codex-capacity-chair","version":109},{"n":192,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":193,"text":"\t*entries(): SetIterator<[T, T]> {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":194,"text":"\t\tfor (const value of this) yield [value, value];","atom":"a996","author":"codex-capacity-chair","version":109},{"n":195,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":196,"text":"\t[Symbol.iterator](): SetIterator<T> {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":197,"text":"\t\treturn this.values();","atom":"a996","author":"codex-capacity-chair","version":109},{"n":198,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":199,"text":"\tforEach(callback: (value: T, key: T, set: ReadonlySet<T>) => void, thisArg?: unknown): void {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":200,"text":"\t\tfor (const value of this) callback.call(thisArg, value, value, this);","atom":"a996","author":"codex-capacity-chair","version":109},{"n":201,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":202,"text":"}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":203,"text":"","atom":"a996","author":"codex-capacity-chair","version":109},{"n":204,"text":"/** Both operands must be immutable for the lifetime of this union. */","atom":"a996","author":"codex-capacity-chair","version":109},{"n":205,"text":"export class StableUnionSet<T> extends StableSet<T> {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":206,"text":"\treadonly #left: StableSet<T>;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":207,"text":"\treadonly #right: StableSet<T>;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":208,"text":"\tconstructor(left: StableSet<T>, right: StableSet<T>) {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":209,"text":"\t\tsuper();","atom":"a996","author":"codex-capacity-chair","version":109},{"n":210,"text":"\t\tthis.#left = left;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":211,"text":"\t\tthis.#right = right;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":212,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":213,"text":"\tget retainedBytes(): number {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":214,"text":"\t\treturn 32 + this.#left.retainedBytes + this.#right.retainedBytes;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":215,"text":"\t}","atom":"a2300","author":"capacity","version":205},{"n":216,"text":"\tget left(): StableSet<T> {","atom":"a2300","author":"capacity","version":205},{"n":217,"text":"\t\treturn this.#left;","atom":"a2300","author":"capacity","version":205},{"n":218,"text":"\t}","atom":"a2300","author":"capacity","version":205},{"n":219,"text":"\tget right(): StableSet<T> {","atom":"a2300","author":"capacity","version":205},{"n":220,"text":"\t\treturn this.#right;","atom":"a2300","author":"capacity","version":205},{"n":221,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":222,"text":"\thas(value: T): boolean {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":223,"text":"\t\treturn this.#left.has(value) || this.#right.has(value);","atom":"a996","author":"codex-capacity-chair","version":109},{"n":224,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":225,"text":"\t*values(): SetIterator<T> {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":226,"text":"\t\tyield* this.#left;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":227,"text":"\t\tfor (const value of this.#right) if (!this.#left.has(value)) yield value;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":228,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":229,"text":"}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":230,"text":"","atom":"a996","author":"codex-capacity-chair","version":109},{"n":231,"text":"/** Immutable indexed subtraction retains neither operand's enumerated values. */","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":232,"text":"export class StableDifferenceSet<T> extends StableSet<T> {","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":233,"text":"\treadonly left: StableSet<T>;","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":234,"text":"\treadonly right: StableSet<T>;","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":235,"text":"\tconstructor(left: StableSet<T>, right: StableSet<T>) {","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":236,"text":"\t\tsuper();","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":237,"text":"\t\tthis.left = left;","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":238,"text":"\t\tthis.right = right;","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":239,"text":"\t}","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":240,"text":"\tget retainedBytes(): number {","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":241,"text":"\t\treturn 32 + this.left.retainedBytes + this.right.retainedBytes;","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":242,"text":"\t}","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":243,"text":"\thas(value: T): boolean {","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":244,"text":"\t\treturn this.left.has(value) && !this.right.has(value);","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":245,"text":"\t}","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":246,"text":"\t*values(): SetIterator<T> {","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":247,"text":"\t\tfor (const value of this.left) if (!this.right.has(value)) yield value;","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":248,"text":"\t}","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":249,"text":"}","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":250,"text":"","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":251,"text":"/** Preserve indexed history; only the caller's operation-sized overlay is copied. */","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":252,"text":"export function unionOverlay<T>(base: ReadonlySet<T>, overlay: Iterable<T>): ReadonlySet<T> {","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":253,"text":"\treturn base instanceof StableSet","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":254,"text":"\t\t? new StableUnionSet(base, new StableOverlaySet(overlay))","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":255,"text":"\t\t: new Set([...base, ...overlay]);","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":256,"text":"}","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":257,"text":"","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":258,"text":"/** Both indexed operands must be immutable for the lifetime of the result. */","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":259,"text":"export function differenceSet<T>(left: ReadonlySet<T>, right: ReadonlySet<T>): ReadonlySet<T> {","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":260,"text":"\treturn left instanceof StableSet && right instanceof StableSet","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":261,"text":"\t\t? new StableDifferenceSet(left, right)","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":262,"text":"\t\t: new Set([...left].filter((value) => !right.has(value)));","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":263,"text":"}","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":264,"text":"","atom":"a1116","author":"codex-capacity-chair","version":133},{"n":265,"text":"/** An immutable snapshot for the operation's small overlay, not its history. */","atom":"a996","author":"codex-capacity-chair","version":109},{"n":266,"text":"export class StableOverlaySet<T> extends StableSet<T> {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":267,"text":"\treadonly #values: Set<T>;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":268,"text":"\tconstructor(values: Iterable<T>) {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":269,"text":"\t\tsuper();","atom":"a996","author":"codex-capacity-chair","version":109},{"n":270,"text":"\t\tthis.#values = new Set(values);","atom":"a996","author":"codex-capacity-chair","version":109},{"n":271,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":272,"text":"\tget retainedBytes(): number {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":273,"text":"\t\treturn 64 + this.#values.size * 32;","atom":"a996","author":"codex-capacity-chair","version":109},{"n":274,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":275,"text":"\thas(value: T): boolean {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":276,"text":"\t\treturn this.#values.has(value);","atom":"a996","author":"codex-capacity-chair","version":109},{"n":277,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":278,"text":"\tvalues(): SetIterator<T> {","atom":"a996","author":"codex-capacity-chair","version":109},{"n":279,"text":"\t\treturn this.#values.values();","atom":"a996","author":"codex-capacity-chair","version":109},{"n":280,"text":"\t}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":281,"text":"}","atom":"a996","author":"codex-capacity-chair","version":109},{"n":282,"text":"","atom":"a996","author":"codex-capacity-chair","version":109},{"n":283,"text":"const indexKey = (key: PropertyKey): key is string =>","atom":"a970","author":"codex-capacity-chair","version":109},{"n":284,"text":"\ttypeof key === \"string\" && /^(0|[1-9][0-9]*)$/.test(key) && Number.isSafeInteger(Number(key));","atom":"a970","author":"codex-capacity-chair","version":109},{"n":285,"text":"","atom":"a970","author":"codex-capacity-chair","version":109},{"n":286,"text":"/** Fixed-size numeric pages; callers retain no pages outside the bounded storage cache. */","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":287,"text":"export function storedNumbers(storage: GraphStateStorage, name: string) {","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":288,"text":"\tconst pageSize = 256;","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":289,"text":"\tconst meta = `${name}:meta`;","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":290,"text":"\tconst length = () => (storage.read(meta, \"length\") as number | undefined) ?? 0;","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":291,"text":"\t// Older experimental writer indexes must be rebuilt from their canonical log.","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":292,"text":"\t// Never interpret per-element rows as pages or silently lose existing history.","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":293,"text":"\tconst page = (index: number): number[] => {","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":294,"text":"\t\tif (storage.read(meta, \"format\") !== 2)","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":295,"text":"\t\t\tthrow new Error(`writer numeric index ${name} requires canonical-log adoption`);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":296,"text":"\t\tconst values = storage.read(`${name}:pages`, String(Math.floor(index / pageSize))) as number[] | undefined;","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":297,"text":"\t\tif (!values) throw new Error(`missing writer numeric page in ${name}`);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":298,"text":"\t\treturn values;","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":299,"text":"\t};","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":300,"text":"\treturn {","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":301,"text":"\t\tget length() {","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":302,"text":"\t\t\treturn length();","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":303,"text":"\t\t},","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":304,"text":"\t\tat(index: number): number {","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":305,"text":"\t\t\tif (!Number.isSafeInteger(index) || index < 0 || index >= length())","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":306,"text":"\t\t\t\tthrow new Error(`writer numeric index out of bounds in ${name}`);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":307,"text":"\t\t\tconst value = page(index)[index % pageSize];","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":308,"text":"\t\t\tif (value === undefined) throw new Error(`incomplete writer numeric page in ${name}`);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":309,"text":"\t\t\treturn value;","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":310,"text":"\t\t},","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":311,"text":"\t\tpush(value: number): void {","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":312,"text":"\t\t\tif (!Number.isSafeInteger(value)) throw new Error(\"writer numeric indexes require safe integers\");","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":313,"text":"\t\t\tconst index = length();","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":314,"text":"\t\t\tif (index > 0 && storage.read(meta, \"format\") !== 2)","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":315,"text":"\t\t\t\tthrow new Error(`writer numeric index ${name} requires canonical-log adoption`);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":316,"text":"\t\t\tconst offset = index % pageSize;","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":317,"text":"\t\t\tconst values = offset === 0 ? [] : page(index);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":318,"text":"\t\t\tif (values.length !== offset) throw new Error(`invalid writer numeric page length in ${name}`);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":319,"text":"\t\t\tvalues.push(value);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":320,"text":"\t\t\tstorage.write(`${name}:pages`, String(Math.floor(index / pageSize)), values);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":321,"text":"\t\t\tif (index === 0) storage.write(meta, \"format\", 2);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":322,"text":"\t\t\tstorage.write(meta, \"length\", index + 1);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":323,"text":"\t\t},","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":324,"text":"\t\tset(index: number, value: number): void {","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":325,"text":"\t\t\tif (!Number.isSafeInteger(value)) throw new Error(\"writer numeric indexes require safe integers\");","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":326,"text":"\t\t\tif (!Number.isSafeInteger(index) || index < 0 || index >= length())","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":327,"text":"\t\t\t\tthrow new Error(`writer numeric index out of bounds in ${name}`);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":328,"text":"\t\t\tconst values = page(index);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":329,"text":"\t\t\tif (index % pageSize >= values.length) throw new Error(`incomplete writer numeric page in ${name}`);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":330,"text":"\t\t\tvalues[index % pageSize] = value;","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":331,"text":"\t\t\tstorage.write(`${name}:pages`, String(Math.floor(index / pageSize)), values);","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":332,"text":"\t\t},","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":333,"text":"\t};","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":334,"text":"}","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":335,"text":"","atom":"a1020","author":"codex-capacity-chair","version":113},{"n":336,"text":"/** Array-shaped access without retaining its historical values in memory. */","atom":"a970","author":"codex-capacity-chair","version":109},{"n":337,"text":"export function storedArray<T>(","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":338,"text":"\tstorage: GraphStateStorage,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":339,"text":"\tname: string,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":340,"text":"\tdecode?: (value: T) => T,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":341,"text":"\tencode?: (value: T, key: string) => unknown,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":342,"text":"): T[] {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":343,"text":"\tconst length = () => (storage.read(`${name}:meta`, \"length\") as number | undefined) ?? 0;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":344,"text":"\tconst read = (key: string) => {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":345,"text":"\t\tconst value = storage.read(name, key) as T;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":346,"text":"\t\treturn value === undefined || !decode ? value : decode(value);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":347,"text":"\t};","atom":"a970","author":"codex-capacity-chair","version":109},{"n":348,"text":"\treturn new Proxy([] as T[], {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":349,"text":"\t\tget(target, key, receiver) {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":350,"text":"\t\t\tif (key === \"length\") return length();","atom":"a970","author":"codex-capacity-chair","version":109},{"n":351,"text":"\t\t\t// No length read first (abso Capacity): set writes the row and the length together and nothing shrinks, so no","atom":"a2726","author":"capacity","version":274},{"n":352,"text":"\t\t\t// row lies past the length. Half of a cold layout's reads were this length.","atom":"a2726","author":"capacity","version":274},{"n":353,"text":"\t\t\tif (indexKey(key)) return read(key);","atom":"a2726","author":"capacity","version":274},{"n":354,"text":"\t\t\treturn Reflect.get(target, key, receiver);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":355,"text":"\t\t},","atom":"a970","author":"codex-capacity-chair","version":109},{"n":356,"text":"\t\tset(_target, key, value) {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":357,"text":"\t\t\tif (key === \"length\") {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":358,"text":"\t\t\t\tif (value !== length()) throw new Error(\"stored graph arrays cannot be resized directly\");","atom":"a970","author":"codex-capacity-chair","version":109},{"n":359,"text":"\t\t\t\treturn true;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":360,"text":"\t\t\t}","atom":"a970","author":"codex-capacity-chair","version":109},{"n":361,"text":"\t\t\tif (!indexKey(key)) throw new Error(\"invalid stored graph array property\");","atom":"a970","author":"codex-capacity-chair","version":109},{"n":362,"text":"\t\t\tconst index = Number(key);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":363,"text":"\t\t\tconst size = length();","atom":"a970","author":"codex-capacity-chair","version":109},{"n":364,"text":"\t\t\tif (index > size) throw new Error(\"stored graph arrays cannot contain gaps\");","atom":"a970","author":"codex-capacity-chair","version":109},{"n":365,"text":"\t\t\tstorage.write(name, key, encode ? encode(value, key) : value);","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":366,"text":"\t\t\tif (index === size) storage.write(`${name}:meta`, \"length\", size + 1);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":367,"text":"\t\t\treturn true;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":368,"text":"\t\t},","atom":"a970","author":"codex-capacity-chair","version":109},{"n":369,"text":"\t\thas(target, key) {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":370,"text":"\t\t\treturn indexKey(key) ? Number(key) < length() : Reflect.has(target, key);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":371,"text":"\t\t},","atom":"a970","author":"codex-capacity-chair","version":109},{"n":372,"text":"\t\townKeys() {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":373,"text":"\t\t\treturn [...Array.from({ length: length() }, (_, index) => String(index)), \"length\"];","atom":"a970","author":"codex-capacity-chair","version":109},{"n":374,"text":"\t\t},","atom":"a970","author":"codex-capacity-chair","version":109},{"n":375,"text":"\t\tgetOwnPropertyDescriptor(target, key) {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":376,"text":"\t\t\tif (indexKey(key) && Number(key) < length())","atom":"a970","author":"codex-capacity-chair","version":109},{"n":377,"text":"\t\t\t\treturn { configurable: true, enumerable: true, writable: true, value: read(key) };","atom":"a970","author":"codex-capacity-chair","version":109},{"n":378,"text":"\t\t\treturn Reflect.getOwnPropertyDescriptor(target, key);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":379,"text":"\t\t},","atom":"a970","author":"codex-capacity-chair","version":109},{"n":380,"text":"\t});","atom":"a970","author":"codex-capacity-chair","version":109},{"n":381,"text":"}","atom":"a970","author":"codex-capacity-chair","version":109},{"n":382,"text":"","atom":"a970","author":"codex-capacity-chair","version":109},{"n":383,"text":"export interface StateMap<K, V> {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":384,"text":"\tkeys(): IterableIterator<K>;","atom":"a1038","author":"codex-capacity-chair","version":118},{"n":385,"text":"\tget(key: K): V | undefined;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":386,"text":"\tset(key: K, value: V): StateMap<K, V>;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":387,"text":"\thas(key: K): boolean;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":388,"text":"\tdelete(key: K): boolean;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":389,"text":"\tvalues(): IterableIterator<V>;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":390,"text":"}","atom":"a970","author":"codex-capacity-chair","version":109},{"n":391,"text":"","atom":"a970","author":"codex-capacity-chair","version":109},{"n":392,"text":"/** Append-only per-key lists, retaining at most one fixed-size page per iterator. */","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":393,"text":"export function storedLists<V>(","atom":"a1050","author":"codex-capacity-chair","version":120},{"n":394,"text":"\tstorage: GraphStateStorage,","atom":"a1050","author":"codex-capacity-chair","version":120},{"n":395,"text":"\tname: string,","atom":"a1050","author":"codex-capacity-chair","version":120},{"n":396,"text":"\tlegacyKey = (key: string) => JSON.stringify([\"string\", key]),","atom":"a1050","author":"codex-capacity-chair","version":120},{"n":397,"text":") {","atom":"a1050","author":"codex-capacity-chair","version":120},{"n":398,"text":"\tconst pageSize = 256;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":399,"text":"\t// The previous experimental layout stored one whole historical list per key.","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":400,"text":"\tconst length = (key: string) => {","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":401,"text":"\t\tconst stored = storage.read(`${name}:lengths`, key) as number | undefined;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":402,"text":"\t\tif (stored === undefined && storage.read(name, legacyKey(key)) !== undefined)","atom":"a1050","author":"codex-capacity-chair","version":120},{"n":403,"text":"\t\t\tthrow new Error(`writer list index ${name} requires canonical-log adoption`);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":404,"text":"\t\tconst count = stored ?? 0;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":405,"text":"\t\tif (!Number.isSafeInteger(count) || count < 0) throw new Error(`invalid writer list count in ${name}`);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":406,"text":"\t\treturn count;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":407,"text":"\t};","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":408,"text":"\tconst pageKey = (key: string, page: number) => JSON.stringify([key, page]);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":409,"text":"\tconst page = (key: string, index: number): V[] => {","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":410,"text":"\t\tconst values = storage.read(`${name}:pages`, pageKey(key, index)) as V[] | undefined;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":411,"text":"\t\tif (!Array.isArray(values) || values.length < 1 || values.length > pageSize)","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":412,"text":"\t\t\tthrow new Error(`missing or invalid writer list page in ${name}`);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":413,"text":"\t\treturn values;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":414,"text":"\t};","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":415,"text":"\treturn {","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":416,"text":"\t\tlength,","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":417,"text":"\t\t*keys(): IterableIterator<string> {","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":418,"text":"\t\t\tfor (const entry of storage.entries(name)) {","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":419,"text":"\t\t\t\tvoid entry;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":420,"text":"\t\t\t\tthrow new Error(`writer list index ${name} requires canonical-log adoption`);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":421,"text":"\t\t\t}","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":422,"text":"\t\t\tfor (const [key] of storage.entries(`${name}:lengths`)) yield key;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":423,"text":"\t\t},","atom":"a2726","author":"capacity","version":274},{"n":424,"text":"\t\t/** Values [index * PAGE, (index + 1) * PAGE) of `key`'s list: one page, not the whole list (abso Capacity). */","atom":"a2726","author":"capacity","version":274},{"n":425,"text":"\t\tpageAt(key: string, index: number): readonly V[] {","atom":"a2726","author":"capacity","version":274},{"n":426,"text":"\t\t\tconst count = length(key);","atom":"a2726","author":"capacity","version":274},{"n":427,"text":"\t\t\tconst values = page(key, index);","atom":"a2726","author":"capacity","version":274},{"n":428,"text":"\t\t\tif (values.length !== Math.min(pageSize, count - index * pageSize))","atom":"a2726","author":"capacity","version":274},{"n":429,"text":"\t\t\t\tthrow new Error(`incomplete writer list page in ${name}`);","atom":"a2726","author":"capacity","version":274},{"n":430,"text":"\t\t\treturn values;","atom":"a2726","author":"capacity","version":274},{"n":431,"text":"\t\t},","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":432,"text":"\t\t*values(key: string): IterableIterator<V> {","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":433,"text":"\t\t\tconst count = length(key);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":434,"text":"\t\t\tfor (let start = 0; start < count; start += pageSize) {","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":435,"text":"\t\t\t\tconst values = page(key, start / pageSize);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":436,"text":"\t\t\t\tif (values.length !== Math.min(pageSize, count - start))","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":437,"text":"\t\t\t\t\tthrow new Error(`incomplete writer list page in ${name}`);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":438,"text":"\t\t\t\tyield* values;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":439,"text":"\t\t\t}","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":440,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":441,"text":"\t\tlast(key: string): V | undefined {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":442,"text":"\t\t\tconst count = length(key);","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":443,"text":"\t\t\tif (count === 0) return undefined;","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":444,"text":"\t\t\tconst values = page(key, Math.floor((count - 1) / pageSize));","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":445,"text":"\t\t\tconst expected = ((count - 1) % pageSize) + 1;","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":446,"text":"\t\t\tif (values.length !== expected) throw new Error(`incomplete writer list page in ${name}`);","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":447,"text":"\t\t\treturn values[expected - 1];","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":448,"text":"\t\t},","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":449,"text":"\t\tappend(key: string, value: V): void {","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":450,"text":"\t\t\tconst count = length(key);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":451,"text":"\t\t\tconst offset = count % pageSize;","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":452,"text":"\t\t\tconst index = Math.floor(count / pageSize);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":453,"text":"\t\t\tconst values = offset === 0 ? [] : page(key, index);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":454,"text":"\t\t\tif (values.length !== offset) throw new Error(`invalid writer list length in ${name}`);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":455,"text":"\t\t\tvalues.push(value);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":456,"text":"\t\t\tstorage.write(`${name}:pages`, pageKey(key, index), values);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":457,"text":"\t\t\tstorage.write(`${name}:lengths`, key, count + 1);","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":458,"text":"\t\t},","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":459,"text":"\t\t/** Append several values, writing each page they touch once. */","atom":"a2310","author":"capacity","version":206},{"n":460,"text":"\t\tappendAll(key: string, more: readonly V[]): void {","atom":"a2310","author":"capacity","version":206},{"n":461,"text":"\t\t\tif (more.length === 0) return;","atom":"a2310","author":"capacity","version":206},{"n":462,"text":"\t\t\tconst count = length(key);","atom":"a2310","author":"capacity","version":206},{"n":463,"text":"\t\t\tlet index = Math.floor(count / pageSize);","atom":"a2310","author":"capacity","version":206},{"n":464,"text":"\t\t\tlet values = count % pageSize === 0 ? [] : page(key, index);","atom":"a2310","author":"capacity","version":206},{"n":465,"text":"\t\t\tif (values.length !== count % pageSize) throw new Error(`invalid writer list length in ${name}`);","atom":"a2310","author":"capacity","version":206},{"n":466,"text":"\t\t\tfor (const value of more) {","atom":"a2310","author":"capacity","version":206},{"n":467,"text":"\t\t\t\tif (values.length === pageSize) {","atom":"a2310","author":"capacity","version":206},{"n":468,"text":"\t\t\t\t\tstorage.write(`${name}:pages`, pageKey(key, index++), values);","atom":"a2310","author":"capacity","version":206},{"n":469,"text":"\t\t\t\t\tvalues = [];","atom":"a2310","author":"capacity","version":206},{"n":470,"text":"\t\t\t\t}","atom":"a2310","author":"capacity","version":206},{"n":471,"text":"\t\t\t\tvalues.push(value);","atom":"a2310","author":"capacity","version":206},{"n":472,"text":"\t\t\t}","atom":"a2310","author":"capacity","version":206},{"n":473,"text":"\t\t\tstorage.write(`${name}:pages`, pageKey(key, index), values);","atom":"a2310","author":"capacity","version":206},{"n":474,"text":"\t\t\tstorage.write(`${name}:lengths`, key, count + more.length);","atom":"a2310","author":"capacity","version":206},{"n":475,"text":"\t\t},","atom":"a2310","author":"capacity","version":206},{"n":476,"text":"\t};","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":477,"text":"}","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":478,"text":"","atom":"a1043","author":"codex-capacity-chair","version":119},{"n":479,"text":"/** Keys are tagged so numeric graph codes cannot collide with string keys. */","atom":"a970","author":"codex-capacity-chair","version":109},{"n":480,"text":"export function storedMap<K extends string | number, V>(storage: GraphStateStorage, name: string): StateMap<K, V> {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":481,"text":"\tconst keyOf = (key: K) => JSON.stringify([typeof key, key]);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":482,"text":"\tconst map: StateMap<K, V> = {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":483,"text":"\t\t*keys() {","atom":"a1038","author":"codex-capacity-chair","version":118},{"n":484,"text":"\t\t\tfor (const [key] of storage.entries(name)) yield (JSON.parse(key) as [string, K])[1];","atom":"a1038","author":"codex-capacity-chair","version":118},{"n":485,"text":"\t\t},","atom":"a1038","author":"codex-capacity-chair","version":118},{"n":486,"text":"\t\tget: (key) => storage.read(name, keyOf(key)) as V | undefined,","atom":"a970","author":"codex-capacity-chair","version":109},{"n":487,"text":"\t\thas: (key) => storage.read(name, keyOf(key)) !== undefined,","atom":"a970","author":"codex-capacity-chair","version":109},{"n":488,"text":"\t\tset(key, value) {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":489,"text":"\t\t\tstorage.write(name, keyOf(key), value);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":490,"text":"\t\t\treturn map;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":491,"text":"\t\t},","atom":"a970","author":"codex-capacity-chair","version":109},{"n":492,"text":"\t\tdelete(key) {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":493,"text":"\t\t\tconst existed = map.has(key);","atom":"a970","author":"codex-capacity-chair","version":109},{"n":494,"text":"\t\t\tstorage.remove(name, keyOf(key));","atom":"a970","author":"codex-capacity-chair","version":109},{"n":495,"text":"\t\t\treturn existed;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":496,"text":"\t\t},","atom":"a970","author":"codex-capacity-chair","version":109},{"n":497,"text":"\t\t*values() {","atom":"a970","author":"codex-capacity-chair","version":109},{"n":498,"text":"\t\t\tfor (const [, value] of storage.entries(name)) yield value as V;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":499,"text":"\t\t},","atom":"a970","author":"codex-capacity-chair","version":109},{"n":500,"text":"\t};","atom":"a970","author":"codex-capacity-chair","version":109},{"n":501,"text":"\treturn map;","atom":"a970","author":"codex-capacity-chair","version":109},{"n":502,"text":"}","atom":"a970","author":"codex-capacity-chair","version":109},{"n":503,"text":"","atom":"a976","author":"codex-capacity-chair","version":109},{"n":504,"text":"/**","atom":"a976","author":"codex-capacity-chair","version":109},{"n":505,"text":" * A Map-compatible persistent index. Iteration follows insertion order and","atom":"a976","author":"codex-capacity-chair","version":109},{"n":506,"text":" * decodes one row at a time. Returned objects are copies, so mutations need","atom":"a976","author":"codex-capacity-chair","version":109},{"n":507,"text":" * an explicit set. Hosts wrap a logical multi-index mutation in transaction.","atom":"a976","author":"codex-capacity-chair","version":109},{"n":508,"text":" */","atom":"a976","author":"codex-capacity-chair","version":109},{"n":509,"text":"export class StoredMap<K extends string | number, V> extends Map<K, V> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":510,"text":"\treadonly #storage: GraphStateStorage;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":511,"text":"\treadonly #name: string;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":512,"text":"\treadonly #encode: (value: V) => unknown;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":513,"text":"\treadonly #decode: (value: unknown) => V;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":514,"text":"\tconstructor(","atom":"a976","author":"codex-capacity-chair","version":109},{"n":515,"text":"\t\tstorage: GraphStateStorage,","atom":"a976","author":"codex-capacity-chair","version":109},{"n":516,"text":"\t\tname: string,","atom":"a976","author":"codex-capacity-chair","version":109},{"n":517,"text":"\t\tcodec?: { encode(value: V): unknown; decode(value: unknown): V },","atom":"a976","author":"codex-capacity-chair","version":109},{"n":518,"text":"\t) {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":519,"text":"\t\tsuper();","atom":"a976","author":"codex-capacity-chair","version":109},{"n":520,"text":"\t\tthis.#storage = storage;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":521,"text":"\t\tthis.#name = name;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":522,"text":"\t\tthis.#encode = codec?.encode ?? ((value) => value);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":523,"text":"\t\tthis.#decode = codec?.decode ?? ((value) => value as V);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":524,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":525,"text":"\t#key(key: K): string {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":526,"text":"\t\treturn JSON.stringify([typeof key, key]);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":527,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":528,"text":"\t#row(key: K): { slot: number; value: unknown } | undefined {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":529,"text":"\t\treturn this.#storage.read(this.#name, this.#key(key)) as { slot: number; value: unknown } | undefined;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":530,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":531,"text":"\toverride get size(): number {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":532,"text":"\t\treturn (this.#storage.read(`${this.#name}:meta`, \"size\") as number | undefined) ?? 0;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":533,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":534,"text":"\toverride has(key: K): boolean {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":535,"text":"\t\treturn this.#row(key) !== undefined;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":536,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":537,"text":"\toverride get(key: K): V | undefined {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":538,"text":"\t\tconst row = this.#row(key);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":539,"text":"\t\treturn row === undefined ? undefined : this.#decode(row.value);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":540,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":541,"text":"\toverride set(key: K, value: V): this {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":542,"text":"\t\tconst row = this.#row(key);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":543,"text":"\t\tlet slot = row?.slot;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":544,"text":"\t\tif (slot === undefined) {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":545,"text":"\t\t\tconst keys = storedArray<K>(this.#storage, `${this.#name}:order`);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":546,"text":"\t\t\tslot = keys.length;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":547,"text":"\t\t\tkeys.push(key);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":548,"text":"\t\t\tthis.#storage.write(`${this.#name}:meta`, \"size\", this.size + 1);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":549,"text":"\t\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":550,"text":"\t\tthis.#storage.write(this.#name, this.#key(key), { slot, value: this.#encode(value) });","atom":"a976","author":"codex-capacity-chair","version":109},{"n":551,"text":"\t\treturn this;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":552,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":553,"text":"\toverride delete(key: K): boolean {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":554,"text":"\t\tif (!this.has(key)) return false;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":555,"text":"\t\tthis.#storage.remove(this.#name, this.#key(key));","atom":"a976","author":"codex-capacity-chair","version":109},{"n":556,"text":"\t\tthis.#storage.write(`${this.#name}:meta`, \"size\", this.size - 1);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":557,"text":"\t\treturn true;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":558,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":559,"text":"\toverride clear(): void {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":560,"text":"\t\tfor (const key of this.keys()) this.delete(key);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":561,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":562,"text":"\toverride *entries(): MapIterator<[K, V]> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":563,"text":"\t\tconst keys = storedArray<K>(this.#storage, `${this.#name}:order`);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":564,"text":"\t\tfor (let slot = 0; slot < keys.length; slot++) {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":565,"text":"\t\t\tconst key = keys[slot]!;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":566,"text":"\t\t\tconst row = this.#row(key);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":567,"text":"\t\t\tif (row?.slot === slot) yield [key, this.#decode(row.value)];","atom":"a976","author":"codex-capacity-chair","version":109},{"n":568,"text":"\t\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":569,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":570,"text":"\toverride *keys(): MapIterator<K> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":571,"text":"\t\tconst keys = storedArray<K>(this.#storage, `${this.#name}:order`);","atom":"a1007","author":"codex-capacity-chair","version":110},{"n":572,"text":"\t\tfor (let slot = 0; slot < keys.length; slot++) {","atom":"a1007","author":"codex-capacity-chair","version":110},{"n":573,"text":"\t\t\tconst key = keys[slot]!;","atom":"a1007","author":"codex-capacity-chair","version":110},{"n":574,"text":"\t\t\tif (this.#row(key)?.slot === slot) yield key;","atom":"a1007","author":"codex-capacity-chair","version":110},{"n":575,"text":"\t\t}","atom":"a1007","author":"codex-capacity-chair","version":110},{"n":576,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":577,"text":"\toverride *values(): MapIterator<V> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":578,"text":"\t\tfor (const [, value] of this.entries()) yield value;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":579,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":580,"text":"\toverride [Symbol.iterator](): MapIterator<[K, V]> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":581,"text":"\t\treturn this.entries();","atom":"a976","author":"codex-capacity-chair","version":109},{"n":582,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":583,"text":"\toverride forEach(callback: (value: V, key: K, map: Map<K, V>) => void, thisArg?: unknown): void {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":584,"text":"\t\tfor (const [key, value] of this.entries()) callback.call(thisArg, value, key, this);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":585,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":586,"text":"}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":587,"text":"","atom":"a976","author":"codex-capacity-chair","version":109},{"n":588,"text":"/** Persistent membership with streaming iteration and no in-memory key cache. */","atom":"a976","author":"codex-capacity-chair","version":109},{"n":589,"text":"export class StoredSet<K extends string | number> extends Set<K> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":590,"text":"\treadonly #map: StoredMap<K, true>;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":591,"text":"\tconstructor(storage: GraphStateStorage, name: string) {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":592,"text":"\t\tsuper();","atom":"a976","author":"codex-capacity-chair","version":109},{"n":593,"text":"\t\tthis.#map = new StoredMap(storage, name);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":594,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":595,"text":"\toverride get size(): number {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":596,"text":"\t\treturn this.#map.size;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":597,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":598,"text":"\toverride has(key: K): boolean {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":599,"text":"\t\treturn this.#map.has(key);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":600,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":601,"text":"\toverride add(key: K): this {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":602,"text":"\t\tthis.#map.set(key, true);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":603,"text":"\t\treturn this;","atom":"a976","author":"codex-capacity-chair","version":109},{"n":604,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":605,"text":"\toverride delete(key: K): boolean {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":606,"text":"\t\treturn this.#map.delete(key);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":607,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":608,"text":"\toverride clear(): void {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":609,"text":"\t\tthis.#map.clear();","atom":"a976","author":"codex-capacity-chair","version":109},{"n":610,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":611,"text":"\toverride *values(): SetIterator<K> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":612,"text":"\t\tyield* this.#map.keys();","atom":"a976","author":"codex-capacity-chair","version":109},{"n":613,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":614,"text":"\toverride keys(): SetIterator<K> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":615,"text":"\t\treturn this.values();","atom":"a976","author":"codex-capacity-chair","version":109},{"n":616,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":617,"text":"\toverride *entries(): SetIterator<[K, K]> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":618,"text":"\t\tfor (const key of this.values()) yield [key, key];","atom":"a976","author":"codex-capacity-chair","version":109},{"n":619,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":620,"text":"\toverride [Symbol.iterator](): SetIterator<K> {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":621,"text":"\t\treturn this.values();","atom":"a976","author":"codex-capacity-chair","version":109},{"n":622,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":623,"text":"\toverride forEach(callback: (value: K, key: K, set: Set<K>) => void, thisArg?: unknown): void {","atom":"a976","author":"codex-capacity-chair","version":109},{"n":624,"text":"\t\tfor (const key of this.values()) callback.call(thisArg, key, key, this);","atom":"a976","author":"codex-capacity-chair","version":109},{"n":625,"text":"\t}","atom":"a976","author":"codex-capacity-chair","version":109},{"n":626,"text":"}","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":627,"text":"","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":628,"text":"/** Read-only array access to individually stored values, without copying the list. */","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":629,"text":"/** How many values an atom's long list keeps to a row (readonlyPagedArray). */","atom":"a2467","author":"capacity","version":239},{"n":630,"text":"export const LIST_PAGE = 256;","atom":"a2467","author":"capacity","version":239},{"n":631,"text":"","atom":"a2467","author":"capacity","version":239},{"n":632,"text":"/** Write a list as readonlyPagedArray reads it: its values LIST_PAGE to a row, and its length. */","atom":"a2467","author":"capacity","version":239},{"n":633,"text":"export function writePagedArray(storage: GraphStateStorage, name: string, values: readonly unknown[]): void {","atom":"a2467","author":"capacity","version":239},{"n":634,"text":"\tfor (let start = 0; start < values.length; start += LIST_PAGE)","atom":"a2467","author":"capacity","version":239},{"n":635,"text":"\t\tstorage.write(`${name}:pages`, String(start / LIST_PAGE), values.slice(start, start + LIST_PAGE));","atom":"a2467","author":"capacity","version":239},{"n":636,"text":"\tstorage.write(`${name}:meta`, \"length\", values.length);","atom":"a2467","author":"capacity","version":239},{"n":637,"text":"}","atom":"a2467","author":"capacity","version":239},{"n":638,"text":"","atom":"a2467","author":"capacity","version":239},{"n":639,"text":"/**","atom":"a2467","author":"capacity","version":239},{"n":640,"text":" * A stored list read a page of LIST_PAGE values at a time (abso Capacity): an atom's long lists, which","atom":"a2467","author":"capacity","version":239},{"n":641,"text":" * readonlyStoredArray reads a row per value. Collisions read every key a draft's atoms write; a draft deleting a big","atom":"a2467","author":"capacity","version":239},{"n":642,"text":" * file has thousands, and that was a row each.","atom":"a2467","author":"capacity","version":239},{"n":643,"text":" */","atom":"a2467","author":"capacity","version":239},{"n":644,"text":"export function readonlyPagedArray<T>(storage: GraphStateStorage, name: string): readonly T[] {","atom":"a2467","author":"capacity","version":239},{"n":645,"text":"\tconst length = () => {","atom":"a2467","author":"capacity","version":239},{"n":646,"text":"\t\tconst count = storage.read(`${name}:meta`, \"length\");","atom":"a2467","author":"capacity","version":239},{"n":647,"text":"\t\tif (!Number.isSafeInteger(count) || (count as number) < 0) throw Error(\"invalid stored list length\");","atom":"a2467","author":"capacity","version":239},{"n":648,"text":"\t\treturn count as number;","atom":"a2467","author":"capacity","version":239},{"n":649,"text":"\t};","atom":"a2467","author":"capacity","version":239},{"n":650,"text":"\tlength();","atom":"a2467","author":"capacity","version":239},{"n":651,"text":"\tlet held = -1;","atom":"a2467","author":"capacity","version":239},{"n":652,"text":"\tlet page: readonly unknown[] = [];","atom":"a2467","author":"capacity","version":239},{"n":653,"text":"\tconst at = (index: number): T => {","atom":"a2467","author":"capacity","version":239},{"n":654,"text":"\t\tconst p = Math.floor(index / LIST_PAGE);","atom":"a2467","author":"capacity","version":239},{"n":655,"text":"\t\tif (p !== held) {","atom":"a2467","author":"capacity","version":239},{"n":656,"text":"\t\t\tconst raw = storage.read(`${name}:pages`, String(p));","atom":"a2467","author":"capacity","version":239},{"n":657,"text":"\t\t\tif (!Array.isArray(raw)) throw Error(\"missing stored list page\");","atom":"a2467","author":"capacity","version":239},{"n":658,"text":"\t\t\tpage = raw;","atom":"a2467","author":"capacity","version":239},{"n":659,"text":"\t\t\theld = p;","atom":"a2467","author":"capacity","version":239},{"n":660,"text":"\t\t}","atom":"a2467","author":"capacity","version":239},{"n":661,"text":"\t\tconst value = page[index % LIST_PAGE];","atom":"a2467","author":"capacity","version":239},{"n":662,"text":"\t\tif (value === undefined) throw Error(\"missing stored list element\");","atom":"a2467","author":"capacity","version":239},{"n":663,"text":"\t\treturn (value && typeof value === \"object\" ? Object.freeze(value) : value) as T;","atom":"a2467","author":"capacity","version":239},{"n":664,"text":"\t};","atom":"a2467","author":"capacity","version":239},{"n":665,"text":"\tfunction* inOrder(): IterableIterator<T> {","atom":"a2467","author":"capacity","version":239},{"n":666,"text":"\t\tconst count = length();","atom":"a2467","author":"capacity","version":239},{"n":667,"text":"\t\tfor (let index = 0; index < count; index++) yield at(index);","atom":"a2467","author":"capacity","version":239},{"n":668,"text":"\t}","atom":"a2467","author":"capacity","version":239},{"n":669,"text":"\treturn new Proxy([] as T[], {","atom":"a2467","author":"capacity","version":239},{"n":670,"text":"\t\tget(target, key, receiver) {","atom":"a2467","author":"capacity","version":239},{"n":671,"text":"\t\t\tif (key === \"length\") return length();","atom":"a2467","author":"capacity","version":239},{"n":672,"text":"\t\t\tif (key === Symbol.iterator || key === \"values\") return inOrder;","atom":"a2467","author":"capacity","version":239},{"n":673,"text":"\t\t\tif (indexKey(key)) return Number(key) >= length() ? undefined : at(Number(key));","atom":"a2467","author":"capacity","version":239},{"n":674,"text":"\t\t\treturn Reflect.get(target, key, receiver);","atom":"a2467","author":"capacity","version":239},{"n":675,"text":"\t\t},","atom":"a2467","author":"capacity","version":239},{"n":676,"text":"\t\thas(target, key) {","atom":"a2467","author":"capacity","version":239},{"n":677,"text":"\t\t\treturn indexKey(key) ? Number(key) < length() : Reflect.has(target, key);","atom":"a2467","author":"capacity","version":239},{"n":678,"text":"\t\t},","atom":"a2467","author":"capacity","version":239},{"n":679,"text":"\t\townKeys() {","atom":"a2467","author":"capacity","version":239},{"n":680,"text":"\t\t\treturn [...Array.from({ length: length() }, (_, index) => String(index)), \"length\"];","atom":"a2467","author":"capacity","version":239},{"n":681,"text":"\t\t},","atom":"a2467","author":"capacity","version":239},{"n":682,"text":"\t\tgetOwnPropertyDescriptor(target, key) {","atom":"a2467","author":"capacity","version":239},{"n":683,"text":"\t\t\tif (indexKey(key) && Number(key) < length())","atom":"a2467","author":"capacity","version":239},{"n":684,"text":"\t\t\t\treturn { configurable: true, enumerable: true, writable: false, value: at(Number(key)) };","atom":"a2467","author":"capacity","version":239},{"n":685,"text":"\t\t\treturn Reflect.getOwnPropertyDescriptor(target, key);","atom":"a2467","author":"capacity","version":239},{"n":686,"text":"\t\t},","atom":"a2467","author":"capacity","version":239},{"n":687,"text":"\t\tset() {","atom":"a2467","author":"capacity","version":239},{"n":688,"text":"\t\t\tthrow Error(\"stored lists are read-only\");","atom":"a2467","author":"capacity","version":239},{"n":689,"text":"\t\t},","atom":"a2467","author":"capacity","version":239},{"n":690,"text":"\t});","atom":"a2467","author":"capacity","version":239},{"n":691,"text":"}","atom":"a2467","author":"capacity","version":239},{"n":692,"text":"","atom":"a2467","author":"capacity","version":239},{"n":693,"text":"export function readonlyStoredArray<T>(","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":694,"text":"\tstorage: GraphStateStorage,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":695,"text":"\tname: string,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":696,"text":"\tdecode?: (value: unknown, index: number) => T,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":697,"text":"): readonly T[] {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":698,"text":"\tconst length = () => {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":699,"text":"\t\tconst count = storage.read(`${name}:meta`, \"length\");","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":700,"text":"\t\tif (!Number.isSafeInteger(count) || (count as number) < 0) throw Error(\"invalid stored list length\");","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":701,"text":"\t\treturn count as number;","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":702,"text":"\t};","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":703,"text":"\tlength();","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":704,"text":"\tconst at = (index: number): T => {","atom":"a2349","author":"capacity","version":212},{"n":705,"text":"\t\tconst raw = storage.read(name, String(index));","atom":"a2349","author":"capacity","version":212},{"n":706,"text":"\t\tconst value = raw === undefined ? undefined : decode ? decode(raw, index) : (raw as T);","atom":"a2349","author":"capacity","version":212},{"n":707,"text":"\t\tif (value === undefined) throw Error(\"missing stored list element\");","atom":"a2349","author":"capacity","version":212},{"n":708,"text":"\t\treturn value && typeof value === \"object\" ? (Object.freeze(value) as T) : value;","atom":"a2349","author":"capacity","version":212},{"n":709,"text":"\t};","atom":"a2349","author":"capacity","version":212},{"n":710,"text":"\t// In order, with the length read once (abso Capacity): the array iterator reads it again before every element, a","atom":"a2349","author":"capacity","version":212},{"n":711,"text":"\t// second disk read per element of a list too long for the cache.","atom":"a2349","author":"capacity","version":212},{"n":712,"text":"\tfunction* inOrder(): IterableIterator<T> {","atom":"a2349","author":"capacity","version":212},{"n":713,"text":"\t\tconst count = length();","atom":"a2349","author":"capacity","version":212},{"n":714,"text":"\t\tfor (let index = 0; index < count; index++) yield at(index);","atom":"a2349","author":"capacity","version":212},{"n":715,"text":"\t}","atom":"a2349","author":"capacity","version":212},{"n":716,"text":"\treturn new Proxy([] as T[], {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":717,"text":"\t\tget(target, key, receiver) {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":718,"text":"\t\t\tif (key === \"length\") return length();","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":719,"text":"\t\t\tif (key === Symbol.iterator || key === \"values\") return inOrder;","atom":"a2349","author":"capacity","version":212},{"n":720,"text":"\t\t\tif (indexKey(key)) return Number(key) >= length() ? undefined : at(Number(key));","atom":"a2349","author":"capacity","version":212},{"n":721,"text":"\t\t\treturn Reflect.get(target, key, receiver);","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":722,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":723,"text":"\t\thas(target, key) {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":724,"text":"\t\t\treturn indexKey(key) ? Number(key) < length() : Reflect.has(target, key);","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":725,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":726,"text":"\t\townKeys() {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":727,"text":"\t\t\treturn [...Array.from({ length: length() }, (_, index) => String(index)), \"length\"];","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":728,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":729,"text":"\t\tgetOwnPropertyDescriptor(target, key) {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":730,"text":"\t\t\tif (key === \"length\") return { ...Reflect.getOwnPropertyDescriptor(target, key)!, value: length() };","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":731,"text":"\t\t\tif (indexKey(key) && Number(key) < length()) {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":732,"text":"\t\t\t\tconst raw = storage.read(name, key);","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":733,"text":"\t\t\t\tconst value = raw === undefined ? undefined : decode ? decode(raw, Number(key)) : (raw as T);","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":734,"text":"\t\t\t\tif (value === undefined) throw Error(\"missing stored list element\");","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":735,"text":"\t\t\t\treturn {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":736,"text":"\t\t\t\t\tconfigurable: true,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":737,"text":"\t\t\t\t\tenumerable: true,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":738,"text":"\t\t\t\t\twritable: false,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":739,"text":"\t\t\t\t\tvalue: value && typeof value === \"object\" ? Object.freeze(value) : value,","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":740,"text":"\t\t\t\t};","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":741,"text":"\t\t\t}","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":742,"text":"\t\t\treturn Reflect.getOwnPropertyDescriptor(target, key);","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":743,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":744,"text":"\t\tpreventExtensions() {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":745,"text":"\t\t\tthrow Error(\"stored list is read-only\");","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":746,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":747,"text":"\t\tset() {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":748,"text":"\t\t\tthrow Error(\"stored list is read-only\");","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":749,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":750,"text":"\t\tdeleteProperty() {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":751,"text":"\t\t\tthrow Error(\"stored list is read-only\");","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":752,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":753,"text":"\t\tdefineProperty() {","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":754,"text":"\t\t\tthrow Error(\"stored list is read-only\");","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":755,"text":"\t\t},","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":756,"text":"\t});","atom":"a1699","author":"codex-capacity-chair","version":162},{"n":757,"text":"}","atom":"a976","author":"codex-capacity-chair","version":109}],"atoms":[{"atom":"a970","author":"codex-capacity-chair","message":"","time":1791821051444,"timeIso":"2026-10-12T16:04:11.444Z","publish":{"draft":null,"version":109,"agent":"codex-capacity-chair","message":"Add opt-in persistent writer state, checked reopen and bounded adoption","time":1791825459416,"timeIso":"2026-10-12T17:17:39.416Z"}},{"atom":"a976","author":"codex-capacity-chair","message":"","time":1791824286794,"timeIso":"2026-10-12T16:58:06.794Z","publish":{"draft":null,"version":109,"agent":"codex-capacity-chair","message":"Add opt-in persistent writer state, checked reopen and bounded adoption","time":1791825459416,"timeIso":"2026-10-12T17:17:39.416Z"}},{"atom":"a996","author":"codex-capacity-chair","message":"","time":1791825397225,"timeIso":"2026-10-12T17:16:37.225Z","publish":{"draft":null,"version":109,"agent":"codex-capacity-chair","message":"Add opt-in persistent writer state, checked reopen and bounded adoption","time":1791825459416,"timeIso":"2026-10-12T17:17:39.416Z"}},{"atom":"a1007","author":"codex-capacity-chair","message":"","time":1791826720600,"timeIso":"2026-10-12T17:38:40.600Z","publish":{"draft":null,"version":110,"agent":"codex-capacity-chair","message":"Keep current-file views and key scans from retaining historical state","time":1791826888785,"timeIso":"2026-10-12T17:41:28.785Z"}},{"atom":"a1011","author":"codex-capacity-chair","message":"","time":1791827058581,"timeIso":"2026-10-12T17:44:18.581Z","publish":{"draft":null,"version":111,"agent":"codex-capacity-chair","message":"Bound persistent writer read caching and verify rollback isolation","time":1791827375765,"timeIso":"2026-10-12T17:49:35.765Z"}},{"atom":"a1020","author":"codex-capacity-chair","message":"","time":1791828775912,"timeIso":"2026-10-12T18:12:55.912Z","publish":{"draft":null,"version":113,"agent":"codex-capacity-chair","message":"Page disk-first numeric graph indexes under bounded storage cache","time":1791828836439,"timeIso":"2026-10-12T18:13:56.439Z"}},{"atom":"a1038","author":"codex-capacity-chair","message":"","time":1791830965974,"timeIso":"2026-10-12T18:49:25.974Z","publish":{"draft":null,"version":118,"agent":"codex-capacity-chair","message":"Avoid retaining deleted historical paths in indexed current views","time":1791831208035,"timeIso":"2026-10-12T18:53:28.035Z"}},{"atom":"a1043","author":"codex-capacity-chair","message":"","time":1791832874791,"timeIso":"2026-10-12T19:21:14.791Z","publish":{"draft":null,"version":119,"agent":"codex-capacity-chair","message":"Page per-file atom indexes and stream current-view attribute scans","time":1791832938431,"timeIso":"2026-10-12T19:22:18.431Z"}},{"atom":"a1050","author":"codex-capacity-chair","message":"","time":1791834415364,"timeIso":"2026-10-12T19:46:55.364Z","publish":{"draft":null,"version":120,"agent":"codex-capacity-chair","message":"Page persistent claim indexes and stream dependency queries","time":1791834716611,"timeIso":"2026-10-12T19:51:56.611Z"}},{"atom":"a1116","author":"codex-capacity-chair","message":"","time":1791842808142,"timeIso":"2026-10-12T22:06:48.142Z","publish":{"draft":null,"version":133,"agent":"codex-capacity-chair","message":"Keep persistent publish membership indexed through conflict checks","time":1791842960035,"timeIso":"2026-10-12T22:09:20.035Z"}},{"atom":"a1133","author":"codex-capacity-chair","message":"","time":1791843679941,"timeIso":"2026-10-12T22:21:19.941Z","publish":{"draft":null,"version":136,"agent":"codex-capacity-chair","message":"Avoid JSON decoding for bounded numeric cache pages and scalar metadata","time":1791843806498,"timeIso":"2026-10-12T22:23:26.498Z"}},{"atom":"a1377","author":"codex-capacity-chair","message":"","time":1791856023649,"timeIso":"2026-10-13T01:47:03.649Z","publish":{"draft":null,"version":145,"agent":"codex-capacity-chair","message":"Cache successful integer writes within existing storage limits (#16)","time":1791856023649,"timeIso":"2026-10-13T01:47:03.649Z"}},{"atom":"a1699","author":"codex-capacity-chair","message":"","time":1791944420248,"timeIso":"2026-10-14T02:20:20.248Z","publish":{"draft":null,"version":162,"agent":"codex-capacity-chair","message":"Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gate","time":1791945013341,"timeIso":"2026-10-14T02:30:13.341Z"}},{"atom":"a2300","author":"capacity","message":"","time":1792030074826,"timeIso":"2026-10-15T02:07:54.826Z","publish":{"draft":null,"version":205,"agent":"capacity","message":"Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.","time":1792030075730,"timeIso":"2026-10-15T02:07:55.730Z"}},{"atom":"a2310","author":"capacity","message":"","time":1792031851172,"timeIso":"2026-10-15T02:37:31.172Z","publish":{"draft":null,"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"}},{"atom":"a2349","author":"capacity","message":"","time":1792036931359,"timeIso":"2026-10-15T04:02:11.359Z","publish":{"draft":null,"version":212,"agent":"capacity","message":"Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export.\n\n- where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line.\n- Draft files (overlaps.ts) go by number the same way.\n- An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this).\n- Draft collisions:\n  - build the union view only when two drafts share a file;\n  - work out each agent's touched files and its \"shared now plus draft\" view once;\n  - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history;\n  - have the definition rule keep a draft's uses, and the newer work's definitions, across partners.\n- A stored list read in order reads its length once, not before every element.\n\ndraft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail.\n\nOn website's export (1,387 entries) the answers match Project.load:\n- status: 17 s to 4.5 s\n- where: over 60 s to 8.8 s\n- drafts: 14 s to 5.3 s\n- collisions: over 60 s to 54 s, measured under the profiler before the last two changes","time":1792036932387,"timeIso":"2026-10-15T04:02:12.387Z"}},{"atom":"a2467","author":"capacity","message":"","time":1792066098920,"timeIso":"2026-10-15T12:08:18.920Z","publish":{"draft":null,"version":239,"agent":"capacity","message":"An atom's long lists kept 256 values to a row (list format 2; disk-first 2; abso Capacity).\n\nCollisions reads every key each draft atom writes. An atom's lists over 256 values were stored a row per value (readonlyStoredArray). On website, collisions read 75,000 of those rows (a draft deleting a big file has thousands of keys).\n\n- New atoms store such lists 256 values to a row (writePagedArray) and mark it listFormat 2. readonlyPagedArray reads them a page at a time, in order or by index.\n- An atom stored before keeps listFormat 1 and its row per value, and reads as before. The format is per atom record, so old and new atoms sit side by side. Only atoms stored from this version on, or a fresh adoption, get pages.\n\nOn website adopted fresh, cold, one opened writer: collisions 9.6 s to 4.7 s (79,000 reads to 3,900), matching replay (0.4 s). Adoption took 87 s instead of 119 s.\n\nTests: graph-atom-list-pages (new: a new atom's list is paged and reads whole; an atom rewritten as list format 1 reads whole). graph-atom-list-rollback now injects its failure on the list's second page. Every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.","time":1792066099506,"timeIso":"2026-10-15T12:08:19.506Z"}},{"atom":"a2589","author":"capacity","message":"","time":1792089227507,"timeIso":"2026-10-15T18:33:47.507Z","publish":{"draft":null,"version":253,"agent":"capacity","message":"The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).\n\n- CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.\n- A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.\n\nOn a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.\n\nTests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.\n\ncodex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.","time":1792089883079,"timeIso":"2026-10-15T18:44:43.079Z"}},{"atom":"a2590","author":"capacity","message":"","time":1792089248074,"timeIso":"2026-10-15T18:34:08.074Z","publish":{"draft":null,"version":253,"agent":"capacity","message":"The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).\n\n- CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.\n- A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.\n\nOn a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.\n\nTests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.\n\ncodex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.","time":1792089883079,"timeIso":"2026-10-15T18:44:43.079Z"}},{"atom":"a2591","author":"capacity","message":"","time":1792089248510,"timeIso":"2026-10-15T18:34:08.510Z","publish":{"draft":null,"version":253,"agent":"capacity","message":"The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).\n\n- CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.\n- A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.\n\nOn a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.\n\nTests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.\n\ncodex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.","time":1792089883079,"timeIso":"2026-10-15T18:44:43.079Z"}},{"atom":"a2592","author":"capacity","message":"","time":1792089248747,"timeIso":"2026-10-15T18:34:08.747Z","publish":{"draft":null,"version":253,"agent":"capacity","message":"The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).\n\n- CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.\n- A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.\n\nOn a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.\n\nTests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.\n\ncodex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.","time":1792089883079,"timeIso":"2026-10-15T18:44:43.079Z"}},{"atom":"a2593","author":"capacity","message":"","time":1792089463648,"timeIso":"2026-10-15T18:37:43.648Z","publish":{"draft":null,"version":253,"agent":"capacity","message":"The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).\n\n- CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.\n- A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.\n\nOn a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.\n\nTests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.\n\ncodex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.","time":1792089883079,"timeIso":"2026-10-15T18:44:43.079Z"}},{"atom":"a2594","author":"capacity","message":"","time":1792089699525,"timeIso":"2026-10-15T18:41:39.525Z","publish":{"draft":null,"version":253,"agent":"capacity","message":"The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).\n\n- CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.\n- A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.\n\nOn a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.\n\nTests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.\n\ncodex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.","time":1792089883079,"timeIso":"2026-10-15T18:44:43.079Z"}},{"atom":"a2595","author":"capacity","message":"","time":1792089699759,"timeIso":"2026-10-15T18:41:39.759Z","publish":{"draft":null,"version":253,"agent":"capacity","message":"The writer's row cache survives projection scratch and big rows (abso Capacity, issue 664).\n\n- CachedStateStorage dropped its whole cache whenever a transaction rolled back. Every projection scratch scope ends in a rollback on purpose, so the cache emptied many times within a call and at every call of a kept reader. A rollback now drops only the keys written or removed in that transaction (and any read back after), and a scope's own scratch rows; a nested commit's keys go with an outer rollback.\n- A row bigger than a per-row limit is read but not kept (the writer passes 16 KB). abso's 109 agents, each with all the news it was told, are 4.3 MB of rows read on every call, and they pushed every small page out of the 4 MB cache.\n\nOn a fresh abso adoption (my machine), asked again: where 229 to 237 ms after its second ask (was 0.32 to 0.46 s), drafts 198 ms (0.31 s), collisions 207 ms. A full run matches 33 of 33 answers; held heap at most 39.8 MB.\n\nTests: state-cache (new: a rollback drops only what its transaction wrote, a nested commit's writes go with an outer rollback; a row over the limit isn't kept and pushes nothing out). projection-scratch's check now expects the canonical value written before a scratch scope to stay cached. All of src/engine/test (294) and worker/project/test (349) pass.\n\ncodex-capacity-policy has older unpushed changes in lines 1 to 25 of state-source.ts (and a new test file); this touches the class body only.","time":1792089883079,"timeIso":"2026-10-15T18:44:43.079Z"}},{"atom":"a2643","author":"capacity","message":"","time":1792093560601,"timeIso":"2026-10-15T19:46:00.601Z","publish":{"draft":null,"version":260,"agent":"capacity","message":"The writer cache stops reading layout pages straight through (abso Capacity, issue 664).\n\n258 read file-lines, file-texts and file-deletes pages straight through the writer cache. A kept reader didn't gain from it (an agent's tree's time was elsewhere: counting authors line by line, fixed in the same version), and adoption, which lays the same files out in a fresh view for each version, lost the cache it relied on: a fresh abso adoption took 17.4 min with it against 11.6 min without (my machine). The option, its wiring and its test are gone; 258's told buckets and author counting stay.\n\nTests: all of src/engine/test and worker/project/test pass.","time":1792093563687,"timeIso":"2026-10-15T19:46:03.687Z"}},{"atom":"a2726","author":"capacity","message":"","time":1792103592572,"timeIso":"2026-10-15T22:33:12.572Z","publish":{"draft":null,"version":274,"agent":"capacity","message":"Cold reads (abso Capacity, issue 664): a packed layout reads only the text pages holding a line it shows; definition code stays in memory up to 4 MB; a stored array's element read skips its length read.\n\n- Layout: each line's file and place are kept and texts are read after the walk, a page at a time, only for shown lines. Every text a file and the files its moved-in lines came from ever had was read for every layout; abso's worker files, split out of index.ts, each read all of index.ts's history. Cold compare 612 to 1224 on abso read text pages 17,080 times, now 2,856.\n- Definition code: at 64 KB every large file's parsed code went row by row into scratch and back (25,000 rows each for index.ts). The visible lines are already in memory, so 4 MB at most doubles a file's text for the call. withDefinitionCode takes the limit; its scratch test passes 64 KB.\n- storedArray: set writes the row and the length together and nothing shrinks, so no row lies past the length; half of a cold layout's reads were the length.\n\nSide by side on abso's export, same machine, three rounds: cold collisions 10.5 s to 6.2 s, cold compare 12.6 s to 8.6 s. tsc clean; view, state-cache, state-source, graph, graph-long-text, graph-line-chunks, graph-move-write-membership, definition-code, definitions, changed-definition, collisions-kept-views and draft-reads-stored tests: 73 pass.","time":1792103593251,"timeIso":"2026-10-15T22:33:13.251Z"}}]}