Skip to content

Commit 5ce9ea5

Browse files
committed
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
1 parent 616cafc commit 5ce9ea5

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/core/prompts/tools/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,11 @@ export function getToolDescriptionsForMode(
101101
// Add always available tools
102102
ALWAYS_AVAILABLE_TOOLS.forEach((tool) => tools.add(tool))
103103

104-
// Note: codebase_search is now always included in the tool list
105-
// The tool itself will check the indexing state at runtime and provide appropriate feedback
104+
// Conditionally exclude codebase_search if feature is disabled or not configured
105+
// Note: We still show the tool when it's initialized but indexing is in progress
106+
if (!codeIndexManager || !codeIndexManager.isFeatureEnabled || !codeIndexManager.isFeatureConfigured) {
107+
tools.delete("codebase_search")
108+
}
106109

107110
// Conditionally exclude update_todo_list if disabled in settings
108111
if (settings?.todoListEnabled === false) {

src/core/tools/__tests__/codebaseSearchTool.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,37 @@ describe("codebaseSearchTool", () => {
243243
}),
244244
)
245245
})
246+
247+
it("should be available when enabled and configured but not initialized", async () => {
248+
// This test verifies that the tool is available even when indexing is not complete
249+
// The tool itself will handle the state checking
250+
mockCodeIndexManager.isFeatureEnabled = true
251+
mockCodeIndexManager.isFeatureConfigured = true
252+
mockCodeIndexManager.isInitialized = false
253+
mockCodeIndexManager.state = "Standby"
254+
255+
const block: ToolUse = {
256+
type: "tool_use",
257+
name: "codebase_search",
258+
params: { query: "test query" },
259+
partial: false,
260+
}
261+
262+
await codebaseSearchTool(
263+
mockTask,
264+
block,
265+
mockAskApproval,
266+
mockHandleError,
267+
mockPushToolResult,
268+
mockRemoveClosingTag,
269+
)
270+
271+
// Should not throw an error, but should provide feedback about the state
272+
expect(mockHandleError).not.toHaveBeenCalled()
273+
expect(mockPushToolResult).toHaveBeenCalledWith(
274+
expect.stringContaining("Semantic search is not available yet (currently Standby)"),
275+
)
276+
})
246277
})
247278

248279
describe("parameter validation", () => {

0 commit comments

Comments
 (0)