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

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 +61 -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.18";
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.18`;
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,15 @@ 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
+ const conflictMsg = `另一个安装指令正在运行,请等待其完成后重试。\n 占用指令: ${existing.command}\n 进程 PID : ${existing.pid}\n 开始时间: ${existing.startedAt}\n 锁文件 : ${INSTALL_LOCK_FILE}`;
11950
+ console.error(`[install-lock] conflict: command=${command} blocked by pid=${existing.pid} command=${existing.command}`);
11951
+ return conflictMsg;
11950
11952
  }
11951
11953
  }
11952
11954
  /**
11953
11955
  * 释放安装操作互斥锁。
11954
11956
  * 仅删除由本进程创建的锁文件,避免误删其他进程的锁。
11955
- * 通常由 process.on('exit') 自动调用,不需要手动调用。
11957
+ * 通常由 process.once('exit') 自动调用,不需要手动调用。
11956
11958
  */
11957
11959
  function releaseInstallLock() {
11958
11960
  try {
@@ -11966,6 +11968,14 @@ function releaseInstallLock() {
11966
11968
  }
11967
11969
  //#endregion
11968
11970
  //#region src/index.ts
11971
+ /** 锁冲突时各 install 命令的统一处理:输出 { ok: false } 并退出 */
11972
+ function handleInstallLockConflict(lockErr) {
11973
+ console.log(JSON.stringify({
11974
+ ok: false,
11975
+ error: lockErr
11976
+ }));
11977
+ node_process.default.exit(1);
11978
+ }
11969
11979
  const args = node_process.default.argv.slice(2);
11970
11980
  const mode = args.find((a) => !a.startsWith("-"));
11971
11981
  const t0 = Date.now();
@@ -12164,8 +12174,18 @@ async function main() {
12164
12174
  console.error("Error: --task-id=<id> is required for worker");
12165
12175
  node_process.default.exit(1);
12166
12176
  }
12167
- acquireInstallLock("reset");
12168
12177
  const resultFile = resetResultFile(taskId);
12178
+ const resetLockErr = acquireInstallLock("reset");
12179
+ if (resetLockErr) {
12180
+ try {
12181
+ node_fs.default.writeFileSync(resultFile, JSON.stringify({
12182
+ status: "failed",
12183
+ error: resetLockErr
12184
+ }));
12185
+ } catch {}
12186
+ node_process.default.exitCode = 1;
12187
+ return;
12188
+ }
12169
12189
  const raw = await fetchCtxViaInnerApi({
12170
12190
  populate: planCtxPopulate({ command: "reset" }),
12171
12191
  caller,
@@ -12209,7 +12229,8 @@ async function main() {
12209
12229
  console.error("Usage: install-openclaw <tag> [--oss_file_map=<base64>]");
12210
12230
  node_process.default.exit(1);
12211
12231
  }
12212
- acquireInstallLock("install-openclaw");
12232
+ const installOcLockErr = acquireInstallLock("install-openclaw");
12233
+ if (installOcLockErr) handleInstallLockConflict(installOcLockErr);
12213
12234
  const ossFileMapFlag = getFlag(args, "oss_file_map");
12214
12235
  let installOssFileMap;
12215
12236
  let rawForTelemetry;
@@ -12252,7 +12273,8 @@ async function main() {
12252
12273
  console.error("Usage: install-extension <tag> (--all | --extension=<name>...) [--home_base=<dir>] [--config_path=<path>] [--skip-config-update] [--oss_file_map=<base64>]");
12253
12274
  node_process.default.exit(1);
12254
12275
  }
12255
- acquireInstallLock("install-extension");
12276
+ const installExtLockErr = acquireInstallLock("install-extension");
12277
+ if (installExtLockErr) handleInstallLockConflict(installExtLockErr);
12256
12278
  const all = args.includes("--all");
12257
12279
  const names = getMultiFlag(args, "extension");
12258
12280
  const homeBase = getFlag(args, "home_base");
@@ -12316,7 +12338,8 @@ async function main() {
12316
12338
  console.error("Usage: install-cli <tag> --cli=<name>... [--home_base=<dir>] [--oss_file_map=<base64>]");
12317
12339
  node_process.default.exit(1);
12318
12340
  }
12319
- acquireInstallLock("install-cli");
12341
+ const installCliLockErr = acquireInstallLock("install-cli");
12342
+ if (installCliLockErr) handleInstallLockConflict(installCliLockErr);
12320
12343
  const homeBase = getFlag(args, "home_base");
12321
12344
  const ossFileMapFlag = getFlag(args, "oss_file_map");
12322
12345
  let installOssFileMap;
@@ -12460,7 +12483,31 @@ async function main() {
12460
12483
  }
12461
12484
  case "upgrade-lark": {
12462
12485
  const checkOnly = args.includes("--check");
12463
- if (!checkOnly) acquireInstallLock("upgrade-lark");
12486
+ if (!checkOnly) {
12487
+ const upgradeLockErr = acquireInstallLock("upgrade-lark");
12488
+ if (upgradeLockErr) {
12489
+ const fixStatus = computeFixStatus(scene, "failed");
12490
+ const failResult = {
12491
+ status: "failed",
12492
+ error: upgradeLockErr,
12493
+ logFile: "",
12494
+ fixStatus
12495
+ };
12496
+ if (fixStatus !== void 0) writeFixStatusEvent(fixStatus, failResult, console.error);
12497
+ console.log(JSON.stringify(failResult));
12498
+ reportUpgradeLarkToSlardar({
12499
+ scene,
12500
+ checkOnly,
12501
+ durationMs: Date.now() - t0,
12502
+ resultStatus: "failed",
12503
+ error: upgradeLockErr,
12504
+ logFile: "",
12505
+ resultSummary: buildUpgradeLarkResultSummary(failResult, checkOnly)
12506
+ });
12507
+ node_process.default.exitCode = 1;
12508
+ return;
12509
+ }
12510
+ }
12464
12511
  const skipRestart = args.includes("--skip-restart");
12465
12512
  const result = runUpgradeLark({
12466
12513
  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.18",
4
4
  "description": "CLI for OpenClaw config diagnose and repair with JSON5 support",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {