Files
orca/src/shared/dashboard-snapshot.ts
T
Brennan Benson 1df8aa5605 fix(dashboard): give the agent preview terminal a real pane's keyboard (#11015)
* fix(dashboard): give the agent preview terminal a real pane's keyboard

The dashboard's preview terminal is a bare xterm, not a pane, so it never
ran `resolveTerminalShortcutAction` — its only custom key handler covered
copy/paste and IME. Ctrl+Backspace therefore fell through to xterm's default
`\x08`, which readline binds to backward-delete-char: one character instead
of a word.

Route the preview's keys through the pane's own shortcut policy, so word and
line kills, Option chords, modified Enter, and scrollback chords encode
identically. Pane-scoped verdicts (splits, search, focus) are swallowed rather
than passed to xterm, which would send e.g. Ctrl+Shift+D as a bare Ctrl+D.

The policy needs three things the preview could not see:

- kitty-protocol flags — mirrored locally from the same PTY output stream
- the PTY's execution host — bytes follow the host, not the client OS, so a
  new `DashboardCard.terminalInput` profile is derived in the main renderer
  (the only one holding the store) and relayed to the pop-out
- host terminal options — the ConPTY backend and the kitty withhold now apply

Also brings the emulator itself up to a pane's: Orca's Unicode 11 width shim
(replayed CJK/emoji/ZWJ laid out wrong without it), Windows Ctrl+Alt chord
repair, user font/cursor/line-height/word-separator/sensitivity settings,
ligatures, the TUI wheel multiplier, lazy Arabic shaping, clickable links, and
the IME candidate anchor — extracted from pane-lifecycle so both surfaces share
one implementation.

The in-window drawer built its snapshot from a slice subset, which would have
degraded the new profile to client-OS defaults there; it now reads the full
store non-reactively.

* fix(dashboard): enumerate pane-scoped chords instead of a default case

The switch-exhaustiveness gate rejects a `default` over the shortcut-action
union — it would let a newly added action be swallowed silently instead of
forcing a decision at the preview's boundary.

* fix(dashboard): preserve native shortcuts and PTY host routing

* chore: keep merge scope limited to dashboard

* perf(dashboard): avoid full-store copies for terminal profiles

* fix(dashboard): validate terminal input profiles at IPC boundary

* fix(dashboard): sync preview terminal refs on commit, not during render

react-compiler rejects ref writes in the render pass; every reader is an event handler or a post-await continuation, so a commit-phase sync is equivalent.

* test(dashboard): cover the three seams that relay the host-input profile

Reverting any of them left every suite green: the dialog's terminalInput prop
(the only reader of DashboardCard.terminalInput), the drawer's hand-threaded
store slices, and the pop-out's republish triggers. Each new assertion was
mutation-checked against its source line.

* fix(dashboard): follow the WSL host for a preview terminal's byte routing

The card resolver handed resolveTerminalInputHostPlatform a transport with no
getLocalSessionMetadata, so a WSL pty on a Windows client resolved to win32
while its own pane resolves linux — Shift+Enter would then encode CSI-u where
the pane sends alt-enter. Mirror the pane transport's own gate.

* fix(dashboard): republish on every slice the host-input profile resolves from

The compare set covered 4 of the ~11 slices that decide a card's execution
host, so a change to the rest (folder workspaces, project groups, the runtime
catalog, detected worktrees) never triggered a publish. On a quiet board there
is no later publish to heal from, and the pop-out — which cannot re-derive the
profile — keeps encoding bytes for the host the pty used to run on.

* fix(dashboard): sync preview terminal refs on layout, not on a passive effect

xterm's keydown is a native listener, so React never flushes a passive effect
before it. A just-relayed host profile could therefore miss the next keystroke.

* test(dashboard): pin the preview's replay-vs-live kitty scan

The existing A/B passed either way: a lone CSI > u sets the same flags through
scan and scanReplay. Redeliver the push across a snapshot and its replay so
stack semantics would leave the TUI's single pop on a stale frame.

* fix(dashboard): rebuild the drawer's snapshot on every host-input slice

The in-window drawer read ~12 host slices through getState() while subscribing
to none of them, on the premise that agent activity drives the next rebuild. A
quiet board has no such rebuild: an SSH handshake completing with every agent
idle leaves the preview terminal encoding bytes for the pre-connect host, and
agentStatusEpoch only ticks on live status changes so it never heals. Watch the
same set useDashboardPopoutBridge republishes on — each writer bails out when
nothing changed, so the added deps are far quieter than agentStatusByPaneKey,
which already rebuilds this memo on every status ping.

The existing coverage mounted a second hook, which always recomputes; the new
test re-renders the same hook after changing only sshConnectionStates.

* fix(dashboard): key the preview by the user's terminal shortcut policy

The preview passed 11 of the 12 inputs the pane's policy takes and let the
12th default to orca-first. Under terminal-first a remapped tab.close chord is
meant to yield to the shell — Ctrl+W is a word-kill there — but the preview
kept claiming it as a pane close and swallowed the bytes.

* test(dashboard): pin the host-input profile to card snapshots only

The count path main added in #11042 renders no cards, so it must not pay a
per-pty host resolution on every agent-status tick. Both assertions run against
a card that does have a live pty, so only the gate keeps the profile off.

* refactor(dashboard): extract the board's client-host read

The merge of main's label bounding pushed build-dashboard-snapshot.ts to
302 lines. The client's own platform facts are a distinct concept from the
pty host each card keys against, so they move out rather than earn a
max-lines bypass.
2026-07-28 21:57:41 -07:00

154 lines
5.9 KiB
TypeScript

