openclawsetup 2.4.1 → 2.4.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/cli.mjs +61 -10
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -895,13 +895,20 @@ async function runHealthCheck(cliName, autoFix = false) {
|
|
|
895
895
|
// 1. 检查配置文件
|
|
896
896
|
console.log(colors.cyan('检查配置文件...'));
|
|
897
897
|
if (!config.configPath || !existsSync(config.configPath)) {
|
|
898
|
-
|
|
898
|
+
const issue = {
|
|
899
899
|
level: 'error',
|
|
900
900
|
title: '配置文件不存在',
|
|
901
901
|
detail: '未找到 openclaw.json 配置文件',
|
|
902
902
|
solution: '运行 openclaw onboard 重新配置',
|
|
903
903
|
fixCmd: `${cliName} onboard`,
|
|
904
|
-
}
|
|
904
|
+
};
|
|
905
|
+
if (autoFix) {
|
|
906
|
+
console.log(colors.yellow(' 尝试运行 onboard 生成配置...'));
|
|
907
|
+
spawnSync(cliName, ['onboard'], { stdio: 'inherit', shell: true });
|
|
908
|
+
fixed.push('已运行 onboard 生成配置');
|
|
909
|
+
} else {
|
|
910
|
+
issues.push(issue);
|
|
911
|
+
}
|
|
905
912
|
} else {
|
|
906
913
|
try {
|
|
907
914
|
const raw = readFileSync(config.configPath, 'utf8');
|
|
@@ -983,21 +990,46 @@ async function runHealthCheck(cliName, autoFix = false) {
|
|
|
983
990
|
// 检查是否有其他进程占用端口
|
|
984
991
|
const conflictCheck = safeExec(`lsof -i :${port} 2>/dev/null | head -5`);
|
|
985
992
|
if (conflictCheck.ok && conflictCheck.output && !conflictCheck.output.includes('openclaw') && !conflictCheck.output.includes('node')) {
|
|
986
|
-
|
|
993
|
+
const issue = {
|
|
987
994
|
level: 'error',
|
|
988
995
|
title: `端口 ${port} 被其他程序占用`,
|
|
989
996
|
detail: conflictCheck.output.slice(0, 100),
|
|
990
997
|
solution: `更换端口: ${cliName} config set gateway.port 18790`,
|
|
991
998
|
fixCmd: `${cliName} config set gateway.port 18790 && ${cliName} gateway restart`,
|
|
992
|
-
}
|
|
999
|
+
};
|
|
1000
|
+
if (autoFix) {
|
|
1001
|
+
console.log(colors.yellow(' 尝试更换端口到 18790...'));
|
|
1002
|
+
const portResult = safeExec(`${cliName} config set gateway.port 18790`);
|
|
1003
|
+
const restartResult = safeExec(`${cliName} gateway restart`);
|
|
1004
|
+
if (portResult.ok && restartResult.ok) {
|
|
1005
|
+
log.success('已更换端口到 18790 并重启 Gateway');
|
|
1006
|
+
fixed.push('端口冲突已自动解决(更换到 18790)');
|
|
1007
|
+
} else {
|
|
1008
|
+
issues.push(issue);
|
|
1009
|
+
}
|
|
1010
|
+
} else {
|
|
1011
|
+
issues.push(issue);
|
|
1012
|
+
}
|
|
993
1013
|
} else {
|
|
994
|
-
|
|
1014
|
+
const issue = {
|
|
995
1015
|
level: 'error',
|
|
996
1016
|
title: `端口 ${port} 未监听`,
|
|
997
1017
|
detail: 'Gateway 端口未开放,服务可能未正常启动',
|
|
998
1018
|
solution: `运行 ${cliName} gateway restart`,
|
|
999
1019
|
fixCmd: `${cliName} gateway restart`,
|
|
1000
|
-
}
|
|
1020
|
+
};
|
|
1021
|
+
if (autoFix) {
|
|
1022
|
+
console.log(colors.yellow(' 尝试重启 Gateway...'));
|
|
1023
|
+
const restartResult = safeExec(`${cliName} gateway restart`);
|
|
1024
|
+
if (restartResult.ok) {
|
|
1025
|
+
log.success('Gateway 已重启');
|
|
1026
|
+
fixed.push('Gateway 已自动重启');
|
|
1027
|
+
} else {
|
|
1028
|
+
issues.push(issue);
|
|
1029
|
+
}
|
|
1030
|
+
} else {
|
|
1031
|
+
issues.push(issue);
|
|
1032
|
+
}
|
|
1001
1033
|
}
|
|
1002
1034
|
}
|
|
1003
1035
|
|
|
@@ -1025,13 +1057,25 @@ async function runHealthCheck(cliName, autoFix = false) {
|
|
|
1025
1057
|
}
|
|
1026
1058
|
}
|
|
1027
1059
|
} else {
|
|
1028
|
-
|
|
1060
|
+
const issue = {
|
|
1029
1061
|
level: 'error',
|
|
1030
1062
|
title: 'API 无响应',
|
|
1031
1063
|
detail: '无法连接到 Gateway API',
|
|
1032
1064
|
solution: `重启服务: ${cliName} gateway restart`,
|
|
1033
1065
|
fixCmd: `${cliName} gateway restart`,
|
|
1034
|
-
}
|
|
1066
|
+
};
|
|
1067
|
+
if (autoFix) {
|
|
1068
|
+
console.log(colors.yellow(' 尝试重启 Gateway...'));
|
|
1069
|
+
const restartResult = safeExec(`${cliName} gateway restart`);
|
|
1070
|
+
if (restartResult.ok) {
|
|
1071
|
+
log.success('Gateway 已重启');
|
|
1072
|
+
fixed.push('Gateway 已自动重启(API 无响应)');
|
|
1073
|
+
} else {
|
|
1074
|
+
issues.push(issue);
|
|
1075
|
+
}
|
|
1076
|
+
} else {
|
|
1077
|
+
issues.push(issue);
|
|
1078
|
+
}
|
|
1035
1079
|
}
|
|
1036
1080
|
|
|
1037
1081
|
// 5. 检查模型配置
|
|
@@ -1040,13 +1084,20 @@ async function runHealthCheck(cliName, autoFix = false) {
|
|
|
1040
1084
|
const hasModels = config.raw.includes('"models"') || config.raw.includes('"providers"');
|
|
1041
1085
|
const hasApiKey = config.raw.includes('"apiKey"') || config.raw.includes('"api_key"');
|
|
1042
1086
|
if (!hasModels && !hasApiKey) {
|
|
1043
|
-
|
|
1087
|
+
const issue = {
|
|
1044
1088
|
level: 'warning',
|
|
1045
1089
|
title: '未配置 AI 模型',
|
|
1046
1090
|
detail: '配置文件中未找到模型或 API Key 配置',
|
|
1047
1091
|
solution: '运行 npx openclawapi@latest 配置模型',
|
|
1048
1092
|
fixCmd: 'npx openclawapi@latest',
|
|
1049
|
-
}
|
|
1093
|
+
};
|
|
1094
|
+
if (autoFix) {
|
|
1095
|
+
console.log(colors.yellow(' 启动模型配置...'));
|
|
1096
|
+
spawnSync('npx', ['openclawapi@latest'], { stdio: 'inherit', shell: true });
|
|
1097
|
+
fixed.push('已启动模型配置向导');
|
|
1098
|
+
} else {
|
|
1099
|
+
issues.push(issue);
|
|
1100
|
+
}
|
|
1050
1101
|
} else {
|
|
1051
1102
|
log.success('已配置模型');
|
|
1052
1103
|
}
|