From 39a09f007b7d77dd9ff4ad6c3ee31b08201af1ce Mon Sep 17 00:00:00 2001 From: Alex Gorevski Date: Thu, 19 Feb 2026 11:45:12 -0800 Subject: [PATCH] fix(cli): add range validation for temperature argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a custom value_parser for the --temperature CLI argument to enforce the documented 0.0-2.0 range at parse time. Previously, the comment stated the valid range but clap did not reject out-of-range values, allowing invalid temperatures to propagate to provider API calls. - Add parse_temperature() validator that rejects values outside 0.0..=2.0 - Wire it into the Agent subcommand's temperature arg via value_parser Addresses API surface audit ยง2.3 (CLI argument range validation). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 672e7e6..18e59d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,14 @@ use serde::{Deserialize, Serialize}; use tracing::{info, warn}; use tracing_subscriber::{fmt, EnvFilter}; +fn parse_temperature(s: &str) -> std::result::Result { + let t: f64 = s.parse().map_err(|e| format!("{e}"))?; + if !(0.0..=2.0).contains(&t) { + return Err("temperature must be between 0.0 and 2.0".to_string()); + } + Ok(t) +} + mod agent; mod approval; mod auth; @@ -144,7 +152,7 @@ enum Commands { model: Option, /// Temperature (0.0 - 2.0) - #[arg(short, long, default_value = "0.7")] + #[arg(short, long, default_value = "0.7", value_parser = parse_temperature)] temperature: f64, /// Attach a peripheral (board:path, e.g. nucleo-f401re:/dev/ttyACM0)