@sciagent/cli 1.0.51 → 1.0.53

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
@@ -8,6 +8,7 @@
8
8
  const { spawn } = require('child_process');
9
9
  const path = require('path');
10
10
  const fs = require('fs');
11
+ const os = require('os');
11
12
 
12
13
  // 平台和架构映射
13
14
  const PLATFORM_MAP = {
@@ -47,6 +48,15 @@ function getBinaryPath() {
47
48
  // 尝试从node_modules中查找
48
49
  const binName = platform === 'win32' ? 'sciagent.exe' : 'sciagent';
49
50
 
51
+ // 方法0: 从 ~/.sciagent/bin/ 或 %LOCALAPPDATA%\sciagent\bin 查找(postinstall下载位置)
52
+ const homeBinDir = platform === 'win32'
53
+ ? path.join(process.env.LOCALAPPDATA || os.homedir(), 'sciagent', 'bin')
54
+ : path.join(os.homedir(), '.sciagent', 'bin');
55
+ const homeBinPath = path.join(homeBinDir, binName);
56
+ if (fs.existsSync(homeBinPath)) {
57
+ return homeBinPath;
58
+ }
59
+
50
60
  // 方法1: 从optionalDependencies安装的包中查找
51
61
  try {
52
62
  const packagePath = require.resolve(`${packageName}/bin/${binName}`);
@@ -69,12 +79,12 @@ function getBinaryPath() {
69
79
 
70
80
  // 未找到二进制文件
71
81
  console.error(`Error: Could not find SciAgent binary for ${platform}-${arch}`);
72
- console.error(`Tried to find package: ${packageName}`);
73
- console.error('');
74
- console.error('Please install the platform-specific package:');
75
- console.error(` npm install ${packageName}`);
82
+ console.error(`Tried locations:`);
83
+ console.error(` ${homeBinPath}`);
84
+ console.error(` ${packageName}/bin/${binName} (npm package)`);
85
+ console.error(` ${localPath} (dev mode)`);
76
86
  console.error('');
77
- console.error('Or install all platform packages:');
87
+ console.error('Please reinstall:');
78
88
  console.error(' npm install -g @sciagent/cli');
79
89
  process.exit(1);
80
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sciagent/cli",
3
- "version": "1.0.51",
3
+ "version": "1.0.53",
4
4
  "description": "SciAgent CLI - AI Research Assistant",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -15,11 +15,11 @@
15
15
  "postinstall": "node scripts/postinstall.js"
16
16
  },
17
17
  "optionalDependencies": {
18
- "@sciagent/cli-linux-x64": "1.0.51",
18
+ "@sciagent/cli-linux-x64": "1.0.53",
19
19
  "@sciagent/cli-linux-arm64": "1.0.39",
20
20
  "@sciagent/cli-darwin-x64": "1.0.39",
21
21
  "@sciagent/cli-darwin-arm64": "1.0.39",
22
- "@sciagent/cli-win32-x64": "1.0.51",
22
+ "@sciagent/cli-win32-x64": "1.0.53",
23
23
  "@sciagent/cli-win32-arm64": "1.0.39"
24
24
  },
25
25
  "keywords": [
@@ -27,7 +27,10 @@ const ARCH_MAP = {
27
27
  };
28
28
 
29
29
  // 当前版本号 - 每次发布时同步更新
30
- const CURRENT_VERSION = '1.0.51';
30
+ const CURRENT_VERSION = '1.0.53';
31
+
32
+ // GitHub Releases 回退版本列表(当当前版本的 release 不存在时尝试)
33
+ const GITHUB_FALLBACK_VERSIONS = ['1.0.50', '1.0.48', '1.0.46', '1.0.40', '1.0.38', '1.0.36'];
31
34
 
32
35
  // Releases 服务器配置
33
36
  // 优先使用环境变量,否则使用默认服务器
@@ -80,6 +83,19 @@ function checkBinaryInstalled(platform, arch) {
80
83
  const packageName = `@sciagent/cli-${platform}-${arch}`;
81
84
  const binName = platform === 'win32' ? 'sciagent.exe' : 'sciagent';
82
85
 
86
+ // 检查 ~/.sciagent/bin/ 或 %LOCALAPPDATA%\sciagent\bin(postinstall下载位置)
87
+ const homeBinDir = platform === 'win32'
88
+ ? path.join(process.env.LOCALAPPDATA || os.homedir(), 'sciagent', 'bin')
89
+ : path.join(os.homedir(), '.sciagent', 'bin');
90
+ const homeBinPath = path.join(homeBinDir, binName);
91
+ if (fs.existsSync(homeBinPath)) {
92
+ const stats = fs.statSync(homeBinPath);
93
+ if (stats.size > 10 * 1024 * 1024) {
94
+ return { installed: true, path: homeBinPath };
95
+ }
96
+ }
97
+
98
+ // 检查 npm 包路径
83
99
  try {
84
100
  const packagePath = require.resolve(`${packageName}/bin/${binName}`);
85
101
  return { installed: true, path: packagePath };
@@ -590,6 +606,7 @@ function installBinaryPackage(platform, arch) {
590
606
  }
591
607
 
592
608
  async function main() {
609
+ console.log('[postinstall] Starting postinstall script...');
593
610
  const platform = PLATFORM_MAP[process.platform];
594
611
  const arch = ARCH_MAP[process.arch];
595
612
 
@@ -632,7 +649,19 @@ async function main() {
632
649
  // Releases 服务器失败,尝试 GitHub Releases
633
650
  console.log('');
634
651
  console.log(' 尝试从 GitHub Releases 下载...');
635
- const githubSuccess = await downloadFromGitHub(platform, arch, CURRENT_VERSION);
652
+
653
+ // 尝试当前版本
654
+ let githubSuccess = await downloadFromGitHub(platform, arch, CURRENT_VERSION);
655
+
656
+ // 如果当前版本失败,尝试回退版本
657
+ if (!githubSuccess) {
658
+ for (const fallbackVersion of GITHUB_FALLBACK_VERSIONS) {
659
+ if (fallbackVersion === CURRENT_VERSION) continue;
660
+ console.log(` 尝试回退版本 v${fallbackVersion}...`);
661
+ githubSuccess = await downloadFromGitHub(platform, arch, fallbackVersion);
662
+ if (githubSuccess) break;
663
+ }
664
+ }
636
665
 
637
666
  if (!githubSuccess) {
638
667
  // GitHub 也失败,回退到 npm 包安装