import { useBrainState, type BrainState, type WisdomConsensus } from "@/hooks/useBrainState"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { Badge } from "@/components/ui/badge"; import { Brain, AlertTriangle, CheckCircle2, TrendingUp, TrendingDown, Minus, Eye, Target, Sparkles, Globe, BarChart3, Lightbulb } from "lucide-react"; import { format } from "date-fns"; // Fear & Greed color coding function getFearGreedColor(value: number): string { if (value <= 25) return "text-destructive"; if (value <= 45) return "text-warning"; if (value <= 55) return "text-warning"; if (value <= 75) return "text-success"; return "text-success"; } function getFearGreedBg(value: number): string { if (value <= 25) return "bg-destructive/20"; if (value <= 45) return "bg-warning/20"; if (value <= 55) return "bg-warning/20"; if (value <= 75) return "bg-success/20"; return "bg-success/20"; } // Direction icon function DirectionIcon({ direction }: { direction: string }) { if (direction === "BULLISH") return ; if (direction === "BEARISH") return ; return ; } // Wisdom consensus display function WisdomConsensusDisplay({ wisdom }: { wisdom: WisdomConsensus }) { if (!wisdom || Object.keys(wisdom).length === 0) { return Awaiting wisdom council...; } const civilizations = wisdom.civilization_actions || {}; const civIcons: Record = { celtic: "☘️", aztec: "🦅", vedic: "🕉️", egyptian: "🔺", greek: "🏛️", chinese: "☯️", mayan: "🌀", }; return ( {wisdom.sentiment || "NEUTRAL"} {wisdom.confidence ? `${(wisdom.confidence * 100).toFixed(0)}% confidence` : ""} {(wisdom.bullish_votes !== undefined || wisdom.bearish_votes !== undefined) && ( 📈 {wisdom.bullish_votes || 0} 📉 {wisdom.bearish_votes || 0} ⚖️ {wisdom.neutral_votes || 0} )} {Object.keys(civilizations).length > 0 && ( {Object.entries(civilizations).map(([civ, action]) => ( {civIcons[civ.toLowerCase()] || "🌍"} {String(action).slice(0, 8)} ))} )} ); } export function BrainStatePanel() { const { brainState, loading, lastUpdated } = useBrainState(true, 10000); if (loading && !brainState.id) { return ( AUREON Brain Awaiting cognitive state from Python terminal... ); } const { // Market fear_greed, fear_greed_class, btc_price, btc_change_24h, // Live Pulse live_pulse, // Quantum quantum_coherence, planetary_gamma, lambda_field, cascade_multiplier, is_lighthouse, probability_edge, harmonic_signal, hnc_probability, // Council / prediction / accuracy manipulation_probability, red_flags, green_flags, council_consensus, council_action, truth_score, spoof_score, brain_directive, prediction_direction, prediction_confidence, overall_accuracy, total_predictions, // Extended dreams, sandbox_generation, sandbox_win_rate, should_trade, entry_filter_reason, exit_targets, position_size_pct, piano_lambda, piano_coherence, rainbow_state, diamond_coherence, diamond_phi_alignment, reflection, // Wisdom speculations, wisdom_consensus, } = brainState; const btcPriceSafe = typeof btc_price === "number" && btc_price > 0 ? btc_price : null; const btcChangeSafe = typeof btc_change_24h === "number" ? btc_change_24h : 0; const manipulationPct = Math.round((manipulation_probability || 0) * 100); const truthPct = Math.round((truth_score || 0) * 100); const spoofPct = Math.round((spoof_score || 0) * 100); const accuracyPct = Math.round((overall_accuracy || 0) * 100); const predConfPct = Math.round((prediction_confidence || 0) * 100); const coherencePct = quantum_coherence == null ? null : quantum_coherence <= 1 ? quantum_coherence * 100 : quantum_coherence; const gammaSafe = planetary_gamma == null ? null : Number(planetary_gamma); const lambdaSafe = lambda_field == null ? null : Number(lambda_field); const dreamScenarios = dreams?.scenarios_dreamed ?? []; const dreamInsights = dreams?.key_insights ?? []; const blindSpots = reflection?.blind_spots ?? []; const selfCritique = reflection?.self_critique ?? []; return ( AUREON Brain - Live Cognitive State {lastUpdated && ( Updated {format(lastUpdated, "HH:mm:ss")} )} {/* Row 0: Quantum State + Live Pulse */} Quantum State {is_lighthouse ? "Lighthouse" : "Scanning"} Coherence Ψ {coherencePct == null ? "---" : `${coherencePct.toFixed(1)}%`} Lambda Λ {lambdaSafe == null ? "---" : lambdaSafe >= 1e6 ? `${(lambdaSafe / 1e6).toFixed(2)}M` : lambdaSafe.toFixed(0)} Prism {rainbow_state || "---"} Cascade {cascade_multiplier == null ? "---" : Number(cascade_multiplier).toFixed(2)} {(probability_edge != null || harmonic_signal != null || hnc_probability != null || gammaSafe != null) && ( Γ: {gammaSafe == null ? "---" : gammaSafe.toFixed(3)} Edge: {probability_edge == null ? "---" : Number(probability_edge).toFixed(3)} H: {harmonic_signal == null ? "---" : Number(harmonic_signal).toFixed(2)} HNC: {hnc_probability == null ? "---" : `${(Number(hnc_probability) * 100).toFixed(0)}%`} )} Live Pulse {live_pulse?.pulse || "AWAITING_DATA"} Strength {live_pulse?.strength == null ? "---" : Number(live_pulse.strength).toFixed(2)} Avg 24h Δ {live_pulse?.avg_change_24h == null ? "---" : `${Number(live_pulse.avg_change_24h).toFixed(2)}%`} BTC (pulse) {live_pulse?.btc_price == null ? "---" : `$${Number(live_pulse.btc_price).toLocaleString(undefined, { maximumFractionDigits: 0 })}`} {/* Row 1: Fear & Greed + Market */} Fear & Greed {fear_greed} {fear_greed_class} BTC Price = 0 ? "BULLISH" : "BEARISH"} /> {btcPriceSafe == null ? "---" : `$${btcPriceSafe.toLocaleString(undefined, { maximumFractionDigits: 0 })}`} = 0 ? "text-success" : "text-destructive"}`}> {btcPriceSafe == null ? "---" : `${btcChangeSafe >= 0 ? "+" : ""}${btcChangeSafe.toFixed(2)}%`} {/* Row 2: Manipulation Detection */} 50 ? "text-destructive" : "text-success"}`} /> Manipulation Detection 50 ? "destructive" : "secondary"}>{manipulationPct}% {green_flags.length > 0 ? ( {green_flags.slice(0, 2).map((flag, i) => ( {flag} ))} ) : ( No green flags )} {red_flags.length > 0 ? ( {red_flags.slice(0, 2).map((flag, i) => ( {flag} ))} ) : ( No red flags )} {/* Row 3: Truth Council */} Truth Council {council_consensus} → {council_action} Truth: {truthPct}% Spoof: {spoofPct}% {/* Row 4: Prediction + Accuracy */} Prediction {prediction_direction} {predConfPct}% confidence Brain Accuracy {accuracyPct}% {total_predictions} predictions {/* Row 5: Sandbox Evolution */} Sandbox Evolution {should_trade ? "ENTER" : "SKIP"} Generation {sandbox_generation || "---"} Win Rate {sandbox_win_rate ? `${Number(sandbox_win_rate).toFixed(1)}%` : "---"} Position Size {position_size_pct == null ? "---" : `${Number(position_size_pct).toFixed(2)}%`} Exit Targets {exit_targets?.take_profit_pct != null || exit_targets?.stop_loss_pct != null ? `TP ${exit_targets?.take_profit_pct ?? "-"}% / SL ${exit_targets?.stop_loss_pct ?? "-"}%` : "---"} {entry_filter_reason && ( Reason: {entry_filter_reason} )} {/* Row 6: Harmonic Lattice (Piano/Diamond) */} Piano / Diamond Harmony Piano Λ {piano_lambda == null ? "---" : Number(piano_lambda).toFixed(2)} Piano Ψ {piano_coherence == null ? "---" : `${(Number(piano_coherence) <= 1 ? Number(piano_coherence) * 100 : Number(piano_coherence)).toFixed(1)}%`} Diamond Ψ {diamond_coherence == null ? "---" : `${Number(diamond_coherence).toFixed(3)}`} Φ Alignment {diamond_phi_alignment == null ? "---" : Number(diamond_phi_alignment).toFixed(3)} {/* Row 7: Dream Engine */} Dream Engine {dreamScenarios.length === 0 && dreamInsights.length === 0 ? ( Awaiting dream output... ) : ( {dreamScenarios.length > 0 && ( {dreamScenarios.slice(0, 3).map((s, idx) => ( Scenario: {s.scenario} — {s.decision} ))} )} {dreamInsights.length > 0 && ( {dreamInsights.slice(0, 3).map((i, idx) => ( {i} ))} )} )} {/* Row 8: Wisdom Consensus */} 7 Civilization Wisdom {/* Row 9: Self-Reflection */} Self-Reflection {blindSpots.length === 0 && selfCritique.length === 0 ? ( Awaiting reflection... ) : ( Blind Spots {(blindSpots.length ? blindSpots : ["---"]).slice(0, 3).map((b, i) => ( • {b} ))} Self-Critique {(selfCritique.length ? selfCritique : ["---"]).slice(0, 3).map((c, i) => ( • {c} ))} )} {/* Row 10: Brain Directive */} {brain_directive && ( Brain Directive {brain_directive} )} {/* Row 11: Speculations (if any) */} {speculations.length > 0 && ( Speculative Insights {speculations.slice(0, 3).map((spec, i) => ( 💭 {spec} ))} )} ); }
Awaiting cognitive state from Python terminal...
{brain_directive}