peppa/packages/core/src/platform-failure.ts
peppa-bot f3d10a4c25 PEP-243: платформа называется FORGE — название во всех текстах для людей и подсказках агентам, адрес forge.telecom.quest
«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>
2026-11-23 11:18:49 +05:00

40 lines
1.9 KiB
TypeScript

// PEP-154: an exception inside Peppa is not the project owner's business. A clear refusal
// (PeppaError: «подписка не выбрана») is still told to the owner; anything else goes to the
// error tracker and, once per error a day, to the superadmins.
import { m as tr } from "@peppa/shared/i18n";
import type { Db } from "@peppa/db";
import { createHash } from "node:crypto";
import { PeppaError } from "./errors.ts";
import { reportPlatformError } from "./error-report.ts";
import { normalizeMessage } from "./message-state.ts";
import { alertAdmins } from "./monitor.ts";
export interface FailureContext {
/** Which process: "watchdog", "hook", "bot", "web". */
service: string;
/** Which part failed: "dispatch PAY-7", "restart #12". */
where: string;
log?: (m: string) => void;
now?: Date;
}
/**
* What to tell the project owner about a failure: the text of a clear refusal, or null — it is
* a platform error (reported to the error tracker and to the superadmins, one message per error
* a day) and the owner gets nothing. Never throws.
*/
export async function platformFailure(db: Db, e: unknown, ctx: FailureContext): Promise<string | null> {
if (e instanceof PeppaError) return e.message;
const message = (e as Error)?.message ?? String(e);
try {
await reportPlatformError(db, e, { service: ctx.service, where: ctx.where });
// The same error of the same part (numbers aside) is one message a day.
const fp = createHash("sha1").update(`${ctx.service}|${normalizeMessage(ctx.where)}|${normalizeMessage(message)}`).digest("hex").slice(0, 12);
const day = (ctx.now ?? new Date()).toISOString().slice(0, 10);
// glossary-ignore: read by superadmins only
const text = tr("⚠️ Сбой в FORGE ({where}): {error}", { where: ctx.where, error: message.length > 300 ? `${message.slice(0, 300)}…` : message });
await alertAdmins(db, `fail:${fp}:${day}`, text, ctx.log ?? (() => {}));
} catch {}
return null;
}