feat(agent): unified cross-platform shell execution contract (cmd/bash)

Windows runs 'cmd.exe /d /s /c <command>' as a string command line; Linux uses ['/bin/bash', '-lc', command]. Removes implicit shell=True behavior and aligns the agent system prompt per platform.
This commit is contained in:
2026-09-17 16:40:02 +08:00
parent ce56c77023
commit 60200260ab
5 changed files with 424 additions and 54 deletions
+14 -12
View File
@@ -37,8 +37,10 @@ from core.agent import (Agent, AgentConfig, AgentEvent, AgentMessage, AgentRunne
default_tools, from_openai_messages,
openai_stream)
from core.agent.stream_fn import _pick_reasoning, _pick_usage
# P0-01:配置读取统一入口(环境变量 HAOCODE_CONFIG_FILE 优先,缺省回落项目内 data/config.json
from core.config_paths import load_config
from core import platform_shell # P1-02:提示词平台段(通用正文 + 短 shell/path 段)
CONFIG_PATH = os.path.join(os.path.dirname(__file__), "..", "data", "config.json")
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
# 🌟 Agent 系统提示词文件(项目根目录,core 前面那个 .md)
SYSTEM_PROMPT_FILE = os.path.join(PROJECT_ROOT, "SYSTEM_PROMPT.md")
@@ -49,25 +51,25 @@ _FALLBACK_SYSTEM_PROMPT = (
def load_system_prompt() -> str:
"""读取 SYSTEM_PROMPT.md;缺失时用兜底短提示词。"""
"""读取 SYSTEM_PROMPT.md;缺失时用兜底短提示词。
P1-02:通用正文 + 运行时插入的短平台 shell/path 段(占位符替换);
每次请求重读本函数即重读文件,Windows 段不会出现在 Linux 请求中,反之亦然。
"""
text = None
try:
with open(SYSTEM_PROMPT_FILE, "r", encoding="utf-8") as f:
text = f.read().strip()
if text:
return text
except FileNotFoundError:
pass
return _FALLBACK_SYSTEM_PROMPT
if not text:
text = _FALLBACK_SYSTEM_PROMPT
return platform_shell.apply_platform_section(text)
def _load_config() -> dict:
if os.path.exists(CONFIG_PATH):
try:
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
return json.load(f)
except Exception as e:
print(f"[llm_engine] 读取配置失败: {e}")
return {}
"""P0-01:统一走 core.config_paths.load_config(环境变量优先、容错、可见警告)。"""
return load_config()
def _provider_info(config: dict, provider_name: str) -> dict: