Repository navigation
fix(kimi-code): make fullscreen copy reach the clipboard in tmux and on Linux - #4755
Conversation
The native clipboard module reports success on Linux without holding the X11 selection, so copies landed nowhere. Linux now writes through termux-clipboard-set, wl-copy, xclip or xsel, and every platform plans its route from the platform and environment: remote sessions (SSH, mosh, or KIMI_CODE_CLIPBOARD_OSC52=1) always emit OSC 52 after the direct write; without a display, under WSL, or in Termux, OSC 52 backs up a failed write; and any other desktop reports which tool to install instead of trusting OSC 52. Clipboard commands run asynchronously from / with no output pipes and a 5 second timeout.
Fullscreen selections were copied with a bare OSC 52 sequence, which tmux drops by default and GNOME Terminal ignores, while the renderer still flashed "Copied!". Selections now go through the same clipboard path as /copy: a verified write flashes "Copied!", an OSC 52-only copy flashes "Copied via terminal", and a failure flashes the error.
Releasing a mouse selection in fullscreen copies it right away. The new copy_on_select key in tui.toml (default true) and the "Copy on select" entry in /settings, shown only in fullscreen, let users keep the selection highlighted instead. Changes from /settings and /reload apply to the running fullscreen view, and saving any other preference keeps the choice.
In fullscreen, Ctrl+C, Ctrl+Shift+C, or Cmd+C copies a highlighted selection and clears it, whichever dialog has focus and whether or not copy on select already copied it, so the next Ctrl+C interrupts or clears the input as before. A copy also cancels a pending Ctrl+C exit.
tmux forwards the bare sequence only with set-clipboard on and the DCS passthrough form only with allow-passthrough on, so send both. The env var docs now name the tmux settings.
🦋 Changeset detectedLatest commit: e33a2d5 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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 093b4792d8
ℹ️ 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".
There was a problem hiding this comment.
🟡 Changes recommended
Clipboard copying can execute untrusted workspace binaries during the trust prompt, and copy-key handling can trigger interrupts or leave stale double-Esc state.
3 open issues
What changed in this PR
此 PR 将全屏选区复制接入 CLI 共用的剪贴板路径,改善 tmux 和 Linux 下提示成功但未实际复制的问题,并增加可配置的选区复制行为。
Changes:
- 按平台和环境选择原生剪贴板、异步命令及 OSC 52,区分复制成功、终端转交和失败提示。
- 新增
copy_on_select设置及全屏选区复制快捷键,支持即时设置和/reload。 - 补充剪贴板、键盘交互和配置测试,以及中英文文档和发布说明。
| File | Description |
|---|---|
docs/zh/reference/keyboard.md |
说明全屏选区复制快捷键。 |
docs/zh/configuration/env-vars.md |
说明 OSC 52 开关与远程环境检测。 |
docs/zh/configuration/config-files.md |
记录 copy_on_select 配置。 |
docs/en/reference/keyboard.md |
同步英文快捷键说明。 |
docs/en/configuration/env-vars.md |
同步英文剪贴板环境变量说明。 |
docs/en/configuration/config-files.md |
同步英文选区复制配置说明。 |
apps/kimi-code/test/utils/clipboard/clipboard-text.test.ts |
覆盖平台计划、后备路径及 tmux 序列。 |
apps/kimi-code/test/tui/fullscreen-layout.test.ts |
验证选区复制调用和结果提示。 |
apps/kimi-code/test/tui/create-tui-state.test.ts |
验证启动时应用复制设置。 |
apps/kimi-code/test/tui/controllers/editor-keyboard.test.ts |
覆盖复制快捷键、清除选区和事件消费。 |
apps/kimi-code/test/tui/config.test.ts |
验证配置默认值及读写往返。 |
apps/kimi-code/test/tui/components/dialogs/mermaid-preference-selector.test.ts |
验证设置项可见性和选项映射。 |
apps/kimi-code/test/tui/commands/update-preferences.test.ts |
验证保存其他偏好时保留复制设置。 |
apps/kimi-code/test/tui/commands/transcript-preferences.test.ts |
验证设置保存、即时生效及失败处理。 |
apps/kimi-code/src/utils/clipboard/clipboard-text.ts |
引入复制计划和异步命令执行。 |
apps/kimi-code/src/utils/clipboard/clipboard-osc52.ts |
tmux 中同时发送裸序列和透传序列。 |
apps/kimi-code/src/tui/types.ts |
增加选区复制状态字段。 |
apps/kimi-code/src/tui/tui-state.ts |
注入共用复制函数和结果提示。 |
apps/kimi-code/src/tui/kimi-tui.ts |
将复制配置传入初始状态。 |
apps/kimi-code/src/tui/controllers/editor-keyboard.ts |
在全屏选区存在时拦截复制快捷键。 |
apps/kimi-code/src/tui/config.ts |
解析、默认化并保存复制配置。 |
apps/kimi-code/src/tui/components/dialogs/settings-selector.ts |
添加全屏 Copy on select 设置面板。 |
apps/kimi-code/src/tui/commands/reload.ts |
重载时更新实时复制行为。 |
apps/kimi-code/src/tui/commands/config.ts |
连接设置选择、持久化和实时更新。 |
.changeset/fullscreen-ctrl-c-copy.md |
记录全屏 Ctrl+C 行为变化。 |
.changeset/fullscreen-copy-on-select.md |
记录新增选区复制设置。 |
.changeset/fullscreen-copy-clipboard.md |
记录剪贴板复制修复。 |
.changeset/clipboard-osc52-scope.md |
记录 OSC 52 使用范围及强制开关。 |
Review effort: Balanced
A fullscreen selection can be copied while the workspace trust prompt is still open, so clipboard writers are now resolved with resolveCommandPath and a writer found only inside the workspace is never run. Wayland sessions that set XDG_SESSION_TYPE=wayland without WAYLAND_DISPLAY try wl-copy again, as before this branch.
|
@codex review |
Kitty terminals report Ctrl+C with Caps Lock as an uppercase codepoint, so the copy key fell through to the editor and interrupted instead. The consumed copy key also skipped the editor's non-Escape hook, which let Esc, copy, Esc open the undo selector.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53ff65e4f4
ℹ️ 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".
process.cwd() returns the physical path, so a PATH entry that reached the workspace through a symlinked alias passed the containment check and the planted command could run before trust was granted.
In SSH, mosh, or with KIMI_CODE_CLIPBOARD_OSC52=1 the terminal copy waited for every system clipboard attempt, so a slow or stuck writer delayed it.
|
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1519af8db
ℹ️ 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".
Under the kitty protocol a held Ctrl-C sends repeat events. After the press copied and cleared the selection, those repeats reached the editor as Ctrl-C and interrupted the stream or armed exit.
There was a problem hiding this comment.
💡 Codex Review
kimi-code/apps/kimi-code/src/utils/process/resolve-command.ts
Lines 61 to 62 in f71666b
When PATH contains a workspace child such as $PWD/..bin, relative() returns ..bin/wl-copy, so this prefix check classifies the executable as outside the workspace and allows a fullscreen selection made before the trust prompt to spawn the planted helper. Check for the parent path components .. and ../ (using the platform separator), rather than rejecting every relative path beginning with two dots.
AGENTS.md reference: apps/kimi-code/AGENTS.md:L68-L68
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
# Conflicts: # apps/kimi-code/src/tui/commands/config.ts # apps/kimi-code/src/tui/components/dialogs/settings-selector.ts # apps/kimi-code/test/tui/components/dialogs/mermaid-preference-selector.test.ts
…on Linux Port upstream MoonshotAI#4755. - Rewrite the clipboard writer around planClipboardWrite: Termux, Wayland and X11 backends, no native module on Linux, OSC 52 forced for SSH/mosh or KIMI_CODE_CLIPBOARD_OSC52=1, and an OSC 52 fallback only where the terminal honors it. - Spawn writers with Bun.spawn: no stdout/stderr pipes, POSIX detached session, 5s SIGKILL timeout, and an absolute executable path that refuses anything reachable inside the workspace (symlink-aware physical comparison). - Send both the bare OSC 52 sequence and the tmux DCS passthrough so set-clipboard on and allow-passthrough on both reach the outer terminal. - Add the copy_on_select setting with a /settings picker, tui.toml persistence and /reload support; Ctrl-C, Ctrl-Shift-C and Cmd-C copy an active fullscreen selection, clear it, and swallow auto-repeat so holding the key cannot interrupt the turn. - Extend pi-tui's copySelection to return a failure hint string and add resetTextSelection; localize the new copy, update both docs and add four changesets.
…hotAI#4755 evidence MoonshotAI#4618 is configured through [transcript].tool_call_density and [transcript].thinking, not a [transcript.group] table. The MoonshotAI#4618 probe limitation and the four-file hang noted on MoonshotAI#4755 were fixed in 580b5b5 and 4d88e05. MoonshotAI#4730 was recorded as no longer reconstructing step ids, which the step.begin case still does; the real gap was the live context-memory fold dropping the recorded content-part timing, now fixed in 008fb38. Verdicts are unchanged.


