Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe("getRequestTools - Tool Filtering", () => {
// Read-only tools should still be available
expect(toolNames).toContain("Read");
expect(toolNames).toContain("List");
expect(toolNames).toContain("Search");
expect(toolNames).toContain("Fetch");
expect(toolNames).toContain("Checklist");

Expand Down Expand Up @@ -130,7 +129,6 @@ describe("getRequestTools - Tool Filtering", () => {
expect(toolNames).toContain("Bash");
expect(toolNames).toContain("Write");
expect(toolNames).toContain("List");
expect(toolNames).toContain("Search");
});

test("plan mode should override allow flags (regression test for GitHub Actions issue)", async () => {
Expand Down Expand Up @@ -158,6 +156,5 @@ describe("getRequestTools - Tool Filtering", () => {
// Read-only tools should be available
expect(toolNames).toContain("Read");
expect(toolNames).toContain("List");
expect(toolNames).toContain("Search");
});
});
25 changes: 11 additions & 14 deletions extensions/cli/src/tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { multiEditTool } from "./multiEdit.js";
import { readFileTool } from "./readFile.js";
import { reportFailureTool } from "./reportFailure.js";
import { runTerminalCommandTool } from "./runTerminalCommand.js";
import { searchCodeTool } from "./searchCode.js";
import { checkIfRipgrepIsInstalled, searchCodeTool } from "./searchCode.js";
import {
type Tool,
type ToolCall,
Expand Down Expand Up @@ -57,32 +57,29 @@ const BASE_BUILTIN_TOOLS: Tool[] = [
readFileTool,
writeFileTool,
listFilesTool,
searchCodeTool,
runTerminalCommandTool,
fetchTool,
writeChecklistTool,
reportFailureTool,
];

const BUILTIN_SEARCH_TOOLS: Tool[] = [searchCodeTool];

// Get all builtin tools including dynamic ones, with capability-based filtering
export async function getAllAvailableTools(
isHeadless: boolean,
): Promise<Tool[]> {
const tools = [...BASE_BUILTIN_TOOLS];

// Filter out ReportFailure tool if no agent ID is present
const isRipgrepInstalled = await checkIfRipgrepIsInstalled();
if (isRipgrepInstalled) {
tools.push(...BUILTIN_SEARCH_TOOLS);
}

// Add ReportFailure tool if no agent ID is present
// (it requires --id to function and will confuse the agent if unavailable)
const agentId = getAgentIdFromArgs();
if (!agentId) {
const reportFailureIndex = tools.findIndex(
(t) => t.name === reportFailureTool.name,
);
if (reportFailureIndex !== -1) {
tools.splice(reportFailureIndex, 1);
logger.debug(
`Filtered out ${reportFailureTool.name} tool - no agent ID present (--id flag not provided)`,
);
}
if (agentId) {
tools.push(reportFailureTool);
}

// If model is capable, exclude editTool in favor of multiEditTool
Expand Down
9 changes: 9 additions & 0 deletions extensions/cli/src/tools/searchCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ const execPromise = util.promisify(child_process.exec);
const DEFAULT_MAX_RESULTS = 100;
const MAX_LINE_LENGTH = 1000;

export async function checkIfRipgrepIsInstalled(): Promise<boolean> {
try {
await execPromise("rg --version");
return true;
} catch {
return false;
}
}

export const searchCodeTool: Tool = {
name: "Search",
displayName: "Search",
Expand Down
Loading