Skip to main content
This section documents the Palyra CLI’s capabilities for agent interaction, including the Agent Control Protocol (ACP) bridge for IDE/tool integration, the Ratatui-based Terminal User Interface (TUI), and the underlying session management logic that enables branching, history, and transcript exports.

Agent Control Protocol (ACP) Bridge

The ACP Bridge allows external tools (such as IDE extensions or automated scripts) to control Palyra agents via a standardized stdio-based JSON-RPC protocol. It acts as a translation layer between the agent_client_protocol and the Palyra gRPC Gateway.

Bridge Implementation

The bridge is primarily implemented in crates/palyra-cli/src/acp_bridge.rs via the PalyraAcpAgent struct crates/palyra-cli/src/acp_bridge.rs#56-63. It manages the mapping between ACP session IDs and Palyra ULID-based session identifiers using BridgeState crates/palyra-cli/src/acp_bridge.rs#39-42. Key functionalities include:

Data Flow: ACP to Gateway

The following diagram illustrates how an ACP request from an IDE is translated into a Palyra Run Stream. ACP Request Translation Flow Sources: crates/palyra-cli/src/acp_bridge.rs#31-63, crates/palyra-cli/src/acp_bridge.rs#163-170

Terminal User Interface (TUI)

The Palyra TUI provides a rich, interactive environment for managing agent sessions without leaving the terminal. It is built using the ratatui and crossterm crates.

TUI Architecture and State

The TUI lifecycle is managed by the App struct crates/palyra-cli/src/tui/mod.rs#107-130. It maintains:

Key Components

ComponentResponsibility
ManagedRunStreamHandles the background gRPC stream for a single run, emitting events to the TUI crates/palyra-cli/src/client/operator.rs#31-35.
run_loopThe main event loop that polls for terminal events and drains stream events crates/palyra-cli/src/tui/mod.rs#148-164.
PickerStateManages the selection of agents or sessions within a modal overlay crates/palyra-cli/src/tui/mod.rs#76-81.
TUI Entity Association Sources: crates/palyra-cli/src/tui/mod.rs#107-130, crates/palyra-cli/src/client/operator.rs#15-35

Session Management

The CLI provides comprehensive commands for managing the lifecycle of agent sessions, including branching, history, and state recovery.

Session Lifecycle Commands

The sessions command group is defined in crates/palyra-cli/src/args/sessions.rs crates/palyra-cli/src/args/sessions.rs#4-214 and implemented in crates/palyra-cli/src/commands/sessions.rs.

Interactive Session Handling

For standard terminal interaction (outside the full TUI), run_agent_interactive_async provides a REPL-like experience crates/palyra-cli/src/commands/agent.rs#115-135. It supports slash commands such as:

Workspace Patching

A critical part of session management involves the agent’s ability to modify files. The apply_workspace_patch function in crates/palyra-common/src/workspace_patch.rs handles the atomic application of multi-file changes crates/palyra-common/src/workspace_patch.rs#207-211. It enforces security limits (e.g., max_files_touched, max_patch_bytes) and provides rollback capabilities on failure crates/palyra-common/src/workspace_patch.rs#23-39. Sources: crates/palyra-cli/src/commands/sessions.rs#3-44, crates/palyra-cli/src/commands/agent.rs#115-154, crates/palyra-common/src/workspace_patch.rs#101-138