Class: AgentC::Tools::FileMetadata

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/agent_c/tools/file_metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace_dir: nil) ⇒ FileMetadata

Returns a new instance of FileMetadata.

Raises:

  • (ArgumentError)


16
17
18
19
# File 'lib/agent_c/tools/file_metadata.rb', line 16

def initialize(workspace_dir: nil, **)
  raise ArgumentError, "workspace_dir is required" unless workspace_dir
  @workspace_dir = workspace_dir
end

Instance Attribute Details

#workspace_dirObject (readonly)

Returns the value of attribute workspace_dir.



15
16
17
# File 'lib/agent_c/tools/file_metadata.rb', line 15

def workspace_dir
  @workspace_dir
end

Instance Method Details

#execute(path:, line_range_start: 0, line_range_end: nil, **params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/agent_c/tools/file_metadata.rb', line 21

def execute(path:, line_range_start: 0, line_range_end: nil, **params)
  if params.any?
    return "The following params were passed but are not allowed: #{params.keys.join(",")}"
  end

  unless Paths.allowed?(workspace_dir, path)
    return "Path: #{path} not acceptable. Must be a child of directory: #{workspace_dir}."
  end

  workspace_path = Paths.relative_to_dir(workspace_dir, path)

  unless File.exist?(workspace_path)
    return "File not found"
  end

  {
    mtime: File.mtime(workspace_path),
    lines: File.foreach(workspace_path).count,
  }
end