TUI

Swarm's terminal user interface (TUI) is the primary way to monitor and interact with a running swarm session. It provides real-time visibility into agent states, logs, events, and session metadata.

Design Philosophy

The TUI is a first-class component, not an afterthought (ADR-007). It's built with ratatui (a Rust TUI framework) on top of crossterm for terminal handling, rendering at approximately 30 FPS (33ms frame interval).

For environments where a TUI isn't suitable (CI, remote servers, testing), the --no-tui flag runs swarm in headless mode, logging to stdout instead.

Components

TuiApp

The TuiApp struct holds all mutable TUI state:

FieldTypeDescription
agentsVec<AgentEntry>Ordered list of agents (sorted by name)
selectedusizeIndex of the currently selected agent
log_viewerLogViewerLog file viewer for the selected agent
event_viewerEventViewerReal-time streaming event viewer
inputStringCurrent contents of the command input bar
session_idStringDisplayed in the status bar
quit_requestedboolSet to true when user requests quit
context_infoHashMap<String, ContextInfo>Per-agent context window usage
show_task_listboolTask list overlay visibility (Ctrl+T)
tasksVec<Task>Snapshot of tasks from the task store
show_workflow_panelboolWorkflow panel visibility (Ctrl+W)
show_iteration_panelboolIteration panel visibility (Ctrl+I)

AgentEntry

Each agent in the TUI is represented as an AgentEntry:

FieldTypeDescription
nameStringAgent name
stateAgentStateCurrent state from the state machine
log_pathPathBufPath to the agent's log file
livenessOption<AgentLiveness>Liveness monitoring data (idle time, stall, nudges)

Agent Panel

The left panel shows a list of all agents with their current state:

┌─ Agents ──────────────────┐
│ ● backend      Running    │
│ ● frontend     Running    │
│ ○ reviewer     CoolingDown│
│ ■ supervisor   Stopped    │
└───────────────────────────┘

Each agent shows:

  • A state indicator icon
  • The agent name
  • The current state label
  • Liveness suffix when available (running duration, idle time, stall warnings)

Log/Event Viewer

The right panel displays output for the selected agent:

  • Event viewer — Real-time streaming events from the agent's backend session
  • Log viewer — Fallback log file viewer when event streaming isn't available

The viewer auto-scrolls to follow new output.

Input Bar

The bottom of the screen shows a command input bar where you can type messages to send to agents. The input bar is always visible.

Overlays

Toggle-able overlay panels:

OverlayToggleContent
Task listCtrl+TTasks from the beads task store
Workflow progressCtrl+WActive/recent workflow runs and stages
Iteration progressCtrl+IIteration loop runs and status

Context Window

Per-agent context window usage is tracked and displayed:

FieldDescription
used_tokensTokens consumed in the current session
max_tokensMaximum context window size
usage_percentPercentage of context used
KeyAction
Up / DownSelect previous/next agent
Ctrl+TToggle task list overlay
Ctrl+WToggle workflow panel
Ctrl+IToggle iteration panel
q / Ctrl+CQuit (triggers graceful shutdown)

State Refresh

The TUI refreshes agent states each frame by calling AgentRegistry::states(). Liveness data is refreshed from a watch channel provided by the liveness monitor. This keeps the display current without expensive polling.

Headless Mode

When --no-tui is specified:

  • No terminal UI is rendered
  • Agent state changes are logged to stdout via tracing
  • The orchestrator still runs all the same subsystems (router, periodic tasks, etc.)
  • Shutdown is triggered by SIGTERM only (no interactive quit)