import Link from "next/link";
import { notFound } from "next/navigation";
import { AutoRefresh } from "@/components/AutoRefresh";
import { ago, Badge, Flash, QuestionCard, SessionCard } from "@/components/ui";
import { requireUser } from "@/lib/auth";
import { openspecArtifacts, taskActivity, taskForUser } from "@/lib/queries";
import { db } from "@/lib/db";
import { goals } from "@peppa/db";
import { taskCiSummary } from "@peppa/core";
import { eq } from "drizzle-orm";
import { startTaskSession } from "../../actions";
export default async function TaskPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string }> }) {
const user = await requireUser();
const { key } = await params;
const { error } = await searchParams;
const ref = await taskForUser(user.id, decodeURIComponent(key)).catch(() => null);
if (!ref) notFound();
const { task, project } = ref;
const [goal] = task.goalId ? await db.select().from(goals).where(eq(goals.id, task.goalId)) : [];
const { questions, sessions, events } = await taskActivity(task.id);
const artifacts = openspecArtifacts(project, task.openspecChange);
const ci = await taskCiSummary(db, ref);
const back = `/t/${ref.key}`;
return (
<>
{project.name} {goal && <> · 🎯 {goal.title}>}
{ci.state === "success" ? "✅ " : ci.state === "failure" ? "❌ " : ci.state === "pending" ? "⏳ " : ""} {ci.runUrl ? {ci.label} : ci.label} {ci.sha && · {ci.sha.slice(0, 7)}} {task.ciAttempts > 0 && · красных подряд: {task.ciAttempts}}
{ci.failed.map((f) => ({f.logTail.split("\n").slice(-60).join("\n")}}
{task.description || Без описания}
Вопросов не было.
: questions.map((q) =>{a.text}
Change ещё не создан.
)}