Skip to content

Build and run agents you can see, understand and trust.

fix(tool): ignore user ripgrep config in Grep (#3358)

ydflow048055c9f883
diff --git a/src/agentscope/tool/_builtin/_grep.py b/src/agentscope/tool/_builtin/_grep.py
index 3fc70a819..74d8d3374 100644
--- a/src/agentscope/tool/_builtin/_grep.py
+++ b/src/agentscope/tool/_builtin/_grep.py
@@ -285,8 +285,14 @@ class Grep(ToolBase):
``backend.exec_shell`` (which runs the program directly, without
a shell), so the same code path works for local, Docker, and E2B
backends and needs no platform-specific argument quoting.
+
+ ``--no-config`` keeps the search isolated from the caller's own
+ ripgrep defaults (``RIPGREP_CONFIG_PATH`` and the per-user config
+ file). A config that sets e.g. ``--fixed-strings`` would otherwise
+ turn this tool's regular-expression search into a literal one and
+ silently change the results the agent sees.
"""
- command = ["rg", *args, "--", search_path]
+ command = ["rg", "--no-config", *args, "--", search_path]
result = await self._backend.exec_shell(
command,
diff --git a/tests/builtin_grep_test.py b/tests/builtin_grep_test.py
index 3d6c3c944..b9b0eb91c 100644
--- a/tests/builtin_grep_test.py
+++ b/tests/builtin_grep_test.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Grep tool test case."""
import os
+import subprocess
import tempfile
from unittest.async_case import IsolatedAsyncioTestCase
@@ -245,6 +246,47 @@ class GrepToolTest(IsolatedAsyncioTestCase):
],
)
+ async def test_search_ignores_user_ripgrep_config(self) -> None:
+ """A user ripgrep config must not change the tool's regex semantics.
+
+ ``RIPGREP_CONFIG_PATH`` is inherited by the subprocess, so a config
+ that sets ``--fixed-strings`` would turn this tool's pattern into a
+ literal search and silently report no matches.
+ """
+ target = os.path.join(self.temp_dir, "config_probe.txt")
+ with open(target, "w", encoding="utf-8") as f:
+ f.write("error42\n")
+
+ config = os.path.join(self.temp_dir, "ripgreprc")
+ with open(config, "w", encoding="utf-8") as f:
+ f.write("--fixed-strings\n")
+
+ with patch.dict(os.environ, {"RIPGREP_CONFIG_PATH": config}):
+ # The config really does reach a plain ripgrep invocation, so
+ # the assertion below is about the tool's isolation rather than
+ # about a config ripgrep would ignore anyway.
+ raw = subprocess.run(
+ ["rg", "-l", r"error\d+", "--", target],
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+ self.assertEqual(
+ raw.returncode,
+ 1,
+ f"expected the user config to disable the regex: "
+ f"{raw.stdout}{raw.stderr}",
+ )
+
+ chunk = await self.grep_tool(
+ pattern=r"error\d+",
+ path=target,
+ output_mode="content",
+ )
+
+ self.assertEqual(chunk.state, ToolResultState.SUCCESS)
+ self.assertIn("error42", chunk.content[0].text)
+
async def test_case_insensitive(self) -> None:
"""Test case-insensitive search."""
chunk = await self.grep_tool(