diff --git a/core/tools/builtIn.ts b/core/tools/builtIn.ts index a7b2ecd61..c5c5da16c 100644 --- a/core/tools/builtIn.ts +++ b/core/tools/builtIn.ts @@ -1,23 +1,23 @@ export enum BuiltInToolNames { - ReadFile = "builtin_read_file", - EditExistingFile = "builtin_edit_existing_file", - SearchAndReplaceInFile = "builtin_search_and_replace_in_file", - ReadCurrentlyOpenFile = "builtin_read_currently_open_file", - CreateNewFile = "builtin_create_new_file", - RunTerminalCommand = "builtin_run_terminal_command", - GrepSearch = "builtin_grep_search", - FileGlobSearch = "builtin_file_glob_search", - SearchWeb = "builtin_search_web", - ViewDiff = "builtin_view_diff", - LSTool = "builtin_ls", - CreateRuleBlock = "builtin_create_rule_block", - RequestRule = "builtin_request_rule", - FetchUrlContent = "builtin_fetch_url_content", - CodebaseTool = "builtin_codebase", + ReadFile = "read_file", + EditExistingFile = "edit_existing_file", + SearchAndReplaceInFile = "search_and_replace_in_file", + ReadCurrentlyOpenFile = "read_currently_open_file", + CreateNewFile = "create_new_file", + RunTerminalCommand = "run_terminal_command", + GrepSearch = "grep_search", + FileGlobSearch = "file_glob_search", + SearchWeb = "search_web", + ViewDiff = "view_diff", + LSTool = "ls", + CreateRuleBlock = "create_rule_block", + RequestRule = "request_rule", + FetchUrlContent = "fetch_url_content", + CodebaseTool = "codebase", // excluded from allTools for now - ViewRepoMap = "builtin_view_repo_map", - ViewSubdirectory = "builtin_view_subdirectory", + ViewRepoMap = "view_repo_map", + ViewSubdirectory = "view_subdirectory", } export const BUILT_IN_GROUP_NAME = "Built-In"; diff --git a/docs/docs/agent/how-it-works.md b/docs/docs/agent/how-it-works.md index 5847b99a5..9253b45d3 100644 --- a/docs/docs/agent/how-it-works.md +++ b/docs/docs/agent/how-it-works.md @@ -28,14 +28,12 @@ In [Chat mode](../chat/how-to-use-it.md), tools are **not** included in the requ Continue includes several built-in tools which provide the model access to IDE functionality: -- **Read file** (`builtin_read_file`): read the contents of a file within the project -- **Read currently open file** (`builtin_read_currently_open_file`): read the contents of the currently open file -- **Create new file** (`builtin_create_new_file`): Create a new file within the project, with path and contents specified by the model -- **Exact search** (`builtin_exact_search`): perform a `ripgrep` search within the project -- **Glob search** (`builtin_file_glob_search`): perform a glob search on files in the project. Currently limits to 100 output and warns the Agent if limit reached. -- **Run terminal command** (`builtin_run_terminal_command`): run a terminal command from the workspace root -- **Search web** (`builtin_search_web`): Perform a web search to get top results -- **View diff** (`builtin_view_diff`): View the current working git diff -- **View repo map** (`builtin_view_repo_map`): request a copy of the repository map—same as the [Repo Map Context Provider](../customize/context-providers.mdx#repository-map) -- **View subdirectory** (`builtin_view_subdirectory`): request a copy of a repo map for a specific directory within the project -- **Create Rule Block** (`builtin_create_rule_block`): creates a new rule block in `.continue/rules` based on the contents of the conversation +- **Read file** (`read_file`): read the contents of a file within the project +- **Read currently open file** (`read_currently_open_file`): read the contents of the currently open file +- **Create new file** (`create_new_file`): Create a new file within the project, with path and contents specified by the model +- **Exact search** (`exact_search`): perform a `ripgrep` search within the project +- **Glob search** (`file_glob_search`): perform a glob search on files in the project. Currently limits to 100 output and warns the Agent if limit reached. +- **Run terminal command** (`run_terminal_command`): run a terminal command from the workspace root +- **Search web** (`search_web`): Perform a web search to get top results +- **View diff** (`view_diff`): View the current working git diff +- **Create Rule Block** (`create_rule_block`): creates a new rule block in `.continue/rules` based on the contents of the conversation diff --git a/docs/docs/customize/deep-dives/rules.mdx b/docs/docs/customize/deep-dives/rules.mdx index 92a006b5e..610878f0c 100644 --- a/docs/docs/customize/deep-dives/rules.mdx +++ b/docs/docs/customize/deep-dives/rules.mdx @@ -48,7 +48,7 @@ Rules can be added locally using the "Add Rules" button while viewing the Local ![add local rules button](/img/add-local-rules.png) :::info Automatically create local rule blocks -When in Agent mode, you can prompt the agent to create a rule for you using the `builtin_create_rule_block` tool if enabled. +When in Agent mode, you can prompt the agent to create a rule for you using the `create_rule_block` tool if enabled. For example, you can say "Create a rule for this", and a rule will be created for you in `.continue/rules` based on your conversation. ::: diff --git a/extensions/vscode/e2e/test-continue-yaml/config.yaml b/extensions/vscode/e2e/test-continue-yaml/config.yaml index 9dfe3ed0e..31d2c4985 100644 --- a/extensions/vscode/e2e/test-continue-yaml/config.yaml +++ b/extensions/vscode/e2e/test-continue-yaml/config.yaml @@ -37,7 +37,7 @@ models: - id: test_id type: function function: - name: builtin_view_diff + name: view_diff - REPEAT_LAST_MSG roles: - chat diff --git a/extensions/vscode/e2e/test-continue/config.json b/extensions/vscode/e2e/test-continue/config.json index e6b610f6a..fbe78fa0a 100644 --- a/extensions/vscode/e2e/test-continue/config.json +++ b/extensions/vscode/e2e/test-continue/config.json @@ -36,7 +36,7 @@ "id": "test_id", "type": "function", "function": { - "name": "builtin_view_diff" + "name": "view_diff" } } ] diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index b05302226..a709266ec 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -304,7 +304,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD * 100); it("should call tool after approval", async () => { - await GUIActions.toggleToolPolicy(view, "builtin_view_diff", 2); + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -325,7 +325,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); it("should cancel tool", async () => { - await GUIActions.toggleToolPolicy(view, "builtin_view_diff", 2); + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index 246e92ce6..862cb6ca3 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -38,6 +38,7 @@ import { } from "../styles/theme"; import { isJetBrains } from "../util"; import { setLocalStorage } from "../util/localStorage"; +import { migrateLocalStorage } from "../util/migrateLocalStorage"; import { useWebviewListener } from "./useWebviewListener"; function ParallelListeners() { @@ -310,6 +311,10 @@ function ParallelListeners() { } }, [isInEdit, history]); + useEffect(() => { + migrateLocalStorage(dispatch); + }, []); + return <>; } diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx index 9f867356e..d8a1f0dec 100644 --- a/gui/src/pages/gui/ToolCallDiv/index.tsx +++ b/gui/src/pages/gui/ToolCallDiv/index.tsx @@ -46,9 +46,9 @@ const toolCallIcons: Record = { [BuiltInToolNames.ViewRepoMap]: MapIcon, [BuiltInToolNames.ViewSubdirectory]: FolderOpenIcon, [BuiltInToolNames.CreateRuleBlock]: PencilIcon, - // EditExistingFile = "builtin_edit_existing_file", - // CreateNewFile = "builtin_create_new_file", - // RunTerminalCommand = "builtin_run_terminal_command", + // EditExistingFile + // CreateNewFile + // RunTerminalCommand }; function getStatusIcon(state: ToolStatus) { diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 0efcfe2ce..65350d7c8 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -106,6 +106,18 @@ export const uiSlice = createSlice({ state.toolSettings[action.payload.function.name] = "allowedWithPermission"; }, + setToolPolicy: ( + state, + action: PayloadAction<{ + toolName: string; + policy: ToolPolicy; + }>, + ) => { + state.toolSettings[action.payload.toolName] = action.payload.policy; + }, + clearToolPolicy: (state, action: PayloadAction) => { + delete state.toolSettings[action.payload]; + }, toggleToolSetting: (state, action: PayloadAction) => { const setting = state.toolSettings[action.payload]; @@ -166,6 +178,8 @@ export const { setIsExploreDialogOpen, setHasDismissedExploreDialog, toggleToolSetting, + setToolPolicy, + clearToolPolicy, toggleToolGroupSetting, addTool, addRule, diff --git a/gui/src/util/migrateLocalStorage.ts b/gui/src/util/migrateLocalStorage.ts new file mode 100644 index 000000000..13beb0eaf --- /dev/null +++ b/gui/src/util/migrateLocalStorage.ts @@ -0,0 +1,74 @@ +import { BuiltInToolNames } from "core/tools/builtIn"; +import { + clearToolPolicy, + setToolPolicy, + ToolPolicy, +} from "../redux/slices/uiSlice"; +import { AppDispatch } from "../redux/store"; + +const validPolicyValues: ToolPolicy[] = [ + "allowedWithPermission", + "allowedWithoutPermission", + "disabled", +]; +function migrateToolPolicies(dispatch: AppDispatch) { + const toFromMap: Record = { + [BuiltInToolNames.ReadFile]: ["builtin_read_file"], + [BuiltInToolNames.EditExistingFile]: ["builtin_edit_existing_file"], + [BuiltInToolNames.SearchAndReplaceInFile]: [ + "builtin_search_and_replace_in_file", + ], + [BuiltInToolNames.ReadCurrentlyOpenFile]: [ + "builtin_read_currently_open_file", + ], + [BuiltInToolNames.CreateNewFile]: ["builtin_create_new_file"], + [BuiltInToolNames.RunTerminalCommand]: ["builtin_run_terminal_command"], + [BuiltInToolNames.GrepSearch]: ["builtin_grep_search"], + [BuiltInToolNames.FileGlobSearch]: ["builtin_file_glob_search"], + [BuiltInToolNames.SearchWeb]: ["builtin_search_web"], + [BuiltInToolNames.ViewDiff]: ["builtin_view_diff"], + [BuiltInToolNames.LSTool]: ["builtin_ls"], + [BuiltInToolNames.CreateRuleBlock]: ["builtin_create_rule_block"], + [BuiltInToolNames.RequestRule]: ["builtin_request_rule"], + [BuiltInToolNames.FetchUrlContent]: ["builtin_fetch_url_content"], + [BuiltInToolNames.CodebaseTool]: ["builtin_codebase"], + [BuiltInToolNames.ViewRepoMap]: ["builtin_view_repo_map"], + [BuiltInToolNames.ViewSubdirectory]: ["builtin_view_subdirectory"], + }; + const persistedRedux = localStorage.getItem("persist:root"); + if (persistedRedux) { + const uiState = JSON.parse(persistedRedux)?.ui; + if (uiState) { + const parsedSettings = JSON.parse(uiState)?.toolSettings; + if (parsedSettings) { + let migratedToolSettings = 0; + Object.entries(toFromMap).forEach(([newToolName, oldToolNames]) => { + for (const tool of oldToolNames) { + if ( + tool in parsedSettings && + validPolicyValues.includes(parsedSettings[tool]) + ) { + dispatch( + setToolPolicy({ + toolName: newToolName, + policy: parsedSettings[tool], + }), + ); + dispatch(clearToolPolicy(tool)); + migratedToolSettings++; + } + } + }); + if (migratedToolSettings > 0) { + console.log( + `Migrated ${migratedToolSettings} tool policies successfully.`, + ); + } + } + } + } +} + +export function migrateLocalStorage(dispatch: AppDispatch) { + migrateToolPolicies(dispatch); +}