From 5ce9ea50f230826ad75d7bc995660a8928d6763f Mon Sep 17 00:00:00 2001 From: MuriloFP Date: Wed, 23 Jul 2025 11:18:22 -0300 Subject: [PATCH] fix: keep tool hidden when disabled/not configured - Only show codebase_search when feature is enabled AND configured - Tool is now visible during indexing (Standby/Indexing states) - Added test to verify tool availability during initialization --- src/core/prompts/tools/index.ts | 7 +++-- .../__tests__/codebaseSearchTool.spec.ts | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/core/prompts/tools/index.ts b/src/core/prompts/tools/index.ts index be3bb3ccd1..ea09280000 100644 --- a/src/core/prompts/tools/index.ts +++ b/src/core/prompts/tools/index.ts @@ -101,8 +101,11 @@ export function getToolDescriptionsForMode( // Add always available tools ALWAYS_AVAILABLE_TOOLS.forEach((tool) => tools.add(tool)) - // Note: codebase_search is now always included in the tool list - // The tool itself will check the indexing state at runtime and provide appropriate feedback + // Conditionally exclude codebase_search if feature is disabled or not configured + // Note: We still show the tool when it's initialized but indexing is in progress + if (!codeIndexManager || !codeIndexManager.isFeatureEnabled || !codeIndexManager.isFeatureConfigured) { + tools.delete("codebase_search") + } // Conditionally exclude update_todo_list if disabled in settings if (settings?.todoListEnabled === false) { diff --git a/src/core/tools/__tests__/codebaseSearchTool.spec.ts b/src/core/tools/__tests__/codebaseSearchTool.spec.ts index b3b5d0d8d9..b6cd5092d8 100644 --- a/src/core/tools/__tests__/codebaseSearchTool.spec.ts +++ b/src/core/tools/__tests__/codebaseSearchTool.spec.ts @@ -243,6 +243,37 @@ describe("codebaseSearchTool", () => { }), ) }) + + it("should be available when enabled and configured but not initialized", async () => { + // This test verifies that the tool is available even when indexing is not complete + // The tool itself will handle the state checking + mockCodeIndexManager.isFeatureEnabled = true + mockCodeIndexManager.isFeatureConfigured = true + mockCodeIndexManager.isInitialized = false + mockCodeIndexManager.state = "Standby" + + const block: ToolUse = { + type: "tool_use", + name: "codebase_search", + params: { query: "test query" }, + partial: false, + } + + await codebaseSearchTool( + mockTask, + block, + mockAskApproval, + mockHandleError, + mockPushToolResult, + mockRemoveClosingTag, + ) + + // Should not throw an error, but should provide feedback about the state + expect(mockHandleError).not.toHaveBeenCalled() + expect(mockPushToolResult).toHaveBeenCalledWith( + expect.stringContaining("Semantic search is not available yet (currently Standby)"), + ) + }) }) describe("parameter validation", () => {