openclawsetup 2.1.0 → 2.1.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.
package/README.md CHANGED
@@ -7,6 +7,7 @@ OpenClaw 智能安装向导 - 调用官方 `openclaw onboard` 交互界面,自
7
7
  - **真实体验**:调用官方 `openclaw onboard` 命令,用户看到完整的原版安装界面
8
8
  - **智能自动化**:自动选择推荐配置,无需手动操作
9
9
  - **可观看过程**:用户可以看到每一步的选择过程,了解发生了什么
10
+ - **随时接管**:按任意键立刻切换为手动操作
10
11
  - **手动模式**:`--manual` 参数可切换到完全手动模式
11
12
  - **三系统支持**:macOS、Linux、Windows
12
13
 
@@ -32,13 +33,13 @@ npx openclawsetup@latest
32
33
 
33
34
  ## 安装模式
34
35
 
35
- ### 智能模式(默认)
36
+ ### 智能模式(默认,自动应答)
36
37
 
37
38
  ```bash
38
39
  npx openclawsetup@latest
39
40
  ```
40
41
 
41
- 自动完成以下选择:
42
+ 自动完成以下选择(按任意键可接管):
42
43
  - ✓ 选择 QuickStart 模式
43
44
  - ✓ 跳过模型配置(后续用 `npx openclawapi` 配置)
44
45
  - ✓ 跳过渠道配置(后续用 `npx openclawdc` 或 `npx openclaw-chat-cn@latest feishu` 配置)
@@ -53,12 +54,22 @@ npx openclawsetup@latest --manual
53
54
 
54
55
  完全交互,自己选择所有配置项。
55
56
 
57
+ ### 强制自动模式
58
+
59
+ ```bash
60
+ npx openclawsetup@latest --auto
61
+ ```
62
+
63
+ 自动应答不可用时将直接退出(适合脚本化场景)。
64
+
56
65
  ## 命令行参数
57
66
 
58
67
  | 参数 | 说明 |
59
68
  |------|------|
60
69
  | `--manual` | 手动模式,不自动选择 |
61
- | `--with-model` | 安装时配置模型(默认跳过) |
70
+ | `--auto` | 强制自动模式(不可用则退出) |
71
+ | `--with-model` | 检测到模型配置时暂停自动选择 |
72
+ | `--with-channel` | 检测到渠道配置时暂停自动选择 |
62
73
  | `--update` | 检查并更新已安装的 OpenClaw |
63
74
  | `--reinstall` | 卸载后重新安装(清除配置) |
64
75
  | `--help, -h` | 显示帮助信息 |
@@ -132,7 +143,7 @@ openclaw doctor
132
143
  ## 工作原理
133
144
 
134
145
  1. 安装 `openclaw` npm 包
135
- 2. 使用 `script` 命令(Unix)创建伪终端,运行 `openclaw onboard --install-daemon`
146
+ 2. 使用 `node-pty` 创建跨平台伪终端(Windows 使用 ConPTY)
136
147
  3. 监听输出,识别交互提示后自动发送预设答案
137
148
  4. 用户看到完整的原版界面 + 自动选择过程
138
149
 
@@ -149,6 +160,8 @@ openclaw doctor
149
160
  | Daemon/Service | 安装 (y) |
150
161
  | UI 选择 | Web Dashboard |
151
162
 
163
+ > 使用 `--with-model` / `--with-channel` 时,自动模式会在对应步骤暂停并交给用户操作。
164
+
152
165
  ## 卸载
153
166
 
