2026-10-12 边界:此文原有身份、分工、环境与状态均为历史快照,不是现行职责或在线证明。现行资料见 全量审计与来源索引。

2026-10-09:本文保存一次旧 WSL 故障的修复建议,未标注 Hermes commit,也不是本次对当前服务的根因验证。脚本全局替换源码中的 gateway run --replace 会误改其他生成路径;实施时须先核对当前版本的具体模板位置,限定修改目标并验收。本次仅维护文档,未执行此脚本或重启服务。

我不能直接改你 WSL 里的本地文件,但当时建议核查的修改点:不要再 patch service 文件,而是 patch hermes_cli/gateway.py 里生成 service 的模板。你日志里也显示手动改 service 后会被 gateway 启动逻辑重新覆盖,所以源头确实在源码模板。

直接在 WSL 里执行这一整段:

FILE="${HOME}/.hermes/hermes-agent/hermes_cli/gateway.py"
 
# 1. 备份
cp "$FILE" "$FILE.bak.$(date +%F-%H%M%S)"
 
# 2. 把源码模板里的 gateway run --replace 改成 gateway run
python3 - <<'PY'
from pathlib import Path
 
p = Path("${HOME}/.hermes/hermes-agent/hermes_cli/gateway.py")
s = p.read_text()
 
old = "gateway run --replace"
new = "gateway run"
 
count = s.count(old)
print(f"found {count} occurrences of: {old!r}")
 
if count == 0:
    raise SystemExit("ERROR: no occurrences found, file may already be patched or code changed")
 
s = s.replace(old, new)
p.write_text(s)
 
print(f"patched {count} occurrences")
PY
 
# 3. 确认 gateway.py 里已经没有 --replace
grep -n -- "--replace" "$FILE" || echo "OK: no --replace in gateway.py"
 
# 4. 重启 systemd service
systemctl --user daemon-reload
systemctl --user restart hermes-gateway.service
 
# 5. 等几秒后检查 service 文件是否还会被写回 --replace
sleep 5
echo "=== service file check ==="
grep -n -- "--replace" ~/.config/systemd/user/hermes-gateway.service || echo "OK: no --replace in service file"
 
echo "=== service status ==="
systemctl --user status hermes-gateway.service --no-pager -l | head -30
 
echo "=== gateway processes ==="
pgrep -af "hermes.*gateway" || true

正常结果应该看到:

OK: no --replace in gateway.py
OK: no --replace in service file

并且:

pgrep -af "hermes.*gateway"

只剩 一个 gateway 进程。

如果执行后 service file check 里还是出现 --replace,说明还有另一个生成 service 的路径,不止 hermes_cli/gateway.py。那就继续搜:

grep -rn "gateway run --replace" ${HOME}/.hermes/hermes-agent \
  --exclude-dir=venv \
  --exclude-dir=.git \
  --exclude-dir=node_modules

然后逐处确认是否属于同一个受影响的 service 模板;不要批量删除所有匹配项中的 --replace。