根本原因是python的select.select()在windows上无法监听伪终端(pty)文件描述符,属底层api限制;修复需启用git bash替代终端后端并替换select为poll轮询机制。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 多模态理解力帮你轻松跨越从0到1的创作门槛☜☜☜

Windows原生环境下Hermes Agent终端命令全部返回空输出,根本原因是Python的select.select()在Windows上无法监听伪终端(PTY)文件描述符——这不是配置错误,而是底层API限制导致的硬性失效。
确认问题是否属于PTY兼容性范畴
执行hermes doctor,观察输出中是否包含terminal: failed (pty not available)或subprocess stdout empty despite non-zero exit字样。若出现这类提示,且pwdlsecho hello等基础命令耗时正常但out字段为空字符串,则已锁定为PTY兼容性问题。
注意:此问题与网络、API Key、模型选择完全无关,无需重装或重配模型。
启用Git Bash替代原生Windows终端后端
第一步:确认Git Bash已安装且路径正确
打开PowerShell,运行:where git-bash或Test-Path "C:Program FilesGitusrinash.exe"。若返回True,说明Git for Windows已就绪;否则需重新安装Git for Windows并勾选“Add Git Bash to PATH”选项。
第二步:强制Hermes使用Git Bash作为终端执行器
编辑%LOCALAPPDATA%hermesconfig.yaml,在environments:层级下添加或修改以下字段:
local: shell: path: "C:\Program Files\Git\usr\bin\bash.exe" args: ["-c"]
【path中的双反斜杠不可省略,单反斜杠会导致YAML解析失败】
第三步:重启Hermes服务
执行hermes gateway stop && hermes gateway start,确保新配置加载生效。
修复Python select.select()在Windows上的阻塞缺陷
方法一:替换为poll()轮询机制(推荐)
定位到%LOCALAPPDATA%hermesenvLibsite-packageshermes_agent oolsenvironmentslocal.py,搜索select.select(,将原始调用:
ready, _, _ = select.select([proc.stdout], [], [], timeout)
在 Windows 上执行终端命令,或对比 Windows 与 Linux 的 Shell 语法时使用。建议先检测当前 Shell 是 PowerShell 还是 cmd.exe,再给出相应命令……
替换为:
import timestart = time.time()while proc.poll() is None and time.time() - start <br><code> if proc.stdout.peek(1): break time.sleep(0.05)output = proc.stdout.read()
这一步绕过了Windows对select()的限制,改用非阻塞peek+sleep轮询,实测延迟增加不超过80ms,但100%捕获stdout。
方法二:降级至uvloop兼容版本(仅限Python 3.11)
执行pip install "uvloop==0.19.0",然后在local.py顶部添加:
import uvloopuvloop.install()
该方案依赖uvloop内部对Windows IOCP的封装,但仅在Python 3.11下稳定——Python 3.12已移除部分兼容层,强行使用会导致RuntimeError: This event loop does not support subprocesses。
验证修复效果
运行hermes chat -q "run pwd and show me the path",观察响应中是否包含真实路径字符串(如D:codeHermesAgent),而非空值或超时提示。
执行hermes execute "ls -la | head -n 3",确认输出前三行可见且格式正常(含权限位、用户、大小、时间、文件名)。
若两次命令均返回有效内容,说明PTY兼容性问题已彻底解决。










