Skip to content

fix(pi-tui): skip Kitty keyboard protocol on Windows Terminal to prevent Cyrillic doubling#1979

Open
dev66613 wants to merge 4 commits into
MoonshotAI:mainfrom
dev66613:fix/cyrillic-doubling-windows-terminal
Open

fix(pi-tui): skip Kitty keyboard protocol on Windows Terminal to prevent Cyrillic doubling#1979
dev66613 wants to merge 4 commits into
MoonshotAI:mainfrom
dev66613:fix/cyrillic-doubling-windows-terminal

Conversation

@dev66613

Copy link
Copy Markdown

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

  • **\packages/pi-tui/src/terminal.ts**: Added \isWindowsTerminal()\ helper that checks \WT_SESSION\ (excluding SSH sessions). Modified \queryAndEnableKittyProtocol()\ to skip Kitty protocol and enable \modifyOtherKeys\ when running in Windows Terminal.
  • **\packages/pi-tui/test/terminal.test.ts**: Added test verifying that when \WT_SESSION\ is set, the terminal skips the Kitty query and enables \modifyOtherKeys\ instead.

Testing

  • All 13 existing + new tests pass (
    ode --test test/terminal.test.ts)
  • Manually verified: built and installed patched kimi.exe, Cyrillic input no longer doubles in Windows Terminal

Fixes #1978

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

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cce6dbd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/pi-tui Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/pi-tui/test/terminal.test.ts Outdated

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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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" &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

dev66613 added 3 commits July 20, 2026 20:47
… 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.
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.

Cyrillic input doubles every character in Windows Terminal (regression from OpenCode fix)

1 participant