macOS 上的 Gateway 生命周期

macOS 应用默认通过 launchd 管理 Gateway,而不是将 Gateway 作为子进程启动。它首先尝试连接到配置端口上已运行的 Gateway;如果无法访问,则通过外部 openclaw CLI(无嵌入式运行时)启用 launchd 服务。这为你提供了可靠的登录自动启动和崩溃重启功能。

子进程模式(Gateway 由应用直接启动)目前未使用。如果你需要与 UI 更紧密的耦合,请在终端中手动运行 Gateway。

默认行为(launchd)

  • 应用安装一个标记为 bot.molt.gateway 的用户级 LaunchAgent (或使用 --profile/OPENCLAW_PROFILE 时为 bot.molt.<profile>;支持旧版 com.openclaw.*)。
  • 当启用本地模式时,应用确保 LaunchAgent 已加载,并在需要时启动 Gateway。
  • 日志写入 launchd gateway 日志路径(在调试设置中可见)。

常用命令:

launchctl kickstart -k gui/$UID/bot.molt.gateway
launchctl bootout gui/$UID/bot.molt.gateway

使用命名 profile 时,将标签替换为 bot.molt.<profile>

未签名的开发构建

scripts/restart-mac.sh --no-sign 用于没有签名密钥时的快速本地构建。为了防止 launchd 指向未签名的 relay 二进制文件,它会:

  • 写入 ~/.openclaw/disable-launchagent

scripts/restart-mac.sh 的签名运行会在标记存在时清除此覆盖。手动重置:

rm ~/.openclaw/disable-launchagent

仅附加模式

要强制 macOS 应用永不安装或管理 launchd,使用 --attach-only(或 --no-launchd)启动。这会设置 ~/.openclaw/disable-launchagent,使应用仅附加到已运行的 Gateway。你可以在调试设置中切换相同的行为。

远程模式

远程模式永不启动本地 Gateway。应用使用 SSH 隧道连接到远程主机,并通过该隧道连接。

为什么我们偏好 launchd

  • 登录自动启动。
  • 内置重启/KeepAlive 语义。
  • 可预测的日志和监控。

如果将来再次需要真正的子进程模式,应将其记录为单独的、明确的仅开发模式。