Agent Control Protocol (ACP) Bridge
Theacp command implements the Agent Control Protocol stdio bridge. It allows external IDEs (like VS Code or Cursor) or other ACP-compliant clients to use Palyra as a backend agent provider via standard input/output.
Implementation and Data Flow
The bridge is implemented incrates/palyra-cli/src/acp_bridge.rs and acts as a translator between ACP JSON-RPC messages and Palyra’s gRPC Gateway API.
- Initialization: The bridge starts a
PalyraAcpAgentwhich wraps anAgentConnectioncrates/palyra-cli/src/acp_bridge.rs#56-63. - Session Mapping: ACP sessions are mapped to Palyra sessions using a
BridgeStatewhich tracksSessionBinding(mapping ACPSessionIdto PalyraCanonicalId) crates/palyra-cli/src/acp_bridge.rs#31-42. - Prompt Handling: When a client sends a prompt, the bridge calls
GatewayRuntimeClient::run_agent_stream. It handles streaming events (text, tool calls) and converts them back to ACPSessionUpdatenotifications crates/palyra-cli/src/acp_bridge.rs#100-116. - Permission Proxy: If the Palyra daemon requires human-in-the-loop approval for a tool, the bridge can proxy this request back to the ACP client using
request_permissioncrates/palyra-cli/src/acp_bridge.rs#118-131.
ACP Shim Mode
The CLI includes a “shim” mode (palyra acp shim) which provides legacy compatibility for tools expecting older agent protocol signatures while routing the actual execution through the modern ACP bridge crates/palyra-cli/src/commands/agent.rs#110.
Diagram: ACP Bridge Request Flow
Sources: crates/palyra-cli/src/acp_bridge.rs#31-63, crates/palyra-cli/src/commands/agent.rs#110-111.
Terminal User Interface (TUI)
The TUI provides a full-screen interactive terminal environment for managing sessions and chatting with agents without leaving the command line. It is built using theratatui and crossterm libraries crates/palyra-cli/src/tui/mod.rs#7-19.
Key Components
- OperatorRuntime: Handles the asynchronous communication with the daemon crates/palyra-cli/src/client/operator.rs#22.
- App Struct: Maintains the TUI state, including the
transcript(history of messages),active_stream(the current running agent task), andfocus(Input vs Transcript) crates/palyra-cli/src/tui/mod.rs#107-130. - Mode System: The TUI switches between
Chat,Picker(for selecting agents/models),Approval(for tool execution authorization), andSettingscrates/palyra-cli/src/tui/mod.rs#44-52.
Event Loop
Therun_loop function drives the interface crates/palyra-cli/src/tui/mod.rs#148-164:
- Drain Events: Polls the
ManagedRunStreamfor new tokens or tool calls from the daemon. - Render: Draws the UI frames using
ratatuiwidgets. - Handle Input: Captures keystrokes via
crosstermto update the input buffer or navigate the transcript.
Agent and Session Commands
The CLI provides a suite of commands for direct agent interaction and CRUD operations on sessions.Agent Commands (palyra agent ...)
- Run: A single-shot execution of an agent prompt. Supports
ndjsonoutput for machine consumption crates/palyra-cli/src/commands/agent.rs#31-74. - Interactive: A REPL-style interface that maintains session context between prompts crates/palyra-cli/src/commands/agent.rs#75-109. It supports slash commands like
/session,/reset, and/abortcrates/palyra-cli/src/commands/agent.rs#145-191.
Session Management (palyra sessions ...)
Sessions represent the persistent history and state of an agent interaction.
- List: Retrieves a paginated list of sessions from the
JournalStorecrates/palyra-cli/src/commands/sessions.rs#48-94. - History: Searches through session transcripts using the daemon’s FTS (Full Text Search) capabilities crates/palyra-cli/src/commands/sessions.rs#95-154.
- Compaction: Triggers session compaction to reduce token usage by summarizing old history crates/palyra-cli/src/commands/sessions.rs#31-33.
Workspace Patching
A critical capability of agent commands is the ability to apply filesystem changes viaapply_workspace_patch. This function enforces WorkspacePatchLimits (max bytes, max files) and performs atomic writes with rollback on failure crates/palyra-common/src/workspace_patch.rs#207-211.
Sources: crates/palyra-common/src/workspace_patch.rs#23-39, crates/palyra-common/src/workspace_patch.rs#207-211.