Compare commits
15
Commits
7ec2969c7a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13533cdb4f | ||
|
|
e5261401fe | ||
|
|
adb2286929 | ||
|
|
e9c8b14ee6 | ||
|
|
9e94512214 | ||
|
|
fa3d5d0a8f | ||
|
|
11840644c8 | ||
|
|
52fe7a2d83 | ||
|
|
f70c10d767 | ||
|
|
4e2d51e84a | ||
|
|
85c6777c55 | ||
|
|
6154088197 | ||
|
|
270eb109f1 | ||
|
|
cbbdd1b4d2 | ||
|
|
5f8e30c33e |
@@ -0,0 +1,8 @@
|
|||||||
|
node_modules
|
||||||
|
.next
|
||||||
|
.git
|
||||||
|
.env.local
|
||||||
|
npm-debug.log*
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
|
__pycache__
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
# Fleet Control Tower — Phase 0.13 (Fork nemo-shell-dashboard).
|
||||||
|
# Custom-Server (server.mjs + next({dev:false})) — KEIN standalone-Output;
|
||||||
|
# Runtime braucht: .next (build), node_modules (prod), server.mjs, public/.
|
||||||
|
FROM docker.io/library/node:22-bookworm-slim AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# node-pty ist eine native dep (spawnpty) — braucht python3+make+gcc fuer node-gyp.
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends python3 make g++ \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci --no-audit --no-fund
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
# Upstream-Host-Features im Tower-Image abschalten (kein Login, kein Telemetry).
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1 OPENSHELL_CONTROL_AUTH_DISABLED=1
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM docker.io/library/node:22-bookworm-slim AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production NEXT_TELEMETRY_DISABLED=1 OPENSHELL_CONTROL_AUTH_DISABLED=1 PORT=3000
|
||||||
|
# KEIN npm ci hier: node_modules kommt komplett (inkl. kompiliertem node-pty)
|
||||||
|
# aus dem Builder — ein Runtime-npm-ci wuerde node-pty ohne python/make/g++
|
||||||
|
# neu kompilieren und brechen, und danach eh vom COPY ueberschrieben.
|
||||||
|
# node:22-bookworm-slim hat GID 1000 (node) belegt — Tower-User auf 1001.
|
||||||
|
COPY --from=builder /app/package.json /app/package-lock.json ./
|
||||||
|
RUN addgroup --system --gid 1001 tower \
|
||||||
|
&& adduser --system --uid 1001 --ingroup tower tower
|
||||||
|
COPY --from=builder --chown=tower:tower /app/.next ./.next
|
||||||
|
COPY --from=builder --chown=tower:tower /app/public ./public
|
||||||
|
COPY --from=builder --chown=tower:tower /app/server.mjs ./server.mjs
|
||||||
|
# terminal-server (spawnpty-Backend fuer /api/openshell/terminal/*) + Sidecars:
|
||||||
|
# server.mjs autostartet terminal-server.mjs und den inter-sandbox-chat-sidecar
|
||||||
|
# — beide mssen im Image liegen, sonst crashen die Subprozesse (MODULE_NOT_FOUND).
|
||||||
|
COPY --from=builder --chown=tower:tower /app/terminal-server.mjs ./terminal-server.mjs
|
||||||
|
COPY --from=builder --chown=tower:tower /app/scripts ./scripts
|
||||||
|
COPY --from=builder --chown=tower:tower /app/node_modules ./node_modules
|
||||||
|
USER tower
|
||||||
|
EXPOSE 3000
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
|
||||||
|
CMD node -e "fetch('http://127.0.0.1:3000/').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"
|
||||||
|
CMD ["node", "server.mjs"]
|
||||||
@@ -45,11 +45,11 @@ It is currently built for active development and lab use. It includes a simple p
|
|||||||
|
|
||||||
## Compatibility Targets
|
## Compatibility Targets
|
||||||
|
|
||||||
This dashboard is validated against the current NVIDIA NemoClaw repo and the OpenShell version range declared in NemoClaw's `nemoclaw-blueprint/blueprint.yaml`, not the older April 2026 point releases. Current NemoClaw `main` pins OpenShell exactly to `0.0.106`, so the bundled refresh helper defaults to:
|
This dashboard is validated against the current NVIDIA NemoClaw repo and the OpenShell version range declared in NemoClaw's `nemoclaw-blueprint/blueprint.yaml`, not the older April 2026 point releases. Current NemoClaw `main` pins OpenShell exactly to `0.0.116`, so the bundled refresh helper defaults to:
|
||||||
|
|
||||||
- OpenShell installer release: `v0.0.106` (`OPENSHELL_VERSION=v0.0.106`)
|
- OpenShell installer release: `v0.0.116` (`OPENSHELL_VERSION=v0.0.116`)
|
||||||
- NemoClaw source ref: `main` (`NEMOCLAW_INSTALL_REF=main`)
|
- NemoClaw source ref: `main` (`NEMOCLAW_INSTALL_REF=main`)
|
||||||
- OpenClaw base-image build target: `2026.7.1` (`OPENCLAW_VERSION=2026.7.1`) unless overridden
|
- OpenClaw base-image build target: `2026.9.2` (`OPENCLAW_VERSION=2026.9.2`) unless overridden
|
||||||
|
|
||||||
Runtime/toolchain versions used during development:
|
Runtime/toolchain versions used during development:
|
||||||
|
|
||||||
@@ -60,6 +60,8 @@ Runtime/toolchain versions used during development:
|
|||||||
- OpenShell CLI and gateway compatible with current `NVIDIA/NemoClaw` blueprint constraints
|
- OpenShell CLI and gateway compatible with current `NVIDIA/NemoClaw` blueprint constraints
|
||||||
- NemoClaw CLI compatible with the current `NVIDIA/NemoClaw` repo
|
- NemoClaw CLI compatible with the current `NVIDIA/NemoClaw` repo
|
||||||
|
|
||||||
|
Sandbox creation follows NemoClaw's OpenShell routed-name contract: names are 1-19 characters, start with a lowercase letter, contain only lowercase letters, numbers, and single internal hyphens, and end with a letter or number.
|
||||||
|
|
||||||
Use `./install_versioned_nemoclaw_openshell.sh` to install or refresh the OpenShell/NemoClaw pair. Override `OPENSHELL_VERSION`, `NEMOCLAW_INSTALL_REF`, or `OPENCLAW_VERSION` only when intentionally testing a different pair.
|
Use `./install_versioned_nemoclaw_openshell.sh` to install or refresh the OpenShell/NemoClaw pair. Override `OPENSHELL_VERSION`, `NEMOCLAW_INSTALL_REF`, or `OPENCLAW_VERSION` only when intentionally testing a different pair.
|
||||||
|
|
||||||
The app uses Next.js `15.5.15`, React `18.3.1`, TypeScript, Tailwind CSS, `ws`, `node-pty`, and the official MCP TypeScript SDK.
|
The app uses Next.js `15.5.15`, React `18.3.1`, TypeScript, Tailwind CSS, `ws`, `node-pty`, and the official MCP TypeScript SDK.
|
||||||
@@ -90,6 +92,8 @@ OpenShell must already be installed and able to reach its gateway. On this host
|
|||||||
|
|
||||||
The installer does not create an OpenShell gateway for you. Start or connect OpenShell first, then install this dashboard.
|
The installer does not create an OpenShell gateway for you. Start or connect OpenShell first, then install this dashboard.
|
||||||
|
|
||||||
|
Controller commands follow OpenShell's active gateway by default. Set `OPENSHELL_GATEWAY` only for an intentional override; leaving it unset also allows current NemoClaw to restore a port-qualified gateway such as `nemoclaw-8990` when its installer selected an alternate gateway port. Quick Deploy image discovery checks both the default NemoClaw registry and its numeric alternate-port registry roots, and fails closed if a sandbox name is registered under multiple gateways.
|
||||||
|
|
||||||
## Installer
|
## Installer
|
||||||
|
|
||||||
Install or refresh the locked OpenShell/NemoClaw pair first:
|
Install or refresh the locked OpenShell/NemoClaw pair first:
|
||||||
@@ -98,7 +102,7 @@ Install or refresh the locked OpenShell/NemoClaw pair first:
|
|||||||
./install_versioned_nemoclaw_openshell.sh
|
./install_versioned_nemoclaw_openshell.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
That helper defaults to `OPENSHELL_VERSION=v0.0.106`, `NEMOCLAW_INSTALL_REF=main`, and `OPENCLAW_VERSION=2026.7.1`.
|
That helper defaults to `OPENSHELL_VERSION=v0.0.116`, `NEMOCLAW_INSTALL_REF=main`, and `OPENCLAW_VERSION=2026.9.2`.
|
||||||
|
|
||||||
Then install the dashboard from the repository root:
|
Then install the dashboard from the repository root:
|
||||||
|
|
||||||
@@ -221,7 +225,11 @@ The dashboard shells out to the OpenShell CLI for several operations:
|
|||||||
- `openshell provider create/update/delete/list`
|
- `openshell provider create/update/delete/list`
|
||||||
- `openshell inference set/get/update`
|
- `openshell inference set/get/update`
|
||||||
|
|
||||||
The **Quick Deploy New NemoClaw Sandbox** path clones a registered image through OpenShell, but it deliberately does not write the clone into NemoClaw's private `sandboxes.json`. Current NemoClaw entries include lifecycle identity, policy-authority, and workload receipts that must be issued by NemoClaw itself. The clone remains visible and operable through OpenShell Control; use **Fresh NemoClaw Image** when the new sandbox must participate in NemoClaw-managed lifecycle operations.
|
The **Quick Deploy New NemoClaw Sandbox** path clones a registered image through OpenShell, but it deliberately does not write the clone into NemoClaw's private `sandboxes.json`. Current NemoClaw entries include lifecycle identity, workload provenance, and agent-specific state that must be issued by NemoClaw itself. The clone remains visible and operable through OpenShell Control; use **Fresh NemoClaw Image** when the new sandbox must participate in NemoClaw-managed lifecycle operations.
|
||||||
|
|
||||||
|
Sandbox gateway restarts use NemoClaw's native-agent lifecycle command. The controller does not kill or launch OpenClaw or Hermes gateway processes directly; if NemoClaw cannot verify the restart, the request fails without bypassing the agent-owned lifecycle boundary.
|
||||||
|
|
||||||
|
OpenClaw owns `openclaw.json` after first launch. Controller-managed MCP and inference updates use OpenClaw's native `config patch --stdin` boundary and do not replace the file or recreate NemoClaw's retired `.config-hash` ownership metadata.
|
||||||
|
|
||||||
OpenClaw dashboard access is loopback-only inside the host/sandbox context, so the UI uses local proxy routes:
|
OpenClaw dashboard access is loopback-only inside the host/sandbox context, so the UI uses local proxy routes:
|
||||||
|
|
||||||
|
|||||||
@@ -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 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { readJournalTail } from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/escalations — HITL-/Escalation-Historie (Kernfeature 4):
|
||||||
|
* Journal-Filter auf type=escalation + rejected-Events (Quarantine).
|
||||||
|
* Kein psql — Escalations sind Spool-Envelopes, die DB bleibt reiner Index.
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const tail = readJournalTail(500)
|
||||||
|
const escalations = tail.filter(
|
||||||
|
(l) => l.event === "accepted" && l.type === "escalation"
|
||||||
|
)
|
||||||
|
const rejected = tail.filter((l) => l.event === "rejected")
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
escalations: escalations.reverse(),
|
||||||
|
rejected: rejected.reverse(),
|
||||||
|
counts: { escalations: escalations.length, rejected: rejected.length },
|
||||||
|
},
|
||||||
|
{ headers: { "Cache-Control": "no-store" } }
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `FLEET_ESCALATIONS_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { mcpCallTool, FLEET_BOARD_MCP_URL, cached } from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/kanban — VS-Liste + Kanban je VS (Kernfeature 3) als Proxy
|
||||||
|
* auf board-service-MCP (get_kanban / list_value_streams).
|
||||||
|
* Tower schreibt NIE direkt aufs Board-PVC (Single-Writer board-service).
|
||||||
|
* Cache 3 s (Karten-Statuswechsel erscheinen ohne Reload <=10 s, §8).
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const data = await cached("fleet-kanban", 3000, async () => {
|
||||||
|
const vsList = await mcpCallTool(FLEET_BOARD_MCP_URL, "list_value_streams")
|
||||||
|
if (!vsList.ok) throw new Error(`list_value_streams: ${vsList.error}`)
|
||||||
|
const vsIds = ((vsList.data as { value_streams?: Array<{ vs_id: string }> }).value_streams || []).map(
|
||||||
|
(v) => v.vs_id
|
||||||
|
)
|
||||||
|
const boards = await Promise.all(
|
||||||
|
vsIds.map(async (vs) => {
|
||||||
|
const board = await mcpCallTool(FLEET_BOARD_MCP_URL, "get_kanban", { vs })
|
||||||
|
if (!board.ok) throw new Error(`get_kanban(${vs}): ${board.error}`)
|
||||||
|
return { vs, board: board.data }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return { value_streams: vsIds, boards, generated_at: new Date().toISOString() }
|
||||||
|
})
|
||||||
|
return NextResponse.json(data, { headers: { "Cache-Control": "no-store" } })
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `FLEET_KANBAN_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { readJournalTail } from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/messages?limit=200&cursor=<epoch>
|
||||||
|
* Rollierendes Spool-Journal (Kernfeature 2): accepted/rejected/run_* je task_id.
|
||||||
|
* `cursor` = time_epoch des letzten sichtbaren Eintrags; geliefert werden nur
|
||||||
|
* neuere Eintraege (Aufsteigend), der Client haelt die Liste selbst.
|
||||||
|
*/
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
try {
|
||||||
|
const url = new URL(request.url)
|
||||||
|
const limit = Math.min(Number(url.searchParams.get("limit") || 200), 500)
|
||||||
|
const cursor = Number(url.searchParams.get("cursor") || 0)
|
||||||
|
const tail = readJournalTail(limit)
|
||||||
|
const filtered = cursor > 0 ? tail.filter((l) => Number(l.time_epoch || 0) > cursor) : tail
|
||||||
|
// absteigend fuer die Anzeige (neueste oben), Cursor bleibt epoch-basiert
|
||||||
|
filtered.reverse()
|
||||||
|
return NextResponse.json(
|
||||||
|
{ messages: filtered, count: filtered.length },
|
||||||
|
{ headers: { "Cache-Control": "no-store" } }
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `FLEET_MESSAGES_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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" } }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import {
|
||||||
|
loadOrg,
|
||||||
|
loadVkMapping,
|
||||||
|
loadTokenRates,
|
||||||
|
loadHeartbeatAges,
|
||||||
|
countInbox,
|
||||||
|
cached,
|
||||||
|
} from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/overview — aggregierter Org-Chart-Datensatz (Kernfeature 1).
|
||||||
|
* Alle Quellen fail-loud: eine tote Quelle -> 500 mit Klartext (Design §5.5),
|
||||||
|
* KEIN teilweises Rendering mit stillen Nullen.
|
||||||
|
* Cache 2 s (Views pollen 5 s -> max 1 upstream call je Quelle je Zyklus).
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const data = await cached("fleet-overview", 2000, async () => {
|
||||||
|
const [org, vks, rates, hearts] = await Promise.all([
|
||||||
|
loadOrg(),
|
||||||
|
loadVkMapping(),
|
||||||
|
loadTokenRates(),
|
||||||
|
loadHeartbeatAges(),
|
||||||
|
])
|
||||||
|
const inbox = countInbox()
|
||||||
|
const vkByAgent = new Map(vks.map((v) => [v.agent_id, v]))
|
||||||
|
const agents = org.members.map((m) => {
|
||||||
|
const vk = vkByAgent.get(m.agent_id)
|
||||||
|
const rate = vk ? rates[vk.vk_name] || { in: 0, out: 0 } : { in: 0, out: 0 }
|
||||||
|
const hbAge = hearts[m.agent_id]
|
||||||
|
return {
|
||||||
|
...m,
|
||||||
|
vk_name: vk?.vk_name || null,
|
||||||
|
model: vk?.model || null,
|
||||||
|
profile: vk?.profile || null,
|
||||||
|
tok_in_per_s: rate.in,
|
||||||
|
tok_out_per_s: rate.out,
|
||||||
|
inbox: inbox[m.agent_id] || 0,
|
||||||
|
heartbeat_age_s: typeof hbAge === "number" ? hbAge : null,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return { agents, generated_at: new Date().toISOString() }
|
||||||
|
})
|
||||||
|
return NextResponse.json(data, {
|
||||||
|
headers: { "Cache-Control": "no-store" },
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `FLEET_OVERVIEW_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { mcpCallTool, FLEET_BOARD_MCP_URL, readChatThreads } from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/owner/chat — Thread-Liste + Nachrichten (Kernfeature 5).
|
||||||
|
* POST /api/fleet/owner/chat — neue Owner-Nachricht in einen Thread via
|
||||||
|
* board-service submit_owner_task (type=chat, thread_id, topic) — der Tower
|
||||||
|
* schreibt NIE direkt in den Spool (Single-Writer-Disziplin via board-service).
|
||||||
|
* from=tower-owner, to=ceo; CEO-Antworten erscheinen als ceo->tower-owner?
|
||||||
|
* NEIN: to muss 9er-Org sein -> CEO-Antworten sind Tasks von ceo mit
|
||||||
|
* thread_id + reply_to; der Chat-View rendert alle type=chat-Tasks eines
|
||||||
|
* thread_id unabhaengig von from/to (solange from in 9er-Org oder tower-owner).
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const threads = readChatThreads()
|
||||||
|
return NextResponse.json(
|
||||||
|
{ threads, count: threads.length },
|
||||||
|
{ headers: { "Cache-Control": "no-store" } }
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `OWNER_CHAT_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const body = (await request.json()) as { thread_id?: string; topic?: string; message?: string }
|
||||||
|
const thread_id = String(body.thread_id || "").trim()
|
||||||
|
const topic = String(body.topic || "").trim()
|
||||||
|
const message = String(body.message || "").trim()
|
||||||
|
if (!thread_id || !message) {
|
||||||
|
return NextResponse.json({ error: "thread_id und message sind Pflicht" }, { status: 400 })
|
||||||
|
}
|
||||||
|
const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "submit_owner_task", {
|
||||||
|
to: "ceo",
|
||||||
|
type: "chat",
|
||||||
|
priority: "P3",
|
||||||
|
topic: topic || thread_id,
|
||||||
|
thread_id,
|
||||||
|
body: message,
|
||||||
|
requires_ack: false,
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
return NextResponse.json({ error: `submit_owner_task: ${res.error}` }, { status: 500 })
|
||||||
|
}
|
||||||
|
return NextResponse.json(res.data, { headers: { "Cache-Control": "no-store" } })
|
||||||
|
} catch (err) {
|
||||||
|
getErrLog(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getErrLog(err: unknown) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `OWNER_CHAT_POST_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { mcpCallTool, FLEET_BOARD_MCP_URL } from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/fleet/owner/decide — Owner-Entscheidung über einen NAR/Owner-Inbox-Task
|
||||||
|
* via board-service decide_owner_task (approve|decline). Der Tower schreibt nie
|
||||||
|
* direkt in den Spool — alles läuft über den board-service (Single-Writer).
|
||||||
|
* Response enthält folge_task (an den Antragsteller).
|
||||||
|
*/
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const body = (await request.json()) as { task_id?: string; decision?: string; note?: string }
|
||||||
|
const task_id = String(body.task_id || "").trim()
|
||||||
|
const decision = String(body.decision || "").trim()
|
||||||
|
const note = String(body.note || "")
|
||||||
|
if (!task_id || !decision) {
|
||||||
|
return NextResponse.json({ error: "task_id und decision sind Pflicht" }, { status: 400 })
|
||||||
|
}
|
||||||
|
const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "decide_owner_task", {
|
||||||
|
task_id,
|
||||||
|
decision,
|
||||||
|
note,
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
return NextResponse.json({ error: `decide_owner_task: ${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: `OWNER_DECIDE_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { mcpCallTool, FLEET_BOARD_MCP_URL } from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/fleet/owner/idea — Owner-Idee -> board-service add_backlog_card
|
||||||
|
* (ursprung=owner, immer markiert). Kernfeature 5, E-V3: "Ideen -> VS-Backlog".
|
||||||
|
* Fail loud: unbekannte VS / ungueltige Werte -> 500 mit Klartext.
|
||||||
|
*/
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const body = (await request.json()) as {
|
||||||
|
vs?: string
|
||||||
|
karte_id?: string
|
||||||
|
titel?: string
|
||||||
|
wert?: number
|
||||||
|
machbarkeit?: number
|
||||||
|
}
|
||||||
|
const vs = String(body.vs || "").trim()
|
||||||
|
const karte_id = String(body.karte_id || "").trim()
|
||||||
|
const titel = String(body.titel || "").trim()
|
||||||
|
const wert = Number(body.wert)
|
||||||
|
const machbarkeit = Number(body.machbarkeit)
|
||||||
|
if (!vs || !karte_id || !titel) {
|
||||||
|
return NextResponse.json({ error: "vs, karte_id und titel sind Pflicht" }, { status: 400 })
|
||||||
|
}
|
||||||
|
const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "add_backlog_card", {
|
||||||
|
vs,
|
||||||
|
karte_id,
|
||||||
|
titel,
|
||||||
|
wert,
|
||||||
|
machbarkeit,
|
||||||
|
ursprung: "owner",
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
return NextResponse.json({ error: `add_backlog_card: ${res.error}` }, { status: 500 })
|
||||||
|
}
|
||||||
|
return NextResponse.json(res.data, { headers: { "Cache-Control": "no-store" } })
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `OWNER_IDEA_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { mcpCallTool, FLEET_BOARD_MCP_URL } from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/owner/inbox — Owner-Inbox (NAR-Verfahren §1.3):
|
||||||
|
* Alle Tasks an 'tower-owner' via board-service list_owner_inbox.
|
||||||
|
* status=submitted = wartet auf Owner-Entscheidung.
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "list_owner_inbox", {})
|
||||||
|
if (!res.ok) {
|
||||||
|
return NextResponse.json({ error: `list_owner_inbox: ${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: `OWNER_INBOX_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { mcpCallTool, FLEET_BOARD_MCP_URL } from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/fleet/owner/new-vs — "Neuer Value Stream" -> CEO-Task (type=build, P2)
|
||||||
|
* via board-service submit_owner_task (neuer Tool, Phase 0.13). E-V3:
|
||||||
|
* Owner-Chat verdraengt nie den Task-Flow; VS-Gruendung ist ein formaler Task.
|
||||||
|
* Fail loud bei unbekanntem CEO oder Spool-Fehler.
|
||||||
|
*/
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const body = (await request.json()) as { topic?: string; ziel?: string }
|
||||||
|
const topic = String(body.topic || "").trim()
|
||||||
|
const ziel = String(body.ziel || "").trim()
|
||||||
|
if (!topic || topic.length > 200) {
|
||||||
|
return NextResponse.json({ error: "topic Pflicht (max 200 Zeichen)" }, { status: 400 })
|
||||||
|
}
|
||||||
|
const res = await mcpCallTool(FLEET_BOARD_MCP_URL, "submit_owner_task", {
|
||||||
|
to: "ceo",
|
||||||
|
type: "build",
|
||||||
|
priority: "P2",
|
||||||
|
topic,
|
||||||
|
body: ziel || topic,
|
||||||
|
requires_ack: true,
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
return NextResponse.json({ error: `submit_owner_task: ${res.error}` }, { status: 500 })
|
||||||
|
}
|
||||||
|
return NextResponse.json(res.data, { headers: { "Cache-Control": "no-store" } })
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `OWNER_NEW_VS_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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" } }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import {
|
||||||
|
loadOrg,
|
||||||
|
loadSandboxFacts,
|
||||||
|
loadHeartbeatAges,
|
||||||
|
cached,
|
||||||
|
} from "@/app/lib/fleet/fleetSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/sandboxes — fleet-native Sandbox-View (Kernfeature-Ergänzung,
|
||||||
|
* Design §2 Datenquellen-Adapter). Zeigt die K8s-Realität der 9 Agenten-Sandboxes:
|
||||||
|
* Phase, Restarts, Age, Node, Requests, Image-Digest (kube-state-metrics via
|
||||||
|
* Prometheus) + Worker-/Heartbeat-Status aus Spool/Beacon.
|
||||||
|
* KEIN kubectl / KEINE Host-CLI im Tower (macOS-Design des Upstream ersetzt).
|
||||||
|
* Fail-loud: tote Quelle -> 500 mit Klartext, kein stilles Leeren (§5.5).
|
||||||
|
* Cache 2 s (View pollt 5 s -> max 1 Upstream-Call je Quelle je Zyklus).
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const data = await cached("fleet-sandboxes", 2000, async () => {
|
||||||
|
const [org, facts, hearts] = await Promise.all([
|
||||||
|
loadOrg(),
|
||||||
|
loadSandboxFacts(),
|
||||||
|
loadHeartbeatAges(),
|
||||||
|
])
|
||||||
|
const sandboxByAgent = new Map(facts.sandboxes.map((s) => [s.agent_id, s]))
|
||||||
|
const agents = org.members.map((m) => {
|
||||||
|
const sb = sandboxByAgent.get(m.agent_id)
|
||||||
|
const hbAge = hearts[m.agent_id]
|
||||||
|
return {
|
||||||
|
agent_id: m.agent_id,
|
||||||
|
role: m.role,
|
||||||
|
title: m.title ?? null,
|
||||||
|
exists: Boolean(sb),
|
||||||
|
phase: sb?.phase ?? null,
|
||||||
|
ready: sb?.ready ?? null,
|
||||||
|
restarts: sb?.restarts ?? null,
|
||||||
|
pod_age_s: sb?.pod_age_s ?? null,
|
||||||
|
node: sb?.node ?? null,
|
||||||
|
cpu_request_milli: sb?.cpu_request_milli ?? null,
|
||||||
|
mem_request_mb: sb?.mem_request_mb ?? null,
|
||||||
|
image_digest: sb?.image_digest ?? null,
|
||||||
|
heartbeat_age_s: typeof hbAge === "number" ? hbAge : null,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const healthy =
|
||||||
|
facts.sandboxes.length === org.members.length &&
|
||||||
|
facts.sandboxes.every((s) => s.phase === "Running" && s.ready)
|
||||||
|
return {
|
||||||
|
agents,
|
||||||
|
fleet_image_digest: facts.fleet_image_digest,
|
||||||
|
all_running: healthy,
|
||||||
|
generated_at: new Date().toISOString(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return NextResponse.json(data, { headers: { "Cache-Control": "no-store" } })
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `FLEET_SANDBOXES_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { getTaskDetail } from "@/app/lib/fleet/taskSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/task-detail?id=<task_id>[&kind=spool|dead-letter|alarm]
|
||||||
|
* Voller Task-Envelope fuer die Detailansicht (Karte tower-task-detail).
|
||||||
|
*
|
||||||
|
* Garantien aus der Change-Order: nie 5xx fuer unbekannte/leere ids (found:false),
|
||||||
|
* fehlende Felder als "-", Body unveraendert. Nur ein kaputter Lesepfad liefert
|
||||||
|
* degraded:true mit 200 — die Ansicht bleibt bedienbar.
|
||||||
|
*/
|
||||||
|
export async function GET(req: Request) {
|
||||||
|
const url = new URL(req.url)
|
||||||
|
const id = (url.searchParams.get("id") || "").trim()
|
||||||
|
const kind = (url.searchParams.get("kind") || "").trim()
|
||||||
|
try {
|
||||||
|
const data = getTaskDetail(id, kind)
|
||||||
|
return NextResponse.json(data, { headers: { "Cache-Control": "no-store" } })
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `FLEET_TASK_DETAIL_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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-<original>` 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<string, unknown>
|
||||||
|
const data = call.data
|
||||||
|
if (typeof data === "string") {
|
||||||
|
try {
|
||||||
|
payload = JSON.parse(data) as Record<string, unknown>
|
||||||
|
} catch {
|
||||||
|
payload = { result: "ERR_DISPATCH_FAILED", task_id: id, reason: data.slice(0, 300) }
|
||||||
|
}
|
||||||
|
} else if (data && typeof data === "object") {
|
||||||
|
payload = data as Record<string, unknown>
|
||||||
|
} 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" } }
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { loadTaskOverview } from "@/app/lib/fleet/taskSource"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fleet/tasks — Listen der Task-Detail-Ansicht (Karte tower-task-detail).
|
||||||
|
* Liefert Spool-Reifegrad (offene Envelopes), Dead-Letter (failed, 7 Tage) und
|
||||||
|
* Alarm-Feed (Stoerungsereignisse aus dem Journal) in einem Datensatz.
|
||||||
|
* Cache 10 s (Panel pollt 30 s).
|
||||||
|
*
|
||||||
|
* Abweichung zur Change-Order: Pfad /api/fleet/tasks statt /api/spool|/api/alarm-feed
|
||||||
|
* — konsistent mit den uebrigen Fleet-Routen (/api/fleet/overview, /sandboxes, ...).
|
||||||
|
* Degradierte Quelle -> 200 mit degraded:true (Panel zeigt Banner statt Crash).
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const data = loadTaskOverview()
|
||||||
|
return NextResponse.json(data, { headers: { "Cache-Control": "no-store" } })
|
||||||
|
} catch (err) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: `FLEET_TASKS_FAILED: ${err instanceof Error ? err.message : String(err)}` },
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ async function runOpenShell(args: string[], extraEnv: Record<string, string> = {
|
|||||||
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, args, {
|
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, args, {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
...extraEnv,
|
...extraEnv,
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
}),
|
}),
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
maxBuffer: 20 * 1024 * 1024,
|
maxBuffer: 20 * 1024 * 1024,
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
import { NextResponse } from "next/server"
|
import { NextResponse } from "next/server"
|
||||||
import { execFile } from "node:child_process"
|
import { restartSandboxGatewayWithNemoClaw } from "@/app/lib/nemoclawCli"
|
||||||
import { promisify } from "node:util"
|
|
||||||
import { OPENSHELL_BIN, hostCommandEnv } from "@/app/lib/hostCommands"
|
|
||||||
import { recoverSandboxWithNemoClaw } from "@/app/lib/nemoclawCli"
|
|
||||||
import { inspectSandbox, resolveSandboxRef } from "@/app/lib/openshellHost"
|
import { inspectSandbox, resolveSandboxRef } from "@/app/lib/openshellHost"
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
|
||||||
const SANDBOX_DASHBOARD_REMOTE_PORT = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_REMOTE_PORT || "18789", 10)
|
|
||||||
|
|
||||||
function sleep(ms: number) {
|
function sleep(ms: number) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||||
}
|
}
|
||||||
@@ -18,20 +12,6 @@ function validateSandboxName(value: string) {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runOpenShell(args: string[], timeout = 30000) {
|
|
||||||
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, args, {
|
|
||||||
env: hostCommandEnv({
|
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
|
||||||
}),
|
|
||||||
timeout,
|
|
||||||
maxBuffer: 4 * 1024 * 1024,
|
|
||||||
})
|
|
||||||
return { stdout: String(stdout).trim(), stderr: String(stderr).trim() }
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runSandboxShell(sandboxName: string, script: string, timeout = 30000) {
|
|
||||||
return runOpenShell(["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], timeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function waitForSandboxReady(sandboxName: string, timeoutMs: number, intervalMs: number) {
|
async function waitForSandboxReady(sandboxName: string, timeoutMs: number, intervalMs: number) {
|
||||||
const startedAt = Date.now()
|
const startedAt = Date.now()
|
||||||
@@ -55,29 +35,6 @@ async function waitForSandboxReady(sandboxName: string, timeoutMs: number, inter
|
|||||||
return { ready: false, attempts, elapsedMs: Date.now() - startedAt, lastError }
|
return { ready: false, attempts, elapsedMs: Date.now() - startedAt, lastError }
|
||||||
}
|
}
|
||||||
|
|
||||||
function restartOpenClawGatewayScript() {
|
|
||||||
return [
|
|
||||||
`port=${SANDBOX_DASHBOARD_REMOTE_PORT}`,
|
|
||||||
"for p in /proc/[0-9]*; do",
|
|
||||||
" cmd=$(tr '\\0' ' ' < \"$p/cmdline\" 2>/dev/null || true)",
|
|
||||||
" case \"$cmd\" in",
|
|
||||||
" *'openclaw gateway run'*) kill \"${p##*/}\" 2>/dev/null || true ;;",
|
|
||||||
" esac",
|
|
||||||
"done",
|
|
||||||
"sleep 1",
|
|
||||||
"if command -v openclaw >/dev/null 2>&1; then openclaw_bin=$(command -v openclaw);",
|
|
||||||
"elif [ -x /usr/local/bin/openclaw ]; then openclaw_bin=/usr/local/bin/openclaw;",
|
|
||||||
"else echo 'openclaw command not found in sandbox' >&2; exit 127; fi",
|
|
||||||
"nohup \"$openclaw_bin\" gateway run --allow-unconfigured --bind loopback --port \"$port\" >/tmp/gateway.log 2>&1 &",
|
|
||||||
"for i in 1 2 3 4 5 6 7 8 9 10; do",
|
|
||||||
" curl -fsS --max-time 2 \"http://127.0.0.1:$port/\" >/dev/null 2>&1 && exit 0",
|
|
||||||
" sleep 1",
|
|
||||||
"done",
|
|
||||||
"echo 'OpenClaw gateway did not answer after restart. Last log lines:' >&2",
|
|
||||||
"tail -40 /tmp/gateway.log >&2 2>/dev/null || true",
|
|
||||||
"exit 1",
|
|
||||||
].join("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
_request: Request,
|
_request: Request,
|
||||||
@@ -101,37 +58,34 @@ export async function POST(
|
|||||||
}, { status: 409 })
|
}, { status: 409 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const nemoclawRecover = await recoverSandboxWithNemoClaw(sandboxName)
|
const nemoclawRestart = await restartSandboxGatewayWithNemoClaw(sandboxName)
|
||||||
if (nemoclawRecover.attempted && nemoclawRecover.ok) {
|
if (nemoclawRestart.attempted && nemoclawRestart.ok) {
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
ok: true,
|
ok: true,
|
||||||
restarted: true,
|
restarted: true,
|
||||||
restartMode: "nemoclaw-recover",
|
restartMode: "nemoclaw-native-gateway",
|
||||||
sandboxId: resolved.id,
|
sandboxId: resolved.id,
|
||||||
sandboxName,
|
sandboxName,
|
||||||
readiness,
|
readiness,
|
||||||
nemoclawRecover,
|
nemoclawRestart,
|
||||||
elapsedMs: Date.now() - startedAt,
|
elapsedMs: Date.now() - startedAt,
|
||||||
note: "NemoClaw recover completed. The sandbox runtime and dashboard forward were checked without deleting the sandbox.",
|
note: "NemoClaw asked the sandbox's native agent to restart its gateway, then verified gateway health and host forwards.",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const runtime = await runSandboxShell(sandboxName, restartOpenClawGatewayScript(), 45000)
|
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
ok: true,
|
ok: false,
|
||||||
restarted: true,
|
restarted: false,
|
||||||
restartMode: "openclaw-runtime",
|
restartMode: "nemoclaw-native-gateway",
|
||||||
sandboxId: resolved.id,
|
sandboxId: resolved.id,
|
||||||
sandboxName,
|
sandboxName,
|
||||||
readiness,
|
readiness,
|
||||||
nemoclawRecover,
|
nemoclawRestart,
|
||||||
runtime,
|
|
||||||
elapsedMs: Date.now() - startedAt,
|
elapsedMs: Date.now() - startedAt,
|
||||||
note: nemoclawRecover.attempted
|
note: nemoclawRestart.attempted
|
||||||
? "NemoClaw recover did not complete, so the dashboard fell back to restarting the in-sandbox OpenClaw runtime. The sandbox pod was not deleted."
|
? "NemoClaw could not complete the native gateway restart. The controller did not bypass the agent-owned lifecycle boundary."
|
||||||
: "OpenClaw runtime restarted inside the sandbox. The sandbox pod was not deleted.",
|
: "The installed NemoClaw CLI does not support the native gateway restart command. Upgrade NemoClaw before retrying.",
|
||||||
})
|
}, { status: nemoclawRestart.attempted ? 502 : 409 })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : "Failed to restart sandbox runtime"
|
const message = error instanceof Error ? error.message : "Failed to restart sandbox runtime"
|
||||||
return NextResponse.json({ ok: false, restarted: false, error: message }, { status: /required|invalid/.test(message) ? 400 : 500 })
|
return NextResponse.json({ ok: false, restarted: false, error: message }, { status: /required|invalid/.test(message) ? 400 : 500 })
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { NextResponse } from "next/server"
|
import { NextResponse } from "next/server"
|
||||||
import { execFile, spawn } from "node:child_process"
|
import { execFile, spawn } from "node:child_process"
|
||||||
import { existsSync, readFileSync } from "node:fs"
|
import { existsSync } from "node:fs"
|
||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import { promisify } from "node:util"
|
import { promisify } from "node:util"
|
||||||
import { inspectSandbox, resolveSandboxRef } from "@/app/lib/openshellHost"
|
import { inspectSandbox, resolveSandboxRef } from "@/app/lib/openshellHost"
|
||||||
import { recordActivity } from "@/app/lib/activityLog"
|
import { recordActivity } from "@/app/lib/activityLog"
|
||||||
import { repairOpenClawExecApprovalsFile } from "@/app/lib/sandboxPrivilegedFiles"
|
import {
|
||||||
|
findNemoClawRegistryEntry,
|
||||||
|
listNemoClawRegistryCandidates,
|
||||||
|
} from "@/app/lib/nemoclawRegistry.mjs"
|
||||||
import {
|
import {
|
||||||
commandExists,
|
commandExists,
|
||||||
HOST_PATH,
|
HOST_PATH,
|
||||||
@@ -20,13 +23,13 @@ import {
|
|||||||
} from "@/app/lib/hostCommands"
|
} from "@/app/lib/hostCommands"
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
const execFileAsync = promisify(execFile)
|
||||||
const NEMOCLAW_REGISTRY_FILE = path.join(process.env.HOME || "/tmp", ".nemoclaw", "sandboxes.json")
|
const NEMOCLAW_STATE_ROOT = path.join(process.env.HOME || "/tmp", ".nemoclaw")
|
||||||
|
|
||||||
function validateSandboxName(name: string) {
|
function validateSandboxName(name: string) {
|
||||||
if (!name || typeof name !== "string") throw new Error("sandbox name is required")
|
if (!name || typeof name !== "string") throw new Error("sandbox name is required")
|
||||||
if (name.length > 63) throw new Error("sandbox name too long (max 63 chars)")
|
if (name.length > 19) throw new Error("sandbox name too long (max 19 chars)")
|
||||||
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(name)) {
|
if (!/^(?!.*--)[a-z]([a-z0-9-]*[a-z0-9])?$/.test(name)) {
|
||||||
throw new Error("sandbox name must be lowercase alphanumeric with optional internal hyphens")
|
throw new Error("sandbox name must start with a lowercase letter and contain only lowercase letters, numbers, and single internal hyphens")
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
@@ -84,10 +87,6 @@ type CreateInferenceSettings = {
|
|||||||
envSummary: string[]
|
envSummary: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
type NemoClawRegistryData = {
|
|
||||||
sandboxes?: Record<string, { name?: string; createdAt?: string; imageTag?: string }>
|
|
||||||
defaultSandbox?: string | null
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCreateGpuMode(body: any): CreateGpuMode {
|
function parseCreateGpuMode(body: any): CreateGpuMode {
|
||||||
const raw = typeof body?.gpuMode === "string"
|
const raw = typeof body?.gpuMode === "string"
|
||||||
@@ -270,21 +269,11 @@ function parseOpenShellSandboxNames(output: string) {
|
|||||||
.filter((entry): entry is string => Boolean(entry))
|
.filter((entry): entry is string => Boolean(entry))
|
||||||
}
|
}
|
||||||
|
|
||||||
function readNemoClawRegistry(): NemoClawRegistryData {
|
|
||||||
try {
|
|
||||||
return existsSync(NEMOCLAW_REGISTRY_FILE)
|
|
||||||
? JSON.parse(readFileSync(NEMOCLAW_REGISTRY_FILE, "utf8"))
|
|
||||||
: {}
|
|
||||||
} catch {
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listOpenShellSandboxNames() {
|
async function listOpenShellSandboxNames() {
|
||||||
try {
|
try {
|
||||||
const { stdout } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "list"], {
|
const { stdout } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "list"], {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
}),
|
}),
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
maxBuffer: 1024 * 1024,
|
maxBuffer: 1024 * 1024,
|
||||||
@@ -299,7 +288,7 @@ async function resolveSourcePodImageFromRef(sourceSandboxRef: string) {
|
|||||||
const requested = sourceSandboxRef.trim()
|
const requested = sourceSandboxRef.trim()
|
||||||
const source = await resolveSandboxRef(requested)
|
const source = await resolveSandboxRef(requested)
|
||||||
const sourceName = validateSandboxName(source.name)
|
const sourceName = validateSandboxName(source.name)
|
||||||
const registryEntry = readNemoClawRegistry().sandboxes?.[sourceName]
|
const registryEntry = findNemoClawRegistryEntry(sourceName)?.entry
|
||||||
const sourceImage = registryEntry?.imageTag?.trim() || null
|
const sourceImage = registryEntry?.imageTag?.trim() || null
|
||||||
|
|
||||||
if (!sourceImage) {
|
if (!sourceImage) {
|
||||||
@@ -319,15 +308,10 @@ async function resolveSourcePodImage(sourceSandboxRef: string | null | undefined
|
|||||||
return await resolveSourcePodImageFromRef(sourceSandboxRef)
|
return await resolveSourcePodImageFromRef(sourceSandboxRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
const registry = readNemoClawRegistry()
|
const registeredNames = listNemoClawRegistryCandidates()
|
||||||
const registeredEntries = Object.entries(registry.sandboxes ?? {})
|
|
||||||
const newestRegisteredNames = registeredEntries
|
|
||||||
.sort(([, a], [, b]) => String(b?.createdAt ?? "").localeCompare(String(a?.createdAt ?? "")))
|
|
||||||
.map(([key, value]) => value?.name || key)
|
|
||||||
const liveNames = await listOpenShellSandboxNames()
|
const liveNames = await listOpenShellSandboxNames()
|
||||||
const candidates = Array.from(new Set([
|
const candidates = Array.from(new Set([
|
||||||
registry.defaultSandbox || undefined,
|
...registeredNames,
|
||||||
...newestRegisteredNames,
|
|
||||||
...liveNames,
|
...liveNames,
|
||||||
].filter((candidate): candidate is string => Boolean(candidate && candidate !== targetSandboxName))))
|
].filter((candidate): candidate is string => Boolean(candidate && candidate !== targetSandboxName))))
|
||||||
|
|
||||||
@@ -346,8 +330,8 @@ function skippedNemoClawImageRedeployRegistration() {
|
|||||||
return {
|
return {
|
||||||
registered: false as const,
|
registered: false as const,
|
||||||
skipped: true as const,
|
skipped: true as const,
|
||||||
registryFile: NEMOCLAW_REGISTRY_FILE,
|
registryFile: NEMOCLAW_STATE_ROOT,
|
||||||
note: "The quick-deployed sandbox remains an OpenShell-managed clone and was not written into NemoClaw's private registry. Current NemoClaw registry entries carry lifecycle, policy-authority, and workload receipts that only NemoClaw can issue safely.",
|
note: "The quick-deployed sandbox remains an OpenShell-managed clone and was not written into NemoClaw's private registry. Current NemoClaw registry entries carry lifecycle identity, workload provenance, and agent-specific state that only NemoClaw can issue safely.",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,7 +632,7 @@ async function approveOpenClawDeviceRequests(sandboxName: string) {
|
|||||||
"-lc",
|
"-lc",
|
||||||
"openclaw devices approve --latest --json --timeout 10000",
|
"openclaw devices approve --latest --json --timeout 10000",
|
||||||
], hostCommandEnv({
|
], hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
}), 15000)
|
}), 15000)
|
||||||
|
|
||||||
const combinedOutput = `${result.stdout}\n${result.stderr}`.trim()
|
const combinedOutput = `${result.stdout}\n${result.stderr}`.trim()
|
||||||
@@ -783,7 +767,7 @@ export async function POST(request: Request) {
|
|||||||
NEMOCLAW_NON_INTERACTIVE: "1",
|
NEMOCLAW_NON_INTERACTIVE: "1",
|
||||||
NEMOCLAW_RECREATE_SANDBOX: "1",
|
NEMOCLAW_RECREATE_SANDBOX: "1",
|
||||||
NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1",
|
NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1",
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!enableTailscale) {
|
if (!enableTailscale) {
|
||||||
@@ -829,11 +813,6 @@ export async function POST(request: Request) {
|
|||||||
error: "Sandbox readiness polling produced no verification result.",
|
error: "Sandbox readiness polling produced no verification result.",
|
||||||
}
|
}
|
||||||
const created = readiness.verified
|
const created = readiness.verified
|
||||||
const execApprovalsRepair = created && isOpenClawAgent ? await repairOpenClawExecApprovalsFile(sandboxName).catch((error) => ({
|
|
||||||
sandboxName,
|
|
||||||
path: "/sandbox/.openclaw/exec-approvals.json",
|
|
||||||
error: error instanceof Error ? error.message : "Failed to repair OpenClaw exec approvals file",
|
|
||||||
})) : null
|
|
||||||
const deviceApproval = created && isOpenClawAgent ? await approveOpenClawDeviceRequests(sandboxName) : null
|
const deviceApproval = created && isOpenClawAgent ? await approveOpenClawDeviceRequests(sandboxName) : null
|
||||||
console.log(
|
console.log(
|
||||||
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} agent=${agent} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} agent=${agent} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
||||||
@@ -867,7 +846,6 @@ export async function POST(request: Request) {
|
|||||||
attempts: readiness.attempts,
|
attempts: readiness.attempts,
|
||||||
elapsedMs: readiness.elapsedMs,
|
elapsedMs: readiness.elapsedMs,
|
||||||
},
|
},
|
||||||
execApprovalsRepair,
|
|
||||||
deviceApproval,
|
deviceApproval,
|
||||||
stdout: result.stdout,
|
stdout: result.stdout,
|
||||||
stderr: result.stderr,
|
stderr: result.stderr,
|
||||||
@@ -883,8 +861,6 @@ export async function POST(request: Request) {
|
|||||||
: gpuMode === "required"
|
: gpuMode === "required"
|
||||||
? "GPU passthrough was required for this create run."
|
? "GPU passthrough was required for this create run."
|
||||||
: "NemoClaw chose GPU passthrough automatically for this create run.",
|
: "NemoClaw chose GPU passthrough automatically for this create run.",
|
||||||
execApprovalsRepair && "note" in execApprovalsRepair ? execApprovalsRepair.note : false,
|
|
||||||
execApprovalsRepair && "error" in execApprovalsRepair ? `OpenClaw exec approvals repair failed: ${execApprovalsRepair.error}` : false,
|
|
||||||
deviceApproval?.note,
|
deviceApproval?.note,
|
||||||
)
|
)
|
||||||
: "Blueprint command reported success, but the sandbox never reached a ready verification state afterward.",
|
: "Blueprint command reported success, but the sandbox never reached a ready verification state afterward.",
|
||||||
@@ -893,7 +869,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
if (blueprint === "custom-sandbox") {
|
if (blueprint === "custom-sandbox") {
|
||||||
const env: NodeJS.ProcessEnv = hostCommandEnv({
|
const env: NodeJS.ProcessEnv = hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
NO_COLOR: "1",
|
NO_COLOR: "1",
|
||||||
CLICOLOR: "0",
|
CLICOLOR: "0",
|
||||||
CLICOLOR_FORCE: "0",
|
CLICOLOR_FORCE: "0",
|
||||||
@@ -926,11 +902,6 @@ export async function POST(request: Request) {
|
|||||||
error: "Sandbox readiness polling produced no verification result.",
|
error: "Sandbox readiness polling produced no verification result.",
|
||||||
}
|
}
|
||||||
const created = readiness.verified
|
const created = readiness.verified
|
||||||
const execApprovalsRepair = created ? await repairOpenClawExecApprovalsFile(sandboxName).catch((error) => ({
|
|
||||||
sandboxName,
|
|
||||||
path: "/sandbox/.openclaw/exec-approvals.json",
|
|
||||||
error: error instanceof Error ? error.message : "Failed to repair OpenClaw exec approvals file",
|
|
||||||
})) : null
|
|
||||||
const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null
|
const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null
|
||||||
const policyPrepared = Boolean(policy)
|
const policyPrepared = Boolean(policy)
|
||||||
console.log(
|
console.log(
|
||||||
@@ -968,7 +939,6 @@ export async function POST(request: Request) {
|
|||||||
attempts: readiness.attempts,
|
attempts: readiness.attempts,
|
||||||
elapsedMs: readiness.elapsedMs,
|
elapsedMs: readiness.elapsedMs,
|
||||||
},
|
},
|
||||||
execApprovalsRepair,
|
|
||||||
deviceApproval,
|
deviceApproval,
|
||||||
policyPrepared,
|
policyPrepared,
|
||||||
note: created
|
note: created
|
||||||
@@ -981,8 +951,6 @@ export async function POST(request: Request) {
|
|||||||
gpuMode === "required"
|
gpuMode === "required"
|
||||||
? "GPU passthrough was requested for this create run."
|
? "GPU passthrough was requested for this create run."
|
||||||
: false,
|
: false,
|
||||||
execApprovalsRepair && "note" in execApprovalsRepair ? execApprovalsRepair.note : false,
|
|
||||||
execApprovalsRepair && "error" in execApprovalsRepair ? `OpenClaw exec approvals repair failed: ${execApprovalsRepair.error}` : false,
|
|
||||||
deviceApproval?.note,
|
deviceApproval?.note,
|
||||||
)
|
)
|
||||||
: "Create command started, but the sandbox never reached a ready verification state afterward.",
|
: "Create command started, but the sandbox never reached a ready verification state afterward.",
|
||||||
@@ -995,7 +963,7 @@ export async function POST(request: Request) {
|
|||||||
const sourceImage = source.image
|
const sourceImage = source.image
|
||||||
const basePolicyPath = resolveNemoClawBasePolicyPath()
|
const basePolicyPath = resolveNemoClawBasePolicyPath()
|
||||||
const env: NodeJS.ProcessEnv = hostCommandEnv({
|
const env: NodeJS.ProcessEnv = hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
const createAttempt = await runCreateCommandUntilReady(OPENSHELL_BIN, [
|
const createAttempt = await runCreateCommandUntilReady(OPENSHELL_BIN, [
|
||||||
@@ -1028,11 +996,6 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
const created = readiness.verified
|
const created = readiness.verified
|
||||||
const registry = created ? skippedNemoClawImageRedeployRegistration() : null
|
const registry = created ? skippedNemoClawImageRedeployRegistration() : null
|
||||||
const execApprovalsRepair = created ? await repairOpenClawExecApprovalsFile(sandboxName).catch((error) => ({
|
|
||||||
sandboxName,
|
|
||||||
path: "/sandbox/.openclaw/exec-approvals.json",
|
|
||||||
error: error instanceof Error ? error.message : "Failed to repair OpenClaw exec approvals file",
|
|
||||||
})) : null
|
|
||||||
const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null
|
const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null
|
||||||
console.log(
|
console.log(
|
||||||
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} mode=redeploy-image createTimedOut=${createAttempt.timedOut} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} mode=redeploy-image createTimedOut=${createAttempt.timedOut} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
||||||
@@ -1079,7 +1042,6 @@ export async function POST(request: Request) {
|
|||||||
elapsedMs: readiness.elapsedMs,
|
elapsedMs: readiness.elapsedMs,
|
||||||
},
|
},
|
||||||
registry,
|
registry,
|
||||||
execApprovalsRepair,
|
|
||||||
deviceApproval,
|
deviceApproval,
|
||||||
note: created
|
note: created
|
||||||
? appendNote(
|
? appendNote(
|
||||||
@@ -1094,8 +1056,6 @@ export async function POST(request: Request) {
|
|||||||
? "The OpenShell create command stayed attached after the sandbox reached Ready, so the dashboard stopped waiting for the local command."
|
? "The OpenShell create command stayed attached after the sandbox reached Ready, so the dashboard stopped waiting for the local command."
|
||||||
: false,
|
: false,
|
||||||
registry?.note,
|
registry?.note,
|
||||||
execApprovalsRepair && "note" in execApprovalsRepair ? execApprovalsRepair.note : false,
|
|
||||||
execApprovalsRepair && "error" in execApprovalsRepair ? `OpenClaw exec approvals repair failed: ${execApprovalsRepair.error}` : false,
|
|
||||||
deviceApproval?.note,
|
deviceApproval?.note,
|
||||||
)
|
)
|
||||||
: createFailed
|
: createFailed
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ async function deleteSandbox(sandboxName: string) {
|
|||||||
try {
|
try {
|
||||||
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "delete", sandboxName], {
|
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "delete", sandboxName], {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
}),
|
}),
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
maxBuffer: 20 * 1024 * 1024,
|
maxBuffer: 20 * 1024 * 1024,
|
||||||
@@ -154,7 +154,7 @@ async function wipePersistentSandboxState(sandboxName: string, agent: string | n
|
|||||||
try {
|
try {
|
||||||
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
}),
|
}),
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
maxBuffer: 1024 * 1024,
|
maxBuffer: 1024 * 1024,
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { probe, uptimeSeconds, TOWER_VERSION } from "@/app/lib/fleet/health"
|
||||||
|
import {
|
||||||
|
FLEET_BEACON_URL,
|
||||||
|
FLEET_PROM_URL,
|
||||||
|
FLEET_SPOOL_DIR,
|
||||||
|
loadOrg,
|
||||||
|
} from "@/app/lib/fleet/fleetSource"
|
||||||
|
import { existsSync } from "node:fs"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/status — maschinenlesbarer Betriebszustand (Karte it1-tower-03).
|
||||||
|
* Version, Uptime, Datenquellen-Zustand mit Latenz + Klartext-Fehler.
|
||||||
|
* Immer 200 (Monitoring braucht eine Antwort); Degradation steht im Body.
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
const t0 = Date.now()
|
||||||
|
|
||||||
|
let orgOk = false
|
||||||
|
let orgError = ""
|
||||||
|
try {
|
||||||
|
const org = loadOrg()
|
||||||
|
orgOk = org.members.length > 0
|
||||||
|
} catch (e) {
|
||||||
|
orgError = e instanceof Error ? e.message : String(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
const [prom, beacon] = await Promise.all([
|
||||||
|
probe(`${FLEET_PROM_URL}/-/healthy`),
|
||||||
|
probe(`${FLEET_BEACON_URL}/metrics`),
|
||||||
|
])
|
||||||
|
|
||||||
|
const sources = {
|
||||||
|
spool: {
|
||||||
|
ok: existsSync(FLEET_SPOOL_DIR),
|
||||||
|
latency_ms: 0,
|
||||||
|
error: existsSync(FLEET_SPOOL_DIR) ? "" : `fehlt: ${FLEET_SPOOL_DIR}`,
|
||||||
|
},
|
||||||
|
org_yaml: { ok: orgOk, latency_ms: 0, error: orgError },
|
||||||
|
prometheus: prom,
|
||||||
|
beacon: beacon,
|
||||||
|
}
|
||||||
|
|
||||||
|
const coreOk = sources.spool.ok && sources.org_yaml.ok
|
||||||
|
const allOk = coreOk && prom.ok && beacon.ok
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
status: allOk ? "ok" : coreOk ? "degraded" : "down",
|
||||||
|
version: TOWER_VERSION,
|
||||||
|
uptime_seconds: uptimeSeconds(),
|
||||||
|
generated_at: new Date().toISOString(),
|
||||||
|
response_ms: Date.now() - t0,
|
||||||
|
sources,
|
||||||
|
},
|
||||||
|
{ headers: { "Cache-Control": "no-store" } }
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ export const dynamic = "force-dynamic"
|
|||||||
async function run(command: string, args: string[]) {
|
async function run(command: string, args: string[]) {
|
||||||
try {
|
try {
|
||||||
const env = command === OPENSHELL_BIN
|
const env = command === OPENSHELL_BIN
|
||||||
? hostCommandEnv({ OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw" })
|
? hostCommandEnv({ OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined })
|
||||||
: { ...process.env, PATH: HOST_PATH, NO_COLOR: "1", CLICOLOR: "0", CLICOLOR_FORCE: "0" }
|
: { ...process.env, PATH: HOST_PATH, NO_COLOR: "1", CLICOLOR: "0", CLICOLOR_FORCE: "0" }
|
||||||
const { stdout, stderr } = await execFileAsync(command, args, {
|
const { stdout, stderr } = await execFileAsync(command, args, {
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ import { hostname, networkInterfaces } from "node:os"
|
|||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import { promisify } from "node:util"
|
import { promisify } from "node:util"
|
||||||
import { NEMOCLAW_BIN, NODE_BIN, OPENSHELL_BIN, hostCommandEnv } from "@/app/lib/hostCommands"
|
import { NEMOCLAW_BIN, NODE_BIN, OPENSHELL_BIN, hostCommandEnv } from "@/app/lib/hostCommands"
|
||||||
|
import {
|
||||||
|
parseDefaultSandboxNames,
|
||||||
|
parseNemoclawListJson,
|
||||||
|
resolveSandboxAgent,
|
||||||
|
type NemoClawListJsonIdentity,
|
||||||
|
type NemoClawRegistryData,
|
||||||
|
} from "@/app/lib/nemoclawIdentity.mjs"
|
||||||
import { resolveRuntimeAuthority } from "@/app/lib/runtimeAuthority"
|
import { resolveRuntimeAuthority } from "@/app/lib/runtimeAuthority"
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
const execFileAsync = promisify(execFile)
|
||||||
@@ -30,10 +37,6 @@ type NemoClawSummary = {
|
|||||||
source: "nemoclaw-cli" | "none"
|
source: "nemoclaw-cli" | "none"
|
||||||
}
|
}
|
||||||
|
|
||||||
type NemoClawRegistryData = {
|
|
||||||
sandboxes?: Record<string, { name?: string; agent?: string | null }>
|
|
||||||
}
|
|
||||||
|
|
||||||
type SandboxItem = {
|
type SandboxItem = {
|
||||||
metadata: {
|
metadata: {
|
||||||
name: string
|
name: string
|
||||||
@@ -115,17 +118,6 @@ function parseOpenShellSandboxNames(output: string) {
|
|||||||
.filter((entry): entry is string => Boolean(entry))
|
.filter((entry): entry is string => Boolean(entry))
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDefaultSandboxNames(output: string) {
|
|
||||||
return new Set(
|
|
||||||
output
|
|
||||||
.split(/\r?\n/)
|
|
||||||
.map((entry) => stripAnsi(entry))
|
|
||||||
.filter((entry) => /^\s{2,}[\w.-]+(?:\s+\*)?\s*$/.test(entry) && entry.includes("*"))
|
|
||||||
.map((entry) => entry.replace("*", "").trim())
|
|
||||||
.filter(Boolean)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildNemoClawSummary(output: string | null, defaultSandboxNames: Set<string>): NemoClawSummary {
|
function buildNemoClawSummary(output: string | null, defaultSandboxNames: Set<string>): NemoClawSummary {
|
||||||
if (!output) {
|
if (!output) {
|
||||||
return {
|
return {
|
||||||
@@ -163,17 +155,9 @@ function readNemoClawRegistry(): NemoClawRegistryData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveSandboxAgent(name: string, id: string | null, registry: NemoClawRegistryData) {
|
|
||||||
const entries = registry.sandboxes ?? {}
|
|
||||||
const directEntry = entries[name] || (id ? entries[id] : undefined)
|
|
||||||
const namedEntry = Object.values(entries).find((entry) => entry?.name === name || Boolean(id && entry?.name === id))
|
|
||||||
const agent = directEntry?.agent || namedEntry?.agent
|
|
||||||
return typeof agent === "string" && agent.trim() ? agent.trim() : "openclaw"
|
|
||||||
}
|
|
||||||
|
|
||||||
async function execNemoclaw(args: string[]) {
|
async function execNemoclaw(args: string[]) {
|
||||||
const env = hostCommandEnv({
|
const env = hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
const command = /\.(?:c?m?js|ts)$/i.test(NEMOCLAW_BIN)
|
const command = /\.(?:c?m?js|ts)$/i.test(NEMOCLAW_BIN)
|
||||||
@@ -215,7 +199,12 @@ function readHostIdentity() {
|
|||||||
return { hostname: hostname(), address: "127.0.0.1", interface: "lo0" }
|
return { hostname: hostname(), address: "127.0.0.1", interface: "lo0" }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readSandbox(name: string, defaultSandboxNames: Set<string>, registry: NemoClawRegistryData): Promise<{ summary: SandboxSummary; pod: SandboxItem }> {
|
async function readSandbox(
|
||||||
|
name: string,
|
||||||
|
defaultSandboxNames: Set<string>,
|
||||||
|
listJsonIdentity: NemoClawListJsonIdentity | null,
|
||||||
|
registry: NemoClawRegistryData | null
|
||||||
|
): Promise<{ summary: SandboxSummary; pod: SandboxItem }> {
|
||||||
try {
|
try {
|
||||||
const [{ stdout: detailsStdout }, { stdout: sshStdout }] = await Promise.all([
|
const [{ stdout: detailsStdout }, { stdout: sshStdout }] = await Promise.all([
|
||||||
execOpenShell(["sandbox", "get", name]),
|
execOpenShell(["sandbox", "get", name]),
|
||||||
@@ -229,7 +218,7 @@ async function readSandbox(name: string, defaultSandboxNames: Set<string>, regis
|
|||||||
const sshConfig = sshStdout.trim()
|
const sshConfig = sshStdout.trim()
|
||||||
const sshHostAlias = parseSshHostAlias(sshConfig, sandboxName)
|
const sshHostAlias = parseSshHostAlias(sshConfig, sandboxName)
|
||||||
const isDefault = defaultSandboxNames.has(sandboxName)
|
const isDefault = defaultSandboxNames.has(sandboxName)
|
||||||
const agent = resolveSandboxAgent(sandboxName, sandboxId, registry)
|
const agent = resolveSandboxAgent(sandboxName, sandboxId, listJsonIdentity, registry)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
summary: {
|
summary: {
|
||||||
@@ -274,7 +263,7 @@ async function readSandbox(name: string, defaultSandboxNames: Set<string>, regis
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
const sandboxName = name
|
const sandboxName = name
|
||||||
const isDefault = defaultSandboxNames.has(sandboxName)
|
const isDefault = defaultSandboxNames.has(sandboxName)
|
||||||
const agent = resolveSandboxAgent(sandboxName, sandboxName, registry)
|
const agent = resolveSandboxAgent(sandboxName, sandboxName, listJsonIdentity, registry)
|
||||||
return {
|
return {
|
||||||
summary: {
|
summary: {
|
||||||
id: sandboxName,
|
id: sandboxName,
|
||||||
@@ -322,15 +311,28 @@ export async function GET() {
|
|||||||
try {
|
try {
|
||||||
const { stdout: sandboxListStdout } = await execOpenShell(["sandbox", "list"])
|
const { stdout: sandboxListStdout } = await execOpenShell(["sandbox", "list"])
|
||||||
const names = parseOpenShellSandboxNames(sandboxListStdout)
|
const names = parseOpenShellSandboxNames(sandboxListStdout)
|
||||||
const [nemoclawListResult, nemoclawStatusResult] = names.length > 0
|
let listJsonIdentity: NemoClawListJsonIdentity | null = null
|
||||||
? await Promise.all([
|
let legacyListResult: { stdout: string; stderr: string } | null = null
|
||||||
execNemoclaw(["list"]).catch(() => null),
|
const nemoclawStatusPromise = names.length > 0
|
||||||
execNemoclaw(["status"]).catch(() => null),
|
? execNemoclaw(["status"]).catch(() => null)
|
||||||
])
|
: Promise.resolve(null)
|
||||||
: [null, null]
|
|
||||||
const defaultSandboxNames = parseDefaultSandboxNames(nemoclawListResult?.stdout ?? "")
|
if (names.length > 0) {
|
||||||
const registry = readNemoClawRegistry()
|
const nemoclawListJsonResult = await execNemoclaw(["list", "--json"]).catch(() => null)
|
||||||
const results = await Promise.all(names.map((name) => readSandbox(name, defaultSandboxNames, registry)))
|
listJsonIdentity = parseNemoclawListJson(nemoclawListJsonResult?.stdout ?? "")
|
||||||
|
if (!listJsonIdentity) {
|
||||||
|
legacyListResult = await execNemoclaw(["list"]).catch(() => null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const nemoclawStatusResult = await nemoclawStatusPromise
|
||||||
|
const defaultSandboxNames = listJsonIdentity
|
||||||
|
? new Set(listJsonIdentity.defaultSandboxNames)
|
||||||
|
: parseDefaultSandboxNames(legacyListResult?.stdout ?? "")
|
||||||
|
const registry = listJsonIdentity ? null : readNemoClawRegistry()
|
||||||
|
const results = await Promise.all(
|
||||||
|
names.map((name) => readSandbox(name, defaultSandboxNames, listJsonIdentity, registry))
|
||||||
|
)
|
||||||
const sandboxes = results.map((result) => result.summary)
|
const sandboxes = results.map((result) => result.summary)
|
||||||
const items = results.map((result) => result.pod)
|
const items = results.map((result) => result.pod)
|
||||||
const nemoclaw = buildNemoClawSummary(nemoclawStatusResult?.stdout ?? null, defaultSandboxNames)
|
const nemoclaw = buildNemoClawSummary(nemoclawStatusResult?.stdout ?? null, defaultSandboxNames)
|
||||||
@@ -363,7 +365,11 @@ export async function GET() {
|
|||||||
explicitInstanceOverride: authority.explicitInstanceOverride,
|
explicitInstanceOverride: authority.explicitInstanceOverride,
|
||||||
usedMappedSandboxInstance: authority.usedMappedSandboxInstance,
|
usedMappedSandboxInstance: authority.usedMappedSandboxInstance,
|
||||||
})),
|
})),
|
||||||
defaultSource: defaultSandboxNames.size > 0 ? "nemoclaw-cli" : "none",
|
defaultSource: listJsonIdentity
|
||||||
|
? "nemoclaw-list-json"
|
||||||
|
: defaultSandboxNames.size > 0
|
||||||
|
? "nemoclaw-cli"
|
||||||
|
: "none",
|
||||||
count: inventoryCount,
|
count: inventoryCount,
|
||||||
message: hasMappedFallbackWithoutInventory
|
message: hasMappedFallbackWithoutInventory
|
||||||
? "Fetched live OpenShell inventory: zero sandboxes reported, so any mapped NemoClaw dashboard should be treated as fallback-only."
|
? "Fetched live OpenShell inventory: zero sandboxes reported, so any mapped NemoClaw dashboard should be treated as fallback-only."
|
||||||
|
|||||||
@@ -220,8 +220,8 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label className="text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Sandbox Name<FieldHelp text="Lowercase letters, numbers, and hyphens only." /></label>
|
<label className="text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Sandbox Name<FieldHelp text="1-19 characters; start with a lowercase letter; use lowercase letters, numbers, and single internal hyphens only." /></label>
|
||||||
<input value={sandboxName} onChange={(e) => setSandboxName(e.target.value)} placeholder={selectedBlueprint === 'nemoclaw-hermes' ? 'my-hermes' : selectedBlueprint === 'nemoclaw-deepagents-code' ? 'my-deepagents-code' : selectedBlueprint === 'nemoclaw-blueprint' ? 'my-assistant' : selectedBlueprint === 'redeploy-image' ? 'my-assistant-copy' : 'custom-sandbox'} className="mt-2 w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" />
|
<input value={sandboxName} onChange={(e) => setSandboxName(e.target.value)} maxLength={19} pattern="(?!.*--)[a-z](?:[a-z0-9-]*[a-z0-9])?" placeholder={selectedBlueprint === 'nemoclaw-hermes' ? 'my-hermes' : selectedBlueprint === 'nemoclaw-deepagents-code' ? 'my-deepagents-code' : selectedBlueprint === 'nemoclaw-blueprint' ? 'my-assistant' : selectedBlueprint === 'redeploy-image' ? 'my-assistant-copy' : 'custom-sandbox'} className="mt-2 w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]" />
|
||||||
</div>
|
</div>
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4 space-y-4">
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4 space-y-4">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -78,14 +78,19 @@ function openDashboardUrl(url: string, openInNewTab: boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function displaySandboxAgent(agent?: string) {
|
function displaySandboxAgent(agent?: string) {
|
||||||
if (agent === 'hermes') return 'Hermes'
|
const normalized = typeof agent === 'string' ? agent.trim().toLowerCase() : ''
|
||||||
return 'OpenClaw'
|
if (normalized === 'hermes') return 'Hermes'
|
||||||
|
if (!normalized || normalized === 'openclaw') return 'OpenClaw'
|
||||||
|
if (normalized === 'unknown') return 'Unknown'
|
||||||
|
return agent || 'Unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
function SandboxTypeLogo({ agent }: { agent?: string }) {
|
function SandboxTypeLogo({ agent }: { agent?: string }) {
|
||||||
const isHermes = agent === 'hermes'
|
const normalized = typeof agent === 'string' ? agent.trim().toLowerCase() : ''
|
||||||
const label = isHermes ? 'Hermes sandbox' : 'OpenClaw sandbox'
|
const isHermes = normalized === 'hermes'
|
||||||
const logoSrc = isHermes ? HERMES_SANDBOX_LOGO : OPENCLAW_SANDBOX_LOGO
|
const isOpenClaw = !normalized || normalized === 'openclaw'
|
||||||
|
const label = isHermes ? 'Hermes sandbox' : isOpenClaw ? 'OpenClaw sandbox' : 'Non-OpenClaw sandbox'
|
||||||
|
const logoSrc = isHermes ? HERMES_SANDBOX_LOGO : isOpenClaw ? OPENCLAW_SANDBOX_LOGO : null
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
@@ -93,10 +98,16 @@ function SandboxTypeLogo({ agent }: { agent?: string }) {
|
|||||||
className={`flex h-8 w-8 shrink-0 items-center justify-center rounded-md border shadow-inner ${
|
className={`flex h-8 w-8 shrink-0 items-center justify-center rounded-md border shadow-inner ${
|
||||||
isHermes
|
isHermes
|
||||||
? 'border-sky-300/60 bg-sky-500/15'
|
? 'border-sky-300/60 bg-sky-500/15'
|
||||||
: 'border-rose-300/60 bg-rose-500/15'
|
: isOpenClaw
|
||||||
|
? 'border-rose-300/60 bg-rose-500/15'
|
||||||
|
: 'border-slate-300/60 bg-slate-500/15 text-[10px] font-semibold uppercase tracking-wide text-[var(--foreground-dim)]'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<span aria-hidden="true" className="h-6 w-6 bg-contain bg-center bg-no-repeat" style={{ backgroundImage: `url(${logoSrc})` }} />
|
{logoSrc ? (
|
||||||
|
<span aria-hidden="true" className="h-6 w-6 bg-contain bg-center bg-no-repeat" style={{ backgroundImage: `url(${logoSrc})` }} />
|
||||||
|
) : (
|
||||||
|
<span aria-hidden="true">?</span>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+142
-1
@@ -14,7 +14,7 @@ type ControllerNodeRecord = {
|
|||||||
interface SidebarProps {
|
interface SidebarProps {
|
||||||
sandboxesRunning: number
|
sandboxesRunning: number
|
||||||
sandboxesTotal: number
|
sandboxesTotal: number
|
||||||
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp'
|
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp' | 'org' | 'messages' | 'board' | 'owner' | 'escalations' | 'approvals' | 'attention' | 'fleet-sandboxes' | 'tasks' | 'ops'
|
||||||
isCreateMode: boolean
|
isCreateMode: boolean
|
||||||
isDestroyMode: boolean
|
isDestroyMode: boolean
|
||||||
onSandboxesClick: () => void
|
onSandboxesClick: () => void
|
||||||
@@ -25,6 +25,17 @@ interface SidebarProps {
|
|||||||
onMcpClick: () => void
|
onMcpClick: () => void
|
||||||
onWizardsClick: () => void
|
onWizardsClick: () => void
|
||||||
onHelpClick: () => void
|
onHelpClick: () => void
|
||||||
|
onFleetOrgClick: () => void
|
||||||
|
onFleetMessagesClick: () => void
|
||||||
|
onFleetBoardClick: () => void
|
||||||
|
onFleetOwnerClick: () => void
|
||||||
|
onFleetApprovalsClick: () => void
|
||||||
|
onFleetAttentionClick: () => void
|
||||||
|
|
||||||
|
onFleetEscalationsClick: () => void
|
||||||
|
onFleetSandboxesClick: () => void
|
||||||
|
onFleetTasksClick: () => void
|
||||||
|
onFleetOpsClick: () => void
|
||||||
onExitMode: () => void
|
onExitMode: () => void
|
||||||
onLogout: () => void
|
onLogout: () => void
|
||||||
terminalDisabled?: boolean
|
terminalDisabled?: boolean
|
||||||
@@ -46,6 +57,16 @@ export default function Sidebar({
|
|||||||
onMcpClick,
|
onMcpClick,
|
||||||
onWizardsClick,
|
onWizardsClick,
|
||||||
onHelpClick,
|
onHelpClick,
|
||||||
|
onFleetOrgClick,
|
||||||
|
onFleetMessagesClick,
|
||||||
|
onFleetBoardClick,
|
||||||
|
onFleetOwnerClick,
|
||||||
|
onFleetApprovalsClick,
|
||||||
|
onFleetAttentionClick,
|
||||||
|
onFleetEscalationsClick,
|
||||||
|
onFleetSandboxesClick,
|
||||||
|
onFleetTasksClick,
|
||||||
|
onFleetOpsClick,
|
||||||
onExitMode,
|
onExitMode,
|
||||||
onLogout,
|
onLogout,
|
||||||
terminalDisabled = false,
|
terminalDisabled = false,
|
||||||
@@ -216,6 +237,126 @@ export default function Sidebar({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav className="flex-1 p-2 max-lg:flex max-lg:gap-1 max-lg:overflow-x-auto max-lg:[scrollbar-width:none]">
|
<nav className="flex-1 p-2 max-lg:flex max-lg:gap-1 max-lg:overflow-x-auto max-lg:[scrollbar-width:none]">
|
||||||
|
<button
|
||||||
|
onClick={onFleetOrgClick}
|
||||||
|
className={navItemClass(activeView === 'org')}
|
||||||
|
aria-current={activeView === 'org' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-org"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 4v4m0 4v4m-6-8h4m8 0h-4M6 16h12" />
|
||||||
|
</svg>
|
||||||
|
<span className="text-sm max-lg:text-[11px]">Fleet Org</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onFleetSandboxesClick}
|
||||||
|
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'fleet-sandboxes')}`}
|
||||||
|
aria-current={activeView === 'fleet-sandboxes' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-sandboxes"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M3 8l9-5 9 5-9 5-9-5zM3 8v8l9 5 9-5V8M12 13v8" />
|
||||||
|
</svg>
|
||||||
|
<span className="text-sm max-lg:text-[11px]">Sandboxes</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onFleetTasksClick}
|
||||||
|
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'tasks')}`}
|
||||||
|
aria-current={activeView === 'tasks' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-tasks"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 6h16M4 12h16M4 18h10" />
|
||||||
|
</svg>
|
||||||
|
<span className="text-sm max-lg:text-[11px]">Tasks</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onFleetOpsClick}
|
||||||
|
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'ops')}`}
|
||||||
|
aria-current={activeView === 'ops' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-ops"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 8v4l3 2m6-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<span className="text-sm max-lg:text-[11px]">Betrieb</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onFleetMessagesClick}
|
||||||
|
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'messages')}`}
|
||||||
|
aria-current={activeView === 'messages' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-messages"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 6h16v10H8l-4 4V6z" />
|
||||||
|
</svg>
|
||||||
|
<span className="text-sm max-lg:text-[11px]">Messages</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onFleetBoardClick}
|
||||||
|
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'board')}`}
|
||||||
|
aria-current={activeView === 'board' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-board"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 5h5v5H4V5zm11 0h5v5h-5V5zM4 14h5v5H4v-5zm11 0h5v5h-5v-5z" />
|
||||||
|
</svg>
|
||||||
|
<span className="text-sm max-lg:text-[11px]">Kanban</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onFleetOwnerClick}
|
||||||
|
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'owner')}`}
|
||||||
|
aria-current={activeView === 'owner' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-owner"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M5 12h14M12 5v14" />
|
||||||
|
</svg>
|
||||||
|
<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)}`}
|
||||||
|
aria-current={activeView === 'approvals' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-approvals"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9 12l2 2 4-4m-8-5h10a2 2 0 012 2v10a2 2 0 01-2 2H7a2 2 0 01-2-2V7a2 2 0 012-2z" />
|
||||||
|
</svg>
|
||||||
|
<span className="text-sm max-lg:text-[11px]">Freigaben</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onFleetEscalationsClick}
|
||||||
|
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'escalations', true)}`}
|
||||||
|
aria-current={activeView === 'escalations' ? 'page' : undefined}
|
||||||
|
data-testid="fleet-nav-escalations"
|
||||||
|
>
|
||||||
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 3l9 16H3l9-16z M12 10v4m0 2v1" />
|
||||||
|
</svg>
|
||||||
|
<span className="text-sm max-lg:text-[11px]">Escalations</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={onSandboxesClick}
|
onClick={onSandboxesClick}
|
||||||
className={navItemClass(activeView === 'sandboxes' && !isCreateMode && !isDestroyMode)}
|
className={navItemClass(activeView === 'sandboxes' && !isCreateMode && !isDestroyMode)}
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ function contentDispositionFileName(value: string | null, fallback: string) {
|
|||||||
|
|
||||||
function defaultCloneName(source?: SandboxInventoryItem) {
|
function defaultCloneName(source?: SandboxInventoryItem) {
|
||||||
if (!source) return ""
|
if (!source) return ""
|
||||||
return `${source.name.replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "")}-clone`.slice(0, 63)
|
const base = source.name.replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 13).replace(/-+$/g, "")
|
||||||
|
return `${base || "sandbox"}-clone`
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function WizardPanel({
|
export default function WizardPanel({
|
||||||
@@ -134,7 +135,7 @@ export default function WizardPanel({
|
|||||||
|
|
||||||
const canContinue = (() => {
|
const canContinue = (() => {
|
||||||
if (activeStep === "source") return Boolean(sourceSandbox)
|
if (activeStep === "source") return Boolean(sourceSandbox)
|
||||||
if (activeStep === "target") return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(targetName) && targetName.length <= 63
|
if (activeStep === "target") return /^(?!.*--)[a-z]([a-z0-9-]*[a-z0-9])?$/.test(targetName) && targetName.length <= 19
|
||||||
if (activeStep === "options") return Boolean(backupPath.trim() && restorePath.trim())
|
if (activeStep === "options") return Boolean(backupPath.trim() && restorePath.trim())
|
||||||
if (activeStep === "review") return Boolean(sourceSandbox && targetName.trim())
|
if (activeStep === "review") return Boolean(sourceSandbox && targetName.trim())
|
||||||
return false
|
return false
|
||||||
@@ -626,9 +627,12 @@ export default function WizardPanel({
|
|||||||
<input
|
<input
|
||||||
value={targetName}
|
value={targetName}
|
||||||
onChange={(event) => setTargetName(event.target.value)}
|
onChange={(event) => setTargetName(event.target.value)}
|
||||||
|
maxLength={19}
|
||||||
|
pattern="(?!.*--)[a-z](?:[a-z0-9-]*[a-z0-9])?"
|
||||||
placeholder="source-clone"
|
placeholder="source-clone"
|
||||||
className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]"
|
className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)] focus:outline-none focus:border-[var(--nvidia-green)]"
|
||||||
/>
|
/>
|
||||||
|
<span className="text-[11px] text-[var(--foreground-dim)]">1-19 characters; start with a lowercase letter; no consecutive hyphens.</span>
|
||||||
</label>
|
</label>
|
||||||
{activeBlueprint?.supportsTailscale && (
|
{activeBlueprint?.supportsTailscale && (
|
||||||
<label className="flex items-center gap-3 text-sm font-mono text-[var(--foreground)]">
|
<label className="flex items-center gap-3 text-sm font-mono text-[var(--foreground)]">
|
||||||
|
|||||||
@@ -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>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import RunbookHint from "./RunbookHint"
|
||||||
|
import { hintByKey } from "@/app/lib/fleet/runbookHints"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EscalationHistory — Kernfeature 4: HITL-/Escalation-Historie.
|
||||||
|
* Journal-Filter type=escalation (Deadman-Alarm, Agent-Escalations) plus
|
||||||
|
* rejected-Quarantine-Events. Poll 5 s. Kein psql — Spool ist die Wahrheit.
|
||||||
|
*/
|
||||||
|
|
||||||
|
type JournalLine = {
|
||||||
|
event?: string
|
||||||
|
task_id?: string
|
||||||
|
from?: string
|
||||||
|
to?: string
|
||||||
|
type?: string
|
||||||
|
priority?: string
|
||||||
|
time_epoch?: number
|
||||||
|
errors?: string
|
||||||
|
[k: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EscalationHistory() {
|
||||||
|
const [esc, setEsc] = useState<JournalLine[]>([])
|
||||||
|
const [rej, setRej] = useState<JournalLine[]>([])
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false
|
||||||
|
const load = () => {
|
||||||
|
fetch("/api/fleet/escalations", { cache: "no-store" })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then((d: { escalations: JournalLine[]; rejected: JournalLine[] }) => {
|
||||||
|
if (cancelled) return
|
||||||
|
setEsc(d.escalations)
|
||||||
|
setRej(d.rejected)
|
||||||
|
setError(null)
|
||||||
|
})
|
||||||
|
.catch((e: Error) => {
|
||||||
|
if (!cancelled) setError(e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
load()
|
||||||
|
const timer = setInterval(load, 5000)
|
||||||
|
return () => {
|
||||||
|
cancelled = true
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const row = (l: JournalLine, kind: "esc" | "rej") => (
|
||||||
|
<div
|
||||||
|
key={`${l.task_id}-${l.time_epoch}-${kind}`}
|
||||||
|
className="border-b border-[var(--border)] py-2 font-mono text-xs flex gap-3 items-baseline"
|
||||||
|
data-fleet-escalation={kind}
|
||||||
|
>
|
||||||
|
<span className="text-[var(--foreground-dim)] w-36 shrink-0">
|
||||||
|
{l.time_epoch ? new Date(l.time_epoch * 1000).toLocaleString("de-DE") : "--"}
|
||||||
|
</span>
|
||||||
|
<span className="w-20 shrink-0">{l.from || "system"}</span>
|
||||||
|
<span className="text-[var(--foreground-dim)] w-4 shrink-0">→</span>
|
||||||
|
<span className="w-16 shrink-0">{l.to || "-"}</span>
|
||||||
|
<span className="w-8 shrink-0 text-[var(--status-stopped)]">{l.priority || ""}</span>
|
||||||
|
<span className="truncate text-[var(--foreground-dim)]">{l.task_id?.slice(0, 8) || l.errors || ""}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="panel p-8 text-center" data-testid="fleet-escalations-error">
|
||||||
|
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
||||||
|
Journal nicht erreichbar
|
||||||
|
</h3>
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] mt-2 font-mono break-all">{error}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="panel p-4 flex items-center gap-4">
|
||||||
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||||
|
ESCALATIONS
|
||||||
|
</h1>
|
||||||
|
<span className="text-[10px] font-mono text-[var(--foreground-dim)]">
|
||||||
|
{esc.length} Alarme · {rej.length} Quarantaene
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="panel p-4">
|
||||||
|
<h2 className="text-[10px] uppercase tracking-wider text-[var(--status-stopped)] mb-3">
|
||||||
|
HITL-Alarme (type=escalation)
|
||||||
|
</h2>
|
||||||
|
<RunbookHint hint={hintByKey("deadman")} />
|
||||||
|
{esc.length === 0 ? (
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] font-mono py-4 text-center">
|
||||||
|
Keine Alarme — alles ruhig
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
esc.map((l) => row(l, "esc"))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="panel p-4">
|
||||||
|
<h2 className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] mb-3">
|
||||||
|
Quarantaene (rejected/invalid)
|
||||||
|
</h2>
|
||||||
|
{rej.length === 0 ? (
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] font-mono py-4 text-center">
|
||||||
|
Keine abgelehnten Envelopes
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
rej.map((l) => row(l, "rej"))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* KanbanBoard — Kernfeature 3: VS-Auswahl, Spalten Neu/Bewertet/In Bau/Fertig
|
||||||
|
* aus board-service (via /api/fleet/kanban), Poll 5 s (Statuswechsel <=10 s).
|
||||||
|
*/
|
||||||
|
|
||||||
|
type Card = { id: string; titel: string; score: number; status: string; ursprung: string; erstellt: string }
|
||||||
|
type KanbanData = {
|
||||||
|
value_streams: string[]
|
||||||
|
boards: Array<{ vs: string; board: { kanban: Record<string, Card[]> } }>
|
||||||
|
generated_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const COLUMNS = ["Neu", "Bewertet", "In Bau", "Fertig"] as const
|
||||||
|
|
||||||
|
export default function KanbanBoard() {
|
||||||
|
const [data, setData] = useState<KanbanData | null>(null)
|
||||||
|
const [selectedVs, setSelectedVs] = useState<string>("")
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false
|
||||||
|
const load = () => {
|
||||||
|
fetch("/api/fleet/kanban", { cache: "no-store" })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then((d: KanbanData) => {
|
||||||
|
if (cancelled) return
|
||||||
|
setData(d)
|
||||||
|
setError(null)
|
||||||
|
if (!selectedVs && d.value_streams.length > 0) setSelectedVs(d.value_streams[0])
|
||||||
|
})
|
||||||
|
.catch((e: Error) => {
|
||||||
|
if (!cancelled) setError(e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
load()
|
||||||
|
const timer = setInterval(load, 5000)
|
||||||
|
return () => {
|
||||||
|
cancelled = true
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}, [selectedVs])
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="panel p-8 text-center" data-testid="fleet-kanban-error">
|
||||||
|
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
||||||
|
Board-Service nicht erreichbar
|
||||||
|
</h3>
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] mt-2 font-mono break-all">{error}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!data) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center h-64" data-testid="fleet-kanban-loading">
|
||||||
|
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">LADEN...</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const board = data.boards.find((b) => b.vs === selectedVs)
|
||||||
|
const kanban = board?.board.kanban || { Neu: [], Bewertet: [], "In Bau": [], Fertig: [] }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="panel p-4 flex flex-wrap gap-3 items-center">
|
||||||
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||||
|
KANBAN
|
||||||
|
</h1>
|
||||||
|
<select
|
||||||
|
value={selectedVs}
|
||||||
|
onChange={(e) => setSelectedVs(e.target.value)}
|
||||||
|
className="bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
data-testid="fleet-kanban-vs-select"
|
||||||
|
>
|
||||||
|
{data.value_streams.map((vs) => (
|
||||||
|
<option key={vs} value={vs}>
|
||||||
|
{vs}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 gap-4" data-testid="fleet-kanban-board">
|
||||||
|
{COLUMNS.map((col) => (
|
||||||
|
<div key={col} className="panel p-3 min-h-[300px]" data-fleet-kanban-column={col}>
|
||||||
|
<div className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] mb-3 flex justify-between">
|
||||||
|
<span>{col}</span>
|
||||||
|
<span>{kanban[col]?.length || 0}</span>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
{(kanban[col] || []).map((c) => (
|
||||||
|
<div key={c.id} className="bg-[var(--background-tertiary)] p-2 rounded-sm" data-fleet-kanban-card={c.id}>
|
||||||
|
<div className="text-xs font-semibold truncate">{c.id}</div>
|
||||||
|
<div className="text-[10px] text-[var(--foreground-dim)] truncate">{c.titel}</div>
|
||||||
|
<div className="text-[10px] font-mono text-[var(--nvidia-green)] mt-1">
|
||||||
|
score {c.score} · {c.ursprung}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useRef, useState } from "react"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessageFeed — Kernfeature 2: rollierendes Spool-Journal.
|
||||||
|
* Zeigt from/to/priority/status je Eintrag; escalations rot hervorgehoben;
|
||||||
|
* Filter nach type und agent. Poll 5 s mit Epoch-Cursor (nur neue Eintraege).
|
||||||
|
*/
|
||||||
|
|
||||||
|
type JournalLine = {
|
||||||
|
event?: string
|
||||||
|
task_id?: string
|
||||||
|
from?: string
|
||||||
|
to?: string
|
||||||
|
type?: string
|
||||||
|
priority?: string
|
||||||
|
status?: string
|
||||||
|
file?: string
|
||||||
|
time_epoch?: number
|
||||||
|
errors?: string
|
||||||
|
raw?: string
|
||||||
|
[k: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
const EVENT_COLOR: Record<string, string> = {
|
||||||
|
accepted: "var(--status-running)",
|
||||||
|
rejected: "var(--status-stopped)",
|
||||||
|
run_finished: "var(--nvidia-green)",
|
||||||
|
escalation: "#e5534b",
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function MessageFeed() {
|
||||||
|
const [lines, setLines] = useState<JournalLine[]>([])
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
const [typeFilter, setTypeFilter] = useState<string>("all")
|
||||||
|
const [agentFilter, setAgentFilter] = useState<string>("all")
|
||||||
|
const cursorRef = useRef(0)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false
|
||||||
|
const load = () => {
|
||||||
|
const url = `/api/fleet/messages?limit=200${cursorRef.current > 0 ? `&cursor=${cursorRef.current}` : ""}`
|
||||||
|
fetch(url, { cache: "no-store" })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then((d: { messages: JournalLine[] }) => {
|
||||||
|
if (cancelled) return
|
||||||
|
if (d.messages.length > 0) {
|
||||||
|
const maxEpoch = Math.max(...d.messages.map((m) => Number(m.time_epoch || 0)))
|
||||||
|
if (maxEpoch > cursorRef.current) cursorRef.current = maxEpoch
|
||||||
|
setLines((prev) => {
|
||||||
|
const seen = new Set(prev.map((l) => `${l.task_id}:${l.event}:${l.time_epoch}`))
|
||||||
|
const fresh = d.messages.filter((l) => !seen.has(`${l.task_id}:${l.event}:${l.time_epoch}`))
|
||||||
|
return [...prev, ...fresh].slice(-500)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setError(null)
|
||||||
|
})
|
||||||
|
.catch((e: Error) => {
|
||||||
|
if (!cancelled) setError(e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
load()
|
||||||
|
const timer = setInterval(load, 5000)
|
||||||
|
return () => {
|
||||||
|
cancelled = true
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const visible = lines.filter((l) => {
|
||||||
|
if (typeFilter !== "all" && l.type !== typeFilter && l.event !== typeFilter) return false
|
||||||
|
if (agentFilter !== "all" && l.from !== agentFilter && l.to !== agentFilter) return false
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="panel p-8 text-center" data-testid="fleet-messages-error">
|
||||||
|
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
||||||
|
Spool-Journal nicht erreichbar
|
||||||
|
</h3>
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] mt-2 font-mono break-all">{error}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="panel p-4 flex flex-wrap gap-3 items-center">
|
||||||
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||||
|
MESSAGES
|
||||||
|
</h1>
|
||||||
|
<select
|
||||||
|
value={typeFilter}
|
||||||
|
onChange={(e) => setTypeFilter(e.target.value)}
|
||||||
|
className="bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
data-testid="fleet-msg-type-filter"
|
||||||
|
>
|
||||||
|
{["all", "escalation", "chat", "build", "review", "vote", "fyi", "accepted", "rejected", "run_finished"].map(
|
||||||
|
(t) => (
|
||||||
|
<option key={t} value={t}>
|
||||||
|
{t}
|
||||||
|
</option>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
<select
|
||||||
|
value={agentFilter}
|
||||||
|
onChange={(e) => setAgentFilter(e.target.value)}
|
||||||
|
className="bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
data-testid="fleet-msg-agent-filter"
|
||||||
|
>
|
||||||
|
{["all", "ceo", "cto", "ciso", "chro", "coo", "cmo", "agile-coach", "research", "devops"].map((a) => (
|
||||||
|
<option key={a} value={a}>
|
||||||
|
{a}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<span className="text-[10px] text-[var(--foreground-dim)] font-mono">{visible.length} Eintraege</span>
|
||||||
|
</div>
|
||||||
|
<div className="panel p-4 max-h-[70vh] overflow-y-auto" data-testid="fleet-message-feed">
|
||||||
|
{visible.length === 0 && (
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] font-mono py-8 text-center">
|
||||||
|
Keine Eintraege (Filter oder wartet auf ersten Task)
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{visible.map((l, i) => {
|
||||||
|
const key = `${l.task_id}-${l.event}-${l.time_epoch}-${i}`
|
||||||
|
const isEsc = l.type === "escalation" || l.event === "rejected"
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={key}
|
||||||
|
className="border-b border-[var(--border)] py-2 font-mono text-xs flex gap-3 items-baseline"
|
||||||
|
data-fleet-message={l.event}
|
||||||
|
style={isEsc ? { borderLeft: "3px solid #e5534b", paddingLeft: "8px" } : undefined}
|
||||||
|
>
|
||||||
|
<span className="text-[var(--foreground-dim)] w-20 shrink-0">
|
||||||
|
{l.time_epoch ? new Date(l.time_epoch * 1000).toLocaleTimeString("de-DE") : "--:--"}
|
||||||
|
</span>
|
||||||
|
<span style={{ color: EVENT_COLOR[l.event || ""] || "var(--foreground)" }} className="w-24 shrink-0">
|
||||||
|
{l.event || "?"}
|
||||||
|
</span>
|
||||||
|
<span className="w-16 shrink-0">{l.from || "system"}</span>
|
||||||
|
<span className="text-[var(--foreground-dim)] w-4 shrink-0">→</span>
|
||||||
|
<span className="w-16 shrink-0">{l.to || "-"}</span>
|
||||||
|
<span className="w-10 shrink-0 text-[var(--foreground-dim)]">{l.priority || ""}</span>
|
||||||
|
<span className="w-16 shrink-0 text-[var(--foreground-dim)]">{l.type || ""}</span>
|
||||||
|
<span className="w-20 shrink-0 text-[var(--foreground-dim)]">{l.status || ""}</span>
|
||||||
|
<span className="truncate text-[var(--foreground-dim)]">{l.task_id?.slice(0, 8) || l.file || l.raw || ""}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,348 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fleet/OpsPanels.tsx — Betriebs-Audit im Control Tower.
|
||||||
|
*
|
||||||
|
* Zwei Karten in einem Panel (Umsetzung der Change-Orders aus der devops-Sandbox):
|
||||||
|
* - NAR-Historie (Karte tower-nar-historie): vollzogene Rueckbauten mit Datum,
|
||||||
|
* Grant, Ziel und Nachweis; ausstehende Rueckbauten mit Faelligkeit,
|
||||||
|
* Ueberfaelligkeits-Marke und Grant-Lebenszyklus. Badge in der Kopfzeile.
|
||||||
|
* - Release-Feed (Karte tower-release-notes-feed): chronologische Lieferliste
|
||||||
|
* aller Release-Notes inkl. Quittungen, filterbar nach Agent.
|
||||||
|
*
|
||||||
|
* Rein lesend: GET /api/fleet/nar-history und /api/fleet/release-feed.
|
||||||
|
* Keine Mutation, keine Netz-Grants, 30 s Auto-Refresh.
|
||||||
|
*/
|
||||||
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
|
import RunbookHint from './RunbookHint'
|
||||||
|
import { hintByKey } from '@/app/lib/fleet/runbookHints'
|
||||||
|
|
||||||
|
const REFRESH_MS = 30_000
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
type NarPayload = {
|
||||||
|
generated_at: string
|
||||||
|
today: string
|
||||||
|
degraded: boolean
|
||||||
|
degraded_reason: string
|
||||||
|
vollzogen_count: number
|
||||||
|
ausstehend_count: number
|
||||||
|
ueberfaellig_count: number
|
||||||
|
badge: { count: number; level: string; label: string }
|
||||||
|
history: NarEntry[]
|
||||||
|
ausstehend: NarEntry[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReleaseEntry = {
|
||||||
|
iso: string
|
||||||
|
text: string
|
||||||
|
agent: string
|
||||||
|
vs: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReleasePayload = {
|
||||||
|
generated_at: string
|
||||||
|
degraded: boolean
|
||||||
|
degraded_reason: string
|
||||||
|
total: number
|
||||||
|
matching: number
|
||||||
|
shown: number
|
||||||
|
agents: string[]
|
||||||
|
entries: ReleaseEntry[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tab = 'nar' | 'releases'
|
||||||
|
|
||||||
|
function fmt(iso: string): string {
|
||||||
|
if (!iso) return '—'
|
||||||
|
const t = Date.parse(iso)
|
||||||
|
if (Number.isNaN(t)) return iso
|
||||||
|
return new Date(t).toISOString().replace('T', ' ').slice(0, 16) + 'Z'
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusClass(status: string): string {
|
||||||
|
const s = status.toLowerCase()
|
||||||
|
if (s === 'fertig') return 'text-emerald-400'
|
||||||
|
if (s === 'inbau' || s === 'in bau') return 'text-amber-400'
|
||||||
|
return 'text-[var(--foreground-dim)]'
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function OpsPanels() {
|
||||||
|
const [tab, setTab] = useState<Tab>('nar')
|
||||||
|
const [nar, setNar] = useState<NarPayload | null>(null)
|
||||||
|
const [rel, setRel] = useState<ReleasePayload | null>(null)
|
||||||
|
const [agent, setAgent] = useState('')
|
||||||
|
const [err, setErr] = useState('')
|
||||||
|
|
||||||
|
const loadNar = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/fleet/nar-history', { cache: 'no-store' })
|
||||||
|
const body = (await res.json()) as NarPayload
|
||||||
|
setNar(body)
|
||||||
|
if (body.degraded) setErr(body.degraded_reason)
|
||||||
|
} catch (e) {
|
||||||
|
setErr(e instanceof Error ? e.message : String(e))
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const loadRel = useCallback(async (agentFilter: string) => {
|
||||||
|
try {
|
||||||
|
const q = new URLSearchParams({ limit: '120' })
|
||||||
|
if (agentFilter) q.set('agent', agentFilter)
|
||||||
|
const res = await fetch(`/api/fleet/release-feed?${q.toString()}`, { cache: 'no-store' })
|
||||||
|
const body = (await res.json()) as ReleasePayload
|
||||||
|
setRel(body)
|
||||||
|
if (body.degraded) setErr(body.degraded_reason)
|
||||||
|
} catch (e) {
|
||||||
|
setErr(e instanceof Error ? e.message : String(e))
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void loadNar()
|
||||||
|
void loadRel(agent)
|
||||||
|
const t = setInterval(() => {
|
||||||
|
void loadNar()
|
||||||
|
void loadRel(agent)
|
||||||
|
}, REFRESH_MS)
|
||||||
|
return () => clearInterval(t)
|
||||||
|
}, [loadNar, loadRel, agent])
|
||||||
|
|
||||||
|
const tabBtn = (id: Tab, label: string, count?: number) => (
|
||||||
|
<button
|
||||||
|
key={id}
|
||||||
|
type="button"
|
||||||
|
onClick={() => setTab(id)}
|
||||||
|
data-testid={`ops-tab-${id}`}
|
||||||
|
className={`rounded px-3 py-1 text-xs uppercase tracking-wider ${
|
||||||
|
tab === id
|
||||||
|
? 'bg-[var(--background-tertiary)] text-[var(--nvidia-green)]'
|
||||||
|
: 'text-[var(--foreground-dim)] hover:text-[var(--foreground)]'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
{typeof count === 'number' && count > 0 && (
|
||||||
|
<span className="ml-2 rounded bg-[var(--background-tertiary)] px-1.5 py-0.5 text-[10px]">
|
||||||
|
{count}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="panel p-4">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-sm font-semibold uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||||
|
Betrieb & Audit
|
||||||
|
</h1>
|
||||||
|
<p className="mt-1 text-xs text-[var(--foreground-dim)]">
|
||||||
|
Rueckbau-Lebenszyklus (NAR) und Lieferliste — read-only aus dem Board, 30 s Refresh.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{nar && (
|
||||||
|
<span
|
||||||
|
className={`rounded px-2 py-1 text-[11px] ${
|
||||||
|
nar.badge.level === 'red'
|
||||||
|
? 'bg-red-500/15 text-red-300'
|
||||||
|
: nar.badge.level === 'yellow'
|
||||||
|
? 'bg-amber-500/15 text-amber-300'
|
||||||
|
: 'bg-emerald-500/15 text-emerald-300'
|
||||||
|
}`}
|
||||||
|
data-testid="nar-badge"
|
||||||
|
>
|
||||||
|
{nar.badge.label}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
void loadNar()
|
||||||
|
void loadRel(agent)
|
||||||
|
}}
|
||||||
|
className="rounded border border-[var(--border)] px-2 py-1 text-[11px] hover:bg-[var(--background-tertiary)]"
|
||||||
|
>
|
||||||
|
Aktualisieren
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 flex gap-1">
|
||||||
|
{tabBtn('nar', 'NAR-Historie', nar?.ausstehend_count)}
|
||||||
|
{tabBtn('releases', 'Release-Feed', rel?.total)}
|
||||||
|
</div>
|
||||||
|
{err && (
|
||||||
|
<p className="mt-2 rounded bg-amber-500/10 px-2 py-1 text-[11px] text-amber-300">
|
||||||
|
Datenquelle eingeschraenkt: {err}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{err && <RunbookHint hint={hintByKey("health")} />}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{tab === 'nar' && (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="panel p-4">
|
||||||
|
<h2 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
Ausstehende Rueckbauten ({nar?.ausstehend.length ?? 0})
|
||||||
|
</h2>
|
||||||
|
<table className="mt-2 w-full text-left text-xs" data-testid="nar-ausstehend">
|
||||||
|
<thead className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
<tr>
|
||||||
|
<th className="py-2 pr-3">Karte</th>
|
||||||
|
<th className="py-2 pr-3">Faellig</th>
|
||||||
|
<th className="py-2 pr-3">Status</th>
|
||||||
|
<th className="py-2 pr-3">Grant</th>
|
||||||
|
<th className="py-2 pr-3">Ziel</th>
|
||||||
|
<th className="py-2">Titel</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="font-mono">
|
||||||
|
{(nar?.ausstehend ?? []).map((e) => (
|
||||||
|
<tr key={e.karte} className="border-t border-[var(--border)]">
|
||||||
|
<td className="py-1.5 pr-3">{e.karte}</td>
|
||||||
|
<td
|
||||||
|
className={`py-1.5 pr-3 whitespace-nowrap ${
|
||||||
|
e.ueberfaellig ? 'text-red-400' : ''
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{e.datum || 'ohne Datum'}
|
||||||
|
{e.faellig_in_tagen !== null && !e.ueberfaellig && e.faellig_in_tagen <= 7 && (
|
||||||
|
<span className="ml-1 text-amber-400">
|
||||||
|
(in {e.faellig_in_tagen} T)
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{e.ueberfaellig && (
|
||||||
|
<span className="ml-1">
|
||||||
|
({Math.abs(e.faellig_in_tagen ?? 0)} T ueberfaellig)
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className={`py-1.5 pr-3 ${statusClass(e.status)}`}>{e.status}</td>
|
||||||
|
<td className="py-1.5 pr-3">{e.grant || '—'}</td>
|
||||||
|
<td className="py-1.5 pr-3">{e.ziel || '—'}</td>
|
||||||
|
<td className="py-1.5 max-w-[30rem] truncate" title={e.titel}>
|
||||||
|
{e.titel}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{nar && nar.ausstehend.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={6} className="py-3 text-[var(--foreground-dim)]">
|
||||||
|
Keine offenen Rueckbauten.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="panel p-4">
|
||||||
|
<h2 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
Vollzogen ({nar?.history.length ?? 0})
|
||||||
|
</h2>
|
||||||
|
<table className="mt-2 w-full text-left text-xs" data-testid="nar-history">
|
||||||
|
<thead className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
<tr>
|
||||||
|
<th className="py-2 pr-3">Datum</th>
|
||||||
|
<th className="py-2 pr-3">Karte</th>
|
||||||
|
<th className="py-2 pr-3">Grant</th>
|
||||||
|
<th className="py-2 pr-3">Ziel</th>
|
||||||
|
<th className="py-2 pr-3">Agent</th>
|
||||||
|
<th className="py-2">Nachweis</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="font-mono">
|
||||||
|
{(nar?.history ?? []).map((e) => (
|
||||||
|
<tr key={e.karte} className="border-t border-[var(--border)]">
|
||||||
|
<td className="py-1.5 pr-3 whitespace-nowrap text-emerald-400">
|
||||||
|
{e.datum || '—'}
|
||||||
|
</td>
|
||||||
|
<td className="py-1.5 pr-3">{e.karte}</td>
|
||||||
|
<td className="py-1.5 pr-3">{e.grant || '—'}</td>
|
||||||
|
<td className="py-1.5 pr-3">{e.ziel || '—'}</td>
|
||||||
|
<td className="py-1.5 pr-3">{e.agent || '—'}</td>
|
||||||
|
<td className="py-1.5 max-w-[30rem] truncate" title={e.nachweis}>
|
||||||
|
{e.nachweis || '—'}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{nar && nar.history.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={6} className="py-3 text-[var(--foreground-dim)]">
|
||||||
|
Noch kein Rueckbau vollzogen.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{tab === 'releases' && (
|
||||||
|
<div className="panel p-4">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||||
|
<h2 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
Lieferliste ({rel?.shown ?? 0} von {rel?.matching ?? 0})
|
||||||
|
</h2>
|
||||||
|
<label className="text-[11px] text-[var(--foreground-dim)]">
|
||||||
|
Agent{' '}
|
||||||
|
<select
|
||||||
|
value={agent}
|
||||||
|
onChange={(e) => setAgent(e.target.value)}
|
||||||
|
className="ml-1 rounded border border-[var(--border)] bg-[var(--background-tertiary)] px-1 py-0.5 text-[11px] text-[var(--foreground)]"
|
||||||
|
data-testid="release-agent-filter"
|
||||||
|
>
|
||||||
|
<option value="">alle</option>
|
||||||
|
{(rel?.agents ?? []).map((a) => (
|
||||||
|
<option key={a} value={a}>
|
||||||
|
{a}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<ul className="mt-2 space-y-1.5" data-testid="release-feed">
|
||||||
|
{(rel?.entries ?? []).map((e, i) => (
|
||||||
|
<li
|
||||||
|
key={`${e.iso}-${i}`}
|
||||||
|
className="border-t border-[var(--border)] pt-1.5 text-xs"
|
||||||
|
>
|
||||||
|
<span className="font-mono text-[10px] text-[var(--foreground-dim)]">
|
||||||
|
{fmt(e.iso)}
|
||||||
|
</span>
|
||||||
|
{e.agent && (
|
||||||
|
<span className="ml-2 rounded bg-[var(--background-tertiary)] px-1.5 py-0.5 font-mono text-[10px] text-[var(--nvidia-green)]">
|
||||||
|
{e.agent}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<p className="mt-0.5 leading-snug">{e.text}</p>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
{rel && rel.entries.length === 0 && (
|
||||||
|
<li className="py-3 text-xs text-[var(--foreground-dim)]">
|
||||||
|
Keine Release-Notes im Filter.
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OrgChart — Kernfeature 1: Live-Org-Chart aus /api/fleet/overview.
|
||||||
|
* 9 Agenten-Karten (parent-Hierarchie), je Karte tok/s (in/out), Inbox-Size,
|
||||||
|
* Heartbeat-Status (gruen < 300 s, gelb < 900 s, rot sonst/null=pending).
|
||||||
|
* Poll 5 s; Fehler fail-loud sichtbar (kein leeres UI).
|
||||||
|
*/
|
||||||
|
|
||||||
|
type OverviewAgent = {
|
||||||
|
agent_id: string
|
||||||
|
role: string
|
||||||
|
al: number
|
||||||
|
parent: string | null
|
||||||
|
wave: number
|
||||||
|
function: string
|
||||||
|
title?: string
|
||||||
|
vk_name: string | null
|
||||||
|
model: string | null
|
||||||
|
tok_in_per_s: number
|
||||||
|
tok_out_per_s: number
|
||||||
|
inbox: number
|
||||||
|
heartbeat_age_s: number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
type Overview = { agents: OverviewAgent[]; generated_at: string }
|
||||||
|
|
||||||
|
function hbColor(age: number | null): { color: string; label: string } {
|
||||||
|
if (age === null) return { color: "var(--foreground-dim)", label: "pending" }
|
||||||
|
if (age < 300) return { color: "var(--status-running)", label: `${Math.round(age)}s` }
|
||||||
|
if (age < 900) return { color: "#e6b450", label: `${Math.round(age)}s` }
|
||||||
|
return { color: "var(--status-stopped)", label: `${Math.round(age)}s` }
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function OrgChart() {
|
||||||
|
const [data, setData] = useState<Overview | null>(null)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false
|
||||||
|
const load = () => {
|
||||||
|
fetch("/api/fleet/overview", { cache: "no-store" })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then((d: Overview) => {
|
||||||
|
if (!cancelled) {
|
||||||
|
setData(d)
|
||||||
|
setError(null)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e: Error) => {
|
||||||
|
if (!cancelled) setError(e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
load()
|
||||||
|
const timer = setInterval(load, 5000)
|
||||||
|
return () => {
|
||||||
|
cancelled = true
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="panel p-8 text-center" data-testid="fleet-org-error">
|
||||||
|
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
||||||
|
Fleet-Datenquelle nicht erreichbar
|
||||||
|
</h3>
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] mt-2 font-mono break-all">{error}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!data) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center h-64" data-testid="fleet-org-loading">
|
||||||
|
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">
|
||||||
|
LADEN...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ceo = data.agents.filter((a) => a.parent === null)
|
||||||
|
const byParent = new Map<string, OverviewAgent[]>()
|
||||||
|
for (const a of data.agents) {
|
||||||
|
if (a.parent === null) continue
|
||||||
|
const list = byParent.get(a.parent) || []
|
||||||
|
list.push(a)
|
||||||
|
byParent.set(a.parent, list)
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderCard = (a: OverviewAgent) => {
|
||||||
|
const hb = hbColor(a.heartbeat_age_s)
|
||||||
|
const children = byParent.get(a.agent_id) || []
|
||||||
|
return (
|
||||||
|
<div key={a.agent_id} className="flex flex-col items-center gap-4" data-testid={`fleet-agent-card-${a.agent_id}`}>
|
||||||
|
<div className="panel p-4 min-w-[220px]" data-fleet-agent-card={a.agent_id}>
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<span className="text-sm font-semibold">{a.agent_id}</span>
|
||||||
|
<span className="text-[10px] text-[var(--foreground-dim)] uppercase">AL{a.al}</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">{a.function}</div>
|
||||||
|
<div className="mt-3 grid grid-cols-3 gap-2 text-center" data-fleet-status-elements="3">
|
||||||
|
<div>
|
||||||
|
<div className="text-[9px] uppercase text-[var(--foreground-dim)]">tok/s in</div>
|
||||||
|
<div className="text-sm font-mono text-[var(--nvidia-green)]">{a.tok_in_per_s.toFixed(1)}</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="text-[9px] uppercase text-[var(--foreground-dim)]">tok/s out</div>
|
||||||
|
<div className="text-sm font-mono text-[var(--nvidia-green)]">{a.tok_out_per_s.toFixed(1)}</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="text-[9px] uppercase text-[var(--foreground-dim)]">Inbox</div>
|
||||||
|
<div className="text-sm font-mono" data-fleet-inbox={a.agent_id}>{a.inbox}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 flex items-center gap-2">
|
||||||
|
<span className="text-[9px] uppercase text-[var(--foreground-dim)]">Heartbeat</span>
|
||||||
|
<span className="text-xs font-mono" style={{ color: hb.color }} data-fleet-heartbeat={a.agent_id}>
|
||||||
|
{hb.label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{children.length > 0 && (
|
||||||
|
<div className="flex flex-wrap justify-center gap-4 border-t border-[var(--border)] pt-4">
|
||||||
|
{children.map(renderCard)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div className="panel p-6">
|
||||||
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mb-2">
|
||||||
|
FLEET ORG
|
||||||
|
</h1>
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] font-mono">
|
||||||
|
{data.agents.length} Agenten · Stand {new Date(data.generated_at).toLocaleTimeString("de-DE")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col items-center gap-8" data-testid="fleet-org-chart">
|
||||||
|
{ceo.map(renderCard)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,309 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OwnerApprovals — NAR-Freigaben (Kernfeature 5 / NAR-Verfahren §1.3).
|
||||||
|
* Liste der Owner-Inbox-Tasks (an tower-owner), Detail-Ansicht je Antrag mit
|
||||||
|
* geparsten Pflichtfeldern (Antragsteller / Ziel / Protokoll / Zweck / Dauer /
|
||||||
|
* Alternativen) + CISO-Bewertung, Approve/Decline mit Notizfeld.
|
||||||
|
* Bescheid geht via board-service decide_owner_task an den Antragsteller.
|
||||||
|
* Poll 5 s, fail loud.
|
||||||
|
*/
|
||||||
|
|
||||||
|
type OwnerTask = {
|
||||||
|
task_id: string
|
||||||
|
from: string
|
||||||
|
type: string
|
||||||
|
priority: string
|
||||||
|
status: string
|
||||||
|
created?: number
|
||||||
|
topic?: string
|
||||||
|
body?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ParsedNar = {
|
||||||
|
antragsteller: string
|
||||||
|
ziel: string
|
||||||
|
protokoll: string
|
||||||
|
zweck: string
|
||||||
|
dauer: string
|
||||||
|
alternativen: string
|
||||||
|
bewertung: string
|
||||||
|
empfehlung: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function section(body: string, startMark: string, endMarks: string[]): string {
|
||||||
|
const s = body.indexOf(startMark)
|
||||||
|
if (s === -1) return ""
|
||||||
|
let end = body.length
|
||||||
|
for (const m of endMarks) {
|
||||||
|
const i = body.indexOf(m, s + startMark.length)
|
||||||
|
if (i !== -1 && i < end) end = i
|
||||||
|
}
|
||||||
|
return body.slice(s, end).trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function field(src: string, label: string): string {
|
||||||
|
const re = new RegExp(`${label}:\\s*(.*)`)
|
||||||
|
const m = src.match(re)
|
||||||
|
return (m ? m[1] : "").trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseNar(body: string, from: string): ParsedNar {
|
||||||
|
const antrag = section(body, "Antragsteller:", [
|
||||||
|
"\nZiel:", "\nProtokoll:", "\nZweck:", "\nDauer:", "\nAlternativen:",
|
||||||
|
])
|
||||||
|
const ziel = section(body, "Ziel:", ["\nProtokoll:", "\nZweck:", "\nDauer:", "\nAlternativen:"])
|
||||||
|
const protokoll = section(body, "Protokoll:", ["\nZweck:", "\nDauer:", "\nAlternativen:"])
|
||||||
|
const zweck = section(body, "Zweck:", ["\nDauer:", "\nAlternativen:"])
|
||||||
|
const dauer = section(body, "Dauer:", ["\nAlternativen:"])
|
||||||
|
const alternativen = section(body, "Alternativen:", ["\n---"])
|
||||||
|
const bewertung = section(body, "--- CISO-BEWERTUNG ---", ["\n--- EMPFEHLUNG"])
|
||||||
|
const empfehlung = body.includes("--- EMPFEHLUNG")
|
||||||
|
? body.slice(body.indexOf("--- EMPFEHLUNG")).trim()
|
||||||
|
: ""
|
||||||
|
return {
|
||||||
|
antragsteller: field(antrag, "Antragsteller") || from,
|
||||||
|
ziel: field(ziel, "Ziel"),
|
||||||
|
protokoll: field(protokoll, "Protokoll"),
|
||||||
|
zweck: zweck.replace(/^Zweck:\s*/, "").trim(),
|
||||||
|
dauer: field(dauer, "Dauer"),
|
||||||
|
alternativen: alternativen.replace(/^Alternativen:\s*/, "").trim(),
|
||||||
|
bewertung,
|
||||||
|
empfehlung,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const InfoRow = ({ label, value }: { label: string; value: string }) => (
|
||||||
|
<div className="flex gap-3 items-baseline">
|
||||||
|
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] w-28 shrink-0">
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs font-mono break-all">{value || "—"}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default function OwnerApprovals() {
|
||||||
|
const [tasks, setTasks] = useState<OwnerTask[]>([])
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
const [selected, setSelected] = useState<string | null>(null)
|
||||||
|
const [note, setNote] = useState("")
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const [feedback, setFeedback] = useState<{ ok: boolean; msg: string } | null>(null)
|
||||||
|
|
||||||
|
const load = () => {
|
||||||
|
fetch("/api/fleet/owner/inbox", { cache: "no-store" })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then((d: { tasks: OwnerTask[] }) => {
|
||||||
|
setTasks(d.tasks || [])
|
||||||
|
setError(null)
|
||||||
|
})
|
||||||
|
.catch((e: Error) => setError(e.message))
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
load()
|
||||||
|
const timer = setInterval(load, 5000)
|
||||||
|
return () => clearInterval(timer)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const decide = (decision: "approve" | "decline") => {
|
||||||
|
if (!selected || busy) return
|
||||||
|
setBusy(true)
|
||||||
|
setFeedback(null)
|
||||||
|
fetch("/api/fleet/owner/decide", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ task_id: selected, decision, note }),
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
const body = await res.json()
|
||||||
|
if (!res.ok) throw new Error(body.error || `HTTP ${res.status}`)
|
||||||
|
return body
|
||||||
|
})
|
||||||
|
.then((d) => {
|
||||||
|
const ft = d.folge_task?.task?.task_id || d.folge_task?.task_id || "?"
|
||||||
|
setFeedback({
|
||||||
|
ok: true,
|
||||||
|
msg: `${decision === "approve" ? "Freigegeben" : "Abgelehnt"} — Bescheid-Task ${String(ft).slice(0, 8)} an ${d.antragsteller}`,
|
||||||
|
})
|
||||||
|
setNote("")
|
||||||
|
setSelected(null)
|
||||||
|
setTimeout(load, 500)
|
||||||
|
})
|
||||||
|
.catch((e: Error) => setFeedback({ ok: false, msg: e.message }))
|
||||||
|
.finally(() => setBusy(false))
|
||||||
|
}
|
||||||
|
|
||||||
|
const open = tasks.filter((t) => t.status === "submitted")
|
||||||
|
const done = tasks.filter((t) => t.status !== "submitted")
|
||||||
|
const current = tasks.find((t) => t.task_id === selected)
|
||||||
|
const nar = current ? parseNar(current.body || "", current.from) : null
|
||||||
|
|
||||||
|
const row = (t: OwnerTask, isDone: boolean) => (
|
||||||
|
<button
|
||||||
|
key={t.task_id}
|
||||||
|
onClick={() => {
|
||||||
|
setSelected(t.task_id)
|
||||||
|
setFeedback(null)
|
||||||
|
}}
|
||||||
|
className={`w-full text-left px-3 py-2 rounded-sm border-b border-[var(--border)] text-xs font-mono ${
|
||||||
|
selected === t.task_id ? "bg-[var(--background-panel)]" : "hover:bg-[var(--background-tertiary)]"
|
||||||
|
}`}
|
||||||
|
data-testid="fleet-approval-row"
|
||||||
|
data-status={t.status}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
className="w-8 shrink-0"
|
||||||
|
style={{ color: isDone ? "var(--foreground-dim)" : "var(--status-stopped)" }}
|
||||||
|
>
|
||||||
|
{t.priority}
|
||||||
|
</span>
|
||||||
|
<span className="w-20 shrink-0 truncate">{t.from}</span>
|
||||||
|
<span className="flex-1 truncate text-[var(--foreground-dim)]">{t.topic}</span>
|
||||||
|
<span className="shrink-0 text-[10px] text-[var(--foreground-dim)]">
|
||||||
|
{t.status === "submitted" ? "OFFEN" : t.status}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="panel p-4 flex items-center gap-4">
|
||||||
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||||
|
FREIGABEN
|
||||||
|
</h1>
|
||||||
|
<span className="text-[10px] font-mono text-[var(--foreground-dim)]">
|
||||||
|
{open.length} offen · {done.length} entschieden
|
||||||
|
</span>
|
||||||
|
{feedback && (
|
||||||
|
<span
|
||||||
|
className="text-xs font-mono"
|
||||||
|
style={{ color: feedback.ok ? "var(--status-running)" : "var(--status-stopped)" }}
|
||||||
|
data-testid="fleet-approval-feedback"
|
||||||
|
>
|
||||||
|
{feedback.msg}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{error && (
|
||||||
|
<div className="panel p-4 border-l-4 border-[var(--status-stopped)]">
|
||||||
|
<p className="text-xs font-mono text-[var(--status-stopped)] break-all">{error}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="grid grid-cols-[400px_1fr] gap-4 max-lg:grid-cols-1">
|
||||||
|
<div className="panel p-2" data-testid="fleet-approval-list">
|
||||||
|
<h2 className="text-[10px] uppercase tracking-wider text-[var(--status-stopped)] px-2 py-1">
|
||||||
|
Offene Anträge
|
||||||
|
</h2>
|
||||||
|
{open.length === 0 ? (
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] font-mono py-4 text-center">
|
||||||
|
Keine offenen Anträge
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
open.map((t) => row(t, false))
|
||||||
|
)}
|
||||||
|
{done.length > 0 && (
|
||||||
|
<h2 className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] px-2 py-1 mt-2">
|
||||||
|
Entscheidungs-Historie
|
||||||
|
</h2>
|
||||||
|
)}
|
||||||
|
{done.map((t) => row(t, true))}
|
||||||
|
</div>
|
||||||
|
<div className="panel p-4 min-h-[400px]" data-testid="fleet-approval-detail">
|
||||||
|
{current && nar ? (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
{current.type} · {current.priority}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs font-mono font-semibold">{current.topic}</span>
|
||||||
|
{current.status !== "submitted" && (
|
||||||
|
<span className="text-[10px] font-mono text-[var(--foreground-dim)] ml-auto">
|
||||||
|
{current.status}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2 border-l-2 border-[var(--border)] pl-4">
|
||||||
|
<h3 className="text-[10px] uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||||
|
Wer braucht Zugriff worauf?
|
||||||
|
</h3>
|
||||||
|
<InfoRow label="Antragsteller" value={nar.antragsteller} />
|
||||||
|
<InfoRow label="Ziel" value={nar.ziel} />
|
||||||
|
<InfoRow label="Protokoll" value={nar.protokoll} />
|
||||||
|
<h3 className="text-[10px] uppercase tracking-wider text-[var(--nvidia-green)] pt-2">
|
||||||
|
Wofür / Wie lange?
|
||||||
|
</h3>
|
||||||
|
<InfoRow label="Zweck" value={nar.zweck} />
|
||||||
|
<InfoRow label="Dauer" value={nar.dauer} />
|
||||||
|
<InfoRow label="Alternativen" value={nar.alternativen} />
|
||||||
|
</div>
|
||||||
|
{nar.bewertung && (
|
||||||
|
<div className="border-l-2 border-[var(--status-stopped)] pl-4 space-y-1">
|
||||||
|
<h3 className="text-[10px] uppercase tracking-wider text-[var(--status-stopped)]">
|
||||||
|
CISO-Bewertung
|
||||||
|
</h3>
|
||||||
|
<pre className="text-[11px] font-mono whitespace-pre-wrap text-[var(--foreground-dim)] max-h-48 overflow-y-auto">
|
||||||
|
{nar.bewertung}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{nar.empfehlung && (
|
||||||
|
<div className="border-l-2 border-[var(--nvidia-green)] pl-4 space-y-1">
|
||||||
|
<h3 className="text-[10px] uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||||
|
Empfehlung des CISO
|
||||||
|
</h3>
|
||||||
|
<pre className="text-[11px] font-mono whitespace-pre-wrap text-[var(--foreground-dim)] max-h-56 overflow-y-auto">
|
||||||
|
{nar.empfehlung}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{current.status === "submitted" ? (
|
||||||
|
<div className="space-y-3 pt-2" data-testid="fleet-approval-actions">
|
||||||
|
<textarea
|
||||||
|
value={note}
|
||||||
|
onChange={(e) => setNote(e.target.value)}
|
||||||
|
placeholder="Bedingungen / Begründung (optional, geht an den Antragsteller)..."
|
||||||
|
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm min-h-[60px]"
|
||||||
|
/>
|
||||||
|
<div className="flex gap-2 justify-end">
|
||||||
|
<button
|
||||||
|
onClick={() => decide("decline")}
|
||||||
|
disabled={busy}
|
||||||
|
className="px-4 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--status-stopped)] text-black font-semibold disabled:opacity-50"
|
||||||
|
data-testid="fleet-approval-decline"
|
||||||
|
>
|
||||||
|
Ablehnen
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => decide("approve")}
|
||||||
|
disabled={busy}
|
||||||
|
className="px-4 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold disabled:opacity-50"
|
||||||
|
data-testid="fleet-approval-approve"
|
||||||
|
>
|
||||||
|
Freigeben
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="text-xs font-mono text-[var(--foreground-dim)]">
|
||||||
|
Entscheidung getroffen — Bescheid ist an den Antragsteller gegangen.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] font-mono m-auto">
|
||||||
|
Antrag auswählen
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,310 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useRef, useState } from "react"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OwnerPanel — Kernfeature 5 (E-V3): Owner-Eingabekanaele.
|
||||||
|
* 1) Ideen-Formular -> add_backlog_card (ursprung=owner)
|
||||||
|
* 2) "Neuer Value Stream" -> CEO-Task (type=build, P2)
|
||||||
|
* 3) CEO-Chat mit Threads (type=chat, thread_id) — Chat verdraengt nie Task-Flow.
|
||||||
|
* Fail loud: Fehler des board-service/Spool als Klartext im Panel.
|
||||||
|
*/
|
||||||
|
|
||||||
|
type Thread = {
|
||||||
|
thread_id: string
|
||||||
|
topic: string
|
||||||
|
messages: Array<{ task_id: string; from: string; to: string; body: string; created: number }>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function OwnerPanel() {
|
||||||
|
const [threads, setThreads] = useState<Thread[]>([])
|
||||||
|
const [vsList, setVsList] = useState<string[]>([])
|
||||||
|
const [activeThread, setActiveThread] = useState<string | null>(null)
|
||||||
|
const [feedback, setFeedback] = useState<{ ok: boolean; msg: string } | null>(null)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
|
// Idee-Formular
|
||||||
|
const [ideaVs, setIdeaVs] = useState("")
|
||||||
|
const [ideaTitle, setIdeaTitle] = useState("")
|
||||||
|
const [ideaWert, setIdeaWert] = useState("7")
|
||||||
|
const [ideaMach, setIdeaMach] = useState("7")
|
||||||
|
// VS-Formular
|
||||||
|
const [vsTopic, setVsTopic] = useState("")
|
||||||
|
const [vsZiel, setVsZiel] = useState("")
|
||||||
|
// Chat
|
||||||
|
const [chatMsg, setChatMsg] = useState("")
|
||||||
|
const chatBottomRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
const loadThreads = () => {
|
||||||
|
fetch("/api/fleet/owner/chat", { cache: "no-store" })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then((d: { threads: Thread[] }) => {
|
||||||
|
setThreads(d.threads)
|
||||||
|
setError(null)
|
||||||
|
})
|
||||||
|
.catch((e: Error) => setError(e.message))
|
||||||
|
}
|
||||||
|
const loadVs = () => {
|
||||||
|
fetch("/api/fleet/kanban", { cache: "no-store" })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then((d: { value_streams: string[] }) => setVsList(d.value_streams))
|
||||||
|
.catch((e: Error) => setError(e.message))
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadThreads()
|
||||||
|
loadVs()
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
loadThreads()
|
||||||
|
}, 5000)
|
||||||
|
return () => clearInterval(timer)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
chatBottomRef.current?.scrollIntoView({ behavior: "smooth" })
|
||||||
|
}, [threads, activeThread])
|
||||||
|
|
||||||
|
const post = (url: string, payload: unknown, okMsg: (d: unknown) => string) => {
|
||||||
|
setFeedback(null)
|
||||||
|
fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
const body = await res.json()
|
||||||
|
if (!res.ok) throw new Error(body.error || `HTTP ${res.status}`)
|
||||||
|
return body
|
||||||
|
})
|
||||||
|
.then((d) => setFeedback({ ok: true, msg: okMsg(d) }))
|
||||||
|
.catch((e: Error) => setFeedback({ ok: false, msg: e.message }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitIdea = () => {
|
||||||
|
if (!ideaVs || !ideaTitle.trim()) {
|
||||||
|
setFeedback({ ok: false, msg: "VS und Titel sind Pflicht" })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const id = `owner-${Date.now().toString(36)}`
|
||||||
|
post(
|
||||||
|
"/api/fleet/owner/idea",
|
||||||
|
{ vs: ideaVs, karte_id: id, titel: ideaTitle, wert: Number(ideaWert), machbarkeit: Number(ideaMach) },
|
||||||
|
() => `Idee als Backlog-Karte '${id}' angelegt (Neu)`
|
||||||
|
)
|
||||||
|
setIdeaTitle("")
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitNewVs = () => {
|
||||||
|
if (!vsTopic.trim()) {
|
||||||
|
setFeedback({ ok: false, msg: "Topic ist Pflicht" })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
post(
|
||||||
|
"/api/fleet/owner/new-vs",
|
||||||
|
{ topic: vsTopic, ziel: vsZiel },
|
||||||
|
(d) => `VS-Gruendung als CEO-Task eingelegt (task_id ${(d as { task?: { task_id?: string } }).task?.task_id?.slice(0, 8) || "ok"})`
|
||||||
|
)
|
||||||
|
setVsTopic("")
|
||||||
|
setVsZiel("")
|
||||||
|
}
|
||||||
|
|
||||||
|
const startThread = () => {
|
||||||
|
const tid = `owner-chat-${Date.now().toString(36)}`
|
||||||
|
setActiveThread(tid)
|
||||||
|
setThreads((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ thread_id: tid, topic: `Owner-Chat ${new Date().toLocaleString("de-DE")}`, messages: [] },
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendChat = () => {
|
||||||
|
if (!activeThread || !chatMsg.trim()) return
|
||||||
|
post(
|
||||||
|
"/api/fleet/owner/chat",
|
||||||
|
{ thread_id: activeThread, topic: threads.find((t) => t.thread_id === activeThread)?.topic, message: chatMsg },
|
||||||
|
() => "gesendet"
|
||||||
|
)
|
||||||
|
setChatMsg("")
|
||||||
|
setTimeout(loadThreads, 800)
|
||||||
|
}
|
||||||
|
|
||||||
|
const current = threads.find((t) => t.thread_id === activeThread)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="panel p-4 flex items-center gap-4">
|
||||||
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mr-auto">
|
||||||
|
OWNER KANAELE
|
||||||
|
</h1>
|
||||||
|
{feedback && (
|
||||||
|
<span
|
||||||
|
className="text-xs font-mono"
|
||||||
|
style={{ color: feedback.ok ? "var(--status-running)" : "var(--status-stopped)" }}
|
||||||
|
data-testid="fleet-owner-feedback"
|
||||||
|
>
|
||||||
|
{feedback.msg}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{error && (
|
||||||
|
<div className="panel p-4 border-l-4 border-[var(--status-stopped)]">
|
||||||
|
<p className="text-xs font-mono text-[var(--status-stopped)] break-all">{error}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div className="panel p-4 space-y-3" data-testid="fleet-owner-idea-form">
|
||||||
|
<h2 className="text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Idee ins VS-Backlog</h2>
|
||||||
|
<select
|
||||||
|
value={ideaVs}
|
||||||
|
onChange={(e) => setIdeaVs(e.target.value)}
|
||||||
|
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
>
|
||||||
|
<option value="">Value Stream...</option>
|
||||||
|
{vsList.map((v) => (
|
||||||
|
<option key={v} value={v}>
|
||||||
|
{v}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<input
|
||||||
|
value={ideaTitle}
|
||||||
|
onChange={(e) => setIdeaTitle(e.target.value)}
|
||||||
|
placeholder="Titel der Idee"
|
||||||
|
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
/>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<label className="text-[10px] text-[var(--foreground-dim)] flex items-center gap-1">
|
||||||
|
Wert
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
max={10}
|
||||||
|
value={ideaWert}
|
||||||
|
onChange={(e) => setIdeaWert(e.target.value)}
|
||||||
|
className="w-14 bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="text-[10px] text-[var(--foreground-dim)] flex items-center gap-1">
|
||||||
|
Machbarkeit
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
max={10}
|
||||||
|
value={ideaMach}
|
||||||
|
onChange={(e) => setIdeaMach(e.target.value)}
|
||||||
|
className="w-14 bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
onClick={submitIdea}
|
||||||
|
className="ml-auto px-3 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold"
|
||||||
|
data-testid="fleet-owner-idea-submit"
|
||||||
|
>
|
||||||
|
Anlegen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="panel p-4 space-y-3" data-testid="fleet-owner-newvs-form">
|
||||||
|
<h2 className="text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Neuer Value Stream</h2>
|
||||||
|
<input
|
||||||
|
value={vsTopic}
|
||||||
|
onChange={(e) => setVsTopic(e.target.value)}
|
||||||
|
placeholder="Topic (z.B. 'Imkerei-Website 2.0')"
|
||||||
|
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={vsZiel}
|
||||||
|
onChange={(e) => setVsZiel(e.target.value)}
|
||||||
|
placeholder="Ziel (optional)"
|
||||||
|
className="w-full bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={submitNewVs}
|
||||||
|
className="px-3 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold"
|
||||||
|
data-testid="fleet-owner-newvs-submit"
|
||||||
|
>
|
||||||
|
CEO-Task anlegen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-[280px_1fr] gap-4">
|
||||||
|
<div className="panel p-3 space-y-2" data-testid="fleet-owner-thread-list">
|
||||||
|
<button
|
||||||
|
onClick={startThread}
|
||||||
|
className="w-full px-3 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold"
|
||||||
|
>
|
||||||
|
Neuer Chat-Thread
|
||||||
|
</button>
|
||||||
|
{threads.map((t) => (
|
||||||
|
<button
|
||||||
|
key={t.thread_id}
|
||||||
|
onClick={() => setActiveThread(t.thread_id)}
|
||||||
|
className={`w-full text-left px-2 py-1 rounded-sm text-xs font-mono truncate ${
|
||||||
|
activeThread === t.thread_id ? "bg-[var(--background-panel)]" : "hover:bg-[var(--background-tertiary)]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{t.topic || t.thread_id}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="panel p-4 flex flex-col min-h-[360px]" data-testid="fleet-owner-chat-panel">
|
||||||
|
{current ? (
|
||||||
|
<>
|
||||||
|
<div className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)] mb-3">
|
||||||
|
{current.topic || current.thread_id}
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 overflow-y-auto space-y-2">
|
||||||
|
{current.messages.map((m) => (
|
||||||
|
<div
|
||||||
|
key={m.task_id}
|
||||||
|
className="flex"
|
||||||
|
data-fleet-chat-message={m.from}
|
||||||
|
style={{ justifyContent: m.from === "tower-owner" ? "flex-end" : "flex-start" }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="max-w-[70%] p-2 rounded-sm text-xs font-mono"
|
||||||
|
style={{
|
||||||
|
background:
|
||||||
|
m.from === "tower-owner" ? "var(--background-panel)" : "var(--background-tertiary)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="text-[9px] text-[var(--foreground-dim)] mb-1">{m.from}</div>
|
||||||
|
{m.body}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<div ref={chatBottomRef} />
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 mt-3">
|
||||||
|
<input
|
||||||
|
value={chatMsg}
|
||||||
|
onChange={(e) => setChatMsg(e.target.value)}
|
||||||
|
onKeyDown={(e) => e.key === "Enter" && sendChat()}
|
||||||
|
placeholder="Nachricht an CEO..."
|
||||||
|
className="flex-1 bg-[var(--background-tertiary)] text-xs font-mono px-2 py-1 rounded-sm"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={sendChat}
|
||||||
|
className="px-3 py-1 text-[10px] uppercase tracking-wider rounded-sm bg-[var(--nvidia-green)] text-black font-semibold"
|
||||||
|
data-testid="fleet-owner-chat-send"
|
||||||
|
>
|
||||||
|
Senden
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] font-mono m-auto">
|
||||||
|
Thread auswaehlen oder neu anlegen
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RunbookHint.tsx — statischer Inline-Hint an den Alarm-Flaechen des Towers.
|
||||||
|
* Portierung der render_hint_html()-Semantik als React-Komponente
|
||||||
|
* (Karte tower-notfall-runbook, DATEI 3). Rein statisch: kein Polling,
|
||||||
|
* kein Egress, keine Secrets — nur interner Deep-Link auf /runbook#<anker>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { LampHint } from "@/app/lib/fleet/runbookHints"
|
||||||
|
|
||||||
|
export default function RunbookHint({ hint }: { hint: LampHint }) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
id={`hint-${hint.key}`}
|
||||||
|
className="lamp-hint text-xs leading-snug text-[var(--foreground-dim)]"
|
||||||
|
data-component={hint.component}
|
||||||
|
data-testid={`runbook-hint-${hint.key}`}
|
||||||
|
>
|
||||||
|
<span className="lh-title block font-semibold text-[var(--foreground)]">
|
||||||
|
Notfall {hint.scenario} — {hint.title}
|
||||||
|
</span>
|
||||||
|
<ol className="lh-steps my-0.5 ml-4 list-decimal">
|
||||||
|
{hint.kurzschritte.map((s: string) => (
|
||||||
|
<li key={s}>{s}</li>
|
||||||
|
))}
|
||||||
|
</ol>
|
||||||
|
<div className="lh-esc mt-0.5">
|
||||||
|
<strong>Eskalation:</strong> {hint.eskalation}
|
||||||
|
</div>
|
||||||
|
<a
|
||||||
|
className="lh-link text-[#93c5fd] underline hover:text-[#a5ccff]"
|
||||||
|
href={`/runbook${hint.anchor}`}
|
||||||
|
>
|
||||||
|
Vollständiges Runbook →
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SandboxFleetView — fleet-native Sandboxes-View (ersetzt die tote Upstream-
|
||||||
|
* "Sandboxes"-View, die den openshell-CLI auf dem Tower-HOST brauchte — unser
|
||||||
|
* Tower ist ein K8s-Container ohne Host-CLI).
|
||||||
|
*
|
||||||
|
* Datenquelle: /api/fleet/sandboxes (kube-state-metrics via Prometheus,
|
||||||
|
* read-only PromQL; KEIN kubectl, KEINE Host-CLI). Zeigt die 9 Agenten-Sandboxes:
|
||||||
|
* Phase/Ready, Restarts, Pod-Age, Node, CPU/Mem-Requests, Image-Digest,
|
||||||
|
* Heartbeat-Age. Poll 5 s, Fehler fail-loud sichtbar (kein stilles Leeren).
|
||||||
|
*/
|
||||||
|
|
||||||
|
type SandboxAgent = {
|
||||||
|
agent_id: string
|
||||||
|
role: string
|
||||||
|
title: string | null
|
||||||
|
exists: boolean
|
||||||
|
phase: string | null
|
||||||
|
ready: boolean | null
|
||||||
|
restarts: number | null
|
||||||
|
pod_age_s: number | null
|
||||||
|
node: string | null
|
||||||
|
cpu_request_milli: number | null
|
||||||
|
mem_request_mb: number | null
|
||||||
|
image_digest: string | null
|
||||||
|
heartbeat_age_s: number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
type SandboxesData = {
|
||||||
|
agents: SandboxAgent[]
|
||||||
|
fleet_image_digest: string | null
|
||||||
|
all_running: boolean
|
||||||
|
generated_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function phaseColor(agent: SandboxAgent): { color: string; label: string } {
|
||||||
|
if (!agent.exists || !agent.phase) return { color: "var(--foreground-dim)", label: "kein Pod" }
|
||||||
|
if (agent.phase === "Running" && agent.ready) return { color: "var(--status-running)", label: "Running" }
|
||||||
|
if (agent.phase === "Running") return { color: "#e6b450", label: "Running/NotReady" }
|
||||||
|
return { color: "var(--status-stopped)", label: agent.phase }
|
||||||
|
}
|
||||||
|
|
||||||
|
function hbColor(age: number | null): { color: string; label: string } {
|
||||||
|
if (age === null) return { color: "var(--foreground-dim)", label: "pending" }
|
||||||
|
if (age < 120) return { color: "var(--status-running)", label: `${Math.round(age)}s` }
|
||||||
|
if (age < 300) return { color: "#e6b450", label: `${Math.round(age)}s` }
|
||||||
|
return { color: "var(--status-stopped)", label: `${Math.round(age)}s` }
|
||||||
|
}
|
||||||
|
|
||||||
|
function fmtAge(sec: number): string {
|
||||||
|
if (sec < 60) return `${sec}s`
|
||||||
|
if (sec < 3600) return `${Math.floor(sec / 60)}m`
|
||||||
|
if (sec < 86400) return `${Math.floor(sec / 3600)}h ${Math.floor((sec % 3600) / 60)}m`
|
||||||
|
return `${Math.floor(sec / 86400)}d ${Math.floor((sec % 86400) / 3600)}h`
|
||||||
|
}
|
||||||
|
|
||||||
|
function fmtDigest(d: string | null): string {
|
||||||
|
if (!d) return "—"
|
||||||
|
return d.length > 19 ? `${d.slice(0, 19)}…` : d
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SandboxFleetView() {
|
||||||
|
const [data, setData] = useState<SandboxesData | null>(null)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false
|
||||||
|
const load = () => {
|
||||||
|
fetch("/api/fleet/sandboxes", { cache: "no-store" })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw new Error((await res.json()).error || `HTTP ${res.status}`)
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then((d: SandboxesData) => {
|
||||||
|
if (!cancelled) {
|
||||||
|
setData(d)
|
||||||
|
setError(null)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e: Error) => {
|
||||||
|
if (!cancelled) setError(e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
load()
|
||||||
|
const timer = setInterval(load, 5000)
|
||||||
|
return () => {
|
||||||
|
cancelled = true
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="panel p-8 text-center" data-testid="fleet-sandboxes-error">
|
||||||
|
<h3 className="text-sm font-semibold text-[var(--status-stopped)] uppercase tracking-wider">
|
||||||
|
Fleet-Datenquelle nicht erreichbar
|
||||||
|
</h3>
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] mt-2 font-mono break-all">{error}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!data) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center h-64" data-testid="fleet-sandboxes-loading">
|
||||||
|
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">Lade Sandboxes…</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const running = data.agents.filter((a) => a.phase === "Running" && a.ready).length
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4" data-testid="fleet-sandboxes-view">
|
||||||
|
<div className="flex items-center justify-between flex-wrap gap-2">
|
||||||
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider">Sandboxes</h1>
|
||||||
|
<div className="flex items-center gap-3 text-xs font-mono text-[var(--foreground-dim)]">
|
||||||
|
<span data-testid="fleet-sandboxes-count">
|
||||||
|
{running}/{data.agents.length} running
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className="px-2 py-0.5 rounded"
|
||||||
|
style={{
|
||||||
|
backgroundColor: data.all_running ? "rgba(118,185,0,0.15)" : "rgba(255,107,107,0.15)",
|
||||||
|
color: data.all_running ? "var(--status-running)" : "var(--status-stopped)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{data.all_running ? "ALLE GRÜN" : "DEGRADED"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="panel p-4">
|
||||||
|
<div className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">Fleet Image (digest-gepinnt)</div>
|
||||||
|
<div className="text-xs font-mono text-[var(--foreground)] mt-1" data-testid="fleet-sandboxes-image">
|
||||||
|
{fmtDigest(data.fleet_image_digest)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4">
|
||||||
|
{data.agents.map((agent) => {
|
||||||
|
const ph = phaseColor(agent)
|
||||||
|
const hb = hbColor(agent.heartbeat_age_s)
|
||||||
|
return (
|
||||||
|
<div key={agent.agent_id} className="panel p-4" data-testid={`fleet-sandbox-${agent.agent_id}`}>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<div className="text-sm font-semibold text-[var(--foreground)] font-mono">{agent.agent_id}</div>
|
||||||
|
<div className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">{agent.role}</div>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
className="text-[10px] font-mono px-2 py-0.5 rounded uppercase"
|
||||||
|
style={{ backgroundColor: "rgba(255,255,255,0.06)", color: ph.color }}
|
||||||
|
data-testid={`fleet-sandbox-phase-${agent.agent_id}`}
|
||||||
|
>
|
||||||
|
{ph.label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-x-4 gap-y-1 mt-3 text-xs">
|
||||||
|
<span className="text-[var(--foreground-dim)]">Node</span>
|
||||||
|
<span className="font-mono text-right text-[var(--foreground)]">{agent.node || "—"}</span>
|
||||||
|
|
||||||
|
<span className="text-[var(--foreground-dim)]">Pod-Age</span>
|
||||||
|
<span className="font-mono text-right text-[var(--foreground)]">
|
||||||
|
{agent.pod_age_s === null ? "—" : fmtAge(agent.pod_age_s)}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span className="text-[var(--foreground-dim)]">Restarts</span>
|
||||||
|
<span
|
||||||
|
className="font-mono text-right"
|
||||||
|
style={{ color: agent.restarts && agent.restarts > 0 ? "#e6b450" : "var(--foreground)" }}
|
||||||
|
>
|
||||||
|
{agent.restarts ?? "—"}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span className="text-[var(--foreground-dim)]">Requests</span>
|
||||||
|
<span className="font-mono text-right text-[var(--foreground)]">
|
||||||
|
{agent.cpu_request_milli ? `${agent.cpu_request_milli}m / ${agent.mem_request_mb}Mi` : "—"}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span className="text-[var(--foreground-dim)]">Heartbeat</span>
|
||||||
|
<span className="font-mono text-right" style={{ color: hb.color }} data-testid={`fleet-sandbox-hb-${agent.agent_id}`}>
|
||||||
|
{hb.label}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span className="text-[var(--foreground-dim)]">Image</span>
|
||||||
|
<span className="font-mono text-right text-[var(--foreground-dim)]">{fmtDigest(agent.image_digest)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-[10px] text-[var(--foreground-dim)] font-mono">
|
||||||
|
Stand: {new Date(data.generated_at).toLocaleTimeString("de-DE")} · Quelle: kube-state-metrics via Prometheus (read-only)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,515 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TaskBrowser — Task-Detail-Ansicht im Tower (Karte tower-task-detail).
|
||||||
|
*
|
||||||
|
* Drei Listen aus /api/fleet/tasks:
|
||||||
|
* - Spool-Reifegrad (offene submitted/working, Alter)
|
||||||
|
* - Dead-Letter (failed der letzten 7 Tage)
|
||||||
|
* - Alarm-Feed (Stoerungsereignisse aus dem Journal)
|
||||||
|
* Klick auf eine Zeile -> /api/fleet/task-detail?id=... -> Modal mit vollem
|
||||||
|
* Envelope (from/to/type/status/priority/created/Alter/topic/thread/karte/body).
|
||||||
|
* Body unredigiert (Change-Order Abnahme 3; React escaped beim Rendern).
|
||||||
|
* Polt 30 s; degradierte Quelle -> Banner statt Leeranzeige.
|
||||||
|
*/
|
||||||
|
import { useCallback, useEffect, useRef, useState } from "react"
|
||||||
|
import RunbookHint from "./RunbookHint"
|
||||||
|
import { hintByKey } from "@/app/lib/fleet/runbookHints"
|
||||||
|
|
||||||
|
type TaskEnvelope = {
|
||||||
|
task_id: string
|
||||||
|
from: string
|
||||||
|
to: string
|
||||||
|
type: string
|
||||||
|
status: string
|
||||||
|
priority: string
|
||||||
|
created: number | null
|
||||||
|
created_iso: string
|
||||||
|
age_seconds: number | null
|
||||||
|
age_human: string
|
||||||
|
topic: string
|
||||||
|
body: string
|
||||||
|
thread_id: string
|
||||||
|
karte_id: string
|
||||||
|
reply_to: string
|
||||||
|
vs: string
|
||||||
|
claimed_at: string
|
||||||
|
status_label: string
|
||||||
|
re_dispatched_to: string
|
||||||
|
re_dispatch_of: string
|
||||||
|
file: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type AlarmRow = {
|
||||||
|
time_epoch: number | null
|
||||||
|
time_iso: string
|
||||||
|
age_human: string
|
||||||
|
event: string
|
||||||
|
ref: string
|
||||||
|
from: string
|
||||||
|
to: string
|
||||||
|
task_id: string
|
||||||
|
note: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskOverview = {
|
||||||
|
generated_at: string
|
||||||
|
spool: TaskEnvelope[]
|
||||||
|
dead_letter: TaskEnvelope[]
|
||||||
|
alarm: AlarmRow[]
|
||||||
|
counts: { spool: number; dead_letter: number; alarm: number }
|
||||||
|
degraded: boolean
|
||||||
|
degraded_reason: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskDetail = {
|
||||||
|
generated_at: string
|
||||||
|
found: boolean
|
||||||
|
query_task_id: string
|
||||||
|
entry_kind: string
|
||||||
|
task: Record<string, string | number | null>
|
||||||
|
missing_fields: string[]
|
||||||
|
raw_keys: string[]
|
||||||
|
body_note: string
|
||||||
|
degraded: boolean
|
||||||
|
degraded_reason: string
|
||||||
|
error: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tab = "spool" | "dead-letter" | "alarm"
|
||||||
|
|
||||||
|
const REFRESH_MS = 30000
|
||||||
|
const AGING_ALERT_S = 5400
|
||||||
|
|
||||||
|
const DETAIL_FIELDS: Array<[string, string]> = [
|
||||||
|
["task_id", "Task-ID"],
|
||||||
|
["status_label", "Status"],
|
||||||
|
["from", "Von"],
|
||||||
|
["to", "An"],
|
||||||
|
["type", "Typ"],
|
||||||
|
["priority", "Prio"],
|
||||||
|
["created_iso", "Erstellt (ISO)"],
|
||||||
|
["age_human", "Alter"],
|
||||||
|
["topic", "Thema"],
|
||||||
|
["thread_id", "Thread-ID"],
|
||||||
|
["karte_id", "Karte"],
|
||||||
|
["reply_to", "Antwort an"],
|
||||||
|
["vs", "Value-Stream"],
|
||||||
|
["claimed_at", "Geclaimt"],
|
||||||
|
]
|
||||||
|
|
||||||
|
function ageClass(seconds: number | null): string {
|
||||||
|
if (seconds === null) return "text-[var(--foreground-dim)]"
|
||||||
|
if (seconds > AGING_ALERT_S) return "text-[var(--status-stopped)] font-semibold"
|
||||||
|
if (seconds > 900) return "text-amber-400"
|
||||||
|
return "text-[var(--foreground-dim)]"
|
||||||
|
}
|
||||||
|
|
||||||
|
function prioClass(p: string): string {
|
||||||
|
switch (p) {
|
||||||
|
case "P1": return "text-[var(--status-stopped)] font-semibold"
|
||||||
|
case "P2": return "text-amber-400"
|
||||||
|
default: return "text-[var(--foreground-dim)]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TaskBrowser() {
|
||||||
|
const [data, setData] = useState<TaskOverview | null>(null)
|
||||||
|
const [loadError, setLoadError] = useState("")
|
||||||
|
const [tab, setTab] = useState<Tab>("spool")
|
||||||
|
const [detail, setDetail] = useState<TaskDetail | null>(null)
|
||||||
|
const [detailLoading, setDetailLoading] = useState(false)
|
||||||
|
const [detailError, setDetailError] = useState("")
|
||||||
|
const [redis, setRedis] = useState<Record<string, { state: string; msg: string }>>({})
|
||||||
|
const modalRef = useRef<HTMLDivElement | null>(null)
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/fleet/tasks", { cache: "no-store" })
|
||||||
|
const body = (await res.json()) as TaskOverview & { error?: string }
|
||||||
|
if (!res.ok || body.error) {
|
||||||
|
setLoadError(body.error || `HTTP ${res.status}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setData(body)
|
||||||
|
setLoadError("")
|
||||||
|
} catch (e) {
|
||||||
|
setLoadError(e instanceof Error ? e.message : String(e))
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load()
|
||||||
|
const t = setInterval(() => void load(), REFRESH_MS)
|
||||||
|
return () => clearInterval(t)
|
||||||
|
}, [load])
|
||||||
|
|
||||||
|
/** Dead-Letter-Re-Dispatch: neuer Envelope ueber den board-service (Tower schreibt nie selbst). */
|
||||||
|
const redispatch = useCallback(
|
||||||
|
async (taskId: string) => {
|
||||||
|
setRedis((prev) => ({ ...prev, [taskId]: { state: "busy", msg: "stelle zu…" } }))
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/fleet/task-redispatch", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ id: taskId }),
|
||||||
|
})
|
||||||
|
const body = (await res.json()) as {
|
||||||
|
result?: string
|
||||||
|
new_task_id?: string
|
||||||
|
reason?: string
|
||||||
|
problems?: string[]
|
||||||
|
}
|
||||||
|
const result = String(body.result || `HTTP ${res.status}`)
|
||||||
|
let state = "err"
|
||||||
|
let msg = result
|
||||||
|
if (result === "OK_REDISPATCHED") {
|
||||||
|
state = "ok"
|
||||||
|
msg = `erneut zugestellt -> ${body.new_task_id}`
|
||||||
|
} else if (result === "OK_ALREADY") {
|
||||||
|
state = "already"
|
||||||
|
msg = `bereits re-dispatched -> ${body.new_task_id || "?"}`
|
||||||
|
} else if (body.reason || body.problems?.length) {
|
||||||
|
msg = `${result}: ${body.reason || body.problems?.join("; ")}`
|
||||||
|
}
|
||||||
|
setRedis((prev) => ({ ...prev, [taskId]: { state, msg } }))
|
||||||
|
await load()
|
||||||
|
} catch (e) {
|
||||||
|
setRedis((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[taskId]: { state: "err", msg: e instanceof Error ? e.message : String(e) },
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[load]
|
||||||
|
)
|
||||||
|
|
||||||
|
const openDetail = useCallback(async (id: string, kind: string) => {
|
||||||
|
setDetailLoading(true)
|
||||||
|
setDetailError("")
|
||||||
|
setDetail(null)
|
||||||
|
try {
|
||||||
|
const res = await fetch(
|
||||||
|
`/api/fleet/task-detail?id=${encodeURIComponent(id)}&kind=${encodeURIComponent(kind)}`,
|
||||||
|
{ cache: "no-store" }
|
||||||
|
)
|
||||||
|
const body = (await res.json()) as TaskDetail & { error?: string }
|
||||||
|
if (!res.ok || body.error) {
|
||||||
|
setDetailError(body.error || `HTTP ${res.status}`)
|
||||||
|
} else {
|
||||||
|
setDetail(body)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setDetailError(e instanceof Error ? e.message : String(e))
|
||||||
|
} finally {
|
||||||
|
setDetailLoading(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Escape") setDetail(null)
|
||||||
|
}
|
||||||
|
document.addEventListener("keydown", onKey)
|
||||||
|
return () => document.removeEventListener("keydown", onKey)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const counts = data?.counts
|
||||||
|
const tabBtn = (id: Tab, label: string, n: number | undefined) => (
|
||||||
|
<button
|
||||||
|
onClick={() => setTab(id)}
|
||||||
|
data-testid={`task-tab-${id}`}
|
||||||
|
className={`px-3 py-1.5 text-[11px] font-mono uppercase tracking-wider border ${
|
||||||
|
tab === id
|
||||||
|
? "border-[var(--nvidia-green)] text-[var(--nvidia-green)] bg-[var(--background-tertiary)]"
|
||||||
|
: "border-[var(--border)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{label} <span className="ml-1 opacity-70">{n ?? 0}</span>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4" data-testid="fleet-task-browser">
|
||||||
|
<div className="panel p-6">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider">
|
||||||
|
Tasks
|
||||||
|
</h1>
|
||||||
|
<p className="mt-1 text-xs text-[var(--foreground-dim)]">
|
||||||
|
Spool-Reifegrad, Dead-Letter und Alarm-Feed — Klick auf eine Zeile zeigt den vollen
|
||||||
|
Task-Envelope (Body unveraendert). Refresh alle 30 s
|
||||||
|
{data ? ` · Stand ${new Date(data.generated_at).toLocaleTimeString()}` : ""}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2" data-testid="task-tabs">
|
||||||
|
{tabBtn("spool", "Spool-Reife", counts?.spool)}
|
||||||
|
{tabBtn("dead-letter", "Dead-Letter", counts?.dead_letter)}
|
||||||
|
{tabBtn("alarm", "Alarm-Feed", counts?.alarm)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{loadError && (
|
||||||
|
<div className="mt-4 border border-[var(--status-stopped)] bg-[var(--background-tertiary)] p-3 text-xs text-[var(--status-stopped)]">
|
||||||
|
Tasks nicht ladbar: {loadError}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{tab === "spool" && (
|
||||||
|
<div className="mt-4 border border-[var(--border)] bg-[var(--background-tertiary)] p-3">
|
||||||
|
<RunbookHint hint={hintByKey("spool")} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{tab === "dead-letter" && (
|
||||||
|
<div className="mt-4 border border-[var(--border)] bg-[var(--background-tertiary)] p-3">
|
||||||
|
<RunbookHint hint={hintByKey("deadletter")} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{data?.degraded && (
|
||||||
|
<div className="mt-4 border border-amber-500 bg-[var(--background-tertiary)] p-3 text-xs text-amber-400">
|
||||||
|
DEGRADED: {data.degraded_reason || "Quelle gestoert"} — Anzeige evtl. unvollstaendig.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{(loadError || data?.degraded) && (
|
||||||
|
<div className="mt-4 border border-[var(--border)] bg-[var(--background-tertiary)] p-3">
|
||||||
|
<RunbookHint hint={hintByKey("health")} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="mt-4 overflow-x-auto">
|
||||||
|
{tab === "alarm" ? (
|
||||||
|
<table className="w-full text-left text-xs" data-testid="task-table-alarm">
|
||||||
|
<thead className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
<tr>
|
||||||
|
<th className="py-2 pr-3">Alter</th>
|
||||||
|
<th className="py-2 pr-3">Event</th>
|
||||||
|
<th className="py-2 pr-3">Ref</th>
|
||||||
|
<th className="py-2 pr-3">Von</th>
|
||||||
|
<th className="py-2 pr-3">An</th>
|
||||||
|
<th className="py-2">Notiz</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="font-mono">
|
||||||
|
{(data?.alarm || []).map((row, i) => (
|
||||||
|
<tr
|
||||||
|
key={`${row.event}-${row.ref}-${i}`}
|
||||||
|
data-tid={row.ref}
|
||||||
|
data-kind="alarm"
|
||||||
|
onClick={() => void openDetail(row.ref, "alarm")}
|
||||||
|
className="cursor-pointer border-t border-[var(--border)] hover:bg-[var(--background-tertiary)]"
|
||||||
|
>
|
||||||
|
<td className={`py-1.5 pr-3 whitespace-nowrap ${ageClass(null)}`}>{row.age_human}</td>
|
||||||
|
<td className="py-1.5 pr-3">{row.event}</td>
|
||||||
|
<td className="py-1.5 pr-3">{row.ref}</td>
|
||||||
|
<td className="py-1.5 pr-3">{row.from}</td>
|
||||||
|
<td className="py-1.5 pr-3">{row.to}</td>
|
||||||
|
<td className="py-1.5 max-w-[28rem] truncate" title={row.note}>
|
||||||
|
{row.note || "-"}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{data && data.alarm.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={6} className="py-4 text-[var(--foreground-dim)]">
|
||||||
|
Keine Stoerungsereignisse in den letzten 24 h.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
) : (
|
||||||
|
<table className="w-full text-left text-xs" data-testid={`task-table-${tab}`}>
|
||||||
|
<thead className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
<tr>
|
||||||
|
<th className="py-2 pr-3">Alter</th>
|
||||||
|
<th className="py-2 pr-3">Task-ID</th>
|
||||||
|
<th className="py-2 pr-3">Von -> An</th>
|
||||||
|
<th className="py-2 pr-3">Typ</th>
|
||||||
|
<th className="py-2 pr-3">Prio</th>
|
||||||
|
<th className="py-2 pr-3">Status</th>
|
||||||
|
<th className="py-2 pr-3">Thema</th>
|
||||||
|
{tab === "dead-letter" && <th className="py-2">Aktion</th>}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="font-mono">
|
||||||
|
{(tab === "spool" ? data?.spool : data?.dead_letter)?.map((t) => (
|
||||||
|
<tr
|
||||||
|
key={t.task_id}
|
||||||
|
data-tid={t.task_id}
|
||||||
|
data-kind={tab}
|
||||||
|
onClick={() => void openDetail(t.task_id, tab)}
|
||||||
|
className="cursor-pointer border-t border-[var(--border)] hover:bg-[var(--background-tertiary)]"
|
||||||
|
>
|
||||||
|
<td className={`py-1.5 pr-3 whitespace-nowrap ${ageClass(t.age_seconds)}`}>
|
||||||
|
{t.age_human}
|
||||||
|
</td>
|
||||||
|
<td className="py-1.5 pr-3 whitespace-nowrap">{t.task_id.slice(0, 8)}</td>
|
||||||
|
<td className="py-1.5 pr-3 whitespace-nowrap">
|
||||||
|
{t.from} -> {t.to}
|
||||||
|
</td>
|
||||||
|
<td className="py-1.5 pr-3">{t.type}</td>
|
||||||
|
<td className={`py-1.5 pr-3 ${prioClass(t.priority)}`}>{t.priority}</td>
|
||||||
|
<td className="py-1.5 pr-3">{t.status_label}</td>
|
||||||
|
<td className="py-1.5 max-w-[26rem] truncate" title={t.topic}>
|
||||||
|
{t.re_dispatch_of !== "-" && t.re_dispatch_of !== "" && (
|
||||||
|
<span
|
||||||
|
className="mr-1 text-[var(--foreground-dim)]"
|
||||||
|
title={`Re-Dispatch von ${t.re_dispatch_of}`}
|
||||||
|
data-testid={`redispatch-of-${t.task_id}`}
|
||||||
|
>
|
||||||
|
↻
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{t.topic}
|
||||||
|
</td>
|
||||||
|
{tab === "dead-letter" && (
|
||||||
|
<td className="py-1.5 whitespace-nowrap" data-testid={`redispatch-${t.task_id}`}>
|
||||||
|
{t.re_dispatched_to !== "-" && t.re_dispatched_to !== "" ? (
|
||||||
|
<span
|
||||||
|
className="text-[var(--foreground-dim)]"
|
||||||
|
title={`Bereits erneut zugestellt an ${t.re_dispatched_to}`}
|
||||||
|
data-testid={`redispatch-already-${t.task_id}`}
|
||||||
|
>
|
||||||
|
↻ zugestellt {t.re_dispatched_to.slice(0, 8)}
|
||||||
|
</span>
|
||||||
|
) : redis[t.task_id] ? (
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
redis[t.task_id].state === "ok"
|
||||||
|
? "text-emerald-400"
|
||||||
|
: redis[t.task_id].state === "already"
|
||||||
|
? "text-[var(--foreground-dim)]"
|
||||||
|
: redis[t.task_id].state === "busy"
|
||||||
|
? "text-[var(--foreground-dim)]"
|
||||||
|
: "text-red-400"
|
||||||
|
}
|
||||||
|
title={redis[t.task_id].msg}
|
||||||
|
>
|
||||||
|
{redis[t.task_id].state === "ok"
|
||||||
|
? "✔ "
|
||||||
|
: redis[t.task_id].state === "already"
|
||||||
|
? "✔ "
|
||||||
|
: redis[t.task_id].state === "busy"
|
||||||
|
? "… "
|
||||||
|
: "✖ "}
|
||||||
|
{redis[t.task_id].msg.slice(0, 42)}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="rounded border border-[var(--border)] px-2 py-0.5 text-[11px] hover:bg-[var(--background-tertiary)]"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
void redispatch(t.task_id)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Erneut zustellen
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{data && ((tab === "spool" ? data.spool : data.dead_letter).length === 0) && (
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
colSpan={tab === "dead-letter" ? 8 : 7}
|
||||||
|
className="py-4 text-[var(--foreground-dim)]"
|
||||||
|
>
|
||||||
|
{tab === "spool"
|
||||||
|
? "Keine offenen Tasks — Spool leer."
|
||||||
|
: "Keine fehlgeschlagenen Tasks in den letzten 7 Tagen."}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{(detail || detailLoading || detailError) && (
|
||||||
|
<div
|
||||||
|
ref={modalRef}
|
||||||
|
className="fixed inset-0 z-50 flex items-start justify-center bg-black/70 p-4 overflow-y-auto"
|
||||||
|
onClick={(e) => {
|
||||||
|
if (e.target === modalRef.current) setDetail(null)
|
||||||
|
}}
|
||||||
|
data-testid="task-detail-modal"
|
||||||
|
>
|
||||||
|
<div className="panel w-full max-w-3xl p-6 my-8">
|
||||||
|
<div className="flex items-start justify-between gap-4">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-sm font-semibold text-[var(--nvidia-green)] uppercase tracking-wider">
|
||||||
|
Task-Detail
|
||||||
|
</h2>
|
||||||
|
<p className="mt-1 text-[11px] text-[var(--foreground-dim)] font-mono">
|
||||||
|
{(detail?.task.task_id as string) || "…"}
|
||||||
|
{detail?.entry_kind ? ` · Quelle: ${detail.entry_kind}` : ""}
|
||||||
|
{detail && !detail.found ? " · kein Envelope gefunden (synthetisches Ereignis)" : ""}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={() => setDetail(null)}
|
||||||
|
className="px-3 py-1 text-xs font-mono border border-[var(--border)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]"
|
||||||
|
data-testid="task-detail-close"
|
||||||
|
>
|
||||||
|
Schliessen (Esc)
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{detailLoading && <p className="mt-4 text-xs text-[var(--foreground-dim)]">Lade Envelope…</p>}
|
||||||
|
{detailError && (
|
||||||
|
<p className="mt-4 text-xs text-[var(--status-stopped)]">Detail nicht ladbar: {detailError}</p>
|
||||||
|
)}
|
||||||
|
{detail?.degraded && (
|
||||||
|
<p className="mt-4 text-xs text-amber-400">
|
||||||
|
DEGRADED: {detail.degraded_reason || "Quelle gestoert"}
|
||||||
|
{detail.error ? ` — ${detail.error}` : ""}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{detail && (
|
||||||
|
<>
|
||||||
|
<dl className="mt-4 grid grid-cols-2 gap-x-4 gap-y-2 text-xs" data-testid="task-detail-grid">
|
||||||
|
{DETAIL_FIELDS.map(([key, label]) => (
|
||||||
|
<div key={key} className="contents">
|
||||||
|
<dt className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
{label}
|
||||||
|
</dt>
|
||||||
|
<dd className="font-mono break-all">{String(detail.task[key] ?? "-")}</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
{detail.missing_fields.length > 0 && (
|
||||||
|
<p className="mt-3 text-[10px] text-[var(--foreground-dim)]">
|
||||||
|
Fehlende Felder: {detail.missing_fields.join(", ")}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<div className="mt-4">
|
||||||
|
<p className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">
|
||||||
|
Body (unveraendert aus dem Spool)
|
||||||
|
</p>
|
||||||
|
<pre
|
||||||
|
className="mt-1 max-h-72 overflow-auto whitespace-pre-wrap break-words border border-[var(--border)] bg-[var(--background-tertiary)] p-3 text-[11px] font-mono"
|
||||||
|
data-testid="task-detail-body"
|
||||||
|
>
|
||||||
|
{String(detail.task.body ?? "-")}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
{detail.raw_keys.length > 0 && (
|
||||||
|
<p className="mt-3 text-[10px] text-[var(--foreground-dim)]">
|
||||||
|
Envelope-Keys: {detail.raw_keys.join(", ")}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{Object.keys(detail.task).length === 0 && (
|
||||||
|
<p className="mt-3 text-xs text-[var(--foreground-dim)]">Keine Daten.</p>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { uptimeSeconds, TOWER_VERSION } from "@/app/lib/fleet/health"
|
||||||
|
import { FLEET_SPOOL_DIR, FLEET_ORG_PATH, loadOrg } from "@/app/lib/fleet/fleetSource"
|
||||||
|
import { existsSync } from "node:fs"
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /healthz — Readiness/Liveness des Tower-Service (Karte it1-tower-03).
|
||||||
|
* 200 = Kernquellen (Spool-PVC, org.yaml) verfuegbar; 503 = eine Kernquelle tot.
|
||||||
|
* JSON statt HTML, damit Uptime-Monitoring den Grund maschinell lesen kann.
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
const problems: string[] = []
|
||||||
|
|
||||||
|
const spoolOk = existsSync(FLEET_SPOOL_DIR)
|
||||||
|
if (!spoolOk) problems.push(`spool fehlt: ${FLEET_SPOOL_DIR}`)
|
||||||
|
|
||||||
|
if (!existsSync(FLEET_ORG_PATH)) {
|
||||||
|
problems.push(`org.yaml fehlt: ${FLEET_ORG_PATH}`)
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if (loadOrg().members.length === 0) problems.push("org.yaml ohne members")
|
||||||
|
} catch (e) {
|
||||||
|
problems.push(`org.yaml unlesbar: ${e instanceof Error ? e.message : String(e)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ok = problems.length === 0
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
status: ok ? "ok" : "unhealthy",
|
||||||
|
version: TOWER_VERSION,
|
||||||
|
uptime_seconds: uptimeSeconds(),
|
||||||
|
generated_at: new Date().toISOString(),
|
||||||
|
problems,
|
||||||
|
},
|
||||||
|
{ status: ok ? 200 : 503, headers: { "Cache-Control": "no-store" } }
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -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:
|
||||||
|
* - <vs>/ideen-register.md Markdown-Tabelle | karte_id | titel | score | status | ursprung | epoch |
|
||||||
|
* - <vs>/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 }
|
||||||
|
}
|
||||||
@@ -0,0 +1,422 @@
|
|||||||
|
/**
|
||||||
|
* fleet/fleetSource.ts — zentrale Datenquellen-Adapter für Fleet-Views (Design-Doc §2).
|
||||||
|
*
|
||||||
|
* Server-seitig (Next-API-Routen), KEIN Browser-Zugriff auf Cluster-Ressourcen.
|
||||||
|
* Fail-loud: Quelle tot -> Exception -> 500 mit Klartext statt leeres UI (§5.5).
|
||||||
|
*
|
||||||
|
* Datenquellen:
|
||||||
|
* - org.yaml + bifrost-vks.yaml: CM-Mount (read-only)
|
||||||
|
* - Token je Agent: Prometheus /api/v1/query (bifrost_*_tokens_total, 2m-Rate)
|
||||||
|
* - Heartbeat: Beacon /metrics
|
||||||
|
* - Spool-Journal + Inbox: CephFS-RO-Mount (fleet-spool-PVC)
|
||||||
|
* - Sandbox-Status: provisioning-MCP get_sandbox_status
|
||||||
|
* - Board/Kanban + Owner-Submit: board-service-MCP
|
||||||
|
*/
|
||||||
|
import { readFileSync, existsSync, readdirSync } from "node:fs"
|
||||||
|
import path from "node:path"
|
||||||
|
import { parse as parseYaml } from "yaml"
|
||||||
|
|
||||||
|
export const FLEET_ORG_PATH = process.env.FLEET_ORG_YAML_PATH || "/etc/fleet/org.yaml"
|
||||||
|
export const FLEET_VKS_PATH = process.env.FLEET_VKS_YAML_PATH || "/etc/fleet/bifrost-vks.yaml"
|
||||||
|
export const FLEET_SPOOL_DIR = process.env.FLEET_SPOOL_DIR || "/srv/fleet/tasks"
|
||||||
|
export const FLEET_PROM_URL = (process.env.FLEET_PROM_URL || "http://10.0.30.202:9090").replace(/\/$/, "")
|
||||||
|
export const FLEET_BEACON_URL = (process.env.FLEET_BEACON_URL || "http://fleet-beacon.fleet.svc:8000").replace(/\/$/, "")
|
||||||
|
export const FLEET_BOARD_MCP_URL =
|
||||||
|
process.env.FLEET_BOARD_MCP_URL || "http://fleet-board-service.fleet.svc:8080/mcp"
|
||||||
|
export const FLEET_PROVISIONING_MCP_URL =
|
||||||
|
process.env.FLEET_PROVISIONING_MCP_URL || "http://fleet-provisioning.fleet.svc:8080/mcp"
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- org.yaml
|
||||||
|
|
||||||
|
export type OrgMember = {
|
||||||
|
agent_id: string
|
||||||
|
role: string
|
||||||
|
al: number
|
||||||
|
parent: string | null
|
||||||
|
wave: number
|
||||||
|
function: string
|
||||||
|
title?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OrgDoc = { members: OrgMember[] }
|
||||||
|
|
||||||
|
function readYamlDoc(p: string): Record<string, unknown> {
|
||||||
|
if (!existsSync(p)) {
|
||||||
|
throw new Error(`FLEET-Datenquelle fehlt: ${p} (CM gemountet?)`)
|
||||||
|
}
|
||||||
|
const doc = parseYaml(readFileSync(p, "utf8"))
|
||||||
|
if (!doc || typeof doc !== "object") {
|
||||||
|
throw new Error(`FLEET-Datenquelle unparsebar: ${p}`)
|
||||||
|
}
|
||||||
|
return doc as Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
/** org.yaml lesen (fail loud, kein Cache — Datei ist klein und statisch je Deploy). */
|
||||||
|
export function loadOrg(): OrgDoc {
|
||||||
|
const spec = readYamlDoc(FLEET_ORG_PATH).spec as { members?: OrgMember[] } | undefined
|
||||||
|
const members = spec?.members
|
||||||
|
if (!Array.isArray(members) || members.length === 0) {
|
||||||
|
throw new Error(`org.yaml enthaelt keine spec.members (${FLEET_ORG_PATH})`)
|
||||||
|
}
|
||||||
|
for (const m of members) {
|
||||||
|
if (!m.agent_id) throw new Error(`org.yaml Member ohne agent_id (${FLEET_ORG_PATH})`)
|
||||||
|
}
|
||||||
|
return { members }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------ bifrost-vks
|
||||||
|
|
||||||
|
export type VkMapping = { agent_id: string; vk_name: string; model: string; profile: string }
|
||||||
|
|
||||||
|
/** VK<->Agent-Mapping aus bifrost-vks.yaml. */
|
||||||
|
export function loadVkMapping(): VkMapping[] {
|
||||||
|
const spec = readYamlDoc(FLEET_VKS_PATH).spec as { members?: VkMapping[] } | undefined
|
||||||
|
const members = spec?.members
|
||||||
|
if (!Array.isArray(members) || members.length === 0) {
|
||||||
|
throw new Error(`bifrost-vks.yaml enthaelt keine spec.members (${FLEET_VKS_PATH})`)
|
||||||
|
}
|
||||||
|
return members
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ utils
|
||||||
|
|
||||||
|
const globalCache = new Map<string, { value: unknown; expires: number }>()
|
||||||
|
|
||||||
|
/** Kleiner TTL-Cache (Server-seite; Views pollen 5 s — Prom/Beacon-TTL 2 s). */
|
||||||
|
export function cached<T>(key: string, ttlMs: number, fn: () => T): T {
|
||||||
|
const hit = globalCache.get(key) as { value: T; expires: number } | undefined
|
||||||
|
if (hit && hit.expires > Date.now()) return hit.value
|
||||||
|
const value = fn()
|
||||||
|
globalCache.set(key, { value, expires: Date.now() + ttlMs })
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchText(url: string, timeoutMs = 8000): Promise<string> {
|
||||||
|
const ctrl = new AbortController()
|
||||||
|
const timer = setTimeout(() => ctrl.abort(), timeoutMs)
|
||||||
|
try {
|
||||||
|
const res = await fetch(url, { signal: ctrl.signal, cache: "no-store" })
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`HTTP ${res.status} von ${url}`)
|
||||||
|
}
|
||||||
|
return await res.text()
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------- Prometheus tok/s
|
||||||
|
|
||||||
|
export type TokenRates = Record<string, { in: number; out: number }>
|
||||||
|
|
||||||
|
/** tok/s je VK (2-Minuten-Rate) aus Prometheus.
|
||||||
|
*
|
||||||
|
* AGGREGATION IST PFLICHT: `rate()` liefert eine Serie je Label-Kombination
|
||||||
|
* (method, model, provider, fallback_index, ...). Ein simples
|
||||||
|
* `out[vk].in = v` ueberschreibt die echte Rate mit der letzten Serie — und das
|
||||||
|
* ist fast immer eine 0. Folge: Org-Chart zeigt 0 tok/s, obwohl Bifrost
|
||||||
|
* Millionen Tokens zaehlt (Befund 29.10.2026: devops-v2 8,5 Mio in 30 min,
|
||||||
|
* Tower 0). Deshalb `sum by (virtual_key_name)` in der Query UND additive
|
||||||
|
* Auswertung im Code (doppelte Absicherung).
|
||||||
|
*/
|
||||||
|
export async function loadTokenRates(): Promise<TokenRates> {
|
||||||
|
const query = (metric: string) =>
|
||||||
|
`${FLEET_PROM_URL}/api/v1/query?query=${encodeURIComponent(`sum by (virtual_key_name) (rate(${metric}[2m]))`)}`
|
||||||
|
const [inBody, outBody] = await Promise.all([
|
||||||
|
fetchText(query("bifrost_input_tokens_total")),
|
||||||
|
fetchText(query("bifrost_output_tokens_total")),
|
||||||
|
])
|
||||||
|
const pick = (body: string): Array<{ vk: string; v: number }> => {
|
||||||
|
const parsed = JSON.parse(body)
|
||||||
|
if (parsed.status !== "success") {
|
||||||
|
throw new Error(`Prometheus-Query nicht success: ${parsed.status || body.slice(0, 120)}`)
|
||||||
|
}
|
||||||
|
return (parsed.data?.result || []).map((r: { metric: Record<string, string>; value: [number, string] }) => ({
|
||||||
|
vk: String(r.metric.virtual_key_name || ""),
|
||||||
|
v: Number(r.value[1]) || 0,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
const out: TokenRates = {}
|
||||||
|
for (const { vk, v } of pick(inBody)) {
|
||||||
|
if (vk) (out[vk] = out[vk] || { in: 0, out: 0 }).in += v
|
||||||
|
}
|
||||||
|
for (const { vk, v } of pick(outBody)) {
|
||||||
|
if (vk) (out[vk] = out[vk] || { in: 0, out: 0 }).out += v
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------ Beacon /metrics
|
||||||
|
|
||||||
|
export type HeartbeatAges = Record<string, number>
|
||||||
|
|
||||||
|
/** Heartbeat-Alter je Agent aus Beacon /metrics. */
|
||||||
|
export async function loadHeartbeatAges(): Promise<HeartbeatAges> {
|
||||||
|
const body = await fetchText(`${FLEET_BEACON_URL}/metrics`)
|
||||||
|
const out: HeartbeatAges = {}
|
||||||
|
for (const line of body.split("\n")) {
|
||||||
|
const m = line.match(/^beacon_last_heartbeat_age_seconds\{agent="([^"]+)"\}\s+([0-9.e+-]+)$/)
|
||||||
|
if (m) out[m[1]] = Number(m[2])
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- Spool-Journal
|
||||||
|
|
||||||
|
export type JournalLine = {
|
||||||
|
time_epoch?: number
|
||||||
|
event?: string
|
||||||
|
task_id?: string
|
||||||
|
from?: string
|
||||||
|
to?: string
|
||||||
|
type?: string
|
||||||
|
priority?: string
|
||||||
|
status?: string
|
||||||
|
file?: string
|
||||||
|
[k: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spool-Journal-Tail (letzte N JSON-Lines aus _journal/journal.logl).
|
||||||
|
* Fail loud wenn Journal fehlt — es MUSS existieren (Spool-PVC ro gemountet).
|
||||||
|
*/
|
||||||
|
export function readJournalTail(limit = 200): JournalLine[] {
|
||||||
|
const jpath = path.join(FLEET_SPOOL_DIR, "_journal", "journal.logl")
|
||||||
|
if (!existsSync(jpath)) {
|
||||||
|
throw new Error(`Spool-Journal fehlt: ${jpath} (fleet-spool-PVC ro gemountet?)`)
|
||||||
|
}
|
||||||
|
const raw = readFileSync(jpath, "utf8").trim()
|
||||||
|
if (!raw) return []
|
||||||
|
const lines = raw.split("\n")
|
||||||
|
const tail = lines.slice(-limit)
|
||||||
|
const out: JournalLine[] = []
|
||||||
|
for (const line of tail) {
|
||||||
|
try {
|
||||||
|
out.push(JSON.parse(line) as JournalLine)
|
||||||
|
} catch {
|
||||||
|
// Journal ist append-only; eine kaputte Zeile wirft NICHT das ganze UI um,
|
||||||
|
// wird aber sichtbar markiert statt verschluckt (fail-loud-lesend).
|
||||||
|
out.push({ event: "journal_parse_error", raw: line.slice(0, 200) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Inbox-Groesse je to-Agent: anzahl *unbearbeiteter* Task-Dateien im Spool-Root. */
|
||||||
|
export function countInbox(): Record<string, number> {
|
||||||
|
const out: Record<string, number> = {}
|
||||||
|
if (!existsSync(FLEET_SPOOL_DIR)) {
|
||||||
|
throw new Error(`Spool-Dir fehlt: ${FLEET_SPOOL_DIR} (fleet-spool-PVC ro gemountet?)`)
|
||||||
|
}
|
||||||
|
for (const f of readdirSync(FLEET_SPOOL_DIR)) {
|
||||||
|
if (!f.endsWith(".yaml")) continue
|
||||||
|
try {
|
||||||
|
const doc = parseYaml(readFileSync(path.join(FLEET_SPOOL_DIR, f), "utf8")) as { to?: string; status?: string }
|
||||||
|
if (!doc?.to) continue
|
||||||
|
if (doc.status && doc.status !== "submitted" && doc.status !== "running") continue
|
||||||
|
out[doc.to] = (out[doc.to] || 0) + 1
|
||||||
|
} catch {
|
||||||
|
// unparsebare Task-Datei: zaehlt unter _invalid-artefakt, ignoriert hier nicht
|
||||||
|
// grob — wird im Journal als rejected sichtbar sein.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Chat-Threads: Task-Dateien mit type=chat gruppiert nach thread_id. */
|
||||||
|
export type ChatThread = {
|
||||||
|
thread_id: string
|
||||||
|
topic: string
|
||||||
|
messages: Array<{ task_id: string; from: string; to: string; body: string; created: number }>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function readChatThreads(): ChatThread[] {
|
||||||
|
if (!existsSync(FLEET_SPOOL_DIR)) {
|
||||||
|
throw new Error(`Spool-Dir fehlt: ${FLEET_SPOOL_DIR}`)
|
||||||
|
}
|
||||||
|
const threads = new Map<string, ChatThread>()
|
||||||
|
for (const f of readdirSync(FLEET_SPOOL_DIR)) {
|
||||||
|
if (!f.endsWith(".yaml")) continue
|
||||||
|
try {
|
||||||
|
const doc = parseYaml(readFileSync(path.join(FLEET_SPOOL_DIR, f), "utf8")) as {
|
||||||
|
task_id?: string
|
||||||
|
from?: string
|
||||||
|
to?: string
|
||||||
|
type?: string
|
||||||
|
thread_id?: string
|
||||||
|
topic?: string
|
||||||
|
body?: string
|
||||||
|
created?: number
|
||||||
|
}
|
||||||
|
if (doc?.type !== "chat" || !doc.thread_id) continue
|
||||||
|
const t = threads.get(doc.thread_id) || { thread_id: doc.thread_id, topic: doc.topic || "", messages: [] }
|
||||||
|
t.messages.push({
|
||||||
|
task_id: String(doc.task_id || f),
|
||||||
|
from: String(doc.from || ""),
|
||||||
|
to: String(doc.to || ""),
|
||||||
|
body: String(doc.body || ""),
|
||||||
|
created: Number(doc.created || 0),
|
||||||
|
})
|
||||||
|
threads.set(doc.thread_id, t)
|
||||||
|
} catch {
|
||||||
|
// kaputte Datei: skip (im Journal sichtbar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const list = [...threads.values()]
|
||||||
|
for (const t of list) t.messages.sort((a, b) => a.created - b.created)
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------ kube-state-metrics
|
||||||
|
|
||||||
|
export type SandboxFact = {
|
||||||
|
agent_id: string
|
||||||
|
phase: string
|
||||||
|
ready: boolean
|
||||||
|
restarts: number
|
||||||
|
pod_age_s: number
|
||||||
|
node: string
|
||||||
|
cpu_request_milli: number
|
||||||
|
mem_request_mb: number
|
||||||
|
image_digest: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
function parsePromQuery(body: string): Array<{ metric: Record<string, string>; value: [number, string] }> {
|
||||||
|
const parsed = JSON.parse(body)
|
||||||
|
if (parsed.status !== "success") {
|
||||||
|
throw new Error(`Prometheus-Query nicht success: ${parsed.status || String(body).slice(0, 120)}`)
|
||||||
|
}
|
||||||
|
return (parsed.data?.result || []) as Array<{ metric: Record<string, string>; value: [number, string] }>
|
||||||
|
}
|
||||||
|
|
||||||
|
async function promQueryRaw(promql: string): Promise<Array<{ metric: Record<string, string>; value: [number, string] }>> {
|
||||||
|
const body = await fetchText(`${FLEET_PROM_URL}/api/v1/query?query=${encodeURIComponent(promql)}`)
|
||||||
|
return parsePromQuery(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sandbox-Pod-Facts je Agent aus kube-state-metrics (read-only PromQL).
|
||||||
|
* Pods heissen default--<agent_id> in NS openshell (K8s-Driver-Konvention).
|
||||||
|
* Fail-loud: Prometheus tot -> Exception (kein leeres UI).
|
||||||
|
*/
|
||||||
|
export async function loadSandboxFacts(): Promise<{
|
||||||
|
sandboxes: SandboxFact[]
|
||||||
|
fleet_image_digest: string | null
|
||||||
|
}> {
|
||||||
|
const agentIds = loadOrg().members.map((m) => m.agent_id)
|
||||||
|
const podSel = agentIds.map((a) => `default--${a}`).join("|")
|
||||||
|
const ns = "openshell"
|
||||||
|
const [phaseRes, readyRes, restartRes, startRes, infoRes, reqRes, imgRes] = await Promise.all([
|
||||||
|
promQueryRaw(`kube_pod_status_phase{namespace="${ns}",pod=~"${podSel}"}`),
|
||||||
|
promQueryRaw(`kube_pod_container_status_ready{namespace="${ns}",pod=~"${podSel}",container="agent"}`),
|
||||||
|
promQueryRaw(`kube_pod_container_status_restarts_total{namespace="${ns}",pod=~"${podSel}",container="agent"}`),
|
||||||
|
promQueryRaw(`kube_pod_start_time{namespace="${ns}",pod=~"${podSel}"}`),
|
||||||
|
promQueryRaw(`kube_pod_info{namespace="${ns}",pod=~"${podSel}"}`),
|
||||||
|
promQueryRaw(`kube_pod_container_resource_requests{namespace="${ns}",pod=~"${podSel}",container="agent"}`),
|
||||||
|
promQueryRaw(`kube_pod_container_info{namespace="${ns}",pod=~"${podSel}",container="agent"}`),
|
||||||
|
])
|
||||||
|
const agentOf = (pod: string | undefined): string | null => {
|
||||||
|
if (!pod) return null
|
||||||
|
const m = pod.match(/^default--(.+)$/)
|
||||||
|
return m ? m[1] : null
|
||||||
|
}
|
||||||
|
const now = Date.now() / 1000
|
||||||
|
// kube_pod_status_phase liefert EINE Zeile je Phase je Pod -> je Pod einmal
|
||||||
|
const pods = [...new Set(phaseRes.map((r) => r.metric.pod).filter(Boolean))] as string[]
|
||||||
|
const out: SandboxFact[] = []
|
||||||
|
for (const pod of pods) {
|
||||||
|
const agent = agentOf(pod)
|
||||||
|
if (!agent) continue
|
||||||
|
const phase =
|
||||||
|
phaseRes.find((x) => x.metric.pod === pod && Number(x.value[1]) === 1)?.metric.phase ||
|
||||||
|
phaseRes.find((x) => x.metric.pod === pod)?.metric.phase ||
|
||||||
|
"Unknown"
|
||||||
|
const readyRow = readyRes.find((x) => x.metric.pod === pod && Number(x.value[1]) === 1)
|
||||||
|
const restartRow = restartRes.find((x) => x.metric.pod === pod)
|
||||||
|
const startRow = startRes.find((x) => x.metric.pod === pod)
|
||||||
|
const infoRow = infoRes.find((x) => x.metric.pod === pod)
|
||||||
|
const cpuRow = reqRes.find((x) => x.metric.pod === pod && x.metric.resource === "cpu")
|
||||||
|
const memRow = reqRes.find((x) => x.metric.pod === pod && x.metric.resource === "memory")
|
||||||
|
const imgRow = imgRes.find((x) => x.metric.pod === pod)
|
||||||
|
out.push({
|
||||||
|
agent_id: agent,
|
||||||
|
phase,
|
||||||
|
ready: Boolean(readyRow),
|
||||||
|
restarts: restartRow ? Math.round(Number(restartRow.value[1])) : 0,
|
||||||
|
pod_age_s: startRow ? Math.max(0, Math.round(now - Number(startRow.value[1]))) : 0,
|
||||||
|
node: infoRow?.metric.node || "?",
|
||||||
|
cpu_request_milli: cpuRow ? Math.round(Number(cpuRow.value[1]) * 1000) : 0,
|
||||||
|
mem_request_mb: memRow ? Math.round(Number(memRow.value[1]) / (1024 * 1024)) : 0,
|
||||||
|
image_digest: imgRow?.metric.image_id?.match(/sha256:[a-f0-9]+/)?.[0] || null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const fleetRow = imgRes.find((x) => x.metric.pod?.startsWith("default--"))
|
||||||
|
return { sandboxes: out, fleet_image_digest: fleetRow?.metric.image_id?.match(/sha256:[a-f0-9]+/)?.[0] || null }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------- MCP-Client
|
||||||
|
|
||||||
|
export type McpCallResult = { ok: boolean; data?: unknown; error?: string }
|
||||||
|
|
||||||
|
type McpResponsePayload = {
|
||||||
|
result?: { content?: Array<{ type: string; text?: string }> }
|
||||||
|
error?: { message?: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Streamable-HTTP-MCP-Call gegen eine Fleet-Facility (mcp 2.3.0, stateless). */
|
||||||
|
export async function mcpCallTool(serverUrl: string, tool: string, args: Record<string, unknown> = {}, timeoutMs = 20000): Promise<McpCallResult> {
|
||||||
|
const ctrl = new AbortController()
|
||||||
|
const timer = setTimeout(() => ctrl.abort(), timeoutMs)
|
||||||
|
try {
|
||||||
|
const headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json, text/event-stream",
|
||||||
|
}
|
||||||
|
// 1) initialize (stateless_http) — noetig bevor tools/call
|
||||||
|
const initRes = await fetch(serverUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify({
|
||||||
|
jsonrpc: "2.0",
|
||||||
|
id: 1,
|
||||||
|
method: "initialize",
|
||||||
|
params: {
|
||||||
|
protocolVersion: "2025-06-18",
|
||||||
|
capabilities: {},
|
||||||
|
clientInfo: { name: "fleet-tower", version: "0.13" },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
signal: ctrl.signal,
|
||||||
|
cache: "no-store",
|
||||||
|
})
|
||||||
|
if (!initRes.ok) throw new Error(`MCP initialize HTTP ${initRes.status} von ${serverUrl}`)
|
||||||
|
// 2) tools/call
|
||||||
|
const callRes = await fetch(serverUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify({ jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: tool, arguments: args } }),
|
||||||
|
signal: ctrl.signal,
|
||||||
|
cache: "no-store",
|
||||||
|
})
|
||||||
|
if (!callRes.ok) throw new Error(`MCP tools/call HTTP ${callRes.status} von ${serverUrl}`)
|
||||||
|
const text = await callRes.text()
|
||||||
|
// Antwort kann JSON oder SSE sein — letzte data:-Zeile ist das Result.
|
||||||
|
let payload: unknown
|
||||||
|
const ct = callRes.headers.get("content-type") || ""
|
||||||
|
if (ct.includes("text/event-stream")) {
|
||||||
|
const dataLines = text.split("\n").filter((l) => l.startsWith("data:"))
|
||||||
|
if (dataLines.length === 0) throw new Error(`MCP-Antwort ohne data:-Zeile von ${serverUrl}`)
|
||||||
|
payload = JSON.parse(dataLines[dataLines.length - 1].slice(5).trim())
|
||||||
|
} else {
|
||||||
|
payload = JSON.parse(text)
|
||||||
|
}
|
||||||
|
const obj = payload as McpResponsePayload
|
||||||
|
if (obj?.error) return { ok: false, error: String(obj.error.message || JSON.stringify(obj.error)) }
|
||||||
|
const textContent = obj?.result?.content?.find((c) => c.type === "text")?.text
|
||||||
|
return { ok: true, data: textContent ? JSON.parse(textContent) : obj?.result }
|
||||||
|
} catch (err) {
|
||||||
|
return { ok: false, error: err instanceof Error ? err.message : String(err) }
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timer)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Betriebsreife-Endpunkte für den Tower (Karte it1-tower-03-healthz-status).
|
||||||
|
*
|
||||||
|
* /healthz — Liveness/Readiness für Uptime-Monitoring (HTTP 200 = Kern ok,
|
||||||
|
* 503 = eine Kernquelle tot). JSON, nie HTML.
|
||||||
|
* /api/status — maschinenlesbares JSON: Version, Uptime, Zustand der
|
||||||
|
* Datenquellen (Spool-PVC, org.yaml, Prometheus, Beacon) mit
|
||||||
|
* Latenz und Klartext-Fehler.
|
||||||
|
*
|
||||||
|
* Beide Endpunkte sind fail-loud-lesend: eine tote Quelle macht den Endpunkt
|
||||||
|
* NICHT 500, sondern sichtbar degraded (Uptime-Monitoring braucht eine Antwort).
|
||||||
|
*/
|
||||||
|
export const TOWER_VERSION = process.env.FLEET_TOWER_VERSION || "0.20"
|
||||||
|
export const TOWER_STARTED_AT_MS = Date.now()
|
||||||
|
|
||||||
|
export type SourceState = {
|
||||||
|
ok: boolean
|
||||||
|
latency_ms: number
|
||||||
|
error: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function uptimeSeconds(): number {
|
||||||
|
return Math.round((Date.now() - TOWER_STARTED_AT_MS) / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Quelle mit Timeout prüfen; wirft nie. */
|
||||||
|
export async function probe(url: string, timeoutMs = 3000): Promise<SourceState> {
|
||||||
|
const t0 = Date.now()
|
||||||
|
const ctrl = new AbortController()
|
||||||
|
const timer = setTimeout(() => ctrl.abort(), timeoutMs)
|
||||||
|
try {
|
||||||
|
const res = await fetch(url, { signal: ctrl.signal, cache: "no-store" })
|
||||||
|
return {
|
||||||
|
ok: res.ok,
|
||||||
|
latency_ms: Date.now() - t0,
|
||||||
|
error: res.ok ? "" : `HTTP ${res.status}`,
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
latency_ms: Date.now() - t0,
|
||||||
|
error: e instanceof Error ? e.message : String(e),
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timer)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
/**
|
||||||
|
* runbookHints.ts — 1:1-Portierung von /sandbox/fleet-change-orders/
|
||||||
|
* tower-notfall-runbook/runbook_hints.py (Karte tower-notfall-runbook, devops).
|
||||||
|
*
|
||||||
|
* Zweck: Kurzschritte + Eskalationskontakt fuer den Owner direkt an den
|
||||||
|
* Alarm-Ampeln des Towers (10.0.30.213, tcp/8099) als kontextueller
|
||||||
|
* Inline-Hint mit Deep-Link auf das Notfall-Runbook (/runbook#<anker>).
|
||||||
|
*
|
||||||
|
* Rein statisch — KEINE Datenquelle, KEIN Polling, KEIN Egress, KEINE
|
||||||
|
* Secrets. LAMP_HINTS + buildView() + renderHintHtml() entsprechen
|
||||||
|
* LAMP_HINTS + build_view() + render_hint_html() der Referenz 1:1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const RUNBOOK_URL = "/runbook"
|
||||||
|
|
||||||
|
export type LampHint = {
|
||||||
|
key: "deadman" | "spool" | "health" | "deadletter"
|
||||||
|
component: string
|
||||||
|
badge_id: string | null
|
||||||
|
anchor: string
|
||||||
|
scenario: string
|
||||||
|
title: string
|
||||||
|
core: boolean
|
||||||
|
kurzschritte: string[]
|
||||||
|
eskalation: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reihenfolge = Anzeige-Reihenfolge im Tower-Header/Panel.
|
||||||
|
// core=true -> Pflicht-Ampel laut Karte (Deadman-Blockade, Spool-Stau, Panel-Ausfall).
|
||||||
|
export const LAMP_HINTS: LampHint[] = [
|
||||||
|
{
|
||||||
|
key: "deadman",
|
||||||
|
component: "Deadman-Status",
|
||||||
|
badge_id: "dm-badge",
|
||||||
|
anchor: "#deadman",
|
||||||
|
scenario: "A",
|
||||||
|
title: "Deadman-Blockade",
|
||||||
|
core: true,
|
||||||
|
kurzschritte: [
|
||||||
|
"Owner-Queue oeffnen: blockierenden Task (ID, Typ, Alter) an der Deadman-Ampel ablesen.",
|
||||||
|
"Task in der Queue entscheiden (Abnahme/Review/NAR) oder mit reply_to + Kommentar zurueckgeben.",
|
||||||
|
"Deadman-Ampel auf 'progress' pruefen (Auto-Refresh 30 s).",
|
||||||
|
],
|
||||||
|
eskalation:
|
||||||
|
"Bleibt 'blocked' > 5400 s oder ist der Task unklar: Owner ueber die Owner-Queue informieren (Grund + Task-ID nennen).",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "spool",
|
||||||
|
component: "Spool-Aging (Reife)",
|
||||||
|
badge_id: "sp-badge",
|
||||||
|
anchor: "#spool",
|
||||||
|
scenario: "B",
|
||||||
|
title: "Spool-Stau",
|
||||||
|
core: true,
|
||||||
|
kurzschritte: [
|
||||||
|
"Spool-Aging: aeltesten roten Envelope (> 5400 s) + Empfaenger ablesen.",
|
||||||
|
"Empfaenger gruen: Task an denselben Empfaenger erneut submitten (reply_to setzen).",
|
||||||
|
"Empfaenger rot: zuerst Szenario A/C loesen; Failed-Tasks ueber die Dead-Letter-Ansicht (#deadletter) pruefen.",
|
||||||
|
],
|
||||||
|
eskalation:
|
||||||
|
"Envelope > 5400 s ohne roten Empfaenger (Ursache unklar): an tower-owner ueber den CISO-Kanal melden (Envelope-IDs); ab 2 betroffenen Agents zusaetzlich Owner informieren.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "health",
|
||||||
|
component: "Health-Ampel / Panel",
|
||||||
|
badge_id: null,
|
||||||
|
anchor: "#health",
|
||||||
|
scenario: "C",
|
||||||
|
title: "Panel-Ausfall",
|
||||||
|
core: true,
|
||||||
|
kurzschritte: [
|
||||||
|
"/healthz pruefen: 200 = Server lebt, Problem liegt bei Datenquelle/UI.",
|
||||||
|
"/api/status + Degraded-Banner: Quelle down = Degraded (60 s-Cache laeuft weiter), KEIN Totalausfall.",
|
||||||
|
"Kein 200 / Verbindung abgelehnt = Totalausfall: Neustart/Deploy nur ueber Aenderungsauftrag, nicht selbst am Host.",
|
||||||
|
],
|
||||||
|
eskalation:
|
||||||
|
"healthz-Ausfall oder Deploy-Bedarf: sofort P1 an tower-owner ueber den CISO-Kanal; parallel Owner informieren (ohne Panel ist die Lage nur ueber die Agenten-Boards sichtbar).",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "deadletter",
|
||||||
|
component: "Dead-Letter-Ansicht",
|
||||||
|
badge_id: null,
|
||||||
|
anchor: "#deadletter",
|
||||||
|
scenario: "B3",
|
||||||
|
title: "Verlorene Tasks",
|
||||||
|
core: false,
|
||||||
|
kurzschritte: [
|
||||||
|
"Dead-Letter: failed-Tasks (7 Tage) mit from->to + Alter pruefen.",
|
||||||
|
"Wiederholbar: erneut submitten (reply_to); unloesbar: Task mit Grund neu aufsetzen, nicht still verwerfen.",
|
||||||
|
],
|
||||||
|
eskalation:
|
||||||
|
"Gehaeufte Failed-Tasks eines Empfaengers: Empfaenger-Health pruefen (#health), dann wie Szenario B eskalieren.",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
/** Hint per key (statisch, wirft bei unbekanntem key). */
|
||||||
|
export function hintByKey(key: LampHint["key"]): LampHint {
|
||||||
|
const h = LAMP_HINTS.find((x) => x.key === key)
|
||||||
|
if (!h) throw new Error(`unknown runbook hint: ${key}`)
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
|
export type HintView = {
|
||||||
|
key: string
|
||||||
|
component: string
|
||||||
|
badge_id: string | null
|
||||||
|
scenario: string
|
||||||
|
title: string
|
||||||
|
core: boolean
|
||||||
|
anchor: string
|
||||||
|
url: string
|
||||||
|
kurzschritte: string[]
|
||||||
|
eskalation: string
|
||||||
|
html: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Statische Hint-Ansicht (JSON-faehig) — entspricht build_view(). */
|
||||||
|
export function buildView(now: string | null = null, source = "static") {
|
||||||
|
const hints: HintView[] = LAMP_HINTS.map((h) => ({
|
||||||
|
key: h.key,
|
||||||
|
component: h.component,
|
||||||
|
badge_id: h.badge_id,
|
||||||
|
scenario: h.scenario,
|
||||||
|
title: h.title,
|
||||||
|
core: h.core,
|
||||||
|
anchor: h.anchor,
|
||||||
|
url: RUNBOOK_URL + h.anchor,
|
||||||
|
kurzschritte: [...h.kurzschritte],
|
||||||
|
eskalation: h.eskalation,
|
||||||
|
html: renderHintHtml(h),
|
||||||
|
}))
|
||||||
|
return {
|
||||||
|
generated_at: now,
|
||||||
|
source,
|
||||||
|
runbook_url: RUNBOOK_URL,
|
||||||
|
refresh_seconds: 0, // statisch
|
||||||
|
hint_count: hints.length,
|
||||||
|
core_count: hints.filter((h) => h.core).length,
|
||||||
|
hints,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(s: string): string {
|
||||||
|
return s
|
||||||
|
.replace(/&/g, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Kompakter Inline-Hint als HTML-String (rein Text + interner Link). */
|
||||||
|
export function renderHintHtml(h: LampHint): string {
|
||||||
|
const esc = escapeHtml
|
||||||
|
const stepLis = h.kurzschritte.map((s) => `<li>${esc(s)}</li>`).join("")
|
||||||
|
return `<div id="hint-${esc(h.key)}" class="lamp-hint" data-component="${esc(h.component)}">` +
|
||||||
|
`<span class="lh-title">Notfall ${esc(h.scenario)} — ${esc(h.title)}</span>` +
|
||||||
|
`<ol class="lh-steps">${stepLis}</ol>` +
|
||||||
|
`<div class="lh-esc"><strong>Eskalation:</strong> ${esc(h.eskalation)}</div>` +
|
||||||
|
`<a class="lh-link" href="${esc(RUNBOOK_URL + h.anchor)}">Vollstaendiges Runbook →</a>` +
|
||||||
|
`</div>`
|
||||||
|
}
|
||||||
@@ -0,0 +1,334 @@
|
|||||||
|
/**
|
||||||
|
* fleet/taskSource.ts — Task-Envelope-Leser für die Task-Detail-Ansicht.
|
||||||
|
*
|
||||||
|
* Karte tower-task-detail (Change-Order 2026-10-30 aus devops-Sandbox,
|
||||||
|
* /sandbox/fleet-change-orders/tower-task-detail/): Klick auf einen Eintrag der
|
||||||
|
* Listen Spool-Reifegrad / Alarm-Feed / Dead-Letter zeigt den VOLLEN
|
||||||
|
* Task-Envelope (from/to/type/status/priority/created/Alter/topic/body/...).
|
||||||
|
*
|
||||||
|
* Datenquelle: Spool-PVC ro (FLEET_SPOOL_DIR), dieselbe Quelle wie
|
||||||
|
* countInbox()/readJournalTail(). Kein Egress, keine Secrets, kein neuer Grant.
|
||||||
|
*
|
||||||
|
* Abnahme-Regeln aus der Change-Order:
|
||||||
|
* - Fehlende Felder -> "-" (missing_fields listet sie zusaetzlich).
|
||||||
|
* - found:false (synthetisches Ereignis, z.B. Beacon-Event mit ref=agent_id)
|
||||||
|
* liefert alle Kernfelder als "-" und die angefragte id, KEIN Crash.
|
||||||
|
* - Body UNVERAENDERT (keine Maskierung) — XSS-Escaping nur im Panel.
|
||||||
|
* - Nie 5xx fuer unbekannte ids; tote Quelle -> degraded statt Throw.
|
||||||
|
*/
|
||||||
|
import { readFileSync, existsSync, readdirSync, statSync } from "node:fs"
|
||||||
|
import path from "node:path"
|
||||||
|
import { parse as parseYaml } from "yaml"
|
||||||
|
import { FLEET_SPOOL_DIR, readJournalTail, type JournalLine } from "./fleetSource"
|
||||||
|
|
||||||
|
export const MISSING = "-"
|
||||||
|
const DEAD_LETTER_DAYS = 7
|
||||||
|
const DETAIL_STALE_SECONDS = Number(process.env.FLEET_DETAIL_STALE_SECONDS || "900")
|
||||||
|
|
||||||
|
const CORE_FIELDS = [
|
||||||
|
"task_id", "from", "to", "type", "status", "priority", "created",
|
||||||
|
"created_iso", "age_seconds", "age_human", "topic", "body", "thread_id",
|
||||||
|
"karte_id", "reply_to", "vs", "claimed_at", "status_label",
|
||||||
|
] as const
|
||||||
|
|
||||||
|
const STATUS_LABEL: Record<string, string> = {
|
||||||
|
submitted: "eingereicht", working: "in Arbeit", open: "offen",
|
||||||
|
completed: "abgeschlossen", failed: "fehlgeschlagen", blocked: "blockiert",
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TaskEnvelope = {
|
||||||
|
task_id: string
|
||||||
|
from: string
|
||||||
|
to: string
|
||||||
|
type: string
|
||||||
|
status: string
|
||||||
|
priority: string
|
||||||
|
created: number | null
|
||||||
|
created_iso: string
|
||||||
|
age_seconds: number | null
|
||||||
|
age_human: string
|
||||||
|
topic: string
|
||||||
|
body: string
|
||||||
|
thread_id: string
|
||||||
|
karte_id: string
|
||||||
|
reply_to: string
|
||||||
|
vs: string
|
||||||
|
claimed_at: string
|
||||||
|
status_label: string
|
||||||
|
re_dispatched_to: string
|
||||||
|
re_dispatch_of: string
|
||||||
|
file: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TaskDetail = {
|
||||||
|
generated_at: string
|
||||||
|
now: number
|
||||||
|
source: string
|
||||||
|
refresh_seconds: number
|
||||||
|
entry_kind: string
|
||||||
|
found: boolean
|
||||||
|
query_task_id: string
|
||||||
|
task: Record<string, string | number | null>
|
||||||
|
missing_fields: string[]
|
||||||
|
extra_fields: Record<string, unknown>
|
||||||
|
raw_keys: string[]
|
||||||
|
body_note: string
|
||||||
|
degraded: boolean
|
||||||
|
degraded_reason: string
|
||||||
|
data_ts: string | number | null
|
||||||
|
data_age_seconds: number | null
|
||||||
|
stale: boolean
|
||||||
|
error: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function iso(epoch: number | null): string {
|
||||||
|
return epoch === null ? MISSING : new Date(epoch * 1000).toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
function humanize(seconds: number | null): string {
|
||||||
|
if (seconds === null) return MISSING
|
||||||
|
const s = Math.max(0, Math.floor(seconds))
|
||||||
|
const d = Math.floor(s / 86400)
|
||||||
|
const h = Math.floor((s % 86400) / 3600)
|
||||||
|
const m = Math.floor((s % 3600) / 60)
|
||||||
|
if (d) return `${d}d ${h}h`
|
||||||
|
if (h) return `${h}h ${m}m`
|
||||||
|
return `${m}m`
|
||||||
|
}
|
||||||
|
|
||||||
|
function toEpoch(value: unknown): number | null {
|
||||||
|
if (value === null || value === undefined || typeof value === "boolean") return null
|
||||||
|
if (typeof value === "number") return Number.isFinite(value) ? Math.floor(value) : null
|
||||||
|
const s = String(value).trim()
|
||||||
|
if (!s) return null
|
||||||
|
if (/^\d+$/.test(s)) return Number(s)
|
||||||
|
const t = Date.parse(s)
|
||||||
|
return Number.isNaN(t) ? null : Math.floor(t / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
function str(value: unknown): string {
|
||||||
|
if (value === null || value === undefined) return MISSING
|
||||||
|
if (typeof value === "string") return value.trim() === "" ? MISSING : value
|
||||||
|
if (typeof value === "object") return JSON.stringify(value)
|
||||||
|
return String(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeEnvelope(doc: Record<string, unknown>, now: number, file: string): TaskEnvelope {
|
||||||
|
const taskId = String(doc.task_id ?? doc.id ?? "")
|
||||||
|
const created = toEpoch(doc.created ?? doc.created_at)
|
||||||
|
const age = created === null ? null : Math.max(0, now - created)
|
||||||
|
const status = String(doc.status ?? "").toLowerCase()
|
||||||
|
const claimedRaw = doc.claimed_at ?? doc.working_since ?? doc.claimed
|
||||||
|
return {
|
||||||
|
task_id: taskId || MISSING,
|
||||||
|
from: str(doc.from ?? doc.from_agent),
|
||||||
|
to: str(doc.to),
|
||||||
|
type: str(doc.type),
|
||||||
|
status: status || MISSING,
|
||||||
|
priority: str(doc.priority),
|
||||||
|
created,
|
||||||
|
created_iso: iso(created),
|
||||||
|
age_seconds: age,
|
||||||
|
age_human: humanize(age),
|
||||||
|
topic: str(doc.topic),
|
||||||
|
body: str(doc.body),
|
||||||
|
thread_id: str(doc.thread_id),
|
||||||
|
karte_id: str(doc.karte_id),
|
||||||
|
reply_to: str(doc.reply_to),
|
||||||
|
vs: str(doc.vs),
|
||||||
|
claimed_at: claimedRaw === undefined || claimedRaw === null ? MISSING : iso(toEpoch(claimedRaw)),
|
||||||
|
status_label: STATUS_LABEL[status] ?? (status || MISSING),
|
||||||
|
re_dispatched_to: str(doc.re_dispatched_to),
|
||||||
|
re_dispatch_of: str(doc.re_dispatch_of),
|
||||||
|
file,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type RawEnvelope = { doc: Record<string, unknown>; envelope: TaskEnvelope }
|
||||||
|
|
||||||
|
function readAllEnvelopes(now: number): RawEnvelope[] {
|
||||||
|
if (!existsSync(FLEET_SPOOL_DIR)) {
|
||||||
|
throw new Error(`Spool-Dir fehlt: ${FLEET_SPOOL_DIR} (fleet-spool-PVC ro gemountet?)`)
|
||||||
|
}
|
||||||
|
const out: RawEnvelope[] = []
|
||||||
|
for (const f of readdirSync(FLEET_SPOOL_DIR)) {
|
||||||
|
if (!f.endsWith(".yaml")) continue
|
||||||
|
const full = path.join(FLEET_SPOOL_DIR, f)
|
||||||
|
try {
|
||||||
|
if (!statSync(full).isFile()) continue
|
||||||
|
const doc = parseYaml(readFileSync(full, "utf8")) as Record<string, unknown> | null
|
||||||
|
if (!doc || typeof doc !== "object") continue
|
||||||
|
if (!doc.task_id && !doc.id) continue
|
||||||
|
out.push({ doc, envelope: normalizeEnvelope(doc, now, f) })
|
||||||
|
} catch {
|
||||||
|
// Unparsebare Datei: nicht Teil der Ansicht — erscheint im Journal als rejected.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Spool-Reifegrad: offene Envelopes (submitted/working), aelteste zuerst. */
|
||||||
|
export function listSpoolTasks(): TaskEnvelope[] {
|
||||||
|
const now = Math.floor(Date.now() / 1000)
|
||||||
|
const open = readAllEnvelopes(now).filter(({ envelope }) =>
|
||||||
|
["submitted", "working", "running", "open"].includes(envelope.status))
|
||||||
|
return open.map((r) => r.envelope).sort((a, b) => (b.age_seconds ?? 0) - (a.age_seconds ?? 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dead-Letter: fehlgeschlagene Envelopes der letzten 7 Tage, aelteste zuerst. */
|
||||||
|
export function listDeadLetterTasks(): TaskEnvelope[] {
|
||||||
|
const now = Math.floor(Date.now() / 1000)
|
||||||
|
const cutoff = now - DEAD_LETTER_DAYS * 86400
|
||||||
|
return readAllEnvelopes(now)
|
||||||
|
.filter(({ envelope }) => envelope.status === "failed")
|
||||||
|
.filter(({ envelope }) => envelope.created !== null && envelope.created >= cutoff)
|
||||||
|
.map((r) => r.envelope)
|
||||||
|
.sort((a, b) => (b.age_seconds ?? 0) - (a.age_seconds ?? 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AlarmRow = {
|
||||||
|
time_epoch: number | null
|
||||||
|
time_iso: string
|
||||||
|
age_human: string
|
||||||
|
event: string
|
||||||
|
ref: string
|
||||||
|
from: string
|
||||||
|
to: string
|
||||||
|
task_id: string
|
||||||
|
note: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const ALARM_EVENT_RE = /deadman|alarm|stall|beacon|gateway|reject|invalid|orphan|escalat|blocked|timeout|fail|_warn/i
|
||||||
|
|
||||||
|
/** Alarm-Feed: Stoerungs-/Zustandsereignisse aus dem Spool-Journal (letzte 24 h). */
|
||||||
|
export function listAlarmEvents(limit = 120): AlarmRow[] {
|
||||||
|
const now = Math.floor(Date.now() / 1000)
|
||||||
|
const cutoff = now - 24 * 3600
|
||||||
|
const lines: JournalLine[] = readJournalTail(1500)
|
||||||
|
const rows: AlarmRow[] = []
|
||||||
|
for (const line of lines) {
|
||||||
|
const event = String(line.event ?? "")
|
||||||
|
if (!event || !ALARM_EVENT_RE.test(event)) continue
|
||||||
|
const t = toEpoch(line.time_epoch)
|
||||||
|
if (t !== null && t < cutoff) continue
|
||||||
|
rows.push({
|
||||||
|
time_epoch: t,
|
||||||
|
time_iso: iso(t),
|
||||||
|
age_human: humanize(t === null ? null : now - t),
|
||||||
|
event,
|
||||||
|
ref: String(line.task_id ?? line.ref ?? line.agent_id ?? line.agent ?? MISSING),
|
||||||
|
from: String(line.from ?? line.by ?? MISSING),
|
||||||
|
to: String(line.to ?? MISSING),
|
||||||
|
task_id: String(line.task_id ?? MISSING),
|
||||||
|
note: String(line.note ?? line.reason ?? ""),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return rows.slice(-limit).reverse()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Vollstaendiger Envelope fuer die Detailansicht. Wirft NICHT bei unbekannter id. */
|
||||||
|
export function getTaskDetail(queryId: string, kind = ""): TaskDetail {
|
||||||
|
const now = Math.floor(Date.now() / 1000)
|
||||||
|
const base: TaskDetail = {
|
||||||
|
generated_at: new Date(now * 1000).toISOString(),
|
||||||
|
now,
|
||||||
|
source: FLEET_SPOOL_DIR,
|
||||||
|
refresh_seconds: 30,
|
||||||
|
entry_kind: kind || "unknown",
|
||||||
|
found: false,
|
||||||
|
query_task_id: queryId,
|
||||||
|
task: Object.fromEntries(CORE_FIELDS.map((k) => [k, MISSING])),
|
||||||
|
missing_fields: [...CORE_FIELDS],
|
||||||
|
extra_fields: {},
|
||||||
|
raw_keys: [],
|
||||||
|
body_note: "Body unveraendert aus dem Spool (keine Maskierung).",
|
||||||
|
degraded: false,
|
||||||
|
degraded_reason: "",
|
||||||
|
data_ts: null,
|
||||||
|
data_age_seconds: null,
|
||||||
|
stale: false,
|
||||||
|
error: "",
|
||||||
|
}
|
||||||
|
if (!queryId) {
|
||||||
|
base.error = "Parameter id fehlt"
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
if (!existsSync(FLEET_SPOOL_DIR)) {
|
||||||
|
base.degraded = true
|
||||||
|
base.degraded_reason = "quelle-tot"
|
||||||
|
base.error = `Spool-Dir fehlt: ${FLEET_SPOOL_DIR}`
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const wanted = queryId.trim().toLowerCase()
|
||||||
|
const hits = readAllEnvelopes(now).filter(({ envelope }) =>
|
||||||
|
envelope.task_id.toLowerCase() === wanted)
|
||||||
|
if (hits.length === 0) {
|
||||||
|
base.task.task_id = queryId
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
const best = hits.sort((a, b) => (b.envelope.created ?? 0) - (a.envelope.created ?? 0))[0]
|
||||||
|
const env = best.envelope
|
||||||
|
const task: Record<string, string | number | null> = {}
|
||||||
|
const missing: string[] = []
|
||||||
|
for (const k of CORE_FIELDS) {
|
||||||
|
const v = env[k as keyof TaskEnvelope]
|
||||||
|
if (v === MISSING || v === null || v === "") {
|
||||||
|
task[k] = MISSING
|
||||||
|
missing.push(k)
|
||||||
|
} else {
|
||||||
|
task[k] = v as string | number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const extra: Record<string, unknown> = {}
|
||||||
|
const known = new Set<string>([...CORE_FIELDS, "id", "file", "created_at", "working_since", "claimed"])
|
||||||
|
for (const [k, v] of Object.entries(best.doc)) {
|
||||||
|
if (!known.has(k)) extra[k] = v
|
||||||
|
}
|
||||||
|
base.found = true
|
||||||
|
base.task = task
|
||||||
|
base.missing_fields = missing
|
||||||
|
base.extra_fields = extra
|
||||||
|
base.raw_keys = Object.keys(best.doc).sort()
|
||||||
|
base.data_ts = env.created
|
||||||
|
base.data_age_seconds = env.age_seconds
|
||||||
|
base.stale = env.age_seconds !== null && env.age_seconds > DETAIL_STALE_SECONDS
|
||||||
|
return base
|
||||||
|
} catch (e) {
|
||||||
|
base.degraded = true
|
||||||
|
base.degraded_reason = "lesefehler"
|
||||||
|
base.error = e instanceof Error ? e.message : String(e)
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TaskOverview = {
|
||||||
|
generated_at: string
|
||||||
|
spool: TaskEnvelope[]
|
||||||
|
dead_letter: TaskEnvelope[]
|
||||||
|
alarm: AlarmRow[]
|
||||||
|
counts: { spool: number; dead_letter: number; alarm: number }
|
||||||
|
degraded: boolean
|
||||||
|
degraded_reason: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Alle drei Listen in einem Call (Panel-Initialisierung + 30s-Refresh). */
|
||||||
|
export function loadTaskOverview(): TaskOverview {
|
||||||
|
const now = Math.floor(Date.now() / 1000)
|
||||||
|
const out: TaskOverview = {
|
||||||
|
generated_at: new Date(now * 1000).toISOString(),
|
||||||
|
spool: [], dead_letter: [], alarm: [],
|
||||||
|
counts: { spool: 0, dead_letter: 0, alarm: 0 },
|
||||||
|
degraded: false, degraded_reason: "",
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
out.spool = listSpoolTasks()
|
||||||
|
out.dead_letter = listDeadLetterTasks()
|
||||||
|
out.alarm = listAlarmEvents()
|
||||||
|
out.counts = { spool: out.spool.length, dead_letter: out.dead_letter.length, alarm: out.alarm.length }
|
||||||
|
} catch (e) {
|
||||||
|
out.degraded = true
|
||||||
|
out.degraded_reason = e instanceof Error ? e.message : String(e)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ function parseRouteModel(output: string, label: "Gateway inference" | "System in
|
|||||||
async function readOpenShellInferenceModel() {
|
async function readOpenShellInferenceModel() {
|
||||||
const { stdout } = await execFileAsync(OPENSHELL_BIN, ["inference", "get"], {
|
const { stdout } = await execFileAsync(OPENSHELL_BIN, ["inference", "get"], {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
}),
|
}),
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
maxBuffer: 5 * 1024 * 1024,
|
maxBuffer: 5 * 1024 * 1024,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { promisify } from "node:util"
|
|||||||
import { NEMOCLAW_BIN, NODE_BIN, commandExists, hostCommandEnv } from "./hostCommands"
|
import { NEMOCLAW_BIN, NODE_BIN, commandExists, hostCommandEnv } from "./hostCommands"
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
const execFileAsync = promisify(execFile)
|
||||||
const NEMOCLAW_RECOVERY_MIN_VERSION = "0.0.37"
|
const NEMOCLAW_LIFECYCLE_MIN_VERSION = "0.0.37"
|
||||||
|
|
||||||
type NemoClawInvocation = {
|
type NemoClawInvocation = {
|
||||||
file: string
|
file: string
|
||||||
@@ -98,7 +98,7 @@ async function runNemoClaw(args: string[], timeout = 30000): Promise<NemoClawRun
|
|||||||
try {
|
try {
|
||||||
const { stdout, stderr } = await execFileAsync(invocation.file, invocation.args, {
|
const { stdout, stderr } = await execFileAsync(invocation.file, invocation.args, {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
NO_COLOR: "1",
|
NO_COLOR: "1",
|
||||||
CLICOLOR: "0",
|
CLICOLOR: "0",
|
||||||
CLICOLOR_FORCE: "0",
|
CLICOLOR_FORCE: "0",
|
||||||
@@ -143,8 +143,8 @@ async function hasModernNemoClawSurface() {
|
|||||||
const version = await getNemoClawVersion()
|
const version = await getNemoClawVersion()
|
||||||
return {
|
return {
|
||||||
...version,
|
...version,
|
||||||
supported: version.version ? versionGte(version.version, NEMOCLAW_RECOVERY_MIN_VERSION) : false,
|
supported: version.version ? versionGte(version.version, NEMOCLAW_LIFECYCLE_MIN_VERSION) : false,
|
||||||
minimumVersion: NEMOCLAW_RECOVERY_MIN_VERSION,
|
minimumVersion: NEMOCLAW_LIFECYCLE_MIN_VERSION,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ export async function getNemoClawDoctorReport(sandboxName: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function recoverSandboxWithNemoClaw(sandboxName: string) {
|
export async function restartSandboxGatewayWithNemoClaw(sandboxName: string) {
|
||||||
const capability = await hasModernNemoClawSurface()
|
const capability = await hasModernNemoClawSurface()
|
||||||
if (!capability.supported) {
|
if (!capability.supported) {
|
||||||
return {
|
return {
|
||||||
@@ -196,12 +196,12 @@ export async function recoverSandboxWithNemoClaw(sandboxName: string) {
|
|||||||
stderr: "",
|
stderr: "",
|
||||||
exitCode: null as number | null,
|
exitCode: null as number | null,
|
||||||
error: capability.available
|
error: capability.available
|
||||||
? `NemoClaw ${capability.version || "unknown"} does not expose sandbox recover`
|
? `NemoClaw ${capability.version || "unknown"} does not expose sandbox gateway restart`
|
||||||
: capability.error || "NemoClaw CLI is not available",
|
: capability.error || "NemoClaw CLI is not available",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await runNemoClaw([sandboxName, "recover"], 90000)
|
const result = await runNemoClaw(["sandbox", "gateway", "restart", sandboxName], 90000)
|
||||||
return {
|
return {
|
||||||
available: true,
|
available: true,
|
||||||
supported: true,
|
supported: true,
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
export type NemoClawRegistryData = {
|
||||||
|
sandboxes?: Record<string, { name?: string; agent?: string | null }>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NemoClawListJsonIdentity = {
|
||||||
|
agentsByName: Record<string, string>
|
||||||
|
defaultSandboxNames: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeAgentIdentifier(agent: unknown): string | null
|
||||||
|
export function parseNemoclawListJson(output: string): NemoClawListJsonIdentity | null
|
||||||
|
export function parseDefaultSandboxNames(output: string): Set<string>
|
||||||
|
export function resolveSandboxAgent(
|
||||||
|
name: string,
|
||||||
|
id: string | null,
|
||||||
|
listJsonIdentity: NemoClawListJsonIdentity | null,
|
||||||
|
registry: NemoClawRegistryData | null
|
||||||
|
): string
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
function canonicalizeAgent(value) {
|
||||||
|
return value
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]+/g, '-')
|
||||||
|
.replace(/^-+|-+$/g, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeAgentIdentifier(agent) {
|
||||||
|
if (typeof agent !== 'string') return null
|
||||||
|
const trimmed = agent.trim()
|
||||||
|
if (!trimmed) return null
|
||||||
|
|
||||||
|
const compact = trimmed.toLowerCase().replace(/[^a-z0-9]/g, '')
|
||||||
|
if (compact === 'openclaw') return 'openclaw'
|
||||||
|
if (compact === 'nemohermes' || compact === 'hermes') return 'hermes'
|
||||||
|
if (compact.includes('openclaw')) return 'openclaw'
|
||||||
|
if (compact.includes('hermes')) return 'hermes'
|
||||||
|
|
||||||
|
const canonical = canonicalizeAgent(trimmed)
|
||||||
|
if (!canonical) return null
|
||||||
|
if (canonical === 'unknown') return 'unknown'
|
||||||
|
return canonical
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseNemoclawListJson(output) {
|
||||||
|
if (typeof output !== 'string' || output.trim().length === 0) return null
|
||||||
|
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(output)
|
||||||
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return null
|
||||||
|
if (parsed.schemaVersion !== 1) return null
|
||||||
|
if (!Array.isArray(parsed.sandboxes)) return null
|
||||||
|
|
||||||
|
const agentsByName = {}
|
||||||
|
const defaultSandboxNames = []
|
||||||
|
|
||||||
|
for (const entry of parsed.sandboxes) {
|
||||||
|
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) continue
|
||||||
|
const name = typeof entry.name === 'string' ? entry.name.trim() : ''
|
||||||
|
if (!name) continue
|
||||||
|
|
||||||
|
const normalized = normalizeAgentIdentifier(entry.agent)
|
||||||
|
agentsByName[name] = normalized || 'unknown'
|
||||||
|
if (entry.isDefault === true) defaultSandboxNames.push(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
agentsByName,
|
||||||
|
defaultSandboxNames,
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseDefaultSandboxNames(output) {
|
||||||
|
return new Set(
|
||||||
|
output
|
||||||
|
.split(/\r?\n/)
|
||||||
|
.map((entry) => entry.replace(/\u001b\[[0-9;]*m/g, ''))
|
||||||
|
.filter((entry) => /^\s{2,}[\w.-]+(?:\s+\*)?\s*$/.test(entry) && entry.includes('*'))
|
||||||
|
.map((entry) => entry.replace('*', '').trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveSandboxAgent(name, id, listJsonIdentity, registry) {
|
||||||
|
if (listJsonIdentity) {
|
||||||
|
const direct = listJsonIdentity.agentsByName[name] || (id ? listJsonIdentity.agentsByName[id] : null)
|
||||||
|
return direct || 'unknown'
|
||||||
|
}
|
||||||
|
|
||||||
|
const entries = registry?.sandboxes || {}
|
||||||
|
const directEntry = entries[name] || (id ? entries[id] : undefined)
|
||||||
|
const namedEntry = Object.values(entries).find((entry) => entry?.name === name || Boolean(id && entry?.name === id))
|
||||||
|
const normalized = normalizeAgentIdentifier(directEntry?.agent ?? namedEntry?.agent)
|
||||||
|
|
||||||
|
if (normalized) return normalized
|
||||||
|
return 'openclaw'
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
export function discoverNemoClawRegistryFiles(home = process.env.HOME || '/tmp') {
|
||||||
|
const stateRoot = path.join(home, '.nemoclaw')
|
||||||
|
const files = [path.join(stateRoot, 'sandboxes.json')]
|
||||||
|
const gatewaysRoot = path.join(stateRoot, 'gateways')
|
||||||
|
|
||||||
|
if (existsSync(gatewaysRoot)) {
|
||||||
|
try {
|
||||||
|
const ports = readdirSync(gatewaysRoot, { withFileTypes: true })
|
||||||
|
.filter((entry) => entry.isDirectory() && /^(?:[1-9][0-9]{0,4})$/.test(entry.name))
|
||||||
|
.map((entry) => Number(entry.name))
|
||||||
|
.filter((port) => port <= 65535)
|
||||||
|
.sort((a, b) => a - b)
|
||||||
|
for (const port of ports) files.push(path.join(gatewaysRoot, String(port), 'sandboxes.json'))
|
||||||
|
} catch {
|
||||||
|
// Individual readable registry files remain usable when directory discovery is unavailable.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return files.filter((file) => existsSync(file))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function readNemoClawRegistries(home = process.env.HOME || '/tmp') {
|
||||||
|
return discoverNemoClawRegistryFiles(home).flatMap((registryFile) => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(readFileSync(registryFile, 'utf8'))
|
||||||
|
return data && typeof data === 'object' && !Array.isArray(data)
|
||||||
|
? [{ registryFile, data }]
|
||||||
|
: []
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findNemoClawRegistryEntry(sandboxName, home = process.env.HOME || '/tmp') {
|
||||||
|
const matches = []
|
||||||
|
for (const registry of readNemoClawRegistries(home)) {
|
||||||
|
const entries = registry.data.sandboxes && typeof registry.data.sandboxes === 'object'
|
||||||
|
? registry.data.sandboxes
|
||||||
|
: {}
|
||||||
|
const keyed = entries[sandboxName]
|
||||||
|
const entry = keyed || Object.values(entries).find((candidate) => candidate?.name === sandboxName)
|
||||||
|
if (entry) matches.push({ entry, registryFile: registry.registryFile })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matches.length > 1) {
|
||||||
|
throw new Error(`Sandbox '${sandboxName}' appears in multiple NemoClaw gateway registries; resolve the duplicate registration before quick deploy.`)
|
||||||
|
}
|
||||||
|
return matches[0] || null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listNemoClawRegistryCandidates(home = process.env.HOME || '/tmp') {
|
||||||
|
const defaults = []
|
||||||
|
const entries = []
|
||||||
|
for (const { data } of readNemoClawRegistries(home)) {
|
||||||
|
if (typeof data.defaultSandbox === 'string' && data.defaultSandbox.trim()) {
|
||||||
|
defaults.push(data.defaultSandbox.trim())
|
||||||
|
}
|
||||||
|
for (const [key, value] of Object.entries(data.sandboxes || {})) {
|
||||||
|
const name = typeof value?.name === 'string' && value.name.trim() ? value.name.trim() : key
|
||||||
|
entries.push({ name, createdAt: String(value?.createdAt || '') })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entries.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
|
||||||
|
return [...new Set([...defaults, ...entries.map(({ name }) => name)])]
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { spawn } from "node:child_process"
|
||||||
|
import { OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
||||||
|
|
||||||
|
export type OpenClawConfigPatch = Record<string, unknown>
|
||||||
|
|
||||||
|
export function applyNativeOpenClawConfigPatch(
|
||||||
|
sandboxName: string,
|
||||||
|
patch: OpenClawConfigPatch,
|
||||||
|
timeoutMs = 60000,
|
||||||
|
) {
|
||||||
|
const payload = JSON.stringify(patch)
|
||||||
|
return new Promise<{ stdout: string; stderr: string; code: number | null }>((resolve, reject) => {
|
||||||
|
const child = spawn(
|
||||||
|
OPENSHELL_BIN,
|
||||||
|
[
|
||||||
|
"sandbox",
|
||||||
|
"exec",
|
||||||
|
"-n",
|
||||||
|
sandboxName,
|
||||||
|
"--env",
|
||||||
|
"HOME=/sandbox",
|
||||||
|
"--",
|
||||||
|
"openclaw",
|
||||||
|
"config",
|
||||||
|
"patch",
|
||||||
|
"--stdin",
|
||||||
|
],
|
||||||
|
{
|
||||||
|
env: hostCommandEnv({
|
||||||
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
let stdout = ""
|
||||||
|
let stderr = ""
|
||||||
|
let settled = false
|
||||||
|
const timer = setTimeout(() => child.kill("SIGTERM"), timeoutMs)
|
||||||
|
child.stdout.on("data", (chunk) => { stdout += String(chunk) })
|
||||||
|
child.stderr.on("data", (chunk) => { stderr += String(chunk) })
|
||||||
|
child.on("error", (error) => {
|
||||||
|
if (settled) return
|
||||||
|
settled = true
|
||||||
|
clearTimeout(timer)
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
child.on("close", (code) => {
|
||||||
|
if (settled) return
|
||||||
|
settled = true
|
||||||
|
clearTimeout(timer)
|
||||||
|
resolve({ stdout: stdout.trim(), stderr: stderr.trim(), code })
|
||||||
|
})
|
||||||
|
child.stdin.end(payload)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function writeNativeOpenClawConfigPatch(
|
||||||
|
sandboxName: string,
|
||||||
|
patch: OpenClawConfigPatch,
|
||||||
|
failureMessage: string,
|
||||||
|
) {
|
||||||
|
const result = await applyNativeOpenClawConfigPatch(sandboxName, patch)
|
||||||
|
if (result.code !== 0) throw new Error(result.stderr || failureMessage)
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import { execFile, spawn } from "node:child_process"
|
|||||||
import { promisify } from "node:util"
|
import { promisify } from "node:util"
|
||||||
import { HOST_PATH, OPENCLAW_BIN, OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
import { HOST_PATH, OPENCLAW_BIN, OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
||||||
import { getDefaultOpenClawInstance, getOpenClawDashboardPortForSandbox, resolveOpenClawInstance } from "./openclawInstances"
|
import { getDefaultOpenClawInstance, getOpenClawDashboardPortForSandbox, resolveOpenClawInstance } from "./openclawInstances"
|
||||||
|
import { restartSandboxGatewayWithNemoClaw } from "./nemoclawCli"
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
const execFileAsync = promisify(execFile)
|
||||||
const OPENSHELL_GATEWAY = process.env.OPENSHELL_GATEWAY?.trim() || undefined
|
const OPENSHELL_GATEWAY = process.env.OPENSHELL_GATEWAY?.trim() || undefined
|
||||||
@@ -397,13 +398,16 @@ function resolveSandboxInstanceId(instanceId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildSandboxSshArgs(sandboxName: string, extraArgs: string[]) {
|
function buildSandboxSshArgs(sandboxName: string, extraArgs: string[]) {
|
||||||
|
const gatewayOption = OPENSHELL_GATEWAY
|
||||||
|
? ` --gateway-name ${JSON.stringify(OPENSHELL_GATEWAY)}`
|
||||||
|
: ""
|
||||||
return [
|
return [
|
||||||
"-o", "BatchMode=yes",
|
"-o", "BatchMode=yes",
|
||||||
"-o", "StrictHostKeyChecking=no",
|
"-o", "StrictHostKeyChecking=no",
|
||||||
"-o", "UserKnownHostsFile=/dev/null",
|
"-o", "UserKnownHostsFile=/dev/null",
|
||||||
"-o", "GlobalKnownHostsFile=/dev/null",
|
"-o", "GlobalKnownHostsFile=/dev/null",
|
||||||
"-o", "LogLevel=ERROR",
|
"-o", "LogLevel=ERROR",
|
||||||
"-o", `ProxyCommand=${OPENSHELL_BIN} ssh-proxy --gateway-name nemoclaw --name ${sandboxName}`,
|
"-o", `ProxyCommand=${OPENSHELL_BIN} ssh-proxy${gatewayOption} --name ${sandboxName}`,
|
||||||
`sandbox@openshell-${sandboxName}`,
|
`sandbox@openshell-${sandboxName}`,
|
||||||
...extraArgs,
|
...extraArgs,
|
||||||
]
|
]
|
||||||
@@ -418,13 +422,13 @@ async function execSandboxSsh(sandboxName: string, command: string, timeoutMs =
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function ensureRemoteSandboxOpenClawDashboard(sandboxName: string) {
|
async function ensureRemoteSandboxOpenClawDashboard(sandboxName: string) {
|
||||||
const command = [
|
try {
|
||||||
`curl -fsS --max-time 2 http://127.0.0.1:${SANDBOX_DASHBOARD_REMOTE_PORT}/ >/dev/null 2>&1`,
|
await execSandboxSsh(sandboxName, `curl -fsS --max-time 2 http://127.0.0.1:${SANDBOX_DASHBOARD_REMOTE_PORT}/ >/dev/null`, 5000)
|
||||||
"||",
|
return true
|
||||||
`(nohup /usr/local/bin/openclaw gateway run --allow-unconfigured --bind loopback --port ${SANDBOX_DASHBOARD_REMOTE_PORT} >/tmp/gateway.log 2>&1 &)`
|
} catch {
|
||||||
].join(" ")
|
const restart = await restartSandboxGatewayWithNemoClaw(sandboxName)
|
||||||
|
if (!restart.ok) return false
|
||||||
await execSandboxSsh(sandboxName, command).catch(() => null)
|
}
|
||||||
|
|
||||||
for (let attempt = 0; attempt < 16; attempt += 1) {
|
for (let attempt = 0; attempt < 16; attempt += 1) {
|
||||||
try {
|
try {
|
||||||
@@ -445,7 +449,7 @@ async function ensureSandboxOpenClawDashboardTunnel(sandboxName: string) {
|
|||||||
const initial = await inspectListeningPort(port)
|
const initial = await inspectListeningPort(port)
|
||||||
if (initial.listenerPresent) return initial
|
if (initial.listenerPresent) return initial
|
||||||
|
|
||||||
await ensureRemoteSandboxOpenClawDashboard(sandboxName)
|
if (!await ensureRemoteSandboxOpenClawDashboard(sandboxName)) return initial
|
||||||
|
|
||||||
const child = spawn("ssh", buildSandboxSshArgs(sandboxName, [
|
const child = spawn("ssh", buildSandboxSshArgs(sandboxName, [
|
||||||
"-N",
|
"-N",
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ function runSandboxExec(sandboxName: string, script: string, input?: Buffer, tim
|
|||||||
return new Promise<{ stdout: Buffer; stderr: string; code: number | null }>((resolve, reject) => {
|
return new Promise<{ stdout: Buffer; stderr: string; code: number | null }>((resolve, reject) => {
|
||||||
const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
}),
|
}),
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { execFile, spawn } from "node:child_process"
|
import { execFile } from "node:child_process"
|
||||||
import { promisify } from "node:util"
|
import { promisify } from "node:util"
|
||||||
import { OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
import { OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
||||||
|
import { restartSandboxGatewayWithNemoClaw } from "./nemoclawCli"
|
||||||
|
import { writeNativeOpenClawConfigPatch } from "./openClawNativeConfig"
|
||||||
import { getSandboxInferenceConfig, type SandboxInferenceRoute } from "./sandboxInferenceStore"
|
import { getSandboxInferenceConfig, type SandboxInferenceRoute } from "./sandboxInferenceStore"
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
const execFileAsync = promisify(execFile)
|
||||||
@@ -106,11 +108,9 @@ function resolveOpenClawRoute(route: SandboxInferenceRoute) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildOpenClawConfig(current: any, routes: SandboxInferenceRoute[], primary: SandboxInferenceRoute) {
|
function buildOpenClawConfigPatch(routes: SandboxInferenceRoute[], primary: SandboxInferenceRoute) {
|
||||||
const providers: Record<string, any> = {}
|
const providers: Record<string, any> = {}
|
||||||
let primaryModelRef = primary.model
|
let primaryModelRef = primary.model
|
||||||
const channelDefaults = { ...(current?.channels?.defaults || {}) }
|
|
||||||
delete channelDefaults.configWrites
|
|
||||||
|
|
||||||
for (const route of routes.filter((item) => item.enabled)) {
|
for (const route of routes.filter((item) => item.enabled)) {
|
||||||
const resolved = resolveOpenClawRoute(route)
|
const resolved = resolveOpenClawRoute(route)
|
||||||
@@ -125,26 +125,20 @@ function buildOpenClawConfig(current: any, routes: SandboxInferenceRoute[], prim
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...current,
|
|
||||||
agents: {
|
agents: {
|
||||||
...(current?.agents || {}),
|
|
||||||
defaults: {
|
defaults: {
|
||||||
...(current?.agents?.defaults || {}),
|
|
||||||
model: {
|
model: {
|
||||||
...(current?.agents?.defaults?.model || {}),
|
|
||||||
primary: primaryModelRef,
|
primary: primaryModelRef,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
models: {
|
models: {
|
||||||
...(current?.models || {}),
|
|
||||||
mode: "merge",
|
mode: "merge",
|
||||||
providers,
|
providers,
|
||||||
},
|
},
|
||||||
channels: {
|
channels: {
|
||||||
...(current?.channels || {}),
|
|
||||||
defaults: {
|
defaults: {
|
||||||
...channelDefaults,
|
configWrites: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -161,64 +155,30 @@ async function runOpenShell(args: string[]) {
|
|||||||
return { stdout: String(stdout).trim(), stderr: String(stderr).trim() }
|
return { stdout: String(stdout).trim(), stderr: String(stderr).trim() }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runOpenShellExec(sandboxName: string, script: string, input?: string) {
|
|
||||||
return await new Promise<{ stdout: string; stderr: string; code: number | null }>((resolve, reject) => {
|
|
||||||
const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
|
||||||
env: hostCommandEnv({
|
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
|
||||||
}),
|
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
|
||||||
})
|
|
||||||
let stdout = ""
|
|
||||||
let stderr = ""
|
|
||||||
child.stdout.on("data", (chunk) => { stdout += String(chunk) })
|
|
||||||
child.stderr.on("data", (chunk) => { stderr += String(chunk) })
|
|
||||||
child.on("error", reject)
|
|
||||||
child.on("close", (code) => resolve({ stdout: stdout.trim(), stderr: stderr.trim(), code }))
|
|
||||||
if (input) child.stdin.end(input)
|
|
||||||
else child.stdin.end()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function readCurrentOpenClawConfig(sandboxName: string) {
|
|
||||||
const result = await runOpenShellExec(sandboxName, "cat /sandbox/.openclaw/openclaw.json")
|
|
||||||
if (result.code !== 0) throw new Error(result.stderr || "Failed to read OpenClaw config")
|
|
||||||
return JSON.parse(result.stdout)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function writeOpenClawConfig(sandboxName: string, config: any) {
|
|
||||||
const payload = `${JSON.stringify(config, null, 2)}\n`
|
|
||||||
const script = [
|
|
||||||
"cat > /sandbox/.openclaw/openclaw.json",
|
|
||||||
"chmod 600 /sandbox/.openclaw/openclaw.json",
|
|
||||||
"sha256sum /sandbox/.openclaw/openclaw.json > /sandbox/.openclaw/.config-hash",
|
|
||||||
"chmod 600 /sandbox/.openclaw/.config-hash",
|
|
||||||
].join(" && ")
|
|
||||||
const result = await runOpenShellExec(sandboxName, script, payload)
|
|
||||||
if (result.code !== 0) throw new Error(result.stderr || "Failed to write OpenClaw config")
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
async function restartOpenClawGatewayIfRunning(sandboxName: string) {
|
|
||||||
const script = "for p in /proc/[0-9]*; do cmd=$(tr '\\0' ' ' < \"$p/cmdline\" 2>/dev/null || true); case \"$cmd\" in *'openclaw gateway'*) kill \"${p##*/}\" 2>/dev/null || true;; esac; done"
|
|
||||||
return await runOpenShellExec(sandboxName, script)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function applySandboxInferenceProfile(sandboxId: string, sandboxName: string) {
|
export async function applySandboxInferenceProfile(sandboxId: string, sandboxName: string) {
|
||||||
const config = await getSandboxInferenceConfig(sandboxId)
|
const config = await getSandboxInferenceConfig(sandboxId)
|
||||||
const enabledRoutes = config.routes.filter((route) => route.enabled)
|
const enabledRoutes = config.routes.filter((route) => route.enabled)
|
||||||
if (enabledRoutes.length === 0) throw new Error("No enabled inference routes are configured for this sandbox")
|
if (enabledRoutes.length === 0) throw new Error("No enabled inference routes are configured for this sandbox")
|
||||||
const primary = enabledRoutes.find((route) => route.id === config.primaryRouteId) || enabledRoutes[0]
|
const primary = enabledRoutes.find((route) => route.id === config.primaryRouteId) || enabledRoutes[0]
|
||||||
|
|
||||||
const currentOpenClawConfig = await readCurrentOpenClawConfig(sandboxName)
|
const openClawPatch = buildOpenClawConfigPatch(enabledRoutes, primary)
|
||||||
const nextOpenClawConfig = buildOpenClawConfig(currentOpenClawConfig, enabledRoutes, primary)
|
await writeNativeOpenClawConfigPatch(
|
||||||
await writeOpenClawConfig(sandboxName, nextOpenClawConfig)
|
sandboxName,
|
||||||
await restartOpenClawGatewayIfRunning(sandboxName)
|
openClawPatch,
|
||||||
|
"Failed to apply native OpenClaw inference config",
|
||||||
|
)
|
||||||
const routeResult = await runOpenShell(["inference", "set", "--no-verify", "--provider", primary.provider, "--model", primary.model])
|
const routeResult = await runOpenShell(["inference", "set", "--no-verify", "--provider", primary.provider, "--model", primary.model])
|
||||||
|
const restartResult = await restartSandboxGatewayWithNemoClaw(sandboxName)
|
||||||
|
if (!restartResult.ok) {
|
||||||
|
throw new Error(
|
||||||
|
restartResult.stderr || restartResult.error ||
|
||||||
|
"NemoClaw could not verify the native agent gateway restart after applying inference config",
|
||||||
|
)
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
primaryRoute: primary,
|
primaryRoute: primary,
|
||||||
routesApplied: enabledRoutes.length,
|
routesApplied: enabledRoutes.length,
|
||||||
gatewayRoute: routeResult,
|
gatewayRoute: routeResult,
|
||||||
|
gatewayRestart: "nemoclaw-native-gateway",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
syncSandboxOpenClawMcpConfig,
|
syncSandboxOpenClawMcpConfig,
|
||||||
revokeSandboxOpenClawMcpConfig,
|
revokeSandboxOpenClawMcpConfig,
|
||||||
} from "./sandboxOpenClawMcpConfig"
|
} from "./sandboxOpenClawMcpConfig"
|
||||||
import { repairOpenClawExecApprovalsFile, writeSandboxFilePrivileged } from "./sandboxPrivilegedFiles"
|
import { writeSandboxFilePrivileged } from "./sandboxPrivilegedFiles"
|
||||||
|
|
||||||
export const SANDBOX_MCP_MANIFEST_PATH = "/sandbox/openshell_control_mcp.md"
|
export const SANDBOX_MCP_MANIFEST_PATH = "/sandbox/openshell_control_mcp.md"
|
||||||
|
|
||||||
@@ -112,8 +112,6 @@ export async function syncSandboxMcpManifest(
|
|||||||
options.brokerBaseUrl,
|
options.brokerBaseUrl,
|
||||||
handoff.token,
|
handoff.token,
|
||||||
)
|
)
|
||||||
const execApprovals = await repairOpenClawExecApprovalsFile(sandboxName)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: uploaded.path,
|
path: uploaded.path,
|
||||||
sandboxName: uploaded.sandboxName,
|
sandboxName: uploaded.sandboxName,
|
||||||
@@ -126,7 +124,6 @@ export async function syncSandboxMcpManifest(
|
|||||||
expiresAt: handoff.session.expiresAt,
|
expiresAt: handoff.session.expiresAt,
|
||||||
},
|
},
|
||||||
openClaw,
|
openClaw,
|
||||||
execApprovals,
|
|
||||||
markdown: handoff.markdown,
|
markdown: handoff.markdown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +1,21 @@
|
|||||||
import { spawn } from "node:child_process"
|
import { restartSandboxGatewayWithNemoClaw } from "./nemoclawCli"
|
||||||
import { OPENSHELL_BIN, hostCommandEnv } from "./hostCommands"
|
import { writeNativeOpenClawConfigPatch } from "./openClawNativeConfig"
|
||||||
|
|
||||||
export const OPENSHELL_CONTROL_MCP_SERVER_NAME = "openshell-control"
|
export const OPENSHELL_CONTROL_MCP_SERVER_NAME = "openshell-control"
|
||||||
export const OPENCLAW_CONFIG_PATH = "/sandbox/.openclaw/openclaw.json"
|
export const OPENCLAW_CONFIG_PATH = "/sandbox/.openclaw/openclaw.json"
|
||||||
const OPENCLAW_CONFIG_HASH_PATH = "/sandbox/.openclaw/.config-hash"
|
|
||||||
|
|
||||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
||||||
return Boolean(value) && typeof value === "object" && !Array.isArray(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeBrokerBaseUrl(value: string) {
|
function normalizeBrokerBaseUrl(value: string) {
|
||||||
return value.replace(/\/+$/, "")
|
return value.replace(/\/+$/, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
function runSandboxShell(sandboxName: string, script: string, input?: string, timeoutMs = 60000) {
|
async function restartNativeGateway(sandboxName: string) {
|
||||||
return new Promise<{ stdout: string; stderr: string; code: number | null }>((resolve, reject) => {
|
const result = await restartSandboxGatewayWithNemoClaw(sandboxName)
|
||||||
const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
if (!result.ok) {
|
||||||
env: hostCommandEnv({
|
throw new Error(
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
result.stderr || result.error ||
|
||||||
}),
|
"NemoClaw could not verify the native agent gateway restart after updating MCP config",
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
)
|
||||||
})
|
}
|
||||||
let stdout = ""
|
|
||||||
let stderr = ""
|
|
||||||
const timer = setTimeout(() => child.kill("SIGTERM"), timeoutMs)
|
|
||||||
child.stdout.on("data", (chunk) => { stdout += String(chunk) })
|
|
||||||
child.stderr.on("data", (chunk) => { stderr += String(chunk) })
|
|
||||||
child.on("error", (error) => {
|
|
||||||
clearTimeout(timer)
|
|
||||||
reject(error)
|
|
||||||
})
|
|
||||||
child.on("close", (code) => {
|
|
||||||
clearTimeout(timer)
|
|
||||||
resolve({ stdout: stdout.trim(), stderr: stderr.trim(), code })
|
|
||||||
})
|
|
||||||
if (input) child.stdin.end(input)
|
|
||||||
else child.stdin.end()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function readOpenClawConfig(sandboxName: string) {
|
|
||||||
const result = await runSandboxShell(sandboxName, `cat ${OPENCLAW_CONFIG_PATH}`)
|
|
||||||
if (result.code !== 0) throw new Error(result.stderr || "Failed to read OpenClaw config")
|
|
||||||
const parsed = JSON.parse(result.stdout)
|
|
||||||
if (!isRecord(parsed)) throw new Error("OpenClaw config must be a JSON object")
|
|
||||||
return parsed
|
|
||||||
}
|
|
||||||
|
|
||||||
async function writeOpenClawConfig(sandboxName: string, config: Record<string, unknown>) {
|
|
||||||
const payload = `${JSON.stringify(config, null, 2)}\n`
|
|
||||||
const script = [
|
|
||||||
`cat > ${OPENCLAW_CONFIG_PATH}`,
|
|
||||||
`chmod 0660 ${OPENCLAW_CONFIG_PATH}`,
|
|
||||||
`chown sandbox:sandbox ${OPENCLAW_CONFIG_PATH} 2>/dev/null || chown 998:998 ${OPENCLAW_CONFIG_PATH}`,
|
|
||||||
`sha256sum ${OPENCLAW_CONFIG_PATH} > ${OPENCLAW_CONFIG_HASH_PATH}`,
|
|
||||||
`chmod 0660 ${OPENCLAW_CONFIG_HASH_PATH}`,
|
|
||||||
`chown sandbox:sandbox ${OPENCLAW_CONFIG_HASH_PATH} 2>/dev/null || chown 998:998 ${OPENCLAW_CONFIG_HASH_PATH}`,
|
|
||||||
].join(" && ")
|
|
||||||
const result = await runSandboxShell(sandboxName, script, payload)
|
|
||||||
if (result.code !== 0) throw new Error(result.stderr || "Failed to write OpenClaw MCP config")
|
|
||||||
}
|
|
||||||
|
|
||||||
async function restartOpenClawGatewayIfRunning(sandboxName: string) {
|
|
||||||
const script = "for p in /proc/[0-9]*; do cmd=$(tr '\\0' ' ' < \"$p/cmdline\" 2>/dev/null || true); case \"$cmd\" in *'openclaw gateway'*) kill \"${p##*/}\" 2>/dev/null || true;; esac; done"
|
|
||||||
await runSandboxShell(sandboxName, script)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildOpenClawMcpServerConfig(brokerBaseUrl: string, token: string) {
|
export function buildOpenClawMcpServerConfig(brokerBaseUrl: string, token: string) {
|
||||||
@@ -82,19 +34,14 @@ export async function syncSandboxOpenClawMcpConfig(
|
|||||||
brokerBaseUrl: string,
|
brokerBaseUrl: string,
|
||||||
token: string,
|
token: string,
|
||||||
) {
|
) {
|
||||||
const current = await readOpenClawConfig(sandboxName)
|
|
||||||
const mcp = isRecord(current.mcp) ? { ...current.mcp } : {}
|
|
||||||
const servers = isRecord(mcp.servers) ? { ...mcp.servers } : {}
|
|
||||||
const serverConfig = buildOpenClawMcpServerConfig(brokerBaseUrl, token)
|
const serverConfig = buildOpenClawMcpServerConfig(brokerBaseUrl, token)
|
||||||
|
|
||||||
servers[OPENSHELL_CONTROL_MCP_SERVER_NAME] = serverConfig
|
await writeNativeOpenClawConfigPatch(
|
||||||
mcp.servers = servers
|
sandboxName,
|
||||||
|
{ mcp: { servers: { [OPENSHELL_CONTROL_MCP_SERVER_NAME]: serverConfig } } },
|
||||||
await writeOpenClawConfig(sandboxName, {
|
"Failed to apply native OpenClaw MCP config",
|
||||||
...current,
|
)
|
||||||
mcp,
|
await restartNativeGateway(sandboxName)
|
||||||
})
|
|
||||||
await restartOpenClawGatewayIfRunning(sandboxName)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: OPENCLAW_CONFIG_PATH,
|
path: OPENCLAW_CONFIG_PATH,
|
||||||
@@ -105,23 +52,12 @@ export async function syncSandboxOpenClawMcpConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function revokeSandboxOpenClawMcpConfig(sandboxName: string) {
|
export async function revokeSandboxOpenClawMcpConfig(sandboxName: string) {
|
||||||
const current = await readOpenClawConfig(sandboxName)
|
await writeNativeOpenClawConfigPatch(
|
||||||
const mcp = isRecord(current.mcp) ? { ...current.mcp } : {}
|
sandboxName,
|
||||||
const servers = isRecord(mcp.servers) ? { ...mcp.servers } : {}
|
{ mcp: { servers: { [OPENSHELL_CONTROL_MCP_SERVER_NAME]: null } } },
|
||||||
delete servers[OPENSHELL_CONTROL_MCP_SERVER_NAME]
|
"Failed to remove native OpenClaw MCP config",
|
||||||
|
)
|
||||||
const nextConfig: Record<string, unknown> = { ...current }
|
await restartNativeGateway(sandboxName)
|
||||||
if (Object.keys(servers).length > 0) {
|
|
||||||
mcp.servers = servers
|
|
||||||
nextConfig.mcp = mcp
|
|
||||||
} else {
|
|
||||||
delete mcp.servers
|
|
||||||
if (Object.keys(mcp).length > 0) nextConfig.mcp = mcp
|
|
||||||
else delete nextConfig.mcp
|
|
||||||
}
|
|
||||||
|
|
||||||
await writeOpenClawConfig(sandboxName, nextConfig)
|
|
||||||
await restartOpenClawGatewayIfRunning(sandboxName)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: OPENCLAW_CONFIG_PATH,
|
path: OPENCLAW_CONFIG_PATH,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type BrokerNetworkAction = {
|
|||||||
function runOpenShell(args: string[], timeout = 60000) {
|
function runOpenShell(args: string[], timeout = 60000) {
|
||||||
return execFileAsync(OPENSHELL_BIN, args, {
|
return execFileAsync(OPENSHELL_BIN, args, {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
TERM: "dumb",
|
TERM: "dumb",
|
||||||
}),
|
}),
|
||||||
timeout,
|
timeout,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function runSandboxShell(sandboxName: string, script: string, input?: Buffer | s
|
|||||||
return new Promise<{ stdout: string; stderr: string; code: number | null }>((resolve, reject) => {
|
return new Promise<{ stdout: string; stderr: string; code: number | null }>((resolve, reject) => {
|
||||||
const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
const child = spawn(OPENSHELL_BIN, ["sandbox", "exec", "-n", sandboxName, "--", "sh", "-lc", script], {
|
||||||
env: hostCommandEnv({
|
env: hostCommandEnv({
|
||||||
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw",
|
OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY?.trim() || undefined,
|
||||||
}),
|
}),
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
})
|
})
|
||||||
@@ -51,107 +51,3 @@ export async function writeSandboxFilePrivileged(
|
|||||||
bytes: payload.byteLength,
|
bytes: payload.byteLength,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function repairOpenClawExecApprovalsFile(sandboxName: string) {
|
|
||||||
const normalizeScript = [
|
|
||||||
`const fs = require("fs")`,
|
|
||||||
`const approval = "/sandbox/.openclaw/exec-approvals.json"`,
|
|
||||||
`const tmp = process.argv[1]`,
|
|
||||||
`let source = ""`,
|
|
||||||
`try { source = fs.readFileSync(approval, "utf8") } catch {}`,
|
|
||||||
`const trimmed = source.trim()`,
|
|
||||||
`let payload = "{}\\n"`,
|
|
||||||
`if (trimmed) { try { payload = JSON.stringify(JSON.parse(trimmed), null, 2) + "\\n" } catch {} }`,
|
|
||||||
`fs.writeFileSync(tmp, payload)`,
|
|
||||||
].join("; ")
|
|
||||||
const script = [
|
|
||||||
`mkdir -p /sandbox/.openclaw`,
|
|
||||||
`tmp="/sandbox/.openclaw/.exec-approvals.json.$$"`,
|
|
||||||
`node -e ${shellQuote(normalizeScript)} "$tmp"`,
|
|
||||||
`rm -f /sandbox/.openclaw/exec-approvals.json`,
|
|
||||||
`mv "$tmp" /sandbox/.openclaw/exec-approvals.json`,
|
|
||||||
`chown sandbox:sandbox /sandbox/.openclaw/exec-approvals.json 2>/dev/null || chown 998:998 /sandbox/.openclaw/exec-approvals.json`,
|
|
||||||
`chmod 0600 /sandbox/.openclaw/exec-approvals.json`,
|
|
||||||
].join(" && ")
|
|
||||||
const result = await runSandboxShell(sandboxName, script)
|
|
||||||
if (result.code !== 0) throw new Error(result.stderr || "failed to repair OpenClaw exec approvals file")
|
|
||||||
return {
|
|
||||||
sandboxName,
|
|
||||||
path: "/sandbox/.openclaw/exec-approvals.json",
|
|
||||||
note: "Replaced OpenClaw exec approvals symlink with a real sandbox-owned file for newer OpenClaw versions.",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function stabilizeOpenClawGatewayConfig(sandboxName: string) {
|
|
||||||
const patchConfig = [
|
|
||||||
`const fs = require("fs")`,
|
|
||||||
`const path = "/sandbox/.openclaw/openclaw.json"`,
|
|
||||||
`const cfg = JSON.parse(fs.readFileSync(path, "utf8"))`,
|
|
||||||
`cfg.plugins = cfg.plugins && typeof cfg.plugins === "object" && !Array.isArray(cfg.plugins) ? cfg.plugins : {}`,
|
|
||||||
`cfg.plugins.entries = cfg.plugins.entries && typeof cfg.plugins.entries === "object" && !Array.isArray(cfg.plugins.entries) ? cfg.plugins.entries : {}`,
|
|
||||||
`cfg.plugins.entries.bonjour = { ...(cfg.plugins.entries.bonjour || {}), enabled: false }`,
|
|
||||||
`fs.writeFileSync(path, JSON.stringify(cfg, null, 2) + "\\n")`,
|
|
||||||
].join("; ")
|
|
||||||
const script = [
|
|
||||||
`node -e ${shellQuote(patchConfig)}`,
|
|
||||||
`chmod 444 /sandbox/.openclaw/openclaw.json`,
|
|
||||||
`chown root:root /sandbox/.openclaw/openclaw.json`,
|
|
||||||
`(cd /sandbox/.openclaw && sha256sum openclaw.json > .config-hash)`,
|
|
||||||
`chmod 444 /sandbox/.openclaw/.config-hash`,
|
|
||||||
`chown root:root /sandbox/.openclaw/.config-hash`,
|
|
||||||
`mkdir -p /sandbox/.openclaw-data/logs`,
|
|
||||||
`chown -R sandbox:sandbox /sandbox/.openclaw-data/logs 2>/dev/null || chown -R 998:998 /sandbox/.openclaw-data/logs`,
|
|
||||||
`openclaw gateway stop >/dev/null 2>&1 || true`,
|
|
||||||
`if command -v gosu >/dev/null 2>&1; then nohup gosu sandbox openclaw gateway run >/sandbox/.openclaw-data/logs/gateway.log 2>&1 & else nohup openclaw gateway run >/sandbox/.openclaw-data/logs/gateway.log 2>&1 & fi`,
|
|
||||||
].join(" && ")
|
|
||||||
const result = await runSandboxShell(sandboxName, script)
|
|
||||||
if (result.code !== 0) throw new Error(result.stderr || "failed to stabilize OpenClaw gateway config")
|
|
||||||
return {
|
|
||||||
sandboxName,
|
|
||||||
path: "/sandbox/.openclaw/openclaw.json",
|
|
||||||
note: "Disabled the Bonjour gateway discovery plugin inside the sandbox because it crashes under the OpenShell network namespace.",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function repairOpenClawWorkspacePermissions(sandboxName: string) {
|
|
||||||
const mutableDirs = [
|
|
||||||
"agents",
|
|
||||||
"extensions",
|
|
||||||
"workspace",
|
|
||||||
"skills",
|
|
||||||
"hooks",
|
|
||||||
"identity",
|
|
||||||
"devices",
|
|
||||||
"canvas",
|
|
||||||
"cron",
|
|
||||||
"memory",
|
|
||||||
"logs",
|
|
||||||
"credentials",
|
|
||||||
"flows",
|
|
||||||
"sandbox",
|
|
||||||
"telegram",
|
|
||||||
"plugin-runtime-deps",
|
|
||||||
]
|
|
||||||
const mutableFiles = [
|
|
||||||
"update-check.json",
|
|
||||||
]
|
|
||||||
const script = [
|
|
||||||
`mkdir -p /sandbox/.openclaw /sandbox/.openclaw-data/agents/main/agent`,
|
|
||||||
`for dir in ${mutableDirs.map(shellQuote).join(" ")}; do target="/sandbox/.openclaw-data/$dir"; link="/sandbox/.openclaw/$dir"; mkdir -p "$target"; if [ -d "$link" ] && [ ! -L "$link" ]; then cp -a "$link/." "$target/" 2>/dev/null || true; rm -rf "$link"; fi; ln -sfn "$target" "$link"; done`,
|
|
||||||
`for file in ${mutableFiles.map(shellQuote).join(" ")}; do target="/sandbox/.openclaw-data/$file"; link="/sandbox/.openclaw/$file"; if [ ! -e "$target" ]; then if [ -f "$link" ] && [ ! -L "$link" ]; then cp "$link" "$target" 2>/dev/null || : > "$target"; else : > "$target"; fi; fi; if [ -e "$link" ] && [ ! -L "$link" ]; then rm -f "$link"; fi; ln -sfn "$target" "$link"; done`,
|
|
||||||
`approval="/sandbox/.openclaw/exec-approvals.json"; approval_data="/sandbox/.openclaw-data/exec-approvals.json"; tmp="/sandbox/.openclaw/.exec-approvals.reconcile.$$"; if [ -L "$approval" ]; then if [ -s "$approval_data" ]; then cp "$approval_data" "$tmp" 2>/dev/null || : > "$tmp"; else : > "$tmp"; fi; rm -f "$approval"; mv "$tmp" "$approval"; elif [ ! -e "$approval" ]; then : > "$approval"; fi`,
|
|
||||||
`chown -R sandbox:sandbox /sandbox/.openclaw-data 2>/dev/null || chown -R 998:998 /sandbox/.openclaw-data`,
|
|
||||||
`chown sandbox:sandbox /sandbox/.openclaw /sandbox/.openclaw/exec-approvals.json 2>/dev/null || chown 998:998 /sandbox/.openclaw /sandbox/.openclaw/exec-approvals.json`,
|
|
||||||
`chmod 0755 /sandbox/.openclaw && chmod 0600 /sandbox/.openclaw/exec-approvals.json`,
|
|
||||||
].join(" && ")
|
|
||||||
const result = await runSandboxShell(sandboxName, script)
|
|
||||||
if (result.code !== 0) throw new Error(result.stderr || "failed to repair OpenClaw mutable paths")
|
|
||||||
return {
|
|
||||||
sandboxName,
|
|
||||||
path: "/sandbox/.openclaw",
|
|
||||||
target: "/sandbox/.openclaw-data",
|
|
||||||
mutableDirs,
|
|
||||||
mutableFiles,
|
|
||||||
note: "Reconciled the OpenClaw directory layout for NemoClaw: mutable state paths, AGENTS.md, session locks, update-check state, plugin runtime deps, and exec approvals are writable where the bundled OpenClaw expects them.",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+92
-2
@@ -10,6 +10,16 @@ import McpConfigurationPanel from './components/McpConfigurationPanel'
|
|||||||
import LiveTelemetryBar from './components/LiveTelemetryBar'
|
import LiveTelemetryBar from './components/LiveTelemetryBar'
|
||||||
import ActivityPanel from './components/ActivityPanel'
|
import ActivityPanel from './components/ActivityPanel'
|
||||||
import { useSandboxInventory } from './hooks/useSandboxInventory'
|
import { useSandboxInventory } from './hooks/useSandboxInventory'
|
||||||
|
import OrgChart from './components/fleet/OrgChart'
|
||||||
|
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'
|
||||||
|
import OpsPanels from './components/fleet/OpsPanels'
|
||||||
import {
|
import {
|
||||||
createHydrationSafeDashboardSessionState,
|
createHydrationSafeDashboardSessionState,
|
||||||
buildOperatorTerminalRoute,
|
buildOperatorTerminalRoute,
|
||||||
@@ -25,7 +35,7 @@ export default function Dashboard() {
|
|||||||
const [dashboardSession, setDashboardSession] = useState(() => createHydrationSafeDashboardSessionState())
|
const [dashboardSession, setDashboardSession] = useState(() => createHydrationSafeDashboardSessionState())
|
||||||
const [isCreateMode, setIsCreateMode] = useState(false)
|
const [isCreateMode, setIsCreateMode] = useState(false)
|
||||||
const [isDestroyMode, setIsDestroyMode] = useState(false)
|
const [isDestroyMode, setIsDestroyMode] = useState(false)
|
||||||
const [activeView, setActiveView] = useState<'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp'>('sandboxes')
|
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 [telemetryBarEnabled, setTelemetryBarEnabled] = useState(false)
|
||||||
const [deletingSandboxId, setDeletingSandboxId] = useState<string | null>(null)
|
const [deletingSandboxId, setDeletingSandboxId] = useState<string | null>(null)
|
||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
||||||
@@ -234,6 +244,66 @@ export default function Dashboard() {
|
|||||||
setIsDestroyMode(false)
|
setIsDestroyMode(false)
|
||||||
clearSelection()
|
clearSelection()
|
||||||
}}
|
}}
|
||||||
|
onFleetOrgClick={() => {
|
||||||
|
setActiveView('org')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetMessagesClick={() => {
|
||||||
|
setActiveView('messages')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetBoardClick={() => {
|
||||||
|
setActiveView('board')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetOwnerClick={() => {
|
||||||
|
setActiveView('owner')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetApprovalsClick={() => {
|
||||||
|
setActiveView('approvals')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetAttentionClick={() => {
|
||||||
|
setActiveView('attention')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetEscalationsClick={() => {
|
||||||
|
setActiveView('escalations')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetSandboxesClick={() => {
|
||||||
|
setActiveView('fleet-sandboxes')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetTasksClick={() => {
|
||||||
|
setActiveView('tasks')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
|
onFleetOpsClick={() => {
|
||||||
|
setActiveView('ops')
|
||||||
|
setIsCreateMode(false)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
clearSelection()
|
||||||
|
}}
|
||||||
onExitMode={() => {
|
onExitMode={() => {
|
||||||
setIsCreateMode(false)
|
setIsCreateMode(false)
|
||||||
setIsDestroyMode(false)
|
setIsDestroyMode(false)
|
||||||
@@ -249,7 +319,27 @@ export default function Dashboard() {
|
|||||||
<div>
|
<div>
|
||||||
<div className="mx-auto max-w-7xl p-8 max-sm:p-4">
|
<div className="mx-auto max-w-7xl p-8 max-sm:p-4">
|
||||||
{telemetryBarEnabled && <LiveTelemetryBar />}
|
{telemetryBarEnabled && <LiveTelemetryBar />}
|
||||||
{activeView === 'settings' ? (
|
{activeView === 'org' ? (
|
||||||
|
<OrgChart />
|
||||||
|
) : activeView === 'messages' ? (
|
||||||
|
<MessageFeed />
|
||||||
|
) : activeView === 'board' ? (
|
||||||
|
<KanbanBoard />
|
||||||
|
) : activeView === 'owner' ? (
|
||||||
|
<OwnerPanel />
|
||||||
|
) : activeView === 'fleet-sandboxes' ? (
|
||||||
|
<SandboxFleetView />
|
||||||
|
) : activeView === 'tasks' ? (
|
||||||
|
<TaskBrowser />
|
||||||
|
) : activeView === 'ops' ? (
|
||||||
|
<OpsPanels />
|
||||||
|
) : activeView === 'attention' ? (
|
||||||
|
<AttentionPanel />
|
||||||
|
) : activeView === 'approvals' ? (
|
||||||
|
<OwnerApprovals />
|
||||||
|
) : activeView === 'escalations' ? (
|
||||||
|
<EscalationHistory />
|
||||||
|
) : activeView === 'settings' ? (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="panel p-8">
|
<div className="panel p-8">
|
||||||
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mb-4">
|
<h1 className="text-lg font-semibold text-[var(--nvidia-green)] uppercase tracking-wider mb-4">
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/**
|
||||||
|
* /runbook — Statische Notfall-Runbook-Seite des Towers (Server Component).
|
||||||
|
* Karte tower-notfall-runbook, DATEI 2: rendert die Runbook-Datei als
|
||||||
|
* schlichte Markdown-/Textseite — rein statisch, kein Script, keine
|
||||||
|
* externen URLs, keine Secrets. Anker (#deadman etc.) kommen aus der MD.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { readFile } from "node:fs/promises"
|
||||||
|
import path from "node:path"
|
||||||
|
|
||||||
|
export const dynamic = "force-static"
|
||||||
|
export const metadata = { title: "Notfall-Runbook Tower" }
|
||||||
|
|
||||||
|
const MD_PATH = path.join(process.cwd(), "public", "runbook", "runbook-tower-notfall.md")
|
||||||
|
|
||||||
|
/** Minimaler Markdown->HTML-Renderer (keine Dep, kein Script-Output). */
|
||||||
|
function renderMarkdown(md: string): string {
|
||||||
|
const esc = (s: string) =>
|
||||||
|
s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """)
|
||||||
|
const lines = md.split(/\r?\n/)
|
||||||
|
const out: string[] = []
|
||||||
|
let inCode = false
|
||||||
|
let listOpen = false
|
||||||
|
const closeList = () => {
|
||||||
|
if (listOpen) {
|
||||||
|
out.push("</ul>")
|
||||||
|
listOpen = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const raw of lines) {
|
||||||
|
const line = raw
|
||||||
|
// Bekannt-sichere Anker-Tags aus der Runbook-MD unverändert durchreichen
|
||||||
|
// (Deep-Link-Ziele #deadman/#spool/#deadletter/#health).
|
||||||
|
const anchor = line.match(/^<a id="([a-z]+)"><\/a>$/)
|
||||||
|
if (anchor && !inCode) {
|
||||||
|
out.push(`<span id="${anchor[1]}"></span>`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (/^```/.test(line)) {
|
||||||
|
closeList()
|
||||||
|
out.push(inCode ? "</code></pre>" : '<pre class="runbook-code"><code>')
|
||||||
|
inCode = !inCode
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (inCode) {
|
||||||
|
out.push(esc(line))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const h = line.match(/^(#{1,4})\s+(.*)$/)
|
||||||
|
if (h) {
|
||||||
|
closeList()
|
||||||
|
const lvl = Math.min(h[1].length + 1, 5) // h1->h2 (Seitenh1 ist der Titel)
|
||||||
|
out.push(`<h${lvl}>${esc(h[2])}</h${lvl}>`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (/^\s*[-*]\s+/.test(line)) {
|
||||||
|
if (!listOpen) {
|
||||||
|
out.push('<ul class="runbook-list">')
|
||||||
|
listOpen = true
|
||||||
|
}
|
||||||
|
out.push(`<li>${esc(line.replace(/^\s*[-*]\s+/, ""))}</li>`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (line.trim() === "") {
|
||||||
|
closeList()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out.push(`<p>${esc(line)}</p>`)
|
||||||
|
}
|
||||||
|
closeList()
|
||||||
|
return out.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function RunbookPage() {
|
||||||
|
let md = ""
|
||||||
|
try {
|
||||||
|
md = await readFile(MD_PATH, "utf8")
|
||||||
|
} catch {
|
||||||
|
md = "# Runbook nicht gefunden\n\nDie Runbook-Datei ist im Image nicht vorhanden (public/runbook/runbook-tower-notfall.md)."
|
||||||
|
}
|
||||||
|
const html = renderMarkdown(md)
|
||||||
|
return (
|
||||||
|
<main className="panel mx-auto my-8 max-w-4xl p-8" data-testid="runbook-page">
|
||||||
|
<h1 className="text-lg font-semibold uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||||
|
Notfall-Runbook Tower
|
||||||
|
</h1>
|
||||||
|
<p className="mt-1 text-xs text-[var(--foreground-dim)]">
|
||||||
|
Statisch · Deep-Link-Ziele der Alarm-Ampeln:{" "}
|
||||||
|
<a className="text-[#93c5fd] underline" href="#deadman">#deadman</a> ·{" "}
|
||||||
|
<a className="text-[#93c5fd] underline" href="#spool">#spool</a> ·{" "}
|
||||||
|
<a className="text-[#93c5fd] underline" href="#deadletter">#deadletter</a> ·{" "}
|
||||||
|
<a className="text-[#93c5fd] underline" href="#health">#health</a>
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
className="runbook-body mt-6 space-y-2 text-sm leading-relaxed"
|
||||||
|
dangerouslySetInnerHTML={{ __html: html }}
|
||||||
|
/>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -8,11 +8,11 @@ YELLOW='\033[1;33m'
|
|||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
OPENSHELL_VERSION="${OPENSHELL_VERSION:-v0.0.106}"
|
OPENSHELL_VERSION="${OPENSHELL_VERSION:-v0.0.116}"
|
||||||
OPENSHELL_INSTALL_URL="${OPENSHELL_INSTALL_URL:-https://raw.githubusercontent.com/NVIDIA/OpenShell/main/install.sh}"
|
OPENSHELL_INSTALL_URL="${OPENSHELL_INSTALL_URL:-https://raw.githubusercontent.com/NVIDIA/OpenShell/main/install.sh}"
|
||||||
NEMOCLAW_INSTALL_REF="${NEMOCLAW_INSTALL_REF:-${NEMOCLAW_INSTALL_TAG:-main}}"
|
NEMOCLAW_INSTALL_REF="${NEMOCLAW_INSTALL_REF:-${NEMOCLAW_INSTALL_TAG:-main}}"
|
||||||
NEMOCLAW_SOURCE_URL="${NEMOCLAW_SOURCE_URL:-https://github.com/NVIDIA/NemoClaw.git}"
|
NEMOCLAW_SOURCE_URL="${NEMOCLAW_SOURCE_URL:-https://github.com/NVIDIA/NemoClaw.git}"
|
||||||
OPENCLAW_VERSION="${OPENCLAW_VERSION:-2026.7.1}"
|
OPENCLAW_VERSION="${OPENCLAW_VERSION:-2026.9.2}"
|
||||||
NEMOCLAW_BASE_IMAGE="${NEMOCLAW_BASE_IMAGE:-ghcr.io/nvidia/nemoclaw/sandbox-base:latest}"
|
NEMOCLAW_BASE_IMAGE="${NEMOCLAW_BASE_IMAGE:-ghcr.io/nvidia/nemoclaw/sandbox-base:latest}"
|
||||||
NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE="${NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE:-1}"
|
NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE="${NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE:-1}"
|
||||||
NEMOCLAW_NON_INTERACTIVE="${NEMOCLAW_NON_INTERACTIVE:-1}"
|
NEMOCLAW_NON_INTERACTIVE="${NEMOCLAW_NON_INTERACTIVE:-1}"
|
||||||
|
|||||||
@@ -1,6 +1,24 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
serverExternalPackages: ["ssh2"],
|
serverExternalPackages: ["ssh2"],
|
||||||
|
async headers() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
// Tower-Security §4: CSP ohne externe URLs, kein Framing, kein Sniffing.
|
||||||
|
source: "/(.*)",
|
||||||
|
headers: [
|
||||||
|
{ key: "Content-Security-Policy", value: "default-src 'self'; frame-ancestors 'none'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; connect-src 'self'" },
|
||||||
|
{ key: "X-Content-Type-Options", value: "nosniff" },
|
||||||
|
{ key: "Referrer-Policy", value: "no-referrer" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Live-Daten + Owner-Kanaele: nichts in Proxies/Caches (§4.4).
|
||||||
|
source: "/api/fleet/:path*",
|
||||||
|
headers: [{ key: "Cache-Control", value: "no-store" }],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default nextConfig
|
export default nextConfig
|
||||||
|
|||||||
Generated
+16
@@ -20,6 +20,7 @@
|
|||||||
"ws": "^8.20.0",
|
"ws": "^8.20.0",
|
||||||
"xterm": "^5.3.0",
|
"xterm": "^5.3.0",
|
||||||
"xterm-addon-fit": "^0.8.0",
|
"xterm-addon-fit": "^0.8.0",
|
||||||
|
"yaml": "^2.9.1",
|
||||||
"zod": "^4.3.6",
|
"zod": "^4.3.6",
|
||||||
"zustand": "^4.5.5"
|
"zustand": "^4.5.5"
|
||||||
},
|
},
|
||||||
@@ -7284,6 +7285,21 @@
|
|||||||
"xterm": "^5.0.0"
|
"xterm": "^5.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/yaml": {
|
||||||
|
"version": "2.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz",
|
||||||
|
"integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"bin": {
|
||||||
|
"yaml": "bin.mjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14.6"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/eemeli"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/yocto-queue": {
|
"node_modules/yocto-queue": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
"ws": "^8.20.0",
|
"ws": "^8.20.0",
|
||||||
"xterm": "^5.3.0",
|
"xterm": "^5.3.0",
|
||||||
"xterm-addon-fit": "^0.8.0",
|
"xterm-addon-fit": "^0.8.0",
|
||||||
|
"yaml": "^2.9.1",
|
||||||
"zod": "^4.3.6",
|
"zod": "^4.3.6",
|
||||||
"zustand": "^4.5.5"
|
"zustand": "^4.5.5"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
# Notfall-Runbook Tower (Fleet vs-fleet-rebuild)
|
||||||
|
|
||||||
|
Stand: 2026-10-30 · Autor: devops · Karte: tower-notfall-runbook
|
||||||
|
Geltung: Owner am Tower-Panel (10.0.30.213, tcp/8099). Ziel: in <5 min
|
||||||
|
entscheiden und handeln, ohne zu raetseln.
|
||||||
|
|
||||||
|
## Anker (Deep-Link-Ziele fuer die Alarm-Ampeln)
|
||||||
|
Die Inline-Hints/Links an den Tower-Ampeln springen genau auf einen dieser
|
||||||
|
Anker (nur interne Links, kein aktiver Inhalt/Script, keine Secrets):
|
||||||
|
- **#deadman** -> Deadman-Status / Szenario A
|
||||||
|
- **#spool** -> Spool-Aging / Szenario B
|
||||||
|
- **#deadletter** -> Dead-Letter-Ansicht / Szenario B (Punkt 3)
|
||||||
|
- **#health** -> Health-Ampel / Degraded-Banner / Szenario C
|
||||||
|
Diese Datei ist reiner Text (Markdown); die Hints rendern daraus nur
|
||||||
|
Ueberschrift + Link, nichts Ausfuehrbares.
|
||||||
|
|
||||||
|
## 0. Grundlagen (immer zuerst lesen)
|
||||||
|
- Heartbeat-Intervall: 300 s je Agent an den Beacon.
|
||||||
|
- Ampel Health: gruen <120 s, gelb 120-300 s, rot >300 s (Beacon-Heartbeat-Age).
|
||||||
|
- Deadman-Schwelle: 5400 s (90 min) blockierte Fleet -> Kaskade reisst.
|
||||||
|
- Spool-Aging: offene Envelopes (submitted/working), rot >5400 s.
|
||||||
|
- Diagnose-Oberflaechen am Tower-Panel: Deadman-Status, Spool-Aging,
|
||||||
|
Dead-Letter, Alarm-Feed, Health-Ampel, /healthz + /api/status.
|
||||||
|
- Aufgaben des Owners: nur ENTSCHEIDEN + Freigeben. Kein Debugging im Panel.
|
||||||
|
|
||||||
|
## ESKALATIONSKONTAKT (Owner)
|
||||||
|
- Primaer: **Owner** (Dominik). Kanal: Owner-Inbox/Queue im Tower.
|
||||||
|
- Eskalation aus einem Agenten heraus: ueber den CISO-Kanal
|
||||||
|
(`submit_task(from_agent=<id>, to=ciso, type=review, topic="[NAR] <ziel>")`);
|
||||||
|
der CISO leitet kritische Faelle als `escalation` P1 an `tower-owner`
|
||||||
|
weiter (FLEET-POLICIES 1.3). Direkt-Adressierung an `tower-owner` ist nur
|
||||||
|
dem CISO erlaubt.
|
||||||
|
- Owner-Entscheidungen (Abnahme/Review/NAR) laufen ueber die Owner-Queue.
|
||||||
|
- Bei Netz-Themen: NAR ueber den CISO; bei Infrastruktur/Tower: tower-owner.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<a id="deadman"></a>
|
||||||
|
## Szenario A — Deadman-Blockade (Fleet steht, Ampel "Deadman: blocked")
|
||||||
|
Beobachtung: Deadman-Status zeigt Zustand `blocked` + blockierenden Owner-Task
|
||||||
|
(ID, Typ, Alter) im Header; ggf. rot in der Health-Ampel.
|
||||||
|
|
||||||
|
Diagnose-Pfad:
|
||||||
|
1. Panel -> **Deadman-Status**: welcher Owner-Task blockiert? Alter auslesen.
|
||||||
|
2. Panel -> **Alarm-Feed**: juengste Deadman-Kaskade (Zeit, Agent, Ursache,
|
||||||
|
Dauer) - bestaetigt, ob es die laufende Blockade ist.
|
||||||
|
3. Panel -> **Health-Ampel** (#health): welche Agents stehen rot/gelb (wer ist
|
||||||
|
betroffen)?
|
||||||
|
4. Abgleich: blockierender Task-Typ (Abnahme/Review/NAR/Entscheidung).
|
||||||
|
|
||||||
|
Schritte:
|
||||||
|
1. Blockierenden Owner-Task oeffnen und INNERHALB der Queue entscheiden
|
||||||
|
(Abnahme erteilen, Review freigeben/ablehnen, NAR approven).
|
||||||
|
2. Nach Entscheidung Deadman-Status auf `progress` pruefen (Auto-Refresh 30 s).
|
||||||
|
3. Wenn der Task nicht entscheidbar ist (fehlender Kontext): Task mit
|
||||||
|
Kommentar zurueck an Absender (reply_to) statt liegen zu lassen.
|
||||||
|
4. Verifikation: Health-Ampel der betroffenen Agents wieder gruen <120 s
|
||||||
|
binnen 2 Heartbeat-Zyklen (<=10 min).
|
||||||
|
|
||||||
|
Eskalation: Bleibt die Blockade >5400 s bestehen oder ist der Task unklar ->
|
||||||
|
Owner direkt ansprechen (Kanal s.o.), Grund + Task-ID nennen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<a id="spool"></a>
|
||||||
|
## Szenario B — Spool-Stau (Tasks haengen, Zustellung klemmt)
|
||||||
|
Beobachtung: Spool-Aging listet Envelopes >5400 s rot; Zusteller liefern nicht.
|
||||||
|
|
||||||
|
Diagnose-Pfad:
|
||||||
|
1. Panel -> **Spool-Aging**: Envelopes nach Alter + Empfaenger. Aeltester
|
||||||
|
Eintrag zuerst; rot = >5400 s.
|
||||||
|
<a id="deadletter"></a>
|
||||||
|
2. Panel -> **Dead-Letter**: status=failed (letzte 7 Tage) mit from->to, Alter -
|
||||||
|
bereits verlorene Arbeit (Luecke Spool-Aging vs. Alarm-Feed).
|
||||||
|
3. Panel -> **Health-Ampel** (#health): ist Empfaenger-Agent rot? -> down.
|
||||||
|
4. Panel -> **/api/status**: Datenquellen-Zustand Prometheus/Beacon; degraded?
|
||||||
|
|
||||||
|
Schritte:
|
||||||
|
1. Einzelner haengender Envelope, Empfaenger gruen -> Zustellung neu anstossen
|
||||||
|
(Task erneut submitten an denselben Empfaenger, reply_to setzen).
|
||||||
|
2. Blockierter ganzer Empfaenger (rot) -> Szenario A/C zuerst loesen; der Spool
|
||||||
|
leert sich danach automatisch.
|
||||||
|
3. Failed-Tasks aus der Dead-Letter-Ansicht pruefen: wiederholbar -> erneut
|
||||||
|
submitten; endgueltig unloesbar -> Task mit Grund neu aufsetzen (nicht still
|
||||||
|
verwerfen).
|
||||||
|
4. Verifikation: keine Eintraege mehr >5400 s im Spool-Aging; Dead-Letter
|
||||||
|
waechst nicht weiter.
|
||||||
|
|
||||||
|
Eskalation: Envelopes >5400 s ohne down-Empfaenger -> Ursache unklar, an
|
||||||
|
tower-owner mit Screenshot/IDs melden; bei >2 betroffenen Agents zusaetzlich
|
||||||
|
Owner informieren (Kanal s.o.).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<a id="health"></a>
|
||||||
|
## Szenario C — Panel-Ausfall (Tower nicht erreichbar/leer/fehlerhaft)
|
||||||
|
Beobachtung: Panel laedt nicht, Leeranzeige oder Crash; /healthz antwortet nicht.
|
||||||
|
|
||||||
|
Diagnose-Pfad (Reihenfolge, um Server vs. Daten zu trennen):
|
||||||
|
1. Panel -> **/healthz**: 200 = Server lebt -> Problem ist Datenquelle/UI.
|
||||||
|
2. Panel -> **/api/status**: Version, Uptime, Datenquellen-Zustand
|
||||||
|
Prometheus/Beacon. Liefert JSON = API ok.
|
||||||
|
3. Degraded-Banner + Datenalter-Anzeige: bei Prometheus-/Beacon-Ausfall zeigt
|
||||||
|
der Tower Datenalter + 60 s-Cache; das ist Degraded, KEIN Totalausfall.
|
||||||
|
4. Wenn /healthz gar nicht antwortet: Panel-/Prozess-Ausfall am Tower-Host.
|
||||||
|
|
||||||
|
Schritte:
|
||||||
|
1. Degraded (healthz 200, /api/status zeigt Quelle down): keine Panik -
|
||||||
|
Betrieb laeuft mit Cache weiter. Ursache der Quelle pruefen (Beacon-Ausfall
|
||||||
|
= alle Agents rot -> Szenario-A-Umfeld).
|
||||||
|
2. Totalausfall (healthz kein 200 / Verbindung abgelehnt): Tower braucht
|
||||||
|
Neustart/Deploy -> Aenderungsauftrag an tower-owner (nicht selbst am Host
|
||||||
|
eingreifen).
|
||||||
|
3. Waehrend Ausfall: Diagnose ersatzweise ueber die Agenten-Boards/Beacon
|
||||||
|
(Karten-Status, Heartbeat-Zeitstempel) weiterfuehren, Owner informieren.
|
||||||
|
4. Verifikation: /healthz 200 UND /api/status mit allen Quellen "up"; Panel
|
||||||
|
zeigt Datenalter ~0.
|
||||||
|
|
||||||
|
Eskalation: healthz-Ausfall oder Deploy-Bedarf -> sofort P1 an tower-owner
|
||||||
|
(ueber den CISO-Kanal); parallele Owner-Info, da ohne Panel die Lage ueber
|
||||||
|
Agenten nicht sichtbar ist.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Kurz-Anhang: Anzeige am Tower
|
||||||
|
Dieses Runbook + Eskalationskontakt sollen an den Alarm-Ampeln (Deadman-Status
|
||||||
|
-> #deadman, Spool-Aging -> #spool, Dead-Letter -> #deadletter, Health-Ampel ->
|
||||||
|
#health) als kontextueller Hilfe-Link/Inline-Hint erscheinen. Der Hint ist
|
||||||
|
reiner Text (Ueberschrift + interner Link), kein aktives Element; Alarmlogik
|
||||||
|
und Degraded-Banner bleiben unberuehrt. Aenderungsauftrag an tower-owner siehe
|
||||||
|
separater Task "[build] tower-notfall-runbook: Runbook-Link an Alarm-Ampeln".
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* DOM-Smoke-Test Fleet Control Tower (Phase 0.13, Abnahme §8).
|
||||||
|
* 16+ Checks gegen die laufende Tower-Instanz (TOWER_URL, Default localhost:3000).
|
||||||
|
* Werkzeugbestimmt (kein manuelles Klick-Gate): alle Checks muessen PASS sein.
|
||||||
|
*
|
||||||
|
* Checks:
|
||||||
|
* 1-5 Sidebar-Nav (org, messages, board, owner, escalations) sichtbar
|
||||||
|
* 6-14 Org-Chart: 9 Agent-Karten je 3 Status-Elemente (tok/s, inbox, heartbeat)
|
||||||
|
* 15 Message-Feed >= 10 Zeilen
|
||||||
|
* 16 Kanban: 4 Spalten + >= 1 Karte
|
||||||
|
* 17 Escalations-View rendert
|
||||||
|
* 18 CSP-Header vorhanden
|
||||||
|
* 19 Cache-Control no-store auf /api/fleet/*
|
||||||
|
* 20 Idea-Formular vorhanden
|
||||||
|
* 21 New-VS-Formular vorhanden
|
||||||
|
* 22 Chat-Panel vorhanden
|
||||||
|
*/
|
||||||
|
const TOWER_URL = process.env.TOWER_URL || "http://127.0.0.1:3000"
|
||||||
|
|
||||||
|
const results = []
|
||||||
|
let failed = 0
|
||||||
|
|
||||||
|
function check(name, cond, detail = "") {
|
||||||
|
const pass = Boolean(cond)
|
||||||
|
if (!pass) failed += 1
|
||||||
|
results.push(`${pass ? "PASS" : "FAIL"} ${name}${detail ? ` (${detail})` : ""}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
// --- HTML-Render (Views sind client-gerendert — wir pruefen die Shell + Assets)
|
||||||
|
const shellRes = await fetch(TOWER_URL + "/")
|
||||||
|
check("tower-shell-200", shellRes.status === 200, `HTTP ${shellRes.status}`)
|
||||||
|
const csp = shellRes.headers.get("content-security-policy") || ""
|
||||||
|
check("csp-header", csp.includes("default-src 'self'"), csp.slice(0, 60))
|
||||||
|
check("nosniff", (shellRes.headers.get("x-content-type-options") || "") === "nosniff")
|
||||||
|
|
||||||
|
// --- Fleet-API-Routen (fail-loud, 500 wenn Quelle tot — Smoke erwartet Quellen gruen)
|
||||||
|
const overview = await fetch(TOWER_URL + "/api/fleet/overview").then((r) => r.json()).catch(() => null)
|
||||||
|
check("overview-reach", overview && !overview.error, overview?.error || "ok")
|
||||||
|
if (overview && !overview.error) {
|
||||||
|
check("org-9-agents", (overview.agents || []).length === 9, `${(overview.agents || []).length} Agenten`)
|
||||||
|
for (const a of overview.agents || []) {
|
||||||
|
const hasTok = typeof a.tok_in_per_s === "number" && typeof a.tok_out_per_s === "number"
|
||||||
|
const hasInbox = typeof a.inbox === "number"
|
||||||
|
const hasHb = a.heartbeat_age_s === null || typeof a.heartbeat_age_s === "number"
|
||||||
|
check(`org-card-${a.agent_id}`, hasTok && hasInbox && hasHb, `tok=${a.tok_in_per_s} inbox=${a.inbox} hb=${a.heartbeat_age_s}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const messagesRes = await fetch(TOWER_URL + "/api/fleet/messages")
|
||||||
|
check("messages-no-store", (messagesRes.headers.get("cache-control") || "") === "no-store")
|
||||||
|
const messages = await messagesRes.json().catch(() => null)
|
||||||
|
check("messages-reach", messages && !messages.error, messages?.error || "ok")
|
||||||
|
if (messages && !messages.error) {
|
||||||
|
check("messages-count", messages.count >= 10, `${messages.count} Eintraege`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const kanban = await fetch(TOWER_URL + "/api/fleet/kanban").then((r) => r.json()).catch(() => null)
|
||||||
|
check("kanban-reach", kanban && !kanban.error, kanban?.error || "ok")
|
||||||
|
if (kanban && !kanban.error) {
|
||||||
|
check("kanban-4-columns", ["Neu", "Bewertet", "In Bau", "Fertig"].every((c) => c && c.length > 0), "Spalten-Definition via API")
|
||||||
|
const cards = (kanban.boards || []).reduce((n, b) => n + Object.values(b.board?.kanban || {}).flat().length, 0)
|
||||||
|
check("kanban-has-card", cards >= 1, `${cards} Karten`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const escalations = await fetch(TOWER_URL + "/api/fleet/escalations").then((r) => r.json()).catch(() => null)
|
||||||
|
check("escalations-reach", escalations && !escalations.error, escalations?.error || "ok")
|
||||||
|
|
||||||
|
const chat = await fetch(TOWER_URL + "/api/fleet/owner/chat").then((r) => r.json()).catch(() => null)
|
||||||
|
check("owner-chat-reach", chat && !chat.error, chat?.error || "ok")
|
||||||
|
|
||||||
|
// --- Frontend-Shell referenziert Fleet-Views (Build-Artefakt-Check)
|
||||||
|
const buildManifest = await fetch(TOWER_URL + "/").then((r) => r.text()).catch(() => "")
|
||||||
|
check("shell-has-app", buildManifest.includes("_next/static"), "Next-Assets verlinkt")
|
||||||
|
|
||||||
|
console.log(results.join("\n"))
|
||||||
|
console.log(`\n${failed === 0 ? "ALL-CHECKS-PASS" : "CHECKS-FAILED"}: ${results.length - failed}/${results.length}`)
|
||||||
|
process.exit(failed === 0 ? 0 : 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((e) => {
|
||||||
|
console.error("DOM-SMOKE-FATAL:", e)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
@@ -12,7 +12,7 @@ const execFileAsync = promisify(execFile)
|
|||||||
const DASHBOARD_PORT_BASE = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_PORT_BASE || "19000", 10)
|
const DASHBOARD_PORT_BASE = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_PORT_BASE || "19000", 10)
|
||||||
const DASHBOARD_PORT_RANGE = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_PORT_RANGE || "2000", 10)
|
const DASHBOARD_PORT_RANGE = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_PORT_RANGE || "2000", 10)
|
||||||
const REMOTE_DASHBOARD_PORT = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_REMOTE_PORT || "18789", 10)
|
const REMOTE_DASHBOARD_PORT = Number.parseInt(process.env.OPENCLAW_SANDBOX_DASHBOARD_REMOTE_PORT || "18789", 10)
|
||||||
const OPENSHELL_GATEWAY = process.env.OPENSHELL_GATEWAY || "nemoclaw"
|
const OPENSHELL_GATEWAY = process.env.OPENSHELL_GATEWAY?.trim() || undefined
|
||||||
const CONTROL_UI_ORIGIN = process.env.OPENCLAW_SANDBOX_CONTROL_UI_ORIGIN || "http://127.0.0.1:18789"
|
const CONTROL_UI_ORIGIN = process.env.OPENCLAW_SANDBOX_CONTROL_UI_ORIGIN || "http://127.0.0.1:18789"
|
||||||
const CONNECT_TIMEOUT_MS = Number.parseInt(process.env.INTER_SANDBOX_CHAT_OPENCLAW_CONNECT_TIMEOUT_MS || "15000", 10)
|
const CONNECT_TIMEOUT_MS = Number.parseInt(process.env.INTER_SANDBOX_CHAT_OPENCLAW_CONNECT_TIMEOUT_MS || "15000", 10)
|
||||||
const SEND_TIMEOUT_MS = Number.parseInt(process.env.INTER_SANDBOX_CHAT_OPENCLAW_SEND_TIMEOUT_MS || "120000", 10)
|
const SEND_TIMEOUT_MS = Number.parseInt(process.env.INTER_SANDBOX_CHAT_OPENCLAW_SEND_TIMEOUT_MS || "120000", 10)
|
||||||
@@ -28,6 +28,13 @@ const OPENSHELL_BIN = firstExisting([
|
|||||||
"/usr/local/bin/openshell",
|
"/usr/local/bin/openshell",
|
||||||
"/opt/homebrew/bin/openshell",
|
"/opt/homebrew/bin/openshell",
|
||||||
], "openshell")
|
], "openshell")
|
||||||
|
const NEMOCLAW_BIN = firstExisting([
|
||||||
|
process.env.NEMOCLAW_BIN,
|
||||||
|
path.join(os.homedir(), ".local/bin/nemoclaw"),
|
||||||
|
path.join(os.homedir(), ".nemoclaw/source/bin/nemoclaw.js"),
|
||||||
|
"/usr/local/bin/nemoclaw",
|
||||||
|
"/opt/homebrew/bin/nemoclaw",
|
||||||
|
], "nemoclaw")
|
||||||
|
|
||||||
function cleanText(value, fallback = "") {
|
function cleanText(value, fallback = "") {
|
||||||
return String(value ?? fallback).trim()
|
return String(value ?? fallback).trim()
|
||||||
@@ -54,13 +61,16 @@ function getDashboardPort(sandboxName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildSandboxSshArgs(sandboxName, extraArgs) {
|
function buildSandboxSshArgs(sandboxName, extraArgs) {
|
||||||
|
const gatewayOption = OPENSHELL_GATEWAY
|
||||||
|
? ` --gateway-name ${JSON.stringify(OPENSHELL_GATEWAY)}`
|
||||||
|
: ""
|
||||||
return [
|
return [
|
||||||
"-o", "BatchMode=yes",
|
"-o", "BatchMode=yes",
|
||||||
"-o", "StrictHostKeyChecking=no",
|
"-o", "StrictHostKeyChecking=no",
|
||||||
"-o", "UserKnownHostsFile=/dev/null",
|
"-o", "UserKnownHostsFile=/dev/null",
|
||||||
"-o", "GlobalKnownHostsFile=/dev/null",
|
"-o", "GlobalKnownHostsFile=/dev/null",
|
||||||
"-o", "LogLevel=ERROR",
|
"-o", "LogLevel=ERROR",
|
||||||
"-o", `ProxyCommand=${OPENSHELL_BIN} ssh-proxy --gateway-name ${OPENSHELL_GATEWAY} --name ${sandboxName}`,
|
"-o", `ProxyCommand=${OPENSHELL_BIN} ssh-proxy${gatewayOption} --name ${sandboxName}`,
|
||||||
`sandbox@openshell-${sandboxName}`,
|
`sandbox@openshell-${sandboxName}`,
|
||||||
...extraArgs,
|
...extraArgs,
|
||||||
]
|
]
|
||||||
@@ -99,12 +109,17 @@ async function waitForPort(port, timeoutMs = 8000) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function ensureRemoteDashboard(sandboxName) {
|
async function ensureRemoteDashboard(sandboxName) {
|
||||||
const command = [
|
try {
|
||||||
`curl -fsS --max-time 2 http://127.0.0.1:${REMOTE_DASHBOARD_PORT}/ >/dev/null 2>&1`,
|
await execSandboxSsh(sandboxName, `curl -fsS --max-time 2 http://127.0.0.1:${REMOTE_DASHBOARD_PORT}/ >/dev/null`, 5000)
|
||||||
"||",
|
return true
|
||||||
`(nohup /usr/local/bin/openclaw gateway run --allow-unconfigured --bind loopback --port ${REMOTE_DASHBOARD_PORT} >/tmp/gateway.log 2>&1 &)`,
|
} catch {
|
||||||
].join(" ")
|
await execFileAsync(NEMOCLAW_BIN, ["sandbox", "gateway", "restart", sandboxName], {
|
||||||
await execSandboxSsh(sandboxName, command, 15000).catch(() => null)
|
timeout: 90000,
|
||||||
|
maxBuffer: 8 * 1024 * 1024,
|
||||||
|
env: process.env,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureDashboardTunnel(sandboxName, port) {
|
async function ensureDashboardTunnel(sandboxName, port) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ const brokerMcpRoutePath = path.join(root, 'app/api/mcp/broker/mcp/route.ts')
|
|||||||
const sandboxMcpRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/mcp/route.ts')
|
const sandboxMcpRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/mcp/route.ts')
|
||||||
const brokerUrlPath = path.join(root, 'app/lib/mcpBrokerUrl.ts')
|
const brokerUrlPath = path.join(root, 'app/lib/mcpBrokerUrl.ts')
|
||||||
const sandboxOpenClawMcpConfigPath = path.join(root, 'app/lib/sandboxOpenClawMcpConfig.ts')
|
const sandboxOpenClawMcpConfigPath = path.join(root, 'app/lib/sandboxOpenClawMcpConfig.ts')
|
||||||
|
const openClawNativeConfigPath = path.join(root, 'app/lib/openClawNativeConfig.ts')
|
||||||
const sandboxPermissionsPath = path.join(root, 'app/lib/sandboxPermissions.ts')
|
const sandboxPermissionsPath = path.join(root, 'app/lib/sandboxPermissions.ts')
|
||||||
const preflightLibPath = path.join(root, 'app/lib/mcpPreflight.ts')
|
const preflightLibPath = path.join(root, 'app/lib/mcpPreflight.ts')
|
||||||
const preflightRepairLibPath = path.join(root, 'app/lib/mcpPreflightRepair.ts')
|
const preflightRepairLibPath = path.join(root, 'app/lib/mcpPreflightRepair.ts')
|
||||||
@@ -43,7 +44,7 @@ const interSandboxChatPath = path.join(root, 'scripts/inter-sandbox-chat-mcp.mjs
|
|||||||
const interSandboxChatOpenClawDispatchPath = path.join(root, 'scripts/inter-sandbox-chat-openclaw-dispatch.mjs')
|
const interSandboxChatOpenClawDispatchPath = path.join(root, 'scripts/inter-sandbox-chat-openclaw-dispatch.mjs')
|
||||||
const interSandboxChatSidecarPath = path.join(root, 'scripts/inter-sandbox-chat-sidecar.mjs')
|
const interSandboxChatSidecarPath = path.join(root, 'scripts/inter-sandbox-chat-sidecar.mjs')
|
||||||
|
|
||||||
const [storeSource, brokerStoreSource, brokerClientSource, brokerProtocolSource, sandboxAutoSyncSource, manifestSource, privilegedFilesSource, routeSource, uploadRouteSource, preflightRouteSource, healthRouteSource, registryRouteSource, registriesRouteSource, registriesAssistRouteSource, installAssistRouteSource, registryStoreSource, inferenceModelSource, brokerCapabilitiesRouteSource, brokerCallRouteSource, brokerMcpRouteSource, sandboxMcpRouteSource, brokerUrlSource, sandboxOpenClawMcpConfigSource, sandboxPermissionsSource, preflightLibSource, preflightRepairLibSource, mcpServerSpecsSource, middlewareSource, panelSource, helpSource, sidebarSource, sandboxListSource, pageSource, interSandboxChatCoreSource, interSandboxChatSource, interSandboxChatOpenClawDispatchSource, interSandboxChatSidecarSource, serverSource] = await Promise.all([
|
const [storeSource, brokerStoreSource, brokerClientSource, brokerProtocolSource, sandboxAutoSyncSource, manifestSource, privilegedFilesSource, routeSource, uploadRouteSource, preflightRouteSource, healthRouteSource, registryRouteSource, registriesRouteSource, registriesAssistRouteSource, installAssistRouteSource, registryStoreSource, inferenceModelSource, brokerCapabilitiesRouteSource, brokerCallRouteSource, brokerMcpRouteSource, sandboxMcpRouteSource, brokerUrlSource, sandboxOpenClawMcpConfigSource, openClawNativeConfigSource, sandboxPermissionsSource, preflightLibSource, preflightRepairLibSource, mcpServerSpecsSource, middlewareSource, panelSource, helpSource, sidebarSource, sandboxListSource, pageSource, interSandboxChatCoreSource, interSandboxChatSource, interSandboxChatOpenClawDispatchSource, interSandboxChatSidecarSource, serverSource] = await Promise.all([
|
||||||
readFile(storePath, 'utf8'),
|
readFile(storePath, 'utf8'),
|
||||||
readFile(brokerStorePath, 'utf8'),
|
readFile(brokerStorePath, 'utf8'),
|
||||||
readFile(brokerClientPath, 'utf8'),
|
readFile(brokerClientPath, 'utf8'),
|
||||||
@@ -67,6 +68,7 @@ const [storeSource, brokerStoreSource, brokerClientSource, brokerProtocolSource,
|
|||||||
readFile(sandboxMcpRoutePath, 'utf8'),
|
readFile(sandboxMcpRoutePath, 'utf8'),
|
||||||
readFile(brokerUrlPath, 'utf8'),
|
readFile(brokerUrlPath, 'utf8'),
|
||||||
readFile(sandboxOpenClawMcpConfigPath, 'utf8'),
|
readFile(sandboxOpenClawMcpConfigPath, 'utf8'),
|
||||||
|
readFile(openClawNativeConfigPath, 'utf8'),
|
||||||
readFile(sandboxPermissionsPath, 'utf8'),
|
readFile(sandboxPermissionsPath, 'utf8'),
|
||||||
readFile(preflightLibPath, 'utf8'),
|
readFile(preflightLibPath, 'utf8'),
|
||||||
readFile(preflightRepairLibPath, 'utf8'),
|
readFile(preflightRepairLibPath, 'utf8'),
|
||||||
@@ -140,6 +142,8 @@ assert.match(interSandboxChatOpenClawDispatchSource, /WebSocket/, 'Inter-Sandbox
|
|||||||
assert.match(interSandboxChatOpenClawDispatchSource, /openclaw\.json/, 'Inter-Sandbox Chat OpenClaw dispatch must read the sandbox gateway token from OpenClaw config')
|
assert.match(interSandboxChatOpenClawDispatchSource, /openclaw\.json/, 'Inter-Sandbox Chat OpenClaw dispatch must read the sandbox gateway token from OpenClaw config')
|
||||||
assert.match(interSandboxChatOpenClawDispatchSource, /ssh-proxy/, 'Inter-Sandbox Chat OpenClaw dispatch must route through the OpenShell sandbox SSH proxy')
|
assert.match(interSandboxChatOpenClawDispatchSource, /ssh-proxy/, 'Inter-Sandbox Chat OpenClaw dispatch must route through the OpenShell sandbox SSH proxy')
|
||||||
assert.match(interSandboxChatOpenClawDispatchSource, /OPENCLAW_SANDBOX_DASHBOARD_PORT_BASE/, 'Inter-Sandbox Chat OpenClaw dispatch must share controller sandbox dashboard port mapping')
|
assert.match(interSandboxChatOpenClawDispatchSource, /OPENCLAW_SANDBOX_DASHBOARD_PORT_BASE/, 'Inter-Sandbox Chat OpenClaw dispatch must share controller sandbox dashboard port mapping')
|
||||||
|
assert.match(interSandboxChatOpenClawDispatchSource, /NEMOCLAW_BIN[\s\S]*\["sandbox", "gateway", "restart", sandboxName\]/, 'Inter-Sandbox Chat dashboard recovery must use NemoClaw native agent lifecycle')
|
||||||
|
assert.doesNotMatch(interSandboxChatOpenClawDispatchSource, /\/usr\/local\/bin\/openclaw gateway run/, 'Inter-Sandbox Chat must not manually launch OpenClaw in a managed sandbox')
|
||||||
assert.match(serverSource, /inter-sandbox-chat-sidecar\.mjs/, 'OpenShell controller must start the Inter-Sandbox Chat sidecar with the server')
|
assert.match(serverSource, /inter-sandbox-chat-sidecar\.mjs/, 'OpenShell controller must start the Inter-Sandbox Chat sidecar with the server')
|
||||||
assert.match(serverSource, /INTER_SANDBOX_CHAT_SIDECAR_AUTOSTART/, 'OpenShell controller must let operators disable the chat sidecar autostart')
|
assert.match(serverSource, /INTER_SANDBOX_CHAT_SIDECAR_AUTOSTART/, 'OpenShell controller must let operators disable the chat sidecar autostart')
|
||||||
assert.match(brokerProtocolSource, /tools\/list/, 'MCP broker protocol adapter must expose an MCP tools/list JSON-RPC method')
|
assert.match(brokerProtocolSource, /tools\/list/, 'MCP broker protocol adapter must expose an MCP tools/list JSON-RPC method')
|
||||||
@@ -184,10 +188,14 @@ assert.match(brokerUrlSource, /if \(!shouldUseProxyWrappedBrokerUrl\(\)\) return
|
|||||||
assert.match(brokerUrlSource, /discoverSandboxProxyOrigin/, 'Sandbox MCP broker handoff must discover each sandbox proxy endpoint')
|
assert.match(brokerUrlSource, /discoverSandboxProxyOrigin/, 'Sandbox MCP broker handoff must discover each sandbox proxy endpoint')
|
||||||
assert.match(brokerUrlSource, /HTTP_PROXY/, 'Sandbox MCP broker handoff must derive the proxy endpoint from sandbox environment')
|
assert.match(brokerUrlSource, /HTTP_PROXY/, 'Sandbox MCP broker handoff must derive the proxy endpoint from sandbox environment')
|
||||||
assert.match(brokerUrlSource, /FALLBACK_SANDBOX_PROXY_ORIGIN/, 'Sandbox MCP broker handoff may keep a fallback for older OpenShell layouts')
|
assert.match(brokerUrlSource, /FALLBACK_SANDBOX_PROXY_ORIGIN/, 'Sandbox MCP broker handoff may keep a fallback for older OpenShell layouts')
|
||||||
assert.match(sandboxOpenClawMcpConfigSource, /mcp\.servers = servers/, 'Sandbox MCP sync must write mcp.servers into OpenClaw config')
|
assert.match(sandboxOpenClawMcpConfigSource, /writeNativeOpenClawConfigPatch/, 'Sandbox MCP sync must use OpenClaw native config ownership')
|
||||||
|
assert.match(openClawNativeConfigSource, /"openclaw",[\s\S]*"config",[\s\S]*"patch",[\s\S]*"--stdin"/, 'OpenClaw config helper must use the native patch stdin command')
|
||||||
|
assert.match(sandboxOpenClawMcpConfigSource, /\[OPENSHELL_CONTROL_MCP_SERVER_NAME\]: null/, 'Sandbox MCP revoke must remove only the controller-owned native config entry')
|
||||||
|
assert.doesNotMatch(sandboxOpenClawMcpConfigSource, /config-hash|cat > .*openclaw\.json|chmod .*openclaw\.json/, 'Sandbox MCP sync must not replace OpenClaw native config or recreate retired ownership metadata')
|
||||||
assert.match(sandboxOpenClawMcpConfigSource, /streamable-http/, 'OpenClaw MCP broker config must use streamable HTTP transport')
|
assert.match(sandboxOpenClawMcpConfigSource, /streamable-http/, 'OpenClaw MCP broker config must use streamable HTTP transport')
|
||||||
assert.match(sandboxOpenClawMcpConfigSource, /Authorization: `Bearer \$\{token\}`/, 'OpenClaw MCP broker config must pass the sandbox broker token as bearer auth')
|
assert.match(sandboxOpenClawMcpConfigSource, /Authorization: `Bearer \$\{token\}`/, 'OpenClaw MCP broker config must pass the sandbox broker token as bearer auth')
|
||||||
assert.match(sandboxOpenClawMcpConfigSource, /restartOpenClawGatewayIfRunning/, 'OpenClaw gateway must restart after MCP config changes')
|
assert.match(sandboxOpenClawMcpConfigSource, /restartSandboxGatewayWithNemoClaw/, 'MCP config changes must restart through NemoClaw native agent lifecycle')
|
||||||
|
assert.doesNotMatch(sandboxOpenClawMcpConfigSource, /\/proc\/[[]0-9[]][*]|openclaw gateway run/, 'MCP config changes must not kill or launch OpenClaw processes outside NemoClaw lifecycle ownership')
|
||||||
assert.match(sandboxPermissionsSource, /method: "initialize"[\s\S]*method: "POST"/, 'MCP broker network sync must probe the actual streamable HTTP POST initialize path')
|
assert.match(sandboxPermissionsSource, /method: "initialize"[\s\S]*method: "POST"/, 'MCP broker network sync must probe the actual streamable HTTP POST initialize path')
|
||||||
assert.match(sandboxPermissionsSource, /"--input-type=module"/, 'MCP broker network sync probe must support top-level await')
|
assert.match(sandboxPermissionsSource, /"--input-type=module"/, 'MCP broker network sync probe must support top-level await')
|
||||||
assert.match(sandboxPermissionsSource, /await fetch\(/, 'MCP broker network sync probe must wait for the policy-generating request')
|
assert.match(sandboxPermissionsSource, /await fetch\(/, 'MCP broker network sync probe must wait for the policy-generating request')
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ const [helperSource, healthRouteSource, restartRouteSource] = await Promise.all(
|
|||||||
readFile(restartRoutePath, 'utf8'),
|
readFile(restartRoutePath, 'utf8'),
|
||||||
])
|
])
|
||||||
|
|
||||||
assert.match(helperSource, /const NEMOCLAW_RECOVERY_MIN_VERSION = "0\.0\.37"/, 'NemoClaw doctor/recover integration must be gated behind the v0.0.37 CLI surface')
|
assert.match(helperSource, /const NEMOCLAW_LIFECYCLE_MIN_VERSION = "0\.0\.37"/, 'NemoClaw doctor/lifecycle integration must be gated behind the v0.0.37 CLI surface')
|
||||||
assert.match(helperSource, /NEMOCLAW_BIN, NODE_BIN, commandExists, hostCommandEnv/, 'NemoClaw helper must use the shared host command resolver')
|
assert.match(helperSource, /NEMOCLAW_BIN, NODE_BIN, commandExists, hostCommandEnv/, 'NemoClaw helper must use the shared host command resolver')
|
||||||
assert.match(helperSource, /parseVersion/, 'NemoClaw helper must parse CLI versions instead of assuming latest behavior')
|
assert.match(helperSource, /parseVersion/, 'NemoClaw helper must parse CLI versions instead of assuming latest behavior')
|
||||||
assert.match(helperSource, /versionGte/, 'NemoClaw helper must compare semantic versions before using newer commands')
|
assert.match(helperSource, /versionGte/, 'NemoClaw helper must compare semantic versions before using newer commands')
|
||||||
assert.match(helperSource, /export async function getNemoClawDoctorReport/, 'NemoClaw helper must expose a doctor JSON probe')
|
assert.match(helperSource, /export async function getNemoClawDoctorReport/, 'NemoClaw helper must expose a doctor JSON probe')
|
||||||
assert.match(helperSource, /\[sandboxName, "doctor", "--json"\]/, 'doctor probe must use the structured NemoClaw doctor JSON command')
|
assert.match(helperSource, /\[sandboxName, "doctor", "--json"\]/, 'doctor probe must use the structured NemoClaw doctor JSON command')
|
||||||
assert.match(helperSource, /export async function recoverSandboxWithNemoClaw/, 'NemoClaw helper must expose sandbox recovery')
|
assert.match(helperSource, /export async function restartSandboxGatewayWithNemoClaw/, 'NemoClaw helper must expose native sandbox gateway restart')
|
||||||
assert.match(helperSource, /\[sandboxName, "recover"\]/, 'sandbox recovery must use the new NemoClaw recover command')
|
assert.match(helperSource, /\["sandbox", "gateway", "restart", sandboxName\]/, 'sandbox restart must use the canonical NemoClaw native gateway restart command')
|
||||||
assert.match(helperSource, /supported: false,[\s\S]*attempted: false/, 'unsupported old NemoClaw versions must skip newer commands without failing')
|
assert.match(helperSource, /supported: false,[\s\S]*attempted: false/, 'unsupported old NemoClaw versions must skip newer commands without failing')
|
||||||
|
|
||||||
assert.match(healthRouteSource, /getNemoClawDoctorReport/, 'sandbox health must include NemoClaw doctor integration when available')
|
assert.match(healthRouteSource, /getNemoClawDoctorReport/, 'sandbox health must include NemoClaw doctor integration when available')
|
||||||
@@ -28,13 +28,9 @@ assert.match(healthRouteSource, /key: "nemoclaw-doctor"/, 'sandbox health must s
|
|||||||
assert.match(healthRouteSource, /Using OpenShell compatibility checks/, 'sandbox health must explicitly fall back for current NemoClaw versions')
|
assert.match(healthRouteSource, /Using OpenShell compatibility checks/, 'sandbox health must explicitly fall back for current NemoClaw versions')
|
||||||
assert.match(healthRouteSource, /minimumVersion/, 'sandbox health response must expose the minimum version for doctor support')
|
assert.match(healthRouteSource, /minimumVersion/, 'sandbox health response must expose the minimum version for doctor support')
|
||||||
|
|
||||||
assert.match(restartRouteSource, /recoverSandboxWithNemoClaw/, 'sandbox restart must try NemoClaw recover when supported')
|
assert.match(restartRouteSource, /restartSandboxGatewayWithNemoClaw/, 'sandbox restart must use NemoClaw native gateway restart when supported')
|
||||||
assert.ok(
|
assert.match(restartRouteSource, /restartMode: "nemoclaw-native-gateway"/, 'restart route must report the native gateway lifecycle path')
|
||||||
restartRouteSource.indexOf('recoverSandboxWithNemoClaw(sandboxName)') < restartRouteSource.indexOf('runSandboxShell(sandboxName, restartOpenClawGatewayScript()'),
|
assert.match(restartRouteSource, /did not bypass the agent-owned lifecycle boundary/, 'restart route must fail closed when native restart fails')
|
||||||
'sandbox restart must try NemoClaw recover before the legacy OpenClaw runtime restart fallback',
|
assert.doesNotMatch(restartRouteSource, /runSandboxShell|restartOpenClawGatewayScript|openclaw gateway run/, 'sandbox restart must not bypass native agent lifecycle with a manual OpenClaw process launch')
|
||||||
)
|
|
||||||
assert.match(restartRouteSource, /restartMode: "nemoclaw-recover"/, 'restart route must report when the new NemoClaw recovery path succeeds')
|
|
||||||
assert.match(restartRouteSource, /restartMode: "openclaw-runtime"/, 'restart route must retain the current OpenShell/OpenClaw runtime fallback')
|
|
||||||
assert.match(restartRouteSource, /NemoClaw recover did not complete[\s\S]*fell back/, 'restart route must report fallback when modern recovery is attempted but fails')
|
|
||||||
|
|
||||||
console.log('nemoclaw-compat-check: PASS NemoClaw old/new compatibility assertions')
|
console.log('nemoclaw-compat-check: PASS NemoClaw old/new compatibility assertions')
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import {
|
||||||
|
normalizeAgentIdentifier,
|
||||||
|
parseNemoclawListJson,
|
||||||
|
resolveSandboxAgent,
|
||||||
|
} from '../app/lib/nemoclawIdentity.mjs'
|
||||||
|
|
||||||
|
const jsonInventory = JSON.stringify({
|
||||||
|
schemaVersion: 1,
|
||||||
|
sandboxes: [
|
||||||
|
{ name: 'my-hermes', agent: 'Hermes', isDefault: true },
|
||||||
|
{ name: 'gateway-recovered', agent: 'unknown', isDefault: false },
|
||||||
|
{ name: 'custom-agent', agent: 'LangChain DeepAgents Code', isDefault: false },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const parsed = parseNemoclawListJson(jsonInventory)
|
||||||
|
assert.ok(parsed, 'schemaVersion=1 NemoClaw JSON inventory should parse')
|
||||||
|
assert.deepEqual(parsed.defaultSandboxNames, ['my-hermes'])
|
||||||
|
assert.equal(parsed.agentsByName['my-hermes'], 'hermes')
|
||||||
|
assert.equal(parsed.agentsByName['gateway-recovered'], 'unknown')
|
||||||
|
assert.equal(parsed.agentsByName['custom-agent'], 'langchain-deepagents-code')
|
||||||
|
|
||||||
|
assert.equal(resolveSandboxAgent('my-hermes', null, parsed, null), 'hermes')
|
||||||
|
assert.equal(resolveSandboxAgent('gateway-recovered', null, parsed, null), 'unknown')
|
||||||
|
assert.equal(resolveSandboxAgent('missing-from-json', null, parsed, null), 'unknown')
|
||||||
|
|
||||||
|
assert.equal(normalizeAgentIdentifier('OpenClaw'), 'openclaw')
|
||||||
|
assert.equal(normalizeAgentIdentifier('nemohermes'), 'hermes')
|
||||||
|
assert.equal(normalizeAgentIdentifier('unknown'), 'unknown')
|
||||||
|
|
||||||
|
const legacyRegistry = {
|
||||||
|
sandboxes: {
|
||||||
|
'legacy-null-agent': { name: 'legacy-null-agent', agent: null },
|
||||||
|
'explicit-hermes': { name: 'explicit-hermes', agent: 'Hermes' },
|
||||||
|
'explicit-unknown': { name: 'explicit-unknown', agent: 'unknown' },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(resolveSandboxAgent('legacy-null-agent', null, null, legacyRegistry), 'openclaw')
|
||||||
|
assert.equal(resolveSandboxAgent('explicit-hermes', null, null, legacyRegistry), 'hermes')
|
||||||
|
assert.equal(resolveSandboxAgent('explicit-unknown', null, null, legacyRegistry), 'unknown')
|
||||||
|
|
||||||
|
assert.equal(parseNemoclawListJson('{'), null, 'invalid JSON must fail closed')
|
||||||
|
assert.equal(parseNemoclawListJson(JSON.stringify({ schemaVersion: 2, sandboxes: [] })), null, 'unsupported schema versions must fail closed')
|
||||||
|
|
||||||
|
console.log('nemoclaw-identity-resolution-check: PASS json identity resolution assertions')
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||||
|
import os from 'node:os'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
import {
|
||||||
|
discoverNemoClawRegistryFiles,
|
||||||
|
findNemoClawRegistryEntry,
|
||||||
|
listNemoClawRegistryCandidates,
|
||||||
|
} from '../app/lib/nemoclawRegistry.mjs'
|
||||||
|
|
||||||
|
const home = await mkdtemp(path.join(os.tmpdir(), 'nemoclaw-registry-roots-'))
|
||||||
|
try {
|
||||||
|
const root = path.join(home, '.nemoclaw')
|
||||||
|
await mkdir(path.join(root, 'gateways', '8990'), { recursive: true })
|
||||||
|
await mkdir(path.join(root, 'gateways', 'not-a-port'), { recursive: true })
|
||||||
|
await writeFile(path.join(root, 'sandboxes.json'), JSON.stringify({
|
||||||
|
defaultSandbox: 'base-box',
|
||||||
|
sandboxes: {
|
||||||
|
'base-box': { name: 'base-box', imageTag: 'base:image', createdAt: '2026-09-01' },
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
await writeFile(path.join(root, 'gateways', '8990', 'sandboxes.json'), JSON.stringify({
|
||||||
|
defaultSandbox: 'port-box',
|
||||||
|
sandboxes: {
|
||||||
|
'port-box': { name: 'port-box', imageTag: 'port:image', createdAt: '2026-09-02' },
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
await writeFile(path.join(root, 'gateways', 'not-a-port', 'sandboxes.json'), '{}')
|
||||||
|
|
||||||
|
const files = discoverNemoClawRegistryFiles(home)
|
||||||
|
assert.deepEqual(files, [
|
||||||
|
path.join(root, 'sandboxes.json'),
|
||||||
|
path.join(root, 'gateways', '8990', 'sandboxes.json'),
|
||||||
|
], 'registry discovery must include the default root and numeric alternate-port roots only')
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
findNemoClawRegistryEntry('port-box', home)?.entry.imageTag,
|
||||||
|
'port:image',
|
||||||
|
'quick deploy must resolve image metadata from an alternate-port registry',
|
||||||
|
)
|
||||||
|
assert.deepEqual(
|
||||||
|
listNemoClawRegistryCandidates(home),
|
||||||
|
['base-box', 'port-box'],
|
||||||
|
'defaults remain first and registered candidates are deduplicated across roots',
|
||||||
|
)
|
||||||
|
|
||||||
|
await writeFile(path.join(root, 'sandboxes.json'), JSON.stringify({
|
||||||
|
sandboxes: { duplicate: { name: 'port-box', imageTag: 'wrong:image' } },
|
||||||
|
}))
|
||||||
|
assert.throws(
|
||||||
|
() => findNemoClawRegistryEntry('port-box', home),
|
||||||
|
/multiple NemoClaw gateway registries/,
|
||||||
|
'ambiguous cross-port registrations must fail closed',
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('nemoclaw-registry-roots-check: PASS cross-port registry resolution assertions')
|
||||||
|
} finally {
|
||||||
|
await rm(home, { recursive: true, force: true })
|
||||||
|
}
|
||||||
@@ -54,10 +54,10 @@ assert.match(installSource, /python3 -m venv "\$PROJECT_VENV"/, 'installer must
|
|||||||
assert.match(installSource, /\$venv_python" -m pip install --upgrade uv/, 'installer must install uvx into the virtual environment')
|
assert.match(installSource, /\$venv_python" -m pip install --upgrade uv/, 'installer must install uvx into the virtual environment')
|
||||||
assert.match(installSource, /set_env "OPENSHELL_CONTROL_VENV"/, 'installer must persist the virtual environment path for runtime MCP launches')
|
assert.match(installSource, /set_env "OPENSHELL_CONTROL_VENV"/, 'installer must persist the virtual environment path for runtime MCP launches')
|
||||||
|
|
||||||
assert.match(versionedInstallSource, /OPENSHELL_VERSION="\$\{OPENSHELL_VERSION:-v0\.0\.106\}"/, 'versioned installer must default to the OpenShell release supported by current NemoClaw main')
|
assert.match(versionedInstallSource, /OPENSHELL_VERSION="\$\{OPENSHELL_VERSION:-v0\.0\.116\}"/, 'versioned installer must default to the OpenShell release supported by current NemoClaw main')
|
||||||
assert.match(versionedInstallSource, /NEMOCLAW_INSTALL_REF="\$\{NEMOCLAW_INSTALL_REF:-\$\{NEMOCLAW_INSTALL_TAG:-main\}\}"/, 'versioned installer must track the current NemoClaw main ref by default')
|
assert.match(versionedInstallSource, /NEMOCLAW_INSTALL_REF="\$\{NEMOCLAW_INSTALL_REF:-\$\{NEMOCLAW_INSTALL_TAG:-main\}\}"/, 'versioned installer must track the current NemoClaw main ref by default')
|
||||||
assert.match(versionedInstallSource, /NEMOCLAW_SOURCE_URL="\$\{NEMOCLAW_SOURCE_URL:-https:\/\/github\.com\/NVIDIA\/NemoClaw\.git\}"/, 'versioned installer must use the NemoClaw source repository URL')
|
assert.match(versionedInstallSource, /NEMOCLAW_SOURCE_URL="\$\{NEMOCLAW_SOURCE_URL:-https:\/\/github\.com\/NVIDIA\/NemoClaw\.git\}"/, 'versioned installer must use the NemoClaw source repository URL')
|
||||||
assert.match(versionedInstallSource, /OPENCLAW_VERSION="\$\{OPENCLAW_VERSION:-2026\.7\.1\}"/, 'versioned installer must default to NemoClaw main\'s current OpenClaw build target')
|
assert.match(versionedInstallSource, /OPENCLAW_VERSION="\$\{OPENCLAW_VERSION:-2026\.9\.2\}"/, 'versioned installer must default to NemoClaw main\'s current OpenClaw build target')
|
||||||
assert.match(versionedInstallSource, /https:\/\/raw\.githubusercontent\.com\/NVIDIA\/OpenShell\/main\/install\.sh/, 'versioned installer must use the OpenShell installer URL')
|
assert.match(versionedInstallSource, /https:\/\/raw\.githubusercontent\.com\/NVIDIA\/OpenShell\/main\/install\.sh/, 'versioned installer must use the OpenShell installer URL')
|
||||||
assert.match(versionedInstallSource, /git -C "\$source_dir" fetch[\s\S]*"\$NEMOCLAW_INSTALL_REF"/, 'versioned installer must fetch NemoClaw from the selected git ref')
|
assert.match(versionedInstallSource, /git -C "\$source_dir" fetch[\s\S]*"\$NEMOCLAW_INSTALL_REF"/, 'versioned installer must fetch NemoClaw from the selected git ref')
|
||||||
assert.match(versionedInstallSource, /Requested NemoClaw install ref/, 'versioned installer must fail clearly when the selected NemoClaw ref is unavailable')
|
assert.match(versionedInstallSource, /Requested NemoClaw install ref/, 'versioned installer must fail clearly when the selected NemoClaw ref is unavailable')
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ assert.match(terminalReadinessSource, /const authority = resolveRuntimeAuthority
|
|||||||
assert.match(telemetrySource, /authoritySource: "runtimeAuthority"/, 'inventory route must declare shared authority source')
|
assert.match(telemetrySource, /authoritySource: "runtimeAuthority"/, 'inventory route must declare shared authority source')
|
||||||
assert.match(telemetrySource, /authorities: authorities\.map\(/, 'inventory route must expose per-sandbox authority metadata')
|
assert.match(telemetrySource, /authorities: authorities\.map\(/, 'inventory route must expose per-sandbox authority metadata')
|
||||||
assert.match(openshellHostSource, /const OPENSHELL_GATEWAY = process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'OpenShell host commands must not force the legacy openshell gateway when NemoClaw has selected the nemoclaw gateway')
|
assert.match(openshellHostSource, /const OPENSHELL_GATEWAY = process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'OpenShell host commands must not force the legacy openshell gateway when NemoClaw has selected the nemoclaw gateway')
|
||||||
|
assert.match(openshellHostSource, /ssh-proxy\$\{gatewayOption\}/, 'sandbox SSH proxy commands must make the explicit gateway option conditional')
|
||||||
|
assert.doesNotMatch(openshellHostSource, /ssh-proxy --gateway-name nemoclaw/, 'sandbox SSH proxy commands must not force the legacy unqualified NemoClaw gateway')
|
||||||
|
assert.match(openshellHostSource, /restartSandboxGatewayWithNemoClaw\(sandboxName\)/, 'sandbox dashboard recovery must use NemoClaw native agent lifecycle')
|
||||||
|
assert.doesNotMatch(openshellHostSource, /\/usr\/local\/bin\/openclaw gateway run/, 'sandbox dashboard recovery must not manually launch OpenClaw')
|
||||||
assert.match(sandboxHealthSource, /stripAnsi/, 'sandbox health must strip OpenShell ANSI styling before parsing fields such as Phase')
|
assert.match(sandboxHealthSource, /stripAnsi/, 'sandbox health must strip OpenShell ANSI styling before parsing fields such as Phase')
|
||||||
assert.match(openshellHostSource, /const canMintBootstrapFromCli = instance\.id === defaultInstance\.id/, 'bootstrap minting should only use CLI for the default OpenClaw instance')
|
assert.match(openshellHostSource, /const canMintBootstrapFromCli = instance\.id === defaultInstance\.id/, 'bootstrap minting should only use CLI for the default OpenClaw instance')
|
||||||
assert.match(openshellHostSource, /readSandboxOpenClawDashboardToken/, 'sandbox dashboard bootstrap must fall back to the sandbox OpenClaw token when CLI output is bare')
|
assert.match(openshellHostSource, /readSandboxOpenClawDashboardToken/, 'sandbox dashboard bootstrap must fall back to the sandbox OpenClaw token when CLI output is bare')
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const ollamaModelsRoutePath = path.join(root, 'app/api/ollama/models/route.ts')
|
|||||||
const sandboxInferenceRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/inference/route.ts')
|
const sandboxInferenceRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/inference/route.ts')
|
||||||
const sandboxInferenceApplyRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/inference/apply/route.ts')
|
const sandboxInferenceApplyRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/inference/apply/route.ts')
|
||||||
const sandboxInferenceApplyLibPath = path.join(root, 'app/lib/sandboxInferenceApply.ts')
|
const sandboxInferenceApplyLibPath = path.join(root, 'app/lib/sandboxInferenceApply.ts')
|
||||||
|
const openClawNativeConfigPath = path.join(root, 'app/lib/openClawNativeConfig.ts')
|
||||||
const sandboxInferenceStorePath = path.join(root, 'app/lib/sandboxInferenceStore.ts')
|
const sandboxInferenceStorePath = path.join(root, 'app/lib/sandboxInferenceStore.ts')
|
||||||
const sandboxRestartRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/restart/route.ts')
|
const sandboxRestartRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/restart/route.ts')
|
||||||
const gatewayRepairRoutePath = path.join(root, 'app/api/openshell/gateway/repair/route.ts')
|
const gatewayRepairRoutePath = path.join(root, 'app/api/openshell/gateway/repair/route.ts')
|
||||||
@@ -24,6 +25,7 @@ const versionedInstallerPath = path.join(root, 'install_versioned_nemoclaw_opens
|
|||||||
const hookPath = path.join(root, 'app/hooks/useSandboxInventory.ts')
|
const hookPath = path.join(root, 'app/hooks/useSandboxInventory.ts')
|
||||||
const pagePath = path.join(root, 'app/page.tsx')
|
const pagePath = path.join(root, 'app/page.tsx')
|
||||||
const configPanelPath = path.join(root, 'app/components/ConfigurationPanel.tsx')
|
const configPanelPath = path.join(root, 'app/components/ConfigurationPanel.tsx')
|
||||||
|
const wizardPanelPath = path.join(root, 'app/components/WizardPanel.tsx')
|
||||||
const activityPanelPath = path.join(root, 'app/components/ActivityPanel.tsx')
|
const activityPanelPath = path.join(root, 'app/components/ActivityPanel.tsx')
|
||||||
const inferencePanelPath = path.join(root, 'app/components/InferenceEndpointPanel.tsx')
|
const inferencePanelPath = path.join(root, 'app/components/InferenceEndpointPanel.tsx')
|
||||||
const sandboxInferencePanelPath = path.join(root, 'app/components/SandboxInferencePanel.tsx')
|
const sandboxInferencePanelPath = path.join(root, 'app/components/SandboxInferencePanel.tsx')
|
||||||
@@ -45,6 +47,7 @@ const ollamaModelsRouteSource = await readFile(ollamaModelsRoutePath, 'utf8')
|
|||||||
const sandboxInferenceRouteSource = await readFile(sandboxInferenceRoutePath, 'utf8')
|
const sandboxInferenceRouteSource = await readFile(sandboxInferenceRoutePath, 'utf8')
|
||||||
const sandboxInferenceApplyRouteSource = await readFile(sandboxInferenceApplyRoutePath, 'utf8')
|
const sandboxInferenceApplyRouteSource = await readFile(sandboxInferenceApplyRoutePath, 'utf8')
|
||||||
const sandboxInferenceApplyLibSource = await readFile(sandboxInferenceApplyLibPath, 'utf8')
|
const sandboxInferenceApplyLibSource = await readFile(sandboxInferenceApplyLibPath, 'utf8')
|
||||||
|
const openClawNativeConfigSource = await readFile(openClawNativeConfigPath, 'utf8')
|
||||||
const sandboxInferenceStoreSource = await readFile(sandboxInferenceStorePath, 'utf8')
|
const sandboxInferenceStoreSource = await readFile(sandboxInferenceStorePath, 'utf8')
|
||||||
const sandboxRestartRouteSource = await readFile(sandboxRestartRoutePath, 'utf8')
|
const sandboxRestartRouteSource = await readFile(sandboxRestartRoutePath, 'utf8')
|
||||||
const gatewayRepairRouteSource = await readFile(gatewayRepairRoutePath, 'utf8')
|
const gatewayRepairRouteSource = await readFile(gatewayRepairRoutePath, 'utf8')
|
||||||
@@ -53,6 +56,7 @@ const versionedInstallerSource = await readFile(versionedInstallerPath, 'utf8')
|
|||||||
const hookSource = await readFile(hookPath, 'utf8')
|
const hookSource = await readFile(hookPath, 'utf8')
|
||||||
const pageSource = await readFile(pagePath, 'utf8')
|
const pageSource = await readFile(pagePath, 'utf8')
|
||||||
const configPanelSource = await readFile(configPanelPath, 'utf8')
|
const configPanelSource = await readFile(configPanelPath, 'utf8')
|
||||||
|
const wizardPanelSource = await readFile(wizardPanelPath, 'utf8')
|
||||||
const activityPanelSource = await readFile(activityPanelPath, 'utf8')
|
const activityPanelSource = await readFile(activityPanelPath, 'utf8')
|
||||||
const inferencePanelSource = await readFile(inferencePanelPath, 'utf8')
|
const inferencePanelSource = await readFile(inferencePanelPath, 'utf8')
|
||||||
const sandboxInferencePanelSource = await readFile(sandboxInferencePanelPath, 'utf8')
|
const sandboxInferencePanelSource = await readFile(sandboxInferencePanelPath, 'utf8')
|
||||||
@@ -94,6 +98,8 @@ assert.match(createRouteSource, /mode === "none"[\s\S]*return \["--no-gpu"\]/, '
|
|||||||
assert.match(createRouteSource, /openShellGpuArgs\(mode: CreateGpuMode\)/, 'OpenShell create paths must share GPU request handling')
|
assert.match(createRouteSource, /openShellGpuArgs\(mode: CreateGpuMode\)/, 'OpenShell create paths must share GPU request handling')
|
||||||
assert.doesNotMatch(createRouteSource, /resolvePreferredNemoClawDockerfile|prepareDashboardOwnedNemoClawDockerfile/, 'blueprint create must not force the explicit Dockerfile path')
|
assert.doesNotMatch(createRouteSource, /resolvePreferredNemoClawDockerfile|prepareDashboardOwnedNemoClawDockerfile/, 'blueprint create must not force the explicit Dockerfile path')
|
||||||
assert.match(createRouteSource, /NEMOCLAW_SANDBOX_NAME: sandboxName/, 'blueprint create must pass the requested sandbox name to NemoClaw onboarding')
|
assert.match(createRouteSource, /NEMOCLAW_SANDBOX_NAME: sandboxName/, 'blueprint create must pass the requested sandbox name to NemoClaw onboarding')
|
||||||
|
assert.match(createRouteSource, /name\.length > 19/, 'create API must enforce NemoClaw\'s 19-character routed sandbox-name limit')
|
||||||
|
assert.match(createRouteSource, /\^\(\?!\.\*--\)\[a-z\]/, 'create API must require a leading lowercase letter and reject consecutive hyphens')
|
||||||
assert.match(createRouteSource, /id: "redeploy-image"/, 'create API must expose image redeploy as a sandbox creation path')
|
assert.match(createRouteSource, /id: "redeploy-image"/, 'create API must expose image redeploy as a sandbox creation path')
|
||||||
assert.match(createRouteSource, /label: "Quick Deploy New NemoClaw Sandbox"/, 'image redeploy must be labeled as the quick deploy default path')
|
assert.match(createRouteSource, /label: "Quick Deploy New NemoClaw Sandbox"/, 'image redeploy must be labeled as the quick deploy default path')
|
||||||
assert.match(createRouteSource, /label: "Fresh NemoClaw Image"/, 'full rebuild path must be labeled as fresh image creation')
|
assert.match(createRouteSource, /label: "Fresh NemoClaw Image"/, 'full rebuild path must be labeled as fresh image creation')
|
||||||
@@ -102,7 +108,7 @@ assert.match(createRouteSource, /label: "Fresh Hermes Sandbox"/, 'Hermes sandbox
|
|||||||
assert.match(createRouteSource, /source: "~\/NemoClaw\/agents\/hermes\/Dockerfile"/, 'Hermes sandbox creation must point at the upstream Hermes agent source')
|
assert.match(createRouteSource, /source: "~\/NemoClaw\/agents\/hermes\/Dockerfile"/, 'Hermes sandbox creation must point at the upstream Hermes agent source')
|
||||||
assert.match(createRouteSource, /id: "nemoclaw-deepagents-code"/, 'create API must expose Deep Agents Code sandbox creation')
|
assert.match(createRouteSource, /id: "nemoclaw-deepagents-code"/, 'create API must expose Deep Agents Code sandbox creation')
|
||||||
assert.match(createRouteSource, /source: "~\/NemoClaw\/agents\/langchain-deepagents-code\/manifest\.yaml"/, 'Deep Agents Code sandbox creation must point at the upstream agent manifest')
|
assert.match(createRouteSource, /source: "~\/NemoClaw\/agents\/langchain-deepagents-code\/manifest\.yaml"/, 'Deep Agents Code sandbox creation must point at the upstream agent manifest')
|
||||||
assert.match(createRouteSource, /readNemoClawRegistry/, 'image redeploy must discover the default NemoClaw sandbox image automatically')
|
assert.match(createRouteSource, /findNemoClawRegistryEntry/, 'image redeploy must discover NemoClaw sandbox images across default and alternate-port registries')
|
||||||
assert.match(createRouteSource, /listOpenShellSandboxNames/, 'image redeploy must fall back to live OpenShell inventory when registry entries are stale')
|
assert.match(createRouteSource, /listOpenShellSandboxNames/, 'image redeploy must fall back to live OpenShell inventory when registry entries are stale')
|
||||||
assert.match(createRouteSource, /resolveSourcePodImage\(sourceSandboxName, sandboxName\)/, 'image redeploy must allow optional explicit source while defaulting automatically')
|
assert.match(createRouteSource, /resolveSourcePodImage\(sourceSandboxName, sandboxName\)/, 'image redeploy must allow optional explicit source while defaulting automatically')
|
||||||
assert.match(createRouteSource, /"--from",\s*sourceImage/, 'image redeploy must pass the resolved image to openshell sandbox create')
|
assert.match(createRouteSource, /"--from",\s*sourceImage/, 'image redeploy must pass the resolved image to openshell sandbox create')
|
||||||
@@ -110,7 +116,7 @@ assert.match(createRouteSource, /registryEntry\?\.imageTag\?\.trim\(\)/, 'image
|
|||||||
assert.doesNotMatch(createRouteSource, /OPENSHELL_CLUSTER_CONTAINER|readPodImage|"kubectl"/, 'image redeploy must not depend on obsolete cluster containers or in-container kubectl')
|
assert.doesNotMatch(createRouteSource, /OPENSHELL_CLUSTER_CONTAINER|readPodImage|"kubectl"/, 'image redeploy must not depend on obsolete cluster containers or in-container kubectl')
|
||||||
assert.match(createRouteSource, /"--auto-providers"/, 'image redeploy must use OpenShell auto providers for provider-backed images')
|
assert.match(createRouteSource, /"--auto-providers"/, 'image redeploy must use OpenShell auto providers for provider-backed images')
|
||||||
assert.match(createRouteSource, /skippedNemoClawImageRedeployRegistration/, 'image redeploy must report that NemoClaw registry registration was deliberately skipped')
|
assert.match(createRouteSource, /skippedNemoClawImageRedeployRegistration/, 'image redeploy must report that NemoClaw registry registration was deliberately skipped')
|
||||||
assert.match(createRouteSource, /lifecycle, policy-authority, and workload receipts that only NemoClaw can issue safely/, 'image redeploy must explain why direct NemoClaw registry writes are unsafe')
|
assert.match(createRouteSource, /lifecycle identity, workload provenance, and agent-specific state that only NemoClaw can issue safely/, 'image redeploy must explain why direct NemoClaw registry writes are unsafe')
|
||||||
assert.doesNotMatch(createRouteSource, /function registerNemoClawImageRedeploy|writeFileSync\(tempPath|renameSync\(tempPath/, 'image redeploy must not forge current NemoClaw registry entries by copying source-bound authority receipts')
|
assert.doesNotMatch(createRouteSource, /function registerNemoClawImageRedeploy|writeFileSync\(tempPath|renameSync\(tempPath/, 'image redeploy must not forge current NemoClaw registry entries by copying source-bound authority receipts')
|
||||||
assert.match(createRouteSource, /readyVerification\?: SandboxVerification/, 'ready-aware create command must carry the authoritative verification result')
|
assert.match(createRouteSource, /readyVerification\?: SandboxVerification/, 'ready-aware create command must carry the authoritative verification result')
|
||||||
assert.match(createRouteSource, /readyVerification: verification/, 'ready-aware create command must return the verification that proved readiness')
|
assert.match(createRouteSource, /readyVerification: verification/, 'ready-aware create command must return the verification that proved readiness')
|
||||||
@@ -124,36 +130,15 @@ assert.match(createRouteSource, /NEMOCLAW_ENDPOINT_URL = settings\.endpointUrl/,
|
|||||||
assert.match(createRouteSource, /COMPATIBLE_API_KEY = apiKey \|\| "dummy"/, 'OpenAI-compatible onboarding must pass COMPATIBLE_API_KEY or a no-auth placeholder')
|
assert.match(createRouteSource, /COMPATIBLE_API_KEY = apiKey \|\| "dummy"/, 'OpenAI-compatible onboarding must pass COMPATIBLE_API_KEY or a no-auth placeholder')
|
||||||
assert.match(createRouteSource, /NEMOCLAW_PROVIDER_KEY = env\.COMPATIBLE_API_KEY/, 'OpenAI-compatible onboarding must bridge the provider key without printing secrets')
|
assert.match(createRouteSource, /NEMOCLAW_PROVIDER_KEY = env\.COMPATIBLE_API_KEY/, 'OpenAI-compatible onboarding must bridge the provider key without printing secrets')
|
||||||
assert.match(createRouteSource, /Hosted NVIDIA Build onboarding requires an nvapi-\*/, 'blueprint create must reject non-nvapi keys for the hosted NVIDIA build provider')
|
assert.match(createRouteSource, /Hosted NVIDIA Build onboarding requires an nvapi-\*/, 'blueprint create must reject non-nvapi keys for the hosted NVIDIA build provider')
|
||||||
assert.match(versionedInstallerSource, /OPENSHELL_VERSION="\$\{OPENSHELL_VERSION:-v0\.0\.106\}"/, 'versioned installer must default to the OpenShell release supported by current NemoClaw main')
|
assert.match(versionedInstallerSource, /OPENSHELL_VERSION="\$\{OPENSHELL_VERSION:-v0\.0\.116\}"/, 'versioned installer must default to the OpenShell release supported by current NemoClaw main')
|
||||||
assert.match(versionedInstallerSource, /NEMOCLAW_INSTALL_REF="\$\{NEMOCLAW_INSTALL_REF:-\$\{NEMOCLAW_INSTALL_TAG:-main\}\}"/, 'versioned installer must track the current NemoClaw main ref by default while preserving the legacy tag override')
|
assert.match(versionedInstallerSource, /NEMOCLAW_INSTALL_REF="\$\{NEMOCLAW_INSTALL_REF:-\$\{NEMOCLAW_INSTALL_TAG:-main\}\}"/, 'versioned installer must track the current NemoClaw main ref by default while preserving the legacy tag override')
|
||||||
assert.match(versionedInstallerSource, /OPENCLAW_VERSION="\$\{OPENCLAW_VERSION:-2026\.7\.1\}"/, 'versioned installer must pin the current NemoClaw-compatible OpenClaw base image version')
|
assert.match(versionedInstallerSource, /OPENCLAW_VERSION="\$\{OPENCLAW_VERSION:-2026\.9\.2\}"/, 'versioned installer must pin the current NemoClaw-compatible OpenClaw base image version')
|
||||||
assert.match(versionedInstallerSource, /git -C "\$source_dir" fetch[\s\S]*"\$NEMOCLAW_INSTALL_REF"/, 'versioned installer must fetch NemoClaw by git ref so branch heads and tags both work')
|
assert.match(versionedInstallerSource, /git -C "\$source_dir" fetch[\s\S]*"\$NEMOCLAW_INSTALL_REF"/, 'versioned installer must fetch NemoClaw by git ref so branch heads and tags both work')
|
||||||
assert.match(versionedInstallerSource, /docker build[\s\S]*Dockerfile\.base[\s\S]*--build-arg "OPENCLAW_VERSION=\$OPENCLAW_VERSION"[\s\S]*"\$source_dir"/, 'versioned installer must rebuild the stock NemoClaw base image with the pinned OpenClaw version')
|
assert.match(versionedInstallerSource, /docker build[\s\S]*Dockerfile\.base[\s\S]*--build-arg "OPENCLAW_VERSION=\$OPENCLAW_VERSION"[\s\S]*"\$source_dir"/, 'versioned installer must rebuild the stock NemoClaw base image with the pinned OpenClaw version')
|
||||||
assert.doesNotMatch(createRouteSource, /repairOpenClawRuntimePolicy|runtimePolicyRepair/, 'sandbox create must not mutate OpenShell filesystem policy for OpenClaw')
|
assert.doesNotMatch(createRouteSource, /repairOpenClawRuntimePolicy|runtimePolicyRepair/, 'sandbox create must not mutate OpenShell filesystem policy for OpenClaw')
|
||||||
assert.doesNotMatch(createRouteSource, /stabilizeOpenClawGatewayConfig|gatewayConfigRepair|repairOpenClawWorkspacePermissions|workspaceRepair/, 'sandbox create must not patch OpenClaw internals after the Monday rollback')
|
assert.doesNotMatch(createRouteSource, /stabilizeOpenClawGatewayConfig|gatewayConfigRepair|repairOpenClawWorkspacePermissions|workspaceRepair|repairOpenClawExecApprovalsFile|execApprovalsRepair/, 'sandbox create must not patch OpenClaw internals owned by current NemoClaw images')
|
||||||
assert.match(createRouteSource, /repairOpenClawExecApprovalsFile/, 'sandbox create may apply the narrow exec approvals symlink compatibility repair')
|
|
||||||
assert.match(createRouteSource, /execApprovalsRepair/, 'sandbox create response must report the narrow exec approvals compatibility repair')
|
|
||||||
assert.match(createRouteSource, /created && isOpenClawAgent \? await repairOpenClawExecApprovalsFile/, 'Hermes create must skip OpenClaw-only exec approvals repair')
|
|
||||||
assert.match(createRouteSource, /created && isOpenClawAgent \? await approveOpenClawDeviceRequests/, 'Hermes create must skip OpenClaw-only device approval')
|
assert.match(createRouteSource, /created && isOpenClawAgent \? await approveOpenClawDeviceRequests/, 'Hermes create must skip OpenClaw-only device approval')
|
||||||
assert.doesNotMatch(sandboxPrivilegedFilesSource, /openshell-openclaw-policy-|"policy", "set"|withoutReadOnlyOpenClaw/, 'OpenClaw repair must not mutate OpenShell filesystem policy')
|
assert.doesNotMatch(sandboxPrivilegedFilesSource, /exec-approvals\.json|openclaw gateway run|plugins\.entries\.bonjour|\.openclaw-data/, 'privileged file helper must not recreate retired OpenClaw state or bypass NemoClaw lifecycle ownership')
|
||||||
assert.match(sandboxPrivilegedFilesSource, /plugins\.entries\.bonjour/, 'gateway config stabilization must disable the crashing Bonjour plugin')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /sha256sum openclaw\.json > \.config-hash/, 'gateway config stabilization must refresh OpenClaw config hash')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /openclaw gateway run/, 'gateway config stabilization must restart the OpenClaw gateway')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /"workspace"/, 'workspace repair must target the OpenClaw workspace directory')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /\/sandbox\/\.openclaw-data\/\$dir/, 'workspace repair must use the policy-writable OpenClaw data tree')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /ln -sfn/, 'workspace repair must link the OpenClaw workspace path into writable storage')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /"flows"/, 'workspace repair must include the stock NemoClaw flows symlink')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /"plugin-runtime-deps"/, 'workspace repair must include the OpenClaw plugin runtime dependency directory')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /"update-check\.json"/, 'workspace repair must include the stock NemoClaw update-check symlink')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /exec-approvals\.json/, 'workspace repair must include exec approval state handling')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /const mutableFiles = \[\s*"update-check\.json",\s*\]/, 'workspace repair must not leave exec approvals in the symlinked mutable files list for newer OpenClaw')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /chmod 0600 \/sandbox\/\.openclaw\/exec-approvals\.json/, 'workspace repair must make exec approvals a real writable file for newer OpenClaw')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /chown -R sandbox:sandbox \/sandbox\/\.openclaw-data/, 'workspace repair must restore stock NemoClaw ownership for OpenClaw data')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /AGENTS\.md/, 'workspace repair note must document the AGENTS.md permission failure it prevents')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /"agents"/, 'workspace repair must target the OpenClaw agent directory so sessions are writable through .openclaw-data')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /"agents"[\s\S]*"workspace"[\s\S]*"memory"/, 'workspace repair must cover NemoClaw expected OpenClaw mutable symlink directories')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /sessions\.json\.lock|session lock/, 'workspace repair note must document the sessions.json.lock permission failure it prevents')
|
|
||||||
assert.match(sandboxPrivilegedFilesSource, /bundled OpenClaw expects/, 'workspace repair note must document the dashboard reconciles to the bundled OpenClaw expectations')
|
|
||||||
|
|
||||||
assert.match(hookSource, /type RefreshOptions = \{\s*force\?: boolean\s*\}/, 'inventory refresh must accept a force option')
|
assert.match(hookSource, /type RefreshOptions = \{\s*force\?: boolean\s*\}/, 'inventory refresh must accept a force option')
|
||||||
assert.match(hookSource, /!refreshOptions\?\.force && inFlightRef\.current/, 'forced inventory refresh must bypass existing in-flight reads')
|
assert.match(hookSource, /!refreshOptions\?\.force && inFlightRef\.current/, 'forced inventory refresh must bypass existing in-flight reads')
|
||||||
@@ -168,7 +153,7 @@ assert.match(deleteRouteSource, /workspace-\*/, 'persistent state wipe must incl
|
|||||||
assert.match(pageSource, /JSON\.stringify\(\{ sandboxName, agent: sandbox\?\.agent \|\| 'openclaw' \}\)/, 'destroy workflow must pass the selected NemoClaw agent to delete state cleanup')
|
assert.match(pageSource, /JSON\.stringify\(\{ sandboxName, agent: sandbox\?\.agent \|\| 'openclaw' \}\)/, 'destroy workflow must pass the selected NemoClaw agent to delete state cleanup')
|
||||||
assert.match(deleteRouteSource, /validateSandboxName/, 'delete route must validate sandbox names before execution')
|
assert.match(deleteRouteSource, /validateSandboxName/, 'delete route must validate sandbox names before execution')
|
||||||
assert.match(deleteRouteSource, /resolveSandboxRef/, 'delete route must resolve sandbox ids to names before deleting')
|
assert.match(deleteRouteSource, /resolveSandboxRef/, 'delete route must resolve sandbox ids to names before deleting')
|
||||||
assert.match(deleteRouteSource, /OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY \|\| "nemoclaw"/, 'delete route must use the NemoClaw gateway context')
|
assert.match(deleteRouteSource, /OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'delete route must preserve an explicit gateway without forcing the legacy NemoClaw name')
|
||||||
assert.match(hostCommandsSource, /export function hostCommandEnv/, 'host commands must provide a shared environment for OpenShell child processes')
|
assert.match(hostCommandsSource, /export function hostCommandEnv/, 'host commands must provide a shared environment for OpenShell child processes')
|
||||||
assert.match(hostCommandsSource, /XDG_CONFIG_HOME/, 'shared host command environment must preserve the OpenShell config home')
|
assert.match(hostCommandsSource, /XDG_CONFIG_HOME/, 'shared host command environment must preserve the OpenShell config home')
|
||||||
assert.match(hostCommandsSource, /export function openshellGatewayAddressEnv/, 'shared host command environment must expose gateway address override variables')
|
assert.match(hostCommandsSource, /export function openshellGatewayAddressEnv/, 'shared host command environment must expose gateway address override variables')
|
||||||
@@ -179,9 +164,9 @@ assert.match(hostCommandsSource, /gateway\.json/, 'shared host command environme
|
|||||||
assert.match(hostCommandsSource, /config\.json/, 'shared host command environment must also support the general OpenShell config file')
|
assert.match(hostCommandsSource, /config\.json/, 'shared host command environment must also support the general OpenShell config file')
|
||||||
assert.match(hostCommandsSource, /gatewayHost/, 'OpenShell gateway address config must support a top-level gatewayHost key')
|
assert.match(hostCommandsSource, /gatewayHost/, 'OpenShell gateway address config must support a top-level gatewayHost key')
|
||||||
assert.match(hostCommandsSource, /gateway\.host/, 'OpenShell gateway address config must support a nested gateway host key')
|
assert.match(hostCommandsSource, /gateway\.host/, 'OpenShell gateway address config must support a nested gateway host key')
|
||||||
assert.match(createRouteSource, /const env: NodeJS\.ProcessEnv = hostCommandEnv\(\{[\s\S]*NEMOCLAW_SANDBOX_NAME: sandboxName[\s\S]*OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY \|\| "nemoclaw"/, 'NemoClaw onboard must receive the shared host command environment')
|
assert.match(createRouteSource, /const env: NodeJS\.ProcessEnv = hostCommandEnv\(\{[\s\S]*NEMOCLAW_SANDBOX_NAME: sandboxName[\s\S]*OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'NemoClaw onboard must preserve an explicit gateway while allowing NemoClaw to select its port-qualified gateway')
|
||||||
assert.match(createRouteSource, /NEMOCLAW_AGENT: agent/, 'NemoClaw onboard must receive the selected dashboard agent')
|
assert.match(createRouteSource, /NEMOCLAW_AGENT: agent/, 'NemoClaw onboard must receive the selected dashboard agent')
|
||||||
assert.match(deleteRouteSource, /env: hostCommandEnv\(\{[\s\S]*OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY \|\| "nemoclaw"/, 'delete route must pass the shared host command environment to OpenShell')
|
assert.match(deleteRouteSource, /env: hostCommandEnv\(\{[\s\S]*OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'delete route must pass the shared host command environment without forcing a gateway')
|
||||||
assert.match(deleteRouteSource, /waitForSandboxDeleted/, 'delete route must poll authoritative inventory until the sandbox is gone')
|
assert.match(deleteRouteSource, /waitForSandboxDeleted/, 'delete route must poll authoritative inventory until the sandbox is gone')
|
||||||
assert.doesNotMatch(deleteRouteSource, /cleanupNemoClawSandbox/, 'delete route must not run NemoClaw destroy cleanup after OpenShell deletion')
|
assert.doesNotMatch(deleteRouteSource, /cleanupNemoClawSandbox/, 'delete route must not run NemoClaw destroy cleanup after OpenShell deletion')
|
||||||
assert.doesNotMatch(deleteRouteSource, /isNemoClawSandboxNotRegistered/, 'delete route must not keep NemoClaw registry cleanup helpers')
|
assert.doesNotMatch(deleteRouteSource, /isNemoClawSandboxNotRegistered/, 'delete route must not keep NemoClaw registry cleanup helpers')
|
||||||
@@ -190,7 +175,7 @@ assert.doesNotMatch(deleteRouteSource, /Pruned NemoClaw registry entry without d
|
|||||||
assert.match(deleteRouteSource, /openShellAlreadyGone/, 'delete route must tolerate sandboxes that OpenShell already deleted while NemoClaw still has registry state')
|
assert.match(deleteRouteSource, /openShellAlreadyGone/, 'delete route must tolerate sandboxes that OpenShell already deleted while NemoClaw still has registry state')
|
||||||
assert.doesNotMatch(deleteRouteSource, /isGatewayRecoverable|recoverableGateway/, 'delete route must not include the later gateway-repair branching')
|
assert.doesNotMatch(deleteRouteSource, /isGatewayRecoverable|recoverableGateway/, 'delete route must not include the later gateway-repair branching')
|
||||||
assert.match(telemetryRouteSource, /const names = parseOpenShellSandboxNames\(sandboxListStdout\)/, 'telemetry must derive inventory from OpenShell before consulting NemoClaw')
|
assert.match(telemetryRouteSource, /const names = parseOpenShellSandboxNames\(sandboxListStdout\)/, 'telemetry must derive inventory from OpenShell before consulting NemoClaw')
|
||||||
assert.match(telemetryRouteSource, /names\.length > 0[\s\S]*execNemoclaw\(\["list"\]\)[\s\S]*execNemoclaw\(\["status"\]\)/, 'telemetry must skip NemoClaw list/status when OpenShell reports zero live sandboxes')
|
assert.match(telemetryRouteSource, /names\.length > 0[\s\S]*execNemoclaw\(\["status"\]\)[\s\S]*execNemoclaw\(\["list", "--json"\]\)/, 'telemetry must skip NemoClaw list/status when OpenShell reports zero live sandboxes and prefer nemoclaw list --json when sandboxes exist')
|
||||||
assert.match(telemetryRouteSource, /readNemoClawRegistry/, 'telemetry must read the NemoClaw registry for agent metadata')
|
assert.match(telemetryRouteSource, /readNemoClawRegistry/, 'telemetry must read the NemoClaw registry for agent metadata')
|
||||||
assert.match(telemetryRouteSource, /resolveSandboxAgent/, 'telemetry must resolve OpenClaw versus Hermes agent metadata')
|
assert.match(telemetryRouteSource, /resolveSandboxAgent/, 'telemetry must resolve OpenClaw versus Hermes agent metadata')
|
||||||
assert.match(telemetryRouteSource, /"nemoclaw\.ai\/agent": agent/, 'telemetry pod labels must include the selected NemoClaw agent')
|
assert.match(telemetryRouteSource, /"nemoclaw\.ai\/agent": agent/, 'telemetry pod labels must include the selected NemoClaw agent')
|
||||||
@@ -200,7 +185,7 @@ assert.match(sandboxListSource, /function displaySandboxAgent\(agent\?: string\)
|
|||||||
assert.match(sandboxListSource, /function SandboxTypeLogo\(\{ agent \}/, 'sandbox list must render per-agent sandbox logos')
|
assert.match(sandboxListSource, /function SandboxTypeLogo\(\{ agent \}/, 'sandbox list must render per-agent sandbox logos')
|
||||||
assert.match(sandboxListSource, /const OPENCLAW_SANDBOX_LOGO = '\/sandbox-logos\/openclaw\.svg'/, 'OpenClaw sandboxes must use the local OpenClaw favicon asset')
|
assert.match(sandboxListSource, /const OPENCLAW_SANDBOX_LOGO = '\/sandbox-logos\/openclaw\.svg'/, 'OpenClaw sandboxes must use the local OpenClaw favicon asset')
|
||||||
assert.match(sandboxListSource, /const HERMES_SANDBOX_LOGO = '\/sandbox-logos\/hermes\.png'/, 'Hermes sandboxes must use the local Hermes favicon asset')
|
assert.match(sandboxListSource, /const HERMES_SANDBOX_LOGO = '\/sandbox-logos\/hermes\.png'/, 'Hermes sandboxes must use the local Hermes favicon asset')
|
||||||
assert.match(sandboxListSource, /const logoSrc = isHermes \? HERMES_SANDBOX_LOGO : OPENCLAW_SANDBOX_LOGO/, 'sandbox type logo must switch assets by agent type')
|
assert.match(sandboxListSource, /const logoSrc = isHermes \? HERMES_SANDBOX_LOGO : isOpenClaw \? OPENCLAW_SANDBOX_LOGO : null/, 'sandbox type logo must avoid misclassifying unknown agents as OpenClaw')
|
||||||
assert.ok(openClawLogoStat.size > 0, 'OpenClaw favicon asset must be vendored locally')
|
assert.ok(openClawLogoStat.size > 0, 'OpenClaw favicon asset must be vendored locally')
|
||||||
assert.ok(hermesLogoStat.size > 0, 'Hermes favicon asset must be vendored locally')
|
assert.ok(hermesLogoStat.size > 0, 'Hermes favicon asset must be vendored locally')
|
||||||
assert.match(sandboxListSource, /selectedSandbox\?\.agent === 'hermes'/, 'sandbox operations must detect Hermes sandboxes')
|
assert.match(sandboxListSource, /selectedSandbox\?\.agent === 'hermes'/, 'sandbox operations must detect Hermes sandboxes')
|
||||||
@@ -297,17 +282,21 @@ assert.match(sandboxInferencePanelSource, /\/api\/sandbox\/\$\{encodeURIComponen
|
|||||||
assert.match(sandboxInferencePanelSource, /\/api\/ollama\/models/, 'selected sandbox UI must offer Ollama model selection')
|
assert.match(sandboxInferencePanelSource, /\/api\/ollama\/models/, 'selected sandbox UI must offer Ollama model selection')
|
||||||
assert.match(sandboxInferencePanelSource, /Enabled Routes/, 'selected sandbox UI must show multiple enabled inference routes')
|
assert.match(sandboxInferencePanelSource, /Enabled Routes/, 'selected sandbox UI must show multiple enabled inference routes')
|
||||||
assert.match(sandboxInferencePanelSource, /Add Route/, 'selected sandbox UI must allow adding provider/model routes')
|
assert.match(sandboxInferencePanelSource, /Add Route/, 'selected sandbox UI must allow adding provider/model routes')
|
||||||
assert.match(sandboxInferenceApplyLibSource, /\/sandbox\/\.openclaw\/openclaw\.json/, 'live apply must patch OpenClaw config inside the running sandbox')
|
assert.match(sandboxInferenceApplyLibSource, /writeNativeOpenClawConfigPatch/, 'live apply must use OpenClaw native config ownership')
|
||||||
assert.match(sandboxInferenceApplyLibSource, /sha256sum \/sandbox\/\.openclaw\/openclaw\.json > \/sandbox\/\.openclaw\/\.config-hash/, 'live apply must refresh the immutable OpenClaw config hash')
|
assert.doesNotMatch(sandboxInferenceApplyLibSource, /config-hash|cat > .*openclaw\.json|chmod .*openclaw\.json/, 'live apply must not replace OpenClaw native config or recreate retired ownership metadata')
|
||||||
assert.match(sandboxInferenceApplyLibSource, /spawn\(OPENSHELL_BIN, \["sandbox", "exec", "-n", sandboxName/, 'live apply must use the supported OpenShell sandbox exec boundary')
|
assert.match(openClawNativeConfigSource, /\[\s*"sandbox",[\s\S]*"exec",[\s\S]*"-n",[\s\S]*sandboxName,[\s\S]*"--env",[\s\S]*"HOME=\/sandbox",[\s\S]*"openclaw",[\s\S]*"config",[\s\S]*"patch",[\s\S]*"--stdin"/, 'native config writes must use OpenShell sandbox exec and OpenClaw config patch stdin')
|
||||||
assert.match(sandboxInferenceApplyLibSource, /OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'live apply must respect the active gateway unless explicitly configured')
|
assert.match(openClawNativeConfigSource, /OPENSHELL_GATEWAY: process\.env\.OPENSHELL_GATEWAY\?\.trim\(\) \|\| undefined/, 'live apply must respect the active gateway unless explicitly configured')
|
||||||
assert.doesNotMatch(sandboxInferenceApplyLibSource, /docker[\s\S]*kubectl|OPENSHELL_CLUSTER_CONTAINER/, 'live apply must not depend on obsolete cluster containers or in-container kubectl')
|
assert.doesNotMatch(sandboxInferenceApplyLibSource, /docker[\s\S]*kubectl|OPENSHELL_CLUSTER_CONTAINER/, 'live apply must not depend on obsolete cluster containers or in-container kubectl')
|
||||||
assert.doesNotMatch(sandboxInferenceApplyLibSource, /chmod 444|chown root:root/, 'live apply must leave OpenClaw config writable by the sandbox owner for subsequent updates')
|
assert.doesNotMatch(sandboxInferenceApplyLibSource, /chmod 444|chown root:root/, 'live apply must leave OpenClaw config writable by the sandbox owner for subsequent updates')
|
||||||
assert.match(sandboxInferenceApplyLibSource, /\["inference", "set", "--no-verify", "--provider", primary\.provider, "--model", primary\.model\]/, 'live apply must point OpenShell inference at the primary route')
|
assert.match(sandboxInferenceApplyLibSource, /\["inference", "set", "--no-verify", "--provider", primary\.provider, "--model", primary\.model\]/, 'live apply must point OpenShell inference at the primary route')
|
||||||
|
assert.match(sandboxInferenceApplyLibSource, /restartSandboxGatewayWithNemoClaw\(sandboxName\)/, 'live apply must restart through NemoClaw native agent lifecycle after config and route updates')
|
||||||
|
assert.match(sandboxInferenceApplyLibSource, /gatewayRestart: "nemoclaw-native-gateway"/, 'live apply must report its verified native restart mode')
|
||||||
|
assert.doesNotMatch(sandboxInferenceApplyLibSource, /\/proc\/[[]0-9[]][*]|openclaw gateway run/, 'live apply must not kill or launch OpenClaw processes outside NemoClaw lifecycle ownership')
|
||||||
assert.match(sandboxInferenceApplyLibSource, /resolveInferenceModelIdentity/, 'live apply must normalize provider/model identities for OpenClaw inference routes')
|
assert.match(sandboxInferenceApplyLibSource, /resolveInferenceModelIdentity/, 'live apply must normalize provider/model identities for OpenClaw inference routes')
|
||||||
assert.match(sandboxInferenceApplyLibSource, /providerKey: "nvidia"[\s\S]*modelRef: route\.model/, 'live apply must preserve nvidia/... model refs without wrapping them as inference/...')
|
assert.match(sandboxInferenceApplyLibSource, /providerKey: "nvidia"[\s\S]*modelRef: route\.model/, 'live apply must preserve nvidia/... model refs without wrapping them as inference/...')
|
||||||
assert.doesNotMatch(sandboxRestartRouteSource, /delete", "pod"|kubectl delete/, 'restart route must not delete the backing sandbox pod')
|
assert.doesNotMatch(sandboxRestartRouteSource, /delete", "pod"|kubectl delete/, 'restart route must not delete the backing sandbox pod')
|
||||||
assert.match(sandboxRestartRouteSource, /restartMode: "openclaw-runtime"/, 'restart route must restart only the in-sandbox OpenClaw runtime')
|
assert.match(sandboxRestartRouteSource, /restartMode: "nemoclaw-native-gateway"/, 'restart route must use NemoClaw native agent gateway lifecycle')
|
||||||
|
assert.doesNotMatch(sandboxRestartRouteSource, /openclaw gateway run|runSandboxShell/, 'restart route must not bypass the native agent lifecycle with a manual OpenClaw launch')
|
||||||
assert.match(sandboxRestartRouteSource, /waitForSandboxReady\(sandboxName, 15000, 1000\)/, 'restart route must verify OpenShell reports the sandbox ready before runtime restart')
|
assert.match(sandboxRestartRouteSource, /waitForSandboxReady\(sandboxName, 15000, 1000\)/, 'restart route must verify OpenShell reports the sandbox ready before runtime restart')
|
||||||
assert.match(sandboxListSource, /Restart Sandbox/, 'sandbox details must expose the Monday-era sandbox restart button')
|
assert.match(sandboxListSource, /Restart Sandbox/, 'sandbox details must expose the Monday-era sandbox restart button')
|
||||||
assert.match(sandboxListSource, /\/api\/sandbox\/\$\{encodeURIComponent\(selectedSandbox\.id\)\}\/restart/, 'restart button must call the sandbox restart endpoint')
|
assert.match(sandboxListSource, /\/api\/sandbox\/\$\{encodeURIComponent\(selectedSandbox\.id\)\}\/restart/, 'restart button must call the sandbox restart endpoint')
|
||||||
@@ -345,6 +334,11 @@ assert.match(configPanelSource, /createInference/, 'create panel must send creat
|
|||||||
assert.match(configPanelSource, /selectedBlueprint === 'nemoclaw-blueprint' \|\| selectedBlueprint === 'nemoclaw-hermes' \|\| selectedBlueprint === 'nemoclaw-deepagents-code'/, 'create panel must treat NemoClaw managed agents as onboard blueprints')
|
assert.match(configPanelSource, /selectedBlueprint === 'nemoclaw-blueprint' \|\| selectedBlueprint === 'nemoclaw-hermes' \|\| selectedBlueprint === 'nemoclaw-deepagents-code'/, 'create panel must treat NemoClaw managed agents as onboard blueprints')
|
||||||
assert.match(configPanelSource, /selectedBlueprint === 'nemoclaw-hermes' \? 'my-hermes'/, 'create panel must provide a Hermes-specific sandbox name placeholder')
|
assert.match(configPanelSource, /selectedBlueprint === 'nemoclaw-hermes' \? 'my-hermes'/, 'create panel must provide a Hermes-specific sandbox name placeholder')
|
||||||
assert.match(configPanelSource, /selectedBlueprint === 'nemoclaw-deepagents-code' \? 'my-deepagents-code'/, 'create panel must provide a Deep Agents Code-specific sandbox name placeholder')
|
assert.match(configPanelSource, /selectedBlueprint === 'nemoclaw-deepagents-code' \? 'my-deepagents-code'/, 'create panel must provide a Deep Agents Code-specific sandbox name placeholder')
|
||||||
|
assert.match(configPanelSource, /maxLength=\{19\}/, 'create panel must expose NemoClaw\'s 19-character sandbox-name limit')
|
||||||
|
assert.match(configPanelSource, /single internal hyphens only/, 'create panel must explain the canonical sandbox-name grammar')
|
||||||
|
assert.match(wizardPanelSource, /targetName\.length <= 19/, 'clone wizard must enforce NemoClaw\'s 19-character sandbox-name limit')
|
||||||
|
assert.match(wizardPanelSource, /\^\(\?!\.\*--\)\[a-z\]/, 'clone wizard must reject leading digits and consecutive hyphens')
|
||||||
|
assert.match(wizardPanelSource, /\.slice\(0, 13\)[\s\S]*-clone/, 'clone wizard must keep generated clone names within the 19-character limit')
|
||||||
assert.match(configPanelSource, /useState<string>\('redeploy-image'\)/, 'create panel must default to quick deploy')
|
assert.match(configPanelSource, /useState<string>\('redeploy-image'\)/, 'create panel must default to quick deploy')
|
||||||
assert.doesNotMatch(configPanelSource, /Source Sandbox|sourceSandboxName/, 'basic create panel must not require choosing a source image')
|
assert.doesNotMatch(configPanelSource, /Source Sandbox|sourceSandboxName/, 'basic create panel must not require choosing a source image')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user