openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.76 kB
JavaScript
import { w as resolveGlobalSingleton } from "./number-coercion-PJEgwXYS.mjs";
import "./subsystem-Caj1-NVj.mjs";
import { a as areDiagnosticsEnabledForProcess } from "./signal-exit-barrier-CXSq-V21.mjs";
import "./runtime-process-entrypoints-De68tE_W.mjs";
import "./host-XUeqeshL.mjs";
import path from "node:path";
import { AsyncLocalStorage } from "node:async_hooks";
//#region src/process/spawn-broker/context.ts
const context = new AsyncLocalStorage();
function getSpawnBroker() {
return context.getStore();
}
//#endregion
//#region src/process/spawn-diagnostics.ts
const spawnCounts = resolveGlobalSingleton(Symbol.for("openclaw.childProcessSpawnCounts"), () => ({
counts: /* @__PURE__ */ new Map(),
sampledAt: performance.now()
}));
const COMMAND_FAMILIES = /^(node|bun|git|ps|pgrep|lsof|sh|bash|zsh|cmd|powershell|pwsh|npm|pnpm|python|python3|uv|ssh|openclaw)$/;
const gitOperation = resolveGlobalSingleton(Symbol.for("openclaw.gitSpawnOperation"), () => new AsyncLocalStorage());
/** Count admitted local and broker launches, without recording paths or arguments. */
function recordChildProcessSpawn(command, child) {
if (!areDiagnosticsEnabledForProcess()) return;
const name = path.win32.basename(command).toLowerCase().replace(/\.(exe|cmd)$/, "");
const family = COMMAND_FAMILIES.test(name) ? name : "other";
const operation = family === "git" ? gitOperation.getStore() ?? "unknown" : "none";
const key = `${family}:${operation}`;
child.once("spawn", () => {
if (areDiagnosticsEnabledForProcess()) {
const previous = spawnCounts.counts.get(key);
spawnCounts.counts.set(key, {
family,
operation,
count: (previous?.count ?? 0) + 1
});
}
});
}
//#endregion
export { getSpawnBroker as n, recordChildProcessSpawn as t };