Class: Brute::Tools::FSWrite

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/brute/tools/fs_write.rb

Instance Method Summary collapse

Instance Method Details

#execute(file_path:, content:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/brute/tools/fs_write.rb', line 19

def execute(file_path:, content:)
  path = File.expand_path(file_path)
  Brute::Queue::FileMutationQueue.serialize(path) do
    old_content = File.exist?(path) ? File.read(path) : ''
    Brute::Store::SnapshotStore.save(path)
    FileUtils.mkdir_p(File.dirname(path))
    File.write(path, content)
    diff = Brute::Diff.unified(old_content, content)
    { success: true, file_path: path, bytes: content.bytesize, diff: diff }
  end
end

#nameObject



17
# File 'lib/brute/tools/fs_write.rb', line 17

def name; "write"; end