openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
128 lines (127 loc) • 6.01 kB
JavaScript
import { r as resolveRuntimeScriptPosition } from "./runtime-binary-QwVVJ9cA.mjs";
import { y as resolveNodeServiceIdentityEnvironment } from "./constants-BZisy3jr.mjs";
import { C as resolveIsNixMode, o as isDefaultInstallIdentity } from "./paths-DAcAg5aV.mjs";
import { n as resolveOpenClawPackageRoot } from "./openclaw-root-C-ayo09z.mjs";
import { i as hasCommandProcessCleanupError } from "./exec-result-DJMhztYN.mjs";
import { o as hasGatewayServiceLauncherOverride, s as resolveManagedGatewayServiceCommand, t as assertServiceDefinitionWritable } from "./service-types-DdxELPHF.mjs";
import { n as GatewayServiceAuthorityError } from "./service-update-authority-wlK0pAdP.mjs";
import { t as mergeGatewayServiceEnv } from "./service-env-merge-994N__ny.mjs";
import { n as readInstallOwner, t as formatInstallOwnerMessage } from "./install-owner-DDPQXcjQ.mjs";
import { m as resolveNodeServiceEntrypoint } from "./service-hQiIzcTo.mjs";
import { a as readDaemonRuntimePin, c as withDaemonRuntimePinMigration } from "./runtime-pin-state-DXPlp4E4.mjs";
import { t as note } from "./note-CnLgHvug.mjs";
import { t as resolveNodeService } from "./node-service-CJZ08R6H.mjs";
import { a as isServiceRepairDeferred, n as assertDoctorServiceSelection, s as resolveServiceRepairPolicy } from "./doctor-service-repair-policy-DAuL0W8-.mjs";
import { isDeepStrictEqual } from "node:util";
//#region src/commands/doctor-node-services.ts
/** Repair the shipped direct-entry node definition without rebuilding its launch options. */
async function maybeRepairNodeServiceConfig(e, t, n = process.env) {
if (!isDefaultInstallIdentity(n) || resolveIsNixMode(n)) return;
const r = resolveNodeService();
try {
const e = await r.readCommand(n, { requireEffective: true });
const i = resolveManagedGatewayServiceCommand(e);
if (!e || !i) return;
const { position: a } = resolveRuntimeScriptPosition(i.programArguments);
if (typeof a !== "number" || !/[\\/]dist[\\/]index\.m?js$/u.test(i.programArguments[a] ?? "") || i.programArguments[a + 1] !== "node" || i.programArguments[a + 2] !== "run") return;
note("Node service bypasses the node-host launcher, so automatic node updates cannot start. Run openclaw doctor --fix to repair it.", "Node service");
if (isServiceRepairDeferred(resolveServiceRepairPolicy(n))) {
note("Node service repair deferred; its definition and activation were left unchanged.", "Node service");
return;
}
if (hasGatewayServiceLauncherOverride(e) || i.environment?.OPENCLAW_WRAPPER?.trim()) {
note("Node service has a custom launcher. Update that launcher to invoke openclaw.mjs or dist/entry.js; it was left unchanged.", "Node service");
return;
}
const o = await resolveOpenClawPackageRoot({ argv1: i.programArguments[a] });
if (!o) {
note("Node service package ownership could not be verified; its definition was left unchanged.", "Node service");
return;
}
const s = await readInstallOwner(o);
if (s) {
note(formatInstallOwnerMessage(s), "Node service");
return;
}
const c = [...i.programArguments];
c[a] = await resolveNodeServiceEntrypoint(i.programArguments[a]);
const l = mergeGatewayServiceEnv(n, e);
assertDoctorServiceSelection(n, l);
const u = {
...l,
...resolveNodeServiceIdentityEnvironment(l)
};
const d = [];
let f;
if (process.platform === "darwin") {
const { auditLaunchdDefinition: e } = await import("./service-audit-launchd-uZMhrVeh.mjs");
await e(u, [], d, void 0, true);
} else if (process.platform === "linux") {
const { auditSystemdUnit: t } = await import("./service-audit-systemd-5hqN8Jjy.mjs");
f = await t(u, [], void 0, e, d, true);
} else if (process.platform === "win32") {
const { auditScheduledTaskDefinition: e } = await import("./service-audit-schtasks-DVQxQsfS.mjs");
await e(u, d, void 0, {
...i,
programArguments: c
});
}
if (f || d.some((e) => e.kind !== "outdated")) {
note("Node service has custom or unverified native settings. Reinstall with openclaw node install --force after preserving those settings; it was left unchanged.", "Node service");
return;
}
const p = await r.readDefinitionMutationCapability?.({
env: l,
environment: i.environment
});
if (p) assertServiceDefinitionWritable(p);
if (!await t.confirmRuntimeRepair({
message: "Repair the node service launcher?",
initialValue: true
})) return;
const m = await withDaemonRuntimePinMigration(u, () => readDaemonRuntimePin({
kind: "node",
env: l
}, e));
const h = await r.readRuntime(l, { commandInspection: {
kind: "present",
command: e
} });
if (h.status !== "running" && h.status !== "stopped") {
note("Node service runtime could not be inspected; its definition was left unchanged.", "Node service");
return;
}
const g = {
env: l,
stdout: process.stdout,
...i,
programArguments: c,
preserveAutoStart: true,
runtimePinUpdate: {
expected: m,
pin: m.pin,
requireDefinitionMatch: true
},
beforeMutation: async () => {
if (isServiceRepairDeferred(resolveServiceRepairPolicy(n)) || !isDeepStrictEqual(await r.readCommand(n, { requireEffective: true }), e)) throw new Error("Node service changed during Doctor; rerun doctor to inspect its current definition.");
},
warn: (e) => note(e, "Node service")
};
if (h.status === "running") {
await r.install(g);
if (process.platform === "win32") await r.restart({
env: l,
stdout: process.stdout
});
note("Node service launcher repaired and restarted; automatic node updates can now start.", "Node service");
} else {
await r.stage(g);
note("Node service launcher repaired; its stopped state was preserved. Run openclaw node start when ready.", "Node service");
}
} catch (t) {
if (t instanceof GatewayServiceAuthorityError || hasCommandProcessCleanupError(t)) throw t;
e.error(`Node service repair did not complete: ${String(t)}`);
}
}
//#endregion
export { maybeRepairNodeServiceConfig };