import { decisionCounts, indexHealth, listFolders, listProjects } from "@/lib/projects"; export const dynamic = "force-dynamic"; // Every project, as JSON. The index page's data, for an agent or a script. // // `x-index` reports how much of that came from the persistent index and how much // was read fresh. It is the only place the index is observable at all, which is // the intent: a stale index self-heals on the next load and the user sees // nothing but latency, so the health has to be surfaced deliberately or not at // all. The specs assert on it. export async function GET(request: Request) { const url = new URL(request.url); const projects = await listProjects(); const health = indexHealth(); const counts = url.searchParams.get("decisions") === "1" ? await decisionCounts() : null; const folders = [...(await listFolders()).values()]; return Response.json( { projects: counts ? projects.map((p) => ({ ...p, decisions: counts.get(p.id) ?? null })) : projects, folders, }, { headers: { "cache-control": "no-store", "x-index": health.ok ? `${health.fresh}/${health.total} fresh` : "off", }, }, ); }