MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / execute

Method execute

src/core/tools/CodebaseSearchTool.ts:21–129  ·  view source on GitHub ↗
(params: CodebaseSearchParams, task: Task, callbacks: ToolCallbacks)

Source from the content-addressed store, hash-verified

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 }

Callers

nothing calls this directly

Calls 10

getWorkspacePathFunction · 0.90
handleErrorFunction · 0.85
pushToolResultFunction · 0.85
askApprovalFunction · 0.85
forEachMethod · 0.80
asRelativePathMethod · 0.80
sayMethod · 0.80
searchIndexMethod · 0.65
getInstanceMethod · 0.45

Tested by

no test coverage detected