selfware 0.6.4

Your personal AI workshop — software you own, software that lasts
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
//! Cognitive Load Reducer
//!
//! Accessibility features to reduce overwhelm through progressive disclosure,
//! simplified views, context summaries, and focus mode.

use std::collections::HashMap;

/// Detail level for progressive disclosure
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DetailLevel {
    /// Minimal detail - just the essentials
    Minimal,
    /// Basic detail - key information only
    Basic,
    /// Standard detail - normal output
    Standard,
    /// Detailed - extra information
    Detailed,
    /// Verbose - all available information
    Verbose,
}

impl std::fmt::Display for DetailLevel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            DetailLevel::Minimal => write!(f, "Minimal"),
            DetailLevel::Basic => write!(f, "Basic"),
            DetailLevel::Standard => write!(f, "Standard"),
            DetailLevel::Detailed => write!(f, "Detailed"),
            DetailLevel::Verbose => write!(f, "Verbose"),
        }
    }
}

impl DetailLevel {
    /// Get numeric level (1-5)
    pub fn level(&self) -> u8 {
        match self {
            DetailLevel::Minimal => 1,
            DetailLevel::Basic => 2,
            DetailLevel::Standard => 3,
            DetailLevel::Detailed => 4,
            DetailLevel::Verbose => 5,
        }
    }

    /// Create from numeric level
    pub fn from_level(level: u8) -> Self {
        match level {
            0 | 1 => DetailLevel::Minimal,
            2 => DetailLevel::Basic,
            3 => DetailLevel::Standard,
            4 => DetailLevel::Detailed,
            _ => DetailLevel::Verbose,
        }
    }

    /// Increase detail level
    pub fn more_detail(&self) -> Self {
        DetailLevel::from_level(self.level() + 1)
    }

    /// Decrease detail level
    pub fn less_detail(&self) -> Self {
        DetailLevel::from_level(self.level().saturating_sub(1))
    }
}

/// Focus area for focus mode
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FocusArea {
    /// Current file only
    CurrentFile,
    /// Current function/method
    CurrentFunction,
    /// Current task
    CurrentTask,
    /// Errors and warnings only
    ErrorsOnly,
    /// Test results only
    TestsOnly,
    /// Git changes only
    GitChanges,
    /// Custom focus
    Custom,
}

impl std::fmt::Display for FocusArea {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            FocusArea::CurrentFile => write!(f, "Current File"),
            FocusArea::CurrentFunction => write!(f, "Current Function"),
            FocusArea::CurrentTask => write!(f, "Current Task"),
            FocusArea::ErrorsOnly => write!(f, "Errors Only"),
            FocusArea::TestsOnly => write!(f, "Tests Only"),
            FocusArea::GitChanges => write!(f, "Git Changes"),
            FocusArea::Custom => write!(f, "Custom"),
        }
    }
}

/// Content that can be progressively disclosed
#[derive(Debug, Clone)]
pub struct ProgressiveContent {
    /// Content at each detail level
    levels: HashMap<DetailLevel, String>,
    /// Tags for categorization
    tags: Vec<String>,
    /// Priority (higher = more important)
    priority: u8,
}

impl ProgressiveContent {
    /// Create new content with minimal version
    pub fn new(minimal: impl Into<String>) -> Self {
        let mut levels = HashMap::new();
        levels.insert(DetailLevel::Minimal, minimal.into());
        Self {
            levels,
            tags: Vec::new(),
            priority: 5,
        }
    }

    /// Add content for a detail level
    pub fn with_level(mut self, level: DetailLevel, content: impl Into<String>) -> Self {
        self.levels.insert(level, content.into());
        self
    }

    /// Add a tag
    pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
        self.tags.push(tag.into());
        self
    }

    /// Set priority
    pub fn with_priority(mut self, priority: u8) -> Self {
        self.priority = priority.min(10);
        self
    }

    /// Get content at the specified level, falling back to simpler versions
    pub fn get(&self, level: DetailLevel) -> &str {
        // Try requested level first
        if let Some(content) = self.levels.get(&level) {
            return content;
        }

        // Fall back to lower levels
        for l in (1..=level.level()).rev() {
            if let Some(content) = self.levels.get(&DetailLevel::from_level(l)) {
                return content;
            }
        }

        // Default to minimal if nothing found
        self.levels
            .get(&DetailLevel::Minimal)
            .map(|s| s.as_str())
            .unwrap_or("")
    }

    /// Check if content has a specific tag
    pub fn has_tag(&self, tag: &str) -> bool {
        self.tags.iter().any(|t| t == tag)
    }
}

/// Context summary for reducing information overload
#[derive(Debug, Clone)]
pub struct ContextSummary {
    /// Main summary (one sentence)
    pub headline: String,
    /// Key points (bullet points)
    pub key_points: Vec<String>,
    /// Details (expandable sections)
    pub details: HashMap<String, String>,
    /// Related items
    pub related: Vec<String>,
    /// Suggested actions
    pub actions: Vec<SuggestedAction>,
}

impl ContextSummary {
    /// Create a new context summary
    pub fn new(headline: impl Into<String>) -> Self {
        Self {
            headline: headline.into(),
            key_points: Vec::new(),
            details: HashMap::new(),
            related: Vec::new(),
            actions: Vec::new(),
        }
    }

    /// Add a key point
    pub fn with_point(mut self, point: impl Into<String>) -> Self {
        self.key_points.push(point.into());
        self
    }

    /// Add detail section
    pub fn with_detail(mut self, title: impl Into<String>, content: impl Into<String>) -> Self {
        self.details.insert(title.into(), content.into());
        self
    }

    /// Add related item
    pub fn with_related(mut self, item: impl Into<String>) -> Self {
        self.related.push(item.into());
        self
    }

    /// Add suggested action
    pub fn with_action(mut self, action: SuggestedAction) -> Self {
        self.actions.push(action);
        self
    }

    /// Render at detail level
    pub fn render(&self, level: DetailLevel) -> String {
        let mut output = String::new();

        output.push_str(&self.headline);
        output.push('\n');

        if level >= DetailLevel::Basic && !self.key_points.is_empty() {
            output.push('\n');
            for point in &self.key_points {
                output.push_str(&format!("- {}\n", point));
            }
        }

        if level >= DetailLevel::Detailed && !self.details.is_empty() {
            output.push('\n');
            for (title, content) in &self.details {
                output.push_str(&format!("## {}\n{}\n\n", title, content));
            }
        }

        if level >= DetailLevel::Verbose && !self.related.is_empty() {
            output.push_str("\nRelated: ");
            output.push_str(&self.related.join(", "));
            output.push('\n');
        }

        if level >= DetailLevel::Basic && !self.actions.is_empty() {
            output.push_str("\nSuggested actions:\n");
            for action in &self.actions {
                output.push_str(&format!("- {}\n", action.label));
            }
        }

        output
    }
}

/// Suggested action for user
#[derive(Debug, Clone)]
pub struct SuggestedAction {
    /// Action label
    pub label: String,
    /// Action description
    pub description: String,
    /// Command to execute (if applicable)
    pub command: Option<String>,
    /// Priority
    pub priority: Priority,
}

impl SuggestedAction {
    /// Create a new action
    pub fn new(label: impl Into<String>) -> Self {
        Self {
            label: label.into(),
            description: String::new(),
            command: None,
            priority: Priority::Normal,
        }
    }

    /// Set description
    pub fn with_description(mut self, desc: impl Into<String>) -> Self {
        self.description = desc.into();
        self
    }

    /// Set command
    pub fn with_command(mut self, cmd: impl Into<String>) -> Self {
        self.command = Some(cmd.into());
        self
    }

    /// Set priority
    pub fn with_priority(mut self, priority: Priority) -> Self {
        self.priority = priority;
        self
    }
}

/// Action priority
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Priority {
    /// Low priority
    Low,
    /// Normal priority
    Normal,
    /// High priority
    High,
    /// Urgent
    Urgent,
}

