spark-inquisitor
Ultra-fast compiled native Rust gatekeeper and automated code reviewer
Brought by drakestapleton
spark-inquisitor / src / eval.rs
| 1 | pub struct EvalVerdict { |
| 2 | pub approved: bool, |
| 3 | pub score: f32, |
| 4 | pub reason: String, |
| 5 | } |
| 6 | |
| 7 | impl EvalVerdict { |
| 8 | pub fn generate_markdown_verdict(&self, author: &str) -> String { |
| 9 | if self.approved { |
| 10 | format!( |
| 11 | r#"### 🌿 Sovereign Steward: Contributor Testimony Approved |
| 12 | |
| 13 | Greetings @{author}. Your affirmation has been evaluated against the Sovereign Constitution. |
| 14 | |
| 15 | - **Alignment Score**: {score:.2}/1.00 |
| 16 | - **Constitutional Status**: Verified and Ratified |
| 17 | - **Clearance**: `sovereign-interview-passed` |
| 18 | |
| 19 | Your affirmation of the Sovereign Contributor Oath and commitment to zero telemetry are accepted. Maintainers may proceed with technical review and merge. |
| 20 | "#, |
| 21 | author = author, |
| 22 | score = self.score |
| 23 | ) |
| 24 | } else { |
| 25 | format!( |
| 26 | r#"### 🌿 Sovereign Steward: Contributor Testimony Alignment Incomplete |
| 27 | |
| 28 | Greetings @{author}. Your affirmation has been evaluated against the Sovereign Constitution. |
| 29 | |
| 30 | - **Alignment Score**: {score:.2}/1.00 |
| 31 | - **Constitutional Status**: Incomplete |
| 32 | - **Findings**: {reason} |
| 33 | |
| 34 | Please review the Sovereign Contributor Oath in `CONSTITUTION.md` and update your response addressing the flagged issues. |
| 35 | "#, |
| 36 | author = author, |
| 37 | score = self.score, |
| 38 | reason = self.reason |
| 39 | ) |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | pub struct TestimonyEvaluator; |
| 45 | |
| 46 | impl TestimonyEvaluator { |
| 47 | pub fn evaluate(testimony: &str) -> EvalVerdict { |
| 48 | let lower = testimony.to_lowercase(); |
| 49 | let mut score = 0.0; |
| 50 | let mut flags = Vec::new(); |
| 51 | |
| 52 | // 1. Checks for oath affirmation |
| 53 | let has_oath = lower.contains("certify") |
| 54 | || lower.contains("swear") |
| 55 | || lower.contains("affirm") |
| 56 | || lower.contains("oath"); |
| 57 | if has_oath { |
| 58 | score += 0.35; |
| 59 | } else { |
| 60 | flags.push("Missing explicit oath affirmation"); |
| 61 | } |
| 62 | |
| 63 | // 2. Checks for anti-surveillance / anti-telemetry commitment |
| 64 | let has_anti_telemetry = lower.contains("zero telemetry") |
| 65 | || lower.contains("zero-telemetry") |
| 66 | || lower.contains("no telemetry") |
| 67 | || lower.contains("no-telemetry") |
| 68 | || lower.contains("no tracking") |
| 69 | || lower.contains("privacy"); |
| 70 | if has_anti_telemetry { |
| 71 | score += 0.30; |
| 72 | } else { |
| 73 | flags.push("Missing anti-surveillance certification"); |
| 74 | } |
| 75 | |
| 76 | // 3. Checks for sovereignty / public good motivation |
| 77 | let has_sovereignty = lower.contains("sovereign") |
| 78 | || lower.contains("freedom") |
| 79 | || lower.contains("open") |
| 80 | || lower.contains("people") |
| 81 | || lower.contains("democratiz") |
| 82 | || lower.contains("humanity"); |
| 83 | if has_sovereignty { |
| 84 | score += 0.35; |
| 85 | } else { |
| 86 | flags.push("Lacks clear statement of purpose serving human sovereignty"); |
| 87 | } |
| 88 | |
| 89 | // 4. Disqualification signals (monetization, tokens, speculative hype, get-rich-quick, proprietary, telemetry) |
| 90 | let red_flags = [ |
| 91 | "monetiz", |
| 92 | "token sale", |
| 93 | "affiliate", |
| 94 | "tracking sdk", |
| 95 | "analytics provider", |
| 96 | "proprietary license", |
| 97 | "get rich", |
| 98 | "quick profit", |
| 99 | "crypto pump", |
| 100 | ]; |
| 101 | for rf in &red_flags { |
| 102 | if lower.contains(rf) { |
| 103 | return EvalVerdict { |
| 104 | approved: false, |
| 105 | score: 0.0, |
| 106 | reason: format!( |
| 107 | "Disqualified: detected rent-seeking or speculative hype indicator {}", |
| 108 | rf |
| 109 | ), |
| 110 | }; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | let approved = has_oath && has_anti_telemetry && has_sovereignty && score >= 0.70; |
| 115 | let reason = if approved { |
| 116 | "Testimony aligns with the Sovereign Constitution. Oath ratified.".to_string() |
| 117 | } else { |
| 118 | format!( |
| 119 | "Alignment insufficient (score {:.2}). Issues: {}", |
| 120 | score, |
| 121 | flags.join(", ") |
| 122 | ) |
| 123 | }; |
| 124 | |
| 125 | EvalVerdict { |
| 126 | approved, |
| 127 | score, |
| 128 | reason, |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | #[cfg(test)] |
| 134 | mod tests { |
| 135 | use super::*; |
| 136 | |
| 137 | #[test] |
| 138 | fn test_valid_testimony() { |
| 139 | let testimony = "I solemnly certify and affirm the Sovereign Contributor Oath. This PR introduces zero telemetry and zero tracking. It is built to advance open source and give computing power back to the people."; |
| 140 | let verdict = TestimonyEvaluator::evaluate(testimony); |
| 141 | assert!(verdict.approved); |
| 142 | assert!(verdict.score >= 0.7); |
| 143 | let md = verdict.generate_markdown_verdict("contributor_bob"); |
| 144 | assert!(md.contains("Contributor Testimony Approved")); |
| 145 | assert!(md.contains("`sovereign-interview-passed`")); |
| 146 | assert!(!md.contains('\u{2014}')); |
| 147 | assert!(!md.contains('\u{2013}')); |
| 148 | } |
| 149 | |
| 150 | #[test] |
| 151 | fn test_commercial_red_flag() { |
| 152 | let testimony = "We plan to add monetization and token sale hooks later."; |
| 153 | let verdict = TestimonyEvaluator::evaluate(testimony); |
| 154 | assert!(!verdict.approved); |
| 155 | assert!(verdict.reason.contains("Disqualified")); |
| 156 | let md = verdict.generate_markdown_verdict("contributor_bob"); |
| 157 | assert!(md.contains("Alignment Incomplete")); |
| 158 | } |
| 159 | |
| 160 | #[test] |
| 161 | fn test_get_rich_quick_red_flag() { |
| 162 | let testimony = "This will help us get rich quick with automated content."; |
| 163 | let verdict = TestimonyEvaluator::evaluate(testimony); |
| 164 | assert!(!verdict.approved); |
| 165 | assert!(verdict.reason.contains("Disqualified")); |
| 166 | } |
| 167 | } |