import { listRuns, listWorkers, overviewCounts } from "@autoscholar/core"; import { papers, securityEvents } from "@autoscholar/db"; import { STAGES } from "@autoscholar/schemas"; import { desc, sql } from "drizzle-orm"; import Link from "next/link"; import { StatusBadge } from "@/components/StatusBadge"; import { ago, fmtDateTime, fmtUsd } from "@/lib/format"; import { db } from "@/lib/server/db"; export const dynamic = "force-dynamic"; export default async function Overview() { const d = db(); const counts = await overviewCounts(d); const workers = await listWorkers(d); const [pubs] = await d.select({ n: sql`count(*)::int` }).from(papers); const alerts = await d.select().from(securityEvents).orderBy(desc(securityEvents.createdAt)).limit(8); const recent = await listRuns(d, { limit: 10 }); const active = recent.filter((r) => ["running", "provisioning", "queued", "retrying", "quality_check", "publishing"].includes(r.status), ); const tiles: Array<[string, number, string]> = [ [ "Running", (counts.byStatus.running ?? 0) + (counts.byStatus.provisioning ?? 0), "var(--color-info-500)", ], ["Queued", (counts.byStatus.queued ?? 0) + (counts.byStatus.retrying ?? 0), "var(--fg-muted)"], [ "Needs attention", (counts.byStatus.quality_failed ?? 0) + (counts.byStatus.awaiting_approval ?? 0), "var(--color-warn-500)", ], ["Published", counts.byStatus.published ?? 0, "var(--color-ok-500)"], [ "Failed / cancelled", (counts.byStatus.failed ?? 0) + (counts.byStatus.cancelled ?? 0), "var(--color-danger-500)", ], ]; const online = workers.filter((w) => w.status === "online" || w.status === "draining"); return (

Command center

Overview

New research
{tiles.map(([l, n, c]) => (

{l}

0 ? c : undefined }}> {n}

))}

Provider spend

{fmtUsd(counts.totalCostUsd)}

client-side estimate

{active.length > 0 && (

Active research

    {active.map((r) => { const idx = STAGES.findIndex((s) => s.key === r.currentStage); const pct = Math.max(4, Math.round(((idx + 1) / STAGES.length) * 100)); return (
  • {r.title}

    {r.id}

    {r.currentStage ?? "—"} {idx >= 0 ? `${idx + 1}/${STAGES.length}` : ""}
    {fmtUsd(r.totalCostUsd)} · {ago(r.updatedAt)}
  • ); })}
)}

MacLustr workers

Details

{online.length} of {workers.length} online · {pubs?.n ?? 0} publications

    {workers.length === 0 && (
  • No worker has enrolled yet. Install the worker daemon on a MacLustr node (docs/OPERATIONS.md).
  • )} {workers.map((w) => (
  • {w.name} {w.running}/{w.capacity} · {ago(w.lastHeartbeatAt)}
  • ))}

Security alerts

Audit log
    {alerts.length === 0 &&
  • No security events recorded.
  • } {alerts.map((a) => (
  • {a.kind}{" "} {JSON.stringify(a.detail).slice(0, 80)} {fmtDateTime(a.createdAt)}
  • ))}

Recent runs

All runs
{recent.length === 0 && ( )} {recent.map((r) => ( ))}
Title Status Stage Attempt Cost Updated
No runs yet. Upload a research instruction to start.
{r.title} {r.currentStage ?? "—"} {r.currentAttemptNo}/{r.maxAttempts} {fmtUsd(r.totalCostUsd)} {ago(r.updatedAt)}
); }