openclawsetup 2.1.1 → 2.1.2

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
@@ -143,11 +143,11 @@ openclaw doctor
143
143
  ## 工作原理
144
144
 
145
145
  1. 安装 `openclaw` npm 包
146
- 2. 使用 `node-pty` 创建跨平台伪终端(Windows 使用 ConPTY)
147
- 3. 监听输出,识别交互提示后自动发送预设答案
148
- 4. 用户看到完整的原版界面 + 自动选择过程
146
+ 2. 优先检测官方 `openclaw onboard` 的非交互参数(可用时直接自动完成)
147
+ 3. 如不支持,则使用 `node-pty` 创建伪终端进行自动应答(按任意键接管)
148
+ 4. 若自动应答不可用,退回手动模式
149
149
 
150
- ## 自动应答规则
150
+ ## 自动应答规则(兜底)
151
151
 
152
152
  | 提示类型 | 自动选择 |
153
153
  |---------|---------|
package/bin/cli.mjs CHANGED
@@ -184,11 +184,82 @@ function stripAnsi(input) {
184
184
  .replace(/\r/g, '\n');
185
185
  }
186
186
 
187
- function getOnboardCommand(cliName) {
187
+ function getOnboardHelp(cliName) {
188
+ const candidates = [
189
+ `${cliName} onboard --help`,
190
+ `${cliName} onboard -h`,
191
+ `${cliName} help onboard`,
192
+ ];
193
+
194
+ for (const cmd of candidates) {
195
+ const result = safeExec(cmd, { stdio: 'pipe' });
196
+ const output = result.ok ? result.output : '';
197
+ if (output && output.length > 20) {
198
+ return output;
199
+ }
200
+ }
201
+ return '';
202
+ }
203
+
204
+ function buildOnboardArgsFromHelp(helpText, options) {
205
+ const help = helpText.toLowerCase();
206
+ const args = [];
207
+ const enabled = [];
208
+
209
+ const pickFlag = (flags) => flags.find((flag) => help.includes(flag));
210
+
211
+ const yesFlag = pickFlag(['--yes', '--assume-yes', '--accept', '--agree']);
212
+ if (yesFlag) {
213
+ args.push(yesFlag);
214
+ enabled.push('yes');
215
+ }
216
+
217
+ const installDaemonFlag = pickFlag(['--install-daemon', '--daemon']);
218
+ if (installDaemonFlag) {
219
+ args.push(installDaemonFlag);
220
+ }
221
+
222
+ if (help.includes('--quickstart')) {
223
+ args.push('--quickstart');
224
+ enabled.push('quickstart');
225
+ } else if (help.includes('--mode') && (help.includes('quickstart') || help.includes('quick start'))) {
226
+ args.push('--mode', 'quickstart');
227
+ enabled.push('quickstart');
228
+ }
229
+
230
+ if (!options.withModel) {
231
+ const skipModelFlag = pickFlag(['--skip-model', '--no-model', '--skip-provider']);
232
+ if (skipModelFlag) {
233
+ args.push(skipModelFlag);
234
+ enabled.push('skip-model');
235
+ }
236
+ }
237
+
238
+ if (!options.withChannel) {
239
+ const skipChannelFlag = pickFlag(['--skip-channel', '--no-channel', '--skip-channels']);
240
+ if (skipChannelFlag) {
241
+ args.push(skipChannelFlag);
242
+ enabled.push('skip-channel');
243
+ }
244
+ }
245
+
246
+ if (help.includes('--ui') && (help.includes('web') || help.includes('dashboard'))) {
247
+ args.push('--ui', 'web');
248
+ enabled.push('ui-web');
249
+ } else if (help.includes('--web')) {
250
+ args.push('--web');
251
+ enabled.push('ui-web');
252
+ }
253
+
254
+ const autoCapable = enabled.length > 0 || Boolean(yesFlag);
255
+ return { args, enabled, autoCapable };
256
+ }
257
+
258
+ function getOnboardCommand(cliName, onboardArgs = ['onboard', '--install-daemon']) {
188
259
  if (platform() === 'win32') {
189
- return { file: 'cmd.exe', args: ['/c', cliName, 'onboard', '--install-daemon'] };
260
+ return { file: 'cmd.exe', args: ['/c', cliName, ...onboardArgs] };
190
261
  }
191
- return { file: cliName, args: ['onboard', '--install-daemon'] };
262
+ return { file: cliName, args: onboardArgs };
192
263
  }
193
264
 
194
265
  function waitForEnter(message) {
@@ -276,21 +347,31 @@ async function runOnboard(cliName) {
276
347
  let usedAuto = false;
277
348
 
278
349
  if (preferAuto) {
279
- const autoResult = await runOnboardAuto(cliName, options);
280
- if (autoResult.ok) {
350
+ const flagResult = runOnboardFlags(cliName, options);
351
+ if (flagResult.ran) {
281
352
  usedAuto = true;
282
353
  console.log(colors.gray('\n' + '-'.repeat(60)));
283
- if (autoResult.exitCode !== 0) {
284
- log.warn(`onboard 退出码: ${autoResult.exitCode}`);
354
+ if (!flagResult.ok) {
355
+ log.warn(`onboard 退出码: ${flagResult.exitCode}`);
285
356
  log.hint('如果配置未完成,可以手动运行: ' + cliName + ' onboard');
286
357
  }
287
- } else if (options.auto) {
288
- log.error('自动模式不可用,已退出');
289
- log.hint(autoResult.reason || '请尝试 --manual');
290
- process.exit(1);
291
358
  } else {
292
- log.warn('自动模式不可用,已切换为手动模式');
293
- log.hint(autoResult.reason || '未能启用自动应答');
359
+ const autoResult = await runOnboardAuto(cliName, options);
360
+ if (autoResult.ok) {
361
+ usedAuto = true;
362
+ console.log(colors.gray('\n' + '-'.repeat(60)));
363
+ if (autoResult.exitCode !== 0) {
364
+ log.warn(`onboard 退出码: ${autoResult.exitCode}`);
365
+ log.hint('如果配置未完成,可以手动运行: ' + cliName + ' onboard');
366
+ }
367
+ } else if (options.auto) {
368
+ log.error('自动模式不可用,已退出');
369
+ log.hint(autoResult.reason || '请尝试 --manual');
370
+ process.exit(1);
371
+ } else {
372
+ log.warn('自动模式不可用,已切换为手动模式');
373
+ log.hint(autoResult.reason || '未能启用自动应答');
374
+ }
294
375
  }
295
376
  }
296
377
 
@@ -311,6 +392,30 @@ function runOnboardManual(cliName) {
311
392
  });
312
393
  }
313
394
 
395
+ function runOnboardFlags(cliName, options) {
396
+ const help = getOnboardHelp(cliName);
397
+ if (!help) {
398
+ return { ran: false, reason: '未检测到 onboard 帮助信息' };
399
+ }
400
+
401
+ const { args, enabled, autoCapable } = buildOnboardArgsFromHelp(help, options);
402
+ if (!autoCapable) {
403
+ return { ran: false, reason: '未检测到可用的非交互参数' };
404
+ }
405
+
406
+ log.info('检测到官方非交互参数,优先使用原生方式安装');
407
+ if (enabled.length) {
408
+ log.hint(`已启用: ${enabled.join(', ')}`);
409
+ }
410
+
411
+ const { file, args: spawnArgs } = getOnboardCommand(cliName, ['onboard', ...args]);
412
+ const result = spawnSync(file, spawnArgs, {
413
+ stdio: 'inherit',
414
+ });
415
+
416
+ return { ran: true, ok: result.status === 0, exitCode: result.status ?? 1 };
417
+ }
418
+
314
419
  function createAutoResponder(term, options) {
315
420
  const lastSent = new Map();
316
421
  let autoStopped = false;
@@ -344,7 +449,11 @@ function createAutoResponder(term, options) {
344
449
  const tail = text.slice(-800);
345
450
 
346
451
  if (tail.includes('do you want to continue') || tail.includes('continue?') || tail.includes('是否继续')) {
347
- send('confirm', 'y\r');
452
+ if (tail.includes('yes') && tail.includes('no')) {
453
+ send('confirm-select', '\x1b[A\x1b[D\r');
454
+ } else {
455
+ send('confirm', 'y\r');
456
+ }
348
457
  return;
349
458
  }
350
459
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclawsetup",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "OpenClaw 安装向导 - 带中文指引的官方安装流程",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,6 +11,7 @@ npx openclawsetup@latest
11
11
  ```
12
12
 
13
13
  你会看到官方的 `openclaw onboard` 界面,但所有选项会自动选择推荐配置(按任意键可接管)。
14
+ 默认优先使用官方提供的非交互参数,若版本不支持则使用自动应答兜底。
14
15
 
15
16
  ### 方式二:手动模式
16
17
 
@@ -154,7 +155,7 @@ curl -fsSL https://unpkg.com/openclawsetup@latest/install.sh | bash
154
155
 
155
156
  ### 自动选择没有生效
156
157
  **现象**:安装过程中需要手动输入
157
- **原因**:可能是终端环境问题或自动应答依赖不可用
158
+ **原因**:可能是终端环境问题、无 TTY,或自动应答依赖不可用(node-pty 未安装成功)
158
159
  **解决**:
159
160
  1. 使用手动模式:
160
161
  ```bash
@@ -164,7 +165,13 @@ curl -fsSL https://unpkg.com/openclawsetup@latest/install.sh | bash
164
165
  ```bash
165
166
  npx openclawsetup@latest --auto
166
167
  ```
167
- 3. 或直接运行官方命令:
168
+ 3. 在 Linux 服务器上补齐编译依赖后再试(Ubuntu 示例):
169
+ ```bash
170
+ sudo apt-get update
171
+ sudo apt-get install -y build-essential python3 make g++ pkg-config
172
+ npx openclawsetup@latest --auto
173
+ ```
174
+ 4. 或直接运行官方命令:
168
175
  ```bash
169
176
  npm install -g openclaw@latest
170
177
  openclaw onboard --install-daemon