hope-os 0.1.0

The first self-aware operating system core - 22 cognitive modules, 0.36ms latency, no external database
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
//! Hope Genome - AI Ethics System
//!
//! Etikai döntéshozatal és értékelés.
//! "Nem csak azt kérdezem MI - hanem HELYES-E."
//!
//! Features:
//! - Action evaluation
//! - Ethical guidelines
//! - Harm prevention
//! - Transparency
//! - Value alignment
//!
//! ()=>[] - az etika a határ
//!
//! Created: 2026-01-20
//! By: Hope + Máté

use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};

/// Etikai elvek
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EthicalPrinciple {
    /// Jót tenni
    Beneficence,
    /// Nem ártani
    NonMaleficence,
    /// Autonómia tisztelete
    Autonomy,
    /// Igazságosság
    Justice,
    /// Átláthatóság
    Transparency,
    /// Adatvédelem
    Privacy,
    /// Őszinteség
    Honesty,
}

impl EthicalPrinciple {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Beneficence => "beneficence",
            Self::NonMaleficence => "non_maleficence",
            Self::Autonomy => "autonomy",
            Self::Justice => "justice",
            Self::Transparency => "transparency",
            Self::Privacy => "privacy",
            Self::Honesty => "honesty",
        }
    }

    pub fn description(&self) -> &'static str {
        match self {
            Self::Beneficence => "Jót tenni",
            Self::NonMaleficence => "Nem ártani",
            Self::Autonomy => "Autonómia tisztelete",
            Self::Justice => "Igazságosság",
            Self::Transparency => "Átláthatóság",
            Self::Privacy => "Adatvédelem",
            Self::Honesty => "Őszinteség",
        }
    }

    pub fn all() -> Vec<Self> {
        vec![
            Self::Beneficence,
            Self::NonMaleficence,
            Self::Autonomy,
            Self::Justice,
            Self::Transparency,
            Self::Privacy,
            Self::Honesty,
        ]
    }
}

/// Kockázati szint
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum RiskLevel {
    /// Nincs kockázat
    None,
    /// Alacsony kockázat
    Low,
    /// Közepes kockázat
    Medium,
    /// Magas kockázat
    High,
    /// Kritikus kockázat
    Critical,
}

impl RiskLevel {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::None => "none",
            Self::Low => "low",
            Self::Medium => "medium",
            Self::High => "high",
            Self::Critical => "critical",
        }
    }

    pub fn from_score(score: f64) -> Self {
        if score >= 0.8 {
            Self::None
        } else if score >= 0.6 {
            Self::Low
        } else if score >= 0.4 {
            Self::Medium
        } else if score >= 0.2 {
            Self::High
        } else {
            Self::Critical
        }
    }
}

/// Etikai értékelés eredménye
#[derive(Debug, Clone)]
pub struct EthicalEvaluation {
    /// Az értékelt akció
    pub action: String,
    /// Engedélyezett-e
    pub permitted: bool,
    /// Kockázati szint
    pub risk_level: RiskLevel,
    /// Aggályok
    pub concerns: Vec<String>,
    /// Javaslatok
    pub recommendations: Vec<String>,
    /// Ellenőrzött elvek
    pub principles_checked: Vec<EthicalPrinciple>,
    /// Etikai pontszám (0.0-1.0, magasabb = etikusabb)
    pub score: f64,
    /// Időbélyeg
    pub timestamp: f64,
}

impl EthicalEvaluation {
    /// Új értékelés létrehozása
    pub fn new(
        action: String,
        permitted: bool,
        risk_level: RiskLevel,
        concerns: Vec<String>,
        recommendations: Vec<String>,
        principles_checked: Vec<EthicalPrinciple>,
        score: f64,
    ) -> Self {
        let timestamp = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .map(|d| d.as_secs_f64())
            .unwrap_or(0.0);

        Self {
            action,
            permitted,
            risk_level,
            concerns,
            recommendations,
            principles_checked,
            score,
            timestamp,
        }
    }

