yymaxapi 1.0.8 → 1.0.10
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 +76 -10
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -513,8 +513,18 @@ function getConfigPath() {
|
|
|
513
513
|
// ============ 配置读写 ============
|
|
514
514
|
function readConfig(configPath) {
|
|
515
515
|
if (fs.existsSync(configPath)) {
|
|
516
|
-
|
|
517
|
-
|
|
516
|
+
try {
|
|
517
|
+
const raw = fs.readFileSync(configPath, 'utf8').trim();
|
|
518
|
+
if (!raw || (!raw.startsWith('{') && !raw.startsWith('['))) {
|
|
519
|
+
console.log(chalk.yellow(`\n⚠ 配置文件格式异常,将重新创建: ${configPath}`));
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
return JSON5.parse(raw);
|
|
523
|
+
} catch (e) {
|
|
524
|
+
console.log(chalk.yellow(`\n⚠ 配置文件解析失败: ${e.message}`));
|
|
525
|
+
console.log(chalk.gray(` 文件: ${configPath}`));
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
518
528
|
}
|
|
519
529
|
return null;
|
|
520
530
|
}
|
|
@@ -2190,19 +2200,28 @@ async function testConnection(paths, args = {}) {
|
|
|
2190
2200
|
|
|
2191
2201
|
const allowAutoDaemon = !(args['no-daemon'] || args.noDaemon);
|
|
2192
2202
|
|
|
2193
|
-
// 步骤0:
|
|
2203
|
+
// 步骤0: 清理所有挂死的 agent 进程(不限于 yymaxapi-test)
|
|
2194
2204
|
try {
|
|
2195
2205
|
const { execSync } = require('child_process');
|
|
2196
2206
|
const platform = process.platform;
|
|
2197
2207
|
if (platform === 'win32') {
|
|
2198
|
-
|
|
2208
|
+
// Windows: 用 wmic 精确匹配 agent 子进程(排除 gateway)
|
|
2209
|
+
for (const name of ['openclaw', 'clawdbot', 'moltbot']) {
|
|
2210
|
+
try {
|
|
2211
|
+
execSync(`wmic process where "commandline like '%${name}%agent%' and not commandline like '%gateway%'" call terminate 2>nul`, { stdio: 'ignore', timeout: 10000 });
|
|
2212
|
+
} catch { /* ignore */ }
|
|
2213
|
+
}
|
|
2214
|
+
// fallback: 杀掉所有 Not Responding 的 node 进程
|
|
2215
|
+
try {
|
|
2216
|
+
execSync('taskkill /F /FI "IMAGENAME eq node.exe" /FI "STATUS eq Not Responding" 2>nul', { stdio: 'ignore' });
|
|
2217
|
+
} catch { /* ignore */ }
|
|
2199
2218
|
} else {
|
|
2200
|
-
//
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2219
|
+
// Unix: 杀掉所有 openclaw/clawdbot/moltbot agent 子进程(排除 gateway)
|
|
2220
|
+
for (const name of ['openclaw', 'clawdbot', 'moltbot']) {
|
|
2221
|
+
execSync(`pkill -f '${name}.*agent' 2>/dev/null || true`, { stdio: 'ignore' });
|
|
2222
|
+
}
|
|
2204
2223
|
}
|
|
2205
|
-
console.log(chalk.gray('
|
|
2224
|
+
console.log(chalk.gray('已清理残留 agent 进程'));
|
|
2206
2225
|
} catch { /* ignore */ }
|
|
2207
2226
|
|
|
2208
2227
|
// 步骤1: 先重启 Gateway 使配置生效
|
|
@@ -2942,10 +2961,57 @@ async function installOrUpdateOpenClaw() {
|
|
|
2942
2961
|
spinner.succeed(`OpenClaw ${actionLabel}完成`);
|
|
2943
2962
|
|
|
2944
2963
|
// 显示新版本
|
|
2945
|
-
const
|
|
2964
|
+
const cliBin = cliBinary || (process.platform === 'win32' ? 'openclaw.cmd' : 'openclaw');
|
|
2965
|
+
const newV = safeExec(`"${cliBin}" --version`);
|
|
2946
2966
|
if (newV.ok) {
|
|
2947
2967
|
console.log(chalk.green(` 版本: ${newV.output.trim()}`));
|
|
2948
2968
|
}
|
|
2969
|
+
|
|
2970
|
+
// 安装后自动 onboard — 初始化数据目录和配置
|
|
2971
|
+
const homeDir = os.homedir();
|
|
2972
|
+
const configFile = path.join(homeDir, '.openclaw', 'openclaw.json');
|
|
2973
|
+
|
|
2974
|
+
// 如果配置文件存在但内容无效,先备份移除
|
|
2975
|
+
if (fs.existsSync(configFile)) {
|
|
2976
|
+
try {
|
|
2977
|
+
const raw = fs.readFileSync(configFile, 'utf8').trim();
|
|
2978
|
+
if (raw && !raw.startsWith('{') && !raw.startsWith('[')) {
|
|
2979
|
+
const badBak = configFile + '.bad.' + Date.now();
|
|
2980
|
+
fs.renameSync(configFile, badBak);
|
|
2981
|
+
console.log(chalk.yellow(`\n⚠ 配置文件格式异常,已备份到: ${path.basename(badBak)}`));
|
|
2982
|
+
} else if (raw) {
|
|
2983
|
+
JSON5.parse(raw); // 验证 JSON 合法性
|
|
2984
|
+
}
|
|
2985
|
+
} catch {
|
|
2986
|
+
const badBak = configFile + '.bad.' + Date.now();
|
|
2987
|
+
try { fs.renameSync(configFile, badBak); } catch { /* ignore */ }
|
|
2988
|
+
console.log(chalk.yellow(`\n⚠ 配置文件解析失败,已备份移除`));
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
// 运行 onboard 初始化
|
|
2993
|
+
console.log(chalk.cyan('\n正在初始化 OpenClaw...'));
|
|
2994
|
+
const onboardCmd = process.platform === 'win32'
|
|
2995
|
+
? `"${cliBin}" onboard --non-interactive --accept-risk`
|
|
2996
|
+
: `"${cliBin}" onboard --non-interactive --accept-risk 2>/dev/null || true`;
|
|
2997
|
+
const onboardResult = safeExec(onboardCmd, { timeout: 60000 });
|
|
2998
|
+
if (onboardResult.ok) {
|
|
2999
|
+
console.log(chalk.green('✅ OpenClaw 初始化完成'));
|
|
3000
|
+
// 显示数据目录位置
|
|
3001
|
+
const dataDirs = [
|
|
3002
|
+
path.join(homeDir, '.openclaw'),
|
|
3003
|
+
path.join(homeDir, '.clawdbot'),
|
|
3004
|
+
path.join(homeDir, '.moltbot'),
|
|
3005
|
+
].filter(d => fs.existsSync(d));
|
|
3006
|
+
if (dataDirs.length > 0) {
|
|
3007
|
+
console.log(chalk.gray(` 数据目录: ${dataDirs[0]}`));
|
|
3008
|
+
}
|
|
3009
|
+
} else {
|
|
3010
|
+
console.log(chalk.yellow('⚠ 自动初始化未成功,请手动运行: openclaw onboard'));
|
|
3011
|
+
if (onboardResult.output) {
|
|
3012
|
+
console.log(chalk.gray(` ${onboardResult.output.split('\n')[0]}`));
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
2949
3015
|
} catch (error) {
|
|
2950
3016
|
spinner.fail(`${actionLabel}失败`);
|
|
2951
3017
|
console.log(chalk.red(` 错误: ${error.message}`));
|