feat(tools): use installed ripgrep for native file search (#5948)

* feat(tools): expose installed ripgrep through exec

* refactor(tools): launch ripgrep with native argument vectors

* refactor(tools): reuse the fresh exec parameter schema

* fix(tools): select search backend in loader and display rg arguments

* fix(ui): simplify rg previews and localize search completion

* docs: simplify ripgrep configuration note

* docs: keep ripgrep note on one line
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-28 13:44:51 +08:00
1 parent b8893aba56
commit e0b8efa0be
33 files changed
+514 -204

No files matched your search

+6 -18
View File
@@ -207,33 +207,23 @@ class TestIsTemplateContent:
class TestBundledToolContract:
def test_tool_contract_balances_general_and_coding_workflows(self):
def test_tool_contract_contains_shared_execution_policy(self):
from importlib.resources import files as pkg_files
tpl = pkg_files("nanobot") / "templates" / "agent" / "tool_contract.md"
content = tpl.read_text(encoding="utf-8")
assert "## General Tool Contract" in content
assert "Use the narrowest structured tool" in content
assert "Do not use `exec` as a universal workaround" in content
assert "## File and Coding Workflows" in content
assert "`grep` returns matches with five context lines by default" in content
assert "apply_patch" in content
assert "acceptance criteria into concrete checks" in content
assert "visual evidence reaches the model" in content
assert "clear user request as authorization" in content
assert "Never invent missing records or measurements" in content
assert "## Web and External Information" in content
assert "## Messaging and Media" in content
assert "## Scheduling and Background Work" in content
assert "execution and verification" in content
assert "irreversible action" in content
assert "Wait for tool results" in content
def test_tool_contract_is_injected_without_workspace_file(self, tmp_path):
builder = _builder(tmp_path)
prompt = builder.build_system_prompt()
assert "# Tool Usage Notes" in prompt
assert "## General Tool Contract" in prompt
assert "Do not use `exec` as a universal workaround" in prompt
assert "clear user request as authorization" in prompt
# ---------------------------------------------------------------------------
@@ -305,7 +295,6 @@ class TestBuildSystemPrompt:
def test_default_identity_uses_relative_agent_paths(self, tmp_path):
result = ContextBuilder(tmp_path)._get_identity()
assert str(tmp_path.resolve()) not in result
assert "Agent profile: SOUL.md and USER.md" in result
assert "History log: memory/history.jsonl" in result
assert "Custom skills: skills/{skill-name}/SKILL.md" in result
@@ -318,10 +307,9 @@ class TestBuildSystemPrompt:
result = ContextBuilder(agent_home)._get_identity(workspace=project)
assert str(project.resolve()) not in result
assert f"agent workspace is at: {agent_home.resolve()}" in result
assert f"{agent_home.resolve()}/SOUL.md" in result
assert f"{project.resolve()}/SOUL.md" not in result
assert f"Custom skills: {agent_home.resolve()}/skills/" in result
def test_includes_bootstrap_files(self, tmp_path):
(tmp_path / "AGENTS.md").write_text("Be helpful and concise.", encoding="utf-8")
+6 -21
View File
@@ -118,9 +118,7 @@ def test_execution_rules_in_system_prompt(tmp_path) -> None:
prompt = builder.build_system_prompt()
assert "clear user request" in prompt
assert "multi-step tasks" in prompt
assert "read-only discovery before writes" in prompt
assert "verify the result" in prompt
assert "execution and verification" in prompt
def test_execution_rules_reach_existing_workspace_soul(tmp_path) -> None:
@@ -152,8 +150,8 @@ def test_default_soul_template_keeps_execution_policy_in_tool_contract() -> None
assert "## Execution Rules" not in soul
assert "clear user request" not in soul
assert "clear user request" in contract
assert "multi-step tasks" in contract
assert "irreversible action needs confirmation" in contract
assert "execution and verification" in contract
assert "Ask for confirmation when an irreversible action requires it" in contract
def test_channel_format_hint_telegram(tmp_path) -> None:
@@ -202,18 +200,6 @@ def test_build_messages_passes_channel_to_system_prompt(tmp_path) -> None:
assert "messaging app" in system
def test_system_prompt_keeps_message_tool_out_of_current_chat_replies(tmp_path) -> None:
workspace = _make_workspace(tmp_path)
builder = ContextBuilder(workspace)
prompt = builder.build_system_prompt(channel="slack")
assert "Do not use the 'message' tool for normal replies in the current chat" in prompt
assert "When 'generate_image' creates images" in prompt
assert "call 'message' with the artifact paths in the 'media' parameter" in prompt
assert "Wait for the tool results, then answer once" in prompt
def test_memory_skill_is_lazy_loaded_from_skills_index(tmp_path) -> None:
"""Memory search guidance should be discoverable without loading its full body."""
workspace = _make_workspace(tmp_path)
@@ -239,11 +225,10 @@ def test_fresh_workspace_omits_default_prompt_scaffolding(tmp_path) -> None:
assert "## USER.md" not in prompt
assert "8281248569" not in prompt
assert "(your name)" not in prompt
assert prompt.count("Do not use the 'message' tool for normal replies") == 1
def test_template_memory_md_is_skipped(tmp_path) -> None:
"""MEMORY.md matching the bundled template should not inject the Memory section."""
"""Template content is omitted while memory locations remain available."""
workspace = _make_workspace(tmp_path)
from nanobot.utils.helpers import sync_workspace_templates
sync_workspace_templates(workspace, silent=True)
@@ -251,8 +236,8 @@ def test_template_memory_md_is_skipped(tmp_path) -> None:
builder = ContextBuilder(workspace)
prompt = builder.build_system_prompt()
# This block is produced only when populated long-term memory is injected.
assert "# Memory\n\n## Long-term Memory" not in prompt
assert "## Long-term Memory" not in prompt
assert "History log: memory/history.jsonl" in prompt
assert "This file is automatically updated by nanobot" not in prompt
+1 -2
View File
@@ -350,8 +350,7 @@ def test_bundled_skills_use_agent_owned_paths(tmp_path: Path) -> None:
update_setup = loader.load_skill("update-setup")
assert memory is not None
assert "<history-log-path>" in memory
assert 'path="memory/history.jsonl"' not in memory
assert "`History log` path from the system prompt" in memory
assert update_setup is not None
assert "<agent-workspace>/skills/update/SKILL.md" in update_setup
assert "Never substitute a project-relative" in update_setup
+11
View File
@@ -16,6 +16,17 @@ def _hint(calls, max_length=40):
class TestToolHintKnownTools:
"""Test registered tool types produce correct formatted output."""
def test_rg_shows_argument_boundaries(self):
assert _hint([_tc("rg", {"args": ["-n", "hello world", "src"]})]) == 'rg -n "hello world" src'
def test_rg_shows_regex_and_empty_argument(self):
assert _hint([_tc("rg", {"args": [r"resolve\(", ""]})]) == 'rg resolve\\( ""'
def test_rg_truncates_long_arguments(self):
result = _hint([_tc("rg", {"args": ["x" * 100]})])
assert result.endswith("…")
assert len(result) == 43
def test_read_file_short_path(self):
result = _hint([_tc("read_file", {"path": "foo.txt"})])
assert result == 'read foo.txt'