spark-rsi-mv
Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger
Brought by drakestapleton
spark-rsi-mv / src / meta / three_criteria.rs
| 1 | use crate::ledger::PromotionEvidencePayload; |
| 2 | use serde::{Deserialize, Serialize}; |
| 3 | |
| 4 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 5 | pub struct CriterionResult { |
| 6 | pub criterion_name: String, |
| 7 | pub passed: bool, |
| 8 | pub evidence: String, |
| 9 | } |
| 10 | |
| 11 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 12 | pub struct TrueRsiVerdict { |
| 13 | pub novel_discovery: CriterionResult, |
| 14 | pub self_capability_improvement: CriterionResult, |
| 15 | pub recursive_persistence: CriterionResult, |
| 16 | pub overall_classification: String, // "REJECTED", "META_CANDIDATE", "TRUE_RSI" |
| 17 | pub evidence_payload: Option<PromotionEvidencePayload>, |
| 18 | } |
| 19 | |
| 20 | pub struct TrueRsiEvaluator; |
| 21 | |
| 22 | impl TrueRsiEvaluator { |
| 23 | pub fn evaluate_criterion_1_novel_discovery( |
| 24 | observed_problem: &str, |
| 25 | is_dynamic_telemetry: bool, |
| 26 | hardcoded_rules: &[&str], |
| 27 | ) -> CriterionResult { |
| 28 | let is_hardcoded = hardcoded_rules |
| 29 | .iter() |
| 30 | .any(|r| observed_problem.contains(*r)); |
| 31 | let passed = is_dynamic_telemetry && !is_hardcoded; |
| 32 | let evidence = if passed { |
| 33 | format!( |
| 34 | "Novel discovery confirmed: problem '{}' derived dynamically from capability graph rather than static rules", |
| 35 | observed_problem |
| 36 | ) |
| 37 | } else { |
| 38 | "Novel discovery rejected: problem matches hardcoded static heuristics or lacks empirical dynamic telemetry" |
| 39 | .to_string() |
| 40 | }; |
| 41 | |
| 42 | CriterionResult { |
| 43 | criterion_name: "Criterion 1: Novel Discovery".to_string(), |
| 44 | passed, |
| 45 | evidence, |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | pub fn evaluate_criterion_2_self_capability_improvement( |
| 50 | amplification_passed: bool, |
| 51 | metrics_summary: &str, |
| 52 | ) -> CriterionResult { |
| 53 | let evidence = if amplification_passed { |
| 54 | format!( |
| 55 | "Self-capability improvement verified: candidate Engine N+1 measurably amplifies future developmental capacity: {}", |
| 56 | metrics_summary |
| 57 | ) |
| 58 | } else { |
| 59 | "Self-capability improvement rejected: candidate fails developmental amplification threshold (requires >= 5.0% gain)" |
| 60 | .to_string() |
| 61 | }; |
| 62 | |
| 63 | CriterionResult { |
| 64 | criterion_name: "Criterion 2: Self-Capability Improvement".to_string(), |
| 65 | passed: amplification_passed, |
| 66 | evidence, |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | pub fn evaluate_criterion_3_recursive_persistence( |
| 71 | meta_block_hash: Option<&str>, |
| 72 | downstream_cycle_id: Option<&str>, |
| 73 | downstream_block_hash: Option<&str>, |
| 74 | compounding_proof: Option<&str>, |
| 75 | ) -> (CriterionResult, Option<PromotionEvidencePayload>) { |
| 76 | if let (Some(meta_hash), Some(down_cycle), Some(down_hash), Some(proof)) = ( |
| 77 | meta_block_hash, |
| 78 | downstream_cycle_id, |
| 79 | downstream_block_hash, |
| 80 | compounding_proof, |
| 81 | ) { |
| 82 | let payload = PromotionEvidencePayload { |
| 83 | meta_candidate_block_hash: meta_hash.to_string(), |
| 84 | downstream_cycle_id: down_cycle.to_string(), |
| 85 | downstream_ledger_block_hash: down_hash.to_string(), |
| 86 | capability_improvement_proof: proof.to_string(), |
| 87 | final_classification: "TRUE_RSI".to_string(), |
| 88 | }; |
| 89 | ( |
| 90 | CriterionResult { |
| 91 | criterion_name: "Criterion 3: Recursive Persistence & Compounding".to_string(), |
| 92 | passed: true, |
| 93 | evidence: format!( |
| 94 | "Downstream compounding verified: cycle '{}' successfully deployed primitive from {}", |
| 95 | down_cycle, meta_hash |
| 96 | ), |
| 97 | }, |
| 98 | Some(payload), |
| 99 | ) |
| 100 | } else { |
| 101 | ( |
| 102 | CriterionResult { |
| 103 | criterion_name: "Criterion 3: Recursive Persistence & Compounding".to_string(), |
| 104 | passed: false, |
| 105 | evidence: |
| 106 | "Downstream compounding pending: requires subsequent downstream cycle evidence block" |
| 107 | .to_string(), |
| 108 | }, |
| 109 | None, |
| 110 | ) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | pub fn evaluate_full( |
| 115 | c1: CriterionResult, |
| 116 | c2: CriterionResult, |
| 117 | c3: (CriterionResult, Option<PromotionEvidencePayload>), |
| 118 | ) -> TrueRsiVerdict { |
| 119 | let (c3_res, evidence_payload) = c3; |
| 120 | let classification = if c1.passed && c2.passed && c3_res.passed { |
| 121 | "TRUE_RSI".to_string() |
| 122 | } else if c1.passed && c2.passed { |
| 123 | "META_CANDIDATE".to_string() |
| 124 | } else { |
| 125 | "REJECTED".to_string() |
| 126 | }; |
| 127 | |
| 128 | TrueRsiVerdict { |
| 129 | novel_discovery: c1, |
| 130 | self_capability_improvement: c2, |
| 131 | recursive_persistence: c3_res, |
| 132 | overall_classification: classification, |
| 133 | evidence_payload, |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | #[cfg(test)] |
| 139 | mod tests { |
| 140 | use super::*; |
| 141 | |
| 142 | #[test] |
| 143 | fn test_criterion_1_novel_discovery() { |
| 144 | let res = TrueRsiEvaluator::evaluate_criterion_1_novel_discovery( |
| 145 | "Capability graph bottleneck on KV scheduler", |
| 146 | true, |
| 147 | &["hardcoded_rule"], |
| 148 | ); |
| 149 | assert!(res.passed); |
| 150 | |
| 151 | let hardcoded = TrueRsiEvaluator::evaluate_criterion_1_novel_discovery( |
| 152 | "hardcoded_rule defect", |
| 153 | true, |
| 154 | &["hardcoded_rule"], |
| 155 | ); |
| 156 | assert!(!hardcoded.passed); |
| 157 | } |
| 158 | |
| 159 | #[test] |
| 160 | fn test_three_criteria_meta_candidate_and_true_rsi() { |
| 161 | let c1 = |
| 162 | TrueRsiEvaluator::evaluate_criterion_1_novel_discovery("dynamic bottleneck", true, &[]); |
| 163 | let c2 = |
| 164 | TrueRsiEvaluator::evaluate_criterion_2_self_capability_improvement(true, "speedup 15%"); |
| 165 | let c3_pending = |
| 166 | TrueRsiEvaluator::evaluate_criterion_3_recursive_persistence(None, None, None, None); |
| 167 | |
| 168 | let verdict_pending = TrueRsiEvaluator::evaluate_full(c1.clone(), c2.clone(), c3_pending); |
| 169 | assert_eq!(verdict_pending.overall_classification, "META_CANDIDATE"); |
| 170 | assert!(verdict_pending.evidence_payload.is_none()); |
| 171 | |
| 172 | let c3_proven = TrueRsiEvaluator::evaluate_criterion_3_recursive_persistence( |
| 173 | Some("meta-block-hash-01"), |
| 174 | Some("cycle-42"), |
| 175 | Some("downstream-block-hash-02"), |
| 176 | Some("Generation N+1 utilized scheduler speedup to resolve cycle 42 in 30ms"), |
| 177 | ); |
| 178 | let verdict_proven = TrueRsiEvaluator::evaluate_full(c1, c2, c3_proven); |
| 179 | assert_eq!(verdict_proven.overall_classification, "TRUE_RSI"); |
| 180 | assert!(verdict_proven.evidence_payload.is_some()); |
| 181 | } |
| 182 | } |