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
//! Integration tests for the complete TUI system

#[cfg(test)]
mod tui_integration_tests {
    use std::path::PathBuf;
    use uuid::Uuid;

    // Test data structures that mirror the TUI components
    #[derive(Debug, Clone)]
    struct TestApp {
        pub current_mode: AppMode,
        pub current_input: String,
        pub messages: Vec<TestMessage>,
        pub agents: Vec<TestAgent>,
        pub media_files: Vec<TestMediaFile>,
        pub selected_media_index: usize,
        pub selected_agent_index: usize,
    }

    #[derive(Debug, Clone)]
    enum AppMode {
        Chat,
        Agents,
        Media,
        Help,
    }

    #[derive(Debug, Clone)]
    struct TestMessage {
        pub role: String,
        pub content: String,
        #[allow(dead_code)]
        pub timestamp: String,
        #[allow(dead_code)]
        pub id: Uuid,
    }

    #[derive(Debug, Clone)]
    struct TestAgent {
        pub id: Uuid,
        pub name: String,
        pub description: String,
        pub capabilities: Vec<String>,
        pub status: AgentStatus,
        pub task_count: usize,
    }

    #[derive(Debug, Clone)]
    enum AgentStatus {
        Idle,
        #[allow(dead_code)]
        Active,
        #[allow(dead_code)]
        Processing,
        Error(String),
    }

    #[derive(Debug, Clone)]
    struct TestMediaFile {
        pub path: PathBuf,
        #[allow(dead_code)]
        pub file_type: MediaType,
        #[allow(dead_code)]
        pub size: u64,
        pub selected: bool,
    }

    #[derive(Debug, Clone)]
    enum MediaType {
        Image,
        Audio,
        Video,
        Unknown,
    }

    impl TestApp {
        fn new() -> Self {
            Self {
                current_mode: AppMode::Chat,
                current_input: String::new(),
                messages: Vec::new(),
                agents: Vec::new(),
                media_files: Vec::new(),
                selected_media_index: 0,
                selected_agent_index: 0,
            }
        }

        fn switch_mode(&mut self, mode: AppMode) {
            self.current_mode = mode;
        }

        fn add_message(&mut self, role: &str, content: &str) {
            let message = TestMessage {
                role: role.to_string(),
                content: content.to_string(),
                timestamp: "2024-01-01 12:00:00".to_string(),
                id: Uuid::new_v4(),
            };
            self.messages.push(message);
        }

        fn add_agent(&mut self, name: &str, description: &str) {
            let agent = TestAgent {
                id: Uuid::new_v4(),
                name: name.to_string(),
                description: description.to_string(),
                capabilities: vec!["text".to_string(), "image".to_string()],
                status: AgentStatus::Idle,
                task_count: 0,
            };
            self.agents.push(agent);
        }

        fn add_media_file(&mut self, path: &str, media_type: MediaType) {
            let media_file = TestMediaFile {
                path: PathBuf::from(path),
                file_type: media_type,
                size: 1024,
                selected: false,
            };
            self.media_files.push(media_file);
        }

        fn next_media(&mut self) {
            if !self.media_files.is_empty() {
                self.selected_media_index =
                    (self.selected_media_index + 1) % self.media_files.len();
            }
        }

        fn previous_media(&mut self) {
            if !self.media_files.is_empty() {
                self.selected_media_index = if self.selected_media_index == 0 {
                    self.media_files.len() - 1
                } else {
                    self.selected_media_index - 1
                };
            }
        }

        fn toggle_media_selection(&mut self) {
            if let Some(media) = self.media_files.get_mut(self.selected_media_index) {
                media.selected = !media.selected;
            }
        }

        fn get_selected_media(&self) -> Vec<&TestMediaFile> {
            self.media_files.iter().filter(|m| m.selected).collect()
        }
    }

    #[test]
    fn test_app_initialization() {
        let app = TestApp::new();

        assert!(matches!(app.current_mode, AppMode::Chat));
        assert!(app.current_input.is_empty());
        assert!(app.messages.is_empty());
        assert!(app.agents.is_empty());
        assert!(app.media_files.is_empty());
        assert_eq!(app.selected_media_index, 0);
        assert_eq!(app.selected_agent_index, 0);
    }

    #[test]
    fn test_mode_switching_workflow() {
        let mut app = TestApp::new();

        // Start in chat mode
        assert!(matches!(app.current_mode, AppMode::Chat));

        // Switch to agents mode
        app.switch_mode(AppMode::Agents);
        assert!(matches!(app.current_mode, AppMode::Agents));

        // Switch to media mode
        app.switch_mode(AppMode::Media);
        assert!(matches!(app.current_mode, AppMode::Media));

        // Switch to help mode
        app.switch_mode(AppMode::Help);
        assert!(matches!(app.current_mode, AppMode::Help));

        // Switch back to chat
        app.switch_mode(AppMode::Chat);
        assert!(matches!(app.current_mode, AppMode::Chat));
    }

