命令结构
OpenClaw CLI 使用 Commander.js 组织命令,约 183 个文件实现了完整的命令树。
程序构建
Source: src/cli/program/build-program.ts
typescript
// src/cli/program/build-program.ts (simplified)
function buildProgram(): Command {
const program = new Command("openclaw");
// 1. Create program context
createProgramContext(program);
// 2. Register all commands
registerProgramCommands(program);
// 3. Configure help output
configureProgramHelp(program);
// 4. Register pre-action hooks
registerPreActionHooks(program);
return program;
}命令树
主要命令组
gateway — Gateway 管理
openclaw gateway start # 启动 Gateway
openclaw gateway stop # 停止 Gateway
openclaw gateway status # 查看状态
openclaw gateway restart # 重启Source: src/commands/gateway-cli.ts
send — 消息发送
openclaw send -t telegram -c <chatId> "Hello"Source: src/commands/send-cli.ts
channels — 通道管理
openclaw channels login telegram # 登录 Telegram
openclaw channels logout discord # 登出 Discord
openclaw channels list # 列出所有通道
openclaw channels status # 查看通道状态Source: src/commands/channels-cli.ts
config — 配置管理
openclaw config get # 查看完整配置
openclaw config set key value # 设置配置项
openclaw config patch '{"key":"val"}' # JSON 补丁Source: src/commands/config-cli.ts
plugins — 插件管理
openclaw plugins install <name> # 安装插件
openclaw plugins list # 列出已安装
openclaw plugins enable <name> # 启用
openclaw plugins disable <name> # 禁用Source: src/commands/plugins-cli.ts
skills — 技能管理
openclaw skills install <name> # 安装技能
openclaw skills list # 列出技能
openclaw skills remove <name> # 移除技能Source: src/commands/skills-cli.ts
其他命令
| 命令 | 说明 | 源文件 |
|---|---|---|
cron | 定时任务管理 | cron-cli.ts |
nodes | 远程节点管理 | nodes-cli.ts |
memory | 记忆搜索和管理 | memory-cli.ts |
hooks | Hook 调试和列表 | hooks-cli.ts |
update | 版本更新 | update-cli.ts |
doctor | 诊断和修复 | doctor-cli.ts |
Pre-Action Hooks
Commander.js 的 pre-action hook 在命令执行前运行:
typescript
// Pre-action hooks (simplified)
function registerPreActionHooks(program: Command): void {
program.hook("preAction", async () => {
// Load config
// Initialize dependencies
// Check prerequisites
});
}小结
- Commander.js 构建的命令树,约 183 个文件
buildProgram()统一创建上下文、注册命令、配置帮助- 主要命令组:gateway、send、channels、config、plugins、skills、nodes
- Pre-action hooks 在命令执行前初始化依赖和配置
下一章:依赖注入