Skip to content

feat: add kill_ring_system_clipboard config option#2260

Open
sdkks wants to merge 1 commit into
MoonshotAI:mainfrom
sdkks:feat/kill-ring-clipboard-config
Open

feat: add kill_ring_system_clipboard config option#2260
sdkks wants to merge 1 commit into
MoonshotAI:mainfrom
sdkks:feat/kill-ring-clipboard-config

Conversation

@sdkks
Copy link
Copy Markdown

@sdkks sdkks commented May 13, 2026

Related Issue

N/A — This change is under 100 lines (per CONTRIBUTING.md), so no prior issue discussion is required.

Description

Add a kill_ring_system_clipboard configuration option (default: true) that allows users to prevent emacs-style kill commands from polluting the system clipboard.

Problem: Kimi CLI uses prompt_toolkit's PyperclipClipboard, which means all built-in emacs "kill" commands (Ctrl-W, Ctrl-K, Ctrl-U, Ctrl-Delete, Alt-D, Alt-Backspace) write deleted text to the system clipboard via pyperclip. This silently destroys existing clipboard content and pollutes clipboard history managers.

Solution: When kill_ring_system_clipboard = false, eager keybinding overrides intercept the 6 kill commands before prompt_toolkit's built-in handlers can touch the clipboard. The text is deleted without being copied. The in-memory kill ring still works for Ctrl-Y within the same session.

Intentional cut/copy/paste operations (Ctrl-W with text selected, Alt-W, Ctrl-Y, Ctrl-V) continue to use the system clipboard regardless of this setting.

Files changed:

  • src/kimi_cli/config.py: Added kill_ring_system_clipboard: bool = Field(default=True, ...)
  • src/kimi_cli/ui/shell/__init__.py: Pass config value into CustomPromptSession
  • src/kimi_cli/ui/shell/prompt.py: Add conditional eager keybinding overrides for the 6 kill commands
  • docs/en/configuration/config-files.md: Document the new option

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any. (N/A — under 100 lines)
  • I have added tests that prove my fix is effective or that my feature works. (Keybinding UI behavior is not currently unit-tested in this codebase; the change is verified by prek format/check pass and manual code review against prompt_toolkit's original handlers.)
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open in Devin Review

Copy link
Copy Markdown

@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

Here are some automated review suggestions for this pull request.

Reviewed commit: 8121e870e9

ℹ️ 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".

Comment thread src/kimi_cli/ui/shell/prompt.py
Copy link
Copy Markdown
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 2 potential issues.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment thread src/kimi_cli/ui/shell/prompt.py Outdated
Comment thread src/kimi_cli/ui/shell/prompt.py
@sdkks sdkks force-pushed the feat/kill-ring-clipboard-config branch from 8121e87 to 0f26cf8 Compare May 13, 2026 13:02
Copy link
Copy Markdown

@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

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f26cf83a2

ℹ️ 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".

Comment thread src/kimi_cli/ui/shell/prompt.py Outdated
Comment on lines +1505 to +1506
@_kb.add("c-w", eager=True)
def _(event: KeyPressEvent) -> None:
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 Don't override selection cut with Ctrl-W kill handler

When kill_ring_system_clipboard=false, this eager c-w binding runs unconditionally and preempts prompt_toolkit’s built-in c-w selection-cut path (c-w with has_selection). In any state where text is selected, pressing Ctrl-W now deletes the previous word instead of cutting the selection, so users lose the expected cut behavior and the documented guarantee that intentional cut operations still use the system clipboard.

Useful? React with 👍 / 👎.

Add a configurable option to prevent emacs-style kill commands
(Ctrl-W, Ctrl-K, Ctrl-U, etc.) from writing deleted text to the
system clipboard. When set to false, these commands use an
in-memory kill ring instead, avoiding clipboard pollution.

Intentional cut/copy/paste operations (Ctrl-W with selection,
Alt-W, Ctrl-Y, Ctrl-V) continue to use the system clipboard
regardless of this setting.

Files changed:
- config.py: add kill_ring_system_clipboard field (default: true)
- shell/__init__.py: pass config value to CustomPromptSession
- shell/prompt.py: add eager keybinding overrides when disabled
- docs: document the new option
@sdkks sdkks force-pushed the feat/kill-ring-clipboard-config branch from 0f26cf8 to b2f1aef Compare May 13, 2026 13:12
@sdkks
Copy link
Copy Markdown
Author

sdkks commented May 13, 2026

Author response to review bot comments:

The core design choice here is intentional: when kill_ring_system_clipboard = false, killed text is discarded — not saved to any clipboard or ring. The config description was misleading (said "in-memory ring") and has been corrected to "deleted text is discarded." The purpose is to give users who want zero clipboard pollution a way to delete text without it being retained anywhere.

Specific responses:

  1. Selection-cut with Ctrl-W — Fixed. Added filter=~has_selection to the c-w override so the built-in emacs cut handler takes over when text is selected. The override now only fires when no selection is active.

  2. "In-memory kill ring" not implemented — This is by design. There is no kill ring because the flag's purpose is to prevent killed text from being retained anywhere. Users who want kill/yank should leave the default (true).

  3. Ctrl-Y yanking stale content — Expected behavior when the flag is off. Ctrl-Y reads from the system clipboard; if kills don't write to it, there's nothing fresh to yank. This is the trade-off of the setting.

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.

1 participant