cass

DocsInternals

Deep Dive: Internals

On this page

The TUI Engine (Elm Architecture on FrankenTUI)#

The interactive interface (src/ui/app.rs) uses FrankenTUI (ftui), a Rust TUI framework implementing the Elm architecture (Model-View-Update). The runtime handles terminal lifecycle, event polling, rendering, and cleanup.

  1. Model (CassApp): A monolithic struct tracks the entire UI state (search query, cursor position, scroll offsets, active filters, cached details, animation state).
  2. Update: Each event (key, mouse, tick, resize) maps to a CassMsg variant. The update() function produces Cmd effects (async tasks, ticks, quit).
  3. View: The view() function renders the current state to an ftui Frame. The runtime diff engine minimizes terminal writes using Bayesian strategy selection.
  4. Adaptive Budget: A 120 ms total frame budget (render 24 ms, present 12 ms, diff 6 ms; frames are never skipped) with PID-controlled degradation automatically simplifies rendering (borders, animations) when frame times exceed budget.
  5. Background Tasks: Search queries, indexing, and analytics run on background threads via Cmd::Task, with results delivered as messages.
Mermaid diagram source
graph TD
 Input([User Input]) -->|Key/Mouse/Tick| Runtime
 Runtime -->|CassMsg| Update[Model::update]
 Update -->|Cmd| Runtime
 Update -->|State Change| View[Model::view]
 View -->|Frame| DiffEngine[Bayesian Diff]
 DiffEngine -->|Minimal Writes| Terminal

 Update -->|Cmd::Task| Background[Background Thread]
 Background -->|Result Msg| Runtime

Storage Strategy#

Data integrity is paramount. cass treats the SQLite database (src/storage/sqlite.rs, powered by frankensqlite) as the source of truth for conversations. History grows by insertion, and rows change only where the source changed:

  • Messages are inserted, not rewritten: when an agent adds a message to a conversation, cass inserts a new row linked to the conversation ID. There are exceptions:
    • A Codebuff/Freebuff message whose content or metadata changed under the same native ID is updated in place.
    • Conversation rows are updated as they grow: end time, last message index, token summaries, title and metadata.
    • Deduplication, forget and purge delete rows.
  • Deduplication: messages are keyed by UNIQUE(conversation_id, idx). New conversations are written with batched plain INSERTs, with the unique index as the backstop. Appends to a known conversation use INSERT OR IGNORE, so an agent re-writing a file cannot store a message twice. BLAKE3 content hashes are used only in memory, as merge fingerprints.
  • Versioning: a _schema_migrations table and a strict migration path keep upgrades safe and atomic; see Database Schema Migrations. Production creates a fresh database with one combined full_schema_v13 step and then applies v14–v23, so a new database records versions 13–23. The v1–v12 SQL is compiled only into tests.