Use consistent param names (#12517)

This commit is contained in:
Tommaso Sciortino
2025-11-06 15:03:52 -08:00
committed by GitHub
parent 5f1208ad81
commit f05d937f39
27 changed files with 553 additions and 525 deletions
+30 -30
View File
@@ -6,7 +6,6 @@
import type { MessageBus } from '../confirmation-bus/message-bus.js';
import path from 'node:path';
import process from 'node:process';
import { makeRelative, shortenPath } from '../utils/paths.js';
import type { ToolInvocation, ToolLocation, ToolResult } from './tools.js';
import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js';
@@ -28,9 +27,9 @@ import { READ_FILE_TOOL_NAME } from './tool-names.js';
*/
export interface ReadFileToolParams {
/**
* The absolute path to the file to read
* The path to the file to read
*/
absolute_path: string;
file_path: string;
/**
* The line number to start reading from (optional)
@@ -47,6 +46,7 @@ class ReadFileToolInvocation extends BaseToolInvocation<
ReadFileToolParams,
ToolResult
> {
private readonly resolvedPath: string;
constructor(
private config: Config,
params: ReadFileToolParams,
@@ -55,23 +55,27 @@ class ReadFileToolInvocation extends BaseToolInvocation<
_toolDisplayName?: string,
) {
super(params, messageBus, _toolName, _toolDisplayName);
this.resolvedPath = path.resolve(
this.config.getTargetDir(),
this.params.file_path,
);
}
getDescription(): string {
const relativePath = makeRelative(
this.params.absolute_path,
this.resolvedPath,
this.config.getTargetDir(),
);
return shortenPath(relativePath);
}
override toolLocations(): ToolLocation[] {
return [{ path: this.params.absolute_path, line: this.params.offset }];
return [{ path: this.resolvedPath, line: this.params.offset }];
}
async execute(): Promise<ToolResult> {
const result = await processSingleFileContent(
this.params.absolute_path,
this.resolvedPath,
this.config.getTargetDir(),
this.config.getFileSystemService(),
this.params.offset,
@@ -111,9 +115,9 @@ ${result.llmContent}`;
typeof result.llmContent === 'string'
? result.llmContent.split('\n').length
: undefined;
const mimetype = getSpecificMimeType(this.params.absolute_path);
const mimetype = getSpecificMimeType(this.resolvedPath);
const programming_language = getProgrammingLanguage({
absolute_path: this.params.absolute_path,
file_path: this.resolvedPath,
});
logFileOperation(
this.config,
@@ -122,7 +126,7 @@ ${result.llmContent}`;
FileOperation.READ,
lines,
mimetype,
path.extname(this.params.absolute_path),
path.extname(this.resolvedPath),
programming_language,
),
);
@@ -154,11 +158,8 @@ export class ReadFileTool extends BaseDeclarativeTool<
Kind.Read,
{
properties: {
absolute_path: {
description:
process.platform === 'win32'
? "The absolute path to the file to read (e.g., 'C:\\Users\\project\\file.txt'). Relative paths are not supported. You must provide an absolute path."
: "The absolute path to the file to read (e.g., '/home/user/project/file.txt'). Relative paths are not supported. You must provide an absolute path.",
file_path: {
description: 'The path to the file to read.',
type: 'string',
},
offset: {
@@ -172,7 +173,7 @@ export class ReadFileTool extends BaseDeclarativeTool<
type: 'number',
},
},
required: ['absolute_path'],
required: ['file_path'],
type: 'object',
},
true,
@@ -184,24 +185,25 @@ export class ReadFileTool extends BaseDeclarativeTool<
protected override validateToolParamValues(
params: ReadFileToolParams,
): string | null {
const filePath = params.absolute_path;
if (params.absolute_path.trim() === '') {
return "The 'absolute_path' parameter must be non-empty.";
}
if (!path.isAbsolute(filePath)) {
return `File path must be absolute, but was relative: ${filePath}. You must provide an absolute path.`;
if (params.file_path.trim() === '') {
return "The 'file_path' parameter must be non-empty.";
}
const workspaceContext = this.config.getWorkspaceContext();
const projectTempDir = this.config.storage.getProjectTempDir();
const resolvedFilePath = path.resolve(filePath);
const resolvedPath = path.resolve(
this.config.getTargetDir(),
params.file_path,
);
const resolvedProjectTempDir = path.resolve(projectTempDir);
const isWithinTempDir =
resolvedFilePath.startsWith(resolvedProjectTempDir + path.sep) ||
resolvedFilePath === resolvedProjectTempDir;
resolvedPath.startsWith(resolvedProjectTempDir + path.sep) ||
resolvedPath === resolvedProjectTempDir;
if (!workspaceContext.isPathWithinWorkspace(filePath) && !isWithinTempDir) {
if (
!workspaceContext.isPathWithinWorkspace(resolvedPath) &&
!isWithinTempDir
) {
const directories = workspaceContext.getDirectories();
return `File path must be within one of the workspace directories: ${directories.join(', ')} or within the project temp directory: ${projectTempDir}`;
}
@@ -214,10 +216,8 @@ export class ReadFileTool extends BaseDeclarativeTool<
const fileService = this.config.getFileService();
const fileFilteringOptions = this.config.getFileFilteringOptions();
if (
fileService.shouldIgnoreFile(params.absolute_path, fileFilteringOptions)
) {
return `File path '${filePath}' is ignored by configured ignore patterns.`;
if (fileService.shouldIgnoreFile(resolvedPath, fileFilteringOptions)) {
return `File path '${resolvedPath}' is ignored by configured ignore patterns.`;
}
return null;