// Story page tabs (PEP-32): OpenSpec artifacts of the change, comments, checks, the PR and // the activity log. Server components; each tab reads only what it shows. import { AgentBadge } from "@/components/AgentBadge"; import { CircleCheck, CircleX, ExternalLink, GitMerge, GitPullRequest, Hourglass, MessageSquare, Send } from "lucide-react"; import type { ChangeArtifacts, CiSummary, CodeReview, DeltaOp, GiteaPull, Question, StoryComment, TasksProgress } from "@peppa/core"; import { attachmentsByEvent, PENDING_ACCEPT_LABEL, reviewLabel, storyOwnAttachments } from "@peppa/core"; import { db } from "@/lib/db"; import { AttachField } from "@/components/AttachField"; import { Attachments } from "@/components/Attachments"; import { Hidden, QuestionCard } from "@/components/cards"; import { Dictate } from "@/components/Dictate"; import { ago, Disclosure, Empty } from "@/components/common"; import { Markdown } from "@/components/Markdown"; import { eventLine } from "@/components/RunnerConsole"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/input"; import { commentHint } from "@/lib/comment-hint"; import { cn } from "@/lib/utils"; import { getT } from "@/lib/i18n"; import { m, translator, type Translator } from "@peppa/shared/i18n"; import { acceptStoryAction, commentStoryAction } from "../../actions"; export const STORY_TABS = [ // PEP-94: names a product manager understands (ids stay — links keep working). { id: "proposal", label: m("План") }, { id: "design", label: m("Как устроено") }, { id: "specs", label: m("Требования") }, { id: "tasks", label: m("Шаги") }, { id: "comments", label: m("Обсуждение") }, { id: "tests", label: m("Проверки") }, { id: "merge", label: m("Результат") }, { id: "activity", label: m("История") }, ] as const; export type StoryTab = (typeof STORY_TABS)[number]["id"]; // glossary-ignore: имя OpenSpec change — техническое, как в main const noChange = (t: Translator, change: string | null) => {change ? t("Change {change} не найден в рабочей копии.", { change }) : t("План ещё не написан — агент составит его, когда возьмёт стори.")}; export async function ArtifactTab({ change, changeId, file }: { change: ChangeArtifacts | null; changeId: string | null; file: "proposal" | "design" }) { const t = await getT(); if (!change) return noChange(t, changeId); const text = change[file]; if (!text) return {file === "design" ? t("Отдельных решений об устройстве не понадобилось — всё есть в плане.") : t("План ещё не написан.")}; return (
); } const OP: Record = { ADDED: { label: m("добавлено"), variant: "ok" }, MODIFIED: { label: m("изменено"), variant: "info" }, REMOVED: { label: m("удалено"), variant: "danger" }, RENAMED: { label: m("переименовано"), variant: "outline" }, }; export async function SpecsTab({ change, changeId }: { change: ChangeArtifacts | null; changeId: string | null }) { const t = await getT(); if (!change) return noChange(t, changeId); if (!change.specs.length) return {t("В change нет дельта-спецификаций (specs/*/spec.md).")}; return (
{change.specs.map((spec) => (

{spec.capability}

{spec.sections.map((sec, si) => (
{sec.requirements.length === 0 &&

{t("{op}: без требований", { op: t(OP[sec.op].label) })}

} {sec.requirements.map((r, ri) => ( {t(OP[sec.op].label)} {r.name} {r.scenarios.length > 0 && {t("сценариев: {n}", { n: r.scenarios.length })}} } >
{r.body && } {r.scenarios.map((sc, i) => (

{t("Сценарий: {name}", { name: sc.name })}

))}
))}
))}
))}
); } export async function TasksTab({ change, changeId, progress }: { change: ChangeArtifacts | null; changeId: string | null; progress: TasksProgress | null }) { const t = await getT(); if (!change) return noChange(t, changeId); if (!progress?.total) return {t("tasks.md ещё нет или в нём нет пунктов.")}; return (
{progress.sections.map((sec, i) => { const done = sec.items.filter((it) => it.done).length; return (

{sec.title || t("Пункты")} {done}/{sec.items.length}

    {sec.items.map((it, j) => (
  • {it.text}
  • ))}
); })}
); } export async function ProgressBar({ done, total, current, compact = false }: { done: number; total: number; current: string | null; compact?: boolean }) { const t = await getT(); const pct = total ? Math.round((done / total) * 100) : 0; return (
{done}/{total}
{current && !compact && {t("Сейчас: {current}", { current })}}
); } type Thread = { at: number; kind: "q"; q: Question } | { at: number; kind: "c"; c: StoryComment }; export async function CommentsTab({ taskId, projectId, taskKey, taskStatus, questions, comments, back, hasLive, refining = false }: { taskId: number; projectId: number; taskKey: string; taskStatus: string; questions: Question[]; comments: StoryComment[]; back: string; hasLive: boolean; refining?: boolean }) { const t = await getT(); // PEP-159: the files of every comment and the story's own. const files = await attachmentsByEvent(db, comments.map((c) => c.id)); const own = await storyOwnAttachments(db, taskId); const thread: Thread[] = [...questions.map((q) => ({ at: q.createdAt.getTime(), kind: "q" as const, q })), ...comments.map((c) => ({ at: c.createdAt.getTime(), kind: "c" as const, c }))].sort((a, b) => a.at - b.at); return (
{own.length > 0 && (

{t("Файлы задачи")}

)} {thread.length === 0 && own.length === 0 && {t("Вопросов и комментариев пока нет.")}} {thread.map((x) => x.kind === "q" ? ( ) : (
{x.c.role ? : } {x.c.role ? (x.c.role === "product" ? t("зачем и что берём") : t("что должно получиться")) : <>{x.c.login} {t("комментарий PM")}} · {ago(x.c.createdAt, t)}

{x.c.text}

), )} {refining && (

{t("Аналитик уточняет постановку…")}

)}