yymaxapi 1.0.9 → 1.0.11
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/yymaxapi.js +77 -16
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -874,16 +874,21 @@ function resolveCliBinary() {
|
|
|
874
874
|
}
|
|
875
875
|
|
|
876
876
|
const candidates = ['openclaw', 'clawdbot', 'moltbot'];
|
|
877
|
+
const isWin = process.platform === 'win32';
|
|
877
878
|
const searchDirs = (process.env.PATH || '').split(path.delimiter).concat(EXTRA_BIN_DIRS);
|
|
878
879
|
for (const name of candidates) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
if (
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
880
|
+
// Windows: 优先找 .cmd 版本(原生可执行),再找无扩展名版本
|
|
881
|
+
const nameVariants = isWin ? [`${name}.cmd`, name] : [name];
|
|
882
|
+
for (const variant of nameVariants) {
|
|
883
|
+
for (const dir of searchDirs) {
|
|
884
|
+
if (!dir) continue;
|
|
885
|
+
const full = path.join(dir, variant);
|
|
886
|
+
try {
|
|
887
|
+
if (fs.existsSync(full) && fs.statSync(full).isFile() && isRealCli(full)) {
|
|
888
|
+
return full;
|
|
889
|
+
}
|
|
890
|
+
} catch {}
|
|
891
|
+
}
|
|
887
892
|
}
|
|
888
893
|
}
|
|
889
894
|
|
|
@@ -2200,19 +2205,28 @@ async function testConnection(paths, args = {}) {
|
|
|
2200
2205
|
|
|
2201
2206
|
const allowAutoDaemon = !(args['no-daemon'] || args.noDaemon);
|
|
2202
2207
|
|
|
2203
|
-
// 步骤0:
|
|
2208
|
+
// 步骤0: 清理所有挂死的 agent 进程(不限于 yymaxapi-test)
|
|
2204
2209
|
try {
|
|
2205
2210
|
const { execSync } = require('child_process');
|
|
2206
2211
|
const platform = process.platform;
|
|
2207
2212
|
if (platform === 'win32') {
|
|
2208
|
-
|
|
2213
|
+
// Windows: 用 wmic 精确匹配 agent 子进程(排除 gateway)
|
|
2214
|
+
for (const name of ['openclaw', 'clawdbot', 'moltbot']) {
|
|
2215
|
+
try {
|
|
2216
|
+
execSync(`wmic process where "commandline like '%${name}%agent%' and not commandline like '%gateway%'" call terminate 2>nul`, { stdio: 'ignore', timeout: 10000 });
|
|
2217
|
+
} catch { /* ignore */ }
|
|
2218
|
+
}
|
|
2219
|
+
// fallback: 杀掉所有 Not Responding 的 node 进程
|
|
2220
|
+
try {
|
|
2221
|
+
execSync('taskkill /F /FI "IMAGENAME eq node.exe" /FI "STATUS eq Not Responding" 2>nul', { stdio: 'ignore' });
|
|
2222
|
+
} catch { /* ignore */ }
|
|
2209
2223
|
} else {
|
|
2210
|
-
//
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2224
|
+
// Unix: 杀掉所有 openclaw/clawdbot/moltbot agent 子进程(排除 gateway)
|
|
2225
|
+
for (const name of ['openclaw', 'clawdbot', 'moltbot']) {
|
|
2226
|
+
execSync(`pkill -f '${name}.*agent' 2>/dev/null || true`, { stdio: 'ignore' });
|
|
2227
|
+
}
|
|
2214
2228
|
}
|
|
2215
|
-
console.log(chalk.gray('
|
|
2229
|
+
console.log(chalk.gray('已清理残留 agent 进程'));
|
|
2216
2230
|
} catch { /* ignore */ }
|
|
2217
2231
|
|
|
2218
2232
|
// 步骤1: 先重启 Gateway 使配置生效
|
|
@@ -2952,10 +2966,57 @@ async function installOrUpdateOpenClaw() {
|
|
|
2952
2966
|
spinner.succeed(`OpenClaw ${actionLabel}完成`);
|
|
2953
2967
|
|
|
2954
2968
|
// 显示新版本
|
|
2955
|
-
const
|
|
2969
|
+
const cliBin = cliBinary || (process.platform === 'win32' ? 'openclaw.cmd' : 'openclaw');
|
|
2970
|
+
const newV = safeExec(`"${cliBin}" --version`);
|
|
2956
2971
|
if (newV.ok) {
|
|
2957
2972
|
console.log(chalk.green(` 版本: ${newV.output.trim()}`));
|
|
2958
2973
|
}
|
|
2974
|
+
|
|
2975
|
+
// 安装后自动 onboard — 初始化数据目录和配置
|
|
2976
|
+
const homeDir = os.homedir();
|
|
2977
|
+
const configFile = path.join(homeDir, '.openclaw', 'openclaw.json');
|
|
2978
|
+
|
|
2979
|
+
// 如果配置文件存在但内容无效,先备份移除
|
|
2980
|
+
if (fs.existsSync(configFile)) {
|
|
2981
|
+
try {
|
|
2982
|
+
const raw = fs.readFileSync(configFile, 'utf8').trim();
|
|
2983
|
+
if (raw && !raw.startsWith('{') && !raw.startsWith('[')) {
|
|
2984
|
+
const badBak = configFile + '.bad.' + Date.now();
|
|
2985
|
+
fs.renameSync(configFile, badBak);
|
|
2986
|
+
console.log(chalk.yellow(`\n⚠ 配置文件格式异常,已备份到: ${path.basename(badBak)}`));
|
|
2987
|
+
} else if (raw) {
|
|
2988
|
+
JSON5.parse(raw); // 验证 JSON 合法性
|
|
2989
|
+
}
|
|
2990
|
+
} catch {
|
|
2991
|
+
const badBak = configFile + '.bad.' + Date.now();
|
|
2992
|
+
try { fs.renameSync(configFile, badBak); } catch { /* ignore */ }
|
|
2993
|
+
console.log(chalk.yellow(`\n⚠ 配置文件解析失败,已备份移除`));
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2997
|
+
// 运行 onboard 初始化
|
|
2998
|
+
console.log(chalk.cyan('\n正在初始化 OpenClaw...'));
|
|
2999
|
+
const onboardCmd = process.platform === 'win32'
|
|
3000
|
+
? `"${cliBin}" onboard --non-interactive --accept-risk`
|
|
3001
|
+
: `"${cliBin}" onboard --non-interactive --accept-risk 2>/dev/null || true`;
|
|
3002
|
+
const onboardResult = safeExec(onboardCmd, { timeout: 60000 });
|
|
3003
|
+
if (onboardResult.ok) {
|
|
3004
|
+
console.log(chalk.green('✅ OpenClaw 初始化完成'));
|
|
3005
|
+
// 显示数据目录位置
|
|
3006
|
+
const dataDirs = [
|
|
3007
|
+
path.join(homeDir, '.openclaw'),
|
|
3008
|
+
path.join(homeDir, '.clawdbot'),
|
|
3009
|
+
path.join(homeDir, '.moltbot'),
|
|
3010
|
+
].filter(d => fs.existsSync(d));
|
|
3011
|
+
if (dataDirs.length > 0) {
|
|
3012
|
+
console.log(chalk.gray(` 数据目录: ${dataDirs[0]}`));
|
|
3013
|
+
}
|
|
3014
|
+
} else {
|
|
3015
|
+
console.log(chalk.yellow('⚠ 自动初始化未成功,请手动运行: openclaw onboard'));
|
|
3016
|
+
if (onboardResult.output) {
|
|
3017
|
+
console.log(chalk.gray(` ${onboardResult.output.split('\n')[0]}`));
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
2959
3020
|
} catch (error) {
|
|
2960
3021
|
spinner.fail(`${actionLabel}失败`);
|
|
2961
3022
|
console.log(chalk.red(` 错误: ${error.message}`));
|