«Peppa FACTORY» → «FORGE» в экранах, сообщениях, словарях en/kk, шаблоне и тестах; «Пеппа» → «FORGE» в подсказках агентам и правилах; логотип, значок, версия кэша service worker; в словаре старые названия — в «Нельзя». Внутренние имена (CLI peppa, PEPPA_*, MCP-сервер peppa, ключи PEP-N) не меняются. Второй адрес — в mac-route.sh. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
395 lines
21 KiB
TypeScript
395 lines
21 KiB
TypeScript
// Project page tabs «Код», «Спеки», «PR» and the epics block of «⋯ Настройки проекта» (PEP-66).
|
||
import type { Words } from "@peppa/shared/wording";
|
||
import { Archive, ExternalLink, GitBranch, GitPullRequest, Pencil } from "lucide-react";
|
||
import type { Epic, SpecSummary } from "@peppa/core";
|
||
import { Markdown } from "@/components/Markdown";
|
||
import type { AgentsMd, OpenPull, RepoOverview } from "@peppa/runner";
|
||
import { addEpic, editEpic, saveAgentsMdAction } from "../../actions";
|
||
import { Hidden } from "@/components/cards";
|
||
import { Disclosure, Empty, Key, Notice, Section, StatusBadge } from "@/components/common";
|
||
import { Badge } from "@/components/ui/badge";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Input, Textarea } from "@/components/ui/input";
|
||
import { getT } from "@/lib/i18n";
|
||
import { intlLocale, type Translator } from "@peppa/shared/i18n";
|
||
|
||
const when = (iso: string | null, t: Translator) => (iso ? new Date(iso).toLocaleString(intlLocale(t.locale), { dateStyle: "short", timeStyle: "short" }) : "—");
|
||
|
||
export async function CodeTab({ code }: { code: RepoOverview }) {
|
||
const t = await getT();
|
||
const gitea = (
|
||
<Button asChild size="sm">
|
||
<a href={code.url}>
|
||
{t("Открыть в Gitea")} <ExternalLink />
|
||
</a>
|
||
</Button>
|
||
);
|
||
if (code.error) {
|
||
return (
|
||
<Section title={t("Код")} actions={gitea}>
|
||
<Empty>{t.text(code.error)}. {t("Репозиторий:")} <a href={code.url} className="text-primary">{code.url}</a></Empty>
|
||
</Section>
|
||
);
|
||
}
|
||
return (
|
||
<div className="grid gap-6 lg:grid-cols-[minmax(0,1fr)_320px]">
|
||
<Section title={<>README {code.readme && <span className="ml-1 font-mono text-xs font-normal text-muted-foreground">{code.readme.path}</span>}</>} actions={gitea}>
|
||
{code.readme ? (
|
||
<pre className="m-0 max-h-[40em] overflow-auto rounded-lg border bg-card p-4 font-mono text-xs leading-relaxed whitespace-pre-wrap">{code.readme.text}</pre>
|
||
) : (
|
||
<Empty>{code.defaultBranch ? t("В ветке {branch} нет README.", { branch: code.defaultBranch }) : t("Репозиторий пуст.")}</Empty>
|
||
)}
|
||
</Section>
|
||
<div className="flex flex-col gap-6">
|
||
<Section title={t("Ветки")} count={code.branches.length}>
|
||
{code.branches.length === 0 ? (
|
||
<Empty>{t("Веток нет.")}</Empty>
|
||
) : (
|
||
<ul className="m-0 flex list-none flex-col gap-1 p-0 text-sm">
|
||
{code.branches.map((b) => (
|
||
<li key={b.name} className="flex min-w-0 items-center gap-2 rounded-md px-2 py-1">
|
||
<GitBranch className="size-3.5 shrink-0 text-muted-foreground" />
|
||
<a href={`${code.url}/src/branch/${b.name.split("/").map(encodeURIComponent).join("/")}`} className="truncate font-mono text-xs text-primary">
|
||
{b.name}
|
||
</a>
|
||
{b.name === code.defaultBranch && <Badge variant="muted">{t("по умолчанию")}</Badge>}
|
||
<span className="ml-auto shrink-0 font-mono text-[11px] text-muted-foreground">{b.sha.slice(0, 7)}</span>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
)}
|
||
</Section>
|
||
<Section title={t("Коммиты {branch}", { branch: code.defaultBranch ?? "" })}>
|
||
{code.commits.length === 0 ? (
|
||
<Empty>{t("Коммитов нет.")}</Empty>
|
||
) : (
|
||
<ul className="m-0 flex list-none flex-col gap-2 p-0 text-sm">
|
||
{code.commits.map((c) => (
|
||
<li key={c.sha} className="flex flex-col gap-0.5 rounded-md border bg-card px-3 py-2">
|
||
<span className="[overflow-wrap:anywhere]">{c.message}</span>
|
||
<span className="flex flex-wrap gap-x-2 text-xs text-muted-foreground">
|
||
<a href={c.url} className="font-mono text-primary">{c.sha.slice(0, 7)}</a>
|
||
{c.author} · {when(c.date, t)}
|
||
</span>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
)}
|
||
</Section>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/** PEP-30: the project memory (.peppa/memory.md of the working copy), written by agents. */
|
||
export async function MemorySection({ text, chars, max, nearLimit }: { text: string; chars: number; max: number; nearLimit: boolean }) {
|
||
const t = await getT();
|
||
return (
|
||
<Section title={t("Память проекта")} actions={<span className={nearLimit ? "text-warn" : "text-muted-foreground"}>{t("{chars} из {max} символов", { chars, max })}</span>} className="mb-8">
|
||
<p className="m-0 text-sm text-muted-foreground">{t("Что агенты запомнили для следующих стори: команды, соглашения, грабли, решения")} (<code>.peppa/memory.md</code>, MCP <code>remember</code>). {t("Раннер подкладывает её агенту при каждом запуске.")}</p>
|
||
{text.trim() ? (
|
||
<Disclosure summary={<span className="text-sm">{nearLimit ? t("Показать память — почти предел, агент ужмёт её") : t("Показать память")}</span>}>
|
||
<Markdown text={text} />
|
||
</Disclosure>
|
||
) : (
|
||
<Empty>{t("Память пуста — агенты пополнят её в конце стори.")}</Empty>
|
||
)}
|
||
</Section>
|
||
);
|
||
}
|
||
|
||
export async function SpecsTab({ specs }: { specs: SpecSummary[] }) {
|
||
const t = await getT();
|
||
return (
|
||
<Section title={t("Спеки")} count={specs.length}>
|
||
<p className="m-0 text-sm text-muted-foreground">{t("Что система умеет сейчас: требования OpenSpec из рабочей копии (openspec/specs). Обновляются, когда стори архивирует свой change.")}</p>
|
||
{specs.length === 0 ? (
|
||
<Empty>{t("Спек ещё нет — они появляются после archive первого change.")}</Empty>
|
||
) : (
|
||
specs.map((s) => (
|
||
<Disclosure
|
||
key={s.name}
|
||
summary={
|
||
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||
<span className="flex items-center gap-2">
|
||
<span className="font-mono">{s.name}</span>
|
||
<Badge variant="muted">
|
||
{t.n(s.requirements, "{n} требование", "{n} требования", "{n} требований")}
|
||
</Badge>
|
||
</span>
|
||
{s.purpose && <span className="text-xs font-normal text-muted-foreground">{s.purpose.split("\n")[0]}</span>}
|
||
</span>
|
||
}
|
||
>
|
||
<pre className="m-0 max-h-[40em] overflow-auto font-mono text-xs leading-relaxed whitespace-pre-wrap">{s.text}</pre>
|
||
</Disclosure>
|
||
))
|
||
)}
|
||
</Section>
|
||
);
|
||
}
|
||
|
||
const CI_TONE = { success: "ok", failure: "danger", pending: "info", none: "muted", not_configured: "muted" } as const;
|
||
|
||
export async function PullsTab({ pulls, error, repoUrl }: { pulls: OpenPull[]; error: string | null; repoUrl: string }) {
|
||
const t = await getT();
|
||
return (
|
||
<Section
|
||
title={t("Открытые PR")}
|
||
count={pulls.length}
|
||
actions={
|
||
<Button asChild size="sm">
|
||
<a href={`${repoUrl}/pulls`}>
|
||
{t("Все PR в Gitea")} <ExternalLink />
|
||
</a>
|
||
</Button>
|
||
}
|
||
>
|
||
{error ? (
|
||
<Empty>{t.text(error)}.</Empty>
|
||
) : pulls.length === 0 ? (
|
||
<Empty>{t("Открытых PR нет.")}</Empty>
|
||
) : (
|
||
pulls.map((p) => (
|
||
<article key={p.number} className="flex flex-col gap-1.5 rounded-lg border bg-card p-3.5 text-sm">
|
||
<div className="flex items-start gap-2">
|
||
<GitPullRequest className="mt-0.5 size-4 shrink-0 text-ok" />
|
||
<a href={p.url} className="min-w-0 flex-1 text-foreground [overflow-wrap:anywhere]">
|
||
<span className="font-mono text-xs text-muted-foreground">#{p.number}</span> {p.title}
|
||
</a>
|
||
</div>
|
||
<div className="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground">
|
||
<span className="font-mono">{p.branch}</span>
|
||
{p.task ? (
|
||
<>
|
||
· <Key href={`/t/${p.task.key}`}>{p.task.key}</Key>
|
||
<StatusBadge status={p.task.status} />
|
||
<Badge variant={CI_TONE[p.task.ci.state]}>{t.text(p.task.ci.label)}</Badge>
|
||
</>
|
||
) : (
|
||
<span>· {t("не стори FORGE")}</span>
|
||
)}
|
||
</div>
|
||
</article>
|
||
))
|
||
)}
|
||
</Section>
|
||
);
|
||
}
|
||
|
||
/** «⋯ Настройки проекта» → Эпики: labels that group stories (stored as goals). */
|
||
/** PEP-34: done/total of an epic as a thin bar. */
|
||
export async function ProgressBar({ done, total, className }: { done: number; total: number; className?: string }) {
|
||
const t = await getT();
|
||
const pct = total ? Math.round((done / total) * 100) : 0;
|
||
return (
|
||
<span role="progressbar" aria-valuemin={0} aria-valuemax={total} aria-valuenow={done} aria-label={t("Готово {done} из {total}", { done, total })} className={`inline-block h-1 overflow-hidden rounded-full bg-muted ${className ?? "w-12"}`}>
|
||
<span className="block h-full rounded-full bg-ok" style={{ width: `${pct}%` }} />
|
||
</span>
|
||
);
|
||
}
|
||
|
||
export async function EpicsPanel({ projectId, projectKey, epics, progress, back, w }: { w: Words; projectId: number; projectKey: string; epics: Epic[]; progress: Map<number, { done: number; total: number }>; back: string }) {
|
||
const t = await getT();
|
||
return (
|
||
<div className="flex flex-col gap-2 text-sm">
|
||
{epics.length === 0 && <p className="m-0 text-muted-foreground">{t("Эпиков нет. Эпик — большая цель, которая объединяет {tasks}; его описание агент получает вместе с {task}.", { tasks: w.task("accPl"), task: w.task("ins") })}</p>}
|
||
{epics.map((e) => (
|
||
<details key={e.id} className="group rounded-md border bg-card">
|
||
<summary className="flex cursor-pointer list-none items-center gap-2 px-3 py-2 select-none [&::-webkit-details-marker]:hidden">
|
||
<span className="text-muted-foreground transition-transform group-open:rotate-90">›</span>
|
||
<span className="min-w-0 flex-1 truncate">{e.title}</span>
|
||
<ProgressBar done={progress.get(e.id)?.done ?? 0} total={progress.get(e.id)?.total ?? 0} />
|
||
<span className="font-mono text-[11px] text-muted-foreground tabular-nums">{progress.get(e.id)?.done ?? 0}/{progress.get(e.id)?.total ?? 0}</span>
|
||
{w.engineer && <span className="font-mono text-[11px] text-muted-foreground">#{e.id}</span>}
|
||
</summary>
|
||
<div className="flex flex-col gap-2 border-t px-3 py-2.5">
|
||
<form action={editEpic} className="flex flex-col gap-2">
|
||
<Hidden fields={{ projectId, epicId: e.id, back }} />
|
||
<Input name="title" required minLength={2} defaultValue={e.title} aria-label={t("Название эпика")} className="h-8" />
|
||
<Textarea name="description" rows={3} defaultValue={e.description ?? ""} placeholder={t("Описание для агента: зачем этот эпик")} aria-label={t("Описание эпика")} />
|
||
<Button size="xs" className="self-start">{t("Сохранить")}</Button>
|
||
</form>
|
||
<div className="flex flex-wrap gap-2">
|
||
<Button asChild size="xs" variant="outline">
|
||
<a href={`/p/${projectKey}/plan/${e.id}`}>{t("Спланировать {tasks}", { tasks: w.task("accPl") })}</a>
|
||
</Button>
|
||
<form action={editEpic}>
|
||
<Hidden fields={{ projectId, epicId: e.id, back, archive: "1" }} />
|
||
<Button size="xs" variant="ghost">
|
||
<Archive />{t("В архив")}
|
||
</Button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</details>
|
||
))}
|
||
<form action={addEpic} className="flex flex-col gap-2">
|
||
<Hidden fields={{ projectId, back }} />
|
||
<div className="flex gap-2">
|
||
<Input name="title" required minLength={2} placeholder={t("Новый эпик")} aria-label={t("Название нового эпика")} className="h-8" />
|
||
<Button size="sm">{t("Добавить")}</Button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/** PEP-73: the project's AGENTS.md — prompt and standards every agent follows; read and edit. */
|
||
export async function AgentsMdTab({ projectId, projectKey, md, edit, saved }: { projectId: number; projectKey: string; md: AgentsMd; edit: boolean; saved: boolean }) {
|
||
const t = await getT();
|
||
const tabHref = `/p/${projectKey}?tab=agents`;
|
||
const gitea = (
|
||
<Button asChild size="sm">
|
||
<a href={md.url}>
|
||
{t("В Gitea")} <ExternalLink />
|
||
</a>
|
||
</Button>
|
||
);
|
||
if (md.error) {
|
||
return (
|
||
<Section title="AGENTS.md" actions={gitea}>
|
||
<Empty>{t.text(md.error)}</Empty>
|
||
</Section>
|
||
);
|
||
}
|
||
if (edit) {
|
||
return (
|
||
<Section title={t("AGENTS.md — правка")} actions={gitea}>
|
||
<form action={saveAgentsMdAction} className="flex flex-col gap-3">
|
||
<Hidden fields={{ projectId: String(projectId), sha: md.sha ?? "", back: `${tabHref}&edit=1` }} />
|
||
<Textarea name="text" defaultValue={md.text || AGENTS_MD_STARTER} rows={28} spellCheck={false} className="font-mono text-xs leading-relaxed" aria-label={t("Текст AGENTS.md")} />
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<Button variant="default">{t("Сохранить в {branch}", { branch: md.branch })}</Button>
|
||
<Button asChild variant="ghost">
|
||
<a href={tabHref}>{t("Отмена")}</a>
|
||
</Button>
|
||
<span className="text-xs text-muted-foreground">{t("Коммит в ветку {branch} от вашего имени. Новые и перезапущенные агенты прочитают его сразу.", { branch: md.branch })}</span>
|
||
</div>
|
||
</form>
|
||
</Section>
|
||
);
|
||
}
|
||
return (
|
||
<Section
|
||
title="AGENTS.md"
|
||
actions={
|
||
<>
|
||
<Button asChild size="sm" variant="default">
|
||
<a href={`${tabHref}&edit=1`}>
|
||
<Pencil /> {t("Изменить")}
|
||
</a>
|
||
</Button>
|
||
{gitea}
|
||
</>
|
||
}
|
||
>
|
||
{saved && <Notice>{t("AGENTS.md сохранён в {branch}", { branch: md.branch })}</Notice>}
|
||
<p className="m-0 text-sm text-muted-foreground">
|
||
{t("Промпт и стандарты проекта: стек, команды, соглашения, этапы (например, проверка ИБ перед PR). Его читают все агенты — Claude, Codex и OpenCode; общие правила FORGE добавляются сами.")}
|
||
</p>
|
||
{md.text.trim() ? (
|
||
<div className="rounded-lg border bg-card p-4">
|
||
<Markdown text={md.text} />
|
||
</div>
|
||
) : (
|
||
<Empty>{t("В репозитории ещё нет AGENTS.md — нажмите «Изменить», чтобы создать его из заготовки.")}</Empty>
|
||
)}
|
||
</Section>
|
||
);
|
||
}
|
||
|
||
// i18n-ignore — file content for the project repository (like template/AGENTS.md), not UI text
|
||
const AGENTS_MD_STARTER = `# AGENTS.md
|
||
|
||
Проект ведётся на **FORGE**. Общие правила (OpenSpec, PR, ревью) агент получает от FORGE;
|
||
здесь — только стандарты этого проекта.
|
||
|
||
## Стек и команды
|
||
<!-- Язык, фреймворки, как собрать и запустить тесты. -->
|
||
|
||
## Соглашения
|
||
<!-- Стиль кода, структура, именование, что запрещено. -->
|
||
|
||
## Перед PR
|
||
- Тесты и линтеры проходят.
|
||
- Безопасность (ИБ): нет секретов в коде и логах; весь ввод проверяется; доступ к данным — только своему пользователю;
|
||
новые зависимости — без известных уязвимостей. Итог проверки — раздел «ИБ» в описании PR.
|
||
`;
|
||
|
||
interface EpicStory {
|
||
key: string;
|
||
title: string;
|
||
status: string;
|
||
goalId: number | null;
|
||
}
|
||
|
||
/** PEP-81: epics in plain sight — each epic (a big goal) with its stories (the steps agents do). */
|
||
export async function EpicsTab({ projectId, projectKey, epics, stories, progress, back, w }: { w: Words; projectId: number; projectKey: string; epics: Epic[]; stories: EpicStory[]; progress: Map<number, { done: number; total: number }>; back: string }) {
|
||
const t = await getT();
|
||
const loose = stories.filter((s) => !s.goalId || !epics.some((e) => e.id === s.goalId));
|
||
const list = (items: EpicStory[]) =>
|
||
items.length ? (
|
||
<ul className="m-0 flex list-none flex-col gap-1 p-0 text-sm">
|
||
{items.map((s) => (
|
||
<li key={s.key} className="flex flex-wrap items-center gap-x-2 gap-y-0.5">
|
||
<Key href={`/t/${s.key}`}>{s.key}</Key>
|
||
<span className="min-w-0 flex-[1_1_12em] truncate">{s.title}</span>
|
||
<StatusBadge status={s.status} />
|
||
</li>
|
||
))}
|
||
</ul>
|
||
) : (
|
||
<p className="m-0 text-sm text-muted-foreground">{t("{Tasks} пока нет.", { Tasks: w.Task("genPl") })}</p>
|
||
);
|
||
return (
|
||
<Section title={t("Эпики")} count={epics.length}>
|
||
<p className="m-0 text-sm text-muted-foreground">
|
||
<b className="text-foreground">{t("Эпик")}</b> {t("— большая цель, например «Оплата» или «Личный кабинет».")} <b className="text-foreground">{w.Task()}</b>{" "}
|
||
{t("— один конкретный шаг к ней: её делает агент, она — карточка на доске. У {task} может быть один эпик; его описание агент получает вместе с {taskIns}.", { task: w.task("gen"), taskIns: w.task("ins") })}
|
||
</p>
|
||
<form action={addEpic} className="flex flex-wrap items-end gap-2 rounded-lg border bg-card px-4 py-3">
|
||
<Hidden fields={{ projectId, back }} />
|
||
<Input name="title" required minLength={2} placeholder={t("Новый эпик: большая цель")} aria-label={t("Название нового эпика")} className="h-8 min-w-48 flex-1" />
|
||
<Input name="description" placeholder={t("Зачем он — одной фразой (необязательно)")} aria-label={t("Описание нового эпика")} className="h-8 min-w-48 flex-[2]" />
|
||
<Button size="sm" variant="default">{t("Добавить эпик")}</Button>
|
||
</form>
|
||
{epics.map((e) => {
|
||
const pr = progress.get(e.id) ?? { done: 0, total: 0 };
|
||
return (
|
||
<article key={e.id} id={`epic-${e.id}`} className="flex flex-col gap-2.5 rounded-lg border bg-card px-4 py-3" data-epic={e.id}>
|
||
<header className="flex flex-wrap items-center gap-2">
|
||
<Badge variant="primary">{t("эпик")}</Badge>
|
||
<h3 className="m-0 min-w-0 flex-1 truncate text-base font-medium">{e.title}</h3>
|
||
<ProgressBar done={pr.done} total={pr.total} className="w-24" />
|
||
<span className="text-xs text-muted-foreground tabular-nums">
|
||
{t("готово {done} из {total}", { done: pr.done, total: pr.total })}
|
||
</span>
|
||
</header>
|
||
{e.description && <p className="m-0 text-sm text-muted-foreground">{e.description}</p>}
|
||
{list(stories.filter((s) => s.goalId === e.id))}
|
||
<div className="flex flex-wrap gap-2">
|
||
<Button asChild size="xs" variant="outline">
|
||
<a href={`/p/${projectKey}?epic=${e.id}`}>{t("На доске")}</a>
|
||
</Button>
|
||
<Button asChild size="xs" variant="outline">
|
||
<a href={`/p/${projectKey}/plan/${e.id}`}>{t("Спланировать {tasks}", { tasks: w.task("accPl") })}</a>
|
||
</Button>
|
||
</div>
|
||
</article>
|
||
);
|
||
})}
|
||
{loose.length > 0 && (
|
||
<article className="flex flex-col gap-2.5 rounded-lg border border-dashed px-4 py-3">
|
||
<header className="flex items-center gap-2">
|
||
<h3 className="m-0 text-base font-medium text-muted-foreground">{t("{Tasks} без эпика", { Tasks: w.Task("pl") })}</h3>
|
||
<span className="text-xs text-muted-foreground">{loose.length}</span>
|
||
</header>
|
||
{list(loose)}
|
||
</article>
|
||
)}
|
||
<p className="m-0 text-xs text-muted-foreground">{t("Переименовать эпик, изменить описание или убрать в архив — «Настройки проекта → Эпики». Эпик {task} меняется кнопкой «Изменить» на её странице.", { task: w.task("gen") })}</p>
|
||
</Section>
|
||
);
|
||
}
|