Skip to content

API Reference parrot.cli.commands

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.cli.commands

View source

Slash command dispatcher and built-in commands for the AI-Parrot agent REPL.

Provides SlashCommandDispatcher with built-in commands: /tools, /info, /clear, /export, /stream, /help, /resume, /quit (aliased as /exit).

Protocol note: handlers take a structural CommandContext (a typing.Protocol), not a concrete presenter class — both the inline REPL (TASK-3407) and TUICommandContext (Textual workspace, TASK-3411) satisfy it without inheritance, which keeps this module free of any runtime import of parrot.cli.repl (avoiding the circular import at repl.py:22).

Class CommandContext

Host surface a handler may touch. Implemented by the inline REPL (TASK-3407) and TUICommandContext (tui/adapter.py, TASK-3411).

renderer is declared as a read-only property (never reassigned by any handler or presenter) rather than a plain attribute, so mypy checks it covariantly: a presenter's ResponseRenderer/TUIRenderer -- both supersets of RendererProtocol -- correctly satisfy this Protocol without widening either concrete class's own self.renderer type.

Attributes:

Attribute Type Description
bot Any
config REPLConfig
dispatcher SlashCommandDispatcher
runner TurnRunner
renderer RendererProtocol
history List[ConversationTurn]

Method CommandContext.suspend

Yield the terminal to a foreign prompt (HITL, device code): inline → LiveRegion.modal(); TUI → App.suspend().

suspend() -> ContextManager[None]

Returns: ContextManager[None]

Class ConversationTurn

A single turn in the conversation history (used by /export).

Parameter Type Default Description
query str
response Any
timestamp datetime datetime.now()

Fields:

Field Type Default Description
query str The user's input.
response Any The agent's AIMessage response.
timestamp datetime field(default_factory=datetime.now) When this turn occurred.

Method ConversationTurn.to_dict

Serialise the turn to a JSON-safe dictionary.

to_dict() -> Dict[str, Any]

Returns: Dict[str, Any] — Dictionary with query, response, and timestamp keys.

Alias REPLConfig

Re-exported from parrot.cli.repl.REPLConfig.

Class RendererProtocol

What a slash-command handler may call on ctx.renderer (inline ResponseRenderer or the TUI adapter).

Method RendererProtocol.print

print(*args: Any, **kwargs: Any) -> None

Parameter Type Default Description
*args Any ()
**kwargs Any {}

Method RendererProtocol.render

render(response: Any) -> None

Parameter Type Default Description
response Any

Method RendererProtocol.render_error

render_error(error: Exception) -> None

Parameter Type Default Description
error Exception

Method RendererProtocol.render_table

render_table(headers: List[str], rows: List[List[str]], title: Optional[str] = None) -> None

Parameter Type Default Description
headers List[str]
rows List[List[str]]
title Optional[str] None

Method RendererProtocol.render_info

render_info(lines: List[tuple[str, str]]) -> None

Parameter Type Default Description
lines List[tuple[str, str]]

Method RendererProtocol.render_history

render_history(turns: List[ConversationTurn], *, session_id: str) -> None

Parameter Type Default Description
turns List[ConversationTurn]
session_id str

Class SlashCommand

A registered slash command.

Parameter Type Default Description
name str
description str
handler Callable

Fields:

Field Type Default Description
name str Command trigger string (without leading slash), e.g. tools.
description str Short description shown in /help.
handler Callable Async callable handler(ctx, args) -> None.

Class SlashCommandDispatcher

Dispatches slash commands in the agent REPL.

Parses /command [args] strings and routes them to registered async handler functions. Unknown commands print the help listing.

Attributes:

Attribute Type Description
logger Module-level logger.

Method SlashCommandDispatcher.register

Register a slash command.

register(cmd: SlashCommand) -> None

Parameter Type Default Description
cmd SlashCommand The SlashCommand to register.

Method SlashCommandDispatcher.dispatch_async

Parse and execute a slash command asynchronously.

Preferred over dispatch() when called from an async context.

dispatch_async(input_text: str, ctx: CommandContext) -> bool

Parameter Type Default Description
input_text str Raw input string from the user.
ctx CommandContext The CommandContext instance.

Returns: bool — True if the input was a slash command, False otherwise.

Method SlashCommandDispatcher.get_completions

Return slash command names for tab completion.

get_completions() -> List[str]

Returns: List[str] — List of strings like ["/tools", "/info", ...].

Alias TurnRunner

Re-exported from parrot.cli.session.TurnRunner.

Alias load_session_pointer

Re-exported from parrot.cli.modes.load_session_pointer.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally