import { spawn } from "node:child_process";
import { resolveExecutableInPath } from "../application/environment.js";
export { parseCliUserModelId } from "../engine/cli-model-id.js";
export async function canSpawnCommand({ command, args = ["--help"], env, }) {
    if (!command.trim())
        return false;
    return new Promise((resolve) => {
        const proc = spawn(command, args, {
            stdio: ["ignore", "ignore", "ignore"],
            env,
            windowsHide: true,
        });
        proc.on("error", () => resolve(false));
        proc.on("close", (code) => resolve(code === 0));
    });
}
export function hasBirdCli(env) {
    return resolveExecutableInPath("bird", env) !== null;
}
export function hasXurlCli(env) {
    return resolveExecutableInPath("xurl", env) !== null;
}
export function hasUvxCli(env) {
    if (typeof env.UVX_PATH === "string" && env.UVX_PATH.trim().length > 0) {
        return true;
    }
    return resolveExecutableInPath("uvx", env) !== null;
}
export function parseCliProviderArg(raw) {
    const normalized = raw.trim().toLowerCase();
    if (normalized === "claude" ||
        normalized === "codex" ||
        normalized === "gemini" ||
        normalized === "agent" ||
        normalized === "openclaw" ||
        normalized === "opencode" ||
        normalized === "copilot" ||
        normalized === "agy" ||
        normalized === "pi") {
        return normalized;
    }
    throw new Error(`Unsupported --cli: ${raw}`);
}
//# sourceMappingURL=env.js.map