Skip to content

🪟 Windows 11 环境适配:终端工具描述、路径支持与系统命令参考 #7835

@RAFOLIE

Description

@RAFOLIE

问题

Hermes Agent 目前主要针对 Linux/macOS 环境设计,在 Windows 11 上运行时存在以下问题:

1. 终端工具描述硬编码 Linux

terminal_tool.py 中的工具描述写死了 "Execute shell commands on a Linux environment",导致 LLM 在 Windows 环境下也会尝试使用 Linux-only 命令(如 systemctl, apt, free -h 等)。

2. workdir 路径验证不支持 Windows 路径

_WORKDIR_SAFE_RE 正则只允许 / 作为路径分隔符,不支持 Windows 的 \ 和盘符 C:,导致使用 Windows 绝对路径作为 workdir 时被安全检查拦截。

3. 退出码解析不支持 Windows 可执行文件

_interpret_exit_code() 中提取 base_cmd 时只处理 Unix 路径(/ 分隔),不支持 Windows 反斜杠路径和 .exe 后缀。

4. 缺少 Windows 系统命令参考

Agent 不知道 Windows 环境下应该用什么命令替代 Linux 命令(如 systemctlGet-Service, free -h → PowerShell 等)。


已实现的修复

我在本地做了以下适配,可以作为 PR 参考:

tools/terminal_tool.py

# 1. 工具描述:去除 Linux 硬编码
-TERMINAL_TOOL_DESCRIPTION = """Execute shell commands on a Linux environment."""
+TERMINAL_TOOL_DESCRIPTION = """Execute shell commands on the host environment."""

# 2. workdir 正则:支持 Windows 路径
-_WORKDIR_SAFE_RE = re.compile(r'^[A-Za-z0-9/_\-.~ +@=,]+$')
+_WORKDIR_SAFE_RE = re.compile(r'^[A-Za-z0-9/\\_\-.~ +@=,:]+$')

# 3. 退出码解析:支持 Windows 路径和 .exe 后缀
-base_cmd = w.split("/")[-1]
+base_cmd = w.replace("\\", "/").split("/")[-1]
+if base_cmd.lower().endswith(".exe"):
+    base_cmd = base_cmd[:-4]

新增 Windows 11 Skill

创建 skills/windows/SKILL.md,提供完整的 Linux → Windows 命令映射表:

  • 系统信息:uname -asysteminfofree -h → PowerShell Get-CimInstance
  • 进程管理:ps auxGet-Processkilltaskkill
  • 网络工具:ip addripconfigss -tlnpGet-NetTCPConnection
  • 服务管理:systemctlGet-Service/Start-Service
  • 包管理:aptwinget
  • Git Bash 特殊注意事项(斜杠转义等)

建议

  1. 工具描述改为平台无关 — 已修复
  2. workdir 验证支持 Windows 路径 — 已修复
  3. 退出码解析支持 Windows exe — 已修复
  4. 内置 Windows 命令参考 Skill — 建议将 skills/windows/ 加入项目内置 skills
  5. 考虑在系统提示中注入平台检测 — 可在 build_platform_hint() 中加入 Windows 特定提示
  6. 考虑 local.py 的 PATH 处理 — 当前 _SANE_PATH 只有 Unix 路径,Windows 本地执行时可能需要补充常用路径

环境

  • Windows 11 (Build 26100)
  • Git Bash (hermes 终端后端)
  • Python 3.11+

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/cliCLI entry point, hermes_cli/, setup wizardtool/terminalTerminal execution and process managementtype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions