Skip to content

The agent that grows with you

feat(search): hidden/gitignored probe on zero-match results

Tekniume7aa06c3a659
diff --git a/tests/tools/test_search_zero_match_and_multipath.py b/tests/tools/test_search_zero_match_and_multipath.py
index a6b49151ebf..86b13e82420 100644
--- a/tests/tools/test_search_zero_match_and_multipath.py
+++ b/tests/tools/test_search_zero_match_and_multipath.py
@@ -39,6 +39,14 @@ class TestZeroMatchProbe:
assert r["total_count"] == 0
assert "warning" not in r
+ def test_hidden_only_match_gets_hint(self, proj):
+ d = proj / "proj"
+ (d / ".secretdir").mkdir()
+ (d / ".secretdir" / "conf.cfg").write_text("HIDDEN_ONLY_TOKEN = true\n")
+ r = json.loads(search_tool("HIDDEN_ONLY_TOKEN", path=str(d), task_id="t-zm"))
+ assert r["total_count"] == 0
+ assert "hidden or gitignored" in r.get("warning", "")
+
def test_matching_search_unaffected(self, proj):
r = json.loads(search_tool("TOKEN_ALPHA", path=str(proj / "proj"), task_id="t-zm"))
assert r["total_count"] >= 2
diff --git a/tools/file_operations.py b/tools/file_operations.py
index 2d04b369a84..c48abd0c33f 100644
--- a/tools/file_operations.py
+++ b/tools/file_operations.py
@@ -2262,6 +2262,29 @@ class ShellFileOperations(FileOperations):
f"0 exact matches, but {ci_total} case-insensitive match(es) "
f"in {ci_files} file(s) — the pattern's casing may be wrong."
)
+ # Hidden/ignored probe: rg skips dotdirs and .gitignore'd files by
+ # default. When the pattern exists only there, say so instead of
+ # returning a bare zero (bench case: match in .hidden/ silently
+ # missing from results).
+ hidden = self._exec(
+ f"rg --hidden --no-ignore --count-matches{glob_expr} "
+ f"{self._escape_shell_arg(pattern)} {self._escape_shell_arg(path)} "
+ f"2>/dev/null | head -50",
+ timeout=30,
+ )
+ h_total = 0
+ h_files = 0
+ for line in (hidden.stdout or "").strip().splitlines():
+ _p, _sep, n = line.rpartition(":")
+ if n.isdigit():
+ h_total += int(n)
+ h_files += 1
+ if h_total > 0:
+ return (
+ f"0 matches in visible files, but {h_total} match(es) in "
+ f"{h_files} hidden or gitignored file(s) — these are excluded "
+ "by default. Search the hidden path explicitly to include them."
+ )
if re.search(r"[.\[\](){}?*+^$\\|]", pattern):
fixed = self._exec(
f"rg -F --count-matches{glob_expr} "