Class: RubyCoded::Tools::EditFileTool
- Defined in:
- lib/ruby_coded/tools/edit_file_tool.rb
Overview
Replace a specific text occurrence in an existing file (search and replace)
Constant Summary
Constants inherited from BaseTool
BaseTool::CONFIRM_RISK, BaseTool::DANGEROUS_RISK, BaseTool::SAFE_RISK
Instance Method Summary collapse
Methods inherited from BaseTool
Constructor Details
This class inherits a constructor from RubyCoded::Tools::BaseTool
Instance Method Details
#execute(path:, old_text:, new_text:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_coded/tools/edit_file_tool.rb', line 18 def execute(path:, old_text:, new_text:) full_path = validate_path!(path) return full_path if full_path.is_a?(Hash) return { error: "File not found: #{path}" } unless File.exist?(full_path) return { error: "Not a file: #{path}" } unless File.file?(full_path) apply_edit(path, full_path, old_text, new_text) rescue SystemCallError => e { error: "Failed to edit #{path}: #{e.}" } end |