Skip to content

Add setting to support OSC 52 paste #15336

Merged
scidomino merged 1 commit intomainfrom
tomm_paste
Jan 6, 2026
Merged

Add setting to support OSC 52 paste #15336
scidomino merged 1 commit intomainfrom
tomm_paste

Conversation

@scidomino
Copy link
Copy Markdown
Collaborator

@scidomino scidomino commented Dec 19, 2025

Summary

Add setting to support OSC 52 paste

Details

Some users can't paste any other way. it's off by default.

How to Validate

Add to your settings.json:

  "experimental": {
    "useOSC52Paste": true
  },

Use alternate buffer mode and paste with a mouse right-click and verify that it works (it may pop up a warning dialog first). (Note: depending on your terminal, ctrl+v may still use bracketed paste and not OSC 52)

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker
@scidomino scidomino requested a review from a team as a code owner December 19, 2025 18:45
@scidomino scidomino marked this pull request as draft December 19, 2025 18:45
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @scidomino, 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 enhances the application's paste functionality by introducing a robust fallback mechanism. Previously, if the clipboardy library encountered an issue reading the system clipboard, paste operations might fail silently or with a generic error. Now, the system will attempt to retrieve clipboard content directly from the terminal using the OSC 52 escape sequence, improving reliability and user experience for pasting text. This involves both sending the OSC 52 request and correctly parsing the terminal's response.

Highlights

  • OSC 52 Fallback for Paste: Implemented a mechanism to request clipboard content using the OSC 52 terminal escape sequence if the clipboardy library fails to read the system clipboard, enhancing paste reliability.
  • OSC 52 Response Parsing: Added logic to KeypressContext to parse incoming OSC 52 responses from the terminal, decoding base64 content and emitting a paste event with the retrieved text.
  • Improved Paste Error Handling: Updated error messages for paste operations to be more generic and included stdout in the dependency array for paste-related useCallback hooks.
  • Comprehensive Test Coverage: Introduced new test cases for InputPrompt to cover the OSC 52 fallback and extensive tests for KeypressContext to validate OSC 52 parsing, including edge cases like split sequences and invalid formats.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@scidomino scidomino changed the title OSC 52 paste Dec 19, 2025
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @scidomino, 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 enhances the application's paste functionality by introducing a robust fallback mechanism. Previously, if the primary method for reading clipboard content failed, the paste operation would simply error out. Now, the system attempts to retrieve the clipboard content using an OSC 52 query to the terminal, ensuring a more reliable paste experience. This change involves both requesting the OSC 52 data and processing its response, along with updated error messaging and comprehensive test coverage.

Highlights

  • OSC 52 Paste Fallback: Implemented a fallback mechanism where if the primary clipboard reading method (clipboardy) fails, the application sends an OSC 52 query to the terminal to request the clipboard data.
  • OSC 52 Response Parsing: The KeypressContext now includes logic to detect, parse, and decode OSC 52 responses from the terminal, treating the received data as a paste event.
  • Improved Error Handling: Generalized the error message for paste operations from 'Error handling clipboard image:' to 'Error handling paste:' for broader applicability.
  • Comprehensive Testing: Added new unit tests to validate the OSC 52 fallback mechanism, covering scenarios for valid responses, split responses, different termination sequences, and invalid formats.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @scidomino, 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 significantly improves the robustness of paste functionality within the application. By introducing a fallback mechanism that leverages the OSC 52 terminal protocol, the system can now retrieve clipboard content even when the standard clipboardy library encounters issues. This change ensures a more consistent and reliable user experience for pasting text, especially in diverse terminal environments.

Highlights

  • OSC 52 Paste Fallback Implementation: The system now attempts to use the OSC 52 terminal escape sequence to retrieve clipboard content if the primary clipboardy library fails to read the clipboard, enhancing paste reliability.
  • OSC 52 Response Parsing: The KeypressContext has been updated to detect, parse, and decode incoming OSC 52 responses, allowing the application to receive pasted text directly from the terminal.
  • Improved Error Handling and Testing: Error messages related to paste operations have been generalized, and comprehensive new tests have been added to validate the OSC 52 fallback and parsing logic across various scenarios, including split sequences and different terminators.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 19, 2025

Size Change: +1.58 kB (+0.01%)

Total Size: 22.2 MB

Filename Size Change
./bundle/gemini.js 22.2 MB +1.58 kB (+0.01%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fallback mechanism for clipboard pasting using the OSC 52 protocol, which is a valuable enhancement for terminal compatibility. The changes are well-implemented, with new logic for parsing OSC 52 responses and comprehensive tests to validate it. I've identified one high-severity issue concerning the handling of large paste payloads, which could lead to excessive memory usage and application instability. My review includes a detailed comment and a code suggestion to address this potential denial-of-service vulnerability.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fallback mechanism for pasting text using the OSC 52 escape sequence, which is triggered when the primary clipboardy library fails. The implementation is robust, correctly handling the request for clipboard content and parsing the terminal's response. The parsing logic in KeypressContext.tsx is well-designed, covering various scenarios such as different terminators (BEL and ST), split data chunks, and invalid sequences. The accompanying tests are comprehensive and validate the new functionality thoroughly. Overall, this is a high-quality contribution that improves the tool's resilience in different terminal environments.

@scidomino scidomino marked this pull request as ready for review December 19, 2025 19:21
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of querying XTGETTCAP
to test whether the terminal supports OSC 52 paste. If it does I think it should be our primary option not a fallback option. The same place we detect the terminal background color and whether kitty is supported would be ideal for this.

From Gemini:
Modern terminals (Kitty, WezTerm, recent xterm) support a query sequence called XTGETTCAP. You can ask the terminal specifically for the Ms (Manipulate Selection) capability.

How it works:

Send \x1bP+q546e\x1b\ (Request capability "Tn" - often mapped to clipboard).

Or specifically query the termcap code for clipboard Ms.

Listen to stdin for a response.

@scidomino
Copy link
Copy Markdown
Collaborator Author

scidomino commented Dec 19, 2025

I don't think it would be a good default since all the terminals I've tried that support this pop up an ugly warning dialog each time a paste is processed. That would be a big downgrade for existing users.

Detecting support would only be useful for preventing dumping garbage characters to the screens of terminals that don't support it. But that doesn't seem super important to me. Paste will be broken there anyways.

@scidomino scidomino force-pushed the tomm_paste branch 2 times, most recently from ca00d36 to f5bdea1 Compare December 20, 2025 00:12
@scidomino scidomino changed the title Support OSC 52 paste fallback Dec 20, 2025
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably worth following up with detection of whether OSC 52 is available. Otherwise behavior is confusing when this option is enabled as you attempt to paste but get nothing.lgtm

@jacob314
Copy link
Copy Markdown
Contributor

We should use OSC 52 for copy as well as paste. In fact that is the use of OSC 52 that we should potentially use by default rather than requiring a setting as terminals do not block it as copying to the clipboard is safer than reading from it. This will be important for people using SSH.
Fyi @galz10 who should be interested in the security implications of this as well as possible ramifications for an electron app.

@scidomino scidomino added this pull request to the merge queue Jan 6, 2026
Merged via the queue into main with commit 384fb6a Jan 6, 2026
19 of 20 checks passed
@scidomino scidomino deleted the tomm_paste branch January 6, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants