Skip to content

Conversation

@raiden-staging
Copy link
Contributor

@raiden-staging raiden-staging commented Aug 16, 2025

  • Extending server with /clipboard routes
# Clipboard
# | GET /clipboard - Get clipboard content
curl http://localhost:10001/clipboard
# | > {"type":"text","text":"lorem_ipsum"}

# | POST /clipboard - Set clipboard content
curl -X POST -H "Content-Type: application/json" \
  --data '{"type":"text","text":"hello"}' \
  http://localhost:10001/clipboard

# | GET /clipboard/stream - Stream clipboard changes as SSE
# Keep this running in one terminal
curl -N http://localhost:10001/clipboard/stream

# In another terminal, set clipboard content to see events
curl -X POST -H "Content-Type: application/json" \
  --data '{"type":"text","text":"this_notifies_stream"}' \
  http://localhost:10001/clipboard

TL;DR

Introduced new /clipboard API endpoints to get, set, and stream system clipboard content, extending server capabilities for external application interaction.

Why we made these changes

To enhance server functionality by providing programmatic access to the system clipboard, enabling external applications to interact with clipboard data.

What changed?

  • Added Clipboard API: Implemented GET, POST, and SSE stream endpoints for clipboard operations in clipboard.go, leveraging xclip.
  • API Specification & Generation: Updated openapi.yaml and regenerated OpenAPI files (oapi.go, clipboard_types.go, server_handlers.go).
  • Server Integration: ApiService was enhanced with a clipboardManager, and main.go explicitly registers the new handlers.
  • Dependencies: go.mod and go.sum were updated to reflect new direct and indirect Go dependencies, including oapi-codegen.
  • Testing: New unit tests were added in clipboard_test.go for the clipboard API functionalities.
  • Documentation: README.md was updated with curl examples for the new routes.

Description generated by Mesa. Update settings

Copy link

@mesa-dot-dev mesa-dot-dev bot left a comment

Choose a reason for hiding this comment

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

Performed full review of fe02e69...a6f392e

11 files reviewed | 0 comments | Review on Mesa | Edit Reviewer Settings

cursor[bot]

This comment was marked as outdated.

// Initialize clipboard manager if not already done
if s.clipboardManager == nil {
s.clipboardManager = newClipboardManager()
}
Copy link

Choose a reason for hiding this comment

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

Bug: Clipboard Manager Initialization Race Condition

A race condition exists in the lazy initialization of clipboardManager. Multiple concurrent requests to GetClipboard, SetClipboard, or StreamClipboard can cause several clipboardManager instances to be created. This leads to lost state and inconsistent behavior, potentially dropping clipboard events for watchers.

Fix in Cursor Fix in Web

@matthewjmarangoni
Copy link
Contributor

Neat idea! Any thoughts about supporting clearing the clipboard?

log := logger.FromContext(ctx)
display := getDisplay()

// Create a temporary file to store the content (more reliable than piping for large content)
Copy link
Contributor

@matthewjmarangoni matthewjmarangoni Aug 25, 2025

Choose a reason for hiding this comment

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

Possibly this is an outdated comment?

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.

2 participants