154
167
  ```bash
package/bin/cli.mjs CHANGED
@@ -2,8 +2,8 @@
2
2
  /**
3
3
  * OpenClaw 安装向导
4
4
  *
5
- * 调用官方 openclaw onboard,在关键步骤前提供中文指引
6
- * 用户看到完整的原版安装过程,我们只提供选择建议
5
+ * 调用官方 openclaw onboard,自动选择推荐配置
6
+ * 用户可随时按任意键接管,切换为手动操作
7
7
  *
8
8
  * 用法:
9
9
  * npx openclawsetup # 带中文指引的安装
@@ -51,6 +51,10 @@ function parseArgs() {
51
51
  return {
52
52
  update: args.includes('--update'),
53
53
  reinstall: args.includes('--reinstall'),
54
+ manual: args.includes('--manual'),
55
+ auto: args.includes('--auto'),
56
+ withModel: args.includes('--with-model'),
57
+ withChannel: args.includes('--with-channel'),
54
58
  help: args.includes('--help') || args.includes('-h'),
55
59
  };
56
60
  }
@@ -63,10 +67,16 @@ ${colors.cyan('用法:')}
63
67
  npx openclawsetup 带中文指引的安装
64
68
  npx openclawsetup --update 更新已安装的 OpenClaw
65
69
  npx openclawsetup --reinstall 卸载后重新安装
70
+ npx openclawsetup --manual 完全手动模式
71
+ npx openclawsetup --auto 强制自动模式
66
72
 
67
73
  ${colors.cyan('说明:')}
68
74
  本工具会调用官方 openclaw onboard 命令
69
- 在关键步骤前提供中文指引,告诉你该如何选择
75
+ 自动选择推荐配置,按任意键可随时接管
76
+
77
+ ${colors.cyan('高级选项:')}
78
+ --with-model 检测到模型配置时暂停自动选择
79
+ --with-channel 检测到渠道配置时暂停自动选择
70
80
 
71
81
  ${colors.cyan('安装后配置模型:')}
72
82
  npx openclawapi@latest preset-claude
@@ -137,7 +147,7 @@ function showInstallGuide() {
137
147
  console.log(colors.bold(colors.cyan('='.repeat(60))));
138
148
 
139
149
  console.log(colors.yellow('\n接下来会运行官方 openclaw onboard 命令'));
140
- console.log(colors.yellow('请按照以下指引选择:\n'));
150
+ console.log(colors.yellow('自动模式会按以下推荐选择(可随时接管):\n'));
141
151
 
142
152
  console.log(colors.cyan('┌─────────────────────────────────────────────────────────┐'));
143
153
  console.log(colors.cyan('│') + colors.bold(' 步骤 1: 安全确认') + colors.cyan(' │'));
@@ -167,6 +177,20 @@ function showInstallGuide() {
167
177
  console.log(colors.gray('如果不确定,选择 Skip 或直接回车通常是安全的\n'));
168
178
  }
169
179
 
180
+ function stripAnsi(input) {
181
+ return input
182
+ .replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '')
183
+ .replace(/\x1b\][^\x07]*\x07/g, '')
184
+ .replace(/\r/g, '\n');
185
+ }
186
+
187
+ function getOnboardCommand(cliName) {
188
+ if (platform() === 'win32') {
189
+ return { file: 'cmd.exe', args: ['/c', cliName, 'onboard', '--install-daemon'] };
190
+ }
191
+ return { file: cliName, args: ['onboard', '--install-daemon'] };
192
+ }
193
+
170
194
  function waitForEnter(message) {
171
195
  return new Promise((resolve) => {
172
196
  const rl = createInterface({ input: process.stdin, output: process.stdout });
@@ -247,18 +271,253 @@ async function runOnboard(cliName) {
247
271
  console.log(colors.gray('以下是官方 openclaw onboard 界面:'));
248
272
  console.log(colors.gray('-'.repeat(60) + '\n'));
249
273
 
250
- // 直接运行官方 onboard,完全交互
251
- const result = spawnSync(cliName, ['onboard', '--install-daemon'], {
274
+ const options = parseArgs();
275
+ const preferAuto = !options.manual;
276
+ let usedAuto = false;
277
+
278
+ if (preferAuto) {
279
+ const autoResult = await runOnboardAuto(cliName, options);
280
+ if (autoResult.ok) {
281
+ usedAuto = true;
282
+ console.log(colors.gray('\n' + '-'.repeat(60)));
283
+ if (autoResult.exitCode !== 0) {
284
+ log.warn(`onboard 退出码: ${autoResult.exitCode}`);
285
+ log.hint('如果配置未完成,可以手动运行: ' + cliName + ' onboard');
286
+ }
287
+ } else if (options.auto) {
288
+ log.error('自动模式不可用,已退出');
289
+ log.hint(autoResult.reason || '请尝试 --manual');
290
+ process.exit(1);
291
+ } else {
292
+ log.warn('自动模式不可用,已切换为手动模式');
293
+ log.hint(autoResult.reason || '未能启用自动应答');
294
+ }
295
+ }
296
+
297
+ if (!usedAuto) {
298
+ const manualResult = runOnboardManual(cliName);
299
+ console.log(colors.gray('\n' + '-'.repeat(60)));
300
+ if (manualResult.status !== 0) {
301
+ log.warn(`onboard 退出码: ${manualResult.status}`);
302
+ log.hint('如果配置未完成,可以手动运行: ' + cliName + ' onboard');
303
+ }
304
+ }
305
+ }
306
+
307
+ function runOnboardManual(cliName) {
308
+ const { file, args } = getOnboardCommand(cliName);
309
+ return spawnSync(file, args, {
252
310
  stdio: 'inherit',
253
- shell: true,
254
311
  });
312
+ }
255
313
 
256
- console.log(colors.gray('\n' + '-'.repeat(60)));
314
+ function createAutoResponder(term, options) {
315
+ const lastSent = new Map();
316
+ let autoStopped = false;
317
+ let pausedNoticeShown = false;
318
+
319
+ const cooldownMs = 1200;
320
+ const shouldRespond = (id) => {
321
+ const now = Date.now();
322
+ const last = lastSent.get(id) || 0;
323
+ if (now - last < cooldownMs) return false;
324
+ lastSent.set(id, now);
325
+ return true;
326
+ };
327
+
328
+ const stopAuto = (reason) => {
329
+ if (autoStopped) return;
330
+ autoStopped = true;
331
+ log.warn(reason);
332
+ log.hint('已进入手动模式');
333
+ };
334
+
335
+ const send = (id, payload) => {
336
+ if (!shouldRespond(id)) return false;
337
+ term.write(payload);
338
+ return true;
339
+ };
340
+
341
+ return (rawText) => {
342
+ if (autoStopped) return;
343
+ const text = rawText.toLowerCase();
344
+ const tail = text.slice(-800);
345
+
346
+ if (tail.includes('do you want to continue') || tail.includes('continue?') || tail.includes('是否继续')) {
347
+ send('confirm', 'y\r');
348
+ return;
349
+ }
350
+
351
+ if ((tail.includes('quick start') || tail.includes('quickstart')) && (tail.includes('advanced') || tail.includes('custom'))) {
352
+ send('setup', '\r');
353
+ return;
354
+ }
355
+
356
+ const modelPrompt =
357
+ tail.includes('model provider') ||
358
+ tail.includes('model providers') ||
359
+ tail.includes('select a model') ||
360
+ tail.includes('模型') && tail.includes('提供商');
361
+
362
+ if (modelPrompt) {
363
+ if (options.withModel) {
364
+ stopAuto('检测到模型配置提示,已暂停自动选择(--with-model)');
365
+ return;
366
+ }
367
+ send('model-skip', tail.includes('skip') || tail.includes('跳过') ? 's\r' : '\r');
368
+ return;
369
+ }
370
+
371
+ const apiKeyPrompt =
372
+ tail.includes('api key') ||
373
+ tail.includes('apikey') ||
374
+ (tail.includes('key') && tail.includes('请输入'));
375
+
376
+ if (apiKeyPrompt) {
377
+ if (options.withModel) {
378
+ stopAuto('检测到 API Key 配置,已暂停自动选择(--with-model)');
379
+ return;
380
+ }
381
+ send('api-skip', tail.includes('skip') || tail.includes('跳过') ? 's\r' : '\r');
382
+ return;
383
+ }
384
+
385
+ const channelPrompt =
386
+ tail.includes('channel') ||
387
+ tail.includes('discord') ||
388
+ tail.includes('telegram') ||
389
+ tail.includes('feishu') ||
390
+ (tail.includes('渠道') && (tail.includes('选择') || tail.includes('配置')));
391
+
392
+ if (channelPrompt) {
393
+ if (options.withChannel) {
394
+ stopAuto('检测到渠道配置提示,已暂停自动选择(--with-channel)');
395
+ return;
396
+ }
397
+ send('channel-skip', 's\r');
398
+ return;
399
+ }
400
+
401
+ if (tail.includes('skills') || tail.includes('skill')) {
402
+ send('skills-skip', 's\r');
403
+ return;
404
+ }
405
+
406
+ const daemonPrompt =
407
+ tail.includes('daemon') ||
408
+ tail.includes('service') && (tail.includes('install') || tail.includes('enable')) ||
409
+ (tail.includes('后台') && tail.includes('服务')) ||
410
+ tail.includes('开机') && tail.includes('自启');
411
+
412
+ if (daemonPrompt) {
413
+ send('daemon-yes', 'y\r');
414
+ return;
415
+ }
416
+
417
+ const uiPrompt =
418
+ tail.includes('dashboard') ||
419
+ tail.includes('web ui') ||
420
+ tail.includes('web dashboard') ||
421
+ (tail.includes('ui') && tail.includes('选择')) ||
422
+ (tail.includes('界面') && tail.includes('选择'));
423
+
424
+ if (uiPrompt) {
425
+ send('ui-web', tail.includes('web') || tail.includes('dashboard') ? '\r' : 'w\r');
426
+ return;
427
+ }
428
+
429
+ if (tail.includes('port') && (tail.includes('gateway') || tail.includes('端口'))) {
430
+ send('port-default', '\r');
431
+ return;
432
+ }
433
+
434
+ if (!pausedNoticeShown && (options.withModel || options.withChannel)) {
435
+ pausedNoticeShown = true;
436
+ log.hint('检测到 --with-model / --with-channel,将在相关步骤暂停自动选择');
437
+ }
438
+ };
439
+ }
440
+
441
+ async function runOnboardAuto(cliName, options) {
442
+ let ptyModule;
443
+ try {
444
+ ptyModule = await import('node-pty');
445
+ } catch (e) {
446
+ return { ok: false, reason: 'node-pty 依赖不可用,请尝试 --manual' };
447
+ }
448
+
449
+ const pty = ptyModule.default ?? ptyModule;
450
+ const spawn = pty?.spawn;
451
+ if (typeof spawn !== 'function') {
452
+ return { ok: false, reason: 'node-pty 未正确加载,请尝试 --manual' };
453
+ }
257
454
 
258
- if (result.status !== 0) {
259
- log.warn(`onboard 退出码: ${result.status}`);
260
- log.hint('如果配置未完成,可以手动运行: ' + cliName + ' onboard');
455
+ const { file, args } = getOnboardCommand(cliName);
456
+ const cols = process.stdout.columns || 80;
457
+ const rows = process.stdout.rows || 24;
458
+ const env = { ...process.env, FORCE_COLOR: '1' };
459
+
460
+ let term;
461
+ try {
462
+ term = spawn(file, args, {
463
+ name: 'xterm-256color',
464
+ cols,
465
+ rows,
466
+ cwd: process.cwd(),
467
+ env,
468
+ });
469
+ } catch (e) {
470
+ return { ok: false, reason: `启动 PTY 失败: ${e.message}` };
261
471
  }
472
+
473
+ const autoResponder = createAutoResponder(term, options);
474
+ let buffer = '';
475
+ let manualOverride = false;
476
+
477
+ log.info('自动模式已开启,按任意键可接管');
478
+
479
+ const stdin = process.stdin;
480
+ const canReadInput = Boolean(stdin.isTTY);
481
+ const restoreRaw = canReadInput ? stdin.isRaw : false;
482
+
483
+ const onUserData = (data) => {
484
+ if (!manualOverride) {
485
+ manualOverride = true;
486
+ log.warn('已接管,自动模式停止');
487
+ }
488
+ term.write(data.toString('utf8'));
489
+ };
490
+
491
+ if (canReadInput && typeof stdin.setRawMode === 'function') {
492
+ stdin.setRawMode(true);
493
+ }
494
+ if (canReadInput) {
495
+ stdin.on('data', onUserData);
496
+ stdin.resume();
497
+ }
498
+
499
+ term.onData((data) => {
500
+ process.stdout.write(data);
501
+ if (manualOverride) return;
502
+ buffer += stripAnsi(data);
503
+ if (buffer.length > 4000) {
504
+ buffer = buffer.slice(-4000);
505
+ }
506
+ autoResponder(buffer);
507
+ });
508
+
509
+ return await new Promise((resolve) => {
510
+ term.onExit(({ exitCode }) => {
511
+ if (canReadInput) {
512
+ stdin.off('data', onUserData);
513
+ if (typeof stdin.setRawMode === 'function') {
514
+ stdin.setRawMode(Boolean(restoreRaw));
515
+ }
516
+ stdin.pause();
517
+ }
518
+ resolve({ ok: true, exitCode });
519
+ });
520
+ });
262
521
  }
263
522
 
264
523
  // ============ 更新 ============
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "openclawsetup",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "OpenClaw 安装向导 - 带中文指引的官方安装流程",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "openclawsetup": "bin/cli.mjs"
8
8
  },
9
+ "optionalDependencies": {
10
+ "node-pty": "^1.0.0"
11
+ },
9
12
  "scripts": {
10
13
  "start": "node bin/cli.mjs"
11
14
  },
@@ -10,7 +10,7 @@
10
10
  npx openclawsetup@latest
11
11
  ```