Requirement or Bug
在全屏模式下用鼠标拖选文字,松开后界面会提示 "Copied!"。但在 tmux 里和 Ubuntu 上,剪贴板里的内容并没有变。这个 PR 修好之后,全屏选区和
/copy走同一条剪贴板路径。写入成功时提示 "Copied!",只能交给终端处理时提示 "Copied via terminal",写不进去时直接显示原因。另外加了「选中即复制」开关copy_on_select,关掉后用 Ctrl+C 复制选区,和 Claude Code、Codex 的做法一致。Bug Reproduction Steps
tui.toml里设置tui_mode = "fullscreen",然后在 tmux(默认配置)里启动 kimi。pbpaste读出来的还是旧内容。在 Ubuntu 默认的 GNOME Terminal 里粘贴,也是旧内容。Root Cause
TuiAltScreen时没有传copySelection,pi-tui 只能写一条裸 OSC52,然后无条件提示成功。OSC52 是一种转义序列,请终端代为写入剪贴板。tmux 默认会丢掉应用发出的 OSC52,GNOME Terminal 不支持 OSC52。copyTextToClipboard会先调用@mariozechner/clipboard的setText。上游 pi 已经确认,这个调用在 Linux 上返回成功,但不持有 X11 选区,所以/copy在 Linux 上也可能报告成功、剪贴板却是空的。另外它用spawnSync调用wl-copy和xclip。这两个工具会 fork 出后台进程来持有选区,同步等待它们有挂住事件循环的风险。这是根本修复,不是绕过。全屏选区改走应用的剪贴板函数,剪贴板函数按上游 pi 的路径重新排序。
Code Changes
全屏选区不再交给 pi-tui 自带的 OSC52,而是通过
copySelection注入应用的copyTextToClipboard。剪贴板写入拆成两步。先由纯函数planClipboardWrite(platform, env)算出计划,再由执行器照计划写入。计划包括三件事:要不要用原生模块,按什么顺序试哪些写入命令,OSC52 是一定发、兜底发还是不发。flowchart TD M[全屏松开鼠标,或有选区时按 Ctrl+C] --> S["copySelection(tui-state.ts 注入)"] C["/copy、复制 mermaid、复制恢复命令"] --> K S --> K[copyTextToClipboard] K --> P["planClipboardWrite(platform, env)"] P --> N{"macOS / Windows?"} N -- 是 --> NM["@mariozechner/clipboard"] NM -- 失败 --> CMD N -- 否 --> CMD["异步写入命令<br/>pbcopy / clip.exe / termux-clipboard-set / wl-copy / xclip / xsel"] NM -- 成功 --> O CMD --> O{"OSC52"} O -- "SSH / mosh,或 KIMI_CODE_CLIPBOARD_OSC52=1:一定发" --> OSC["发 OSC52<br/>tmux 里同时发裸序列和 DCS 透传"] O -- "没写成功,且没有显示、在 WSL 或 Termux 里:兜底发" --> OSC O -- 其余情况:不发 --> R OSC --> R["'native' → Copied!<br/>'osc52' → Copied via terminal<br/>抛错 → 显示原因"]计划是纯函数,所以每种平台和环境组合的路径都能用一张表直接断言,执行器只剩下照做。返回类型
'native' | 'osc52'没有变,/copy等调用方不用改。全屏模式下按 Ctrl+C 时,先看屏幕上有没有选区高亮:
flowchart TD A["Ctrl+C / Ctrl+Shift+C / Cmd+C"] --> B{有选区高亮?} B -- 否 --> E["照旧交给输入框或对话框<br/>中断、清空输入框、退出确认"] B -- 是 --> D["复制选区,清除高亮<br/>不管 copy_on_select 开没开"] D --> G[按键到此为止,同时取消待确认的退出]关键决策:
@mariozechner/clipboard,失败时改用pbcopy/clip.exeset-clipboard on时到达外层终端,DCS 透传只在allow-passthrough on时到达。两种都发,开任意一个设置都能用input-buffer-size默认值)才丢弃,屏幕也不会乱其他改动:
resolveCommandPath解析成绝对路径,只在工作区里找到的同名程序不会被执行。全屏选区在工作区信任确认之前就可能被复制,所以这条路径要守住信任关卡之前不按裸命令名启动进程的规则。copy_on_select默认是true,只在全屏模式下生效,和[transcript.group]这类全屏配置一样不带前缀。全屏模式下/settings里多了一项 Copy on select,切换后立即生效,/reload也会应用这个值。阅读顺序:
apps/kimi-code/src/utils/clipboard/clipboard-text.ts。路径计划和执行器都在这里。apps/kimi-code/src/tui/tui-state.ts。copySelection的注入,以及三种提示的来源。apps/kimi-code/src/tui/controllers/editor-keyboard.ts。Ctrl+C 怎么在界面层拦截选区复制。apps/kimi-code/src/utils/clipboard/clipboard-osc52.ts。tmux 里两种形式都发。配置项的解析与写回、设置面板、
/reload、文档和测试可以略读。Screenshots / Recordings
全屏模式下打开
/settings,列表里多了 Copy on select(PR 分支实际运行,tmux 里抓屏):选中这一项后的子面板。选 Off 后状态栏显示
Copy on select disabled.,tui.toml写入copy_on_select = false:Behavior Changes and Affected Users
/copy、复制 mermaid、复制恢复命令spawnSync调wl-copy/xclipWAYLAND_DISPLAY或XDG_SESSION_TYPE=wayland)、DISPLAY、TERMUX_VERSION异步选用wl-copy/xclip/xsel/termux-clipboard-set/copy提示无法确认KIMI_CODE_CLIPBOARD_OSC52=1DISPLAY和WAYLAND_DISPLAY的 WSLg)、Termux 上写入工具失败pbcopy/clip.exe,不再发 OSC52KIMI_CODE_CLIPBOARD_OSC52=1/copy只发 DCS 透传形式,全屏选区只发裸序列set-clipboard on和allow-passthrough on的用户,外层终端会收到两次相同内容tui.tomlcopy_on_select = true全屏模式下 Ctrl+C 那一行没有配置项退路。维护者(本 PR 作者)确认这是预期行为。
测试覆盖:
test/utils/clipboard/clipboard-text.test.ts。计划表覆盖 macOS、Windows、X11、Wayland(包括只设了XDG_SESSION_TYPE的会话)、无显示、WSLg、Termux、SSH、mosh,以及KIMI_CODE_CLIPBOARD_OSC52。执行器部分覆盖 Linux 跳过原生插件、远程会话额外发 OSC52、无显示和 WSLg 下回退到 OSC52、有显示没工具时报错、长文本不设上限、写入命令按绝对路径启动、工作区里的同名程序不会被执行,以及 tmux 里两种形式都发。test/tui/fullscreen-layout.test.ts。test/tui/config.test.ts。设置面板只在全屏模式下显示、保存后立即生效,在test/tui/commands/transcript-preferences.test.ts。test/tui/controllers/editor-keyboard.test.ts,用真实的TuiAltScreen驱动选区。覆盖四种按键编码、复制后清除高亮并吞掉按键、copy_on_select 开着时再复制一次、忽略按键抬起事件、取消待确认的退出、regular 模式下照常放行,以及控制器销毁后不再拦截。验证记录
set-clipboard on时到达外层终端,DCS 透传形式只在allow-passthrough on时到达,默认配置下两种都到不了。两种一起发时,开任意一个设置都能到达。pbpaste。kitty 0.49.2 和 Ghostty 1.4.0 收 6 万到 400 万字符的文本都完整进入剪贴板。kitty 里的 tmux 3.7c 收 15 万字符正常,100 万字符被丢弃,剪贴板不变,屏幕正常。test/tui和test/utils/clipboard的测试。apps/kimi-code完整测试套件:4796 个通过,2 个失败。失败都在test/scripts/native/release-artifacts.test.ts,在 base commit 上同样失败。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.