mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 11:55:47 -06:00
e2ec8283c4
* refactor(deadcode): trim auto-reply and CLI exports * refactor(deadcode): trim cron and task exports * refactor(deadcode): trim fleet and process exports * test(deadcode): exercise live task and process seams * test(fleet): cover stream redaction through owner module * refactor(security): trim dead internal exports * refactor(secrets): trim dead internal exports * refactor(deadcode): trim remaining src exports * refactor(deadcode): remove test-only runtime exports * refactor(deadcode): trim pairing test exports * refactor(deadcode): reconcile refreshed baseline * test(auto-reply): deduplicate queue state imports
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
/** Detects whether the current process is running inside a launchd service label. */
|
|
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
|
|
|
|
type CurrentProcessLaunchdServiceLabelOptions = {
|
|
allowConfiguredLabelFallback?: boolean;
|
|
};
|
|
|
|
/** Checks whether the current process appears to be running under the requested launchd label. */
|
|
export function isCurrentProcessLaunchdServiceLabel(
|
|
label: string,
|
|
env: NodeJS.ProcessEnv = process.env,
|
|
options: CurrentProcessLaunchdServiceLabelOptions = {},
|
|
): boolean {
|
|
const currentLabels = [env.LAUNCH_JOB_LABEL, env.LAUNCH_JOB_NAME, env.XPC_SERVICE_NAME].flatMap(
|
|
(value) => {
|
|
const normalized = normalizeOptionalString(value);
|
|
return normalized ? [normalized] : [];
|
|
},
|
|
);
|
|
|
|
for (const currentLabel of currentLabels) {
|
|
if (currentLabel === label) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
const configuredLabel = normalizeOptionalString(env.OPENCLAW_LAUNCHD_LABEL);
|
|
if (!configuredLabel || configuredLabel !== label) {
|
|
return false;
|
|
}
|
|
if (
|
|
normalizeOptionalString(env.OPENCLAW_SERVICE_MARKER) === "openclaw" &&
|
|
Boolean(normalizeOptionalString(env.OPENCLAW_SERVICE_KIND))
|
|
) {
|
|
// Managed wrappers inject service metadata; trust it when launchd's own
|
|
// label variables are absent or renamed by the host environment.
|
|
return true;
|
|
}
|
|
return options.allowConfiguredLabelFallback !== false && currentLabels.length === 0;
|
|
}
|