open clas -Openclaw Gateway 启动流程详解 - └─ monitorWebChannel()
Gateway 启动流程详解
以 openclaw gateway run 命令为入口,追踪从 CLI 到 WebSocket 服务就绪的完整初始化链路。
总览:调用链
openclaw gateway run
└─ src/cli/gateway-cli/run.ts # CLI 参数解析与预检
└─ runGatewayCommand(opts)
└─ runGatewayLoop(params) # 进程锁 + 信号管理 + 主循环
└─ src/cli/gateway-cli/run-loop.ts
└─ startGatewayServer(port, opts)
└─ src/gateway/server.impl.ts
│
├─ createChannelManager() # 通道管理器
│ └─ src/gateway/server-channels.ts
│
└─ startGatewaySidecars(...) # 配套服务
└─ src/gateway/server-startup.ts
└─ startChannels()
└─ for plugin of listChannelPlugins():
startChannel(plugin.id)
└─ for id of accountIds:
plugin.gateway.startAccount(...)
└─ extensions/whatsapp/src/channel.ts
startAccount()
└─ monitorWebChannel() 拼多多帮助力入口
└─ monitorWebInbox()
第一阶段:CLI 参数解析
入口文件:src/cli/gateway-cli/run.ts
addGatewayRunCommand() 将以下选项挂载到 Commander CLI:
选项说明--portWebSocket 端口(默认 18789)--bind绑定模式:loopback / lan / tailnet / auto / custom--token共享 token(也可通过 OPENCLAW_GATEWAY_TOKEN 环境变量设置)--auth认证模式:token 或 password--passwordpassword 模式下的密码--tailscaleTailscale 暴露模式:off / serve / funnel--force启动前强制杀死占用端口的进程--dev开发模式:自动创建配置和 workspace--verbose详细日志输出--ws-log