Class: Yorishiro::Tools::Grep

Inherits:
Yorishiro::Tool show all
Defined in:
lib/yorishiro/tools/grep.rb

Constant Summary collapse

MAX_RESULTS =
100
EXCLUDED_DIRS =
%w[.git node_modules vendor tmp].freeze
BINARY_CHECK_BYTES =
8_000
MAX_LINE_LENGTH =
250

Instance Method Summary collapse

Methods inherited from Yorishiro::Tool

#configure, #definition, #permission_check, #preview

Instance Method Details

#descriptionObject



19
20
21
22
# File 'lib/yorishiro/tools/grep.rb', line 19

def description
  "Search file contents recursively with a Ruby regular expression. " \
    "Returns matches as 'file:line:content'. Hidden files and directories (e.g. .git) are skipped."
end

#execute(**params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/yorishiro/tools/grep.rb', line 36

def execute(**params)
  pattern = params[:pattern] || params["pattern"]
  path = params[:path] || params["path"] || "."
  glob = params[:glob] || params["glob"]

  regexp = build_regexp(pattern)
  raise "Directory not found: #{path}" unless Dir.exist?(path)

  matches, truncated = search(regexp, path, glob)
  format_results(matches, truncated, pattern)
end

#nameObject



15
16
17
# File 'lib/yorishiro/tools/grep.rb', line 15

def name
  "grep"
end

#parametersObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yorishiro/tools/grep.rb', line 24

def parameters
  {
    type: "object",
    properties: {
      pattern: { type: "string", description: "Ruby regular expression to search for" },
      path: { type: "string", description: "Directory to search in (default: current directory)" },
      glob: { type: "string", description: "Glob pattern to filter files (e.g., '*.rb')" }
    },
    required: ["pattern"]
  }
end

#read_only?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/yorishiro/tools/grep.rb', line 11

def read_only?
  true
end