fix(cli): support WSL2 clipboard image paste#27588
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces support for pasting images from the clipboard when running in a WSL2 environment. By leveraging PowerShell interop, the CLI can now access the Windows clipboard from within Linux, ensuring a seamless experience for users working across the WSL boundary. The changes also refactor existing Windows clipboard logic into a shared utility to improve maintainability and consistency. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for detecting and saving clipboard images in WSL2 environments by utilizing PowerShell interop and wslpath for path translation, alongside refactoring the Windows implementation to share a common helper. The review feedback highlights that checking PowerShell's stdout with strict equality after trimming is fragile due to potential extra output (like telemetry or BOM characters), and recommends using .includes() instead for more robust validation.
| '-Command', | ||
| 'Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Clipboard]::ContainsImage()', | ||
| ]); | ||
| return stdout.trim() === 'True'; |
There was a problem hiding this comment.
Using stdout.trim() === 'True' is fragile because PowerShell can sometimes output extra text to stdout (such as update notifications, telemetry warnings, or BOM characters), even when -NoProfile is specified. If any extra text is printed, stdout.trim() will not equal 'True', causing the check to fail. Using stdout.includes('True') is much more robust and ensures the clipboard check works reliably across different user environments.
| return stdout.trim() === 'True'; | |
| return stdout.includes('True'); |
| if (stdout.trim() !== 'success') { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Using stdout.trim() !== 'success' is fragile because PowerShell can sometimes output extra text to stdout (such as update notifications, telemetry warnings, or BOM characters), even when -NoProfile is specified. If any extra text is printed, stdout.trim() will not equal 'success', causing the image save to fail. Using !stdout.includes('success') is much more robust and ensures the clipboard paste works reliably across different user environments.
| if (stdout.trim() !== 'success') { | |
| return false; | |
| } | |
| if (!stdout.includes('success')) { | |
| return false; | |
| } |
Summary
Fixes #22274
Test plan