peppa/apps/web/components/common.tsx
Асель 094ab632cc PEP-152: формат сообщения агента — суть, что нужно от вас, где посмотреть, подробности под «Подробнее»
Сообщение агента пользователю собирается из полей summary / need / link / details
(core/agent-message.ts); основной текст проверяется при приёме (длина, словарь, файлы,
ветки, команды, номера PR, статусы из кода) — нарушение возвращается агенту, после трёх
отказов подряд сообщение уходит с нейтральной первой строкой. Разбор словаря — общий
модуль @peppa/shared/glossary. Сайт и Telegram показывают основной текст, details — под
«Подробнее». Карточка «готово» и реплика конца хода — в том же формате. Правила агентам,
переводы en/kk, тесты по сценариям, change pep-152-agent-message-format в архиве.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 17:38:04 +05:00

122 lines
5.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.

// Page building blocks of the console (PEP-38): header, sections, empty states, status badges, alerts.
import Link from "next/link";
import type { ReactNode } from "react";
import { CircleAlert, CircleCheck } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { SESSION_STATUS, TASK_STATUS, TONE_BG } from "@/lib/status";
import { cn } from "@/lib/utils";
import { getT } from "@/lib/i18n";
import { intlLocale, type Translator } from "@peppa/shared/i18n";
export function PageHeader({ title, crumbs, actions, children }: { title: ReactNode; crumbs?: ReactNode; actions?: ReactNode; children?: ReactNode }) {
return (
<header className="mb-6 flex flex-col gap-1.5">
{crumbs && <div className="flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">{crumbs}</div>}
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
<h1 className="m-0 flex min-w-0 flex-wrap items-center gap-2 text-xl font-semibold tracking-tight md:text-2xl">{title}</h1>
{actions && <div className="ml-auto flex flex-wrap items-center gap-2">{actions}</div>}
</div>
{children && <div className="text-sm text-muted-foreground">{children}</div>}
</header>
);
}
export function Section({ title, count, actions, children, className, id }: { title: ReactNode; count?: number; actions?: ReactNode; children: ReactNode; className?: string; id?: string }) {
return (
<section id={id} className={cn("mt-8 flex flex-col gap-3 first:mt-0", className)}>
<div className="flex flex-wrap items-center gap-2">
<h2 className="m-0 text-[15px] font-semibold">{title}</h2>
{count != null && count > 0 && <span className="rounded-full bg-primary px-2 font-mono text-[11px] leading-5 font-semibold text-primary-foreground tabular-nums">{count}</span>}
{actions && <div className="ml-auto flex items-center gap-2 text-sm">{actions}</div>}
</div>
{children}
</section>
);
}
export function MoreLink({ href, children }: { href: string; children: ReactNode }) {
return (
<Link href={href} className="text-xs text-muted-foreground hover:text-foreground">
{children} →
</Link>
);
}
export function Empty({ children }: { children: ReactNode }) {
return <p className="m-0 rounded-lg border border-dashed px-4 py-5 text-center text-sm text-muted-foreground">{children}</p>;
}
/** Monospace task/project key, optionally a link. */
export function Key({ children, href, className }: { children: ReactNode; href?: string; className?: string }) {
const cls = cn("font-mono text-[0.9em] whitespace-nowrap", href ? "text-primary hover:underline" : "text-muted-foreground", className);
return href ? <Link href={href} className={cls}>{children}</Link> : <span className={cls}>{children}</span>;
}
export async function StatusBadge({ status, kind = "task" }: { status: string; kind?: "task" | "session" }) {
const t = await getT();
const s = (kind === "task" ? TASK_STATUS : SESSION_STATUS)[status] ?? { label: status, tone: "muted" as const };
return (
<Badge variant={s.tone}>
{kind === "session" && <span className={cn("size-1.5 rounded-full", TONE_BG[s.tone], status === "running" && "animate-pulse")} />}
{t.text(s.label)}
</Badge>
);
}
export async function Flash({ error }: { error?: string }) {
const t = await getT();
return error ? (
// Sticky: an action far down the page (a board card, «Принять») must not fail silently above the fold.
<p role="alert" className="sticky top-2 z-40 mb-4 flex items-start gap-2 rounded-lg border border-destructive/60 bg-[color-mix(in_oklab,var(--destructive)_14%,var(--background))] px-4 py-3 text-sm text-foreground shadow-lg">
<CircleAlert className="mt-0.5 size-4 shrink-0 text-destructive" />
<span>{t.text(error)}</span>
</p>
) : null;
}
export function Notice({ children }: { children: ReactNode }) {
return (
<div role="status" className="mb-4 flex flex-wrap items-center gap-2 rounded-lg border border-ok/40 bg-ok/10 px-4 py-3 text-sm">
<CircleCheck className="size-4 shrink-0 text-ok" />
{children}
</div>
);
}
/** Collapsible block styled as a card (native <details>: no client JS). */
export function Disclosure({ summary, children, open, className }: { summary: ReactNode; children: ReactNode; open?: boolean; className?: string }) {
return (
<details open={open} className={cn("group rounded-lg border bg-card", className)}>
<summary className="flex cursor-pointer list-none items-center gap-2 px-4 py-2.5 text-sm font-medium select-none [&::-webkit-details-marker]:hidden">
<span className="text-muted-foreground transition-transform group-open:rotate-90">›</span>
{summary}
</summary>
<div className="border-t px-4 py-3">{children}</div>
</details>
);
}
/** «5 мин назад» in the page's language. */
export function ago(d: Date | null | undefined, t: Translator): string {
if (!d) return "—";
const s = Math.round((Date.now() - d.getTime()) / 1000);
if (s < 60) return t("{n} с назад", { n: s });
if (s < 3600) return t("{n} мин назад", { n: Math.round(s / 60) });
if (s < 86400) return t("{n} ч назад", { n: Math.round(s / 3600) });
return d.toLocaleDateString(intlLocale(t.locale));
}
/** Text with its http(s) addresses as links. */
export function linkify(text: string) {
return text.split(/(https?:\/\/[^\s<>«»"]+[^\s<>«»".,;:!?)])/g).map((part, i) =>
i % 2 ? (
<a key={i} href={part} target={part.startsWith(process.env.PEPPA_WEB_URL ?? "\0") ? undefined : "_blank"} rel="noreferrer">
{part}
</a>
) : (
part
),
);
}