aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-18 12:28:29 +0100
committersalmonik <salmonik@tuta.io>2026-11-18 12:28:29 +0100
commit84e70c0e73460e5db1297c47d02d9b76802bfdf7 (patch)
treeff0cd75141a28d7112b4f82b2c74bdba91b332a3 /src/main.rs
parent0.9.0: distinguishable tool errors, separated stderr, configurable limits (diff)
downloadagent686-84e70c0e73460e5db1297c47d02d9b76802bfdf7.tar.gz
agent686-84e70c0e73460e5db1297c47d02d9b76802bfdf7.zip
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)
Diffstat (limited to '')
-rw-r--r--src/main.rs39
1 files changed, 34 insertions, 5 deletions
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<Args, String> {
93 words.push(arg); 93 words.push(arg);
94 continue; 94 continue;
95 } 95 }
96 // `--flag=value` form, so a value that begins with `-` is expressible.
97 if arg.starts_with('-') {
98 if let Some((flag, value)) = arg.split_once('=') {
99 match flag {
100 "-m" | "--model" => {
101 args.model = Some(value.to_string());
102 continue;
103 }
104 "--base-url" => {
105 args.base_url = Some(value.to_string());
106 continue;
107 }
108 "--session" | "--resume" => {
109 args.session = Some(value.to_string());
110 continue;
111 }
112 "--show" => {
113 args.show = Some(Some(value.to_string()));
114 continue;
115 }
116 _ => return Err(format!("unknown flag {flag}\n\n{HELP}")),
117 }
118 }
119 }
96 match arg.as_str() { 120 match arg.as_str() {
97 "--" => literal = true, 121 "--" => literal = true,
98 "-m" | "--model" => args.model = Some(take_value(&mut iter, "--model")?), 122 "-m" | "--model" => args.model = Some(take_value(&mut iter, "--model")?),
@@ -147,8 +171,13 @@ fn parse_args() -> Result<Args, String> {
147 171
148fn take_value(iter: &mut impl Iterator<Item = String>, flag: &str) -> Result<String, String> { 172fn take_value(iter: &mut impl Iterator<Item = String>, flag: &str) -> Result<String, String> {
149 match iter.next() { 173 match iter.next() {
150 Some(value) if !value.trim().is_empty() => Ok(value), 174 Some(value)
151 _ => Err(format!("{flag} needs a value")), 175 if !value.trim().is_empty()
176 && !(value.starts_with('-') && value.len() > 1) =>
177 {
178 Ok(value)
179 }
180 _ => Err(format!("{flag} needs a value (use --{flag}=… for a value starting with -)")),
152 } 181 }
153} 182}
154 183
@@ -207,7 +236,7 @@ fn run(args: Args) {
207 236
208 warn_if_moved(&session); 237 warn_if_moved(&session);
209 if resuming { 238 if resuming {
210 print_last_reply(&session.id); 239 print_last_reply(&session);
211 } 240 }
212 if !session.version.is_empty() && session.version != env!("CARGO_PKG_VERSION") { 241 if !session.version.is_empty() && session.version != env!("CARGO_PKG_VERSION") {
213 eprintln!( 242 eprintln!(
@@ -655,11 +684,11 @@ fn render_message(message: &Value, color: bool) -> String {
655/// On resume, show where the conversation left off: the last answer, or the last 684/// On resume, show where the conversation left off: the last answer, or the last
656/// reasoning when the model never produced content. Only on a terminal, so piped 685/// reasoning when the model never produced content. Only on a terminal, so piped
657/// runs stay clean. 686/// runs stay clean.
658fn print_last_reply(id: &str) { 687fn print_last_reply(session: &Session) {
659 if !std::io::stdout().is_terminal() { 688 if !std::io::stdout().is_terminal() {
660 return; 689 return;
661 } 690 }
662 let Some(reply) = session::last_reply(id) else { 691 let Some(reply) = session.last_reply.as_ref() else {
663 return; 692 return;
664 }; 693 };
665 let text = if reply.content.trim().is_empty() { 694 let text = if reply.content.trim().is_empty() {