# Design: Agent workspace and side panel

Status: **implemented** (Phase C, `d568dd0`; see [What shipped](#what-shipped-phase-c)).
Interface for the Agent Bridge (`../agents/bridge.md`).

The goal is an assistant that feels part of Phantom the way Copilot feels
part of GitHub: one place to hold longer conversations, and a panel that is
there on every page, sees what the user is looking at (by reference, with
permission) and can act through the same services as the user.

## Who and when

A researcher in the middle of an engagement: reading a request in History,
iterating in Repeater, writing a note, triaging a finding. They want to ask
"what is odd about this response?", hand over "summarise today's traffic
for api.example.com into a note", or approve a step an agent wants to take,
without leaving the page.

## Agent page (`/agent`, rail item "Agent", G A)

Two columns: the sidebar and the open conversation. There is no third
column; what the agent sees and its open work live in the header.

- **Sidebar**: New conversation and search on top; conversations in
  collapsible groups (Pinned, Recent, Archived on demand) as single-line
  rows with a short trailing time ("4h"; the agent and full time in the
  row's tooltip, a lock when sharing is paused); the connected agents as a
  compact folded group at the end (status beside each name, protocol
  limits in the tooltip, a click starts a conversation with that agent).
- **Header**: the conversation title on the left (renamed in place from
  ⋯), then one faint "Sees" line of what the agent sees of this window.
  On the right only quiet controls: "N open" when tasks run or approvals
  wait (a popover lists them; the task rows and approval cards stay
  inline in the thread), the agent as a status chip (dot and name), the
  labelled Sharing and Navigate chips the panel uses, and ⋯ with Rename,
  Pin and Archive.
- **Conversation**: one centred reading measure (740 px) shared by the
  thread and the composer, not chat bubbles. User messages are soft
  filled surfaces at the end of the column (no outline, 16 px corner, at
  most three quarters of the width). Agent replies read as plain text
  under a quiet name label (no monogram: a conversation has one agent),
  1.65 line height, spaced paragraphs, bold at 600; inline code on a faint
  tint; code blocks (the note renderer and code block components, with
  Copy) scroll horizontally inside their own box on the page and wrap in
  the panel, so they never widen the column. Under each completed reply,
  Copy (the reply's Markdown, credentials masked) and Quote (into the
  composer) appear on hover or focus and stay visible under the latest
  reply. Research references are the existing chips that open their
  module, tool activity collapsed one-line rows ("Read request #812 ·
  3 ms") that expand to the arguments and a redacted result, progress
  lines for tasks, errors with Retry, and **approval cards**: the
  operation in plain words, what it touches, the grant it relies on,
  Approve and Deny.
- **Composer** at the bottom: one rounded field that starts a single line
  tall and grows with the draft (to 40% of the window); + on the left
  starts a `[[` mention of a request, finding, note or target, and the
  agent picker (with the model of a provider), Stop while work runs
  (Escape) and Send (Enter) sit on the right of the same row; Shift+Enter
  for a new line. Attached references are chips above the field. One
  faint line under it on the page: "Agents read objects through their
  grants; treat replies as research notes."

Streaming text renders as it arrives with a thin vermillion caret; when a
message completes, nothing jumps.

## Global panel

A collapsible right panel available on every page (Ctrl+., a rail button,
the palette). It holds one conversation at a time with the same message
list and composer in a narrower measure, and is resizable and remembered
like other panels.

- **Workspace context** ([Design: Workspace Context Service](workspace-context.md)): the assistant always
  knows the vault, module, open resources, selection, visible data and
  filters, as references filtered by the agent's grants and redacted. The
  header shows what it sees ("History · request #812 · 3 selected"); one
  click pauses sharing for the conversation.
- **One conversation, two views**: the Agent page and the panel share the
  same store; switching between them or navigating never interrupts a
  stream, a task or the composer draft.
- **Attach to conversation**: a shared contextual action in the text
  selection menu, the History row menu, the request panel, the note row
  menu, the finding inspector, Report Studio and Files. It adds a reference
  chip to the composer.

## States

Empty (no agents configured): explain the two ways (connect an external
agent with a token, or add a provider) with buttons to Settings →
Connections. Disconnected agent: the composer still accepts messages; they
show as queued and send when the agent returns. Failed delivery: the
message shows failed with Retry. Provider errors: plain reason (rate
limited, key rejected, context too long) and what to do.

## Visual language

Kuro tokens only. Agent identity is shown with a small monogram tile and
the agent's name, never brand logos. Vermillion is reserved for the
streaming caret, primary actions and approval highlights. Tool activity
and progress are mono and quiet. Motion: messages fade up 6 px on arrival
(reduced motion: none); the panel slides like the side panels.

## Keyboard

Ctrl+. toggle panel; G A open the page; Enter send; Shift+Enter newline;
Escape stop; Ctrl+K palette commands for "New conversation", "Attach
selection", "Share this view".

## Backend contract (Phase B, implemented)

What the interface builds on ([Agent Bridge protocol](../agents/bridge-protocol.md),
[Agent Bridge routes](../agents/bridge-routes.md)):

- Sidebar: `GET /bridge/conversations?vault_id=&search=&pinned=&archived=`
  (pinned first, by last message); `POST /bridge/conversations`;
  `PATCH /bridge/conversations/{id}` for rename, pin, archive and the
  context-sharing switch; agents from `GET /connections/agents`.
- Conversation: `GET …/messages?after_seq=` (gapless `seq`; refetch after a
  reconnect), `POST …/messages` with an `Idempotency-Key` generated per
  composer send (a retried request never duplicates), `delivery` for the
  queued / failed states, `POST /bridge/messages/{id}/retry` for Retry.
- Live: the existing WebSocket delivers `bridge.conversation`,
  `bridge.message`, `bridge.delta` (`{message_id, offset, text}` for the
  streaming caret), `bridge.task`, `bridge.approval`, `agent.status` and
  `context.updated`, each with the full object; one store serves the page
  and the panel.
- Tasks and approvals: `GET /bridge/tasks?vault_id=&conversation_id=`,
  cancel / pause / resume; approval cards from `approval_request` messages
  and `GET /bridge/approvals?vault_id=&state=pending`, decided with
  `POST /bridge/approvals/{id}`.
- Workspace context: publish with the WebSocket `context` op
  ([Design: Workspace Context Service](workspace-context.md)); the header reads the
  user's own view from `GET /bridge/context?window=`.

## What shipped (Phase C)

Interface code lives in `frontend/src/components/agent/`, `views/AgentView.vue`,
the stores `agentConversations`, `agentMessages`, `agentWork`,
`agentComposer`, `agentRoster` and `workspaceContext`, the composables
`useAgentSession`, `useAttachToAgent`, `useOpenRef`, `useAgentCommands`,
`useProxyContext` and `useWorkspaceContext`, and the pure helpers in
`utils/agent/` (tested in `agentStream.spec.ts`, `agentRefs.spec.ts`,
`agentContext.spec.ts`). Calls are `bridgeApi.*` in `api/resources.ts`.

- **One store, two views.** Page and panel render the same
  `PAgentWorkspace` from the shared stores; nothing is owned by a view, so
  navigation and switching never interrupt a stream, a task or a draft.
  The open conversation (per vault) and drafts are kept for the tab's life
  (sessionStorage); the panel's width and open state are remembered.
- **New conversations are drafts** until their first message, which
  creates the conversation (title from the message) and moves the draft.
  The agent is chosen in the composer's picker or by clicking an agent in
  the sidebar; an existing conversation shows its agent.
- **Messages**: history by `seq` (`after_seq`), merged by id where the more
  advanced copy wins; a live `seq` past the next expected one, or a
  reconnect, fetches what was missed. Streams are assembled from
  `bridge.delta` by offset (repeats ignored, overlaps trimmed, a gap noted)
  and replaced by the stored text on `message.completed`. Each send has one
  `Idempotency-Key`; a send that never reached Phantom is retried with the
  same key, a message Phantom marked failed through the retry route.
- **Rows**: user text as a soft surface with a delivery note (waiting,
  queued while the agent is away, not delivered with Retry); agent text as
  Markdown via `PNoteMarkdown` (secrets masked, code highlighted with
  Copy); `tool_call`, `tool_result`, `progress`, `attachment` and approval
  decisions as one collapsed mono line; tasks as a line with a progress bar
  and pause, resume, cancel; approval cards with operation, what it
  touches, the grant in words, the reason, Approve (vermillion) and Deny,
  kept afterwards as a record. Stop (and Escape in the composer) cancels
  the conversation's open tasks: a stream itself can only be ended by its
  agent.
- **Composer**: the note editor (`createNoteEditor`, source mode, with
  extra keys and a compact theme through its new `extensions` option);
  `[[` suggestions open above the caret; attached references are chips;
  dropping files says Vault Files is still to come instead of pretending.
- **Attach to conversation**: History row menu (the row or the selection),
  request panel ("Ask agent"), the text selection menu ("Ask the agent
  about this": a quote plus its source, also shared as the selected text of
  the context), note row menu, finding inspector ("Ask agent"), Report
  Studio outline rows. Each opens the panel unless the Agent page is shown.
- **Honest states**: no agent for the vault explains connecting an
  external agent (Create a token) and that model providers come later; the
  sidebar states each agent's protocol limit ("MCP only: checks for
  messages", "Bridge: live messages, streamed replies"); an archived
  conversation offers Restore instead of a composer.
- **Keyboard and access**: Ctrl+., G A, palette entries (Go to Agent,
  Show / Hide agent panel, New conversation, Attach what is open or
  selected, Pause / resume sharing); the thread is a `log`, a polite live
  region announces completed replies, task rows are `status`, the panel
  edge is a keyboard-resizable separator; motion is a 6 px fade-up and
  respects reduced motion.

Deferred: drag-and-drop files (Vault Files), model providers and the
"what will be shared" preview (Phase D), slash commands in the composer,
per-row tool arguments as structured views (agents send Markdown today),
unread counts.
