





















@@ -1,3 +1,5 @@
1+import { execFile } from "node:child_process";
2+import { promisify } from "node:util";
13import { formatCliCommand } from "../cli/command-format.js";
24import type { OpenClawConfig } from "../config/types.openclaw.js";
35import { resolveCronStorePath, loadCronStore, saveCronStore } from "../cron/store.js";
@@ -20,6 +22,12 @@ type CronDoctorOutcome = {
2022warnings: string[];
2123};
222425+type CrontabReader = () => Promise<{ stdout: string; stderr?: string }>;
26+27+const execFileAsync = promisify(execFile);
28+const LEGACY_WHATSAPP_HEALTH_SCRIPT_RE =
29+/(?:^|\s)(?:"[^"]*ensure-whatsapp\.sh"|'[^']*ensure-whatsapp\.sh'|[^\s#;|&]*ensure-whatsapp\.sh)\b/u;
30+2331function pluralize(count: number, noun: string) {
2432return `${count} ${noun}${count === 1 ? "" : "s"}`;
2533}
@@ -129,6 +137,58 @@ function migrateLegacyNotifyFallback(params: {
129137return { changed, warnings };
130138}
131139140+async function readUserCrontab(): Promise<{ stdout: string; stderr?: string }> {
141+const result = await execFileAsync("crontab", ["-l"], {
142+encoding: "utf8",
143+windowsHide: true,
144+});
145+return {
146+stdout: result.stdout,
147+stderr: result.stderr,
148+};
149+}
150+151+function findLegacyWhatsAppHealthCrontabLines(crontab: string): string[] {
152+return crontab
153+.split(/\r?\n/u)
154+.map((line) => line.trim())
155+.filter((line) => line.length > 0 && !line.startsWith("#"))
156+.filter((line) => LEGACY_WHATSAPP_HEALTH_SCRIPT_RE.test(line));
157+}
158+159+export async function noteLegacyWhatsAppCrontabHealthCheck(
160+params: {
161+platform?: NodeJS.Platform;
162+readCrontab?: CrontabReader;
163+} = {},
164+): Promise<void> {
165+if ((params.platform ?? process.platform) !== "linux") {
166+return;
167+}
168+169+let crontab: string;
170+try {
171+crontab = (await (params.readCrontab ?? readUserCrontab)()).stdout;
172+} catch {
173+return;
174+}
175+176+const legacyLines = findLegacyWhatsAppHealthCrontabLines(crontab);
177+if (legacyLines.length === 0) {
178+return;
179+}
180+181+note(
182+[
183+"Legacy WhatsApp crontab health check detected.",
184+"`~/.openclaw/bin/ensure-whatsapp.sh` is not maintained by current OpenClaw and can misreport `Gateway inactive` from cron when the systemd user bus environment is missing.",
185+`Remove the stale crontab entry with ${formatCliCommand("crontab -e")}; use ${formatCliCommand("openclaw channels status --probe")}, ${formatCliCommand("openclaw doctor")}, and ${formatCliCommand("openclaw gateway status")} for current health checks.`,
186+`Matched ${pluralize(legacyLines.length, "entry")}.`,
187+].join("\n"),
188+"Cron",
189+);
190+}
191+132192export async function maybeRepairLegacyCronStore(params: {
133193cfg: OpenClawConfig;
134194options: DoctorOptions;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。