Class: Brute::Tools::FSWrite

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

Instance Method Summary collapse

Instance Method Details

#call(file_path:, content:) ⇒ Object



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

def call(file_path:, content:)
  path = File.expand_path(file_path)
  Brute::FileMutationQueue.serialize(path) do
    old_content = File.exist?(path) ? File.read(path) : ''
    Brute::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