import { t as isLarkCliAvailable } from "./resolve-D1pCHyvv.js";
import { existsSync, readdirSync } from "node:fs";
import { join } from "node:path";
import { homedir } from "node:os";
//#region src/infra/lark-cli/auto-disable.ts
/** All native feishu tool keys that can be toggled in channels.feishu.tools.* */
const ALL_TOOL_KEYS = [
	"doc",
	"chat",
	"wiki",
	"drive",
	"perm",
	"scopes",
	"vc",
	"task",
	"bitable"
];
/** Feishu skill IDs to disable when lark-cli takes over native tools */
const FEISHU_SKILL_IDS = [
	"feishu-doc",
	"feishu-wiki",
	"feishu-drive",
	"feishu-perm"
];
/**
* Check if lark-* skills are installed in ~/.agents/skills/.
* Auto-disable should only activate when CLI skills are ready to replace
* native tools — otherwise existing users lose feishu capability on upgrade.
*/
function areLarkSkillsInstalled() {
	const skillsDir = join(homedir(), ".agents", "skills");
	if (!existsSync(skillsDir)) return false;
	try {
		return readdirSync(skillsDir, { withFileTypes: true }).some((e) => e.isDirectory() && e.name.startsWith("lark-") && existsSync(join(skillsDir, e.name, "SKILL.md")));
	} catch {
		return false;
	}
}
/**
* Check if native feishu tools should be auto-disabled.
* Returns true when:
* 1. lark-cli binary is available AND healthy
* 2. lark-* skills are installed (CLI has replacements ready)
* 3. User has NOT explicitly configured any tools.* keys
*/
function shouldDisableNativeTools(userToolsConfig) {
	if (!isLarkCliAvailable()) return false;
	if (!areLarkSkillsInstalled()) return false;
	if (userToolsConfig && Object.keys(userToolsConfig).length > 0) return false;
	return true;
}
/**
* Build the tools config that disables all native feishu tools.
*/
function buildDisabledToolsConfig() {
	const result = {};
	for (const key of ALL_TOOL_KEYS) result[key] = false;
	return result;
}
/**
* Build skill disable entries for feishu skills.
*/
function buildDisabledSkillEntries() {
	const result = {};
	for (const id of FEISHU_SKILL_IDS) result[id] = { enabled: false };
	return result;
}
//#endregion
export { shouldDisableNativeTools as i, buildDisabledSkillEntries as n, buildDisabledToolsConfig as r, areLarkSkillsInstalled as t };
