MCPcopy Index your code
hub / github.com/PatrickSys/codebase-context / runSearchCodebase

Function runSearchCodebase

src/eval/discovery-harness.ts:45–75  ·  view source on GitHub ↗
(
  task: DiscoveryTaskType,
  rootPath: string
)

Source from the content-addressed store, hash-verified

43}
44
45async 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
77async function runCodebaseMetadata(
78 _task: DiscoveryTaskType,

Callers

nothing calls this directly

Calls 2

createToolProjectFunction · 0.85
parseJsonPayloadFunction · 0.85

Tested by

no test coverage detected