peppa/apps/web/components/ui.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

130 lines
5.4 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 type { Question, SessionView } from "@peppa/core";
import { answerQuestion, messageSession, resumeTaskSession, stopTaskSession } from "@/app/(app)/actions";
const TASK_STATUS: Record<string, string> = {
backlog: "Бэклог",
proposing: "Proposal",
awaiting_approval: "Ждёт одобрения",
in_progress: "В работе",
review: "Ревью",
done: "Готово",
blocked: "Блок",
};
const SESSION_STATUS: Record<string, string> = {
starting: "запуск",
running: "работает",
waiting_input: "ждёт тебя",
idle: "простаивает",
stalled: "зависла?",
rate_limited: "лимит",
done: "завершена",
failed: "упала",
};
const KIND: Record<string, string> = { approval: "Одобрение proposal", question: "Вопрос", permission: "Разрешение", attention: "Сессия ждёт тебя" };
export function Badge({ status, kind = "task" }: { status: string; kind?: "task" | "session" }) {
const label = (kind === "task" ? TASK_STATUS : SESSION_STATUS)[status] ?? status;
return <span className={`badge s-${status}`}>{label}</span>;
}
export function Flash({ error }: { error?: string }) {
return error ? <p className="flash" role="alert">{error}</p> : null;
}
export function ago(d: Date | null | undefined): string {
if (!d) return "—";
const s = Math.round((Date.now() - d.getTime()) / 1000);
if (s < 60) return `${s} с назад`;
if (s < 3600) return `${Math.round(s / 60)} мин назад`;
if (s < 86400) return `${Math.round(s / 3600)} ч назад`;
return d.toLocaleDateString("ru-RU");
}
export function QuestionCard({ q, taskKey, back }: { q: Question; taskKey?: string | null; back: string }) {
const answered = !!q.answeredAt;
return (
<article className={`card q q-${q.kind}${answered ? " answered" : ""}`}>
<header className="row">
<span className="kind">{KIND[q.kind]}</span>
{taskKey && (
<Link href={`/t/${taskKey}`} className="mono">
{taskKey}
</Link>
)}
<span className="muted">#{q.id} · {ago(q.createdAt)}</span>
</header>
<p className="qtext">{q.text}</p>
{answered ? (
<p className="muted">
{q.answeredVia === "system" ? "⌛ " : "✅ "}
{q.answeredVia === "system" ? q.answer : `Ответ (${q.answeredVia}): ${q.answer}`}
</p>
) : (
<form action={answerQuestion} className="answer">
<input type="hidden" name="questionId" value={q.id} />
<input type="hidden" name="back" value={back} />
<div className="row wrap">
{q.kind === "approval" && <button name="choice" value="ок" className="primary">Одобрить</button>}
{q.kind === "permission" && (
<>
<button name="choice" value="allow" className="primary">Разрешить</button>
<button name="choice" value="always">Всегда</button>
<button name="choice" value="deny" className="danger">Запретить</button>
</>
)}
{q.kind === "attention" && <button name="choice" value="Продолжай." className="primary">Продолжай</button>}
{(q.options ?? []).map((o) => (
<button key={o} name="choice" value={o}>{o}</button>
))}
</div>
{q.kind !== "permission" && (
<div className="row">
<input type="text" name="answer" placeholder={q.kind === "approval" ? "Комментарий — вернёт на доработку" : "Свой ответ"} aria-label="Ответ" />
<button>Ответить</button>
</div>
)}
</form>
)}
</article>
);
}
export function SessionCard({ s, back }: { s: SessionView; back: string }) {
const alive = !["done", "failed"].includes(s.status);
return (
<article className="card session">
<header className="row">
<Badge status={s.status} kind="session" />
{s.taskKey && <Link href={`/t/${s.taskKey}`} className="mono">{s.taskKey}</Link>}
<span className="muted">#{s.id} · {s.provider} · поколение {s.generation} · {ago(s.lastActivityAt)}</span>
</header>
<code className="attach">tmux attach -t {s.tmuxName}</code>
<div className="row wrap">
{alive && (
<form action={messageSession} className="row grow">
<input type="hidden" name="sessionId" value={s.id} />
<input type="hidden" name="back" value={back} />
<input type="text" name="text" placeholder="Сообщение в сессию" aria-label="Сообщение в сессию" />
<button>Отправить</button>
</form>
)}
{alive ? (
<form action={stopTaskSession}>
<input type="hidden" name="sessionId" value={s.id} />
<input type="hidden" name="back" value={back} />
<button className="danger">Остановить</button>
</form>
) : null}
{(!alive || ["rate_limited", "stalled"].includes(s.status)) && (
<form action={resumeTaskSession}>
<input type="hidden" name="sessionId" value={s.id} />
<input type="hidden" name="back" value={back} />
<button>Resume</button>
</form>
)}
</div>
</article>
);
}