Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/fastcontext/agent/tool/grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GrepTool(Tool):
"output_mode": {
"type": "string",
"enum": ["content", "files_with_matches", "count"],
"description": 'Output mode: "content" shows matching lines (supports -A/-B/-C context, -n line numbers, head_limit), "files_with_matches" shows file paths (supports head_limit), "count" shows match counts (supports head_limit). Defaults to "files_with_matches".',
"description": 'Output mode: "content" shows matching lines (supports -A/-B/-C context, -n line numbers, head_limit), "files_with_matches" shows file paths (supports head_limit), "count" shows match counts (supports head_limit). Defaults to "content".',
},
"-B": {
"type": "number",
Expand Down Expand Up @@ -72,7 +72,7 @@ async def call(self, parameters: str, **kwargs) -> str:
pattern = params.get("pattern")
path = params.get("path", cwd)
glob = params.get("glob")
output_mode = params.get("output_mode")
output_mode = params.get("output_mode", "content")
before_context = params.get("-B")
after_context = params.get("-A")
context = params.get("-C", 3)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_grep_default_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import asyncio
import json
import re
import tempfile
from pathlib import Path

from fastcontext.agent.tool.grep import GrepTool


def test_grep_defaults_to_content():
"""With output_mode omitted, Grep must behave as 'content' (matching lines
with line numbers), not as files_with_matches and not as a flag-less rg
call that drops -n."""
grep = GrepTool()
with tempfile.TemporaryDirectory() as cwd:
(Path(cwd) / "haystack.txt").write_text("alpha\nMATCH here\nbeta\n", encoding="utf-8")

out = asyncio.run(grep.call(json.dumps({"pattern": "MATCH"}), cwd=cwd))
lines = out.splitlines()

# Content mode with -n emits "<lineno>:<text>" rows for matches.
assert any(re.match(r"\d+:.*MATCH", ln) for ln in lines), f"expected line-numbered match, got: {out!r}"
# files_with_matches would emit only the bare path with no match text.
assert "MATCH here" in out


def test_grep_schema_documents_content_default():
schema = GrepTool().schema()
desc = schema["function"]["parameters"]["properties"]["output_mode"]["description"]
assert 'Defaults to "content"' in desc
assert "files_with_matches" not in desc.split("Defaults to")[1]