@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "一键配置所有 AI 编程工具接入 HolySheep API — Claude Code / Codex / Gemini CLI / OpenCode / OpenClaw / Aider / Cursor",
5
5
  "keywords": [
6
6
  "claude",
@@ -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 ⚙️ 正在初始化并启动 OpenClaw Gateway(约 15 秒)...'))
184
+ console.log(chalk.gray('\n ⚙️ 正在启动 OpenClaw Gateway...'))
185
185
 
186
- // Step 1: 无交互 onboard + install-daemon
187
- const r1 = spawnSync(bin, ['onboard', '--non-interactive', '--install-daemon'], {
188
- shell: true,
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 初始化完成,Gateway 已在后台启动'))
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 失败,直接 gateway start
201
- const r2 = spawnSync(bin, ['gateway', 'start'], {
202
- shell: true,
203
- timeout: 15000,
204
- stdio: 'pipe',
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
- if (r2.status === 0) {
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: cmd start 开新窗口后台运行
215
- spawnSync('cmd', ['/c', `start /B "" openclaw gateway --port 18789`], {
216
- shell: true, stdio: 'ignore',
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
- // 等 3 秒让 gateway 起来
228
- const t = Date.now(); while (Date.now() - t < 3000) {}
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
- console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
231
- console.log(chalk.cyan(' 浏览器打开: http://127.0.0.1:18789/'))
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
  }