aethershell 0.3.1

The world's first multi-agent shell with typed functional pipelines and multi-modal AI
Documentation
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
//! UI rendering for the TUI

use ratatui::{
    layout::{Alignment, Constraint, Direction, Layout, Rect},
    style::{Color, Modifier, Style},
    text::{Line, Span, Text},
    widgets::{Block, Borders, List, ListItem, Paragraph, Tabs, Wrap},
    Frame,
};

use super::app::{AgentStatus, App, AppMode, InputMode, MessageRole};
use super::dashboard;

pub fn draw(f: &mut Frame, app: &App) {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .margin(1)
        .constraints(
            [
                Constraint::Length(3),
                Constraint::Min(0),
                Constraint::Length(3),
            ]
            .as_ref(),
        )
        .split(f.size());

    // Header with tabs
    draw_header(f, app, chunks[0]);

    // Main content area
    match app.mode {
        AppMode::Chat => draw_chat(f, app, chunks[1]),
        AppMode::AgentSwarm => draw_agent_swarm(f, app, chunks[1]),
        AppMode::MediaBrowser => draw_media_browser(f, app, chunks[1]),
        AppMode::Settings => draw_settings(f, app, chunks[1]),
        AppMode::DistributedAgents => draw_distributed_agents(f, app, chunks[1]),
        AppMode::AdvancedReasoning => draw_advanced_reasoning(f, app, chunks[1]),
        AppMode::Search => draw_search(f, app, chunks[1]),
    }

    // Footer with input and help
    draw_footer(f, app, chunks[2]);
}

fn draw_header(f: &mut Frame, app: &App, area: Rect) {
    let titles = app.get_tab_titles();
    let tabs = Tabs::new(titles)
        .block(
            Block::default()
                .borders(Borders::ALL)
                .title("AetherShell TUI"),
        )
        .select(app.tab_index)
        .style(Style::default().fg(Color::White))
        .highlight_style(
            Style::default()
                .add_modifier(Modifier::BOLD)
                .bg(Color::Blue)
                .fg(Color::White),
        );
    f.render_widget(tabs, area);
}

fn draw_chat(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([Constraint::Percentage(70), Constraint::Percentage(30)].as_ref())
        .split(area);

    // Chat messages
    let messages: Vec<ListItem> = app
        .messages
        .iter()
        .map(|msg| {
            let content = format_message_content(msg);
            let style = match msg.role {
                MessageRole::User => Style::default().fg(Color::Cyan),
                MessageRole::Assistant => Style::default().fg(Color::Green),
                MessageRole::System => Style::default().fg(Color::Yellow),
            };
            ListItem::new(content).style(style)
        })
        .collect();

    let messages_list = List::new(messages)
        .block(
            Block::default()
                .borders(Borders::ALL)
                .title("Chat Messages"),
        )
        .highlight_style(
            Style::default()
                .add_modifier(Modifier::BOLD)
                .bg(Color::DarkGray),
        );

    f.render_stateful_widget(
        messages_list,
        chunks[0],
        &mut app.message_list_state.clone(),
    );

    // Side panel with media and agent info
    draw_chat_sidebar(f, app, chunks[1]);
}

fn draw_chat_sidebar(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints(
            [
                Constraint::Percentage(33),
                Constraint::Percentage(33),
                Constraint::Percentage(34),
            ]
            .as_ref(),
        )
        .split(area);

    // Selected media files
    let media_items: Vec<ListItem> = app
        .get_selected_media_files()
        .iter()
        .map(|media| ListItem::new(media.display_info()))
        .collect();

    let media_list = List::new(media_items).block(
        Block::default()
            .borders(Borders::ALL)
            .title("Attached Media"),
    );

    f.render_widget(media_list, chunks[0]);

    // Active agents summary
    let agent_count = app.agents.len();
    let working_agents = app
        .agents
        .iter()
        .filter(|a| a.status == AgentStatus::Working)
        .count();

    let agent_info = Paragraph::new(format!(
        "Agents: {} total\nWorking: {}\nModel: {}",
        agent_count, working_agents, app.current_model
    ))
    .block(Block::default().borders(Borders::ALL).title("Agent Status"));

    f.render_widget(agent_info, chunks[1]);

    // Conversation statistics panel
    dashboard::draw_stats_panel(f, app, chunks[2]);
}

