Class: SwarmMemory::Tools::MemoryGrep
- Inherits:
-
SwarmSDK::Tools::Base
- Object
- SwarmSDK::Tools::Base
- SwarmMemory::Tools::MemoryGrep
- 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
-
#execute(pattern:, path: nil, case_insensitive: false, output_mode: "files_with_matches") ⇒ String
Execute the tool.
-
#initialize(storage:) ⇒ MemoryGrep
constructor
Initialize with storage instance.
-
#name ⇒ Object
Override name to return simple "MemoryGrep".
Methods included from TitleLookup
#format_memory_path_with_title, #lookup_title
Constructor Details
#initialize(storage:) ⇒ MemoryGrep
Initialize with 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
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.) rescue RegexpError => e validation_error("Invalid regex pattern: #{e.message}") end |
#name ⇒ Object
Override name to return simple "MemoryGrep"
143 144 145 |
# File 'lib/swarm_memory/tools/memory_grep.rb', line 143 def name "MemoryGrep" end |