Module: OllamaAgent::Runtime::KernelToolSeed::SearchTextBackend
- Defined in:
- lib/ollama_agent/runtime/kernel_tool_seed.rb
Overview
ripgrep/grep text search (same backend selection as the Agent search tool).
Class Method Summary collapse
- .no_backends_message ⇒ Object
- .search(ripgrep_bin:, grep_bin:, pattern:, target:) ⇒ Object
- .search_timeout_seconds ⇒ Object
- .timeout_message(seconds) ⇒ Object
- .with_search_timeout ⇒ Object
Class Method Details
.no_backends_message ⇒ Object
196 197 198 199 200 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 196 def <<~MSG.strip Error: ollama_agent: no text search backend available. Install ripgrep (`rg`) or GNU grep on PATH. MSG end |
.search(ripgrep_bin:, grep_bin:, pattern:, target:) ⇒ Object
202 203 204 205 206 207 208 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 202 def search(ripgrep_bin:, grep_bin:, pattern:, target:) if ripgrep_bin with_search_timeout { Open3.capture2(ripgrep_bin, "-n", "--", pattern, target) } else with_search_timeout { Open3.capture2(grep_bin, "-rn", "--", pattern, target) } end end |
.search_timeout_seconds ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 220 def search_timeout_seconds EnvConfig.fetch_int( "OLLAMA_AGENT_SEARCH_TIMEOUT_SEC", 120, strict: EnvConfig.strict_env? ) end |
.timeout_message(seconds) ⇒ Object
228 229 230 231 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 228 def (seconds) tail = "(raise OLLAMA_AGENT_SEARCH_TIMEOUT_SEC for longer runs)." "Error: ollama_agent: search timed out after #{seconds}s #{tail}" end |
.with_search_timeout ⇒ Object
210 211 212 213 214 215 216 217 218 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 210 def with_search_timeout(&) sec = search_timeout_seconds stdout, status = Timeout.timeout(sec, &) return stdout.to_s if status.success? "Error: ollama_agent: search command exited with status #{status.exitstatus}" rescue Timeout::Error (sec) end |