Skip to main content
The Palyra TUI provides a high-fidelity terminal-based operator client that mirrors the capabilities of the Web Console. It is implemented using the ratatui ecosystem and provides a multi-modal interface for session management, agent interaction, and real-time run monitoring.

Overview and Architecture

The TUI is encapsulated within the palyra-cli crate and operates as a standalone interactive mode. It leverages a dedicated OperatorRuntime to manage gRPC communication with the palyrad gateway, handling streaming events and command execution.

Key Components

ComponentFile PathRole
Appcrates/palyra-cli/src/tui/mod.rs#122-152Central state machine for the TUI, managing transcript, input, and UI mode.
OperatorRuntimecrates/palyra-cli/src/client/operator.rs#15-17Business logic layer for interacting with the Gateway and Control Plane.
ManagedRunStreamcrates/palyra-cli/src/client/operator.rs#31-35Wraps the gRPC RunStream, providing an MPSC-based event queue for the TUI loop.
TuiSlashPaletteStatecrates/palyra-cli/src/tui/slash_palette.rs#110-113Manages the state of the command palette, including suggestions and active commands.

Data Flow: Run Stream Processing

The TUI uses an asynchronous run loop that polls for terminal events and drains gRPC stream events concurrently. Sources: crates/palyra-cli/src/tui/mod.rs#177-193, crates/palyra-cli/src/client/operator.rs#137-151

Shared Chat Commands & Parity

Palyra maintains strict parity between the Web Console and the TUI using a shared command registry. This registry defines slash commands, their execution context (local vs. server), and surface visibility.

Command Registry Implementation

The registry is stored as a JSON artifact in the web application but is compiled into the CLI binary using include_str! and the OnceLock pattern.

Common TUI Commands

CommandExecutionDescription
/agentServerSwitch active agent or open agent picker apps/web/src/chat/chatCommandRegistry.json#39-49.
/statusLocalPrint compact runtime status in the transcript apps/web/src/chat/chatCommandRegistry.json#15-25.
/undoServerRestore latest safe checkpoint apps/web/src/chat/chatCommandRegistry.json#147-157.
/shellLocalToggle local shell execution capability crates/palyra-cli/tests/shared_chat_command_parity.md#50-50.
Sources: crates/palyra-cli/src/shared_chat_commands.rs#7-10, crates/palyra-cli/tests/shared_chat_command_parity.md#1-51

The Slash Palette

The Slash Palette is the primary navigation and discovery mechanism. It provides real-time suggestions based on the user’s input and the current TuiSlashEntityCatalog.

Entity Catalog and Suggestions

The catalog caches entities retrieved from the daemon to provide instant autocomplete for IDs and keys. Sources: crates/palyra-cli/src/tui/slash_palette.rs#8-16, crates/palyra-cli/src/tui/slash_palette.rs#132-134

Implementation Details

  1. Trigger: Activation occurs when input starts with / crates/palyra-cli/src/tui/slash_palette.rs#135-139.
  2. Command Resolution: Uses resolve_shared_chat_command_name to handle aliases (e.g., /abort resolving to /interrupt) crates/palyra-cli/src/tui/slash_palette.rs#145-149.
  3. Suggestion Logic: If a command is recognized, it triggers build_entity_suggestions to populate the palette with relevant items from the TuiSlashEntityCatalog crates/palyra-cli/src/tui/slash_palette.rs#171-181.

UI States and Interaction

The TUI utilizes a Mode and Focus system to manage keyboard input routing.

UI Modes (enum Mode)

Focus Management

The Focus enum (crates/palyra-cli/src/tui/mod.rs#54-57) determines whether keystrokes (like arrows) scroll the Transcript or move the cursor in the Input box.

Tool Approvals

When an agent requests a sensitive tool, the ManagedRunStream yields a ToolApprovalRequest. The TUI switches to Mode::Approval, prompting the operator. The decision is sent back via send_tool_approval_decision which routes the response through the gRPC request stream crates/palyra-cli/src/client/operator.rs#50-68. Sources: crates/palyra-cli/src/tui/mod.rs#53-81, crates/palyra-cli/src/client/operator.rs#154-173