Class: WritersRoom::WriteFileTool

Inherits:
ProjectTool
  • Object
show all
Defined in:
lib/writers_room/tools/write_file_tool.rb

Overview

LLM tool that writes or updates files within the project directory.

Instance Attribute Summary

Attributes inherited from ProjectTool

#project_path

Instance Method Summary collapse

Methods inherited from ProjectTool

#initialize

Constructor Details

This class inherits a constructor from WritersRoom::ProjectTool

Instance Method Details

#execute(path:, content:) ⇒ Object



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

def execute(path:, content:)
  full_path = resolve_path(path)

  FileUtils.mkdir_p(File.dirname(full_path))
  File.write(full_path, content)

  "Wrote #{content.length} bytes to #{path}"
rescue RuntimeError => e
  e.message
rescue StandardError => e
  "Error writing file: #{e.message}"
end