use serde::{Deserialize, Serialize};
use std::sync::LazyLock;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ConsciousnessThresholds {
pub fl_veto: f32,
pub fl_dampen: f32,
pub fl_boost: f32,
pub fl_dampen_factor: f32,
pub fl_boost_factor: f32,
pub consciousness_gate_basic: f64,
pub consciousness_gate_proposal: f64,
pub consciousness_gate_voting: f64,
pub consciousness_gate_constitutional: f64,
pub consciousness_gate_pledge: f64,
pub consciousness_gate_matching: f64,
pub consciousness_gate_impact: f64,
pub bootstrap_community_threshold: u32,
pub bootstrap_ttl_us: u64,
pub bootstrap_min_identity: f64,
}
impl Default for ConsciousnessThresholds {
fn default() -> Self {
Self {
fl_veto: 0.1,
fl_dampen: 0.3,
fl_boost: 0.6,
fl_dampen_factor: 0.3,
fl_boost_factor: 1.5,
consciousness_gate_basic: 0.2,
consciousness_gate_proposal: 0.3,
consciousness_gate_voting: 0.4,
consciousness_gate_constitutional: 0.6,
consciousness_gate_pledge: 0.2,
consciousness_gate_matching: 0.3,
consciousness_gate_impact: 0.2,
bootstrap_community_threshold: BOOTSTRAP_COMMUNITY_THRESHOLD,
bootstrap_ttl_us: BOOTSTRAP_TTL_US,
bootstrap_min_identity: BOOTSTRAP_MIN_IDENTITY,
}
}
}
pub const BOOTSTRAP_COMMUNITY_THRESHOLD: u32 = 5;
pub const BOOTSTRAP_TTL_US: u64 = 900_000_000;
pub const BOOTSTRAP_MIN_IDENTITY: f64 = 0.25;
pub type PhiThresholds = ConsciousnessThresholds;
static CONSCIOUSNESS_THRESHOLDS: LazyLock<ConsciousnessThresholds> =
LazyLock::new(ConsciousnessThresholds::default);
pub fn consciousness_thresholds() -> &'static ConsciousnessThresholds {
&CONSCIOUSNESS_THRESHOLDS
}
pub fn phi_thresholds() -> &'static ConsciousnessThresholds {
consciousness_thresholds()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_thresholds_are_consistent() {
let t = ConsciousnessThresholds::default();
assert!(t.fl_veto < t.fl_dampen);
assert!(t.fl_dampen < t.fl_boost);
assert!(t.consciousness_gate_basic < t.consciousness_gate_proposal);
assert!(t.consciousness_gate_proposal < t.consciousness_gate_voting);
assert!(t.consciousness_gate_voting < t.consciousness_gate_constitutional);
}
#[test]
fn consciousness_thresholds_returns_defaults() {
let t = consciousness_thresholds();
assert_eq!(t.fl_veto, 0.1);
assert_eq!(t.fl_dampen, 0.3);
assert_eq!(t.fl_boost, 0.6);
assert_eq!(t.fl_dampen_factor, 0.3);
assert_eq!(t.fl_boost_factor, 1.5);
assert_eq!(t.consciousness_gate_basic, 0.2);
assert_eq!(t.consciousness_gate_proposal, 0.3);
assert_eq!(t.consciousness_gate_voting, 0.4);
assert_eq!(t.consciousness_gate_constitutional, 0.6);
}
#[test]
fn allocation_thresholds_defaults() {
let t = consciousness_thresholds();
assert_eq!(t.consciousness_gate_pledge, 0.2);
assert_eq!(t.consciousness_gate_matching, 0.3);
assert_eq!(t.consciousness_gate_impact, 0.2);
}
#[test]
fn allocation_thresholds_consistent_with_governance() {
let t = ConsciousnessThresholds::default();
assert_eq!(t.consciousness_gate_pledge, t.consciousness_gate_basic);
assert_eq!(t.consciousness_gate_matching, t.consciousness_gate_proposal);
assert_eq!(t.consciousness_gate_impact, t.consciousness_gate_basic);
}
#[test]
fn bootstrap_thresholds_defaults() {
let t = ConsciousnessThresholds::default();
assert_eq!(t.bootstrap_community_threshold, 5);
assert_eq!(t.bootstrap_ttl_us, 900_000_000); assert_eq!(t.bootstrap_min_identity, 0.25);
}
#[test]
fn backward_compat_alias_works() {
let t = phi_thresholds();
assert_eq!(t.fl_veto, 0.1);
}
#[test]
fn serde_roundtrip() {
let t = ConsciousnessThresholds::default();
let json = serde_json::to_string(&t).unwrap();
let t2: ConsciousnessThresholds = serde_json::from_str(&json).unwrap();
assert_eq!(t, t2);
}
}