@simonyea/holysheep-cli 1.2.6 → 1.2.7
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.
- package/package.json +1 -1
- package/src/tools/openclaw.js +55 -26
package/package.json
CHANGED
package/src/tools/openclaw.js
CHANGED
|
@@ -181,52 +181,81 @@ function _initAndStartGateway() {
|
|
|
181
181
|
const isWin = process.platform === 'win32'
|
|
182
182
|
const bin = 'openclaw'
|
|
183
183
|
|
|
184
|
-
console.log(chalk.gray('\n ⚙️
|
|
184
|
+
console.log(chalk.gray('\n ⚙️ 正在启动 OpenClaw Gateway...'))
|
|
185
185
|
|
|
186
|
-
// Step 1:
|
|
187
|
-
const r1 = spawnSync(bin, ['
|
|
188
|
-
shell:
|
|
189
|
-
timeout: 60000,
|
|
190
|
-
stdio: 'pipe',
|
|
191
|
-
env: { ...process.env },
|
|
186
|
+
// Step 1: gateway start(已有 daemon 时直接生效)
|
|
187
|
+
const r1 = spawnSync(bin, ['gateway', 'start'], {
|
|
188
|
+
shell: true, timeout: 10000, stdio: 'pipe',
|
|
192
189
|
})
|
|
193
|
-
|
|
194
190
|
if (r1.status === 0) {
|
|
195
|
-
console.log(chalk.green(' ✓ OpenClaw
|
|
191
|
+
console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
|
|
196
192
|
console.log(chalk.cyan(' → 浏览器打开: http://127.0.0.1:18789/'))
|
|
197
193
|
return
|
|
198
194
|
}
|
|
199
195
|
|
|
200
|
-
// Step 2: onboard
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
timeout:
|
|
204
|
-
|
|
196
|
+
// Step 2: 无交互 onboard --install-daemon(注册系统服务)
|
|
197
|
+
console.log(chalk.gray(' → 首次初始化,注册系统服务...'))
|
|
198
|
+
const r2 = spawnSync(bin, ['onboard', '--non-interactive', '--install-daemon'], {
|
|
199
|
+
shell: true, timeout: 60000, stdio: 'pipe',
|
|
200
|
+
env: { ...process.env },
|
|
205
201
|
})
|
|
206
|
-
|
|
202
|
+
// 再次尝试 start
|
|
203
|
+
const r3 = spawnSync(bin, ['gateway', 'start'], {
|
|
204
|
+
shell: true, timeout: 10000, stdio: 'pipe',
|
|
205
|
+
})
|
|
206
|
+
if (r3.status === 0) {
|
|
207
207
|
console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
|
|
208
208
|
console.log(chalk.cyan(' → 浏览器打开: http://127.0.0.1:18789/'))
|
|
209
209
|
return
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
// Step 3: fallback —
|
|
212
|
+
// Step 3: fallback — 直接后台运行进程
|
|
213
|
+
console.log(chalk.gray(' → 以守护进程模式启动...'))
|
|
213
214
|
if (isWin) {
|
|
214
|
-
// Windows:
|
|
215
|
-
spawnSync('
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
// Windows: PowerShell Start-Process 后台运行,不弹窗
|
|
216
|
+
spawnSync('powershell', [
|
|
217
|
+
'-NonInteractive', '-WindowStyle', 'Hidden', '-Command',
|
|
218
|
+
`Start-Process -FilePath "openclaw" -ArgumentList "gateway","--port","18789" -WindowStyle Hidden`
|
|
219
|
+
], { shell: false, timeout: 5000, stdio: 'ignore' })
|
|
218
220
|
} else {
|
|
219
221
|
const { spawn } = require('child_process')
|
|
220
222
|
const child = spawn(bin, ['gateway', '--port', '18789'], {
|
|
221
|
-
detached: true,
|
|
222
|
-
stdio: 'ignore',
|
|
223
|
+
detached: true, stdio: 'ignore',
|
|
223
224
|
})
|
|
224
225
|
child.unref()
|
|
225
226
|
}
|
|
226
227
|
|
|
227
|
-
// 等
|
|
228
|
-
const
|
|
228
|
+
// 等 4 秒让 gateway 起来再报告
|
|
229
|
+
const deadline = Date.now() + 4000
|
|
230
|
+
while (Date.now() < deadline) {}
|
|
231
|
+
|
|
232
|
+
// 验证是否真的起来了
|
|
233
|
+
const http = require('http')
|
|
234
|
+
const verify = new Promise(resolve => {
|
|
235
|
+
const req = http.get('http://127.0.0.1:18789/', res => resolve(true))
|
|
236
|
+
req.on('error', () => resolve(false))
|
|
237
|
+
req.setTimeout(3000, () => { req.destroy(); resolve(false) })
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
// 用同步方式等验证(node 18+)
|
|
241
|
+
let ok = false
|
|
242
|
+
try {
|
|
243
|
+
const { execSync } = require('child_process')
|
|
244
|
+
execSync(
|
|
245
|
+
isWin
|
|
246
|
+
? 'powershell -NonInteractive -Command "Invoke-WebRequest -Uri http://127.0.0.1:18789/ -TimeoutSec 3 -UseBasicParsing | Out-Null"'
|
|
247
|
+
: 'curl -sf http://127.0.0.1:18789/ -o /dev/null --max-time 3',
|
|
248
|
+
{ stdio: 'ignore', timeout: 5000 }
|
|
249
|
+
)
|
|
250
|
+
ok = true
|
|
251
|
+
} catch {}
|
|
229
252
|
|
|
230
|
-
|
|
231
|
-
|
|
253
|
+
if (ok) {
|
|
254
|
+
console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
|
|
255
|
+
console.log(chalk.cyan(' → 浏览器打开: http://127.0.0.1:18789/'))
|
|
256
|
+
} else {
|
|
257
|
+
console.log(chalk.yellow(' ⚠️ Gateway 启动中,请稍等 10 秒后访问:'))
|
|
258
|
+
console.log(chalk.cyan(' → http://127.0.0.1:18789/'))
|
|
259
|
+
console.log(chalk.gray(' 如仍无法访问,请手动运行: openclaw gateway start'))
|
|
260
|
+
}
|
|
232
261
|
}
|