soft3/strata/cli/src/main.rs

// ---
// tags: strata, rust, cli
// crystal-type: source
// crystal-domain: comp
// ---
//! strata β€” one door to the five algebras.
//!
//!   strata nebu   …   Goldilocks field π”½β‚š
//!   strata jali   …   R_q polynomial ring
//!   strata kuro   …   𝔽₂ tower field
//!   strata trop   …   tropical (min,+)
//!   strata genies …   𝔽_q isogeny field
//!
//! `strata <algebra> [args…]` forwards to the algebra's CLI β€” the binary built
//! alongside this one, so no lookup beyond our own directory.

use std::io::IsTerminal;
use std::process::{exit, Command};

const ALGEBRAS: &[(&str, &str)] = &[
    ("nebu", "Goldilocks field π”½β‚š arithmetic"),
    ("jali", "R_q polynomial ring"),
    ("kuro", "𝔽₂ tower field for binary proving"),
    ("trop", "tropical (min,+) algebra"),
    ("genies", "𝔽_q isogeny field"),
];

fn tty() -> bool {
    std::io::stdout().is_terminal()
}
fn paint(code: &str, s: &str) -> String {
    if tty() { format!("\x1b[{code}m{s}\x1b[0m") } else { s.to_string() }
}
fn dim(s: &str) -> String {
    paint("90", s)
}
fn bold(s: &str) -> String {
    paint("1", s)
}

const LOGO: &str = "\
\x1b[31mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— \x1b[0m
\x1b[33mβ–ˆβ–ˆβ•”β•β•β•β•β•β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—\x1b[0m
\x1b[32mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘\x1b[0m
\x1b[36mβ•šβ•β•β•β•β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘\x1b[0m
\x1b[34mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘\x1b[0m
\x1b[35mβ•šβ•β•β•β•β•β•β•   β•šβ•β•   β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•   β•šβ•β•   β•šβ•β•  β•šβ•β•\x1b[0m";

fn help() {
    if tty() {
        println!("{LOGO}");
        println!("{}\n", paint("37", "    the five algebras"));
    }
    println!("{}", dim("usage: strata <algebra> [args…]"));
    for (name, desc) in ALGEBRAS {
        println!("  {}  {}", bold(&format!("{name:<7}")), dim(desc));
    }
}

fn main() {
    let args: Vec<String> = std::env::args().skip(1).collect();
    let sub = args.first().map(String::as_str).unwrap_or("");

    if matches!(sub, "" | "help" | "--help" | "-h") {
        help();
        return;
    }
    if !ALGEBRAS.iter().any(|(a, _)| *a == sub) {
        eprintln!("strata: unknown algebra '{sub}' β€” try `strata help`");
        exit(2);
    }

    // The algebra binary sits next to us (same target/release dir). Its name is
    // either the algebra (nebu/jali/kuro) or `<algebra>-cli` (trop/genies).
    // Canonicalize first: when invoked via a `~/.cargo/bin` symlink, resolve it
    // back to the real build directory where the siblings live.
    let dir = std::env::current_exe()
        .ok()
        .and_then(|e| std::fs::canonicalize(&e).ok().or(Some(e)))
        .and_then(|e| e.parent().map(|p| p.to_path_buf()))
        .unwrap_or_default();
    let target = [dir.join(sub), dir.join(format!("{sub}-cli"))]
        .into_iter()
        .find(|p| p.exists());

    match target {
        Some(bin) => match Command::new(&bin).args(&args[1..]).status() {
            Ok(status) => exit(status.code().unwrap_or(0)),
            Err(e) => {
                eprintln!("strata: cannot run {sub}: {e}");
                exit(1);
            }
        },
        None => {
            eprintln!("strata: {sub} is not built β€” run `cy install strata`");
            exit(1);
        }
    }
}

Homonyms

neural/rune/cli/main.rs
cyb/optica/src/main.rs
soft3/nox/cli/main.rs
warriors/trisha/cli/main.rs
soft3/glia/import/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
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