cellz 0.1.0

SQLite-per-session, event-sourced state server for AI agents
Documentation

cellz

SQLite-per-session, event-sourced state server for AI agents
Language-agnostic state & stream plane with atomic CAS leasing, Cloudflare R2 / S3 durability, and sub-millisecond local commits. Built in 100% Rust.

CI crates.io docs.rs License Rust


⚑ Positioning & Comparison with celld

While projects like denoland/celld bring Cloudflare Durable Objects to self-hosted environments by executing JavaScript/TypeScript Workers inside a sandbox, cellz takes a different, agent-focused path:

  • Pure State & Stream Plane: cellz does not execute user code inside the cell. It is completely language-agnostic, exposing REST, SSE, and WebSocket interfaces so agents written in Rust, Python, TypeScript, or Go can connect instantly.
  • Agent-Native Primitives: Built-in event sourcing, message materialization, key-value stores (Todos, Compactions), checkpointing, and branch rewinding.
  • Atomic Single-Writer CAS Leases: Prevents split-brain across multiple distributed workers using S3 PutMode::Create / If-Match ETag conditional writes and atomic OS filesystem locks.
  • Actor Mailbox Serialization: Snapshots (wal_checkpoint(TRUNCATE)) and state exports are serialized within the cell's actor mailbox, eliminating race gaps between WAL writes and backup reads.
  • Lossless Realtime Reconnection: SSE stream supports Last-Event-ID and ?since= query parameters to seamlessly replay historical missed events before transitioning to live broadcast.

πŸ›οΈ Architecture

               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚              Client / Web UI / Coding Agent            β”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                          β”‚ HTTP / SSE (Last-Event-ID) / WS
                                          β–Ό
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚                 cellz                  β”‚
                      β”‚      (Axum REST & Real-time Mesh)      β”‚
                      β”‚                                        β”‚
                      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                      β”‚  β”‚       Session Cell (Actor)       β”‚  β”‚
                      β”‚  β”‚  - Monotonic Event Sourcing       β”‚  β”‚
                      β”‚  β”‚  - Materialized Message Projectionβ”‚  β”‚
                      β”‚  β”‚  - Key-Value State Machine        β”‚  β”‚
                      β”‚  β”‚  - Dedicated SQLite (WAL Mode)    β”‚  β”‚
                      β”‚  β”‚  - Mailbox-Serialized Snapshots   β”‚  β”‚
                      β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                          β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β–Ό                                         β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚  Local Cell SQLite DBs  β”‚               β”‚   Blob Storage Engine   β”‚
        β”‚   `data/cells/{id}.db`  β”‚               β”‚ (Local FS / S3 / R2)    β”‚
        β”‚  (Microsecond Latency)  β”‚               β”‚ (CAS Leases & Snapshots)β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

For in-depth architectural details, refer to Architecture Specification.


πŸš€ Quick Start

Install from crates.io

cargo install cellz
cellz

Embed the Axum router in your own process:

[dependencies]
cellz = "0.1"
use std::sync::Arc;
use cellz::cell::CellManager;
use cellz::config::Config;
use cellz::server::create_router;
use cellz::storage::LocalBlobStore;

let config = Config::default();
let storage = Arc::new(LocalBlobStore::new(&config.storage_dir));
let manager = Arc::new(CellManager::new(
    &config.data_dir,
    storage,
    config.lease_ttl_secs,
));
let app = create_router(manager);

1. Run the Daemon from source

# Local filesystem storage
cargo run --release

# Or with Cloudflare R2 / S3
export CELLZ_STORAGE_BACKEND="s3"
export CELLZ_S3_ENDPOINT="https://<account_id>.r2.cloudflarestorage.com"
export CELLZ_S3_BUCKET="zene-cells"
export CELLZ_S3_ACCESS_KEY_ID="<your_key>"
export CELLZ_S3_SECRET_ACCESS_KEY="<your_secret>"
cargo run --release

2. Configuration Options

cellz is configured via environment variables:

Environment Variable Default Value Description
CELLZ_HOST 0.0.0.0 Bind IP address
CELLZ_PORT 8080 Listen port
CELLZ_DATA_DIR ./data/cells Local SQLite databases storage path
CELLZ_STORAGE_DIR ./data/storage Snapshot backup & lease directory (local backend)
CELLZ_LEASE_TTL 60 Lease lock expiry duration in seconds
CELLZ_STORAGE_BACKEND local Storage backend (local or s3)
CELLZ_S3_ENDPOINT None S3 / Cloudflare R2 endpoint URL
CELLZ_S3_BUCKET None S3 / Cloudflare R2 bucket name
CELLZ_S3_ACCESS_KEY_ID None S3 Access Key ID
CELLZ_S3_SECRET_ACCESS_KEY None S3 Secret Access Key
CELLZ_S3_REGION auto S3 Region (auto for Cloudflare R2)

3. Create a Session & Append Events

# 1. Create a new Cell
curl -X POST http://localhost:8080/api/v1/cells \
  -H "Content-Type: application/json" \
  -d '{"id": "agent-007", "name": "Refactor Agent"}'

# 2. Append a user message
curl -X POST http://localhost:8080/api/v1/cells/agent-007/events \
  -H "Content-Type: application/json" \
  -d '{
    "turn_id": "turn-1",
    "event_type": "user_message",
    "payload": { "content": "Add unit tests for cell/db.rs" }
  }'

# 3. Retrieve projected messages
curl http://localhost:8080/api/v1/cells/agent-007/messages

# 4. Subscribe to real-time events via SSE
curl -N -H "Accept: text/event-stream" http://localhost:8080/api/v1/cells/agent-007/stream

Full API documentation and request/response payloads are available in API Reference.


πŸ§ͺ Testing & Quality Gates

Run full test suite:

cargo test --workspace

Run linter:

cargo clippy --all-targets -- -D warnings

πŸ“š Documentation Index


πŸ“„ License

Licensed under either of

at your option.