mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 14:17:11 +08:00
fix(win): add Windows platform hint in bash tool description
This commit is contained in:
@@ -23,7 +23,7 @@ class Bash(BaseTool):
|
|||||||
name: str = "bash"
|
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.
|
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 ''}
|
''' if _IS_WIN else ''}
|
||||||
ENVIRONMENT: All API keys from env_config are auto-injected. Use $VAR_NAME directly.
|
ENVIRONMENT: All API keys from env_config are auto-injected. Use $VAR_NAME directly.
|
||||||
|
|
||||||
@@ -106,25 +106,13 @@ SAFETY:
|
|||||||
else:
|
else:
|
||||||
logger.debug(f"[Bash] Process User: {os.environ.get('USERNAME', os.environ.get('USER', 'unknown'))}")
|
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:
|
if self._IS_WIN:
|
||||||
env["PYTHONIOENCODING"] = "utf-8"
|
env["PYTHONIOENCODING"] = "utf-8"
|
||||||
wrapped = (
|
command = self._convert_env_vars_for_windows(command, dotenv_vars)
|
||||||
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; "
|
if command and not command.strip().lower().startswith("chcp"):
|
||||||
f"{command}; exit $LASTEXITCODE"
|
command = f"chcp 65001 >nul 2>&1 && {command}"
|
||||||
)
|
|
||||||
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(
|
result = subprocess.run(
|
||||||
command,
|
command,
|
||||||
shell=True,
|
shell=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user