@sciagent/cli 1.0.67 → 1.0.69

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
@@ -1,189 +1,189 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * SciAgent CLI 薄壳脚本
5
- * 自动识别平台并调用对应的预编译二进制文件
6
- */
7
-
8
- const { spawn } = require('child_process');
9
- const path = require('path');
10
- const fs = require('fs');
11
- const os = require('os');
12
-
13
- // 当前版本号 - 与 postinstall.js 和 package.json 保持同步
14
- const CURRENT_VERSION = '1.0.67';
15
-
16
- // 平台和架构映射
17
- const PLATFORM_MAP = {
18
- linux: 'linux',
19
- darwin: 'darwin',
20
- win32: 'win32'
21
- };
22
-
23
- const ARCH_MAP = {
24
- x64: 'x64',
25
- arm64: 'arm64',
26
- amd64: 'x64'
27
- };
28
-
29
- /**
30
- * 获取当前平台的二进制文件路径
31
- */
32
- function getBinaryPath() {
33
- const platform = PLATFORM_MAP[process.platform];
34
- const arch = ARCH_MAP[process.arch];
35
-
36
- if (!platform) {
37
- console.error(`Error: Unsupported platform: ${process.platform}`);
38
- console.error('Supported platforms: linux, darwin, win32');
39
- process.exit(1);
40
- }
41
-
42
- if (!arch) {
43
- console.error(`Error: Unsupported architecture: ${process.arch}`);
44
- console.error('Supported architectures: x64, arm64');
45
- process.exit(1);
46
- }
47
-
48
- // 构建包名
49
- const packageName = `@sciagent/cli-${platform}-${arch}`;
50
-
51
- // 尝试从node_modules中查找
52
- const binName = platform === 'win32' ? 'sciagent.exe' : 'sciagent';
53
-
54
- // 方法0: 从 ~/.sciagent/bin/ 或 %LOCALAPPDATA%\sciagent\bin 查找(postinstall下载位置)
55
- const homeBinDir = platform === 'win32'
56
- ? path.join(process.env.LOCALAPPDATA || os.homedir(), 'sciagent', 'bin')
57
- : path.join(os.homedir(), '.sciagent', 'bin');
58
- const homeBinPath = path.join(homeBinDir, binName);
59
- if (fs.existsSync(homeBinPath)) {
60
- const stats = fs.statSync(homeBinPath);
61
- if (stats.size > 10 * 1024 * 1024) {
62
- // 检查版本是否匹配
63
- const versionFile = path.join(homeBinDir, '.version');
64
- if (fs.existsSync(versionFile)) {
65
- const installedVersion = fs.readFileSync(versionFile, 'utf8').trim();
66
- if (installedVersion !== CURRENT_VERSION) {
67
- console.warn(`⚠️ Binary version mismatch: installed=${installedVersion}, expected=${CURRENT_VERSION}`);
68
- console.warn(` Run 'npm install -g @sciagent/cli' to update`);
69
- }
70
- }
71
- return homeBinPath;
72
- }
73
- }
74
-
75
- // 方法1: 从optionalDependencies安装的包中查找
76
- try {
77
- const packagePath = require.resolve(`${packageName}/bin/${binName}`);
78
- return packagePath;
79
- } catch (e) {
80
- // 包未安装,继续尝试其他方法
81
- }
82
-
83
- // 方法2: 从本地packages目录查找(开发模式)
84
- const localPath = path.join(__dirname, '..', 'packages', `sciagent-${platform}-${arch}`, 'bin', binName);
85
- if (fs.existsSync(localPath)) {
86
- return localPath;
87
- }
88
-
89
- // 方法3: 从当前目录的bin查找
90
- const binPath = path.join(__dirname, '..', 'bin', platform, arch, binName);
91
- if (fs.existsSync(binPath)) {
92
- return binPath;
93
- }
94
-
95
- // 未找到二进制文件
96
- console.error(`Error: Could not find SciAgent binary for ${platform}-${arch}`);
97
- console.error(`Tried locations:`);
98
- console.error(` ${homeBinPath}`);
99
- console.error(` ${packageName}/bin/${binName} (npm package)`);
100
- console.error(` ${localPath} (dev mode)`);
101
- console.error('');
102
- console.error('Please reinstall:');
103
- console.error(' npm install -g @sciagent/cli');
104
- process.exit(1);
105
- }
106
-
107
- /**
108
- * 主函数
109
- */
110
- function main() {
111
- const binaryPath = getBinaryPath();
112
-
113
- // 检查二进制文件是否存在
114
- if (!fs.existsSync(binaryPath)) {
115
- console.error(`Error: Binary not found at: ${binaryPath}`);
116
- console.error('The package may be corrupted. Please reinstall:');
117
- console.error(' npm install -g @sciagent/cli');
118
- process.exit(1);
119
- }
120
-
121
- // 检查可执行权限(非Windows)
122
- if (process.platform !== 'win32') {
123
- try {
124
- fs.accessSync(binaryPath, fs.constants.X_OK);
125
- } catch (e) {
126
- // 添加可执行权限
127
- fs.chmodSync(binaryPath, 0o755);
128
- }
129
- }
130
-
131
- // 获取命令行参数(跳过node和脚本路径)
132
- const args = process.argv.slice(2);
133
-
134
- // 启动子进程
135
- const child = spawn(binaryPath, args, {
136
- stdio: 'inherit', // 继承父进程的stdio
137
- windowsHide: false // Windows下不隐藏控制台
138
- });
139
-
140
- // 处理子进程退出
141
- child.on('exit', (code, signal) => {
142
- if (signal) {
143
- // 被信号终止
144
- process.kill(process.pid, signal);
145
- } else {
146
- // 正常退出,传递退出码
147
- process.exit(code || 0);
148
- }
149
- });
150
-
151
- // 处理子进程错误
152
- child.on('error', (err) => {
153
- if (err.code === 'ENOENT') {
154
- console.error(`Error: Could not execute binary: ${binaryPath}`);
155
- console.error('The binary may be corrupted or missing.');
156
- } else if (err.code === 'EACCES') {
157
- console.error(`Error: Permission denied: ${binaryPath}`);
158
- console.error('Please check file permissions.');
159
- } else {
160
- console.error(`Error: Failed to start SciAgent: ${err.message}`);
161
- }
162
- process.exit(1);
163
- });
164
-
165
- // 转发信号到子进程
166
- process.on('SIGINT', () => {
167
- child.kill('SIGINT');
168
- });
169
-
170
- process.on('SIGTERM', () => {
171
- child.kill('SIGTERM');
172
- });
173
-
174
- // Windows下处理CTRL+C
175
- if (process.platform === 'win32') {
176
- const readline = require('readline');
177
- const rl = readline.createInterface({
178
- input: process.stdin,
179
- output: process.stdout
180
- });
181
-
182
- rl.on('SIGINT', () => {
183
- child.kill('SIGINT');
184
- });
185
- }
186
- }
187
-
188
- // 运行主函数
189
- main();
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * SciAgent CLI 薄壳脚本
5
+ * 自动识别平台并调用对应的预编译二进制文件
6
+ */
7
+
8
+ const { spawn } = require('child_process');
9
+ const path = require('path');
10
+ const fs = require('fs');
11
+ const os = require('os');
12
+
13
+ // 当前版本号 - 与 postinstall.js 和 package.json 保持同步
14
+ const CURRENT_VERSION = '1.0.69';
15
+
16
+ // 平台和架构映射
17
+ const PLATFORM_MAP = {
18
+ linux: 'linux',
19
+ darwin: 'darwin',
20
+ win32: 'win32'
21
+ };
22
+
23
+ const ARCH_MAP = {
24
+ x64: 'x64',
25
+ arm64: 'arm64',
26
+ amd64: 'x64'
27
+ };
28
+
29
+ /**
30
+ * 获取当前平台的二进制文件路径
31
+ */
32
+ function getBinaryPath() {
33
+ const platform = PLATFORM_MAP[process.platform];
34
+ const arch = ARCH_MAP[process.arch];
35
+
36
+ if (!platform) {
37
+ console.error(`Error: Unsupported platform: ${process.platform}`);
38
+ console.error('Supported platforms: linux, darwin, win32');
39
+ process.exit(1);
40
+ }
41
+
42
+ if (!arch) {
43
+ console.error(`Error: Unsupported architecture: ${process.arch}`);
44
+ console.error('Supported architectures: x64, arm64');
45
+ process.exit(1);
46
+ }
47
+
48
+ // 构建包名
49
+ const packageName = `@sciagent/cli-${platform}-${arch}`;
50
+
51
+ // 尝试从node_modules中查找
52
+ const binName = platform === 'win32' ? 'sciagent.exe' : 'sciagent';
53
+
54
+ // 方法0: 从 ~/.sciagent/bin/ 或 %LOCALAPPDATA%\sciagent\bin 查找(postinstall下载位置)
55
+ const homeBinDir = platform === 'win32'
56
+ ? path.join(process.env.LOCALAPPDATA || os.homedir(), 'sciagent', 'bin')
57
+ : path.join(os.homedir(), '.sciagent', 'bin');
58
+ const homeBinPath = path.join(homeBinDir, binName);
59
+ if (fs.existsSync(homeBinPath)) {
60
+ const stats = fs.statSync(homeBinPath);
61
+ if (stats.size > 10 * 1024 * 1024) {
62
+ // 检查版本是否匹配
63
+ const versionFile = path.join(homeBinDir, '.version');
64
+ if (fs.existsSync(versionFile)) {
65
+ const installedVersion = fs.readFileSync(versionFile, 'utf8').trim();
66
+ if (installedVersion !== CURRENT_VERSION) {
67
+ console.warn(`⚠️ Binary version mismatch: installed=${installedVersion}, expected=${CURRENT_VERSION}`);
68
+ console.warn(` Run 'npm install -g @sciagent/cli' to update`);
69
+ }
70
+ }
71
+ return homeBinPath;
72
+ }
73
+ }
74
+
75
+ // 方法1: 从optionalDependencies安装的包中查找
76
+ try {
77
+ const packagePath = require.resolve(`${packageName}/bin/${binName}`);
78
+ return packagePath;
79
+ } catch (e) {
80
+ // 包未安装,继续尝试其他方法
81
+ }
82
+
83
+ // 方法2: 从本地packages目录查找(开发模式)
84
+ const localPath = path.join(__dirname, '..', 'packages', `sciagent-${platform}-${arch}`, 'bin', binName);
85
+ if (fs.existsSync(localPath)) {
86
+ return localPath;
87
+ }
88
+
89
+ // 方法3: 从当前目录的bin查找
90
+ const binPath = path.join(__dirname, '..', 'bin', platform, arch, binName);
91
+ if (fs.existsSync(binPath)) {
92
+ return binPath;
93
+ }
94
+
95
+ // 未找到二进制文件
96
+ console.error(`Error: Could not find SciAgent binary for ${platform}-${arch}`);
97
+ console.error(`Tried locations:`);
98
+ console.error(` ${homeBinPath}`);
99
+ console.error(` ${packageName}/bin/${binName} (npm package)`);
100
+ console.error(` ${localPath} (dev mode)`);
101
+ console.error('');
102
+ console.error('Please reinstall:');
103
+ console.error(' npm install -g @sciagent/cli');
104
+ process.exit(1);
105
+ }
106
+
107
+ /**
108
+ * 主函数
109
+ */
110
+ function main() {
111
+ const binaryPath = getBinaryPath();
112
+
113
+ // 检查二进制文件是否存在
114
+ if (!fs.existsSync(binaryPath)) {
115
+ console.error(`Error: Binary not found at: ${binaryPath}`);
116
+ console.error('The package may be corrupted. Please reinstall:');
117
+ console.error(' npm install -g @sciagent/cli');
118
+ process.exit(1);
119
+ }
120
+
121
+ // 检查可执行权限(非Windows)
122
+ if (process.platform !== 'win32') {
123
+ try {
124
+ fs.accessSync(binaryPath, fs.constants.X_OK);
125
+ } catch (e) {
126
+ // 添加可执行权限
127
+ fs.chmodSync(binaryPath, 0o755);
128
+ }
129
+ }
130
+
131
+ // 获取命令行参数(跳过node和脚本路径)
132
+ const args = process.argv.slice(2);
133
+
134
+ // 启动子进程
135
+ const child = spawn(binaryPath, args, {
136
+ stdio: 'inherit', // 继承父进程的stdio
137
+ windowsHide: false // Windows下不隐藏控制台
138
+ });
139
+
140
+ // 处理子进程退出
141
+ child.on('exit', (code, signal) => {
142
+ if (signal) {
143
+ // 被信号终止
144
+ process.kill(process.pid, signal);
145
+ } else {
146
+ // 正常退出,传递退出码
147
+ process.exit(code || 0);
148
+ }
149
+ });
150
+
151
+ // 处理子进程错误
152
+ child.on('error', (err) => {
153
+ if (err.code === 'ENOENT') {
154
+ console.error(`Error: Could not execute binary: ${binaryPath}`);
155
+ console.error('The binary may be corrupted or missing.');
156
+ } else if (err.code === 'EACCES') {
157
+ console.error(`Error: Permission denied: ${binaryPath}`);
158
+ console.error('Please check file permissions.');
159
+ } else {
160
+ console.error(`Error: Failed to start SciAgent: ${err.message}`);
161
+ }
162
+ process.exit(1);
163
+ });
164
+
165
+ // 转发信号到子进程
166
+ process.on('SIGINT', () => {
167
+ child.kill('SIGINT');
168
+ });
169
+
170
+ process.on('SIGTERM', () => {
171
+ child.kill('SIGTERM');
172
+ });
173
+
174
+ // Windows下处理CTRL+C
175
+ if (process.platform === 'win32') {
176
+ const readline = require('readline');
177
+ const rl = readline.createInterface({
178
+ input: process.stdin,
179
+ output: process.stdout
180
+ });
181
+
182
+ rl.on('SIGINT', () => {
183
+ child.kill('SIGINT');
184
+ });
185
+ }
186
+ }
187
+
188
+ // 运行主函数
189
+ main();
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "@sciagent/cli",
3
- "version": "1.0.67",
4
- "description": "SciAgent CLI - AI Research Assistant",
5
- "main": "index.js",
6
- "files": [
7
- "bin/",
8
- "scripts/",
9
- "index.js"
10
- ],
11
- "bin": {
12
- "sciagent": "bin/sciagent.js"
13
- },
14
- "scripts": {
15
- "postinstall": "node scripts/postinstall.js"
16
- },
17
- "optionalDependencies": {
18
- "@sciagent/cli-linux-x64": "1.0.67",
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.67",
23
- "@sciagent/cli-win32-arm64": "1.0.39"
24
- },
25
- "keywords": [
26
- "ai",
27
- "research",
28
- "agent",
29
- "cli",
30
- "codebuddy"
31
- ],
32
- "author": "SciAgent Team",
33
- "license": "MIT",
34
- "repository": {
35
- "type": "git",
36
- "url": "https://gitee.com/garva/research-agent.git"
37
- },
38
- "engines": {
39
- "node": ">=16"
40
- },
41
- "os": [
42
- "linux",
43
- "darwin",
44
- "win32"
45
- ],
46
- "cpu": [
47
- "x64",
48
- "arm64"
49
- ]
50
- }
1
+ {
2
+ "name": "@sciagent/cli",
3
+ "version": "1.0.69",
4
+ "description": "SciAgent CLI - AI Research Assistant",
5
+ "main": "index.js",
6
+ "files": [
7
+ "bin/",
8
+ "scripts/",
9
+ "index.js"
10
+ ],
11
+ "bin": {
12
+ "sciagent": "bin/sciagent.js"
13
+ },
14
+ "scripts": {
15
+ "postinstall": "node scripts/postinstall.js"
16
+ },
17
+ "optionalDependencies": {
18
+ "@sciagent/cli-linux-x64": "1.0.69",
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.69",
23
+ "@sciagent/cli-win32-arm64": "1.0.39"
24
+ },
25
+ "keywords": [
26
+ "ai",
27
+ "research",
28
+ "agent",
29
+ "cli",
30
+ "codebuddy"
31
+ ],
32
+ "author": "SciAgent Team",
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://gitee.com/garva/research-agent.git"
37
+ },
38
+ "engines": {
39
+ "node": ">=16"
40
+ },
41
+ "os": [
42
+ "linux",
43
+ "darwin",
44
+ "win32"
45
+ ],
46
+ "cpu": [
47
+ "x64",
48
+ "arm64"
49
+ ]
50
+ }
package/scripts/chmod.js CHANGED
@@ -1,29 +1,29 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * SciAgent CLI chmod 脚本
5
- * 在Linux/macOS上设置二进制文件的可执行权限
6
- */
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
-
11
- // 只在非Windows平台上运行
12
- if (process.platform === 'win32') {
13
- process.exit(0);
14
- }
15
-
16
- // 查找二进制文件
17
- const binDir = path.join(__dirname, '..', 'bin');
18
- const binaryName = 'sciagent';
19
- const binaryPath = path.join(binDir, binaryName);
20
-
21
- try {
22
- if (fs.existsSync(binaryPath)) {
23
- // 设置可执行权限 (755)
24
- fs.chmodSync(binaryPath, 0o755);
25
- console.log(`Set executable permission: ${binaryPath}`);
26
- }
27
- } catch (err) {
28
- console.warn(`Warning: Could not set executable permission: ${err.message}`);
29
- }
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * SciAgent CLI chmod 脚本
5
+ * 在Linux/macOS上设置二进制文件的可执行权限
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ // 只在非Windows平台上运行
12
+ if (process.platform === 'win32') {
13
+ process.exit(0);
14
+ }
15
+
16
+ // 查找二进制文件
17
+ const binDir = path.join(__dirname, '..', 'bin');
18
+ const binaryName = 'sciagent';
19
+ const binaryPath = path.join(binDir, binaryName);
20
+
21
+ try {
22
+ if (fs.existsSync(binaryPath)) {
23
+ // 设置可执行权限 (755)
24
+ fs.chmodSync(binaryPath, 0o755);
25
+ console.log(`Set executable permission: ${binaryPath}`);
26
+ }
27
+ } catch (err) {
28
+ console.warn(`Warning: Could not set executable permission: ${err.message}`);
29
+ }