Skip to main content
This page details the operator-facing interaction layers of the Palyra CLI, including the terminal user interface (TUI), the Agent Control Protocol (ACP) bridge for IDE integrations, and the underlying gRPC transport mechanisms used to orchestrate agent runs and sessions.

Terminal User Interface (TUI)

The Palyra TUI is a ratatui-based interface providing a rich, interactive environment for managing agent sessions. It handles real-time event streaming, tool approval workflows, and multi-agent switching.

Implementation and State Management

The TUI is centered around the App struct crates/palyra-cli/src/tui/mod.rs#107-130, which maintains the UI state, including the OperatorRuntime, current session metadata, and a transcript of interaction entries. The application operates in several modes crates/palyra-cli/src/tui/mod.rs#45-52:
  • Chat: The primary interaction surface.
  • Picker: For selecting agents, sessions, or models.
  • Approval: A blocking state for manual tool execution authorization.
  • Settings: Toggling UI features like “Show Thinking” or “Local Shell”.

Event Loop and Rendering

The TUI uses a standard event loop powered by crossterm crates/palyra-cli/src/tui/mod.rs#148-164. It polls for terminal events every 50ms and drains asynchronous events from the ManagedRunStream crates/palyra-cli/src/tui/mod.rs#150.
ComponentRoleSource
setup_terminalEnables raw mode and alternate screencrates/palyra-cli/src/tui/mod.rs#166-171
drain_stream_eventsProcesses incoming NDJSON events from the daemoncrates/palyra-cli/src/tui/mod.rs#150
renderDraws the UI frames using ratatui widgetscrates/palyra-cli/src/tui/mod.rs#151
Sources: crates/palyra-cli/src/tui/mod.rs#1-180

ACP Bridge (Agent Control Protocol)

The ACP Bridge allows Palyra to act as a backend for IDEs and external tools (like VS Code or JetBrains) by shimming the standard input/output into Palyra’s gRPC protocol.

Shim Architecture

The bridge implements the PalyraAcpAgent crates/palyra-cli/src/acp_bridge.rs#81-98, which translates ACP JSON-RPC requests into Palyra GatewayRuntimeClient calls. Natural Language to Code Entity Space: ACP Flow Sources: crates/palyra-cli/src/acp_bridge.rs#31-63, crates/palyra-cli/src/acp_bridge.rs#81-98

Session and Permission Mapping

Sources: crates/palyra-cli/src/acp_bridge.rs#1-131

Agent Interaction and Run Orchestration

The CLI interacts with the daemon via the OperatorRuntime crates/palyra-cli/src/client/operator.rs#15-17, which abstracts gRPC connection management and stream handling.

Managed Run Streams

A “Run” is orchestrated through a ManagedRunStream crates/palyra-cli/src/client/operator.rs#31-35. This handles the bidirectional nature of the open_run_stream gRPC call:
  1. Downstream: Receives RunStreamEvent (text chunks, tool calls, status updates) crates/palyra-cli/src/client/operator.rs#42-48.
  2. Upstream: Sends ToolApprovalResponse back to the daemon when a tool requires operator consent crates/palyra-cli/src/client/operator.rs#50-68.

Run Execution Logic

The execute_agent_stream function (called by run_agent) crates/palyra-cli/src/commands/agent.rs#73 handles the lifecycle of a single prompt: Interaction Flow: CLI to Daemon Sources: crates/palyra-cli/src/client/operator.rs#137-200, crates/palyra-cli/src/commands/agent.rs#27-74

Session Management

The CLI provides comprehensive session control through the sessions command group crates/palyra-cli/src/commands/sessions.rs#47-94.

Key Operations

Session Resolution

Before a run begins, the CLI often calls resolve_session crates/palyra-cli/src/client/operator.rs#112-118. This ensures the session_key and session_label provided by the operator are mapped to a valid CanonicalId (ULID) in the daemon’s JournalStore. Sources: crates/palyra-cli/src/commands/sessions.rs#1-154, crates/palyra-cli/src/client/operator.rs#101-118

Operator Client Transport

The transport layer relies on GatewayRuntimeClient crates/palyra-cli/src/client/runtime.rs, which wraps the Tonic-generated gRPC stubs.

Connection Security

Connections are established using AgentConnection metadata, which includes:

Diagnostics

The daemon status and admin-status commands verify transport health by checking the /healthz endpoint crates/palyra-daemon/tests/health_endpoint.rs#27 and gRPC service availability crates/palyra-cli/tests/cli_v1_acp_shim.rs#23-57. Sources: crates/palyra-cli/tests/daemon_status.rs#18-132, crates/palyra-daemon/tests/health_endpoint.rs#1-158