Lines 228–246 at 162 (were 228–233 at 161)
231+/** A decoded entry is supplied by a host that binds its bytes to canonical authority. */ 232+export type WriterAdoptionFrame = { seq: number; json: string } | { seq: number; bytes: number; entry: Entry }; 233+function adoptionFrameBytes(frame: WriterAdoptionFrame): number { 234+ return "json" in frame 235+ ? typeof frame.json === "string" 236+ ? new TextEncoder().encode(frame.json).byteLength 240+function adoptionFrameEntry(frame: WriterAdoptionFrame): Entry { 241+ return "json" in frame ? (JSON.parse(frame.json) as Entry) : frame.entry; 231244export class Project { 232245 readonly #store: ProjectStore; 233246 readonly #writerStorage?: GraphStateStorage; Lines 493–538 at 162 (were 480–485 at 161)
480493 return new Project(store, { ...options, writerStorage: storage }, WRITER_REOPEN); 496+ /** Open a host-verified historical prefix. Its state must be immutable and 497+ * scoped to canonical authority; adoption readiness describes the live writer, 498+ * not whether this individual prefix has a complete checkpoint. */ 499+ static openHistorical( 500+ storage: GraphStateStorage, 502+ scratch: GraphStateStorage, 503+ assertScope: () => void = () => { 504+ storage.read("project:meta", "checkpoint"); 506+ readViewProvider?: ProjectOptions["readViewProvider"], 508+ const refuse = (): never => { 509+ throw new Error("historical project is read-only"); 511+ const selected = (collection: string) => { 512+ // Revalidate the historical scope even when accessing derived scratch. 514+ return collection.startsWith("projection-scratch:") ? scratch : storage; 516+ return Project.#openWriter( 519+ read: (collection, key) => selected(collection).read(collection, key), 520+ entries: (collection) => selected(collection).entries(collection), 521+ write: (collection, key, value) => { 522+ if (selected(collection) !== scratch) refuse(); 523+ scratch.write(collection, key, value); 525+ remove: (collection, key) => { 526+ if (selected(collection) !== scratch) refuse(); 527+ scratch.remove(collection, key); 529+ transaction: (body) => storage.transaction(() => scratch.transaction(body)), 532+ { readViewProvider }, 484537 * Derive one bounded page from the host's canonical frames. The host reads 485538 * those frames from its own log and revalidates the source inside this same Lines 543–557 at 162 (were 490–499 at 161)
491544 source: WriterSource; 493− frames: Iterable<{ seq: number; json: string }>;
546+ frames: Iterable<WriterAdoptionFrame>; 494547 maxEntries: number; 549+ /** The host supplies disk-backed decoded entries and verified byte counts. */ 550+ decodedFrames?: boolean; 496551 currentSource(): WriterSource; 552+ /** Select the host's derived historical revision before applying a frame. 553+ * Each selected revision receives a complete Project checkpoint. */ 554+ beginRevision?(logLength: number): void; 498556 options: Omit<ProjectOptions, "writerStorage"> = {}, 499557 ): { next: number; ready: boolean; entries: number; bytes: number } { Lines 567–573 at 162 (were 509–515 at 161)
509567 input.maxEntries > 256 || 510568 !Number.isSafeInteger(input.maxBytes) || 511569 input.maxBytes < 1 || 512− input.maxBytes > 8_000_000
570+ (input.maxBytes > 8_000_000 && input.decodedFrames !== true) 514572 throw new Error("invalid writer adoption bounds or source"); 515573 return storage.transaction(() => { Lines 591–614 at 162 (were 533–551 at 161)
535593 for (const frame of input.frames) { 594+ if (input.decodedFrames && "json" in frame) throw new Error("decoded adoption requires decoded frames"); 595+ const size = adoptionFrameBytes(frame); 537597 count >= input.maxEntries || 538598 frame.seq !== input.from + count || 539599 frame.seq >= input.source.logLength || 540− typeof frame.json !== "string" ||
541− frame.json.length > input.maxBytes - bytes
600+ !Number.isSafeInteger(size) || 602+ size > input.maxBytes - bytes 543604 throw new Error("writer adoption page exceeds bounds or has a noncontiguous frame"); 544− bytes += new TextEncoder().encode(frame.json).byteLength;
545606 if (bytes > input.maxBytes) throw new Error("writer adoption page exceeds byte bound"); 546− project.#apply(JSON.parse(frame.json) as Entry);
607+ input.beginRevision?.(frame.seq + 1); 608+ project.#apply(adoptionFrameEntry(frame)); 547609 project.#stored++; 548610 project.#persistMutable(); 611+ if (input.beginRevision) project.#writeCheckpoint(); 551614 if (count === 0) throw new Error("writer adoption page must advance"); Lines 626–706 at 162 (were 563–571 at 161)
566− * Apply more stored entries to a copy loaded for reading (#41, replay):
567− * scrubbing forward applies only what's new. Never for the live project.
629+ * Extend derived historical indexes from an already checkpointed prefix. 630+ * The host supplies only new canonical frames inside its commit transaction. 632+ static extendHistoricalPage( 633+ storage: GraphStateStorage, 636+ frames: Iterable<WriterAdoptionFrame>; 639+ /** The host supplies disk-backed decoded entries and verified byte counts. */ 640+ decodedFrames?: boolean; 641+ beginRevision(logLength: number): void; 642+ /** Verify both the saved prefix and the new frames against canonical authority. */ 643+ validateAuthority(): void; 645+ ): { next: number; entries: number; bytes: number } { 647+ !Number.isSafeInteger(input.from) || 649+ !Number.isSafeInteger(input.maxEntries) || 650+ input.maxEntries < 1 || 651+ input.maxEntries > 256 || 652+ !Number.isSafeInteger(input.maxBytes) || 653+ input.maxBytes < 1 || 654+ (input.maxBytes > 8_000_000 && input.decodedFrames !== true) 656+ throw new Error("invalid historical extension bounds"); 657+ const validate = () => { 658+ const result: unknown = input.validateAuthority(); 659+ if (result && (typeof result === "object" || typeof result === "function") && "then" in result) 660+ throw new Error("historical authority must be synchronous"); 662+ return storage.transaction(() => { 664+ const project = Project.#openWriter( 667+ throw new Error("history derivation cannot append canonical entries"); 674+ project.#loading = true; 677+ for (const frame of input.frames) { 678+ if (input.decodedFrames && "json" in frame) throw new Error("decoded adoption requires decoded frames"); 679+ const size = adoptionFrameBytes(frame); 681+ entries >= input.maxEntries || 682+ frame.seq !== input.from + entries || 683+ !Number.isSafeInteger(size) || 685+ size > input.maxBytes - bytes 687+ throw new Error("historical extension exceeds bounds or is not contiguous"); 689+ if (bytes > input.maxBytes) throw new Error("historical extension exceeds byte bound"); 690+ input.beginRevision(frame.seq + 1); 691+ project.#apply(adoptionFrameEntry(frame)); 693+ project.#persistMutable(); 694+ project.#writeCheckpoint(); 697+ if (!entries) throw new Error("historical extension must advance"); 699+ return { next: input.from + entries, entries, bytes }; 703+ /** Apply more entries to a replay copy. Never for the live project. */ 569704 catchUp(entries: Iterable<Entry>): void { 570705 this.#loading = true; Lines 1031–1037 at 162 (were 896–901 at 161)
8971032 /** The project's reviewers per area (#44): avcs.json's `"review": [{"paths": [...], "reviewer": "..."}]` in shared. */ 8981033 #reviewRules(): ReviewRule[] { 1034+ if (["abso.json", "avcs.json"].every((path) => this.#graph.startCodeOf(path) === undefined)) return []; 8991035 return reviewRulesIn(projectFileIn(this.#sharedView())?.text); Lines 1461–1467 at 162 (were 1325–1331 at 161)
13261462 changes: AtomId[], 1328− ): { collisions: Collision[]; newer: Set<AtomId>; union: Set<AtomId> } {
1464+ ): { collisions: Collision[]; newer: ReadonlySet<AtomId>; union: ReadonlySet<AtomId> } { 13291465 return hostedLandCollisions(this.#landHost, space, changes, pick); Lines 2179–2190 at 162 (were 2043–2048 at 161)
20432179 #landers?: LandHost; 20442180 get #landHost(): LandHost { 20452181 this.#landers ??= { 2182+ viewAt: (space, version, changes) => 2184+ ? this.#viewKeyed(`a ${space.name}@${version}+${changes.join(",")}`, () => 2185+ unionOverlay(this.#at(space, version), changes), 2187+ : this.#viewAt(space, version), 20462188 agents: this.#agents, 20472189 graph: this.#graph, 20482190 spaces: this.#spaces,