import { t as isLarkCliAvailable } from "./resolve-pBPj3wEy.js";
import { execFile } from "node:child_process";
//#region src/infra/lark-cli/install-skills.ts
const INSTALL_TIMEOUT_MS = 12e4;
/**
* Resolve the npx executable name for the current platform.
*
* On Windows, `execFile("npx", ...)` fails with ENOENT because cmd.exe
* needs the `.cmd` extension to resolve batch/shell scripts.  The npm
* bin directory is already on PATH for most setups, but `execFile` does
* not go through cmd.exe unless `shell: true` is set.
*/
function resolveNpxCommand() {
	if (process.platform === "win32") return {
		file: "npx",
		useShell: true
	};
	return {
		file: "npx",
		useShell: false
	};
}
/**
* Install lark-cli skills (lark-*) to ~/.agents/skills/.
*
* Runs `npx skills add larksuite/cli -g --all` which installs ~28 lark-*
* skills that wrap lark-cli commands as prompt guides (SKILL.md files).
*
* Requires:
*   1. lark-cli binary available (resolved from optionalDependency or PATH)
*   2. Network access (skills are fetched from registry)
*
* Non-blocking: returns error info instead of throwing.
*/
async function installLarkCliSkills() {
	if (!isLarkCliAvailable()) return {
		ok: false,
		error: "lark-cli not available"
	};
	const { file, useShell } = resolveNpxCommand();
	return new Promise((resolve) => {
		execFile(file, [
			"-y",
			"skills",
			"add",
			"larksuite/cli",
			"-g",
			"--all"
		], {
			timeout: INSTALL_TIMEOUT_MS,
			env: process.env,
			...useShell ? { shell: true } : {}
		}, (error, stdout, stderr) => {
			if (error) {
				resolve({
					ok: false,
					error: (typeof stderr === "string" ? stderr : "")?.trim() || error.message
				});
				return;
			}
			const match = (typeof stdout === "string" ? stdout : "").match(/(\d+)\s+skill/i);
			resolve({
				ok: true,
				installed: match ? parseInt(match[1], 10) : void 0
			});
		});
	});
}
//#endregion
export { installLarkCliSkills };