import type { AgentType } from './agent-status-types'
import type { RepoIcon } from './repo-icon'
/**
* Serializable contract for the pop-out agent dashboard. The main renderer owns
* the live store, derives this snapshot, and relays it (through the main
* process) to the separate pop-out renderer, which renders it presentationally.
* Every field must be structured-clone-safe (no functions / class instances).
*/
/** Agent lifecycle columns; idle is optional while completed agents remain visible. */
export type DashboardBucket = 'attention' | 'working' | 'done' | 'idle'
/** Column order shared by producer and pop-out so they never drift. */
export const DASHBOARD_BUCKET_ORDER: readonly DashboardBucket[] = [
'attention',
'working',
'done',
'idle'
]
/** Max length of a card's display labels. The producer truncates to this and
* the main-process validator enforces it, so an unbounded name (a long
* `terminal rename`, an OSC title) cannot cost the card its place on the board. */
export const DASHBOARD_MAX_LABEL_LENGTH = 1_024
/** Kept distinct from `bucket` so attention cards retain their precise dot state. */
export type DashboardCardDotState = 'working' | 'blocked' | 'waiting' | 'done' | 'idle'
export type DashboardCardReview = {
number: number
state: 'open' | 'closed' | 'merged' | 'draft'
}
export type DashboardCardSubagent = {
id: string
name: string
dotState: DashboardCardDotState
}
export type DashboardCard = {
/** Stable identity for React keys. */
paneKey: string
/** Resolved live PTY id for the terminal preview, or null when the agent has
* no live pane (e.g. a retained/done row whose pane is gone). */
ptyId: string | null
agentType: AgentType
bucket: DashboardBucket
dotState: DashboardCardDotState
/** One-line task/prompt text shown on the card. */
task: string
/** The most recent message the user sent this agent (its current prompt). */
lastUserMessage?: string
/** The most recent message the agent sent back. */
lastAgentMessage?: string
/** Routing target for click-to-focus. leafId is null when unresolved. */
repoId: string
worktreeId: string
tabId: string
leafId: string | null
repoName: string
worktreeName: string
workspaceStatusId?: string
workspaceStatusLabel?: string
workspaceStatusColor?: string
/** True when the workspace links a review whose live state is not cached yet. */
hasReview?: boolean
review?: DashboardCardReview
subagents?: DashboardCardSubagent[]
/** "Started … ago" display. */
startedAt: number
/** When the agent last entered `done`, or null if it never finished. Drives
* the card's time column: finished cards read time-since-finish (parity with
* the left worktree sidebar), active cards fall back to startedAt. */
finishedAt: number | null
/** When the agent entered its current state — column ordering key (cards
* that moved into a bucket most recently sort first). 0 when unknown. */
stateChangedAt: number
/** Mirrors the sidebar's unvisited signal: the agent changed state since the
* user last acknowledged it (visited its tab / opened its dashboard dialog).
* Derived from the app-wide ack map so both surfaces mute in lockstep. */
unseen: boolean
/** Short summary of the pending question when bucket === 'attention'. */
askSummary?: string
/** The tab's conversation name, resolved exactly as the sidebar's agent rows
* resolve it. Undefined when no usable name exists (status-only titles). */
conversationName?: string
/** Host-dependent input facts the preview terminal needs to encode keys the
* way this agent's real pane does. Null when the card has no live pty. Only
* the main renderer owns the store these derive from, so they ride the
* snapshot to reach the pop-out. */
terminalInput?: DashboardCardTerminalInput
}
/**
* Per-pty input contract shared by a pane and its dashboard preview. Byte
* protocols follow the PTY's execution host, not the client OS — they differ
* for a macOS client driving a Windows runtime.
*/
export type DashboardCardTerminalInput = {
/** Platform executing the pty; picks the host-side byte encodings. */
hostPlatform: NodeJS.Platform
/** Local native Windows ConPTY, where PSReadLine binds Ctrl+←/→ itself. */
localWindowsConpty: boolean
/** OS release of a local Windows client, for xterm's ConPTY wrap-marker compat. */
osRelease?: string
/** Shift+Enter encoding resolved from this pane's agent evidence. */
windowsShiftEnterEncoding: 'alt-enter' | 'csi-u'
/** False withholds the kitty (CSI-u) advertisement, as ConPTY panes do. */
kittyKeyboardAdvertised: boolean
}
export type DashboardFilterOption = {
id: string
label: string
color?: string
}
export type DashboardFilterOptions = {
projects: DashboardFilterOption[]
workspaceStatuses: DashboardFilterOption[]
}
export type DashboardSnapshot = {
generatedAt: number
cards: DashboardCard[]
showIdle?: boolean
/** Available filter dimensions are store-derived so zero-card projects and
* statuses remain selectable. Optional for preload-version compatibility. */
filterOptions?: DashboardFilterOptions
/** Icons for the repos the cards belong to. Keyed by repoId rather than
* carried per card: image icons are data URLs up to 400KB, and the snapshot
* is republished several times a second. Optional so a pop-out running
* pre-upgrade code still accepts the payload. */
repoIconsByRepoId?: Record<string, RepoIcon | null>
}
export const EMPTY_DASHBOARD_SNAPSHOT: DashboardSnapshot = {
generatedAt: 0,
cards: [],
filterOptions: { projects: [], workspaceStatuses: [] },
repoIconsByRepoId: {}
}
/** Routing payload for click-to-focus: reveal this agent's pane in the main
* window. leafId is null when the pane could not be resolved (best-effort:
* the worktree is still activated). */
export type DashboardRevealAgentArgs = {
repoId: string
worktreeId: string
tabId: string
leafId: string | null
}