diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-18 12:28:29 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-18 12:28:29 +0100 |
| commit | 84e70c0e73460e5db1297c47d02d9b76802bfdf7 (patch) | |
| tree | ff0cd75141a28d7112b4f82b2c74bdba91b332a3 /src/tools/mod.rs | |
| parent | 0.9.0: distinguishable tool errors, separated stderr, configurable limits (diff) | |
| download | agent686-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/tools/mod.rs | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 27840e9..7c6a921 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs | |||
| @@ -24,13 +24,6 @@ pub fn approval(name: &str) -> Approval { | |||
| 24 | } | 24 | } |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | /// True when the call cannot be replayed as a real tool call at all: no name. | ||
| 28 | /// (Named calls with no arguments are kept so the model can be told what went | ||
| 29 | /// wrong and retry.) | ||
| 30 | pub fn is_placeholder(arguments: &str) -> bool { | ||
| 31 | arguments.trim().is_empty() | ||
| 32 | } | ||
| 33 | |||
| 34 | /// Returns the keys the model actually sent, quoted and bounded. | 27 | /// Returns the keys the model actually sent, quoted and bounded. |
| 35 | fn received_keys(args: &Value) -> String { | 28 | fn received_keys(args: &Value) -> String { |
| 36 | let Some(object) = args.as_object() else { | 29 | let Some(object) = args.as_object() else { |
| @@ -55,32 +48,45 @@ fn received_keys(args: &Value) -> String { | |||
| 55 | /// arrived with no arguments at all (usually argument loss in transit). They | 48 | /// arrived with no arguments at all (usually argument loss in transit). They |
| 56 | /// used to share one message, which pointed callers at the wrong fix. | 49 | /// used to share one message, which pointed callers at the wrong fix. |
| 57 | pub fn validate(name: &str, args: &Value) -> Result<(), String> { | 50 | pub fn validate(name: &str, args: &Value) -> Result<(), String> { |
| 58 | let required = |key: &str| match args.get(key).and_then(|value| value.as_str()) { | 51 | let missing = |key: &str| { |
| 52 | if args.as_object().map(|o| o.is_empty()).unwrap_or(true) { | ||
| 53 | format!( | ||
| 54 | "the call arrived with no arguments at all, so `{key}` is missing. \ | ||
| 55 | If you sent one, it was lost in transit — retry the call" | ||
| 56 | ) | ||
| 57 | } else { | ||
| 58 | format!( | ||
| 59 | "missing `{key}`; received {}. The parameter is `{key}`", | ||
| 60 | received_keys(args) | ||
| 61 | ) | ||
| 62 | } | ||
| 63 | }; | ||
| 64 | // Must be present and non-blank. | ||
| 65 | let required_text = |key: &str| match args.get(key).and_then(|value| value.as_str()) { | ||
| 59 | Some(value) if !value.trim().is_empty() => Ok(()), | 66 | Some(value) if !value.trim().is_empty() => Ok(()), |
| 60 | Some(_) => Err(format!("`{key}` is present but empty")), | 67 | Some(_) => Err(format!("`{key}` is present but empty")), |
| 61 | None => { | 68 | None => Err(missing(key)), |
| 62 | if args.as_object().map(|o| o.is_empty()).unwrap_or(true) { | 69 | }; |
| 63 | Err(format!( | 70 | // Must be present, but may be the empty string (an empty file, a deletion). |
| 64 | "the call arrived with no arguments at all, so `{key}` is missing. \ | 71 | let required_string = |key: &str| match args.get(key) { |
| 65 | If you sent one, it was lost in transit — retry the call" | 72 | Some(Value::String(_)) => Ok(()), |
| 66 | )) | 73 | Some(_) => Err(format!("`{key}` must be a string")), |
| 67 | } else { | 74 | None => Err(missing(key)), |
| 68 | Err(format!( | ||
| 69 | "missing `{key}`; received {}. The parameter is `{key}`", | ||
| 70 | received_keys(args) | ||
| 71 | )) | ||
| 72 | } | ||
| 73 | } | ||
| 74 | }; | 75 | }; |
| 75 | 76 | ||
| 76 | match name { | 77 | match name { |
| 77 | "bash" => required("cmd"), | 78 | "bash" => required_text("cmd"), |
| 78 | "read" | "write" => required("path"), | 79 | "read" => required_text("path"), |
| 80 | "write" => { | ||
| 81 | required_text("path")?; | ||
| 82 | required_string("content") | ||
| 83 | } | ||
| 79 | "edit" => { | 84 | "edit" => { |
| 80 | required("path")?; | 85 | required_text("path")?; |
| 81 | required("old") | 86 | required_text("old")?; |
| 87 | required_string("new") | ||
| 82 | } | 88 | } |
| 83 | "grep" | "glob" => required("pattern"), | 89 | "grep" | "glob" => required_text("pattern"), |
| 84 | "" => Err("the tool call arrived without a tool name; it was probably truncated in transit — retry the call".into()), | 90 | "" => Err("the tool call arrived without a tool name; it was probably truncated in transit — retry the call".into()), |
| 85 | _ => Ok(()), | 91 | _ => Ok(()), |
| 86 | } | 92 | } |
