warriors/joy/cli/run.rs

use std::path::PathBuf;
use std::process;

use clap::Args;

use joy_rs::Warrior;
use trident::runtime::Runner;

use super::{check_target, load_bundle, make_input};

#[derive(Args)]
pub struct RunArgs {
    /// Input: .json bundle, .tri source (or project dir), or raw .nox formula
    pub input: PathBuf,
    /// Target terrain (nox) or battlefield (cyber)
    #[arg(long)]
    pub target: Option<String>,
    /// Compilation profile for .tri inputs (debug or release)
    #[arg(long, default_value = "debug")]
    pub profile: String,
    /// Public input values (comma-separated field elements)
    #[arg(long, value_delimiter = ',')]
    pub input_values: Option<Vec<u64>>,
    /// Secret/divine input values (comma-separated field elements)
    #[arg(long, value_delimiter = ',')]
    pub secret: Option<Vec<u64>>,
    /// Reduction budget (bounds trace rows one-to-one)
    #[arg(long, default_value_t = joy_rs::DEFAULT_BUDGET)]
    pub budget: u64,
    /// Public BBG state certificate (JSON)
    #[arg(long)]
    pub state: Option<String>,
}

pub fn cmd_run(args: RunArgs) {
    if let Err(e) = check_target(args.target.as_deref().unwrap_or("nox")) {
        eprintln!("error: {}", e);
        process::exit(1);
    }
    let bundle = match load_bundle(&args.input, &args.profile, args.target.as_deref()) {
        Ok(b) => b,
        Err(e) => {
            eprintln!("error: {}", e);
            process::exit(1);
        }
    };
    let pi = make_input(&args.input_values, &args.secret);
    let warrior = Warrior::with_budget(args.budget);
    let result = if let Some(path) = &args.state {
        joy_rs::state_execution::load_certificate(std::path::Path::new(path)).and_then(
            |certificate| warrior.run_state_certificate(&bundle, &pi, &certificate, args.budget),
        )
    } else {
        warrior.run(&bundle, &pi)
    };
    match result {
        Ok(result) => {
            for val in &result.output {
                println!("{}", val);
            }
            eprintln!("Executed in {} reductions", result.cycle_count);
        }
        Err(e) => {
            eprintln!("error: {}", e);
            process::exit(1);
        }
    }
}

Homonyms

warriors/trisha/cli/run.rs
neural/trident/src/cli/run.rs
cyb/wysm/crates/cli/tests/run.rs
soft3/radio/iroh-willow/src/session/run.rs
soft3/glia/run/cli/cmd/run.rs
cyb/wysm/crates/cli/src/commands/run.rs

Graph