From 7c035acc6e282cdbaa3b0060a528660fa0dba0d4 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 22 Nov 2026 18:58:26 +0100 Subject: 0.12.1: accept `command` as an alias for `cmd` in bash A field report showed ~40% of bash calls died on a one-word slip (command vs cmd); the alias removes the failure class instead of improving the error for it. --- CHANGELOG.md | 9 ++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/agent.rs | 22 +++++++++++++++++++- src/tools/mod.rs | 10 ++++++--- src/tools/shell.rs | 6 +++++- src/ui.rs | 1 + tests/loop.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- tests/tools.rs | 13 ++++++++++++ 9 files changed, 116 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3e68e7..dc5c016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ 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.12.1 + +### Fixed +- `bash` accepts `command` as an alias for `cmd`. A field report showed ~40% of + its calls were rejected because the model kept writing `command` instead of + `cmd`; the error was precise but named the *absence* of `cmd` rather than the + offending key, so the slip persisted for ~50 turns. The alias removes the whole + failure class. The schema still names the parameter `cmd`. + ## 0.12.0 ### Changed (breaking) diff --git a/Cargo.lock b/Cargo.lock index 48f449c..72a6c92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "agent686" -version = "0.11.0" +version = "0.12.0" dependencies = [ "crossterm", "libc", diff --git a/Cargo.toml b/Cargo.toml index 465673f..d5efb2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "agent686" -version = "0.12.0" +version = "0.12.1" edition = "2021" description = "A small coding agent for Debian-class Linux" publish = false diff --git a/src/agent.rs b/src/agent.rs index c3d77c1..f575908 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -372,6 +372,22 @@ fn execute( )); } }; + // A model keeps spelling the bash parameter `command` instead of `cmd`. The + // field report (0.12.0) shows that ~40% of calls died on this one-word slip, + // so accept the alias rather than teaching the model through repeated + // failures. Normalised once, here, so every downstream reader sees `cmd`. + let args = if call.name == "bash" && args.get("cmd").is_none() { + match args.get("command").and_then(|value| value.as_str()) { + Some(command) => { + let mut object = args.as_object().cloned().unwrap_or_default(); + object.insert("cmd".into(), serde_json::Value::String(command.to_string())); + serde_json::Value::Object(object) + } + None => args, + } + } else { + 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()); @@ -402,7 +418,11 @@ fn execute( Err(error) => ToolOutcome::Failed(error), }, Approval::EveryCall => { - let cmd = args.get("cmd").and_then(|v| v.as_str()).unwrap_or(""); + let cmd = args + .get("cmd") + .or_else(|| args.get("command")) + .and_then(|v| v.as_str()) + .unwrap_or(""); if approver.allow_bash(cmd) { match tools::run(&call.name, &args, cancel) { Ok(output) => ToolOutcome::Ok(output), diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 7c6a921..5d6189f 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -75,7 +75,11 @@ pub fn validate(name: &str, args: &Value) -> Result<(), String> { }; match name { - "bash" => required_text("cmd"), + "bash" => match args.get("cmd").or_else(|| args.get("command")) { + Some(value) if !value.as_str().unwrap_or("").trim().is_empty() => Ok(()), + Some(_) => Err("`cmd` is present but empty".into()), + None => Err(missing("cmd")), + }, "read" => required_text("path"), "write" => { required_text("path")?; @@ -177,11 +181,11 @@ pub fn schemas() -> Vec { "type": "function", "function": { "name": "bash", - "description": "Run a shell command. Each call is a fresh shell at the working directory, so `cd` does not persist; pass cwd instead. stdout and stderr are reported in separate labelled sections when both produce output. Times out after timeout_seconds (default 120, maximum 600). Large output is truncated head+tail with an explicit marker; raise max_bytes if the match you need is in the middle.", + "description": "Run a shell command. The command string is the `cmd` parameter (not `command`). Each call is a fresh shell at the working directory, so `cd` does not persist; pass cwd instead. stdout and stderr are reported in separate labelled sections when both produce output. Times out after timeout_seconds (default 120, maximum 600). Large output is truncated head+tail with an explicit marker; raise max_bytes if the match you need is in the middle.", "parameters": { "type": "object", "properties": { - "cmd": { "type": "string" }, + "cmd": { "type": "string", "description": "the shell command to run" }, "cwd": { "type": "string", "description": "working directory (default: project root)" }, "timeout_seconds": { "type": "integer", "description": "1-600, default 120" }, "max_bytes": { "type": "integer", "description": "per-stream output budget, 1024-16777216, default 81920" } diff --git a/src/tools/shell.rs b/src/tools/shell.rs index c38f032..c64bab3 100644 --- a/src/tools/shell.rs +++ b/src/tools/shell.rs @@ -37,7 +37,11 @@ pub fn bash( timeout: Duration, cancel: &AtomicBool, ) -> Result { - let cmd = match args.get("cmd").and_then(|v| v.as_str()) { + let cmd = match args + .get("cmd") + .or_else(|| args.get("command")) + .and_then(|v| v.as_str()) + { Some(cmd) => cmd.to_string(), None => return Err("missing required argument `cmd`".into()), }; diff --git a/src/ui.rs b/src/ui.rs index 1d59ac4..e778eee 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -113,6 +113,7 @@ pub fn tool_line(label: &str, name: &str, args: &serde_json::Value, include_deta let detail = match name { "bash" => args .get("cmd") + .or_else(|| args.get("command")) .and_then(|v| v.as_str()) .unwrap_or("") .to_string(), diff --git a/tests/loop.rs b/tests/loop.rs index 7e6086f..73592f0 100644 --- a/tests/loop.rs +++ b/tests/loop.rs @@ -483,7 +483,7 @@ fn a_wrong_argument_key_names_both_keys() { "delta": { "tool_calls": [{ "index": 0, "id": "call_wrong", - "function": { "name": "bash", "arguments": "{\"command\":\"ls\"}" } + "function": { "name": "bash", "arguments": "{\"shell\":\"ls\"}" } }]}, "finish_reason": "tool_calls" }] @@ -525,7 +525,63 @@ fn a_wrong_argument_key_names_both_keys() { .expect("the turn should survive a wrong key"); let result = history[3]["content"].as_str().unwrap(); - assert!(result.contains("`command`"), "should name what arrived: {result}"); + assert!(result.contains("`shell`"), "should name what arrived: {result}"); assert!(result.contains("`cmd`"), "should name what was expected: {result}"); assert!(!result.contains("denied"), "{result}"); } + +#[test] +fn a_command_key_alias_runs_the_call() { + let dir = temp_dir("alias"); + let call = sse(&format!( + "data: {}\n\ndata: [DONE]\n\n", + json!({ + "choices": [{ + "delta": { "tool_calls": [{ + "index": 0, + "id": "call_alias", + "function": { "name": "bash", "arguments": "{\"command\":\"echo alias-ok\"}" } + }]}, + "finish_reason": "tool_calls" + }] + }) + )); + let final_round = sse( + "data: {\"choices\":[{\"delta\":{\"content\":\"done\"},\"finish_reason\":\"stop\"}]}\n\n\ + data: [DONE]\n\n", + ); + + let base = serve_sequence(vec![call, final_round]); + 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: true, + lenient: false, + system_ca: false, + provider: agent686::config::Provider::OpenCode, + allow_home: false, + allow_nogit: false, + }; + let mut history = agent::new_history(system); + let mut approver = Approver::new(true); + + agent::run_turn( + &cfg, + &mut session, + &mut history, + "run it", + &AtomicBool::new(false), + &mut approver, + ) + .expect("the turn should succeed"); + + let result = history[3]["content"].as_str().unwrap(); + assert!(result.contains("alias-ok"), "{result}"); + assert!(result.contains("[exit 0]"), "{result}"); +} diff --git a/tests/tools.rs b/tests/tools.rs index 4a8176e..0321bf8 100644 --- a/tests/tools.rs +++ b/tests/tools.rs @@ -517,3 +517,16 @@ fn a_pipeline_that_exceeds_the_file_limit_is_reported() { "should report the file limit: {text}" ); } + +#[test] +fn bash_accepts_command_as_an_alias_for_cmd() { + use agent686::tools::validate; + + assert!(validate("bash", &json!({ "command": "ls" })).is_ok()); + assert!(validate("bash", &json!({ "command": " " })).is_err()); + assert!(validate("bash", &json!({})).is_err()); + + let text = run("bash", &json!({ "command": "echo alias-works" })).unwrap(); + assert!(text.contains("alias-works"), "{text}"); + assert!(text.contains("[exit 0]"), "{text}"); +} -- cgit v1.2.3