Migrate EditTool, GrepTool, and GlobTool to DeclarativeTool (#5744)

This commit is contained in:
joshualitt
2025-08-07 10:05:37 -07:00
committed by GitHub
parent 0d65baf928
commit 8bac9e7d04
8 changed files with 649 additions and 563 deletions

View File

@@ -9,6 +9,7 @@ import { SchemaValidator } from '../utils/schemaValidator.js';
import { makeRelative, shortenPath } from '../utils/paths.js';
import {
BaseDeclarativeTool,
BaseToolInvocation,
Icon,
ToolInvocation,
ToolLocation,
@@ -45,13 +46,16 @@ export interface ReadFileToolParams {
limit?: number;
}
class ReadFileToolInvocation
implements ToolInvocation<ReadFileToolParams, ToolResult>
{
class ReadFileToolInvocation extends BaseToolInvocation<
ReadFileToolParams,
ToolResult
> {
constructor(
private config: Config,
public params: ReadFileToolParams,
) {}
params: ReadFileToolParams,
) {
super(params);
}
getDescription(): string {
const relativePath = makeRelative(
@@ -61,14 +65,10 @@ class ReadFileToolInvocation
return shortenPath(relativePath);
}
toolLocations(): ToolLocation[] {
override toolLocations(): ToolLocation[] {
return [{ path: this.params.absolute_path, line: this.params.offset }];
}
shouldConfirmExecute(): Promise<false> {
return Promise.resolve(false);
}
async execute(): Promise<ToolResult> {
const result = await processSingleFileContent(
this.params.absolute_path,