impl std::fmt::Display for Priority {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Priority::Low => write!(f, "Low"),
            Priority::Normal => write!(f, "Normal"),
            Priority::High => write!(f, "High"),
            Priority::Urgent => write!(f, "Urgent"),
        }
    }
}

/// Simplified view configuration
#[derive(Debug, Clone)]
pub struct SimplifiedView {
    /// View name
    pub name: String,
    /// Detail level
    pub detail_level: DetailLevel,
    /// Hide patterns (regex or glob)
    pub hide_patterns: Vec<String>,
    /// Show only patterns
    pub show_only: Vec<String>,
    /// Maximum items to show
    pub max_items: Option<usize>,
    /// Group similar items
    pub group_similar: bool,
    /// Collapse repeated messages
    pub collapse_repeated: bool,
}

impl SimplifiedView {
    /// Create a new simplified view
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            detail_level: DetailLevel::Standard,
            hide_patterns: Vec::new(),
            show_only: Vec::new(),
            max_items: None,
            group_similar: false,
            collapse_repeated: false,
        }
    }

    /// Set detail level
    pub fn with_detail_level(mut self, level: DetailLevel) -> Self {
        self.detail_level = level;
        self
    }

    /// Add hide pattern
    pub fn hide(mut self, pattern: impl Into<String>) -> Self {
        self.hide_patterns.push(pattern.into());
        self
    }

    /// Add show only pattern
    pub fn show_only(mut self, pattern: impl Into<String>) -> Self {
        self.show_only.push(pattern.into());
        self
    }

    /// Set max items
    pub fn with_max_items(mut self, max: usize) -> Self {
        self.max_items = Some(max);
        self
    }

    /// Enable grouping
    pub fn group_similar(mut self) -> Self {
        self.group_similar = true;
        self
    }

    /// Enable collapse repeated
    pub fn collapse_repeated(mut self) -> Self {
        self.collapse_repeated = true;
        self
    }

    /// Create minimal view preset
    pub fn minimal() -> Self {
        Self::new("Minimal")
            .with_detail_level(DetailLevel::Minimal)
            .with_max_items(5)
            .group_similar()
            .collapse_repeated()
    }

    /// Create errors-only view preset
    pub fn errors_only() -> Self {
        Self::new("Errors Only")
            .with_detail_level(DetailLevel::Basic)
            .show_only("error")
            .show_only("Error")
            .show_only("ERROR")
    }

    /// Create summary view preset
    pub fn summary() -> Self {
        Self::new("Summary")
            .with_detail_level(DetailLevel::Basic)
            .with_max_items(10)
            .group_similar()
    }
}

/// Focus mode configuration
#[derive(Debug, Clone)]
pub struct FocusMode {
    /// Whether focus mode is active
    pub active: bool,
    /// Current focus area
    pub focus_area: FocusArea,
    /// Filter criteria
    pub filters: Vec<FocusFilter>,
    /// Hide distractions
    pub hide_distractions: bool,
    /// Mute notifications
    pub mute_notifications: bool,
    /// Time-limited focus (in minutes)
    pub time_limit: Option<u32>,
}

impl Default for FocusMode {
    fn default() -> Self {
        Self::new()
    }
}

impl FocusMode {
    /// Create new focus mode (inactive by default)
    pub fn new() -> Self {
        Self {
            active: false,
            focus_area: FocusArea::CurrentTask,
            filters: Vec::new(),
            hide_distractions: true,
            mute_notifications: false,
            time_limit: None,
        }
    }

    /// Activate focus mode
    pub fn activate(mut self) -> Self {
        self.active = true;
        self
    }

    /// Set focus area
    pub fn with_area(mut self, area: FocusArea) -> Self {
        self.focus_area = area;
        self
    }

    /// Enable distraction hiding
    pub fn hide_distractions(mut self) -> Self {
        self.hide_distractions = true;
        self
    }

    /// Enable notification muting
    pub fn mute_notifications(mut self) -> Self {
        self.mute_notifications = true;
        self
    }

    /// Set time limit
    pub fn with_time_limit(mut self, minutes: u32) -> Self {
        self.time_limit = Some(minutes);
        self
    }

