clm-kernel 0.0.17

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
use serde_json::Value;
use crate::yaml::evaluate_jq;

pub fn classify(json_ast: &Value) -> String {
    let has_abstract = evaluate_jq(
        json_ast,
        ".clm.abstract_spec.context // .abstract_spec.context",
    );
    let has_concrete = evaluate_jq(
        json_ast,
        ".clm.concrete_impl.process.type // .concrete_impl.process.type // \
         .clm.concrete_impl.process_behavior_exec.dispatcher // .concrete_impl.process_behavior_exec.dispatcher // \
         .clm.concrete_impl.runtime // .concrete_impl.runtime // \
         .clm.concrete.runtime // .concrete.runtime",
    );

    let abs_str = match has_abstract {
        Value::String(s) => s,
        Value::Null => "".to_string(),
        other => other.to_string(),
    };
    
    let conc_str = match has_concrete {
        Value::String(s) => s,
        Value::Null => "".to_string(),
        other => other.to_string(),
    };

    if !abs_str.is_empty() && !conc_str.is_empty() {
        "Function".to_string()
    } else {
        "Number".to_string()
    }
}

pub fn detect_dialect(json_ast: &Value, classification: &str) -> String {
    if classification != "Function" {
        return "UNKNOWN".to_string();
    }

    // Dialect M (Process type)
    let process_type = evaluate_jq(
        json_ast,
        ".clm.concrete_impl.process.type // .concrete_impl.process.type",
    );
    let p_type_str = match process_type {
        Value::String(s) => s,
        Value::Null => "".to_string(),
        other => other.to_string(),
    };
    if !p_type_str.is_empty() {
        return format!("M:{}", p_type_str);
    }

    // Dialect A (Dispatcher)
    let disp = evaluate_jq(
        json_ast,
        ".clm.concrete_impl.process_behavior_exec.dispatcher // .concrete_impl.process_behavior_exec.dispatcher",
    );
    let disp_str = match disp {
        Value::String(s) => s,
        Value::Null => "".to_string(),
        other => other.to_string(),
    };
    if !disp_str.is_empty() {
        return format!("A:{}", disp_str);
    }

    // Dialect B (Runtime)
    let rt = evaluate_jq(
        json_ast,
        ".clm.concrete_impl.runtime // .concrete_impl.runtime",
    );
    let rt_str = match rt {
        Value::String(s) => s,
        Value::Null => "".to_string(),
        other => other.to_string(),
    };
    if !rt_str.is_empty() {
        let op = evaluate_jq(
            json_ast,
            ".clm.concrete_impl.operation // .concrete_impl.operation",
        );
        let op_str = match op {
            Value::String(s) => s,
            Value::Null => "invoke".to_string(),
            other => other.to_string(),
        };
        return format!("B:{}:{}", rt_str, op_str);
    }

    // Dialect C (Concrete runtime)
    let crt = evaluate_jq(
        json_ast,
        ".clm.concrete.runtime // .concrete.runtime",
    );
    let crt_str = match crt {
        Value::String(s) => s,
        Value::Null => "".to_string(),
        other => other.to_string(),
    };
    if !crt_str.is_empty() {
        let cop = evaluate_jq(
            json_ast,
            ".clm.concrete.operation // .concrete.operation",
        );
        let cop_str = match cop {
            Value::String(s) => s,
            Value::Null => "invoke".to_string(),
            other => other.to_string(),
        };
        return format!("C:{}:{}", crt_str, cop_str);
    }

    "UNKNOWN".to_string()
}