Skip to content

fix(dashboard): give the agent preview terminal a real pane's keyboard - #11015

Merged
brennanb2025 merged 19 commits into
mainfrom
brennanb2025/fix-agent-dashboard-ctrl
Jul 29, 2026
Merged

brennanb2025 merged 19 commits into
mainfrom
brennanb2025/fix-agent-dashboard-ctrl

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

The bug

In the Agent Dashboard's terminal, Ctrl+Backspace deleted one character instead of a word.

The dashboard's terminal (AgentTerminalPreview, used by both the in-window drawer and the pop-out) is a bare xterm, not a pane — and its only custom key handler covered copy/paste and IME. resolveTerminalShortcutAction never ran there, so Ctrl+Backspace fell through to xterm's default \x08, which readline binds to backward-delete-char.

Since the same gap applied to every other chord, this routes the preview through the pane's own policy rather than patching the one key.

What changed

Keyboard. The preview now runs the pane's resolveTerminalShortcutAction: word/line kills, Option chords with layout-aware base characters (Dvorak/AZERTY), modified Enter, Cmd+←/→, Cmd+↑/↓ scrollback, input-source switch. Pane-scoped verdicts (splits, search, focus) are swallowed — letting them reach xterm would send e.g. Ctrl+Shift+D to the agent as a bare Ctrl+D. The swallow list enumerates all 13 members of TerminalShortcutAction with no default:, so the => boolean return type makes a newly added action a build error rather than a silent byte leak.

Three inputs the policy needs that the preview couldn't see:

Need How it's resolved
Kitty-protocol flags Mirrored locally — the preview parses the same PTY stream, so a TerminalKittyKeyboardModeTracker fed scan()/scanReplay() matches the pane
The PTY's execution host New DashboardCard.terminalInput, derived in the main renderer (the only one holding the store) and relayed to the pop-out, which has no store
Host terminal options The ConPTY backend and the kitty (CSI-u) withhold now apply, as they do for a pane

Emulator. Also brought 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/scroll-sensitivity settings applied live, ligatures, the TUI wheel multiplier, lazy Arabic shaping, clickable links, and the IME candidate anchor — the last extracted from pane-lifecycle.ts so both surfaces share one implementation instead of a copy.

Fixes added during review

The first pass shipped the keyboard routing but missed several things that review caught. Each is a real defect with a mutation-verified test:

  • A synthetic PtyTransport silently loses capability. resolveTerminalInputHostPlatform only detects WSL through transport.getLocalSessionMetadata(), which the hand-built transport omitted — so the branch was dead and a WSL pty on a Windows client resolved hostPlatform: 'win32' where its own pane resolves 'linux'. Shift+Enter then encoded CSI-u where the pane sends alt-enter. The existing WSL test passed vacuously: it asserted localWindowsConpty/kitty but never hostPlatform.
  • resolveTerminalShortcutAction takes 12 args; the preview passed 11. terminalShortcutPolicy (from settings, not keybindings) silently defaulted to orca-first. Under terminal-first — the documented escape hatch for shells and TUIs — a remapped tab.close chord must reach the shell, and Ctrl+W is a shell word-kill.
  • The republish gate decides whether a publish happens at all. dashboardSnapshotInputsChanged covered 4 of ~11 slices feeding the host profile; folder workspaces, project groups, the runtime catalog and detected worktrees were missing, so on a quiet board there was no "next publish" to self-heal from. useLiveDashboardSnapshot (the drawer) had the same staleness class, reading those slices through getState() while subscribing to none.
  • Passive effects don't flush before a native keydown. xterm's key handler is a plain DOM listener, so moving render-phase ref writes into useEffect (to satisfy react-compiler) opened a real stale-read window. useLayoutEffect closes it and makes ordering independent of declaration order.
  • Merging main's includeCardDetails opt-out. feat(dashboard): add agent status search board #11042 added a count-only snapshot path (useAgentBucketCounts, recomputed on every agent-status tick); a naive union merge left terminalInput resolving on it, allocating 3 Maps + a Set per live-pty row for a value the counts discard.
  • Two independently-clean merges summed past a lint cap. This PR's added lines plus main's boundedLabel lines put build-dashboard-snapshot.ts at 302 against a 300 max-lines cap — neither branch alone crossed it, so neither branch's CI could see it, and typecheck plus every test suite were green at 302. Fixed by extracting dashboard-client-host.ts, not a disable or a limit bump.
  • Validator policy moved underneath us. fix(perf): correct three 07-27 perf regressions #11234 changed isDashboardSnapshot (all-or-nothing) to admitDashboardSnapshot (drops only the offending card, and logs). No production change was needed — isDashboardTerminalInput is a conjunct of isDashboardCard, so it inherited per-card dropping — but the tests only pinned isDashboardSnapshot, which is now production-dead.

