22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/legion/cli/chat/tools/edit_file.rb', line 22
def execute(path:, new_text:, old_text: nil, start_line: nil, end_line: nil)
expanded = File.expand_path(path)
return "Error: file not found: #{path}" unless File.exist?(expanded)
require 'legion/cli/chat/checkpoint'
if start_line
line_replace(expanded, new_text, start_line, end_line || start_line)
else
return 'Error: old_text is required when not using line-number mode' if old_text.nil?
string_replace(expanded, old_text, new_text)
end
rescue StandardError => e
Legion::Logging.warn("EditFile#execute failed for #{path}: #{e.message}") if defined?(Legion::Logging)
"Error editing #{path}: #{e.message}"
end
|