diff --git a/core/tools/definitions/createRuleBlock.ts b/core/tools/definitions/createRuleBlock.ts index 92aecb158..8f19c5955 100644 --- a/core/tools/definitions/createRuleBlock.ts +++ b/core/tools/definitions/createRuleBlock.ts @@ -16,7 +16,7 @@ export const createRuleBlock: Tool = { 'Creates a "rule" that can be referenced in future conversations. This should be used whenever you want to establish code standards / preferences that should be applied consistently, or when you want to avoid making a mistake again. To modify existing rules, use the edit tool instead.\n\nRule Types:\n- Always: Include only "rule" (always included in model context)\n- Auto Attached: Include "rule", "globs", and/or "regex" (included when files match patterns)\n- Agent Requested: Include "rule" and "description" (AI decides when to apply based on description)\n- Manual: Include only "rule" (only included when explicitly mentioned using @ruleName)', parameters: { type: "object", - required: ["name", "rule", "description"], + required: ["name", "rule"], properties: { name: { type: "string", diff --git a/core/tools/definitions/ls.ts b/core/tools/definitions/ls.ts index 979f9450b..71f4e5cf9 100644 --- a/core/tools/definitions/ls.ts +++ b/core/tools/definitions/ls.ts @@ -16,12 +16,11 @@ export const lsTool: Tool = { description: "List files and folders in a given directory", parameters: { type: "object", - required: ["dirPath", "recursive"], properties: { dirPath: { type: "string", description: - "The directory path relative to the root of the project. Always use forward slash paths like '/'. rather than e.g. '.'", + "The directory path relative to the root of the project. Use forward slash paths like '/'. rather than e.g. '.'", }, recursive: { type: "boolean", diff --git a/core/tools/implementations/codebaseTool.ts b/core/tools/implementations/codebaseTool.ts index fe4f77ace..9ea0ecdc7 100644 --- a/core/tools/implementations/codebaseTool.ts +++ b/core/tools/implementations/codebaseTool.ts @@ -3,14 +3,8 @@ import { RangeInFile } from "../.."; import { retrieveContextItemsFromEmbeddings } from "../../context/retrieval/retrieval"; export const codebaseToolImpl: ToolImpl = async (args, extras) => { - if (!args.query || args.query.trim() === "") { - return [ - { - name: "Error", - description: "Codebase search error", - content: "Query parameter is required and cannot be empty.", - }, - ]; + if (!args?.query || args.query.trim() === "") { + throw new Error("`query` parameter is required and cannot be empty."); } try { diff --git a/core/tools/implementations/createNewFile.ts b/core/tools/implementations/createNewFile.ts index 5b18f03d3..d1849025e 100644 --- a/core/tools/implementations/createNewFile.ts +++ b/core/tools/implementations/createNewFile.ts @@ -4,6 +4,14 @@ import { ToolImpl } from "."; import { getCleanUriPath, getUriPathBasename } from "../../util/uri"; export const createNewFileImpl: ToolImpl = async (args, extras) => { + if (!args?.filepath) { + throw new Error("`filepath` argument is required and cannot be empty."); + } + if (args?.contents === undefined) { + throw new Error( + "`contents` argument is required to create a new file (can be empty).", + ); + } const resolvedFileUri = await inferResolvedUriFromRelativePath( args.filepath, extras.ide, diff --git a/core/tools/implementations/createRuleBlock.ts b/core/tools/implementations/createRuleBlock.ts index e433c233d..2e7a646aa 100644 --- a/core/tools/implementations/createRuleBlock.ts +++ b/core/tools/implementations/createRuleBlock.ts @@ -13,6 +13,11 @@ export const createRuleBlockImpl: ToolImpl = async ( { name, rule, ...otherArgs }: CreateRuleBlockArgs, extras, ) => { + if (!name || !rule) { + throw new Error( + "`name` and `rule` arguments are required to create a rule.", + ); + } const fileContent = createRuleMarkdown(name, rule, otherArgs); const [localContinueDir] = await extras.ide.getWorkspaceDirs(); diff --git a/core/tools/implementations/fetchUrlContent.ts b/core/tools/implementations/fetchUrlContent.ts index 16259780a..802be2e7c 100644 --- a/core/tools/implementations/fetchUrlContent.ts +++ b/core/tools/implementations/fetchUrlContent.ts @@ -4,6 +4,10 @@ import { getUrlContextItems } from "../../context/providers/URLContextProvider"; const DEFAULT_FETCH_URL_CHAR_LIMIT = 20000; export const fetchUrlContentImpl: ToolImpl = async (args, extras) => { + if (!args?.url) { + throw new Error("`url` argument is required and cannot be empty"); + } + const contextItems = await getUrlContextItems(args.url, extras.fetch); // Track truncated content diff --git a/core/tools/implementations/globSearch.ts b/core/tools/implementations/globSearch.ts index 1e551d9e2..03a061b57 100644 --- a/core/tools/implementations/globSearch.ts +++ b/core/tools/implementations/globSearch.ts @@ -2,7 +2,13 @@ import { ToolImpl } from "."; import { ContextItem } from "../.."; const MAX_AGENT_GLOB_RESULTS = 100; + export const fileGlobSearchImpl: ToolImpl = async (args, extras) => { + if (!args?.pattern) { + throw new Error( + "`pattern` argument is required for a glob search, and cannot be empty", + ); + } const results = await extras.ide.getFileResults( args.pattern, MAX_AGENT_GLOB_RESULTS, diff --git a/core/tools/implementations/grepSearch.ts b/core/tools/implementations/grepSearch.ts index b13839669..d9dd3df20 100644 --- a/core/tools/implementations/grepSearch.ts +++ b/core/tools/implementations/grepSearch.ts @@ -41,6 +41,12 @@ function splitGrepResultsByFile(content: string): ContextItem[] { } export const grepSearchImpl: ToolImpl = async (args, extras) => { + if (!args?.query) { + throw new Error( + "`query` argument is required for a grep search, and cannot be empty", + ); + } + const results = await extras.ide.getSearchResults( args.query, DEFAULT_GREP_SEARCH_RESULTS_LIMIT, diff --git a/core/tools/implementations/readFile.ts b/core/tools/implementations/readFile.ts index 4736d0b4c..89e9ccbdc 100644 --- a/core/tools/implementations/readFile.ts +++ b/core/tools/implementations/readFile.ts @@ -5,6 +5,12 @@ import { ToolImpl } from "."; import { throwIfFileExceedsHalfOfContext } from "./readFileLimit"; export const readFileImpl: ToolImpl = async (args, extras) => { + if (!args?.filepath) { + throw new Error( + "`filepath` argument is required to read a file, and cannot be empty", + ); + } + const firstUriMatch = await resolveRelativePathInDir( args.filepath, extras.ide, diff --git a/core/tools/implementations/requestRule.ts b/core/tools/implementations/requestRule.ts index a8801f344..f61d6328c 100644 --- a/core/tools/implementations/requestRule.ts +++ b/core/tools/implementations/requestRule.ts @@ -1,6 +1,12 @@ import { ToolImpl } from "."; export const requestRuleImpl: ToolImpl = async (args, extras) => { + if (!args?.name) { + throw new Error( + "`name` argument is required to request a rule, and cannot be empty", + ); + } + // Find the rule by name in the config const rule = extras.config.rules.find((r) => r.name === args.name); diff --git a/core/tools/implementations/runTerminalCommand.ts b/core/tools/implementations/runTerminalCommand.ts index 3336a1006..b57a9572d 100644 --- a/core/tools/implementations/runTerminalCommand.ts +++ b/core/tools/implementations/runTerminalCommand.ts @@ -50,6 +50,12 @@ const ENABLED_FOR_REMOTES = [ ]; export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { + if (!args?.command) { + throw new Error( + "`command` argument is required to run a terminal command, and cannot be empty", + ); + } + // Default to waiting for completion if not specified const waitForCompletion = args.waitForCompletion !== false; const ideInfo = await extras.ide.getIdeInfo(); diff --git a/core/tools/implementations/searchWeb.ts b/core/tools/implementations/searchWeb.ts index c7b64feb3..4a5d277c3 100644 --- a/core/tools/implementations/searchWeb.ts +++ b/core/tools/implementations/searchWeb.ts @@ -4,6 +4,12 @@ import { fetchSearchResults } from "../../context/providers/WebContextProvider"; const DEFAULT_WEB_SEARCH_CHAR_LIMIT = 8000; export const searchWebImpl: ToolImpl = async (args, extras) => { + if (!args?.query) { + throw new Error( + "`query` argument is required to search the web, and cannot be empty", + ); + } + const webResults = await fetchSearchResults(args.query, 5, extras.fetch); // Track truncated results diff --git a/core/tools/implementations/viewSubdirectory.ts b/core/tools/implementations/viewSubdirectory.ts index c62887dc5..bbda7143f 100644 --- a/core/tools/implementations/viewSubdirectory.ts +++ b/core/tools/implementations/viewSubdirectory.ts @@ -4,7 +4,13 @@ import { resolveRelativePathInDir } from "../../util/ideUtils"; import { ToolImpl } from "."; export const viewSubdirectoryImpl: ToolImpl = async (args: any, extras) => { + if (!args?.directory_path) { + throw new Error( + "`directory_path` argument is required to view a map of a subdirectory, and cannot be empty", + ); + } const { directory_path } = args; + const uri = await resolveRelativePathInDir(directory_path, extras.ide); if (!uri) { diff --git a/gui/src/util/clientTools/editImpl.ts b/gui/src/util/clientTools/editImpl.ts index 6873e0512..a6f56e7c9 100644 --- a/gui/src/util/clientTools/editImpl.ts +++ b/gui/src/util/clientTools/editImpl.ts @@ -6,6 +6,11 @@ export const editToolImpl: ClientToolImpl = async ( toolCallId, extras, ) => { + if (!args.filepath || !args.changes) { + throw new Error( + "`filepath` and `changes` arguments are required to edit an existing file.", + ); + } const firstUriMatch = await resolveRelativePathInDir( args.filepath, extras.ideMessenger.ide,