From 4d5375f6d660219d94308aea5dee70ddff21d650 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Wed, 8 Apr 2026 16:54:26 +0800 Subject: [PATCH] fix(win): add Windows platform hint in bash tool description --- agent/tools/bash/bash.py | 48 +++++++++++++++------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/agent/tools/bash/bash.py b/agent/tools/bash/bash.py index 5933d604..dd9114ed 100644 --- a/agent/tools/bash/bash.py +++ b/agent/tools/bash/bash.py @@ -23,7 +23,7 @@ class Bash(BaseTool): name: str = "bash" description: str = f"""Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last {DEFAULT_MAX_LINES} lines or {DEFAULT_MAX_BYTES // 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. {''' -PLATFORM: Windows (PowerShell). +PLATFORM: Windows (cmd.exe). Do NOT use Unix-only commands like grep, head, tail, sed, awk. ''' if _IS_WIN else ''} ENVIRONMENT: All API keys from env_config are auto-injected. Use $VAR_NAME directly. @@ -106,37 +106,25 @@ SAFETY: else: logger.debug(f"[Bash] Process User: {os.environ.get('USERNAME', os.environ.get('USER', 'unknown'))}") + # On Windows, convert $VAR references to %VAR% for cmd.exe if self._IS_WIN: env["PYTHONIOENCODING"] = "utf-8" - wrapped = ( - "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; " - f"{command}; exit $LASTEXITCODE" - ) - result = subprocess.run( - ["powershell.exe", "-NoProfile", "-NonInteractive", - "-ExecutionPolicy", "Bypass", "-Command", wrapped], - cwd=self.cwd, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True, - encoding="utf-8", - errors="replace", - timeout=timeout, - env=env, - ) - else: - result = subprocess.run( - command, - shell=True, - cwd=self.cwd, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True, - encoding="utf-8", - errors="replace", - timeout=timeout, - env=env, - ) + command = self._convert_env_vars_for_windows(command, dotenv_vars) + if command and not command.strip().lower().startswith("chcp"): + command = f"chcp 65001 >nul 2>&1 && {command}" + + result = subprocess.run( + command, + shell=True, + cwd=self.cwd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + encoding="utf-8", + errors="replace", + timeout=timeout, + env=env, + ) logger.debug(f"[Bash] Exit code: {result.returncode}") logger.debug(f"[Bash] Stdout length: {len(result.stdout)}")