fix: prefer rg in agent prompts

This commit is contained in:
jxxghp
2026-05-20 15:31:02 +08:00
parent 3ec0964a01
commit 5fe5523d13
2 changed files with 10 additions and 0 deletions
+6
View File
@@ -388,6 +388,12 @@ class PromptManager:
info_lines.extend(
f" - {command}: {path}" for command, path in available_commands
)
# `rg` 同时覆盖文件枚举和文本检索,且比通用 shell 查找更适合
# Agent 的代码阅读与定位场景;只有在它不可用或不适合时才退回其他工具。
if any(command == "rg" for command, _ in available_commands):
info_lines.append(
"- When searching files or text, prefer `rg` / `rg --files`. Only fall back to other search tools when `rg` is unavailable or unsuitable."
)
return "\n".join(info_lines)
+4
View File
@@ -61,6 +61,10 @@ class TestAgentPromptStyle(unittest.TestCase):
self.assertIn("- 可用系统命令(可通过 `execute_command` 调用):", prompt)
self.assertIn(" - ssh: /usr/bin/ssh", prompt)
self.assertIn(" - rg: /opt/homebrew/bin/rg", prompt)
self.assertIn(
"When searching files or text, prefer `rg` / `rg --files`",
prompt,
)
self.assertNotIn(" - git:", prompt)
def test_base_prompt_omits_shell_command_section_when_none_available(self):