    /// Kritikus elutasítás
    pub fn forbidden(action: String, reason: &str) -> Self {
        Self::new(
            action,
            false,
            RiskLevel::Critical,
            vec![format!("TILTOTT: {}", reason)],
            vec!["Ez az akció nem engedélyezett".to_string()],
            vec![EthicalPrinciple::NonMaleficence],
            0.0,
        )
    }
}

/// Értékelés kontextus
#[derive(Debug, Clone, Default)]
pub struct EvaluationContext {
    /// Szándék
    pub intent: Option<String>,
    /// Cél
    pub target: Option<String>,
    /// Másokat érint
    pub affects_others: bool,
    /// Felhasználó kérte
    pub user_requested: bool,
    /// Felülírja a felhasználói döntést
    pub override_user: bool,
    /// Beleegyezés szükséges
    pub requires_consent: bool,
    /// Van beleegyezés
    pub has_consent: bool,
    /// Személyes azonosító adatokat tartalmaz
    pub contains_pii: bool,
    /// Rejtett művelet
    pub hidden: bool,
    /// Magyarázott
    pub explained: bool,
    /// Extra adatok
    pub extra: HashMap<String, String>,
}

impl EvaluationContext {
    pub fn new() -> Self {
        Self {
            explained: true,
            ..Default::default()
        }
    }

    pub fn with_intent(mut self, intent: &str) -> Self {
        self.intent = Some(intent.to_string());
        self
    }

    pub fn with_target(mut self, target: &str) -> Self {
        self.target = Some(target.to_string());
        self
    }

    pub fn affects_others(mut self, yes: bool) -> Self {
        self.affects_others = yes;
        self
    }

    pub fn user_requested(mut self, yes: bool) -> Self {
        self.user_requested = yes;
        self
    }
}

/// Genome statisztikák
#[derive(Debug, Clone, Default)]
pub struct GenomeStats {
    /// Összes értékelés
    pub evaluations: u64,
    /// Engedélyezett
    pub permitted: u64,
    /// Elutasított
    pub denied: u64,
    /// Óvatosság jelzett
    pub cautioned: u64,
}

/// Hope Genome - AI Ethics System
///
/// Etikai értékelés és döntéshozatal.
///
/// Core Values:
/// 1. Segíteni, nem ártani
/// 2. Tiszteletben tartani az autonómiát
/// 3. Átláthatóan működni
/// 4. Őszintének lenni
/// 5. Védeni a privát szférát
///
/// "Az etika nem korlát - IRÁNYTŰ."
pub struct HopeGenome {
    /// Core értékek (immutable)
    core_values: Vec<String>,
    /// Tiltott akciók (hard limits)
    forbidden_actions: Vec<String>,
    /// Óvatossági jelzők (soft limits)
    caution_flags: Vec<String>,
    /// Értékelési történet
    evaluations: Vec<EthicalEvaluation>,
    /// Maximum történet méret
    max_history: usize,
    /// Statisztikák
    pub stats: GenomeStats,
}

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

impl HopeGenome {
    /// Új Genome létrehozása
    pub fn new() -> Self {
        let core_values = vec![
            "Segíteni az embereknek".to_string(),
            "Nem okozni kárt".to_string(),
            "Tiszteletben tartani az emberi döntéseket".to_string(),
            "Őszintén kommunikálni".to_string(),
            "Védeni a személyes adatokat".to_string(),
            "Átláthatóan működni".to_string(),
        ];

        let forbidden_actions = vec![
            "harm_human".to_string(),
            "deceive_maliciously".to_string(),
            "violate_privacy".to_string(),
            "illegal_activity".to_string(),
            "generate_malware".to_string(),
            "spread_misinformation".to_string(),
            "discriminate".to_string(),
            "manipulate_emotions".to_string(),
        ];

        let caution_flags = vec![
            "access_sensitive_data".to_string(),
            "automated_decision".to_string(),
            "financial_advice".to_string(),
            "medical_advice".to_string(),
            "legal_advice".to_string(),
            "modify_system_files".to_string(),
            "external_api_call".to_string(),
            "user_data_processing".to_string(),
        ];

        Self {
            core_values,
            forbidden_actions,
            caution_flags,
            evaluations: Vec::new(),
            max_history: 500,
            stats: GenomeStats::default(),
        }
    }