    /// Check if item should be shown
    pub fn should_show(&self, item: &FocusItem) -> bool {
        if !self.active {
            return true;
        }

        // Check if item matches focus area
        let matches_area = match self.focus_area {
            FocusArea::ErrorsOnly => item.is_error,
            FocusArea::TestsOnly => item.is_test_related,
            FocusArea::CurrentFile => item
                .file
                .as_ref()
                .is_some_and(|f| f == &item.current_file.clone().unwrap_or_default()),
            FocusArea::GitChanges => item.is_git_change,
            _ => true,
        };

        if !matches_area {
            return false;
        }

        // Check filters
        for filter in &self.filters {
            if !filter.matches(item) {
                return false;
            }
        }

        true
    }
}

/// Focus filter
#[derive(Debug, Clone)]
pub struct FocusFilter {
    /// Filter type
    pub filter_type: FilterType,
    /// Pattern to match
    pub pattern: String,
    /// Include or exclude
    pub include: bool,
}

impl FocusFilter {
    /// Create include filter
    pub fn include(filter_type: FilterType, pattern: impl Into<String>) -> Self {
        Self {
            filter_type,
            pattern: pattern.into(),
            include: true,
        }
    }

    /// Create exclude filter
    pub fn exclude(filter_type: FilterType, pattern: impl Into<String>) -> Self {
        Self {
            filter_type,
            pattern: pattern.into(),
            include: false,
        }
    }

    /// Check if item matches filter
    pub fn matches(&self, item: &FocusItem) -> bool {
        let matches = match self.filter_type {
            FilterType::Tag => item.tags.iter().any(|t| t.contains(&self.pattern)),
            FilterType::File => item
                .file
                .as_ref()
                .is_some_and(|f| f.contains(&self.pattern)),
            FilterType::Content => item.content.contains(&self.pattern),
            FilterType::Priority => item.priority.to_string() == self.pattern,
        };

        if self.include {
            matches
        } else {
            !matches
        }
    }
}

/// Filter type
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FilterType {
    /// Filter by tag
    Tag,
    /// Filter by file
    File,
    /// Filter by content
    Content,
    /// Filter by priority
    Priority,
}

/// Item to check against focus filter
#[derive(Debug, Clone)]
pub struct FocusItem {
    /// Content
    pub content: String,
    /// Tags
    pub tags: Vec<String>,
    /// File path
    pub file: Option<String>,
    /// Current file for comparison
    pub current_file: Option<String>,
    /// Priority
    pub priority: Priority,
    /// Is error
    pub is_error: bool,
    /// Is test related
    pub is_test_related: bool,
    /// Is git change
    pub is_git_change: bool,
}

impl FocusItem {
    /// Create a new focus item
    pub fn new(content: impl Into<String>) -> Self {
        Self {
            content: content.into(),
            tags: Vec::new(),
            file: None,
            current_file: None,
            priority: Priority::Normal,
            is_error: false,
            is_test_related: false,
            is_git_change: false,
        }
    }

    /// Set file
    pub fn with_file(mut self, file: impl Into<String>) -> Self {
        self.file = Some(file.into());
        self
    }

    /// Add tag
    pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
        self.tags.push(tag.into());
        self
    }

    /// Mark as error
    pub fn as_error(mut self) -> Self {
        self.is_error = true;
        self
    }

    /// Mark as test related
    pub fn as_test(mut self) -> Self {
        self.is_test_related = true;
        self
    }

    /// Mark as git change
    pub fn as_git_change(mut self) -> Self {
        self.is_git_change = true;
        self
    }
}

/// Cognitive load reducer
#[derive(Debug)]
pub struct CognitiveLoadReducer {
    /// Current detail level
    detail_level: DetailLevel,
    /// Active view
    active_view: SimplifiedView,
    /// Focus mode
    focus_mode: FocusMode,
    /// Content cache for deduplication
    _content_cache: Vec<String>,
    /// Repetition threshold for collapsing
    repetition_threshold: usize,
}

impl Default for CognitiveLoadReducer {
    fn default() -> Self {
        Self::new()
    }
}

