peppa/apps/web/app/(app)/t/[key]/page.tsx
Асель cae49d5b54 PEP-57: CI feedback — check runs, red checks back to the agent, review/merge gates
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 14:37:10 +05:00

104 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 (
<>
<AutoRefresh />
<Flash error={error} />
<p className="crumbs">
<Link href={`/p/${project.key}`}>{project.name}</Link>
{goal && <> · 🎯 {goal.title}</>}
</p>
<h1>
<span className="mono">{ref.key}</span> {task.title} <Badge status={task.status} />
</h1>
{task.prUrl && <p><a href={task.prUrl}>PR</a></p>}
<section className="checks">
<h2>Проверки</h2>
<p>
{ci.state === "success" ? "✅ " : ci.state === "failure" ? "❌ " : ci.state === "pending" ? "⏳ " : ""}
{ci.runUrl ? <a href={ci.runUrl}>{ci.label}</a> : ci.label}
{ci.sha && <span className="mono muted"> · {ci.sha.slice(0, 7)}</span>}
{task.ciAttempts > 0 && <span className="muted"> · красных подряд: {task.ciAttempts}</span>}
</p>
{ci.failed.map((f) => (
<details key={f.check}>
<summary>
❌ <span className="mono">{f.check}</span> {f.runUrl && <a href={f.runUrl}>лог</a>}
</summary>
{f.logTail && <pre className="md">{f.logTail.split("\n").slice(-60).join("\n")}</pre>}
</details>
))}
</section>
<p className="desc">{task.description || <span className="muted">Без описания</span>}</p>
<section>
<h2>Сессии</h2>
<form action={startTaskSession} className="row wrap">
<input type="hidden" name="taskKey" value={ref.key} />
<input type="hidden" name="back" value={back} />
<select name="provider" defaultValue="claude" aria-label="Агент">
<option value="claude">Claude Code</option>
<option value="codex">Codex</option>
</select>
<input type="text" name="prompt" placeholder="Доп. инструкция (необязательно)" aria-label="Доп. инструкция" className="grow" />
<button className="primary">Запустить агента</button>
</form>
{sessions.map((s) => <SessionCard key={s.id} s={s} back={back} />)}
</section>
<section>
<h2>Вопросы</h2>
{questions.length === 0 ? <p className="empty">Вопросов не было.</p> : questions.map((q) => <QuestionCard key={q.id} q={q} taskStatus={task.status} back={back} />)}
</section>
<section>
<h2>OpenSpec {task.openspecChange && <span className="mono muted">{task.openspecChange}</span>}</h2>
{artifacts?.length ? (
artifacts.map((a) => (
<details key={a.name} open={a.name === "proposal.md"}>
<summary className="mono">{a.name}</summary>
<pre className="md">{a.text}</pre>
</details>
))
) : (
<p className="empty">Change ещё не создан.</p>
)}
</section>
<section>
<h2>События</h2>
<ul className="events">
{events.map((e) => (
<li key={e.id}>
<span className="muted">{ago(e.createdAt)}</span> <span className="mono">{e.type}</span>{" "}
{e.type === "progress" ? (e.payload as { text: string }).text : e.type === "task_updated" ? JSON.stringify((e.payload as { to: unknown }).to) : ""}
</li>
))}
</ul>
</section>
</>
);
}