# Slack Bot 配置说明

**最后更新**: 2026-03-02
**当前机器**: Linux (`/root/projects/butler`)

---

## ✅ 当前配置

### LLM 后端

当前使用 **OpenRouter** 作为 Gemini API 代理，配置通过 `.gemini.current.env` 动态加载：

```bash
GEMINI_CONFIG_PATH=.gemini.current.env
```

`.gemini.current.env` 内容：
```bash
GEMINI_BASE_URL=https://openrouter.ai/api
GEMINI_MODEL=google/gemini-3-flash-preview
TOOL_MODE=all
```

如需切换模型，修改 `.gemini.current.env` 或通过 `scripts/select_gemini.py` 切换配置。

---

## 🤖 Bot 架构

| Bot | 入口文件 | 用途 | 启动条件 |
|-----|---------|------|---------|
| **Health Bot** | `slack_bot/main.py` | 健康数据查询、记录、分析 | 需要 `SLACK_BOT_TOKEN` + `SLACK_APP_TOKEN` |
| **Shell Bot** | `slack_bot/shell_main.py` | 系统管理、命令执行 | 需要 `SHELL_BOT_ENABLED=true` + Shell 专属 Token |

> **注意**: Shell Bot 默认禁用。必须在 `.env` 中显式设置 `SHELL_BOT_ENABLED=true` 才能启动。
> 这是为了防止在不应开放 shell 访问权限的机器上被误启动。

---

## 🚀 启动方式

```bash
# 进入项目目录并激活虚拟环境
cd /root/projects/butler
source venv/bin/activate

# 启动 Health Bot
python scripts/bot_manager.py start health

# 启动 Shell Bot (需先确认 .env 中 SHELL_BOT_ENABLED=true)
python scripts/bot_manager.py start shell

# 查看所有 Bot 运行状态
python scripts/bot_manager.py status

# 指定模型启动 (覆盖 .env)
python -m slack_bot.main --model google/gemini-2.5-flash
```

---

## 🧪 验证测试

```bash
# 快速冒烟测试 (模块导入、工具注册、上下文存储)
python smoke_test.py

# API 连接测试
python quick_test.py

# 系统整体验证
python scripts/verify_system.py
```

---

## 🛠️ 可用工具 (Health Bot - 全部 tools)

当前 `TOOL_MODE=all`，Health Bot 加载所有工具：

| 类别 | 工具 |
|------|------|
| 读取 | `get_daily_detailed_stats`, `get_metric_history`, `get_activity_history`, `get_manual_history` |
| 写入 | `log_diet`, `log_alcohol`, `log_supplement`, `log_feeling`, `log_fasting` |
| 同步 | `sync_garmin`, `sync_obsidian` |
| 分析 | `get_health_insights`, `analyze_driver` |
| 系统 | `search_web`, `execute_shell` |

---

## 🔧 故障排查

### Bot 无响应
```bash
# 查看运行日志
tail -f logs/slack_bot.log
tail -f logs/health.log

# 检查进程是否运行
python scripts/bot_manager.py status

# 测试 API 连接
python quick_test.py
```

### 工具未执行
检查 `slack_bot/tools/registry.py` 中工具定义是否正确，以及 `TOOL_MODE` 配置。

### 模型切换
```bash
# 查看可用配置
python scripts/select_gemini.py check

# 切换配置 (或通过 Slack 发送 ### gmode <config-name> ###)
python scripts/select_gemini.py <config-name>
```

---

## 📝 下一步

详见 [`docs/TODO.md`](docs/TODO.md) 的功能增强任务清单。
