Skip to content

Commit d561046

Browse files
committed
feat: enhance shell command execution description for cross-platform compatibility
fixes: #5499
1 parent fd223bb commit d561046

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

astrbot/core/astr_main_agent.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datetime
66
import json
77
import os
8+
import platform
89
import zoneinfo
910
from collections.abc import Coroutine
1011
from dataclasses import dataclass, field
@@ -265,6 +266,22 @@ def _apply_local_env_tools(req: ProviderRequest) -> None:
265266
req.func_tool = ToolSet()
266267
req.func_tool.add_tool(LOCAL_EXECUTE_SHELL_TOOL)
267268
req.func_tool.add_tool(LOCAL_PYTHON_TOOL)
269+
req.system_prompt = f"{req.system_prompt or ''}\n{_build_local_mode_prompt()}\n"
270+
271+
272+
def _build_local_mode_prompt() -> str:
273+
system_name = platform.system() or "Unknown"
274+
shell_hint = (
275+
"The runtime shell is Windows Command Prompt (cmd.exe). "
276+
"Use cmd-compatible commands and do not assume Unix commands like cat/ls/grep are available."
277+
if system_name.lower() == "windows"
278+
else "The runtime shell is Unix-like. Use POSIX-compatible shell commands."
279+
)
280+
return (
281+
"You have access to the host local environment and can execute shell commands and Python code. "
282+
f"Current operating system: {system_name}. "
283+
f"{shell_hint}"
284+
)
268285

269286

270287
async def _ensure_persona_and_skills(

astrbot/core/computer/tools/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ExecuteShellTool(FunctionTool):
2020
"properties": {
2121
"command": {
2222
"type": "string",
23-
"description": "The bash command to execute. Equal to 'cd {working_dir} && {your_command}'.",
23+
"description": "The shell command to execute in the current runtime shell (for example, cmd.exe on Windows). Equal to 'cd {working_dir} && {your_command}'.",
2424
},
2525
"background": {
2626
"type": "boolean",

0 commit comments

Comments
 (0)