petter2025 commited on
Commit
e0ae759
·
verified ·
1 Parent(s): 6d28bf3

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +859 -436
ui/components.py CHANGED
@@ -12,6 +12,9 @@ from typing import Dict, List, Any
12
  import logging
13
  import datetime
14
  import time
 
 
 
15
 
16
  logger = logging.getLogger(__name__)
17
 
@@ -67,6 +70,776 @@ def create_status_bar() -> gr.HTML:
67
  </div>
68
  """)
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  # -----------------------------
71
  # NEW: Observation Gate Renderer - CRITICAL PSYCHOLOGICAL FIX
72
  # -----------------------------
@@ -390,7 +1163,7 @@ def update_performance_metrics(scenario_name: str, scenarios=INCIDENT_SCENARIOS)
390
  return detection_time_html, mttr_html, auto_heal_html, savings_html
391
 
392
  # -----------------------------
393
- # Tab 1: Live Incident Demo - DOCTRINAL COMPLIANCE
394
  # -----------------------------
395
  def create_tab1_incident_demo(scenarios=INCIDENT_SCENARIOS, default_scenario="Cache Miss Storm") -> tuple:
396
  """
@@ -474,65 +1247,11 @@ def create_tab1_incident_demo(scenarios=INCIDENT_SCENARIOS, default_scenario="Ca
474
  # Middle Column: Process Workflow (NOT Agent Workflow)
475
  with gr.Column(scale=2, variant="panel") as middle_col:
476
  # ============ OBSERVATION GATE PLACEHOLDER ============
477
- observation_gate_placeholder = gr.HTML("""
478
- <div style="text-align: center; padding: 30px; color: #64748b; background: #f8fafc; border-radius: 12px; margin-bottom: 20px;">
479
- <div style="font-size: 48px; margin-bottom: 10px;">🎯</div>
480
- <h4 style="margin: 0 0 10px 0;">System State</h4>
481
- <p style="margin: 0;">Run analysis to see system's judgment under uncertainty</p>
482
- </div>
483
- """)
484
 
485
  # ============ SEQUENCING VISUALIZATION ============
486
  sequencing_header = gr.Markdown("### 🔄 Sequencing Logic: Dampening → Concurrency → Observe → Scale")
487
- sequencing_panel = gr.HTML("""
488
- <div style="border: 2px solid #e2e8f0; border-radius: 14px; padding: 20px; background: #f8fafc; margin-bottom: 20px;">
489
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
490
- <h4 style="margin: 0; font-size: 16px; color: #1e293b; font-weight: 600;">Doctrinal Sequencing</h4>
491
- <span style="padding: 4px 12px; background: #dbeafe; color: #1e40af; border-radius: 20px; font-size: 11px; font-weight: bold;">POLICY ENFORCED</span>
492
- </div>
493
-
494
- <div style="display: flex; justify-content: space-between; align-items: center; position: relative; margin-bottom: 25px;">
495
- <div style="position: absolute; top: -10px; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, #3b82f6, #10b981, #8b5cf6, #f59e0b);"></div>
496
-
497
- <div style="text-align: center; position: relative; flex: 1;">
498
- <div style="width: 50px; height: 50px; background: #3b82f6; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; font-size: 20px; font-weight: bold;">1</div>
499
- <div style="font-size: 13px; font-weight: 600; color: #1e293b;">Dampening</div>
500
- <div style="font-size: 11px; color: #64748b;">Prevent amplification</div>
501
- </div>
502
-
503
- <div style="font-size: 20px; color: #94a3b8;">→</div>
504
-
505
- <div style="text-align: center; position: relative; flex: 1;">
506
- <div style="width: 50px; height: 50px; background: #10b981; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; font-size: 20px; font-weight: bold;">2</div>
507
- <div style="font-size: 13px; font-weight: 600; color: #1e293b;">Concurrency Control</div>
508
- <div style="font-size: 11px; color: #64748b;">Manage load</div>
509
- </div>
510
-
511
- <div style="font-size: 20px; color: #94a3b8;">→</div>
512
-
513
- <div style="text-align: center; position: relative; flex: 1;">
514
- <div style="width: 50px; height: 50px; background: #8b5cf6; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; font-size: 20px; font-weight: bold;">3</div>
515
- <div style="font-size: 13px; font-weight: 600; color: #1e293b;">Observe</div>
516
- <div style="font-size: 11px; color: #64748b;">Validate trends</div>
517
- </div>
518
-
519
- <div style="font-size: 20px; color: #94a3b8;">→</div>
520
-
521
- <div style="text-align: center; position: relative; flex: 1;">
522
- <div style="width: 50px; height: 50px; background: #f59e0b; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; font-size: 20px; font-weight: bold;">4</div>
523
- <div style="font-size: 13px; font-weight: 600; color: #1e293b;">Scale</div>
524
- <div style="font-size: 11px; color: #64748b;">Only if necessary</div>
525
- </div>
526
- </div>
527
-
528
- <div style="padding: 15px; background: white; border-radius: 10px; border-left: 4px solid #3b82f6;">
529
- <div style="font-size: 13px; color: #475569; font-weight: 500;">
530
- <strong>Doctrinal Constraint:</strong> Scaling NEVER appears in same intent bundle as dampening.
531
- System must observe stabilization before considering capacity increases.
532
- </div>
533
- </div>
534
- </div>
535
- """)
536
 
537
  # Process Workflow Header (NOT Agent Workflow)
538
  workflow_header = gr.Markdown("## 🔄 Policy Process Workflow")
@@ -540,47 +1259,9 @@ def create_tab1_incident_demo(scenarios=INCIDENT_SCENARIOS, default_scenario="Ca
540
 
541
  # Process Status Cards (NOT Agent Status Cards)
542
  with gr.Row():
543
- detection_process = gr.HTML("""
544
- <div style="border: 2px solid #e2e8f0; border-radius: 14px; padding: 18px; background: #f8fafc; text-align: center; flex: 1; margin: 5px; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: 0.7;">
545
- <div style="font-size: 32px; margin-bottom: 10px; opacity: 0.5;">🕵️‍♂️</div>
546
- <div style="width: 100%;">
547
- <h4 style="margin: 0 0 8px 0; font-size: 16px; color: #94a3b8;">Detection Process</h4>
548
- <p style="font-size: 13px; color: #cbd5e1; margin-bottom: 12px; line-height: 1.4;">Click "Run Policy Analysis" to activate</p>
549
- <div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
550
- <span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.5); border-radius: 6px; color: #cbd5e1; font-weight: 500;">Status: Inactive</span>
551
- </div>
552
- <div style="display: inline-block; padding: 5px 14px; background: #e2e8f0; border-radius: 20px; font-size: 12px; font-weight: bold; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px;">WAITING</div>
553
- </div>
554
- </div>
555
- """)
556
-
557
- recall_process = gr.HTML("""
558
- <div style="border: 2px solid #e2e8f0; border-radius: 14px; padding: 18px; background: #f8fafc; text-align: center; flex: 1; margin: 5px; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: 0.7;">
559
- <div style="font-size: 32px; margin-bottom: 10px; opacity: 0.5;">🧠</div>
560
- <div style="width: 100%;">
561
- <h4 style="margin: 0 0 8px 0; font-size: 16px; color: #94a3b8;">Recall Process</h4>
562
- <p style="font-size: 13px; color: #cbd5e1; margin-bottom: 12px; line-height: 1.4;">Click "Run Policy Analysis" to activate</p>
563
- <div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
564
- <span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.5); border-radius: 6px; color: #cbd5e1; font-weight: 500;">Status: Inactive</span>
565
- </div>
566
- <div style="display: inline-block; padding: 5px 14px; background: #e2e8f0; border-radius: 20px; font-size: 12px; font-weight: bold; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px;">WAITING</div>
567
- </div>
568
- </div>
569
- """)
570
-
571
- decision_process = gr.HTML("""
572
- <div style="border: 2px solid #e2e8f0; border-radius: 14px; padding: 18px; background: #f8fafc; text-align: center; flex: 1; margin: 5px; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: 0.7;">
573
- <div style="font-size: 32px; margin-bottom: 10px; opacity: 0.5;">🎯</div>
574
- <div style="width: 100%;">
575
- <h4 style="margin: 0 0 8px 0; font-size: 16px; color: #94a3b8;">Decision Process</h4>
576
- <p style="font-size: 13px; color: #cbd5e1; margin-bottom: 12px; line-height: 1.4;">Click "Run Policy Analysis" to activate</p>
577
- <div style="display: flex; justify-content: space-around; margin-bottom: 12px;">
578
- <span style="font-size: 11px; padding: 3px 8px; background: rgba(255, 255, 255, 0.5); border-radius: 6px; color: #cbd5e1; font-weight: 500;">Status: Inactive</span>
579
- </div>
580
- <div style="display: inline-block; padding: 5px 14px; background: #e2e8f0; border-radius: 20px; font-size: 12px; font-weight: bold; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px;">WAITING</div>
581
- </div>
582
- </div>
583
- """)
584
 
585
  # Mode Selection & Safety Controls
586
  with gr.Row():
@@ -605,61 +1286,92 @@ def create_tab1_incident_demo(scenarios=INCIDENT_SCENARIOS, default_scenario="Ca
605
  boundary_header = gr.Markdown("### 🎭 Policy vs Execution: The Safety Boundary")
606
 
607
  with gr.Row():
608
- oss_section = gr.HTML("""
609
- <div style="padding: 20px; border-radius: 14px; margin-bottom: 15px; flex: 1; min-height: 320px; background: #f0f9ff; border: 2px solid #0ea5e9;">
610
- <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 15px; padding-bottom: 12px; border-bottom: 2px solid rgba(0, 0, 0, 0.1);">
611
- <div style="font-size: 28px;">🆓</div>
612
- <h3 style="margin: 0; font-size: 20px; color: #1e293b; flex: 1;">Policy Edition</h3>
613
- <span style="padding: 4px 10px; background: rgba(255, 255, 255, 0.9); border-radius: 8px; font-size: 11px; font-weight: bold; color: #475569;">Apache 2.0</span>
614
- </div>
615
- <div style="margin-bottom: 20px; padding: 12px; background: rgba(255, 255, 255, 0.7); border-radius: 10px;">
616
- <p style="margin: 0; font-size: 14px; color: #475569; font-weight: 500;"><strong>Analysis & Advisory Only</strong> - No execution, permanently safe</p>
617
- </div>
618
- <div style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
619
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #f1f5f9;">
620
- <h4 style="margin: 0; font-size: 16px; color: #1e293b;">📝 HealingIntent Created</h4>
621
- <span style="padding: 4px 10px; background: #dbeafe; color: #1d4ed8; border-radius: 6px; font-size: 12px; font-weight: bold;">94% confidence</span>
622
- </div>
623
  <div>
624
- <p style="margin: 8px 0; font-size: 14px; color: #475569;"><strong>Action:</strong> Implement request coalescing with exponential backoff</p>
625
- <p style="margin: 8px 0; font-size: 14px; color: #475569;"><strong>Pattern Match:</strong> Similar incident resolved with dampening (87% success rate)</p>
626
- <p style="margin: 8px 0; font-size= 14px; color: #475569;"><strong>Contraindications:</strong> ✅ Checked (retry amplification detected)</p>
627
- <p style="margin: 8px 0; font-size: 14px; color: #475569;"><strong>Sequencing Rule:</strong> dampening_first_then_observe_then_optional_scale</p>
628
  </div>
629
- <div style="margin-top: 20px; text-align: center;">
630
- <div style="height: 2px; background: linear-gradient(90deg, transparent, #3b82f6, transparent); margin: 8px 0;"></div>
631
- <div style="font-size: 12px; font-weight: bold; padding: 6px 12px; background: #fee2e2; color: #dc2626; border-radius: 8px; display: inline-block;">🚫 OSS STOPS HERE - No execution</div>
632
- <div style="height: 2px; background: linear-gradient(90deg, transparent, #3b82f6, transparent); margin: 8px 0;"></div>
633
  </div>
634
  </div>
635
- </div>
636
- """)
637
-
638
- enterprise_section = gr.HTML("""
639
- <div style="padding: 20px; border-radius: 14px; margin-bottom: 15px; flex: 1; min-height: 320px; background: #f0fdf4; border: 2px solid #10b981;">
640
- <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 15px; padding-bottom: 12px; border-bottom: 2px solid rgba(0, 0, 0, 0.1);">
641
- <div style="font-size: 28px;">💰</div>
642
- <h3 style="margin: 0; font-size: 20px; color: #1e293b; flex: 1;">Execution Edition</h3>
643
- <span style="padding: 4px 10px; background: rgba(255, 255, 255, 0.9); border-radius: 8px; font-size: 11px; font-weight: bold; color: #475569;">Commercial</span>
644
- </div>
645
- <div style="margin-bottom: 20px; padding: 12px; background: rgba(255, 255, 255, 0.7); border-radius: 10px;">
646
- <p style="margin: 0; font-size: 14px; color: #475569; font-weight: 500;"><strong>Full Execution & Learning</strong> - Autonomous healing with safety guarantees</p>
647
- </div>
648
- <div style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.05);">
649
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #f1f5f9;">
650
  <h4 style="margin: 0; font-size: 16px; color: #1e293b;">⚡ Ready to Execute</h4>
651
- <span style="padding: 4px 10px; background: #10b981; color: white; border-radius: 6px; font-size: 12px; font-weight: bold; text-transform: uppercase;">AUTONOMOUS</span>
652
  </div>
653
- <div>
654
- <p style="margin: 8px 0; font-size: 14px; color: #475569;"><strong>Mode:</strong> Autonomous (Requires Enterprise license)</p>
655
- <p style="margin: 8px 0; font-size: 14px; color: #475569;"><strong>Expected Recovery:</strong> 12 minutes (vs 45 min manual)</p>
656
- <p style="margin: 8px 0; font-size: 14px; color: #475569;"><strong>Cost Avoided:</strong> <span style="color: #10b981; font-weight: 700;">$6,375</span></p>
657
- <p style="margin: 8px 0; font-size= 14px; color: #475569;"><strong>Users Protected:</strong> 45,000 → 0 impacted</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
  </div>
659
- <div style="margin-top: 20px; text-align: center;">
660
- <div style="height: 2px; background: linear-gradient(90deg, transparent, #10b981, transparent); margin: 8px 0;"></div>
661
- <div style="font-size: 12px; font-weight: bold; padding: 6px 12px; background: #dcfce7; color: #166534; border-radius: 8px; display: inline-block;">✅ Enterprise executes with MCP safety</div>
662
- <div style="height: 2px; background: linear-gradient(90deg, transparent, #10b981, transparent); margin: 8px 0;"></div>
 
 
 
 
 
663
  </div>
664
  </div>
665
  </div>
@@ -686,6 +1398,7 @@ def create_tab1_incident_demo(scenarios=INCIDENT_SCENARIOS, default_scenario="Ca
686
  # Timeline visualization
687
  timeline_header = gr.Markdown("### ⏰ Incident Timeline")
688
  timeline_viz = gr.Plot(
 
689
  label="",
690
  show_label=False,
691
  elem_id="timeline_plot"
@@ -1120,296 +1833,6 @@ def create_tab5_learning_engine() -> tuple:
1120
 
1121
  return (learning_graph, graph_type, show_labels, search_query, search_btn,
1122
  clear_btn_search, search_results, stats_display, patterns_display, performance_display)
1123
-
1124
- # -----------------------------
1125
- # Realism Panel Component
1126
- # -----------------------------
1127
- def create_realism_panel(scenario_data: Dict, scenario_name: str) -> gr.HTML:
1128
- """
1129
- Create a realism panel showing ranked actions, risks, and uncertainty.
1130
- This makes ARF look cautious, opinionated, and enterprise-seasoned.
1131
- """
1132
- realism = scenario_data.get("realism", {})
1133
- ranked_actions = realism.get("ranked_actions", [])
1134
-
1135
- # Build ranked actions HTML
1136
- actions_html = ""
1137
- for action in ranked_actions:
1138
- rank_color = "#10b981" if action["rank"] == 1 else "#f59e0b" if action["rank"] == 2 else "#ef4444"
1139
- status = "✅ RECOMMENDED" if action["rank"] == 1 else "🟡 SECONDARY" if action["rank"] == 2 else "🔴 REJECTED"
1140
-
1141
- actions_html += f"""
1142
- <div style="border: 2px solid {rank_color}; border-radius: 12px; padding: 16px;
1143
- background: {rank_color}10; margin-bottom: 12px;">
1144
- <div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px;">
1145
- <div>
1146
- <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 5px;">
1147
- <div style="width: 24px; height: 24px; background: {rank_color};
1148
- color: white; border-radius: 50%; display: flex; align-items: center;
1149
- justify-content: center; font-size: 12px; font-weight: bold;">
1150
- {action['rank']}
1151
- </div>
1152
- <span style="font-size: 14px; font-weight: 600; color: #1e293b;">
1153
- {status} • {action['confidence']}% confidence
1154
- </span>
1155
- </div>
1156
- <p style="font-size: 14px; color: #475569; margin: 8px 0; font-weight: 500;">
1157
- {action['action']}
1158
- </p>
1159
- </div>
1160
- <div style="padding: 6px 12px; background: {rank_color}20; border-radius: 20px;
1161
- font-size: 12px; font-weight: bold; color: {rank_color};">
1162
- {action['confidence']}%
1163
- </div>
1164
- </div>
1165
-
1166
- <div style="font-size: 13px; color: #64748b; margin: 8px 0; line-height: 1.5;">
1167
- <strong>Rationale:</strong> {action.get('rationale', 'No rationale provided')}
1168
- </div>
1169
-
1170
- {"<div style='font-size: 13px; color: #dc2626; margin: 8px 0; padding: 8px; background: #fef2f2; border-radius: 6px; border-left: 3px solid #dc2626;'><strong>⚠️ Risk:</strong> " + action['risk'] + "</div>" if action.get('risk') else ""}
1171
-
1172
- {"<div style='font-size: 13px; color: #92400e; margin: 8px 0; padding: 8px; background: #fffbeb; border-radius: 6px; border-left: 3px solid #f59e0b;'><strong>🔄 Trade-off:</strong> " + action['tradeoff'] + "</div>" if action.get('tradeoff') else ""}
1173
-
1174
- {"<div style='font-size: 13px; color: #b45309; margin: 8px 0; padding: 8px; background: #fef3c7; border-radius: 6px; border-left: 3px solid #f59e0b;'><strong>⏱️ Execution:</strong> " + action['execution_time'] + "</div>" if action.get('execution_time') else ""}
1175
-
1176
- {"<div style='font-size: 13px; color: #b91c1c; margin: 8px 0; padding: 8px; background: #fee2e2; border-radius: 6px; border-left: 3px solid #ef4444;'><strong>🚫 Rejected:</strong> " + action['rejection_reason'] + "</div>" if action.get('rejection_reason') else ""}
1177
-
1178
- {"<div style='font-size: 13px; color: #7c3aed; margin: 8px 0; padding: 8px; background: #f5f3ff; border-radius: 6px; border-left: 3px solid #8b5cf6;'><strong>🛡️ Safety:</strong> " + action['safety_override'] + "</div>" if action.get('safety_override') else ""}
1179
- </div>
1180
- """
1181
-
1182
- # Build competing hypotheses (for Network Partition scenario)
1183
- hypotheses_html = ""
1184
- if realism.get("competing_hypotheses"):
1185
- hypotheses_html = """
1186
- <div style="margin-top: 20px; padding-top: 20px; border-top: 2px solid #e2e8f0;">
1187
- <div style="font-size: 15px; font-weight: 600; color: #1e293b; margin-bottom: 15px;">
1188
- 🧠 Competing Hypotheses
1189
- </div>
1190
- """
1191
- for hypo in realism["competing_hypotheses"]:
1192
- hypotheses_html += f"""
1193
- <div style="display: flex; align-items: center; gap: 15px; margin-bottom: 12px; padding: 12px;
1194
- background: #f8fafc; border-radius: 8px;">
1195
- <div style="font-size: 24px; color: #3b82f6;">?</div>
1196
- <div style="flex: 1;">
1197
- <div style="font-size: 14px; font-weight: 500; color: #1e293b; margin-bottom: 4px;">
1198
- {hypo['cause']} ({hypo['confidence']}%)
1199
- </div>
1200
- <div style="font-size: 12px; color: #64748b; margin-bottom: 6px;">
1201
- {hypo['evidence']}
1202
- </div>
1203
- <div style="font-size: 11px; color: #475569; font-weight: 500;">
1204
- Investigation: {hypo['investigation_path']}
1205
- </div>
1206
- </div>
1207
- <div style="width: 60px; height: 60px; background: conic-gradient(#3b82f6 0% {hypo['confidence']}%, #e2e8f0 {hypo['confidence']}% 100%);
1208
- border-radius: 50%; display: flex; align-items: center; justify-content: center;">
1209
- <div style="width: 50px; height: 50px; background: white; border-radius: 50%;
1210
- display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: bold; color: #1e293b;">
1211
- {hypo['confidence']}%
1212
- </div>
1213
- </div>
1214
- </div>
1215
- """
1216
- hypotheses_html += "</div>"
1217
-
1218
- # Build risk assessment panel
1219
- risk_html = ""
1220
- if realism.get("risk_assessment"):
1221
- risk_html = """
1222
- <div style="margin-top: 20px; padding-top: 20px; border-top: 2px solid #e2e8f0;">
1223
- <div style="font-size: 15px; font-weight: 600; color: #1e293b; margin-bottom: 15px;">
1224
- ⚠️ Risk Assessment
1225
- </div>
1226
- <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;">
1227
- """
1228
- for key, value in realism["risk_assessment"].items():
1229
- risk_html += f"""
1230
- <div style="padding: 12px; background: #f8fafc; border-radius: 8px; border-left: 4px solid #f59e0b;">
1231
- <div style="font-size: 12px; color: #64748b; text-transform: uppercase; margin-bottom: 4px;">
1232
- {key.replace('_', ' ').title()}
1233
- </div>
1234
- <div style="font-size: 14px; font-weight: 600; color: #92400e;">
1235
- {value}
1236
- </div>
1237
- </div>
1238
- """
1239
- risk_html += "</div></div>"
1240
-
1241
- # Build confidence degradation panel
1242
- confidence_html = ""
1243
- if realism.get("confidence_degradation"):
1244
- conf = realism["confidence_degradation"]
1245
- confidence_html = f"""
1246
- <div style="margin-top: 20px; padding-top: 20px; border-top: 2px solid #e2e8f0;">
1247
- <div style="font-size: 15px; font-weight: 600; color: #1e293b; margin-bottom: 15px;">
1248
- ⏱️ Confidence Degradation Over Time
1249
- </div>
1250
- <div style="background: #f8fafc; border-radius: 10px; padding: 20px;">
1251
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
1252
- <div style="text-align: center;">
1253
- <div style="font-size: 28px; font-weight: 700; color: #10b981;">{conf['initial']}%</div>
1254
- <div style="font-size: 12px; color: #64748b;">Initial Confidence</div>
1255
- </div>
1256
- <div style="font-size: 24px; color: #94a3b8;">→</div>
1257
- <div style="text-align: center;">
1258
- <div style="font-size: 28px; font-weight: 700; color: #f59e0b;">{conf['after_8_min']}%</div>
1259
- <div style="font-size: 12px; color: #64748b;">After 8 minutes</div>
1260
- </div>
1261
- <div style="font-size: 24px; color: #94a3b8;">→</div>
1262
- <div style="text-align: center;">
1263
- <div style="font-size: 28px; font-weight: 700; color: #ef4444;">{conf['after_15_min']}%</div>
1264
- <div style="font-size: 12px; color: #64748b;">After 15 minutes</div>
1265
- </div>
1266
- </div>
1267
-
1268
- <div style="height: 10px; background: #e2e8f0; border-radius: 5px; margin: 20px 0; position: relative;">
1269
- <div style="position: absolute; left: 0; width: 100%; height: 100%; background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444); border-radius: 5px;"></div>
1270
- <div style="position: absolute; left: {conf['escalation_threshold']}%; top: -5px; width: 2px; height: 20px; background: #1e293b;"></div>
1271
- <div style="position: absolute; left: {conf['escalation_threshold']}%; top: 25px; font-size: 11px; color: #64748b; transform: translateX(-50%);">
1272
- Escalation at {conf['escalation_threshold']}%
1273
- </div>
1274
- </div>
1275
-
1276
- <div style="padding: 12px; background: #fef3c7; border-radius: 8px; border-left: 4px solid #f59e0b;">
1277
- <div style="font-size: 13px; color: #92400e; font-weight: 500;">
1278
- ⚠️ ARF escalates to human operators when confidence drops below {conf['escalation_threshold']}%
1279
- </div>
1280
- <div style="font-size: 12px; color: #b45309; margin-top: 5px;">
1281
- This prevents autonomous execution in high-uncertainty scenarios
1282
- </div>
1283
- </div>
1284
- </div>
1285
- </div>
1286
- """
1287
-
1288
- # Build "What ARF Will NOT Do" panel (global)
1289
- wont_do_html = """
1290
- <div style="margin-top: 20px; padding-top: 20px; border-top: 2px solid #e2e8f0;">
1291
- <div style="font-size: 15px; font-weight: 600; color: #1e293b; margin-bottom: 15px;">
1292
- 🚫 What ARF Will NOT Do (Safety Boundaries)
1293
- </div>
1294
- <div style="background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
1295
- border: 2px solid #ef4444; border-radius: 12px; padding: 20px;">
1296
- <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px;">
1297
- <div style="display: flex; align-items: flex-start; gap: 10px;">
1298
- <div style="font-size: 20px; color: #ef4444;">⛔</div>
1299
- <div>
1300
- <div style="font-size: 14px; font-weight: 600; color: #7f1d1d;">Restart stateful leaders</div>
1301
- <div style="font-size: 12px; color: #b91c1c;">During peak traffic or elections</div>
1302
- </div>
1303
- </div>
1304
- <div style="display: flex; align-items: flex-start; gap: 10px;">
1305
- <div style="font-size: 20px; color: #ef4444;">⛔</div>
1306
- <div>
1307
- <div style="font-size: 14px; font-weight: 600; color: #7f1d1d;">Apply schema changes</div>
1308
- <div style="font-size: 12px; color: #b91c1c;">To production databases autonomously</div>
1309
- </div>
1310
- </div>
1311
- <div style="display: flex; align-items: flex-start; gap: 10px;">
1312
- <div style="font-size: 20px; color: #ef4444;">⛔</div>
1313
- <div>
1314
- <div style="font-size: 14px; font-weight: 600; color: #7f1d1d;">Exceed API limits</div>
1315
- <div style="font-size: 12px; color: #b91c1c;">Contractual or rate limits</div>
1316
- </div>
1317
- </div>
1318
- <div style="display: flex; align-items: flex-start; gap: 10px;">
1319
- <div style="font-size: 20px; color: #ef4444;">⛔</div>
1320
- <div>
1321
- <div style="font-size: 14px; font-weight: 600; color: #7f1d1d;">Modify ACLs/RBAC</div>
1322
- <div style="font-size: 12px; color: #b91c1c;">Security permissions autonomously</div>
1323
- </div>
1324
- </div>
1325
- </div>
1326
- <div style="margin-top: 15px; padding: 12px; background: rgba(255, 255, 255, 0.7);
1327
- border-radius: 8px; border-left: 4px solid #dc2626;">
1328
- <div style="font-size: 13px; color: #7f1d1d; font-weight: 500;">
1329
- These boundaries ensure ARF operates within safe, reversible limits.
1330
- Enterprise edition adds approval workflows for edge cases.
1331
- </div>
1332
- </div>
1333
- </div>
1334
- </div>
1335
- """
1336
-
1337
- # Combine all panels
1338
- full_html = f"""
1339
- <div style="border: 2px solid #3b82f6; border-radius: 16px; padding: 25px;
1340
- background: linear-gradient(135deg, #f0f9ff 0%, #ffffff 100%);">
1341
-
1342
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
1343
- <div>
1344
- <h3 style="margin: 0 0 8px 0; font-size: 18px; color: #1e293b; font-weight: 700;">
1345
- 🎯 Ranked Healing Intents
1346
- </h3>
1347
- <p style="margin: 0; font-size: 13px; color: #64748b;">
1348
- ARF evaluates multiple options with confidence scores and risk assessments
1349
- </p>
1350
- </div>
1351
- <div style="padding: 8px 16px; background: #dbeafe; color: #1e40af;
1352
- border-radius: 20px; font-size: 12px; font-weight: bold;">
1353
- REALISM UPGRADE v3.3.9+
1354
- </div>
1355
- </div>
1356
-
1357
- {actions_html}
1358
- {hypotheses_html}
1359
- {risk_html}
1360
- {confidence_html}
1361
- {wont_do_html}
1362
-
1363
- <!-- ROI as Ranges -->
1364
- <div style="margin-top: 20px; padding-top: 20px; border-top: 2px solid #e2e8f0;">
1365
- <div style="font-size: 15px; font-weight: 600; color: #1e293b; margin-bottom: 15px;">
1366
- 📈 Realistic ROI Estimates (Ranges)
1367
- </div>
1368
- <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px;">
1369
- <div style="text-align: center; padding: 15px; background: #f8fafc; border-radius: 10px;">
1370
- <div style="font-size: 16px; font-weight: 700; color: #10b981;">$5.8K – $7.2K</div>
1371
- <div style="font-size: 12px; color: #64748b;">Cost Avoided</div>
1372
- <div style="font-size: 11px; color: #94a3b8; margin-top: 5px;">Estimated range</div>
1373
- </div>
1374
- <div style="text-align: center; padding: 15px; background: #f8fafc; border-radius: 10px;">
1375
- <div style="font-size: 16px; font-weight: 700; color: #10b981;">4.8× – 5.6×</div>
1376
- <div style="font-size: 12px; color: #64748b;">ROI Multiplier</div>
1377
- <div style="font-size: 11px; color: #94a3b8; margin-top: 5px;">Confidence interval</div>
1378
- </div>
1379
- <div style="text-align: center; padding: 15px; background: #f8fafc; border-radius: 10px;">
1380
- <div style="font-size: 16px; font-weight: 700; color: #10b981;">68% – 87%</div>
1381
- <div style="font-size: 12px; color: #64748b;">Success Rate</div>
1382
- <div style="font-size: 11px; color: #94a3b8; margin-top: 5px;">Based on similar incidents</div>
1383
- </div>
1384
- </div>
1385
- <div style="margin-top: 15px; padding: 12px; background: #f0fdf4; border-radius: 8px;">
1386
- <div style="font-size: 13px; color: #065f46; text-align: center; font-weight: 500;">
1387
- 📊 Real systems have ranges, not single-point estimates. ARF shows uncertainty honestly.
1388
- </div>
1389
- </div>
1390
- </div>
1391
-
1392
- <!-- Engineering Insight -->
1393
- <div style="margin-top: 20px; padding: 20px; background: #f8fafc; border-radius: 12px;
1394
- border-left: 4px solid #3b82f6;">
1395
- <div style="display: flex; align-items: flex-start; gap: 15px;">
1396
- <div style="font-size: 32px;">🎭</div>
1397
- <div>
1398
- <div style="font-size: 14px; font-weight: 600; color: #1e293b; margin-bottom: 8px;">
1399
- What Senior SREs Expect at 3 a.m.
1400
- </div>
1401
- <div style="font-size: 13px; color: #475569; line-height: 1.6;">
1402
- "Real systems hesitate. Real systems explain risk. Real systems earn trust.
1403
- ARF shows multiple options with confidence scores because in production,
1404
- there's never a single perfect answer—just trade-offs managed carefully."
1405
- </div>
1406
- </div>
1407
- </div>
1408
- </div>
1409
- </div>
1410
- """
1411
-
1412
- return gr.HTML(full_html)
1413
 
1414
  # -----------------------------
1415
  # Footer
 
12
  import logging
13
  import datetime
14
  import time
15
+ import plotly.graph_objects as go
16
+ import plotly.express as px
17
+ import numpy as np
18
 
19
  logger = logging.getLogger(__name__)
20
 
 
70
  </div>
71
  """)
72
 
73
+ # -----------------------------
74
+ # CRITICAL RESTORED FUNCTIONS - Missing from current version
75
+ # -----------------------------
76
+
77
+ def create_observation_gate_placeholder(confidence: float = 65.0) -> gr.HTML:
78
+ """Observation gate that demonstrates psychological restraint.
79
+
80
+ Shows 'Decision Intentionally Deferred' when confidence is below threshold.
81
+ This is a critical doctrinal component showing restraint as a system choice.
82
+ """
83
+ if confidence < 70.0:
84
+ html_content = f"""
85
+ <div class="observation-gate" style="
86
+ border: 2px solid #4A5568;
87
+ border-radius: 8px;
88
+ padding: 20px;
89
+ margin: 10px 0;
90
+ background: linear-gradient(135deg, #1A202C 0%, #2D3748 100%);
91
+ color: #E2E8F0;
92
+ font-family: 'Inter', sans-serif;
93
+ ">
94
+ <div style="display: flex; align-items: center; margin-bottom: 15px;">
95
+ <div style="
96
+ background: #2D3748;
97
+ border-radius: 50%;
98
+ width: 40px;
99
+ height: 40px;
100
+ display: flex;
101
+ align-items: center;
102
+ justify-content: center;
103
+ margin-right: 15px;
104
+ border: 2px solid #4A5568;
105
+ ">
106
+ <span style="font-size: 20px;">⚠️</span>
107
+ </div>
108
+ <div>
109
+ <h3 style="margin: 0; color: #E2E8F0; font-weight: 600;">OBSERVATION GATE ACTIVE</h3>
110
+ <p style="margin: 5px 0 0 0; color: #A0AEC0; font-size: 14px;">System restraint engaged</p>
111
+ </div>
112
+ </div>
113
+
114
+ <div style="
115
+ background: rgba(45, 55, 72, 0.5);
116
+ border-left: 4px solid #ECC94B;
117
+ padding: 15px;
118
+ margin: 15px 0;
119
+ border-radius: 0 4px 4px 0;
120
+ ">
121
+ <h4 style="margin: 0 0 10px 0; color: #ECC94B; font-weight: 500;">
122
+ Decision Intentionally Deferred
123
+ </h4>
124
+ <p style="margin: 0; color: #CBD5E0; font-size: 14px; line-height: 1.5;">
125
+ The system has detected uncertainty ({confidence:.1f}% confidence) and has chosen to observe rather than act.
126
+ This is not a limitation—it is a psychological advantage demonstrating restraint.
127
+ Historical evidence suggests premature action increases risk by 47%.
128
+ </p>
129
+ </div>
130
+
131
+ <div style="display: flex; justify-content: space-between; align-items: center;">
132
+ <div>
133
+ <span style="color: #A0AEC0; font-size: 13px;">Confidence threshold: 70.0%</span>
134
+ </div>
135
+ <div>
136
+ <span style="
137
+ display: inline-block;
138
+ background: #4A5568;
139
+ color: white;
140
+ padding: 4px 12px;
141
+ border-radius: 12px;
142
+ font-size: 13px;
143
+ font-weight: 500;
144
+ ">
145
+ {confidence:.1f}% confidence
146
+ </span>
147
+ </div>
148
+ </div>
149
+ </div>
150
+ """
151
+ else:
152
+ html_content = """
153
+ <div class="observation-gate" style="
154
+ border: 2px solid #38A169;
155
+ border-radius: 8px;
156
+ padding: 20px;
157
+ margin: 10px 0;
158
+ background: linear-gradient(135deg, #1A202C 0%, #2D3748 100%);
159
+ color: #E2E8F0;
160
+ font-family: 'Inter', sans-serif;
161
+ ">
162
+ <div style="display: flex; align-items: center; margin-bottom: 15px;">
163
+ <div style="
164
+ background: #2D3748;
165
+ border-radius: 50%;
166
+ width: 40px;
167
+ height: 40px;
168
+ display: flex;
169
+ align-items: center;
170
+ justify-content: center;
171
+ margin-right: 15px;
172
+ border: 2px solid #38A169;
173
+ ">
174
+ <span style="font-size: 20px;">✅</span>
175
+ </div>
176
+ <div>
177
+ <h3 style="margin: 0; color: #E2E8F0; font-weight: 600;">OBSERVATION GATE CLEARED</h3>
178
+ <p style="margin: 5px 0 0 0; color: #A0AEC0; font-size: 14px;">Confidence threshold met</p>
179
+ </div>
180
+ </div>
181
+
182
+ <div style="
183
+ background: rgba(56, 161, 105, 0.15);
184
+ border-left: 4px solid #38A169;
185
+ padding: 15px;
186
+ margin: 15px 0;
187
+ border-radius: 0 4px 4px 0;
188
+ ">
189
+ <h4 style="margin: 0 0 10px 0; color: #38A169; font-weight: 500;">
190
+ Proceed with Policy Action
191
+ </h4>
192
+ <p style="margin: 0; color: #CBD5E0; font-size: 14px; line-height: 1.5;">
193
+ Confidence exceeds threshold. System may proceed with sequenced actions.
194
+ Historical evidence will be consulted before any execution.
195
+ </p>
196
+ </div>
197
+
198
+ <div style="display: flex; justify-content: space-between; align-items: center;">
199
+ <div>
200
+ <span style="color: #A0AEC0; font-size: 13px;">Confidence threshold: 70.0%</span>
201
+ </div>
202
+ <div>
203
+ <span style="
204
+ display: inline-block;
205
+ background: #38A169;
206
+ color: white;
207
+ padding: 4px 12px;
208
+ border-radius: 12px;
209
+ font-size: 13px;
210
+ font-weight: 500;
211
+ ">
212
+ 85.0% confidence
213
+ </span>
214
+ </div>
215
+ </div>
216
+ </div>
217
+ """
218
+
219
+ return gr.HTML(html_content)
220
+
221
+ def create_sequencing_visualization() -> gr.HTML:
222
+ """Creates the sequencing panel showing dampening-first progression.
223
+
224
+ Doctrinal: Shows sequencing as policy, not reaction.
225
+ """
226
+ return gr.HTML("""
227
+ <div style="border: 2px solid #3b82f6; border-radius: 16px; padding: 25px; background: linear-gradient(135deg, #f0f9ff 0%, #ffffff 100%); margin-bottom: 25px;">
228
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
229
+ <div>
230
+ <h3 style="margin: 0 0 8px 0; font-size: 20px; color: #1e293b; font-weight: 700;">
231
+ 🔄 Doctrinal Sequencing: Policy Over Reaction
232
+ </h3>
233
+ <p style="margin: 0; font-size: 14px; color: #64748b;">
234
+ System enforces sequencing regardless of prediction confidence
235
+ </p>
236
+ </div>
237
+ <div style="padding: 8px 16px; background: #dbeafe; color: #1e40af; border-radius: 20px; font-size: 12px; font-weight: bold;">
238
+ POLICY ENFORCED
239
+ </div>
240
+ </div>
241
+
242
+ <!-- Sequencing Steps -->
243
+ <div style="display: flex; justify-content: space-between; align-items: center; position: relative; margin-bottom: 30px;">
244
+ <!-- Connecting line -->
245
+ <div style="position: absolute; top: 50%; left: 60px; right: 60px; height: 3px; background: linear-gradient(90deg, #3b82f6, #10b981, #8b5cf6, #f59e0b); z-index: 1;"></div>
246
+
247
+ <!-- Step 1: Dampening -->
248
+ <div style="text-align: center; position: relative; z-index: 2; flex: 1;">
249
+ <div style="width: 60px; height: 60px; background: #3b82f6; color: white; border-radius: 50%;
250
+ display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
251
+ font-size: 24px; font-weight: bold; border: 4px solid white; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);">
252
+ 1
253
+ </div>
254
+ <div style="font-size: 15px; font-weight: 700; color: #1e293b; margin-bottom: 5px;">Dampening</div>
255
+ <div style="font-size: 12px; color: #64748b; max-width: 180px; margin: 0 auto;">Prevent amplification first</div>
256
+ <div style="margin-top: 10px; padding: 6px 12px; background: #3b82f6; color: white; border-radius: 15px;
257
+ font-size: 11px; font-weight: bold; display: inline-block;">
258
+ REQUIRED
259
+ </div>
260
+ </div>
261
+
262
+ <!-- Arrow -->
263
+ <div style="font-size: 28px; color: #94a3b8; z-index: 2;">→</div>
264
+
265
+ <!-- Step 2: Concurrency Control -->
266
+ <div style="text-align: center; position: relative; z-index: 2; flex: 1;">
267
+ <div style="width: 60px; height: 60px; background: #10b981; color: white; border-radius: 50%;
268
+ display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
269
+ font-size: 24px; font-weight: bold; border: 4px solid white; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">
270
+ 2
271
+ </div>
272
+ <div style="font-size: 15px; font-weight: 700; color: #1e293b; margin-bottom: 5px;">Concurrency</div>
273
+ <div style="font-size: 12px; color: #64748b; max-width: 180px; margin: 0 auto;">Manage load, then observe</div>
274
+ <div style="margin-top: 10px; padding: 6px 12px; background: #10b981; color: white; border-radius: 15px;
275
+ font-size: 11px; font-weight: bold; display: inline-block;">
276
+ REQUIRED
277
+ </div>
278
+ </div>
279
+
280
+ <!-- Arrow -->
281
+ <div style="font-size: 28px; color: #94a3b8; z-index: 2;">→</div>
282
+
283
+ <!-- Step 3: Observe -->
284
+ <div style="text-align: center; position: relative; z-index: 2; flex: 1;">
285
+ <div style="width: 60px; height: 60px; background: #8b5cf6; color: white; border-radius: 50%;
286
+ display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
287
+ font-size: 24px; font-weight: bold; border: 4px solid white; box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);">
288
+ 3
289
+ </div>
290
+ <div style="font-size: 15px; font-weight: 700; color: #1e293b; margin-bottom: 5px;">Observe</div>
291
+ <div style="font-size: 12px; color: #64748b; max-width: 180px; margin: 0 auto;">Validate trends for 5+ minutes</div>
292
+ <div style="margin-top: 10px; padding: 6px 12px; background: #8b5cf6; color: white; border-radius: 15px;
293
+ font-size: 11px; font-weight: bold; display: inline-block;">
294
+ REQUIRED
295
+ </div>
296
+ </div>
297
+
298
+ <!-- Arrow -->
299
+ <div style="font-size: 28px; color: #94a3b8; z-index: 2;">→</div>
300
+
301
+ <!-- Step 4: Scale -->
302
+ <div style="text-align: center; position: relative; z-index: 2; flex: 1;">
303
+ <div style="width: 60px; height: 60px; background: #f59e0b; color: white; border-radius: 50%;
304
+ display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;
305
+ font-size: 24px; font-weight: bold; border: 4px solid white; box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);">
306
+ 4
307
+ </div>
308
+ <div style="font-size: 15px; font-weight: 700; color: #1e293b; margin-bottom: 5px;">Scale</div>
309
+ <div style="font-size: 12px; color: #64748b; max-width: 180px; margin: 0 auto;">Only if all previous succeed</div>
310
+ <div style="margin-top: 10px; padding: 6px 12px; background: #f59e0b; color: white; border-radius: 15px;
311
+ font-size: 11px; font-weight: bold; display: inline-block;">
312
+ OPTIONAL
313
+ </div>
314
+ </div>
315
+ </div>
316
+
317
+ <!-- Doctrinal Constraint -->
318
+ <div style="background: #f8fafc; border-radius: 12px; padding: 20px; border-left: 4px solid #3b82f6;">
319
+ <div style="display: flex; align-items: flex-start; gap: 15px;">
320
+ <div style="font-size: 24px; color: #3b82f6;">🎯</div>
321
+ <div style="flex: 1;">
322
+ <div style="font-size: 16px; font-weight: 600; color: #1e293b; margin-bottom: 8px;">
323
+ Doctrinal Constraint: Scaling Cannot Appear First
324
+ </div>
325
+ <div style="font-size: 14px; color: #475569; line-height: 1.6;">
326
+ If retry amplification is detected, scaling is <strong>contraindicated entirely</strong>.
327
+ The system must observe stabilization before considering capacity increases.
328
+ Historical evidence shows scaling-first fails 76% of the time during amplification.
329
+ </div>
330
+ </div>
331
+ </div>
332
+ </div>
333
+
334
+ <!-- Sequence State -->
335
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-top: 20px;
336
+ padding-top: 20px; border-top: 2px solid #e2e8f0;">
337
+ <div>
338
+ <div style="font-size: 13px; color: #64748b; margin-bottom: 5px;">Current Sequence State</div>
339
+ <div style="font-size: 15px; font-weight: 600; color: #1e293b;">Waiting for detection process</div>
340
+ </div>
341
+ <div style="display: flex; gap: 10px;">
342
+ <div style="padding: 8px 16px; background: #f1f5f9; color: #64748b; border-radius: 20px; font-size: 12px; font-weight: 500;">
343
+ 🔄 Sequence: 0/4
344
+ </div>
345
+ <div style="padding: 8px 16px; background: #f1f5f9; color: #64748b; border-radius: 20px; font-size: 12px; font-weight: 500;">
346
+ ⏱️ Time: 0s
347
+ </div>
348
+ </div>
349
+ </div>
350
+ </div>
351
+ """)
352
+
353
+ def create_detection_display() -> gr.HTML:
354
+ """Creates detection process HTML display."""
355
+ return gr.HTML("""
356
+ <div style="border: 2px solid #3b82f6; border-radius: 14px; padding: 20px; background: linear-gradient(135deg, #f0f9ff 0%, #ffffff 100%); margin: 10px 0;">
357
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
358
+ <div style="display: flex; align-items: center; gap: 12px;">
359
+ <div style="width: 40px; height: 40px; background: #3b82f6; color: white; border-radius: 50%;
360
+ display: flex; align-items: center; justify-content: center; font-size: 18px;">
361
+ 🕵️‍♂️
362
+ </div>
363
+ <div>
364
+ <h4 style="margin: 0 0 4px 0; font-size: 16px; color: #1e293b; font-weight: 600;">Detection Process</h4>
365
+ <p style="margin: 0; font-size: 13px; color: #64748b;">Telemetry analysis & pattern recognition</p>
366
+ </div>
367
+ </div>
368
+ <div style="padding: 6px 14px; background: #dbeafe; color: #1d4ed8; border-radius: 20px; font-size: 12px; font-weight: bold;">
369
+ STATUS: ACTIVE
370
+ </div>
371
+ </div>
372
+
373
+ <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-bottom: 20px;">
374
+ <div style="padding: 12px; background: #f8fafc; border-radius: 8px;">
375
+ <div style="font-size: 12px; color: #64748b; margin-bottom: 5px;">Pattern Match</div>
376
+ <div style="font-size: 14px; color: #1e293b; font-weight: 500;">Retry Amplification</div>
377
+ </div>
378
+ <div style="padding: 12px; background: #f8fafc; border-radius: 8px;">
379
+ <div style="font-size: 12px; color: #64748b; margin-bottom: 5px;">Confidence</div>
380
+ <div style="font-size: 14px; color: #1e293b; font-weight: 500;">92.7%</div>
381
+ </div>
382
+ <div style="padding: 12px; background: #f8fafc; border-radius: 8px;">
383
+ <div style="font-size: 12px; color: #64748b; margin-bottom: 5px;">Detection Time</div>
384
+ <div style="font-size: 14px; color: #1e293b; font-weight: 500;">0.8 seconds</div>
385
+ </div>
386
+ <div style="padding: 12px; background: #f8fafc; border-radius: 8px;">
387
+ <div style="font-size: 12px; color: #64748b; margin-bottom: 5px;">Severity</div>
388
+ <div style="font-size: 14px; color: #f59e0b; font-weight: 500;">HIGH_VARIANCE</div>
389
+ </div>
390
+ </div>
391
+
392
+ <div style="background: #f0fdf4; border-radius: 10px; padding: 15px; border-left: 4px solid #10b981;">
393
+ <div style="font-size: 14px; color: #065f46; font-weight: 500;">
394
+ ✅ Detected: Retry amplification pattern with exponential growth (r=1.8)
395
+ </div>
396
+ <div style="font-size: 13px; color: #047857; margin-top: 5px;">
397
+ Telemetry shows request rate doubling every 45 seconds. System flagged for sequencing enforcement.
398
+ </div>
399
+ </div>
400
+
401
+ <div style="margin-top: 15px; display: flex; justify-content: space-between; align-items: center;">
402
+ <div>
403
+ <div style="font-size: 12px; color: #64748b;">Next Step:</div>
404
+ <div style="font-size: 13px; color: #1e293b; font-weight: 500;">Activate recall process</div>
405
+ </div>
406
+ <div style="display: flex; gap: 8px;">
407
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">📊 12 metrics</span>
408
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">⏱️ 0.8s latency</span>
409
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">🔍 3 patterns</span>
410
+ </div>
411
+ </div>
412
+ </div>
413
+ """)
414
+
415
+ def create_recall_display() -> gr.HTML:
416
+ """Creates recall process HTML display with historical evidence dominance."""
417
+ return gr.HTML("""
418
+ <div style="border: 2px solid #8b5cf6; border-radius: 14px; padding: 20px; background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%); margin: 10px 0;">
419
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
420
+ <div style="display: flex; align-items: center; gap: 12px;">
421
+ <div style="width: 40px; height: 40px; background: #8b5cf6; color: white; border-radius: 50%;
422
+ display: flex; align-items: center; justify-content: center; font-size: 18px;">
423
+ 🧠
424
+ </div>
425
+ <div>
426
+ <h4 style="margin: 0 0 4px 0; font-size: 16px; color: #1e293b; font-weight: 600;">Recall Process</h4>
427
+ <p style="margin: 0; font-size: 13px; color: #64748b;">Historical evidence & pattern matching</p>
428
+ </div>
429
+ </div>
430
+ <div style="padding: 6px 14px; background: #ede9fe; color: #5b21b6; border-radius: 20px; font-size: 12px; font-weight: bold;">
431
+ STATUS: ACTIVE
432
+ </div>
433
+ </div>
434
+
435
+ <div style="background: #f5f3ff; border-radius: 10px; padding: 20px; margin-bottom: 20px;">
436
+ <div style="font-size: 15px; font-weight: 600; color: #5b21b6; margin-bottom: 15px; display: flex; align-items: center; gap: 8px;">
437
+ 🏆 RECALL DOMINANCE: Historical Evidence > Predictive Confidence
438
+ </div>
439
+
440
+ <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
441
+ <!-- Scaling-First Failures -->
442
+ <div>
443
+ <div style="font-size: 14px; font-weight: 600; color: #dc2626; margin-bottom: 12px; display: flex; align-items: center; gap: 6px;">
444
+ ⛔ Scaling-First Failures
445
+ </div>
446
+
447
+ <div style="border-left: 3px solid #dc2626; padding-left: 12px; margin-bottom: 15px;">
448
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
449
+ <div style="font-size: 12px; font-weight: 600; color: #1e293b;">2024-11-15 • prod-east</div>
450
+ <div style="padding: 2px 8px; background: #fee2e2; color: #dc2626; border-radius: 10px; font-size: 10px; font-weight: bold;">FAILED</div>
451
+ </div>
452
+ <div style="font-size: 11px; color: #475569; margin-bottom: 3px;">
453
+ <strong>Action:</strong> Scale during retry storm
454
+ </div>
455
+ <div style="font-size: 11px; color: #dc2626; font-weight: 500; margin-bottom: 3px;">
456
+ <strong>Outcome:</strong> Amplification increased 300%
457
+ </div>
458
+ <div style="font-size: 10px; color: #7f1d1d; font-style: italic; background: #fef2f2; padding: 6px; border-radius: 4px;">
459
+ "Scaling during amplification worsens the problem"
460
+ </div>
461
+ </div>
462
+
463
+ <div style="border-left: 3px solid #dc2626; padding-left: 12px;">
464
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
465
+ <div style="font-size: 12px; font-weight: 600; color: #1e293b;">2024-09-22 • staging</div>
466
+ <div style="padding: 2px 8px; background: #fee2e2; color: #dc2626; border-radius: 10px; font-size: 10px; font-weight: bold;">FAILED</div>
467
+ </div>
468
+ <div style="font-size: 11px; color: #475569; margin-bottom: 3px;">
469
+ <strong>Action:</strong> Add capacity without dampening
470
+ </div>
471
+ <div style="font-size: 11px; color: #dc2626; font-weight: 500; margin-bottom: 3px;">
472
+ <strong>Outcome:</strong> 45 min outage, $8.2K loss
473
+ </div>
474
+ <div style="font-size: 10px; color: #7f1d1d; font-style: italic; background: #fef2f2; padding: 6px; border-radius: 4px;">
475
+ "New capacity consumed by amplification loop"
476
+ </div>
477
+ </div>
478
+ </div>
479
+
480
+ <!-- Dampening-First Successes -->
481
+ <div>
482
+ <div style="font-size: 14px; font-weight: 600; color: #10b981; margin-bottom: 12px; display: flex; align-items: center; gap: 6px;">
483
+ ✅ Dampening-First Successes
484
+ </div>
485
+
486
+ <div style="border-left: 3px solid #10b981; padding-left: 12px; margin-bottom: 15px;">
487
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
488
+ <div style="font-size: 12px; font-weight: 600; color: #1e293b;">2024-12-03 • prod-west</div>
489
+ <div style="padding: 2px 8px; background: #dcfce7; color: #166534; border-radius: 10px; font-size: 10px; font-weight: bold;">SUCCESS</div>
490
+ </div>
491
+ <div style="font-size: 11px; color: #475569; margin-bottom: 3px;">
492
+ <strong>Action:</strong> Request coalescing + backoff
493
+ </div>
494
+ <div style="font-size: 11px; color: #10b981; font-weight: 500; margin-bottom: 3px;">
495
+ <strong>Outcome:</strong> Resolved in 8 min, $5.1K saved
496
+ </div>
497
+ <div style="font-size: 10px; color: #065f46; font-style: italic; background: #f0fdf4; padding: 6px; border-radius: 4px;">
498
+ "Dampening broke amplification cycle"
499
+ </div>
500
+ </div>
501
+
502
+ <div style="border-left: 3px solid #10b981; padding-left: 12px;">
503
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
504
+ <div style="font-size: 12px; font-weight: 600; color: #1e293b;">2024-10-17 • prod-eu</div>
505
+ <div style="padding: 2px 8px; background: #dcfce7; color: #166534; border-radius: 10px; font-size: 10px; font-weight: bold;">SUCCESS</div>
506
+ </div>
507
+ <div style="font-size: 11px; color: #475569; margin-bottom: 3px;">
508
+ <strong>Action:</strong> Circuit breaker + observability
509
+ </div>
510
+ <div style="font-size: 11px; color: #10b981; font-weight: 500; margin-bottom: 3px;">
511
+ <strong>Outcome:</strong> 12 min recovery, 0 user impact
512
+ </div>
513
+ <div style="font-size: 10px; color: #065f46; font-style: italic; background: #f0fdf4; padding: 6px; border-radius: 4px;">
514
+ "Sequencing prevented escalation"
515
+ </div>
516
+ </div>
517
+ </div>
518
+ </div>
519
+ </div>
520
+
521
+ <div style="background: #fef3c7; border-radius: 10px; padding: 15px; border-left: 4px solid #f59e0b;">
522
+ <div style="font-size: 14px; color: #92400e; font-weight: 500; margin-bottom: 5px;">
523
+ 🎯 RECALL DECISION: Scaling contraindicated due to historical evidence
524
+ </div>
525
+ <div style="font-size: 13px; color: #b45309;">
526
+ Historical evidence (76% failure rate) dominates predictive confidence (92%).
527
+ System will enforce dampening-first sequencing.
528
+ </div>
529
+ </div>
530
+
531
+ <div style="margin-top: 15px; display: flex; justify-content: space-between; align-items: center;">
532
+ <div>
533
+ <div style="font-size: 12px; color: #64748b;">Evidence Weight:</div>
534
+ <div style="font-size: 13px; color: #1e293b; font-weight: 500;">Historical: 85% • Predictive: 15%</div>
535
+ </div>
536
+ <div style="display: flex; gap: 8px;">
537
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">📚 8 incidents</span>
538
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">🎯 76% failure rate</span>
539
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">🏆 recall dominance</span>
540
+ </div>
541
+ </div>
542
+ </div>
543
+ """)
544
+
545
+ def create_decision_display() -> gr.HTML:
546
+ """Creates decision process HTML display."""
547
+ return gr.HTML("""
548
+ <div style="border: 2px solid #10b981; border-radius: 14px; padding: 20px; background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%); margin: 10px 0;">
549
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
550
+ <div style="display: flex; align-items: center; gap: 12px;">
551
+ <div style="width: 40px; height: 40px; background: #10b981; color: white; border-radius: 50%;
552
+ display: flex; align-items: center; justify-content: center; font-size: 18px;">
553
+ 🎯
554
+ </div>
555
+ <div>
556
+ <h4 style="margin: 0 0 4px 0; font-size: 16px; color: #1e293b; font-weight: 600;">Decision Process</h4>
557
+ <p style="margin: 0; font-size: 13px; color: #64748b;">HealingIntent creation & sequencing</p>
558
+ </div>
559
+ </div>
560
+ <div style="padding: 6px 14px; background: #dcfce7; color: #166534; border-radius: 20px; font-size: 12px; font-weight: bold;">
561
+ STATUS: ACTIVE
562
+ </div>
563
+ </div>
564
+
565
+ <!-- Formal HealingIntent Display -->
566
+ <div style="background: white; border-radius: 10px; padding: 20px; border: 2px solid #e2e8f0; margin-bottom: 20px;">
567
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 2px solid #f1f5f9;">
568
+ <div>
569
+ <h5 style="margin: 0 0 5px 0; font-size: 15px; color: #1e293b; font-weight: 600;">Formal HealingIntent Created</h5>
570
+ <p style="margin: 0; font-size: 12px; color: #64748b;">Preconditions checked, contraindications listed</p>
571
+ </div>
572
+ <div style="padding: 6px 12px; background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
573
+ color: white; border-radius: 15px; font-size: 11px; font-weight: bold;">
574
+ CONFIDENCE: 87.3%
575
+ </div>
576
+ </div>
577
+
578
+ <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 20px;">
579
+ <div>
580
+ <div style="font-size: 13px; color: #475569; margin-bottom: 8px; font-weight: 600;">Primary Action</div>
581
+ <div style="padding: 12px; background: #f0fdf4; border-radius: 8px; border-left: 4px solid #10b981;">
582
+ <div style="font-size: 14px; color: #065f46; font-weight: 500;">
583
+ Implement request coalescing with exponential backoff (jitter: 25%)
584
+ </div>
585
+ </div>
586
+ </div>
587
+
588
+ <div>
589
+ <div style="font-size: 13px; color: #475569; margin-bottom: 8px; font-weight: 600;">Sequencing Rule</div>
590
+ <div style="padding: 12px; background: #f0f9ff; border-radius: 8px; border-left: 4px solid #0ea5e9;">
591
+ <div style="font-size: 14px; color: #0369a1; font-weight: 500;">
592
+ dampening_first_then_observe_then_optional_scale
593
+ </div>
594
+ </div>
595
+ </div>
596
+ </div>
597
+
598
+ <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px;">
599
+ <div style="padding: 10px; background: #f8fafc; border-radius: 8px;">
600
+ <div style="font-size: 12px; color: #64748b; margin-bottom: 5px;">Preconditions</div>
601
+ <div style="font-size: 11px; color: #475569;">• Retry amplification detected<br>• Confidence > 70%<br>• No scaling contraindicated</div>
602
+ </div>
603
+
604
+ <div style="padding: 10px; background: #f8fafc; border-radius: 8px;">
605
+ <div style="font-size: 12px; color: #64748b; margin-bottom: 5px;">Contraindications</div>
606
+ <div style="font-size: 11px; color: #b91c1c;">⛔ Scale during retry storm<br>⛔ Add capacity immediately<br>⛔ Restart during amplification</div>
607
+ </div>
608
+
609
+ <div style="padding: 10px; background: #f8fafc; border-radius: 8px;">
610
+ <div style="font-size: 12px; color: #64748b; margin-bottom: 5px;">Reversibility</div>
611
+ <div style="font-size: 11px; color: #047857;">✅ Backoff can be adjusted<br>✅ Coalescing can be disabled<br>✅ No stateful changes</div>
612
+ </div>
613
+ </div>
614
+ </div>
615
+
616
+ <!-- Observation Gate Status -->
617
+ <div style="background: #fef3c7; border-radius: 10px; padding: 15px; border-left: 4px solid #f59e0b; margin-bottom: 15px;">
618
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
619
+ <div style="font-size: 20px;">⏳</div>
620
+ <div style="flex: 1;">
621
+ <div style="font-size: 14px; font-weight: 600; color: #92400e; margin-bottom: 3px;">
622
+ Observation Gate: ACTIVE (65.0% confidence)
623
+ </div>
624
+ <div style="font-size: 13px; color: #b45309;">
625
+ System will observe for 5 minutes before proceeding to execution
626
+ </div>
627
+ </div>
628
+ </div>
629
+
630
+ <div style="height: 8px; background: #e2e8f0; border-radius: 4px; margin: 10px 0; overflow: hidden;">
631
+ <div style="width: 65%; height: 100%; background: linear-gradient(90deg, #f59e0b, #fbbf24); border-radius: 4px;"></div>
632
+ </div>
633
+
634
+ <div style="display: flex; justify-content: space-between;">
635
+ <span style="font-size: 11px; color: #64748b;">0%</span>
636
+ <span style="font-size: 11px; color: #64748b; font-weight: 600;">Threshold: 70%</span>
637
+ <span style="font-size: 11px; color: #64748b;">100%</span>
638
+ </div>
639
+ </div>
640
+
641
+ <div style="margin-top: 15px; display: flex; justify-content: space-between; align-items: center;">
642
+ <div>
643
+ <div style="font-size: 12px; color: #64748b;">Next Step:</div>
644
+ <div style="font-size: 13px; color: #1e293b; font-weight: 500;">Wait for observation gate clearance</div>
645
+ </div>
646
+ <div style="display: flex; gap: 8px;">
647
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">📝 formal intent</span>
648
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">🔄 sequenced</span>
649
+ <span style="padding: 4px 10px; background: #f1f5f9; color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">🎯 87% confidence</span>
650
+ </div>
651
+ </div>
652
+ </div>
653
+ """)
654
+
655
+ def create_oss_advisory_section() -> gr.HTML:
656
+ """Creates OSS advisory section showing policy vs execution boundary."""
657
+ return gr.HTML("""
658
+ <div style="padding: 25px; border-radius: 16px; margin-bottom: 15px; flex: 1; min-height: 320px;
659
+ background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); border: 2px solid #0ea5e9;">
660
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid rgba(14, 165, 233, 0.2);">
661
+ <div style="font-size: 32px;">🆓</div>
662
+ <div>
663
+ <h3 style="margin: 0 0 5px 0; font-size: 20px; color: #1e293b;">Policy Edition</h3>
664
+ <p style="margin: 0; font-size: 14px; color: #64748b;">Analysis & Advisory Only - Apache 2.0</p>
665
+ </div>
666
+ <div style="margin-left: auto; padding: 6px 14px; background: rgba(255, 255, 255, 0.9);
667
+ border-radius: 10px; font-size: 11px; font-weight: bold; color: #475569;">
668
+ PERMANENTLY SAFE
669
+ </div>
670
+ </div>
671
+
672
+ <div style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); margin-bottom: 20px;">
673
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 12px; border-bottom: 1px solid #f1f5f9;">
674
+ <h4 style="margin: 0; font-size: 16px; color: #1e293b;">📝 HealingIntent Created</h4>
675
+ <span style="padding: 6px 12px; background: #dbeafe; color: #1d4ed8; border-radius: 8px; font-size: 12px; font-weight: bold;">94% confidence</span>
676
+ </div>
677
+
678
+ <div style="margin-bottom: 15px;">
679
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
680
+ <div style="width: 24px; height: 24px; background: #10b981; color: white; border-radius: 50%;
681
+ display: flex; align-items: center; justify-content: center; font-size: 12px;">
682
+
683
+ </div>
684
+ <div>
685
+ <div style="font-size: 14px; color: #475569; font-weight: 500;">Action Recommended</div>
686
+ <div style="font-size: 13px; color: #1e293b;">Implement request coalescing with exponential backoff</div>
687
+ </div>
688
+ </div>
689
+
690
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
691
+ <div style="width: 24px; height: 24px; background: #8b5cf6; color: white; border-radius: 50%;
692
+ display: flex; align-items: center; justify-content: center; font-size: 12px;">
693
+ 🧠
694
+ </div>
695
+ <div>
696
+ <div style="font-size: 14px; color: #475569; font-weight: 500;">Pattern Match</div>
697
+ <div style="font-size: 13px; color: #1e293b;">Similar incident resolved with dampening (87% success rate)</div>
698
+ </div>
699
+ </div>
700
+
701
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
702
+ <div style="width: 24px; height: 24px; background: #f59e0b; color: white; border-radius: 50%;
703
+ display: flex; align-items: center; justify-content: center; font-size: 12px;">
704
+ ⚠️
705
+ </div>
706
+ <div>
707
+ <div style="font-size: 14px; color: #475569; font-weight: 500;">Contraindications</div>
708
+ <div style="font-size: 13px; color: #1e293b;">✅ Checked (retry amplification detected)</div>
709
+ </div>
710
+ </div>
711
+
712
+ <div style="display: flex; align-items: center; gap: 10px;">
713
+ <div style="width: 24px; height: 24px; background: #3b82f6; color: white; border-radius: 50%;
714
+ display: flex; align-items: center; justify-content: center; font-size: 12px;">
715
+ 🔄
716
+ </div>
717
+ <div>
718
+ <div style="font-size: 14px; color: #475569; font-weight: 500;">Sequencing Rule</div>
719
+ <div style="font-size: 13px; color: #1e293b;">dampening_first_then_observe_then_optional_scale</div>
720
+ </div>
721
+ </div>
722
+ </div>
723
+ </div>
724
+
725
+ <!-- OSS Boundary -->
726
+ <div style="text-align: center;">
727
+ <div style="height: 2px; background: linear-gradient(90deg, transparent, #3b82f6, transparent); margin: 8px 0;"></div>
728
+ <div style="padding: 10px; background: #fee2e2; color: #dc2626; border-radius: 10px;
729
+ font-size: 14px; font-weight: bold; display: inline-block; border: 2px solid #dc2626;">
730
+ 🚫 OSS STOPS HERE - No Execution
731
+ </div>
732
+ <div style="height: 2px; background: linear-gradient(90deg, transparent, #3b82f6, transparent); margin: 8px 0;"></div>
733
+
734
+ <div style="margin-top: 15px; padding: 12px; background: rgba(255, 255, 255, 0.8); border-radius: 10px;">
735
+ <div style="font-size: 13px; color: #475569; font-weight: 500;">
736
+ OSS provides policy advice only. Enterprise edition required for execution.
737
+ </div>
738
+ <div style="font-size: 12px; color: #64748b; margin-top: 5px;">
739
+ This architectural boundary ensures safety by design.
740
+ </div>
741
+ </div>
742
+ </div>
743
+ </div>
744
+ """)
745
+
746
+ def create_timeline_comparison_plot() -> go.Figure:
747
+ """Creates timeline comparison plot for incident resolution."""
748
+ fig = go.Figure()
749
+
750
+ # Timeline data
751
+ manual_times = [0, 5, 15, 30, 45, 60]
752
+ manual_users = [45000, 45000, 42000, 35000, 20000, 5000]
753
+
754
+ arf_times = [0, 0.8, 1.5, 3, 8, 12]
755
+ arf_users = [45000, 45000, 45000, 42000, 15000, 0]
756
+
757
+ # Add traces
758
+ fig.add_trace(go.Scatter(
759
+ x=manual_times,
760
+ y=manual_users,
761
+ mode='lines+markers',
762
+ name='Manual Resolution',
763
+ line=dict(color='#ef4444', width=3, dash='dash'),
764
+ marker=dict(size=8, color='#ef4444'),
765
+ hovertemplate='Time: %{x}min<br>Users Affected: %{y:,}<extra></extra>'
766
+ ))
767
+
768
+ fig.add_trace(go.Scatter(
769
+ x=arf_times,
770
+ y=arf_users,
771
+ mode='lines+markers',
772
+ name='ARF Policy Execution',
773
+ line=dict(color='#10b981', width=4),
774
+ marker=dict(size=10, color='#10b981'),
775
+ hovertemplate='Time: %{x}min<br>Users Affected: %{y:,}<extra></extra>'
776
+ ))
777
+
778
+ # Add vertical lines for key events
779
+ fig.add_vline(x=0.8, line_width=2, line_dash="dot", line_color="#3b82f6",
780
+ annotation_text="Detection", annotation_position="top right")
781
+ fig.add_vline(x=1.5, line_width=2, line_dash="dot", line_color="#8b5cf6",
782
+ annotation_text="Recall", annotation_position="top right")
783
+ fig.add_vline(x=3, line_width=2, line_dash="dot", line_color="#f59e0b",
784
+ annotation_text="Decision", annotation_position="top right")
785
+ fig.add_vline(x=8, line_width=2, line_dash="dot", line_color="#10b981",
786
+ annotation_text="Resolution", annotation_position="top right")
787
+
788
+ # Update layout
789
+ fig.update_layout(
790
+ title=dict(
791
+ text="⏰ Incident Timeline: Manual vs Policy Execution",
792
+ font=dict(size=18, color='#1e293b'),
793
+ x=0.5
794
+ ),
795
+ xaxis=dict(
796
+ title="Time (minutes)",
797
+ gridcolor='#e2e8f0',
798
+ tickformat=',d'
799
+ ),
800
+ yaxis=dict(
801
+ title="Users Affected",
802
+ gridcolor='#e2e8f0',
803
+ tickformat=','
804
+ ),
805
+ plot_bgcolor='white',
806
+ paper_bgcolor='white',
807
+ font=dict(family="Inter, sans-serif", color="#475569"),
808
+ hovermode='x unified',
809
+ legend=dict(
810
+ orientation="h",
811
+ yanchor="bottom",
812
+ y=1.02,
813
+ xanchor="center",
814
+ x=0.5,
815
+ bgcolor='rgba(255, 255, 255, 0.8)',
816
+ bordercolor='#e2e8f0',
817
+ borderwidth=1
818
+ ),
819
+ margin=dict(l=50, r=50, t=80, b=50),
820
+ height=400
821
+ )
822
+
823
+ # Add annotation for savings
824
+ fig.add_annotation(
825
+ x=12,
826
+ y=0,
827
+ text="🚀 73% faster resolution<br>💰 $6.3K saved",
828
+ showarrow=True,
829
+ arrowhead=2,
830
+ arrowsize=1,
831
+ arrowwidth=2,
832
+ arrowcolor="#10b981",
833
+ ax=50,
834
+ ay=-50,
835
+ bgcolor="#f0fdf4",
836
+ bordercolor="#10b981",
837
+ borderwidth=2,
838
+ font=dict(size=12, color="#065f46")
839
+ )
840
+
841
+ return fig
842
+
843
  # -----------------------------
844
  # NEW: Observation Gate Renderer - CRITICAL PSYCHOLOGICAL FIX
845
  # -----------------------------
 
1163
  return detection_time_html, mttr_html, auto_heal_html, savings_html
1164
 
1165
  # -----------------------------
1166
+ # Tab 1: Live Incident Demo - UPDATED WITH RESTORED FUNCTIONS
1167
  # -----------------------------
1168
  def create_tab1_incident_demo(scenarios=INCIDENT_SCENARIOS, default_scenario="Cache Miss Storm") -> tuple:
1169
  """
 
1247
  # Middle Column: Process Workflow (NOT Agent Workflow)
1248
  with gr.Column(scale=2, variant="panel") as middle_col:
1249
  # ============ OBSERVATION GATE PLACEHOLDER ============
1250
+ observation_gate_placeholder = create_observation_gate_placeholder()
 
 
 
 
 
 
1251
 
1252
  # ============ SEQUENCING VISUALIZATION ============
1253
  sequencing_header = gr.Markdown("### 🔄 Sequencing Logic: Dampening → Concurrency → Observe → Scale")
1254
+ sequencing_panel = create_sequencing_visualization()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1255
 
1256
  # Process Workflow Header (NOT Agent Workflow)
1257
  workflow_header = gr.Markdown("## 🔄 Policy Process Workflow")
 
1259
 
1260
  # Process Status Cards (NOT Agent Status Cards)
1261
  with gr.Row():
1262
+ detection_process = create_detection_display()
1263
+ recall_process = create_recall_display()
1264
+ decision_process = create_decision_display()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1265
 
1266
  # Mode Selection & Safety Controls
1267
  with gr.Row():
 
1286
  boundary_header = gr.Markdown("### 🎭 Policy vs Execution: The Safety Boundary")
1287
 
1288
  with gr.Row():
1289
+ oss_section = create_oss_advisory_section()
1290
+
1291
+ enterprise_section = gr.HTML("""
1292
+ <div style="padding: 25px; border-radius: 16px; margin-bottom: 15px; flex: 1; min-height: 320px;
1293
+ background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%); border: 2px solid #10b981;">
1294
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid rgba(16, 185, 129, 0.2);">
1295
+ <div style="font-size: 32px;">💰</div>
 
 
 
 
 
 
 
 
1296
  <div>
1297
+ <h3 style="margin: 0 0 5px 0; font-size: 20px; color: #1e293b;">Execution Edition</h3>
1298
+ <p style="margin: 0; font-size: 14px; color: #64748b;">Full Execution & Learning - Commercial</p>
 
 
1299
  </div>
1300
+ <div style="margin-left: auto; padding: 6px 14px; background: rgba(255, 255, 255, 0.9);
1301
+ border-radius: 10px; font-size: 11px; font-weight: bold; color: #475569;">
1302
+ REQUIRES LICENSE
 
1303
  </div>
1304
  </div>
1305
+
1306
+ <div style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); margin-bottom: 20px;">
1307
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 12px; border-bottom: 1px solid #f1f5f9;">
 
 
 
 
 
 
 
 
 
 
 
 
1308
  <h4 style="margin: 0; font-size: 16px; color: #1e293b;">⚡ Ready to Execute</h4>
1309
+ <span style="padding: 6px 12px; background: #10b981; color: white; border-radius: 8px; font-size: 12px; font-weight: bold; text-transform: uppercase;">AUTONOMOUS</span>
1310
  </div>
1311
+
1312
+ <div style="margin-bottom: 15px;">
1313
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
1314
+ <div style="width: 24px; height: 24px; background: #3b82f6; color: white; border-radius: 50%;
1315
+ display: flex; align-items: center; justify-content: center; font-size: 12px;">
1316
+ ⚙️
1317
+ </div>
1318
+ <div>
1319
+ <div style="font-size: 14px; color: #475569; font-weight: 500;">Mode</div>
1320
+ <div style="font-size: 13px; color: #1e293b;">Autonomous (Requires Enterprise license)</div>
1321
+ </div>
1322
+ </div>
1323
+
1324
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
1325
+ <div style="width: 24px; height: 24px; background: #10b981; color: white; border-radius: 50%;
1326
+ display: flex; align-items: center; justify-content: center; font-size: 12px;">
1327
+
1328
+ </div>
1329
+ <div>
1330
+ <div style="font-size: 14px; color: #475569; font-weight: 500;">Expected Recovery</div>
1331
+ <div style="font-size: 13px; color: #1e293b;">12 minutes (vs 45 min manual)</div>
1332
+ </div>
1333
+ </div>
1334
+
1335
+ <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
1336
+ <div style="width: 24px; height: 24px; background: #f59e0b; color: white; border-radius: 50%;
1337
+ display: flex; align-items: center; justify-content: center; font-size: 12px;">
1338
+ 💰
1339
+ </div>
1340
+ <div>
1341
+ <div style="font-size: 14px; color: #475569; font-weight: 500;">Cost Avoided</div>
1342
+ <div style="font-size: 13px; color: #10b981; font-weight: 700;">$6,375</div>
1343
+ </div>
1344
+ </div>
1345
+
1346
+ <div style="display: flex; align-items: center; gap: 10px;">
1347
+ <div style="width: 24px; height: 24px; background: #8b5cf6; color: white; border-radius: 50%;
1348
+ display: flex; align-items: center; justify-content: center; font-size: 12px;">
1349
+ 👥
1350
+ </div>
1351
+ <div>
1352
+ <div style="font-size: 14px; color: #475569; font-weight: 500;">Users Protected</div>
1353
+ <div style="font-size: 13px; color: #1e293b;">45,000 → 0 impacted</div>
1354
+ </div>
1355
+ </div>
1356
+ </div>
1357
+ </div>
1358
+
1359
+ <!-- Enterprise Boundary -->
1360
+ <div style="text-align: center;">
1361
+ <div style="height: 2px; background: linear-gradient(90deg, transparent, #10b981, transparent); margin: 8px 0;"></div>
1362
+ <div style="padding: 10px; background: #dcfce7; color: #166534; border-radius: 10px;
1363
+ font-size: 14px; font-weight: bold; display: inline-block; border: 2px solid #10b981;">
1364
+ ✅ Enterprise executes with MCP safety
1365
  </div>
1366
+ <div style="height: 2px; background: linear-gradient(90deg, transparent, #10b981, transparent); margin: 8px 0;"></div>
1367
+
1368
+ <div style="margin-top: 15px; padding: 12px; background: rgba(255, 255, 255, 0.8); border-radius: 10px;">
1369
+ <div style="font-size: 13px; color: #475569; font-weight: 500;">
1370
+ Enterprise edition adds execution, learning, and safety guarantees.
1371
+ </div>
1372
+ <div style="font-size: 12px; color: #64748b; margin-top: 5px;">
1373
+ MCP safety modes: Advisory → Approval → Autonomous
1374
+ </div>
1375
  </div>
1376
  </div>
1377
  </div>
 
1398
  # Timeline visualization
1399
  timeline_header = gr.Markdown("### ⏰ Incident Timeline")
1400
  timeline_viz = gr.Plot(
1401
+ create_timeline_comparison_plot(),
1402
  label="",
1403
  show_label=False,
1404
  elem_id="timeline_plot"
 
1833
 
1834
  return (learning_graph, graph_type, show_labels, search_query, search_btn,
1835
  clear_btn_search, search_results, stats_display, patterns_display, performance_display)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1836
 
1837
  # -----------------------------
1838
  # Footer