openclaw-tools 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,239 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/Sobranier/openclaw-doctor/main/assets/welcome.png" alt="OpenClaw watch" width="400" />
3
+ </p>
4
+
5
+ <h1 align="center">OpenClaw watch</h1>
6
+
7
+ <p align="center">
8
+ Keep your OpenClaw service alive. Automatically.
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="./README.zh-CN.md">中文文档</a>
13
+ </p>
14
+
15
+ ## Get Started
16
+
17
+ ```bash
18
+ npm install -g openclaw-watch
19
+ openclaw-watch watch -d
20
+ ```
21
+
22
+ That's it. Doctor monitors your OpenClaw gateway in the background, restarts it when it goes down, and tells you what happened. Zero configuration needed -- it reads everything from your existing OpenClaw setup.
23
+
24
+ ## Core Commands
25
+
26
+ ```bash
27
+ openclaw-watch watch # Start monitoring (foreground)
28
+ openclaw-watch watch -d # Start monitoring (background)
29
+ openclaw-watch unwatch # Stop monitoring
30
+
31
+ openclaw-watch status # Quick health check
32
+ ```
33
+
34
+ These four commands cover 90% of daily use.
35
+
36
+ ## Gateway Management
37
+
38
+ ```bash
39
+ openclaw-watch gateway start # Start the OpenClaw gateway
40
+ openclaw-watch gateway stop # Stop the gateway
41
+ openclaw-watch gateway restart # Restart the gateway
42
+ ```
43
+
44
+ ## Diagnostics & Logs
45
+
46
+ ```bash
47
+ openclaw-watch doctor # Full diagnostics (binary, gateway, channels)
48
+ openclaw-watch logs # View gateway logs
49
+ openclaw-watch logs --error # View error logs only
50
+ openclaw-watch logs --doctor # View Doctor's own event logs
51
+ openclaw-watch dashboard # Web management UI (http://localhost:9090)
52
+ ```
53
+
54
+ ## Install
55
+
56
+ ```bash
57
+ # npm (recommended)
58
+ npm install -g openclaw-watch
59
+
60
+ # or run without installing
61
+ npx openclaw-watch status
62
+ ```
63
+
64
+ Requires Node >= 22 (same as OpenClaw).
65
+
66
+ ## How It Works
67
+
68
+ Doctor auto-detects your OpenClaw installation:
69
+
70
+ - Reads `~/.openclaw/openclaw.json` for gateway port, channels, agents
71
+ - Finds the launchd service from `~/Library/LaunchAgents/`
72
+ - Checks health via `openclaw health --json` (real gateway RPC, not HTTP)
73
+ - Restarts via `launchctl kickstart` when needed
74
+
75
+ **You don't configure OpenClaw details.** Doctor figures them out.
76
+
77
+ ## All Commands
78
+
79
+ | Command | Description |
80
+ |---------|-------------|
81
+ | **Monitoring** | |
82
+ | `watch` | Start health monitoring (foreground) |
83
+ | `watch -d` | Start health monitoring (background) |
84
+ | `watch -d --dashboard` | Background monitoring + web dashboard |
85
+ | `unwatch` | Stop monitoring |
86
+ | **Gateway** | |
87
+ | `gateway start` | Start the OpenClaw gateway |
88
+ | `gateway stop` | Stop the gateway |
89
+ | `gateway restart` | Restart the gateway |
90
+ | **Info** | |
91
+ | `status` | Show gateway and channel health |
92
+ | `status --json` | Machine-readable JSON output |
93
+ | `doctor` | Run full diagnostics |
94
+ | `dashboard` | Start web management UI |
95
+ | `logs` | Show gateway logs |
96
+ | `logs --error` | Show error logs only |
97
+ | `logs --doctor` | Show Doctor event logs |
98
+
99
+ ## Configuration
100
+
101
+ Config is stored at `~/.openclaw-doctor/config.json`. Created automatically on first run. Only Doctor's own preferences -- no OpenClaw settings needed.
102
+
103
+ ```json
104
+ {
105
+ "checkInterval": 30,
106
+ "failThreshold": 3,
107
+ "dashboardPort": 9090,
108
+ "maxRestartsPerHour": 5,
109
+ "openclawProfile": "default",
110
+ "notify": {
111
+ "webhook": {
112
+ "enabled": false,
113
+ "url": "",
114
+ "bodyTemplate": "{\"msgtype\":\"text\",\"text\":{\"content\":\"{{message}}\"}}"
115
+ },
116
+ "system": {
117
+ "enabled": true
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ | Field | Description | Default |
124
+ |-------|-------------|---------|
125
+ | `checkInterval` | Seconds between health checks | `30` |
126
+ | `failThreshold` | Consecutive failures before restart | `3` |
127
+ | `dashboardPort` | Web dashboard port | `9090` |
128
+ | `maxRestartsPerHour` | Restart throttle | `5` |
129
+ | `openclawProfile` | OpenClaw profile to monitor (`default`, `dev`, ...) | `default` |
130
+ | `notify.webhook.url` | Webhook for notifications | -- |
131
+ | `notify.system.enabled` | macOS native notifications | `true` |
132
+
133
+ ## Notifications
134
+
135
+ Doctor notifies you across the full lifecycle:
136
+
137
+ | Event | Example |
138
+ |-------|---------|
139
+ | Monitoring started | "Doctor is watching your OpenClaw service" |
140
+ | Health degraded | "Service unhealthy (attempt 2/3)" |
141
+ | Restarting | "Restarting gateway..." |
142
+ | Restart succeeded | "Gateway back online" |
143
+ | Restart failed | "Restart failed: [error]" |
144
+ | Throttled | "Too many restarts, manual intervention needed" |
145
+ | Recovered | "Service recovered on its own" |
146
+ | Monitoring stopped | "Doctor stopped" |
147
+
148
+ Channels: **Webhook** (DingTalk, Feishu, Slack, etc.) + **macOS system notifications**.
149
+
150
+ ## Skills Integration
151
+
152
+ Doctor runs as a standalone daemon, callable by OpenClaw or other tools:
153
+
154
+ ```bash
155
+ openclaw-watch status --json # Machine-readable output
156
+ openclaw-watch watch -d # Idempotent -- safe to call repeatedly
157
+ ```
158
+
159
+ If the caller crashes, Doctor keeps running.
160
+
161
+ ## Architecture
162
+
163
+ ```
164
+ +-----------------+
165
+ | Notification |
166
+ | (Webhook/OS) |
167
+ +--------^--------+
168
+ |
169
+ +-------------+ CLI +--------+--------+ RPC +-----------+
170
+ | OpenClaw | --------> | | ---------> | OpenClaw |
171
+ | / Scripts | | openclaw-doctor | | Gateway |
172
+ | / Skills | <-------- | (daemon) | <--------- | :18789 |
173
+ +-------------+ stdout +--------+--------+ health +-----------+
174
+ |
175
+ +--------v--------+
176
+ | ~/.openclaw/logs |
177
+ | (read & analyze) |
178
+ +-----------------+
179
+ ```
180
+
181
+ ## Development
182
+
183
+ ```bash
184
+ git clone https://github.com/openclaw/openclaw-doctor.git
185
+ cd openclaw-doctor
186
+ npm install
187
+
188
+ npm run dev -- status # Quick test
189
+ npm run dev -- watch # Foreground monitoring
190
+ npm run dev -- watch -d # Background daemon
191
+ npm run dev -- unwatch # Stop daemon
192
+
193
+ npm run build # Build for distribution
194
+ ```
195
+
196
+ ## Roadmap
197
+
198
+ - [x] Health check via `openclaw health --json` + auto-restart with throttling
199
+ - [x] Auto-detect OpenClaw config (gateway port, channels, agents, launchd)
200
+ - [x] Background daemon mode (`watch -d` / `unwatch`)
201
+ - [x] Gateway management (`gateway start/stop/restart`)
202
+ - [x] Read and display OpenClaw gateway logs
203
+ - [x] Web status dashboard
204
+ - [x] `--json` output for status
205
+ - [ ] Notification system (Webhook + macOS)
206
+ - [ ] `logs --tail` (real-time follow)
207
+ - [ ] `config` command (get/set)
208
+ - [ ] Multiple service monitoring
209
+ - [ ] Linux systemd support
210
+
211
+ ## License
212
+
213
+ [MIT](./LICENSE)
214
+
215
+ ## Publishing
216
+
217
+ This repo publishes two npm packages from the same codebase:
218
+
219
+ - **`openclaw-watch`** — the main package (`package.json`)
220
+ - **`openclaw-watch`** — alias package (`package.openclaw-watch.json`)
221
+
222
+ Both packages share the same version number and dist output.
223
+
224
+ ### Release a new version
225
+
226
+ ```bash
227
+ # 1. Bump version (patch / minor / major)
228
+ npm version patch
229
+
230
+ # 2. Build + publish both packages
231
+ npm run release
232
+ ```
233
+
234
+ `npm run release` calls `scripts/publish.sh`, which:
235
+ 1. Builds once (`npm run build`)
236
+ 2. Publishes `openclaw-watch` with the default `package.json`
237
+ 3. Temporarily swaps in `package.openclaw-watch.json`, publishes `openclaw-watch`, then restores
238
+
239
+ To update the `openclaw-watch` package metadata (description, keywords, bin name, etc.), edit `package.openclaw-watch.json`. Keep `version` in sync — it's automatically picked up from whichever `package.json` is active during publish.
@@ -0,0 +1,213 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/Sobranier/openclaw-doctor/main/assets/welcome.png" alt="OpenClaw Doctor" width="400" />
3
+ </p>
4
+
5
+ <h1 align="center">OpenClaw Doctor</h1>
6
+
7
+ <p align="center">
8
+ 让你的 OpenClaw 服务永不宕机。
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="./README.md">English</a>
13
+ </p>
14
+
15
+ ## 开始使用
16
+
17
+ ```bash
18
+ npm install -g openclaw-doctor
19
+ openclaw-doctor watch -d
20
+ ```
21
+
22
+ 就这样。Doctor 在后台监控你的 OpenClaw 网关,挂了自动重启,全程通知你。无需任何配置——它会自动读取你现有的 OpenClaw 设置。
23
+
24
+ ## 核心命令
25
+
26
+ ```bash
27
+ openclaw-doctor watch # 开始监控(前台)
28
+ openclaw-doctor watch -d # 开始监控(后台)
29
+ openclaw-doctor unwatch # 停止监控
30
+
31
+ openclaw-doctor status # 快速健康检查
32
+ ```
33
+
34
+ 这四个命令覆盖日常 90% 的使用场景。
35
+
36
+ ## 网关管理
37
+
38
+ ```bash
39
+ openclaw-doctor gateway start # 启动 OpenClaw 网关
40
+ openclaw-doctor gateway stop # 停止网关
41
+ openclaw-doctor gateway restart # 重启网关
42
+ ```
43
+
44
+ ## 诊断和日志
45
+
46
+ ```bash
47
+ openclaw-doctor doctor # 完整诊断(二进制、网关、通道)
48
+ openclaw-doctor logs # 查看网关日志
49
+ openclaw-doctor logs --error # 只看错误日志
50
+ openclaw-doctor logs --doctor # 查看 Doctor 自身事件日志
51
+ openclaw-doctor dashboard # Web 管理面板(http://localhost:9090)
52
+ ```
53
+
54
+ ## 安装
55
+
56
+ ```bash
57
+ # npm(推荐)
58
+ npm install -g openclaw-doctor
59
+
60
+ # 或免安装直接跑
61
+ npx openclaw-doctor status
62
+ ```
63
+
64
+ 需要 Node >= 22(和 OpenClaw 一致)。
65
+
66
+ ## 工作原理
67
+
68
+ Doctor 自动探测你的 OpenClaw 安装:
69
+
70
+ - 读取 `~/.openclaw/openclaw.json` 获取网关端口、通道、Agent 信息
71
+ - 扫描 `~/Library/LaunchAgents/` 找到 launchd 服务
72
+ - 通过 `openclaw health --json` 检查健康(真正的网关 RPC,不是 HTTP 探测)
73
+ - 需要时通过 `launchctl kickstart` 重启
74
+
75
+ **你不需要配置 OpenClaw 的任何信息。** Doctor 会自动搞定。
76
+
77
+ ## 完整命令
78
+
79
+ | 命令 | 说明 |
80
+ |------|------|
81
+ | **监控** | |
82
+ | `watch` | 开始健康监控(前台) |
83
+ | `watch -d` | 开始健康监控(后台) |
84
+ | `watch -d --dashboard` | 后台监控 + Web 面板 |
85
+ | `unwatch` | 停止监控 |
86
+ | **网关** | |
87
+ | `gateway start` | 启动 OpenClaw 网关 |
88
+ | `gateway stop` | 停止网关 |
89
+ | `gateway restart` | 重启网关 |
90
+ | **信息** | |
91
+ | `status` | 显示网关和通道健康状态 |
92
+ | `status --json` | 机器可读的 JSON 输出 |
93
+ | `doctor` | 运行完整诊断 |
94
+ | `dashboard` | 启动 Web 管理面板 |
95
+ | `logs` | 查看网关日志 |
96
+ | `logs --error` | 只看错误日志 |
97
+ | `logs --doctor` | 查看 Doctor 事件日志 |
98
+
99
+ ## 配置
100
+
101
+ 配置文件位于 `~/.openclaw-doctor/config.json`,首次运行时自动创建。只包含 Doctor 自身的偏好——无需配置 OpenClaw 的信息。
102
+
103
+ ```json
104
+ {
105
+ "checkInterval": 30,
106
+ "failThreshold": 3,
107
+ "dashboardPort": 9090,
108
+ "maxRestartsPerHour": 5,
109
+ "openclawProfile": "default",
110
+ "notify": {
111
+ "webhook": {
112
+ "enabled": false,
113
+ "url": "",
114
+ "bodyTemplate": "{\"msgtype\":\"text\",\"text\":{\"content\":\"{{message}}\"}}"
115
+ },
116
+ "system": {
117
+ "enabled": true
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ | 字段 | 说明 | 默认值 |
124
+ |------|------|--------|
125
+ | `checkInterval` | 健康检查间隔(秒) | `30` |
126
+ | `failThreshold` | 连续失败几次后重启 | `3` |
127
+ | `dashboardPort` | Web 面板端口 | `9090` |
128
+ | `maxRestartsPerHour` | 每小时最多重启次数 | `5` |
129
+ | `openclawProfile` | 监控的 OpenClaw 配置(`default`、`dev`...) | `default` |
130
+ | `notify.webhook.url` | Webhook 通知地址 | -- |
131
+ | `notify.system.enabled` | macOS 系统通知 | `true` |
132
+
133
+ ## 通知系统
134
+
135
+ Doctor 在整个生命周期都会通知你:
136
+
137
+ | 事件 | 示例消息 |
138
+ |------|----------|
139
+ | 开始监控 | "Doctor 正在守护你的 OpenClaw 服务" |
140
+ | 状态异常 | "服务异常(第 2/3 次检测)" |
141
+ | 准备重启 | "正在重启网关..." |
142
+ | 重启成功 | "网关已恢复上线" |
143
+ | 重启失败 | "重启失败:[错误详情]" |
144
+ | 重启受限 | "重启次数过多,需要人工介入" |
145
+ | 自行恢复 | "服务自行恢复,无需重启" |
146
+ | 停止监控 | "Doctor 已停止" |
147
+
148
+ 支持渠道:**Webhook**(钉钉、飞书、Slack、企业微信等)+ **macOS 系统通知**。
149
+
150
+ ## Skills 集成
151
+
152
+ Doctor 作为独立守护进程运行,可被 OpenClaw 或其他工具调用:
153
+
154
+ ```bash
155
+ openclaw-doctor status --json # 机器可读输出
156
+ openclaw-doctor watch -d # 幂等——重复调用安全
157
+ ```
158
+
159
+ 即使调用方崩溃,Doctor 继续运行。
160
+
161
+ ## 架构
162
+
163
+ ```
164
+ +-----------------+
165
+ | 通知系统 |
166
+ | (Webhook/OS) |
167
+ +--------^--------+
168
+ |
169
+ +-------------+ CLI +--------+--------+ RPC +-----------+
170
+ | OpenClaw | --------> | | ---------> | OpenClaw |
171
+ | / 脚本 | | openclaw-doctor | | 网关 |
172
+ | / Skills | <-------- | (守护进程) | <--------- | :18789 |
173
+ +-------------+ stdout +--------+--------+ health +-----------+
174
+ |
175
+ +--------v--------+
176
+ | ~/.openclaw/logs |
177
+ | (读取并分析) |
178
+ +-----------------+
179
+ ```
180
+
181
+ ## 开发
182
+
183
+ ```bash
184
+ git clone https://github.com/Sobranier/openclaw-doctor.git
185
+ cd openclaw-doctor
186
+ npm install
187
+
188
+ npm run dev -- status # 快速测试
189
+ npm run dev -- watch # 前台监控
190
+ npm run dev -- watch -d # 后台守护
191
+ npm run dev -- unwatch # 停止守护
192
+
193
+ npm run build # 构建发布版本
194
+ ```
195
+
196
+ ## 路线图
197
+
198
+ - [x] 通过 `openclaw health --json` 检查健康 + 自动重启(含频率限制)
199
+ - [x] 自动探测 OpenClaw 配置(网关端口、通道、Agent、launchd)
200
+ - [x] 后台守护模式(`watch -d` / `unwatch`)
201
+ - [x] 网关管理(`gateway start/stop/restart`)
202
+ - [x] 读取并展示 OpenClaw 网关日志
203
+ - [x] Web 状态面板
204
+ - [x] `status --json` 输出
205
+ - [ ] 通知系统(Webhook + macOS)
206
+ - [ ] `logs --tail`(实时跟踪)
207
+ - [ ] `config` 命令(get/set)
208
+ - [ ] 多服务监控
209
+ - [ ] Linux systemd 支持
210
+
211
+ ## 协议
212
+
213
+ [MIT](./LICENSE)