Skip to content

fix(terminal): forward synthesized/dictated text dropped under kitty keyboard protocol (#6513) - #6575

Merged
nwparker merged 2 commits into
mainfrom
nwparker/fix-6513
Jun 28, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/fix-6513

Conversation

@nwparker

@nwparker nwparker commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

🧑‍🤝‍🧑 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 native insertText on the xterm helper textarea, so the DOM input event 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-level CGEvent keyboardSetUnicodeString injection 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:

  • Part A — remove the locale gate. The forwarder now arms on macOS regardless of input source (the drop affects every locale, not just CJK punctuation). The now-unused getMacCjkInputSourceTracker import and local are removed, and the isEnabled option (no longer used by any consumer) is dropped from the forwarder. Safe for ordinary typing: claimKeyEvent only ever bypasses unmodified, non-composing single ASCII punctuation/symbol keydowns — letters, digits, space, named keys, and modifier chords are never claimed.
  • Part B — forward arbitrary injected prose. Part A alone only recovers punctuation-shaped commits; injected words/sentences never satisfy the punctuation-keydown claim path. The forwarder now also forwards a standalone non-composing insertText that 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 (insertCompositionText and the resolving composition commit are skipped), and routes through stopImmediatePropagation() so xterm's own _inputEvent cannot 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/keyboardSetUnicodeString injector plus a kitty-mode CLI, which cannot be faithfully synthesized over CDP (a CDP-dispatched synthetic InputEvent would not exercise xterm's preventDefault-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 (tsgo config/tsconfig.tc.web.json — clean)
  • pnpm test (forwarder suite + related IME/keyboard suites — see PR comment for output)
  • pnpm build
  • Added or updated high-quality tests that would catch regressions

Added/updated unit coverage in terminal-ime-punctuation-forwarder.test.ts:

  • Part A: a claimed punctuation insert is forwarded with no input-source gate.
  • Part B: a multi-character injected phrase is forwarded exactly once; a standalone injected glyph (emoji-picker case) is forwarded; a later injection forwards after an earlier key press resolved.
  • Double-send guards: an insertText produced 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.
  • The obsolete CJK-gate tests were removed (the gate no longer exists).

AI Review Report

Self-review focused on: correctness of the keyboard-vs-injection discriminator, double-send risk against xterm's own _inputEvent handler, composition edge cases, and cross-platform safety.

  • Double-send: Verified xterm's _inputEvent (CoreBrowserTerminal) also forwards insertText via triggerDataEvent. Our listener is capture-phase on the terminal element (ancestor of the helper textarea), so it runs first; every forward calls stopImmediatePropagation(), so xterm's handler never double-sends. Normal typed keys (where sawKeyActivity is true) are deliberately NOT stopped, so xterm keeps handling them.
  • Normal typing: keyActivitySinceInput is set on every observed key event and consumed per input event, so a keydown→[keypress]→input sequence is attributed to xterm and never re-forwarded. An unresolved claimed punctuation press is skipped via claimedPress until keyup, preserving "one forward per claimed press."
  • Composition: insertCompositionText marks compositionInProgress; the resolving commit insertText is skipped via that marker plus the live isComposing() check, so IME composition output is never treated as injection.
  • Cross-platform: macOS-only behavior stays behind the existing isMac (navigator.userAgent.includes('Mac')) check; non-Mac keeps the no-op forwarder. No e.metaKey/path-separator hardcoding. Forwarding via pane.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 insertText data that the user/OS produced for the focused terminal into the existing pane.terminal.input() path (the same sink xterm itself uses). No eval, 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

  • The terminal-ime-input-source.ts tracker module and its test are now unused in production (only the lifecycle consumed getMacCjkInputSourceTracker). Left in place to keep this diff minimal; safe to delete in a scoped follow-up.
  • Assumption to confirm on real hardware: the injection path keys off "a non-composing insertText with no preceding key event." This matches the issue's own suggested fix and the standard CGEvent keyboardSetUnicodeString "type a string" mechanism (no meaningful printable keydown). If a particular dictation/injector fires a printable keydown that xterm processes before the insertText, 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

  • Delete the now-unused terminal-ime-input-source.ts + test in a follow-up.

Made with Orca 🐋

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

coderabbitai Bot commented Jun 28, 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: fba59b77-9967-47ce-b6e0-a37c3ce62f23

📥 Commits

Reviewing files that changed from the base of the PR and between 601f75d2a44b6b1092b68900078e58c32bedd157 and d5102a0.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.ts

📝 Walkthrough

Walkthrough

The installTerminalImePunctuationForwarder logic removes the CJK input-source gate and adds keyboard attribution plus composition tracking for committed text handling. A new textFromKeyboardEvent helper is introduced, and forwardCommittedText now distinguishes insertCompositionText, pending punctuation commits, and injected insertText. The lifecycle wiring no longer creates or passes a CJK input-source tracker. Tests now cover standalone injected text, punctuation forwarding, duplicate suppression, composition-related commits, and non-text input events.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main fix: forwarding synthesized/dictated terminal text dropped under kitty keyboard protocol.
Description check ✅ Passed The description follows the template with all required sections and enough detail on scope, testing, review, security, and notes.
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

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

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.11][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.16][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.test.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.16][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist


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.

@nwparker

Copy link
Copy Markdown
Contributor Author

Verification evidence (#6513)

Before / after reasoning

Before: the IME punctuation forwarder was wired with isEnabled: () => macCjkInputSourceTracker?.isActive() === true. On a non-CJK (U.S. Latin) input source it never armed, so under xterm's kitty keyboard protocol (engaged by e.g. Codex) the keydown preventDefault() cancelled Chromium's native insertText, the input event carrying any synthesized/injected glyph never fired through to the PTY, and dictation / text-expander / accessibility text was silently dropped.

After:

  • Part A removes the CJK gate, so a claimed punctuation insertText is forwarded on any input source.
  • Part B forwards a standalone non-composing insertText that no key event produced (the OS-injection signature), recovering arbitrary dictated prose — while a double-send guard (stopImmediatePropagation() + key-activity/claimed-press/composition attribution) keeps normal typing and IME composition untouched.

Unit tests — terminal-ime-punctuation-forwarder.test.ts

Command:

./node_modules/.bin/vitest run --config config/vitest.config.ts \
  src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.test.ts

Result: Test Files 1 passed (1) · Tests 29 passed (29)

New / changed coverage that pins the fix:

  • ✓ forwards a claimed punctuation insert without any input-source gate (Part A)
  • ✓ forwards a standalone injected insertText that no key event produced
  • ✓ injected text › forwards a multi-character injected phrase exactly once (Part B prose)
  • ✓ injected text › does not forward an insertText that a normally-typed key produced (no double-send)
  • ✓ injected text › does not forward when a key event preceded the insert but produced no keypress
  • ✓ injected text › does not forward a composition commit as injected text
  • ✓ injected text › does not forward while a composition is active
  • ✓ injected text › forwards a later injected insert after an earlier key press resolved
  • ✓ injected text › does not forward a non-text input type

The earlier isEnabled CJK-gate tests were removed because the gate no longer exists; all pre-existing punctuation/composition/keyup/dispose tests still pass unchanged.

Related suites (no regressions)

Command:

./node_modules/.bin/vitest run --config config/vitest.config.ts \
  src/renderer/src/components/terminal-pane/keyboard-handlers.test.ts \
  src/renderer/src/components/terminal-pane/terminal-ime-input-source.test.ts \
  src/renderer/src/components/terminal-pane/terminal-ime-composition-tracker.test.ts ... (IME + xterm-bypass)

Result: Test Files 10 passed (10) · Tests 168 passed (168)

Lint / typecheck (scoped to changed files)

./node_modules/.bin/oxlint <3 changed files>            → exit 0 (clean)
./node_modules/.bin/tsgo --noEmit -p config/tsconfig.tc.web.json → exit 0 (clean)

Electron / visual

No visual change. End-to-end repro requires an external OS-level CGEvent keyboardSetUnicodeString injector plus a kitty-mode CLI; a CDP-dispatched synthetic InputEvent would not faithfully exercise xterm's preventDefault-on-keydown ordering, so the Electron skill cannot reproduce it. The renderer unit tests fully cover the encode/forward logic. A human macOS smoke test (real dictation app or small CGEvent script against a Codex pane) is the recommended end-to-end confirmation.

@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: 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.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-punctuation-forwarder.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts

Comment on lines +227 to +237
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

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n "deleteCompositionText|insertCompositionText|compositionInProgress" src/renderer/src/components/terminal-pane

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

@nwparker
nwparker force-pushed the nwparker/fix-6513 branch from 601f75d to d5102a0 Compare June 28, 2026 23:17
@nwparker
nwparker merged commit 863a5ec into main Jun 28, 2026
1 check failed
@nwparker
nwparker deleted the nwparker/fix-6513 branch June 28, 2026 23:19
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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>
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.

[Bug]: Synthesized/dictated text is dropped in terminal panes when the kitty keyboard protocol is active (non-CJK)

1 participant