import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { logger } from "../utils/logger.js";
const execFileAsync = promisify(execFile);
/**
 * Check if the opencode binary is available in PATH and get its version.
 *
 * Runs `opencode --version` which outputs something like "opencode v1.2.0".
 * If not installed or the command fails, returns { available: false }.
 */
export async function checkOpenCodeInstalled() {
    try {
        const { stdout } = await execFileAsync("opencode", ["--version"], {
            timeout: 10_000,
        });
        const version = stdout.trim();
        logger.info(`OpenCode detected: ${version}`);
        return { available: true, version };
    }
    catch {
        logger.warn("OpenCode not found in PATH");
        return { available: false };
    }
}
//# sourceMappingURL=check-installed.js.map