fix(pi-tui): skip Kitty keyboard protocol on Windows Terminal to prevent Cyrillic doubling#1979
fix(pi-tui): skip Kitty keyboard protocol on Windows Terminal to prevent Cyrillic doubling#1979dev66613 wants to merge 4 commits into
Conversation
…ent Cyrillic doubling Windows Terminal with Kitty keyboard protocol flag 4 (alternate keys) emits CSI-u sequences for non-Latin characters AND the raw character, causing every Cyrillic keystroke to be inserted twice. Detect Windows Terminal via WT_SESSION env var and fall back to modifyOtherKeys instead of negotiating Kitty protocol. Fixes MoonshotAI#1978
🦋 Changeset detectedLatest commit: cce6dbd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee0b593929
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| it("skips Kitty protocol and enables modifyOtherKeys on Windows Terminal (WT_SESSION)", () => { | ||
| const previousWtSession = process.env['WT_SESSION']; | ||
| process.env['WT_SESSION'] = 'test-guid-1234'; |
There was a problem hiding this comment.
Mock win32 before asserting Windows Terminal behavior
This test only sets WT_SESSION, but the new production check also requires process.platform === "win32". The dedicated test-pi-tui workflow runs on ubuntu-latest, so setupNegotiation() still writes the Kitty query and this test fails there; I also reproduced it with node --test packages/pi-tui/test/terminal.test.ts. Please mock process.platform or make the assertion platform-aware.
Useful? React with 👍 / 👎.
| */ | ||
| function isWindowsTerminal(): boolean { | ||
| return ( | ||
| process.platform === "win32" && |
There was a problem hiding this comment.
Handle WSL Windows Terminal sessions
This gate makes the workaround native-Windows-only, but Windows Terminal tabs running WSL expose the same terminal emulator while Node reports process.platform === "linux". In that environment WT_SESSION is present but this helper returns false, so the app still negotiates Kitty and the Cyrillic doubling remains for WSL users; the SSH checks below already distinguish remote sessions. Consider keying off WT_SESSION without the win32 requirement or adding explicit WSL handling.
Useful? React with 👍 / 👎.
… return Prevents spurious Kitty disable sequence on cleanup when running on Windows Terminal, where Kitty protocol is never pushed.
Move WT_SESSION save/restore into setupNegotiation() so all Kitty protocol tests are properly isolated from the ambient environment. Previously, running tests on Windows Terminal (where WT_SESSION is set by default) would cause the non-Windows-Terminal tests to fail because they would take the modifyOtherKeys path instead of the Kitty query path.
Problem
When typing Cyrillic (or other non-Latin) characters in kimi-code running in Windows Terminal, every character appears doubled (e.g., \ппррииввеетт\ instead of \привет). This only happens in Windows Terminal — git-bash and cmd work fine.
Root Cause
Windows Terminal with Kitty keyboard protocol flag 4 (alternate keys) emits CSI-u sequences for non-Latin characters AND the raw character byte. The pi-tui framework processes both, resulting in each keystroke being inserted twice.
English ASCII characters are unaffected because they don't trigger the alternate-key CSI-u path.
Fix
Detect Windows Terminal via the \WT_SESSION\ environment variable (set by Windows Terminal for every tab) and skip Kitty keyboard protocol negotiation entirely, falling back to \modifyOtherKeys\ (xterm-style CSI 27;mod;code~ sequences) which handles all characters correctly.
Changes
Testing
ode --test test/terminal.test.ts)
Fixes #1978