Class: SharedTools::Tools::DiskTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::DiskTool
- Defined in:
- lib/shared_tools/tools/disk_tool.rb
Overview
A tool for interacting with files and directories. Be careful using as it can perform actions on your computer!
Defined Under Namespace
Modules: Action
Constant Summary collapse
- ACTIONS =
[ Action::DIRECTORY_CREATE, Action::DIRECTORY_DELETE, Action::DIRECTORY_MOVE, Action::DIRECTORY_LIST, Action::FILE_CREATE, Action::FILE_DELETE, Action::FILE_MOVE, Action::FILE_READ, Action::FILE_WRITE, Action::FILE_REPLACE, ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #execute(action:, path:, destination: nil, old_text: nil, new_text: nil, text: nil) ⇒ Object
-
#initialize(driver: nil, logger: nil) ⇒ DiskTool
constructor
A new instance of DiskTool.
Constructor Details
#initialize(driver: nil, logger: nil) ⇒ DiskTool
Returns a new instance of DiskTool.
96 97 98 99 |
# File 'lib/shared_tools/tools/disk_tool.rb', line 96 def initialize(driver: nil, logger: nil) @driver = driver || Disk::LocalDriver.new(root: Dir.pwd) @logger = logger || RubyLLM.logger end |
Class Method Details
.name ⇒ Object
16 |
# File 'lib/shared_tools/tools/disk_tool.rb', line 16 def self.name = 'disk_tool' |
Instance Method Details
#execute(action:, path:, destination: nil, old_text: nil, new_text: nil, text: nil) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/shared_tools/tools/disk_tool.rb', line 107 def execute(action:, path:, destination: nil, old_text: nil, new_text: nil, text: nil) @logger.info({ action:, path:, destination:, old_text:, new_text:, text:, }.compact.map { |key, value| "#{key}=#{value.inspect}" }.join(" ")) case action when Action::DIRECTORY_CREATE then @driver.directory_create(path:) when Action::DIRECTORY_DELETE then @driver.directory_delete(path:) when Action::DIRECTORY_MOVE then @driver.directory_move(path:, destination:) when Action::DIRECTORY_LIST then @driver.directory_list(path:) when Action::FILE_CREATE then @driver.file_create(path:) when Action::FILE_DELETE then @driver.file_delete(path:) when Action::FILE_MOVE then @driver.file_move(path:, destination:) when Action::FILE_READ then @driver.file_read(path:) when Action::FILE_WRITE then @driver.file_write(path:, text:) when Action::FILE_REPLACE then @driver.file_replace(old_text:, new_text:, path:) end end |