Class: SharedTools::Tools::ClipboardTool

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/shared_tools/tools/clipboard_tool.rb

Overview

A tool for reading from and writing to the system clipboard. Supports macOS (pbcopy/pbpaste), Linux (xclip/xsel), and Windows (clip).

Examples:

tool = SharedTools::Tools::ClipboardTool.new
tool.execute(action: 'write', content: 'Hello, World!')
result = tool.execute(action: 'read')
puts result[:content]  # "Hello, World!"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ ClipboardTool

Returns a new instance of ClipboardTool.

Parameters:

  • logger (Logger) (defaults to: nil)

    optional logger



60
61
62
# File 'lib/shared_tools/tools/clipboard_tool.rb', line 60

def initialize(logger: nil)
  @logger = logger || RubyLLM.logger
end

Class Method Details

.nameObject



16
# File 'lib/shared_tools/tools/clipboard_tool.rb', line 16

def self.name = 'clipboard'

Instance Method Details

#execute(action:, content: nil) ⇒ Hash

Execute clipboard action

Parameters:

  • action (String)

    ‘read’, ‘write’, or ‘clear’

  • content (String, nil) (defaults to: nil)

    content to write (required for ‘write’ action)

Returns:

  • (Hash)

    result with success status and content/error



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/shared_tools/tools/clipboard_tool.rb', line 69

def execute(action:, content: nil)
  @logger.info("ClipboardTool#execute action=#{action.inspect}")

  case action.to_s.downcase
  when 'read'
    read_clipboard
  when 'write'
    write_clipboard(content)
  when 'clear'
    clear_clipboard
  else
    {
      success: false,
      error: "Unknown action: #{action}. Valid actions are: read, write, clear"
    }
  end
rescue => e
  @logger.error("ClipboardTool error: #{e.message}")
  {
    success: false,
    error: e.message
  }
end