Live QA — A/B on a real dev build

Typed through the real xterm via CDP into a live shell behind a dashboard card, then asserted on a file the shell wrote (the WebGL/DOM buffer isn't scrapeable). Same keystrokes both runs: echo one two three → Ctrl+Backspace → > /tmp/marker.txt → Enter.

Command line after Ctrl+Backspace Marker file
This branch echo one two > … one two
Same build, changes stashed echo one two thre > … one two thre

This branch — the whole word is gone:

qa-shot-06-typed-branch.png

Negative control (changes stashed) — one character deleted, bug reproduces:

qa-shot-07-typed-main.png

The board the preview opens from:

qa-shot-04-board.png

Re-validated after the review fixes. The A/B above was run on the first version of this branch, so it was re-run against the current tree on an isolated profile: echo one two three → one two, and echo alpha beta gamma → alpha beta. Both killed the whole word. Because the preview and the pane share one pty — and the pane has always word-killed correctly — the runs were instrumented to rule out a keystroke leak: 2 xterms mounted (pane + preview) with focus confirmed inside the dialog's own helper textarea, which the pane's container-scoped handler ignores.

QA scaffolding note: an isolated user-data profile with a scratch repo, and the agent-status entry that puts the card on the board was seeded directly into the store. The keystroke path under test was fully real — CDP keys → xterm → policy → IPC → PTY → shell → file.

Tests and gates

New coverage: policy delegation (host-routed Shift+Enter, ConPTY Ctrl+arrow suppression, kitty gating), the option builder, the card profile resolver (SSH host, ConPTY, the Grok kitty exception, WSL with an explicit hostPlatform assertion, unhydrated store), preview-level A/B tests proving the kitty tracker flips Option+Backspace handling, a replay-vs-live scan test, the three seams that relay the host-input profile, the includeCardDetails gate, the shortcut-policy differential, and per-card drop of an unusable profile.

tsc clean on node/cli/web; oxlint 0 errors; oxfmt --check clean; check:code-quality:changed reports 0 new findings (react-compiler, type-aware, React Doctor); check:max-lines-ratchet shows no new bypasses. Note lint:switch-exhaustiveness no longer exists — main folded that rule into audit:code-quality:type-aware, which is green. AgentTerminalPreview.tsx was split into paste/compatibility/IME-bridge modules rather than adding a max-lines disable.

Deliberate divergences

Links open in the system browser (the pop-out hosts no in-app browser pane); scrollback stays at 1000 rows since main only ever serializes 24; no search overlay or pane splits in a dialog; DOM renderer, so no WebGL atlas rebuild after a ligature toggle.

The preview calls resolveTerminalShortcutAction directly rather than the resolveTerminalKeyboardShortcutAction wrapper: the wrapper only makes one arg non-optional, and it lives in keyboard-handlers.ts, which would drag pane-manager and split machinery into the pop-out's separate rollup entry.

Known, pre-existing, not fixed here

  • Any settings change tears down and recreates the preview terminal (terminalTheme is a fresh object in the effect deps), reconnecting the PTY. Identical at the merge base; a correct fix means moving theme into the appearance sync.
  • The preview's paste runtime loses its WSL/SSH key. This affects the redacted diagnostic label and the remote-vs-local paste timeout; the call is byte-identical to the merge base.

Note for reviewers

The dashboard is behind experimentalAgentDashboardPopout, so this ships dark until that flag is on.

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.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds host-specific terminal input metadata to dashboard cards, including platform, ConPTY, Shift+Enter encoding, OS release, and kitty keyboard state. Dashboard previews now use this metadata for terminal options, shortcut routing, paste handling, compatibility integrations, links, ligatures, keyboard negotiation, and IME bridging. Preview lifecycle cleanup and tests are expanded. Snapshot validation and refresh tracking now cover the new data, while pane IME anchoring and local ConPTY option construction are extracted into reusable helpers.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is substantive, but it misses required template sections like AI Review Report and Security Audit. Add the missing template sections, especially AI Review Report and Security Audit, and use the required Summary/Screenshots/Testing/Notes headings.
Docstring Coverage ⚠️ Warning Docstring coverage is 73.91% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: routing the agent preview terminal through pane-like keyboard handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.
…t-dashboard-ctrl

# Conflicts:
#	src/renderer/src/components/dashboard/build-dashboard-snapshot.ts
#	src/shared/dashboard-snapshot.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (2)
src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx (1)

265-298: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

replaceExisting keeps the original host-compatibility options.

The reset path resizes and resets but never re-derives hostCompatibility (vtExtensions.kittyKeyboard, ConPTY options) from terminalInputRef.current. If the card's terminal input facts changed between snapshots, the emulator keeps the stale advertisement while the shortcut policy reads the fresh one. Cheap to re-apply via Object.assign(terminal.options, …) next to the tracker reset.

src/renderer/src/components/dashboard-popout/preview-terminal-compatibility.ts (1)

42-49: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep installTerminalImeCandidateAnchor and caller cleanup in sync.

installTerminalImeCandidateAnchor still returns the handler and internally removes compose* events, but preview-terminal-compatibility.ts also hand-removes them here. That duplicates cleanup; if the helper later adds a third event, this stopper can become stale. Remove the caller-side removeEventListener block and rely on the helper’s returned handler/cleanup contract.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 159f61e7-8acf-41f5-ac9b-92ed3038d07a

📥 Commits

Reviewing files that changed from the base of the PR and between 2cf91b8 and 9b74c11.

📒 Files selected for processing (25)
  • src/main/ipc/dashboard-payload-validation.test.ts
  • src/main/ipc/dashboard-payload-validation.ts
  • src/renderer/src/components/dashboard-popout/AgentTerminalDialog.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard-popout/preview-clipboard-shortcuts.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-compatibility.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-ime-bridge.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-key-handler.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-ligatures.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-links.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-options.test.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-options.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-paste.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-shortcuts.test.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-shortcuts.ts
  • src/renderer/src/components/dashboard/build-dashboard-snapshot.ts
  • src/renderer/src/components/dashboard/dashboard-card-terminal-input.test.ts
  • src/renderer/src/components/dashboard/dashboard-card-terminal-input.ts
  • src/renderer/src/components/dashboard/useDashboardPopoutBridge.ts
  • src/renderer/src/components/dashboard/useLiveDashboardSnapshot.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/terminal-ime-candidate-anchor.ts
  • src/renderer/src/lib/pane-manager/windows-pty-compatibility.ts
  • src/shared/dashboard-snapshot.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/dashboard-popout/preview-clipboard-shortcuts.ts

Comment on lines 416 to +431
}, [ptyId, terminalTheme, terminalMode])

