refactor(daemon): share schtasks exec helper

This commit is contained in:
Peter Steinberger
2026-02-14 14:14:49 +00:00
parent 3150ece95a
commit 2004ce919a
3 changed files with 35 additions and 65 deletions

View File

@@ -1,7 +1,5 @@
import { execFile } from "node:child_process";
import fs from "node:fs/promises";
import path from "node:path";
import { promisify } from "node:util";
import {
GATEWAY_SERVICE_KIND,
GATEWAY_SERVICE_MARKER,
@@ -9,6 +7,7 @@ import {
resolveGatewaySystemdServiceName,
resolveGatewayWindowsTaskName,
} from "./constants.js";
import { execSchtasks } from "./schtasks-exec.js";
export type ExtraGatewayService = {
platform: "darwin" | "linux" | "win32";
@@ -24,7 +23,6 @@ export type FindExtraGatewayServicesOptions = {
};
const EXTRA_MARKERS = ["openclaw", "clawdbot", "moltbot"] as const;
const execFileAsync = promisify(execFile);
export function renderGatewayServiceCleanupHints(
env: Record<string, string | undefined> = process.env as Record<string, string | undefined>,
@@ -296,35 +294,6 @@ function parseSchtasksList(output: string): ScheduledTaskInfo[] {
return tasks;
}
async function execSchtasks(
args: string[],
): Promise<{ stdout: string; stderr: string; code: number }> {
try {
const { stdout, stderr } = await execFileAsync("schtasks", args, {
encoding: "utf8",
windowsHide: true,
});
return {
stdout: String(stdout ?? ""),
stderr: String(stderr ?? ""),
code: 0,
};
} catch (error) {
const e = error as {
stdout?: unknown;
stderr?: unknown;
code?: unknown;
message?: unknown;
};
return {
stdout: typeof e.stdout === "string" ? e.stdout : "",
stderr:
typeof e.stderr === "string" ? e.stderr : typeof e.message === "string" ? e.message : "",
code: typeof e.code === "number" ? e.code : 1,
};
}
}
export async function findExtraGatewayServices(
env: Record<string, string | undefined>,
opts: FindExtraGatewayServicesOptions = {},