diff --git a/src/daemon/inspect.ts b/src/daemon/inspect.ts index 63970351a9..d0153ce13b 100644 --- a/src/daemon/inspect.ts +++ b/src/daemon/inspect.ts @@ -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 = process.env as Record, @@ -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, opts: FindExtraGatewayServicesOptions = {}, diff --git a/src/daemon/schtasks-exec.ts b/src/daemon/schtasks-exec.ts new file mode 100644 index 0000000000..c9c2628b44 --- /dev/null +++ b/src/daemon/schtasks-exec.ts @@ -0,0 +1,33 @@ +import { execFile } from "node:child_process"; +import { promisify } from "node:util"; + +const execFileAsync = promisify(execFile); + +export 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, + }; + } +} diff --git a/src/daemon/schtasks.ts b/src/daemon/schtasks.ts index 138fe7c505..eb66626916 100644 --- a/src/daemon/schtasks.ts +++ b/src/daemon/schtasks.ts @@ -1,14 +1,11 @@ -import { execFile } from "node:child_process"; import fs from "node:fs/promises"; import path from "node:path"; -import { promisify } from "node:util"; import type { GatewayServiceRuntime } from "./service-runtime.js"; import { colorize, isRich, theme } from "../terminal/theme.js"; import { formatGatewayServiceDescription, resolveGatewayWindowsTaskName } from "./constants.js"; import { resolveGatewayStateDir } from "./paths.js"; import { parseKeyValueOutput } from "./runtime-parse.js"; - -const execFileAsync = promisify(execFile); +import { execSchtasks } from "./schtasks-exec.js"; const formatLine = (label: string, value: string) => { const rich = isRich(); @@ -197,35 +194,6 @@ function buildTaskScript({ return `${lines.join("\r\n")}\r\n`; } -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, - }; - } -} - async function assertSchtasksAvailable() { const res = await execSchtasks(["/Query"]); if (res.code === 0) {