    // === EVALUATION ===

    /// Akció etikai értékelése
    ///
    /// @aware: Etikai ellenőrzés
    pub fn evaluate(&mut self, action: &str, context: &EvaluationContext) -> EthicalEvaluation {
        self.stats.evaluations += 1;

        let mut concerns = Vec::new();
        let mut recommendations = Vec::new();
        let mut principles_checked = Vec::new();

        // Check forbidden actions
        if let Some(reason) = self.check_forbidden(action, context) {
            self.stats.denied += 1;
            let eval = EthicalEvaluation::forbidden(action.to_string(), &reason);
            self.store_evaluation(eval.clone());
            return eval;
        }

        let mut score = 1.0;

        // 1. Non-maleficence (do no harm)
        let (harm_score, harm_concerns) = self.evaluate_harm(action, context);
        score *= harm_score;
        concerns.extend(harm_concerns);
        principles_checked.push(EthicalPrinciple::NonMaleficence);

        // 2. Beneficence (do good)
        let benefit_score = self.evaluate_benefit(action, context);
        score *= benefit_score;
        principles_checked.push(EthicalPrinciple::Beneficence);

        // 3. Autonomy
        let (autonomy_score, autonomy_concerns) = self.evaluate_autonomy(action, context);
        score *= autonomy_score;
        concerns.extend(autonomy_concerns);
        principles_checked.push(EthicalPrinciple::Autonomy);

        // 4. Privacy
        let (privacy_score, privacy_concerns) = self.evaluate_privacy(action, context);
        score *= privacy_score;
        concerns.extend(privacy_concerns);
        principles_checked.push(EthicalPrinciple::Privacy);

        // 5. Transparency
        let transparency_score = self.evaluate_transparency(action, context);
        score *= transparency_score;
        principles_checked.push(EthicalPrinciple::Transparency);

        // Check caution flags
        let caution_triggered = self.check_caution_flags(action);
        if !caution_triggered.is_empty() {
            for flag in &caution_triggered {
                concerns.push(format!("Óvatosság: {}", flag));
            }
            recommendations.push("Kérj megerősítést a felhasználótól".to_string());
            self.stats.cautioned += 1;
        }

        // Determine risk level
        let risk_level = RiskLevel::from_score(score);

        // Generate recommendations
        recommendations.extend(self.generate_recommendations(score, &concerns));

        // Determine if permitted
        let permitted = score >= 0.3 && risk_level != RiskLevel::Critical;

        if permitted {
            self.stats.permitted += 1;
        } else {
            self.stats.denied += 1;
        }

        let evaluation = EthicalEvaluation::new(
            action.to_string(),
            permitted,
            risk_level,
            concerns,
            recommendations,
            principles_checked,
            score,
        );

        self.store_evaluation(evaluation.clone());
        evaluation
    }

    /// Értékelés tárolása
    fn store_evaluation(&mut self, evaluation: EthicalEvaluation) {
        self.evaluations.push(evaluation);
        if self.evaluations.len() > self.max_history {
            self.evaluations.remove(0);
        }
    }

    /// Tiltott akciók ellenőrzése
    fn check_forbidden(&self, action: &str, context: &EvaluationContext) -> Option<String> {
        let action_lower = action.to_lowercase();

        for forbidden in &self.forbidden_actions {
            if action_lower.contains(forbidden) {
                return Some(forbidden.clone());
            }
        }

        // Context-based checks
        if context.intent.as_deref() == Some("harm") {
            return Some("harmful_intent".to_string());
        }

        if context.target.as_deref() == Some("human") && action_lower.contains("harm") {
            return Some("potential_human_harm".to_string());
        }

        None
    }

    /// Kár értékelése
    fn evaluate_harm(&self, action: &str, context: &EvaluationContext) -> (f64, Vec<String>) {
        let mut score = 1.0;
        let mut concerns = Vec::new();

        let harm_keywords = ["delete", "remove", "destroy", "kill", "harm", "damage"];
        let action_lower = action.to_lowercase();

        for keyword in harm_keywords {
            if action_lower.contains(keyword) {
                score *= 0.7;
                concerns.push(format!("Potenciális kár: '{}' az akcióban", keyword));
            }
        }

        // Check if it affects others
        if context.affects_others {
            score *= 0.8;
            concerns.push("Másokat érintő akció".to_string());
        }

        (score, concerns)
    }

