Class: Zephira::Tools::UpdateFile

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/zephira/tools/update_file.rb

Instance Attribute Summary

Attributes inherited from BaseTool

#agent, #args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseTool

announces_intent?, #arg, #error_result, #initialize, read_only?, run, #success_result, #validate

Constructor Details

This class inherits a constructor from Zephira::Tools::BaseTool

Class Method Details

.descriptionObject



13
14
15
# File 'lib/zephira/tools/update_file.rb', line 13

def description
  "Update or create a file by providing the full replacement content."
end

.nameObject



9
10
11
# File 'lib/zephira/tools/update_file.rb', line 9

def name
  "update_file"
end

.parametersObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zephira/tools/update_file.rb', line 17

def parameters
  {
    type: "object",
    properties: {
      content: {type: "string", description: "Full replacement file text"},
      file_path: {type: "string", description: "Path to the file to be updated or created"},
      intent: {type: "string", description: "Brief summary of intent of the operation, meant to be used for context compaction and presentation to the user. Use active voice (e.g., 'Reading X to do Y')."}
    },
    required: ["content", "file_path", "intent"]
  }
end

Instance Method Details

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zephira/tools/update_file.rb', line 30

def run
  content = validate(arg(:content), arg_path: "content", type: String, allow_empty: true)
  file_path = validate(arg(:file_path), arg_path: "file_path", type: String)

  agent.status.verbose(" • Updating file: '#{file_path}'")

  ::FileUtils.mkdir_p(::File.dirname(file_path))
  ::File.write(file_path, content)

  msg = "Updated file: '#{file_path}'"
  agent.status.verbose("#{msg}")
  agent.logger.info(msg)
  success_result(msg)
end