From b554f66d9cf7afa942db54db3d6cd142918f6eca Mon Sep 17 00:00:00 2001 From: peppa-bot Date: Wed, 18 Nov 2026 16:50:03 +0500 Subject: [PATCH] =?UTF-8?q?PEP-209:=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D0=B0=20=C2=AB=D0=9F=D1=80=D0=B8=D1=91=D0=BC=D0=BA=D0=B0?= =?UTF-8?q?=C2=BB,=20=C2=AB=D0=9F=D1=80=D0=B8=D0=BD=D1=8F=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B2=D1=81=D1=91=C2=BB,=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9,=20=D1=81=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=D0=BA=D0=B0=20=D0=B2=20Telegram,=20=D0=93=D0=BB?= =?UTF-8?q?=D0=B0=D0=B2=D0=BD=D0=B0=D1=8F=20=D0=B8=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D0=B8=20=D0=B2=20=D0=94=D0=B0=D1=88?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- apps/bot/src/bot.ts | 4 +- apps/web/app/(app)/actions.ts | 31 +++- apps/web/app/(app)/dashboard/actions.ts | 33 ++++ apps/web/app/(app)/dashboard/delays/page.tsx | 49 +++++ apps/web/app/(app)/dashboard/page.tsx | 9 +- apps/web/app/(app)/p/[key]/accept/page.tsx | 181 +++++++++++++++++++ apps/web/app/(app)/p/[key]/page.tsx | 18 +- apps/web/app/(app)/page.tsx | 57 +++++- apps/web/app/(app)/t/[key]/page.tsx | 6 +- apps/web/components/Board.tsx | 18 +- apps/web/components/PlatformDelays.tsx | 33 +++- packages/core/src/accept-digest.ts | 98 ++++++++++ packages/core/src/accept-screen.ts | 163 +++++++++++++++++ packages/core/src/index.ts | 2 + packages/core/src/story-product.ts | 4 +- packages/runner/src/ci-feedback.ts | 1 + packages/runner/src/deploy.ts | 4 +- packages/runner/src/flow.ts | 21 ++- packages/runner/src/proposals.ts | 33 +++- packages/runner/src/watchdog.ts | 5 +- packages/testkit/test/helpers.ts | 2 + template/.gitea/peppa-deploy.sh | 5 +- 22 files changed, 744 insertions(+), 33 deletions(-) create mode 100644 apps/web/app/(app)/dashboard/actions.ts create mode 100644 apps/web/app/(app)/dashboard/delays/page.tsx create mode 100644 apps/web/app/(app)/p/[key]/accept/page.tsx create mode 100644 packages/core/src/accept-digest.ts create mode 100644 packages/core/src/accept-screen.ts diff --git a/apps/bot/src/bot.ts b/apps/bot/src/bot.ts index e5a48803..78f994bc 100644 --- a/apps/bot/src/bot.ts +++ b/apps/bot/src/bot.ts @@ -2,7 +2,7 @@ // alerts) to the paired chat and turns button presses / replies into answers delivered // back into the agent session. Telegram is an adapter over the DB, not a remote shell: // it can only answer a specific pending question or resume/stop the session it is about. -import { duringPause, heldForDigest, isProjectPaused, LOCALIZED_PARAM, localizeMessage, messageDetails, questionIsFreeText, reportPlatformError, telegramChatLocale } from "@peppa/core"; +import { acceptDigestHold, duringPause, heldForDigest, isProjectPaused, LOCALIZED_PARAM, localizeMessage, messageDetails, questionIsFreeText, reportPlatformError, telegramChatLocale } from "@peppa/core"; import { asIs, localizeRoleMessage, m as tr, stripAsIs } from "@peppa/shared/i18n"; import { accountUsageForUser, @@ -347,6 +347,8 @@ export function createBot(o: BotOptions) { const url = ctx.taskKey ? `/t/${ctx.taskKey}` : `/p/${await projectKey(q.projectId)}`; // PEP-198: a finished story nobody waits for comes in the evening digest, not one by one. if (await heldForDigest(db, q, ctx.taskStatus ?? null)) continue; + // PEP-209: more than two ready within an hour — one summary with «Приёмка» instead (acceptDigestTick). + if ((await acceptDigestHold(db, q)) !== "send") continue; for (const u of audience) { // PEP-154: the terminal command is for the «Инженер» view only. const r = renderQuestion(q, { ...ctx, engineer: (await getUiMode(db, u.id)) === "engineer" }); diff --git a/apps/web/app/(app)/actions.ts b/apps/web/app/(app)/actions.ts index 3878225b..be802300 100644 --- a/apps/web/app/(app)/actions.ts +++ b/apps/web/app/(app)/actions.ts @@ -64,10 +64,10 @@ import { setUiMode, } from "@peppa/core"; import { attachmentLabel, fixFeedback, linkAttachments, linkFeedback, parseAttachmentIds, rejectFeedback, restoreProject } from "@peppa/core"; -import { deleteProject, decideProposals } from "@peppa/runner"; +import { deleteProject, decideProposals, mergeProposals } from "@peppa/runner"; import { bugsinkFromEnv } from "@peppa/bugsink"; import { loadEnv } from "@peppa/shared"; -import { pauseProject, resumeProject, acceptStory, autoPublish, fixStory, confirmTaskDecision, changeTaskDecision, undoSplit, budgetChanged, resolveTaskById, deployProd, bugsinkWebhookBase, connectErrorTracking, decideIncident, resolveIncident, acceptTask, answerAndDeliver, grantRepoAccess, moveTask, provisionProjectOnce, projectNamespace, setProjectVisibility, shareProject, unshareProject, type BoardColumn, resumeSession, sendToSession, syncSessionAttachments, startSession, stopSession, type Provider, startFreeRunner, renameRunner, promoteRunner, queueTaskOnRunner, managesProject, saveAgentsMd, cancelOwnLogin, finishOwnClaudeLogin, connectOwnSubscription, removeOwnSubscription, type OwnSubscriptionKind, chooseSharedSubscription, requestSubscription } from "@peppa/runner"; +import { pauseProject, resumeProject, acceptAll, acceptStory, autoPublish, fixStory, confirmTaskDecision, changeTaskDecision, undoSplit, budgetChanged, resolveTaskById, deployProd, bugsinkWebhookBase, connectErrorTracking, decideIncident, resolveIncident, acceptTask, answerAndDeliver, grantRepoAccess, moveTask, provisionProjectOnce, projectNamespace, setProjectVisibility, shareProject, unshareProject, type BoardColumn, resumeSession, sendToSession, syncSessionAttachments, startSession, stopSession, type Provider, startFreeRunner, renameRunner, promoteRunner, queueTaskOnRunner, managesProject, saveAgentsMd, cancelOwnLogin, finishOwnClaudeLogin, connectOwnSubscription, removeOwnSubscription, type OwnSubscriptionKind, chooseSharedSubscription, requestSubscription } from "@peppa/runner"; import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { asWebActor, requireUser, words } from "@/lib/auth"; @@ -203,6 +203,28 @@ export async function acceptStoryAction(f: FormData) { }); } +/** + * PEP-209: «Принять» / «Принять всё» on the acceptance page — one by one, a failure of one doesn't + * stop the others; the page shows the result («Принято 6, на доработке 1…»). + */ +export async function acceptAllAction(f: FormData) { + const user = asWebActor(await requireUser()); + const key = str(f, "project"); + const base = `/p/${encodeURIComponent(key)}/accept`; + await attempt(f, async () => { + const refs = []; + for (const k of f.getAll("taskKey").map(String)) { + const ref = await resolveTask(db, k).catch(() => null); + if (!ref || ref.project.key !== key) continue; + await projectForUser(db, user.id, ref.project.id); + if (ref.task.status === "review") refs.push(ref); + } + if (!refs.length) throw new PeppaError(m("Принимать нечего: задачи уже приняты или вернулись в работу")); + const r = await acceptAll(db, refs, "web"); + return `${base}?ok=${r.accepted.length}&pending=${r.pending.length}&failed=${r.failed.length}`; + }); +} + /** «Поправить» on the story page in «Продакт» mode (PEP-120): the remark goes to the agent, the story — back to work. */ export async function fixStoryAction(f: FormData) { const user = asWebActor(await requireUser()); @@ -503,6 +525,11 @@ export async function proposalAction(f: FormData) { const user = asWebActor(await requireUser()); await attempt(f, async () => { const choice = str(f, "choice"); + // PEP-209: «Объединить в одну» — the ticked proposals become one story. + if (choice === "merge") { + await mergeProposals(db, user, f.getAll("pick").map(Number).filter((n) => Number.isInteger(n) && n > 0)); + return; + } if (choice !== "do" && choice !== "no" && choice !== "important" && choice !== "none") throw new PeppaError(m("Эта кнопка уже не работает.")); const ids = str(f, "ids").split(",").map(Number).filter((n) => Number.isInteger(n) && n > 0); await decideProposals(db, user, ids, choice); diff --git a/apps/web/app/(app)/dashboard/actions.ts b/apps/web/app/(app)/dashboard/actions.ts new file mode 100644 index 00000000..72fee04c --- /dev/null +++ b/apps/web/app/(app)/dashboard/actions.ts @@ -0,0 +1,33 @@ +"use server"; +// PEP-209: the superadmin's buttons on a delay card («Дашборд → Задержки»). + +import { DELAY_REASON_NAMES, PeppaError, requireSuperadmin, type DelayAction, type DelayReason } from "@peppa/core"; +import { delayAction } from "@peppa/runner"; +import { revalidatePath } from "next/cache"; +import { redirect } from "next/navigation"; +import { asWebActor, requireUser } from "@/lib/auth"; +import { db } from "@/lib/db"; +import { getT } from "@/lib/i18n"; + +const BASE = "/dashboard/delays"; +const str = (f: FormData, k: string) => String(f.get(k) ?? "").trim(); + +export async function delayActionForm(f: FormData) { + const user = asWebActor(await requireUser()); + const params = new URLSearchParams(); + try { + await requireSuperadmin(db, user); + const reason = str(f, "reason") as DelayReason; + const action = str(f, "action") as DelayAction; + const projectId = Number(str(f, "project")); + const taskId = str(f, "task") ? Number(str(f, "task")) : null; + if (!(reason in DELAY_REASON_NAMES) || !["restart", "review", "close"].includes(action) || !Number.isInteger(projectId)) throw new PeppaError("?"); + const t = await getT(); + params.set("ok", t.text(await delayAction(db, { projectId, taskId }, reason, action)).slice(0, 300)); + } catch (e) { + const t = await getT(); + params.set("error", (e instanceof PeppaError ? t.text(e.message) : t("Ошибка: {message}", { message: (e as Error).message })).slice(0, 300)); + } + revalidatePath("/", "layout"); + redirect(`${BASE}?${params}`); +} diff --git a/apps/web/app/(app)/dashboard/delays/page.tsx b/apps/web/app/(app)/dashboard/delays/page.tsx new file mode 100644 index 00000000..2c065de0 --- /dev/null +++ b/apps/web/app/(app)/dashboard/delays/page.tsx @@ -0,0 +1,49 @@ +import Link from "next/link"; +import { notFound } from "next/navigation"; +import { Hourglass } from "lucide-react"; +import { isSuperadmin, platformDelayOverview } from "@peppa/core"; +import { Empty, Flash, Notice, PageHeader, Section } from "@/components/common"; +import { LiveRefresh } from "@/components/LiveRefresh"; +import { PlatformDelays } from "@/components/PlatformDelays"; +import { Workspace } from "@/components/Workspace"; +import { requireUser } from "@/lib/auth"; +import { db } from "@/lib/db"; +import { getT } from "@/lib/i18n"; + +export async function generateMetadata() { + const t = await getT(); + return { title: t("Задержки — Peppa FACTORY") }; +} + +/** PEP-209: every delay on the platform's side with the superadmin's buttons; «нужен администратор» first. */ +export default async function Delays({ searchParams }: { searchParams: Promise<{ error?: string; ok?: string }> }) { + const user = await requireUser(); + if (!(await isSuperadmin(db, user))) notFound(); + const { error, ok } = await searchParams; + const t = await getT(); + const all = await platformDelayOverview(db); + const admin = all.filter((d) => d.exhausted); + const trying = all.filter((d) => !d.exhausted); + return ( + + + + {ok && {t.text(ok)}} + {t("Задержки на стороне Peppa FACTORY")}}> + {t("Что сейчас задерживается у пользователей и почему. Владельцы видят только строку ожидания на задаче.")}{" "} + {t("← Дашборд")} + + {all.length === 0 && {t("Задержек нет.")}} + {admin.length > 0 && ( +
+ +
+ )} + {trying.length > 0 && ( +
+ +
+ )} +
+ ); +} diff --git a/apps/web/app/(app)/dashboard/page.tsx b/apps/web/app/(app)/dashboard/page.tsx index 727be144..809ab5bf 100644 --- a/apps/web/app/(app)/dashboard/page.tsx +++ b/apps/web/app/(app)/dashboard/page.tsx @@ -1,7 +1,7 @@ import Link from "next/link"; import { notFound } from "next/navigation"; import { Gauge } from "lucide-react"; -import { isSuperadmin, platformDashboard, type DashboardCounts } from "@peppa/core"; +import { isSuperadmin, platformDashboard, platformDelayCounts, type DashboardCounts } from "@peppa/core"; import { ago, Empty, PageHeader, Section } from "@/components/common"; import { LiveRefresh } from "@/components/LiveRefresh"; import { Badge } from "@/components/ui/badge"; @@ -54,6 +54,7 @@ export default async function Dashboard() { const t = await getT(); const d = await platformDashboard(db); const x = d.totals; + const delays = await platformDelayCounts(db); return ( @@ -70,6 +71,12 @@ export default async function Dashboard() { +

+ + {delays.total ? t("Задержки на платформе: {n}, требуют вас: {m}", { n: delays.total, m: delays.admin }) : t("Задержек на платформе нет")} → + +

+
{d.attention.length === 0 ? ( {t("Всё в порядке: ничего не зависло.")} diff --git a/apps/web/app/(app)/p/[key]/accept/page.tsx b/apps/web/app/(app)/p/[key]/accept/page.tsx new file mode 100644 index 00000000..ea5fd3ec --- /dev/null +++ b/apps/web/app/(app)/p/[key]/accept/page.tsx @@ -0,0 +1,181 @@ +import Link from "next/link"; +import { notFound } from "next/navigation"; +import { acceptAllSummary, acceptScreen, type AcceptItem } from "@peppa/core"; +import { acceptAllAction, fixStoryAction } from "@/app/(app)/actions"; +import { Empty, Flash, Key, Notice, PageHeader } from "@/components/common"; +import { LiveRefresh } from "@/components/LiveRefresh"; +import { Button } from "@/components/ui/button"; +import { Textarea } from "@/components/ui/input"; +import { Workspace } from "@/components/Workspace"; +import { requireUser } from "@/lib/auth"; +import { db } from "@/lib/db"; +import { getT } from "@/lib/i18n"; +import { projectForUserByKey } from "@/lib/queries"; + +export async function generateMetadata() { + const t = await getT(); + return { title: t("Приёмка — Peppa FACTORY") }; +} + +const BIG = "min-h-11"; // PEP-209: buttons at least 44 px on a phone + +/** + * PEP-209: acceptance on one screen — every story waiting for «Принять», grouped by product page, + * with «было» / «стало», «Принять», «Поправить» and «Принять всё» on top. + */ +export default async function AcceptPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string; ok?: string; pending?: string; failed?: string }> }) { + const user = await requireUser(); + const { key } = await params; + const sp = await searchParams; + const t = await getT(); + const p = await projectForUserByKey(user.id, key).catch(() => null); + if (!p) notFound(); + const screen = await acceptScreen(db, p); + const back = `/p/${p.key}/accept`; + const all = screen.groups.flatMap((g) => g.items); + const done = sp.ok != null ? { accepted: Number(sp.ok) || 0, pending: Number(sp.pending) || 0, failed: Number(sp.failed) || 0 } : null; + return ( + + + + {p.name}} title={t("Приёмка")}> + {screen.total ? t("Работа, которая ждёт вашего решения: посмотрите и примите или напишите, что поправить.") : t("Принимать пока нечего: агенты пришлют задачи, когда работа будет готова.")} + + + {done && ( + + {t.text(acceptAllSummary(done))} + {screen.liveUrl && done.accepted + done.pending > 0 && ( + {t("Открыть продукт")} → + )} + + )} + + {screen.total > 0 && ( +
+ {screen.checkUrl && ( + + {t("Открыть версию для проверки")} + + )} +
+ + {t("Принять всё · {n}", { n: all.length })} + +
+ + +

{t("Будут приняты по очереди:")}

+
    + {all.map((it) => ( +
  • + + {it.key} {it.title} +
  • + ))} +
+

{t("Если какая-то не примется, остальные всё равно примутся, а у неё будет написано почему.")}

+ +
+
+
+ )} + + {screen.total === 0 && !done && {t("Задач на приёмке нет.")}} + + {screen.groups.map((g) => ( +
+

+ {g.page ? t("Страница {page}", { page: g.page }) : t("Без снимков страниц")} · {g.items.length} +

+
+ {g.items.map((it) => )} +
+
+ ))} +
+ ); +} + +async function AcceptCard({ it, back }: { it: AcceptItem; back: string }) { + const t = await getT(); + return ( +
+
+ + {it.key} + + {it.title} +
+

{t.text(it.summary)}

+ {it.failed && ( +

+ {t("Не принялась: {reason}", { reason: t.text(it.failed) })} +

+ )} + {it.pending &&

{t("Вы уже приняли — изменения обновляются, задача закроется сама.")}

} + {it.shots.length > 0 ? ( + // Scrolls sideways on a phone: one page per screen, «было» above «стало». +
+ {it.shots.map((s, i) => ( +
+
{s.path}
+
+ + +
+
+ ))} +
+ ) : it.previewUrl ? ( +

+ {t("Открыть в версии для проверки")} → +

+ ) : ( +

{t("Снимков и версии для проверки нет — посмотрите описание задачи.")}

+ )} + {it.shots.length > 0 && it.previewUrl && ( +

+ {t("Открыть в версии для проверки")} → +

+ )} + {!it.pending && ( +
+
+ + + + +
+
+ {t("Поправить")} +
+ + +