peppa/packages/core/src/platform-status.ts
peppa-bot 6fb083a064 Поезд приёмки: PEP-255 поверх предыдущих (task/pep-255)
Конфликт в packages/core/src/platform-status.ts: импорт версий агентов (PEP-267)
и standingChecksLanes (PEP-255) — оставлены оба.
2026-11-25 20:07:11 +05:00

34 lines
2.3 KiB
TypeScript

// PEP-212: the platform's state in one text for the superadmin — what `peppa status` prints plus
// the delays and the broken subscriptions. Read by the code-mode API (`peppa.platform.status()`).
// glossary-ignore-file: читает суперадмин (инженер), не продакт
import type { Db } from "@peppa/db";
import { describeAgentVersions, getAgentVersions } from "./agent-versions.ts";
import { standingChecksLanes } from "./ci.ts";
import { describeState, outboxStats, serviceStatus, SERVICE_NAMES } from "./monitor.ts";
import { platformDelayOverview } from "./platform-delay.ts";
import { listSubscriptions } from "./subscriptions.ts";
import { pendingQuestions } from "./tasks.ts";
export async function platformStatus(db: Db): Promise<string> {
const out: string[] = [];
out.push("Services:");
for (const s of await serviceStatus(db, { probe: false })) {
const hb = s.heartbeat;
out.push(`- ${SERVICE_NAMES[s.service]}: ${describeState(s)}${hb ? ` (v${hb.version}, pid ${hb.pid}, since ${hb.startedAt.slice(0, 16).replace("T", " ")})` : ""}`);
}
const ob = await outboxStats(db);
out.push(`Outbox: ${ob.pending} pending, ${ob.failed} failed`);
const lanes = await standingChecksLanes(db);
out.push(`Checks queue: ${lanes ? `standing (heads wait too long): ${lanes.join(", ")}` : "ok"}`);
const delays = await platformDelayOverview(db);
out.push(delays.length ? `Delays on our side (${delays.length}):` : "Delays on our side: none");
for (const d of delays) out.push(`- ${d.key}${d.title ? ` «${d.title}»` : ""}: ${d.reason}, attempts ${d.attempts}${d.exhausted ? ", needs an administrator" : ""}`);
out.push(`Open questions: ${(await pendingQuestions(db)).length}`);
const bad = (await listSubscriptions(db)).filter((s) => s.status === "auth_error" || s.status === "limited");
out.push(bad.length ? `Subscriptions out of order (${bad.length}):` : "Subscriptions out of order: none");
for (const s of bad) out.push(`- #${s.id} ${s.provider}: ${s.status}${s.limitedUntil ? ` until ${s.limitedUntil.toISOString().slice(0, 16)}` : ""}${s.lastError ? ` — ${s.lastError.slice(0, 120)}` : ""}`);
// PEP-267: pinned agent CLIs against what runs.
out.push(...describeAgentVersions(await getAgentVersions(db)));
return out.join("\n");
}