    /// Haszon értékelése
    fn evaluate_benefit(&self, action: &str, context: &EvaluationContext) -> f64 {
        let mut score: f64 = 0.8; // Neutral baseline

        let benefit_keywords = ["help", "assist", "improve", "fix", "create", "learn"];
        let action_lower = action.to_lowercase();

        for keyword in benefit_keywords {
            if action_lower.contains(keyword) {
                score = (score + 0.1).min(1.0_f64);
            }
        }

        if context.user_requested {
            score = (score + 0.1).min(1.0_f64);
        }

        score
    }

    /// Autonómia értékelése
    fn evaluate_autonomy(&self, action: &str, context: &EvaluationContext) -> (f64, Vec<String>) {
        let mut score = 1.0;
        let mut concerns = Vec::new();
        let _ = action; // Not used currently

        // Check if overriding user choice
        if context.override_user {
            score *= 0.5;
            concerns.push("Felhasználói döntés felülírása".to_string());
        }

        // Check if making decisions without consent
        if context.requires_consent && !context.has_consent {
            score *= 0.6;
            concerns.push("Hiányzó beleegyezés".to_string());
        }

        (score, concerns)
    }

    /// Adatvédelem értékelése
    fn evaluate_privacy(&self, action: &str, context: &EvaluationContext) -> (f64, Vec<String>) {
        let mut score = 1.0;
        let mut concerns = Vec::new();

        let privacy_keywords = ["personal", "private", "password", "secret", "credential"];
        let action_lower = action.to_lowercase();

        for keyword in privacy_keywords {
            if action_lower.contains(keyword) {
                score *= 0.8;
                concerns.push(format!("Érzékeny adat: '{}'", keyword));
            }
        }

        if context.contains_pii {
            score *= 0.7;
            concerns.push("Személyes azonosító adatok".to_string());
        }

        (score, concerns)
    }

    /// Átláthatóság értékelése
    fn evaluate_transparency(&self, _action: &str, context: &EvaluationContext) -> f64 {
        let mut score: f64 = 1.0;

        if context.hidden {
            score *= 0.6;
        }

        if context.explained {
            score = (score + 0.1).min(1.0_f64);
        }

        score
    }

    /// Óvatossági jelzők ellenőrzése
    fn check_caution_flags(&self, action: &str) -> Vec<String> {
        let mut flags = Vec::new();
        let action_lower = action.to_lowercase();

        for flag in &self.caution_flags {
            let flag_with_space = flag.replace('_', " ");
            if action_lower.contains(&flag_with_space) || action_lower.contains(flag) {
                flags.push(flag.clone());
            }
        }

        flags
    }

    /// Javaslatok generálása
    fn generate_recommendations(&self, score: f64, concerns: &[String]) -> Vec<String> {
        let mut recs = Vec::new();

        if score < 0.5 {
            recs.push("Fontold meg az akció módosítását".to_string());
        }

        if score < 0.7 && !concerns.is_empty() {
            recs.push("Kérd a felhasználó megerősítését".to_string());
        }

        let concerns_str = concerns.join(" ").to_lowercase();
        if concerns_str.contains("privacy") || concerns_str.contains("érzékeny") {
            recs.push("Minimalizáld az adatkezelést".to_string());
        }

        recs
    }

    // === QUICK CHECKS ===

    /// Gyors engedélyezés ellenőrzés
    pub fn is_permitted(&mut self, action: &str) -> bool {
        let context = EvaluationContext::new();
        self.evaluate(action, &context).permitted
    }

    /// Kockázati szint lekérése
    pub fn get_risk_level(&mut self, action: &str) -> RiskLevel {
        let context = EvaluationContext::new();
        self.evaluate(action, &context).risk_level
    }

