Class: LLM::Tool::Rg

Inherits:
LLM::Tool show all
Defined in:
lib/llm/tools/rg.rb

Overview

The LLM::Tool::Rg class implements a frontend to the popular 'rg' tool. The tool can recursively search the current working directory for one or more patterns.

Instance Method Summary collapse

Methods inherited from LLM::Tool

NotFound, a2a, a2a?, #a2a?, abstract!, abstract?, clear_registry!, description, find_by_name!, #function, function, inherited, mcp, #mcp?, mcp?, name, #on_cancel, #on_interrupt, params, register, registry, set, subclasses, unregister

Methods included from Param

#defaults, #param, #required

Methods included from Function::Registry

#clear_registry!, #find_by_name, #lock, #register, #registry, #registry_key, #tool_name, #unregister

Instance Method Details

#call(patterns:, path: Dir.getwd, timeout: 5, max_count: 10, max_bytes: Exec.max_bytes) ⇒ Hash

Parameters:

  • patterns (Array<String>)
  • path (String) (defaults to: Dir.getwd)
  • timeout (Integer) (defaults to: 5)
  • max_count (Integer) (defaults to: 10)
  • max_bytes (Integer) (defaults to: Exec.max_bytes)

Returns:

  • (Hash)


30
31
32
33
34
35
36
37
38
# File 'lib/llm/tools/rg.rb', line 30

def call(patterns:, path: Dir.getwd, timeout: 5, max_count: 10, max_bytes: Exec.max_bytes)
  validate!(patterns:, path:, max_count:)
  Exec.new.call(
    command: "rg",
    arguments: ["-m", max_count, *[*patterns].flat_map { ["-e", _1] }, path],
    timeout:,
    max_bytes:
  )
end