The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(openhuman-tui): expand README with architecture and usage details
Steven Enamakel7aceaa66f17d
diff --git a/crates/openhuman-tui/README.md b/crates/openhuman-tui/README.mdindex 5f61034f8e..61b39f6e83 100644--- a/crates/openhuman-tui/README.md+++ b/crates/openhuman-tui/README.md@@ -1,17 +1,110 @@-# `openhuman-tui`+# openhuman-tui++The standalone terminal client for OpenHuman, built on [ratatui]. It boots the+core inside its own process, with no HTTP server and no sockets, and gives you+four tabs (Logs, Chat, Config, Settings) plus a slash-command cockpit for+threads, models, permissions, approvals, plan review, agents, skills, MCP+servers, artifacts and Git review. Chat uses the same `web_chat` surface the+desktop app drives, so a turn here behaves like a turn in the app. It ships as+the `openhuman-tui` binary next to `openhuman-core`.++## How it works++### Startup++`main.rs` calls `init_crash_reporting()` (a Sentry client when the+`crash-reporting` feature is on) and keeps its guard alive, then calls+`run_from_cli` with the arguments. `runner.rs` does the rest, in order:++1. Loads `.env` (`core::cli::load_dotenv_for_cli`) and applies any startup+ restart delay.+2. Parses flags. `--help` prints usage and returns before anything boots; an+ unknown `-` flag is an error.+3. Sets transient provider and model overrides+ (`core::cli::set_transient_inference_overrides`).+4. Starts file-only logging under the data dir+ (`core::logging::init_for_tui`). The TUI owns the terminal, so nothing is+ written to stderr from here on.+5. Initializes the keyring master key.+6. Builds a multi-thread tokio runtime with the core's+ `AGENT_WORKER_STACK_BYTES` stack size, so nested agent turns do not+ overflow the default 2 MiB stack.+7. Inside the runtime (`async_main`): installs the TinyHumans backend+ transport, installs the on-disk session store+ (`openhuman_rpc::session_store::install`), and builds the core:++ ```rust+ CoreBuilder::new(HostKind::detect_standalone())+ .domains(DomainSet::full())+ .services(ServiceSet::none())+ .backend_transport(backend_transport)+ .build()+ ```++ `DomainSet::full()` is needed because `channel.web_chat` lives in the+ Channels domain group. `ServiceSet::none()` skips background services,+ including channel startup, so the runner registers the approval and+ artifact surface subscribers itself+ (`web_chat::register_approval_surface_subscriber`,+ `register_artifact_surface_subscriber`).+8. Picks a client id (`tui-<12 hex>`), resolves the thread, subscribes to the+ web-channel broadcast before the first turn, and hands off to `app::run`.++Thread resolution: `--thread <id>` attaches to that thread unless `--new` is+also given. `--last` or `--resume` picks the first thread from+`openhuman.threads_list`. Otherwise, or if listing fails, it creates one with+`openhuman.threads_create_new`.++### The event loop++```text+ crossterm reader thread core (in-process)+ (event::poll every 100 ms) web_chat broadcast+ | |+ | mpsc | broadcast::Receiver<WebChannelEvent>+ v v+ +--------------------- app::run: tokio::select! ----------------------++ | key / paste -> handle_key -> composer, tabs, overlays, commands |+ | web event -> TranscriptState::apply_event (state.rs) |+ | 120 ms tick -> spinner |+ +-----------------------------+---------------------------------------++ |+ v+ render::draw(frame, &TranscriptState, &UiState)++ send: runtime.invoke("openhuman.channel_web_chat",+ { client_id, thread_id, message, queue_mode, ... })+ cancel: runtime.invoke("openhuman.channel_web_cancel", { client_id, thread_id })+```++Before entering the loop, `app::run` loads the thread's existing transcript+(`openhuman.threads_transcript_get`), refreshes config, auth and agent paths,+and opens the thread picker if `--resume` was given. It then enters the+terminal through `TerminalGuard` and sends the positional prompt, if any.++Sending a message spawns a task that calls `openhuman.channel_web_chat`+through `CoreRuntime::invoke`. The reply streams back as `WebChannelEvent`s on+the broadcast channel, which `TranscriptState::apply_event` folds into the+transcript. Events for another `client_id` or thread are ignored. If the+invoke itself fails, the TUI publishes a synthetic `chat_error` so the+streaming state clears. `Enter` sends with `queue_mode: "interrupt"`; `Tab`+while a turn is streaming queues the text as a follow-up. `Esc` cancels the+in-flight turn.++Logging in or out from Settings sets `identity_changed`, and the loop starts a+new thread afterwards.++### Login-`openhuman-tui` is the standalone terminal client, embedding the core-in-process. It is a [ratatui]-based agent cockpit with Chat, Logs, Config, and-Settings tabs, persistent thread resume, command/file pickers, approvals, plan-review, task/goal/agent/skill/MCP/artifact views, Git review, and a multiline-composer. Chat uses the same `web_chat` surface the desktop app drives-(`openhuman.channel_web_chat` / `openhuman.channel_web_cancel` +-`web_chat::subscribe_web_channel_events`). It boots the core in-process, with-no HTTP and no sockets, via-`CoreBuilder::new(HostKind::Cli).domains(DomainSet::full()).services(ServiceSet::none())`,-and streams a live transcript in the terminal.+`session.rs` is the TUI's session owner. It wraps+`openhuman_tinyhumans::SessionManager` around an `InProcessLink`, a `CoreLink`+that calls `CoreRuntime::invoke` directly (no HTTP, no bearer). Login-token+exchange and `/auth/me` happen in the TUI process; the core only receives the+resulting credential through `auth.set_credential`. The Settings tab drives+it: "Log in with one-time token" takes a pasted token (zeroized on cancel),+and "Log out" asks for confirmation.-## Run / build+## UsageSee [Building the Rust Core](../../gitbooks/developing/building-rust-core.md)for toolchain setup.@@ -24,72 +117,122 @@ cargo run -p openhuman-tui -- [OPTIONS] [PROMPT]| Flag | Effect || --- | --- || `--thread <id>` | Attach to an existing conversation thread. |-| `--new` | Force a new thread (default when `--thread` is omitted). |-| `--resume` | Open the saved-thread picker (starts on the latest thread). |+| `--new` | Force a new thread (the default when `--thread` is omitted). |+| `--resume` | Open the saved-thread picker, starting on the latest thread. || `--last` | Resume the most recent thread. |-| `--no-alt-screen` | Draw in the current terminal buffer. |+| `--no-alt-screen` | Draw in the current terminal buffer instead of the alternate screen. || `-p`, `--provider <id>` | Override the inference provider for this session (also `--provider-id`, `--provider=<id>`). || `-m`, `--model <id>` | Override the model for this session (also `--model-id`, `--model=<id>`). |-| `-v`, `--verbose` | Debug-level logging, written to the log file and never the UI (the TUI owns the terminal). |+| `-v`, `--verbose` | Debug-level logging, written to the log file only. || `-h`, `--help` | Print usage and exit. |-| a positional prompt | Sent immediately after startup. |+| positional words | Joined into a prompt and sent right after startup. |-Any other `-`-prefixed argument is rejected before the core boots.+`OPENHUMAN_WORKSPACE` overrides the data dir (default `~/.openhuman`), which+holds the `logs/` the TUI writes to.-`Ctrl+Tab`/`Alt+1-4` switch tabs, `/` opens the command picker (see-`COMMANDS` in `src/composer.rs` for the full list), `Enter` sends,-`Shift+Enter` inserts a newline, `Ctrl+C`/`Ctrl+D` quit.+Keys: `Ctrl+Tab` / `Ctrl+Shift+Tab` or `Alt+1` to `Alt+4` switch tabs,+`Enter` sends, `Shift+Enter` or `Alt+Enter` inserts a newline, `Tab`+completes a command or opens the file picker, `Up`/`Down` walk composer+history, `Ctrl+R` searches it, `Ctrl+W` deletes a word, `Esc` cancels a+running turn, and `Ctrl+C` / `Ctrl+D` quit.-## Feature flags--- `crash-reporting` (default on): pulls in `sentry` and `dotenvy`, forwards- `openhuman-core/crash-reporting`, and makes `init_crash_reporting` install a- Sentry client and panic integration before the TUI takes over the terminal.- Without it, `init_crash_reporting` compiles to a no-op at the same call- site.+Slash commands (the full list with descriptions is `COMMANDS` in+`src/composer.rs`): `/help`, `/new`, `/resume`, `/rename`, `/delete`,+`/model`, `/permissions`, `/status`, `/usage`, `/agents`, `/skills`, `/mcp`,+`/artifacts`, `/approvals`, `/diff`, `/review`, `/copy`, `/export`, `/clear`,+`/logs`, `/config`, `/settings`, `/logout`, `/quit`. `/diff` runs `git` in the+agent's action directory and fails cleanly when that is not a repository.-## Crate relationships+## Layout-- Depends on `openhuman-core` directly and runs it in-process: there is no- need to spawn or connect to an `openhuman-core` binary.-- Depends on `openhuman-rpc` only for `unwrap_rpc` (re-exported from- `src/cockpit.rs`), which strips the optional `result`/`data` envelopes core- RPC handlers wrap around their payloads before the TUI reads them.-- The ratatui/crossterm terminal dependencies live only in this crate.- `crates/openhuman-core/Cargo.toml` calls this out explicitly: "The- terminal-specific ratatui/crossterm cohort lives in the separate- `openhuman-tui` package," keeping the shared core free of UI dependencies.+| File | What it does |+| --- | --- |+| `src/main.rs` | Binary entry: crash reporting, then `run_from_cli`. |+| `src/lib.rs` | Module declarations and the public surface. |+| `src/runner.rs` | `run_from_cli`: flags, logging, runtime, core boot, thread resolution. |+| `src/app.rs` | The `tokio::select!` event loop, key handling, slash commands, overlays, sending and cancelling turns, the file picker and Git diff. |+| `src/state.rs` | `TranscriptState`, the pure reducer that folds `WebChannelEvent`s into transcript entries. No terminal or I/O dependencies. |+| `src/ui_state.rs` | `UiState`: active tab, composer, scroll, overlays, Config items and Settings actions. Pure data. |+| `src/render.rs` | `draw`, a pure view over `TranscriptState` and `UiState`. The Logs tab reads `core::logging::tui_log_lines`. |+| `src/composer.rs` | The multiline composer: editing, history, command completion, and the `COMMANDS` table. |+| `src/cockpit.rs` | Overlay types (`OverlayKind`, `Overlay`, `OverlayRow`), pending approval and plan-review records, and JSON helpers; re-exports `openhuman_rpc::unwrap_rpc`. |+| `src/controls.rs` | Config tab edits (API URL, inference URL, default model, autonomy level, privacy mode) and Settings actions (view account, log in, log out). |+| `src/session.rs` | `InProcessLink` and the process-wide `SessionManager`. |+| `src/terminal.rs` | `TerminalGuard` (raw mode, alternate screen, mouse capture, bracketed paste) and a panic hook that restores the terminal first. |+| `src/crash_reporting.rs` | `init_crash_reporting`, a no-op without the `crash-reporting` feature. |+| `tests/cli_e2e.rs` | Spawns the built binary to check `--help` output and that flags are validated before the core boots. |++## Key types and entry points++- `run_from_cli(args)` (`src/runner.rs`) is the public entry point.+- `init_crash_reporting()` (`src/crash_reporting.rs`) returns a+ `sentry::ClientInitGuard` that must live for the whole process.+- `TranscriptState`, `Entry`, `EntryKind` (`src/state.rs`) are exported so the+ reducer can be tested without a terminal. `apply_event` is the single+ transition entry point.+- `app::run` (`src/app.rs`) owns the loop; `LaunchOptions` carries the initial+ prompt, `resume_picker` and `no_alt_screen`.++## Core methods used++All calls go through `CoreRuntime::invoke`:++| Area | Methods |+| --- | --- |+| Chat | `openhuman.channel_web_chat`, `openhuman.channel_web_cancel`, `openhuman.channel_web_queue_status` |+| Threads | `openhuman.threads_list`, `openhuman.threads_create_new`, `openhuman.threads_transcript_get`, `openhuman.threads_update_title`, `openhuman.threads_delete`, `openhuman.threads_token_usage` |+| Approvals and plans | `openhuman.approval_list_pending`, `openhuman.approval_decide`, `openhuman.plan_review_decide` |+| Browsing | `openhuman.agent_list_definitions`, `openhuman.skills_list`, `openhuman.mcp_clients_installed_list`, `openhuman.ai_list_artifacts` |+| Config | `openhuman.config_get_client_config`, `openhuman.config_get_agent_paths`, `openhuman.config_update_model_settings`, `openhuman.config_get_autonomy_settings`, `openhuman.config_update_autonomy_settings`, `openhuman.config_get_privacy_mode`, `openhuman.config_set_privacy_mode` |+| Account | `openhuman.auth_get_state` (login and logout go through `session.rs`) |-## Module map+## Feature flags-| File | Purpose |+| Feature | Meaning || --- | --- |-| `app.rs` | Terminal chat event loop: bridges keyboard input, the web-channel broadcast, and a spinner ticker over `tokio::select!`. |-| `cockpit.rs` | OpenHuman-native overlays and structured control-plane state. |-| `composer.rs` | Keyboard-first, terminal-independent chat composer. |-| `controls.rs` | Config and account actions for the tabbed terminal UI. |-| `crash_reporting.rs` | Crash-reporting client ownership for the standalone terminal binary. |-| `render.rs` | Ratatui rendering: a pure view over `TranscriptState` + `UiState`. |-| `runner.rs` | CLI entry point (`run_from_cli`): flag parsing, logging setup, and core boot. |-| `state.rs` | Pure, terminal-free transcript reducer for the Chat tab. |-| `terminal.rs` | Terminal setup/teardown with panic-safe restoration. |-| `ui_state.rs` | Pure navigation and form state for the four terminal pages. |+| `crash-reporting` (default) | Pulls in `sentry` and `dotenvy` and forwards `openhuman-core/crash-reporting`. `init_crash_reporting` loads `.env`, then starts a Sentry client that scrubs secrets from exception values and messages (`core::log_redaction::scrub_secrets`) and uses the core's Sentry transport. |++## Boundaries++- The core runs in-process through `openhuman-core`; there is no+ `openhuman-core` binary to spawn or connect to.+- `openhuman-rpc` is used for the session store (`session-store` feature) and+ `unwrap_rpc`, which strips the optional `result`/`data` envelopes around+ RPC payloads. The TUI does not use its server or HTTP client.+- `openhuman-tinyhumans` provides the backend transport and the+ `SessionManager`; auth endpoint behavior belongs there.+- The ratatui and crossterm dependencies live only in this crate, which keeps+ the core free of terminal code.+- Chat semantics (queueing, cancellation, streaming events) belong to the+ core's `web_chat` and channel domains. The TUI only renders them.++## Gotchas++- Never print to stdout or stderr after the terminal is entered; use `log::`+ with a `[tui]` prefix, which goes to the log file. A stray `println!` corrupts+ the display.+- Subscribe to `web_chat::subscribe_web_channel_events` before the first turn.+ The runner does this before `app::run`, so streamed events of an initial+ prompt are not lost.+- With `ServiceSet::none()`, anything that normally starts as a background+ service (channel listeners, schedulers) is off. If a new surface needs+ events bridged onto the web channel, register its subscriber in+ `async_main` the way the approval and artifact subscribers are.## Tests-Unit tests sit beside each module. The `state.rs` reducer tests run without a-terminal since `TranscriptState` has no ratatui/crossterm/IO dependencies.-`tests/cli_e2e.rs` covers process-boundary behavior (`--help` output, flag-validation before the core boots) by spawning the built binary.+Unit tests are `*_tests.rs` siblings (`state_tests.rs` needs no terminal).+`tests/cli_e2e.rs` spawns the built binary.```bashcargo test -p openhuman-tui+pnpm debug rust openhuman_tui```## Packaging-`openhuman-tui` ships as the `openhuman-tui` binary alongside `openhuman-core`-in the CLI tarball (`scripts/release/package-cli-tarball.sh`) and the apt-packages (`scripts/release/build-apt-packages.sh`).+`openhuman-tui` ships alongside `openhuman-core` in the CLI tarball+(`scripts/release/package-cli-tarball.sh`) and the apt packages+(`scripts/release/build-apt-packages.sh`).[ratatui]: https://ratatui.rs