Skip to content

fix(terminal): forward Option hotkeys to kitty-keyboard TUIs on compose layouts - #8031

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/terminal-kitty-option-hotkeys
Jul 10, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/terminal-kitty-option-hotkeys

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A user reported that OMP's model hotkeys (Option+P, Option+M) don't work in Orca — they had to fall back to /model slash commands.

Root cause, reproduced byte-for-byte against a real omp 16.3.15 in a pty rig:

  • Orca's terminal advertises the kitty keyboard protocol (vtExtensions.kittyKeyboard), and OMP negotiates it at startup (CSI ? u → CSI > 1 u), expecting modifier-accurate CSI-u key reporting.
  • On macOS layouts where Option composes characters — ABC and every non-US layout, i.e. the effective terminalMacOptionAsAlt default — xterm's kitty encoder reports Option+P from the composed event.key: CSI 960;3u (alt+π) instead of CSI 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).
  • On US layouts (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).
  • Reload/reattach durability — the daemon's headless emulator tracks the same flags next to its existing private-mode mirror, exposes them in 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:

  • 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 scanning the app's one-time CSI > 1 u push 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 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. (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.)
  • 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, which can trigger unintended TUI bindings. New lib/keyboard-layout/layout-base-character.ts caches Chromium's KeyboardLayoutMap (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):

  1. Captured omp's real boot negotiation (142 KB incl. its CSI > 1 u push) → fed through the real tracker → flags = 1.
  2. Ran the real policy for Option+P/M keydowns as macOS reports them on compose layouts (key='π'/'µ', code='KeyP'/'KeyM') → \x1b[112;3u / \x1b[109;3u.
  3. Sent those bytes to live omp: Option+P opens the temporary-model selector (the reported bug), and a second visible binding (CSI 97;3u → agent hub) matches its legacy ESC a behavior exactly. Control: a shell pane that never negotiated kitty gets null from the policy and still composes π.
  4. Hardening round, same live-omp rig driving the real modules: layout-resolved bytes (Colemak KeyR → \x1b[112;3u, AZERTY Semicolon → \x1b[109;3u) open the selector while the US-table bytes (\x1b[114;3u / \x1b[59;3u) provably do not; CSI ! p disarms 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-layout pass (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

  • SSH panes behave identically — all encoding is client-side in the renderer.
  • Known tradeoff: directly-composed Option characters (e.g. Turkish Option+Q → @) can't be typed into a kitty-opted TUI — but that input was already fully swallowed before this fix (nothing typed, no hotkey), so nothing regresses; dead-key composition still works via the IME path.
  • xterm's internal kitty flags still get defensively wiped on interrupt/reattach; non-Option keys then fall back to legacy encodings, which kitty TUIs tolerate (verified for OMP's dual parser).

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

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bcbaf4b1-cd21-4c5e-a562-fc9c7fd0c206

📥 Commits

Reviewing files that changed from the base of the PR and between cd98242 and 78b6e84.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/terminal-pane/pty-connection.ts

📝 Walkthrough

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not follow the required template sections for Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Reformat the PR description to the repository template and add the missing sections, including screenshots, testing checklist, AI review report, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 accurately describes the main user-facing change to Option hotkeys on kitty-keyboard TUIs.
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
📝 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.

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

@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

Run ID: 4143648c-d0f7-44e7-8a8a-2beed0943a17

📥 Commits

Reviewing files that changed from the base of the PR and between 5d5e2c4 and cd98242.

📒 Files selected for processing (15)
  • src/main/daemon/headless-emulator.test.ts
  • src/main/daemon/headless-emulator.ts
  • src/main/daemon/types.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/lib/keyboard-layout/layout-base-character.test.ts
  • src/renderer/src/lib/keyboard-layout/layout-base-character.ts
  • src/shared/terminal-kitty-keyboard-mode-tracker.test.ts
  • src/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.
@brennanb2025
brennanb2025 merged commit da2c692 into main Jul 10, 2026
8 checks passed
juscyllan added a commit to juscyllan/orca that referenced this pull request Sep 13, 2026
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.
juscyllan added a commit to juscyllan/orca that referenced this pull request Sep 13, 2026
The non-ASCII hotkey test pinned å to CSI-u; å is everyday typing text
like ç, so it passes through now. ƒ/∫ stay encoded.
eatmoreduck added a commit to eatmoreduck/orca that referenced this pull request Sep 14, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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