Class: SharedTools::Tools::ClipboardTool

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

Overview

Read, write, and clear the system clipboard. Supports macOS (pbcopy/pbpaste), Linux (xclip or xsel), and Windows (clip/PowerShell).

Examples:

tool = SharedTools::Tools::ClipboardTool.new
tool.execute(action: 'write', text: 'Hello!')
tool.execute(action: 'read')
tool.execute(action: 'clear')

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



34
35
36
# File 'lib/shared_tools/tools/clipboard_tool.rb', line 34

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_tool'

Instance Method Details

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

Returns result.

Parameters:

  • action (String)

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

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

    text for write action

Returns:

  • (Hash)

    result



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/shared_tools/tools/clipboard_tool.rb', line 41

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

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