refactor: remove hardcoded schema details from tool files and use external definitions

This commit is contained in:
Aishanee Shah
2026-02-04 22:00:07 +00:00
parent b2d09c3248
commit e1c0e6d714
3 changed files with 9 additions and 49 deletions

View File

@@ -6,6 +6,7 @@
import type { ToolDefinition } from './types.js';
import { READ_FILE_TOOL_NAME, SHELL_TOOL_NAME } from '../tool-names.js';
import { getCommandDescription } from '../shell.js';
export const READ_FILE_DEFINITION: ToolDefinition = {
base: {
@@ -43,7 +44,7 @@ export const SHELL_DEFINITION: ToolDefinition = {
properties: {
command: {
type: 'string',
description: 'The command to execute.',
description: getCommandDescription(),
},
description: {
type: 'string',

View File

@@ -171,28 +171,9 @@ export class ReadFileTool extends BaseDeclarativeTool<
super(
ReadFileTool.Name,
'ReadFile',
`Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), audio files (MP3, WAV, AIFF, AAC, OGG, FLAC), and PDF files. For text files, it can read specific line ranges.`,
READ_FILE_DEFINITION.base.description!,
Kind.Read,
{
properties: {
file_path: {
description: 'The path to the file to read.',
type: 'string',
},
offset: {
description:
"Optional: For text files, the 0-based line number to start reading from. Requires 'limit' to be set. Use for paginating through large files.",
type: 'number',
},
limit: {
description:
"Optional: For text files, maximum number of lines to read. Use with 'offset' to paginate through large files. If omitted, reads the entire file (if feasible, up to a default limit).",
type: 'number',
},
},
required: ['file_path'],
type: 'object',
},
READ_FILE_DEFINITION.base.parameters!,
messageBus,
true,
false,

View File

@@ -453,7 +453,9 @@ export class ShellToolInvocation extends BaseToolInvocation<
}
}
function getShellToolDescription(enableInteractiveShell: boolean): string {
export function getShellToolDescription(
enableInteractiveShell: boolean,
): string {
const returnedInfo = `
The following information is returned:
@@ -478,7 +480,7 @@ function getShellToolDescription(enableInteractiveShell: boolean): string {
}
}
function getCommandDescription(): string {
export function getCommandDescription(): string {
if (os.platform() === 'win32') {
return 'Exact command to execute as `powershell.exe -NoProfile -Command <command>`';
} else {
@@ -504,31 +506,7 @@ export class ShellTool extends BaseDeclarativeTool<
'Shell',
getShellToolDescription(config.getEnableInteractiveShell()),
Kind.Execute,
{
type: 'object',
properties: {
command: {
type: 'string',
description: getCommandDescription(),
},
description: {
type: 'string',
description:
'Brief description of the command for the user. Be specific and concise. Ideally a single sentence. Can be up to 3 sentences for clarity. No line breaks.',
},
dir_path: {
type: 'string',
description:
'(OPTIONAL) The path of the directory to run the command in. If not provided, the project root directory is used. Must be a directory within the workspace and must already exist.',
},
is_background: {
type: 'boolean',
description:
'Set to true if this command should be run in the background (e.g. for long-running servers or watchers). The command will be started, allowed to run for a brief moment to check for immediate errors, and then moved to the background.',
},
},
required: ['command'],
},
SHELL_DEFINITION.base.parameters!,
messageBus,
false, // output is not markdown
true, // output can be updated