copilot-hub-cli 1.1.1 → 1.1.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.
package/bin/run.js CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  /**
4
4
  * Copilot Hub CLI — 跨平台启动器
5
- * 检测当前系统平台和架构,启动对应的 Go 二进制
5
+ * 启动时自动检查更新,然后运行对应平台的 Go 二进制
6
6
  */
7
7
 
8
- const { spawn } = require('child_process');
8
+ const { spawn, execSync } = require('child_process');
9
9
  const path = require('path');
10
10
  const os = require('os');
11
11
  const fs = require('fs');
@@ -42,33 +42,80 @@ function getBinaryPath() {
42
42
  return binaryPath;
43
43
  }
44
44
 
45
- const binaryPath = getBinaryPath();
45
+ // 自动更新:启动前检查 npm 是否有新版本
46
+ function autoUpdate() {
47
+ // 跳过更新检查:--no-update 参数
48
+ if (process.argv.includes('--no-update')) return;
46
49
 
47
- // 启动 Go 二进制,继承标准输入输出(支持 Ctrl+C)
48
- const child = spawn(binaryPath, process.argv.slice(2), {
49
- stdio: 'inherit',
50
- env: process.env,
51
- });
50
+ try {
51
+ const pkg = require('../package.json');
52
+ const currentVersion = pkg.version;
52
53
 
53
- // 转发退出信号
54
- ['SIGINT', 'SIGTERM', 'SIGHUP'].forEach(signal => {
55
- process.on(signal, () => {
56
- child.kill(signal);
57
- });
58
- });
54
+ console.log(`🔍 检查更新... (当前 v${currentVersion})`);
55
+ const latest = execSync('npm view copilot-hub-cli version 2>/dev/null', {
56
+ encoding: 'utf8', timeout: 8000
57
+ }).trim();
59
58
 
60
- child.on('exit', (code, signal) => {
61
- if (signal) {
62
- process.exit(1);
59
+ if (latest && latest !== currentVersion && isNewer(latest, currentVersion)) {
60
+ console.log(`🆕 发现新版本 v${latest},正在自动更新...`);
61
+ try {
62
+ execSync('npm install -g copilot-hub-cli@latest', {
63
+ stdio: 'inherit', timeout: 120000
64
+ });
65
+ console.log(`✅ 更新成功!重新启动中...\n`);
66
+ // 用新版本重新启动自己(带 --no-update 防止循环)
67
+ const child = spawn(process.argv[0], [process.argv[1], '--no-update', ...process.argv.slice(2)], {
68
+ stdio: 'inherit', env: process.env
69
+ });
70
+ child.on('exit', (code) => process.exit(code || 0));
71
+ return true; // 表示已接管,主流程不要继续
72
+ } catch (e) {
73
+ console.log(`⚠️ 自动更新失败,使用当前版本继续运行`);
74
+ }
75
+ } else {
76
+ console.log(`✅ 已是最新版本 v${currentVersion}`);
77
+ }
78
+ } catch (e) {
79
+ // 网络不通等,静默跳过
63
80
  }
64
- process.exit(code || 0);
65
- });
66
-
67
- child.on('error', (err) => {
68
- console.error(`❌ 启动失败: ${err.message}`);
69
- console.error(` 二进制路径: ${binaryPath}`);
70
- if (err.code === 'EACCES') {
71
- console.error(` 请运行: chmod +x "${binaryPath}"`);
81
+ return false;
82
+ }
83
+
84
+ function isNewer(latest, current) {
85
+ const a = latest.split('.').map(Number);
86
+ const b = current.split('.').map(Number);
87
+ for (let i = 0; i < 3; i++) {
88
+ if ((a[i]||0) > (b[i]||0)) return true;
89
+ if ((a[i]||0) < (b[i]||0)) return false;
72
90
  }
73
- process.exit(1);
74
- });
91
+ return false;
92
+ }
93
+
94
+ // 先检查更新
95
+ if (autoUpdate()) {
96
+ // autoUpdate 已接管进程,等待新版本启动
97
+ } else {
98
+ // 正常启动
99
+ const binaryPath = getBinaryPath();
100
+
101
+ const child = spawn(binaryPath, process.argv.slice(2).filter(a => a !== '--no-update'), {
102
+ stdio: 'inherit',
103
+ env: process.env,
104
+ });
105
+
106
+ ['SIGINT', 'SIGTERM', 'SIGHUP'].forEach(signal => {
107
+ process.on(signal, () => { child.kill(signal); });
108
+ });
109
+
110
+ child.on('exit', (code, signal) => {
111
+ process.exit(signal ? 1 : (code || 0));
112
+ });
113
+
114
+ child.on('error', (err) => {
115
+ console.error(`❌ 启动失败: ${err.message}`);
116
+ if (err.code === 'EACCES') {
117
+ console.error(` 请运行: chmod +x "${binaryPath}"`);
118
+ }
119
+ process.exit(1);
120
+ });
121
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copilot-hub-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Copilot Hub CLI - AI 编程助手代理服务,一键启动 GitHub Copilot 代理 + Web 管理面板",
5
5
  "keywords": [
6
6
  "copilot",