diaryx_sync 1.4.0

Sync engine for Diaryx - CRDT types, sync protocol, siphonophore hooks, and local server
Documentation

title: diaryx_sync author: adammharris part_of: 'Crates README'

diaryx_sync

Sync engine for Diaryx — CRDT types, sync protocol, and server infrastructure.

This crate owns all CRDT and sync functionality. It provides WASM-compatible core types and protocol modules, with optional features for server, native sync, SQLite storage, and git integration.

Feature Flags

  • default — CRDT types and sync protocol only (WASM-compatible)
  • typescript — TypeScript binding derives for CRDT-facing types
  • sqlite — SQLite-backed CRDT storage (SqliteStorage)
  • server — Siphonophore hooks, axum WebSocket server, StorageCache
  • native-sync — Native sync transport (tokio-tungstenite WebSocket)
  • git — Git-backed version history (commit, rebuild)

For non-browser WASM guests (for example Extism on wasm32-unknown-unknown), sync timestamping uses a monotonic fallback clock in time.rs instead of SystemTime::now() to avoid runtime panics in environments without host clock APIs.

Core Modules (always available)

  • typesFileMetadata, BinaryRef, CrdtUpdate, UpdateOrigin
  • workspace_docWorkspaceCrdt — Y.Map-backed workspace metadata
  • body_doc / body_doc_managerBodyDoc, BodyDocManager — Y.Text body documents
  • memory_storageMemoryStorage — in-memory CrdtStorage for tests and WASM
  • sync_protocolSyncProtocol, SyncMessage, wire format (frame/unframe, varint)
  • sync_handlerSyncHandler — remote update application with filesystem effects
  • sync_managerRustSyncManager — unified sync orchestration
  • sync_sessionSyncSession — platform-agnostic sync session state machine
  • sync_typesSyncEvent, SyncStatus, SyncSessionConfig
  • control_messageControlMessage — handshake and control protocol
  • historyHistoryManager, HistoryEntry, FileDiff
  • materializematerialize_workspace() — snapshot export from CRDT state
  • sanityvalidate_workspace() — CRDT consistency checks
  • self_healingHealthTracker — auto-repair for CRDT issues
  • crdt_fsCrdtFs — filesystem decorator that transparently updates CRDTs
  • decorator_stackDecoratedFsBuilder — composable FS decorator builder
  • sync_pluginSyncPlugin<FS>WorkspacePlugin that owns all CRDT state and handles ~50 sync commands

The sync plugin manifest also exposes an explicit WorkspaceProvider contribution so hosts can surface Diaryx Cloud as a provider without inferring it from command names.

InitializeWorkspaceCrdt rebuilds metadata from the logical workspace tree and then backfills any additional on-disk markdown files under the workspace root. That keeps live sync resilient when local create/rename/move operations briefly leave contents or part_of links stale. Late body updates are ignored for files whose workspace metadata is already tombstoned, so a just-deleted file cannot be recreated on disk by delayed body packets that arrive after the delete metadata sync.

Feature-Gated Modules

  • sqlite_storage (feature: sqlite) — SqliteStorage
  • git/ (feature: git) — commit_workspace(), rebuild_crdt_from_git()
  • sync_client (feature: native-sync) — SyncClient, TokioTransport
  • hooks (feature: server) — DiarySyncHook, SyncHookDelegate
  • server (feature: server) — SyncServer builder
  • storage (feature: server) — StorageCache per-workspace connection cache
  • local (feature: server) — Local sync server for CLI web editing
  • protocol (feature: server) — DocType, AuthenticatedUser, handshake types

Usage

WASM (default features)

diaryx_sync = { workspace = true }

Server

diaryx_sync = { workspace = true, features = ["server", "git"] }

CLI

diaryx_sync = { workspace = true, features = ["server"] }