# Ticket 5.1 — Agent Selector

**Phase**: 5 — OpenCode-Specific Features
**Priority**: High
**Depends on**: 1.4, 4.1

## Description

UI for switching between OpenCode's agents (build, plan, general). Each agent has different permissions and capabilities. The selector appears in the header or as tabs, mirroring OpenCode's TUI Tab-switching behaviour.

## Acceptance Criteria

### AC1: Displays available agents

```gherkin
Given the relay connects to OpenCode
When it fetches agents from GET /agent/
Then the UI shows agent options: build, plan, general
And each shows its name and a brief description
And the currently active agent is highlighted
```

### AC2: Switch agent

```gherkin
Given "build" agent is active
When the user selects "plan"
Then the relay sends the agent switch command to OpenCode
And the header updates to show "plan" as active
And a status message appears in chat: "Switched to plan agent"
```

### AC3: Agent description tooltip

```gherkin
Given the agent selector is visible
When the user hovers over an agent option
Then a tooltip shows:
  - Agent name
  - Description
  - Key permissions (e.g., "Read-only, no file edits")
  - Associated model (if different from default)
```

### AC4: Agent persists per session

```gherkin
Given the user switches to "plan" agent in session A
When they switch to session B (which uses "build")
Then the agent selector shows "build" for session B
And switching back to session A shows "plan"
```

## Testable Components

| Component | Test Type | What to Assert |
|-----------|-----------|----------------|
| Agent list parsing | Unit | Parses /agent/ response into display-ready list |
| Per-session agent tracking | Unit | Returns correct agent per session ID |
| Agent list rendering | E2E | All agents shown with names, active agent highlighted |
| Agent switch | E2E | Selecting agent sends switch command, UI updates immediately |
| Agent tooltip | E2E | Hovering shows description and permissions |

## Reference

- OpenCode agents: `../opencode/packages/opencode/src/agent/agent.ts`
- OpenCode agent API: `GET /agent/`
- Agents: build (primary, full access), plan (read-only), general (subagent)
