﻿# Hermes 自进化 Agent 框架 — 部署指南

> 本文档供 Hermes Agent 逐条执行。括号内为操作说明。

---

## 前置检查

### □ 确认环境

运行以下命令确认 Hermes 已安装：

```bash
hermes --version
python --version  # 需要 3.11+
```

确认模型文件存在：

```bash
ls /g/projects/models/gemma4-12B-it-Q4_K_M.gguf     # 策展用
ls /g/projects/models/Qwable-9B-Claude-Fable-5-Q4_K_M.gguf  # 审查用
```

确认 llama-server 存在：

```bash
ls "%LOCALAPPDATA%/hermes/b10069-cuda13/llama-server.exe"
```

### □ 确认部署包

确认桌面有以下目录结构：

```
Desktop/Hermes部署包/
├── deploy_hermes_evolution.py
├── config.yaml
├── .hermes.md
├── scripts/       (10 个 .py 文件)
└── plugins/       (3 个插件目录)
```

如果缺少任何文件，先补全再继续。

---

## 第一步：复制文件

### □ 复制脚本

```bash
# 复制所有脚本到 Hermes scripts 目录
copy "Desktop/Hermes部署包/scripts/*.py" "%LOCALAPPDATA%/hermes/scripts/"
```

或用 Python：

```python
import shutil, os
src = os.path.expandvars(r"%USERPROFILE%\Desktop\Hermes部署包\scripts")
dst = os.path.expandvars(r"%LOCALAPPDATA%\hermes\scripts")
for f in os.listdir(src):
    if f.endswith(".py"):
        shutil.copy2(os.path.join(src, f), os.path.join(dst, f))
print("脚本已复制")
```

### □ 复制插件

```bash
# 逐个复制插件目录
xcopy /E /I "Desktop/Hermes部署包/plugins/code-review-gate" "%LOCALAPPDATA%/hermes/plugins/code-review-gate"
xcopy /E /I "Desktop/Hermes部署包/plugins/iron-law-enforcer" "%LOCALAPPDATA%/hermes/plugins/iron-law-enforcer"
xcopy /E /I "Desktop/Hermes部署包/plugins/auto-checkpoint" "%LOCALAPPDATA%/hermes/plugins/auto-checkpoint"
```

### □ 复制配置和规则

```bash
copy "Desktop/Hermes部署包/config.yaml" "%LOCALAPPDATA%/hermes/config.yaml"
copy "Desktop/Hermes部署包/.hermes.md" "%LOCALAPPDATA%/hermes/.hermes.md"
```

---

## 第二步：创建定时任务

### □ 关闭门禁（临时）

部署 cron 时门禁会拦截，先开启维护模式：

```bash
python "%LOCALAPPDATA%/hermes/scripts/maintenance.py" on -r "部署策展器 cron" -d 15
```

### □ 逐一创建 cron

每个任务用以下命令格式创建，按顺序执行：

**任务 1：Curator 策展器**
```bash
hermes cron create --name "Curator策展器" --schedule "0 0 * * *" --script "model_switcher.py curate" --no-agent
```

**任务 2：模型切换安全监护**
```bash
hermes cron create --name "模型切换安全监护" --schedule "every 10m" --script "model_switcher.py status" --no-agent
```

**任务 3：维护模式自动过期**
```bash
hermes cron create --name "维护模式自动过期" --schedule "every 5m" --prompt "运行 python ~/AppData/Local/hermes/scripts/maintenance.py status 检查维护模式标记，过期则自动清理"
```

**任务 4：行为补丁监控**
```bash
hermes cron create --name "行为补丁监控" --schedule "every 60m" --script "apply-behavior-patches.py" --no-agent
```

**任务 5：审查门禁守护**
```bash
hermes cron create --name "审查门禁守护" --schedule "every 60m" --script "guard_review_gate.py" --no-agent
```

**任务 6：行为完整性守护**
```bash
hermes cron create --name "行为完整性守护" --schedule "every 30m" --script "validate-behaviors.py" --no-agent
```

**任务 7：审计巡检**
```bash
hermes cron create --name "审计巡检" --schedule "every 1m" --script "watchdog.py" --no-agent
```

### □ 确认 cron 列表

```bash
hermes cron list
```

确认所有 7 个任务都在列表中，`last_status` 不为空。

### □ 关闭维护模式

```bash
python "%LOCALAPPDATA%/hermes/scripts/maintenance.py" off
```

---

## 第三步：配置 config.yaml

### □ 确认 curator 模型地址

打开 `%LOCALAPPDATA%/hermes/config.yaml`，找到 `auxiliary.curator` 段：

```yaml
auxiliary:
  curator:
    api_key: ''
    base_url: http://127.0.0.1:8080   # 确认是 8080（Gemma 端口）
    model: ''
    provider: auto
    timeout: 600
```

如果不是 8080，修改为 `http://127.0.0.1:8080`。

