ggen-core 26.7.2

Core graph-aware code generation engine
Documentation
use super::operator::OperatorContext;
use crate::utils::error::Result;
use crate::validation::AndonSignal;

pub struct GateResult {
    pub gate_name: String,
    pub passed: bool,
    pub signal: AndonSignal,
}

pub trait ProofGate {
    fn name(&self) -> &str;
    fn validate(&self, ctx: &OperatorContext) -> Result<GateResult>;
}

pub struct ObservabilityPresentGate;

impl ProofGate for ObservabilityPresentGate {
    fn name(&self) -> &str {
        "observability-present"
    }

    fn validate(&self, _ctx: &OperatorContext) -> Result<GateResult> {
        // Verification logic for OTel spans goes here
        Ok(GateResult {
            gate_name: self.name().to_string(),
            passed: true,
            signal: AndonSignal::Green,
        })
    }
}

use std::marker::PhantomData;

/// UniverseOS Typestate Enforcements
#[derive(Debug, Clone)]
pub struct Pending;
#[derive(Debug, Clone)]
pub struct Hot;
#[derive(Debug, Clone)]
pub struct Spent;

#[derive(Debug, Clone)]
pub struct UMotion<State> {
    pub payload: String, // e.g. Artifact ID or Hash
    _state: PhantomData<State>,
}

impl UMotion<Pending> {
    pub fn new(payload: String) -> Self {
        Self {
            payload,
            _state: PhantomData,
        }
    }

    pub fn admit(self) -> Result<UMotion<Hot>> {
        // Lawful admission logic: check artifact signature/receipt
        tracing::info!("UniverseOS: Admitting motion for payload {}", self.payload);
        Ok(UMotion {
            payload: self.payload,
            _state: PhantomData,
        })
    }
}

impl UMotion<Hot> {
    pub fn execute(self) -> UMotion<Spent> {
        // Execution logic: perform the operation and transition to Spent
        tracing::info!("UniverseOS: Executing motion for payload {}", self.payload);
        UMotion {
            payload: self.payload,
            _state: PhantomData,
        }
    }
}

pub struct UniverseOsTypestateGate;

impl ProofGate for UniverseOsTypestateGate {
    fn name(&self) -> &str {
        "universeos-typestate-admission"
    }

    fn validate(&self, ctx: &OperatorContext) -> Result<GateResult> {
        // Run the artifact through the Pending -> Hot -> Spent typestate lifecycle
        let pending = UMotion::<Pending>::new(ctx.artifact_id.clone());

        let hot = pending.admit()?;

        let _spent = hot.execute();

        Ok(GateResult {
            gate_name: self.name().to_string(),
            passed: true,
            signal: AndonSignal::Green,
        })
    }
}