Repository navigation
feat(terminal): encode IME commits as CSI-u under the all-keys kitty flag - #13310
Conversation
Typing 2-Set Korean shows committed syllables but not the in-progress jamo, so the user composes each syllable blind. Long-standing hole in the vendored terminal library, not a regression: the same test fails identically against the bundle this branch starts from. The `.active` class that CSS keys `display: block` off is added only in `compositionstart` and dropped in `_finalizeComposition`. Some IMEs (observed on Windows/WSL Korean) resume a composition with a bare `compositionupdate` and no second `compositionstart`, by which point `compositionend` has already hidden the overlay, so the resumed preedit is written into a hidden element and never positioned. `updateCompositionElements` also early-returned on `!_isComposing`, so it would not lay the overlay out either. Re-show the overlay on an update that carries data, and key the layout guard on the shown overlay instead. `_isComposing` is deliberately left alone, so no commit bookkeeping changes and `onData` stays byte-identical. The two guards are equivalent on every pre-existing path: `compositionstart` sets both, `_finalizeComposition` clears both. The bundle hunks are the same two edits applied to the shipped minified output; the sourcemaps are carried through unchanged.
…ows capture The synthetic test pins the shape; this replays events a real Microsoft Korean IME emitted on Windows/WSL. The capture holds three compositionupdates that resume a composition with no second compositionstart — the exact ordering that wrote the preedit into a hidden overlay. Without the fix all three report shown:false; with it all three are visible. Fixture derived from the sealed 11919-windows-wsl-current capture, which is read-only and unmodified. Co-authored-by: Orca <[email protected]>
… artifact The capture logs each event twice — a dispatch record and a batched next-frame re-log. Deriving from both replayed every event twice, which made three compositionupdates appear to land after a session had ended. Filtered to dispatch records the capture holds zero resumes and 11 balanced sessions, so the previous toHaveLength(3) was pinning an artifact of the derivation. Re-scoped to what the capture does prove: the preedit stays visible across all 37 real updates. Verified by reverting the patch that this passes either way, so it is coverage and the synthetic test remains the discriminator. Both facts are now stated in the file. Co-authored-by: Orca <[email protected]>
The previous commit accidentally reverted it: checking main's patch and lockfile into the worktree to test whether a test discriminates also stages them, so the commit that followed swept them up. Co-authored-by: Orca <[email protected]>
…t survives Co-authored-by: Orca <[email protected]>
…allowlist removal The gate listed terminal-ime-input-source.test.ts, which went with the input-source allowlist. Points at the substituted-text commit test instead, which covers what the gate is actually protecting: text committed outside a composition session reaching the pty exactly once. Co-authored-by: Orca <[email protected]>
The predicate withholds a keydown's byte until the commit arrives, so a key the IME eats without committing would be dropped. Measured across the recorded corpus that case does not occur, and the browser marks IME-owned presses on the keydown itself. Both facts belong next to the predicate rather than only in a handoff note, since the obvious fix for the imagined gap is a timer, and a timer here once wrote a newline the user never typed. Co-authored-by: Orca <[email protected]>
Flag 8 asks for every printable key as an escape code; this path sends the committed text raw instead. That is a deliberate trade, not an oversight, but it was untested — the suite only covered the disambiguate flag. Pinning it makes the choice visible and records the gate to use if it ever needs closing. Co-authored-by: Orca <[email protected]>
d46e339 to
fc54888
Compare
c414502 to
9b61584
Compare
…ched the pty Claiming the keyup unconditionally suppressed xterm's release report. That was sized for the old design, which claimed only a short punctuation list; the structural claim takes every printable keydown, so on macOS an app that negotiated kitty report_event_types stopped seeing releases for ordinary typing and would treat every printable key as held down. Suppress the release only when the press put nothing on the wire — swallowed by the input source, or owned by a composition transaction. xterm emits nothing from keyup unless kitty report_event_types (or win32 input mode) is on, so letting it through is inert everywhere else. Co-authored-by: Orca <[email protected]>
…input Both IME defects that shipped and were reverted walked through a suite of ~3000 passing assertions, because every one of them was about bytes reaching the PTY. A preedit rendered into a hidden overlay satisfies all of them while the user composes blind. The real-geometry coverage that would have caught it existed but was headful, env-gated and macOS-only, so it never ran in CI. Drives composition through CDP Input.imeSetComposition instead of a native input source, which removes the accessibility grant and the system input source that forced the headful gate. The suite runs in the normal headless project in about 55s serially, and asserts the composition overlay's real bounding rect — the one property an overlay clipped to max-width:0 cannot fake and a DOM emulator cannot produce. Three tests are red on main and marked test.fail() so they stay visible in CI and flip loud when their fix lands: the preedit resumed by a bare compositionupdate, and full-width punctuation and digits committed from a keydown that still carries the ASCII layout key. Co-authored-by: Orca <[email protected]>
Validated on real macOS hardware: with the two fixes below this layer, all three report "Expected to fail, but passed". Korean preedit renders at non-zero geometry through every jamo, and an Apple pinyin source sends ef bc 8c e3 80 82 to the pty where main sends ASCII. Worth recording why the punctuation case looked green on main once: an input source whose id happens to contain an allowlist term, as Sogou's does, satisfies the old gate. Correctness there depended on which IME the user had selected. Co-authored-by: Orca <[email protected]>
The ten headless IME specs on this branch all decided ownership through a macOS user-agent override, so the two platforms whose failure mode is a *dropped* character rather than a downgraded one had no coverage at all, and the one Windows-recorded trace already in the suite was replayed under whichever policy the runner happened to report — macOS locally, Linux on the CI shards. Adds four Linux specs and two Windows specs, every one of them replaying a native capture rather than a hand-authored ordering: - IBus/X11 Hangul mixed with literal ASCII. Its `compositionend` is EMPTY and the syllable arrives afterwards as a bare `insertText`, so reading the commit off `compositionend.data` — which the Windows capture rewards — drops every syllable on this framework. - fcitx5/Wayland Hangul. No keydown at all for a composing key, not even 229, and physically wrong `code` values on the literal keys. Any ownership rule reading 229 or `code` fails here. - Numeric pinyin candidate selection under both frameworks, with the ordinary digit kept as the negative control, so the two directions are pinned against each other rather than separately. - Windows Microsoft Korean captured with real scan codes, including the two lines committed with Shift held. Each asserts both sides of the boundary: the preedit's real geometry at every frame the user would see, and the exact byte stream the native run put on the PTY. The recorded `onData` the Windows/WSL fixture already carried is now asserted instead of sitting unused. Chinese moves up to first-class alongside Korean: pinyin preedit width is now pinned the way the Japanese phrase already was, and full-width punctuation is covered in the composition-session shape the Windows and Linux frameworks use, not only the macOS insertText shape. Two harness fixes fell out of the recorded traces and are why the IBus one passes. The replay applied each event's recorded textarea state *after* dispatch, one event too late for the handlers that read `textarea.value`; and it left a task boundary between `compositionend` and the `input` carrying the commit, which Chromium never inserts, letting xterm's deferred finalizer settle against a textarea the committed text had not reached yet. Co-authored-by: Orca <[email protected]>
…esising them The macOS coverage on this branch drives Chromium composition through CDP, which is genuine but hand-ordered, so it could not assert the one property that decides the macOS rule: a composing keydown arrives with keyCode 229 while `key` is still the single translated character the input source produced — `ㅎ`, not `Process` — which is indistinguishable by length from an ordinary printable key. Three native captures were sitting unused in the evidence set. Adds a recorded 2-Set Korean session, including the syllable boundary where one composition closes and the next opens with no keydown between them, asserted against its own recorded byte stream. Adds the third failure mode, which had no coverage in any shape: an abandoned preedit leaking to the shell. Pinyin and Cangjie both backspace a composition away to nothing, and the assertion is not "the right bytes" but "no bytes". Both cancellation captures continue with a literal `ordinary` typed as bare keydowns, the recorder's own negative control. That tail carries no `input` events because the build it was captured on produced the byte from the keydown itself, so replaying it would measure the recorder rather than the product; the specs cut at the `compositionend` and say so. Co-authored-by: Orca <[email protected]>
… the suite Qingg matches none of the terms the pre-structural build enumerated, so on that build its bypass never installs. It is the one arm no headless spec can express, and the only test here that the pre-structural build cannot pass. Promoted from scratch with four changes, each forced by a measurement rather than by taste: - A non-attached input method is a refusal, not a negative result. macOS attaches per app instance and the attach can simply fail — 3 of 6 instances under exclusive host access, and re-selecting the source did not recover one of them across 9 keystrokes. That is now `test.skip()` with a reason naming the rerun, not a thrown error, and the suite does not gate on a fully green session. - Attachment is probed with a LETTER. Punctuation substitution emits no compositionstart and no keyCode 229 even under a fully attached source, so at the keydown it is indistinguishable from having no source at all. The punctuation arms are judged on PTY bytes alone. - The ASCII-layout control is now part of the spec rather than a side experiment. Without it a build that rewrote every `.` into `。` unconditionally would pass the Qingg arm and be badly wrong. - The assertion runs by default instead of behind a strict-mode flag, and gained a non-vacuity check: the input source must have committed something. That is the sharp end of the mechanism — on the old build the DOM carries only keydown and keyup, so nothing is committed at all and the character is destroyed before the source is asked. The verdict stays an equality between two measurements, never a comparison against a hardcoded glyph, so it holds whatever punctuation mode the operator's input source happens to be in. It reads `beforeinput`, not `input`: the forwarder consumes `input` in the capture phase on the pane element, so a probe on the helper textarea never sees it and a strict run fails with correct bytes underneath. Co-authored-by: Orca <[email protected]>
…flag A pane that negotiates `report_all_keys_as_escape_codes` (bit 3) asked for every printable key as a CSI-u report. The commit path wrote IME-committed text raw, so such a pane got a legacy byte stream it had declined. That predicate has no IME-specific condition, so it affected every macOS user in such a pane, not just CJK users. Encode the press that produced the commit instead, reusing xterm's own kitty encoder rather than hand-rolling CSI-u. `claimKeyEvent` is untouched: still unconditional, still structural, still no kitty read on the keydown. The flag read happens once per commit. The gate is bit 3 alone. Flags 1/2/4/16 leave printable keys as text, so panes negotiating only those keep receiving substituted characters; gating on "kitty active" would strip the substitution from every pane that negotiates anything. Known limit, pinned by test: the report carries the physical key's codepoint, not the committed glyph. Bit 3 is the app declaring it does not want text, and bit 4 is how it asks for text back — but xterm's encoder derives that text field from the same `key` it derives the keycode from, so carrying the committed glyph needs an encoder change, not a wider gate.
fc54888 to
3f43064
Compare
9b61584 to
326d070
Compare
…flags The commit encoder never passed an event type, so xterm's encoder applied its PRESS default to every auto-repeat keydown. A pane negotiating report_event_types alongside bit 3 saw one held key as N separate strikes. Carry the keydown's `repeat` on the claimed press and map it to the protocol's REPEAT. The event type only reaches the wire when report_event_types is negotiated, so this is inert for panes that asked only for bit 3. Co-authored-by: Orca <[email protected]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (18)
💤 Files with no reviewable changes (4)
📝 WalkthroughWalkthroughThe change removes macOS input-source detection and bypass handling from terminal IME setup. Native-text forwarding now claims eligible printable keydowns structurally and tracks PTY output. IME commits can use Kitty keyboard reports when negotiated. Tests cover substituted text, composition ownership, Kitty flags, Backslash handling, and resumed Windows/WSL Korean preedits. Reliability gates now run the substituted-text commit test. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
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/terminal-pane/terminal-ime-native-text-forwarder.ts (1)
142-186: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftA commit that arrives after its keyup loses the kitty encoding. The keyup branch clears
claimedPresswhilependingForwardstays armed, soencodeImeCommitAsKittyReportreceives null and the commit falls back to raw text. The test suite documents the keyup-before-commit ordering but never exercises it under kitty flag 8, so the gap is not caught.
src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.ts#L142-L186: retain the claimed press when the keyup fires whilependingForwardis still true, and consume it inforwardCommittedTextbefore clearing it.src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.test.ts#L275-L293: add a case that installs with flag 8, claims a keydown, dispatches the keyup, then dispatches theinsertText, and asserts the commit is a CSI-u report rather than raw text.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-ime-xterm-windows-resumed-preedit-trace.test.ts (1)
67-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDispose the terminal in
afterEachand drain the pending composition timer.Line 112 disposes inside the test body. If an assertion before it fails, disposal never runs. The sibling file
terminal-ime-xterm-resumed-preedit-visibility.test.tsat lines 172-178 drains two event-loop turns before dispose, becauseupdateCompositionElementsre-arms on a timer. Apply the same teardown here so a pending callback does not run against a live-but-abandoned terminal.♻️ Proposed teardown change
+const openTerminals: Terminal[] = [] + function nextEventLoop(): Promise<void> { return new Promise((resolve) => window.setTimeout(resolve, 0)) }- afterEach(() => { + afterEach(async () => { + // updateCompositionElements re-arms on a timer; let the pending one run before dispose. + await nextEventLoop() + await nextEventLoop() + while (openTerminals.length > 0) { + openTerminals.pop()?.dispose() + } vi.restoreAllMocks() document.body.replaceChildren() })const terminal = new Terminal() terminal.open(container) + openTerminals.push(terminal) const textarea = terminal.textarea} - terminal.dispose() // Guards against a fixture that silently stops covering anything.Also applies to: 112-112
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 261f1c8d-ffa8-4c86-9fe0-1559f5b48511
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (18)
config/patches/@[email protected]config/reliability-gates.jsoncsrc/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsxsrc/renderer/src/components/dashboard-popout/preview-terminal-ime-bridge.tssrc/renderer/src/components/terminal-pane/__fixtures__/windows-wsl-hangul-resumed-preedit-trace.jsonsrc/renderer/src/components/terminal-pane/terminal-ime-input-source.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-input-source.tssrc/renderer/src/components/terminal-pane/terminal-ime-kitty-commit-encoding.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.tssrc/renderer/src/components/terminal-pane/terminal-ime-substituted-text-commit.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-won-composition-order.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-xterm-resumed-preedit-visibility.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-xterm-windows-resumed-preedit-trace.test.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.test.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
💤 Files with no reviewable changes (4)
- src/renderer/src/components/terminal-pane/terminal-ime-input-source.test.ts
- src/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.ts
- src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
- src/renderer/src/components/terminal-pane/terminal-ime-input-source.ts
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 2
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/terminal-pane/terminal-ime-native-text-forwarder.ts (1)
142-186: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftA commit that arrives after its keyup loses the kitty encoding. The keyup branch clears
claimedPresswhilependingForwardstays armed, soencodeImeCommitAsKittyReportreceives null and the commit falls back to raw text. The test suite documents the keyup-before-commit ordering but never exercises it under kitty flag 8, so the gap is not caught.
src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.ts#L142-L186: retain the claimed press when the keyup fires whilependingForwardis still true, and consume it inforwardCommittedTextbefore clearing it.src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.test.ts#L275-L293: add a case that installs with flag 8, claims a keydown, dispatches the keyup, then dispatches theinsertText, and asserts the commit is a CSI-u report rather than raw text.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-ime-xterm-windows-resumed-preedit-trace.test.ts (1)
67-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDispose the terminal in
afterEachand drain the pending composition timer.Line 112 disposes inside the test body. If an assertion before it fails, disposal never runs. The sibling file
terminal-ime-xterm-resumed-preedit-visibility.test.tsat lines 172-178 drains two event-loop turns before dispose, becauseupdateCompositionElementsre-arms on a timer. Apply the same teardown here so a pending callback does not run against a live-but-abandoned terminal.♻️ Proposed teardown change
+const openTerminals: Terminal[] = [] + function nextEventLoop(): Promise<void> { return new Promise((resolve) => window.setTimeout(resolve, 0)) }- afterEach(() => { + afterEach(async () => { + // updateCompositionElements re-arms on a timer; let the pending one run before dispose. + await nextEventLoop() + await nextEventLoop() + while (openTerminals.length > 0) { + openTerminals.pop()?.dispose() + } vi.restoreAllMocks() document.body.replaceChildren() })const terminal = new Terminal() terminal.open(container) + openTerminals.push(terminal) const textarea = terminal.textarea} - terminal.dispose() // Guards against a fixture that silently stops covering anything.Also applies to: 112-112
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 261f1c8d-ffa8-4c86-9fe0-1559f5b48511
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (18)
config/patches/@[email protected]config/reliability-gates.jsoncsrc/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsxsrc/renderer/src/components/dashboard-popout/preview-terminal-ime-bridge.tssrc/renderer/src/components/terminal-pane/__fixtures__/windows-wsl-hangul-resumed-preedit-trace.jsonsrc/renderer/src/components/terminal-pane/terminal-ime-input-source.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-input-source.tssrc/renderer/src/components/terminal-pane/terminal-ime-kitty-commit-encoding.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.tssrc/renderer/src/components/terminal-pane/terminal-ime-substituted-text-commit.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-won-composition-order.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-xterm-resumed-preedit-visibility.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-xterm-windows-resumed-preedit-trace.test.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.test.tssrc/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
💤 Files with no reviewable changes (4)
- src/renderer/src/components/terminal-pane/terminal-ime-input-source.test.ts
- src/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.ts
- src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
- src/renderer/src/components/terminal-pane/terminal-ime-input-source.ts
🛑 Comments failed to post (2)
config/reliability-gates.jsonc (1)
6685-6688: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
A blanket filename replacement reached fields that require different handling. Renaming
terminal-ime-input-source.test.tstoterminal-ime-substituted-text-commit.test.tswas applied to every occurrence. Two fields are not simple path references: one carries assertion text that must describe the new file, and one is a dated record of a command that already ran.
config/reliability-gates.jsonc#L6685-L6688: rewrite theassertionsstrings to describe what the new test file asserts, namely substituted text reaching the terminal and kitty flag 8 CSI-u encoding.config/reliability-gates.jsonc#L6773-L6773: restore the original command in the 2026-07-07evidenceRunsentry, and add a new dated entry if this cohort needs current evidence.📍 Affects 1 file
config/reliability-gates.jsonc#L6685-L6688(this comment)config/reliability-gates.jsonc#L6773-L6773src/renderer/src/components/terminal-pane/xterm-bypass-policy.test.ts (1)
123-126: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the contradictory comment.
Line 126 states the physical key "is no longer named anywhere in this file". Line 122 names Backslash in the test title and line 130 passes
code: 'Backslash'. State that the policy no longer branches on the key instead.📝 Proposed comment fix
// Why: this policy carried a `code === 'Backslash'` bypass because the old // forwarder only claimed keys for input sources on a hardcoded allowlist. - // The structural claim covers every printable key, so the exception is gone - // and the physical key is no longer named anywhere in this file. + // The structural claim covers every printable key, so the policy no longer + // branches on this physical key.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.// Why: this policy carried a `code === 'Backslash'` bypass because the old // forwarder only claimed keys for input sources on a hardcoded allowlist. // The structural claim covers every printable key, so the policy no longer // branches on this physical key.
main replaced the design this branch was written against, so the conflict could not be resolved by picking a side. What changed underneath. The branch was based on eea0bb6, before stablyai#13128 gave terminal composition ownership to xterm and before stablyai#13282 reverted it. Since then stablyai#13288 made the native-text claim structural (every single printable keydown, `key` read for length only) and stablyai#13310 encodes commits as CSI-u under the kitty all-keys flag. terminal-ime-native-text-candidates.ts and the getInputSourceFeatures argument the branch built on no longer exist. Resolution, three judgments. 1. The forwarder takes main's version wholesale. The branch's punctuation feature-list claim is gone from main and reviving it would undo stablyai#13288. 2. The defect the branch reported is still in main, so it is reapplied on the new shape. claimKeyEvent bails on a chorded or composing event BEFORE the keyup branch that retires the claim, and every keyup inside a composition reports isComposing. The release is the only event that retires a claim, so the claim survives the composition; nothing else clears it until the next non-composing printable keydown or a blur. While it is stranded a keypress whose own keydown was refused (composition still live at keydown, ended by keypress) is bypassed with nothing armed to forward it, and the character is dropped. Fix: retire on a matching keyup first, then fold the chord and composition test into the return value. Every existing return value is preserved. Only the leaked state changes: a chorded or composing release returned false before and returns false now. 3. terminal-ime-native-text-claim-release.test.ts is rewritten against main's API. Its old body imported terminal-ime-native-text-candidates, which main deleted, so it could not compile. The two cases it now pins are the two the fix repairs; both fail against main's forwarder and pass against this one (verified by swapping the file back and rerunning). Verified: terminal-ime-native-text-forwarder.test.ts 32/32 (main's own, all still pass), the rewritten suite 2/2, use-terminal-pane-lifecycle 29/29, dashboard-popout 220/220. tsconfig.node, tsconfig.tc.cli, tsconfig.tc.web all 0 errors. oxlint clean. max-lines ratchet OK.
…flag (stablyai#13310) * fix(terminal): show a preedit the IME resumes without a compositionstart Typing 2-Set Korean shows committed syllables but not the in-progress jamo, so the user composes each syllable blind. Long-standing hole in the vendored terminal library, not a regression: the same test fails identically against the bundle this branch starts from. The `.active` class that CSS keys `display: block` off is added only in `compositionstart` and dropped in `_finalizeComposition`. Some IMEs (observed on Windows/WSL Korean) resume a composition with a bare `compositionupdate` and no second `compositionstart`, by which point `compositionend` has already hidden the overlay, so the resumed preedit is written into a hidden element and never positioned. `updateCompositionElements` also early-returned on `!_isComposing`, so it would not lay the overlay out either. Re-show the overlay on an update that carries data, and key the layout guard on the shown overlay instead. `_isComposing` is deliberately left alone, so no commit bookkeeping changes and `onData` stays byte-identical. The two guards are equivalent on every pre-existing path: `compositionstart` sets both, `_finalizeComposition` clears both. The bundle hunks are the same two edits applied to the shipped minified output; the sourcemaps are carried through unchanged. * test(terminal): prove the resumed-preedit fix against a recorded Windows capture The synthetic test pins the shape; this replays events a real Microsoft Korean IME emitted on Windows/WSL. The capture holds three compositionupdates that resume a composition with no second compositionstart — the exact ordering that wrote the preedit into a hidden overlay. Without the fix all three report shown:false; with it all three are visible. Fixture derived from the sealed 11919-windows-wsl-current capture, which is read-only and unmodified. Co-authored-by: Orca <[email protected]> * test(terminal): stop the recorded Hangul fixture pinning a derivation artifact The capture logs each event twice — a dispatch record and a batched next-frame re-log. Deriving from both replayed every event twice, which made three compositionupdates appear to land after a session had ended. Filtered to dispatch records the capture holds zero resumes and 11 balanced sessions, so the previous toHaveLength(3) was pinning an artifact of the derivation. Re-scoped to what the capture does prove: the preedit stays visible across all 37 real updates. Verified by reverting the patch that this passes either way, so it is coverage and the synthetic test remains the discriminator. Both facts are now stated in the file. Co-authored-by: Orca <[email protected]> * fix(terminal): restore the preedit visibility patch onto its own branch The previous commit accidentally reverted it: checking main's patch and lockfile into the worktree to test whether a test discriminates also stages them, so the commit that followed swept them up. Co-authored-by: Orca <[email protected]> * fix(terminal): claim printable keydowns structurally so committed text survives Co-authored-by: Orca <[email protected]> * chore(reliability-gates): retarget the IME forwarding gate after the allowlist removal The gate listed terminal-ime-input-source.test.ts, which went with the input-source allowlist. Points at the substituted-text commit test instead, which covers what the gate is actually protecting: text committed outside a composition session reaching the pty exactly once. Co-authored-by: Orca <[email protected]> * docs(terminal): record why withholding a claimed keydown needs no timer The predicate withholds a keydown's byte until the commit arrives, so a key the IME eats without committing would be dropped. Measured across the recorded corpus that case does not occur, and the browser marks IME-owned presses on the keydown itself. Both facts belong next to the predicate rather than only in a handoff note, since the obvious fix for the imagined gap is a timer, and a timer here once wrote a newline the user never typed. Co-authored-by: Orca <[email protected]> * test(terminal): pin the kitty all-keys-as-escape-codes hole explicitly Flag 8 asks for every printable key as an escape code; this path sends the committed text raw instead. That is a deliberate trade, not an oversight, but it was untested — the suite only covered the disambiguate flag. Pinning it makes the choice visible and records the gate to use if it ever needs closing. Co-authored-by: Orca <[email protected]> * fix(terminal): keep the kitty key-release report for presses that reached the pty Claiming the keyup unconditionally suppressed xterm's release report. That was sized for the old design, which claimed only a short punctuation list; the structural claim takes every printable keydown, so on macOS an app that negotiated kitty report_event_types stopped seeing releases for ordinary typing and would treat every printable key as held down. Suppress the release only when the press put nothing on the wire — swallowed by the input source, or owned by a composition transaction. xterm emits nothing from keyup unless kitty report_event_types (or win32 input mode) is on, so letting it through is inert everywhere else. Co-authored-by: Orca <[email protected]> * test(e2e): assert IME preedit geometry headlessly for Korean and CJK input Both IME defects that shipped and were reverted walked through a suite of ~3000 passing assertions, because every one of them was about bytes reaching the PTY. A preedit rendered into a hidden overlay satisfies all of them while the user composes blind. The real-geometry coverage that would have caught it existed but was headful, env-gated and macOS-only, so it never ran in CI. Drives composition through CDP Input.imeSetComposition instead of a native input source, which removes the accessibility grant and the system input source that forced the headful gate. The suite runs in the normal headless project in about 55s serially, and asserts the composition overlay's real bounding rect — the one property an overlay clipped to max-width:0 cannot fake and a DOM emulator cannot produce. Three tests are red on main and marked test.fail() so they stay visible in CI and flip loud when their fix lands: the preedit resumed by a bare compositionupdate, and full-width punctuation and digits committed from a keydown that still carries the ASCII layout key. Co-authored-by: Orca <[email protected]> * test(e2e): drop the known-broken markers now the stack closes all three Validated on real macOS hardware: with the two fixes below this layer, all three report "Expected to fail, but passed". Korean preedit renders at non-zero geometry through every jamo, and an Apple pinyin source sends ef bc 8c e3 80 82 to the pty where main sends ASCII. Worth recording why the punctuation case looked green on main once: an input source whose id happens to contain an allowlist term, as Sogou's does, satisfies the old gate. Correctness there depended on which IME the user had selected. Co-authored-by: Orca <[email protected]> * test(e2e): cover the Linux and Windows IME ownership shapes headlessly The ten headless IME specs on this branch all decided ownership through a macOS user-agent override, so the two platforms whose failure mode is a *dropped* character rather than a downgraded one had no coverage at all, and the one Windows-recorded trace already in the suite was replayed under whichever policy the runner happened to report — macOS locally, Linux on the CI shards. Adds four Linux specs and two Windows specs, every one of them replaying a native capture rather than a hand-authored ordering: - IBus/X11 Hangul mixed with literal ASCII. Its `compositionend` is EMPTY and the syllable arrives afterwards as a bare `insertText`, so reading the commit off `compositionend.data` — which the Windows capture rewards — drops every syllable on this framework. - fcitx5/Wayland Hangul. No keydown at all for a composing key, not even 229, and physically wrong `code` values on the literal keys. Any ownership rule reading 229 or `code` fails here. - Numeric pinyin candidate selection under both frameworks, with the ordinary digit kept as the negative control, so the two directions are pinned against each other rather than separately. - Windows Microsoft Korean captured with real scan codes, including the two lines committed with Shift held. Each asserts both sides of the boundary: the preedit's real geometry at every frame the user would see, and the exact byte stream the native run put on the PTY. The recorded `onData` the Windows/WSL fixture already carried is now asserted instead of sitting unused. Chinese moves up to first-class alongside Korean: pinyin preedit width is now pinned the way the Japanese phrase already was, and full-width punctuation is covered in the composition-session shape the Windows and Linux frameworks use, not only the macOS insertText shape. Two harness fixes fell out of the recorded traces and are why the IBus one passes. The replay applied each event's recorded textarea state *after* dispatch, one event too late for the handlers that read `textarea.value`; and it left a task boundary between `compositionend` and the `input` carrying the commit, which Chromium never inserts, letting xterm's deferred finalizer settle against a textarea the committed text had not reached yet. Co-authored-by: Orca <[email protected]> * test(e2e): replay the recorded macOS IME shapes instead of only synthesising them The macOS coverage on this branch drives Chromium composition through CDP, which is genuine but hand-ordered, so it could not assert the one property that decides the macOS rule: a composing keydown arrives with keyCode 229 while `key` is still the single translated character the input source produced — `ㅎ`, not `Process` — which is indistinguishable by length from an ordinary printable key. Three native captures were sitting unused in the evidence set. Adds a recorded 2-Set Korean session, including the syllable boundary where one composition closes and the next opens with no keydown between them, asserted against its own recorded byte stream. Adds the third failure mode, which had no coverage in any shape: an abandoned preedit leaking to the shell. Pinyin and Cangjie both backspace a composition away to nothing, and the assertion is not "the right bytes" but "no bytes". Both cancellation captures continue with a literal `ordinary` typed as bare keydowns, the recorder's own negative control. That tail carries no `input` events because the build it was captured on produced the byte from the keydown itself, so replaying it would measure the recorder rather than the product; the specs cut at the `compositionend` and say so. Co-authored-by: Orca <[email protected]> * test(e2e): promote the non-allowlist input-source punctuation spec to the suite Qingg matches none of the terms the pre-structural build enumerated, so on that build its bypass never installs. It is the one arm no headless spec can express, and the only test here that the pre-structural build cannot pass. Promoted from scratch with four changes, each forced by a measurement rather than by taste: - A non-attached input method is a refusal, not a negative result. macOS attaches per app instance and the attach can simply fail — 3 of 6 instances under exclusive host access, and re-selecting the source did not recover one of them across 9 keystrokes. That is now `test.skip()` with a reason naming the rerun, not a thrown error, and the suite does not gate on a fully green session. - Attachment is probed with a LETTER. Punctuation substitution emits no compositionstart and no keyCode 229 even under a fully attached source, so at the keydown it is indistinguishable from having no source at all. The punctuation arms are judged on PTY bytes alone. - The ASCII-layout control is now part of the spec rather than a side experiment. Without it a build that rewrote every `.` into `。` unconditionally would pass the Qingg arm and be badly wrong. - The assertion runs by default instead of behind a strict-mode flag, and gained a non-vacuity check: the input source must have committed something. That is the sharp end of the mechanism — on the old build the DOM carries only keydown and keyup, so nothing is committed at all and the character is destroyed before the source is asked. The verdict stays an equality between two measurements, never a comparison against a hardcoded glyph, so it holds whatever punctuation mode the operator's input source happens to be in. It reads `beforeinput`, not `input`: the forwarder consumes `input` in the capture phase on the pane element, so a probe on the helper textarea never sees it and a strict run fails with correct bytes underneath. Co-authored-by: Orca <[email protected]> * feat(terminal): encode IME commits as CSI-u under the all-keys kitty flag A pane that negotiates `report_all_keys_as_escape_codes` (bit 3) asked for every printable key as a CSI-u report. The commit path wrote IME-committed text raw, so such a pane got a legacy byte stream it had declined. That predicate has no IME-specific condition, so it affected every macOS user in such a pane, not just CJK users. Encode the press that produced the commit instead, reusing xterm's own kitty encoder rather than hand-rolling CSI-u. `claimKeyEvent` is untouched: still unconditional, still structural, still no kitty read on the keydown. The flag read happens once per commit. The gate is bit 3 alone. Flags 1/2/4/16 leave printable keys as text, so panes negotiating only those keep receiving substituted characters; gating on "kitty active" would strip the substitution from every pane that negotiates anything. Known limit, pinned by test: the report carries the physical key's codepoint, not the committed glyph. Bit 3 is the app declaring it does not want text, and bit 4 is how it asks for text back — but xterm's encoder derives that text field from the same `key` it derives the keycode from, so carrying the committed glyph needs an encoder change, not a wider gate. * fix(terminal): report a held key's repeats as REPEAT under the kitty flags The commit encoder never passed an event type, so xterm's encoder applied its PRESS default to every auto-repeat keydown. A pane negotiating report_event_types alongside bit 3 saw one held key as N separate strikes. Carry the keydown's `repeat` on the claimed press and map it to the protocol's REPEAT. The event type only reaches the wire when report_event_types is negotiated, so this is inert for panes that asked only for bit 3. Co-authored-by: Orca <[email protected]> * chore: drop non-mergeable IME e2e scratch files --------- Co-authored-by: Orca <[email protected]>
Fourth layer of the IME stack. Stacked on
nwparker/ime-e2e-korean-headless(#13290) — review that first; this diff is only the top commit.The hole
A pane that negotiates the kitty keyboard protocol's
report_all_keys_as_escape_codesflag (bit 3,0b1000) has asked for every printable key as a CSI-u escape code. Our commit path wrote IME-committed text raw, so that pane received a legacy byte stream it had explicitly declined.This is not a CJK bug. The predicate that routes text through this path has no IME-specific condition — it is every printable key. So the misencoding hit every macOS user typing plain letters into a flag-8 pane, and CJK users only inherited it. What such an app loses: key-release events for printable keys, modifier disambiguation on printable keys, and associated-text reports.
The shape
claimKeyEventis untouched — still unconditional, still structural, still no kitty read on the keydown hot path. The flag read moved into the commit path, where it happens once per commit rather than once per keystroke. A unit test pins exactly that: the flags getter is not called across a keydown and a keypress, and is called exactly once when the commit arrives.The encoder is xterm's own
KittyKeyboard, reused rather than hand-rolled.The gate is bit 3 alone
Not "kitty is active", not
flags !== 0. Previous attempts got this wrong in both directions — one had no gate, one gated on any negotiation, which strips the substitution from every pane that negotiates anything at all.,from the Comma key0,raw1disambiguate,raw2event types,raw4alternate keys,raw5,7,raw16associated text,raw8CSI 44 u9CSI 44 u15CSI 44 u24(8+16)CSI 44 ; ; 44 uAlso pinned: a shifted substitution (
?) encodes asCSI 63 ; 2 u, keeping the shift modifier; and a one-press/two-character commit (——) encodes as one report,CSI 95 ; 2 u, not one per character — bit 3 reports keys, and that was a single key.The caveat, stated plainly
Under flag 8 without flag 16, the CSI-u report carries the physical key's codepoint, so the committed glyph is not delivered. A Korean user typing in such a pane would not get their syllable.
That is the reference design's deliberate reading, not an oversight: flag 8 is the application declaring it does not want text, and flag 16 (
report_associated_text) is how it asks for text back. We are porting that reading rather than inventing a third behaviour.Implementing flag 16 properly is not a small follow-up. The flags-24 row above is the evidence, and it is pinned by a test: the associated-text slot comes back as
44— the physical,— where the committed,(U+FF0C, 65292) would need to be. Reading our encoder shows why._buildCsiUSequencederives the associated text withtextCode = ev.key.codePointAt(0)— the sameev.keyit derives the keycode from. There is no way to hand it a committed glyph separately from the physical key: passing the glyph asev.keyfixes the text field but corrupts the keycode field, and multi-character commits fail theev.key.length === 1test outright and produce no report at all. Closing this requires changing the encoder to accept associated text as its own parameter — an upstream change or a local fork — not a wider gate here.Scope boundary
Composing IMEs (Hangul, kana) are never claimed by this path — the composition path owns them — so their commits are not re-encoded here. Bit-3 fidelity for composition commits would be a separate change to the composition path. Pinned by test so the boundary is not mistaken for coverage.
The dashboard preview bridge installs the forwarder with no pane to negotiate with; it omits the getter and gets raw text. Also pinned.
Discrimination proof
Reverted the production edit (the
sendInputcall inforwardCommittedText), left the tests in place:The 14 raw-behaviour cases still passed with the edit reverted — so the new tests discriminate the fix specifically, rather than being coupled to the presence of the edit.
Implementation note: how the encoder is reached
KittyKeyboardis not in@xterm/xterm's public typings — it lives in the package's shippedsrc/tree. Reusing it therefore means a deep import into a pinned dependency. Verified working through all three toolchains: vitest,tsc --noEmit(the file's internalconst enums do not tripisolatedModules), and a fullelectron-vite build.Two honest costs, neither blocking:
libbundle already had one. Measured: 2 occurrences of a distinctive key-table constant interminal-shortcut-policy-*.js. A few KB of key tables.config/patches/@[email protected], which fails to apply across a bump — so a bump is already a controlled event that would surface this.The alternative was hand-rolling CSI-u, which would have duplicated the encoding rules instead of the bytes and drifted from xterm's own keydown path.
One pinned behaviour worth flagging
The shifted case encodes with
63(?), not the unshifted47(/) that a strict protocol reading would want as the base key. xterm's encoder only unwinds a shifted key to its base throughDigit*/Key*codes, and this press carriesSlash. This is the shared encoder's existing behaviour on every path, not something the commit path introduces. Pinned as-is with a comment rather than worked around.Verification
npx vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/ src/renderer/src/lib/pane-manager/— 313 files, 3906 passed, 1 skipped, 0 failedrm -f config/*.tsbuildinfo && pnpm run typecheck— cleannpx oxlint <changed>— clean;npx oxfmt --check— clean on all changed files (17 pre-existing format issues elsewhere in the tree, all.md/tests/tools, untouched by this branch)node config/scripts/check-reliability-gates.mjs— passed, 73 gatesnode config/scripts/check-react-doctor-changed.mjs— 24 files scanned, 0 issuespnpm run build:electron-vite— succeedsNot done: no hardware validation in a live flag-8 pane. The evidence here is unit-level plus a clean production build.
Made with Orca 🐋