@lark-apaas/openclaw-scripts-diagnose-cli 0.1.15-alpha.14 → 0.1.15-alpha.15
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/dist/index.cjs +91 -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.
|
|
55
|
+
return "0.1.15-alpha.15";
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
58
|
//#region src/rule-engine/base.ts
|
|
@@ -2640,6 +2640,13 @@ const CONFIG_PATH = `${WORKSPACE_DIR}/openclaw.json`;
|
|
|
2640
2640
|
*/
|
|
2641
2641
|
const FIX_EVENT_DIR = "/tmp/event";
|
|
2642
2642
|
/**
|
|
2643
|
+
* 安装指令互斥锁文件路径。
|
|
2644
|
+
* upgrade-lark / install-openclaw / install-extension / install-cli / reset --worker
|
|
2645
|
+
* 共享此锁,同一时刻只允许一个安装指令运行。
|
|
2646
|
+
* 锁文件内容:{ pid, command, startedAt }。
|
|
2647
|
+
*/
|
|
2648
|
+
const INSTALL_LOCK_FILE = `${DIAGNOSE_DIR}/install.lock`;
|
|
2649
|
+
/**
|
|
2643
2650
|
* upgrade-lark 每次运行的日志文件路径,含时间戳便于按时间排序定位。
|
|
2644
2651
|
* checkOnly=true 时文件名含 "-check" 后缀,便于与正式安装日志区分。
|
|
2645
2652
|
*/
|
|
@@ -10697,7 +10704,7 @@ async function reportCliRun(opts) {
|
|
|
10697
10704
|
//#region src/help.ts
|
|
10698
10705
|
const BIN = "mclaw-diagnose";
|
|
10699
10706
|
function versionBanner() {
|
|
10700
|
-
return `v0.1.15-alpha.
|
|
10707
|
+
return `v0.1.15-alpha.15`;
|
|
10701
10708
|
}
|
|
10702
10709
|
const COMMANDS = [
|
|
10703
10710
|
{
|
|
@@ -11871,6 +11878,83 @@ function runUpgradeLark(opts) {
|
|
|
11871
11878
|
});
|
|
11872
11879
|
}
|
|
11873
11880
|
//#endregion
|
|
11881
|
+
//#region src/install-lock.ts
|
|
11882
|
+
/**
|
|
11883
|
+
* 检查指定 PID 是否仍在运行(向进程发 signal 0,不影响其运行状态)。
|
|
11884
|
+
* 跨平台:Linux/macOS 均支持;Windows 不在目标平台范围内。
|
|
11885
|
+
*/
|
|
11886
|
+
function isPidAlive(pid) {
|
|
11887
|
+
try {
|
|
11888
|
+
process.kill(pid, 0);
|
|
11889
|
+
return true;
|
|
11890
|
+
} catch (e) {
|
|
11891
|
+
if (e.code === "EPERM") return true;
|
|
11892
|
+
return false;
|
|
11893
|
+
}
|
|
11894
|
+
}
|
|
11895
|
+
/**
|
|
11896
|
+
* 获取安装操作互斥锁。
|
|
11897
|
+
*
|
|
11898
|
+
* 利用 open(O_CREAT | O_EXCL) 的 POSIX 原子性确保同一时刻只有一个安装指令运行。
|
|
11899
|
+
* 覆盖的安装指令:upgrade-lark / install-openclaw / install-extension / install-cli / reset --worker。
|
|
11900
|
+
*
|
|
11901
|
+
* 若锁被活跃进程持有,抛出包含持有者信息的 Error。
|
|
11902
|
+
* 若锁文件属于已退出进程(crash 遗留),视为过期锁并覆盖。
|
|
11903
|
+
*
|
|
11904
|
+
* 成功获取后自动注册 process.on('exit') 释放锁,无需调用方手动清理。
|
|
11905
|
+
*/
|
|
11906
|
+
function acquireInstallLock(command) {
|
|
11907
|
+
node_fs.default.mkdirSync(DIAGNOSE_DIR, { recursive: true });
|
|
11908
|
+
const info = {
|
|
11909
|
+
pid: process.pid,
|
|
11910
|
+
command,
|
|
11911
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11912
|
+
};
|
|
11913
|
+
const content = JSON.stringify(info);
|
|
11914
|
+
while (true) try {
|
|
11915
|
+
const fd = node_fs.default.openSync(INSTALL_LOCK_FILE, node_fs.default.constants.O_CREAT | node_fs.default.constants.O_EXCL | node_fs.default.constants.O_WRONLY, 420);
|
|
11916
|
+
node_fs.default.writeSync(fd, content);
|
|
11917
|
+
node_fs.default.closeSync(fd);
|
|
11918
|
+
process.once("exit", releaseInstallLock);
|
|
11919
|
+
console.error(`[install-lock] acquired command=${command} pid=${process.pid}`);
|
|
11920
|
+
return;
|
|
11921
|
+
} catch (e) {
|
|
11922
|
+
if (e.code !== "EEXIST") throw e;
|
|
11923
|
+
let existing = null;
|
|
11924
|
+
try {
|
|
11925
|
+
existing = JSON.parse(node_fs.default.readFileSync(INSTALL_LOCK_FILE, "utf-8"));
|
|
11926
|
+
} catch {
|
|
11927
|
+
try {
|
|
11928
|
+
node_fs.default.rmSync(INSTALL_LOCK_FILE, { force: true });
|
|
11929
|
+
} catch {}
|
|
11930
|
+
continue;
|
|
11931
|
+
}
|
|
11932
|
+
if (!isPidAlive(existing.pid)) {
|
|
11933
|
+
console.error(`[install-lock] stale lock detected (pid=${existing.pid} command=${existing.command}), removing`);
|
|
11934
|
+
try {
|
|
11935
|
+
node_fs.default.rmSync(INSTALL_LOCK_FILE, { force: true });
|
|
11936
|
+
} catch {}
|
|
11937
|
+
continue;
|
|
11938
|
+
}
|
|
11939
|
+
throw new Error(`另一个安装指令正在运行,请等待其完成后重试。\n 占用指令: ${existing.command}\n 进程 PID : ${existing.pid}\n 开始时间: ${existing.startedAt}\n 锁文件 : ${INSTALL_LOCK_FILE}`);
|
|
11940
|
+
}
|
|
11941
|
+
}
|
|
11942
|
+
/**
|
|
11943
|
+
* 释放安装操作互斥锁。
|
|
11944
|
+
* 仅删除由本进程创建的锁文件,避免误删其他进程的锁。
|
|
11945
|
+
* 通常由 process.on('exit') 自动调用,不需要手动调用。
|
|
11946
|
+
*/
|
|
11947
|
+
function releaseInstallLock() {
|
|
11948
|
+
try {
|
|
11949
|
+
const raw = node_fs.default.readFileSync(INSTALL_LOCK_FILE, "utf-8");
|
|
11950
|
+
const info = JSON.parse(raw);
|
|
11951
|
+
if (info.pid === process.pid) {
|
|
11952
|
+
node_fs.default.rmSync(INSTALL_LOCK_FILE, { force: true });
|
|
11953
|
+
console.error(`[install-lock] released command=${info.command} pid=${process.pid}`);
|
|
11954
|
+
}
|
|
11955
|
+
} catch {}
|
|
11956
|
+
}
|
|
11957
|
+
//#endregion
|
|
11874
11958
|
//#region src/index.ts
|
|
11875
11959
|
const args = node_process.default.argv.slice(2);
|
|
11876
11960
|
const mode = args.find((a) => !a.startsWith("-"));
|
|
@@ -12070,6 +12154,7 @@ async function main() {
|
|
|
12070
12154
|
console.error("Error: --task-id=<id> is required for worker");
|
|
12071
12155
|
node_process.default.exit(1);
|
|
12072
12156
|
}
|
|
12157
|
+
acquireInstallLock("reset");
|
|
12073
12158
|
const resultFile = resetResultFile(taskId);
|
|
12074
12159
|
const raw = await fetchCtxViaInnerApi({
|
|
12075
12160
|
populate: planCtxPopulate({ command: "reset" }),
|
|
@@ -12114,6 +12199,7 @@ async function main() {
|
|
|
12114
12199
|
console.error("Usage: install-openclaw <tag> [--oss_file_map=<base64>]");
|
|
12115
12200
|
node_process.default.exit(1);
|
|
12116
12201
|
}
|
|
12202
|
+
acquireInstallLock("install-openclaw");
|
|
12117
12203
|
const ossFileMapFlag = getFlag(args, "oss_file_map");
|
|
12118
12204
|
let installOssFileMap;
|
|
12119
12205
|
let rawForTelemetry;
|
|
@@ -12156,6 +12242,7 @@ async function main() {
|
|
|
12156
12242
|
console.error("Usage: install-extension <tag> (--all | --extension=<name>...) [--home_base=<dir>] [--config_path=<path>] [--skip-config-update] [--oss_file_map=<base64>]");
|
|
12157
12243
|
node_process.default.exit(1);
|
|
12158
12244
|
}
|
|
12245
|
+
acquireInstallLock("install-extension");
|
|
12159
12246
|
const all = args.includes("--all");
|
|
12160
12247
|
const names = getMultiFlag(args, "extension");
|
|
12161
12248
|
const homeBase = getFlag(args, "home_base");
|
|
@@ -12219,6 +12306,7 @@ async function main() {
|
|
|
12219
12306
|
console.error("Usage: install-cli <tag> --cli=<name>... [--home_base=<dir>] [--oss_file_map=<base64>]");
|
|
12220
12307
|
node_process.default.exit(1);
|
|
12221
12308
|
}
|
|
12309
|
+
acquireInstallLock("install-cli");
|
|
12222
12310
|
const homeBase = getFlag(args, "home_base");
|
|
12223
12311
|
const ossFileMapFlag = getFlag(args, "oss_file_map");
|
|
12224
12312
|
let installOssFileMap;
|
|
@@ -12362,6 +12450,7 @@ async function main() {
|
|
|
12362
12450
|
}
|
|
12363
12451
|
case "upgrade-lark": {
|
|
12364
12452
|
const checkOnly = args.includes("--check");
|
|
12453
|
+
if (!checkOnly) acquireInstallLock("upgrade-lark");
|
|
12365
12454
|
const skipRestart = args.includes("--skip-restart");
|
|
12366
12455
|
const result = runUpgradeLark({
|
|
12367
12456
|
runId: rc.runId,
|
package/package.json
CHANGED