Skip to content

fix(shell): disable kitty keys in VS Code#1440

Open
Timi16 wants to merge 2 commits intoMoonshotAI:mainfrom
Timi16:fix-vscode-kitty-keys
Open

fix(shell): disable kitty keys in VS Code#1440
Timi16 wants to merge 2 commits intoMoonshotAI:mainfrom
Timi16:fix-vscode-kitty-keys

Conversation

@Timi16
Copy link

@Timi16 Timi16 commented Mar 15, 2026

Summary

  • Disable Kitty keyboard protocol in VS Code terminals to prevent CSI-u enter sequences from being parsed as literal text.
  • Add an env override KIMI_CLI_DISABLE_KITTY_KEYS to force the behavior elsewhere.

Testing

  • Not run (manual testing in VS Code integrated terminal recommended).

Closes #1437


Open with Devin

Summary

  • Disable Kitty keyboard protocol in VS Code terminals to prevent CSI-u enter sequences from being parsed as literal text.
  • Add an env override KIMI_CLI_DISABLE_KITTY_KEYS to force the behavior elsewhere.

Testing

  • Not run (manual testing in VS Code integrated terminal recommended).

Closes #1437


Open with Devin

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Signed-off-by: Timi16 <134459045+Timi16@users.noreply.github.com>
@Timi16
Copy link
Author

Timi16 commented Mar 19, 2026

@Eric-Guo @bigeagle @yetone Please review

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 NameError: _mcp_status_block, _mcp_status_loading, and _bg_task_count are used but no longer defined

The PR deleted the local function/class definitions for _mcp_status_block, _mcp_status_loading, _BgCountCache, and _bg_task_count (previously at old lines 200-230) but left the references to them at lines 204-206 when constructing the CustomPromptSession. This means entering the interactive shell (Shell.run() without a command) will immediately crash with a NameError. This breaks the primary interactive mode of the CLI.

(Refers to lines 204-206)

Prompt for agents
Restore the deleted local function/class definitions that were previously between lines 200-230 (old) of src/kimi_cli/ui/shell/__init__.py. Specifically, you need to re-add these definitions inside the run() method, before the `with CustomPromptSession(...)` block at line 202:

1. `_mcp_status_block(columns: int)` - closure that reads `self.soul.status.mcp_status` and calls `render_mcp_prompt`
2. `_mcp_status_loading() -> bool` - closure that checks if MCP is loading
3. `_BgCountCache` dataclass with `time` and `count` fields
4. `_bg_cache` instance of `_BgCountCache`
5. `_bg_task_count() -> int` - closure that returns background task count with caching

These were defined between the `_plan_mode_toggle` definition and the `CustomPromptSession` context manager, and should be placed back there (after the new `maybe_disable_kitty_keyboard_protocol()` call at line 200 and before the `with CustomPromptSession(...)` at line 202).
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link

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

Choose a reason for hiding this comment

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

💡 Codex Review

status_block_provider=_mcp_status_block,
fast_refresh_provider=_mcp_status_loading,
background_task_count_provider=_bg_task_count,

P1 Badge Restore the prompt callback helpers before starting the shell

Any interactive kimi session now fails before the first prompt is shown: Shell.run(command=None) still passes _mcp_status_block, _mcp_status_loading, and _bg_task_count into CustomPromptSession, but those locals were removed and there are no remaining definitions in this module. That turns shell startup into a runtime NameError for every normal interactive launch.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if not _should_disable_kitty_keyboard_protocol():
return

_write_escape("\x1b[<u")

Choose a reason for hiding this comment

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

P2 Badge Avoid popping the terminal's kitty key mode on startup

CSI < u is the kitty keyboard protocol pop/restore sequence, so sending it unconditionally here changes terminal state without a matching push from this process. In terminals where the parent shell/editor already enabled kitty key handling—or whenever users set KIMI_CLI_DISABLE_KITTY_KEYS=1 outside VS Code—starting kimi will consume the parent's stack entry and leave the outer program in the wrong keyboard mode after exit until it reconfigures the terminal.

Useful? React with 👍 / 👎.

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.

Enter key appends [13u instead of sending message in VS Code integrated terminal

1 participant