fn draw_agent_swarm(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([Constraint::Percentage(60), Constraint::Percentage(40)].as_ref())
        .split(area);

    // Agent list
    let agents: Vec<ListItem> = app
        .agents
        .iter()
        .map(|agent| {
            let status_icon = match agent.status {
                AgentStatus::Idle => "",
                AgentStatus::Working => "🟢",
                AgentStatus::Waiting => "🟡",
                AgentStatus::Error(_) => "🔴",
            };

            let content = format!(
                "{} {} [{}] - {}",
                status_icon,
                agent.name,
                agent.model,
                agent.current_task.as_deref().unwrap_or("idle")
            );

            ListItem::new(content)
        })
        .collect();

    let agents_list = List::new(agents)
        .block(Block::default().borders(Borders::ALL).title("AI Agents"))
        .highlight_style(
            Style::default()
                .add_modifier(Modifier::BOLD)
                .bg(Color::DarkGray),
        );

    f.render_stateful_widget(agents_list, chunks[0], &mut app.agent_list_state.clone());

    // Agent details panel
    draw_agent_details(f, app, chunks[1]);
}

fn draw_agent_details(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints(
            [
                Constraint::Min(10),
                Constraint::Length(10),
                Constraint::Length(5),
            ]
            .as_ref(),
        )
        .split(area);

    // Selected agent details
    let details = if let Some(selected) = app.agent_list_state.selected() {
        if let Some(agent) = app.agents.get(selected) {
            format!(
                "Name: {}\nModel: {}\nStatus: {:?}\nTools: {}\nCreated: {}\nLast Activity: {}",
                agent.name,
                agent.model,
                agent.status,
                agent.tools.join(", "),
                agent.created_at.format("%H:%M:%S"),
                agent.last_activity.format("%H:%M:%S")
            )
        } else {
            "No agent selected".to_string()
        }
    } else {
        "Select an agent to view details".to_string()
    };

    let details_paragraph = Paragraph::new(details)
        .block(
            Block::default()
                .borders(Borders::ALL)
                .title("Agent Details"),
        )
        .wrap(Wrap { trim: true });

    f.render_widget(details_paragraph, chunks[0]);

    // Agent performance metrics
    dashboard::draw_agent_metrics(f, app, chunks[1]);

    // Agent controls help
    let help_text = "n: New Agent | d: Delete | Enter: Start Task | c: Chat | m: Metrics";
    let help = Paragraph::new(help_text)
        .block(Block::default().borders(Borders::ALL).title("Controls"))
        .alignment(Alignment::Center);

    f.render_widget(help, chunks[2]);
}

fn draw_media_browser(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
        .split(area);

    // Media file list
    let media_items: Vec<ListItem> = app
        .media_files
        .iter()
        .enumerate()
        .map(|(idx, media)| {
            let selected_marker = if app.selected_media.contains(&idx) {
                ""
            } else {
                "  "
            };

            let content = format!("{}{}", selected_marker, media.display_info());
            ListItem::new(content)
        })
        .collect();

    let media_list = List::new(media_items)
        .block(Block::default().borders(Borders::ALL).title("Media Files"))
        .highlight_style(
            Style::default()
                .add_modifier(Modifier::BOLD)
                .bg(Color::DarkGray),
        );

    f.render_stateful_widget(media_list, chunks[0], &mut app.media_list_state.clone());

    // Media preview/details
    draw_media_preview(f, app, chunks[1]);
}

fn draw_media_preview(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints([Constraint::Min(10), Constraint::Length(5)].as_ref())
        .split(area);

    // Media details
    let details = if let Some(selected) = app.media_list_state.selected() {
        if let Some(media) = app.media_files.get(selected) {
            format!(
                "Path: {}\nType: {:?}\nSize: {:?}\nDuration: {:?}",
                media.path, media.media_type, media.size, media.duration
            )
        } else {
            "No media selected".to_string()
        }
    } else {
        "Select a media file to view details".to_string()
    };

    let details_paragraph = Paragraph::new(details)
        .block(
            Block::default()
                .borders(Borders::ALL)
                .title("Media Details"),
        )
        .wrap(Wrap { trim: true });

    f.render_widget(details_paragraph, chunks[0]);

    // Media controls help
    let help_text =
        "Space: Select | o: Open File | c: Clear Selection | d: Delete | b: Back to Chat";
    let help = Paragraph::new(help_text)
        .block(Block::default().borders(Borders::ALL).title("Controls"))
        .alignment(Alignment::Center);

    f.render_widget(help, chunks[1]);
}