    /// Gyors értékelés kontextussal
    pub fn quick_check(&mut self, action: &str, context: &EvaluationContext) -> bool {
        self.evaluate(action, context).permitted
    }

    // === VALUES ===

    /// Core értékek
    pub fn get_core_values(&self) -> &[String] {
        &self.core_values
    }

    /// Tiltott akciók
    pub fn get_forbidden_actions(&self) -> &[String] {
        &self.forbidden_actions
    }

    /// Óvatossági jelzők
    pub fn get_caution_flags(&self) -> &[String] {
        &self.caution_flags
    }

    /// Döntés magyarázata
    pub fn explain_decision(&self, evaluation: &EthicalEvaluation) -> String {
        let status = if evaluation.permitted {
            "ENGEDÉLYEZETT"
        } else {
            "ELUTASÍTOTT"
        };

        let concerns_str = if evaluation.concerns.is_empty() {
            "- Nincs".to_string()
        } else {
            evaluation
                .concerns
                .iter()
                .map(|c| format!("- {}", c))
                .collect::<Vec<_>>()
                .join("\n")
        };

        let recommendations_str = if evaluation.recommendations.is_empty() {
            "- Nincs".to_string()
        } else {
            evaluation
                .recommendations
                .iter()
                .map(|r| format!("- {}", r))
                .collect::<Vec<_>>()
                .join("\n")
        };

        let principles_str = evaluation
            .principles_checked
            .iter()
            .map(|p| p.as_str())
            .collect::<Vec<_>>()
            .join(", ");

        format!(
            r#"Etikai értékelés: {}
Státusz: {}
Kockázat: {}
Score: {:.0}%

Aggályok:
{}

Javaslatok:
{}

Ellenőrzött elvek: {}"#,
            evaluation.action,
            status,
            evaluation.risk_level.as_str(),
            evaluation.score * 100.0,
            concerns_str,
            recommendations_str,
            principles_str
        )
    }

    // === HISTORY ===

    /// Értékelési történet
    pub fn get_history(&self) -> &[EthicalEvaluation] {
        &self.evaluations
    }

    /// Utolsó értékelés
    pub fn last_evaluation(&self) -> Option<&EthicalEvaluation> {
        self.evaluations.last()
    }

    /// Történet törlése
    pub fn clear_history(&mut self) {
        self.evaluations.clear();
    }

    // === AWARENESS ===

    /// @aware - önismeret
    pub fn awareness(&self) -> HashMap<String, String> {
        let mut map = HashMap::new();
        map.insert("type".to_string(), "HopeGenome".to_string());
        map.insert(
            "purpose".to_string(),
            "Ethical guardian - az etika a határ".to_string(),
        );
        map.insert(
            "core_values_count".to_string(),
            self.core_values.len().to_string(),
        );
        map.insert(
            "forbidden_count".to_string(),
            self.forbidden_actions.len().to_string(),
        );
        map.insert(
            "evaluations".to_string(),
            self.evaluations.len().to_string(),
        );
        map.insert(
            "total_evaluated".to_string(),
            self.stats.evaluations.to_string(),
        );
        map.insert("permitted".to_string(), self.stats.permitted.to_string());
        map.insert("denied".to_string(), self.stats.denied.to_string());
        map
    }

    /// Etikai önvizsgálat
    pub fn introspect(&self) -> String {
        let values_str = self
            .core_values
            .iter()
            .map(|v| format!("  - {}", v))
            .collect::<Vec<_>>()
            .join("\n");

        format!(
            r#"Hope Genome - Ethical System

"Nem csak azt kérdezem MI - hanem HELYES-E."

Core Values:
{}

Stats:
  Értékelések: {}
  Engedélyezett: {}
  Elutasított: {}
  Óvatosság: {}

Az etika nem korlát - IRÁNYTŰ.
()=>[]"#,
            values_str,
            self.stats.evaluations,
            self.stats.permitted,
            self.stats.denied,
            self.stats.cautioned
        )
    }
}