```python
# 或用此命令自动修改
import os
fp = os.path.expandvars(r"%LOCALAPPDATA%\hermes\config.yaml")
with open(fp) as f: c = f.read()
c = c.replace("base_url: ''", "base_url: http://127.0.0.1:8080")
with open(fp, 'w') as f: f.write(c)
print("config.yaml 已更新")
```

---

## 第四步：启动模型

### □ 确认 Gemma4-12B 在 8080 端口运行

```bash
curl -s -m 3 http://127.0.0.1:8080/v1/models
```

如果有 JSON 返回（显示 Gemma 模型信息），说明已就绪。

如果没有响应，用 LlamaChat 启动 Gemma4-12B 模型。

### □ 可选：确认 Qwable 就绪（代码审查用）

```bash
curl -s -m 3 http://127.0.0.1:8082/v1/models
```

Qwable 由 model_switcher 或 LlamaChat 管理，首次需要手动启动一次。

---

## 第五步：重启 Hermes

### □ 完全重启

关闭所有 Hermes 窗口，然后强制结束所有 Python 进程：

```bash
taskkill /F /IM python.exe
```

重新打开 Hermes 桌面端，让所有插件加载新代码。

---

## 第六步：验证部署

### □ 验证插件加载

确认启动日志中有以下输出（在 Hermes 日志窗口中查看）：

```
[auto-checkpoint] 插件已注册
[code-review-gate] HMAC 门禁已激活
[GATE] register() called!
```

### □ 验证 session 状态追踪

写一个测试文件：

```python
write_file(path="%LOCALAPPDATA%/hermes/temp/_deploy_test.py", content="# deploy test")
```

然后检查状态文件是否生成：

```bash
dir "%LOCALAPPDATA%/hermes/.hermes/session-state.json"
```

如果文件存在且内容包含刚才的操作记录，说明状态追踪正常。

### □ 运行一次策展器

```bash
cd "%LOCALAPPDATA%/hermes"
python scripts/curator.py
```

预期输出：

```
[curator] 扫描 24h 内会话...
[curator] 找到 N 个会话
[curator] NO-OP: 无新会话，跳过扫描，仍跑结构化分析
...
[curator] 0 findings stored in SkillRepo
```

没有报错即正常。如果有 N 个新会话，会输出具体发现数量。

### □ 验证维护模式

```bash
python "%LOCALAPPDATA%/hermes/scripts/maintenance.py" on -r "部署验证" -d 1
python "%LOCALAPPDATA%/hermes/scripts/maintenance.py" status
python "%LOCALAPPDATA%/hermes/scripts/maintenance.py" off
```

三个命令都应该正常输出，无报错。

---

## 第七步：备份

### □ 备份自定义文件

```bash
python "%LOCALAPPDATA%/hermes/scripts/apply-behavior-patches.py" --check-custom
```

确认输出显示所有文件状态为 `OK`：

```json
{
  "scripts/curator.py": "OK",
  "scripts/maintenance.py": "OK",
  "scripts/model_switcher.py": "OK",
  ...
}
```

### □ 同步到桌面

```bash
md "%USERPROFILE%/Desktop/Hermes技能清单"
copy "%LOCALAPPDATA%/hermes/scripts/*.py" "%USERPROFILE%/Desktop/Hermes技能清单/"
copy "%LOCALAPPDATA%/hermes/plugins/code-review-gate/__init__.py" "%USERPROFILE%/Desktop/Hermes技能清单/code_review_gate_init.py"
copy "%LOCALAPPDATA%/hermes/plugins/iron-law-enforcer/__init__.py" "%USERPROFILE%/Desktop/Hermes技能清单/iron_law_enforcer_init.py"
copy "%LOCALAPPDATA%/hermes/plugins/auto-checkpoint/__init__.py" "%USERPROFILE%/Desktop/Hermes技能清单/auto_checkpoint_init.py"
```

---

## 完成

所有组件已部署完毕。系统将自动运行：

| 组件 | 何时运行 | 做什么 |
|------|---------|--------|
| 门禁系统 | 每次代码写入 | HMAC 审查 + 会话状态追踪 |
| 维护模式 | 手动触发 | 临时绕过门禁改核心文件 |
| 策展器 | 每日 00:00 | 扫描会话、发现模式、自动提权技能 |
| 模型切换 | 策展前 | 切换 Qwable/Gemma |
| 审计巡检 | 每分钟 | 扫描未审查文件改动 |
| 行为补丁 | 每 60 分钟 | 升级后自动恢复补丁 |

### 8 月 2 日提醒

3-5 天后检查策展器自动提权的准确率：

```bash
# 查看所有自动生成的技能
dir "%LOCALAPPDATA%/hermes/skills/curator-verified-*"
```

评估提权质量，决定是否需要调整阈值。

---

> 部署日期：2026-07-29
> 如有问题，参考 `Desktop/Hermes部署包/` 内的源文件或 `deploy_hermes_evolution.py`（一键部署脚本）。
