( task: DiscoveryTaskType, rootPath: string )
| 43 | } |
| 44 | |
| 45 | async function runSearchCodebase( |
| 46 | task: DiscoveryTaskType, |
| 47 | rootPath: string |
| 48 | ): Promise<DiscoverySurfaceResultType> { |
| 49 | const project = createToolProject(rootPath); |
| 50 | const response = await searchCodebaseHandle(task.args ?? { query: task.prompt }, { |
| 51 | indexState: project.indexState, |
| 52 | paths: project.paths, |
| 53 | rootPath: project.rootPath, |
| 54 | performIndexing: () => undefined |
| 55 | }); |
| 56 | const payload = response.content?.[0]?.text ?? '{}'; |
| 57 | const parsed = parseJsonPayload(payload) as SearchResponse & JsonRecord; |
| 58 | const results = Array.isArray(parsed.results) ? parsed.results : []; |
| 59 | const topFiles = results |
| 60 | .map((entry) => (typeof entry.file === 'string' ? entry.file.split(':')[0] : '')) |
| 61 | .filter((entry): entry is string => Boolean(entry)); |
| 62 | const preflight = parsed.preflight; |
| 63 | const bestExample = |
| 64 | preflight && typeof preflight === 'object' && preflight !== null && 'bestExample' in preflight |
| 65 | ? ((preflight.bestExample as string | undefined) ?? null) |
| 66 | : typeof parsed.bestExample === 'string' |
| 67 | ? parsed.bestExample |
| 68 | : null; |
| 69 | |
| 70 | return { |
| 71 | payload, |
| 72 | topFiles, |
| 73 | bestExample |
| 74 | }; |
| 75 | } |
| 76 | |
| 77 | async function runCodebaseMetadata( |
| 78 | _task: DiscoveryTaskType, |
nothing calls this directly
no test coverage detected