@sciagent/cli 1.1.77 → 1.1.79
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 +130 -11
- package/package.json +1 -1
- package/scripts/postinstall.js +1 -1
package/bin/sciagent.js
CHANGED
|
@@ -25,7 +25,7 @@ const https = require('https');
|
|
|
25
25
|
const http = require('http');
|
|
26
26
|
|
|
27
27
|
// 当前版本号 - 与 postinstall.js 和 package.json 保持同步
|
|
28
|
-
const CURRENT_VERSION = '1.1.
|
|
28
|
+
const CURRENT_VERSION = '1.1.79';
|
|
29
29
|
|
|
30
30
|
// Releases 下载源配置(优先级从高到低)
|
|
31
31
|
// JihuLab 通用包仓库(国内 CDN,速度快)作为主源
|
|
@@ -841,11 +841,63 @@ function downloadBinary(platform, arch, version) {
|
|
|
841
841
|
}
|
|
842
842
|
|
|
843
843
|
/**
|
|
844
|
-
*
|
|
844
|
+
* 处理更新重启流程
|
|
845
|
+
* 当子进程以退出码42退出时调用:
|
|
846
|
+
* 1. 检查 .download-request 文件,如果存在则下载新版本
|
|
847
|
+
* 2. 应用 .pending-update(如果存在)
|
|
848
|
+
* 3. 返回 true 表示应该重新启动,false 表示不需要
|
|
849
|
+
*/
|
|
850
|
+
function handleUpdateRestart(platform, arch) {
|
|
851
|
+
const installDir = getInstallDir(platform);
|
|
852
|
+
|
|
853
|
+
// 1. 检查 download-request
|
|
854
|
+
const requestFile = path.join(installDir, '.download-request');
|
|
855
|
+
if (fs.existsSync(requestFile)) {
|
|
856
|
+
try {
|
|
857
|
+
const requestData = JSON.parse(fs.readFileSync(requestFile, 'utf8'));
|
|
858
|
+
const targetVersion = requestData.version;
|
|
859
|
+
console.log(`[UPDATE] Found download request for v${targetVersion}`);
|
|
860
|
+
|
|
861
|
+
// 下载新版本二进制到临时目录
|
|
862
|
+
const tempPath = downloadBinaryToTemp(platform, arch, targetVersion);
|
|
863
|
+
if (tempPath) {
|
|
864
|
+
console.log(`[UPDATE] ✅ Downloaded v${targetVersion} to temp.`);
|
|
865
|
+
// .pending-update 已经在 downloadBinaryToTemp 中写入
|
|
866
|
+
} else {
|
|
867
|
+
console.log(`[UPDATE] ⚠️ Download failed, will restart with current version.`);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// 删除 download-request
|
|
871
|
+
try { fs.unlinkSync(requestFile); } catch (e) {}
|
|
872
|
+
} catch (e) {
|
|
873
|
+
console.log(`[UPDATE] ⚠️ Error reading download request: ${e.message}`);
|
|
874
|
+
try { fs.unlinkSync(requestFile); } catch (e2) {}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// 2. 应用 pending update
|
|
879
|
+
const applied = applyPendingUpdate(installDir);
|
|
880
|
+
if (applied) {
|
|
881
|
+
console.log(`[UPDATE] ✅ Update applied successfully.`);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
return true; // 应该重新启动
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* 主函数 - 支持更新重启循环
|
|
845
889
|
*/
|
|
846
890
|
function main() {
|
|
847
|
-
const
|
|
848
|
-
|
|
891
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
892
|
+
const arch = ARCH_MAP[process.arch];
|
|
893
|
+
|
|
894
|
+
if (!platform || !arch) {
|
|
895
|
+
console.error(`Error: Unsupported platform/arch: ${process.platform}/${process.arch}`);
|
|
896
|
+
process.exit(1);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
let binaryPath = getBinaryPath();
|
|
900
|
+
|
|
849
901
|
// 检查二进制文件是否存在
|
|
850
902
|
if (!fs.existsSync(binaryPath)) {
|
|
851
903
|
console.error(`Error: Binary not found at: ${binaryPath}`);
|
|
@@ -859,7 +911,6 @@ function main() {
|
|
|
859
911
|
try {
|
|
860
912
|
fs.accessSync(binaryPath, fs.constants.X_OK);
|
|
861
913
|
} catch (e) {
|
|
862
|
-
// 添加可执行权限
|
|
863
914
|
fs.chmodSync(binaryPath, 0o755);
|
|
864
915
|
}
|
|
865
916
|
}
|
|
@@ -868,9 +919,9 @@ function main() {
|
|
|
868
919
|
const args = process.argv.slice(2);
|
|
869
920
|
|
|
870
921
|
// 启动子进程
|
|
871
|
-
|
|
872
|
-
stdio: 'inherit',
|
|
873
|
-
windowsHide: false
|
|
922
|
+
let child = spawn(binaryPath, args, {
|
|
923
|
+
stdio: 'inherit',
|
|
924
|
+
windowsHide: false
|
|
874
925
|
});
|
|
875
926
|
|
|
876
927
|
// 处理子进程退出
|
|
@@ -878,6 +929,74 @@ function main() {
|
|
|
878
929
|
if (signal) {
|
|
879
930
|
// 被信号终止
|
|
880
931
|
process.kill(process.pid, signal);
|
|
932
|
+
} else if (code === 42) {
|
|
933
|
+
// 退出码 42 = 更新重启
|
|
934
|
+
console.log('[RESTART] Update restart triggered (exit code 42).');
|
|
935
|
+
console.log('[RESTART] Processing update...');
|
|
936
|
+
|
|
937
|
+
// 处理更新流程
|
|
938
|
+
handleUpdateRestart(platform, arch);
|
|
939
|
+
|
|
940
|
+
// 重新获取二进制路径(可能已更新)
|
|
941
|
+
const newBinaryPath = getBinaryPath();
|
|
942
|
+
if (fs.existsSync(newBinaryPath)) {
|
|
943
|
+
binaryPath = newBinaryPath;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
console.log('[RESTART] Re-launching SciAgent...');
|
|
947
|
+
|
|
948
|
+
// 重新启动子进程
|
|
949
|
+
child = spawn(binaryPath, args, {
|
|
950
|
+
stdio: 'inherit',
|
|
951
|
+
windowsHide: false
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
// 重新绑定事件处理
|
|
955
|
+
child.on('exit', (code2, signal2) => {
|
|
956
|
+
if (signal2) {
|
|
957
|
+
process.kill(process.pid, signal2);
|
|
958
|
+
} else if (code2 === 42) {
|
|
959
|
+
// 再次更新重启(递归处理)
|
|
960
|
+
console.log('[RESTART] Second update restart, re-processing...');
|
|
961
|
+
handleUpdateRestart(platform, arch);
|
|
962
|
+
const updatedPath = getBinaryPath();
|
|
963
|
+
if (fs.existsSync(updatedPath)) {
|
|
964
|
+
binaryPath = updatedPath;
|
|
965
|
+
}
|
|
966
|
+
console.log('[RESTART] Re-launching SciAgent...');
|
|
967
|
+
child = spawn(binaryPath, args, {
|
|
968
|
+
stdio: 'inherit',
|
|
969
|
+
windowsHide: false
|
|
970
|
+
});
|
|
971
|
+
child.on('exit', (code3, signal3) => {
|
|
972
|
+
if (signal3) {
|
|
973
|
+
process.kill(process.pid, signal3);
|
|
974
|
+
} else {
|
|
975
|
+
process.exit(code3 || 0);
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
child.on('error', (err) => {
|
|
979
|
+
console.error(`Error: Failed to restart SciAgent: ${err.message}`);
|
|
980
|
+
process.exit(1);
|
|
981
|
+
});
|
|
982
|
+
} else {
|
|
983
|
+
process.exit(code2 || 0);
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
child.on('error', (err) => {
|
|
988
|
+
console.error(`Error: Failed to restart SciAgent: ${err.message}`);
|
|
989
|
+
process.exit(1);
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
// 转发信号
|
|
993
|
+
process.on('SIGINT', () => {
|
|
994
|
+
try { child.kill('SIGINT'); } catch (e) {}
|
|
995
|
+
});
|
|
996
|
+
process.on('SIGTERM', () => {
|
|
997
|
+
try { child.kill('SIGTERM'); } catch (e) {}
|
|
998
|
+
});
|
|
999
|
+
|
|
881
1000
|
} else {
|
|
882
1001
|
// 正常退出,传递退出码
|
|
883
1002
|
process.exit(code || 0);
|
|
@@ -900,11 +1019,11 @@ function main() {
|
|
|
900
1019
|
|
|
901
1020
|
// 转发信号到子进程
|
|
902
1021
|
process.on('SIGINT', () => {
|
|
903
|
-
child.kill('SIGINT');
|
|
1022
|
+
try { child.kill('SIGINT'); } catch (e) {}
|
|
904
1023
|
});
|
|
905
1024
|
|
|
906
1025
|
process.on('SIGTERM', () => {
|
|
907
|
-
child.kill('SIGTERM');
|
|
1026
|
+
try { child.kill('SIGTERM'); } catch (e) {}
|
|
908
1027
|
});
|
|
909
1028
|
|
|
910
1029
|
// Windows下处理CTRL+C
|
|
@@ -916,7 +1035,7 @@ function main() {
|
|
|
916
1035
|
});
|
|
917
1036
|
|
|
918
1037
|
rl.on('SIGINT', () => {
|
|
919
|
-
child.kill('SIGINT');
|
|
1038
|
+
try { child.kill('SIGINT'); } catch (e) {}
|
|
920
1039
|
});
|
|
921
1040
|
}
|
|
922
1041
|
}
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -27,7 +27,7 @@ const ARCH_MAP = {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
// 当前版本号 - 每次发布时同步更新
|
|
30
|
-
const CURRENT_VERSION = '1.1.
|
|
30
|
+
const CURRENT_VERSION = '1.1.79';
|
|
31
31
|
|
|
32
32
|
// GitHub Releases 回退版本列表(当当前版本的 release 不存在时尝试)
|
|
33
33
|
const GITHUB_FALLBACK_VERSIONS = ['1.1.3', '1.0.50', '1.0.48', '1.0.46', '1.0.40', '1.0.38', '1.0.36'];
|