Skip to content

Conversation

@gaius-codius
Copy link

Summary

Features

  • Write-only clipboard access (read queries blocked for security)
  • 75KB size limit matching common terminal implementations
  • Base64 whitespace handling per RFC 4648

Additional Fix

Also fixes StreamCancelFn type mismatch from #2709 where the implementations were updated but the type definition was not.

  • Tested with zellij mouse selection

)

Implements OSC 52 escape sequence handling to allow terminal applications
like zellij, tmux, and neovim to copy text to the system clipboard.

Features:
- Write-only clipboard access (read queries blocked for security)
- 75KB size limit matching common terminal implementations
- Base64 whitespace handling per RFC 4648
- Dual-phase size validation (estimated + actual)

Also fixes StreamCancelFn type mismatch introduced in cfbb39a where
the implementations were updated but the type definition was not.
@CLAassistant
Copy link

CLAassistant commented Dec 28, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 28, 2025

Walkthrough

This pull request modifies three interconnected components to add OSC 52 clipboard copy support in the terminal wrapper and simplify the streaming cancellation mechanism across the stack. The frontend adds OSC 52 parsing and clipboard handling with validation and size limits. The backend web handler and RPC client utilities remove context passing from the streaming cancellation function signature, simplifying the cancellation flow from func(context.Context) error to func(). These changes update call sites and function signatures accordingly while maintaining existing streaming and data handling behaviors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Out of Scope Changes check ❓ Inconclusive Changes to StreamCancelFn signature in multiple files are out of scope for the OSC 52 feature but are acknowledged in the PR description as fixing issue #2709, representing an incidental fix rather than scope creep. Clarify whether the StreamCancelFn type fix should be in a separate PR or confirm it is acceptable as an incidental fix bundled with the OSC 52 feature.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main feature: adding OSC 52 clipboard support for terminal applications, which is the primary focus of the changeset.
Description check ✅ Passed The description clearly relates to the changeset, explaining OSC 52 implementation, clipboard access restrictions, size limits, and the additional StreamCancelFn type fix from issue #2709.
Linked Issues check ✅ Passed The PR successfully implements OSC 52 handling for clipboard operations with write-only access, 75KB size limit, and base64 whitespace handling per RFC 4648, addressing the requirements from issue #2140.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
frontend/app/view/term/termwrap.ts (1)

123-189: Well-implemented OSC 52 handler with proper security considerations.

The implementation correctly:

  • Blocks clipboard read queries (?) to prevent clipboard theft
  • Applies dual-phase size validation (estimated before decode, actual after)
  • Strips whitespace per RFC 4648 for chunked base64 data
  • Uses async clipboard API with proper error handling

One minor edge case: after stripping whitespace on line 166, cleanBase64Data could become empty if base64Data was only whitespace. Consider adding a check:

🔎 Optional fix for edge case
         // strip whitespace from base64 data (some terminals chunk with newlines per RFC 4648)
         const cleanBase64Data = base64Data.replace(/\s+/g, "");
+        if (cleanBase64Data.length === 0) {
+            return true;
+        }
         const decodedText = base64ToString(cleanBase64Data);
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90011a7 and 178a82b.

📒 Files selected for processing (3)
  • frontend/app/view/term/termwrap.ts
  • pkg/web/web.go
  • pkg/wshrpc/wshclient/wshclientutil.go
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: esimkowitz
Repo: wavetermdev/waveterm PR: 1725
File: pkg/remote/fileshare/wavefs/wavefs.go:441-494
Timestamp: 2025-01-29T04:21:11.649Z
Learning: The `CopyRemote` function in WaveTerm's file operations has proper error handling that prevents partial writes by failing fast and using context cancellation. Each step (path cleaning, file operations, tar reading/writing) is guarded by error checks that prevent proceeding with writes on error.
📚 Learning: 2025-01-22T01:28:41.417Z
Learnt from: esimkowitz
Repo: wavetermdev/waveterm PR: 1790
File: pkg/remote/fileshare/wshfs/wshfs.go:122-122
Timestamp: 2025-01-22T01:28:41.417Z
Learning: The RpcClient in pkg/remote/fileshare/wshfs/wshfs.go is initialized and handled downstream by either main-server or wshcmd-connserver, as documented in the package comment.

Applied to files:

  • pkg/wshrpc/wshclient/wshclientutil.go
  • pkg/web/web.go
📚 Learning: 2025-01-29T04:21:11.649Z
Learnt from: esimkowitz
Repo: wavetermdev/waveterm PR: 1725
File: pkg/remote/fileshare/wavefs/wavefs.go:441-494
Timestamp: 2025-01-29T04:21:11.649Z
Learning: The `CopyRemote` function in WaveTerm's file operations has proper error handling that prevents partial writes by failing fast and using context cancellation. Each step (path cleaning, file operations, tar reading/writing) is guarded by error checks that prevent proceeding with writes on error.

Applied to files:

  • pkg/web/web.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: merge-gatekeeper
🔇 Additional comments (4)
frontend/app/view/term/termwrap.ts (2)

38-38: Good choice for the size limit.

The 75 KB limit aligns with common terminal implementations and provides a reasonable safeguard against excessive clipboard data.


529-541: OSC handlers are correctly registered.

The OSC 52 handler is properly integrated alongside the existing OSC 7, 9283, and 16162 handlers, following the established pattern of passing blockId and loaded state.

pkg/web/web.go (1)

257-275: Cancellation signature change is consistent with the RPC layer.

The simplified streamCancelFn func() signature aligns with the corresponding change in wshclientutil.go. The nil check before invoking the cancel function and returning ctx.Err() maintains proper error semantics.

pkg/wshrpc/wshclient/wshclientutil.go (1)

66-68: Simplified cancellation signature is correctly implemented.

The type definition StreamCancelFn func() in wshrpctypes.go:376 matches the implementation at lines 66-68. The signature is consistently used throughout the codebase (e.g., web.go:257), and the fire-and-forget pattern with context.Background() is appropriate for cancellation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support OSC 52 clipboard escape sequences over SSH"

2 participants