From e1c0e6d7140d8db9571ccb421d5d9453df9bd269 Mon Sep 17 00:00:00 2001 From: Aishanee Shah Date: Wed, 4 Feb 2026 22:00:07 +0000 Subject: [PATCH] refactor: remove hardcoded schema details from tool files and use external definitions --- .../core/src/tools/definitions/coreTools.ts | 3 +- packages/core/src/tools/read-file.ts | 23 ++----------- packages/core/src/tools/shell.ts | 32 +++---------------- 3 files changed, 9 insertions(+), 49 deletions(-) diff --git a/packages/core/src/tools/definitions/coreTools.ts b/packages/core/src/tools/definitions/coreTools.ts index 68445efcb6..8470db41dc 100644 --- a/packages/core/src/tools/definitions/coreTools.ts +++ b/packages/core/src/tools/definitions/coreTools.ts @@ -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', diff --git a/packages/core/src/tools/read-file.ts b/packages/core/src/tools/read-file.ts index ed9fc93f18..27b13f1f9a 100644 --- a/packages/core/src/tools/read-file.ts +++ b/packages/core/src/tools/read-file.ts @@ -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, diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index 994c4a9a90..0d4fdcb368 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -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 `'; } 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