Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 161 to 162

Compare

+151 −9 in 9 places
Lines 228–246 at 162 (were 228–233 at 161)
228228 ready: boolean;
229229}
230230
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
237+ : NaN
238+ : frame.bytes;
239+}
240+function adoptionFrameEntry(frame: WriterAdoptionFrame): Entry {
241+ return "json" in frame ? (JSON.parse(frame.json) as Entry) : frame.entry;
242+}
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);
481494 }
482495
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,
501+ logLength: number,
502+ scratch: GraphStateStorage,
503+ assertScope: () => void = () => {
504+ storage.read("project:meta", "checkpoint");
505+ },
506+ readViewProvider?: ProjectOptions["readViewProvider"],
507+ ): Project {
508+ const refuse = (): never => {
509+ throw new Error("historical project is read-only");
510+ };
511+ const selected = (collection: string) => {
512+ // Revalidate the historical scope even when accessing derived scratch.
513+ assertScope();
514+ return collection.startsWith("projection-scratch:") ? scratch : storage;
515+ };
516+ return Project.#openWriter(
517+ { append: refuse },
518+ {
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);
524+ },
525+ remove: (collection, key) => {
526+ if (selected(collection) !== scratch) refuse();
527+ scratch.remove(collection, key);
528+ },
529+ transaction: (body) => storage.transaction(() => scratch.transaction(body)),
530+ },
531+ logLength,
532+ { readViewProvider },
533+ );
534+ }
483536 /**
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)
490543 input: {
491544 source: WriterSource;
492545 from: number;
493− frames: Iterable<{ seq: number; json: string }>;
546+ frames: Iterable<WriterAdoptionFrame>;
494547 maxEntries: number;
495548 maxBytes: 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;
497555 },
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)
513571 )
514572 throw new Error("invalid writer adoption bounds or source");
515573 return storage.transaction(() => {
Lines 591–614 at 162 (were 533–551 at 161)
533591 let count = 0;
534592 let bytes = 0;
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);
536596 if (
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) ||
601+ size < 1 ||
602+ size > input.maxBytes - bytes
542603 )
543604 throw new Error("writer adoption page exceeds bounds or has a noncontiguous frame");
544− bytes += new TextEncoder().encode(frame.json).byteLength;
605+ bytes += size;
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();
549612 count++;
550613 }
551614 if (count === 0) throw new Error("writer adoption page must advance");
Lines 626–706 at 162 (were 563–571 at 161)
563626 }
564627
565628 /**
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.
568631 */
632+ static extendHistoricalPage(
633+ storage: GraphStateStorage,
634+ input: {
635+ from: number;
636+ frames: Iterable<WriterAdoptionFrame>;
637+ maxEntries: number;
638+ maxBytes: number;
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;
644+ },
645+ ): { next: number; entries: number; bytes: number } {
646+ if (
647+ !Number.isSafeInteger(input.from) ||
648+ input.from < 1 ||
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)
655+ )
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");
661+ };
662+ return storage.transaction(() => {
663+ validate();
664+ const project = Project.#openWriter(
665+ {
666+ append: () => {
667+ throw new Error("history derivation cannot append canonical entries");
668+ },
669+ },
670+ storage,
671+ input.from,
672+ {},
673+ );
674+ project.#loading = true;
675+ let entries = 0,
676+ bytes = 0;
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);
680+ if (
681+ entries >= input.maxEntries ||
682+ frame.seq !== input.from + entries ||
683+ !Number.isSafeInteger(size) ||
684+ size < 1 ||
685+ size > input.maxBytes - bytes
686+ )
687+ throw new Error("historical extension exceeds bounds or is not contiguous");
688+ bytes += size;
689+ if (bytes > input.maxBytes) throw new Error("historical extension exceeds byte bound");
690+ input.beginRevision(frame.seq + 1);
691+ project.#apply(adoptionFrameEntry(frame));
692+ project.#stored++;
693+ project.#persistMutable();
694+ project.#writeCheckpoint();
695+ entries++;
696+ }
697+ if (!entries) throw new Error("historical extension must advance");
698+ validate();
699+ return { next: input.from + entries, entries, bytes };
700+ });
701+ }
703+ /** Apply more entries to a replay copy. Never for the live project. */
569704 catchUp(entries: Iterable<Entry>): void {
570705 this.#loading = true;
571706 try {
Lines 1031–1037 at 162 (were 896–901 at 161)
8961031
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);
9001036 }
9011037
Lines 1461–1467 at 162 (were 1325–1331 at 161)
13251461 space: Space,
13261462 changes: AtomId[],
13271463 pick: boolean,
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);
13301466 }
13311467
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) =>
2183+ changes?.length
2184+ ? this.#viewKeyed(`a ${space.name}@${version}+${changes.join(",")}`, () =>
2185+ unionOverlay(this.#at(space, version), changes),
2186+ )
2187+ : this.#viewAt(space, version),
20462188 agents: this.#agents,
20472189 graph: this.#graph,
20482190 spaces: this.#spaces,
MCP
compare on this site's /mcp
CLI
abso diff 161 162 worker/project/project.ts --json
JSON
/christopher/abso-core/compare/161..162?file=worker%2Fproject%2Fproject.ts&format=json