fix(cli): check ripgrep search tool before using
This commit is contained in:
parent
7bd8381d5d
commit
7944a92c15
2 changed files with 17 additions and 2 deletions
|
|
@ -26,7 +26,7 @@ import { listFilesTool } from "./listFiles.js";
|
|||
import { multiEditTool } from "./multiEdit.js";
|
||||
import { readFileTool } from "./readFile.js";
|
||||
import { runTerminalCommandTool } from "./runTerminalCommand.js";
|
||||
import { searchCodeTool } from "./searchCode.js";
|
||||
import { checkIfRipgrepIsInstalled, searchCodeTool } from "./searchCode.js";
|
||||
import { statusTool } from "./status.js";
|
||||
import {
|
||||
type Tool,
|
||||
|
|
@ -45,18 +45,24 @@ const BASE_BUILTIN_TOOLS: Tool[] = [
|
|||
readFileTool,
|
||||
writeFileTool,
|
||||
listFilesTool,
|
||||
searchCodeTool,
|
||||
runTerminalCommandTool,
|
||||
fetchTool,
|
||||
writeChecklistTool,
|
||||
];
|
||||
|
||||
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];
|
||||
|
||||
const isRipgrepInstalled = await checkIfRipgrepIsInstalled();
|
||||
if (isRipgrepInstalled) {
|
||||
tools.push(...BUILTIN_SEARCH_TOOLS);
|
||||
}
|
||||
|
||||
// If model is capable, exclude editTool in favor of multiEditTool
|
||||
const modelState = await serviceContainer.get<ModelServiceState>(
|
||||
SERVICE_NAMES.MODEL,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,15 @@ const execPromise = util.promisify(child_process.exec);
|
|||
// Default maximum number of results to display
|
||||
const DEFAULT_MAX_RESULTS = 100;
|
||||
|
||||
export async function checkIfRipgrepIsInstalled(): Promise<boolean> {
|
||||
try {
|
||||
await execPromise("rg --version");
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export const searchCodeTool: Tool = {
|
||||
name: "Search",
|
||||
displayName: "Search",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue