File size: 24,061 Bytes
05946a6
4b2c586
 
05946a6
 
4b2c586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05946a6
 
 
4b2c586
 
 
 
 
 
 
05946a6
 
 
4b2c586
 
 
 
 
 
 
05946a6
 
 
4b2c586
 
05946a6
4b2c586
 
 
 
05946a6
 
 
4b2c586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05946a6
 
4b2c586
 
 
05946a6
 
4b2c586
 
05946a6
 
4b2c586
 
 
 
05946a6
 
 
4b2c586
05946a6
4b2c586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
"""
Enhanced Demo Guidance System - Manages the psychology and flow of the ARF demo
Adds clear narrative phases and boundary awareness
"""

from enum import Enum
from typing import Dict, List, Any, Optional
from dataclasses import dataclass
import time

class DemoPhase(Enum):
    """Phases of the demo narrative with clear boundaries"""
    INTRODUCTION = "introduction"
    FAILURE_INJECTION = "failure_injection"
    REAL_OSS_ANALYSIS = "real_oss_analysis"
    DECISION_BOUNDARY = "decision_boundary"
    SIMULATED_ENTERPRISE = "simulated_enterprise"
    RESOLUTION = "resolution"
    ARCHITECTURE_REVIEW = "architecture_review"

@dataclass
class PhaseContent:
    """Enhanced content for each demo phase with boundary indicators"""
    phase: DemoPhase
    title: str
    narrative: str
    key_message: str
    visual_cue: str
    duration_seconds: int
    show_boundary: bool = False
    boundary_text: Optional[str] = None
    is_real_arf: bool = False
    
    def get_html(self, show_progress: bool = True, current_step: int = 1, total_steps: int = 7) -> str:
        """Get HTML for this phase with progress indicator"""
        # Progress indicator
        progress_html = ""
        if show_progress:
            progress_percentage = int((current_step / total_steps) * 100)
            progress_html = f"""
            <div style="margin-bottom: 20px;">
                <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
                    <div style="font-size: 13px; color: #64748b; font-weight: 500;">
                        Demo Progress: Step {current_step} of {total_steps}
                    </div>
                    <div style="font-size: 13px; color: #3b82f6; font-weight: 600;">
                        {progress_percentage}%
                    </div>
                </div>
                <div style="height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden;">
                    <div style="width: {progress_percentage}%; height: 100%; 
                                background: linear-gradient(90deg, #3b82f6, #8b5cf6); 
                                border-radius: 3px; transition: width 0.3s ease;">
                    </div>
                </div>
            </div>
            """
        
        # Real ARF indicator
        real_arf_html = ""
        if self.is_real_arf:
            real_arf_html = f"""
            <div style="margin: 15px 0; padding: 10px; background: #f0fdf4; 
                       border-radius: 8px; border: 2px solid #10b981;">
                <div style="display: flex; align-items: center; gap: 8px;">
                    <div style="font-size: 20px;">βœ…</div>
                    <div style="font-weight: 600; color: #065f46;">REAL ARF OSS v3.3.7</div>
                </div>
                <div style="font-size: 13px; color: #047857; margin-top: 5px;">
                    Running actual agentic-reliability-framework==3.3.7 package
                </div>
            </div>
            """
        
        # Boundary indicator
        boundary_html = ""
        if self.show_boundary and self.boundary_text:
            boundary_html = f"""
            <div style="margin: 15px 0; padding: 12px; background: #fef3c7; 
                       border-radius: 10px; border-left: 4px solid #f59e0b;">
                <div style="display: flex; align-items: center; gap: 8px; margin-bottom: 5px;">
                    <div style="font-size: 20px;">🎭</div>
                    <div style="font-weight: 600; color: #92400e;">Demo Boundary</div>
                </div>
                <div style="font-size: 13px; color: #b45309; line-height: 1.5;">
                    {self.boundary_text}
                </div>
            </div>
            """
        
        return f"""
        <div style="border: 2px solid #3b82f6; border-radius: 16px; padding: 25px; 
                   background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
                   box-shadow: 0 8px 32px rgba(59, 130, 246, 0.1); margin: 20px 0;">
            <div style="display: flex; align-items: center; gap: 15px; margin-bottom: 20px;">
                <div style="font-size: 36px;">{self.visual_cue}</div>
                <div>
                    <h3 style="margin: 0 0 5px 0; color: #1e293b; font-size: 20px; font-weight: 700;">
                        {self.title}
                    </h3>
                    <div style="font-size: 14px; color: #64748b;">
                        Phase: {self.phase.value.replace('_', ' ').title()}
                    </div>
                </div>
            </div>
            
            {progress_html}
            
            <div style="margin-bottom: 20px;">
                <div style="font-size: 16px; color: #475569; line-height: 1.6; margin-bottom: 15px;">
                    {self.narrative}
                </div>
                
                {real_arf_html}
                {boundary_html}
                
                <div style="padding: 15px; background: #f1f5f9; border-radius: 10px; 
                           border-left: 4px solid #3b82f6;">
                    <div style="font-weight: 600; color: #1e293b; margin-bottom: 5px;">
                        🎯 Key Message
                    </div>
                    <div style="font-size: 15px; color: #475569; line-height: 1.5;">
                        {self.key_message}
                    </div>
                </div>
            </div>
            
            <div style="display: flex; justify-content: space-between; align-items: center; 
                       margin-top: 20px; padding-top: 15px; border-top: 1px solid #e2e8f0;">
                <div style="font-size: 12px; color: #94a3b8;">
                    ⏱️ Duration: {self.duration_seconds}s β€’ 
                    🎯 Focus: {self.phase.value.replace('_', ' ').title()}
                </div>
                <div style="display: flex; gap: 10px;">
                    <div style="padding: 4px 10px; background: #e2e8f0; 
                               color: #64748b; border-radius: 12px; font-size: 11px; font-weight: 500;">
                        Phase {current_step}
                    </div>
                </div>
            </div>
        </div>
        """

# Complete demo flow with psychological pacing
DEMO_FLOW = {
    DemoPhase.INTRODUCTION: PhaseContent(
        phase=DemoPhase.INTRODUCTION,
        title="πŸš€ Welcome to ARF v3.3.7 - The Architecture Demo",
        narrative="""
        Most AI systems fail silently in production. This one doesn't. We're about to demonstrate 
        a production-grade agentic reliability system with <strong>clear architectural boundaries</strong>.
        
        This demo shows:
        1. <strong>Real ARF OSS v3.3.7</strong> - Actual advisory intelligence
        2. <strong>Simulated Enterprise</strong> - Value proposition without infrastructure access
        3. <strong>Clear separation</strong> - Honest boundaries between OSS and Enterprise
        """,
        key_message="This isn't AI theater. It's a production-ready system with architectural honesty.",
        visual_cue="🎭",
        duration_seconds=30,
        show_boundary=True,
        boundary_text="We're simulating Enterprise execution for the demo. Real execution requires production infrastructure.",
        is_real_arf=False
    ),
    
    DemoPhase.FAILURE_INJECTION: PhaseContent(
        phase=DemoPhase.FAILURE_INJECTION,
        title="🚨 Phase 1: Inject Production Failure",
        narrative="""
        We're simulating a <strong>Cache Miss Storm</strong> affecting 45,000 users with $8,500/hour revenue risk.
        
        This is how most systems look right before they fail silently. The metrics show:
        β€’ Cache hit rate dropped from 85% to 18%
        β€’ Database load increased to 92%
        β€’ Response time spiked to 1,850ms
        
        Notice: No remediation is running yet. We're letting you feel the tension.
        """,
        key_message="Failure happens. The question is how quickly and intelligently you respond.",
        visual_cue="πŸ“‰",
        duration_seconds=20,
        show_boundary=False,
        is_real_arf=False
    ),
    
    DemoPhase.REAL_OSS_ANALYSIS: PhaseContent(
        phase=DemoPhase.REAL_OSS_ANALYSIS,
        title="🧠 Phase 2: Real ARF OSS Intelligence Activates",
        narrative="""
        ARF OSS v3.3.7 is now <strong>analyzing the incident in real-time</strong>. This is not a mock:
        
        1. <strong>Detection Agent</strong> - Finds anomalies with 98.7% confidence
        2. <strong>Recall Agent</strong> - Searches RAG memory for similar incidents
        3. <strong>Decision Agent</strong> - Generates healing intent with reasoning
        
        Watch the confidence scores increase as evidence accumulates. This is <strong>real inference</strong>, 
        not pre-programmed responses. The system is reasoning, not reacting.
        """,
        key_message="ARF OSS provides production-grade intelligence. It reasons before it recommends.",
        visual_cue="πŸ€–",
        duration_seconds=45,
        show_boundary=True,
        boundary_text="This is REAL ARF OSS v3.3.7 (Apache 2.0). It can analyze but not execute.",
        is_real_arf=True
    ),
    
    DemoPhase.DECISION_BOUNDARY: PhaseContent(
        phase=DemoPhase.DECISION_BOUNDARY,
        title="🎯 Phase 3: The Execution Boundary",
        narrative="""
        ARF OSS has created a <strong>HealingIntent with 94% confidence</strong>:
        β€’ Action: Scale Redis cluster from 3 to 5 nodes
        β€’ Pattern match: 87% success rate from similar incidents
        β€’ Safety check: βœ… Passed (blast radius: 2 services)
        
        Now we pause intentionally. This is the <strong>architectural boundary</strong>:
        β€’ <strong>OSS can reason</strong> (Apache 2.0, advisory only)
        β€’ <strong>Enterprise can execute</strong> (Commercial, with safety guarantees)
        
        The system knows what to do, but requires authority to act.
        """,
        key_message="Reasoning and authority are not the same thing. This boundary is intentional.",
        visual_cue="βš–οΈ",
        duration_seconds=25,
        show_boundary=True,
        boundary_text="OSS boundary reached. Execution requires Enterprise edition and infrastructure authority.",
        is_real_arf=True
    ),
    
    DemoPhase.SIMULATED_ENTERPRISE: PhaseContent(
        phase=DemoPhase.SIMULATED_ENTERPRISE,
        title="🏒 Phase 4: Simulated Enterprise Execution",
        narrative="""
        We're now simulating what <strong>ARF Enterprise</strong> would do:
        
        1. <strong>Validate safety constraints</strong> - Business hours, blast radius, rollback plans
        2. <strong>Apply novel execution protocols</strong> - Deterministic confidence, not just ML probabilities
        3. <strong>Execute with guarantees</strong> - Rollback prepared, circuit breakers set
        
        In production, this would execute against real infrastructure (Kubernetes, cloud APIs, etc.). 
        For the demo, we're showing the value proposition without real side effects.
        """,
        key_message="Enterprise adds execution authority, not just better intelligence.",
        visual_cue="⚑",
        duration_seconds=35,
        show_boundary=True,
        boundary_text="SIMULATED EXECUTION - Real Enterprise would execute against production infrastructure.",
        is_real_arf=False
    ),
    
    DemoPhase.RESOLUTION: PhaseContent(
        phase=DemoPhase.RESOLUTION,
        title="βœ… Phase 5: Incident Resolution",
        narrative="""
        The simulated execution completes:
        β€’ <strong>Recovery time:</strong> 12 minutes (vs 45 minutes manual)
        β€’ <strong>Cost saved:</strong> $6,375
        β€’ <strong>Users protected:</strong> 45,000 β†’ 0 impacted
        β€’ <strong>Learning:</strong> Pattern added to RAG memory
        
        System health normalizes. Confidence scores stabilize. The incident is marked as 
        <strong>resolved autonomously</strong>.
        
        Key metrics show the impact:
        β€’ Detection time: 45s (89% faster than average)
        β€’ Auto-heal rate: 81.7% (5.4Γ— industry average)
        """,
        key_message="Autonomous reliability creates measurable business impact.",
        visual_cue="πŸ“Š",
        duration_seconds=30,
        show_boundary=False,
        is_real_arf=False
    ),
    
    DemoPhase.ARCHITECTURE_REVIEW: PhaseContent(
        phase=DemoPhase.ARCHITECTURE_REVIEW,
        title="πŸ—οΈ Phase 6: Architecture Validated",
        narrative="""
        Let's review what we demonstrated:
        
        <strong>βœ… Real Components (Production-Ready):</strong>
        β€’ ARF OSS v3.3.7 intelligence engine
        β€’ Three-agent pattern (Detection, Recall, Decision)
        β€’ RAG-based similarity search
        β€’ Confidence scoring and reasoning chains
        
        <strong>🎭 Simulated Components (Demo Value):</strong>
        β€’ Enterprise execution authority
        β€’ Infrastructure orchestration
        β€’ Rollback guarantees
        β€’ Novel execution protocols
        
        <strong>🎯 Clear Boundaries (Architectural Honesty):</strong>
        β€’ OSS advises, Enterprise executes
        β€’ No hidden automation or deception
        β€’ Production-ready separation
        """,
        key_message="This demo shows production architecture, not just AI capabilities.",
        visual_cue="πŸ’Ž",
        duration_seconds=40,
        show_boundary=True,
        boundary_text="Architecture validated: OSS for intelligence, Enterprise for execution.",
        is_real_arf=False
    )
}

# Original user journey steps (enhanced with phase alignment)
USER_JOURNEY_STEPS = [
    {
        "step": 1,
        "title": "🎭 Understand the Architecture",
        "description": "Review the demo flow to understand clear boundaries between OSS and Enterprise",
        "tab": "All Tabs",
        "action": "Read the phase guidance",
        "learning": "See how ARF separates intelligence (OSS) from execution (Enterprise)",
        "phase": DemoPhase.INTRODUCTION.value,
        "duration": "30s"
    },
    {
        "step": 2,
        "title": "πŸ”₯ Experience REAL ARF OSS Analysis",
        "description": "Select an incident and run OSS analysis to see actual ARF v3.3.7 intelligence",
        "tab": "Live Incident Demo",
        "action": "Click 'Run OSS Analysis'",
        "learning": "See real ARF OSS package analyzing incidents with confidence scores",
        "phase": DemoPhase.REAL_OSS_ANALYSIS.value,
        "duration": "45s"
    },
    {
        "step": 3,
        "title": "🎯 Observe the Execution Boundary",
        "description": "Notice where OSS stops and Enterprise would begin",
        "tab": "Live Incident Demo",
        "action": "Review HealingIntent and boundary indicators",
        "learning": "Understand the architectural separation between advisory and execution",
        "phase": DemoPhase.DECISION_BOUNDARY.value,
        "duration": "25s"
    },
    {
        "step": 4,
        "title": "⚑ Simulate Enterprise Healing",
        "description": "Experience autonomous healing with simulated execution",
        "tab": "Live Incident Demo",
        "action": "Click 'Execute Enterprise Healing'",
        "learning": "See the Enterprise value proposition without real infrastructure",
        "phase": DemoPhase.SIMULATED_ENTERPRISE.value,
        "duration": "35s"
    },
    {
        "step": 5,
        "title": "πŸ’° Calculate Your Business ROI",
        "description": "Adjust the sliders to see potential savings for your organization",
        "tab": "Business Impact & ROI",
        "action": "Use sliders then click 'Calculate My ROI'",
        "learning": "Understand the business case with your specific numbers",
        "phase": "business_roi",
        "duration": "60s"
    },
    {
        "step": 6,
        "title": "πŸ“œ Explore Enterprise-Grade Compliance",
        "description": "View comprehensive audit trail and compliance features",
        "tab": "Audit Trail & History",
        "action": "Check execution and incident history",
        "learning": "See enterprise-level logging, compliance, and audit capabilities",
        "phase": "compliance",
        "duration": "45s"
    },
    {
        "step": 7,
        "title": "🧠 Discover the Learning Engine",
        "description": "Explore pattern detection and similarity search",
        "tab": "Learning Engine",
        "action": "Search for similar incidents and view patterns",
        "learning": "See how ARF learns from past incidents to improve future responses",
        "phase": "learning",
        "duration": "50s"
    }
]

