Expand description
OpenCode event parser implementation
This module handles parsing and displaying OpenCode NDJSON event streams.
§Streaming Output Behavior
This parser implements real-time streaming output for text deltas. When content
arrives in multiple chunks (via text events), the parser:
- Accumulates text deltas from each chunk into a buffer
- Displays the accumulated text after each chunk
- Uses carriage return (
\r) and line clearing (\x1b[2K) to rewrite the entire line, creating an updating effect that shows the content building up in real-time - Shows prefix on every delta, rewriting the entire line each time (industry standard)
Example output sequence for streaming “Hello World” in two chunks:
[OpenCode] Hello\r (first text event with prefix, no newline)
\x1b[2K\r[OpenCode] Hello World\r (second text event clears line, rewrites with accumulated)
[OpenCode] ✓ Step finished... (step_finish shows prefix with newline)§Single-Line Pattern
The renderer uses a single-line pattern with carriage return for in-place updates. This is the industry standard for streaming CLIs (used by Rich, Ink, Bubble Tea).
Each delta rewrites the entire line with prefix, ensuring that:
- The user always sees the prefix
- Content updates in-place without visual artifacts
- Terminal state is clean and predictable
Structs§
- Open
Code Cache - Cache statistics
- Open
Code Event OpenCodeevent types- Open
Code Parser OpenCodeevent parser- Open
Code Part - Nested part object containing the actual event data
- Open
Code Time - Time information
- Open
Code Tokens - Token statistics from
step_finishevents - Open
Code Tool State - Tool state containing status, input, and output