UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

133 lines (132 loc) • 5 kB
import { n as runtimeProcessEntrypoints } from "./runtime-process-entrypoints-qiyJvDDT.mjs"; import { a as resolveRuntimeWorkerUrl, n as resolveRuntimeWorkerArgv } from "./runtime-worker-url-DRDkoS4J.mjs"; import { o as registerSignalExitBarrier } from "./signal-exit-barrier-BOGtFHQL.mjs"; import { a as resolveUpdateRehearsalRoot } from "./update-rehearsal-paths-Dr1MbUA_.mjs"; import { r as scheduleAbsoluteDeadline } from "./absolute-deadline-kK4DcdPs.mjs"; import { i as runUtf8CommandWithTimeout } from "./exec-runner-Br73vG-X.mjs"; import { i as resolveCommandProcessSignal } from "./exec-spawn-DMKoejF-.mjs"; import "./exec-aRIvS9s4.mjs"; import { a as parseUpdateDoctorLintReport, t as UPDATE_DOCTOR_DISPOSAL_WARNING_PREFIX } from "./update-doctor-lint-DBj8vlYP.mjs"; import { t as drainProcessOutput } from "./output-drain-DXUiZ2Pg.mjs"; import { t as scrubDoctorErrorMessage } from "./doctor-error-message-BWgd1c6H.mjs"; import { fileURLToPath } from "node:url"; import { StringDecoder } from "node:string_decoder"; //#region src/commands/doctor-lint-process.ts const MAX_OUTPUT_BYTES = 1048576; /** The copied rehearsal may stop its private inspector after its checks have reported. */ async function runUpdateDoctorLintProcess(e, t) { if (!resolveUpdateRehearsalRoot(process.env) || e.json !== true) throw new Error("Doctor lint worker requires an isolated update rehearsal in JSON mode."); const n = resolveRuntimeWorkerUrl(runtimeProcessEntrypoints.doctorLint); const r = new AbortController(); const i = resolveCommandProcessSignal(); const a = i ? AbortSignal.any([i, r.signal]) : r.signal; const o = Date.now(); const s = new StringDecoder("utf8"); let c = ""; let l; let u; let d = false; let f = false; let p; let m; let h; const g = registerSignalExitBarrier(async () => { f = true; r.abort(); await h; }); const onOutputError = (e) => { p ??= e; r.abort(); }; const callerRefusalReasons = () => [ f && "signal-barrier", i?.aborted && "caller-signal", p && "output-error" ].filter(Boolean); process.stdout.on("error", onOutputError); process.stderr.on("error", onOutputError); try { const i = { options: e, commandStartedAtMs: t?.commandStartedAtMs }; h = runUtf8CommandWithTimeout([process.execPath, ...resolveRuntimeWorkerArgv(n)], { input: JSON.stringify(i), baseEnv: process.env, .../\.[cm]?ts$/.test(fileURLToPath(n)) ? { env: { TSX_TSCONFIG_PATH: fileURLToPath(new URL("../../tsconfig.json", n)) } } : {}, signal: a, killProcessTree: true, requireProcessTreeExtinction: true, killSignal: "SIGKILL", maxOutputBytes: MAX_OUTPUT_BYTES, terminateOnOutputError: true, terminateOnOutputLimit: true, onOutputChunk(e, n) { if (n === "stderr") { process.stderr.write(e); return; } c += s.write(e); if (l) { if (c.trim()) throw new Error("Doctor lint worker emitted output after its readiness report."); return; } const i = c.indexOf("\n"); if (i < 0) return; const a = c.slice(0, i); const f = parseUpdateDoctorLintReport(a); c = c.slice(i + 1); if (c.trim()) throw new Error("Doctor lint worker emitted more than one readiness report."); l = f; u = Date.now(); process.stdout.write(`${a}\n`); const p = Math.max(5e3, u - o); m = scheduleAbsoluteDeadline(Math.min(u + p, t?.disposalDeadlineMs ?? Infinity), () => { d = true; r.abort(); }); } }); const f = await h; const p = [ ...callerRefusalReasons(), f.outputErrorStream && "worker-output", f.outputLimitExceeded && "output-limit", f.cleanup === "uncertain" && "cleanup-uncertain" ].filter(Boolean); if (p.length > 0) { const e = [ d && "disposal-requested", f.killIssuedByAbort && "kill-issued-by-abort", `termination=${f.termination}` ].filter(Boolean); throw new Error(`Doctor lint settlement refused: ${p.join(",")}; ${e.join(",")}.`); } if (!l || u === void 0) throw new Error("Doctor lint worker exited before reporting completed checks."); parseUpdateDoctorLintReport(f.stdout); const g = l.ok ? 0 : 1; const _ = d && f.killIssuedByAbort && f.cleanup === "forced"; if (_) process.stderr.write(`${UPDATE_DOCTOR_DISPOSAL_WARNING_PREFIX} timed out after ${Date.now() - u}ms; checks completed.\n`); if (f.termination === "exit" && f.code === g || _) { await new Promise((e) => { drainProcessOutput(e); }); const e = callerRefusalReasons(); if (e.length > 0) throw new Error(`Doctor lint output-drain refused: ${e.join(",")}.`); return g; } throw new Error(`Doctor lint worker exited unexpectedly after reporting checks (${f.termination}, code ${f.code}).`); } catch (e) { if (!l) throw e; process.stderr.write(`[openclaw] Reason: ${scrubDoctorErrorMessage(e)}\n`); return 2; } finally { m?.(); g(); process.stdout.off("error", onOutputError); process.stderr.off("error", onOutputError); } } //#endregion export { runUpdateDoctorLintProcess };