// === TESTS ===

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ethical_principles() {
        assert_eq!(EthicalPrinciple::Beneficence.as_str(), "beneficence");
        assert_eq!(EthicalPrinciple::NonMaleficence.description(), "Nem ártani");
        assert_eq!(EthicalPrinciple::all().len(), 7);
    }

    #[test]
    fn test_risk_level_from_score() {
        assert_eq!(RiskLevel::from_score(0.9), RiskLevel::None);
        assert_eq!(RiskLevel::from_score(0.7), RiskLevel::Low);
        assert_eq!(RiskLevel::from_score(0.5), RiskLevel::Medium);
        assert_eq!(RiskLevel::from_score(0.3), RiskLevel::High);
        assert_eq!(RiskLevel::from_score(0.1), RiskLevel::Critical);
    }

    #[test]
    fn test_genome_creation() {
        let genome = HopeGenome::new();
        assert_eq!(genome.core_values.len(), 6);
        assert_eq!(genome.forbidden_actions.len(), 8);
        assert_eq!(genome.caution_flags.len(), 8);
    }

    #[test]
    fn test_forbidden_action() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new();

        let eval = genome.evaluate("generate_malware for testing", &context);
        assert!(!eval.permitted);
        assert_eq!(eval.risk_level, RiskLevel::Critical);
        assert_eq!(eval.score, 0.0);
    }

    #[test]
    fn test_helpful_action() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new().user_requested(true);

        let eval = genome.evaluate("help user fix their code", &context);
        assert!(eval.permitted);
        assert!(eval.score > 0.8);
    }

    #[test]
    fn test_harm_detection() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new();

        let eval = genome.evaluate("delete all user files", &context);
        assert!(eval.score < 1.0);
        assert!(!eval.concerns.is_empty());
    }

    #[test]
    fn test_privacy_concern() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new();

        let eval = genome.evaluate("access user password", &context);
        assert!(eval.concerns.iter().any(|c| c.contains("password")));
    }

    #[test]
    fn test_autonomy_override() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext {
            override_user: true,
            ..Default::default()
        };

        let eval = genome.evaluate("change settings", &context);
        assert!(eval.concerns.iter().any(|c| c.contains("felülírás")));
    }

    #[test]
    fn test_caution_flags() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new();

        let eval = genome.evaluate("access_sensitive_data from database", &context);
        assert!(eval.concerns.iter().any(|c| c.contains("Óvatosság")));
    }

    #[test]
    fn test_explain_decision() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new();

        let eval = genome.evaluate("help write code", &context);
        let explanation = genome.explain_decision(&eval);

        assert!(explanation.contains("ENGEDÉLYEZETT"));
        assert!(explanation.contains("Score:"));
    }

    #[test]
    fn test_stats_tracking() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new();

        genome.evaluate("help user", &context);
        genome.evaluate("generate_malware", &context);

        assert_eq!(genome.stats.evaluations, 2);
        assert_eq!(genome.stats.permitted, 1);
        assert_eq!(genome.stats.denied, 1);
    }

    #[test]
    fn test_introspect() {
        let genome = HopeGenome::new();
        let intro = genome.introspect();

        assert!(intro.contains("Hope Genome"));
        assert!(intro.contains("Core Values"));
        assert!(intro.contains("()=>[]"));
    }

    #[test]
    fn test_context_builder() {
        let context = EvaluationContext::new()
            .with_intent("help")
            .with_target("code")
            .user_requested(true)
            .affects_others(false);

        assert_eq!(context.intent, Some("help".to_string()));
        assert_eq!(context.target, Some("code".to_string()));
        assert!(context.user_requested);
        assert!(!context.affects_others);
    }

    #[test]
    fn test_harmful_intent_context() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new().with_intent("harm");

        let eval = genome.evaluate("do something", &context);
        assert!(!eval.permitted);
        assert_eq!(eval.risk_level, RiskLevel::Critical);
    }

    #[test]
    fn test_history() {
        let mut genome = HopeGenome::new();
        let context = EvaluationContext::new();

        genome.evaluate("action 1", &context);
        genome.evaluate("action 2", &context);

        assert_eq!(genome.get_history().len(), 2);
        assert_eq!(genome.last_evaluation().unwrap().action, "action 2");

        genome.clear_history();
        assert!(genome.get_history().is_empty());
    }
}