Class: Genie::WriteFile
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- Genie::WriteFile
- Includes:
- SandboxedFileTool
- Defined in:
- lib/tools/write_file.rb
Instance Method Summary collapse
Methods included from SandboxedFileTool
#enforce_sandbox!, #initialize, #within_sandbox?
Instance Method Details
#execute(filepath:, content:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tools/write_file.rb', line 11 def execute(filepath:, content:) filepath = File.(filepath) Genie.output "Writing file: #{filepath}", color: :blue enforce_sandbox!(filepath) indented_content = content.each_line.map { |line| " #{line}" }.join Genie.output "#{indented_content}", color: :green # Ensure the directory exists FileUtils.mkdir_p(File.dirname(filepath)) File.open(filepath, "w") do |file| file.write(content) end { success: true, } rescue => e Genie.output "Error: #{e.message}", color: :red { error: e. } end |