Motebit

Architecture

Monorepo structure, package layers, and data flow

Motebit is a pnpm monorepo orchestrated by Turborepo. TypeScript throughout, Node 20+, pnpm 9.15. Every package exports from src/index.ts, tests live in src/__tests__/ using Vitest, and all I/O crosses an adapter boundary so the interior never binds to a specific platform.

Monorepo structure

DirectoryContents
apps/desktopTauri (Rust + webview). Flagship client. Three.js glass creature, identity bootstrap, operator mode, voice input, audio-reactive rendering, goal execution, multi-device pairing, MCP discovery with manifest pinning.
apps/cliNode.js REPL + daemon. Full operator console — chat, goal scheduling, tool approval queue, operator mode, motebit export / verify.
apps/mobileReact Native + Expo. Full parity. expo-gl + Three.js rendering, SQLite adapters, dual providers (Anthropic + Ollama + Hybrid), plan-based goal execution, MCP per-server trust, approval queue UI, voice input.
apps/adminReact + Vite dashboard. 10-tab real-time monitoring — state vector, memory graph, behavior cues, event log, tool audit, goals, plans, conversations, devices, intelligence gradient.
apps/spatialAR/VR positioning library. Body-relative orbital mechanics, WebXR audio reactivity.
apps/docsFumadocs + Next.js. This site.
packages/18 shared TypeScript packages — the interior of the system.
services/apiSync relay server. REST + WebSocket, device auth, fan-out.
spec/identity-v1.md — the motebit.md file format specification.

Package layers

Packages are organized into three tiers. Core has zero internal dependencies. Engines depend on core and on each other. Surface packages sit at the outermost boundary — they face the user, the network, or the renderer.

Core

The foundation. No package in this tier imports another motebit package.

PackageRole
sdkShared types — MotebitState, BehaviorCues, MemoryNode, EventLogEntry, PolicyDecision, RenderSpec.
cryptoEd25519 signing, AES-256-GCM encryption, PBKDF2 derivation, signed tokens (5 min expiry).
core-identityUUID v7 identity generation, multi-device registration, Ed25519 public key binding.

Engines

The interior machinery. Each engine owns one concern and communicates through typed interfaces defined in sdk.

PackageRole
runtimeOrchestrator. Wires all engines, exposes sendMessage / sendMessageStreaming.
ai-corePluggable providers (Cloud, Ollama, Hybrid), agentic turn loop, context packing.
behavior-enginecomputeRawCues(state) returns BehaviorCues. EMA smoothing, species constraints, rate limiting.
state-vectorTick-based EMA smoothing, hysteresis, interpolation for 60 FPS rendering.
memory-graphSemantic memory with cosine similarity retrieval, half-life decay (7 days default), graph edges.
event-logAppend-only event sourcing with version clocks, compaction, replay.
policyPolicyGate (tool approval, budgets, audit), MemoryGovernor (sensitivity-aware), injection defense.
privacy-layerRetention rules by sensitivity level, deletion certificates, data export manifests.
persistenceSQLite schema (WAL mode), adapters for events, memories, identities, audit, state, devices.
toolsInMemoryToolRegistry, builtin tools, MCP tool merge.
mcp-clientMCP stdio client, tool discovery, external data boundary marking.
sync-engineMulti-device sync — HTTP/WebSocket adapters, conflict detection, retry backoff.

Surface

The outermost layer. These packages face the renderer, the public npm registry, or the user's terminal.

PackageRole
render-engineRenderSpec (droplet geometry, glass material), ThreeJSAdapter (organic noise, breathing, sag, audio reactivity), WebXRThreeJSAdapter (AR), SpatialAdapter (body-relative orbital mechanics).
identity-fileGenerate, parse, verify motebit.md — signed agent identity files (internal).
verifyStandalone public verifier for motebit.md. Zero monorepo deps, MIT licensed.
create-motebitPublic CLI — npm create motebit. Generates and verifies signed identity files.
policy-invariantsClamping rules, state bounds validation.
browser-persistenceIn-browser storage adapters (IndexedDB) for web contexts.
github-actionGitHub Action for verifying motebit identity files in CI.
plannerPlanEngine — decomposes goals into multi-step plans with dependency tracking.
voiceVoice input pipeline — VAD, transcription, audio routing.

Data flow

A message enters the system and flows through a single pipeline:

  1. User input arrives via chat, voice, or a scheduled goal.
  2. Runtime receives the message and delegates to ai-core.
  3. AI core runs a streaming turn loop — it yields text chunks, tool calls, and status events as they arrive.
  4. Tool execution — if the model requests a tool, the call passes through the policy gate. Read-only tools execute automatically. Write/execute/spend tools require approval. Every decision is logged.
  5. State vector update — the outcome updates the 9-field state vector via EMA smoothing.
  6. Behavior enginecomputeRawCues(state) produces 5 behavior cues deterministically.
  7. Render spec — cues are mapped to droplet geometry, glow, and motion parameters.
  8. Platform renderer — Three.js on desktop, expo-gl on mobile, WebXR on spatial.

The pipeline is streaming end-to-end. Text appears as it arrives. Tool status events surface in real time. The creature's glow and breathing respond to processing state within the same frame loop.

The adapter pattern

Every I/O boundary is an interface. Storage, rendering, AI providers, sync transport — each has an in-memory implementation for tests and a platform-specific implementation for production (SQLite via better-sqlite3, Tauri invoke, expo-sqlite). The adapter is the surface tension boundary in code: the interior must not bind to a specific provider. If you can swap it without changing the engine, the boundary is correct.

Event sourcing

The event log is append-only and immutable. Every state change is recorded as an EventLogEntry with a version clock. Multi-device ordering uses these clocks for conflict detection — if two devices produce concurrent events, the sync engine detects the fork and resolves it. After a snapshot, older events compact to save space while preserving the audit trail.

Identity flow

On first launch the system bootstraps a cryptographic identity:

  1. Generate an Ed25519 keypair.
  2. Store the private key in the OS keychain (Tauri keyring on desktop, PBKDF2-encrypted file on CLI, expo-secure-store on mobile). It never leaves the device.
  3. Register the device against the identity (UUID v7).
  4. Authenticate with the sync relay using signed JWT tokens (5 min expiry, Ed25519 signature).

The identity persists across sessions, devices, and provider changes. Switching from Ollama to Anthropic changes nothing about who the agent is.

State vector, behavior, rendering

The state vector is 9 fields. Seven are continuous floats between 0 and 1: attention, processing, confidence, affect_valence, affect_arousal, social_distance, and curiosity. Two are enums: trust_mode and battery_mode. The vector updates on every tick via EMA smoothing with hysteresis to prevent jitter.

The behavior engine maps state to 5 output cues: hover_distance, drift_amplitude, glow_intensity, eye_dilation, and smile_curvature. The mapping is deterministic and stateless — the same state always produces the same cues.

The render engine translates cues into a RenderSpec: droplet geometry, glass material properties (transmission, IOR, iridescence), breathing frequency, gravity sag, Brownian drift amplitude, and interior glow intensity. The platform renderer (Three.js or expo-gl) consumes the spec and draws the creature at 60 FPS. The creature's visual state is a pure function of the state vector — no hidden state, no animation timelines, no imperative overrides.