OpenClaw 体系资料汇编
- 整合时间:2026-04-17
- 整合范围:
OpenClaw体系文件夹内 5 个 Markdown 文档 - 说明:以下内容按原文档顺序合并,保留原始内容,不做删减。
收录文档
OpenClaw体系/目录.mdOpenClaw体系/OpenClaw工作区上下文注入方案.mdOpenClaw体系/OpenClaw完整自动机制一览.mdOpenClaw体系/OpenClaw现成轮子全览.mdOpenClaw体系/Webhooks详解.md
原文档 1: 目录
原路径:OpenClaw体系/目录.md
OpenClaw体系目录
当前文档
原文档 2: OpenClaw工作区上下文注入方案
原路径:OpenClaw体系/OpenClaw工作区上下文注入方案.md
Workspace Context
你说得对!Hook 确实无法强制 AI 在生成代码前阅读规范。但 OpenClaw 有更好的机制:
解决方案:Workspace Context 文件
OpenClaw 会在 每次对话开始前 自动加载 workspace 下的上下文文件:
| 文件 | 作用 | 加载时机 |
|---|---|---|
AGENTS.md |
Agent 行为指南 | 每次对话 |
SOUL.md |
Agent "灵魂"/ 人设 | 每次对话 |
BOOTSTRAP.md |
启动时加载的上下文 | 启动时 |
USER.md |
用户偏好 | 每次对话 |
TOOLS.md |
工具使用说明 | 每次对话 |
这才是正确的方案 —— 把规范写入这些文件,AI 就会在每次对话时自动 "记住"!
原文档 3: OpenClaw完整自动机制一览
原路径:OpenClaw体系/OpenClaw完整自动机制一览.md
📁 Workspace Context 文件(自动注入)
| 文件 | 作用 | 加载时机 |
|---|---|---|
AGENTS.md |
总控文件,告诉 AI 每次会话要读什么 | 每次对话开始 |
SOUL.md |
AI 的核心价值观、安全边界 | 每次对话开始 |
USER.md |
用户偏好、项目规范 | 每次对话开始 |
IDENTITY.md |
AI 的名字、性格、头像 | 每次对话开始 |
AUTO_SCRIPTS.md |
项目强制规范 | 每次对话开始 |
MEMORY.md |
长期记忆(仅主会话加载) | 主会话时 |
memory/YYYY-MM-DD.md |
日记,短期上下文 | 每次对话开始 |
💓 Heartbeat 机制(定期主动检查)
触发方式:Gateway 定期发送心跳消息
文件:HEARTBEAT.md
用途:让 AI 主动做事,而不是等用户问
- 检查邮件、日历
- 检查天气
- 主动提醒
当前状态:你的 HEARTBEAT.md 是空的(只有注释),所以每次心跳 AI 只会回复 HEARTBEAT_OK
🎬 Bootstrap 机制(首次启动引导)
触发时机:新 workspace 首次启动
文件:BOOTSTRAP.md
用途:引导 AI 和用户完成初始设置
- 确定 AI 名字/性格
- 了解用户偏好
- 设置联系方式
当前状态:你的 BOOTSTRAP.md 还在,AI 每次启动都会看到它。配置完成后应该删除这个文件。
🪝 Hook 机制(事件触发)
你已经知道这个了,但我列完整:
| Hook | 触发时机 | 你的配置 |
|---|---|---|
code-guard |
代码写入前/后 | ✓ 已配置 |
task-logger |
任务执行后 | ✓ 已配置 |
self-heal |
错误发生时 | ✓ 已配置 |
storage-protect |
存储操作时 | ✓ 已配置 |
sender-trigger |
消息发送时 | ✓ 已配置 |
📊 对比总结
| 机制 | 触发时机 | 能做什么 | 不能做什么 |
|---|---|---|---|
| Workspace Context | 对话开始前 | 注入规范、记忆、偏好 | 无法动态执行代码 |
| Heartbeat | 定时触发 | 主动检查、主动提醒 | 需要配置任务清单 |
| Bootstrap | 首次启动 | 引导初始化设置 | 只运行一次 |
| Hook | 事件发生后 | 验证、修复、日志记录 | 无法阻止事件发生 |
🔧 你当前的问题
BOOTSTRAP.md 还在!这个文件应该在初始化完成后删除。现在每次对话 AI 都会看到"你应该引导用户设置名字和性格"的提示。
要我帮你删掉吗?或者你想保留它重新初始化身份?
原文档 4: OpenClaw现成轮子全览
原路径:OpenClaw体系/OpenClaw现成轮子全览.md
一、事件驱动系统
| 组件 | 说明 | 文件位置 |
|---|---|---|
| Hooks | 事件驱动的自动化系统 | ~/.openclaw/hooks/ 或 workspace/hooks/ |
| Webhooks | HTTP 端点,外部系统可触发 | Gateway /hooks/<name> |
| Cron | 定时任务调度器 | openclaw cron |
触发流程:
外部系统 → Webhook → Gateway → Hook → 执行任务
定时器 → Cron → Gateway → Hook → 执行任务
用户操作 → 内部事件 → Hook → 执行任务
二、能力扩展系统
| 组件 | 说明 | 数量 |
|---|---|---|
| Skills | 预定义的能力/工具包 | 67个可用,20个就绪 |
| Plugins | 运行时扩展,可注册工具和钩子 | 已安装飞书、企微等 |
| Extensions | 内置扩展模块 | 渠道、存储等 |
## 查看可用 Skills
openclaw skills list
## 查看已安装 Plugins
openclaw plugins list三、渠道/通道系统
| 渠道 | 状态 | 说明 |
|---|---|---|
| Telegram | ✓ | Bot 模式 |
| ✓ | Web 登录配对 | |
| 飞书/Lark | ✓ | 内置 + 插件 |
| 企业微信 | ✓ | 插件支持 |
| 钉钉 | ✓ | 社区插件 |
| Discord | ✓ | Bot 模式 |
| Slack | ✓ | Bot 模式 |
| iMessage | ✓ | macOS 专用 |
| ✓ | 扫码登录 |
openclaw channels list # 查看已配置渠道
openclaw channels login --channel whatsapp # 登录渠道
openclaw channels status --probe # 检测渠道状态四、记忆系统
| 功能 | 说明 |
|---|---|
| Memory Search | 向量搜索,语义检索历史对话 |
| Memory Index | 自动索引 workspace/memory/ |
| Session Memory | 会话重置时自动保存对话 |
openclaw memory status # 查看索引状态
openclaw memory search "关键词" # 语义搜索
openclaw memory index --force # 强制重建索引五、浏览器自动化
| 功能 | 说明 |
|---|---|
| Snapshot | AI 友好的页面快照(带 ref 引用) |
| Click/Type/Hover | 通过 ref 操作元素 |
| Screenshot/PDF | 截图、导出 PDF |
| Evaluate | 执行 JavaScript |
| Profiles | 多浏览器配置文件管理 |
openclaw browser start # 启动浏览器
openclaw browser open https://example.com
openclaw browser snapshot # 获取页面快照
openclaw browser click 12 # 点击 ref=12 的元素
openclaw browser type 23 "hello" # 输入文本六、Agent 管理
| 功能 | 说明 |
|---|---|
| Isolated Agents | 隔离的 agent 实例(独立 workspace/auth) |
| Routing Bindings | 消息路由绑定(不同用户/群组到不同 agent) |
| Identity | 自定义 agent 名称、主题、emoji |
openclaw agents list # 列出所有 agent
openclaw agents add # 添加新 agent
openclaw agents bind # 绑定路由规则七、执行安全
| 组件 | 说明 |
|---|---|
| Exec Approvals | 命令执行审批白名单 |
| Allowlist | 按 agent 配置允许的命令 |
| Pairing | 安全配对机制,防止未授权访问 |
openclaw approvals get # 查看审批配置
openclaw approvals allowlist # 编辑白名单
openclaw pairing approve feishu <code> # 批准配对请求八、Workspace 上下文文件
| 文件 | 用途 |
|---|---|
| AGENTS.md | Agent 行为指南 |
| SOUL.md | Agent "灵魂"/人设 |
| IDENTITY.md | 身份定义 |
| TOOLS.md | 工具使用说明 |
| BOOTSTRAP.md | 启动时加载的上下文 |
| HEARTBEAT.md | 心跳/状态检查 |
| USER.md | 用户偏好设置 |
| memory/*.md | 持久化记忆文件 |
九、节点服务
| 组件 | 说明 |
|---|---|
| Node Host | 无头服务,可在远程服务器运行 |
| Gateway | 中央控制平面,HTTP+WebSocket 服务 |
| Tailscale | 内网穿透/远程访问 |
openclaw gateway status # Gateway 状态
openclaw node run # 运行节点服务十、内置工具函数
Agent 可直接调用的工具:
| 类别 | 工具 |
|---|---|
| 文件操作 | read, write, edit, search, glob |
| Shell | exec, bash 命令执行 |
| 网络 | fetch, web search |
| 浏览器 | browser_* 系列 |
| 消息 | send_message, read_messages |
架构总览
┌─────────────────────────────────────────────────────────────────┐
│ OpenClaw 架构 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 外部触发 │
│ ├── Channels (Telegram/WhatsApp/飞书/钉钉...) │
│ ├── Webhooks (HTTP 端点) │
│ └── Cron (定时任务) │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────┐ │
│ │ Gateway (5000) │ │
│ │ ┌─────────┬─────────┬─────────┐ │ │
│ │ │ Hooks │ Plugins │ Skills │ │ │
│ │ │ 事件驱动 │ 运行扩展 │ 能力包 │ │ │
│ │ └─────────┴─────────┴─────────┘ │ │
│ └─────────────────┬───────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────┐ │
│ │ Agent (Pi) │ │
│ │ ┌─────────────────────────────────┐ │ │
│ │ │ Workspace Context │ │ │
│ │ │ AGENTS.md / SOUL.md / TOOLS.md │ │ │
│ │ │ memory/ / skills/ / hooks/ │ │ │
│ │ └─────────────────────────────────┘ │ │
│ └─────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
快速参考命令
## 系统状态
openclaw status --all # 完整状态
openclaw doctor # 健康检查
## 配置管理
openclaw config get <key> # 获取配置
openclaw config set <key> <val> # 设置配置
## 消息操作
openclaw message send --to +123 --message "Hi"
openclaw message read --from +123
## 日志查看
openclaw logs --follow # 实时日志
openclaw channels logs # 渠道日志
## Dashboard
openclaw dashboard # 打开控制面板原文档 5: Webhooks详解
原路径:OpenClaw体系/Webhooks详解.md
一、什么是 Webhooks?
Webhooks 是 OpenClaw Gateway 提供的 HTTP 端点,让外部系统可以通过 HTTP 请求触发 OpenClaw 内部的操作。
外部系统 ──HTTP POST──► Gateway /hooks/<name> ──► 执行对应操作二、Webhooks vs Hooks 区别
| 特性 | Hooks | Webhooks |
|---|---|---|
| 触发方式 | 内部事件驱动 | 外部 HTTP 请求 |
| 入口 | 自动触发 | POST /hooks/<name> |
| 用途 | 响应系统内部事件 | 接收外部系统通知 |
| 配置 | openclaw.json → hooks.internal |
openclaw.json → hooks.mappings |
┌─────────────────────────────────────────────────────────────┐
│ 触发来源 │
├─────────────────────────────────────────────────────────────┤
│ │
│ Hooks (内部事件) Webhooks (外部请求) │
│ ├── message:received ├── POST /hooks/gmail │
│ ├── command:new ├── POST /hooks/github │
│ ├── gateway:startup └── POST /hooks/custom │
│ └── agent:bootstrap │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────────────────────────┐ │
│ │ Gateway │ │
│ └─────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘三、配置 Webhooks
在 openclaw.json 中配置:
{
"hooks": {
"enabled": true,
"token": "your-shared-secret",
"path": "/hooks",
"mappings": [
{
"name": "gmail",
"url": "https://gmail.googleapis.com/...",
"model": "coze/auto"
},
{
"name": "custom-hook",
"handler": "./workspace/hooks/custom/index.js"
}
]
}
}四、使用场景
1. Gmail 邮件通知
## 设置 Gmail Pub/Sub webhook
openclaw webhooks gmail setup
## 运行监听服务
openclaw webhooks gmail run外部流程:
Gmail 收到新邮件 → Pub/Sub 推送 → POST /hooks/gmail → Agent 处理邮件2. GitHub Webhook
GitHub 仓库事件 → POST /hooks/github → Agent 执行 CI/CD 操作3. 自定义集成
## 任何支持 webhook 的服务都可以调用
curl -X POST http://your-gateway:5000/hooks/custom \
-H "Authorization: Bearer your-token" \
-H "Content-Type: application/json" \
-d '{"event": "deploy", "status": "success"}'五、请求格式
POST /hooks/<name>
Authorization: Bearer <hooks.token>
Content-Type: application/json
{
"event": "string",
"data": { ... },
"timestamp": "2026-03-16T00:00:00Z"
}六、内置 Webhook 支持
| Webhook | 说明 |
|---|---|
| Gmail | 通过 Google Pub/Sub 接收邮件通知 |
| 自定义 | 在 mappings 中定义,指向 Hook 脚本 |
七、安全机制
- Token 认证:请求必须携带有效的
hooks.token - Agent 白名单:可限制哪些 agent 可以被触发
- HTTPS:生产环境建议使用 HTTPS
{
"hooks": {
"token": "secure-token-here",
"allowedAgentIds": ["main", "hooks"]
}
}八、完整示例:创建自定义 Webhook
// workspace/hooks/custom-webhook/index.js
module.exports.handler = async function(event) {
const { event: eventType, data } = event;
console.log(`收到 Webhook: ${eventType}`);
console.log('数据:', JSON.stringify(data));
// 处理逻辑
if (eventType === 'deploy') {
// 执行部署后操作
}
return { processed: true };
};配置:
{
"hooks": {
"mappings": [
{
"name": "deploy",
"handler": "./workspace/hooks/custom-webhook/index.js"
}
]
}
}调用:
curl -X POST http://localhost:5000/hooks/deploy \
-H "Authorization: Bearer your-token" \
-d '{"event": "deploy", "data": {"app": "myapp"}}'九、与 Hooks 的协作
Webhooks 可以触发 Hooks,形成完整自动化链:
外部系统
│
▼
Webhook (POST /hooks/xxx)
│
▼
触发内部 Hook
│
▼
执行任务 (runner.js / scripts)就是说,比如我可以设定微信接收到某人的消息时自动触发这个任务对吧
思考过程
是的!但这个场景用的是 Hooks,不是 Webhooks。让我解释一下:
场景对比
❌ Webhooks: 外部系统 → HTTP 请求 → Gateway
(比如:GitHub 通知、Gmail 邮件)
✅ Hooks: 内部事件 → 自动触发 → 执行任务
(比如:微信收到消息 → 触发任务)实现方式
你已经有了基础的 Hook,只需要增强过滤逻辑:
方案:修改 message-received-check-state Hook
// workspace/hooks/message-received-check-state/index.js
// 配置特定发送者和对应任务
const CONFIG = {
// ...
// 特定发送者触发规则
senderTriggers: {
// 微信用户 ID 或手机号
'+8613800138000': {
name: '老板',
tasks: ['git-sync', 'tree-diagram'],
notify: true
},
'wxid_abc123': {
name: '重要客户',
tasks: ['step-trace'],
keywords: {
'紧急': { action: 'urgent', tasks: ['all'] },
'报告': { action: 'report', tasks: ['git-sync'] }
}
}
}
};
// Handler 中判断
module.exports.handler = async function(event) {
const { from, content } = event.context;
// 检查是否是特定发送者
const trigger = CONFIG.senderTriggers[from];
if (trigger) {
console.log(`[Hook] 检测到 ${trigger.name} 的消息`);
// 执行对应任务
const { runTasks } = require('../../../workspace/projects/novel-sync/任务日志/runner.js');
await runTasks(trigger.tasks);
// 可选:回复确认
if (trigger.notify) {
event.messages.push(`✓ 已自动执行: ${trigger.tasks.join(', ')}`);
}
}
};完整示例:创建 "特定发送者触发" Hook
创建文件
workspace/hooks/sender-trigger/index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
-
OpenClaw Hook: 特定发送者触发任务
-
触发时机:收到特定发送者的消息时
-
功能:根据发送者身份自动执行预设任务
-
@module hooks/sender-trigger
*/
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
// ============================================================
// 配置
// ============================================================
const CONFIG = {
// 运行器路径
runnerPath: path.join(__dirname, '../../../workspace/projects/novel-sync/任务日志/runner.js'),
// 日志目录
logDir: path.join(__dirname, '../../../workspace/projects/novel-sync/storage/trigger-logs'),
// 是否启用
enabled: true,
// 特定发送者触发规则
// 格式: { 发送者ID: { name, triggers } }
senderRules: {
// 示例:微信用户(替换为实际 ID)
// 'wxid_xxx': {
// name: '张三',
// triggers: {
// always: ['git-sync'], // 每条消息都执行
// keywords: {