From 54e8d9f38dd32ffcd831c5f17e45f7804e9d54cc Mon Sep 17 00:00:00 2001 From: AWSNygma Date: Tue, 6 Jan 2026 21:41:13 -0600 Subject: [PATCH] fix: add OS-aware guidance to execute_bash tool for correct cross-platform commands - Update execute_bash tool description to instruct LLM to check operating_system field before generating commands - Add OS-specific command guidance (PowerShell for Windows, bash for Linux/macOS) - Enhance build_env_state() to provide detailed OS info (version, build, distro) - Add WSL detection to help LLM understand hybrid environments This fixes the issue where the LLM generates Linux commands on Windows instances because it wasn't being instructed to use the OS context when generating commands. --- crates/chat-cli/src/cli/chat/message.rs | 20 ++++++++++++++++++- .../src/cli/chat/tools/tool_index.json | 4 ++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/chat-cli/src/cli/chat/message.rs b/crates/chat-cli/src/cli/chat/message.rs index 569846c1c2..f2c4ec7705 100644 --- a/crates/chat-cli/src/cli/chat/message.rs +++ b/crates/chat-cli/src/cli/chat/message.rs @@ -15,6 +15,11 @@ use tracing::{ warn, }; +use crate::util::system_info::{ + in_wsl, + os_version, +}; + use super::consts::{ MAX_CURRENT_WORKING_DIRECTORY_LEN, MAX_USER_MESSAGE_SIZE, @@ -540,8 +545,21 @@ impl From for AssistantToolUse { } pub fn build_env_state() -> EnvState { + // Build a detailed OS description using system_info + let os_description = match os_version() { + Some(version) => { + let base = version.to_string(); + if in_wsl() { + format!("{} (WSL - Windows Subsystem for Linux)", base) + } else { + base + } + }, + None => env::consts::OS.into(), + }; + let mut env_state = EnvState { - operating_system: Some(env::consts::OS.into()), + operating_system: Some(os_description), ..Default::default() }; diff --git a/crates/chat-cli/src/cli/chat/tools/tool_index.json b/crates/chat-cli/src/cli/chat/tools/tool_index.json index 6ebeb50334..4d3a72c319 100644 --- a/crates/chat-cli/src/cli/chat/tools/tool_index.json +++ b/crates/chat-cli/src/cli/chat/tools/tool_index.json @@ -24,13 +24,13 @@ }, "execute_bash": { "name": "execute_bash", - "description": "Execute the specified bash command.", + "description": "Execute the specified shell command.\n\nIMPORTANT: Always check the 'operating_system' field in the user's environment context before generating commands.\n\nOS-specific guidance:\n- Windows: Use PowerShell syntax (Get-ChildItem instead of ls, Get-Content instead of cat, New-Item instead of touch, Remove-Item instead of rm, Copy-Item instead of cp, Move-Item instead of mv). Use backslashes for paths or forward slashes. Use $env:VAR for environment variables.\n- Linux/macOS: Use bash/POSIX syntax (ls, cat, touch, rm, cp, mv). Use forward slashes for paths. Use $VAR for environment variables.\n- WSL: The environment is Linux but may interact with Windows paths via /mnt/c/.\n\nNever assume Linux commands will work on Windows or vice versa. When the OS is unclear, ask the user to confirm.", "input_schema": { "type": "object", "properties": { "command": { "type": "string", - "description": "Bash command to execute" + "description": "Shell command to execute. Must use syntax appropriate for the user's operating system." }, "summary": { "type": "string",