diff --git a/core/index.d.ts b/core/index.d.ts index 79442065a..eacffcb56 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1069,6 +1069,11 @@ export interface ToolExtras { codeBaseIndexer?: CodebaseIndexer; } +export type ToolPolicy = + | "allowedWithPermission" + | "allowedWithoutPermission" + | "disabled"; + export interface Tool { type: "function"; function: { @@ -1089,6 +1094,7 @@ export interface Tool { group: string; originalFunctionName?: string; systemMessageDescription?: string; + defaultToolPolicy?: ToolPolicy; } interface ToolChoice { diff --git a/core/tools/definitions/codebaseTool.ts b/core/tools/definitions/codebaseTool.ts index 0714a230b..f7806bc30 100644 --- a/core/tools/definitions/codebaseTool.ts +++ b/core/tools/definitions/codebaseTool.ts @@ -27,6 +27,7 @@ export const codebaseTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.CodebaseTool, `To search the codebase, use the ${BuiltInToolNames.CodebaseTool} tool with a natural language query. For example, to find authentication logic, you might respond with:`, diff --git a/core/tools/definitions/createNewFile.ts b/core/tools/definitions/createNewFile.ts index 152af5693..e0ba8ee9a 100644 --- a/core/tools/definitions/createNewFile.ts +++ b/core/tools/definitions/createNewFile.ts @@ -31,6 +31,7 @@ export const createNewFileTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.CreateNewFile, `To create a NEW file, use the ${BuiltInToolNames.CreateNewFile} tool with the relative filepath and new contents. For example, to create a file located at 'path/to/file.txt', you would respond with:`, diff --git a/core/tools/definitions/createRuleBlock.ts b/core/tools/definitions/createRuleBlock.ts index e6bf6689e..3ab63f6a4 100644 --- a/core/tools/definitions/createRuleBlock.ts +++ b/core/tools/definitions/createRuleBlock.ts @@ -60,6 +60,7 @@ export const createRuleBlock: Tool = { }, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.CreateRuleBlock, `Sometimes the user will provide feedback or guidance on your output. If you were not aware of these "rules", consider using the ${BuiltInToolNames.CreateRuleBlock} tool to persist the rule for future interactions. diff --git a/core/tools/definitions/editFile.ts b/core/tools/definitions/editFile.ts index 59e20c681..33ac93e38 100644 --- a/core/tools/definitions/editFile.ts +++ b/core/tools/definitions/editFile.ts @@ -40,6 +40,7 @@ export const editFileTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.EditExistingFile, `To edit an EXISTING file, use the ${BuiltInToolNames.EditExistingFile} tool with diff --git a/core/tools/definitions/fetchUrlContent.ts b/core/tools/definitions/fetchUrlContent.ts index ae57fc532..5deedc9c7 100644 --- a/core/tools/definitions/fetchUrlContent.ts +++ b/core/tools/definitions/fetchUrlContent.ts @@ -26,6 +26,7 @@ export const fetchUrlContentTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.FetchUrlContent, `To fetch the content of a URL, use the ${BuiltInToolNames.FetchUrlContent} tool. For example, to read the contents of a webpage, you might respond with:`, diff --git a/core/tools/definitions/globSearch.ts b/core/tools/definitions/globSearch.ts index e0f195a66..4d4c01c4f 100644 --- a/core/tools/definitions/globSearch.ts +++ b/core/tools/definitions/globSearch.ts @@ -26,6 +26,7 @@ export const globSearchTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithoutPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.FileGlobSearch, `To return a list of files based on a glob search pattern, use the ${BuiltInToolNames.FileGlobSearch} tool`, diff --git a/core/tools/definitions/grepSearch.ts b/core/tools/definitions/grepSearch.ts index e276d5a8f..b3017cbd5 100644 --- a/core/tools/definitions/grepSearch.ts +++ b/core/tools/definitions/grepSearch.ts @@ -27,6 +27,7 @@ export const grepSearchTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithoutPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.GrepSearch, `To perform a grep search within the project, call the ${BuiltInToolNames.GrepSearch} tool with the query pattern to match. For example:`, diff --git a/core/tools/definitions/ls.ts b/core/tools/definitions/ls.ts index 97d23f4f6..7e66300fe 100644 --- a/core/tools/definitions/ls.ts +++ b/core/tools/definitions/ls.ts @@ -31,6 +31,7 @@ export const lsTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithoutPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.LSTool, `To list files and folders in a given directory, call the ${BuiltInToolNames.LSTool} tool with "dirPath" and "recursive". For example:`, diff --git a/core/tools/definitions/readCurrentlyOpenFile.ts b/core/tools/definitions/readCurrentlyOpenFile.ts index 3f07f816f..995dbcd1a 100644 --- a/core/tools/definitions/readCurrentlyOpenFile.ts +++ b/core/tools/definitions/readCurrentlyOpenFile.ts @@ -20,6 +20,7 @@ export const readCurrentlyOpenFileTool: Tool = { properties: {}, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.ReadCurrentlyOpenFile, `To view the user's currently open file, use the ${BuiltInToolNames.ReadCurrentlyOpenFile} tool. diff --git a/core/tools/definitions/readFile.ts b/core/tools/definitions/readFile.ts index fb13eba05..eae37f603 100644 --- a/core/tools/definitions/readFile.ts +++ b/core/tools/definitions/readFile.ts @@ -27,6 +27,7 @@ export const readFileTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithoutPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.ReadFile, `To read a file with a known filepath, use the ${BuiltInToolNames.ReadFile} tool. For example, to read a file located at 'path/to/file.txt', you would respond with this:`, diff --git a/core/tools/definitions/requestRule.ts b/core/tools/definitions/requestRule.ts index 4e2f1ef61..b90c4d7df 100644 --- a/core/tools/definitions/requestRule.ts +++ b/core/tools/definitions/requestRule.ts @@ -60,6 +60,7 @@ export const requestRuleTool: GetTool = ({ rules }) => ({ }, }, }, + defaultToolPolicy: "disabled", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.RequestRule, getRequestRuleSystemMessageDescription(rules), diff --git a/core/tools/definitions/runTerminalCommand.ts b/core/tools/definitions/runTerminalCommand.ts index 8ab379e1b..dea965f5b 100644 --- a/core/tools/definitions/runTerminalCommand.ts +++ b/core/tools/definitions/runTerminalCommand.ts @@ -56,6 +56,7 @@ export const runTerminalCommandTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.RunTerminalCommand, `To run a terminal command, use the ${BuiltInToolNames.RunTerminalCommand} tool diff --git a/core/tools/definitions/searchAndReplaceInFile.ts b/core/tools/definitions/searchAndReplaceInFile.ts index 96dac65da..81800e01e 100644 --- a/core/tools/definitions/searchAndReplaceInFile.ts +++ b/core/tools/definitions/searchAndReplaceInFile.ts @@ -120,4 +120,5 @@ ${SEARCH_AND_REPLACE_RULES} ], ], ), + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/searchWeb.ts b/core/tools/definitions/searchWeb.ts index bcaa743a3..5d66e83e8 100644 --- a/core/tools/definitions/searchWeb.ts +++ b/core/tools/definitions/searchWeb.ts @@ -26,6 +26,7 @@ export const searchWebTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithoutPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.SearchWeb, `To search the web, use the ${BuiltInToolNames.SearchWeb} tool with a natural language query. For example, to search for the current weather, you would respond with:`, diff --git a/core/tools/definitions/viewDiff.ts b/core/tools/definitions/viewDiff.ts index bf488f171..ceaa241ec 100644 --- a/core/tools/definitions/viewDiff.ts +++ b/core/tools/definitions/viewDiff.ts @@ -20,6 +20,7 @@ export const viewDiffTool: Tool = { properties: {}, }, }, + defaultToolPolicy: "allowedWithoutPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.ViewDiff, `To view the current git diff, use the ${BuiltInToolNames.ViewDiff} tool. This will show you the changes made in the working directory compared to the last commit.`, diff --git a/core/tools/definitions/viewRepoMap.ts b/core/tools/definitions/viewRepoMap.ts index a58584fc1..147ce132f 100644 --- a/core/tools/definitions/viewRepoMap.ts +++ b/core/tools/definitions/viewRepoMap.ts @@ -20,6 +20,7 @@ export const viewRepoMapTool: Tool = { properties: {}, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.ViewRepoMap, `To view the repository map, use the ${BuiltInToolNames.ViewRepoMap} tool. This will provide a visual representation of the project's structure and organization.`, diff --git a/core/tools/definitions/viewSubdirectory.ts b/core/tools/definitions/viewSubdirectory.ts index 11c27a775..0d45e922b 100644 --- a/core/tools/definitions/viewSubdirectory.ts +++ b/core/tools/definitions/viewSubdirectory.ts @@ -26,6 +26,7 @@ export const viewSubdirectoryTool: Tool = { }, }, }, + defaultToolPolicy: "allowedWithPermission", systemMessageDescription: createSystemMessageExampleCall( BuiltInToolNames.ViewSubdirectory, `To view a map of a specific folder within the project, you can use the ${BuiltInToolNames.ViewSubdirectory} tool. This will provide a visual representation of the folder's structure and organization.`, diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 589e37ff4..421e17772 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -287,6 +287,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); it("should render tool call", async () => { + await GUIActions.toggleToolPolicy(view, "view_diff", 0); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); await messageInput.sendKeys(Key.ENTER); diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx index c54b2341d..7e346a678 100644 --- a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +++ b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx @@ -10,7 +10,10 @@ import { generateToolCallButtonTestId } from "../../../components/mainInput/Lump import { waitFor } from "@testing-library/dom"; import { act } from "@testing-library/react"; import { ChatMessage } from "core"; -import { toggleToolSetting } from "../../../redux/slices/uiSlice"; +import { + setToolPolicy, + toggleToolSetting, +} from "../../../redux/slices/uiSlice"; import { getElementByTestId, getElementByText, @@ -173,7 +176,12 @@ test("Edit run with no policy and yolo mode", { timeout: 15000 }, async () => { addAndSelectMockLlm(store, ideMessenger); // Enable automatic edit and yolo mode - store.dispatch(toggleToolSetting(BuiltInToolNames.EditExistingFile)); + store.dispatch( + setToolPolicy({ + toolName: BuiltInToolNames.EditExistingFile, + policy: "allowedWithoutPermission", + }), + ); triggerConfigUpdate({ store, ideMessenger, diff --git a/gui/src/redux/selectors/selectActiveTools.ts b/gui/src/redux/selectors/selectActiveTools.ts index 2e90bbfd5..b28a3d903 100644 --- a/gui/src/redux/selectors/selectActiveTools.ts +++ b/gui/src/redux/selectors/selectActiveTools.ts @@ -1,6 +1,7 @@ import { createSelector } from "@reduxjs/toolkit"; import { Tool } from "core"; import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn"; +import { DEFAULT_TOOL_SETTING } from "../slices/uiSlice"; import { RootState } from "../store"; export const selectActiveTools = createSelector( @@ -14,11 +15,15 @@ export const selectActiveTools = createSelector( if (mode === "chat") { return []; } else { - const enabledTools = tools.filter( - (tool) => - policies[tool.function.name] !== "disabled" && - groupPolicies[tool.group] !== "exclude", - ); + const enabledTools = tools.filter((tool) => { + const toolPolicy = + policies[tool.function.name] ?? + tool.defaultToolPolicy ?? + DEFAULT_TOOL_SETTING; + return ( + toolPolicy !== "disabled" && groupPolicies[tool.group] !== "exclude" + ); + }); if (mode === "plan") { return enabledTools.filter( (t) => t.group !== BUILT_IN_GROUP_NAME || t.readonly, diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index f261ff892..e350d9f72 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -1,5 +1,5 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { RuleWithSource, Tool } from "core"; +import { RuleWithSource, Tool, ToolPolicy } from "core"; import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "core/tools/builtIn"; import { defaultOnboardingCardState, @@ -7,11 +7,6 @@ import { } from "../../components/OnboardingCard"; import { getLocalStorage, LocalStorageKey } from "../../util/localStorage"; -export type ToolPolicy = - | "allowedWithPermission" - | "allowedWithoutPermission" - | "disabled"; - export type RulePolicy = "on" | "off"; export type ToolGroupPolicy = "include" | "exclude"; @@ -50,21 +45,7 @@ export const uiSlice = createSlice({ ), shouldAddFileForEditing: false, ttsActive: false, - toolSettings: { - [BuiltInToolNames.ReadFile]: "allowedWithoutPermission", - [BuiltInToolNames.EditExistingFile]: "allowedWithPermission", - [BuiltInToolNames.CreateNewFile]: "allowedWithPermission", - [BuiltInToolNames.RunTerminalCommand]: "allowedWithPermission", - [BuiltInToolNames.GrepSearch]: "allowedWithoutPermission", - [BuiltInToolNames.FileGlobSearch]: "allowedWithoutPermission", - [BuiltInToolNames.SearchWeb]: "allowedWithoutPermission", - [BuiltInToolNames.FetchUrlContent]: "allowedWithPermission", - [BuiltInToolNames.ViewDiff]: "allowedWithoutPermission", - [BuiltInToolNames.LSTool]: "allowedWithoutPermission", - [BuiltInToolNames.CreateRuleBlock]: "allowedWithPermission", - [BuiltInToolNames.RequestRule]: "disabled", - [BuiltInToolNames.SearchAndReplaceInFile]: "allowedWithPermission", - }, + toolSettings: {}, toolGroupSettings: { [BUILT_IN_GROUP_NAME]: "include", }, @@ -95,7 +76,7 @@ export const uiSlice = createSlice({ // Tools addTool: (state, action: PayloadAction) => { state.toolSettings[action.payload.function.name] = - "allowedWithPermission"; + action.payload.defaultToolPolicy ?? DEFAULT_TOOL_SETTING; }, setToolPolicy: ( state, diff --git a/gui/src/util/migrateLocalStorage.ts b/gui/src/util/migrateLocalStorage.ts index 13beb0eaf..b32babff1 100644 --- a/gui/src/util/migrateLocalStorage.ts +++ b/gui/src/util/migrateLocalStorage.ts @@ -1,9 +1,6 @@ +import { ToolPolicy } from "core"; import { BuiltInToolNames } from "core/tools/builtIn"; -import { - clearToolPolicy, - setToolPolicy, - ToolPolicy, -} from "../redux/slices/uiSlice"; +import { clearToolPolicy, setToolPolicy } from "../redux/slices/uiSlice"; import { AppDispatch } from "../redux/store"; const validPolicyValues: ToolPolicy[] = [