clm-kernel 0.0.18

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
use crate::Commands;
use super::helpers::walk_dir_for_md;

pub fn run_okf_cli(command: Commands, _clm_root: &str)  {
    match command {
        Commands::OkfMount { path, mode } => {
            use clm_rust_core::okf_adapter::{OkfMount as OkfMountOp, MountMode};
            use std::collections::HashMap;
            let mount_mode = match mode.as_str() {
                "before" => MountMode::Before,
                "after" => MountMode::After,
                _ => MountMode::Instead,
            };
            let mount_path = std::path::Path::new(&path);
            if !mount_path.exists() {
                eprintln!("[okf-mount] path does not exist: {}", path);
                std::process::exit(1);
            }
            let mut files = HashMap::new();
            walk_dir_for_md(mount_path, mount_path, &mut files);
            match OkfMountOp::mount(&path, mount_mode, files) {
                Ok(mount) => {
                    println!("[okf-mount] mounted {} (mode: {})", path, mode);
                    println!("[okf-mount] {} handles registered", mount.handles.len());
                    for (handle, hash) in &mount.handles {
                        println!("  {} -> sha256:{}", handle, hash);
                    }
                    if let Some(ref manifest) = mount.gluing_manifest {
                        println!("[okf-mount] gluing manifest: {} schemas, {} b-mcard expectations, {} declared types",
                            manifest.schemas.len(), manifest.b_mcard_expectations.len(), manifest.declared_types.len());
                    }
                    std::process::exit(0);
                }
                Err(e) => {
                    eprintln!("[okf-mount] error: {}", e);
                    std::process::exit(1);
                }
            }
        }
        Commands::OkfUnmount { path } => {
            use clm_rust_core::okf_adapter::{OkfMount as OkfMountOp, MountMode};
            use std::collections::HashMap;
            let mount_path = std::path::Path::new(&path);
            if !mount_path.exists() {
                eprintln!("[okf-unmount] path does not exist: {}", path);
                std::process::exit(1);
            }
            let mut files = HashMap::new();
            walk_dir_for_md(mount_path, mount_path, &mut files);
            let mut mount = match OkfMountOp::mount(&path, MountMode::Instead, files) {
                Ok(m) => m,
                Err(e) => {
                    eprintln!("[okf-unmount] error re-mounting for unmount: {}", e);
                    std::process::exit(1);
                }
            };
            match mount.unmount() {
                Ok(()) => {
                    println!("[okf-unmount] unmounted {}", path);
                    std::process::exit(0);
                }
                Err(e) => {
                    eprintln!("[okf-unmount] error: {}", e);
                    std::process::exit(1);
                }
            }
        }
        Commands::OkfSync { path } => {
            use clm_rust_core::okf_adapter::{OkfMount as OkfMountOp, MountMode};
            use std::collections::HashMap;
            let mount_path = std::path::Path::new(&path);
            if !mount_path.exists() {
                eprintln!("[okf-sync] path does not exist: {}", path);
                std::process::exit(1);
            }
            let mut files = HashMap::new();
            walk_dir_for_md(mount_path, mount_path, &mut files);
            let mut mount = match OkfMountOp::mount(&path, MountMode::After, files.clone()) {
                Ok(m) => m,
                Err(e) => {
                    eprintln!("[okf-sync] error mounting: {}", e);
                    std::process::exit(1);
                }
            };
            let report = mount.sync_bidirectional(&files).unwrap_or_else(|e| {
                eprintln!("[okf-sync] error: {}", e);
                std::process::exit(1);
            });
            println!("[okf-sync] disk->mcard: {} events, mcard->disk: {} events, conflicts: {}",
                report.disk_to_mcard_events.len(),
                report.mcard_to_disk_events.len(),
                report.conflicts.len());
            for event in &report.disk_to_mcard_events {
                println!("  disk->mcard: {:?} {} -> {}", event.event_type, event.handle, event.new_hash);
            }
            for event in &report.mcard_to_disk_events {
                println!("  mcard->disk: {:?} {} -> {}", event.event_type, event.handle, event.new_hash);
            }
            for conflict in &report.conflicts {
                println!("  conflict: {} resolved to {:?}", conflict.handle, conflict.resolution);
            }
            std::process::exit(0);
        }
        _ => std::process::exit(0),
    }
}

pub fn run_logic(_command: Commands, _clm_root: &str) -> (i32, String, String) {
    (0, String::new(), String::new())
}