pub mod catalog;
pub mod catalog_ids;
mod registry_core;
mod registry_runtime;
mod registry_infra;
#[path = "registry_infra_testing.rs"]
mod registry_testing;
mod orchestrator_intercepts;
mod orchestrator_invariants;
mod orchestrator_pipeline;
mod orchestrator;
pub(crate) mod runtime;
use std::fs;
use std::path::Path;
pub(crate) type InternalFn = fn(&str, &str) -> Result<(i32, String), String>;
pub(super) fn get_clm_args(clm_file: &str) -> Result<Vec<String>, String> {
let content = fs::read_to_string(clm_file)
.map_err(|e| format!("Failed to read CLM file for args: {}", e))?;
let data: serde_yaml::Value = serde_yaml::from_str(&content)
.map_err(|e| format!("Failed to parse CLM YAML: {}", e))?;
let clm_data = data.get("clm").unwrap_or(&data);
let concrete_impl = clm_data.get("concrete_impl")
.ok_or_else(|| "No concrete_impl in CLM".to_string())?;
let process = concrete_impl.get("process")
.ok_or_else(|| "No process in concrete_impl".to_string())?;
if let Some(args_val) = process.get("args") {
if let Some(arr) = args_val.as_sequence() {
let mut result = Vec::new();
for item in arr {
if let Some(s) = item.as_str() {
result.push(s.to_string());
} else if let Some(i) = item.as_i64() {
result.push(i.to_string());
} else if let Some(b) = item.as_bool() {
result.push(b.to_string());
} else {
result.push("".to_string());
}
}
Ok(result)
} else {
Err("process.args is not a list/sequence".to_string())
}
} else {
Ok(Vec::new())
}
}
pub(super) fn resolve_json_ast_internal(json_or_file: &str, clm_root: &str) -> String {
let trimmed = json_or_file.trim();
if trimmed.starts_with('{') || trimmed.starts_with('[') {
trimmed.to_string()
} else {
let raw_path = Path::new(json_or_file);
let path = if raw_path.is_absolute() {
raw_path.to_path_buf()
} else {
Path::new(clm_root).join(json_or_file)
};
if path.exists() {
crate::yaml::parse_to_mcards(&path.to_string_lossy()).unwrap_or_else(|_| "null".to_string())
} else {
trimmed.to_string()
}
}
}
pub struct DispatchEntry {
pub module_path: &'static str,
pub func: InternalFn,
}
inventory::collect!(DispatchEntry);
#[macro_export]
macro_rules! register_clm_dispatch {
($path:expr, $func:expr) => {
inventory::submit! {
$crate::evaluator::dispatch::DispatchEntry {
module_path: $path,
func: $func,
}
}
};
}
const TESTING_ROUTES: &[&str] = &["clm_rust_core::integration::", "clm_rust_core::test::", "clm_rust_core::prove::"];
pub(crate) fn get_internal_registry(module_path: &str) -> Option<InternalFn> {
registry_core::dispatch(module_path)
.or_else(|| registry_runtime::dispatch(module_path))
.or_else(|| registry_infra::dispatch(module_path))
.or_else(|| testing_registry(module_path))
}
fn testing_registry(module_path: &str) -> Option<InternalFn> {
if !TESTING_ROUTES.iter().any(|prefix| module_path.starts_with(prefix)) {
return None;
}
static REGISTRY: std::sync::OnceLock<std::collections::HashMap<&'static str, InternalFn>> = std::sync::OnceLock::new();
let map = REGISTRY.get_or_init(|| {
let mut m = std::collections::HashMap::with_capacity(256);
for entry in inventory::iter::<DispatchEntry> {
m.insert(entry.module_path, entry.func);
}
m
});
map.get(module_path).copied().or_else(|| registry_testing::dispatch_testing_verification(module_path))
}
pub(crate) use orchestrator::try_internal_dispatch;
#[allow(unused_imports)]
pub(crate) use orchestrator::try_internal_dispatch_with_context;