Files
nexus/openclaw/Agents/TOOLS标准模板.md

1076 lines
31 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: TOOLS管理
source:
author: shenwei
published:
created:
description:
tags: []
---
# TOOLS管理
## 1.统一SSH管理
- **所有服务器**: 包括macmini、ubuntu1、ubuntu2、NAS
- **管理方式**: 通过SSH统一管理不存储sudo密码
- **权限原则**: 遵循最小权限原则
## 2.管理流程
1. 所有服务器操作都通过SSH进行
2. 不存储任何服务器的sudo密码
3. 需要sudo权限的操作通过SSH执行
4. 保持所有服务器的管理方式一致
## 3.文件编辑注意事项
- **所有重要文件**: 使用 `exec + echo` 追加内容,避免 edit 工具在文件末尾无换行时失败
- **edit工具使用准则**: edit依赖精确文本匹配任何空白字符差异都会导致失败。建议先 read 文件确认内容,用 write 重写整个文件更可靠(特别是 memory、SOUL、IDENTITY 等重要文件)
## 4.FRP (frpc 客户端) 管理
### 安装目录
| 服务器     | FRP目录                             |
| ------- | --------------------------------- |
| macmini | /opt/frp/frp_0.65.0_darwin_arm64 |
| ubuntu1 | /opt/frp/frp_0.65.0_linux_amd64   |
| ubuntu2 | /opt/frp/frp_0.65.0_linux_amd64   |
### 配置文件
- **文件名**: `frpc.toml`在FRP目录下
- **作用**: 定义所有通过frp反向代理的应用及端口映射 (localPort ↔ remotePort)
### Mac Mini 管理方式launchd
**启动方式**: launchd plist`KeepAlive: true`,崩溃自动重启)
**plist 位置**: `~/Library/LaunchAgents/com.homebrew.frpc.plist`
**管理命令**:
```bash
# 重启
launchctl unload ~/Library/LaunchAgents/com.homebrew.frpc.plist && launchctl load ~/Library/LaunchAgents/com.homebrew.frpc.plist
# 停止KeepAlive 会自动重启,需先 unload
launchctl unload ~/Library/LaunchAgents/com.homebrew.frpc.plist
# 查看状态
launchctl list | grep frpc
# 查看日志
tail -f /opt/frp/frp_0.65.0_darwin_arm64/frpc.log
```
**正常状态标志**: 日志中显示 `[name] start proxy success`
### Ubuntu1/2 管理方式systemd --user
```bash
ssh ubuntu1 'systemctl --user restart frpc'
ssh ubuntu2 'systemctl --user restart frpc'
ssh ubuntu1 'systemctl --user status frpc'
ssh ubuntu2 'systemctl --user status frpc'
```
不需要密码开机自启linger 已启用)
### 查看配置
```bash
# 读取frpc.toml了解端口映射
cat /opt/frp/frp_0.65.0_xxx/frpc.toml
```
## 5.FRP端口映射查询格式 (2026-03-14)
用户会这样提问:
- "ubuntu1上frp的列表"
- "macmini的frp配置"
- "查看ubuntu2的frpc.toml"
格式: 扫描frpc.toml文件列出proxies相关配置
输出格式: 表格 (名称 | 类型 | localPort | remotePort)
查询示例: ssh到对应服务器 -> cat /opt/frp/frp_0.65.0_xxx/frpc.toml
## 6.FRP状态检查 (2026-04-04)
用户可能说: "检查frp状态"
**检查方法**:
1. 如果是macmini服务器
   - `launchctl list | grep frpc` 查看进程状态
   - `tail /opt/frp/frp_0.65.0_darwin_arm64/frpc.log` 查看代理启动情况
2. 如果是ubuntu服务器
   - `systemctl --user status frpc`
