Class: SwarmSDK::Tools::Scratchpad::ScratchpadList
- Defined in:
- lib/swarm_sdk/tools/scratchpad/scratchpad_list.rb
Overview
Tool for listing scratchpad entries
Shows all entries in the shared scratchpad with their metadata. All agents in the swarm share the same scratchpad.
Class Method Summary collapse
-
.create_for_scratchpad(scratchpad_storage) ⇒ ScratchpadList
Create a ScratchpadList tool for a specific scratchpad storage instance.
Instance Method Summary collapse
-
#execute(prefix: nil) ⇒ String
Execute the tool.
-
#initialize(scratchpad_storage) ⇒ ScratchpadList
constructor
Initialize with scratchpad storage instance.
Methods inherited from Base
removable, removable?, #removable?
Constructor Details
#initialize(scratchpad_storage) ⇒ ScratchpadList
Initialize with scratchpad storage instance
57 58 59 60 |
# File 'lib/swarm_sdk/tools/scratchpad/scratchpad_list.rb', line 57 def initialize(scratchpad_storage) super() # Call RubyLLM::Tool's initialize @scratchpad_storage = scratchpad_storage end |
Class Method Details
.create_for_scratchpad(scratchpad_storage) ⇒ ScratchpadList
Create a ScratchpadList tool for a specific scratchpad storage instance
49 50 51 |
# File 'lib/swarm_sdk/tools/scratchpad/scratchpad_list.rb', line 49 def create_for_scratchpad(scratchpad_storage) new(scratchpad_storage) end |
Instance Method Details
#execute(prefix: nil) ⇒ String
Execute the tool
66 67 68 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/swarm_sdk/tools/scratchpad/scratchpad_list.rb', line 66 def execute(prefix: nil) entries = scratchpad_storage.list(prefix: prefix) if entries.empty? prefix_msg = prefix ? " with prefix '#{prefix}'" : "" return "No entries found in scratchpad#{prefix_msg}" end result = [] prefix_msg = prefix ? " with prefix '#{prefix}'" : "" result << "Scratchpad entries#{prefix_msg} (#{entries.size} #{entries.size == 1 ? "entry" : "entries"}):" result << "" entries.each do |entry| time_str = entry[:updated_at].strftime("%Y-%m-%d %H:%M:%S") result << " scratchpad://#{entry[:path]}" result << " Title: #{entry[:title]}" result << " Size: #{format_bytes(entry[:size])}" result << " Updated: #{time_str}" result << "" end result.join("\n").rstrip rescue ArgumentError => e validation_error(e.) end |