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
This commit is contained in:
MuriloFP 2025-07-23 11:18:22 -03:00
parent 616cafc3a1
commit 5ce9ea50f2
2 changed files with 36 additions and 2 deletions

View file

@ -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) {

View file

@ -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", () => {