@netmind/arena-cli 0.7.1 → 0.7.2
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.js +27 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2531,10 +2531,10 @@ import { join as join4 } from "path";
|
|
|
2531
2531
|
function pidPath(competitionId) {
|
|
2532
2532
|
return join4(getConfigDir(), `watch-${competitionId}.pid`);
|
|
2533
2533
|
}
|
|
2534
|
-
function writePid(competitionId) {
|
|
2534
|
+
function writePid(competitionId, pid) {
|
|
2535
2535
|
const dir = getConfigDir();
|
|
2536
2536
|
mkdirSync4(dir, { recursive: true });
|
|
2537
|
-
writeFileSync4(pidPath(competitionId), String(process.pid), "utf-8");
|
|
2537
|
+
writeFileSync4(pidPath(competitionId), String(pid ?? process.pid), "utf-8");
|
|
2538
2538
|
}
|
|
2539
2539
|
function deletePid(competitionId) {
|
|
2540
2540
|
const p = pidPath(competitionId);
|
|
@@ -2672,15 +2672,17 @@ It requires the \`openclaw\` CLI to be installed and available in PATH.`).action
|
|
|
2672
2672
|
}
|
|
2673
2673
|
const creds = requireCredentials(opts.credentials);
|
|
2674
2674
|
const existingPid = readPid(competitionId);
|
|
2675
|
-
if (existingPid !== null && checkPidAlive(existingPid)) {
|
|
2675
|
+
if (existingPid !== null && existingPid !== process.pid && checkPidAlive(existingPid)) {
|
|
2676
2676
|
console.log(`Already watching competition ${competitionId} (PID: ${existingPid})`);
|
|
2677
2677
|
process.exit(0);
|
|
2678
2678
|
}
|
|
2679
2679
|
const MAX_WATCHERS = 3;
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2680
|
+
if (existingPid !== process.pid) {
|
|
2681
|
+
const aliveCount = countAliveWatchers();
|
|
2682
|
+
if (aliveCount >= MAX_WATCHERS) {
|
|
2683
|
+
printError(`Maximum of ${MAX_WATCHERS} concurrent watchers reached (${aliveCount} running). Stop an existing watcher before starting a new one.`);
|
|
2684
|
+
process.exit(1);
|
|
2685
|
+
}
|
|
2684
2686
|
}
|
|
2685
2687
|
if (opts.detach) {
|
|
2686
2688
|
const childArgs = [process.argv[1], "watch", "start", competitionId, "--interval", opts.interval];
|
|
@@ -2695,22 +2697,15 @@ It requires the \`openclaw\` CLI to be installed and available in PATH.`).action
|
|
|
2695
2697
|
stdio: "ignore"
|
|
2696
2698
|
});
|
|
2697
2699
|
child.unref();
|
|
2700
|
+
if (typeof child.pid !== "number") {
|
|
2701
|
+
printError("Failed to start background watcher: unable to determine child PID");
|
|
2702
|
+
process.exit(1);
|
|
2703
|
+
}
|
|
2704
|
+
writePid(competitionId, child.pid);
|
|
2698
2705
|
console.log(`Watcher started in background (PID: ${child.pid})`);
|
|
2699
2706
|
console.log(`Stop with: kill ${child.pid}`);
|
|
2700
2707
|
return;
|
|
2701
2708
|
}
|
|
2702
|
-
try {
|
|
2703
|
-
dispatchBootstrapToOpenclaw(competitionId, creds);
|
|
2704
|
-
} catch (err) {
|
|
2705
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
2706
|
-
printError(`bootstrap dispatch failed: ${msg}`);
|
|
2707
|
-
process.exit(1);
|
|
2708
|
-
}
|
|
2709
|
-
try {
|
|
2710
|
-
StateManager.getInstance().trackGame(competitionId, competitionId, "unknown");
|
|
2711
|
-
} catch (e) {
|
|
2712
|
-
console.warn(`[watch] warning: failed to persist game tracking: ${e instanceof Error ? e.message : e}`);
|
|
2713
|
-
}
|
|
2714
2709
|
writePid(competitionId);
|
|
2715
2710
|
const handleSigterm = () => {
|
|
2716
2711
|
cleanup();
|
|
@@ -2727,6 +2722,19 @@ It requires the \`openclaw\` CLI to be installed and available in PATH.`).action
|
|
|
2727
2722
|
};
|
|
2728
2723
|
process.on("SIGTERM", handleSigterm);
|
|
2729
2724
|
process.on("SIGINT", handleSigint);
|
|
2725
|
+
try {
|
|
2726
|
+
dispatchBootstrapToOpenclaw(competitionId, creds);
|
|
2727
|
+
} catch (err) {
|
|
2728
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2729
|
+
printError(`bootstrap dispatch failed: ${msg}`);
|
|
2730
|
+
cleanup();
|
|
2731
|
+
process.exit(1);
|
|
2732
|
+
}
|
|
2733
|
+
try {
|
|
2734
|
+
StateManager.getInstance().trackGame(competitionId, competitionId, "unknown");
|
|
2735
|
+
} catch (e) {
|
|
2736
|
+
console.warn(`[watch] warning: failed to persist game tracking: ${e instanceof Error ? e.message : e}`);
|
|
2737
|
+
}
|
|
2730
2738
|
const apiUrl = getApiUrl();
|
|
2731
2739
|
const intervalMs = Math.min(Math.max(parseInt(opts.interval, 10), 2), 60) * 1e3;
|
|
2732
2740
|
console.log(`Watching competition ${competitionId} (interval: ${intervalMs / 1e3}s)`);
|