(args, extras)
| 4 | import { getStringArg } from "../parseArgs"; |
| 5 | |
| 6 | export const codebaseToolImpl: ToolImpl = async (args, extras) => { |
| 7 | const query = getStringArg(args, "query"); |
| 8 | |
| 9 | try { |
| 10 | const contextExtras = { |
| 11 | config: extras.config, |
| 12 | fullInput: query, |
| 13 | embeddingsProvider: extras.config.selectedModelByRole.embed, |
| 14 | reranker: extras.config.selectedModelByRole.rerank, |
| 15 | llm: extras.llm, |
| 16 | ide: extras.ide, |
| 17 | selectedCode: [] as RangeInFile[], |
| 18 | fetch: extras.fetch, |
| 19 | isInAgentMode: true, // always true in tool call |
| 20 | }; |
| 21 | |
| 22 | // Use the existing retrieval function to get context items |
| 23 | const results = await retrieveContextItemsFromEmbeddings( |
| 24 | contextExtras, |
| 25 | undefined, |
| 26 | undefined, |
| 27 | ); |
| 28 | |
| 29 | // If no results found, return helpful message |
| 30 | if (results.length === 0) { |
| 31 | return [ |
| 32 | { |
| 33 | name: "No Results", |
| 34 | description: "Codebase search", |
| 35 | content: `No relevant code found for query: "${query}". This could mean: |
| 36 | - The codebase hasn't been indexed yet |
| 37 | - No code matches the search criteria |
| 38 | - Embeddings provider is not configured |
| 39 | |
| 40 | Try re-indexing the codebase or using a more specific query.`, |
| 41 | }, |
| 42 | ]; |
| 43 | } |
| 44 | |
| 45 | return results; |
| 46 | } catch (error) { |
| 47 | return [ |
| 48 | { |
| 49 | name: "Error", |
| 50 | description: "Codebase search error", |
| 51 | content: `Failed to search codebase: ${error instanceof Error ? error.message : String(error)}`, |
| 52 | }, |
| 53 | ]; |
| 54 | } |
| 55 | }; |
no test coverage detected