aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md11
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/agent.rs15
-rw-r--r--src/tools/mod.rs13
-rw-r--r--src/ui.rs24
-rw-r--r--tests/loop.rs53
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.
7file, and the tool schemas the model sees. Anything a script or a resumed session 7file, and the tool schemas the model sees. Anything a script or a resumed session
8could depend on counts as API. 8could depend on counts as API.
9 9
10## 0.7.1
11
12### Fixed
13- A tool call with a name but no arguments — a placeholder some backends emit
14 alongside a real call — became a blank approval prompt and then an error. It is
15 now dropped before the assistant message is recorded, with a one-line note, so
16 the turn continues as if only the real call had been made.
17- The bash command was printed twice: once on the tool line and again in the
18 approval prompt. When the prompt is going to show it, the tool line now shows
19 only the tool name. The edit prompt no longer repeats the path either.
20
10## 0.7.0 21## 0.7.0
11 22
12### Added 23### 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"
10 10
11[[package]] 11[[package]]
12name = "agent686" 12name = "agent686"
13version = "0.7.0" 13version = "0.7.1"
14dependencies = [ 14dependencies = [
15 "crossterm", 15 "crossterm",
16 "libc", 16 "libc",
diff --git a/Cargo.toml b/Cargo.toml
index 72520a4..f96cf58 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "agent686" 2name = "agent686"
3version = "0.7.0" 3version = "0.7.1"
4edition = "2021" 4edition = "2021"
5description = "A small coding agent for a 32-bit Debian box" 5description = "A small coding agent for a 32-bit Debian box"
6publish = false 6publish = 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(
217 Err(error) => return Err(error), 217 Err(error) => return Err(error),
218 }; 218 };
219 219
220 // Placeholders are dropped before the assistant message is written:
221 // recording a call we refuse to run would leave it unanswered.
222 let before = outcome.tool_calls.len();
223 outcome
224 .tool_calls
225 .retain(|call| !tools::is_placeholder(&call.arguments));
226 if outcome.tool_calls.len() < before {
227 eprintln!("agent686: ignored {} empty tool call(s) from the model", before - outcome.tool_calls.len());
228 }
229
220 // A missing id would make the tool result unattachable. 230 // A missing id would make the tool result unattachable.
221 for (index, call) in outcome.tool_calls.iter_mut().enumerate() { 231 for (index, call) in outcome.tool_calls.iter_mut().enumerate() {
222 if call.id.is_empty() { 232 if call.id.is_empty() {
@@ -351,7 +361,10 @@ fn execute(
351 )) 361 ))
352 } 362 }
353 }; 363 };
354 ui::tool_line(step, &call.name, &args); 364 // The bash approval prompt prints the command; do not print it here too.
365 let repeat_detail = !(tools::approval(&call.name) == Approval::EveryCall
366 && approver.will_prompt_bash());
367 ui::tool_line(step, &call.name, &args, repeat_detail);
355 if let Err(error) = tools::validate(&call.name, &args) { 368 if let Err(error) = tools::validate(&call.name, &args) {
356 return ToolOutcome::Failed(format!("{error}; the call was not run")); 369 return ToolOutcome::Failed(format!("{error}; the call was not run"));
357 } 370 }
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 {
24 } 24 }
25} 25}
26 26
27/// A call with no arguments at all. Every tool here requires at least one, so
28/// this is a placeholder some backends emit next to a real call, not an attempt.
29pub fn is_placeholder(arguments: &str) -> bool {
30 let trimmed = arguments.trim();
31 if trimmed.is_empty() {
32 return true;
33 }
34 matches!(
35 serde_json::from_str::<Value>(trimmed),
36 Ok(Value::Object(map)) if map.is_empty()
37 )
38}
39
27/// Rejects a call that cannot possibly run, before a human is asked to approve 40/// Rejects a call that cannot possibly run, before a human is asked to approve
28/// it. An empty `cmd` used to mean an approval prompt for `run: `. 41/// it. An empty `cmd` used to mean an approval prompt for `run: `.
29pub fn validate(name: &str, args: &Value) -> Result<(), String> { 42pub 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<W: Write> Sink for Renderer<W> {
109 } 109 }
110} 110}
111 111
112pub fn tool_line(step: usize, name: &str, args: &serde_json::Value) { 112pub fn tool_line(step: usize, name: &str, args: &serde_json::Value, include_detail: bool) {
113 let detail = match name { 113 let detail = match name {
114 "bash" => args 114 "bash" => args
115 .get("cmd") 115 .get("cmd")
@@ -132,11 +132,12 @@ pub fn tool_line(step: usize, name: &str, args: &serde_json::Value) {
132 .unwrap_or("") 132 .unwrap_or("")
133 .to_string(), 133 .to_string(),
134 }; 134 };
135 println!( 135 let head = paint("1;36", &format!("● [{step}] {name}"));
136 "{} {}", 136 if include_detail && !detail.is_empty() {
137 paint("1;36", &format!("● [{step}] {name}")), 137 println!("{head} {detail}");
138 detail 138 } else {
139 ); 139 println!("{head}");
140 }
140 let _ = std::io::stdout().flush(); 141 let _ = std::io::stdout().flush();
141} 142}
142 143
@@ -264,7 +265,9 @@ impl Approver {
264 return true; 265 return true;
265 } 266 }
266 println!("{preview}"); 267 println!("{preview}");
267 match self.ask(&format!("apply this change to {path}?"), true) { 268 // The path is already on the tool line above.
269 let _ = path;
270 match self.ask("apply this change?", true) {
268 Answer::Yes => true, 271 Answer::Yes => true,
269 Answer::Always => { 272 Answer::Always => {
270 self.edits_allowed = true; 273 self.edits_allowed = true;
@@ -274,6 +277,13 @@ impl Approver {
274 } 277 }
275 } 278 }
276 279
280 /// True when the next bash call will actually be shown to a human, which is
281 /// the only case where the command appears in the prompt rather than the
282 /// tool line.
283 pub fn will_prompt_bash(&self) -> bool {
284 !self.yolo && self.interactive
285 }
286
277 /// Every call, no memory: the point is seeing the command. 287 /// Every call, no memory: the point is seeing the command.
278 pub fn allow_bash(&mut self, cmd: &str) -> bool { 288 pub fn allow_bash(&mut self, cmd: &str) -> bool {
279 if self.yolo { 289 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() {
345 "delta": { "tool_calls": [{ 345 "delta": { "tool_calls": [{
346 "index": 0, 346 "index": 0,
347 "id": "call_empty", 347 "id": "call_empty",
348 "function": { "name": "bash", "arguments": "{}" } 348 "function": { "name": "bash", "arguments": "{\"cmd\":\"\"}" }
349 }]}, 349 }]},
350 "finish_reason": "tool_calls" 350 "finish_reason": "tool_calls"
351 }] 351 }]
@@ -387,3 +387,54 @@ fn an_empty_bash_call_is_never_approved() {
387 assert!(result.contains("`cmd` is required"), "{result}"); 387 assert!(result.contains("`cmd` is required"), "{result}");
388 assert!(!result.contains("denied"), "must not reach an approval prompt: {result}"); 388 assert!(!result.contains("denied"), "must not reach an approval prompt: {result}");
389} 389}
390
391#[test]
392fn a_tool_call_with_no_arguments_is_dropped_silently() {
393 let dir = temp_dir("placeholder");
394 let placeholder = sse(&format!(
395 "data: {}\n\ndata: [DONE]\n\n",
396 json!({
397 "choices": [{
398 "delta": { "tool_calls": [{
399 "index": 0,
400 "id": "call_ph",
401 "function": { "name": "bash", "arguments": "{}" }
402 }]},
403 "finish_reason": "tool_calls"
404 }]
405 })
406 ));
407
408 let base = serve_sequence(vec![placeholder]);
409 std::env::set_var("AGENT686_DATA", dir.join("data"));
410
411 let system = agent::system_prompt();
412 let mut session = Session::create("test-model", &system).unwrap();
413 let cfg = Config {
414 base_url: base,
415 api_key: "test-key".into(),
416 model: "test-model".into(),
417 session: session.id.clone(),
418 yolo: false,
419 };
420 let mut history = agent::new_history(system);
421 let mut approver = Approver::new(false);
422
423 agent::run_turn(
424 &cfg,
425 &mut session,
426 &mut history,
427 "run something",
428 &AtomicBool::new(false),
429 &mut approver,
430 )
431 .expect("a placeholder must not fail the turn");
432
433 // system, user, assistant with the call removed: no tool message, no prompt.
434 assert_eq!(history.len(), 3, "{history:#?}");
435 let assistant = history.last().unwrap();
436 assert!(
437 assistant.get("tool_calls").is_none(),
438 "the placeholder must not be recorded: {assistant}"
439 );
440}