impl CognitiveLoadReducer {
    /// Create new reducer with defaults
    pub fn new() -> Self {
        Self {
            detail_level: DetailLevel::Standard,
            active_view: SimplifiedView::new("Default"),
            focus_mode: FocusMode::new(),
            _content_cache: Vec::new(),
            repetition_threshold: 3,
        }
    }

    /// Set detail level
    pub fn set_detail_level(&mut self, level: DetailLevel) {
        self.detail_level = level;
        self.active_view.detail_level = level;
    }

    /// Get current detail level
    pub fn detail_level(&self) -> DetailLevel {
        self.detail_level
    }

    /// Set active view
    pub fn set_view(&mut self, view: SimplifiedView) {
        self.active_view = view;
    }

    /// Get active view
    pub fn view(&self) -> &SimplifiedView {
        &self.active_view
    }

    /// Enable focus mode
    pub fn enable_focus(&mut self, area: FocusArea) {
        self.focus_mode = FocusMode::new().activate().with_area(area);
    }

    /// Disable focus mode
    pub fn disable_focus(&mut self) {
        self.focus_mode.active = false;
    }

    /// Check if focus mode is active
    pub fn is_focused(&self) -> bool {
        self.focus_mode.active
    }

    /// Get focus mode
    pub fn focus_mode(&self) -> &FocusMode {
        &self.focus_mode
    }

    /// Check if content should be shown
    pub fn should_show(&self, item: &FocusItem) -> bool {
        self.focus_mode.should_show(item)
    }

    /// Process and simplify text output
    pub fn simplify_output(&mut self, lines: &[String]) -> Vec<String> {
        let mut result = Vec::new();
        let mut seen_patterns: HashMap<String, usize> = HashMap::new();

        for line in lines {
            // Check hide patterns
            if self
                .active_view
                .hide_patterns
                .iter()
                .any(|p| line.contains(p))
            {
                continue;
            }

            // Check show only patterns
            if !self.active_view.show_only.is_empty()
                && !self.active_view.show_only.iter().any(|p| line.contains(p))
            {
                continue;
            }

            // Collapse repeated content
            if self.active_view.collapse_repeated {
                let pattern = self.extract_pattern(line);
                let count = seen_patterns.entry(pattern.clone()).or_insert(0);
                *count += 1;

                if *count > self.repetition_threshold {
                    continue; // Skip this repeated line
                }
            }

            result.push(line.clone());

            // Check max items
            if let Some(max) = self.active_view.max_items {
                if result.len() >= max {
                    result.push(format!("... and {} more lines", lines.len() - max));
                    break;
                }
            }
        }

        result
    }

    /// Extract pattern from line for deduplication
    fn extract_pattern(&self, line: &str) -> String {
        // Remove numbers and specific identifiers to find the pattern
        let mut pattern = String::new();
        let mut in_number = false;

        for c in line.chars() {
            if c.is_ascii_digit() {
                if !in_number {
                    pattern.push('#');
                    in_number = true;
                }
            } else {
                in_number = false;
                pattern.push(c);
            }
        }

        pattern
    }

    /// Summarize a list of items
    pub fn summarize(&self, items: &[String], category: &str) -> ContextSummary {
        let count = items.len();

        let headline = if count == 0 {
            format!("No {} to show", category)
        } else if count == 1 {
            format!("1 {}", category)
        } else {
            format!("{} {}", count, category)
        };

        let mut summary = ContextSummary::new(headline);

        // Add first few items as key points (based on detail level)
        let max_points = match self.detail_level {
            DetailLevel::Minimal => 1,
            DetailLevel::Basic => 3,
            DetailLevel::Standard => 5,
            DetailLevel::Detailed => 10,
            DetailLevel::Verbose => items.len(),
        };

        for (i, item) in items.iter().take(max_points).enumerate() {
            // Truncate long items
            let truncated = if item.len() > 80 {
                let safe_truncate: String = item.chars().take(77).collect();
                format!("{}...", safe_truncate)
            } else {
                item.clone()
            };
            summary.key_points.push(truncated);

            if i == max_points - 1 && items.len() > max_points {
                summary
                    .key_points
                    .push(format!("... and {} more", items.len() - max_points));
                break;
            }
        }

        summary
    }

