Repository navigation
feat(dashboard-popout): size the terminal dialog's PTY to the dialog grid - #9997
Conversation
…grid The popout agent-terminal dialog rendered the pane's serialized frame at its original cols/rows and CSS-scaled it down to fit. The dialog now claims the PTY grid for its own box through the remote-desktop viewer registry: the PTY reflows to the dialog's dimensions (crisp, unscaled), the main-window pane parks at the held grid like any remote viewer hold, and closing the dialog releases the claim so the pane reclaims its geometry. A phone-driven PTY keeps the floor; the dialog then falls back to the scale-to-fit rendering. Any grid change under a live preview stream (fit landing, host reclaim, phone takeover) now pushes a resync so the dialog repaints from a snapshot at the new grid — this also fixes garbled dialogs when the pane resized while a dialog was open.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughTerminal previews now resynchronize when PTY dimensions change and expose a fit IPC API for negotiated grid sizing. Main-process handlers track and release per-preview fit claims while updating remote desktop viewer dimensions. Dashboard popouts measure and debounce terminal grid requests, avoid duplicate fits, and clean up observers and claims. Clipboard shortcut handling was extracted into a dedicated Xterm helper. Tests cover resize resync, fit validation and cleanup, grid deduplication, and preview shortcut integration. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/ipc/terminal-preview.ts (1)
186-219: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winHarden
terminalPreview:fitinput validation and claim bookkeeping.Two related gaps in this handler:
args.cols/args.rowsare only checked withtypeof === 'number'andNumber.isFinite— no positive/integer/bounds check, unlike the siblingterminalPreview:ackhandler which validatesargs.bytesagainst<= 0and a max. A negative, zero, or non-integer value passes straight intoruntime.updateRemoteDesktopViewer.claimed.add(ptyId)runs beforeupdateRemoteDesktopVieweris awaited; if that call throws, the claim is left registered even though the update never landed, so a later release callsunregisterRemoteDesktopViewerfor a viewer that may never have been established.If
clampTerminalViewportdownstream already clamps values, point 1 is lower risk, but explicit boundary validation here is still cheap and matches theackhandler's existing pattern.🛡️ Proposed fix
if ( !isDashboardPopoutRenderer(event.sender) || !isValidPtyId(args?.ptyId) || typeof args.cols !== 'number' || typeof args.rows !== 'number' || !Number.isFinite(args.cols) || - !Number.isFinite(args.rows) + !Number.isFinite(args.rows) || + args.cols < 1 || + args.rows < 1 ) { return null } const ptyId = args.ptyId + const cols = Math.floor(args.cols) + const rows = Math.floor(args.rows) // Why: guarantees the destroyed hook exists even if this claim outlives // the current output stream across a resync reconnect. subscriptionsFor(event.sender) - let claimed = fitClaimsByContents.get(event.sender.id) - if (!claimed) { - claimed = new Set() - fitClaimsByContents.set(event.sender.id, claimed) - } - claimed.add(ptyId) const viewerKey = previewViewerKey(event.sender.id) try { - await runtime.updateRemoteDesktopViewer(ptyId, viewerKey, viewerKey, args.cols, args.rows) + await runtime.updateRemoteDesktopViewer(ptyId, viewerKey, viewerKey, cols, rows) } catch { return null } + let claimed = fitClaimsByContents.get(event.sender.id) + if (!claimed) { + claimed = new Set() + fitClaimsByContents.set(event.sender.id, claimed) + } + claimed.add(ptyId) return runtime.getTerminalSize(ptyId)src/renderer/src/components/dashboard-popout/preview-grid-claim.ts (1)
63-72: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winFailed/unlanded fit requests permanently suppress retries at that exact grid size.
lastRequestedFitis set before thefit()promise settles and is never cleared on failure or anull(not-landed) result. If the same target size recurs later (e.g. a phone releases the grid, or a transient IPC failure), the dedup check skips the request entirely since the key still matches.♻️ Proposed fix
lastRequestedFit = fitKey // The resize triggers a main-side resync push; the reconnect snapshot // carries the new grid. If the claim didn't land (a phone owns the size), // the dialog's scaled fallback rendering stays correct as-is. - void window.api.terminalPreview.fit(args.ptyId, cols, rows) + void window.api.terminalPreview.fit(args.ptyId, cols, rows).then((effective) => { + if (!effective && lastRequestedFit === fitKey) { + // Allow a retry at this exact target once conditions change. + lastRequestedFit = null + } + })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 124c9a56-d0de-414a-90e3-576450c1f35c
📒 Files selected for processing (9)
src/main/ipc/terminal-preview-output-stream.tssrc/main/ipc/terminal-preview.test.tssrc/main/ipc/terminal-preview.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsxsrc/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsxsrc/renderer/src/components/dashboard-popout/preview-clipboard-shortcuts.tssrc/renderer/src/components/dashboard-popout/preview-grid-claim.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/dashboard-popout/preview-grid-claim.ts (1)
61-69: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winReset
lastRequestedFitwhen the fit request does not land.
terminalPreview:fitreturnsnullwhen the requested grid is not applied, but this component commitsfitKeybefore awaiting the result and discards the response. That suppresses future retries for the same target size even after the claim should be retried, so use the returned value to reset the cache key onnullas well as on rejection.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4e54ce6c-097f-417a-beec-56fc0c875ee2
📒 Files selected for processing (5)
src/main/ipc/terminal-preview.test.tssrc/main/ipc/terminal-preview.tssrc/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsxsrc/renderer/src/components/dashboard-popout/preview-grid-claim.test.tssrc/renderer/src/components/dashboard-popout/preview-grid-claim.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
- src/main/ipc/terminal-preview.ts
…grid (stablyai#9997) * feat(dashboard-popout): size the terminal dialog's PTY to the dialog grid The popout agent-terminal dialog rendered the pane's serialized frame at its original cols/rows and CSS-scaled it down to fit. The dialog now claims the PTY grid for its own box through the remote-desktop viewer registry: the PTY reflows to the dialog's dimensions (crisp, unscaled), the main-window pane parks at the held grid like any remote viewer hold, and closing the dialog releases the claim so the pane reclaims its geometry. A phone-driven PTY keeps the floor; the dialog then falls back to the scale-to-fit rendering. Any grid change under a live preview stream (fit landing, host reclaim, phone takeover) now pushes a resync so the dialog repaints from a snapshot at the new grid — this also fixes garbled dialogs when the pane resized while a dialog was open. * fix(dashboard-popout): harden terminal grid claims * perf(dashboard-popout): bound terminal preview resize work
What
The experimental agent-dashboard popout's terminal dialog previously rendered the pane's serialized frame at its original cols/rows and CSS-scaled it down to fit — shrunken, blurry, and sized by the main window rather than the dialog. The dialog now claims the PTY grid for its own box: the PTY reflows to the dialog's dimensions and renders crisp and full-size, exactly like a normal terminal.
How
updateRemoteDesktopViewer/unregisterRemoteDesktopViewer) with a syntheticdashboard-popout:<contentsId>viewer key — the dialog is just another remote viewer of the shared PTY:remote-desktop-fithold (no lock banner, input still shared), and reclaims its geometry when the claim is released (dialog close, unsubscribe, or popout window destruction);terminalPreview:fitIPC; claims tracked per webContents so they can never leak past the window's lifetime.TerminalPreviewOutputStream.requestResync()+ asubscribeToTerminalResizehook: any grid change under a live preview stream (fit landing, host reclaim, phone takeover) pushes a resync so the dialog repaints from a snapshot at the new grid. This also fixes a pre-existing bug where the open dialog garbled if the pane resized under it.preview-grid-claim.ts: measures the cell size from.xterm-screenlayout dims (transform-immune), computes the grid the box holds (clamped to the runtime's 20–240 × 8–120 viewport range), debounced 200 ms, and keyed by target dims — an unchanged target is never re-requested, so a host/phone taking the grid back cannot start a resize tug-of-war.preview-clipboard-shortcuts.tsextracted verbatim fromAgentTerminalPreview(max-lines cap).Evidence (live Electron QA, real zsh PTY)
stty sizein the shared PTY proves the grid at each step.1. Before — main pane owns the grid (58×135):
2. Popout board with the agent card:
3. Dialog open — PTY reflowed to the dialog grid (33×107), terminal fills the dialog at scale 1 (screen 902×528 in a 906×536 box, no CSS transform):
4. Main pane during the hold — same content at the held grid, no garbling, no lock banner:
5. Dialog closed — main pane reclaims its geometry (58×135):
Tests
terminal-preview.test.ts: fit claims + reported effective size, claim release on unsubscribe/sender destruction (one-shot), resize→resync push, non-popout sender rejection.AgentTerminalPreview.test.tsx: claims the grid matching the dialog box, never re-requests an unchanged target after a reconnect.Notes
enqueueLayout→ provider resize path the mobile/remote-desktop flows already use.scale()— after this PR that only applies in the rare fallback mode (phone owns the grid).Reliability and performance contract
terminal-geometry.visible-convergence: while a preview is live, the applied PTY grid, main-process headless snapshot, and preview xterm converge after every viewer/host/mobile ownership change; unsubscribe and popout destruction release the preview's resize floor.stty sizesequence proves dialog claim and host reclaim. Deterministic tests prove effective-size reporting, resize-to-resync ordering, one-shot cleanup, stale/in-flight claim rejection, unchanged-target deduplication, and ACK-before-resync behavior.config/reliability-gates.jsonc→terminal-geometry.visible-convergence; its 8-file command passes (1,363 tests). Focused preview/remote-desktop/mobile ownership coverage also passes (110 passed, 2 skipped).enqueueLayoutcontract covered by the gate; mobile precedence/fallback is covered deterministically. Live Linux, Windows/ConPTY, SSH, and WSL popout runs remain gaps.