From 84e70c0e73460e5db1297c47d02d9b76802bfdf7 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 18 Nov 2026 12:28:29 +0100 Subject: 0.9.1: correctness fixes from the audit - 64 MiB limit detected by file length, so pipelines and redirects are reported - bash temp files removed on every path via a scope guard - validate requires content/new as the schemas declare (present, may be empty) - Session::open folds in model-switch records; resume matches --list - combining mark at a wrap boundary no longer counts as a new row - --flag=value accepted; flag-shaped values rejected - dead code removed; last_reply folded into open (one read per resume) --- src/main.rs | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 45ca8c6..0e5d49a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,6 +93,30 @@ fn parse_args() -> Result { words.push(arg); continue; } + // `--flag=value` form, so a value that begins with `-` is expressible. + if arg.starts_with('-') { + if let Some((flag, value)) = arg.split_once('=') { + match flag { + "-m" | "--model" => { + args.model = Some(value.to_string()); + continue; + } + "--base-url" => { + args.base_url = Some(value.to_string()); + continue; + } + "--session" | "--resume" => { + args.session = Some(value.to_string()); + continue; + } + "--show" => { + args.show = Some(Some(value.to_string())); + continue; + } + _ => return Err(format!("unknown flag {flag}\n\n{HELP}")), + } + } + } match arg.as_str() { "--" => literal = true, "-m" | "--model" => args.model = Some(take_value(&mut iter, "--model")?), @@ -147,8 +171,13 @@ fn parse_args() -> Result { fn take_value(iter: &mut impl Iterator, flag: &str) -> Result { match iter.next() { - Some(value) if !value.trim().is_empty() => Ok(value), - _ => Err(format!("{flag} needs a value")), + Some(value) + if !value.trim().is_empty() + && !(value.starts_with('-') && value.len() > 1) => + { + Ok(value) + } + _ => Err(format!("{flag} needs a value (use --{flag}=… for a value starting with -)")), } } @@ -207,7 +236,7 @@ fn run(args: Args) { warn_if_moved(&session); if resuming { - print_last_reply(&session.id); + print_last_reply(&session); } if !session.version.is_empty() && session.version != env!("CARGO_PKG_VERSION") { eprintln!( @@ -655,11 +684,11 @@ fn render_message(message: &Value, color: bool) -> String { /// On resume, show where the conversation left off: the last answer, or the last /// reasoning when the model never produced content. Only on a terminal, so piped /// runs stay clean. -fn print_last_reply(id: &str) { +fn print_last_reply(session: &Session) { if !std::io::stdout().is_terminal() { return; } - let Some(reply) = session::last_reply(id) else { + let Some(reply) = session.last_reply.as_ref() else { return; }; let text = if reply.content.trim().is_empty() { -- cgit v1.2.3