soft3/glia/import/main.rs

//! mi โ€” model importer CLI (binary entry point of the `import` crate).
//!
//! HuggingFace directory (safetensors + tokenizer.json + config.json)
//! or GGUF โ†’ cyb `.model`. Runtime is in `run/`.

use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(name = "mi")]
#[command(about = "Model importer โ€” HF / GGUF / safetensors โ†’ cyb .model")]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Import a directory containing GGUF + tokenizer.json + config.json
    /// into a `.model` file under `~/llm/`.
    Import {
        /// Path to the source directory.
        dir: String,
    },

    /// List models cached under ~/.cache/huggingface/hub.
    List,

    /// Download a model from HuggingFace (best-effort ONNX/safetensors discovery).
    Download {
        /// HF repo id (e.g. "Qwen/Qwen3-0.6B").
        model: String,
    },
}

fn main() {
    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
    let cli = Cli::parse();
    match cli.command {
        Commands::Import { dir } => run_import(&dir),
        Commands::List => run_list(),
        Commands::Download { model } => run_download(&model),
    }
}

fn run_list() {
    println!("Cached HF models:");
    let cache_dir = std::env::var("HOME")
        .map(|h| std::path::PathBuf::from(h).join(".cache/huggingface/hub"))
        .unwrap_or_default();
    if !cache_dir.exists() {
        println!("  (none)");
        return;
    }
    if let Ok(entries) = std::fs::read_dir(&cache_dir) {
        for entry in entries.flatten() {
            if entry.file_type().map(|t| t.is_dir()).unwrap_or(false) {
                if let Some(s) = entry.file_name().to_str() {
                    if s.starts_with("models--") {
                        println!("  {}", s.replace("models--", "").replace("--", "/"));
                    }
                }
            }
        }
    }
}

fn run_download(model_id: &str) {
    println!("Downloading {model_id}...");
    match import::hf::download_model(model_id) {
        Ok(downloaded) => {
            println!(
                "Artifact ({:?}): {}",
                downloaded.kind,
                downloaded.artifact.display()
            );
            for s in &downloaded.siblings {
                println!("  sibling: {}", s.display());
            }
            if let Some(dir) = downloaded.snapshot_dir() {
                println!("\nSnapshot dir: {}", dir.display());
                println!("Run: mi import {}", dir.display());
            }
        }
        Err(e) => eprintln!("Error: {e}"),
    }
}

/// Import: source dir with weights artifact + tokenizer.json + config.json โ†’ `.model`.
fn run_import(dir_path: &str) {
    let dir = std::path::Path::new(dir_path);
    let name = dir.file_name().and_then(|n| n.to_str()).unwrap_or("model");
    // Keep the historical .canonical suffix for CLI imports, so nothing that
    // greps for it breaks; the library takes whatever name it is given.
    let output_name = format!("{}.canonical", name.strip_suffix("-import").unwrap_or(name));
    match import::pipeline::import_snapshot(dir_path, &output_name) {
        Ok(p) => println!("Imported: {}", p.display()),
        Err(e) => {
            eprintln!("FAIL: {e}");
            std::process::exit(1);
        }
    }
}

Homonyms

neural/rune/cli/main.rs
cyb/optica/src/main.rs
soft3/nox/cli/main.rs
warriors/trisha/cli/main.rs
cyb/shell/src/main.rs
cyb/cli/src/main.rs
neural/trident/src/main.rs
soft3/tru/cli/main.rs
cyb/apps/src/main.rs
cyberia/cyberia-my/src/main.rs
soft3/lens/cli/src/main.rs
soft3/glia/run/cli/main.rs
warriors/erga/cli/src/main.rs
cyberia/research/cyberia-my/src/main.rs
soft3/glia/cli/src/main.rs
soft3/radio/iroh-relay/src/main.rs
soft3/strata/cli/src/main.rs
neural/rs/cli/src/main.rs
neural/rs/macho-linker/src/main.rs
cyb/prysm/cli/src/main.rs
soft3/radio/iroh-dns-server/src/main.rs
soft3/cybergraph/cli/src/main.rs
soft3/hemera/cli/src/main.rs
soft3/radio/particle/src/main.rs
soft3/radio/radio-cli/src/main.rs
neural/rs/link/src/main.rs
soft3/bbg/cli/src/main.rs
neural/eidos/cli/src/main.rs
neural/rs/pure-rust-check/src/main.rs
neural/rs/rsc/src/main.rs
soft3/zheng/cli/src/main.rs
soft3/foculus/src/bin/main.rs
warriors/erga/rs/blake-bench/src/main.rs
soft3/lytics/rs/agent/src/main.rs
warriors/erga/rs/mine-bench/src/main.rs
soft3/strata/trop/cli/src/main.rs
soft3/strata/genies/cli/src/main.rs
soft3/strata/kuro/cli/src/main.rs
soft3/strata/jali/cli/src/main.rs
cyb/wysm/crates/cli/src/main.rs
warriors/erga/rs/rtable-bench/src/main.rs
soft3/lytics/rs/ingest/src/main.rs
cyb/honeycrisp/acpu/src/probe/main.rs
neural/inf/rs/cli/src/main.rs
soft3/strata/nebu/cli/src/main.rs
cyb/honeycrisp/rane/src/probe/main.rs
neural/inf/rs/cozo/cozo-bin/src/main.rs
cyb/honeycrisp/unimem/experiments/hyp_probe/src/main.rs
cyb/honeycrisp/unimem/experiments/iosurface_probe/src/main.rs
cyb/honeycrisp/unimem/experiments/dext_contiguous_alloc/client/src/main.rs
cyb/honeycrisp/unimem/experiments/dext_iosurface_pa/client/src/main.rs
cyb/honeycrisp/.claude/worktrees/agent-ad6c77c38e86bc291/rane/src/probe/main.rs
cyb/honeycrisp/.claude/worktrees/agent-ad6c77c38e86bc291/acpu/src/probe/main.rs
cyb/honeycrisp/.claude/worktrees/agent-aa1259cb10112b22a/acpu/src/probe/main.rs
cyb/honeycrisp/.claude/worktrees/agent-aa1259cb10112b22a/rane/src/probe/main.rs
cyb/honeycrisp/.claude/worktrees/agent-ad6c77c38e86bc291/unimem/experiments/iosurface_probe/src/main.rs
cyb/honeycrisp/.claude/worktrees/agent-aa1259cb10112b22a/unimem/experiments/iosurface_probe/src/main.rs
cyb/honeycrisp/.claude/worktrees/agent-ad6c77c38e86bc291/unimem/experiments/hyp_probe/src/main.rs
cyb/honeycrisp/.claude/worktrees/agent-aa1259cb10112b22a/unimem/experiments/hyp_probe/src/main.rs
cyb/honeycrisp/.claude/worktrees/agent-ad6c77c38e86bc291/unimem/experiments/dext_contiguous_alloc/client/src/main.rs
cyb/honeycrisp/.claude/worktrees/agent-aa1259cb10112b22a/unimem/experiments/dext_contiguous_alloc/client/src/main.rs
cyb/honeycrisp/.claude/worktrees/agent-ad6c77c38e86bc291/unimem/experiments/dext_iosurface_pa/client/src/main.rs
cyb/honeycrisp/.claude/worktrees/agent-aa1259cb10112b22a/unimem/experiments/dext_iosurface_pa/client/src/main.rs

Graph