feat: add headless automation protocol and CLI
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
use clap::Parser;
|
||||
use prometeu_cli::{HeadlessArgs, run_headless};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(
|
||||
name = "prometeu-headless",
|
||||
version,
|
||||
about = "Deterministic headless JSONL automation host"
|
||||
)]
|
||||
struct Cli {
|
||||
#[command(flatten)]
|
||||
options: HeadlessArgs,
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
run_headless(Cli::parse().options)
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
//! Shared CLI options for the dispatcher and its headless executable.
|
||||
use clap::Args;
|
||||
use prometeu_host_headless::automation::Limits;
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
pub struct HeadlessArgs {
|
||||
/// Use the versioned JSONL stdin/stdout protocol (required).
|
||||
#[arg(long, required = true)]
|
||||
pub stdio: bool,
|
||||
#[arg(long, default_value_t = 600)]
|
||||
pub max_frames: u64,
|
||||
#[arg(long, default_value_t = 65536)]
|
||||
pub max_command_bytes: usize,
|
||||
#[arg(long, default_value_t = 33554432)]
|
||||
pub max_response_bytes: usize,
|
||||
#[arg(long, default_value_t = 5000)]
|
||||
pub handshake_timeout_ms: u64,
|
||||
#[arg(long, default_value_t = 60000)]
|
||||
pub call_timeout_ms: u64,
|
||||
#[arg(long, default_value_t = 5000)]
|
||||
pub shutdown_timeout_ms: u64,
|
||||
}
|
||||
|
||||
impl HeadlessArgs {
|
||||
pub fn limits(&self) -> Limits {
|
||||
Limits {
|
||||
max_frames: self.max_frames,
|
||||
max_command_bytes: self.max_command_bytes,
|
||||
max_response_bytes: self.max_response_bytes,
|
||||
handshake_timeout_ms: self.handshake_timeout_ms,
|
||||
call_timeout_ms: self.call_timeout_ms,
|
||||
shutdown_timeout_ms: self.shutdown_timeout_ms,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn forwarded_args(&self) -> Vec<String> {
|
||||
vec![
|
||||
"--stdio".into(),
|
||||
"--max-frames".into(),
|
||||
self.max_frames.to_string(),
|
||||
"--max-command-bytes".into(),
|
||||
self.max_command_bytes.to_string(),
|
||||
"--max-response-bytes".into(),
|
||||
self.max_response_bytes.to_string(),
|
||||
"--handshake-timeout-ms".into(),
|
||||
self.handshake_timeout_ms.to_string(),
|
||||
"--call-timeout-ms".into(),
|
||||
self.call_timeout_ms.to_string(),
|
||||
"--shutdown-timeout-ms".into(),
|
||||
self.shutdown_timeout_ms.to_string(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_headless(args: HeadlessArgs) -> std::io::Result<()> {
|
||||
prometeu_host_headless::automation::serve(
|
||||
std::io::BufReader::new(std::io::stdin()),
|
||||
std::io::stdout(),
|
||||
args.limits(),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
)
|
||||
}
|
||||
@@ -19,6 +19,8 @@ struct Cli {
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Starts the versioned headless automation process (no native window).
|
||||
Headless(prometeu_cli::HeadlessArgs),
|
||||
/// Executes a cartridge using the available runtime.
|
||||
Run {
|
||||
/// Path to the cartridge (directory or .pmc file).
|
||||
@@ -65,6 +67,11 @@ fn main() {
|
||||
};
|
||||
|
||||
match cli.command {
|
||||
Some(Commands::Headless(options)) => {
|
||||
let args = options.forwarded_args();
|
||||
let borrowed: Vec<&str> = args.iter().map(String::as_str).collect();
|
||||
dispatch(&exe_dir, "prometeu-headless", &borrowed);
|
||||
}
|
||||
Some(Commands::Run { cart }) => {
|
||||
dispatch(&exe_dir, "prometeu-runtime", &["--run", &cart]);
|
||||
}
|
||||
@@ -99,6 +106,7 @@ fn dispatch(exe_dir: &Path, bin_name: &str, args: &[&str]) {
|
||||
"prometeu: command '{}' is not yet available in this distribution on {}",
|
||||
match bin_name {
|
||||
"prometeu-runtime" => "run/debug",
|
||||
"prometeu-headless" => "headless",
|
||||
"prometeuc" => "build/verify c",
|
||||
"prometeup" => "pack/verify p",
|
||||
_ => bin_name,
|
||||
|
||||
Reference in New Issue
Block a user