Class: Zephira::Tools::DeleteFile

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/zephira/tools/delete_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/delete_file.rb', line 13

def description
  "Delete a file or directory and its contents."
end

.nameObject



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

def name
  "delete_file"
end

.parametersObject



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

def parameters
  {
    type: "object",
    properties: {
      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')."},
      file_path: {type: "string", description: "Path to the file or directory to delete"}
    },
    required: ["file_path", "intent"]
  }
end

Instance Method Details

#runObject



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

def run
  path = validate(arg(:file_path), arg_path: "file_path", type: String)

  agent.status.verbose(" • Deleting file or directory: '#{path}'")

  expanded = ::File.expand_path(path)
  begin
    ::FileUtils.rm_rf(expanded)
  rescue Errno::EACCES
    return error_result(message: "Permission denied: #{path}")
  end

  agent.status.verbose(" • File or dir deleted: '#{path}'")
  agent.logger.info("File or dir deleted: '#{path}'")
  success_result("File or dir deleted: '#{path}'")
end