72 lines
5.4 KiB
TypeScript
72 lines
5.4 KiB
TypeScript
import { agentAutonomyNote, formatFindings, INCIDENT_STATUS_RU, reviewLabel, type Incident, type TaskDetails, type TaskStatus } from "@peppa/core";
|
||
|
||
const NEXT_STEP: Record<TaskStatus, string> = {
|
||
backlog: "Proposal (workflow openspec-propose) → update_task(status: proposing, openspec_change) → если нет архитектурных решений, сразу update_task(status: in_progress) и Apply в этом же ходе.",
|
||
proposing: "Допиши артефакты, `openspec validate`, затем сразу Apply (update_task status: in_progress). request_approval — только для архитектурных стопперов.",
|
||
awaiting_approval: "Ты запросил одобрение архитектурного решения. Ничего не реализуй — жди ответа PM, закончи ход.",
|
||
in_progress: "Apply: продолжай с первого невыполненного пункта tasks.md (workflow openspec-apply-change), report_progress по ходу. В конце — archive, PR, update_task(status: review).",
|
||
review: "Стори в ревью у PM. Если в вопросах ниже есть замечания — доделай их; иначе ничего не делай.",
|
||
done: "Стори завершена — ничего делать не нужно.",
|
||
blocked: "Стори заблокирована — выясни причину в вопросах ниже или спроси PM через ask_pm.",
|
||
};
|
||
|
||
export function formatTask(d: TaskDetails): string {
|
||
const { task, goal } = d;
|
||
const lines = [
|
||
`# ${d.key}: ${task.title}`,
|
||
"",
|
||
`- Проект: ${d.project.name} (${d.project.key})`,
|
||
`- Статус: **${task.status}**`,
|
||
`- Эпик: ${goal ? `#${goal.id} ${goal.title}` : "—"}`,
|
||
`- OpenSpec change: ${task.openspecChange ? `\`openspec/changes/${task.openspecChange}/\`` : "ещё нет"}`,
|
||
];
|
||
if (task.prUrl) lines.push(`- PR: ${task.prUrl}`);
|
||
lines.push(`- ${d.ci.label.charAt(0).toUpperCase()}${d.ci.label.slice(1)}${d.ci.sha ? ` (коммит ${d.ci.sha.slice(0, 7)})` : ""}${d.ci.runUrl ? ` · ${d.ci.runUrl}` : ""}`);
|
||
for (const f of d.ci.failed) lines.push(` - ❌ ${f.check}${f.runUrl ? ` · ${f.runUrl}` : ""}`);
|
||
if (d.review) {
|
||
lines.push(`- ${reviewLabel(d.review)} (коммит ${d.review.sha.slice(0, 7)})`);
|
||
if (d.review.verdict === "changes") lines.push(formatFindings(d.review.findings).replace(/^/gm, " "));
|
||
}
|
||
lines.push("", "## Описание", "", task.description?.trim() || "_нет описания_");
|
||
if (goal?.description) lines.push("", `## Эпик #${goal.id}: ${goal.title}`, "", goal.description.trim());
|
||
if (d.incident) lines.push("", "## Инцидент", "", formatIncident(d.incident));
|
||
if (d.questions.length) {
|
||
lines.push("", "## Вопросы к PM");
|
||
for (const q of d.questions) {
|
||
lines.push("", `- [${q.kind} #${q.id}] ${q.text}`, q.answer ? ` - Ответ (${q.answeredVia}): ${q.answer}` : " - _ожидает ответа_");
|
||
}
|
||
}
|
||
const progress = d.recentEvents.filter((e) => e.type === "progress");
|
||
if (progress.length) {
|
||
lines.push("", "## Последний прогресс");
|
||
for (const e of progress.slice(-5)) lines.push(`- ${e.createdAt.toISOString().slice(0, 16)} ${(e.payload as { text: string }).text}`);
|
||
}
|
||
// PEP-23: the project's autonomy changes the next step (PM approves every proposal).
|
||
const pmApproves = d.autonomy?.proposal === "pm" && (task.status === "backlog" || task.status === "proposing");
|
||
const next = pmApproves
|
||
? "Proposal (workflow openspec-propose) → update_task(status: proposing, openspec_change) → в этом проекте PM одобряет каждый proposal: request_approval и конец хода. Apply — только после одобрения."
|
||
: NEXT_STEP[task.status];
|
||
lines.push("", "## Следующий шаг", "", next);
|
||
const note = d.autonomy ? agentAutonomyNote(d.autonomy) : null;
|
||
if (note) lines.push("", "## Автономность проекта", "", note);
|
||
return lines.join("\n");
|
||
}
|
||
|
||
/** A production error (PEP-58) as agents and the PM see it. */
|
||
export function formatIncident(i: Incident): string {
|
||
const fmt = (d: Date) => `${d.toISOString().slice(0, 16).replace("T", " ")} UTC`;
|
||
const lines = [
|
||
`- Инцидент #${i.id} [${i.status} — ${INCIDENT_STATUS_RU[i.status]}]: ${i.title}`,
|
||
`- Место: ${i.culprit ?? "—"}`,
|
||
`- Источник: ${i.source}, окружение: ${i.environment ?? "—"}, уровень: ${i.level ?? "—"}`,
|
||
`- Релиз: ${i.lastRelease ?? "—"}${i.firstRelease && i.firstRelease !== i.lastRelease ? ` (впервые в ${i.firstRelease})` : ""}`,
|
||
`- Событий: ${i.events}; впервые ${fmt(i.firstSeen)}, последний раз ${fmt(i.lastSeen)}`,
|
||
];
|
||
if (i.regressions) lines.push(`- Возвращалась: ${i.regressions} раз`);
|
||
if (i.resolvedAt) lines.push(`- Отмечена исправленной: ${fmt(i.resolvedAt)}${i.resolvedRelease ? ` в релизе ${i.resolvedRelease}` : ""}`);
|
||
if (i.decision) lines.push(`- Решение: ${i.decision} (${i.decidedBy})${i.decisionReason ? ` — ${i.decisionReason}` : ""}`);
|
||
if (i.url) lines.push(`- Bugsink: ${i.url}`);
|
||
lines.push("", "Верх стека (внутренний кадр первым):", "", "```", i.stack ?? "(стек недоступен — смотри Bugsink)", "```");
|
||
return lines.join("\n");
|
||
}
|