The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(search): local file search runs Hermes's pinned ripgrep, not the first rg on PATH
ethernet9b4710b829ff
diff --git a/tests/tools/test_search_native_rg.py b/tests/tools/test_search_native_rg.pyindex 8dcde0f8222..da7c229e123 100644--- a/tests/tools/test_search_native_rg.py+++ b/tests/tools/test_search_native_rg.py@@ -126,3 +126,17 @@ def test_limit_hit_keeps_drained_matches_when_group_kill_is_refused(tree, ops_famonkeypatch.setattr(os, "killpg", lambda pgid, sig: (_ for _ in ()).throw(PermissionError(1, "Operation not permitted")))result = ops.search(pattern="needle", path=str(tree), limit=2)assert not result.error and len(result.matches) == 2, result.to_dict()+++def test_local_search_runs_the_pinned_ripgrep_not_the_first_on_path(_local_env, tmp_path, monkeypatch):+ """The terminal PATH puts the user's tools first; Hermes's own search still runs PM's rg."""+ import pm+ from pm.install import InstalledPackage++ pinned = tmp_path / "store" / "ripgrep" / "rg"+ pinned.parent.mkdir(parents=True)+ pinned.write_text("#!/bin/sh\n", encoding="utf-8")+ monkeypatch.setattr(pm, "installed_package",+ lambda name: InstalledPackage(pinned.parent, "15", pinned) if name == "ripgrep" else None)+ ops = ShellFileOperations(_local_env, cwd=str(tmp_path))+ assert ops._resolve_command("rg") == str(pinned).replace("\\", "/")diff --git a/tools/file_operations_search.py b/tools/file_operations_search.pyindex 58839219b50..e3186b3f502 100644--- a/tools/file_operations_search.py+++ b/tools/file_operations_search.py@@ -118,6 +118,18 @@ def _search_stdout_and_limit(result: ExecuteResult) -> tuple[str, Optional[str]]return result.stdout, None+def _bundled_rg() -> Optional[str]:+ """Hermes's pinned ripgrep, forward-slashed for the shell transports, or None."""+ import pm++ try:+ installed = pm.installed_package("ripgrep")+ except (OSError, RuntimeError, ValueError):+ return None+ binary = installed.binary if installed is not None else None+ return str(binary).replace("\\", "/") if binary is not None and binary.is_file() else None++# A real rg/grep output line is a whitespace-free path token followed by ``:``# (match/count), ``-`` (context), or nothing (files_only); tool diagnostics# ("rg: ...", indented carets) never match.@@ -281,6 +293,14 @@ class SearchMixin:cached = self._rg_resolution_cache.get(cmd)if cached:return cached+ from tools.environments.local import LocalEnvironment, _IS_WINDOWS++ # A local search is Hermes's own work, so it runs the pinned ripgrep, never the+ # first rg on the terminal PATH, where the user's tools come first.+ bundled = _bundled_rg() if isinstance(self.env, LocalEnvironment) else None+ if bundled:+ self._rg_resolution_cache[cmd] = bundled+ return bundledresult = self._exec("command -v rg 2>/dev/null")if result.exit_code == 0 and result.stdout.strip():resolved = result.stdout.strip().splitlines()[0]@@ -288,7 +308,6 @@ class SearchMixin:resolved = "rg"self._rg_resolution_cache[cmd] = resolvedreturn resolved- from tools.environments.local import LocalEnvironment, _IS_WINDOWSif _IS_WINDOWS and isinstance(self.env, LocalEnvironment):user_profile = os.environ.get("USERPROFILE") or str(Path.home())