Class: RubyLLM::Toolbox::Tools::MoveFile
- Defined in:
- lib/ruby_llm/toolbox/tools/move_file.rb
Overview
EXEC. Moves or renames a file or directory within fs_root. BOTH the source and destination are confined to the jail, so nothing can be moved in from or out to outside the root. Refuses to clobber an existing destination unless overwrite is set.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#call, exec_tool!, exec_tool?, #initialize, #name
Constructor Details
This class inherits a constructor from RubyLLM::Toolbox::Base
Instance Method Details
#execute(source:, destination:, overwrite: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_llm/toolbox/tools/move_file.rb', line 31 def execute(source:, destination:, overwrite: false) jail = Safety::PathJail.new(config.fs_root) from = jail.resolve(source) to = jail.resolve(destination) return error("source does not exist: #{source}", code: :not_found) unless File.exist?(from) if File.directory?(to) && !File.directory?(from) return error("destination is a directory: #{destination}", code: :is_a_directory) end if File.exist?(to) && !overwrite return error("destination already exists: #{destination} (set overwrite to replace)", code: :exists) end FileUtils.mkdir_p(File.dirname(to)) FileUtils.mv(from, to, force: overwrite) "Moved #{source} -> #{destination}" rescue Safety::PathJail::Jailbreak => e error(e., code: :path_denied) end |