Repository navigation
fix(terminal): forward synthesized/dictated text dropped under kitty keyboard protocol (#6513) - #6575
Conversation
…keyboard protocol With xterm's kitty keyboard protocol active, xterm encodes a printable key on keydown and preventDefaults it, which cancels Chromium's native insertText on the helper textarea. The IME punctuation forwarder added in #6417 was gated to CJK input sources (isEnabled), so on a non-CJK (e.g. U.S. Latin) input source it never armed and any synthesized text — dictation, text expanders, accessibility / CGEvent injection — was silently dropped before reaching the PTY. Part A: drop the CJK-only gate so the forwarder arms on macOS regardless of input source (the drop affects every locale, not just CJK punctuation). Part B: forward a standalone non-composing insertText that no key event produced. Injected prose/words never satisfy the punctuation-keydown claim path, so recover them from the helper-textarea input event, guarded against double-send (key-activity attribution, unresolved claimed press), against composition (insertCompositionText + composition-commit), and via stopImmediatePropagation so xterm's own _inputEvent cannot also forward. Fixes #6513 Co-authored-by: Orca <help@stably.ai>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 601f75d2a44b6b1092b68900078e58c32bedd157 and d5102a0. 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 OpenGrep (1.23.0)src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts┌──────────────┐ �[32m✔�[39m �[1mOpengrep OSS�[0m [00.11][ERROR]: unable to find a config; path src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.ts┌──────────────┐ �[32m✔�[39m �[1mOpengrep OSS�[0m [00.16][ERROR]: unable to find a config; path src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.test.ts┌──────────────┐ �[32m✔�[39m �[1mOpengrep OSS�[0m [00.16][ERROR]: unable to find a config; path 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 |
Verification evidence (#6513)Before / after reasoningBefore: the IME punctuation forwarder was wired with After:
Unit tests —
|
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: 89811e2f-7c2a-4a41-abfe-a42b77c5c8de
📥 Commits
Reviewing files that changed from the base of the PR and between e51b2df and 601f75d2a44b6b1092b68900078e58c32bedd157.
📒 Files selected for processing (3)
src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
| const wasComposing = compositionInProgress | ||
| // Composition inserts belong to xterm's CompositionHelper / the IME preedit; | ||
| // leave them alone in every path. | ||
| if (event.inputType === 'insertCompositionText') { | ||
| pendingForward = false | ||
| compositionInProgress = true | ||
| return | ||
| } | ||
| // The composition resolved with this commit; clear the marker so the next | ||
| // press starts fresh. | ||
| compositionInProgress = false |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n "deleteCompositionText|insertCompositionText|compositionInProgress" src/renderer/src/components/terminal-paneRepository: stablyai/orca
Length of output: 1957
Preserve composing state until the final commit. Keep compositionInProgress true for all composing input events (deleteCompositionText, etc.); clearing it on the first non-insertCompositionText event can make the eventual insertText look like injected text and send it twice. Add a regression test for insertCompositionText → deleteCompositionText → insertText.
601f75d to
d5102a0
Compare
…keyboard protocol (stablyai#6513) (stablyai#6575) * fix(terminal): forward synthesized/dictated text dropped under kitty keyboard protocol With xterm's kitty keyboard protocol active, xterm encodes a printable key on keydown and preventDefaults it, which cancels Chromium's native insertText on the helper textarea. The IME punctuation forwarder added in stablyai#6417 was gated to CJK input sources (isEnabled), so on a non-CJK (e.g. U.S. Latin) input source it never armed and any synthesized text — dictation, text expanders, accessibility / CGEvent injection — was silently dropped before reaching the PTY. Part A: drop the CJK-only gate so the forwarder arms on macOS regardless of input source (the drop affects every locale, not just CJK punctuation). Part B: forward a standalone non-composing insertText that no key event produced. Injected prose/words never satisfy the punctuation-keydown claim path, so recover them from the helper-textarea input event, guarded against double-send (key-activity attribution, unresolved claimed press), against composition (insertCompositionText + composition-commit), and via stopImmediatePropagation so xterm's own _inputEvent cannot also forward. Fixes stablyai#6513 Co-authored-by: Orca <help@stably.ai> * fix: broaden terminal injected text forwarding --------- Co-authored-by: Orca <help@stably.ai>
🧑🤝🧑 Impact & ELI5
1) What's broken today (ELI5). On Macs, if you use dictation (speak-to-type), a text expander (type a shortcut, get a whole snippet), or any accessibility/assistive tool that "types for you," the text silently vanishes when you aim it at an Orca terminal that's running a modern agent CLI (like Codex). Nothing appears, no error pops up — it just disappears. This hits every English/Latin Mac user (not a niche locale), and it's a real blocker for anyone who relies on dictation or text expanders to drive a terminal. A narrower version of the same bug was fixed earlier, but only for Chinese/Japanese punctuation — so everyone else was left out in the cold.
2) What this PR does (ELI5). Think of the terminal as having a tiny invisible "inbox" where typed text lands before being delivered to the program. When the fancy agent CLI is active, the terminal grabs each keypress so aggressively that it accidentally throws away anything the computer injects (dictation, expanders, etc.) before it reaches the inbox. This PR teaches Orca to recognize that injected text — text that showed up without a real keystroke behind it — and hand it straight to the program. So now dictated/expanded/assistive text arrives at the prompt instead of disappearing, on any language setting, and it works the same whether you're local or connected to a remote machine over SSH.
3) Tradeoffs / regressions — honest answer. No meaningful regressions, with one honest caveat below. What changed: the fix removes a gate that previously limited this rescue behavior to Chinese/Japanese keyboards, so it now runs for everyone on macOS. That's purely additive — ordinary typing is untouched (the code only steps in for punctuation symbols or for text that arrived with no keystroke at all; normal letters, digits, space, and shortcuts are never intercepted), and double-delivery is guarded against so nothing gets typed twice. Non-Mac users (Windows/Linux) are completely unaffected — the behavior stays behind a Mac-only check. The one honest caveat, called out by the author too: the fix identifies injected text by the fact that "no real key press came before it." If some unusual dictation/injection tool does fire a fake key press first, that text would still be treated as a normal keystroke and could still be dropped — i.e. the fix covers the standard injection mechanism (and the exact case from the bug report) but can't promise to catch every exotic injector. No feature is disabled, no setting changes, no new setup, and nothing users relied on is lost.
Summary
Fixes #6513.
On macOS, when a terminal pane runs a CLI that turns on xterm's kitty keyboard protocol / progressive enhancement (e.g. Codex), xterm encodes a printable key on keydown and
preventDefault()s it. That cancels Chromium's nativeinsertTexton the xterm helper textarea, so the DOMinputevent carrying any synthesized/injected text never reaches the PTY — the text is silently dropped.The IME punctuation forwarder added in #6417 (for #6147) was wired with
isEnabled: () => macCjkInputSourceTracker?.isActive() === true, gating it to CJK input sources. With a non-CJK (e.g. U.S. Latin) input source the forwarder never armed, so dictation, text expanders, and accessibility / OS-levelCGEvent keyboardSetUnicodeStringinjection were dropped on every non-CJK locale. The CJK gate narrowed a general "kitty protocol cancels native insertText" problem down to one locale.This is a two-part fix:
getMacCjkInputSourceTrackerimport and local are removed, and theisEnabledoption (no longer used by any consumer) is dropped from the forwarder. Safe for ordinary typing:claimKeyEventonly ever bypasses unmodified, non-composing single ASCII punctuation/symbol keydowns — letters, digits, space, named keys, and modifier chords are never claimed.insertTextthat no key event produced — the exact signature of OS-level injection. This is guarded against double-send (key-activity attribution so any keystroke xterm owns is skipped; an unresolved claimed punctuation press is skipped until keyup), against composition (insertCompositionTextand the resolving composition commit are skipped), and routes throughstopImmediatePropagation()so xterm's own_inputEventcannot also forward the same glyph.Forwarding goes through
pane.terminal.input(data), which is transport-agnostic, so this works for local and SSH/remote PTYs.Screenshots
No visual change. This is an input-routing fix in the renderer; there is no UI surface. End-to-end reproduction requires an external OS-level CGEvent/
keyboardSetUnicodeStringinjector plus a kitty-mode CLI, which cannot be faithfully synthesized over CDP (a CDP-dispatched syntheticInputEventwould not exercise xterm'spreventDefault-on-keydown ordering). The regression is fully covered by renderer unit tests (below); a human macOS smoke test with a real dictation app / CGEvent script against a Codex pane is the most convincing end-to-end proof.Testing
pnpm lint(oxlint, scoped to changed files — clean)pnpm typecheck(tsgoconfig/tsconfig.tc.web.json— clean)pnpm test(forwarder suite + related IME/keyboard suites — see PR comment for output)pnpm buildAdded/updated unit coverage in
terminal-ime-punctuation-forwarder.test.ts:insertTextproduced by a normally-typed key (with/without keypress) is NOT forwarded; a composition commit and an active composition are NOT forwarded; non-text input types are ignored.AI Review Report
Self-review focused on: correctness of the keyboard-vs-injection discriminator, double-send risk against xterm's own
_inputEventhandler, composition edge cases, and cross-platform safety._inputEvent(CoreBrowserTerminal) also forwardsinsertTextviatriggerDataEvent. Our listener is capture-phase on the terminal element (ancestor of the helper textarea), so it runs first; every forward callsstopImmediatePropagation(), so xterm's handler never double-sends. Normal typed keys (wheresawKeyActivityis true) are deliberately NOT stopped, so xterm keeps handling them.keyActivitySinceInputis set on every observed key event and consumed perinputevent, so a keydown→[keypress]→input sequence is attributed to xterm and never re-forwarded. An unresolved claimed punctuation press is skipped viaclaimedPressuntil keyup, preserving "one forward per claimed press."insertCompositionTextmarkscompositionInProgress; the resolving commitinsertTextis skipped via that marker plus the liveisComposing()check, so IME composition output is never treated as injection.isMac(navigator.userAgent.includes('Mac')) check; non-Mac keeps the no-op forwarder. Noe.metaKey/path-separator hardcoding. Forwarding viapane.terminal.input()is transport-agnostic (local + SSH/remote). No git-provider relevance.Security Audit
No new input-execution, path, auth, secret, IPC, or dependency surface. The change only re-routes already-present DOM
insertTextdata that the user/OS produced for the focused terminal into the existingpane.terminal.input()path (the same sink xterm itself uses). Noeval, no new IPC channels, no filesystem or network access. The forwarded payload is plain text the PTY would have received anyway absent the kitty-protocol cancellation; it is not interpreted as a shell command by Orca.Notes
terminal-ime-input-source.tstracker module and its test are now unused in production (only the lifecycle consumedgetMacCjkInputSourceTracker). Left in place to keep this diff minimal; safe to delete in a scoped follow-up.insertTextwith no preceding key event." This matches the issue's own suggested fix and the standardCGEvent keyboardSetUnicodeString"type a string" mechanism (no meaningful printable keydown). If a particular dictation/injector fires a printable keydown that xterm processes before theinsertText, that input would be attributed to the keyboard path and skipped — a macOS smoke test against a Codex pane should confirm the recovery works end-to-end.Future suggestions
terminal-ime-input-source.ts+ test in a follow-up.Made with Orca 🐋