clm-kernel 0.0.10

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
// evaluator/dispatch/registry_runtime.rs
// ─────────────────────────────────────────────────────────────
// L0-L2 runtime-oriented dispatch entries:
//   - File Handling & Logging (fs_utils, memorize, jsonl)
//   - CPN-VM (petri_run_net, compose_nets)
//   - Representable State Adapters (normalizer, encoder, directory, invariants)
//   - Polyglot execution
// ─────────────────────────────────────────────────────────────

use super::{InternalFn, get_clm_args};

/// Composite dispatcher for runtime-oriented modules.
pub(super) fn dispatch(module_path: &str) -> Option<InternalFn> {
    dispatch_file_memorize(module_path)
        .or_else(|| dispatch_cpn_vm(module_path))
        .or_else(|| dispatch_representable_state_adapters(module_path))
        .or_else(|| dispatch_polyglot(module_path))
}

// ── File Handling & Logging ─────────────────────────────────

fn dispatch_file_memorize(module_path: &str) -> Option<InternalFn> {
    match module_path {
        // L0 Kenotic Core — File Handling & Logging
        "clm_rust_core::fs_utils::get_file_handle" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            if args.is_empty() {
                return Err("get_file_handle requires at least 1 argument (raw_path)".to_string());
            }
            let handle = crate::fs_utils::get_file_handle(&args[0], Some(clm_root));
            Ok((0, format!("{}\n", handle)))
        }),
        "clm_rust_core::memorize::check_and_register_file_mcard" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            if args.is_empty() {
                return Err("check_and_register_file_mcard requires at least 1 argument (file_path)".to_string());
            }
            crate::memorize::check_and_register_file_mcard(&args[0], clm_root)
                .map(|_| (0, "".to_string()))
        }),
        "clm_rust_core::memorize::memorize_mcard" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            if args.is_empty() {
                return Err("memorize_mcard requires at least 1 argument (mcard_file)".to_string());
            }
            let pillar = args.get(1).map(|s| s.as_str()).unwrap_or("auto");
            crate::memorize::memorize_mcard(&args[0], pillar, clm_root)
                .map(|code| (code, "".to_string()))
        }),
        "clm_rust_core::jsonl::jsonl_emit" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            if args.is_empty() {
                return Err("jsonl_emit requires at least 1 argument (event_type)".to_string());
            }
            let kv_args = args.iter().skip(1).cloned().collect();
            crate::jsonl::jsonl_emit(&args[0], kv_args, clm_root)
                .map(|_| (0, "".to_string()))
        }),
        _ => None,
    }
}

// ── CPN-VM ──────────────────────────────────────────────────

fn dispatch_cpn_vm(module_path: &str) -> Option<InternalFn> {
    match module_path {
        // L1 Colored Petri Net VM
        "clm_rust_core::cpn::petri_run_net" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            if args.is_empty() {
                return Err("petri_run_net requires at least 1 argument (topo_file)".to_string());
            }
            crate::cpn::vm::petri_run_net(&args[0], clm_root)
                .map(|out| (0, out))
        }),
        "clm_rust_core::cpn::compose_nets" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            if args.len() != 4 {
                return Err("compose_nets requires exactly 4 arguments (net_path, output_path, telemetry_path, db_path)".to_string());
            }
            crate::cpn::compiler::compose_nets(&args[0], &args[1], &args[2], &args[3], clm_root)
                .map(|out| (0, out))
        }),
        _ => None,
    }
}

// ── Representable State Adapters ────────────────────────────

fn dispatch_representable_state_adapters(module_path: &str) -> Option<InternalFn> {
    match module_path {
        // L2 Representable State Adapters
        "clm_rust_core::normalizer::normalize_syntax" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            let file = if args.is_empty() { clm_file } else { &args[0] };
            crate::normalizer::normalize_syntax(file, clm_root)
                .map(|out| (0, out))
        }),
        "clm_rust_core::mcard_encoder::file_to_mcard" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            if args.len() != 2 {
                return Err("file_to_mcard requires exactly 2 arguments (source_file, output_dir)".to_string());
            }
            crate::mcard_encoder::file_to_mcard(&args[0], &args[1], clm_root)
                .map(|out| (0, out))
        }),
        "clm_rust_core::memorize::directory_fs_scan" => Some(|clm_root, clm_file| {
            crate::directory_ingest::directory_fs_scan(clm_root, clm_file)
        }),
        "clm_rust_core::memorize::directory_to_db" => Some(|clm_root, clm_file| {
            crate::directory_ingest::directory_to_db(clm_root, clm_file)
        }),
        "clm_rust_core::invariants::assess_equivalence" => Some(|clm_root, clm_file| {
            crate::invariants::assess_equivalence(clm_root, clm_file)
        }),
        _ => None,
    }
}

// ── Polyglot Execution ──────────────────────────────────────

fn dispatch_polyglot(module_path: &str) -> Option<InternalFn> {
    match module_path {
        // Polyglot execution
        "clm_rust_core::cpn::exec_polyglot" => Some(|clm_root, clm_file| {
            let args = get_clm_args(clm_file)?;
            if args.is_empty() {
                return Err("exec_polyglot requires at least 1 argument (file_path)".to_string());
            }
            let payload = args.get(1).map(|s| s.as_str());
            crate::polyglot::exec_polyglot(&args[0], payload, clm_root)
        }),
        _ => None,
    }
}