Skip to content

Commit 521480e

Browse files
authored
Merge pull request #8567 from uinstinct/cli-ripgrep-installed
fix(cli): check ripgrep search tool before using
2 parents b11c958 + 10407bb commit 521480e

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

extensions/cli/src/stream/streamChatResponse.getAllTools.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ describe("getRequestTools - Tool Filtering", () => {
4747
// Read-only tools should still be available
4848
expect(toolNames).toContain("Read");
4949
expect(toolNames).toContain("List");
50-
expect(toolNames).toContain("Search");
5150
expect(toolNames).toContain("Fetch");
5251
expect(toolNames).toContain("Checklist");
5352

@@ -130,7 +129,6 @@ describe("getRequestTools - Tool Filtering", () => {
130129
expect(toolNames).toContain("Bash");
131130
expect(toolNames).toContain("Write");
132131
expect(toolNames).toContain("List");
133-
expect(toolNames).toContain("Search");
134132
});
135133

136134
test("plan mode should override allow flags (regression test for GitHub Actions issue)", async () => {
@@ -158,6 +156,5 @@ describe("getRequestTools - Tool Filtering", () => {
158156
// Read-only tools should be available
159157
expect(toolNames).toContain("Read");
160158
expect(toolNames).toContain("List");
161-
expect(toolNames).toContain("Search");
162159
});
163160
});

extensions/cli/src/tools/index.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { multiEditTool } from "./multiEdit.js";
2727
import { readFileTool } from "./readFile.js";
2828
import { reportFailureTool } from "./reportFailure.js";
2929
import { runTerminalCommandTool } from "./runTerminalCommand.js";
30-
import { searchCodeTool } from "./searchCode.js";
30+
import { checkIfRipgrepIsInstalled, searchCodeTool } from "./searchCode.js";
3131
import {
3232
type Tool,
3333
type ToolCall,
@@ -57,32 +57,29 @@ const BASE_BUILTIN_TOOLS: Tool[] = [
5757
readFileTool,
5858
writeFileTool,
5959
listFilesTool,
60-
searchCodeTool,
6160
runTerminalCommandTool,
6261
fetchTool,
6362
writeChecklistTool,
64-
reportFailureTool,
6563
];
6664

65+
const BUILTIN_SEARCH_TOOLS: Tool[] = [searchCodeTool];
66+
6767
// Get all builtin tools including dynamic ones, with capability-based filtering
6868
export async function getAllAvailableTools(
6969
isHeadless: boolean,
7070
): Promise<Tool[]> {
7171
const tools = [...BASE_BUILTIN_TOOLS];
7272

73-
// Filter out ReportFailure tool if no agent ID is present
73+
const isRipgrepInstalled = await checkIfRipgrepIsInstalled();
74+
if (isRipgrepInstalled) {
75+
tools.push(...BUILTIN_SEARCH_TOOLS);
76+
}
77+
78+
// Add ReportFailure tool if no agent ID is present
7479
// (it requires --id to function and will confuse the agent if unavailable)
7580
const agentId = getAgentIdFromArgs();
76-
if (!agentId) {
77-
const reportFailureIndex = tools.findIndex(
78-
(t) => t.name === reportFailureTool.name,
79-
);
80-
if (reportFailureIndex !== -1) {
81-
tools.splice(reportFailureIndex, 1);
82-
logger.debug(
83-
`Filtered out ${reportFailureTool.name} tool - no agent ID present (--id flag not provided)`,
84-
);
85-
}
81+
if (agentId) {
82+
tools.push(reportFailureTool);
8683
}
8784

8885
// If model is capable, exclude editTool in favor of multiEditTool

extensions/cli/src/tools/searchCode.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ const execPromise = util.promisify(child_process.exec);
1212
const DEFAULT_MAX_RESULTS = 100;
1313
const MAX_LINE_LENGTH = 1000;
1414

15+
export async function checkIfRipgrepIsInstalled(): Promise<boolean> {
16+
try {
17+
await execPromise("rg --version");
18+
return true;
19+
} catch {
20+
return false;
21+
}
22+
}
23+
1524
export const searchCodeTool: Tool = {
1625
name: "Search",
1726
displayName: "Search",

0 commit comments

Comments
 (0)