peppa/apps/web/components/ui.tsx
Асель c24b9b83be PEP-15: where the project's repo is in Gitea — link, visibility, namespace
- New project form: namespace (personal/org) and visibility (private/public) with hints
- provisionProject creates the repo with the chosen visibility (existing repo keeps its own)
- After creation: notice with "Открыть в Gitea"; project page "Репозиторий" block:
  path, namespace kind, visibility, who can see it (read live from Gitea, cached 60 s)
- Members without repo access are marked; owner can grant access to all members
- MCP create_project takes visibility and returns repo URL + who sees it; list_projects shows URLs
- CLI --public, /help, mock-gitea (visibility, /orgs, collaborators), e2e repo-visibility

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 14:12:07 +05:00

161 lines
6.7 KiB
TypeScript
Raw Permalink 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 { ReactNode } from "react";
import type { Project, 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 Notice({ children }: { children: ReactNode }) {
return <p className="notice" role="status">{children}</p>;
}
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, taskStatus, back }: { q: Question; taskKey?: string | null; taskStatus?: string | null; back: string }) {
const review = q.kind === "attention" && taskStatus === "review";
const answered = !!q.answeredAt;
return (
<article className={`card q q-${q.kind}${answered ? " answered" : ""}`}>
<header className="row">
<span className="kind">{review ? "Готово к ревью" : 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>
</>
)}
{review && <button name="choice" value="__accept" className="primary">Принять</button>}
{q.kind === "attention" && !review && <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" || review ? "Замечание — вернёт на доработку" : "Свой ответ"} aria-label="Ответ" />
<button>Ответить</button>
</div>
)}
</form>
)}
</article>
);
}
export function SessionCard({ s, back, showTitle = false }: { s: SessionView; back: string; showTitle?: boolean }) {
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> : <Link href={`/p/${s.projectKey}`} className="mono">{s.projectKey}</Link>}
{showTitle && s.taskTitle && <span className="title">{s.taskTitle}</span>}
<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>
);
}
export function ProjectList({ projects, userId }: { projects: Project[]; userId: number }) {
if (!projects.length)
return (
<p className="empty">
Проектов пока нет. <Link href="/projects/new">Создать первый</Link>
</p>
);
return (
<ul className="projects">
{projects.map((p) => (
<li key={p.id}>
<Link href={`/p/${p.key}`}>
<span className="mono">{p.key}</span> {p.name}
</Link>
<span className="muted">
{p.ownerId !== userId && <span className="badge">общий</span>} {p.giteaOwner}/{p.giteaRepo}
</span>
</li>
))}
</ul>
);
}