Repository navigation
fix(terminal): forward Option hotkeys to kitty-keyboard TUIs on compose layouts - #8031
Conversation
…se layouts On macOS layouts where Option composes characters (ABC and all non-US, the effective default), pressing Option+P in a TUI that negotiated the kitty keyboard protocol made xterm's kitty encoder report the composed codepoint (alt+pi, CSI 960;3u) instead of the physical key (alt+p, CSI 112;3u). No TUI binds the composed form, so agent hotkeys like OMP's Alt+P / Alt+M neither fired nor typed anything. Fix: mirror each pane's application-negotiated kitty flags with a scan-based tracker fed only from PTY output (immune to Orca's defensive renderer-side kitty resets on Ctrl+C interrupts and reattach), and have the terminal shortcut policy encode Option chords as kitty CSI-u from the physical key when the pane's app opted in. Dead keys stay exempt so Option composition still works, and panes without kitty negotiation (shells) are unchanged. Alt+Arrow / Alt+Backspace now defer to xterm's native kitty encoding in kitty panes instead of the legacy readline translations. The daemon's headless emulator tracks the same flags and re-arms them via the snapshot rehydrate preamble (CSI = flags ; 1 u), so the behavior survives window reloads and reattaches; PTY exit and cold restore reset the mirror. Validated byte-for-byte against a real omp 16.3.15 in a pty: the policy's emitted CSI-u opens the temporary-model selector (Alt+P) and agent hub (Alt+A), identical to the legacy ESC-prefixed forms it parses.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds Kitty keyboard mode tracking for live output, replay, resets, screen switches, and snapshots. Terminal snapshots now carry Kitty flags and re-arm them during restoration. Renderer PTY connections mirror per-pane Kitty state across output, replay, session exits, and restores. macOS Option shortcuts use Kitty CSI-u encoding when enabled, with keyboard-layout base-character lookup and preserved non-Kitty behavior. Tests cover tracker parsing, rehydration, PTY wiring, layout utilities, and shortcut resolution. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
…ay redelivery, and non-QWERTY layouts Three review findings on the kitty keyboard mirror, each verified against a live omp 16.3.15 pty session using the real production modules: - DECSTR: xterm's soft reset (CSI ! p) clears its kitty flags and stacks for both screens without switching buffers; the tracker now mirrors that, so a soft-resetting TUI stops receiving kitty-encoded Option chords. - Replay redelivery: relay reconnects can redeliver the retained replay window, and each scan of the app's one-time CSI > u push grew the mirrored stack while the renderer's post-replay reset drained xterm's copy. The TUI's single exit pop (omp emits a bare CSI < u on quit) then landed on a stale frame, leaving Option+B/F/D kitty-encoded in a plain shell. Replay paths now scan with scanReplay(), which applies pushes as idempotent sets so redelivery cannot grow the stack; the live-output funnel and the daemon's once-per-byte emulator keep full stack semantics. - Layout-correct base keys: kitty CSI-u reports must carry the key's unshifted codepoint in the active layout, but the encoder resolved it from a US-QWERTY physical-code table — on Dvorak/Colemak/AZERTY-class layouts (exactly the population whose effective Option-as-Alt default activates this path) the wrong key's chord fired, e.g. Colemak Option+P sent alt+r. A new keyboard-layout module caches Chromium's KeyboardLayoutMap (fetched at terminal setup and on focus-in, like the option-as-alt probe) and the policy resolves through it before the US fallback. Verified live: the layout-resolved bytes open omp's model selector; the US-table bytes do not.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4143648c-d0f7-44e7-8a8a-2beed0943a17
📒 Files selected for processing (15)
src/main/daemon/headless-emulator.test.tssrc/main/daemon/headless-emulator.tssrc/main/daemon/types.tssrc/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/keyboard-handlers.tssrc/renderer/src/components/terminal-pane/pty-connection-types.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.tssrc/renderer/src/components/terminal-pane/terminal-shortcut-policy.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/lib/keyboard-layout/layout-base-character.test.tssrc/renderer/src/lib/keyboard-layout/layout-base-character.tssrc/shared/terminal-kitty-keyboard-mode-tracker.test.tssrc/shared/terminal-kitty-keyboard-mode-tracker.ts
…Y late exits The exit handler resets the per-pane kitty keyboard mirror, but a late exit from a replaced PTY takes the stale-transport early return and skips it — so a restart-in-place could leak the old TUI's kitty flags into the fresh shell, kitty-encoding Option chords the shell cannot parse. A fresh spawn is by definition a new process with kitty state at zero, so startFreshSpawn now resets the reused tracker itself, alongside the other per-pane mode state it already clears. Reattach paths are untouched, so a live TUI's mirrored flags still survive reconnects.
Compose-mode Option+letter yielding ç/ã/å/ą was kitty-encoded to CSI-u, which TUI parsers drop, making the character untypeable even with 'Option as Alt' off. ASCII compositions already passed through (the stablyai#8031 split); extend the same rule to Latin-script letters. µ/×/÷ and non-Latin glyphs keep their hotkey encoding; Meta mode unchanged. Fixes stablyai#20495.
The non-ASCII hotkey test pinned å to CSI-u; å is everyday typing text like ç, so it passes through now. ƒ/∫ stay encoded.
…ablyai#20171) resolveTerminalOptionShortcutAction encoded every non-ASCII composed Option chord as kitty CSI-u from the physical key (alt+c for a press that produced ç), so with a compose layout and a kitty-protocol TUI (Claude Code negotiating CSI > 5 u) non-Latin prose was untypable: ç ą å ø never reached the PTY even with Option-as-Alt explicitly off, while the same pane typed them fine at the shell prompt. The ASCII-only composed-text branch existed so stablyai#8031 Option hotkeys kept reaching kitty TUIs. That trade sacrificed whole alphabets: on Polish Pro, all nine diacritics are Option chords with no fallback route. The effective setting is the user's contract — when it says Option composes, a genuine composition now types its text (any single printable character); chords remain for keys the layout did not compose (key echoes its base character), for Alt-configured sides (shouldActAsMeta), for numpad keys, and under report-all flags (associated text), so stablyai#8031 hotkeys stay reachable by configuring Option as Alt explicitly. Flips the regression expectations that locked stablyai#8031 chord behavior for composed non-ASCII glyphs; adds Polish Pro (layout map, flags 5), ç-style composition, and explicit-Alt escape-hatch coverage.
…se layouts (stablyai#8031) * fix(terminal): forward Option hotkeys to kitty-keyboard TUIs on compose layouts On macOS layouts where Option composes characters (ABC and all non-US, the effective default), pressing Option+P in a TUI that negotiated the kitty keyboard protocol made xterm's kitty encoder report the composed codepoint (alt+pi, CSI 960;3u) instead of the physical key (alt+p, CSI 112;3u). No TUI binds the composed form, so agent hotkeys like OMP's Alt+P / Alt+M neither fired nor typed anything. Fix: mirror each pane's application-negotiated kitty flags with a scan-based tracker fed only from PTY output (immune to Orca's defensive renderer-side kitty resets on Ctrl+C interrupts and reattach), and have the terminal shortcut policy encode Option chords as kitty CSI-u from the physical key when the pane's app opted in. Dead keys stay exempt so Option composition still works, and panes without kitty negotiation (shells) are unchanged. Alt+Arrow / Alt+Backspace now defer to xterm's native kitty encoding in kitty panes instead of the legacy readline translations. The daemon's headless emulator tracks the same flags and re-arms them via the snapshot rehydrate preamble (CSI = flags ; 1 u), so the behavior survives window reloads and reattaches; PTY exit and cold restore reset the mirror. Validated byte-for-byte against a real omp 16.3.15 in a pty: the policy's emitted CSI-u opens the temporary-model selector (Alt+P) and agent hub (Alt+A), identical to the legacy ESC-prefixed forms it parses. * fix(terminal): harden kitty Option-chord mirror for soft resets, replay redelivery, and non-QWERTY layouts Three review findings on the kitty keyboard mirror, each verified against a live omp 16.3.15 pty session using the real production modules: - DECSTR: xterm's soft reset (CSI ! p) clears its kitty flags and stacks for both screens without switching buffers; the tracker now mirrors that, so a soft-resetting TUI stops receiving kitty-encoded Option chords. - Replay redelivery: relay reconnects can redeliver the retained replay window, and each scan of the app's one-time CSI > u push grew the mirrored stack while the renderer's post-replay reset drained xterm's copy. The TUI's single exit pop (omp emits a bare CSI < u on quit) then landed on a stale frame, leaving Option+B/F/D kitty-encoded in a plain shell. Replay paths now scan with scanReplay(), which applies pushes as idempotent sets so redelivery cannot grow the stack; the live-output funnel and the daemon's once-per-byte emulator keep full stack semantics. - Layout-correct base keys: kitty CSI-u reports must carry the key's unshifted codepoint in the active layout, but the encoder resolved it from a US-QWERTY physical-code table — on Dvorak/Colemak/AZERTY-class layouts (exactly the population whose effective Option-as-Alt default activates this path) the wrong key's chord fired, e.g. Colemak Option+P sent alt+r. A new keyboard-layout module caches Chromium's KeyboardLayoutMap (fetched at terminal setup and on focus-in, like the option-as-alt probe) and the policy resolves through it before the US fallback. Verified live: the layout-resolved bytes open omp's model selector; the US-table bytes do not. * fix(terminal): reset kitty mirror on fresh spawn to cover replaced-PTY late exits The exit handler resets the per-pane kitty keyboard mirror, but a late exit from a replaced PTY takes the stale-transport early return and skips it — so a restart-in-place could leak the old TUI's kitty flags into the fresh shell, kitty-encoding Option chords the shell cannot parse. A fresh spawn is by definition a new process with kitty state at zero, so startFreshSpawn now resets the reused tracker itself, alongside the other per-pane mode state it already clears. Reattach paths are untouched, so a live TUI's mirrored flags still survive reconnects. --------- Co-authored-by: Brennan Benson <[email protected]>
Problem
A user reported that OMP's model hotkeys (Option+P, Option+M) don't work in Orca — they had to fall back to
/modelslash commands.Root cause, reproduced byte-for-byte against a real omp 16.3.15 in a pty rig:
vtExtensions.kittyKeyboard), and OMP negotiates it at startup (CSI ? u→CSI > 1 u), expecting modifier-accurate CSI-u key reporting.terminalMacOptionAsAltdefault — xterm's kitty encoder reports Option+P from the composedevent.key:CSI 960;3u(alt+π) instead ofCSI 112;3u(alt+p). No TUI binds the composed form, so the chord neither triggers the hotkey nor types anything (the encoder cancels the keydown).macOptionIsMeta=true) the encoder uses the physical key and everything already works — which is why this only bites some users.Fix
App-scoped, protocol-driven — shells keep Option composition untouched:
shared/terminal-kitty-keyboard-mode-tracker.ts— mirrors each pane's application-negotiated kitty flags by scanning PTY output, replicating xterm's exact algorithm (push/pop/set, per-screen flag slots across alt-screen switches, RIS). Fed only from application bytes (live output + daemon replay payloads), never from renderer-generated resets — so it stays correct through Orca's defensive kitty wipes on Ctrl+C interrupts and reattach resets, which protect dead-TUI shells and must keep firing.terminal-shortcut-policy.ts— when the active pane's app has kitty flags armed and Option-as-Alt isn't'true', Option+letter/digit/punctuation is encoded as kitty CSI-u from the physical key (Option+P → \x1b[112;3u), including shift combos (OMP binds alt+shift+p/l/c). Dead keys are exempt so composition (Option+E → é) keeps working. Alt+Arrow / Alt+Backspace defer to xterm's native kitty encoding in kitty panes instead of the legacy readline translations (fixes Option+Arrow word-nav in OMP too).TerminalModes, and re-arms them in the snapshot rehydrate preamble (CSI = flags ; 1 u, idempotent set rather than push). The renderer mirror re-arms by scanning replay payloads; PTY exit and cold restore reset it.Non-kitty panes are byte-for-byte unchanged (B/F/D readline patches only).
Post-review hardening (second commit)
An adversarial review of the mirror against xterm's actual implementation surfaced three gaps, all fixed and e2e-verified:
CSI ! p) clears its kitty flags and stacks for both screens without switching buffers; the tracker now mirrors that, so a soft-resetting TUI stops receiving kitty-encoded Option chords.CSI > 1 upush on every delivery grew the mirrored stack while the renderer's post-replay reset drained xterm's copy. The TUI's single exit pop (omp emits a bareCSI < uon quit) then landed on a stale frame, leaving Option+B/F/D kitty-encoded in a plain shell. Replay paths now scan withscanReplay(), which applies pushes as idempotent sets so redelivery cannot grow the stack; the live-output funnel and the daemon's once-per-byte emulator keep full stack semantics. (Documented limit: a nested push/push/pop retained inside a replayed window collapses to 0 — inherent to stackless replay; real TUIs push once at startup.)lib/keyboard-layout/layout-base-character.tscaches Chromium'sKeyboardLayoutMap(fetched at terminal setup and refreshed on focus-in, same layout-switch proxy as the option-as-alt probe) and the policy resolves through it before falling back to the US table.Validation
Closed the loop with production code against a live omp 16.3.15 in a pty (isolated HOME, fake provider,
OMP_SKIP_SETUP=1):CSI > 1 upush) → fed through the real tracker → flags = 1.key='π'/'µ',code='KeyP'/'KeyM') →\x1b[112;3u/\x1b[109;3u.CSI 97;3u→ agent hub) matches its legacyESC abehavior exactly. Control: a shell pane that never negotiated kitty getsnullfrom the policy and still composes π.KeyR→\x1b[112;3u, AZERTYSemicolon→\x1b[109;3u) open the selector while the US-table bytes (\x1b[114;3u/\x1b[59;3u) provably do not;CSI ! pdisarms the mirror and Option chords fall through again; a double-redelivered replay window followed by omp's real exit pop (\x1b[<u, emitted on every graceful quit) drains flags to 0 where the old stack semantics left them stuck at 1.Checks: typecheck, oxlint, max-lines ratchet, and all tests across
terminal-pane/daemon/shared/keyboard-layoutpass (47 new: tracker algorithm incl. xterm's pop-to-empty quirk, per-screen swaps, DECSTR and replay-redelivery semantics; policy kitty cases incl. layout-map resolution and non-kitty shift byte-identity; daemon rehydrate incl. alt-screen ordering; layout-map normalization).Notes