# Enhanced demo tips with boundary awareness
DEMO_TIPS = [
    "πŸ’Ž **Architecture Tip**: Look for the 'REAL ARF' vs 'SIMULATED' indicators to understand boundaries",
    "🎭 **Demo Tip**: The 'Run Complete Demo' button follows our psychological pacing guide",
    "⚑ **Enterprise Tip**: Toggle approval mode to see different execution workflows",
    "πŸ“Š **ROI Tip**: Use realistic numbers for your organization in the ROI calculator",
    "πŸ” **Analysis Tip**: Try different incident scenarios to see varied ARF responses",
    "πŸ“œ **Compliance Tip**: Export the audit trail to see comprehensive JSON structure",
    "🧠 **Learning Tip**: Search for patterns to see how ARF improves over time",
    "🎯 **Boundary Tip**: Notice where OSS analysis ends and Enterprise execution would begin"
]

# Psychology-driven quick start guide
QUICK_START_GUIDE = {
    "for_executives": {
        "focus": "Business Impact & ROI",
        "steps": [
            "1. Go to 'Business Impact & ROI' tab",
            "2. Adjust sliders to match your organization",
            "3. Click 'Calculate My ROI'",
            "4. Review the 5.2Γ— ROI multiplier",
            "5. Ask: 'What would 73% faster MTTR mean for us?'"
        ],
        "time": "2 minutes",
        "key_question": "What's the cost of NOT having autonomous reliability?"
    },
    "for_engineers": {
        "focus": "Real ARF OSS Analysis",
        "steps": [
            "1. Select 'Cache Miss Storm' scenario",
            "2. Click 'Run OSS Analysis'",
            "3. Watch the three agents work in real-time",
            "4. Review the HealingIntent with 94% confidence",
            "5. Notice the reasoning chain and evidence"
        ],
        "time": "3 minutes",
        "key_question": "How would this intelligence change your on-call experience?"
    },
    "for_architects": {
        "focus": "Architecture Boundaries",
        "steps": [
            "1. Run the complete demo walkthrough",
            "2. Look for 'REAL ARF' vs 'SIMULATED' indicators",
            "3. Notice the execution boundary",
            "4. Review the architecture validation phase",
            "5. Ask: 'How would this integrate with our stack?'"
        ],
        "time": "4 minutes",
        "key_question": "Is our current approach proactive or reactive?"
    }
}

