Skip to content

xterm.js web terminal component for agent sessions #676

@geoffjay

Description

@geoffjay

Context

Part of #671 (PTY execution backend epic). Blocked by: #675 (PTY stream relay endpoint).

Add a web terminal component using xterm.js that connects to the orchestrator's /terminal/{agent_id} endpoint, providing a real terminal experience for agent sessions in the UI.

Problem

The current AgentLogView.tsx strips ANSI sequences and displays plain timestamped log lines. This is great for structured viewing but loses the rich terminal experience. Users want to:

  • See Claude's output as it would appear in a real terminal (colors, formatting, progress indicators)
  • Optionally interact with the session (send keystrokes, Ctrl-C)
  • Debug agent behavior with full terminal fidelity

Design

Component: AgentTerminal.tsx

A new component that renders an xterm.js terminal connected to the PTY stream relay.

interface AgentTerminalProps {
  agentId: string;
  readOnly?: boolean;  // default: true (observation mode)
}

Tab Layout

The agent detail page gets two tabs:

  • Logs (default) — existing AgentLogView.tsx (structured, searchable, timestamped)
  • Terminal — new AgentTerminal.tsx (raw PTY, full terminal rendering)

The Terminal tab should show a badge/indicator when the backend doesn't support PTY streaming (tmux/docker backends).

Features

  1. Terminal rendering: Full xterm.js with ANSI color support, cursor positioning, scrollback
  2. Auto-connect: Connects to ws://{orchestrator}/terminal/{agentId} when tab is active
  3. Read-only mode (default): Displays output but doesn't send input
  4. Interactive mode (opt-in toggle): Forwards keyboard input to PTY
  5. Fit addon: Auto-resize terminal to container, send resize messages
  6. Reconnection: Match existing WebSocket reconnection behavior (exponential backoff)
  7. Copy/paste: Standard terminal selection and clipboard support
  8. Theme: Match the existing UI dark/light theme

Dependencies

{
  "@xterm/xterm": "^5.x",
  "@xterm/addon-fit": "^0.x",
  "@xterm/addon-web-links": "^0.x",
  "@xterm/addon-search": "^0.x"
}

Implementation Steps

  1. Install xterm.js and addons: bun add @xterm/xterm @xterm/addon-fit @xterm/addon-web-links @xterm/addon-search
  2. Create ui/src/components/agents/AgentTerminal.tsx
  3. Implement WebSocket connection to /terminal/{agent_id} with binary frame handling
  4. Add fit addon for auto-resize with resize message sending
  5. Add read-only / interactive mode toggle
  6. Create tab layout in agent detail page (Logs | Terminal)
  7. Handle graceful degradation when PTY backend isn't available
  8. Style to match existing UI theme
  9. Add search capability (addon-search)

Relevant Files

  • ui/src/components/agents/AgentLogView.tsx — existing log display (reference)
  • ui/src/services/websocket.ts — existing WebSocket manager (reference for connection patterns)
  • ui/src/hooks/useAgentDetail.ts — agent detail page hook
  • ui/src/pages/AgentsPage.tsx — agents page layout

Acceptance Criteria

  • xterm.js terminal renders agent PTY output with full ANSI support
  • Terminal auto-resizes to container and sends resize events
  • Tab switcher between Logs and Terminal views
  • Read-only mode by default, interactive mode toggle
  • WebSocket reconnection with exponential backoff
  • Graceful fallback when PTY streaming unavailable (message explaining tmux backend limitation)
  • Theme matches existing UI (dark/light)
  • Copy/paste works with standard terminal selection
  • No performance degradation for long-running sessions (xterm.js scrollback limits)

Caution

All work for this issue must branch from feature/autonomous-pipeline and PR back into it — never directly to main.
Use bun (not npm) for all package management.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentdesign-agentDesign work — dispatches to design-worker workflowenhancementNew feature or requestfrontendFrontend application codeuiUser interface and frontend

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions