import { tool } from 'ai';
import { CodeIndexer } from '@upstart.gg/lucerna';
const indexer = new CodeIndexer({ projectRoot: process.cwd() });
await indexer.initialize();
await indexer.indexProject();
export const searchCodeTool = tool({
'Search the codebase for relevant functions, classes, methods, or documentation. ' +
'Use natural language or symbol names.',
query: z.string().describe('Natural language or symbol name'),
limit: z.number().int().min(1).max(20).default(5),
language: z.enum(['typescript', 'javascript', 'json', 'markdown']).optional(),
execute: async ({ query, limit, language }) => {
const results = await indexer.search(query, { limit, language });
return results.map(r => ({
name: r.chunk.name ?? null,
lines: `${r.chunk.startLine}–${r.chunk.endLine}`,
content: r.chunk.content,