// Why: appearance settings must land on the open terminal, and the OS input
// source can flip Option-as-Alt with no settings change at all. A remount
// would reconnect the pty and repaint the agent's screen from a new snapshot.
useEffect(() => {
const terminal = terminalRef.current
if (!terminal) {
return
}
Object.assign(
terminal.options,
buildPreviewAppearanceOptions(settings, macOptionAsAlt === 'true')
)
syncPreviewTerminalLigatures(terminal, settings)
}, [settings, macOptionAsAlt])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

The new appearance effect can't prevent remounts while the main effect still depends on the theme.

terminalTheme/terminalMode are recomputed by the useMemo on Lines 71-81 whenever settings changes — a new object identity on any settings edit (font size, cursor style, …). That re-runs the setup effect, disposing the terminal and reconnecting the pty, which is exactly what Lines 418-420 say must not happen. Consider dropping the theme from the dep list (read it from a ref at creation) and applying theme/minimumContrastRatio in the appearance effect alongside the other options.

Comment on lines +53 to +56
const onWindowBlur = (): void => {
optionKeyLocation = 0
nativeOnlyShortcutTracker.clear()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Clear consumedClipboardKeys on blur too.

Entries are only removed on keyup. If the window loses focus between the copy/paste keydown and its keyup (common when a chord triggers an OS-level dialog or app switch), the identity stays latched and the next paste chord hits the !consumedClipboardKeys.has(...) guard on Line 125 and silently does nothing.

🛠️ Proposed fix
   const onWindowBlur = (): void => {
     optionKeyLocation = 0
+    consumedClipboardKeys.clear()
     nativeOnlyShortcutTracker.clear()
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const onWindowBlur = (): void => {
optionKeyLocation = 0
nativeOnlyShortcutTracker.clear()
}
const onWindowBlur = (): void => {
optionKeyLocation = 0
consumedClipboardKeys.clear()
nativeOnlyShortcutTracker.clear()
}

Comment on lines +41 to +53
const platform = getShortcutPlatform()
const plan = await planTerminalPasteWithYield({
text,
source,
target: {
kind: 'terminal',
paneId: 0,
leafId: deps.ptyId,
ptyId: deps.ptyId,
runtime: resolveTerminalPasteRuntime({ platform, ptyId: deps.ptyId })
},
terminalBracketedPasteMode: pasteTerminal.modes.bracketedPasteMode
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -nP -C4 'isWindowsConpty|normalizeTerminalPasteLineEndings' src/renderer/src/components/terminal-pane/terminal-paste-*.ts | head -80

Repository: stablyai/orca

Length of output: 8475


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
fd -a 'preview-terminal-(paste|options|shortcuts)\.[jt]sx?$|terminal-paste-.*\.ts$' src/renderer/src | sed 's#^\./##' | head -120

echo
echo "== preview-terminal-paste outline =="
ast-grep outline src/renderer/src/components/dashboard-popout/preview-terminal-paste.ts --view expanded || true

echo
echo "== relevant preview-terminal-paste lines =="
cat -n src/renderer/src/components/dashboard-popout/preview-terminal-paste.ts | sed -n '1,140p'

echo
echo "== host platform definitions/usages =="
rg -n "hostPlatform|localWindowsConpty|terminalInput|resolveTerminalPasteRuntime|planTerminalPasteWithYield" src/renderer/src -g'*.ts' -g'*.tsx' | sed -n '1,220p'

Repository: stablyai/orca

Length of output: 32367


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== resolveTerminalPasteRuntime implementation and tests =="
cat -n src/renderer/src/components/terminal-pane/terminal-paste-runtime.ts | sed -n '1,220p'
echo
cat -n src/renderer/src/components/terminal-pane/terminal-paste-runtime.test.ts | sed -n '1,260p'

echo
echo "== dashboard preview input types and implementation =="
cat -n src/renderer/src/components/dashboard/dashboard-card-terminal-input.ts | sed -n '1,180p'
echo
cat -n src/renderer/src/components/dashboard-popout/preview-terminal-options.ts | sed -n '1,110p'
echo
cat -n src/renderer/src/components/dashboard-popout/preview-terminal-shortcuts.ts | sed -n '1,90p'

echo
echo "== AgentTerminalPreview prop/building lines =="
cat -n src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx | sed -n '200,275p'

echo
echo "== createPreviewClipboardPaster call sites =="
rg -n "createPreviewClipboardPaster|getShortcutPlatform|terminalInput" src/renderer/src/components/dashboard-popout src/renderer/src/components/dashboard -g'*.ts' -g'*.tsx' | sed -n '1,220p'

echo
echo "== local newline policy and chunk behavior references =="
cat -n src/renderer/src/components/terminal-pane/terminal-paste-multiline-policy.test.ts | sed -n '1,100p'
echo
cat -n src/renderer/src/components/terminal-pane/terminal-paste-coordinator.ts | sed -n '100,220p'
cat -n src/renderer/src/components/terminal-pane/terminal-paste-coordinator.ts | sed -n '330,420p'

Repository: stablyai/orca

Length of output: 42319


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== paste payload metadata implementation =="
cat -n src/renderer/src/components/terminal-pane/terminal-paste-payload-metadata.ts | sed -n '1,240p'

echo
echo "== terminal paste model =="
cat -n src/renderer/src/components/terminal-pane/terminal-paste-model.ts | sed -n '1,180p'

echo
echo "== execute plan newline/chunk handling =="
cat -n src/renderer/src/components/terminal-pane/terminal-paste-coordinator.ts | sed -n '220,360p'
cat -n src/renderer/src/components/terminal-pane/terminal-paste-chunks.ts | sed -n '1,200p'
cat -n src/renderer/src/components/terminal-pane/terminal-bracketed-paste.ts | sed -n '1,160p'

echo
echo "== parse/apply terminal-paste-plan in pane =="
rg -n "parse.*terminal.*paste|terminal-paste-plan|executeTerminalPastePlan|planTerminalPasteWithYield" src/renderer/src/components/terminal-pane -g'*.ts' -g'*.tsx' | sed -n '1,220p'

echo
echo "== current AgentTerminalPreview paste plugging lines =="
cat -n src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx | sed -n '150,205p'

Repository: stablyai/orca

Length of output: 19446


Use the preview terminal’s host context for paste planning.

resolveTerminalPasteRuntime({ platform, ptyId }) currently uses the client OS and omits isWindowsConpty, so a macOS client previewing a Windows/ConPTY pty builds local darwin paste bytes and chunk metadata instead of host-compatible \r line endings. Thread terminalInput into deps and use terminalInput?.hostPlatform ?? getShortcutPlatform() plus terminalInput?.localWindowsConpty.

Comment on lines +32 to +40
state.agentStatusEpoch !== previousState.agentStatusEpoch ||
// Why: each card carries the host-input profile its preview terminal keys
// against. A stale profile encodes bytes for the wrong host, so the slices
// that resolve it have to republish too — all are low-frequency except the
// foreground agent, whose churn the publish throttle already absorbs.
state.sshConnectionStates !== previousState.sshConnectionStates ||
state.sshStateByEnvironment !== previousState.sshStateByEnvironment ||
state.runtimeStatusByEnvironmentId !== previousState.runtimeStatusByEnvironmentId ||
state.paneForegroundAgentByPaneKey !== previousState.paneForegroundAgentByPaneKey

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Terminal-input state slices aren't fully wired into either recompute/republish trigger, so preview key-encoding facts can go stale.

DashboardCardTerminalInputState was extended with ~12 fields (detectedWorktreesByRepo, folderWorkspaces, projectGroups, sshConnectionStates, sshStateByEnvironment, runtimeStatusByEnvironmentId, restoredRuntimeHostIdByWorkspaceSessionKey, runtimeEnvironments, runtimeEnvironmentCatalogHydrated, removedRuntimeEnvironmentIds, paneForegroundAgentByPaneKey, agentLaunchConfigByPaneKey) that all feed resolveDashboardCardTerminalInput. Only a subset of these are actually treated as "this changed, recompute/republish" triggers in either consumer:

  • src/renderer/src/components/dashboard/useDashboardPopoutBridge.ts#L32-L40: dashboardSnapshotInputsChanged only compares sshConnectionStates, sshStateByEnvironment, runtimeStatusByEnvironmentId, and paneForegroundAgentByPaneKey. Add the remaining fields (at least agentLaunchConfigByPaneKey, which directly drives windowsShiftEnterEncoding/kittyKeyboardAdvertised, plus runtimeEnvironments/removedRuntimeEnvironmentIds/restoredRuntimeHostIdByWorkspaceSessionKey) to the comparison so the popout republishes when they change.
  • src/renderer/src/components/dashboard/useLiveDashboardSnapshot.ts#L35-L84: the new fields are read via a one-off useAppStore.getState() call inside the useMemo body instead of reactive selectors, and none are in the deps array (only the original selector values plus agentStatusEpoch are). Either subscribe to each field via useAppStore((s) => s.x) and add them to deps, or otherwise ensure the memo recomputes when they change.

Without this, a user changing an agent's launch config, an SSH/runtime host reconnecting, or a runtime environment being removed/restored can leave the preview terminal encoding keys (Shift+Enter, kitty keyboard advertisement, ConPTY behavior) for the wrong host until an unrelated tracked field happens to change.

📍 Affects 2 files
  • src/renderer/src/components/dashboard/useDashboardPopoutBridge.ts#L32-L40 (this comment)
  • src/renderer/src/components/dashboard/useLiveDashboardSnapshot.ts#L35-L84

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.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e4503809-8482-4bf8-bac3-6dad012a6a01

📥 Commits

Reviewing files that changed from the base of the PR and between 9b74c11 and e68c7c0.

📒 Files selected for processing (4)
  • src/renderer/src/components/dashboard-popout/AgentTerminalDialog.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard/useDashboardPopoutBridge.test.tsx
  • src/renderer/src/components/dashboard/useLiveDashboardSnapshot.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx

Comment on lines +141 to +160
// Why: each card's preview terminal keys against a host-input profile
// derived from these. Not republishing leaves the pop-out encoding bytes
// for the host the pty used to run on.
const profileInputs: Partial<DashboardSnapshotWatchState>[] = [
{ sshConnectionStates: new Map() },
{ sshStateByEnvironment: new Map() },
{ runtimeStatusByEnvironmentId: new Map() },
{ paneForegroundAgentByPaneKey: {} }
]
const republished = profileInputs
.filter((next) =>
dashboardSnapshotInputsChanged({ ...previousState, ...next }, previousState)
)
.map((next) => Object.keys(next)[0])
expect(republished).toEqual([
'sshConnectionStates',
'sshStateByEnvironment',
'runtimeStatusByEnvironmentId',
'paneForegroundAgentByPaneKey'
])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use meaningful slice updates in the republish test.

Each new Map()/{} is empty and differs only by reference from the seeded value, so this verifies !== rather than a real host-profile change. Populate each slice with a representative changed entry to protect the stale-profile behavior this PR fixes.

Comment on lines +119 to +124
const clientUserAgent = typeof navigator === 'undefined' ? '' : navigator.userAgent
const clientPlatform = clientUserAgent.includes('Mac')
? 'darwin'
: clientUserAgent.includes('Windows')
? 'win32'
: 'linux'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 clientPlatform is derived from navigator.userAgent string matching, but the codebase already exposes getShortcutPlatform() (used in preview-terminal-key-handler.ts, preview-terminal-paste.ts, and elsewhere) as the canonical source of process.platform in the renderer. Parsing the UA string is fragile and inconsistent.

Suggested change
const clientUserAgent = typeof navigator === 'undefined' ? '' : navigator.userAgent
const clientPlatform = clientUserAgent.includes('Mac')
? 'darwin'
: clientUserAgent.includes('Windows')
? 'win32'
: 'linux'
const clientUserAgent = typeof navigator === 'undefined' ? '' : navigator.userAgent
const clientPlatform = getShortcutPlatform()
const clientOsRelease = readClientOsRelease()

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@greptile-apps

greptile-apps Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes the agent preview terminal's keyboard handling by routing it through the same resolveTerminalShortcutAction policy a real pane uses, so chords like Ctrl+Backspace (word-kill), Cmd+←/→, and Option sequences now encode correctly rather than falling through to xterm defaults.

  • Keyboard policy: Replaces the bare copy/paste handler with a full installPreviewTerminalKeyHandler that covers word/line kills, modified Enter, Option chords, and scrollback navigation. Pane-scoped actions (splits, search) are swallowed to prevent raw bytes reaching the agent. A TerminalKittyKeyboardModeTracker is fed the same PTY output stream, so the preview mirrors the kitty-protocol state the real pane tracks.
  • Host profile relay: Adds DashboardCardTerminalInput to the card snapshot, resolved in the main renderer (the only process with the full store) and relayed to the pop-out. Three facts it carries — kitty advertisement, ConPTY backend, and Windows Shift+Enter encoding — each prevent the preview from encoding bytes the agent's pane would not send.
  • Emulator parity: Brings the preview up to the pane's Unicode 11 shim, Windows Ctrl+Alt repair, user appearance settings (live-applied without remounting), ligatures, clickable links, and the IME candidate anchor; the anchor logic was extracted from pane-lifecycle.ts into a shared module.

Confidence Score: 5/5

Safe to merge — the feature remains behind the experimentalAgentDashboardPopout flag, and the bug fix path is exercised by 3,262 tests including new A/B proof of the Ctrl+Backspace word-kill.

The keyboard fix and host-profile relay are well-contained: the new modules closely mirror existing pane helpers rather than inventing fresh logic, all disposal paths are symmetric, and the IPC validator degrades at card granularity (bad profile drops one card, not the whole board).

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/components/dashboard-popout/preview-terminal-key-handler.ts New key handler replacing preview-clipboard-shortcuts.ts; installs full pane policy, correctly disposes all six window-level listeners, and routes bytes through terminal.input for the user-input signal.
src/renderer/src/components/dashboard-popout/preview-terminal-shortcuts.ts Thin adapter that maps PreviewShortcutContext onto resolveTerminalShortcutAction, correctly using hostPlatform for byte-protocol decisions and clientPlatform for xterm's own ConPTY client-side compat parameter.
src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx Restructured to accept terminalInput prop, use layout effects for live ref updates, mirror the kitty tracker, and apply appearance updates without remounting; cleanup paths correctly dispose all new handlers.
src/renderer/src/components/dashboard/dashboard-card-terminal-input.ts New module that resolves the per-card host-input profile using the same pane helpers; degrades gracefully on a partially-hydrated store via withHydratedSlices.
src/renderer/src/components/dashboard/dashboard-client-host.ts Provides client platform/userAgent/osRelease for the snapshot builder; derives platform from UA string matching rather than the canonical getShortcutPlatform() (flagged in a previous review thread).
src/renderer/src/components/dashboard/useLiveDashboardSnapshot.ts Adds reactive subscriptions for all host-resolution slices; agentLaunchConfigByPaneKey remains a non-reactive getState() read, intentionally documented as not affecting routing output.
src/renderer/src/components/dashboard/useDashboardPopoutBridge.ts dashboardSnapshotInputsChanged now triggers on all 11 host-resolution slices so the pop-out republishes when an SSH host or runtime changes.
src/renderer/src/components/dashboard-popout/preview-terminal-compatibility.ts Installs Unicode 11 shim, Windows Ctrl+Alt repair, links, ligatures, wheel multiplier, lazy Arabic shaping, and IME candidate anchor; returns a disposer that cleans up the two IME and Arabic shaping listeners.
src/main/ipc/dashboard-payload-validation.ts Adds isDashboardTerminalInput validation; correctly handles optional osRelease via isOptionalBoundedString, rejects unknown host platforms, and drops only the affected card on failure.
src/renderer/src/lib/pane-manager/terminal-ime-candidate-anchor.ts IME candidate anchor logic extracted from pane-lifecycle.ts into a reusable function; API and behavior identical to the removed inline block.
src/renderer/src/components/dashboard-popout/preview-terminal-options.ts Builds full preview terminal options mirroring pane behavior; vtExtensions.kittyKeyboard correctly withheld when kittyKeyboardAdvertised is false, ConPTY options applied only for local native Windows.
src/shared/dashboard-snapshot.ts Adds DashboardCardTerminalInput type and optional terminalInput field to DashboardCard; type models all five host-input facts with correct optionality.

Reviews (4): Last reviewed commit: "refactor(dashboard): extract the board's..." | Re-trigger Greptile

…ting

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.
…ves 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.
…e 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.
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.
…t-dashboard-ctrl

Resolves three dashboard conflicts against #11042 (agent status search board):
- dashboard-payload-validation.ts: keep both validator constant blocks.
- build-dashboard-snapshot.ts: intersect main's DashboardCardContextState with
  this branch's Partial<DashboardCardTerminalInputState>, and gate the card's
  terminalInput on main's new includeCardDetails so the sidebar's bucket counts
  do not pay host resolution on every agent-status tick.
- useLiveDashboardSnapshot.ts: union main's review/status slices with this
  branch's host-profile slices.
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.
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.
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.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 78f4982f-00b6-4489-8500-f859e964ec5e

📥 Commits

Reviewing files that changed from the base of the PR and between bb737b8 and 3b4fa6b.

📒 Files selected for processing (6)
  • src/main/ipc/dashboard-payload-validation.test.ts
  • src/main/ipc/dashboard-payload-validation.ts
  • src/renderer/src/components/dashboard/build-dashboard-snapshot.test.ts
  • src/renderer/src/components/dashboard/build-dashboard-snapshot.ts
  • src/renderer/src/components/dashboard/dashboard-client-host.ts
  • src/shared/dashboard-snapshot.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/shared/dashboard-snapshot.ts
  • src/main/ipc/dashboard-payload-validation.ts

options: { includeCardDetails?: boolean; includeFilterOptions?: boolean } = {}
): DashboardSnapshot {
const cards: DashboardCard[] = []
const clientHost = readDashboardClientHost()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Defer the client-host probe until a preview needs it.

readDashboardClientHost() runs even for count-only snapshots and boards with no live PTY, including window.api.platform.get(). Lazily read and memoize it inside the ptyId && includeCardDetails path. Based on PR objectives, count-only/no-live-PTY snapshots must avoid this work.

Proposed direction
-  const clientHost = readDashboardClientHost()
+  let clientHost: ReturnType<typeof readDashboardClientHost> | undefined
...
-      const terminalInput =
-        ptyId && includeCardDetails
+      const terminalInput =
+        ptyId && includeCardDetails
           ? resolveDashboardCardTerminalInput(state, {
+              ...(clientHost ??= readDashboardClientHost()),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const clientHost = readDashboardClientHost()
let clientHost: ReturnType<typeof readDashboardClientHost> | undefined

@brennanb2025
brennanb2025 merged commit 1df8aa5 into main Jul 29, 2026
29 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
stablyai#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 stablyai#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant