@simonyea/holysheep-cli 1.2.6 → 1.2.8

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.8",
4
4
  "description": "一键配置所有 AI 编程工具接入 HolySheep API — Claude Code / Codex / Gemini CLI / OpenCode / OpenClaw / Aider / Cursor",
5
5
  "keywords": [
6
6
  "claude",
@@ -118,7 +118,15 @@ module.exports = {
118
118
  id: 'openclaw',
119
119
 
120
120
  checkInstalled() {
121
- return require('../utils/which').commandExists('openclaw')
121
+ if (require('../utils/which').commandExists('openclaw')) return true
122
+ // Windows PATH 未刷新时,用 npx 探测
123
+ if (process.platform === 'win32') {
124
+ try {
125
+ require('child_process').execSync('npx openclaw --version', { stdio: 'ignore', timeout: 10000 })
126
+ return true
127
+ } catch {}
128
+ }
129
+ return false
122
130
  },
123
131
 
124
132
  isConfigured() {
@@ -162,7 +170,12 @@ module.exports = {
162
170
  getConfigPath() { return CONFIG_FILE },
163
171
  hint: 'Gateway 已自动在后台启动,打开浏览器即可使用',
164
172
  launchCmd: null,
165
- launchNote: '🌐 打开浏览器访问 http://127.0.0.1:18789/',
173
+ get launchNote() {
174
+ const isWin = process.platform === 'win32'
175
+ return isWin
176
+ ? '🌐 打开浏览器访问 http://127.0.0.1:18789/\n 如无法访问请运行: npx openclaw gateway start'
177
+ : '🌐 打开浏览器访问 http://127.0.0.1:18789/'
178
+ },
166
179
  installCmd: 'npm install -g openclaw@latest',
167
180
  docsUrl: 'https://docs.openclaw.ai',
168
181
  }
@@ -179,54 +192,84 @@ module.exports = {
179
192
  function _initAndStartGateway() {
180
193
  const chalk = require('chalk')
181
194
  const isWin = process.platform === 'win32'
182
- const bin = 'openclaw'
195
+ // Windows 刚装完 npm 包,PATH 未刷新,用 npx 兜底
196
+ const bin = isWin ? 'npx openclaw' : 'openclaw'
183
197
 
184
- console.log(chalk.gray('\n ⚙️ 正在初始化并启动 OpenClaw Gateway(约 15 秒)...'))
198
+ console.log(chalk.gray('\n ⚙️ 正在启动 OpenClaw Gateway...'))
185
199
 
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 },
200
+ // Step 1: gateway start(已有 daemon 时直接生效)
201
+ const r1 = spawnSync(bin, ['gateway', 'start'], {
202
+ shell: true, timeout: 10000, stdio: 'pipe',
192
203
  })
193
-
194
204
  if (r1.status === 0) {
195
- console.log(chalk.green(' ✓ OpenClaw 初始化完成,Gateway 已在后台启动'))
205
+ console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
196
206
  console.log(chalk.cyan(' → 浏览器打开: http://127.0.0.1:18789/'))
197
207
  return
198
208
  }
199
209
 
200
- // Step 2: onboard 失败,直接 gateway start
201
- const r2 = spawnSync(bin, ['gateway', 'start'], {
202
- shell: true,
203
- timeout: 15000,
204
- stdio: 'pipe',
210
+ // Step 2: 无交互 onboard --install-daemon(注册系统服务)
211
+ console.log(chalk.gray(' 首次初始化,注册系统服务...'))
212
+ const r2 = spawnSync(bin, ['onboard', '--non-interactive', '--install-daemon'], {
213
+ shell: true, timeout: 60000, stdio: 'pipe',
214
+ env: { ...process.env },
215
+ })
216
+ // 再次尝试 start
217
+ const r3 = spawnSync(bin, ['gateway', 'start'], {
218
+ shell: true, timeout: 10000, stdio: 'pipe',
205
219
  })
206
- if (r2.status === 0) {
220
+ if (r3.status === 0) {
207
221
  console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
208
222
  console.log(chalk.cyan(' → 浏览器打开: http://127.0.0.1:18789/'))
209
223
  return
210
224
  }
211
225
 
212
- // Step 3: fallback — 后台守护进程
226
+ // Step 3: fallback — 直接后台运行进程
227
+ console.log(chalk.gray(' → 以守护进程模式启动...'))
213
228
  if (isWin) {
214
- // Windows: cmd start 开新窗口后台运行
215
- spawnSync('cmd', ['/c', `start /B "" openclaw gateway --port 18789`], {
216
- shell: true, stdio: 'ignore',
217
- })
229
+ // Windows: PowerShell Start-Process 后台运行(用 npx 兜底 PATH 未刷新)
230
+ spawnSync('powershell', [
231
+ '-NonInteractive', '-WindowStyle', 'Hidden', '-Command',
232
+ `Start-Process -FilePath "npx" -ArgumentList "openclaw","gateway","--port","18789" -WindowStyle Hidden`
233
+ ], { shell: false, timeout: 5000, stdio: 'ignore' })
218
234
  } else {
219
235
  const { spawn } = require('child_process')
220
236
  const child = spawn(bin, ['gateway', '--port', '18789'], {
221
- detached: true,
222
- stdio: 'ignore',
237
+ detached: true, stdio: 'ignore',
223
238
  })
224
239
  child.unref()
225
240
  }
226
241
 
227
- // 等 3 秒让 gateway 起来
228
- const t = Date.now(); while (Date.now() - t < 3000) {}
242
+ // 等 4 秒让 gateway 起来再报告
243
+ const deadline = Date.now() + 4000
244
+ while (Date.now() < deadline) {}
245
+
246
+ // 验证是否真的起来了
247
+ const http = require('http')
248
+ const verify = new Promise(resolve => {
249
+ const req = http.get('http://127.0.0.1:18789/', res => resolve(true))
250
+ req.on('error', () => resolve(false))
251
+ req.setTimeout(3000, () => { req.destroy(); resolve(false) })
252
+ })
253
+
254
+ // 用同步方式等验证(node 18+)
255
+ let ok = false
256
+ try {
257
+ const { execSync } = require('child_process')
258
+ execSync(
259
+ isWin
260
+ ? 'powershell -NonInteractive -Command "Invoke-WebRequest -Uri http://127.0.0.1:18789/ -TimeoutSec 3 -UseBasicParsing | Out-Null"'
261
+ : 'curl -sf http://127.0.0.1:18789/ -o /dev/null --max-time 3',
262
+ { stdio: 'ignore', timeout: 5000 }
263
+ )
264
+ ok = true
265
+ } catch {}
229
266
 
230
- console.log(chalk.green(' ✓ OpenClaw Gateway 已启动'))
231
- console.log(chalk.cyan(' 浏览器打开: http://127.0.0.1:18789/'))
267
+ if (ok) {
268
+ console.log(chalk.green(' OpenClaw Gateway 已启动'))
269
+ console.log(chalk.cyan(' → 浏览器打开: http://127.0.0.1:18789/'))
270
+ } else {
271
+ console.log(chalk.yellow(' ⚠️ Gateway 启动中,请稍等 10 秒后访问:'))
272
+ console.log(chalk.cyan(' → http://127.0.0.1:18789/'))
273
+ console.log(chalk.gray(' 如仍无法访问,请手动运行: openclaw gateway start'))
274
+ }
232
275
  }