warriors/joy/cli/main.rs

mod build_cmd;
mod compile;
mod error;
mod execution_verify;
mod prove;
mod run;
mod state_verify;
mod verify;

use clap::{Parser, Subcommand};

use crate::error::JoyError;
use trident::runtime::ProgramInput;

#[derive(Parser)]
#[command(
    name = "joy",
    version,
    about = "nox warrior โ€” execute, prove, verify on the cyber battlefield"
)]
struct Cli {
    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    /// Describe the installed target package without executing a program (JSON)
    Describe {
        #[arg(long, default_value = "nox")]
        target: String,
    },
    /// Compile a source or project to a metadata-preserving bundle or nox assembly
    Build(build_cmd::BuildArgs),
    /// Execute a Trident program on the nox VM
    Run(run::RunArgs),
    /// Execute and generate a zheng proof artifact
    Prove(prove::ProveArgs),
    /// Verify a zheng proof (--proof) or a claimed output by re-execution (--claim)
    Verify(verify::VerifyArgs),
}

pub(crate) fn make_input(
    input_values: &Option<Vec<u64>>,
    secret: &Option<Vec<u64>>,
) -> ProgramInput {
    ProgramInput {
        public: input_values.clone().unwrap_or_default(),
        secret: secret.clone().unwrap_or_default(),
        digests: Vec::new(),
    }
}

/// joy answers for the nox terrain and the cyber battlefield only.
pub(crate) fn check_target(target: &str) -> Result<(), JoyError> {
    match target {
        "nox" | "cyber" => Ok(()),
        t => Err(JoyError::Execute(format!(
            "joy is the nox warrior; target '{}' is not mine (use trisha for triton)",
            t
        ))),
    }
}

/// Load a ProgramBundle from any of joy's accepted inputs:
/// `.json` bundle, `.tri` source (or project dir), or raw `.nox` formula.
pub(crate) fn load_bundle(
    input: &std::path::Path,
    profile: &str,
    target: Option<&str>,
) -> Result<trident::runtime::ProgramBundle, JoyError> {
    if let Some(target) = target {
        check_target(target)?;
    }
    if input.is_dir() {
        return compile::compile_source(input, profile, target);
    }
    match input.extension().and_then(|e| e.to_str()) {
        Some("json") => {
            let text = joy_rs::read_program_text(input)
                .map_err(|e| JoyError::Io(format!("cannot read '{}': {}", input.display(), e)))?;
            trident::runtime::ProgramBundle::from_json(&text).map_err(JoyError::Parse)
        }
        Some("tri") => compile::compile_source(input, profile, target),
        Some("nox") => bundle_from_nox(input),
        _ => Err(JoyError::Io(format!(
            "unsupported input '{}' (expected .json bundle, .tri source, or .nox formula)",
            input.display()
        ))),
    }
}

/// Wrap a raw .nox formula file into a minimal bundle (trisha's
/// `bundle_from_tasm` pattern).
fn bundle_from_nox(path: &std::path::Path) -> Result<trident::runtime::ProgramBundle, JoyError> {
    let assembly = joy_rs::read_program_text(path)
        .map_err(|e| JoyError::Io(format!("cannot read '{}': {}", path.display(), e)))?;
    let name = path
        .file_stem()
        .unwrap_or_default()
        .to_string_lossy()
        .to_string();
    let source_hash = trident::hash::content_hash_bytes(assembly.as_bytes())
        .iter()
        .map(|b| format!("{b:02x}"))
        .collect();
    Ok(trident::runtime::ProgramBundle {
        name,
        version: String::new(),
        target_vm: "nox".to_string(),
        target_os: None,
        assembly,
        entry_point: String::new(),
        functions: Vec::new(),
        cost: trident::runtime::artifact::BundleCost {
            table_values: Vec::new(),
            table_names: Vec::new(),
            padded_height: 0,
            estimated_proving_ns: 0,
        },
        source_hash,
        reads_state: false,
    })
}

fn main() {
    let cli = Cli::parse();

    match cli.command {
        Command::Describe { target } => match joy_rs::target::describe(&target) {
            Ok(description) => println!("{description}"),
            Err(error) => {
                eprintln!("error: {error}");
                std::process::exit(1);
            }
        },
        Command::Build(args) => build_cmd::cmd_build(args),
        Command::Run(args) => run::cmd_run(args),
        Command::Prove(args) => prove::cmd_prove(args),
        Command::Verify(args) => verify::cmd_verify(args),
    }
}

Homonyms

cyber/src/main.rs
cyb/cli/src/main.rs
cyb/optica/src/main.rs
soft3/nox/cli/main.rs
cyb/shell/src/main.rs
soft3/glia/import/main.rs
cyb/apps/src/main.rs
warriors/trisha/cli/main.rs
neural/trident/src/main.rs
neural/rune/cli/main.rs
cyberia/cyberia-my/src/main.rs
soft3/tru/cli/main.rs
soft3/radio/iroh-dns-server/src/main.rs
neural/eidos/cli/src/main.rs
neural/rs/link/src/main.rs
neural/rs/pure-rust-check/src/main.rs
soft3/radio/iroh-relay/src/main.rs
soft3/radio/radio-cli/src/main.rs
soft3/glia/run/cli/main.rs
soft3/cybergraph/cli/src/main.rs
soft3/neuron/cli/src/main.rs
soft3/hemera/cli/src/main.rs
neural/rs/cli/src/main.rs
warriors/erga/cli/src/main.rs
neural/rs/macho-linker/src/main.rs
soft3/radio/particle/src/main.rs
soft3/lens/cli/src/main.rs
soft3/bbg/cli/src/main.rs
soft3/strata/cli/src/main.rs
neural/rs/rsc/src/main.rs
soft3/foculus/src/bin/main.rs
soft3/zheng/cli/src/main.rs
soft3/strata/jali/cli/src/main.rs
warriors/erga/rs/mine-bench/src/main.rs
neural/trident/silicon/src/bin/main.rs
cyb/wysm/crates/cli/src/main.rs
soft3/strata/genies/cli/src/main.rs
soft3/lytics/rs/agent/src/main.rs
warriors/erga/rs/rtable-bench/src/main.rs
cyb/honeycrisp/rane/src/probe/main.rs
soft3/strata/kuro/cli/src/main.rs
warriors/erga/rs/blake-bench/src/main.rs
soft3/mudra/audit/quantus-mldsa-crosscheck/src/main.rs
neural/inf/rs/cli/src/main.rs
cyb/honeycrisp/acpu/src/probe/main.rs
soft3/strata/trop/cli/src/main.rs
soft3/strata/nebu/cli/src/main.rs
warriors/trisha/tools/neptune-policy-oracle/src/main.rs
soft3/lytics/rs/ingest/src/main.rs
cyb/honeycrisp/unimem/experiments/hyp_probe/src/main.rs
cyb/honeycrisp/unimem/experiments/iosurface_probe/src/main.rs
soft3/mudra/audit/signature-optimality/xnt-predicate-check/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

Graph