import { NextResponse } from 'next/server'; import * as fs from 'fs'; import * as path from 'path'; export async function GET() { const analysesDir = path.resolve(process.cwd(), '..', 'analyses'); try { if (!fs.existsSync(analysesDir)) { return NextResponse.json({ discoveries: [] }); } const files = fs.readdirSync(analysesDir) .filter(f => f.startsWith('discovery_') && f.endsWith('.json')) .sort((a, b) => b.localeCompare(a)); // Newest first const discoveries = files.map(file => { const filePath = path.join(analysesDir, file); const content = fs.readFileSync(filePath, 'utf-8'); const data = JSON.parse(content); return { id: data.id, capability_gap: data.capability_gap, timestamp: data.timestamp, candidate_count: data.candidates?.length || 0, top_score: data.candidates?.[0]?.score || 0, }; }); return NextResponse.json({ discoveries }); } catch (error) { console.error('Failed to list discoveries:', error); return NextResponse.json({ discoveries: [], error: String(error) }); } }