def get_phase_content(phase: DemoPhase) -> PhaseContent:
    """Get content for a specific demo phase"""
    return DEMO_FLOW.get(phase, DEMO_FLOW[DemoPhase.INTRODUCTION])

def get_phase_html(phase: DemoPhase, current_step: int = 1) -> str:
    """Get HTML for a demo phase with progress indicator"""
    content = get_phase_content(phase)
    total_steps = len(DEMO_FLOW)
    
    # Calculate step number based on phase
    phase_order = list(DEMO_FLOW.keys())
    step_number = phase_order.index(phase) + 1 if phase in phase_order else current_step
    
    return content.get_html(
        show_progress=True,
        current_step=step_number,
        total_steps=total_steps
    )

def get_demo_progress(current_phase: DemoPhase) -> Dict[str, Any]:
    """Get current demo progress information"""
    phase_order = list(DEMO_FLOW.keys())
    current_index = phase_order.index(current_phase) if current_phase in phase_order else 0
    
    return {
        "current_phase": current_phase.value,
        "current_step": current_index + 1,
        "total_steps": len(phase_order),
        "progress_percentage": int(((current_index + 1) / len(phase_order)) * 100),
        "next_phase": phase_order[current_index + 1].value if current_index + 1 < len(phase_order) else None,
        "estimated_time_remaining": sum(
            DEMO_FLOW[phase].duration_seconds 
            for i, phase in enumerate(phase_order) 
            if i > current_index
        )
    }

