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

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

Class Method Summary collapse

Methods inherited from Tools::Base

deferred, deferred?, description, error_response, extension, handle_exception, input_schema, log, mcp_category, mcp_tier, runner, sticky, tags, text_response, tool_name, trigger_words

Class Method Details

.call(path:, content:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/legion/cli/chat/tools/write_file.rb', line 22

def self.call(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