"use client" import { useEffect, useMemo, useState } from 'react' import Sidebar from './components/Sidebar' import SandboxList from './components/SandboxList' import ConfigurationPanel from './components/ConfigurationPanel' import { useSandboxInventory } from './hooks/useSandboxInventory' import { createHydrationSafeDashboardSessionState, loadDashboardSessionState, persistDashboardSessionState, updateDashboardSessionSelection, } from './lib/dashboardSession' export default function Dashboard() { const [theme, setTheme] = useState<'light' | 'dark'>('dark') const [isSubmenuOpen, setIsSubmenuOpen] = useState(false) const [hostIP] = useState('192.168.50.173') const [dashboardSession, setDashboardSession] = useState(() => createHydrationSafeDashboardSessionState()) const [isCreateMode, setIsCreateMode] = useState(false) const [isDestroyMode, setIsDestroyMode] = useState(false) const [activeView, setActiveView] = useState<'overview' | 'settings' | 'sandboxes'>('sandboxes') const [deletingSandboxId, setDeletingSandboxId] = useState(null) const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) const inventoryEnabled = isSubmenuOpen || activeView === 'sandboxes' || isCreateMode || isDestroyMode const { sandboxes, nemoclaw, loading, error, refresh } = useSandboxInventory({ enabled: inventoryEnabled, }) useEffect(() => { setDashboardSession(loadDashboardSessionState()) }, []) useEffect(() => { persistDashboardSessionState(dashboardSession) }, [dashboardSession]) useEffect(() => { document.documentElement.dataset.theme = theme }, [theme]) const selectedSandbox = useMemo( () => sandboxes.find((sandbox) => sandbox.id === dashboardSession.selectedSandboxId) ?? null, [sandboxes, dashboardSession.selectedSandboxId] ) const toggleTheme = () => { setTheme(theme === 'light' ? 'dark' : 'light') } const handleSandboxSelect = (id: string | null) => { if (isDestroyMode && id) { setDeletingSandboxId(id) setShowDeleteConfirm(true) } else { setDashboardSession((current) => updateDashboardSessionSelection(current, id)) } } const clearSelection = () => { setDashboardSession((current) => updateDashboardSessionSelection(current, null)) } const handleCreateSuccess = async (createdSandboxId: string) => { setIsCreateMode(false) setIsDestroyMode(false) setActiveView('sandboxes') setIsSubmenuOpen(true) const latest = await refresh() const created = latest.find((sandbox) => sandbox.id === createdSandboxId || sandbox.name === createdSandboxId) setDashboardSession((current) => updateDashboardSessionSelection(current, created?.id ?? createdSandboxId)) } const confirmDelete = () => { console.log('Destroying sandbox:', deletingSandboxId) setShowDeleteConfirm(false) setDeletingSandboxId(null) setIsDestroyMode(false) } const cancelDelete = () => { setShowDeleteConfirm(false) setDeletingSandboxId(null) } return (
{ setIsSubmenuOpen(!isSubmenuOpen) if (isCreateMode) setIsCreateMode(false) if (isDestroyMode) setIsDestroyMode(false) }} isCreateMode={isCreateMode} isDestroyMode={isDestroyMode} activeView={activeView} onCreateClick={() => { setActiveView('sandboxes') setIsCreateMode(true) setIsDestroyMode(false) clearSelection() setIsSubmenuOpen(true) }} onDestroyClick={() => { setActiveView('sandboxes') setIsDestroyMode(true) setIsCreateMode(false) setIsSubmenuOpen(true) }} onOverviewClick={() => { setActiveView('overview') setIsCreateMode(false) setIsDestroyMode(false) clearSelection() setIsSubmenuOpen(false) }} onSettingsClick={() => { setActiveView('settings') setIsCreateMode(false) setIsDestroyMode(false) clearSelection() setIsSubmenuOpen(false) }} onExitMode={() => { setIsCreateMode(false) setIsDestroyMode(false) clearSelection() }} />
{activeView === 'overview' ? (

OVERVIEW

Operational summary of the current OpenShell environment and preset posture.

HOST

{hostIP}

VIEW

OVERVIEW

STATUS

ONLINE

Preset Ladder

Lockdown Mode → minimum writable scope

Enterprise Mode → controlled enterprise defaults

Medium-Spicy → balanced dev workflow

Spicy → broad engineering access, dangerous if misused

Ultra-Lobster → maximum lab convenience, highly permissive

) : activeView === 'settings' ? (

SETTINGS

Global defaults and preset-driven policy controls for this dashboard instance.

Dashboard session {dashboardSession.dashboardSessionId.slice(0, 8)}

) : isCreateMode ? (

CREATE SANDBOX

Start from a named security preset, then refine the OpenShell policy before creating the sandbox.

) : isDestroyMode ? (

DESTROY SANDBOX

Click on any sandbox below to initiate destruction. All sandboxes are highlighted in red.

) : ( <>

NEMOSHELL DASHBOARD

Real-time OpenShell sandbox monitoring

Dashboard session {dashboardSession.dashboardSessionId.slice(0, 8)}

{inventoryEnabled && loading ? (
INITIALIZING...
) : inventoryEnabled && error ? (

Inventory Unavailable

{error}

) : sandboxes.length === 0 ? (

No Sandboxes Detected

No live OpenShell sandboxes reported yet

) : ( )} )}
{showDeleteConfirm && (

WARNING: DESTRUCTIVE ACTION

Destroying this sandbox will permanently delete it and it will not be recoverable. Are you sure?

)}
) }