peppa/apps/web/app/(app)/t/[key]/page.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

85 lines
3.6 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 { notFound } from "next/navigation";
import { AutoRefresh } from "@/components/AutoRefresh";
import { ago, Badge, Flash, QuestionCard, SessionCard } from "@/components/ui";
import { requireUser } from "@/lib/auth";
import { openspecArtifacts, taskActivity, taskForUser } from "@/lib/queries";
import { db } from "@/lib/db";
import { goals } from "@peppa/db";
import { eq } from "drizzle-orm";
import { startTaskSession } from "../../actions";
export default async function TaskPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string }> }) {
const user = await requireUser();
const { key } = await params;
const { error } = await searchParams;
const ref = await taskForUser(user.id, decodeURIComponent(key)).catch(() => null);
if (!ref) notFound();
const { task, project } = ref;
const [goal] = task.goalId ? await db.select().from(goals).where(eq(goals.id, task.goalId)) : [];
const { questions, sessions, events } = await taskActivity(task.id);
const artifacts = openspecArtifacts(project, task.openspecChange);
const back = `/t/${ref.key}`;
return (
<>
<AutoRefresh />
<Flash error={error} />
<p className="crumbs">
<Link href={`/p/${project.key}`}>{project.name}</Link>
{goal && <> · 🎯 {goal.title}</>}
</p>
<h1>
<span className="mono">{ref.key}</span> {task.title} <Badge status={task.status} />
</h1>
{task.prUrl && <p><a href={task.prUrl}>PR</a></p>}
<p className="desc">{task.description || <span className="muted">Без описания</span>}</p>
<section>
<h2>Сессии</h2>
<form action={startTaskSession} className="row wrap">
<input type="hidden" name="taskKey" value={ref.key} />
<input type="hidden" name="back" value={back} />
<select name="provider" defaultValue="claude" aria-label="Агент">
<option value="claude">Claude Code</option>
<option value="codex">Codex</option>
</select>
<input type="text" name="prompt" placeholder="Доп. инструкция (необязательно)" aria-label="Доп. инструкция" className="grow" />
<button className="primary">Запустить агента</button>
</form>
{sessions.map((s) => <SessionCard key={s.id} s={s} back={back} />)}
</section>
<section>
<h2>Вопросы</h2>
{questions.length === 0 ? <p className="empty">Вопросов не было.</p> : questions.map((q) => <QuestionCard key={q.id} q={q} taskStatus={task.status} back={back} />)}
</section>
<section>
<h2>OpenSpec {task.openspecChange && <span className="mono muted">{task.openspecChange}</span>}</h2>
{artifacts?.length ? (
artifacts.map((a) => (
<details key={a.name} open={a.name === "proposal.md"}>
<summary className="mono">{a.name}</summary>
<pre className="md">{a.text}</pre>
</details>
))
) : (
<p className="empty">Change ещё не создан.</p>
)}
</section>
<section>
<h2>События</h2>
<ul className="events">
{events.map((e) => (
<li key={e.id}>
<span className="muted">{ago(e.createdAt)}</span> <span className="mono">{e.type}</span>{" "}
{e.type === "progress" ? (e.payload as { text: string }).text : e.type === "task_updated" ? JSON.stringify((e.payload as { to: unknown }).to) : ""}
</li>
))}
</ul>
</section>
</>
);
}