Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
feat: restructure CLI with all subcommand definitions
FABIOTESS3203580e477b
diff --git a/src/main.rs b/src/main.rsindex 68b1c9af..1a6c6764 100644--- a/src/main.rs+++ b/src/main.rs@@ -1,7 +1,9 @@use clap::{Parser, Subcommand};use rmcp::ServiceExt;+use std::sync::Arc;use open_ontologies::config::{expand_tilde, Config};+use open_ontologies::graph::GraphStore;use open_ontologies::server::OpenOntologiesServer;use open_ontologies::state::StateDb;@@ -10,15 +12,23 @@ data_dir = "~/.open-ontologies""#;#[derive(Parser)]-#[command(name = "open-ontologies", about = "AI-native ontology engine — MCP server")]+#[command(name = "open-ontologies", about = "Terraform for Knowledge Graphs — AI-native ontology engine")]struct Cli {#[command(subcommand)]command: Commands,++ /// Pretty-print JSON output+ #[arg(long, global = true)]+ pretty: bool,++ /// Data directory (default: ~/.open-ontologies)+ #[arg(long, global = true, default_value = "~/.open-ontologies")]+ data_dir: String,}#[derive(Subcommand)]enum Commands {- /// Initialize: create data directory, DB, and default config+ /// Initialize data directory, DB, and default configInit {#[arg(long, default_value = "~/.open-ontologies")]data_dir: String,@@ -28,6 +38,187 @@ enum Commands {#[arg(long, default_value = "~/.open-ontologies/config.toml")]config: String,},++ // ─── Core ontology ────────────────────────────────────────────+ /// Validate RDF/OWL syntax (file or stdin with -)+ Validate { input: String },+ /// Load RDF file into in-memory graph store+ Load { path: String },+ /// Save ontology to file+ Save {+ path: String,+ #[arg(long, default_value = "turtle")]+ format: String,+ },+ /// Clear in-memory store+ Clear,+ /// Show triple count, classes, properties, individuals+ Stats,+ /// Run SPARQL query (or stdin with -)+ Query { query: String },+ /// Compare two ontology files+ Diff {+ old_path: String,+ new_path: String,+ },+ /// Lint: check for missing labels, domains, ranges+ Lint { input: String },+ /// Convert between RDF formats+ Convert {+ path: String,+ #[arg(long)]+ to: String,+ #[arg(long)]+ output: Option<String>,+ },+ /// Server health and loaded triple count+ Status,++ // ─── Remote ───────────────────────────────────────────────────+ /// Fetch ontology from URL or SPARQL endpoint+ Pull {+ url: String,+ #[arg(long)]+ sparql: bool,+ #[arg(long)]+ query: Option<String>,+ },+ /// Push ontology to SPARQL endpoint+ Push {+ endpoint: String,+ #[arg(long)]+ graph: Option<String>,+ },+ /// Resolve and load owl:imports chain+ ImportOwl {+ #[arg(long, default_value = "10")]+ max_depth: usize,+ },++ // ─── Versioning ───────────────────────────────────────────────+ /// Save a named snapshot+ Version { label: String },+ /// List saved version snapshots+ History,+ /// Restore a previous version+ Rollback { label: String },++ // ─── Data pipeline ────────────────────────────────────────────+ /// Generate mapping config from data file + ontology+ Map {+ data_path: String,+ #[arg(long)]+ format: Option<String>,+ #[arg(long)]+ save: Option<String>,+ },+ /// Ingest structured data into RDF+ Ingest {+ path: String,+ #[arg(long)]+ format: Option<String>,+ #[arg(long)]+ mapping: Option<String>,+ #[arg(long)]+ base_iri: Option<String>,+ },+ /// Validate against SHACL shapes+ Shacl { shapes: String },+ /// Run inference (rdfs, owl-rl, owl-rl-ext, owl-dl)+ Reason {+ #[arg(long, default_value = "rdfs")]+ profile: String,+ },+ /// Full pipeline: ingest → SHACL → reason+ Extend {+ data_path: String,+ #[arg(long)]+ format: Option<String>,+ #[arg(long)]+ mapping: Option<String>,+ #[arg(long)]+ shapes: Option<String>,+ #[arg(long)]+ profile: Option<String>,+ },++ // ─── Lifecycle ────────────────────────────────────────────────+ /// Plan changes: diff current vs proposed Turtle+ Plan { file: String },+ /// Apply planned changes (safe or migrate)+ Apply {+ #[arg(default_value = "safe")]+ mode: String,+ },+ /// Lock IRIs to prevent removal+ Lock {+ iris: Vec<String>,+ #[arg(long)]+ reason: Option<String>,+ },+ /// Detect drift between two ontology versions+ Drift {+ file_a: String,+ file_b: String,+ },+ /// Run design pattern enforcement+ Enforce {+ #[arg(default_value = "generic")]+ pack: String,+ },+ /// Run active SPARQL watchers+ Monitor,+ /// Clear monitor block state+ MonitorClear,+ /// View lineage trail+ Lineage {+ #[arg(long)]+ session: Option<String>,+ },++ // ─── Clinical ─────────────────────────────────────────────────+ /// Look up clinical terminology crosswalk+ Crosswalk {+ code: String,+ #[arg(long)]+ system: String,+ },+ /// Add skos:exactMatch triple for clinical code+ Enrich {+ class_iri: String,+ code: String,+ #[arg(long)]+ system: String,+ },+ /// Validate class labels against clinical terminology+ ValidateClinical,++ // ─── Schema import ────────────────────────────────────────────+ /// Import database schema as OWL ontology+ ImportSchema {+ /// Connection string (e.g. postgres://user:pass@host/db)+ connection: String,+ #[arg(long, default_value = "http://example.org/db/")]+ base_iri: String,+ },+}++fn setup(data_dir: &str) -> anyhow::Result<(StateDb, Arc<GraphStore>)> {+ let data_dir = expand_tilde(data_dir);+ let data_path = std::path::Path::new(&data_dir);+ std::fs::create_dir_all(data_path)?;+ let db_path = data_path.join("open-ontologies.db");+ let db = StateDb::open(&db_path)?;+ let graph = Arc::new(GraphStore::new());+ Ok((db, graph))+}++fn output_json(value: &serde_json::Value, pretty: bool) {+ if pretty {+ println!("{}", serde_json::to_string_pretty(value).unwrap());+ } else {+ println!("{}", value);+ }}#[tokio::main]@@ -79,6 +270,12 @@ async fn main() -> anyhow::Result<()> {let service = server.serve(rmcp::transport::stdio()).await?;service.waiting().await?;}++ // ─── Stub all subcommands ─────────────────────────────────+ _ => {+ output_json(&serde_json::json!({"error": "not implemented"}), cli.pretty);+ std::process::exit(1);+ }}Ok(())diff --git a/tests/cli_test.rs b/tests/cli_test.rsnew file mode 100644index 00000000..4402a27e--- /dev/null+++ b/tests/cli_test.rs@@ -0,0 +1,26 @@+use std::process::Command;++fn oo() -> Command {+ Command::new(env!("CARGO_BIN_EXE_open-ontologies"))+}++#[test]+fn test_cli_help() {+ let out = oo().arg("--help").output().unwrap();+ assert!(out.status.success());+ let stdout = String::from_utf8_lossy(&out.stdout);+ assert!(stdout.contains("validate"));+ assert!(stdout.contains("query"));+ assert!(stdout.contains("import-schema"));+}++#[test]+fn test_cli_validate_inline_stdin() {+ let out = oo()+ .args(["validate", "-"])+ .stdin(std::process::Stdio::piped())+ .output()+ .unwrap();+ // Will fail until subcommand exists+ assert!(!out.status.success() || String::from_utf8_lossy(&out.stdout).contains("error"));+}