import { notFound } from "next/navigation"; import { ExternalLink, Plus, Rocket, SquareTerminal } from "lucide-react"; import { columnOf, currentReleases, describeRepo, isPlatform, listReleases, bugsinkWebhookBase, openPulls, platformReleaseCandidate, platformReleaseOffers, ownPendingLogins, readAgentsMd, repoOverview, type Release } from "@peppa/runner"; import { listHosts, DEFAULT_RUNNER_SETTINGS, DEFAULT_AGENT_SETTINGS, getProjectAgentSettings, getSystemAgentSettings, getProjectRunnerSettings, getSystemRunnerSettings, blockedLabel, blockersMap, epicProgress, progressLabel, taskProgress, getProjectBudget, listJournal, listProjectSecrets, projectMetrics, type ActorChannel, type ActorKind, getAutonomy, getIncidentSettings, getReviewSettings, isSuperadmin, listEpics, listErrorSources, listIncidents, listMembers, listPools, listSpecs, taskAgentNames, getIntakeSettings, intakePendingTasks, projectAgentWarning, memoryStats, readMemory, projectPool, sharedPool, ownPool, repoAudience, repoVisibilityLabel } from "@peppa/core"; import { LiveRefresh } from "@/components/LiveRefresh"; import { PanelSection } from "@/components/ActivityAside"; import { Board, type Card } from "@/components/Board"; import { Hidden, SessionCard } from "@/components/cards"; import { Empty, Flash, Key, Notice, PageHeader, Section } from "@/components/common"; import { IncidentSettingsPanel, IncidentsSection } from "@/components/Incidents"; import { AutonomyPanel } from "@/components/Autonomy"; import { NewRunnerForm, RunnerSettingsPanel } from "@/components/Runners"; import { AgentModelPanel } from "@/components/AgentModel"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input, NativeSelect, Textarea } from "@/components/ui/input"; import { SettingsDialog } from "@/components/SettingsDialog"; import { ProjectSecretsPanel } from "@/components/ProjectSecrets"; import { Workspace } from "@/components/Workspace"; import { SubscriptionSetup } from "@/components/SubscriptionSetup"; import { requireUser } from "@/lib/auth"; import { cn } from "@/lib/utils"; import { db } from "@/lib/db"; import { board, projectForUserByKey, projectSessions } from "@/lib/queries"; import { addProjectMember, addTask, deployProdAction, grantRepoAccessToMembers, removeProjectMember, saveReviewSettingsAction, saveIntakeSettingsAction, setProjectVisibilityAction, connectOwnSubscriptionAction, chooseSharedSubscriptionAction } from "../../actions"; import { AgentsMdTab, CodeTab, EpicsPanel, EpicsTab, MemorySection, ProgressBar, PullsTab, SpecsTab } from "./tabs"; import { setProjectPoolAction } from "../../subscriptions/actions"; import { JournalFilters, JournalList, MetricsTab, ProjectBudgetPanel } from "@/components/Accounting"; import { saveProjectBudgetAction } from "../../actions"; const RELEASE_STATUS: Record = { deploying: { label: "выкатывается", tone: "info" }, healthy: { label: "работает", tone: "ok" }, rolled_back: { label: "откат", tone: "warn" }, failed: { label: "не поднялся", tone: "danger" }, removed: { label: "удалён", tone: "muted" }, }; const TABS = [ { id: "board", label: "Доска" }, { id: "epics", label: "Эпики" }, { id: "code", label: "Код" }, { id: "specs", label: "Спеки" }, { id: "agents", label: "AGENTS.md" }, { id: "pulls", label: "PR" }, { id: "releases", label: "Релизы" }, { id: "bugs", label: "Баги" }, { id: "sessions", label: "Сессии" }, { id: "metrics", label: "Метрики" }, { id: "journal", label: "Журнал" }, ] as const; function EnvLine({ name, r }: { name: string; r: Release | null | undefined }) { return (
{name} {r ? ( {r.sha.slice(0, 7)} {r.host && ( {r.host} )} ) : ( нет )}
); } export default async function ProjectPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string; created?: string; tab?: string; epic?: string; weeks?: string; actor?: string; channel?: string; edit?: string; saved?: string }> }) { const user = await requireUser(); const { key } = await params; const { error, created, tab: tabParam, epic: epicParam, weeks, actor, channel, edit, saved } = await searchParams; const tab = TABS.find((t) => t.id === tabParam)?.id ?? "board"; const p = await projectForUserByKey(user.id, key).catch(() => null); if (!p) notFound(); const [{ tasks }, epics, sessions, team, repo, incidentSettings, sources, incidents, releases, current, reviewer, progress, deps] = await Promise.all([ board(p.id), listEpics(db, p.id), projectSessions(p.id), listMembers(db, p), describeRepo(db, p), getIncidentSettings(db, p.id), listErrorSources(db, p.id), listIncidents(db, p.id), listReleases(db, p.id, 15), currentReleases(db, p.id), getReviewSettings(db, p.id), epicProgress(db, p.id), blockersMap(db, p.id), ]); // Peppa itself has no staging: its prod candidate is the newest green main (PEP-18). const prodCandidate = isPlatform(p) ? ((await platformReleaseOffers(db)) ? await platformReleaseCandidate(db, p) : null) : (current.staging?.sha ?? null); const collaborators = new Set((repo.collaborators ?? []).map((l) => l.toLowerCase())); // Members who are not repo collaborators (only known when Gitea listed them; owners of the namespace see it anyway). const noRepoAccess = (login: string) => repo.collaborators !== null && login.toLowerCase() !== p.giteaOwner.toLowerCase() && !collaborators.has(login.toLowerCase()); const missingAccess = team.members.some((m) => noRepoAccess(m.login)); // PEP-67: default subscription pool; only a superadmin changes it. const superadmin = await isSuperadmin(db, user); // PEP-88: a superadmin manages any project like its owner. const isOwner = p.ownerId === user.id || superadmin; const [pool, pools, autonomy, shared] = await Promise.all([projectPool(db, p.id), superadmin ? listPools(db) : Promise.resolve([]), getAutonomy(db, p.id), sharedPool(db)]); // PEP-10/27: runner settings of the project over the system ones. const [runnerOwn, runnerSystem, secrets, runnerHosts] = await Promise.all([getProjectRunnerSettings(db, p.id), getSystemRunnerSettings(db), listProjectSecrets(db, p.id), listHosts(db, { enabled: true })]); // PEP-41: agent provider/model of the project over the platform's. const [agentOwn, agentSystem] = await Promise.all([getProjectAgentSettings(db, p.id), getSystemAgentSettings(db)]); // PEP-31: the project's pool has no working subscription — agents won't start. const agentWarning = await projectAgentWarning(db, p.id); // PEP-80: the owner's own subscriptions — a ChatGPT device login in progress, and whether a pool exists already. const mayChoose = isOwner || superadmin; const [ownLogins, hasOwnPool] = await Promise.all([mayChoose && pool ? ownPendingLogins(db, pool.id) : Promise.resolve([]), mayChoose ? ownPool(db, user.id).then((x) => !!x) : Promise.resolve(false)]); // Epic filter (PEP-66): only an open epic of this project filters; anything else shows all. const epicFilter = epics.find((e) => String(e.id) === epicParam) ?? null; const boardHref = (epicId?: number) => (epicId ? `/p/${p.key}?epic=${epicId}` : `/p/${p.key}`); const back = tab === "board" ? boardHref(epicFilter?.id) : `/p/${p.key}?tab=${tab}`; const epicTitle = new Map(epics.map((e) => [e.id, e.title])); const agentNames = await taskAgentNames(db, p.id); const [intake, refining] = await Promise.all([getIntakeSettings(db, p.id), intakePendingTasks(db, p.id)]); const cards: Card[] = tasks .filter((t) => !epicFilter || t.goalId === epicFilter.id) .map((t) => { const pr = columnOf(t.status) === "in_progress" ? taskProgress(p, t.openspecChange) : null; return { key: `${p.key}-${t.number}`, title: t.title, status: t.status, column: columnOf(t.status), epic: t.goalId ? (epicTitle.get(t.goalId) ?? null) : null, // PEP-33: tasks.md progress of stories in work. progress: pr && { done: pr.done, total: pr.total, current: pr.current }, blocked: t.status === "backlog" ? blockedLabel(deps.get(t.id)) : null, agent: agentNames.get(t.id) ?? null, refining: refining.has(t.id) ? (refining.get(t.id) === "waiting" ? "ждёт ваших ответов" : "уточняется") : null, }; }); // Gitea and the working copy are read only for the open tab. const [code, pulls] = await Promise.all([tab === "code" ? repoOverview(db, p) : null, tab === "pulls" ? openPulls(db, p) : null]); const specs = tab === "specs" ? listSpecs(p) : []; const agentsMd = tab === "agents" ? await readAgentsMd(db, p) : null; const memory = tab === "specs" ? readMemory(p.workspacePath) : ""; // PEP-47 metrics, PEP-48 journal, PEP-43 default budget. const metrics = tab === "metrics" ? await projectMetrics(db, p.id, { weeks: Number(weeks) || 8 }) : null; const journal = tab === "journal" ? await listJournal(db, { projectId: p.id, actorKind: (actor || undefined) as ActorKind | undefined, channel: (channel || undefined) as ActorChannel | undefined, limit: 200 }) : []; const projectBudget = await getProjectBudget(db, p.id); const aside = (
Где
{repo.fullName}
Пространство
{p.giteaOwner} {repo.ownerKind && ` — ${repo.ownerKind === "org" ? "организация" : "личное"}`}
Видимость
{repoVisibilityLabel(repo.private)}
Кто видит
{repoAudience(repo)}
Рабочая копия
{p.workspacePath}
{isOwner && repo.private !== null && (
)}
{isOwner && repo.private !== null && (

{repo.private ? "Публичный репозиторий видят все, у кого есть доступ к Gitea." : "Приватный репозиторий видят только владелец пространства, соавторы и peppa-bot."} Видимость меняется в Gitea сразу.

)}

Продакт решает, зачем это и что берём в первую версию; аналитик пишет критерии приёмки и задаёт до трёх вопросов. Не ответили вовремя — идёт по вариантам по умолчанию (ночью ждёт до утра). Стори, созданные до включения, не трогает.