openclawsetup 1.0.5 → 1.0.6

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/bin/cli.mjs +86 -17
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -173,26 +173,42 @@ function detectExistingInstall() {
173
173
  const openclawDir = join(home, '.openclaw');
174
174
  const clawdbotDir = join(home, '.clawdbot');
175
175
 
176
+ let result = { installed: false };
177
+
176
178
  if (existsSync(openclawDir) || existsSync(clawdbotDir)) {
177
- return {
179
+ result = {
178
180
  installed: true,
179
181
  configDir: existsSync(openclawDir) ? openclawDir : clawdbotDir,
180
182
  name: existsSync(openclawDir) ? 'openclaw' : 'clawdbot',
181
183
  };
184
+ } else {
185
+ // 检查命令是否存在
186
+ const openclawResult = safeExec('openclaw --version');
187
+ if (openclawResult.ok) {
188
+ result = { installed: true, name: 'openclaw', version: openclawResult.output, configDir: openclawDir };
189
+ } else {
190
+ const clawdbotResult = safeExec('clawdbot --version');
191
+ if (clawdbotResult.ok) {
192
+ result = { installed: true, name: 'clawdbot', version: clawdbotResult.output, configDir: clawdbotDir };
193
+ }
194
+ }
182
195
  }
183
196
 
184
- // 检查命令是否存在
185
- const openclawResult = safeExec('openclaw --version');
186
- if (openclawResult.ok) {
187
- return { installed: true, name: 'openclaw', version: openclawResult.output };
188
- }
189
-
190
- const clawdbotResult = safeExec('clawdbot --version');
191
- if (clawdbotResult.ok) {
192
- return { installed: true, name: 'clawdbot', version: clawdbotResult.output };
197
+ // 如果已安装,尝试读取配置获取 token 和 port
198
+ if (result.installed && result.configDir) {
199
+ const configPath = join(result.configDir, result.name === 'openclaw' ? 'openclaw.json' : 'clawdbot.json');
200
+ if (existsSync(configPath)) {
201
+ try {
202
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
203
+ result.token = config.gateway?.auth?.token;
204
+ result.port = config.gateway?.port || 18789;
205
+ } catch (e) {
206
+ // 忽略解析错误
207
+ }
208
+ }
193
209
  }
194
210
 
195
- return { installed: false };
211
+ return result;
196
212
  }
197
213
 
198
214
  // 带进度动画的命令执行
@@ -550,16 +566,69 @@ async function main() {
550
566
  // 检测现有安装
551
567
  const existing = detectExistingInstall();
552
568
  if (existing.installed) {
553
- console.log(colors.yellow('\n检测到已有安装:'));
569
+ console.log(colors.bold(colors.green('\n========================================')));
570
+ console.log(colors.bold(colors.green('✅ OpenClaw 已安装')));
571
+ console.log(colors.bold(colors.green('========================================')));
572
+
554
573
  if (existing.configDir) {
555
- log.detail(`配置目录: ${existing.configDir}`);
574
+ console.log(colors.cyan('\n配置信息:'));
575
+ console.log(` 配置目录: ${colors.yellow(existing.configDir)}`);
556
576
  }
557
577
  if (existing.version) {
558
- log.detail(`版本: ${existing.version}`);
578
+ console.log(` 版本: ${colors.yellow(existing.version)}`);
579
+ }
580
+ if (existing.port) {
581
+ console.log(` Gateway 端口: ${colors.yellow(existing.port)}`);
582
+ }
583
+ if (existing.token) {
584
+ console.log(` Gateway Token: ${colors.yellow(existing.token)}`);
585
+ }
586
+
587
+ // 检测是否在 VPS 上
588
+ const isVPS = detectVPS();
589
+ const port = existing.port || 18789;
590
+ const token = existing.token || '<你的token>';
591
+
592
+ // 显示访问说明
593
+ if (isVPS) {
594
+ console.log(colors.cyan('\n📡 Dashboard 访问 (云服务器):'));
595
+ console.log(colors.gray(' Gateway 默认绑定 127.0.0.1,外部无法直接访问(安全设计)'));
596
+ console.log('');
597
+ console.log(colors.yellow(' 方式一:SSH 隧道(推荐,安全)'));
598
+ console.log(colors.gray(' 在本地电脑执行以下命令,保持终端窗口打开:'));
599
+ console.log(` ssh -N -L ${port}:127.0.0.1:${port} root@<服务器IP>`);
600
+ console.log(colors.gray(' 然后在本地浏览器访问:'));
601
+ console.log(` ${colors.green(`http://127.0.0.1:${port}/?token=${token}`)}`);
602
+ console.log('');
603
+ console.log(colors.yellow(' 方式二:直接暴露端口(不推荐,有安全风险)'));
604
+ console.log(colors.gray(' 1. 修改配置文件 ~/.openclaw/openclaw.json'));
605
+ console.log(colors.gray(' 将 "bind": "loopback" 改为 "bind": "all"'));
606
+ console.log(colors.gray(' 2. 在云服务器控制台开放端口 ' + port));
607
+ console.log(colors.gray(' - 腾讯云:安全组 → 入站规则 → 添加 TCP ' + port));
608
+ console.log(colors.gray(' - 阿里云:安全组 → 配置规则 → 添加 TCP ' + port));
609
+ console.log(colors.gray(' 3. 重启 Gateway:' + existing.name + ' gateway restart'));
610
+ console.log(colors.gray(' 4. 访问:http://<服务器IP>:' + port + '/?token=...'));
611
+ } else {
612
+ console.log(colors.cyan('\nDashboard 访问:'));
613
+ console.log(` ${colors.yellow(`http://127.0.0.1:${port}/?token=${token}`)}`);
559
614
  }
560
- console.log(colors.cyan('\n如需重新安装,请先卸载:'));
561
- console.log(` npm uninstall -g ${existing.name}`);
562
- console.log(` rm -rf ~/.openclaw ~/.clawdbot`);
615
+
616
+ console.log(colors.cyan('\n常用命令:'));
617
+ console.log(` 查看状态: ${colors.yellow(`${existing.name} status`)}`);
618
+ console.log(` 查看日志: ${colors.yellow(`${existing.name} gateway logs`)}`);
619
+ console.log(` 重启服务: ${colors.yellow(`${existing.name} gateway restart`)}`);
620
+ console.log(` 诊断问题: ${colors.yellow(`${existing.name} doctor`)}`);
621
+
622
+ console.log(colors.cyan('\n配置 AI 模型:'));
623
+ console.log(` ${colors.yellow('npx openclawapi@latest preset-claude')}`);
624
+
625
+ console.log(colors.cyan('\n配置聊天渠道:'));
626
+ console.log(` Discord: ${colors.yellow('npx openclawdc')}`);
627
+ console.log(` 飞书: ${colors.yellow('npx openclawfs')}`);
628
+
629
+ console.log(colors.gray('\n如需重新安装,请先卸载:'));
630
+ console.log(colors.gray(` npm uninstall -g ${existing.name}`));
631
+ console.log(colors.gray(` rm -rf ~/.openclaw ~/.clawdbot`));
563
632
  console.log('');
564
633
  process.exit(0);
565
634
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclawsetup",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "一键安装 OpenClaw - 自动完成基础部署,无需交互",
5
5
  "type": "module",
6
6
  "bin": {