For the complete documentation index, see llms.txt. This page is also available as Markdown.

Document Runtime (BETA)

Use @series-inc/rundot-document to build collaborative documents, knowledge bases, world bibles, inventory ledgers, or wiki-style state inside RUN applications.

The document runtime provides:

  • State-based Sequence CRDT: TextRegister provides commutative RGA merges without whole-field clobbering.

  • Dual-mode Operation: Seamlessly works offline with single-user Merkle sessions and 3-way CAS auto-rebase, or online in multi-user authoritative rooms.

  • Cross-tab Sync: Native multi-tab synchronization via TabSyncBus and SynchronizedLocalStorage.

  • Collaborative Discussions: Span-anchored inline suggestions, Google Docs-style comments, review approvals, and entity-level change tracking.

  • Zero Runtime Dependencies: Pure TypeScript ESM designed with a zero-dependency sealed boundary. Platform storage is injected, not imported.

When to use Document Runtime vs Storage API:

  • Use the Storage API directly for simple, low-velocity key-value state (player preferences, session tokens, feature flags, or small single-blob saves < 50 KB).

  • Use the Document Runtime when:

    1. Concurrent readers/writers: Multiple players, browser tabs, or background agents read and edit structured state simultaneously without last-write-wins data loss or clobbering.

    2. Large or growing state: State exceeds simple config blobs (wikis, node graphs, inventory trees, world bibles, long-form content). Raw appStorage rewrites the entire monolithic JSON payload on every single mutation ($O(N)$ CPU serialization overhead and disk I/O). The Document Runtime operates on granular delta operations, localized record patches, and log-compacted commits so performance remains constant regardless of document scale.

Install

npm install @series-inc/rundot-document
# or
pnpm add @series-inc/rundot-document

The document runtime is a separate package. It uses appStorage and standard room transports via structural duck-typing, but it does not import the RUN game SDK at runtime. You can use the version of the game SDK that your game already has.


1. Storage Integration (Venus Platform)

Inject your game's appStorage into the document runtime. Because @series-inc/rundot-document uses the structural adapter pattern, you never need to align SDK versions:

installVenusDocumentStore validates the presence of required storage primitives (getItem, setItem, removeItem, getAllKeys / getAllItems, and compareAndSwap) immediately at startup.

While raw appStorage normally forces full-object rewrites, @series-inc/rundot-document isolates state into granular delta commits and compacted snapshot buckets, preventing monolithic serialization lockups.


2. Define a Document Schema

Schemas declare the top-level registers, entity collections, and rigidity policies:


3. Single-User Session (Offline First with Multi-Tab Sync)

For solo editing or offline-first experiences, create a SingleUserSession. It writes through a local Merkle commit tree, coordinates across browser tabs using BroadcastChannel, and performs optimistic atomic CAS commits against appStorage:

Multi-Tab Synchronization

SingleUserSession automatically connects to TabSyncBus. When the user edits the document in another tab or window, the background tab automatically detects the commit via Web Locks and BroadcastChannel, rebasing remote commits without overwriting local uncommitted drafts.


4. Realtime Collaborative Room (Authoritative Multiplayer)

For real-time multi-user editing, use DocumentAuthorityRoom on the room server and DocumentRoomClient in the browser or mobile client:

Server-Side Room Authority

Client-Side Awareness & Presence

DocumentRoomClient handles ephemeral presence, cursor tracking, and chunked WebSocket frame synchronization:


5. Discussions, Comments & Span Suggestions

The Document Runtime includes first-class support for Google Docs-style inline suggestions, review threads, and entity change proposals:


6. Architecture & Design Rules

@series-inc/rundot-document enforces strict architectural invariants:

  1. Zero Runtime Dependencies: dependencies in package.json is empty. Everything is bundled or injected through ports.

  2. Storage Injection: Storage is never imported from global packages. Pass appStorage via installVenusDocumentStore or custom StructuralStorageApi adapters.

  3. No Node Builtins: Runs purely in web standards (crypto.subtle, BroadcastChannel, localStorage).

  4. Deterministic Merges: All text operations converge deterministically regardless of message arrival order.

Last updated