fix: paste clipboard images on WSL when WSLg only offers BMP#1962
Open
nothankyouzzz wants to merge 1 commit into
Open
fix: paste clipboard images on WSL when WSLg only offers BMP#1962nothankyouzzz wants to merge 1 commit into
nothankyouzzz wants to merge 1 commit into
Conversation
WSLg bridges Windows clipboard images into the Wayland clipboard as image/bmp only. selectPreferredImageMimeType() accepted any image/* type, so the BMP payload was read successfully but dropped downstream (png/jpeg/webp/gif only), and the WSL PowerShell fallback never ran. - Only select MIME types the image pipeline can decode, so a BMP-only clipboard falls through to the PowerShell fallback on WSL. - Embed the temp path in the PowerShell script text instead of an env var: WSL only forwards env vars listed in WSLENV, so the hand-off silently arrived empty without user-side config. - Thread the injected runCommand through the Linux clipboard helpers (matching the macOS path) so the fallback chain is testable. Closes MoonshotAI#1961
|
nothankyouzzz
added a commit
to nothankyouzzz/wezterm-config
that referenced
this pull request
Jul 20, 2026
WSLg bridges Windows clipboard images as image/bmp only, which Kimi cannot decode; the successful BMP read also short-circuits Kimi's WSL PowerShell fallback, and that fallback loses its temp-path env var at the WSL boundary unless it is listed in WSLENV. Ship a wl-paste shim plus a kimi() wrapper and WSLENV entry, all marked temporary until MoonshotAI/kimi-code#1962 lands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1961
Problem
On WSL with WSLg, pasting an image (e.g. a Win+Shift+S screenshot) into the TUI with
Ctrl-Vsilently does nothing. Two compounding causes:image/bmp.selectPreferredImageMimeType()fell back to accepting anyimage/*type, soreadClipboardImageViaWlPaste()successfully returned BMP bytes. Because that read "succeeded",readClipboardMedia()never reached the WSL PowerShell fallback — and the BMP was then dropped byisSupportedImageMimeType()(the pipeline only decodes png/jpeg/webp/gif). Verified by shim-logging the actual subprocess calls on Ctrl-V:wl-paste --type image/bmpis requested,wslpath/powershell.exenever run.KIMI_WSL_CLIPBOARD_IMAGE_PATH, but WSL only forwards env vars listed inWSLENVto Win32 processes, so the variable arrived empty,$img.Save($null)threw (non-terminating), and the fallback silently returned null.Fix
selectPreferredImageMimeType()no longer accepts undecodableimage/*types. A BMP-only clipboard now yieldsnullat the wl-paste/xclip stage, letting the WSL PowerShell fallback produce a real PNG attachment.readClipboardImageViaPowerShell()embeds the temp path (single-quote escaped) directly in the script text instead of relying on an env var crossing the WSL boundary.runCommand(same pattern as the macOS path), making the fallback chain testable.Tests
Added two cases to
clipboard-image.test.ts:image/bmp→ falls through to the PowerShell fallback, returns a PNG, never reads the BMP payload, and the script carries the embedded temp path.null(unchanged behavior, no PowerShell call).pnpm vitest run apps/kimi-code/test/utils/clipboard/— 25/25 pass;pnpm run typecheck(apps/kimi-code) clean;pnpm oxlinton touched files clean.Also verified the exact PowerShell round-trip manually on Windows 11 + WSL2 (Ubuntu 24.04, WSLg 1.0.73.2, WezTerm).