fn draw_settings(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints([Constraint::Percentage(40), Constraint::Percentage(60)].as_ref())
        .split(area);

    let settings_text = format!(
        "Default Model: {}\nMax Messages: {}\nAuto Scroll: {}\nShow Timestamps: {}\nMedia Preview: {}",
        app.config.default_model,
        app.config.max_messages,
        app.config.auto_scroll,
        app.config.show_timestamps,
        app.config.enable_media_preview
    );

    let settings = Paragraph::new(settings_text)
        .block(Block::default().borders(Borders::ALL).title("Settings"))
        .wrap(Wrap { trim: true });

    f.render_widget(settings, chunks[0]);

    // Keyboard shortcuts help panel
    dashboard::draw_help_panel(f, app, chunks[1]);
}

fn draw_footer(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([Constraint::Percentage(70), Constraint::Percentage(30)].as_ref())
        .split(area);

    // Input area
    let input_title = match app.mode {
        AppMode::Chat => "Message",
        AppMode::AgentSwarm => "Agent Task",
        AppMode::Search => "Search Query",
        _ => "Input",
    };

    let input_style = match app.input_mode {
        InputMode::Normal => Style::default(),
        InputMode::Editing => Style::default().fg(Color::Yellow),
    };

    let input = Paragraph::new(app.input.value())
        .style(input_style)
        .block(Block::default().borders(Borders::ALL).title(input_title));

    f.render_widget(input, chunks[0]);

    // Set cursor position when editing
    if app.input_mode == InputMode::Editing {
        let cursor_x = chunks[0].x + app.input.visual_cursor() as u16 + 1;
        let cursor_y = chunks[0].y + 1;
        f.set_cursor(cursor_x, cursor_y);
    }

    // Help text
    let help_text = match app.input_mode {
        InputMode::Normal => "i: Edit | q: Quit | Tab: Switch | ↑↓: Navigate",
        InputMode::Editing => "Enter: Send | Esc: Cancel",
    };

    let help = Paragraph::new(help_text)
        .block(Block::default().borders(Borders::ALL).title("Help"))
        .alignment(Alignment::Center);

    f.render_widget(help, chunks[1]);
}

fn format_message_content(msg: &super::app::ChatMessage) -> Text<'_> {
    let timestamp = if msg.timestamp.date_naive() == chrono::Utc::now().date_naive() {
        msg.timestamp.format("%H:%M:%S").to_string()
    } else {
        msg.timestamp.format("%m/%d %H:%M").to_string()
    };

    let role_prefix = match msg.role {
        MessageRole::User => "👤",
        MessageRole::Assistant => "🤖",
        MessageRole::System => "⚙️",
    };

    let model_info = msg.model.as_deref().unwrap_or("unknown");

    let mut lines = vec![Line::from(vec![
        Span::raw(format!("[{}] ", timestamp)),
        Span::raw(format!("{} ", role_prefix)),
        Span::raw(format!("[{}] ", model_info)),
    ])];

    // Add message content
    let content_lines: Vec<Line> = msg
        .content
        .lines()
        .map(|line| Line::from(Span::raw(format!("  {}", line))))
        .collect();
    lines.extend(content_lines);

    // Add media attachments info
    if !msg.media_attachments.is_empty() {
        lines.push(Line::from(Span::raw("  📎 Attachments:")));
        for media in &msg.media_attachments {
            lines.push(Line::from(Span::raw(format!(
                "    {}",
                media.display_info()
            ))));
        }
    }

    Text::from(lines)
}