12
12
 
13
- 你会看到官方的 `openclaw onboard` 界面,但所有选项会自动选择推荐配置。
13
+ 你会看到官方的 `openclaw onboard` 界面,但所有选项会自动选择推荐配置(按任意键可接管)。
14
14
 
15
15
  ### 方式二:手动模式
16
16
 
@@ -20,7 +20,15 @@ npx openclawsetup@latest
20
20
  npx openclawsetup@latest --manual
21
21
  ```
22
22
 
23
- ### 方式三:一键脚本
23
+ ### 方式三:强制自动模式
24
+
25
+ ```bash
26
+ npx openclawsetup@latest --auto
27
+ ```
28
+
29
+ 自动应答不可用时将直接退出(适合脚本化场景)。
30
+
31
+ ### 方式四:一键脚本
24
32
 
25
33
  自动检测并安装 Node.js,无需任何前置条件。
26
34
 
@@ -49,6 +57,10 @@ irm https://unpkg.com/openclawsetup@latest/install.ps1 | iex
49
57
  | Daemon/Service | 安装 (y) |
50
58
  | UI 选择 | Web Dashboard |
51
59
 
60
+ > 需要在安装过程中配置模型或渠道时,可使用:
61
+ > - `--with-model`:检测到模型配置步骤时暂停自动选择
62
+ > - `--with-channel`:检测到渠道配置步骤时暂停自动选择
63
+
52
64
  **为什么跳过模型和渠道?**
53
65
  - 模型配置:后续用 `npx openclawapi` 单独配置,更灵活
54
66
  - 渠道配置:后续用 `npx openclawdc`(Discord)或 `npx openclaw-chat-cn@latest feishu`(飞书)配置
@@ -142,13 +154,17 @@ curl -fsSL https://unpkg.com/openclawsetup@latest/install.sh | bash
142
154
 
143
155
  ### 自动选择没有生效
144
156
  **现象**:安装过程中需要手动输入
145
- **原因**:可能是终端环境问题
157
+ **原因**:可能是终端环境问题或自动应答依赖不可用
146
158
  **解决**:
147
159
  1. 使用手动模式:
148
160
  ```bash
149
161
  npx openclawsetup@latest --manual
150
162
  ```
151
- 2. 或直接运行官方命令:
163
+ 2. 需要脚本化时使用强制自动模式(不可用会退出):
164
+ ```bash
165
+ npx openclawsetup@latest --auto
166
+ ```
167
+ 3. 或直接运行官方命令:
152
168
  ```bash
153
169
  npm install -g openclaw@latest
154
170
  openclaw onboard --install-daemon