peppa/apps/web/components/ui.tsx
Асель 00c8f79a36 PEP-7: autonomous mode — board moves start agents, PM only for stoppers
- web board (Backlog / In progress / Review / Done) with drag-and-drop and
  buttons; moveTask starts an agent on In progress, stops on Backlog/Done
- routine proposals go straight to apply; request_approval/ask_pm only for
  architectural stoppers (RULES.md, MCP hints, template pushed to Gitea)
- Stop hook keeps the agent going (decision: block, max 2 in a row,
  sessions.auto_nudges reset by a human answer) instead of pinging the PM
- review: ready-for-review message with Accept (acceptTask → done, session
  stopped) in Telegram and web; a text reply goes back to the agent
- mock-claude honours Stop-hook block; 6 new e2e tests (48 total, green)
- OpenSpec: pep-7 archived (task-autonomy, web-workspace board)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:21:11 +05:00

132 lines
5.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Link from "next/link";
import type { Question, SessionView } from "@peppa/core";
import { answerQuestion, messageSession, resumeTaskSession, stopTaskSession } from "@/app/(app)/actions";
const TASK_STATUS: Record<string, string> = {
backlog: "Бэклог",
proposing: "Proposal",
awaiting_approval: "Ждёт одобрения",
in_progress: "В работе",
review: "Ревью",
done: "Готово",
blocked: "Блок",
};
const SESSION_STATUS: Record<string, string> = {
starting: "запуск",
running: "работает",
waiting_input: "ждёт тебя",
idle: "простаивает",
stalled: "зависла?",
rate_limited: "лимит",
done: "завершена",
failed: "упала",
};
const KIND: Record<string, string> = { approval: "Одобрение proposal", question: "Вопрос", permission: "Разрешение", attention: "Сессия ждёт тебя" };
export function Badge({ status, kind = "task" }: { status: string; kind?: "task" | "session" }) {
const label = (kind === "task" ? TASK_STATUS : SESSION_STATUS)[status] ?? status;
return <span className={`badge s-${status}`}>{label}</span>;
}
export function Flash({ error }: { error?: string }) {
return error ? <p className="flash" role="alert">{error}</p> : null;
}
export function ago(d: Date | null | undefined): string {
if (!d) return "—";
const s = Math.round((Date.now() - d.getTime()) / 1000);
if (s < 60) return `${s} с назад`;
if (s < 3600) return `${Math.round(s / 60)} мин назад`;
if (s < 86400) return `${Math.round(s / 3600)} ч назад`;
return d.toLocaleDateString("ru-RU");
}
export function QuestionCard({ q, taskKey, taskStatus, back }: { q: Question; taskKey?: string | null; taskStatus?: string | null; back: string }) {
const review = q.kind === "attention" && taskStatus === "review";
const answered = !!q.answeredAt;
return (
<article className={`card q q-${q.kind}${answered ? " answered" : ""}`}>
<header className="row">
<span className="kind">{review ? "Готово к ревью" : KIND[q.kind]}</span>
{taskKey && (
<Link href={`/t/${taskKey}`} className="mono">
{taskKey}
</Link>
)}
<span className="muted">#{q.id} · {ago(q.createdAt)}</span>
</header>
<p className="qtext">{q.text}</p>
{answered ? (
<p className="muted">
{q.answeredVia === "system" ? "⌛ " : "✅ "}
{q.answeredVia === "system" ? q.answer : `Ответ (${q.answeredVia}): ${q.answer}`}
</p>
) : (
<form action={answerQuestion} className="answer">
<input type="hidden" name="questionId" value={q.id} />
<input type="hidden" name="back" value={back} />
<div className="row wrap">
{q.kind === "approval" && <button name="choice" value="ок" className="primary">Одобрить</button>}
{q.kind === "permission" && (
<>
<button name="choice" value="allow" className="primary">Разрешить</button>
<button name="choice" value="always">Всегда</button>
<button name="choice" value="deny" className="danger">Запретить</button>
</>
)}
{review && <button name="choice" value="__accept" className="primary">Принять</button>}
{q.kind === "attention" && !review && <button name="choice" value="Продолжай." className="primary">Продолжай</button>}
{(q.options ?? []).map((o) => (
<button key={o} name="choice" value={o}>{o}</button>
))}
</div>
{q.kind !== "permission" && (
<div className="row">
<input type="text" name="answer" placeholder={q.kind === "approval" || review ? "Замечание — вернёт на доработку" : "Свой ответ"} aria-label="Ответ" />
<button>Ответить</button>
</div>
)}
</form>
)}
</article>
);
}
export function SessionCard({ s, back }: { s: SessionView; back: string }) {
const alive = !["done", "failed"].includes(s.status);
return (
<article className="card session">
<header className="row">
<Badge status={s.status} kind="session" />
{s.taskKey && <Link href={`/t/${s.taskKey}`} className="mono">{s.taskKey}</Link>}
<span className="muted">#{s.id} · {s.provider} · поколение {s.generation} · {ago(s.lastActivityAt)}</span>
</header>
<code className="attach">tmux attach -t {s.tmuxName}</code>
<div className="row wrap">
{alive && (
<form action={messageSession} className="row grow">
<input type="hidden" name="sessionId" value={s.id} />
<input type="hidden" name="back" value={back} />
<input type="text" name="text" placeholder="Сообщение в сессию" aria-label="Сообщение в сессию" />
<button>Отправить</button>
</form>
)}
{alive ? (
<form action={stopTaskSession}>
<input type="hidden" name="sessionId" value={s.id} />
<input type="hidden" name="back" value={back} />
<button className="danger">Остановить</button>
</form>
) : null}
{(!alive || ["rate_limited", "stalled"].includes(s.status)) && (
<form action={resumeTaskSession}>
<input type="hidden" name="sessionId" value={s.id} />
<input type="hidden" name="back" value={back} />
<button>Resume</button>
</form>
)}
</div>
</article>
);
}