Tower: View 'Wartet auf mich' — strukturierte Attention-Fragen

Der Rueckstau war bisher eine Zahl ('94 offene Tasks'). Diese View zeigt nur
Tasks mit attention-Block, also die, bei denen ein Agent ohne eine
Mensch-Entscheidung nicht weiterkommt.

- /api/fleet/attention: GET ruft attention_summary, POST ruft answer_attention.
- AttentionPanel: Frage, Optionen als Buttons, Freitextfeld, Rueckmeldung
  (OK / OK_ALREADY / OK_JOURNAL_ONLY), Poll 10 s, fail loud.
- Sidebar-View 'attention' + Verdrahtung in page.tsx.

Die Antwort geht ueber board-service answer_attention: Frage wird am Task
geschlossen (answered_at) und der Agent bekommt einen fyi-Reply-Task mit
reply_to. Kein Chat, kein Bauauftrag.
This commit is contained in:
Dominik Schön
2026-11-02 08:35:28 +00:00
parent e5261401fe
commit 13533cdb4f
4 changed files with 282 additions and 2 deletions
+52
View File
@@ -0,0 +1,52 @@
import { NextResponse } from "next/server"
import { mcpCallTool, FLEET_BOARD_MCP_URL } from "@/app/lib/fleet/fleetSource"
export const dynamic = "force-dynamic"
/**
* GET /api/fleet/attention — strukturierte Attention-Fragen.
* Ruft attention_summary() im board-service: wie viele offene Tasks warten
* wirklich auf einen MENSCHEN (Frage + Optionen), nicht nur "offen".
*/
export async function GET() {
try {
const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "attention_summary", {})
if (!res.ok) {
return NextResponse.json({ error: `attention_summary: ${res.error}` }, { status: 500 })
}
const payload = typeof res.data === "string" ? JSON.parse(res.data) : res.data
return NextResponse.json(payload, { headers: { "Cache-Control": "no-store" } })
} catch (err) {
return NextResponse.json(
{ error: `ATTENTION_FAILED: ${err instanceof Error ? err.message : String(err)}` },
{ status: 500 }
)
}
}
/**
* POST /api/fleet/attention — Antwort des Owners auf eine Attention-Frage.
* Geht ueber board-service answer_attention: setzt attention.answer am Task
* und legt beim fragenden Agenten einen fyi-Reply-Task ab.
*/
export async function POST(request: Request) {
try {
const body = (await request.json()) as { task_id?: string; answer?: string }
const task_id = String(body.task_id || "").trim()
const answer = String(body.answer || "").trim()
if (!task_id || !answer) {
return NextResponse.json({ error: "task_id und answer sind Pflicht" }, { status: 400 })
}
const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "answer_attention", { task_id, answer })
if (!res.ok) {
return NextResponse.json({ error: `answer_attention: ${res.error}` }, { status: 500 })
}
const payload = typeof res.data === "string" ? JSON.parse(res.data) : res.data
return NextResponse.json(payload, { headers: { "Cache-Control": "no-store" } })
} catch (err) {
return NextResponse.json(
{ error: `ATTENTION_ANSWER_FAILED: ${err instanceof Error ? err.message : String(err)}` },
{ status: 500 }
)
}
}
+16 -1
View File
@@ -14,7 +14,7 @@ type ControllerNodeRecord = {
interface SidebarProps {
sandboxesRunning: number
sandboxesTotal: number
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp' | 'org' | 'messages' | 'board' | 'owner' | 'escalations' | 'approvals' | 'fleet-sandboxes' | 'tasks' | 'ops'
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp' | 'org' | 'messages' | 'board' | 'owner' | 'escalations' | 'approvals' | 'attention' | 'fleet-sandboxes' | 'tasks' | 'ops'
isCreateMode: boolean
isDestroyMode: boolean
onSandboxesClick: () => void
@@ -30,6 +30,8 @@ interface SidebarProps {
onFleetBoardClick: () => void
onFleetOwnerClick: () => void
onFleetApprovalsClick: () => void
onFleetAttentionClick: () => void
onFleetEscalationsClick: () => void
onFleetSandboxesClick: () => void
onFleetTasksClick: () => void
@@ -60,6 +62,7 @@ export default function Sidebar({
onFleetBoardClick,
onFleetOwnerClick,
onFleetApprovalsClick,
onFleetAttentionClick,
onFleetEscalationsClick,
onFleetSandboxesClick,
onFleetTasksClick,
@@ -318,6 +321,18 @@ export default function Sidebar({
<span className="text-sm max-lg:text-[11px]">Owner</span>
</button>
<button
onClick={onFleetAttentionClick}
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'attention', true)}`}
aria-current={activeView === 'attention' ? 'page' : undefined}
data-testid="fleet-nav-attention"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 8v5m0 3v.5M4 4h16v12H8l-4 4V4z" />
</svg>
<span className="text-sm max-lg:text-[11px]">Wartet auf mich</span>
</button>
<button
onClick={onFleetApprovalsClick}
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'approvals', true)}`}
+204
View File
@@ -0,0 +1,204 @@
"use client"
import { useEffect, useState } from "react"
/**
* AttentionPanel — der Rueckstau, der wirklich dich meint (02.11.2026).
*
* "73 offene Tasks" ist keine handlungsfaehige Zahl. Dieses Panel zeigt nur
* Tasks mit strukturierter Frage (attention.question + options), also die,
* bei denen ein Agent ohne eine Mensch-Entscheidung nicht weiterkommt.
*
* Antwort geht ueber board-service answer_attention: Frage wird am Task
* geschlossen (answered_at) und der Agent bekommt einen fyi-Reply-Task.
* Poll 10 s, fail loud.
*/
type AttentionItem = {
task_id: string
to: string
from: string
priority: string
status: string
age_s: number | null
question: string
options: string[]
}
type AttentionSummary = {
open_total: number
waiting_on_person: number
by_recipient: Record<string, number>
items: AttentionItem[]
}
function age(seconds: number | null): string {
if (seconds === null || seconds < 0) return "?"
if (seconds < 3600) return `${Math.floor(seconds / 60)} min`
if (seconds < 86400) return `${Math.floor(seconds / 3600)} h`
return `${Math.floor(seconds / 86400)} d`
}
export default function AttentionPanel() {
const [data, setData] = useState<AttentionSummary | null>(null)
const [error, setError] = useState<string | null>(null)
const [busy, setBusy] = useState<string | null>(null)
const [feedback, setFeedback] = useState<{ ok: boolean; msg: string } | null>(null)
const [draft, setDraft] = useState<Record<string, string>>({})
const load = () => {
fetch("/api/fleet/attention", { cache: "no-store" })
.then(async (res) => {
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
return res.json()
})
.then((d: AttentionSummary) => {
setData(d)
setError(null)
})
.catch((e: Error) => setError(e.message))
}
useEffect(() => {
load()
const t = setInterval(load, 10000)
return () => clearInterval(t)
}, [])
const answer = async (taskId: string, text: string) => {
if (!text.trim()) {
setFeedback({ ok: false, msg: "Antwort ist leer — nichts gesendet." })
return
}
setBusy(taskId)
setFeedback(null)
try {
const res = await fetch("/api/fleet/attention", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ task_id: taskId, answer: text.trim() }),
})
const d = await res.json()
if (!res.ok) throw new Error(d.error || `HTTP ${res.status}`)
if (d.result === "OK_ALREADY") {
setFeedback({ ok: true, msg: "Bereits beantwortet — nichts doppelt gesendet." })
} else if (d.result === "OK_JOURNAL_ONLY") {
setFeedback({
ok: true,
msg: `Frage geschlossen. Absender '${d.from}' ist ein Systemdienst — Antwort nur im Journal.`,
})
} else {
setFeedback({ ok: true, msg: `Beantwortet. Antwort-Task ${d.antwort_task?.slice(0, 8)} an ${d.an}.` })
}
setDraft((p) => ({ ...p, [taskId]: "" }))
load()
} catch (e) {
setFeedback({ ok: false, msg: e instanceof Error ? e.message : String(e) })
} finally {
setBusy(null)
}
}
const items = data?.items ?? []
const waiting = data?.waiting_on_person ?? 0
const openTotal = data?.open_total ?? 0
return (
<div className="space-y-6">
<div className="panel p-6">
<div className="flex flex-wrap items-baseline justify-between gap-3">
<div>
<h2 className="text-xl font-semibold">Wartet auf dich</h2>
<p className="mt-1 text-sm text-neutral-400">
Strukturierte Fragen mit Entscheidungsbedarf — der Rest des Rueckstaus ist Agentenarbeit.
</p>
</div>
<div className="text-right">
<div className="text-3xl font-semibold tabular-nums">{waiting}</div>
<div className="text-xs text-neutral-400">von {openTotal} offenen Tasks</div>
</div>
</div>
{Object.keys(data?.by_recipient ?? {}).length > 0 && (
<div className="mt-4 flex flex-wrap gap-2 text-xs text-neutral-400">
{Object.entries(data!.by_recipient).map(([who, n]) => (
<span key={who} className="rounded border border-neutral-700 px-2 py-0.5">
{who}: {n}
</span>
))}
</div>
)}
{error && (
<div className="mt-4 rounded border border-red-800 bg-red-950/40 p-3 text-sm text-red-300">
{error}
</div>
)}
{feedback && (
<div
className={`mt-4 rounded border p-3 text-sm ${
feedback.ok
? "border-emerald-800 bg-emerald-950/40 text-emerald-300"
: "border-red-800 bg-red-950/40 text-red-300"
}`}
>
{feedback.msg}
</div>
)}
</div>
{items.length === 0 && !error && (
<div className="panel p-6 text-sm text-neutral-400">
Keine offene Frage braucht gerade eine menschliche Entscheidung. Wenn das dauerhaft so
bleibt, obwohl Agenten haengen, fehlt ihnen das <code>attention</code>-Feld — dann ist
die Skill-Seite dran, nicht die Anzeige.
</div>
)}
{items.map((it) => (
<div key={it.task_id} className="panel p-6">
<div className="flex flex-wrap items-start justify-between gap-3">
<div className="min-w-0">
<div className="text-sm text-neutral-400">
{it.from} → {it.to} · {it.priority} · {it.status} · seit {age(it.age_s)}
</div>
<div className="mt-2 text-base font-medium">{it.question}</div>
</div>
<code className="shrink-0 text-xs text-neutral-500">{it.task_id.slice(0, 8)}</code>
</div>
{it.options?.length > 0 && (
<div className="mt-4 flex flex-wrap gap-2">
{it.options.map((opt) => (
<button
key={opt}
disabled={busy === it.task_id}
onClick={() => answer(it.task_id, opt)}
className="rounded border border-neutral-700 px-3 py-1.5 text-sm hover:border-neutral-500 hover:bg-neutral-800 disabled:opacity-50"
>
{opt}
</button>
))}
</div>
)}
<div className="mt-3 flex flex-wrap gap-2">
<input
value={draft[it.task_id] ?? ""}
onChange={(e) => setDraft((p) => ({ ...p, [it.task_id]: e.target.value }))}
placeholder="Oder eigene Antwort…"
className="min-w-0 flex-1 rounded border border-neutral-700 bg-neutral-900 px-3 py-1.5 text-sm"
/>
<button
disabled={busy === it.task_id}
onClick={() => answer(it.task_id, draft[it.task_id] ?? "")}
className="rounded bg-neutral-100 px-4 py-1.5 text-sm font-medium text-neutral-900 hover:bg-white disabled:opacity-50"
>
{busy === it.task_id ? "sendet…" : "Antworten"}
</button>
</div>
</div>
))}
</div>
)
}
+10 -1
View File
@@ -15,6 +15,7 @@ import MessageFeed from './components/fleet/MessageFeed'
import KanbanBoard from './components/fleet/KanbanBoard'
import OwnerPanel from './components/fleet/OwnerPanel'
import OwnerApprovals from './components/fleet/OwnerApprovals'
import AttentionPanel from './components/fleet/AttentionPanel'
import EscalationHistory from './components/fleet/EscalationHistory'
import SandboxFleetView from './components/fleet/SandboxFleetView'
import TaskBrowser from './components/fleet/TaskBrowser'
@@ -34,7 +35,7 @@ export default function Dashboard() {
const [dashboardSession, setDashboardSession] = useState(() => createHydrationSafeDashboardSessionState())
const [isCreateMode, setIsCreateMode] = useState(false)
const [isDestroyMode, setIsDestroyMode] = useState(false)
const [activeView, setActiveView] = useState<'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp' | 'org' | 'messages' | 'board' | 'owner' | 'escalations' | 'approvals' | 'fleet-sandboxes' | 'tasks' | 'ops'>('org')
const [activeView, setActiveView] = useState<'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp' | 'org' | 'messages' | 'board' | 'owner' | 'escalations' | 'approvals' | 'attention' | 'fleet-sandboxes' | 'tasks' | 'ops'>('org')
const [telemetryBarEnabled, setTelemetryBarEnabled] = useState(false)
const [deletingSandboxId, setDeletingSandboxId] = useState<string | null>(null)
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
@@ -273,6 +274,12 @@ export default function Dashboard() {
setIsDestroyMode(false)
clearSelection()
}}
onFleetAttentionClick={() => {
setActiveView('attention')
setIsCreateMode(false)
setIsDestroyMode(false)
clearSelection()
}}
onFleetEscalationsClick={() => {
setActiveView('escalations')
setIsCreateMode(false)
@@ -326,6 +333,8 @@ export default function Dashboard() {
<TaskBrowser />
) : activeView === 'ops' ? (
<OpsPanels />
) : activeView === 'attention' ? (
<AttentionPanel />
) : activeView === 'approvals' ? (
<OwnerApprovals />
) : activeView === 'escalations' ? (