clm-kernel 0.0.9

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
//! CLM Layer 5: Type Lattice Stratification & Universe Coordinate Verification (U0-U5).
//! Canonical Path: kernel/clm_rust_core/src/layer5/type_lattice.rs
//!
//! Formalizes the 6-tier Universe level hierarchy of the CLM ontological stack:
//! - U0: Static Content-Addressable Storage (MCard CAS)
//! - U1: Linear Dynamic Transitions & State Machines (PCard / CPN-VM)
//! - U2: Cryptographic Identity, Hoare Sandwiches & Receipts (VCard)
//! - U3: Distributed Reticulum Mesh, Satori Speech Acts & Cordis Fibers
//! - U4: Omnichannel Human-Machine Interaction Surface & Chat Presentation
//! - U5: Meta-Circular Reflection & Continuous Learning Stratum (Loop Γ)

use serde::{Deserialize, Serialize};

/// The six canonical universe levels of the CLM Type Lattice.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[repr(u8)]
pub enum UniverseLevel {
    /// U0: Static CAS Data (MCard)
    U0Mcard = 0,
    /// U1: Linear Transitions / CPN Net (PCard)
    U1Pcard = 1,
    /// U2: Verified Identity / Proofs & Receipts (VCard)
    U2Vcard = 2,
    /// U3: Distributed Mesh & Fibers (Satori / Reticulum)
    U3Satori = 3,
    /// U4: Omnichannel Membrane (Human Interaction Surface)
    U4Membrane = 4,
    /// U5: Meta-Circular Learning Stratum (Loop Γ)
    U5MetaGamma = 5,
}

impl UniverseLevel {
    pub fn from_u8(val: u8) -> Result<Self, String> {
        match val {
            0 => Ok(Self::U0Mcard),
            1 => Ok(Self::U1Pcard),
            2 => Ok(Self::U2Vcard),
            3 => Ok(Self::U3Satori),
            4 => Ok(Self::U4Membrane),
            5 => Ok(Self::U5MetaGamma),
            other => Err(format!("Invalid universe level: {other} (expected 0..=5)")),
        }
    }

    pub fn as_u8(&self) -> u8 {
        *self as u8
    }

    pub fn identifier(&self) -> &'static str {
        match self {
            Self::U0Mcard => "U0",
            Self::U1Pcard => "U1",
            Self::U2Vcard => "U2",
            Self::U3Satori => "U3",
            Self::U4Membrane => "U4",
            Self::U5MetaGamma => "U5",
        }
    }

    pub fn stratum_name(&self) -> &'static str {
        match self {
            Self::U0Mcard => "mcard_cas",
            Self::U1Pcard => "pcard_net",
            Self::U2Vcard => "vcard_proof",
            Self::U3Satori => "satori_fiber",
            Self::U4Membrane => "membrane_ui",
            Self::U5MetaGamma => "meta_gamma",
        }
    }
}

/// A verified coordinate in the stratified CLM type lattice.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct LatticeCoordinate {
    pub level: u8,
    pub identifier: String,
    pub stratum_name: String,
    pub description: String,
}

/// Coordinates across all six universe levels U0..=U5 for isomorphism checks.
pub fn get_universe_coordinates() -> Vec<LatticeCoordinate> {
    vec![
        LatticeCoordinate {
            level: 0,
            identifier: "U0".to_string(),
            stratum_name: "mcard_cas".to_string(),
            description: "Static Content-Addressable Storage (MCard)".to_string(),
        },
        LatticeCoordinate {
            level: 1,
            identifier: "U1".to_string(),
            stratum_name: "pcard_net".to_string(),
            description: "Linear Transitions & Colored Petri Net (PCard)".to_string(),
        },
        LatticeCoordinate {
            level: 2,
            identifier: "U2".to_string(),
            stratum_name: "vcard_proof".to_string(),
            description: "Cryptographic Verification & Hoare Receipts (VCard)".to_string(),
        },
        LatticeCoordinate {
            level: 3,
            identifier: "U3".to_string(),
            stratum_name: "satori_fiber".to_string(),
            description: "Distributed Reticulum Mesh & Satori Speech Acts".to_string(),
        },
        LatticeCoordinate {
            level: 4,
            identifier: "U4".to_string(),
            stratum_name: "membrane_ui".to_string(),
            description: "Omnichannel Interaction Surface & Generative Hypermedia".to_string(),
        },
        LatticeCoordinate {
            level: 5,
            identifier: "U5".to_string(),
            stratum_name: "meta_gamma".to_string(),
            description: "Meta-Circular Continuous Learning Stratum (Loop Γ)".to_string(),
        },
    ]
}

/// Verify stratified information ordering: sub-types can only embed into equal or higher universe levels.
pub fn is_stratified(inner_level: u8, outer_level: u8) -> bool {
    inner_level <= outer_level
}

/// Validate that a given level value is valid and within bounds [0, 5].
pub fn validate_universe_level(level: u8) -> Result<UniverseLevel, String> {
    UniverseLevel::from_u8(level)
}