Class: SwarmMemory::Tools::MemoryGrep

Inherits:
SwarmSDK::Tools::Base
  • Object
show all
Includes:
TitleLookup
Defined in:
lib/swarm_memory/tools/memory_grep.rb

Overview

Tool for searching memory content by pattern

Searches content stored in memory entries using regex patterns. Each agent has its own isolated memory storage.

Constant Summary collapse

MAX_RESULTS =

Limit results to prevent overwhelming output

50

Instance Method Summary collapse

Methods included from TitleLookup

#format_memory_path_with_title, #lookup_title

Constructor Details

#initialize(storage:) ⇒ MemoryGrep

Initialize with storage instance

Parameters:

  • Storage instance



137
138
139
140
# File 'lib/swarm_memory/tools/memory_grep.rb', line 137

def initialize(storage:)
  super()
  @storage = storage
end

Instance Method Details

#execute(pattern:, path: nil, case_insensitive: false, output_mode: "files_with_matches") ⇒ String

Execute the tool

Parameters:

  • Regex pattern to search for

  • (defaults to: nil)

    Optional path filter

  • (defaults to: false)

    Whether to perform case-insensitive search

  • (defaults to: "files_with_matches")

    Output mode

Returns:

  • Formatted search results



154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/swarm_memory/tools/memory_grep.rb', line 154

def execute(pattern:, path: nil, case_insensitive: false, output_mode: "files_with_matches")
  results = @storage.grep(
    pattern: pattern,
    path: path,
    case_insensitive: case_insensitive,
    output_mode: output_mode,
  )

  format_results(results, pattern, output_mode, path)
rescue ArgumentError => e
  validation_error(e.message)
rescue RegexpError => e
  validation_error("Invalid regex pattern: #{e.message}")
end

#nameObject

Override name to return simple "MemoryGrep"



143
144
145
# File 'lib/swarm_memory/tools/memory_grep.rb', line 143

def name
  "MemoryGrep"
end