Elffuss BraidHub

kikocis/continue public

fix: use json schema for tool definitions (#7904)

* fix: use json schema for tool definitions

* fix: cubic feedback

* fix: eslint

* fix: broken tool params type
Changeset6c2aba15fe9965aef6a1251a81cd5c87cb58c5257ca7a6eabc3958985fd5fd9b
AuthorDallin Romney <dallinromney@gmail.com> · 2025-09-22 19:40 -07:00
CommitterGitHub <noreply@github.com> · 2025-09-22 19:40 -07:00
Parents54e630386bd7

Browse the files at this changeset

17 files changed

modified extensions/cli/src/permissions/permissionChecker.test.ts +9 −3
@@ -1,4 +1,4 @@
1-import { vi, describe, it, expect, beforeEach, afterEach } from "vitest";
1+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
33 import * as toolsModule from "../tools/index.js";
44
@@ -604,7 +604,10 @@
604604 name: "Bash",
605605 displayName: "Bash",
606606 description: "Execute bash commands",
607- parameters: {},
607+ parameters: {
608+ type: "object" as const,
609+ properties: {},
610+ },
608611 isBuiltIn: true,
609612 evaluateToolCallPolicy: vi.fn(),
610613 run: vi.fn(),
@@ -882,7 +885,10 @@
882885 name: "Read",
883886 displayName: "Read",
884887 description: "Read files",
885- parameters: {},
888+ parameters: {
889+ type: "object" as const,
890+ properties: {},
891+ },
886892 isBuiltIn: true,
887893 run: vi.fn(),
888894 // No evaluateToolCallPolicy
modified extensions/cli/src/stream/handleToolCalls.ts +2 −13
@@ -233,19 +233,8 @@
233233 description: tool.description,
234234 parameters: {
235235 type: "object",
236- properties: Object.fromEntries(
237- Object.entries(tool.parameters).map(([key, param]) => [
238- key,
239- {
240- type: param.type,
241- description: param.description,
242- items: param.items,
243- },
244- ]),
245- ),
246- required: Object.entries(tool.parameters)
247- .filter(([_, param]) => param.required)
248- .map(([key, _]) => key),
236+ required: tool.parameters.required,
237+ properties: tool.parameters.properties,
249238 },
250239 },
251240 }));
modified extensions/cli/src/tools/edit.ts +22 −21
@@ -79,27 +79,28 @@
7979 - When not using \`replace_all\`, the edit will FAIL if \`old_string\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \`replace_all\` to change every instance of \`old_string\`.
8080 - The edit will FAIL if you have not recently used the \`${readFileTool.name}\` tool to view up-to-date file contents.`,
8181 parameters: {
82- file_path: {
83- type: "string",
84- description: "The absolute path to the file to modify",
85- required: true,
86- },
87- old_string: {
88- type: "string",
89- description:
90- "The text to replace - must be exact including whitespace/indentation",
91- required: true,
92- },
93- new_string: {
94- type: "string",
95- description:
96- "The text to replace it with (MUST be different from old_string)",
97- required: true,
98- },
99- replace_all: {
100- type: "boolean",
101- description: "Replace all occurences of old_string (default false)",
102- required: false,
82+ type: "object",
83+ required: ["file_path", "old_string", "new_string"],
84+ properties: {
85+ file_path: {
86+ type: "string",
87+ description:
88+ "Absolute or relative path to the file to modify. Absolute preferred",
89+ },
90+ old_string: {
91+ type: "string",
92+ description:
93+ "The text to replace - must be exact including whitespace/indentation",
94+ },
95+ new_string: {
96+ type: "string",
97+ description:
98+ "The text to replace it with (MUST be different from old_string)",
99+ },
100+ replace_all: {
101+ type: "boolean",
102+ description: "Replace all occurrences of old_string (default false)",
103+ },
103104 },
104105 },
105106 preprocess: async (args) => {
modified extensions/cli/src/tools/exit.ts +4 −1
@@ -5,7 +5,10 @@
55 displayName: "Exit",
66 description:
77 "Exit the current process with status code 1, indicating a failure or error",
8- parameters: {},
8+ parameters: {
9+ type: "object",
10+ properties: {},
11+ },
912 readonly: false,
1013 isBuiltIn: true,
1114 run: async (): Promise<string> => {
modified extensions/cli/src/tools/fetch.test.ts +7 −4
@@ -144,10 +144,13 @@
144144 expect(fetchTool.readonly).toBe(true);
145145 expect(fetchTool.isBuiltIn).toBe(true);
146146 expect(fetchTool.parameters).toEqual({
147- url: {
148- type: "string",
149- description: "The URL to fetch content from",
150- required: true,
147+ type: "object",
148+ required: ["url"],
149+ properties: {
150+ url: {
151+ type: "string",
152+ description: "The URL to fetch content from",
153+ },
151154 },
152155 });
153156 });
modified extensions/cli/src/tools/fetch.ts +7 −4
@@ -9,10 +9,13 @@
99 description:
1010 "Fetches content from a URL, converts to markdown, and handles long content with truncation",
1111 parameters: {
12- url: {
13- type: "string",
14- description: "The URL to fetch content from",
15- required: true,
12+ type: "object",
13+ required: ["url"],
14+ properties: {
15+ url: {
16+ type: "string",
17+ description: "The URL to fetch content from",
18+ },
1619 },
1720 },
1821 readonly: true,
modified extensions/cli/src/tools/index.tsx +15 −21
@@ -26,13 +26,14 @@
2626 import {
2727 type Tool,
2828 type ToolCall,
29- type ToolParameters,
29+ type ToolParametersSchema,
30+ ParameterSchema,
3031 PreprocessedToolCall,
3132 } from "./types.js";
3233 import { writeChecklistTool } from "./writeChecklist.js";
3334 import { writeFileTool } from "./writeFile.js";
3435
35-export type { Tool, ToolCall, ToolParameters };
36+export type { Tool, ToolCall, ToolParametersSchema };
3637
3738 // Base tools that are always available
3839 const BASE_BUILTIN_TOOLS: Tool[] = [
@@ -152,22 +153,6 @@
152153 return toolCalls;
153154 }
154155
155-function convertInputSchemaToParameters(inputSchema: any): ToolParameters {
156- const parameters: Record<
157- string,
158- { type: string; description: string; required: boolean }
159- > = {};
160- for (const [key, value] of Object.entries(inputSchema.properties)) {
161- const val = value as any;
162- parameters[key] = {
163- type: val.type,
164- description: val.description || "",
165- required: inputSchema.required?.includes(key) || false,
166- };
167- }
168- return parameters;
169-}
170-
171156 export async function getAvailableTools() {
172157 // Load MCP tools
173158 const mcpState = await serviceContainer.get<MCPServiceState>(
@@ -179,7 +164,14 @@
179164 name: t.name,
180165 displayName: t.name.replace("mcp__", "").replace("ide__", ""),
181166 description: t.description ?? "",
182- parameters: convertInputSchemaToParameters(t.inputSchema),
167+ parameters: {
168+ type: "object",
169+ properties: (t.inputSchema.properties ?? {}) as Record<
170+ string,
171+ ParameterSchema
172+ >,
173+ required: t.inputSchema.required,
174+ },
183175 readonly: undefined, // MCP tools don't have readonly property
184176 isBuiltIn: false,
185177 run: async (args: any) => {
@@ -255,10 +247,12 @@
255247 }
256248 }
257249
250+// Only checks top-level required
258251 export function validateToolCallArgsPresent(toolCall: ToolCall, tool: Tool) {
259- for (const [paramName, paramDef] of Object.entries(tool.parameters)) {
252+ const requiredParams = tool.parameters.required ?? [];
253+ for (const [paramName] of Object.entries(tool.parameters)) {
260254 if (
261- paramDef.required &&
255+ requiredParams.includes(paramName) &&
262256 (toolCall.arguments[paramName] === undefined ||
263257 toolCall.arguments[paramName] === null)
264258 ) {
modified extensions/cli/src/tools/listFiles.ts +7 −4
@@ -10,10 +10,13 @@
1010 displayName: "List",
1111 description: "List files in a directory",
1212 parameters: {
13- dirpath: {
14- type: "string",
15- description: "The path to the directory to list",
16- required: true,
13+ type: "object",
14+ required: ["dirpath"],
15+ properties: {
16+ dirpath: {
17+ type: "string",
18+ description: "The path to the directory to list",
19+ },
1720 },
1821 },
1922 readonly: true,
modified extensions/cli/src/tools/multiEdit.ts +35 −14
@@ -35,11 +35,11 @@
3535 This tool is ideal when you need to make multiple edits to the same file.
3636
3737 To make multiple edits to a file, provide the following:
38-1. file_path: The absolute path to the file to modify (must be absolute, not relative)
38+1. file_path: The absolute path to the file to modify. Relative paths can also be used (resolved against cwd) but absolute is preferred
3939 2. edits: An array of edit operations to perform, where each edit contains:
4040 - old_string: The text to replace (must match the file contents exactly, including all whitespace/indentation)
4141 - new_string: The edited text to replace the old_string
42- - replace_all: Replace all occurences of old_string. This parameter is optional and defaults to false.
42+ - replace_all: Replace all occurrences of old_string. This parameter is optional and defaults to false.
4343
4444 IMPORTANT:
4545 - All edits are applied in sequence, in the order they are provided
@@ -65,18 +65,39 @@
6565 - The tool will fail if the file does not exist - it cannot create new files
6666 - This tool cannot create new files - the file must already exist`,
6767 parameters: {
68- file_path: {
69- type: "string",
70- description: "The absolute path to the file to modify",
71- required: true,
72- },
73- edits: {
74- type: "array",
75- description:
76- "Array of edit operations to perform sequentially on the file",
77- required: true,
78- items: {
79- type: "object",
68+ type: "object",
69+ required: ["file_path", "edits"],
70+ properties: {
71+ file_path: {
72+ type: "string",
73+ description:
74+ "Absolute or relative path to the file to modify. Absolute preferred",
75+ },
76+ edits: {
77+ type: "array",
78+ description:
79+ "Array of edit operations to perform sequentially on the file",
80+ items: {
81+ type: "object",
82+ required: ["old_string", "new_string"],
83+ properties: {
84+ old_string: {
85+ type: "string",
86+ description:
87+ "The text to replace (exact match including whitespace/indentation)",
88+ },
89+ new_string: {
90+ type: "string",
91+ description:
92+ "The text to replace it with. MUST be different than old_string.",
93+ },
94+ replace_all: {
95+ type: "boolean",
96+ description:
97+ "Replace all occurrences of old_string (default false) in the file",
98+ },
99+ },
100+ },
80101 },
81102 },
82103 },
modified extensions/cli/src/tools/readFile.ts +7 −4
@@ -16,10 +16,13 @@
1616 displayName: "Read",
1717 description: "Read the contents of a file at the specified path",
1818 parameters: {
19- filepath: {
20- type: "string",
21- description: "The path to the file to read",
22- required: true,
19+ type: "object",
20+ required: ["filepath"],
21+ properties: {
22+ filepath: {
23+ type: "string",
24+ description: "The path to the file to read",
25+ },
2326 },
2427 },
2528 readonly: true,
modified extensions/cli/src/tools/runTerminalCommand.ts +7 −4
@@ -36,10 +36,13 @@
3636 Commands are automatically executed from the current working directory (${process.cwd()}), so there's no need to change directories with 'cd' commands.
3737 `,
3838 parameters: {
39- command: {
40- type: "string",
41- description: "The command to execute in the terminal.",
42- required: true,
39+ type: "object",
40+ required: ["command"],
41+ properties: {
42+ command: {
43+ type: "string",
44+ description: "The command to execute in the terminal.",
45+ },
4346 },
4447 },
4548 readonly: false,
modified extensions/cli/src/tools/searchCode.ts +15 −14
@@ -14,20 +14,21 @@
1414 displayName: "Search",
1515 description: "Search the codebase using ripgrep (rg) for a specific pattern",
1616 parameters: {
17- pattern: {
18- type: "string",
19- description: "The search pattern to look for",
20- required: true,
21- },
22- path: {
23- type: "string",
24- description: "The path to search in (defaults to current directory)",
25- required: false,
26- },
27- file_pattern: {
28- type: "string",
29- description: "Optional file pattern to filter results (e.g., '*.ts')",
30- required: false,
17+ type: "object",
18+ required: ["pattern"],
19+ properties: {
20+ pattern: {
21+ type: "string",
22+ description: "The search pattern to look for",
23+ },
24+ path: {
25+ type: "string",
26+ description: "The path to search in (defaults to current directory)",
27+ },
28+ file_pattern: {
29+ type: "string",
30+ description: "Optional file pattern to filter results (e.g., '*.ts')",
31+ },
3132 },
3233 },
3334 readonly: true,
modified extensions/cli/src/tools/types.ts +18 −11
@@ -1,16 +1,23 @@
11 import type { ToolPolicy } from "@continuedev/terminal-security";
22
3-export type ToolParameters = Record<
4- string,
5- {
3+// JSON Schema compatible parameter definition
4+export interface ParameterSchema {
5+ type: string;
6+ description: string;
7+ required?: string[];
8+ properties?: Record<string, ParameterSchema>;
9+ items?: {
610 type: string;
7- description: string;
8- required: boolean;
9- items?: {
10- type: string;
11- };
12- }
13->;
11+ properties?: Record<string, ParameterSchema>;
12+ required?: string[];
13+ };
14+}
15+
16+export interface ToolParametersSchema {
17+ type: "object";
18+ required?: string[];
19+ properties: Record<string, ParameterSchema>;
20+}
1421
1522 export interface ToolCallPreview {
1623 type: "text" | "diff" | "checklist";
@@ -28,7 +35,7 @@
2835 name: string;
2936 displayName: string;
3037 description: string;
31- parameters: ToolParameters;
38+ parameters: ToolParametersSchema;
3239 preprocess?: (args: any) => Promise<PreprocessToolCallResult>;
3340 run: (args: any) => Promise<string>;
3441 readonly?: boolean; // Indicates if the tool is readonly
modified extensions/cli/src/tools/viewDiff.ts +7 −5
@@ -11,11 +11,13 @@
1111 displayName: "Diff",
1212 description: "View all uncommitted changes in the git repository",
1313 parameters: {
14- path: {
15- type: "string",
16- description:
17- "The path to the git repository (defaults to current directory)",
18- required: false,
14+ type: "object",
15+ properties: {
16+ path: {
17+ type: "string",
18+ description:
19+ "The path to the git repository (defaults to current directory)",
20+ },
1921 },
2022 },
2123 readonly: true,
modified extensions/cli/src/tools/writeChecklist.test.ts +3 −2
@@ -16,7 +16,8 @@
1616 expect(writeChecklistTool.displayName).toBe("Checklist");
1717 expect(writeChecklistTool.readonly).toBe(false);
1818 expect(writeChecklistTool.isBuiltIn).toBe(true);
19- expect(writeChecklistTool.parameters.checklist.required).toBe(true);
20- expect(writeChecklistTool.parameters.checklist.type).toBe("string");
19+ expect(writeChecklistTool.parameters.required?.includes("checklist")).toBe(
20+ true,
21+ );
2122 });
2223 });
modified extensions/cli/src/tools/writeChecklist.ts +8 −5
@@ -8,11 +8,14 @@
88 readonly: false,
99 isBuiltIn: true,
1010 parameters: {
11- checklist: {
12- type: "string",
13- description:
14- "The complete checklist in markdown format using - [ ] for incomplete tasks and - [x] for completed tasks. Avoid headers and additional content unless specifically being used to group checkboxes. Try to keep the list short, and make each item specific and actionable.",
15- required: true,
11+ type: "object",
12+ required: ["checklist"],
13+ properties: {
14+ checklist: {
15+ type: "string",
16+ description:
17+ "The complete checklist in markdown format using - [ ] for incomplete tasks and - [x] for completed tasks. Avoid headers and additional content unless specifically being used to group checkboxes. Try to keep the list short, and make each item specific and actionable.",
18+ },
1619 },
1720 },
1821 preprocess: async (args: { checklist: string }) => {
modified extensions/cli/src/tools/writeFile.ts +11 −9
@@ -32,15 +32,17 @@
3232 displayName: "Write",
3333 description: "Write content to a file at the specified path",
3434 parameters: {
35- filepath: {
36- type: "string",
37- description: "The path to the file to write",
38- required: true,
39- },
40- content: {
41- type: "string",
42- description: "The content to write to the file",
43- required: true,
35+ type: "object",
36+ required: ["filepath", "content"],
37+ properties: {
38+ filepath: {
39+ type: "string",
40+ description: "The path to the file to write",
41+ },
42+ content: {
43+ type: "string",
44+ description: "The content to write to the file",
45+ },
4446 },
4547 },
4648 readonly: false,