mirror of
https://github.com/openai/codex.git
synced 2026-04-30 19:32:04 +03:00
FIX: WSL Paste image does not work (#6793)
## Related issues: - https://github.com/openai/codex/issues/3939 - https://github.com/openai/codex/issues/2292 - https://github.com/openai/codex/issues/7528 (After correction https://github.com/openai/codex/pull/3990) **Area:** `codex-cli` (image handling / clipboard & file uploads) **Platforms affected:** WSL (Ubuntu on Windows 10/11). No behavior change on native Linux/macOS/Windows. ## Summary This PR fixes image pasting and file uploads when running `codex-cli` inside WSL. Previously, image operations failed silently or with permission errors because paths weren't properly mapped between Windows and WSL filesystems. ## Visual Result <img width="1118" height="798" alt="image" src="https://github.com/user-attachments/assets/14e10bc4-6b71-4d1f-b2a6-52c0a67dd069" /> ## Last Rust-Cli <img width="1175" height="859" alt="image" src="https://github.com/user-attachments/assets/7ef41e29-9118-42c9-903c-7116d21e1751" /> ## Root cause The CLI assumed native Linux/Windows environments and didn't handle the WSL↔Windows boundary: - Used Linux paths for files that lived on the Windows host - Missing path normalization between Windows (`C:\...`) and WSL (`/mnt/c/...`) - Clipboard access failed under WSL ### Why `Ctrl+V` doesn't work in WSL terminals Most WSL terminal emulators (Windows Terminal, ConEmu, etc.) intercept `Ctrl+V` at the terminal level to paste text from the Windows clipboard. This keypress never reaches the CLI application itself, so our clipboard image handler never gets triggered. Users need `Ctrl+Alt+V`. ## Changes ### WSL detection & path mapping - Detects WSL by checking `/proc/sys/kernel/osrelease` and the `WSL_INTEROP` env var - Maps Windows drive paths to WSL mount paths (`C:\...` → `/mnt/c/...`) ### Clipboard fallback for WSL - When clipboard access fails under WSL, falls back to PowerShell to extract images from the Windows clipboard - Saves to a temp file and maps the path back to WSL ### UI improvements - Shows `Ctrl+Alt+V` hint on WSL (many terminals intercept plain `Ctrl+V`) - Better error messages for unreadable images ## Performance - Negligible overhead. The fallback adds a single FS copy to a temp file only when needed. - Direct streaming remains the default. ## Files changed - `protocol/src/lib.rs` – Added platform detection module - `protocol/src/models.rs` – Added WSL path mapping for local images - `protocol/src/platform.rs` – New module with WSL detection utilities - `tui/src/bottom_pane/chat_composer.rs` – Added base64 data URL support and WSL path mapping - `tui/src/bottom_pane/footer.rs` – WSL-aware keyboard shortcuts - `tui/src/clipboard_paste.rs` – PowerShell clipboard fallback ## How to reproduce the original bug (pre-fix) 1. Run `codex-cli` inside WSL2 on Windows. 2. Paste an image from the Windows clipboard or drag an image from `C:\...` into the terminal. 3. Observe that the image is not attached (silent failure) or an error is logged; no artifact reaches the tool. ## How to verify the fix 1. Build this branch and run `codex-cli` inside WSL2. 2. Paste from clipboard and drag from both Windows and WSL paths. 3. Confirm that the image appears in the tool and the CLI shows a single concise info line (no warning unless fallback was used). I’m happy to adjust paths, naming, or split helpers into a separate module if you prefer. ## How to try this branch If you want to try this before it’s merged, you can use my Git branch: Repository: https://github.com/Waxime64/codex.git Branch: `wsl-image-2` 1. Start WSL on your Windows machine. 2. Clone the repository and switch to the branch: ```bash git clone https://github.com/Waxime64/codex.git cd codex git checkout wsl-image-2 # then go into the Rust workspace root, e.g.: cd codex-rs 3. Build the TUI binary: cargo build -p codex-tui --bin codex-tui --release 4. Install the binary: sudo install -m 0755 target/release/codex-tui /usr/local/bin/codex 5. From the project directory where you want to use Codex, start it with: cd /path/to/your/project /usr/local/bin/codex On WSL, use CTRL+ALT+V to paste an image from the Windows clipboard into the chat.
This commit is contained in:
@@ -49,6 +49,10 @@ pub(crate) const fn ctrl(key: KeyCode) -> KeyBinding {
|
||||
KeyBinding::new(key, KeyModifiers::CONTROL)
|
||||
}
|
||||
|
||||
pub(crate) const fn ctrl_alt(key: KeyCode) -> KeyBinding {
|
||||
KeyBinding::new(key, KeyModifiers::CONTROL.union(KeyModifiers::ALT))
|
||||
}
|
||||
|
||||
fn modifiers_to_string(modifiers: KeyModifiers) -> String {
|
||||
let mut result = String::new();
|
||||
if modifiers.contains(KeyModifiers::CONTROL) {
|
||||
|
||||
Reference in New Issue
Block a user