createRenderer() creates an EventRenderer instance that formats and displays Pi agent events in the terminal.
Function Signature
Configuration object:
If
true, output raw NDJSON events. If false, use the pretty text renderer.Enable ANSI color codes in text mode. Automatically disabled if
NO_COLOR env var is set.Show extended thinking blocks in text mode (e.g., Claude’s
<thinking> tags)Show additional debug output: turn markers,
setStatus messages, etc.EventRenderer
An object with
render(event) and cleanup() methodsEventRenderer Interface
render()
Process and display a single event.A Pi event or app history event. See PiEvent types.
cleanup()
Flush any pending output and reset internal state.Text Renderer
The default renderer formats events with styled labels and streaming output. Features:- Streaming text deltas (assistant messages)
- Tool execution with live output
- Collapsible thinking blocks
- Color-coded tags:
[tool],[error],[compact], etc. - Timing information for tool calls
setStatusdebouncing (200ms)
JSON Renderer
Outputs one JSON object per line (NDJSON). Useful for programmatic consumption or debugging. Example Output:Event Types
The renderer handles these event categories:Agent Lifecycle
agent_start— Agent begins processingagent_end— Agent completes (shown in verbose mode)turn_start,turn_end— Conversation turns
Messages
message_start— New message (user or assistant)message_update— Streaming deltas:text_start,text_delta,text_endthinking_start,thinking_delta,thinking_end(requiresshowThinking: true)toolcall_start,toolcall_delta,toolcall_end
message_end— Message complete
Tool Execution
tool_execution_start— Tool called with argumentstool_execution_update— Streaming tool output (e.g., bash stdout)tool_execution_end— Tool finished with result/error
Auto-Compaction
auto_compaction_start— Context compaction beginsauto_compaction_end— Compaction result or error
Auto-Retry
auto_retry_start— API retry attemptauto_retry_end— Final retry outcome
Errors
extension_error— Extension threw an errorprompt_error— User prompt failed
UI Requests
extension_ui_request— Agent requests user input:setStatus— Status message (verbose mode only)notify— Notificationconfirm— Yes/no promptselect— Choose from optionsinput— Text inputeditor— Multi-line input
App History
app_history_event— Voice/GUI events:user_audio,user_text— User inputassistant_audio,assistant_text— Assistant outputtool_call— Voice tool execution
Options Examples
Minimal Output
Debug Mode
JSON Logging
Full Example
Implementation Notes
- Text renderer tracks streaming state to avoid duplicate labels when events arrive out-of-order
- Tool output is diffed incrementally to show only new lines in
tool_execution_update - Status messages are debounced (200ms) to avoid flickering
- Color support respects
NO_COLORenvironment variable - Cleanup is essential before exit to flush pending output and avoid truncated lines