Class: RubyLLM::Toolbox::Tools::CreateDirectory

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_llm/toolbox/tools/create_directory.rb

Overview

EXEC. Creates a directory (and any missing parents) within fs_root.

Instance Attribute Summary

Attributes inherited from Base

#config

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(path:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_llm/toolbox/tools/create_directory.rb', line 21

def execute(path:)
  jail = Safety::PathJail.new(config.fs_root)
  real = jail.resolve(path)
  return error("a file already exists at #{path}", code: :is_a_file) if File.file?(real)

  existed = File.directory?(real)
  FileUtils.mkdir_p(real)
  existed ? "Directory already exists: #{path}" : "Created directory #{path}"
rescue Safety::PathJail::Jailbreak => e
  error(e.message, code: :path_denied)
end