    #[test]
    fn test_conversation_workflow() {
        let mut app = TestApp::new();

        // Start conversation
        app.add_message("user", "Hello, AI!");
        assert_eq!(app.messages.len(), 1);
        assert_eq!(app.messages[0].role, "user");
        assert_eq!(app.messages[0].content, "Hello, AI!");

        // AI responds
        app.add_message("assistant", "Hello! How can I help you today?");
        assert_eq!(app.messages.len(), 2);
        assert_eq!(app.messages[1].role, "assistant");

        // User asks about image
        app.add_message("user", "Can you analyze this image?");
        assert_eq!(app.messages.len(), 3);

        // Simulate conversation history
        let conversation_text: Vec<String> = app
            .messages
            .iter()
            .map(|m| format!("{}: {}", m.role, m.content))
            .collect();

        assert_eq!(conversation_text.len(), 3);
        assert!(conversation_text[0].contains("user: Hello, AI!"));
        assert!(conversation_text[1].contains("assistant: Hello! How can I help"));
        assert!(conversation_text[2].contains("user: Can you analyze this image?"));
    }

    #[test]
    fn test_agent_management_workflow() {
        let mut app = TestApp::new();

        // Add agents
        app.add_agent("Vision Agent", "Analyzes images and visual content");
        app.add_agent("Audio Agent", "Processes audio and speech");
        app.add_agent("Text Agent", "Handles text analysis and generation");

        assert_eq!(app.agents.len(), 3);

        // Check agent properties
        let vision_agent = &app.agents[0];
        assert_eq!(vision_agent.name, "Vision Agent");
        assert_eq!(
            vision_agent.description,
            "Analyzes images and visual content"
        );
        assert!(matches!(vision_agent.status, AgentStatus::Idle));
        assert_eq!(vision_agent.task_count, 0);
        assert!(vision_agent.capabilities.contains(&"text".to_string()));
        assert!(vision_agent.capabilities.contains(&"image".to_string()));

        // Verify unique IDs
        let ids: Vec<Uuid> = app.agents.iter().map(|a| a.id).collect();
        assert_eq!(ids.len(), 3);
        assert_ne!(ids[0], ids[1]);
        assert_ne!(ids[1], ids[2]);
        assert_ne!(ids[0], ids[2]);
    }

    #[test]
    fn test_media_management_workflow() {
        let mut app = TestApp::new();

        // Add various media files
        app.add_media_file("image1.jpg", MediaType::Image);
        app.add_media_file("audio1.mp3", MediaType::Audio);
        app.add_media_file("video1.mp4", MediaType::Video);
        app.add_media_file("unknown.txt", MediaType::Unknown);

        assert_eq!(app.media_files.len(), 4);
        assert_eq!(app.selected_media_index, 0);

        // Test navigation
        app.next_media();
        assert_eq!(app.selected_media_index, 1);

        app.next_media();
        assert_eq!(app.selected_media_index, 2);

        app.next_media();
        assert_eq!(app.selected_media_index, 3);

        // Wrap around
        app.next_media();
        assert_eq!(app.selected_media_index, 0);

        // Test backward navigation
        app.previous_media();
        assert_eq!(app.selected_media_index, 3);

        app.previous_media();
        assert_eq!(app.selected_media_index, 2);
    }

    #[test]
    fn test_media_selection_workflow() {
        let mut app = TestApp::new();

        app.add_media_file("image1.jpg", MediaType::Image);
        app.add_media_file("audio1.mp3", MediaType::Audio);
        app.add_media_file("video1.mp4", MediaType::Video);

        // Initially no media selected
        assert_eq!(app.get_selected_media().len(), 0);

        // Select first media
        app.toggle_media_selection();
        assert_eq!(app.get_selected_media().len(), 1);
        assert!(app.media_files[0].selected);

        // Navigate and select second media
        app.next_media();
        app.toggle_media_selection();
        assert_eq!(app.get_selected_media().len(), 2);
        assert!(app.media_files[1].selected);

        // Deselect first media
        app.selected_media_index = 0;
        app.toggle_media_selection();
        assert_eq!(app.get_selected_media().len(), 1);
        assert!(!app.media_files[0].selected);
        assert!(app.media_files[1].selected);
    }

    #[test]
    fn test_multimodal_conversation_workflow() {
        let mut app = TestApp::new();

        // Add media files
        app.add_media_file("screenshot.png", MediaType::Image);
        app.add_media_file("recording.mp3", MediaType::Audio);

        // Select media for analysis
        app.toggle_media_selection();
        app.next_media();
        app.toggle_media_selection();

        // Verify both media selected
        assert_eq!(app.get_selected_media().len(), 2);

        // Start multimodal conversation
        app.add_message("user", "Please analyze the attached image and audio");
        app.add_message("system", "Attached: screenshot.png, recording.mp3");
        app.add_message(
            "assistant",
            "I can see the image shows... and the audio contains...",
        );

        assert_eq!(app.messages.len(), 3);

        // Verify the system message contains media info
        let system_message = &app.messages[1];
        assert_eq!(system_message.role, "system");
        assert!(system_message.content.contains("screenshot.png"));
        assert!(system_message.content.contains("recording.mp3"));
    }

