From 0ef2b709b5ec2d44fc947a8b96572f66ee8b3bc9 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 18:31:16 +0100 Subject: 0.7.1: drop argument-less tool calls, print each command once - a name+no-arguments placeholder is removed before the assistant message is recorded, instead of prompting for an empty command - the bash prompt shows the command; the tool line shows only the name - the edit prompt no longer repeats the path already shown above --- CHANGELOG.md | 11 +++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/agent.rs | 15 ++++++++++++++- src/tools/mod.rs | 13 +++++++++++++ src/ui.rs | 24 +++++++++++++++++------- tests/loop.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 109 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d1e21e..b71c654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ break the interface, **PATCH** for bug fixes. file, and the tool schemas the model sees. Anything a script or a resumed session could depend on counts as API. +## 0.7.1 + +### Fixed +- A tool call with a name but no arguments — a placeholder some backends emit + alongside a real call — became a blank approval prompt and then an error. It is + now dropped before the assistant message is recorded, with a one-line note, so + the turn continues as if only the real call had been made. +- The bash command was printed twice: once on the tool line and again in the + approval prompt. When the prompt is going to show it, the tool line now shows + only the tool name. The edit prompt no longer repeats the path either. + ## 0.7.0 ### Added diff --git a/Cargo.lock b/Cargo.lock index a6ef8f8..9326d1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "agent686" -version = "0.7.0" +version = "0.7.1" dependencies = [ "crossterm", "libc", diff --git a/Cargo.toml b/Cargo.toml index 72520a4..f96cf58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "agent686" -version = "0.7.0" +version = "0.7.1" edition = "2021" description = "A small coding agent for a 32-bit Debian box" publish = false diff --git a/src/agent.rs b/src/agent.rs index f0e1292..7d4c4ef 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -217,6 +217,16 @@ pub fn run_turn( Err(error) => return Err(error), }; + // Placeholders are dropped before the assistant message is written: + // recording a call we refuse to run would leave it unanswered. + let before = outcome.tool_calls.len(); + outcome + .tool_calls + .retain(|call| !tools::is_placeholder(&call.arguments)); + if outcome.tool_calls.len() < before { + eprintln!("agent686: ignored {} empty tool call(s) from the model", before - outcome.tool_calls.len()); + } + // A missing id would make the tool result unattachable. for (index, call) in outcome.tool_calls.iter_mut().enumerate() { if call.id.is_empty() { @@ -351,7 +361,10 @@ fn execute( )) } }; - ui::tool_line(step, &call.name, &args); + // The bash approval prompt prints the command; do not print it here too. + let repeat_detail = !(tools::approval(&call.name) == Approval::EveryCall + && approver.will_prompt_bash()); + ui::tool_line(step, &call.name, &args, repeat_detail); if let Err(error) = tools::validate(&call.name, &args) { return ToolOutcome::Failed(format!("{error}; the call was not run")); } diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 060dd7b..ddb1004 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -24,6 +24,19 @@ pub fn approval(name: &str) -> Approval { } } +/// A call with no arguments at all. Every tool here requires at least one, so +/// this is a placeholder some backends emit next to a real call, not an attempt. +pub fn is_placeholder(arguments: &str) -> bool { + let trimmed = arguments.trim(); + if trimmed.is_empty() { + return true; + } + matches!( + serde_json::from_str::(trimmed), + Ok(Value::Object(map)) if map.is_empty() + ) +} + /// Rejects a call that cannot possibly run, before a human is asked to approve /// it. An empty `cmd` used to mean an approval prompt for `run: `. pub fn validate(name: &str, args: &Value) -> Result<(), String> { diff --git a/src/ui.rs b/src/ui.rs index 2fdda1a..03e8dbe 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -109,7 +109,7 @@ impl Sink for Renderer { } } -pub fn tool_line(step: usize, name: &str, args: &serde_json::Value) { +pub fn tool_line(step: usize, name: &str, args: &serde_json::Value, include_detail: bool) { let detail = match name { "bash" => args .get("cmd") @@ -132,11 +132,12 @@ pub fn tool_line(step: usize, name: &str, args: &serde_json::Value) { .unwrap_or("") .to_string(), }; - println!( - "{} {}", - paint("1;36", &format!("● [{step}] {name}")), - detail - ); + let head = paint("1;36", &format!("● [{step}] {name}")); + if include_detail && !detail.is_empty() { + println!("{head} {detail}"); + } else { + println!("{head}"); + } let _ = std::io::stdout().flush(); } @@ -264,7 +265,9 @@ impl Approver { return true; } println!("{preview}"); - match self.ask(&format!("apply this change to {path}?"), true) { + // The path is already on the tool line above. + let _ = path; + match self.ask("apply this change?", true) { Answer::Yes => true, Answer::Always => { self.edits_allowed = true; @@ -274,6 +277,13 @@ impl Approver { } } + /// True when the next bash call will actually be shown to a human, which is + /// the only case where the command appears in the prompt rather than the + /// tool line. + pub fn will_prompt_bash(&self) -> bool { + !self.yolo && self.interactive + } + /// Every call, no memory: the point is seeing the command. pub fn allow_bash(&mut self, cmd: &str) -> bool { if self.yolo { diff --git a/tests/loop.rs b/tests/loop.rs index f90d19d..4fc1da5 100644 --- a/tests/loop.rs +++ b/tests/loop.rs @@ -345,7 +345,7 @@ fn an_empty_bash_call_is_never_approved() { "delta": { "tool_calls": [{ "index": 0, "id": "call_empty", - "function": { "name": "bash", "arguments": "{}" } + "function": { "name": "bash", "arguments": "{\"cmd\":\"\"}" } }]}, "finish_reason": "tool_calls" }] @@ -387,3 +387,54 @@ fn an_empty_bash_call_is_never_approved() { assert!(result.contains("`cmd` is required"), "{result}"); assert!(!result.contains("denied"), "must not reach an approval prompt: {result}"); } + +#[test] +fn a_tool_call_with_no_arguments_is_dropped_silently() { + let dir = temp_dir("placeholder"); + let placeholder = sse(&format!( + "data: {}\n\ndata: [DONE]\n\n", + json!({ + "choices": [{ + "delta": { "tool_calls": [{ + "index": 0, + "id": "call_ph", + "function": { "name": "bash", "arguments": "{}" } + }]}, + "finish_reason": "tool_calls" + }] + }) + )); + + let base = serve_sequence(vec![placeholder]); + std::env::set_var("AGENT686_DATA", dir.join("data")); + + let system = agent::system_prompt(); + let mut session = Session::create("test-model", &system).unwrap(); + let cfg = Config { + base_url: base, + api_key: "test-key".into(), + model: "test-model".into(), + session: session.id.clone(), + yolo: false, + }; + let mut history = agent::new_history(system); + let mut approver = Approver::new(false); + + agent::run_turn( + &cfg, + &mut session, + &mut history, + "run something", + &AtomicBool::new(false), + &mut approver, + ) + .expect("a placeholder must not fail the turn"); + + // system, user, assistant with the call removed: no tool message, no prompt. + assert_eq!(history.len(), 3, "{history:#?}"); + let assistant = history.last().unwrap(); + assert!( + assistant.get("tool_calls").is_none(), + "the placeholder must not be recorded: {assistant}" + ); +} -- cgit v1.2.3