import { EvidenceDrawer } from '@szl-holdings/design-system/cockpit/evidence-drawer'; import { useAuth } from '@szl-holdings/replit-auth-web'; import { useDemoMode, } from '@szl-holdings/shared-ui/demo-mode'; import { useQuery } from '@tanstack/react-query'; import { Activity, AlertTriangle, Archive, BarChart3, Bell, BookOpen, Bot, Brain, Building, CheckCircle2, CheckSquare, ChevronRight, Clapperboard, Code, Cpu, Crown, Database, DollarSign, FileText, FlaskConical, GitBranch, GitCommit, GitMerge, Globe, Globe2, Heart, Inbox, Layers, LayoutDashboard, Lightbulb, Lock, Map, Menu, Mic, Network, Phone, Play, Radio, RotateCcw, Satellite, Scale, Search, Server, Shield, ShieldCheck, Sigma, Target, Users, Workflow, X, Zap, } from 'lucide-react'; import { type ReactNode, useCallback, useEffect, useRef, useState } from 'react'; import { Link, useLocation } from 'wouter'; import { FabricShellProvider, useFabricShell } from '../../lib/fabric-shell-context'; import { VoiceCommandPanel } from './voice-command-panel'; export type WorkspaceMode = 'strategy' | 'operations' | 'infrastructure'; const T = { bg: '#0a0a0a', surface: 'rgba(255,255,255,0.018)', border: 'rgba(255,255,255,0.08)', borderStrong: 'rgba(255,255,255,0.12)', text: '#f5f5f5', textDim: '#8a8a8a', textMuted: '#5e5e5e', accent: '#c9b787', mono: 'ui-monospace, SFMono-Regular, Menlo, monospace', }; const WORKSPACE_TABS: { mode: WorkspaceMode; label: string; icon: typeof LayoutDashboard; }[] = [ { mode: 'strategy', label: 'Strategy', icon: Globe2 }, { mode: 'operations', label: 'Operations', icon: Zap }, { mode: 'infrastructure', label: 'Infrastructure', icon: Shield }, ]; type NavItemDef = { href: string; label: string; icon: typeof LayoutDashboard; external?: boolean }; type NavGroup = { section: string; items: NavItemDef[] }; const ECOSYSTEM_APPS_NAV: NavGroup = { section: 'Ecosystem Apps', items: [ { href: '/conduit/', label: 'Conduit — Reverse ETL', icon: Workflow, external: true }, { href: '/counsel/', label: 'Counsel — Legal', icon: Scale, external: true }, { href: '/imperium/', label: 'IMPERIUM', icon: Crown, external: true }, { href: '/governance/lexicon', label: 'LEXICON — License Intelligence', icon: Zap, external: false }, { href: '/stephen-site/', label: 'Stephen Site', icon: Globe, external: true }, ], }; const CARLOTA_NAV: NavGroup = { section: 'Carlota Jo', items: [ { href: '/carlota/pipeline', label: 'Lead Pipeline', icon: Users }, { href: '/carlota-jo/', label: 'Consulting Site', icon: Globe, external: true }, ], }; const STRATEGY_NAV: NavGroup[] = [ { section: 'ATLAS Spatial Runtime', items: [ { href: '/strategy/atlas-runtime', label: 'Cross-Domain Twin View', icon: Layers }, { href: '/strategy/digital-twins', label: 'Digital Twin Registry', icon: Cpu }, { href: '/strategy/worldline-registry', label: 'Worldline Registry', icon: GitBranch }, { href: '/vessels/atlas-runtime', label: 'SEXTANT ATLAS Runtime', icon: Satellite, external: true }, { href: '/terra/atlas-runtime', label: 'DOMAINE ATLAS Runtime', icon: Map, external: true }, ], }, { section: 'Command', items: [ { href: '/demo', label: 'Demo Launchpad', icon: Play }, { href: '/strategy', label: 'Governed Decision Loop', icon: LayoutDashboard }, { href: '/strategy/enterprise-state', label: 'Enterprise State', icon: Building }, { href: '/strategy/executive-briefing', label: 'Executive Briefing', icon: FileText }, { href: '/strategy/briefing', label: 'Briefing History', icon: BarChart3 }, ], }, { section: 'Cross-Platform Intelligence', items: [ { href: '/strategy/cross-platform', label: 'Signal Correlation', icon: GitMerge }, { href: '/intelligence/evidence', label: 'Evidence Explorer', icon: Sigma }, { href: '/strategy/cross-platform/evidence', label: 'Evidence Registry', icon: Database }, { href: '/strategy/cross-platform/run-health', label: 'Run Health', icon: Activity }, { href: '/strategy/cross-platform/pilots', label: 'Pilot Intelligence', icon: Users }, ], }, { section: 'Primitives', items: [ { href: '/strategy/simulation', label: 'Simulation', icon: Activity }, { href: '/strategy/correlation-map', label: 'Outcome Graph', icon: Network }, { href: '/strategy/signal-chains', label: 'Signal Chains', icon: GitCommit }, ], }, { section: 'Cognitive Runtime', items: [ { href: '/cognitive', label: 'Command Center', icon: Brain }, { href: '/cognitive/self-model', label: 'Self Model', icon: Cpu }, { href: '/cognitive/world-model', label: 'World Model', icon: Globe }, { href: '/cognitive/memory', label: 'Memory Explorer', icon: Archive }, { href: '/cognitive/planner', label: 'Planner Studio', icon: GitMerge }, { href: '/cognitive/verifier', label: 'Verifier Console', icon: CheckCircle2 }, { href: '/cognitive/reflection', label: 'Reflection Console', icon: Lightbulb }, { href: '/cognitive/traces', label: 'Trace Replay', icon: Clapperboard }, { href: '/cognitive/policy-sim', label: 'Policy Simulation', icon: FlaskConical }, ], }, CARLOTA_NAV, ECOSYSTEM_APPS_NAV, ]; const OPERATIONS_NAV: NavGroup[] = [ { section: 'A11oy Agent Runtime', items: [ { href: '/agents', label: 'Operator Control Plane', icon: Bot }, { href: '/agents/workcells', label: 'Workcells', icon: Layers }, { href: '/agents/tools', label: 'Tool Registry', icon: Zap }, { href: '/agents/evals', label: 'MirrorEval', icon: FlaskConical }, { href: '/agents/memory', label: 'Memory Health', icon: Archive }, { href: '/agents/model-router', label: 'Model Router', icon: Cpu }, { href: '/agents/skills', label: 'Skills', icon: BookOpen }, ], }, { section: 'Tool Intelligence', items: [ { href: '/operations/forge', label: 'Tool Intelligence Hub', icon: Sigma }, ], }, { section: 'Global Fabric', items: [{ href: '/operations/fabric', label: 'Global Operations Fabric', icon: Globe2 }], }, { section: 'Governed Decision Loop', items: [ { href: '/operations', label: 'Executive Command', icon: LayoutDashboard }, { href: '/operations/prism/pulse', label: 'Pulse', icon: Heart }, { href: '/operations/prism/signals', label: 'Signal Feed', icon: Radio }, { href: '/operations/prism/atlas-execute', label: 'ATLAS Execute', icon: Play }, { href: '/operations/rules-studio', label: 'Rules Studio', icon: GitBranch }, { href: '/operations/blocker-board', label: 'Blocker Board', icon: AlertTriangle }, { href: '/operations/approvals', label: 'Approvals', icon: CheckSquare }, { href: '/operations/policy-approvals', label: 'Policy Approvals', icon: ShieldCheck }, { href: '/operations/policy-manager', label: 'Policy Manager', icon: ShieldCheck }, { href: '/operations/trust-audit', label: 'Proof Chain Audit', icon: Shield }, { href: '/governed-cockpit', label: 'Governed Intelligence', icon: Shield }, { href: '/operations/inbox', label: 'Command Inbox', icon: Inbox }, ], }, { section: 'Automations', items: [{ href: '/operations/automations', label: 'n8n Automation Bridge', icon: Workflow }], }, { section: 'Counsel — Execution', items: [ { href: '/operations/continuum/policy-compiler', label: 'Policy Compiler', icon: Code }, { href: '/operations/continuum/canvas', label: 'Workflow Canvas', icon: Workflow }, { href: '/operations/continuum/actions', label: 'Action Queue', icon: Activity }, { href: '/operations/continuum/governance', label: 'Covenant Policy', icon: Lock }, { href: '/operations/continuum/intelligence', label: 'Intelligence', icon: Brain }, { href: '/operations/continuum/traces', label: 'Execution Traces', icon: GitBranch }, { href: '/operations/runs', label: 'Run Console', icon: Play }, { href: '/operations/evidence-explorer', label: 'Evidence Explorer', icon: Database }, { href: '/operations/eval-studio', label: 'Eval Studio', icon: FlaskConical }, { href: '/operations/ownership', label: 'Ownership Map', icon: Users }, ], }, { section: 'Precision Evolution Runtime', items: [ { href: '/evolution', label: 'Runtime Overview', icon: Cpu }, { href: '/evolution/evaluation', label: 'Evaluation Console', icon: FlaskConical }, { href: '/evolution/governance', label: 'Governance Console', icon: ShieldCheck }, { href: '/evolution/diagnostics', label: 'Diagnostics', icon: Activity }, ], }, { section: 'Observability', items: [ { href: '/operations/autonomous-noc', label: 'Autonomous NOC', icon: Bot }, { href: '/operations/slo', label: 'SLO Management', icon: Target }, { href: '/operations/metrics', label: 'Metrics', icon: BarChart3 }, { href: '/operations/logs', label: 'Log Analytics', icon: Database }, { href: '/operations/tracing', label: 'Distributed Tracing', icon: GitBranch }, { href: '/operations/topology', label: 'Service Topology', icon: Network }, { href: '/operations/self-healing', label: 'Self-Healing', icon: RotateCcw }, ], }, { section: 'Operations', items: [ { href: '/operations/what-changed', label: 'Twin State Changes', icon: Activity }, { href: '/operations/digest', label: 'Digest Center', icon: FileText }, { href: '/operations/finops', label: 'FinOps', icon: DollarSign }, { href: '/operations/on-call', label: 'On-Call', icon: Phone }, { href: '/operations/runbook-studio', label: 'Mission Runbooks', icon: BookOpen }, { href: '/operations/noise-reduction', label: 'Noise Reduction', icon: Bell }, ], }, { section: 'Cognitive Consoles', items: [ { href: '/cognitive/overview', label: 'Consoles Overview', icon: Brain }, { href: '/cognitive/traces', label: 'Trace Replay', icon: Clapperboard }, { href: '/cognitive/evals', label: 'Eval Console', icon: FlaskConical }, { href: '/cognitive/policies', label: 'Policy Console', icon: ShieldCheck }, ], }, { section: 'Open Evaluation Layer', items: [ { href: '/operations/open-eval-hub', label: 'Open Evaluation Hub', icon: FlaskConical }, { href: '/agents/evals', label: 'MirrorEval', icon: Sigma }, { href: '/operations/eval-studio', label: 'Eval Studio', icon: Layers }, { href: '/evolution/evaluation', label: 'Evolution Eval Console', icon: GitBranch }, ], }, ECOSYSTEM_APPS_NAV, ]; const OPERATIONS_ADMIN_NAV: NavGroup = { section: 'Governance Admin', items: [ { href: '/admin/command-center', label: 'Command Center', icon: LayoutDashboard }, { href: '/operations/admin/analytics', label: 'Analytics Intelligence', icon: BarChart3 }, { href: '/operations/admin/experiments', label: 'Experimentation', icon: FlaskConical }, { href: '/operations/governance-tiers', label: 'Governance Tiers', icon: ShieldCheck }, { href: '/operations/guardrail-configs', label: 'Guardrail Configs', icon: Lock }, ], }; const ADMIN_ROLES = new Set(['admin', 'super_admin']); export function getOperationsNav(isAdmin: boolean): NavGroup[] { if (!isAdmin) return OPERATIONS_NAV; const ecosystemIdx = OPERATIONS_NAV.findIndex((g) => g === ECOSYSTEM_APPS_NAV); const insertAt = ecosystemIdx === -1 ? OPERATIONS_NAV.length : ecosystemIdx; return [ ...OPERATIONS_NAV.slice(0, insertAt), OPERATIONS_ADMIN_NAV, ...OPERATIONS_NAV.slice(insertAt), ]; } const INFRASTRUCTURE_NAV: NavGroup[] = [ { section: 'IMPERIUM Command', items: [ { href: '/infrastructure', label: 'Executive Console', icon: Crown }, { href: '/infrastructure/intelligence', label: 'Intelligence Briefing', icon: Radio }, { href: '/infrastructure/imperium-map', label: 'Resource Map', icon: Map }, { href: '/infrastructure/imperium/atlas-execute', label: 'ATLAS Execute', icon: Play }, ], }, { section: 'Security & Governance', items: [ { href: '/infrastructure/praetorian', label: 'Security Perimeter', icon: Shield }, { href: '/infrastructure/senate', label: 'Governance Board', icon: BookOpen }, { href: '/infrastructure/centurion', label: 'AI Operations', icon: Cpu }, ], }, { section: 'Command & Control', items: [ { href: '/infrastructure/directives', label: 'Directive Cascade', icon: Zap }, { href: '/infrastructure/coalition', label: 'Coalition Manager', icon: Users }, { href: '/infrastructure/reserves', label: 'Strategic Reserves', icon: Database }, ], }, { section: 'Network', items: [ { href: '/infrastructure/supply-lines', label: 'Network Topology', icon: Network }, { href: '/infrastructure/geospatial', label: 'Geospatial Intel', icon: Satellite }, { href: '/infrastructure/substrate', label: 'Substrate Inference', icon: Server }, ], }, { section: 'MCP Ecosystem', items: [ { href: '/ecosystem', label: 'Topology Map', icon: Network }, { href: '/ecosystem/observatory', label: 'Agent Observatory', icon: Bot }, { href: '/ecosystem/inspector', label: 'Tool Inspector', icon: Search }, { href: '/ecosystem/counterfactual', label: 'Counterfactual Studio', icon: GitBranch }, ], }, ]; function SectionHeader({ label }: { label: string }) { return (
); } function NavItem({ href, label, icon: Icon, isActive, badge, external, }: { href: string; label: string; icon: typeof LayoutDashboard; isActive: boolean; badge?: ReactNode; external?: boolean; }) { const s: React.CSSProperties = { display: 'flex', alignItems: 'center', gap: '0.5rem', padding: '0.3rem 1rem', fontSize: '0.75rem', fontWeight: isActive ? 500 : 400, color: isActive ? T.text : T.textDim, background: isActive ? 'rgba(255,255,255,0.03)' : 'transparent', borderLeft: isActive ? `2px solid ${T.accent}` : '2px solid transparent', textDecoration: 'none', letterSpacing: '-0.005em', transition: 'color 0.15s, background 0.15s', cursor: 'pointer', }; const inner = ( <>