@lingyao037/openclaw-lingyao-cli 0.9.2 → 0.9.3

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.
Files changed (2) hide show
  1. package/cli.mjs +49 -7
  2. package/package.json +1 -1
package/cli.mjs CHANGED
@@ -80,6 +80,7 @@ class LingyaoInstaller {
80
80
  this.channelId = 'lingyao';
81
81
  this.gatewayId = null;
82
82
  this.gatewayToken = null;
83
+ this.openclawCommand = null;
83
84
  }
84
85
 
85
86
  setOpenClawPath(path) {
@@ -111,7 +112,7 @@ class LingyaoInstaller {
111
112
  try {
112
113
  const result = spawnSync(command, args, {
113
114
  stdio: 'inherit',
114
- shell: true,
115
+ shell: false,
115
116
  ...options
116
117
  });
117
118
  return {
@@ -171,14 +172,39 @@ class LingyaoInstaller {
171
172
  return [];
172
173
  }
173
174
 
175
+ isNpxEphemeralOpenClawPath(commandPath) {
176
+ if (!commandPath || typeof commandPath !== 'string') return false;
177
+ const normalized = commandPath.replace(/\\/g, '/');
178
+ return normalized.includes('/.npm/_npx/') && normalized.includes('/node_modules/.bin/openclaw');
179
+ }
180
+
181
+ resolveOpenClawCommandPath() {
182
+ const commandPaths = this.getCommandPathCandidates();
183
+ if (commandPaths.length === 0) {
184
+ return null;
185
+ }
186
+
187
+ const nonEphemeral = commandPaths.filter((path) => !this.isNpxEphemeralOpenClawPath(path));
188
+ if (nonEphemeral.length > 0) {
189
+ return nonEphemeral[0];
190
+ }
191
+
192
+ return commandPaths[0];
193
+ }
194
+
174
195
  // 检查 OpenClaw 是否安装
175
196
  checkOpenClaw() {
176
197
  this.log('\n═══════════════════════════════════════════════════', CYAN);
177
198
  this.log(' 灵爻 (Lingyao) Plugin 安装器', CYAN);
178
199
  this.log('═══════════════════════════════════════════════════\n', CYAN);
179
200
 
201
+ this.openclawCommand = this.resolveOpenClawCommandPath() || 'openclaw';
202
+ if (this.openclawCommand !== 'openclaw') {
203
+ this.info(`使用 openclaw 命令: ${this.openclawCommand}`);
204
+ }
205
+
180
206
  // 检查 OpenClaw 命令
181
- const result = this.exec('openclaw', ['--version'], { stdio: 'pipe' });
207
+ const result = this.exec(this.openclawCommand, ['--version'], { stdio: 'pipe' });
182
208
 
183
209
  if (result.success) {
184
210
  this.success('OpenClaw 已安装');
@@ -391,7 +417,11 @@ class LingyaoInstaller {
391
417
  restartGateway() {
392
418
  this.log('\n正在重启 OpenClaw Gateway...\n');
393
419
 
394
- const result = this.exec('openclaw', ['gateway', 'restart']);
420
+ const command = this.openclawCommand || this.resolveOpenClawCommandPath() || 'openclaw';
421
+ if (command !== 'openclaw') {
422
+ this.info(`重启时使用命令: ${command}`);
423
+ }
424
+ const result = this.exec(command, ['gateway', 'restart']);
395
425
 
396
426
  if (result.success) {
397
427
  this.success('Gateway 重启成功');
@@ -456,7 +486,7 @@ class LingyaoInstaller {
456
486
  if (this.gatewayToken) {
457
487
  headers['Authorization'] = `Bearer ${this.gatewayToken}`;
458
488
  }
459
- const req = https.request(url, { method: 'POST', headers }, (res) => {
489
+ const req = https.request(url, { method: 'POST', headers, timeout: 10000 }, (res) => {
460
490
  let chunk = '';
461
491
  res.on('data', (c) => chunk += c);
462
492
  res.on('end', () => {
@@ -464,6 +494,9 @@ class LingyaoInstaller {
464
494
  catch { reject(new Error(`Invalid JSON: ${chunk}`)); }
465
495
  });
466
496
  });
497
+ req.on('timeout', () => {
498
+ req.destroy(new Error('Request timeout while connecting to lingyao.live'));
499
+ });
467
500
  req.on('error', reject);
468
501
  req.write(data);
469
502
  req.end();
@@ -473,14 +506,18 @@ class LingyaoInstaller {
473
506
  httpsGet(path) {
474
507
  return new Promise((resolve, reject) => {
475
508
  const url = `${LINGYAO_API}${path}`;
476
- https.get(url, (res) => {
509
+ const req = https.get(url, { timeout: 10000 }, (res) => {
477
510
  let chunk = '';
478
511
  res.on('data', (c) => chunk += c);
479
512
  res.on('end', () => {
480
513
  try { resolve(JSON.parse(chunk)); }
481
514
  catch { reject(new Error(`Invalid JSON: ${chunk}`)); }
482
515
  });
483
- }).on('error', reject);
516
+ });
517
+ req.on('timeout', () => {
518
+ req.destroy(new Error('Request timeout while connecting to lingyao.live'));
519
+ });
520
+ req.on('error', reject);
484
521
  });
485
522
  }
486
523
 
@@ -585,6 +622,10 @@ class LingyaoInstaller {
585
622
 
586
623
  } catch (error) {
587
624
  this.error(`配对失败: ${error.message}`);
625
+ this.warn('网络诊断建议:');
626
+ this.log(' 1) curl -I https://api.lingyao.live/lyoc/health');
627
+ this.log(' 2) nslookup api.lingyao.live');
628
+ this.log(' 3) 如在公司网络/代理环境,请检查 TLS 拦截或防火墙策略');
588
629
  return false;
589
630
  }
590
631
  }
@@ -720,7 +761,8 @@ class LingyaoInstaller {
720
761
 
721
762
  // 重启网关
722
763
  this.log('\n重启 OpenClaw Gateway...');
723
- this.exec('openclaw', ['gateway', 'restart']);
764
+ const command = this.openclawCommand || this.resolveOpenClawCommandPath() || 'openclaw';
765
+ this.exec(command, ['gateway', 'restart']);
724
766
 
725
767
  this.success('\n✓ 卸载完成!\n');
726
768
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingyao037/openclaw-lingyao-cli",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Lingyao Channel Plugin for OpenClaw - bidirectional sync via lingyao.live server relay",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",