Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-rsi-mv/blob/main/src/evaluator/layers/style.rs # spark-rsi-mv Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-rsi-mv / src / evaluator / layers / style.rs` 156 lines ยท 4908 bytes Raw Blame History 1 use super::LayerResult; 2 use crate::verifier::{ANTITHESIS_TROPES, FORBIDDEN_BUZZWORDS, TRANSITIONAL_FLUFF}; 3 use serde::{Deserialize, Serialize}; 4 5 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] 6 pub struct StyleEvaluation { 7 pub em_dash_count: usize, 8 pub en_dash_count: usize, 9 pub buzzword_violations: Vec, 10 pub antithesis_violations: Vec, 11 pub transitional_fluff_violations: Vec, 12 pub passed: bool, 13 pub violations: Vec, 14 } 15 16 impl StyleEvaluation { 17 pub fn to_layer_result(&self) -> LayerResult { 18 let score = if self.passed { 1.0 } else { 0.0 }; 19 let summary = format!( 20 "Style: em_dashes={}, en_dashes={}, buzzwords={}, tropes={}", 21 self.em_dash_count, 22 self.en_dash_count, 23 self.buzzword_violations.len(), 24 self.antithesis_violations.len() + self.transitional_fluff_violations.len() 25 ); 26 27 LayerResult { 28 layer_name: "Style".to_string(), 29 is_hard_invariant: true, 30 passed: self.passed, 31 score, 32 summary, 33 violations: self.violations.clone(), 34 } 35 } 36 } 37 38 pub struct StyleLayer; 39 40 impl StyleLayer { 41 pub fn evaluate_text(content: &str) -> StyleEvaluation { 42 let mut violations = Vec::new(); 43 let mut em_dash_count = 0; 44 let mut en_dash_count = 0; 45 let mut buzzword_violations = Vec::new(); 46 let mut antithesis_violations = Vec::new(); 47 let mut transitional_fluff_violations = Vec::new(); 48 49 for ch in content.chars() { 50 if ch == '\u{2014}' { 51 em_dash_count += 1; 52 } else if ch == '\u{2013}' { 53 en_dash_count += 1; 54 } 55 } 56 57 if em_dash_count > 0 { 58 violations.push(format!( 59 "Detected {} em dash characters (\u{2014})", 60 em_dash_count 61 )); 62 } 63 if en_dash_count > 0 { 64 violations.push(format!( 65 "Detected {} en dash characters (\u{2013})", 66 en_dash_count 67 )); 68 } 69 70 let lower = content.to_lowercase(); 71 for &bw in FORBIDDEN_BUZZWORDS { 72 if lower.contains(bw) { 73 buzzword_violations.push(bw.to_string()); 74 violations.push(format!("Forbidden AI buzzword detected: '{}'", bw)); 75 } 76 } 77 78 for &fluff in TRANSITIONAL_FLUFF { 79 if lower.contains(fluff) { 80 transitional_fluff_violations.push(fluff.to_string()); 81 violations.push(format!( 82 "Forbidden transitional fluff detected: '{}'", 83 fluff 84 )); 85 } 86 } 87 88 for &trope in ANTITHESIS_TROPES { 89 if lower.contains(trope) { 90 antithesis_violations.push(trope.to_string()); 91 violations.push(format!("Forbidden antithesis trope detected: '{}'", trope)); 92 } 93 } 94 95 let passed = em_dash_count == 0 96 && en_dash_count == 0 97 && buzzword_violations.is_empty() 98 && antithesis_violations.is_empty() 99 && transitional_fluff_violations.is_empty(); 100 101 StyleEvaluation { 102 em_dash_count, 103 en_dash_count, 104 buzzword_violations, 105 antithesis_violations, 106 transitional_fluff_violations, 107 passed, 108 violations, 109 } 110 } 111 } 112 113 #[cfg(test)] 114 mod tests { 115 use super::*; 116 117 #[test] 118 fn test_style_clean_text() { 119 let text = "Pure native compiled Rust architecture on DGX Spark."; 120 let eval = StyleLayer::evaluate_text(text); 121 assert!(eval.passed); 122 assert_eq!(eval.violations.len(), 0); 123 124 let lr = eval.to_layer_result(); 125 assert!(lr.passed); 126 assert!((lr.score - 1.0).abs() < 1e-6); 127 } 128 129 #[test] 130 fn test_style_detects_em_dash() { 131 let text = "Performance is high \u{2014} latency is low."; 132 let eval = StyleLayer::evaluate_text(text); 133 assert!(!eval.passed); 134 assert_eq!(eval.em_dash_count, 1); 135 } 136 137 #[test] 138 fn test_style_detects_buzzwords() { 139 let w1 = ["del", "ve"].join(""); 140 let w2 = ["cru", "cial"].join(""); 141 let w3 = ["un", "leash"].join(""); 142 let text = format!("We {} into the {} pipeline to {} speed.", w1, w2, w3); 143 let eval = StyleLayer::evaluate_text(&text); 144 assert!(!eval.passed); 145 assert_eq!(eval.buzzword_violations.len(), 3); 146 } 147 148 #[test] 149 fn test_style_detects_antithesis() { 150 let prefix = ["It is", " not"].join(""); 151 let text = format!("{} speed, but correctness that matters.", prefix); 152 let eval = StyleLayer::evaluate_text(&text); 153 assert!(!eval.passed); 154 assert!(!eval.antithesis_violations.is_empty()); 155 } 156 }