@lark-apaas/openclaw-scripts-diagnose-cli 0.1.15-alpha.16 → 0.1.15-alpha.17

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.
Files changed (2) hide show
  1. package/dist/index.cjs +59 -14
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -52,7 +52,7 @@ node_assert = __toESM(node_assert);
52
52
  * it terse and parseable.
53
53
  */
54
54
  function getVersion() {
55
- return "0.1.15-alpha.16";
55
+ return "0.1.15-alpha.17";
56
56
  }
57
57
  //#endregion
58
58
  //#region src/rule-engine/base.ts
@@ -10714,7 +10714,7 @@ async function reportCliRun(opts) {
10714
10714
  //#region src/help.ts
10715
10715
  const BIN = "mclaw-diagnose";
10716
10716
  function versionBanner() {
10717
- return `v0.1.15-alpha.16`;
10717
+ return `v0.1.15-alpha.17`;
10718
10718
  }
10719
10719
  const COMMANDS = [
10720
10720
  {
@@ -11903,15 +11903,15 @@ function isPidAlive(pid) {
11903
11903
  }
11904
11904
  }
11905
11905
  /**
11906
- * 获取安装操作互斥锁。
11906
+ * 尝试获取安装操作互斥锁。
11907
11907
  *
11908
11908
  * 利用 open(O_CREAT | O_EXCL) 的 POSIX 原子性确保同一时刻只有一个安装指令运行。
11909
11909
  * 覆盖的安装指令:upgrade-lark / install-openclaw / install-extension / install-cli / reset --worker。
11910
11910
  *
11911
- * 若锁被活跃进程持有,抛出包含持有者信息的 Error。
11912
- * 若锁文件属于已退出进程(crash 遗留),视为过期锁并覆盖。
11911
+ * 返回 null 表示成功获取锁;返回错误信息字符串表示锁被其他进程持有。
11912
+ * 与抛异常相比,返回值让调用方可以输出符合各自格式的 result,而不依赖 catch handler 统一处理。
11913
11913
  *
11914
- * 成功获取后自动注册 process.on('exit') 释放锁,无需调用方手动清理。
11914
+ * 成功获取后自动注册 process.once('exit') 释放锁,无需调用方手动清理。
11915
11915
  */
11916
11916
  function acquireInstallLock(command) {
11917
11917
  node_fs.default.mkdirSync(DIAGNOSE_DIR, { recursive: true });
@@ -11927,7 +11927,7 @@ function acquireInstallLock(command) {
11927
11927
  node_fs.default.closeSync(fd);
11928
11928
  process.once("exit", releaseInstallLock);
11929
11929
  console.error(`[install-lock] acquired command=${command} pid=${process.pid}`);
11930
- return;
11930
+ return null;
11931
11931
  } catch (e) {
11932
11932
  if (e.code !== "EEXIST") throw e;
11933
11933
  let existing = null;
@@ -11946,13 +11946,13 @@ function acquireInstallLock(command) {
11946
11946
  } catch {}
11947
11947
  continue;
11948
11948
  }
11949
- throw new Error(`另一个安装指令正在运行,请等待其完成后重试。\n 占用指令: ${existing.command}\n 进程 PID : ${existing.pid}\n 开始时间: ${existing.startedAt}\n 锁文件 : ${INSTALL_LOCK_FILE}`);
11949
+ return `另一个安装指令正在运行,请等待其完成后重试。\n 占用指令: ${existing.command}\n 进程 PID : ${existing.pid}\n 开始时间: ${existing.startedAt}\n 锁文件 : ${INSTALL_LOCK_FILE}`;
11950
11950
  }
11951
11951
  }
11952
11952
  /**
11953
11953
  * 释放安装操作互斥锁。
11954
11954
  * 仅删除由本进程创建的锁文件,避免误删其他进程的锁。
11955
- * 通常由 process.on('exit') 自动调用,不需要手动调用。
11955
+ * 通常由 process.once('exit') 自动调用,不需要手动调用。
11956
11956
  */
11957
11957
  function releaseInstallLock() {
11958
11958
  try {
@@ -11966,6 +11966,14 @@ function releaseInstallLock() {
11966
11966
  }
11967
11967
  //#endregion
11968
11968
  //#region src/index.ts
11969
+ /** 锁冲突时各 install 命令的统一处理:输出 { ok: false } 并退出 */
11970
+ function handleInstallLockConflict(lockErr) {
11971
+ console.log(JSON.stringify({
11972
+ ok: false,
11973
+ error: lockErr
11974
+ }));
11975
+ node_process.default.exit(1);
11976
+ }
11969
11977
  const args = node_process.default.argv.slice(2);
11970
11978
  const mode = args.find((a) => !a.startsWith("-"));
11971
11979
  const t0 = Date.now();
@@ -12164,8 +12172,18 @@ async function main() {
12164
12172
  console.error("Error: --task-id=<id> is required for worker");
12165
12173
  node_process.default.exit(1);
12166
12174
  }
12167
- acquireInstallLock("reset");
12168
12175
  const resultFile = resetResultFile(taskId);
12176
+ const resetLockErr = acquireInstallLock("reset");
12177
+ if (resetLockErr) {
12178
+ try {
12179
+ node_fs.default.writeFileSync(resultFile, JSON.stringify({
12180
+ status: "failed",
12181
+ error: resetLockErr
12182
+ }));
12183
+ } catch {}
12184
+ node_process.default.exitCode = 1;
12185
+ return;
12186
+ }
12169
12187
  const raw = await fetchCtxViaInnerApi({
12170
12188
  populate: planCtxPopulate({ command: "reset" }),
12171
12189
  caller,
@@ -12209,7 +12227,8 @@ async function main() {
12209
12227
  console.error("Usage: install-openclaw <tag> [--oss_file_map=<base64>]");
12210
12228
  node_process.default.exit(1);
12211
12229
  }
12212
- acquireInstallLock("install-openclaw");
12230
+ const installOcLockErr = acquireInstallLock("install-openclaw");
12231
+ if (installOcLockErr) handleInstallLockConflict(installOcLockErr);
12213
12232
  const ossFileMapFlag = getFlag(args, "oss_file_map");
12214
12233
  let installOssFileMap;
12215
12234
  let rawForTelemetry;
@@ -12252,7 +12271,8 @@ async function main() {
12252
12271
  console.error("Usage: install-extension <tag> (--all | --extension=<name>...) [--home_base=<dir>] [--config_path=<path>] [--skip-config-update] [--oss_file_map=<base64>]");
12253
12272
  node_process.default.exit(1);
12254
12273
  }
12255
- acquireInstallLock("install-extension");
12274
+ const installExtLockErr = acquireInstallLock("install-extension");
12275
+ if (installExtLockErr) handleInstallLockConflict(installExtLockErr);
12256
12276
  const all = args.includes("--all");
12257
12277
  const names = getMultiFlag(args, "extension");
12258
12278
  const homeBase = getFlag(args, "home_base");
@@ -12316,7 +12336,8 @@ async function main() {
12316
12336
  console.error("Usage: install-cli <tag> --cli=<name>... [--home_base=<dir>] [--oss_file_map=<base64>]");
12317
12337
  node_process.default.exit(1);
12318
12338
  }
12319
- acquireInstallLock("install-cli");
12339
+ const installCliLockErr = acquireInstallLock("install-cli");
12340
+ if (installCliLockErr) handleInstallLockConflict(installCliLockErr);
12320
12341
  const homeBase = getFlag(args, "home_base");
12321
12342
  const ossFileMapFlag = getFlag(args, "oss_file_map");
12322
12343
  let installOssFileMap;
@@ -12460,7 +12481,31 @@ async function main() {
12460
12481
  }
12461
12482
  case "upgrade-lark": {
12462
12483
  const checkOnly = args.includes("--check");
12463
- if (!checkOnly) acquireInstallLock("upgrade-lark");
12484
+ if (!checkOnly) {
12485
+ const upgradeLockErr = acquireInstallLock("upgrade-lark");
12486
+ if (upgradeLockErr) {
12487
+ const fixStatus = computeFixStatus(scene, "failed");
12488
+ const failResult = {
12489
+ status: "failed",
12490
+ error: upgradeLockErr,
12491
+ logFile: "",
12492
+ fixStatus
12493
+ };
12494
+ if (fixStatus !== void 0) writeFixStatusEvent(fixStatus, failResult, console.error);
12495
+ console.log(JSON.stringify(failResult));
12496
+ reportUpgradeLarkToSlardar({
12497
+ scene,
12498
+ checkOnly,
12499
+ durationMs: Date.now() - t0,
12500
+ resultStatus: "failed",
12501
+ error: upgradeLockErr,
12502
+ logFile: "",
12503
+ resultSummary: buildUpgradeLarkResultSummary(failResult, checkOnly)
12504
+ });
12505
+ node_process.default.exitCode = 1;
12506
+ return;
12507
+ }
12508
+ }
12464
12509
  const skipRestart = args.includes("--skip-restart");
12465
12510
  const result = runUpgradeLark({
12466
12511
  runId: rc.runId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/openclaw-scripts-diagnose-cli",
3
- "version": "0.1.15-alpha.16",
3
+ "version": "0.1.15-alpha.17",
4
4
  "description": "CLI for OpenClaw config diagnose and repair with JSON5 support",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {