Gateway Guard
Description
Ensures OpenClaw gateway auth consistency and can auto-prompt "continue" when a run error (Unhandled stop reason: error) appears in gateway logs. Use when checking or fixing gateway token/password mismatch, devicetokenmismatch errors, or before delegating to sub-agents.
Ensures OpenClaw gateway auth consistency and can auto-prompt "continue" when a run error (Unhandled stop reason: error) appears in gateway logs. Use when checking or fixing gateway token/password mismatch, devicetokenmismatch errors, or before delegating to sub-agents.
Gateway Guard
Keeps OpenClaw gateway authentication in sync with openclaw.json. Use when the user or agent sees gateway auth issues, device_token_mismatch, or needs to ensure the gateway is running with the correct token/password before spawning sub-agents.
Metadata: This skill uses always: false in _meta.json. It is not forced into every agent run; the orchestrator invokes it when needed (e.g. before delegating to sub-agents). Optional persistence (LaunchAgent) is installed only when you run the install scripts; see "Before installing" below.
Before installing
- - Backup
openclaw.json — The script may add or correct gateway.auth (token/password) when missing or wrong. Make a copy before running ensure --apply. - Test read-only first — Run
python3 scripts/gateway_guard.py status --json and python3 scripts/gateway_guard.py ensure --json (without --apply) to see what it would do before allowing restarts or config writes. - Understand
continue delivery — The watcher can run openclaw agent --message continue --deliver when a run error appears in gateway.log. Confirm that automatically sending that message is acceptable in your environment. - LaunchAgent is optional — Persistence (watcher every 30s) is installed only if you run
install_watcher.sh. The installer copies the plist from the skill directory into ~/Library/LaunchAgents and runs launchctl load; only run it if you accept that. The plist is included in this package: scripts/com.openclaw.gateway-guard.watcher.plist (and scripts/com.openclaw.gateway-guard.continue-on-error.plist). Ensure OPENCLAW_HOME and OPENCLAW_BIN resolve to your intended paths before installing the watcher. - Try in a non-production environment first if you are unsure.
Package contents (file manifest)
Included in this skill so installers do not error:
- -
scripts/gateway_guard.py — Main script (status, ensure, continue-on-error, watch). - INLINECODE21 — Installs the single combined LaunchAgent (token sync + continue-on-error).
- INLINECODE22 — Redirects to
install_watcher.sh. - INLINECODE24 — LaunchAgent plist template (installwatcher.sh copies and substitutes paths).
- INLINECODE25 — Legacy plist (optional; installwatcher.sh replaces with the combined watcher).
Usage
- - User or logs report "Gateway auth issue", "devicetokenmismatch", or "unauthorized"
- Before running the router and
sessions_spawn (orchestrator flow): check gateway status first - After installing or updating OpenClaw: verify gateway and config match
- When the TUI disconnects or won't connect: fix auth and restart gateway
- Run error (Unhandled stop reason: error): run
continue-on-error --loop (e.g. via LaunchAgent or cron) so the guard auto-sends "continue" to the agent when this appears in INLINECODE28
CODEBLOCK0
- - status — Report whether the running gateway's auth matches
openclaw.json. Exit 0 if ok, 1 if mismatch. - ensure — Same check; if mismatch and
--apply, restart the gateway with credentials from config. Writes gateway.auth to openclaw.json only when it is missing or wrong (never overwrites correct config). Use --wait after --apply to block until the gateway port is open (up to 30s), so clients can connect immediately after. - ensuregatewaythen.sh — Detect and connect automatically: ensures the gateway is running (starts it if needed, waits for port), then runs your command. Example:
ensure_gateway_then.sh openclaw tui or ensure_gateway_then.sh (just ensure and wait). - continue-on-error — When
gateway.log contains Unhandled stop reason: error (run error), send continue to the agent via openclaw agent --message continue --deliver. Use --once to check once and exit, or --loop to run every --interval seconds. Cooldown 90s between triggers. State: logs/gateway-guard.continue-state.json. - watch — Single combined daemon (one LaunchAgent). Each run: (0) token sync —
ensure --apply so gateway auth matches config (prevents devicetokenmismatch); (1) gateway back → what-just-happened summary; (2) continue-on-error check. Install one daemon: bash <skill-dir>/scripts/install_watcher.sh (or install_continue_on_error.sh). This unloads the old separate what-just-happened and continue-on-error LaunchAgents and loads com.openclaw.gateway-guard.watcher so users only need one. For periodic gateway recovery (check every 10s, restart if not ok), use the separate gateway-watchdog skill.
Behavior
- - Reads
openclaw.json → gateway.auth (token or password) and gateway.port. - Compares with the process listening on that port (and optional guard state file).
- If
ensure --apply: restarts gateway via openclaw gateway stop then openclaw gateway --port N --auth token|password --token|--password SECRET. - If token is missing in config (token mode only): generates a token, writes it to config once, then proceeds. Does not overwrite config when it is already correct.
- continue-on-error: Tails
OPENCLAW_HOME/logs/gateway.log for the string Unhandled stop reason: error. When found (and not in cooldown), runs openclaw agent --message continue --deliver so the agent receives "continue" and can resume. Run install_continue_on_error.sh to install a LaunchAgent that checks every 30s. If the error appears in the TUI but the watcher never triggers, the gateway may not be writing run errors to gateway.log — ensure run/stream errors are logged there.
JSON output (for orchestration)
- - status --json / ensure --json:
ok, secretMatchesConfig, running, pid, reason, recommendedAction, configPath, authMode, gatewayPort. When not ok, recommendedAction is "run gateway_guard.py ensure --apply and restart client session".
Requirements
- - OpenClaw
openclaw.json with gateway.auth (mode token or password) and gateway.port. - CLI / system:
openclaw CLI on PATH (for ensure --apply and continue-on-error); lsof and ps (macOS/Unix); launchctl on macOS when using the LaunchAgent install scripts. - Environment (optional):
OPENCLAW_HOME — OpenClaw home directory (default: ~/.openclaw). OPENCLAW_BIN — Path or name of openclaw binary (default: openclaw).
Privileged actions (what you accept)
This skill may: read and modify openclaw.json (including writing gateway.auth when missing or wrong); write state and log files under OPENCLAW_HOME/logs/; restart the gateway via the OpenClaw CLI; and, if the watcher is installed, invoke openclaw agent --message continue --deliver automatically when a run error is detected. These are privileged local actions; run only if you accept them.
Gateway Guard
描述
确保 OpenClaw 网关认证一致性,当网关日志中出现运行错误(未处理的停止原因:错误)时,可自动提示继续。适用于检查或修复网关令牌/密码不匹配、devicetokenmismatch 错误,或在委托给子代理之前使用。
确保 OpenClaw 网关认证一致性,当网关日志中出现运行错误(未处理的停止原因:错误)时,可自动提示继续。适用于检查或修复网关令牌/密码不匹配、devicetokenmismatch 错误,或在委托给子代理之前使用。
Gateway Guard
保持 OpenClaw 网关认证与 openclaw.json 同步。当用户或代理遇到网关认证问题、devicetokenmismatch,或需要在生成子代理前确保网关使用正确的令牌/密码运行时使用。
元数据: 此技能在 _meta.json 中使用 always: false。它不会强制在每个代理运行中使用;编排器在需要时调用它(例如在委托给子代理之前)。可选的持久化(LaunchAgent)仅在运行安装脚本时安装;请参阅下面的安装前。
安装前
- - 备份 openclaw.json — 当 gateway.auth(令牌/密码)缺失或错误时,脚本可能会添加或修正。在运行 ensure --apply 前请制作副本。
- 先以只读方式测试 — 在允许重启或配置写入前,运行 python3 scripts/gatewayguard.py status --json 和 python3 scripts/gatewayguard.py ensure --json(不带 --apply)查看其将要执行的操作。
- 理解 continue 投递 — 当 gateway.log 中出现运行错误时,监视器可以运行 openclaw agent --message continue --deliver。请确认在您的环境中自动发送该消息是可接受的。
- LaunchAgent 是可选的 — 仅当运行 installwatcher.sh 时才会安装持久化(每30秒监视一次)。安装程序将 plist 从技能目录复制到 ~/Library/LaunchAgents 并运行 launchctl load;仅当您接受时才运行。plist 包含在此包中:scripts/com.openclaw.gateway-guard.watcher.plist(和 scripts/com.openclaw.gateway-guard.continue-on-error.plist)。在安装监视器前,确保 OPENCLAWHOME 和 OPENCLAW_BIN 解析到您预期的路径。
- 如果不确定,请先在非生产环境中尝试。
包内容(文件清单)
此技能中包含以下内容,以便安装程序不会出错:
- - scripts/gatewayguard.py — 主脚本(状态、确保、继续处理错误、监视)。
- scripts/installwatcher.sh — 安装单个组合 LaunchAgent(令牌同步 + 继续处理错误)。
- scripts/installcontinueonerror.sh — 重定向到 installwatcher.sh。
- scripts/com.openclaw.gateway-guard.watcher.plist — LaunchAgent plist 模板(installwatcher.sh 复制并替换路径)。
- scripts/com.openclaw.gateway-guard.continue-on-error.plist — 旧版 plist(可选;installwatcher.sh 替换为组合监视器)。
使用方法
- - 用户或日志报告网关认证问题、devicetokenmismatch或未授权
- 在运行路由器和 sessions_spawn(编排器流程)前:先检查网关状态
- 在安装或更新 OpenClaw 后:验证网关和配置是否匹配
- 当 TUI 断开连接或无法连接时:修复认证并重启网关
- 运行错误(未处理的停止原因:错误): 运行 continue-on-error --loop(例如通过 LaunchAgent 或 cron),以便当 gateway.log 中出现此错误时,守卫自动向代理发送继续
bash
python3 <技能目录>/scripts/gateway_guard.py status [--json]
python3 <技能目录>/scripts/gateway_guard.py ensure [--apply] [--wait] [--json]
python3 <技能目录>/scripts/ensuregatewaythen.sh [命令 ...]
python3 <技能目录>/scripts/gateway_guard.py continue-on-error [--once] [--loop] [--interval 30] [--json]
- - status — 报告运行中的网关认证是否与 openclaw.json 匹配。匹配时退出码为0,不匹配时为1。
- ensure — 相同检查;如果不匹配且使用了 --apply,则使用配置中的凭据重启网关。仅当 gateway.auth 缺失或错误时才将其写入 openclaw.json(从不覆盖正确的配置)。在 --apply 后使用 --wait 阻塞直到网关端口开放(最多30秒),以便客户端可以立即连接。
- ensuregatewaythen.sh — 自动检测并连接:确保网关正在运行(如果需要则启动它,等待端口),然后运行您的命令。示例:ensuregatewaythen.sh openclaw tui 或 ensuregatewaythen.sh(仅确保并等待)。
- continue-on-error — 当 gateway.log 包含 未处理的停止原因:错误(运行错误)时,通过 openclaw agent --message continue --deliver 向代理发送 继续。使用 --once 检查一次并退出,或使用 --loop 每 --interval 秒运行一次。触发间隔90秒冷却。状态:logs/gateway-guard.continue-state.json。
- watch — 单个组合守护进程(一个 LaunchAgent)。每次运行:(0) 令牌同步 — ensure --apply 使网关认证与配置匹配(防止 devicetokenmismatch);(1) 网关返回 → 刚刚发生了什么摘要;(2) 继续处理错误检查。安装一个守护进程: bash <技能目录>/scripts/installwatcher.sh(或 installcontinueonerror.sh)。这将卸载旧的独立刚刚发生了什么和继续处理错误LaunchAgent,并加载 com.openclaw.gateway-guard.watcher,使用户只需一个。对于定期网关恢复(每10秒检查一次,如果不正常则重启),请使用单独的 gateway-watchdog 技能。
行为
- - 读取 openclaw.json → gateway.auth(令牌或密码)和 gateway.port。
- 与监听该端口的进程(以及可选的守卫状态文件)进行比较。
- 如果 ensure --apply:通过 openclaw gateway stop 然后 openclaw gateway --port N --auth token|password --token|--password SECRET 重启网关。
- 如果配置中缺少令牌(仅令牌模式):生成一个令牌,将其写入配置一次,然后继续。当配置已正确时不会覆盖。
- continue-on-error: 监视 OPENCLAWHOME/logs/gateway.log 中字符串 未处理的停止原因:错误。当找到时(且不在冷却期),运行 openclaw agent --message continue --deliver,使代理收到继续并可以恢复。运行 installcontinueonerror.sh 安装每30秒检查一次的 LaunchAgent。如果错误出现在 TUI 中但监视器从未触发,则网关可能没有将运行错误写入 gateway.log — 确保运行/流错误记录在那里。
JSON 输出(用于编排)
- - status --json / ensure --json:ok、secretMatchesConfig、running、pid、reason、recommendedAction、configPath、authMode、gatewayPort。当不正常时,recommendedAction 为运行 gateway_guard.py ensure --apply 并重启客户端会话。
要求
- - OpenClaw openclaw.json 包含 gateway.auth(模式 token 或 password)和 gateway.port。
- CLI / 系统: PATH 中的 openclaw CLI(用于 ensure --apply 和 continue-on-error);lsof 和 ps(macOS/Unix);使用 LaunchAgent 安装脚本时 macOS 上的 launchctl。
- 环境(可选): OPENCLAWHOME — OpenClaw 主目录(默认:~/.openclaw)。OPENCLAWBIN — openclaw 二进制文件的路径或名称(默认:openclaw)。
特权操作(您接受的内容)
此技能可能:读取和修改 openclaw.json(包括在 gateway.auth 缺失或错误时写入);在 OPENCLAW_HOME/logs/ 下写入