fix: throw error if tool call args are missing

This commit is contained in:
Dallin Romney 2025-07-20 14:13:15 +02:00
parent b25a71c8ff
commit 6af35548c8
14 changed files with 68 additions and 11 deletions

View file

@ -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",

View file

@ -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",

View file

@ -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 {

View file

@ -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,

View file

@ -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();

View file

@ -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

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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);

View file

@ -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();

View file

@ -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

View file

@ -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) {

View file

@ -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,