peppa/apps/web/app/(app)/t/[key]/page.tsx
Асель 2b0f2fd984 PEP-1: web platform with Gitea login, projects, goals, tasks, sessions
- web: Gitea OAuth2 login, signed session cookie, everything behind login;
  inbox with answers, project board (goals → tasks), task page with
  OpenSpec artifacts, questions and session controls; new project form;
  auto-refresh, light/dark, mobile
- users + projects.owner_id; tokens AES-256-GCM encrypted; owner-only access
- provisionProject (runner): new or existing Gitea repo, peppa-bot
  collaborator, template + openspec init, push, rollback; used by web and
  peppa project create (replaces scripts/bootstrap-project.sh)
- peppa web login-link, peppa project owner; Gitea OAuth app script
- bins/template resolved via PEPPA_ROOT (works inside the Next build)
- testkit: mock-gitea + 10 tests (42 e2e total, all green)
- OpenSpec: pep-1-web-platform archived into specs web-auth,
  project-provisioning, web-workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 20:55:02 +05:00

85 lines
3.6 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 { 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 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>}
<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} 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>
</>
);
}