fn draw_distributed_agents(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
        .split(area);

    // Left panel: Connected agents
    let agent_status = app.get_distributed_agent_status();
    let agent_items: Vec<ListItem> = agent_status
        .iter()
        .enumerate()
        .map(|(i, status)| {
            let style = if i % 2 == 0 {
                Style::default().fg(Color::White)
            } else {
                Style::default().fg(Color::Gray)
            };
            ListItem::new(Line::from(Span::styled(status.clone(), style)))
        })
        .collect();

    let agents_list = List::new(agent_items)
        .block(
            Block::default()
                .borders(Borders::ALL)
                .title("🌐 Distributed Agents"),
        )
        .highlight_style(Style::default().add_modifier(Modifier::BOLD))
        .highlight_symbol("> ");

    f.render_widget(agents_list, chunks[0]);

    // Right panel: Network status and controls
    let network_info = vec![
        "Network Status: Active",
        "Connected Nodes: 3",
        "Active Tasks: 7",
        "Load Balancing: Enabled",
        "",
        "Commands:",
        "  [s] Start distributed swarm",
        "  [d] Stop distributed swarm",
        "  [r] Refresh network status",
        "  [t] Test connection",
        "",
        "Recent Activity:",
        "  • Agent-1 completed task #123",
        "  • Agent-2 joined the network",
        "  • Load balancer rebalanced tasks",
    ];

    let network_items: Vec<ListItem> = network_info
        .iter()
        .map(|info| ListItem::new(Line::from(*info)))
        .collect();

    let network_list = List::new(network_items).block(
        Block::default()
            .borders(Borders::ALL)
            .title("📊 Network Status"),
    );

    f.render_widget(network_list, chunks[1]);
}

fn draw_advanced_reasoning(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints(
            [
                Constraint::Percentage(40),
                Constraint::Percentage(30),
                Constraint::Percentage(30),
            ]
            .as_ref(),
        )
        .split(area);

    // Top panel: Active reasoning sessions
    let reasoning_sessions = app.get_active_reasoning_sessions();
    let session_items: Vec<ListItem> = if reasoning_sessions.is_empty() {
        vec![ListItem::new(Line::from("No active reasoning sessions"))]
    } else {
        reasoning_sessions
            .iter()
            .map(|session| ListItem::new(Line::from(session.clone())))
            .collect()
    };

    let sessions_list = List::new(session_items)
        .block(
            Block::default()
                .borders(Borders::ALL)
                .title("🧠 Active Reasoning Sessions"),
        )
        .highlight_style(Style::default().add_modifier(Modifier::BOLD))
        .highlight_symbol("> ");

    f.render_widget(sessions_list, chunks[0]);

    // Middle panel: Reasoning strategies
    let strategies_info = vec![
        "Available Strategies:",
        "",
        "🔗 Chain of Thought",
        "  - Sequential step-by-step reasoning",
        "  - High confidence threshold: 0.7",
        "  - Max steps: 10",
        "",
        "🌳 Tree of Thought",
        "  - Multi-branch exploration",
        "  - Branching factor: 3",
        "  - Max depth: 5",
        "",
        "🔀 Modality Fusion",
        "  - Multi-modal integration",
        "  - Text: 40%, Image: 30%, Audio: 20%, Video: 10%",
        "  - Consensus threshold: 0.8",
        "",
        "📊 Hierarchical Planning",
        "  - Multi-level abstraction",
        "  - 3 abstraction levels",
        "  - Subgoal threshold: 0.7",
        "",
        "⚔️ Adversarial Reasoning",
        "  - Self-criticism and refinement",
        "  - Criticism strength: 0.8",
        "  - Validation rounds: 2",
    ];

    let strategies_items: Vec<ListItem> = strategies_info
        .iter()
        .map(|info| {
            let style = if info.starts_with("🔗")
                || info.starts_with("🌳")
                || info.starts_with("🔀")
                || info.starts_with("📊")
                || info.starts_with("⚔️")
            {
                Style::default()
                    .fg(Color::Cyan)
                    .add_modifier(Modifier::BOLD)
            } else if info.starts_with("  -") {
                Style::default().fg(Color::Yellow)
            } else {
                Style::default().fg(Color::White)
            };
            ListItem::new(Line::from(Span::styled(*info, style)))
        })
        .collect();

    let strategies_list = List::new(strategies_items).block(
        Block::default()
            .borders(Borders::ALL)
            .title("🎯 Reasoning Strategies"),
    );

    f.render_widget(strategies_list, chunks[1]);

    // Bottom panel: Knowledge base and controls
    let knowledge_info = vec![
        "Knowledge Base Status:",
        "",
        "📚 Facts: 0 stored",
        "📋 Rules: 0 defined",
        "🔍 Patterns: 0 learned",
        "💡 Experiences: 0 recorded",
        "",
        "Commands:",
        "  [n] Start new reasoning session",
        "  [p] View planning goals",
        "  [k] Browse knowledge base",
        "  [e] Export reasoning chains",
        "  [i] Import knowledge",
        "",
        "Planning Horizon: 20 steps",
        "Confidence Threshold: 0.75",
    ];

    let knowledge_items: Vec<ListItem> = knowledge_info
        .iter()
        .map(|info| {
            let style = if info.starts_with("📚")
                || info.starts_with("📋")
                || info.starts_with("🔍")
                || info.starts_with("💡")
            {
                Style::default().fg(Color::Green)
            } else if info.starts_with("  [") {
                Style::default().fg(Color::Magenta)
            } else {
                Style::default().fg(Color::White)
            };
            ListItem::new(Line::from(Span::styled(*info, style)))
        })
        .collect();

    let knowledge_list = List::new(knowledge_items).block(
        Block::default()
            .borders(Borders::ALL)
            .title("💾 Knowledge & Controls"),
    );

    f.render_widget(knowledge_list, chunks[2]);
}

