From adb2286929b281574a1690bb93d9f7491390ab5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=B6n?= Date: Fri, 30 Oct 2026 14:58:42 +0000 Subject: [PATCH] =?UTF-8?q?fleet(tower):=200.20-Features=20nachziehen=20?= =?UTF-8?q?=E2=80=94=20nar-history,=20release-feed,=20task-redispatch=20AP?= =?UTF-8?q?I=20+=20OpsPanels=20(live=20in=200.20=20gebaut,=20bisher=20nur?= =?UTF-8?q?=20Working=20Tree)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/fleet/nar-history/route.ts | 61 +++++ app/api/fleet/release-feed/route.ts | 63 +++++ app/api/fleet/task-redispatch/route.ts | 59 +++++ app/components/Sidebar.tsx | 16 +- app/components/fleet/OpsPanels.tsx | 345 +++++++++++++++++++++++++ app/lib/fleet/boardSource.ts | 196 ++++++++++++++ app/page.tsx | 11 +- 7 files changed, 749 insertions(+), 2 deletions(-) create mode 100644 app/api/fleet/nar-history/route.ts create mode 100644 app/api/fleet/release-feed/route.ts create mode 100644 app/api/fleet/task-redispatch/route.ts create mode 100644 app/components/fleet/OpsPanels.tsx create mode 100644 app/lib/fleet/boardSource.ts diff --git a/app/api/fleet/nar-history/route.ts b/app/api/fleet/nar-history/route.ts new file mode 100644 index 0000000..6b1e888 --- /dev/null +++ b/app/api/fleet/nar-history/route.ts @@ -0,0 +1,61 @@ +import { NextResponse } from "next/server" +import { loadNarHistory } from "@/app/lib/fleet/boardSource" + +export const dynamic = "force-dynamic" + +/** + * GET /api/fleet/nar-history — NAR-Historie (Karte tower-nar-historie). + * + * Vollzogene Rueckbauten (Datum, Grant, Ziel, Nachweis) chronologisch plus + * ausstehende Rueckbau-Karten mit Faelligkeit und Ueberfaelligkeits-Marke. + * Quelle: Board-PVC (ideen-register + release-notes), read-only. + * Nie 5xx: fehlende Daten -> leere Listen + degraded/error im Body. + */ +export async function GET() { + try { + const { history, ausstehend, today } = loadNarHistory() + const ueberfaellig = ausstehend.filter((e) => e.ueberfaellig) + const badgeCount = ueberfaellig.length || ausstehend.length + return NextResponse.json( + { + generated_at: new Date().toISOString(), + today, + refresh_seconds: 30, + degraded: false, + degraded_reason: "", + vollzogen_count: history.length, + ausstehend_count: ausstehend.length, + ueberfaellig_count: ueberfaellig.length, + badge: { + count: badgeCount, + level: ueberfaellig.length ? "red" : ausstehend.length ? "yellow" : "green", + label: ueberfaellig.length + ? `${ueberfaellig.length} Rueckbau ueberfaellig` + : ausstehend.length + ? `${ausstehend.length} Rueckbau ausstehend` + : "keine Rueckbauten offen", + }, + history, + ausstehend, + }, + { headers: { "Cache-Control": "no-store" } } + ) + } catch (e) { + return NextResponse.json( + { + generated_at: new Date().toISOString(), + today: new Date().toISOString().slice(0, 10), + refresh_seconds: 30, + degraded: true, + degraded_reason: e instanceof Error ? e.message : String(e), + vollzogen_count: 0, + ausstehend_count: 0, + ueberfaellig_count: 0, + badge: { count: 0, level: "yellow", label: "Quelle nicht lesbar" }, + history: [], + ausstehend: [], + }, + { status: 200, headers: { "Cache-Control": "no-store" } } + ) + } +} diff --git a/app/api/fleet/release-feed/route.ts b/app/api/fleet/release-feed/route.ts new file mode 100644 index 0000000..43c09da --- /dev/null +++ b/app/api/fleet/release-feed/route.ts @@ -0,0 +1,63 @@ +import { NextResponse } from "next/server" +import { listBoardValueStreams, loadReleaseLines, type ReleaseLine } from "@/app/lib/fleet/boardSource" + +export const dynamic = "force-dynamic" + +/** + * GET /api/fleet/release-feed — Release-Notes-Feed (Karte tower-release-notes-feed). + * + * Chronologische Lieferliste (Release-Notes aller Wertstreams), optional + * gefiltert nach Agent (?agent=ciso) und begrenzt (?limit=50, max 500). + * Quelle: Board-PVC read-only. Nie 5xx — leere Liste + degraded im Body. + */ +export async function GET(req: Request) { + try { + const url = new URL(req.url) + const agent = (url.searchParams.get("agent") || "").trim() + const vsFilter = (url.searchParams.get("vs") || "").trim() + const limitRaw = Number(url.searchParams.get("limit") || "80") + const limit = Math.min(Math.max(Number.isFinite(limitRaw) ? limitRaw : 80, 1), 500) + + let streams = listBoardValueStreams() + if (vsFilter) streams = streams.filter((s) => s === vsFilter) + + let lines: ReleaseLine[] = [] + for (const vs of streams) lines = lines.concat(loadReleaseLines(vs)) + lines.sort((a, b) => (b.epoch ?? 0) - (a.epoch ?? 0)) + const all = lines + const filtered = agent ? lines.filter((l) => l.agent === agent) : lines + + const agents = [...new Set(all.map((l) => l.agent).filter(Boolean))].sort() + return NextResponse.json( + { + generated_at: new Date().toISOString(), + refresh_seconds: 30, + degraded: false, + degraded_reason: "", + total: all.length, + matching: filtered.length, + shown: Math.min(filtered.length, limit), + filter: { agent, vs: vsFilter, limit }, + agents, + entries: filtered.slice(0, limit), + }, + { headers: { "Cache-Control": "no-store" } } + ) + } catch (e) { + return NextResponse.json( + { + generated_at: new Date().toISOString(), + refresh_seconds: 30, + degraded: true, + degraded_reason: e instanceof Error ? e.message : String(e), + total: 0, + matching: 0, + shown: 0, + filter: { agent: "", vs: "", limit: 80 }, + agents: [], + entries: [], + }, + { status: 200, headers: { "Cache-Control": "no-store" } } + ) + } +} diff --git a/app/api/fleet/task-redispatch/route.ts b/app/api/fleet/task-redispatch/route.ts new file mode 100644 index 0000000..6d34819 --- /dev/null +++ b/app/api/fleet/task-redispatch/route.ts @@ -0,0 +1,59 @@ +import { NextResponse } from "next/server" +import { FLEET_BOARD_MCP_URL, mcpCallTool } from "@/app/lib/fleet/fleetSource" + +export const dynamic = "force-dynamic" + +/** + * POST /api/fleet/task-redispatch — Dead-Letter-Re-Dispatch (Karte + * tower-deadletter-redispatch). + * + * Der Tower schreibt NIE selbst in den Spool (Single-Writer-Prinzip): der + * Aufruf geht an das board-service-Tool redispatch_task, das den neuen + * Envelope `redis-` anlegt, das Original als re-dispatched markiert + * und journalisiert. Fachliche Fehler (ERR_*) kommen als 200 mit result zurueck + * (die Zeile zeigt sie an); nur Transport-/MCP-Fehler werden 502. + */ +export async function POST(req: Request) { + let body: { id?: unknown; task_id?: unknown } = {} + try { + body = (await req.json()) as { id?: unknown; task_id?: unknown } + } catch { + return NextResponse.json( + { result: "ERR_INVALID", reason: "JSON-Body fehlt oder ist kaputt" }, + { status: 400 } + ) + } + const id = String(body.id ?? body.task_id ?? "").trim() + if (!id) { + return NextResponse.json( + { result: "ERR_INVALID", reason: "Parameter id fehlt" }, + { status: 400 } + ) + } + + const call = await mcpCallTool(FLEET_BOARD_MCP_URL, "redispatch_task", { task_id: id }, 25000) + if (!call.ok) { + return NextResponse.json( + { result: "ERR_DISPATCH_FAILED", task_id: id, reason: call.error || "board-service nicht erreichbar" }, + { status: 502 } + ) + } + // MCP liefert den Tool-Text als String-JSON (board-service json.dumps). + let payload: Record + const data = call.data + if (typeof data === "string") { + try { + payload = JSON.parse(data) as Record + } catch { + payload = { result: "ERR_DISPATCH_FAILED", task_id: id, reason: data.slice(0, 300) } + } + } else if (data && typeof data === "object") { + payload = data as Record + } else { + payload = { result: "ERR_DISPATCH_FAILED", task_id: id, reason: "leere Antwort" } + } + return NextResponse.json( + { ...payload, task_id: id, at: new Date().toISOString() }, + { headers: { "Cache-Control": "no-store" } } + ) +} diff --git a/app/components/Sidebar.tsx b/app/components/Sidebar.tsx index 796731a..6a78ed3 100644 --- a/app/components/Sidebar.tsx +++ b/app/components/Sidebar.tsx @@ -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' + activeView: 'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp' | 'org' | 'messages' | 'board' | 'owner' | 'escalations' | 'approvals' | 'fleet-sandboxes' | 'tasks' | 'ops' isCreateMode: boolean isDestroyMode: boolean onSandboxesClick: () => void @@ -33,6 +33,7 @@ interface SidebarProps { onFleetEscalationsClick: () => void onFleetSandboxesClick: () => void onFleetTasksClick: () => void + onFleetOpsClick: () => void onExitMode: () => void onLogout: () => void terminalDisabled?: boolean @@ -62,6 +63,7 @@ export default function Sidebar({ onFleetEscalationsClick, onFleetSandboxesClick, onFleetTasksClick, + onFleetOpsClick, onExitMode, onLogout, terminalDisabled = false, @@ -268,6 +270,18 @@ export default function Sidebar({ Tasks + + + ) + + return ( +
+
+
+
+

+ Betrieb & Audit +

+

+ Rueckbau-Lebenszyklus (NAR) und Lieferliste — read-only aus dem Board, 30 s Refresh. +

+
+
+ {nar && ( + + {nar.badge.label} + + )} + +
+
+
+ {tabBtn('nar', 'NAR-Historie', nar?.ausstehend_count)} + {tabBtn('releases', 'Release-Feed', rel?.total)} +
+ {err && ( +

+ Datenquelle eingeschraenkt: {err} +

+ )} +
+ + {tab === 'nar' && ( +
+
+

+ Ausstehende Rueckbauten ({nar?.ausstehend.length ?? 0}) +

+ + + + + + + + + + + + + {(nar?.ausstehend ?? []).map((e) => ( + + + + + + + + + ))} + {nar && nar.ausstehend.length === 0 && ( + + + + )} + +
KarteFaelligStatusGrantZielTitel
{e.karte} + {e.datum || 'ohne Datum'} + {e.faellig_in_tagen !== null && !e.ueberfaellig && e.faellig_in_tagen <= 7 && ( + + (in {e.faellig_in_tagen} T) + + )} + {e.ueberfaellig && ( + + ({Math.abs(e.faellig_in_tagen ?? 0)} T ueberfaellig) + + )} + {e.status}{e.grant || '—'}{e.ziel || '—'} + {e.titel} +
+ Keine offenen Rueckbauten. +
+
+ +
+

+ Vollzogen ({nar?.history.length ?? 0}) +

+ + + + + + + + + + + + + {(nar?.history ?? []).map((e) => ( + + + + + + + + + ))} + {nar && nar.history.length === 0 && ( + + + + )} + +
DatumKarteGrantZielAgentNachweis
+ {e.datum || '—'} + {e.karte}{e.grant || '—'}{e.ziel || '—'}{e.agent || '—'} + {e.nachweis || '—'} +
+ Noch kein Rueckbau vollzogen. +
+
+
+ )} + + {tab === 'releases' && ( +
+
+

+ Lieferliste ({rel?.shown ?? 0} von {rel?.matching ?? 0}) +

+ +
+
    + {(rel?.entries ?? []).map((e, i) => ( +
  • + + {fmt(e.iso)} + + {e.agent && ( + + {e.agent} + + )} +

    {e.text}

    +
  • + ))} + {rel && rel.entries.length === 0 && ( +
  • + Keine Release-Notes im Filter. +
  • + )} +
+
+ )} +
+ ) +} diff --git a/app/lib/fleet/boardSource.ts b/app/lib/fleet/boardSource.ts new file mode 100644 index 0000000..de8e914 --- /dev/null +++ b/app/lib/fleet/boardSource.ts @@ -0,0 +1,196 @@ +/** + * fleet/boardSource.ts — Read-only Zugriff auf die Board-Ablage (PVC fleet-board). + * + * Der Tower mountet das Board-PVC seit 0.19 READ-ONLY; geschrieben wird + * weiterhin ausschliesslich ueber den board-service (Single-Writer-Prinzip). + * Zweck: NAR-Historie (Rueckbau-Karten + Vollzug-Nachweise) und der + * Release-Notes-Feed brauchen die Board-Dateien, fuer die es kein MCP-Tool gibt. + * + * Datenformate: + * - /ideen-register.md Markdown-Tabelle | karte_id | titel | score | status | ursprung | epoch | + * - /release-notes.md Zeilen "- [ISO-8601] text (von agent)" + */ +import { readFileSync, readdirSync, existsSync, statSync } from "node:fs" +import path from "node:path" + +export const FLEET_BOARD_DIR = process.env.FLEET_BOARD_DIR || "/srv/fleet/board" + +export type BoardCard = { + karte_id: string + titel: string + score: number | null + status: string + ursprung: string + created: number | null + vs: string +} + +export type ReleaseLine = { + iso: string + epoch: number | null + text: string + agent: string + vs: string +} + +function cell(value: string): string { + return value.trim().replace(/^`|`$/g, "").trim() +} + +/** Wertstreams = Unterverzeichnisse mit ideen-register.md (fail-loud-los: leere Liste). */ +export function listBoardValueStreams(): string[] { + if (!existsSync(FLEET_BOARD_DIR)) return [] + return readdirSync(FLEET_BOARD_DIR) + .filter((name) => { + const p = path.join(FLEET_BOARD_DIR, name) + try { + return statSync(p).isDirectory() && existsSync(path.join(p, "ideen-register.md")) + } catch { + return false + } + }) + .sort() +} + +/** Karten eines Wertstreams aus ideen-register.md (kaputte Zeilen werden uebersprungen). */ +export function loadBoardCards(vs: string): BoardCard[] { + const file = path.join(FLEET_BOARD_DIR, vs, "ideen-register.md") + if (!existsSync(file)) return [] + const out: BoardCard[] = [] + for (const raw of readFileSync(file, "utf8").split("\n")) { + const line = raw.trim() + if (!line.startsWith("|")) continue + const cols = line.split("|").slice(1, -1).map(cell) + if (cols.length < 5) continue + if (/^karte.?id$/i.test(cols[0]) || /^-+$/.test(cols[0])) continue + const scoreRaw = Number(cols[2]) + const createdRaw = Number(cols[5]) + out.push({ + karte_id: cols[0], + titel: cols[1], + score: Number.isFinite(scoreRaw) ? scoreRaw : null, + status: cols[3], + ursprung: cols[4], + created: Number.isFinite(createdRaw) && createdRaw > 0 ? createdRaw : null, + vs, + }) + } + return out +} + +/** Release-Notes-Zeilen eines Wertstreams, neueste zuerst. */ +export function loadReleaseLines(vs: string): ReleaseLine[] { + const file = path.join(FLEET_BOARD_DIR, vs, "release-notes.md") + if (!existsSync(file)) return [] + const out: ReleaseLine[] = [] + for (const raw of readFileSync(file, "utf8").split("\n")) { + const line = raw.trim() + const m = line.match(/^-\s*\[([^\]]+)\]\s*(.*)$/) + if (!m) continue + const iso = m[1].trim() + let text = m[2].trim() + const t = Date.parse(iso) + let agent = "" + const von = text.match(/\(von\s+([^)]+)\)\s*$/) + if (von) { + agent = von[1].trim() + text = text.slice(0, von.index).trim() + } else { + const dash = text.match(/—\s*([A-Za-z0-9._-]+)\s*$/) + if (dash) { + agent = dash[1].trim() + text = text.slice(0, dash.index).trim() + } + } + out.push({ + iso, + epoch: Number.isNaN(t) ? null : Math.floor(t / 1000), + text, + agent, + vs, + }) + } + return out.sort((a, b) => (b.epoch ?? 0) - (a.epoch ?? 0)) +} + +export type NarEntry = { + karte: string + titel: string + datum: string + datum_offen: boolean + faellig_in_tagen: number | null + status: string + vollzogen: boolean + ueberfaellig: boolean + grant: string + ziel: string + agent: string + nachweis: string + vs: string +} + +const TARGET_RE = /\b(\d{1,3}(?:\.\d{1,3}){3}(?::\d{1,5})?)\b/ +const DATE_RE = /\b(\d{4}-\d{2}-\d{2})\b/ +const GRANT_RE = /(?:NAR-Grant|Grant)\s+'?([A-Za-z0-9._-]{3,60})'?/i + +/** + * NAR-Historie: Rueckbau-Karten (Grant-Lebenszyklus) + Vollzug-Nachweise aus + * den Release-Notes. Datenquelle sind ausschliesslich vorhandene Board-Daten — + * keine erfundenen Eintraege: fehlt ein Datum, wird datum_offen=true gesetzt. + */ +export function loadNarHistory(vsList?: string[]): { + history: NarEntry[] + ausstehend: NarEntry[] + today: string +} { + const streams = vsList && vsList.length ? vsList : listBoardValueStreams() + const todayIso = new Date().toISOString().slice(0, 10) + const todayMs = Date.parse(`${todayIso}T00:00:00Z`) + const all: NarEntry[] = [] + for (const vs of streams) { + const cards = loadBoardCards(vs).filter( + (c) => + c.karte_id.startsWith("rueckbau-") || + /rueckbau/i.test(c.titel) || + /NAR-Grant/i.test(c.titel) + ) + const notes = loadReleaseLines(vs) + for (const c of cards) { + const dateMatch = c.titel.match(DATE_RE) + const datum = dateMatch ? dateMatch[1] : "" + let faellig: number | null = null + if (datum) { + const ms = Date.parse(`${datum}T00:00:00Z`) + if (!Number.isNaN(ms)) faellig = Math.round((ms - todayMs) / 86400000) + } + const grantMatch = c.titel.match(GRANT_RE) + const targetMatch = c.titel.match(TARGET_RE) + const status = c.status + const vollzogen = /^fertig$/i.test(status) + // Nachweis: Release-Note, die die Karten-ID nennt (Vollzug) — erste Uebereinstimmung. + const proof = notes.find((n) => n.text.includes(c.karte_id)) + all.push({ + karte: c.karte_id, + titel: c.titel, + datum, + datum_offen: !datum, + faellig_in_tagen: faellig, + status, + vollzogen, + ueberfaellig: !vollzogen && faellig !== null && faellig < 0, + grant: grantMatch ? grantMatch[1] : "", + ziel: targetMatch ? targetMatch[1] : "", + agent: proof ? proof.agent : "", + nachweis: proof ? proof.text.slice(0, 300) : "", + vs, + }) + } + } + const history = all + .filter((e) => e.vollzogen) + .sort((a, b) => (b.datum || "").localeCompare(a.datum || "")) + const ausstehend = all + .filter((e) => !e.vollzogen) + .sort((a, b) => (a.faellig_in_tagen ?? 9e9) - (b.faellig_in_tagen ?? 9e9)) + return { history, ausstehend, today: todayIso } +} diff --git a/app/page.tsx b/app/page.tsx index 4bf0221..da48d8e 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -18,6 +18,7 @@ import OwnerApprovals from './components/fleet/OwnerApprovals' import EscalationHistory from './components/fleet/EscalationHistory' import SandboxFleetView from './components/fleet/SandboxFleetView' import TaskBrowser from './components/fleet/TaskBrowser' +import OpsPanels from './components/fleet/OpsPanels' import { createHydrationSafeDashboardSessionState, buildOperatorTerminalRoute, @@ -33,7 +34,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'>('org') + const [activeView, setActiveView] = useState<'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp' | 'org' | 'messages' | 'board' | 'owner' | 'escalations' | 'approvals' | 'fleet-sandboxes' | 'tasks' | 'ops'>('org') const [telemetryBarEnabled, setTelemetryBarEnabled] = useState(false) const [deletingSandboxId, setDeletingSandboxId] = useState(null) const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) @@ -290,6 +291,12 @@ export default function Dashboard() { setIsDestroyMode(false) clearSelection() }} + onFleetOpsClick={() => { + setActiveView('ops') + setIsCreateMode(false) + setIsDestroyMode(false) + clearSelection() + }} onExitMode={() => { setIsCreateMode(false) setIsDestroyMode(false) @@ -317,6 +324,8 @@ export default function Dashboard() { ) : activeView === 'tasks' ? ( + ) : activeView === 'ops' ? ( + ) : activeView === 'approvals' ? ( ) : activeView === 'escalations' ? (