**正常状态标志**:
- 所有 proxy 启动成功时会显示: `[xxx] [name] start proxy success`
- 例如: `2026-04-04 16:43:01.276 [I] [client/control.go:172] [1a254958e6553119] [macmini-ssh] start proxy success`
**重启命令** (如果需要):
1. 如果是macmini服务器
```bash
launchctl unload ~/Library/LaunchAgents/com.homebrew.frpc.plist && launchctl load ~/Library/LaunchAgents/com.homebrew.frpc.plist
```
2. 如果是ubuntu服务器
```bash
systemctl --user restart frpc
```
## 7.VPS2 (x-UI 科学上网)
- **IP**: 104.194.92.188
- **SSH**: `ssh vps2`
- **管理命令**: `x-ui`
- **用途**: x-UI 面板管理,用于科学上网
- 结果展示用列表方式,方便阅读
## 8.网络测试策略 (2026-03-15)
用户可能说: "网络测试"、"检查服务器科学上网"
**测试项目**:
1. 国内直连baidu (https://www.baidu.com)
2. 国外直连 Google (https://www.google.com)
3. 国外通过代理访问 Google (socks5://127.0.0.1:10808)
**测试命令模板**:
**国内访问直连**
```
curl -v https://www.baidu.com
```
**国外访问直连**
```
curl -v https://www.google.com
```
**国外访问通过代理连**
这是最快、最直接的方法。我们可以强制 `curl` 使用 SOCKS5 代理去访问 Google 的状态页。
**执行命令:**
```
curl -x socks5h://127.0.0.1:10808 -v https://www.google.com
```
- **参数解释:**
    - `-x socks5h://`:指定使用 SOCKS5 代理。注意加个 `h`,这表示让代理服务器去解析域名(防止本地 DNS 污染导致测试失败)。
    - `-v`(Verbose) 显示详细连接过程。
- **判断标准:**    
    - 如果看到 `HTTP/2 200` 或者大量的 HTML 文本,说明**代理成功**。
    - 如果显示 `Connection refused``Timeout`,说明**端口未开放或 V2Ray 未运行**。
**服务器列表与代理端口**:
| 服务器 | IP | 代理端口 | 备注 |
| ------- | --------------- | ----- | ------------ |
| MacMini | 192.168.3.189 | 10808 | V2RayN |
| Ubuntu1 | 192.168.3.47 | 10808 | 需SSH后测试 |
| Ubuntu2 | 192.168.3.45 | 10808 | 需SSH后测试 |
| NAS | 192.168.3.17 | 20170 | 仅监听127.0.0.1 |
| VPS1 | 192.227.222.142 | - | 直连正常 |
| VPS2 | 104.194.92.188 | - | 直连正常 |
**输出格式**: 列表方式,方便阅读
**网络测试输出格式**
用户要求格式示例:
• 服务器名
  • 国内访问直连: ✅/❌
  • 国外访问直连: ✅/❌
  • 国外访问通过代理XXX连: ✅/❌
## 9.OpenClaw 命令路径 (2026-03-27)
| 服务器      | OpenClaw 路径                              |
| -------- | ---------------------------------------- |
| Mac mini | `/opt/homebrew/bin/openclaw`             |
| Ubuntu1  | `/home/shenwei/.npm-global/bin/openclaw` |
| Ubuntu2  | `/home/shenwei/.npm-global/bin/openclaw` |
## 10.NAS Docker 代理配置 (2026-03-27)
- **配置文件**: `/etc/systemd/system/pkg-ContainerManager-dockerd.service.d/http-proxy.conf`
- **用途**: Synology NAS 上 Docker 守护进程的代理设置
- **修改后需执行**: `sudo systemctl daemon-reload && sudo systemctl restart docker`
## 11.sag (TTS 语音生成) (2026-03-27)
### 安装
```bash
brew install steipete/tap/sag
```
### API Key 配置
- 位置: `~/.openclaw/.env`
- 环境变量: `ELEVENLABS_API_KEY`
### 生成语音并发送到 Telegram
```bash
# 1. 生成 MP3 文件
source ~/.openclaw/.env
sag --api-key "$ELEVENLABS_API_KEY" -o /tmp/voice.mp3 "要转换的文字"
# 2. 发送到 Telegram (voice note)
message --account <telegram bot> --chatId <user_id> --filePath /tmp/voice.mp3 --message "文字" --buttons []
```
### 使用规则
- 所有用 sag 生成的语音都必须通过 Telegram voice note 发送给我
- 使用 当前agent对应的telegram bot 账号发送
- 文件临时保存在 /tmp/ 目录
### OpenCode
- **路径**: `/Users/weishen/.opencode/bin/opencode`
- **版本**: 1.2.27
- **用法**: 开发任务必须通过它执行
## 12.OpenClaw Gateway 重启步骤
### Mac Mini (2026-03-30 新方法)
使用 `launchctl` 管理 OpenClaw Gateway 服务:
`launchctl unload ~/Library/LaunchAgents/ai.openclaw.gateway.plist && launchctl load ~/Library/LaunchAgents/ai.openclaw.gateway.plist`
### Ubuntu1/2 服务器 (2026-03-28)
#### 完整操作流程
**1. SSH 登录并重启**
```bash
ssh ubuntu1 'systemctl --user restart openclaw-gateway'
ssh ubuntu2 'systemctl --user restart openclaw-gateway'
```
**2. 查看启动状态**
```bash
ssh ubuntu1 'systemctl --user status openclaw-gateway'
ssh ubuntu2 'systemctl --user status openclaw-gateway'
```
**3. 检查 OpenClaw 健康状态**
```bash
ssh ubuntu1 '/home/shenwei/.npm-global/bin/openclaw status'
ssh ubuntu2 '/home/shenwei/.npm-global/bin/openclaw status'
```
### 快捷命令组合 (单行执行)
```bash
# Ubuntu1
ssh ubuntu1 'systemctl --user restart openclaw-gateway && systemctl --user status openclaw-gateway && /home/shenwei/.npm-global/bin/openclaw status'
# Ubuntu2
ssh ubuntu2 'systemctl --user restart openclaw-gateway && systemctl --user status openclaw-gateway && /home/shenwei/.npm-global/bin/openclaw status'
```
## 13.AgentMail (邮件收发与自动化) (2026-04-04 更新)
### 📂 技能目录
```
~/.openclaw/skills/agentmail/
├── scripts/           # 可直接使用的 Python 脚本
  ├── check_inbox.py   # 查看收件箱
  ├── send_email.py    # 发送邮件
  └── setup_webhook.py # 配置 Webhook
└── references/       # 参考文档
    ├── API.md         # API 完整文档
    ├── EXAMPLES.md    # 使用示例
    └── WEBHOOKS.md   # Webhook 配置指南
```
### 快速使用
#### 查看收件箱
```bash
unset HTTP_PROXY && unset HTTPS_PROXY && unset http_proxy && unset https_proxy
python3 ~/.openclaw/skills/agentmail/scripts/check_inbox.py --inbox star-agent@agentmail.to --limit 10
```
#### 发送邮件
```bash
python3 ~/.openclaw/skills/agentmail/scripts/send_email.py \
  --inbox star-agent@agentmail.to \
  --to "recipient@example.com" \
  --subject "主题" \
  --text "正文内容"
```
### API Key 配置
- 位置: `~/.openclaw/.env`
- 环境变量: `AGENTMAIL_API_KEY=your_key_here`
### 附件处理
附件需要用 Python 代码下载,参考:
```bash
cat ~/.openclaw/skills/agentmail/references/API.md
cat ~/.openclaw/skills/agentmail/references/EXAMPLES.md
```
### ⚠️ 注意事项
- **代理问题**:遇到 SOCKS 代理错误时,先 `unset HTTP_PROXY && unset HTTPS_PROXY`
- **临时文件存放**:下载的附件和临时脚本请放在 `~/.openclaw/temp/<agentId>/` 目录,不要放在 workspace 下
- **参考文档**:详细用法见 `references/API.md``references/EXAMPLES.md`
## 14.Docker命令路径 (2026-04-04)
### 列表
| 服务器 | 命令 | 说明 |
| ------------- | -------------------------------------------------------- | ------------- |
| macmini | `docker` | 直接可用(已在 PATH |
| macmini (SSH) | `/Applications/Docker.app/Contents/Resources/bin/docker` | SSH 时用完整路径 |
| ubuntu1/2 | `docker` | 直接可用 |
**使用方式**:
```bash
# macmini 本地
docker ps
# macmini SSH
ssh macmini '/Applications/Docker.app/Contents/Resources/bin/docker ps'
# ubuntu1/2 SSH
ssh ubuntu1 'docker ps'
ssh ubuntu2 'docker ps'
```
## 15.定时任务创建注意事项 (2026-03-29)
### 预防措施
1. 在远程服务器(Ubuntu1/Ubuntu2)创建定时任务后,**手动运行一次**确认能正常发送 Telegram 通知
2. 如果遇到 "Outbound not configured for channel: telegram" 错误,重启 Gateway
   ```bash
   # Ubuntu1/Ubuntu2 重启 Gateway
   systemctl --user restart openclaw-gateway
   systemctl --user status openclaw-gateway
   ```
### 常见错误处理
| 错误信息 | 原因 | 解决方案 |
| ----------------------------------------------- | --------------------- | ---------- |
| "Outbound not configured for channel: telegram" | Gateway Telegram 连接异常 | 重启 Gateway |
| "Message failed" | Telegram API 限流或连接问题 | 分散任务执行时间 |
## 16. Last30Days 技能 (2026-03-29)
### 功能概述
搜索过去 30 天内 Reddit、X、YouTube、TikTok、Instagram、Hacker News、Polymarket 和网页上的热门内容,生成研究报告
### 调用方式
```bash
python3 ~/.openclaw/skills/last30days-official/scripts/last30days.py "<话题>" --emit=compact --no-native-web --save-dir=~/Documents/Last30Days
```
### 常用参数
| 参数 | 说明 | 示例 |
| ------------------- | ------------------ | --------------------- |
| `--days=N` | 回溯 N 天默认30天 | `--days=7` |
| `--quick` | 快速模式8-12条/来源) | |
| `--deep` | 深度模式50-70条Reddit | |
| `--x-handle=HANDLE` | 指定 X 账号搜索 | `--x-handle=elonmusk` |
### 对比模式
```bash
# 比较两个话题
python3 ~/.openclaw/skills/last30days-official/scripts/last30days.py "cursor vs windsurf" --emit=compact --no-native-web --save-dir=~/Documents/Last30Days
```
### 输出说明
- **What I Learned** — 研究发现摘要
- **Key Patterns** — 关键模式3-5条
- **Stats** — 统计数据(各平台帖子数、点赞数等)
- **Invitation** — 根据类型推荐下一步
### 数据来源权重
| 来源 | 权重 | 说明 |
| ---------------- | --- | ------------ |
| Reddit/X | 高 | 有互动数据(点赞、评论) |
| YouTube | 高 | 有观看数和字幕 |
| TikTok/Instagram | 中 | 有观看数和标题 |
| Polymarket | 高 | 真实钱币投注,数据真实 |
| Web | 低 | 无互动数据 |
### API Keys 配置
在 `~/.openclaw/.env` 中配置:
```bash
SCRAPECREATORS_API_KEY=...   # Reddit + TikTok + Instagram必填
AUTH_TOKEN=...                 # X 搜索(推荐)
CT0=...                        # X 搜索(推荐)
XAI_API_KEY=xai-...           # X 搜索备选
```
### 保存位置
- 研究数据自动保存到:`~/Documents/Last30Days/`
- 文件名格式:`{话题}-YYYY-MM-DD.md`
### 使用场景
1. **热点追踪** — 搜索"AI一人公司"了解最新趋势
2. **工具对比** — "cursor vs windsurf" 对比两个工具
3. **人物研究** — 搜索某人的 X 账号帖子
4. **竞品分析** — 搜索竞品最新动态
5. **话题深挖** — 发现新工具、新技术
### 注意事项
- 深度研究需要 2-8 分钟
- TikTok/Instagram 需要 ScrapeCreators API key前 100 次免费)
- 建议先用 `--quick` 测试话题
## 17. gog (Google Workspace CLI) 代理配置 (2026-03-30)
### 必须走代理
gog CLI 在 Mac Mini 上直连 Google API 会超时,**必须设置代理**
```bash
HTTPS_PROXY=socks5h://127.0.0.1:10808 HTTP_PROXY=socks5h://127.0.0.1:10808 gog <command>
```
### 常用命令示例
```bash
# 日历列表(带代理)
HTTPS_PROXY=socks5h://127.0.0.1:10808 HTTP_PROXY=socks5h://127.0.0.1:10808 gog calendar list --account ishenwei@gmail.com
# 查看日历事件(带代理)
HTTPS_PROXY=socks5h://127.0.0.1:10808 HTTP_PROXY=socks5h://127.0.0.1:10808 gog calendar events --account ishenwei@gmail.com "OpenClaw" --from 2026-03-30T00:00:00+08:00 --to 2026-04-05T23:59:59+08:00 --max 50
# 删除日历事件(带代理)
HTTPS_PROXY=socks5h://127.0.0.1:10808 HTTP_PROXY=socks5h://127.0.0.1:10808 gog calendar delete --account ishenwei@gmail.com "OpenClaw" <eventId> -y
```
### 认证状态
- 已完成 OAuth 授权ishenwei@gmail.com
- Google Calendar: OpenClaw 日历cfd0ba26...@group.calendar.google.com
## 18.n8n工作流标准执行步骤
> ⚠️ n8n 已迁移到 Ubuntu2 服务器2026-03-30 更新)
> 用户可能说:"请用n8n内容转换工作流帮我转化这篇文章<文件名>"
### N8N 配置信息
- **N8N_BASE_URL**: `https://n8n.ishenwei.online`(从 Ubuntu2 `~/.openclaw/.env` 读取)
- **Webhook URL**: `https://n8n.ishenwei.online/webhook/<Webhook Path>`
### ⚠️ 执行时间与等待规范
- **执行时间**: 每次触发 webhook 后,需要等待 **4-5 分钟** 才能得到结果
- **禁止频繁请求**: 触发 webhook 后,**不要**连续发送多个请求或频繁轮询
- **正确做法**: 触发一次 → 等待 4-5 分钟 → 再检查 content-out 目录结果
- **失败标志**: 如果等了 5+ 分钟还没结果,再检查是否有问题
### 目录结构
| 用途 | MacMini 路径 | Ubuntu2 路径 |
| -------- | -------------------------------------------------------- | ------------------------------------------ |
| 源文件目录 | `/Users/weishen/Workspace/nexus/openclaw/content-queue/` | — |
| n8n 文件目录 | — | `/home/shenwei/docker/n8n/n8n_data/files/` |
| 输出目录 | `/Users/weishen/Workspace/nexus/openclaw/content-out/` | — |
### 执行步骤
#### 步骤 1复制源文件到 Ubuntu2
```bash
scp /Users/weishen/Workspace/nexus/openclaw/content-queue/<文件名> ubuntu2:/home/shenwei/docker/n8n/n8n_data/files/<文件名>
```
#### 步骤 2触发 Webhook
```bash
curl -X POST "<N8N_BASE_URL>/webhook/content-translation-v6" \
  -H "Content-Type: application/json" \
  -d '{
    "note_name": "<文件名>",
    "source_path": "/Users/weishen/Workspace/nexus/openclaw/content-queue/<文件名>",
    "output_name": "<文件名去掉后缀>"
  }'
```
#### 步骤 3等待执行完成
- 成功标志:返回 `{"ok":true}` 且 HTTP 200
- N8N 会通过 Telegram bot 发送完成通知
#### 步骤 4复制输出文件到 MacMini
```bash
scp ubuntu2:/home/shenwei/docker/n8n/n8n_data/files/<输出文件名> /Users/weishen/Workspace/nexus/openclaw/content-out/<输出文件名>
```
#### 步骤 5清理 Ubuntu2 临时文件
```bash
ssh ubuntu2 "rm /home/shenwei/docker/n8n/n8n_data/files/<输入文件名>"
ssh ubuntu2 "rm /home/shenwei/docker/n8n/n8n_data/files/<输出文件名>"
```
### n8n 工作流速查表
| 工作流 | Webhook Path | 输入文件规则 | 输出文件规则 | 通知方式 |
| ---- | ------------------------ | -------------------- | ------------------------- | -------- |
| 内容转化 | `content-translation-v6` | `content-queue/*.md` | `content-out/*_output.md` | Telegram |
## 19.Ubuntu Docker 通过 proxychains4 走代理拉取镜像 (2026-04-05)
### 问题背景
Ubuntu1/2 服务器直连 Docker Hub 的 443 端口被封,导致 `docker pull/build` 超时。Ubuntu1/2 上已安装 `proxychains4`,可用于将 Docker 的 TCP 连接通过 SOCKS5 代理转发。
### 验证 proxychains4 是否可用
```bash
ssh ubuntu1 'proxychains4 curl -s -o /dev/null -w "HTTP %{http_code}" --max-time 8 https://registry-1.docker.io/v2/'
ssh ubuntu2 'proxychains4 curl -s -o /dev/null -w "HTTP %{http_code}" --max-time 8 https://registry-1.docker.io/v2/'
# 预期输出: HTTP 401 (TCP 接通,认证失败表示通道打通)
```
### Docker pull 走代理
```bash
ssh ubuntu1 'proxychains4 docker pull <image>:<tag>'
ssh ubuntu2 'proxychains4 docker pull <image>:<tag>'
```
### Docker build 走代理
```bash
ssh ubuntu1 'proxychains4 docker build --pull=false -t <image>:<tag> <dockerfile-path>'
ssh ubuntu2 'proxychains4 docker build --pull=false -t <image>:<tag> <dockerfile-path>'
```
### 注意事项
- **SOCKS5 vs HTTP**: Xray/V2Ray 通常提供 SOCKS5 代理proxychains4 在 TCP 层转发流量,不依赖 HTTP 代理设置
- **--pull=false**: 在已有本地镜像时使用,避免 build 过程中再次拉取基础镜像(耗时且仍可能失败)
- **apt-get 不走代理**: Docker build 过程中 apt-get install 走的是直连 Debian 源,不受影响
- **Docker daemon vs client**: proxychains4 包裹的是 docker 命令,而非 dockerd 守护进程
## 20. memory-lancedb-pro 场景指令手册
### 概述
基于 LanceDB 的长期记忆系统,支持向量+BM25 混合检索、LLM 智能分类、Weibull 衰减。六种分类:`fact` `entity` `preference` `decision` `reflection` `other`。
| 分类 | 适用场景 |
|------|---------|
| `fact` | 客观事实、知识 |
| `entity` | 实体、人物、项目 |
| `preference` | 用户偏好、设置 |
| `decision` | 决策记录、结论 |
| `reflection` | 反思、复盘 |
| `other` | 其他 |
### 场景一:列出记忆
**你说:** "列出 memory-lancedb-pro 记忆"
**Agent 调用:** `memory_list(limit=20)`
**返回:**
```
• [fact] 用户偏好 MacBook Pro 作为开发机 (0.9)
• [entity] NAS 照片项目共 283,801 文件 (0.8)
• [decision] Memory-Pro 选用 nomic-embed-text (0.7)
...
```
---
### 场景二:搜索记忆
**你说:** "搜索 memory-lancedb-pro 里有没有关于 xxx 的记忆"
**Agent 调用:** `memory_recall(query="xxx", limit=5)`
**返回:**
```
[2 条相关]
1. [entity|0.8] NAS照片整理项目2026-03-31启动...
2. [other|0.6] ...
```
---
### 场景三:存储记忆
**你说:** "帮我记住 xxx"
**Agent 调用:** `memory_store(text="xxx", category="fact", importance=0.8)`
**返回:** `✅ 已存储 [fact] "xxx" (0.8)`
---
### 场景四:更新记忆
**你说:** "帮我更新记忆,改为 xxx"
**Agent 调用:** `memory_update(memoryId="<ID>", text="新内容")`
**返回:** `✅ 已更新 ID: a2d1fb54`
---
### 场景五:删除记忆
**你说:** "帮我删除 xxx 这条记忆"
**Agent 调用:**
```
memory_recall(query="xxx") # 先确认
memory_forget(memoryId="<找到的ID>") # 再删除
```
**返回:** `✅ 已删除 ID: a2d1fb54`
---
### 场景六:查询统计
**你说:** "memory-lancedb-pro 有多少条记忆"
**Agent 调用:** `memory_stats()`
**返回:** `总计146 条 / other:69 / fact:25 / entity:19 / ...`
---
### 快速对照表
| 你的需求 | Agent 调用 | 关键参数 |
|---------|-----------|---------|
| 列出记忆 | `memory_list` | `limit`, `scope`, `category` |
| 搜索记忆 | `memory_recall` | `query`, `limit` |
| 记住新内容 | `memory_store` | `text`, `category`, `importance` |
| 更新已有记忆 | `memory_update` | `memoryId`, `text` |
| 删除记忆 | `memory_forget` | `memoryId` 或 `query` |
| 看有多少条 | `memory_stats` | `scope` |
## 21. Hermes Agent (Ubuntu2) (2026-04-12)
### 概述
Hermes Agent 是 Nous Research 开发的自改进 AI agent支持 Telegram/Discord/Slack 等消息平台。
- **安装位置**: `~/.hermes/hermes-agent/`
- **systemd 服务**: `hermes-gateway.service`(已 enablelinger 已开启)
### 配置文件
| 文件 | 位置 |
|------|------|
| 环境变量 | `~/.hermes/hermes-agent/.env` |
| 主配置 | `~/.hermes/config.yaml` |
| systemd service | `~/.config/systemd/user/hermes-gateway.service` |
### 代理配置
Hermes Gateway 通过代理访问 Telegram代理写在 systemd service 文件中:
```ini
Environment="ALL_PROXY=http://127.0.0.1:10808"
Environment="HTTPS_PROXY=http://127.0.0.1:10808"
Environment="HTTP_PROXY=http://127.0.0.1:10808"
```
### 重启步骤
```bash
# 仅重启(无需重载 systemd
systemctl --user restart hermes-gateway
# 重载 systemd修改 service 文件后必须)
systemctl --user daemon-reload && systemctl --user restart hermes-gateway
```
### 状态与日志
```bash
# 查看状态
systemctl --user status hermes-gateway
hermes gateway status
# 查看日志
journalctl --user -u hermes-gateway -n 30 # systemd journal
tail -30 ~/.hermes/logs/agent.log # agent 日志
tail -30 ~/.hermes/logs/gateway.log # gateway 日志
```
正常启动标志:`[Telegram] Connected to Telegram (polling mode)` / `✓ telegram connected`
### Bot Token
- **Bot**: 云智 bot
- **Token**: `8653044481:AAFmqdOBOFeQB6JI3M0977rLgj0s28mvbeY`
- **用户名**: `@shenwei_ubuntu2_yunzhi_bot`
- 更换 bot编辑 `~/.hermes/hermes-agent/.env` 中的 `TELEGRAM_BOT_TOKEN`
## 22. Claude Code 调用方法OpenClaw & Hermes Terminal
### 核心模式
**Print Mode推荐** — 适合绝大多数任务:
```bash
cat << 'TASK_END' | claude -p print \
--dangerously-skip-permissions \
--add-dir ~/.claude/skills/[技能名] \
--add-dir [项目源码路径] \
--max-turns 30 \
2>&1
[任务描述]
TASK_END
```
**TMUX 交互模式** — 适合超长任务:
```bash
tmux new-session -d -s claude-work -x 140 -y 40
tmux send-keys -t claude-work 'claude --permission-mode bypassPermissions' Enter
sleep 8 && tmux capture-pane -t claude-work -p # 确认已启动后即可发送任务
```
> 用 `--permission-mode bypassPermissions` 可直接跳过信任目录 + bypass 权限确认两步
### 关键参数
| 参数 | 作用 |
| ------------------------------------- | ------------------------------------------- |
| `--permission-mode bypassPermissions` | 直接设置 bypass 模式跳过所有交互确认包括信任目录、bypass 权限提示) |
| `--dangerously-skip-permissions` | 跳过文件写入/网络确认提示(必写,否则卡住) |
| `--add-dir <路径>` | 添加可访问目录,可多次使用 |
| `--max-turns N` | 最大迭代次数,建议 20-30 |
| `--bare` | 跳过插件/MCP/CLAUDE.md 加载,最快启动 |
| `-p print` | 非交互单次执行模式 |
### 任务文本结构
```
1. 告诉 Claude Code 要做什么
2. 告诉它用哪个 skill
3. 告诉它输出文件路径
4. 如果需要格式转换,明确写出转换命令
5. 最后要求输出 "done: 文件路径"
```
### Skill 加载
`--add-dir <技能目录>` 会自动扫描该目录下的 `SKILL.md` 和 `.claude/skills/`,触发条件自动匹配激活。
### 常见坑点
1. **不写 `--dangerously-skip-permissions`** → 文件写入被阻塞
2. **命令行参数直接传任务** → 特殊字符引发 shell 转义错误,用 stdin 管道
3. **`max-turns` 太小** → 任务没跑完就超时,复杂任务设 25-30
4. **环境变量 `ANTHROPIC_API_KEY`** → 需在 settings.json 或环境变量中配置
## 23. yt-dlp (网络视频下载) (2026-04-15)
### 功能
从 Internet 下载视频文件,支持 Twitter/X、YouTube 等多种平台。
### 安装位置
```
/opt/homebrew/bin/yt-dlp
```
### 基本用法
#### 下载并存放到挂载盘
```bash
# 直接下载到目标目录
yt-dlp -o "/Users/weishen/mnt/volume2/knowledgebase/%(title)s.%(ext)s" "视频URL"
# 或者先下载到本地,再移动
yt-dlp "视频URL"
mv video.mp4 /Users/weishen/mnt/volume2/knowledgebase/
# 如果需要指定格式
yt-dlp -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]" \
-o "/Users/weishen/mnt/volume2/knowledgebase/%(title)s.%(ext)s" "视频URL"
```
### 常用选项
| 选项 | 说明 |
|------|------|
| `-o filename` | 指定输出文件名 |
| `--audio-format mp3` | 只下载音频并转为 MP3 |
| `--write-auto-sub` | 下载自动生成的字幕 |
### 应用场景
- Twitter/X 视频链接下载
- YouTube 视频下载
- 其他支持的视频平台
### ⚠️ 注意事项
- 大文件通过 SSH pipe 传输时可能有连接问题
- 视频默认保存到挂载盘目录 `~/mnt/volume2/knowledgebase/`
- 临时文件建议放在 `~/.openclaw/temp/<agentId>/attachments/` 目录
## 24. OpenClaw Cron Job 创建规范
### 标准模板
```bash
openclaw cron add \
  --agent <agentId> \
  --name "<job-name>" \
  --every <duration> \        # 如 30m, 1h, 4h
  --announce \
  --channel telegram \
  --to "5038825565" \         # ⚠️ 必须指定,否则投递失败
  --description "<描述>" \
  --message "<执行指令>"
```
### ⚠️ 关键规则
- `--announce --channel telegram` 必须同时指定 `--to "5038825565"`
- 不带 `--to` 时 Telegram 投递会静默失败(无报错),导致 cron 看起来正常但用户收不到通知
- **禁止使用 launchd / crontab / systemd 管理定时任务,必须用 OpenClaw cron**
## 25. Obsidian CLI (官方) (2026-04-16)
### 概述
官方 Obsidian CLI集成在 Obsidian 应用中,支持读取、搜索、创建、修改笔记等操作。**需要 Obsidian 应用在运行状态**。
### 安装信息
- **路径**: `/Applications/Obsidian.app/Contents/MacOS/obsidian-cli`
- **版本**: `1.12.7`
- **命令**: `obsidian`(已软链到 `/opt/homebrew/bin/obsidian`
### 前置要求
- Obsidian 应用必须**已在运行**
- 默认 Vault: `/Users/weishen/Workspace/nexus`
### 核心命令
- 请读取obsidian-cli技能 `/Users/weishen/.openclaw/skills/obsidian-cli/SKILL.md`
### ⚠️ 注意事项
- Obsidian 应用必须运行才能使用 CLI
- 如果 Obsidian 未运行,会报错或无响应
- 内容中换行用 `\n`,制表符用 `\t`
## 26. OpenClaw 发送图片到 Telegram (2026-04-17)
### 功能
通过 OpenClaw 将本地图片发送到 Telegram。
### 前置要求
- Telegram bot 已配置
- 目标 chat ID比利哥: 5038825565
### 操作步骤
#### 1. 复制图片到 media 目录
```bash
cp /path/to/image.png ~/.openclaw/media/inbound/
```
#### 2. 通过 OpenClaw 发送
```bash
/opt/homebrew/bin/openclaw message send \
--account bot1 \
--channel telegram \
--target 5038825565 \
--media ~/.openclaw/media/inbound/image.png \
--message "说明文字"
```
### 参数说明
| 参数 | 说明 |
|------|------|
| `--account` | Telegram bot 账号(如 bot1 |
| `--channel telegram` | 固定为 telegram |
| `--target` | 目标 chat ID比利哥: 5038825565 |
| `--media` | 图片路径 |
| `--message` | 说明文字 |
### 示例
```bash
# 复制并发送
cp ~/Downloads/photo.jpg ~/.openclaw/media/inbound/
/opt/homebrew/bin/openclaw message send --account bot1 --channel telegram --target 5038825565 --media ~/.openclaw/media/inbound/photo.jpg --message "📷 测试图片"
```
### 注意事项
- 图片支持 jpg、png、gif 等常见格式
- 临时文件放在 `~/.openclaw/media/inbound/` 目录
- 文件名避免中文,建议用英文或数字
## 27. update-agents-tools.py 一键更新所有 Agent 的 TOOLS.md
### 脚本位置
```
~/.openclaw/scripts/update-agents-tools.py
```
### 功能
通过 Obsidian CLI 读取权限矩阵,自动解析每个 Agent 的章节分配,再从标准模板提取对应章节内容,一键更新所有 Agent 的 TOOLS.md 文件。
### 工作流程
1. 📖 通过 `obsidian read` 读取 `TOOLS权限矩阵.md`
2. 📊 解析 markdown 表格,自动发现所有 Agent 及其章节
3. 📄 从 `TOOLS标准模板.md` 提取各章节内容
4. ✏️ 写入所有 Agent 的 TOOLS.md支持本地和 SSH 远程路径)
### 用法
```bash
python3 ~/.openclaw/scripts/update-agents-tools.py
```
### 特点
- **无需人工数表格**:程序自动解析矩阵,零失误
- **自动发现 Agent**:从表头动态提取,不依赖硬编码
- **支持远程**:自动同步到 Ubuntu1/2 上的 Agent 目录
- **幂等执行**:重复运行结果一致
## 28. Grafana 服务器监控面板 (2026-04-17)
### 访问地址
| 服务器 | 监控地址 |
|-------|---------|
| MacMini | http://192.168.3.45:3000/d/macmini-cpu-mem/node-exporter-cpu-and-e58685-e5ad98-e79b91-e68ea7?orgId=1&refresh=5s&var-node=192.168.3.189:9100 |
| Ubuntu1 | http://192.168.3.45:3000/d/macmini-cpu-mem/node-exporter-cpu-and-e58685-e5ad98-e79b91-e68ea7?orgId=1&refresh=5s&var-node=192.168.3.47:9100 |
| Ubuntu2 | http://192.168.3.45:3000/d/macmini-cpu-mem/node-exporter-cpu-and-e58685-e5ad98-e79b91-e68ea7?orgId=1&refresh=5s&var-node=192.168.3.45:9100 |
### 认证信息
- **用户名**: `admin`
- **密码**: `admin123`
### 访问方式
通过 `agent-browser` 技能访问 Grafana 页面:
1. 使用 `agent-browser` 打开上述 URL
2. 如需登录,输入用户名 `admin` 和密码 `admin123`
3. 使用截图功能对页面进行截屏
4. 通过 Telegram 发送给用户
### 截图示例命令
```bash
# 使用 agent-browser 打开并截图
# 参考 agent-browser 技能文档进行操作
```