From a6ccb6e7cdb381687916cf31e92404808289892d Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 10:55:11 +0800 Subject: [PATCH 01/20] feat: init tool policy in tools definitions --- core/index.d.ts | 6 ++++ core/tools/definitions/codebaseTool.ts | 1 + core/tools/definitions/createNewFile.ts | 1 + core/tools/definitions/createRuleBlock.ts | 1 + core/tools/definitions/editFile.ts | 1 + core/tools/definitions/fetchUrlContent.ts | 1 + core/tools/definitions/globSearch.ts | 1 + core/tools/definitions/grepSearch.ts | 1 + core/tools/definitions/ls.ts | 1 + .../definitions/readCurrentlyOpenFile.ts | 1 + core/tools/definitions/readFile.ts | 1 + core/tools/definitions/requestRule.ts | 1 + core/tools/definitions/runTerminalCommand.ts | 1 + .../definitions/searchAndReplaceInFile.ts | 1 + core/tools/definitions/searchWeb.ts | 1 + core/tools/definitions/viewDiff.ts | 1 + core/tools/definitions/viewRepoMap.ts | 1 + core/tools/definitions/viewSubdirectory.ts | 1 + gui/src/redux/slices/uiSlice.ts | 35 ++++++++----------- gui/src/util/migrateLocalStorage.ts | 2 +- 20 files changed, 39 insertions(+), 21 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index c2bc7487b..9e017a8f2 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1061,6 +1061,11 @@ export interface ToolExtras { codeBaseIndexer?: CodebaseIndexer; } +export type ToolPolicy = + | "allowedWithPermission" + | "allowedWithoutPermission" + | "disabled"; + export interface Tool { type: "function"; function: { @@ -1080,6 +1085,7 @@ export interface Tool { faviconUrl?: string; group: string; originalFunctionName?: string; + toolPolicy?: ToolPolicy; } interface ToolChoice { diff --git a/core/tools/definitions/codebaseTool.ts b/core/tools/definitions/codebaseTool.ts index fffe51e02..b31b5e680 100644 --- a/core/tools/definitions/codebaseTool.ts +++ b/core/tools/definitions/codebaseTool.ts @@ -26,4 +26,5 @@ export const codebaseTool: Tool = { }, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/createNewFile.ts b/core/tools/definitions/createNewFile.ts index 41bea0b91..397c933b2 100644 --- a/core/tools/definitions/createNewFile.ts +++ b/core/tools/definitions/createNewFile.ts @@ -30,4 +30,5 @@ export const createNewFileTool: Tool = { }, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/createRuleBlock.ts b/core/tools/definitions/createRuleBlock.ts index 92aecb158..71e366080 100644 --- a/core/tools/definitions/createRuleBlock.ts +++ b/core/tools/definitions/createRuleBlock.ts @@ -51,4 +51,5 @@ export const createRuleBlock: Tool = { }, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/editFile.ts b/core/tools/definitions/editFile.ts index 7abd658fc..24ed280c8 100644 --- a/core/tools/definitions/editFile.ts +++ b/core/tools/definitions/editFile.ts @@ -37,4 +37,5 @@ export const editFileTool: Tool = { }, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/fetchUrlContent.ts b/core/tools/definitions/fetchUrlContent.ts index e0122f55b..f2fa3235b 100644 --- a/core/tools/definitions/fetchUrlContent.ts +++ b/core/tools/definitions/fetchUrlContent.ts @@ -25,4 +25,5 @@ export const fetchUrlContentTool: Tool = { }, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/globSearch.ts b/core/tools/definitions/globSearch.ts index 42e8afd2d..b57da84b6 100644 --- a/core/tools/definitions/globSearch.ts +++ b/core/tools/definitions/globSearch.ts @@ -25,4 +25,5 @@ export const globSearchTool: Tool = { }, }, }, + toolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/grepSearch.ts b/core/tools/definitions/grepSearch.ts index 60a4e2710..9f3d4cd34 100644 --- a/core/tools/definitions/grepSearch.ts +++ b/core/tools/definitions/grepSearch.ts @@ -26,4 +26,5 @@ export const grepSearchTool: Tool = { }, }, }, + toolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/ls.ts b/core/tools/definitions/ls.ts index 979f9450b..d49dc288f 100644 --- a/core/tools/definitions/ls.ts +++ b/core/tools/definitions/ls.ts @@ -31,4 +31,5 @@ export const lsTool: Tool = { }, }, }, + toolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/readCurrentlyOpenFile.ts b/core/tools/definitions/readCurrentlyOpenFile.ts index 9c15105a6..972e0e7d0 100644 --- a/core/tools/definitions/readCurrentlyOpenFile.ts +++ b/core/tools/definitions/readCurrentlyOpenFile.ts @@ -19,4 +19,5 @@ export const readCurrentlyOpenFileTool: Tool = { properties: {}, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/readFile.ts b/core/tools/definitions/readFile.ts index 42737fe63..ad59f5a14 100644 --- a/core/tools/definitions/readFile.ts +++ b/core/tools/definitions/readFile.ts @@ -26,4 +26,5 @@ export const readFileTool: Tool = { }, }, }, + toolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/requestRule.ts b/core/tools/definitions/requestRule.ts index cb60cda73..6514d86c2 100644 --- a/core/tools/definitions/requestRule.ts +++ b/core/tools/definitions/requestRule.ts @@ -49,4 +49,5 @@ export const requestRuleTool: GetTool = ({ rules }) => ({ }, }, }, + toolPolicy: "disabled", }); diff --git a/core/tools/definitions/runTerminalCommand.ts b/core/tools/definitions/runTerminalCommand.ts index f9ddd4f9a..3a56c4eff 100644 --- a/core/tools/definitions/runTerminalCommand.ts +++ b/core/tools/definitions/runTerminalCommand.ts @@ -55,4 +55,5 @@ export const runTerminalCommandTool: Tool = { }, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/searchAndReplaceInFile.ts b/core/tools/definitions/searchAndReplaceInFile.ts index 97b79ca4d..422b26a24 100644 --- a/core/tools/definitions/searchAndReplaceInFile.ts +++ b/core/tools/definitions/searchAndReplaceInFile.ts @@ -91,4 +91,5 @@ Each string in the diffs array can contain multiple SEARCH/REPLACE blocks, and a }, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/searchWeb.ts b/core/tools/definitions/searchWeb.ts index d2ce78efc..c75b0d21c 100644 --- a/core/tools/definitions/searchWeb.ts +++ b/core/tools/definitions/searchWeb.ts @@ -25,4 +25,5 @@ export const searchWebTool: Tool = { }, }, }, + toolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/viewDiff.ts b/core/tools/definitions/viewDiff.ts index d835986b0..f80b9a2a1 100644 --- a/core/tools/definitions/viewDiff.ts +++ b/core/tools/definitions/viewDiff.ts @@ -19,4 +19,5 @@ export const viewDiffTool: Tool = { properties: {}, }, }, + toolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/viewRepoMap.ts b/core/tools/definitions/viewRepoMap.ts index dc76e8309..e94f23d14 100644 --- a/core/tools/definitions/viewRepoMap.ts +++ b/core/tools/definitions/viewRepoMap.ts @@ -19,4 +19,5 @@ export const viewRepoMapTool: Tool = { properties: {}, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/viewSubdirectory.ts b/core/tools/definitions/viewSubdirectory.ts index 41c1a904c..20005da80 100644 --- a/core/tools/definitions/viewSubdirectory.ts +++ b/core/tools/definitions/viewSubdirectory.ts @@ -25,4 +25,5 @@ export const viewSubdirectoryTool: Tool = { }, }, }, + toolPolicy: "allowedWithPermission", }; diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index f261ff892..0ea512d4c 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"; @@ -51,19 +46,19 @@ 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", + // [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", }, toolGroupSettings: { [BUILT_IN_GROUP_NAME]: "include", @@ -95,7 +90,7 @@ export const uiSlice = createSlice({ // Tools addTool: (state, action: PayloadAction) => { state.toolSettings[action.payload.function.name] = - "allowedWithPermission"; + action.payload.toolPolicy ?? "allowedWithPermission"; }, setToolPolicy: ( state, diff --git a/gui/src/util/migrateLocalStorage.ts b/gui/src/util/migrateLocalStorage.ts index 13beb0eaf..d03478e06 100644 --- a/gui/src/util/migrateLocalStorage.ts +++ b/gui/src/util/migrateLocalStorage.ts @@ -2,9 +2,9 @@ import { BuiltInToolNames } from "core/tools/builtIn"; import { clearToolPolicy, setToolPolicy, - ToolPolicy, } from "../redux/slices/uiSlice"; import { AppDispatch } from "../redux/store"; +import { ToolPolicy } from "core"; const validPolicyValues: ToolPolicy[] = [ "allowedWithPermission", From d3ef95c5d63bc3e935d8ef392c92e5a1738d0a86 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 11:14:55 +0800 Subject: [PATCH 02/20] fix: Prettier --- gui/src/util/migrateLocalStorage.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gui/src/util/migrateLocalStorage.ts b/gui/src/util/migrateLocalStorage.ts index d03478e06..b32babff1 100644 --- a/gui/src/util/migrateLocalStorage.ts +++ b/gui/src/util/migrateLocalStorage.ts @@ -1,10 +1,7 @@ -import { BuiltInToolNames } from "core/tools/builtIn"; -import { - clearToolPolicy, - setToolPolicy, -} from "../redux/slices/uiSlice"; -import { AppDispatch } from "../redux/store"; import { ToolPolicy } from "core"; +import { BuiltInToolNames } from "core/tools/builtIn"; +import { clearToolPolicy, setToolPolicy } from "../redux/slices/uiSlice"; +import { AppDispatch } from "../redux/store"; const validPolicyValues: ToolPolicy[] = [ "allowedWithPermission", From c9397726aa2a8961fad677c5883c50560f2b488b Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 11:32:12 +0800 Subject: [PATCH 03/20] fix: attempt to pass gui-tests --- .../pages/gui/chat-tests/EditToolScenarios.test.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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, From f6359bd63643c8acb5b91fea1dea63a8fde1fb70 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 11:50:12 +0800 Subject: [PATCH 04/20] fix: attempt to pass / e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 7 +++++-- gui/src/redux/slices/uiSlice.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index e53f2129a..dc9a03b8e 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -287,6 +287,9 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); it("should render tool call", async () => { + // all tool's toolSettings here defaults to allowedWithPermission, which means Ask first + await GUIActions.toggleToolPolicy(view, "view_diff", 1); + const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); await messageInput.sendKeys(Key.ENTER); @@ -304,7 +307,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD * 100); it("should call tool after approval", async () => { - await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -325,7 +328,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); it("should cancel tool", async () => { - await GUIActions.toggleToolPolicy(view, "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/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 0ea512d4c..4f9c10e95 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -90,7 +90,7 @@ export const uiSlice = createSlice({ // Tools addTool: (state, action: PayloadAction) => { state.toolSettings[action.payload.function.name] = - action.payload.toolPolicy ?? "allowedWithPermission"; + action.payload.toolPolicy ?? DEFAULT_TOOL_SETTING; }, setToolPolicy: ( state, From f98088c4f65ea7f8b9d698d6faa8854459167f04 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 12:04:15 +0800 Subject: [PATCH 05/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index dc9a03b8e..9309ec62e 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -287,8 +287,8 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); it("should render tool call", async () => { - // all tool's toolSettings here defaults to allowedWithPermission, which means Ask first - await GUIActions.toggleToolPolicy(view, "view_diff", 1); + // all tool's toolSettings here defaults to "" + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -307,7 +307,8 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD * 100); it("should call tool after approval", async () => { - // await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // all tool's toolSettings here defaults to "" + await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -328,7 +329,8 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); it("should cancel tool", async () => { - // await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // all tool's toolSettings here defaults to "" + await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From 15431be0ca569b490c3eee6b65b1709805a9fda0 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 12:15:06 +0800 Subject: [PATCH 06/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 9309ec62e..02304a81e 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -287,8 +287,8 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); it("should render tool call", async () => { - // all tool's toolSettings here defaults to "" - await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // all tool's toolSettings here defaults to "allowedWithPermission" + await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -307,8 +307,8 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD * 100); it("should call tool after approval", async () => { - // all tool's toolSettings here defaults to "" - await GUIActions.toggleToolPolicy(view, "view_diff", 1); + // all tool's toolSettings here defaults to "allowedWithPermission" + // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -329,8 +329,8 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); it("should cancel tool", async () => { - // all tool's toolSettings here defaults to "" - await GUIActions.toggleToolPolicy(view, "view_diff", 1); + // all tool's toolSettings here defaults to "allowedWithPermission" + // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From da0880545db0bfa36546030b3360029f4ae89303 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 12:24:06 +0800 Subject: [PATCH 07/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 02304a81e..524dc5b95 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -287,8 +287,8 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); it("should render tool call", async () => { - // all tool's toolSettings here defaults to "allowedWithPermission" - await GUIActions.toggleToolPolicy(view, "view_diff", 1); + // all tool's toolSettings here defaults to ? + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -307,7 +307,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD * 100); it("should call tool after approval", async () => { - // all tool's toolSettings here defaults to "allowedWithPermission" + // all tool's toolSettings here defaults to ? // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); @@ -329,7 +329,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); it("should cancel tool", async () => { - // all tool's toolSettings here defaults to "allowedWithPermission" + // all tool's toolSettings here defaults to ? // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); From bdfaa81adbdb4a435a2a3512d79e6c63111122dd Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 12:33:55 +0800 Subject: [PATCH 08/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 524dc5b95..2277401c8 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -15,6 +15,7 @@ import { GUIActions } from "../actions/GUI.actions"; import { DEFAULT_TIMEOUT } from "../constants"; import { GUISelectors } from "../selectors/GUI.selectors"; import { TestUtils } from "../TestUtils"; +import { BuiltInToolNames } from "../../../../core/tools/builtIn"; describe("GUI Test", () => { let view: WebView; @@ -287,8 +288,8 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); it("should render tool call", async () => { - // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // all tool's toolSettings here defaults to "allowedWithPermission", which means Ask first + await GUIActions.toggleToolPolicy(view, BuiltInToolNames.ViewDiff, 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -307,7 +308,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD * 100); it("should call tool after approval", async () => { - // all tool's toolSettings here defaults to ? + // all tool's toolSettings here defaults to "allowedWithPermission", which means Ask first // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); @@ -329,7 +330,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); it("should cancel tool", async () => { - // all tool's toolSettings here defaults to ? + // all tool's toolSettings here defaults to "allowedWithPermission", which means Ask first // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); From eb61cd585be99ff6de0704d101d28e79d9b6dd00 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 12:44:44 +0800 Subject: [PATCH 09/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 2277401c8..0476b5b66 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -288,7 +288,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); it("should render tool call", async () => { - // all tool's toolSettings here defaults to "allowedWithPermission", which means Ask first + // all tool's toolSettings here defaults to ? await GUIActions.toggleToolPolicy(view, BuiltInToolNames.ViewDiff, 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); @@ -308,7 +308,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD * 100); it("should call tool after approval", async () => { - // all tool's toolSettings here defaults to "allowedWithPermission", which means Ask first + // all tool's toolSettings here defaults to ? // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); @@ -330,7 +330,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); it("should cancel tool", async () => { - // all tool's toolSettings here defaults to "allowedWithPermission", which means Ask first + // all tool's toolSettings here defaults to ? // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); From 2bd4762aec2fc98b1bb338776478ae4b2540c3c8 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 12:51:11 +0800 Subject: [PATCH 10/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 0476b5b66..34adb1851 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -15,7 +15,6 @@ import { GUIActions } from "../actions/GUI.actions"; import { DEFAULT_TIMEOUT } from "../constants"; import { GUISelectors } from "../selectors/GUI.selectors"; import { TestUtils } from "../TestUtils"; -import { BuiltInToolNames } from "../../../../core/tools/builtIn"; describe("GUI Test", () => { let view: WebView; @@ -289,7 +288,7 @@ describe("GUI Test", () => { it("should render tool call", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, BuiltInToolNames.ViewDiff, 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From b4924598f5e908849f0bc4f8424368e62bccccd9 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 12:59:12 +0800 Subject: [PATCH 11/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 34adb1851..524dc5b95 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -288,7 +288,7 @@ describe("GUI Test", () => { it("should render tool call", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From 69e0f4c2adac7c90c4add5486e56a5b416178d25 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 13:16:04 +0800 Subject: [PATCH 12/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 524dc5b95..7ec13d69a 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -288,7 +288,7 @@ describe("GUI Test", () => { it("should render tool call", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From 781911a87d37ad8b4e6916f4b003f096464405b6 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Sat, 19 Jul 2025 13:32:56 +0800 Subject: [PATCH 13/20] fix: attempt to pass /e2e/_output/tests/GUI.test.js test --- extensions/vscode/e2e/tests/GUI.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 7ec13d69a..34adb1851 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -288,7 +288,7 @@ describe("GUI Test", () => { it("should render tool call", async () => { // all tool's toolSettings here defaults to ? - // await GUIActions.toggleToolPolicy(view, "view_diff", 2); + await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From 92b9b4828b4ad947e4d98b9ef39a80771a227746 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Wed, 23 Jul 2025 12:33:26 +0800 Subject: [PATCH 14/20] fix: Test that the GUIActions.toggleToolPolicy()method works --- extensions/vscode/e2e/tests/GUI.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 34adb1851..a0bece67b 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -308,7 +308,7 @@ describe("GUI Test", () => { it("should call tool after approval", async () => { // all tool's toolSettings here defaults to ? - // await GUIActions.toggleToolPolicy(view, "view_diff", 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -330,7 +330,7 @@ describe("GUI Test", () => { it("should cancel tool", async () => { // all tool's toolSettings here defaults to ? - // await GUIActions.toggleToolPolicy(view, "view_diff", 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From 8ad03dc4e54d1b71658d19bd36c8a71f92d8cb04 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Wed, 23 Jul 2025 12:44:07 +0800 Subject: [PATCH 15/20] fix: try to pass GUI.test.ts --- extensions/vscode/e2e/tests/GUI.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index a0bece67b..41b3befbf 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -288,7 +288,7 @@ describe("GUI Test", () => { it("should render tool call", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -308,7 +308,7 @@ describe("GUI Test", () => { it("should call tool after approval", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -330,7 +330,7 @@ describe("GUI Test", () => { it("should cancel tool", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 1); + // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); From d1b7b2df59b24a2f7b8b9bd8ee89830d4a729aa3 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Wed, 23 Jul 2025 13:32:51 +0800 Subject: [PATCH 16/20] feat: Add the initialization uiSlice.toolSettings logic. fix: attempt pass GUI.test.ts --- extensions/vscode/e2e/tests/GUI.test.ts | 6 +++--- gui/src/pages/gui/Chat.tsx | 18 ++++++++++++++++++ gui/src/redux/slices/uiSlice.ts | 8 ++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 41b3befbf..2c1be987e 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -288,7 +288,7 @@ describe("GUI Test", () => { it("should render tool call", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // await GUIActions.toggleToolPolicy(view, "view_diff", 0); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -308,7 +308,7 @@ describe("GUI Test", () => { it("should call tool after approval", async () => { // all tool's toolSettings here defaults to ? - await GUIActions.toggleToolPolicy(view, "view_diff", 2); + // await GUIActions.toggleToolPolicy(view, "view_diff", 1); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -330,7 +330,7 @@ describe("GUI Test", () => { it("should cancel tool", async () => { // all tool's toolSettings here defaults to ? - // await GUIActions.toggleToolPolicy(view, "view_diff", 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 7b05087d8..ab1ab53b0 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -48,6 +48,7 @@ import { cancelStream } from "../../redux/thunks/cancelStream"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; import { useAutoScroll } from "./useAutoScroll"; +import { initTool } from "../../redux/slices/uiSlice"; // Helper function to find the index of the latest conversation summary function findLatestSummaryIndex(history: ChatHistoryItem[]): number { @@ -125,6 +126,23 @@ export function Chat() { return isJetBrains(); }, []); + const availableTools = useAppSelector((state) => state.config.config.tools); + // 标记是否已初始化 + const [toolSettingsInitialized, setToolSettingsInitialized] = useState(false); + + useEffect(() => { + if ( + !toolSettingsInitialized && + Array.isArray(availableTools) && + availableTools.length > 0 + ) { + for (const tool of availableTools) { + dispatch(initTool(tool)); + } + setToolSettingsInitialized(true); + } + }, [availableTools, toolSettingsInitialized, dispatch]); + useAutoScroll(stepsDivRef, history); useEffect(() => { diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 4f9c10e95..cbce3134a 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -87,6 +87,13 @@ export const uiSlice = createSlice({ ) => { state.isExploreDialogOpen = action.payload; }, + // Initialize when there is no toolSetting data in the cache + initTool: (state, action: PayloadAction) => { + if (!state.toolSettings[action.payload.function.name]) { + state.toolSettings[action.payload.function.name] = + action.payload.toolPolicy ?? DEFAULT_TOOL_SETTING; + } + }, // Tools addTool: (state, action: PayloadAction) => { state.toolSettings[action.payload.function.name] = @@ -166,6 +173,7 @@ export const { clearToolPolicy, toggleToolGroupSetting, addTool, + initTool, addRule, toggleRuleSetting, setTTSActive, From f7733a65720a8276d99b1c227db4564d6cda016b Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Wed, 23 Jul 2025 13:44:27 +0800 Subject: [PATCH 17/20] fix: attempt pass GUI.test.ts --- extensions/vscode/e2e/tests/GUI.test.ts | 7 +------ gui/src/pages/gui/Chat.tsx | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 2c1be987e..e53f2129a 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -287,9 +287,6 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD); it("should render tool call", async () => { - // all tool's toolSettings here defaults to ? - // await GUIActions.toggleToolPolicy(view, "view_diff", 0); - const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); await messageInput.sendKeys(Key.ENTER); @@ -307,8 +304,7 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.MD * 100); it("should call tool after approval", async () => { - // all tool's toolSettings here defaults to ? - // await GUIActions.toggleToolPolicy(view, "view_diff", 1); + await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); await messageInput.sendKeys("Hello"); @@ -329,7 +325,6 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); it("should cancel tool", async () => { - // all tool's toolSettings here defaults to ? await GUIActions.toggleToolPolicy(view, "view_diff", 2); const [messageInput] = await GUISelectors.getMessageInputFields(view); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index ab1ab53b0..d7e359cfc 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -127,7 +127,7 @@ export function Chat() { }, []); const availableTools = useAppSelector((state) => state.config.config.tools); - // 标记是否已初始化 + // Mark if initialized const [toolSettingsInitialized, setToolSettingsInitialized] = useState(false); useEffect(() => { From 1d773e222d4ea84a0c6fffe0213df1045b968b69 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Mon, 28 Jul 2025 11:24:23 +0800 Subject: [PATCH 18/20] feat: change Tool.toolPolicy to Tool.defaultToolPolicy --- core/index.d.ts | 2 +- core/tools/definitions/codebaseTool.ts | 2 +- core/tools/definitions/createNewFile.ts | 2 +- core/tools/definitions/createRuleBlock.ts | 2 +- core/tools/definitions/editFile.ts | 2 +- core/tools/definitions/fetchUrlContent.ts | 2 +- core/tools/definitions/globSearch.ts | 2 +- core/tools/definitions/grepSearch.ts | 2 +- core/tools/definitions/ls.ts | 2 +- .../definitions/readCurrentlyOpenFile.ts | 2 +- core/tools/definitions/readFile.ts | 2 +- core/tools/definitions/requestRule.ts | 2 +- core/tools/definitions/runTerminalCommand.ts | 2 +- .../definitions/searchAndReplaceInFile.ts | 2 +- core/tools/definitions/searchWeb.ts | 2 +- core/tools/definitions/viewDiff.ts | 2 +- core/tools/definitions/viewRepoMap.ts | 2 +- core/tools/definitions/viewSubdirectory.ts | 2 +- gui/src/redux/slices/uiSlice.ts | 20 +++---------------- 19 files changed, 21 insertions(+), 35 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index b23db94b7..52d11b43d 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1091,7 +1091,7 @@ export interface Tool { faviconUrl?: string; group: string; originalFunctionName?: string; - toolPolicy?: ToolPolicy; + defaultToolPolicy?: ToolPolicy; } interface ToolChoice { diff --git a/core/tools/definitions/codebaseTool.ts b/core/tools/definitions/codebaseTool.ts index b31b5e680..81d5f3374 100644 --- a/core/tools/definitions/codebaseTool.ts +++ b/core/tools/definitions/codebaseTool.ts @@ -26,5 +26,5 @@ export const codebaseTool: Tool = { }, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/createNewFile.ts b/core/tools/definitions/createNewFile.ts index 397c933b2..4bcc0a6b5 100644 --- a/core/tools/definitions/createNewFile.ts +++ b/core/tools/definitions/createNewFile.ts @@ -30,5 +30,5 @@ export const createNewFileTool: Tool = { }, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/createRuleBlock.ts b/core/tools/definitions/createRuleBlock.ts index f10781cd6..d0cf4e993 100644 --- a/core/tools/definitions/createRuleBlock.ts +++ b/core/tools/definitions/createRuleBlock.ts @@ -51,5 +51,5 @@ export const createRuleBlock: Tool = { }, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/editFile.ts b/core/tools/definitions/editFile.ts index 24ed280c8..0fac0b038 100644 --- a/core/tools/definitions/editFile.ts +++ b/core/tools/definitions/editFile.ts @@ -37,5 +37,5 @@ export const editFileTool: Tool = { }, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/fetchUrlContent.ts b/core/tools/definitions/fetchUrlContent.ts index f2fa3235b..6fb6da94f 100644 --- a/core/tools/definitions/fetchUrlContent.ts +++ b/core/tools/definitions/fetchUrlContent.ts @@ -25,5 +25,5 @@ export const fetchUrlContentTool: Tool = { }, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/globSearch.ts b/core/tools/definitions/globSearch.ts index b57da84b6..9fb904fc9 100644 --- a/core/tools/definitions/globSearch.ts +++ b/core/tools/definitions/globSearch.ts @@ -25,5 +25,5 @@ export const globSearchTool: Tool = { }, }, }, - toolPolicy: "allowedWithoutPermission", + defaultToolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/grepSearch.ts b/core/tools/definitions/grepSearch.ts index 9f3d4cd34..79e8cb944 100644 --- a/core/tools/definitions/grepSearch.ts +++ b/core/tools/definitions/grepSearch.ts @@ -26,5 +26,5 @@ export const grepSearchTool: Tool = { }, }, }, - toolPolicy: "allowedWithoutPermission", + defaultToolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/ls.ts b/core/tools/definitions/ls.ts index ebc53ae94..b2ce2c5bd 100644 --- a/core/tools/definitions/ls.ts +++ b/core/tools/definitions/ls.ts @@ -30,5 +30,5 @@ export const lsTool: Tool = { }, }, }, - toolPolicy: "allowedWithoutPermission", + defaultToolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/readCurrentlyOpenFile.ts b/core/tools/definitions/readCurrentlyOpenFile.ts index 972e0e7d0..7309a1f73 100644 --- a/core/tools/definitions/readCurrentlyOpenFile.ts +++ b/core/tools/definitions/readCurrentlyOpenFile.ts @@ -19,5 +19,5 @@ export const readCurrentlyOpenFileTool: Tool = { properties: {}, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/readFile.ts b/core/tools/definitions/readFile.ts index ad59f5a14..831343bfd 100644 --- a/core/tools/definitions/readFile.ts +++ b/core/tools/definitions/readFile.ts @@ -26,5 +26,5 @@ export const readFileTool: Tool = { }, }, }, - toolPolicy: "allowedWithoutPermission", + defaultToolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/requestRule.ts b/core/tools/definitions/requestRule.ts index 6514d86c2..837d013f9 100644 --- a/core/tools/definitions/requestRule.ts +++ b/core/tools/definitions/requestRule.ts @@ -49,5 +49,5 @@ export const requestRuleTool: GetTool = ({ rules }) => ({ }, }, }, - toolPolicy: "disabled", + defaultToolPolicy: "disabled", }); diff --git a/core/tools/definitions/runTerminalCommand.ts b/core/tools/definitions/runTerminalCommand.ts index 4d3d90089..f0b8f2e83 100644 --- a/core/tools/definitions/runTerminalCommand.ts +++ b/core/tools/definitions/runTerminalCommand.ts @@ -55,5 +55,5 @@ export const runTerminalCommandTool: Tool = { }, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/searchAndReplaceInFile.ts b/core/tools/definitions/searchAndReplaceInFile.ts index 422b26a24..52b5c9a52 100644 --- a/core/tools/definitions/searchAndReplaceInFile.ts +++ b/core/tools/definitions/searchAndReplaceInFile.ts @@ -91,5 +91,5 @@ Each string in the diffs array can contain multiple SEARCH/REPLACE blocks, and a }, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/searchWeb.ts b/core/tools/definitions/searchWeb.ts index c75b0d21c..36748fd47 100644 --- a/core/tools/definitions/searchWeb.ts +++ b/core/tools/definitions/searchWeb.ts @@ -25,5 +25,5 @@ export const searchWebTool: Tool = { }, }, }, - toolPolicy: "allowedWithoutPermission", + defaultToolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/viewDiff.ts b/core/tools/definitions/viewDiff.ts index f80b9a2a1..bf1beb25a 100644 --- a/core/tools/definitions/viewDiff.ts +++ b/core/tools/definitions/viewDiff.ts @@ -19,5 +19,5 @@ export const viewDiffTool: Tool = { properties: {}, }, }, - toolPolicy: "allowedWithoutPermission", + defaultToolPolicy: "allowedWithoutPermission", }; diff --git a/core/tools/definitions/viewRepoMap.ts b/core/tools/definitions/viewRepoMap.ts index e94f23d14..9fd0cea42 100644 --- a/core/tools/definitions/viewRepoMap.ts +++ b/core/tools/definitions/viewRepoMap.ts @@ -19,5 +19,5 @@ export const viewRepoMapTool: Tool = { properties: {}, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/core/tools/definitions/viewSubdirectory.ts b/core/tools/definitions/viewSubdirectory.ts index 20005da80..dccdf8dbc 100644 --- a/core/tools/definitions/viewSubdirectory.ts +++ b/core/tools/definitions/viewSubdirectory.ts @@ -25,5 +25,5 @@ export const viewSubdirectoryTool: Tool = { }, }, }, - toolPolicy: "allowedWithPermission", + defaultToolPolicy: "allowedWithPermission", }; diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index cbce3134a..65b4eb7d6 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -45,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", }, @@ -91,13 +77,13 @@ export const uiSlice = createSlice({ initTool: (state, action: PayloadAction) => { if (!state.toolSettings[action.payload.function.name]) { state.toolSettings[action.payload.function.name] = - action.payload.toolPolicy ?? DEFAULT_TOOL_SETTING; + action.payload.defaultToolPolicy ?? DEFAULT_TOOL_SETTING; } }, // Tools addTool: (state, action: PayloadAction) => { state.toolSettings[action.payload.function.name] = - action.payload.toolPolicy ?? DEFAULT_TOOL_SETTING; + action.payload.defaultToolPolicy ?? DEFAULT_TOOL_SETTING; }, setToolPolicy: ( state, From fb44d5bad66d5da11eb373b9ed0c46cf388168be Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Fri, 1 Aug 2025 17:22:39 +0800 Subject: [PATCH 19/20] feat: remove the initialization of tool policy with useEffect, use the defaultToolPolicy as a fallback if a value has not been set by the user in selectActiveTools.ts --- gui/src/pages/gui/Chat.tsx | 18 ------------------ gui/src/redux/selectors/selectActiveTools.ts | 15 ++++++++++----- gui/src/redux/slices/uiSlice.ts | 8 -------- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index d7e359cfc..7b05087d8 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -48,7 +48,6 @@ import { cancelStream } from "../../redux/thunks/cancelStream"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; import { useAutoScroll } from "./useAutoScroll"; -import { initTool } from "../../redux/slices/uiSlice"; // Helper function to find the index of the latest conversation summary function findLatestSummaryIndex(history: ChatHistoryItem[]): number { @@ -126,23 +125,6 @@ export function Chat() { return isJetBrains(); }, []); - const availableTools = useAppSelector((state) => state.config.config.tools); - // Mark if initialized - const [toolSettingsInitialized, setToolSettingsInitialized] = useState(false); - - useEffect(() => { - if ( - !toolSettingsInitialized && - Array.isArray(availableTools) && - availableTools.length > 0 - ) { - for (const tool of availableTools) { - dispatch(initTool(tool)); - } - setToolSettingsInitialized(true); - } - }, [availableTools, toolSettingsInitialized, dispatch]); - useAutoScroll(stepsDivRef, history); useEffect(() => { 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 65b4eb7d6..e350d9f72 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -73,13 +73,6 @@ export const uiSlice = createSlice({ ) => { state.isExploreDialogOpen = action.payload; }, - // Initialize when there is no toolSetting data in the cache - initTool: (state, action: PayloadAction) => { - if (!state.toolSettings[action.payload.function.name]) { - state.toolSettings[action.payload.function.name] = - action.payload.defaultToolPolicy ?? DEFAULT_TOOL_SETTING; - } - }, // Tools addTool: (state, action: PayloadAction) => { state.toolSettings[action.payload.function.name] = @@ -159,7 +152,6 @@ export const { clearToolPolicy, toggleToolGroupSetting, addTool, - initTool, addRule, toggleRuleSetting, setTTSActive, From 161ed3aa9851b0b3d96e919d33219cf7c74eb420 Mon Sep 17 00:00:00 2001 From: QiuYang Shen <1741258352@qq.com> Date: Wed, 6 Aug 2025 01:14:47 +0800 Subject: [PATCH 20/20] feat: try to pass GUI test --- extensions/vscode/e2e/tests/GUI.test.ts | 1 + 1 file changed, 1 insertion(+) 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);