Skip to main content
This page details the interactive and integration layers of the Palyra CLI, specifically the Terminal User Interface (TUI), the Agent Control Protocol (ACP) bridge for IDE integrations, and the session management infrastructure.

Terminal User Interface (TUI)

The Palyra TUI provides a rich, interactive terminal experience for chatting with agents, managing sessions, and approving tool executions. It is built using ratatui and crossterm crates/palyra-cli/src/tui/mod.rs#7-19.

Architecture & State Machine

The TUI is governed by an App struct that maintains the local UI state, including the OperatorRuntime for daemon communication, the current transcript, and active_stream for real-time response rendering crates/palyra-cli/src/tui/mod.rs#107-130. Key UI Modes:

TUI Component Relationship

The following diagram maps the TUI logic to the underlying code entities. TUI Entity Map Sources: crates/palyra-cli/src/tui/mod.rs#107-164, crates/palyra-cli/src/client/operator.rs#15-35

Agent Control Protocol (ACP) Bridge

The ACP Bridge allows Palyra to act as a backend for external tools (like IDE extensions) that speak the Agent Control Protocol. It translates ACP JSON-RPC requests into Palyra gRPC calls.

Bridge Implementation

The bridge is implemented in acp_bridge.rs and utilizes the agent-client-protocol crate crates/palyra-cli/src/acp_bridge.rs#7-18. It maintains a BridgeState to map ACP session identifiers to Palyra’s internal ULID-based sessions crates/palyra-cli/src/acp_bridge.rs#31-42. Protocol Translation Flow:
  1. Session Resolution: ACP requests with _meta fields (like sessionKey or sessionLabel) are parsed by session_overrides crates/palyra-cli/src/acp_bridge.rs#163-170.
  2. Permission Handling: When a Palyra agent requires approval for a tool, the bridge sends a RequestPermission notification back to the ACP client crates/palyra-cli/src/acp_bridge.rs#118-131.
  3. Stream Mapping: Palyra RunStreamEvent messages are converted into ACP ContentBlock sequences crates/palyra-cli/src/acp_bridge.rs#190-210.

ACP Data Flow

ACP to gRPC Translation Sources: crates/palyra-cli/src/acp_bridge.rs#56-63, crates/palyra-cli/src/acp_bridge.rs#133-170, crates/palyra-cli/src/client/operator.rs#137-147

Session Management

Session management is handled through the palyra sessions command group and the OperatorRuntime client module.

Core Commands

The run_sessions_async function dispatches various session operations crates/palyra-cli/src/commands/sessions.rs#14-45:
CommandFunctionalityCode Reference
listLists active and archived sessions with pagination.crates/palyra-cli/src/commands/sessions.rs#48-94
historySearches session history via the control plane.crates/palyra-cli/src/commands/sessions.rs#95-154
resolveCreates or resumes a session by Key or ID.crates/palyra-cli/src/commands/sessions.rs#19-22
compactPreviews or applies session history compaction.crates/palyra-cli/src/commands/sessions.rs#31-33
checkpointCreates/restores point-in-time session snapshots.crates/palyra-cli/src/commands/sessions.rs#34-36

Session Lifecycle Logic

Sessions are identified by a CanonicalId (ULID) crates/palyra-cli/src/commands/sessions.rs#129. The OperatorRuntime provides the abstraction for these operations, wrapping the GatewayRuntimeClient which performs the actual gRPC calls crates/palyra-cli/src/client/operator.rs#101-118.

Operator Client Modules

The OperatorRuntime is the primary high-level client used by the CLI for user-facing operations.

Managed Run Streams

A critical feature of the OperatorRuntime is the ManagedRunStream. It handles the complexity of bi-directional gRPC streaming crates/palyra-cli/src/client/operator.rs#31-35:

Messaging Integration

The CLI also supports sending messages through configured connectors (Discord, Slack, etc.) via the message client crates/palyra-cli/src/client/message.rs#28-41. This uses the post_connector_action helper to communicate with the daemon’s channel router crates/palyra-cli/src/client/message.rs#105-122. Sources: crates/palyra-cli/src/client/operator.rs#137-151, crates/palyra-cli/src/client/message.rs#95-123, crates/palyra-cli/src/commands/message.rs#13-22