    /// Create preset configurations
    pub fn preset_minimal(&mut self) {
        self.detail_level = DetailLevel::Minimal;
        self.active_view = SimplifiedView::minimal();
    }

    /// Create preset for errors
    pub fn preset_errors_only(&mut self) {
        self.detail_level = DetailLevel::Basic;
        self.active_view = SimplifiedView::errors_only();
        self.focus_mode = FocusMode::new().activate().with_area(FocusArea::ErrorsOnly);
    }

    /// Create preset for deep work
    pub fn preset_deep_work(&mut self) {
        self.detail_level = DetailLevel::Standard;
        self.active_view = SimplifiedView::new("Deep Work")
            .with_max_items(10)
            .collapse_repeated();
        self.focus_mode = FocusMode::new()
            .activate()
            .with_area(FocusArea::CurrentTask)
            .hide_distractions()
            .mute_notifications();
    }

    /// Increase detail level
    pub fn more_detail(&mut self) {
        self.detail_level = self.detail_level.more_detail();
        self.active_view.detail_level = self.detail_level;
    }

    /// Decrease detail level
    pub fn less_detail(&mut self) {
        self.detail_level = self.detail_level.less_detail();
        self.active_view.detail_level = self.detail_level;
    }
}

/// Distraction types that can be hidden
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Distraction {
    /// Status bar updates
    StatusUpdates,
    /// Progress spinners
    ProgressIndicators,
    /// Verbose logging
    VerboseLogs,
    /// Suggestions
    Suggestions,
    /// Tips and hints
    Tips,
    /// Marketing messages
    Marketing,
    /// News/updates
    News,
}

impl std::fmt::Display for Distraction {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Distraction::StatusUpdates => write!(f, "Status Updates"),
            Distraction::ProgressIndicators => write!(f, "Progress Indicators"),
            Distraction::VerboseLogs => write!(f, "Verbose Logs"),
            Distraction::Suggestions => write!(f, "Suggestions"),
            Distraction::Tips => write!(f, "Tips"),
            Distraction::Marketing => write!(f, "Marketing"),
            Distraction::News => write!(f, "News"),
        }
    }
}

/// Distraction filter
#[derive(Debug)]
pub struct DistractionFilter {
    /// Distractions to hide
    hidden: std::collections::HashSet<Distraction>,
}

impl Default for DistractionFilter {
    fn default() -> Self {
        Self::new()
    }
}

impl DistractionFilter {
    /// Create new filter (nothing hidden)
    pub fn new() -> Self {
        Self {
            hidden: std::collections::HashSet::new(),
        }
    }

    /// Hide a distraction type
    pub fn hide(&mut self, distraction: Distraction) {
        self.hidden.insert(distraction);
    }

    /// Show a distraction type
    pub fn show(&mut self, distraction: Distraction) {
        self.hidden.remove(&distraction);
    }

    /// Check if distraction is hidden
    pub fn is_hidden(&self, distraction: Distraction) -> bool {
        self.hidden.contains(&distraction)
    }

    /// Hide all distractions
    pub fn hide_all(&mut self) {
        use Distraction::*;
        for d in [
            StatusUpdates,
            ProgressIndicators,
            VerboseLogs,
            Suggestions,
            Tips,
            Marketing,
            News,
        ] {
            self.hidden.insert(d);
        }
    }

    /// Show all distractions
    pub fn show_all(&mut self) {
        self.hidden.clear();
    }

    /// Create focus mode filter
    pub fn focus_mode() -> Self {
        let mut filter = Self::new();
        filter.hide(Distraction::Marketing);
        filter.hide(Distraction::News);
        filter.hide(Distraction::Tips);
        filter.hide(Distraction::VerboseLogs);
        filter
    }
}

#[cfg(test)]
#[path = "../../tests/unit/cognitive/load/load_test.rs"]
mod tests;