Designing and Implementing Run-State Visualization for AI Coding Assistants
AI coding assistants perform multi-step tasks—reading context, reasoning, calling tools, and generating answers—yet users often see only a growing block of text. This article explains how to abstract internal execution events into a small set of display states (idle, working, done), presents a minimal pure-function state reducer with Python code, covers design principles such as strict completion-signal semantics and fallback timeouts, and compares implementation approaches for terminal and graphical environments, ending with an engineering checklist for robust state visualization.
1. Why Run State Is Hard to Judge
A single task round of an AI coding assistant typically involves multiple steps: reading context, reasoning, invoking tools, waiting for results, and producing an answer. From the user’s perspective, the interface often shows nothing more than a steadily growing block of text. It is difficult to tell whether the assistant is still processing, stuck on a particular tool call, or already finished.
This creates two practical problems. First, the user cannot decide whether to keep waiting or to interrupt. Second, the user cannot confirm whether the round truly completed—they can only infer it after reading the answer.
The problem becomes more severe when a task is interrupted or fails. If the UI presents “completed normally,” “interrupted by the user,” and “execution error” identically, users will mistake failure for success. The value of state visualization, therefore, is not aesthetics—it is letting users accurately read the outcome of a task.
2. Abstracting Execution into a Display State Model
The internal execution process contains far more detail than the interface needs to express. A sound approach is to define a small number of display states first, then map internal events onto them.
We recommend three display states:
- Idle: No task is running; the interface stays still.
- Working: A task round has started; the interface shows the current step.
- Done: A task round has ended normally; the interface shows a brief, unambiguous completion signal, then returns to idle.
The mapping between internal events and display states:
| Internal Event | Display State | Displayed Content |
|---|---|---|
| Round starts | Working | Generic status text |
| Tool call starts | Working | Tool name |
| Tool call ends | Working | Unchanged, waiting for the next step |
| Round ends normally | Done | Completion signal, held for a few seconds |
| Round interrupted or errored | Idle | No completion signal |
| Subtask starts | Keep current state | No transition |
A key point here: the end of a tool call does not mean the task is done. Only the end of the entire round may trigger the completion signal. Otherwise, users will believe the task is finished before the assistant has delivered its final answer.
3. Design Principles
1. Signals must come from real events. State transitions should be driven by runtime events, not guessed by timers. Timers are appropriate for controlling display duration, not for judging task progress.
2. The completion signal belongs exclusively to a full round. The end of a single tool call or sub-step must not trigger the completion display. The semantics of the completion signal must be strict; otherwise users will quickly stop trusting it.
3. Abnormal outcomes must be distinguishable from success. On interruption or error, the interface should return directly to idle without showing the completion signal. If an error message is needed, use a dedicated error indicator rather than reusing the completion signal.
4. Display granularity should match what users care about. Users typically only need to know which tool the assistant is using. Command arguments, file paths, and file contents may contain sensitive information and clutter the UI, so they should not be shown directly.
5. The state machine needs a fallback. If the end event is lost due to a network or process failure, the interface could remain stuck in “working” forever. Set a timeout that returns the display to idle after a long period without new events, and log the incident for troubleshooting.
4. A Minimal State Reducer Example
The core of state updating can be written as a pure function: it takes the current state and an event, and returns the new state. This makes unit testing easy and keeps the logic independent of any UI framework.
from dataclasses import dataclassIDLE = "idle"WORKING = "working"DONE = "done"@dataclass(frozen=True)class DisplayState:mode: str = IDLEdetail: str = "" # current tool name or status textdef reduce_state(state: DisplayState, event: dict) -> DisplayState:kind = event.get("type")if kind == "turn_start":return DisplayState(mode=WORKING, detail="")if kind == "tool_start":# Tool name comes from an external event; escape and truncate before renderingname = str(event.get("name", "unknown tool"))[:40]return DisplayState(mode=WORKING, detail=name)if kind == "turn_end":if event.get("status") == "completed":return DisplayState(mode=DONE, detail="")# Interrupted or errored: do not show the completion signalreturn DisplayState(mode=IDLE, detail="")if kind == "subagent_start":# Keep the main state unchanged during subtasksreturn statereturn state
The done state is held for a fixed duration—8 seconds in this example. That duration is controlled by a timer in the rendering layer; the reducer itself knows nothing about time. With this separation of concerns, state logic and visual presentation can be modified and tested independently.
5. Display Boundaries for Subtasks
When the main task spawns subtasks, the display layer must decide whether to follow subtask state changes. There are two common approaches.
Approach A: Follow subtask transitions. Users see more detail, but the main state changes frequently. The completion signal may also be falsely triggered by a subtask’s end event, blurring its semantics.
Approach B: Keep the main state unchanged during subtasks. The main view reflects only the main round’s state, and the completion signal strictly indicates the end of the entire round. If subtask information is genuinely needed, list subtask names in a secondary text area without changing the main state.
If the completion signal’s semantics must remain strict, Approach B is recommended. The cost is that users cannot see subtask details, but this can be compensated for in a secondary information area.
6. Implementation in Two Rendering Environments
The same state model can be implemented on different interfaces, but the rendering constraints differ significantly.
Terminal environments. Terminals use character cells as the minimum unit, with limited column width and row height. A common technique is drawing with half-block characters: each character cell represents two vertical pixels, so a 16-row area can represent 32 pixel rows. When the terminal is narrower than a certain column width, the side panel should be hidden and shown again automatically when there is enough width. Terminal size changes must also be detected before rendering to avoid overflow or misalignment.
Graphical interfaces. A graphical client can use bitmap or vector assets, supporting smooth transitions and richer animation. The trade-offs are higher resource consumption and the need to handle high-resolution displays and varying scale factors. Animations should reduce their refresh rate when idle.
| Dimension | Terminal | Graphical UI |
|---|---|---|
| Minimum unit | Character cell | Pixel |
| Size constraints | Fixed columns and rows | Freely scalable |
| Transitions | Limited | Smooth |
| Main risks | Misalignment, overflow | Resource usage, scaling artifacts |
7. Engineering Considerations
- Throttling and coalescing: Tool calls can occur at high frequency. Merge multiple updates within a short window before rendering to avoid flicker.
- Input escaping: External strings such as tool names must be escaped and length-limited before display. Otherwise control characters may corrupt the terminal display or be interpreted as format directives.
- Accessibility: State must not be conveyed by color or graphics alone; every state should have a corresponding text label.
- Privacy protection: The interface shows only state and tool names—never command arguments, file contents, or credentials.
- Resource control: Lower the refresh rate when idle so a long-running interface does not continuously consume CPU.
8. Acceptance Checklist
- Normal completion: the completion signal appears and the display returns to idle after the configured duration.
- User interruption mid-task: no completion signal; the display returns directly to idle.
- Execution error: no completion signal; an error message is shown or the display returns to idle.
- Subtask running: the main display state remains unchanged.
- End event lost: the display returns to idle after a timeout and leaves a log entry.
- Insufficient terminal width: the side panel hides correctly and the main content does not overflow.
- Overly long tool name: truncated display works without breaking the layout.
- Tool name containing special characters: escaped display works without affecting terminal state.
