Files
gemini-cli/packages/cli/src/tools/grep.tool.ts
T

80 lines
2.4 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
// Import core logic and types from the server package
import { GrepLogic, GrepToolParams, ToolResult } from '@gemini-code/server';
2025-04-15 21:41:08 -07:00
// Import CLI-specific base class and types
import { BaseTool } from './tools.js';
import { ToolCallConfirmationDetails } from '../ui/types.js';
2025-04-15 21:41:08 -07:00
// --- Interfaces (Params defined in server package) ---
2025-04-15 21:41:08 -07:00
// --- GrepTool CLI Wrapper Class ---
2025-04-15 21:41:08 -07:00
/**
* CLI wrapper for the Grep tool
2025-04-15 21:41:08 -07:00
*/
export class GrepTool extends BaseTool<GrepToolParams, ToolResult> {
static readonly Name: string = GrepLogic.Name; // Use name from logic
// Core logic instance from the server package
private coreLogic: GrepLogic;
2025-04-15 21:41:08 -07:00
/**
* Creates a new instance of the GrepTool CLI wrapper
* @param rootDirectory Root directory to ground this tool in.
2025-04-15 21:41:08 -07:00
*/
constructor(rootDirectory: string) {
// Instantiate the core logic from the server package
const coreLogicInstance = new GrepLogic(rootDirectory);
// Initialize the CLI BaseTool
2025-04-15 21:41:08 -07:00
super(
GrepTool.Name,
'SearchText', // Define display name here
'Searches for a regular expression pattern within the content of files in a specified directory (or current working directory). Can filter files by a glob pattern. Returns the lines containing matches, along with their file paths and line numbers.', // Define description here
(coreLogicInstance.schema.parameters as Record<string, unknown>) ?? {},
2025-04-15 21:41:08 -07:00
);
this.coreLogic = coreLogicInstance;
2025-04-15 21:41:08 -07:00
}
/**
* Delegates validation to the core logic
2025-04-15 21:41:08 -07:00
*/
validateToolParams(params: GrepToolParams): string | null {
return this.coreLogic.validateToolParams(params);
2025-04-15 21:41:08 -07:00
}
/**
* Delegates getting description to the core logic
2025-04-15 21:41:08 -07:00
*/
getDescription(params: GrepToolParams): string {
return this.coreLogic.getDescription(params);
2025-04-15 21:41:08 -07:00
}
/**
* Define confirmation behavior (Grep likely doesn't need confirmation)
2025-04-17 18:06:21 -04:00
*/
shouldConfirmExecute(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
params: GrepToolParams,
): Promise<ToolCallConfirmationDetails | false> {
return Promise.resolve(false);
2025-04-15 21:41:08 -07:00
}
/**
* Delegates execution to the core logic
2025-04-17 18:06:21 -04:00
*/
async execute(params: GrepToolParams): Promise<ToolResult> {
return this.coreLogic.execute(params);
2025-04-15 21:41:08 -07:00
}
// Removed private methods (resolveAndValidatePath, performGrepSearch, etc.)
// as they are now part of GrepLogic in the server package.
2025-04-17 18:06:21 -04:00
}