    #[test]
    fn test_agent_swarm_workflow() {
        let mut app = TestApp::new();

        // Create a swarm of specialized agents
        app.add_agent("Image Analyzer", "Specialized in computer vision");
        app.add_agent("Audio Processor", "Handles speech and audio analysis");
        app.add_agent(
            "Text Summarizer",
            "Creates summaries and extracts key points",
        );
        app.add_agent("Coordinator", "Manages task distribution and results");

        assert_eq!(app.agents.len(), 4);

        // Simulate task assignment to multiple agents
        let _task_description = "Analyze uploaded media and provide comprehensive report";

        // Each agent would get assigned specific subtasks
        let image_tasks = vec![
            "Extract visual elements",
            "Identify objects",
            "Analyze composition",
        ];
        let audio_tasks = vec!["Transcribe speech", "Analyze tone", "Extract keywords"];
        let text_tasks = vec![
            "Summarize findings",
            "Generate report",
            "Highlight insights",
        ];
        let coord_tasks = vec!["Coordinate agents", "Compile results", "Final review"];

        // Verify task distribution structure
        assert_eq!(image_tasks.len(), 3);
        assert_eq!(audio_tasks.len(), 3);
        assert_eq!(text_tasks.len(), 3);
        assert_eq!(coord_tasks.len(), 3);

        // All agents should have unique capabilities
        let all_capabilities: Vec<Vec<String>> =
            app.agents.iter().map(|a| a.capabilities.clone()).collect();

        assert_eq!(all_capabilities.len(), 4);
        for capabilities in all_capabilities {
            assert!(!capabilities.is_empty());
        }
    }

    #[test]
    fn test_error_handling_workflow() {
        let mut app = TestApp::new();

        // Add agent and simulate error
        app.add_agent("Test Agent", "Agent for testing error handling");
        assert_eq!(app.agents.len(), 1);

        // Simulate agent error
        if let Some(agent) = app.agents.get_mut(0) {
            agent.status = AgentStatus::Error("Connection timeout".to_string());
        }

        // Verify error state
        let agent = &app.agents[0];
        match &agent.status {
            AgentStatus::Error(msg) => {
                assert_eq!(msg, "Connection timeout");
            }
            _ => panic!("Expected error status"),
        }

        // Test error recovery
        if let Some(agent) = app.agents.get_mut(0) {
            agent.status = AgentStatus::Idle;
        }

        let agent = &app.agents[0];
        assert!(matches!(agent.status, AgentStatus::Idle));
    }

    #[test]
    fn test_complete_tui_session_workflow() {
        let mut app = TestApp::new();

        // 1. Start in chat mode
        assert!(matches!(app.current_mode, AppMode::Chat));

        // 2. Switch to media mode and add files
        app.switch_mode(AppMode::Media);
        app.add_media_file("document.pdf", MediaType::Unknown);
        app.add_media_file("presentation.jpg", MediaType::Image);
        app.add_media_file("meeting.mp3", MediaType::Audio);

        // 3. Select media files
        app.toggle_media_selection(); // Select document.pdf
        app.next_media();
        app.toggle_media_selection(); // Select presentation.jpg

        assert_eq!(app.get_selected_media().len(), 2);

        // 4. Switch to agents mode and set up swarm
        app.switch_mode(AppMode::Agents);
        app.add_agent("Document Analyzer", "Processes documents and PDFs");
        app.add_agent("Vision Specialist", "Analyzes images and presentations");
        app.add_agent("Report Generator", "Creates comprehensive analysis reports");

        assert_eq!(app.agents.len(), 3);

        // 5. Switch back to chat and start multimodal conversation
        app.switch_mode(AppMode::Chat);
        app.add_message(
            "user",
            "Please analyze the uploaded document and presentation",
        );
        app.add_message("system", "Processing 2 files with 3 agents");
        app.add_message("assistant", "Analysis complete. The document contains...");

        assert_eq!(app.messages.len(), 3);

        // 6. Verify complete workflow state
        assert!(matches!(app.current_mode, AppMode::Chat));
        assert_eq!(app.media_files.len(), 3);
        assert_eq!(app.get_selected_media().len(), 2);
        assert_eq!(app.agents.len(), 3);
        assert_eq!(app.messages.len(), 3);

        // 7. Check that all components have proper data
        let selected_media: Vec<&str> = app
            .get_selected_media()
            .iter()
            .map(|m| m.path.file_name().unwrap().to_str().unwrap())
            .collect();

        assert!(selected_media.contains(&"document.pdf"));
        assert!(selected_media.contains(&"presentation.jpg"));

        let agent_names: Vec<&str> = app.agents.iter().map(|a| a.name.as_str()).collect();
        assert!(agent_names.contains(&"Document Analyzer"));
        assert!(agent_names.contains(&"Vision Specialist"));
        assert!(agent_names.contains(&"Report Generator"));

        let last_message = &app.messages[app.messages.len() - 1];
        assert_eq!(last_message.role, "assistant");
        assert!(last_message.content.contains("Analysis complete"));
    }
}