@sciagent/cli 1.0.80 → 1.0.82

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/sciagent.js CHANGED
@@ -5,13 +5,21 @@
5
5
  * 自动识别平台并调用对应的预编译二进制文件
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 fs = require('fs');
11
11
  const os = require('os');
12
+ const https = require('https');
13
+ const http = require('http');
12
14
 
13
15
  // 当前版本号 - 与 postinstall.js 和 package.json 保持同步
14
- const CURRENT_VERSION = '1.0.80';
16
+ const CURRENT_VERSION = '1.0.82';
17
+
18
+ // 极狐GitLab下载配置
19
+ const JIHULAB_URL = 'https://jihulab.com';
20
+ const JIHULAB_PROJECT_ID = 351778;
21
+ const JIHULAB_PACKAGE_NAME = 'sciagent';
22
+ const JIHULAB_DOWNLOAD_TOKEN = '2qxfs606HfwESUYJxtRlgm86MQp1OjVnazAK.01.101vzs2qo';
15
23
 
16
24
  // 平台和架构映射
17
25
  const PLATFORM_MAP = {
@@ -75,25 +83,19 @@ function getBinaryPath() {
75
83
  if (fs.existsSync(homeBinPath)) {
76
84
  const stats = fs.statSync(homeBinPath);
77
85
  if (stats.size > 10 * 1024 * 1024) {
78
- // 严格版本检查:版本不匹配时拒绝运行,避免使用旧版有bug的二进制
86
+ // 版本检查:不匹配时自动下载新版本
79
87
  const versionFile = path.join(homeBinDir, '.version');
80
88
  if (fs.existsSync(versionFile)) {
81
89
  const installedVersion = fs.readFileSync(versionFile, 'utf8').trim();
82
90
  const cmp = compareVersions(installedVersion, CURRENT_VERSION);
83
91
  if (cmp < 0) {
84
- // 安装版本低于预期版本 → 旧版有bug,删除
85
- console.error(`[ERROR] Binary version outdated: installed=${installedVersion}, expected=${CURRENT_VERSION}`);
86
- console.error(` The cached binary is outdated and may have critical bugs (e.g., 405 error on login).`);
87
- console.error(` Deleting cached binary and exiting. Please run 'npm install -g @sciagent/cli' again.`);
88
- try {
89
- fs.unlinkSync(homeBinPath);
90
- fs.unlinkSync(versionFile);
91
- console.error(` [OK] Deleted: ${homeBinPath}`);
92
- console.error(` [OK] Deleted: ${versionFile}`);
93
- } catch (e) {
94
- console.error(` [WARN] Failed to delete: ${e.message}`);
95
- console.error(` Please manually delete: ${homeBinDir}`);
96
- }
92
+ // 安装版本低于预期版本 → 自动下载新版本
93
+ console.log(`[INFO] Binary version outdated: installed=${installedVersion}, expected=${CURRENT_VERSION}`);
94
+ console.log(`[INFO] Downloading new version...`);
95
+ try { fs.unlinkSync(homeBinPath); fs.unlinkSync(versionFile); } catch (e) {}
96
+ const downloaded = downloadBinary(platform, arch, CURRENT_VERSION);
97
+ if (downloaded) return downloaded;
98
+ console.error(`[ERROR] Failed to download v${CURRENT_VERSION}. Please run: npm install -g @sciagent/cli`);
97
99
  process.exit(1);
98
100
  } else if (cmp > 0) {
99
101
  // 安装版本高于预期 → 用户手动装了新版,允许运行
@@ -101,15 +103,12 @@ function getBinaryPath() {
101
103
  }
102
104
  // cmp === 0 → 版本匹配,正常使用
103
105
  } else {
104
- // 没有 .version 文件,说明是极旧版本(v1.0.64之前),可能有405 bug
105
- console.error(`[ERROR] Binary version unknown (no .version file). This binary may be outdated.`);
106
- console.error(` Deleting cached binary and exiting. Please run 'npm install -g @sciagent/cli' again.`);
107
- try {
108
- fs.unlinkSync(homeBinPath);
109
- console.error(` [OK] Deleted: ${homeBinPath}`);
110
- } catch (e) {
111
- console.error(` [WARN] Failed to delete: ${e.message}`);
112
- }
106
+ // 没有 .version 文件 → 自动下载新版本
107
+ console.log(`[INFO] Binary version unknown (no .version file), downloading v${CURRENT_VERSION}...`);
108
+ try { fs.unlinkSync(homeBinPath); } catch (e) {}
109
+ const downloaded = downloadBinary(platform, arch, CURRENT_VERSION);
110
+ if (downloaded) return downloaded;
111
+ console.error(`[ERROR] Failed to download v${CURRENT_VERSION}. Please run: npm install -g @sciagent/cli`);
113
112
  process.exit(1);
114
113
  }
115
114
  return homeBinPath;
@@ -136,18 +135,86 @@ function getBinaryPath() {
136
135
  return binPath;
137
136
  }
138
137
 
139
- // 未找到二进制文件
140
- console.error(`Error: Could not find SciAgent binary for ${platform}-${arch}`);
141
- console.error(`Tried locations:`);
142
- console.error(` ${homeBinPath}`);
143
- console.error(` ${packageName}/bin/${binName} (npm package)`);
144
- console.error(` ${localPath} (dev mode)`);
145
- console.error('');
146
- console.error('Please reinstall:');
147
- console.error(' npm install -g @sciagent/cli');
138
+ // 未找到二进制文件 - 自动下载
139
+ console.log(`⚠️ SciAgent binary not found for ${platform}-${arch}`);
140
+ console.log(` Attempting to download from JiHuLab...`);
141
+
142
+ const downloaded = downloadBinary(platform, arch, CURRENT_VERSION);
143
+ if (downloaded && fs.existsSync(downloaded)) {
144
+ return downloaded;
145
+ }
146
+
147
+ console.error(`\n❌ Failed to download SciAgent binary.`);
148
+ console.error(`Please reinstall: npm install -g @sciagent/cli`);
148
149
  process.exit(1);
149
150
  }
150
151
 
152
+ /**
153
+ * 从极狐GitLab下载二进制文件
154
+ */
155
+ function downloadBinary(platform, arch, version) {
156
+ const binName = platform === 'win32' ? 'sciagent.exe' : 'sciagent';
157
+ const ext = platform === 'win32' ? '.exe' : '';
158
+ const filename = `sciagent-${platform}-${arch}${ext}`;
159
+
160
+ const downloadUrl = (
161
+ `${JIHULAB_URL}/api/v4/projects/${JIHULAB_PROJECT_ID}` +
162
+ `/packages/generic/${JIHULAB_PACKAGE_NAME}/${version}/${filename}` +
163
+ `?access_token=${JIHULAB_DOWNLOAD_TOKEN}`
164
+ );
165
+
166
+ const installDir = platform === 'win32'
167
+ ? path.join(process.env.LOCALAPPDATA || os.homedir(), 'sciagent', 'bin')
168
+ : path.join(os.homedir(), '.sciagent', 'bin');
169
+ fs.mkdirSync(installDir, { recursive: true });
170
+ const targetPath = path.join(installDir, binName);
171
+
172
+ console.log(` Downloading ${filename} v${version}...`);
173
+ console.log(` Target: ${targetPath}`);
174
+
175
+ try {
176
+ // 同步下载(使用curl或PowerShell)
177
+ if (platform === 'win32') {
178
+ // Windows: 使用 PowerShell 下载
179
+ const psCmd = `
180
+ $ProgressPreference = 'SilentlyContinue'
181
+ Invoke-WebRequest -Uri '${downloadUrl}' -OutFile '${targetPath}' -UseBasicParsing
182
+ `.trim();
183
+ execSync(`powershell -NoProfile -Command "${psCmd.replace(/"/g, '\\"')}"`, {
184
+ stdio: 'pipe',
185
+ timeout: 600000
186
+ });
187
+ } else {
188
+ // Linux/macOS: 使用 curl
189
+ execSync(`curl -fsSL -o '${targetPath}' '${downloadUrl}'`, {
190
+ stdio: 'pipe',
191
+ timeout: 600000
192
+ });
193
+ fs.chmodSync(targetPath, 0o755);
194
+ }
195
+
196
+ // 验证下载
197
+ if (fs.existsSync(targetPath)) {
198
+ const stats = fs.statSync(targetPath);
199
+ if (stats.size > 10 * 1024 * 1024) {
200
+ console.log(` ✅ Downloaded: ${(stats.size / (1024 * 1024)).toFixed(1)} MB`);
201
+ // 写入版本文件
202
+ fs.writeFileSync(path.join(installDir, '.version'), version);
203
+ return targetPath;
204
+ } else {
205
+ console.error(` ❌ Downloaded file too small: ${(stats.size / 1024).toFixed(0)} KB`);
206
+ try { fs.unlinkSync(targetPath); } catch (e) {}
207
+ }
208
+ }
209
+ } catch (e) {
210
+ console.error(` ❌ Download failed: ${e.message}`);
211
+ // 清理可能的部分下载
212
+ try { if (fs.existsSync(targetPath)) fs.unlinkSync(targetPath); } catch (e2) {}
213
+ }
214
+
215
+ return null;
216
+ }
217
+
151
218
  /**
152
219
  * 主函数
153
220
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sciagent/cli",
3
- "version": "1.0.80",
3
+ "version": "1.0.82",
4
4
  "description": "SciAgent CLI - AI Research Assistant",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -15,12 +15,12 @@
15
15
  "postinstall": "node scripts/postinstall.js"
16
16
  },
17
17
  "optionalDependencies": {
18
- "@sciagent/cli-linux-x64": "1.0.74",
19
- "@sciagent/cli-linux-arm64": "1.0.39",
20
- "@sciagent/cli-darwin-x64": "1.0.39",
21
- "@sciagent/cli-darwin-arm64": "1.0.39",
22
- "@sciagent/cli-win32-x64": "1.0.80",
23
- "@sciagent/cli-win32-arm64": "1.0.39"
18
+ "@sciagent/cli-linux-x64": "1.0.82",
19
+ "@sciagent/cli-linux-arm64": "1.0.82",
20
+ "@sciagent/cli-darwin-x64": "1.0.82",
21
+ "@sciagent/cli-darwin-arm64": "1.0.82",
22
+ "@sciagent/cli-win32-x64": "1.0.82",
23
+ "@sciagent/cli-win32-arm64": "1.0.82"
24
24
  },
25
25
  "keywords": [
26
26
  "ai",
@@ -27,7 +27,7 @@ const ARCH_MAP = {
27
27
  };
28
28
 
29
29
  // 当前版本号 - 每次发布时同步更新
30
- const CURRENT_VERSION = '1.0.80';
30
+ const CURRENT_VERSION = '1.0.82';
31
31
 
32
32
  // GitHub Releases 回退版本列表(当当前版本的 release 不存在时尝试)
33
33
  const GITHUB_FALLBACK_VERSIONS = ['1.0.50', '1.0.48', '1.0.46', '1.0.40', '1.0.38', '1.0.36'];
@@ -675,30 +675,29 @@ async function main() {
675
675
  } else {
676
676
  console.log(`⚠️ Platform binary not found: ${packageName}`);
677
677
 
678
- // 下载策略: 1) Releases服务器 2) 极狐GitLab 3) npm包
678
+ // 下载策略: 1) 极狐GitLab(稳定可靠) 2) Releases服务器 3) npm包
679
679
  console.log('');
680
- console.log(' 尝试从 Releases 服务器下载...');
681
- const serverSuccess = await downloadFromServer(platform, arch, CURRENT_VERSION);
680
+ console.log(' 尝试从极狐GitLab下载...');
681
+ let jihuSuccess = await downloadFromJiHuLab(platform, arch, CURRENT_VERSION);
682
682
 
683
- if (!serverSuccess) {
684
- // Releases 服务器失败,尝试极狐GitLab
685
- console.log('');
686
- console.log(' 尝试从极狐GitLab下载...');
687
-
688
- let jihuSuccess = await downloadFromJiHuLab(platform, arch, CURRENT_VERSION);
689
-
690
- // 如果当前版本失败,尝试回退版本
691
- if (!jihuSuccess) {
692
- for (const fallbackVersion of GITHUB_FALLBACK_VERSIONS) {
693
- if (fallbackVersion === CURRENT_VERSION) continue;
694
- console.log(` 尝试回退版本 v${fallbackVersion}...`);
695
- jihuSuccess = await downloadFromJiHuLab(platform, arch, fallbackVersion);
696
- if (jihuSuccess) break;
697
- }
683
+ // 如果当前版本失败,尝试回退版本
684
+ if (!jihuSuccess) {
685
+ for (const fallbackVersion of GITHUB_FALLBACK_VERSIONS) {
686
+ if (fallbackVersion === CURRENT_VERSION) continue;
687
+ console.log(` 尝试回退版本 v${fallbackVersion}...`);
688
+ jihuSuccess = await downloadFromJiHuLab(platform, arch, fallbackVersion);
689
+ if (jihuSuccess) break;
698
690
  }
691
+ }
692
+
693
+ if (!jihuSuccess) {
694
+ // 极狐GitLab 失败,尝试 Releases 服务器
695
+ console.log('');
696
+ console.log(' 尝试从 Releases 服务器下载...');
697
+ const serverSuccess = await downloadFromServer(platform, arch, CURRENT_VERSION);
699
698
 
700
- if (!jihuSuccess) {
701
- // 极狐GitLab 也失败,回退到 npm 包安装
699
+ if (!serverSuccess) {
700
+ // Releases 服务器也失败,回退到 npm 包安装
702
701
  console.log('');
703
702
  console.log(' 回退到 npm 包安装...');
704
703
  const npmSuccess = installBinaryPackage(platform, arch);