Zero-Idle-CPU Rust TUI Architecture Across 10 Workplace Clients
Inside BiteFoundry's verified Rust TUI engineering invariants across 10 apps (3,526 tests): 0.0% idle CPU via OS-blocking EventReader, borderless Modern TUI v2, 1/500 & 0/500 FxHashMap incremental rendering, DEC Mode 2026 synchronized frames, bundled SQLite WAL + FTS5, and cargo-auditable SBOM + SLSA Build Provenance.
1. Achieving 0.0% Steady-State Idle CPU with OS-Blocking EventReader
Most terminal UIs poll crossterm::event::poll(Duration::from_millis(16)) in a tight loop. When an engineer leaves five TUI apps open inside tmux or StackBite split panes all day, fixed-interval timers wake the CPU dozens of times per second—draining laptop battery and stealing cycles from builds and AI agents.
BiteFoundry's shared TUI chrome eliminates polling entirely:
- Dedicated OS-Blocking
EventReader: Terminal input blocks directly in the OS kernel (bitefoundry_tui_chrome::EventReader) and pushes events onto a channel only when keystrokes, mouse actions, or resize signals actually arrive. - Exact Deadline Computation (
next_ui_deadline):next_ui_deadline(app, ui, now)returnsNonewhenever no spinner animation, toast expiry, orwhich-keypopup timeout is active. WhenNone,tokio::select!sleeps indefinitely until the next input or background sync message. - Unit-Tested Invariant: Enforced in CI by
next_ui_deadline_returns_none_when_idle_and_earliest_when_active—not a manual claim, a regression-tested runtime invariant. - Adaptive Tokio Runtime Selection:
try_fast_help_or_version()serves--helpand--versionbefore constructing a Tokio runtime or TLS provider, andneeds_multi_thread_runtime()uses a lightweightcurrent_threadruntime for one-shot CLI calls, reserving multi-thread pools fortui,serve,mcp, anddaemon run.
2. Per-Message FxHashMap Incremental Rendering (1/500 Edit · 0/500 Hover)
Re-parsing HTML/Markdown and re-wrapping every message in a 500-message conversation on every scroll tick or mouse hover causes visible frame jitter in dense channels. BiteFoundry replaces full-stream rebuilds with a bounded, per-message incremental render pipeline:
- Thread-Local
MsgRenderCache: Backed byFxHashMap<MsgRenderKey, (u64, u64, RenderedMsg)>with a strict cap (MSG_RENDER_CACHE_MAX = 2048) and LRU half-eviction down to1024to keep long multi-room sessions memory-bounded. O(log S)Viewport Slicing: Assembled streams storeChatStream { segments: Arc<[StreamSegment]>, prefix_sums: Arc<[usize]> }. Slicing visible rows runs inO(log S)viaprefix_sums.partition_point(...)without flattening or cloning the line vector.- Stack-Allocated Hit Targets &
CopyLayout: Inline clickable links useSmallVec<[(u16, u16, HitTarget); 2]>, andLayoutSnapshotis statically verifiedCopy(assert_copy::<LayoutSnapshot>()) so per-event layout invalidation performs zero heap allocations. - Verified Invariants: Editing 1 message in the middle of a 500-message stream re-renders exactly 1/500 message bodies; changing hover, selection, or scroll offset re-renders 0/500.
3. Tear-Free Frames: DEC Mode 2026 & Dual-Bounded FramePacer
Fast terminal scrolling and resize bursts can still tear if ANSI escape sequences flush mid-frame. BiteFoundry wraps Ratatui cell diffs in DEC Mode 2026 Synchronized Output (SyncGuard::begin() emitting CSI ? 2026 h before the diff and CSI ? 2026 l after flush), instructing modern terminals (Ghostty, Kitty, WezTerm, Windows Terminal, iTerm2) to composite the entire frame atomically.
Burst input is paced through FramePacer (~10 ms cadence) with dual-bounded event draining (BATCH_EVENT_CAP = 4096, BATCH_TIME_CAP = 16ms) and scroll/resize event coalescing (coalesce_pushed_event). On Windows ConPTY, ChromeTerminalGuard snapshots and restores original console mode (preventing QuickEdit corruption) and filters duplicate KeyEventKind::Release events.
| Subsystem | Chosen Rust Design | Verified Effect |
|---|---|---|
| Idle Event Loop | OS-blocking EventReader + Option<Instant> next_ui_deadline | 0.0% steady-state idle UI CPU |
| Message Stream Cache | FxHashMap LRU (2048 -> 1024) + Arc<[StreamSegment]> + prefix_sums | 1/500 edit re-render, 0/500 hover/scroll, O(log S) slice |
| Terminal Frame Flush | DEC Mode 2026 (CSI ? 2026 h/l) + 10ms FramePacer + coalescing | Zero mid-frame tearing under rapid scroll/resize |
| Local Search Engine | Bundled SQLite WAL (64 MiB mmap) + FTS5 trigram + CJK LIKE fallback | Zero-dependency offline full-text + 1–2 char Korean/CJK search |
| Inline Graphics | Kitty -> iTerm2 OSC 1337 -> Sixel -> 24-bit Half-Blocks (▀) | Universal terminal image preview with PixelLayerTracker cleanup |
| Release Binary Profile | opt-level="s", lto="fat", codegen-units=1, panic="abort" + panic hook | 5.0–27.1 MiB static binary; terminal always restored on panic |
4. Supply-Chain Hardening: cargo-auditable SBOM, SLSA Provenance & SHA-Pinned CI
Native developer tools that hold Microsoft Graph, Atlassian, Google, Linear, or Notion OS keychain tokens deserve strict supply-chain verifiability. Every BiteFoundry release artifact across all 9 apps adheres to the same verifiable build pipeline:
- Embedded
cargo-auditableSBOM: Every release binary embeds its exact Rust dependency graph as compressed auditable metadata inside the executable itself—verifiable offline withcargo audit bin. - GitHub SLSA Build Provenance & npm
--provenance: Release binaries are attested viaactions/attest-build-provenance(verifiable viagh attestation verify), and npm packages publish with cryptographic provenance linked to the exact GitHub Actions workflow run. - 40-Character SHA-Pinned Workflows: Every GitHub Action in CI/release pipelines is pinned to a full 40-character commit SHA with minimal
permissions, continuously audited byactionlint,pinact, andzizmor(persona: "pedantic"), alongsidecargo denyandcargo machete. - Zero Telemetry & No Forced Auto-Updater: No analytics SDKs, crash uploaders, or silent background self-updaters exist in any binary; outbound traffic goes exclusively to official upstream APIs (and GitHub Releases only when you explicitly run
<app> update).
# 1. Inspect embedded cargo-auditable dependency SBOM in an installed binary
cargo audit bin "$(command -v teams)"
cargo audit bin "$(command -v gdocs)"
# 2. Verify GitHub SLSA Build Provenance on a downloaded release archive
gh attestation verify ./teams-x86_64-unknown-linux-gnu.tar.gz --owner BiteFoundry
# 3. Reproduce runtime invariants from source (on a cloned repo)
cargo nextest run --all-targets -E 'test(next_ui_deadline) | test(layout_snapshot) | test(msg_render_cache)'
Frequently Asked Questions
How can a Rust TUI maintain 0.0% idle CPU while still supporting spinners, toasts, and background sync?
Instead of polling on a fixed timer, `next_ui_deadline()` computes the exact earliest active animation or toast expiry timestamp and returns `None` when idle. `tokio::select!` sleeps with zero wakeups until the OS-blocking `EventReader` or background sync channel delivers a real event.
Why does BiteFoundry use panic = "abort" in release builds if a TUI must restore raw mode?
`panic = "abort"` combined with `opt-level = "s"` and `lto = "fat"` significantly shrinks binary size (5.0–27.1 MiB), while a dedicated `std::panic::set_hook` + `TerminalGuard` invokes `restore_terminal_best_effort()` and clears Kitty graphics before aborting—so your terminal is never left stuck in raw mode.
How does SQLite FTS5 handle short 1–2 character Korean or CJK queries?
SQLite FTS5 `trigram` requires at least 3 characters per token. BiteFoundry's local search engine automatically falls back to indexed `LIKE` queries for 1–2 character tokens while using FTS5 `trigram` (fallback `unicode61`) for 3+ character queries.
How can enterprise security teams verify BiteFoundry binaries before deploying them?
Every release binary embeds a `cargo-auditable` dependency SBOM inspectable via `cargo audit bin`, ships with GitHub SLSA Build Provenance (`gh attestation verify`), publishes to npm with `--provenance`, and passes `cargo deny` license/advisory checks.
Related BiteFoundry Product Pages
More Technical Guides
Microsoft Teams MCP for Claude Code, Cursor & Codex
Connect Claude Code, Cursor, and Codex to Microsoft Teams via native Rust MCP & CLI (@bitefoundry/teams@0.14.0, ~33 MB RAM vs 1,240 MB Desktop, 16 stdio & Streamable HTTP MCP tools, --json compact reads, -p ANSI print, HTTP :8788, Shift+Y and confirm:true delete safety).
Atlassian Jira & Confluence MCP & Terminal Client (Zero Docker)
Unified Atlassian Jira & Confluence MCP server and Rust terminal client without Docker or Node (@bitefoundry/atlassian@0.12.0, 37 MCP tools / 15 --read-only tools, ADF <-> Markdown, cross-linking, j/cf aliases, HTTP :8789 + POST /mcp).
Read Public & Private Google Docs and Drive URLs from Terminal & MCP
Read public and private Google Docs and Drive URLs from the terminal and AI agents (@bitefoundry/gdocs@0.4.0, zero-login gdocs <url>, -p ANSI print, UTF-16 optimistic-locked editing + replace_doc_markdown, 11 stdio & Streamable HTTP MCP tools + --read-only, HTTP :8794, 5.4 MiB binary).