def get_quick_start_guide(role: str = "executives") -> Dict[str, Any]:
    """Get quick start guide for specific role"""
    return QUICK_START_GUIDE.get(role, QUICK_START_GUIDE["for_executives"])

# Psychology-focused demo controller
class DemoPsychologyController:
    """Manages the psychological flow of the demo"""
    
    def __init__(self):
        self.current_phase = DemoPhase.INTRODUCTION
        self.phase_start_time = time.time()
        self.completed_phases = []
        self.user_attention_score = 100  # Start with full attention
        
    def transition_to_phase(self, phase: DemoPhase) -> Dict[str, Any]:
        """Transition to a new demo phase with psychological timing"""
        current_time = time.time()
        phase_duration = current_time - self.phase_start_time
        
        # Calculate attention score (decays over time, refreshes on phase change)
        self.user_attention_score = max(60, self.user_attention_score - (phase_duration / 10))
        
        # If phase was too short, user might have missed it
        if phase_duration < 10 and self.current_phase != DemoPhase.INTRODUCTION:
            self.user_attention_score -= 10
        
        # Update state
        self.completed_phases.append(self.current_phase)
        self.current_phase = phase
        self.phase_start_time = time.time()
        
        # Refresh attention on phase change
        self.user_attention_score = min(100, self.user_attention_score + 20)
        
        return {
            "new_phase": phase.value,
            "previous_phase_duration": int(phase_duration),
            "user_attention_score": int(self.user_attention_score),
            "recommended_pause": self._get_recommended_pause(phase),
            "key_message": DEMO_FLOW[phase].key_message
        }
    
    def _get_recommended_pause(self, phase: DemoPhase) -> str:
        """Get recommended pause based on phase psychology"""
        pauses = {
            DemoPhase.INTRODUCTION: "Pause to set context",
            DemoPhase.FAILURE_INJECTION: "Let the tension build",
            DemoPhase.REAL_OSS_ANALYSIS: "Watch the reasoning unfold",
            DemoPhase.DECISION_BOUNDARY: "Pause intentionally here",
            DemoPhase.SIMULATED_ENTERPRISE: "Explain the simulation",
            DemoPhase.RESOLUTION: "Show the impact",
            DemoPhase.ARCHITECTURE_REVIEW: "Summarize the architecture"
        }
        return pauses.get(phase, "Continue")
    
    def get_current_guidance(self) -> str:
        """Get current guidance HTML"""
        return get_phase_html(self.current_phase, len(self.completed_phases) + 1)
    
    def should_speed_up(self) -> bool:
        """Determine if we should speed up based on attention score"""
        return self.user_attention_score < 70
    
    def should_slow_down(self) -> bool:
        """Determine if we should slow down for emphasis"""
        important_phases = [
            DemoPhase.DECISION_BOUNDARY,
            DemoPhase.ARCHITECTURE_REVIEW
        ]
        return self.current_phase in important_phases

# Global demo controller instance
_demo_controller = None

def get_demo_controller() -> DemoPsychologyController:
    """Get singleton demo controller instance"""
    global _demo_controller
    if _demo_controller is None:
        _demo_controller = DemoPsychologyController()
    return _demo_controller