Class: Legion::CLI::Chat::Tools::WriteFile

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/legion/cli/chat/tools/write_file.rb

Instance Method Summary collapse

Instance Method Details

#execute(path:, content:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/cli/chat/tools/write_file.rb', line 16

def execute(path:, content:)
  expanded = File.expand_path(path)
  require 'legion/cli/chat/checkpoint'
  Checkpoint.save(expanded)
  FileUtils.mkdir_p(File.dirname(expanded))
  File.write(expanded, content, encoding: 'utf-8')
  "Wrote #{content.lines.count} lines to #{expanded}"
rescue StandardError => e
  Legion::Logging.warn("WriteFile#execute failed for #{path}: #{e.message}") if defined?(Legion::Logging)
  "Error writing #{path}: #{e.message}"
end