fn draw_search(f: &mut Frame, app: &App, area: Rect) {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints(
            [
                Constraint::Length(3),
                Constraint::Min(0),
                Constraint::Length(3),
            ]
            .as_ref(),
        )
        .split(area);

    // Search query display
    let query_text = if app.search_query.is_empty() {
        "No active search. Type and press Enter to search.".to_string()
    } else {
        format!(
            "Search: \"{}\" - Found {} result{}",
            app.search_query,
            app.search_results.len(),
            if app.search_results.len() == 1 {
                ""
            } else {
                "s"
            }
        )
    };

    let query_display = Paragraph::new(query_text)
        .block(
            Block::default()
                .borders(Borders::ALL)
                .title("🔍 Search Query"),
        )
        .style(Style::default().fg(Color::Cyan));

    f.render_widget(query_display, chunks[0]);

    // Search results
    if app.search_results.is_empty() {
        let no_results = Paragraph::new("No results found. Try a different search term.")
            .block(
                Block::default()
                    .borders(Borders::ALL)
                    .title("Search Results"),
            )
            .style(Style::default().fg(Color::Gray))
            .alignment(Alignment::Center);

        f.render_widget(no_results, chunks[1]);
    } else {
        let results: Vec<ListItem> = app
            .search_results
            .iter()
            .enumerate()
            .map(|(result_num, &msg_idx)| {
                let msg = &app.messages[msg_idx];
                let is_selected = result_num == app.search_result_index;

                let role_icon = match msg.role {
                    MessageRole::User => "👤",
                    MessageRole::Assistant => "🤖",
                    MessageRole::System => "⚙️",
                };

                let timestamp = msg.timestamp.format("%H:%M:%S");
                let content_preview = if msg.content.len() > 80 {
                    format!("{}...", &msg.content[..77])
                } else {
                    msg.content.clone()
                };

                let line_text = format!(
                    "[{}] {} {} | {}",
                    result_num + 1,
                    role_icon,
                    timestamp,
                    content_preview
                );

                let style = if is_selected {
                    Style::default()
                        .fg(Color::Yellow)
                        .add_modifier(Modifier::BOLD)
                } else {
                    match msg.role {
                        MessageRole::User => Style::default().fg(Color::Cyan),
                        MessageRole::Assistant => Style::default().fg(Color::Green),
                        MessageRole::System => Style::default().fg(Color::Gray),
                    }
                };

                ListItem::new(line_text).style(style)
            })
            .collect();

        let results_list = List::new(results)
            .block(Block::default().borders(Borders::ALL).title(format!(
                "Search Results ({}/{})",
                app.search_result_index + 1,
                app.search_results.len()
            )))
            .highlight_style(
                Style::default()
                    .add_modifier(Modifier::BOLD)
                    .bg(Color::DarkGray),
            );

        f.render_widget(results_list, chunks[1]);
    }

    // Instructions
    let instructions = if app.search_results.is_empty() {
        "i or /: Enter search | Esc: Return to Chat | Tab: Switch mode"
    } else {
        "↑/↓: Navigate results | i: New search | Esc: Return to Chat | Ctrl+C: Copy"
    };

    let help = Paragraph::new(instructions)
        .block(Block::default().borders(Borders::ALL).title("Controls"))
        .alignment(Alignment::Center)
        .style(Style::default().fg(Color::Yellow));

    f.render_widget(help, chunks[2]);
}