(params: CodebaseSearchParams, task: Task, callbacks: ToolCallbacks)
| 19 | readonly name = "codebase_search" as const |
| 20 | |
| 21 | async execute(params: CodebaseSearchParams, task: Task, callbacks: ToolCallbacks): Promise<void> { |
| 22 | const { askApproval, handleError, pushToolResult } = callbacks |
| 23 | const { query, path: directoryPrefix } = params |
| 24 | |
| 25 | const workspacePath = task.cwd && task.cwd.trim() !== "" ? task.cwd : getWorkspacePath() |
| 26 | |
| 27 | if (!workspacePath) { |
| 28 | await handleError("codebase_search", new Error("Could not determine workspace path.")) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | if (!query) { |
| 33 | task.consecutiveMistakeCount++ |
| 34 | task.didToolFailInCurrentTurn = true |
| 35 | pushToolResult(await task.sayAndCreateMissingParamError("codebase_search", "query")) |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | const sharedMessageProps = { |
| 40 | tool: "codebaseSearch", |
| 41 | query: query, |
| 42 | path: directoryPrefix, |
| 43 | isOutsideWorkspace: false, |
| 44 | } |
| 45 | |
| 46 | const didApprove = await askApproval("tool", JSON.stringify(sharedMessageProps)) |
| 47 | if (!didApprove) { |
| 48 | pushToolResult(formatResponse.toolDenied()) |
| 49 | return |
| 50 | } |
| 51 | |
| 52 | task.consecutiveMistakeCount = 0 |
| 53 | |
| 54 | try { |
| 55 | const context = task.providerRef.deref()?.context |
| 56 | if (!context) { |
| 57 | throw new Error("Extension context is not available.") |
| 58 | } |
| 59 | |
| 60 | const manager = CodeIndexManager.getInstance(context) |
| 61 | |
| 62 | if (!manager) { |
| 63 | throw new Error("CodeIndexManager is not available.") |
| 64 | } |
| 65 | |
| 66 | if (!manager.isFeatureEnabled) { |
| 67 | throw new Error("Code Indexing is disabled in the settings.") |
| 68 | } |
| 69 | if (!manager.isFeatureConfigured) { |
| 70 | throw new Error("Code Indexing is not configured (Missing OpenAI Key or Qdrant URL).") |
| 71 | } |
| 72 | |
| 73 | const searchResults: VectorStoreSearchResult[] = await manager.searchIndex(query, directoryPrefix) |
| 74 | |
| 75 | if (!searchResults || searchResults.length === 0) { |
| 76 | pushToolResult(`No relevant code snippets found for the query: "${query}"`) |
| 77 | return |
| 78 | } |
nothing calls this directly
no test coverage detected